ImportC: add __attribute__((pure)) (#15145)

This commit is contained in:
Walter Bright 2023-04-29 10:32:06 -07:00 committed by GitHub
parent c8a88f599a
commit 72f6eff8b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 2 deletions

View file

@ -2893,6 +2893,8 @@ final class CParser(AST) : Parser!AST
auto parameterList = cparseParameterList();
const lkg = specifier.mod & MOD.x__stdcall ? LINK.windows : linkage;
StorageClass stc = specifier._nothrow ? STC.nothrow_ : 0;
if (specifier._pure)
stc |= STC.pure_;
AST.Type tf = new AST.TypeFunction(parameterList, t, lkg, stc);
// tf = tf.addSTC(storageClass); // TODO
insertTx(ts, tf, t); // ts -> ... -> tf -> t
@ -3539,6 +3541,11 @@ final class CParser(AST) : Parser!AST
specifier._nothrow = true;
nextToken();
}
else if (token.ident == Id._pure)
{
specifier._pure = true;
nextToken();
}
else if (token.ident == Id.vector_size)
{
nextToken();
@ -4944,6 +4951,7 @@ final class CParser(AST) : Parser!AST
bool noreturn; /// noreturn attribute
bool naked; /// naked attribute
bool _nothrow; /// nothrow attribute
bool _pure; /// pure attribute
bool dllimport; /// dllimport attribute
bool dllexport; /// dllexport attribute
bool _deprecated; /// deprecated attribute

View file

@ -8896,6 +8896,7 @@ struct Id final
static Identifier* show;
static Identifier* push;
static Identifier* pop;
static Identifier* _pure;
static Identifier* define;
static Identifier* undef;
static void initialize();

View file

@ -377,8 +377,8 @@ extern (C++) class FuncDeclaration : Declaration
extern (D) this(const ref Loc loc, const ref Loc endloc, Identifier ident, StorageClass storage_class, Type type, bool noreturn = false)
{
super(loc, ident);
//printf("FuncDeclaration(id = '%s', type = %p)\n", id.toChars(), type);
//printf("storage_class = x%x\n", storage_class);
//.printf("FuncDeclaration(id = '%s', type = %s)\n", ident.toChars(), type.toChars());
//.printf("storage_class = x%llx\n", storage_class);
this.storage_class = storage_class;
this.type = type;
if (type)

View file

@ -546,6 +546,7 @@ immutable Msgtable[] msgtable =
{ "show" },
{ "push" },
{ "pop" },
{ "_pure", "pure" },
{ "define" },
{ "undef" },
];

View file

@ -0,0 +1,12 @@
/* TEST_OUTPUT:
---
fail_compilation/attrpure.i(11): Error: `pure` function `attrpure.pureAsSnow` cannot call impure function `attrpure.impure`
---
*/
void impure();
__attribute__((pure)) void pureAsSnow()
{
impure();
}