Open Quuxplusone opened 5 years ago
Attached bug.cpp
(234 bytes, text/plain): example
This strawman approach simply makes __builtin_assume_aligned constexpr in all
C++ compilations:
$ git diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 03b6cc91657..0706de3e59e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2004,6 +2004,7 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II,
unsigned ID,
return nullptr;
DeclContext *Parent = Context.getTranslationUnitDecl();
+ ConstexprSpecKind CSK = CSK_unspecified;
if (getLangOpts().CPlusPlus) {
LinkageSpecDecl *CLinkageDecl =
LinkageSpecDecl::Create(Context, Parent, Loc, Loc,
@@ -2011,14 +2012,14 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo
*II, unsigned ID,
CLinkageDecl->setImplicit();
Parent->addDecl(CLinkageDecl);
Parent = CLinkageDecl;
+
+ if (ID == Builtin::BI__builtin_assume_aligned)
+ CSK = CSK_constexpr;
}
- FunctionDecl *New = FunctionDecl::Create(Context,
- Parent,
- Loc, Loc, II, R, /*TInfo=*/nullptr,
- SC_Extern,
- false,
- R->isFunctionProtoType());
+ FunctionDecl *New = FunctionDecl::Create(
+ Context, Parent, Loc, Loc, II, R, /*TInfo=*/nullptr, SC_Extern,
+ /*IsInlineSpecified=*/false, R->isFunctionProtoType(), CSK);
New->setImplicit();
// Create Decl objects for each parameter, adding them to the
It solves the redeclaration error immediately, but it's an awkward special case
in an important common codepath. Should we add a code to Builtins.def for this?
Are there are other builtins that we might wish to mark constexpr? The constant
evaluator seems to know a few.
bug.cpp
(234 bytes, text/plain)