-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang][Interp] Handle AttributedStmts #66495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Just ignore the attributes.
@llvm/pr-subscribers-clang ChangesJust ignore the attributes. -- Full diff: https://github.com//pull/66495.diff3 Files Affected:
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index b7553d8963ff0ee..a0f50c3e69dd918 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -246,6 +246,8 @@ bool ByteCodeStmtGen<Emitter>::visitStmt(const Stmt *S) { case Stmt::GCCAsmStmtClass: case Stmt::MSAsmStmtClass: return visitAsmStmt(cast<AsmStmt>(S)); + case Stmt::AttributedStmtClass: + return visitAttributedStmt(cast<AttributedStmt>(S)); case Stmt::NullStmtClass: return true; default: { @@ -628,6 +630,12 @@ bool ByteCodeStmtGen<Emitter>::visitAsmStmt(const AsmStmt *S) { return this->emitInvalid(S); } +template <class Emitter> +bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) { + // Ignore all attributes. + return this->visitStmt(S->getSubStmt()); +} + namespace clang { namespace interp { diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h index 278e804a803c951..3bdcdd78f397e5b 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.h +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h @@ -68,6 +68,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> { bool visitCaseStmt(const CaseStmt *S); bool visitDefaultStmt(const DefaultStmt *S); bool visitAsmStmt(const AsmStmt *S); + bool visitAttributedStmt(const AttributedStmt *S); bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD); diff --git a/clang/test/AST/Interp/if.cpp b/clang/test/AST/Interp/if.cpp index 2449ace4dd6c6b5..86ae8de6f73ebb7 100644 --- a/clang/test/AST/Interp/if.cpp +++ b/clang/test/AST/Interp/if.cpp @@ -43,4 +43,11 @@ namespace InitDecl { return false; } static_assert(!f2(), ""); + + + constexpr int attrs() { + if (1) [[likely]] {} + return 1; + } + static_assert(attrs() == 1, ""); }; |
@@ -628,6 +630,12 @@ bool ByteCodeStmtGen<Emitter>::visitAsmStmt(const AsmStmt *S) { | |||
return this->emitInvalid(S); | |||
} | |||
|
|||
template <class Emitter> | |||
bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) { | |||
// Ignore all attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what we want to do for [[assume]]
? We can do it this way: https://eel.is/c++draft/expr.const#5.8 but we can also do it better: https://eel.is/c++draft/expr.const#5.33
(We don't support assumptions yet, so I think the code is fine as-is, but I'm wondering if we want to add a FIXME here about [[assume]]
. We should also see if any of our vendor statement attributes have UB we need to consider as well.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a fix me but i wouldn't worry about it too much, until we have a clearer idea of what we do, which we really don't atm
And the wording is clear that this is unspecified either way.
And for vendor attributes, it would only make sense to check them if we want them to fail the evaluation, do we have such things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what we want to do for [[assume]]? We can do it this way: https://eel.is/c++draft/expr.const#5.8 but we can also do it better: https://eel.is/c++draft/expr.const#5.33
The second case would essentially work like an assertion? If this fails, the statement isn't a constant expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At compile time, i suppose so!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sitting in core, which is a good time to mention https://wg21.link/cwg2763 - [[assume]]
is not the only UB standard attribute - but it requires a specific handling so it is also orthogonal to this patch
Just ignore the attributes.
Just ignore the attributes.
Just ignore the attributes.
Just ignore the attributes.