[clang] [clang][bytecode] Fix the handling of address of a vector (PR #106558)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 06:53:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (yronglin)
<details>
<summary>Changes</summary>
The PR https://github.com/llvm/llvm-project/pull/105996 broke taking the address of a vector:
compound-literal.c
```C
typedef int v4i32 __attribute((vector_size(16)));
v4i32 *y = &(v4i32){1,2,3,4};
```
That because the current interpreter handle vector unary operator as a fallback when the generic code path fail. but the new interpreter was not. we need to handle `UO_AddrOf` in `Compiler<Emitter>::VisitVectorUnaryOperator`.
---
Full diff: https://github.com/llvm/llvm-project/pull/106558.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2-2)
- (modified) clang/test/CodeGen/compound-literal.c (+1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 6a77323d939791..9bd77edb0a550f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5324,11 +5324,11 @@ bool Compiler<Emitter>::VisitVectorUnaryOperator(const UnaryOperator *E) {
auto UnaryOp = E->getOpcode();
if (UnaryOp != UO_Plus && UnaryOp != UO_Minus && UnaryOp != UO_LNot &&
- UnaryOp != UO_Not)
+ UnaryOp != UO_Not && UnaryOp != UO_AddrOf)
return this->emitInvalid(E);
// Nothing to do here.
- if (UnaryOp == UO_Plus)
+ if (UnaryOp == UO_Plus || UnaryOp == UO_AddrOf)
return this->delegate(SubExpr);
if (!Initializing) {
diff --git a/clang/test/CodeGen/compound-literal.c b/clang/test/CodeGen/compound-literal.c
index 5b3cebb7c6ae6a..5fe9594c0f954f 100644
--- a/clang/test/CodeGen/compound-literal.c
+++ b/clang/test/CodeGen/compound-literal.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fexperimental-new-constant-interpreter -emit-llvm %s -o - | FileCheck %s
// Capture the type and name so matching later is cleaner.
struct CompoundTy { int a; };
``````````
</details>
https://github.com/llvm/llvm-project/pull/106558
More information about the cfe-commits
mailing list