From d462bd527a6a351e513197f2b3814155adca960f Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Fri, 15 Sep 2023 21:03:18 +0200 Subject: [PATCH] [clang][Interp] Handle AttributedStmts (#66495) Just ignore the attributes. --- clang/lib/AST/Interp/ByteCodeStmtGen.cpp | 8 ++++++++ clang/lib/AST/Interp/ByteCodeStmtGen.h | 1 + clang/test/AST/Interp/if.cpp | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index 5beb5c3d22b4..22a6908daf8b 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -243,6 +243,8 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) { case Stmt::GCCAsmStmtClass: case Stmt::MSAsmStmtClass: return visitAsmStmt(cast(S)); + case Stmt::AttributedStmtClass: + return visitAttributedStmt(cast(S)); case Stmt::NullStmtClass: return true; default: { @@ -625,6 +627,12 @@ bool ByteCodeStmtGen::visitAsmStmt(const AsmStmt *S) { return this->emitInvalid(S); } +template +bool ByteCodeStmtGen::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 5d48c0d27d24..31f9dbb8064c 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.h +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h @@ -64,6 +64,7 @@ private: 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 2449ace4dd6c..86ae8de6f73e 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, ""); };