[clang] [clang][analyzer] Fix #embed crash (PR #107764)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 8 08:55:15 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nicolas van Kempen (nicovank)

<details>
<summary>Changes</summary>


Fix #<!-- -->107724.


---
Full diff: https://github.com/llvm/llvm-project/pull/107764.diff


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+1-4) 
- (added) clang/test/Analysis/embed.c (+9) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 315d85319a85a9..fdabba46992b08 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1938,6 +1938,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
     case Stmt::CXXRewrittenBinaryOperatorClass:
     case Stmt::RequiresExprClass:
     case Expr::CXXParenListInitExprClass:
+    case Stmt::EmbedExprClass:
       // Fall through.
 
     // Cases we intentionally don't evaluate, since they don't need
@@ -2440,10 +2441,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
       Bldr.addNodes(Dst);
       break;
     }
-
-    case Stmt::EmbedExprClass:
-      llvm::report_fatal_error("Support for EmbedExpr is not implemented.");
-      break;
   }
 }
 
diff --git a/clang/test/Analysis/embed.c b/clang/test/Analysis/embed.c
new file mode 100644
index 00000000000000..7201bb30386fb7
--- /dev/null
+++ b/clang/test/Analysis/embed.c
@@ -0,0 +1,9 @@
+// RUN: %clang_analyze_cc1 -std=c23 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+// expected-no-diagnostics
+
+int main() {
+    const unsigned char SelfBytes[] = {
+        #embed "embed.c"
+    };
+}

``````````

</details>


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


More information about the cfe-commits mailing list