llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Fixes #<!-- -->157428

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+3) 
- (added) clang/test/AST/ByteCode/builtins.c (+19) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index a0dcdace854b9..1739aa3e4c1d4 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -300,6 +300,9 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
   if (!CheckDummy(S, OpPC, StrPtr.block(), AK_Read))
     return false;
 
+  if (!StrPtr.getFieldDesc()->isPrimitiveArray())
+    return false;
+
   assert(StrPtr.getFieldDesc()->isPrimitiveArray());
   unsigned ElemSize = StrPtr.getFieldDesc()->getElemSize();
 
diff --git a/clang/test/AST/ByteCode/builtins.c 
b/clang/test/AST/ByteCode/builtins.c
new file mode 100644
index 0000000000000..a51260cd3431f
--- /dev/null
+++ b/clang/test/AST/ByteCode/builtins.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1                                         %s -verify=ref
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+extern __SIZE_TYPE__ strlen(const char *);
+
+struct str_t {
+  char s1[sizeof("a")];
+};
+static const struct str_t str1 = {"a"};
+#define str ((const char *)&str1)
+int structStrlen(void) {
+  if (strlen(str) == 1)
+    return 0;
+  return 1;
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/157494
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to