llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

This happens in C when we subscript an expression of type void*, but there's 
nothing for us to do here. Just reject it early.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3) 
- (modified) clang/test/AST/ByteCode/builtin-object-size-codegen.c (+4) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index af076f90733df..31526327b9e44 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1780,6 +1780,9 @@ bool Compiler<Emitter>::VisitImplicitValueInitExpr(
 
 template <class Emitter>
 bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+  if (E->getType()->isVoidType())
+    return false;
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   const Expr *Index = E->getIdx();
diff --git a/clang/test/AST/ByteCode/builtin-object-size-codegen.c 
b/clang/test/AST/ByteCode/builtin-object-size-codegen.c
index c290385935ba4..6aa0485bd65ad 100644
--- a/clang/test/AST/ByteCode/builtin-object-size-codegen.c
+++ b/clang/test/AST/ByteCode/builtin-object-size-codegen.c
@@ -35,3 +35,7 @@
     // gi = ObjectSize2(&t[1].t[1]);
   }
 
+/// Used to crash due to the void-typed ArraySubscriptExpr.
+void foo(void *p) {
+  int i = __builtin_object_size(&p[2], 3);
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/179619
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to