[llvm-branch-commits] [clang] 3a781b9 - Fix assertion in tryEmitAsConstant
Yaxun Liu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 2 16:15:21 PST 2020
Author: Yaxun (Sam) Liu
Date: 2020-12-02T19:10:01-05:00
New Revision: 3a781b912fc7b492a21fe52cc8ce6c9e5854a9ab
URL: https://github.com/llvm/llvm-project/commit/3a781b912fc7b492a21fe52cc8ce6c9e5854a9ab
DIFF: https://github.com/llvm/llvm-project/commit/3a781b912fc7b492a21fe52cc8ce6c9e5854a9ab.diff
LOG: Fix assertion in tryEmitAsConstant
due to cd95338ee3022bffd658e52cd3eb9419b4c218ca
Need to check if result is LValue before getLValueBase.
Added:
Modified:
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGenCUDA/lambda-reference-var.cu
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 92d0cba7a733..11914b6cd9fb 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1529,7 +1529,7 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {
// global variable as compile time constant, since the host variable is not
// accessible on device. The DRE of the captured reference variable has to be
// loaded from captures.
- if (CGM.getLangOpts().CUDAIsDevice &&
+ if (CGM.getLangOpts().CUDAIsDevice && result.Val.isLValue() &&
refExpr->refersToEnclosingVariableOrCapture()) {
auto *MD = dyn_cast_or_null<CXXMethodDecl>(CurCodeDecl);
if (MD && MD->getParent()->isLambda() &&
diff --git a/clang/test/CodeGenCUDA/lambda-reference-var.cu b/clang/test/CodeGenCUDA/lambda-reference-var.cu
index 6d7b343b3193..44b012956507 100644
--- a/clang/test/CodeGenCUDA/lambda-reference-var.cu
+++ b/clang/test/CodeGenCUDA/lambda-reference-var.cu
@@ -27,6 +27,15 @@ __device__ void dev_capture_dev_ref_by_copy(int *out) {
[=](){ *out = ref;}();
}
+// DEV-LABEL: @_ZZ28dev_capture_dev_rval_by_copyPiENKUlvE_clEv(
+// DEV: store i32 3
+__device__ void dev_capture_dev_rval_by_copy(int *out) {
+ constexpr int a = 1;
+ constexpr int b = 2;
+ constexpr int c = a + b;
+ [=](){ *out = c;}();
+}
+
// DEV-LABEL: @_ZZ26dev_capture_dev_ref_by_refPiENKUlvE_clEv(
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
More information about the llvm-branch-commits
mailing list