[clang] [clang][Interp] Handle AttributedStmts (PR #66495)

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang
            
<details>
<summary>Changes</summary>
Just ignore the attributes.
--
Full diff: https://github.com/llvm/llvm-project/pull/66495.diff

3 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeStmtGen.cpp (+8) 
- (modified) clang/lib/AST/Interp/ByteCodeStmtGen.h (+1) 
- (modified) clang/test/AST/Interp/if.cpp (+7) 


<pre>
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&lt;Emitter&gt;::visitStmt(const Stmt *S) {
   case Stmt::GCCAsmStmtClass:
   case Stmt::MSAsmStmtClass:
     return visitAsmStmt(cast&lt;AsmStmt&gt;(S));
+  case Stmt::AttributedStmtClass:
+    return visitAttributedStmt(cast&lt;AttributedStmt&gt;(S));
   case Stmt::NullStmtClass:
     return true;
   default: {
@@ -628,6 +630,12 @@ bool ByteCodeStmtGen&lt;Emitter&gt;::visitAsmStmt(const AsmStmt *S) {
   return this-&gt;emitInvalid(S);
 }
 
+template &lt;class Emitter&gt;
+bool ByteCodeStmtGen&lt;Emitter&gt;::visitAttributedStmt(const AttributedStmt *S) {
+  // Ignore all attributes.
+  return this-&gt;visitStmt(S-&gt;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&lt;Emitter&gt; {
   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(), &quot;&quot;);
+
+
+  constexpr int attrs() {
+    if (1) [[likely]] {}
+    return 1;
+  }
+  static_assert(attrs() == 1, &quot;&quot;);
 };
</pre>
</details>


https://github.com/llvm/llvm-project/pull/66495


More information about the cfe-commits mailing list