[OPENMP50]Do not imply lvalue as base expression in array shaping

expression.

We should not assume that the base expression in the array shaping
operation is an lvalue of some form, it may be an rvalue.
This commit is contained in:
Alexey Bataev 2020-03-30 16:28:59 -04:00
parent 2641ba52a9
commit a4f74f377b
3 changed files with 12 additions and 14 deletions

View File

@ -5364,14 +5364,12 @@ std::pair<llvm::Value *, Address> CGOpenMPRuntime::emitDependClause(
continue;
const Expr *E = Dependencies[I].second;
const auto *OASE = dyn_cast<OMPArrayShapingExpr>(E);
LValue Addr;
llvm::Value *Addr;
if (OASE) {
const Expr *Base = OASE->getBase()->IgnoreParenImpCasts();
Addr =
CGF.EmitLoadOfPointerLValue(CGF.EmitLValue(Base).getAddress(CGF),
Base->getType()->castAs<PointerType>());
const Expr *Base = OASE->getBase();
Addr = CGF.EmitScalarExpr(Base);
} else {
Addr = CGF.EmitLValue(E);
Addr = CGF.EmitLValue(E).getPointer(CGF);
}
llvm::Value *Size;
QualType Ty = E->getType();
@ -5390,8 +5388,7 @@ std::pair<llvm::Value *, Address> CGOpenMPRuntime::emitDependClause(
CGF.EmitOMPArraySectionExpr(ASE, /*IsLowerBound=*/false);
llvm::Value *UpAddr = CGF.Builder.CreateConstGEP1_32(
UpAddrLVal.getPointer(CGF), /*Idx0=*/1);
llvm::Value *LowIntPtr =
CGF.Builder.CreatePtrToInt(Addr.getPointer(CGF), CGM.SizeTy);
llvm::Value *LowIntPtr = CGF.Builder.CreatePtrToInt(Addr, CGM.SizeTy);
llvm::Value *UpIntPtr = CGF.Builder.CreatePtrToInt(UpAddr, CGM.SizeTy);
Size = CGF.Builder.CreateNUWSub(UpIntPtr, LowIntPtr);
} else {
@ -5410,9 +5407,8 @@ std::pair<llvm::Value *, Address> CGOpenMPRuntime::emitDependClause(
// deps[i].base_addr = &<Dependencies[i].second>;
LValue BaseAddrLVal = CGF.EmitLValueForField(
Base, *std::next(KmpDependInfoRD->field_begin(), BaseAddr));
CGF.EmitStoreOfScalar(
CGF.Builder.CreatePtrToInt(Addr.getPointer(CGF), CGF.IntPtrTy),
BaseAddrLVal);
CGF.EmitStoreOfScalar(CGF.Builder.CreatePtrToInt(Addr, CGF.IntPtrTy),
BaseAddrLVal);
// deps[i].len = sizeof(<Dependencies[i].second>);
LValue LenLVal = CGF.EmitLValueForField(
Base, *std::next(KmpDependInfoRD->field_begin(), Len));

View File

@ -4804,6 +4804,9 @@ ExprResult Sema::ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc,
ArrayRef<SourceRange> Brackets) {
if (Base->getType()->isPlaceholderType()) {
ExprResult Result = CheckPlaceholderExpr(Base);
if (Result.isInvalid())
return ExprError();
Result = DefaultLvalueConversion(Result.get());
if (Result.isInvalid())
return ExprError();
Base = Result.get();

View File

@ -56,7 +56,6 @@ int main() {
// CHECK: store i64 4, i64* [[SIZE_ADDR]],
// CHECK: [[FLAGS_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA0]], i{{.+}} 0, i{{.+}} 2
// CHECK: store i8 1, i8* [[FLAGS_ADDR]],
// CHECK: [[B_ADDR:%.+]] = load i32*, i32** %{{.+}},
// CHECK: [[A:%.+]] = load i32, i32* [[A_ADDR]],
// CHECK: [[A_CAST:%.+]] = sext i32 [[A]] to i64
// CHECK: [[SZ1:%.+]] = mul nuw i64 3, [[A_CAST]]
@ -65,7 +64,7 @@ int main() {
// CHECK: [[SZ:%.+]] = mul nuw i64 [[SZ1]], [[A_CAST]]
// CHECK: [[VLA1:%.+]] = getelementptr %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA]], i64 1
// CHECK: [[BASE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA1]], i{{.+}} 0, i{{.+}} 0
// CHECK: [[B_ADDR_CAST:%.+]] = ptrtoint i32* [[B_ADDR]] to i64
// CHECK: [[B_ADDR_CAST:%.+]] = ptrtoint i32** %{{.+}} to i64
// CHECK: store i64 [[B_ADDR_CAST]], i64* [[BASE_ADDR]],
// CHECK: [[SIZE_ADDR:%.+]] = getelementptr inbounds %struct.kmp_depend_info, %struct.kmp_depend_info* [[VLA1]], i{{.+}} 0, i{{.+}} 1
// CHECK: store i64 [[SZ]], i64* [[SIZE_ADDR]],
@ -85,7 +84,7 @@ int main() {
// CHECK: call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* @{{.+}}, i32 [[GTID]], i8* [[ALLOC]], i32 [[SIZE32]], i8* [[BC]], i32 0, i8* null)
// CHECK: [[SV:%.+]] = load i8*, i8** [[SV_ADDR]],
// CHECK: call void @llvm.stackrestore(i8* [[SV]])
#pragma omp task depend(in: a, ([3][a][a])b) depend(depobj: d, x) detach(evt)
#pragma omp task depend(in: a, ([3][a][a])&b) depend(depobj: d, x) detach(evt)
{
#pragma omp taskgroup
{