[PATCH] D88236: [PR47636] Fix tryEmitPrivate to handle non-constantarraytypes
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 24 11:35:01 PDT 2020
erichkeane updated this revision to Diff 294121.
erichkeane marked an inline comment as done.
erichkeane added a comment.
@rjmccall Done!
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88236/new/
https://reviews.llvm.org/D88236
Files:
clang/lib/CodeGen/CGExprConstant.cpp
clang/test/CodeGenCXX/pr47636.cpp
Index: clang/test/CodeGenCXX/pr47636.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/pr47636.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-linux-pc %s | FileCheck %s
+int(&&intu_rvref)[] {1,2,3,4};
+// CHECK: @_ZGR10intu_rvref_ = internal global [4 x i32] [i32 1, i32 2, i32 3, i32 4]
+// CHECK: @intu_rvref = constant [4 x i32]* @_ZGR10intu_rvref_
+
+void foo() {
+ static const int(&&intu_rvref)[] {1,2,3,4};
+ // CHECK: @_ZZ3foovE10intu_rvref = internal constant [4 x i32]* @_ZGRZ3foovE10intu_rvref_
+ // CHECK: @_ZGRZ3foovE10intu_rvref_ = internal constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
+}
Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -2108,8 +2108,7 @@
case APValue::Union:
return ConstStructBuilder::BuildStruct(*this, Value, DestType);
case APValue::Array: {
- const ConstantArrayType *CAT =
- CGM.getContext().getAsConstantArrayType(DestType);
+ const ArrayType *ArrayTy = CGM.getContext().getAsArrayType(DestType);
unsigned NumElements = Value.getArraySize();
unsigned NumInitElts = Value.getArrayInitializedElts();
@@ -2117,7 +2116,7 @@
llvm::Constant *Filler = nullptr;
if (Value.hasArrayFiller()) {
Filler = tryEmitAbstractForMemory(Value.getArrayFiller(),
- CAT->getElementType());
+ ArrayTy->getElementType());
if (!Filler)
return nullptr;
}
@@ -2132,7 +2131,7 @@
llvm::Type *CommonElementType = nullptr;
for (unsigned I = 0; I < NumInitElts; ++I) {
llvm::Constant *C = tryEmitPrivateForMemory(
- Value.getArrayInitializedElt(I), CAT->getElementType());
+ Value.getArrayInitializedElt(I), ArrayTy->getElementType());
if (!C) return nullptr;
if (I == 0)
@@ -2144,11 +2143,10 @@
// This means that the array type is probably "IncompleteType" or some
// type that is not ConstantArray.
- if (CAT == nullptr && CommonElementType == nullptr && !NumInitElts) {
- const ArrayType *AT = CGM.getContext().getAsArrayType(DestType);
- CommonElementType = CGM.getTypes().ConvertType(AT->getElementType());
- llvm::ArrayType *AType = llvm::ArrayType::get(CommonElementType,
- NumElements);
+ if (!Filler && !NumInitElts) {
+ CommonElementType = CGM.getTypes().ConvertType(ArrayTy->getElementType());
+ llvm::ArrayType *AType =
+ llvm::ArrayType::get(CommonElementType, NumElements);
return llvm::ConstantAggregateZero::get(AType);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88236.294121.patch
Type: text/x-patch
Size: 2808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200924/87f7ec32/attachment.bin>
More information about the cfe-commits
mailing list