Skip to content

Commit

Permalink
[clang][Interp] Handle AttributedStmts (#66495)
Browse files Browse the repository at this point in the history
Just ignore the attributes.
  • Loading branch information
tbaederr committed Sep 15, 2023
1 parent d2e787d commit d462bd5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clang/lib/AST/Interp/ByteCodeStmtGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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: {
Expand Down Expand Up @@ -625,6 +627,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 {

Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeStmtGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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);

Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/Interp/if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ namespace InitDecl {
return false;
}
static_assert(!f2(), "");


constexpr int attrs() {
if (1) [[likely]] {}
return 1;
}
static_assert(attrs() == 1, "");
};

0 comments on commit d462bd5

Please sign in to comment.