[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:04 PDT 2024
https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/106558
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`.
>From cd1a46fc5ec9f2b6fa13d1009fd049c7ecf8b1e5 Mon Sep 17 00:00:00 2001
From: yronglin <yronglin777 at gmail.com>
Date: Thu, 29 Aug 2024 21:47:24 +0800
Subject: [PATCH] [clang][bytecode] Fix the handling of address of a vector
Signed-off-by: yronglin <yronglin777 at gmail.com>
---
clang/lib/AST/ByteCode/Compiler.cpp | 4 ++--
clang/test/CodeGen/compound-literal.c | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
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; };
More information about the cfe-commits
mailing list