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

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 02:12:11 PDT 2024


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

>From a43b9b74ac253c0072498007cf56ed57d8255143 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen <nvankemp at gmail.com>
Date: Sun, 8 Sep 2024 11:52:28 -0400
Subject: [PATCH 1/2] [clang][analyzer] Fix #embed crash

Fix #107724.
---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 5 +----
 clang/test/Analysis/embed.c                  | 9 +++++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Analysis/embed.c

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"
+    };
+}

>From 21b1ed8c9f6680540c3520c06efc04917b74611f Mon Sep 17 00:00:00 2001
From: Balazs Benics <benicsbalazs at gmail.com>
Date: Mon, 9 Sep 2024 11:12:04 +0200
Subject: [PATCH 2/2] Update clang/test/Analysis/embed.c

---
 clang/test/Analysis/embed.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/Analysis/embed.c b/clang/test/Analysis/embed.c
index 7201bb30386fb7..32f6c130325740 100644
--- a/clang/test/Analysis/embed.c
+++ b/clang/test/Analysis/embed.c
@@ -1,9 +1,12 @@
 // RUN: %clang_analyze_cc1 -std=c23 -analyzer-checker=core,debug.ExprInspection -verify %s
 
-// expected-no-diagnostics
+void clang_analyzer_dump_ptr(const unsigned char *ptr);
+void clang_analyzer_dump(unsigned char val);
 
 int main() {
     const unsigned char SelfBytes[] = {
         #embed "embed.c"
     };
+    clang_analyzer_dump_ptr(SelfBytes); // expected-warning {{&Element{SelfBytes,0 S64b,unsigned char}}}
+    clang_analyzer_dump(SelfBytes[0]); // expected-warning {{Unknown}} FIXME: This should be the `/` character.
 }



More information about the cfe-commits mailing list