Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,10 +1045,22 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
llvm_unreachable("Invalid cast kind");
}

static DeclRefExpr *tryToConvertMemberExprToDeclRefExpr(CIRGenFunction &cgf,
const MemberExpr *me) {
if (auto *vd = dyn_cast<VarDecl>(me->getMemberDecl())) {
// Try to emit static variable member expressions as DREs.
return DeclRefExpr::Create(
cgf.getContext(), NestedNameSpecifierLoc(), SourceLocation(), vd,
/*RefersToEnclosingVariableOrCapture=*/false, me->getExprLoc(),
me->getType(), me->getValueKind(), nullptr, nullptr, me->isNonOdrUse());
}
return nullptr;
}

LValue CIRGenFunction::emitMemberExpr(const MemberExpr *e) {
if (isa<VarDecl>(e->getMemberDecl())) {
cgm.errorNYI(e->getSourceRange(), "emitMemberExpr: VarDecl");
return LValue();
if (DeclRefExpr *dre = tryToConvertMemberExprToDeclRefExpr(*this, e)) {
emitIgnoredExpr(e->getBase());
return emitDeclRefLValue(dre);
}

Expr *baseExpr = e->getBase();
Expand Down Expand Up @@ -2101,18 +2113,6 @@ CIRGenFunction::tryEmitAsConstant(const DeclRefExpr *refExpr) {
return ConstantEmission::forValue(cstToEmit);
}

static DeclRefExpr *tryToConvertMemberExprToDeclRefExpr(CIRGenFunction &cgf,
const MemberExpr *me) {
if (auto *vd = dyn_cast<VarDecl>(me->getMemberDecl())) {
// Try to emit static variable member expressions as DREs.
return DeclRefExpr::Create(
cgf.getContext(), NestedNameSpecifierLoc(), SourceLocation(), vd,
/*RefersToEnclosingVariableOrCapture=*/false, me->getExprLoc(),
me->getType(), me->getValueKind(), nullptr, nullptr, me->isNonOdrUse());
}
return nullptr;
}

CIRGenFunction::ConstantEmission
CIRGenFunction::tryEmitAsConstant(const MemberExpr *me) {
if (DeclRefExpr *dre = tryToConvertMemberExprToDeclRefExpr(*this, me))
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {

mlir::Value VisitMemberExpr(MemberExpr *me) {
if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(me)) {
cgf.cgm.errorNYI("VisitMemberExpr tryEmitAsConstant");
return {};
cgf.emitIgnoredExpr(me->getBase());
return emitConstant(constant, me);
}
return emitLoadOfLValue(me);
}
Expand Down
24 changes: 24 additions & 0 deletions clang/test/CIR/CodeGen/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,27 @@ void foo31() {
// OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[ELEM_PTR]], i32 0, i32 0
// OGCG: %[[REAL:.*]] = load i32, ptr %[[REAL_PTR]], align 4
// OGCG: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4

struct Container {
static int _Complex c;
};

void foo32() {
Container con;
int r = __real__ con.c;
}

// CIR: %[[REAL_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
// CIR: %[[ELEM_PTR:.*]] = cir.get_global @_ZN9Container1cE : !cir.ptr<!cir.complex<!s32i>>
// CIR: %[[ELEM:.*]] = cir.load{{.*}} %[[ELEM_PTR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
// CIR: %[[REAL:.*]] = cir.complex.real %[[ELEM]] : !cir.complex<!s32i> -> !s32i
// CIR: cir.store{{.*}} %[[REAL]], %[[REAL_ADDR]] : !s32i, !cir.ptr<!s32i>

// LLVM: %[[REAL_ADDR:.*]] = alloca i32, i64 1, align 4
// LLVM: %[[ELEM:.*]] = load { i32, i32 }, ptr @_ZN9Container1cE, align 4
// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %[[ELEM]], 0
// LLVM: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4

// OGCG: %[[REAL_ADDR:.*]] = alloca i32, align 4
// OGCG: %[[REAL:.*]] = load i32, ptr @_ZN9Container1cE, align 4
// OGCG: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4