Fix assertion in tryEmitAsConstant

due to cd95338ee3

Need to check if result is LValue before getLValueBase.
This commit is contained in:
Yaxun (Sam) Liu 2020-12-02 18:35:52 -05:00
parent dcdd231df6
commit 3a781b912f
2 changed files with 10 additions and 1 deletions

View File

@ -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() &&

View File

@ -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