[clang] d462bd5 - [clang][Interp] Handle AttributedStmts (#66495)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 12:03:22 PDT 2023


Author: Timm Baeder
Date: 2023-09-15T21:03:18+02:00
New Revision: d462bd527a6a351e513197f2b3814155adca960f

URL: https://github.com/llvm/llvm-project/commit/d462bd527a6a351e513197f2b3814155adca960f
DIFF: https://github.com/llvm/llvm-project/commit/d462bd527a6a351e513197f2b3814155adca960f.diff

LOG: [clang][Interp] Handle AttributedStmts (#66495)

Just ignore the attributes.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeStmtGen.cpp
    clang/lib/AST/Interp/ByteCodeStmtGen.h
    clang/test/AST/Interp/if.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 5beb5c3d22b4f64..22a6908daf8b3c2 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -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: {
@@ -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 {
 

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 5d48c0d27d245eb..31f9dbb8064c73c 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -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);
 

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, "");
 };


        


More information about the cfe-commits mailing list