[llvm-branch-commits] [clang] bead8bf - Merging r371548:
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 27 13:56:28 PST 2019
Author: Alexey Bataev
Date: 2019-11-27T13:36:23-08:00
New Revision: bead8bf31fb4a6bf02af67bd3029adb5dedf704f
URL: https://github.com/llvm/llvm-project/commit/bead8bf31fb4a6bf02af67bd3029adb5dedf704f
DIFF: https://github.com/llvm/llvm-project/commit/bead8bf31fb4a6bf02af67bd3029adb5dedf704f.diff
LOG: Merging r371548:
------------------------------------------------------------------------
r371548 | abataev | 2019-09-10 12:16:56 -0700 (Tue, 10 Sep 2019) | 10 lines
Fix for PR43175: compiler crash when trying to emit noncapturable
constant.
If the constexpr variable is partially initialized, the initializer can
be emitted as the structure, not as an array, because of some early
optimizations. The llvm variable gets the type from this constant and,
thus, gets the type which is pointer to struct rather than pointer to an
array. We need to convert this type to be truely array, otherwise it may
lead to the compiler crash when trying to emit array subscript
expression.
------------------------------------------------------------------------
Added:
clang/test/OpenMP/constexpr_partial_array.cpp
Modified:
clang/lib/CodeGen/CGExpr.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5a4b1188b711..b6c2567bd578 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2540,6 +2540,11 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
// Spill the constant value to a global.
Addr = CGM.createUnnamedGlobalFrom(*VD, Val,
getContext().getDeclAlign(VD));
+ llvm::Type *VarTy = getTypes().ConvertTypeForMem(VD->getType());
+ auto *PTy = llvm::PointerType::get(
+ VarTy, getContext().getTargetAddressSpace(VD->getType()));
+ if (PTy != Addr.getType())
+ Addr = Builder.CreatePointerBitCastOrAddrSpaceCast(Addr, PTy);
} else {
// Should we be using the alignment of the constant pointer we emitted?
CharUnits Alignment =
diff --git a/clang/test/OpenMP/constexpr_partial_array.cpp b/clang/test/OpenMP/constexpr_partial_array.cpp
new file mode 100644
index 000000000000..998d75edbb88
--- /dev/null
+++ b/clang/test/OpenMP/constexpr_partial_array.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -triple x86_64-pc-windows-msvc19.22.27905 -emit-llvm -o - -fopenmp %s | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: [[C_VAR_VAL:@.+]] = private unnamed_addr constant <{ i8, [26 x i8] }> <{ i8 1, [26 x i8] zeroinitializer }>,
+char a;
+bool b() {
+ static constexpr bool c[27]{1};
+ // CHECK: getelementptr inbounds [27 x i8], [27 x i8]* bitcast (<{ i8, [26 x i8] }>* [[C_VAR_VAL]] to [27 x i8]*),
+ return c[a];
+}
More information about the llvm-branch-commits
mailing list