Skip to content

Commit

Permalink
Fix assertion in tryEmitAsConstant
Browse files Browse the repository at this point in the history
due to cd95338

Need to check if result is LValue before getLValueBase.
  • Loading branch information
yxsamliu committed Dec 3, 2020
1 parent dcdd231 commit 3a781b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Expand Up @@ -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() &&
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGenCUDA/lambda-reference-var.cu
Expand Up @@ -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
Expand Down

0 comments on commit 3a781b9

Please sign in to comment.