Skip to content
Draft
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
11 changes: 4 additions & 7 deletions clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2710,18 +2710,15 @@ LValue CIRGenFunction::emitLValue(const Expr *E) {
return emitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
case Expr::PredefinedExprClass:
return emitPredefinedLValue(cast<PredefinedExpr>(E));
case Expr::ImplicitCastExprClass:
case Expr::CStyleCastExprClass:
case Expr::CXXFunctionalCastExprClass:
case Expr::CXXStaticCastExprClass:
case Expr::CXXDynamicCastExprClass:
case Expr::CXXReinterpretCastExprClass:
case Expr::CXXConstCastExprClass:
case Expr::CXXAddrspaceCastExprClass:
case Expr::ObjCBridgedCastExprClass:
emitError(getLoc(E->getExprLoc()), "l-value not implemented for '")
<< E->getStmtClassName() << "'";
assert(0 && "Use emitCastLValue below, remove me when adding testcase");
case Expr::CStyleCastExprClass:
case Expr::CXXStaticCastExprClass:
case Expr::CXXDynamicCastExprClass:
case Expr::ImplicitCastExprClass:
return emitCastLValue(cast<CastExpr>(E));
case Expr::OpaqueValueExprClass:
return emitOpaqueValueLValue(cast<OpaqueValueExpr>(E));
Expand Down
47 changes: 47 additions & 0 deletions clang/test/CIR/CodeGen/cast-lvalue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.orig.ll
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.orig.ll %s
//
// Test for cast expressions as l-values (const_cast, reinterpret_cast, etc.)

void const_cast_lvalue() {
const int x = 0;
const_cast<int&>(x) = 1;
}

// CIR-LABEL: cir.func dso_local @_Z17const_cast_lvaluev
// CIR: %[[X:.*]] = cir.alloca !s32i, {{.*}}, ["x", init, const]
// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
// CIR: cir.store {{.*}} %[[ZERO]], %[[X]] : !s32i, !cir.ptr<!s32i>
// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s32i
// CIR: cir.store {{.*}} %[[ONE]], %[[X]] : !s32i, !cir.ptr<!s32i>
// CIR: cir.return

// LLVM-LABEL: define {{.*}}void @_Z17const_cast_lvaluev
// LLVM: %[[X:.*]] = alloca i32
// LLVM: store i32 0, ptr %[[X]]
// LLVM: store i32 1, ptr %[[X]]
// LLVM: ret void

void reinterpret_cast_lvalue() {
long x = 0;
reinterpret_cast<int&>(x) = 1;
}

// CIR-LABEL: cir.func dso_local @_Z23reinterpret_cast_lvaluev
// CIR: %[[X:.*]] = cir.alloca !s64i, {{.*}}, ["x", init]
// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
// CIR: cir.store {{.*}} %{{.*}}, %[[X]] : !s64i, !cir.ptr<!s64i>
// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s32i
// CIR: %[[CAST:.*]] = cir.cast bitcast %[[X]] : !cir.ptr<!s64i> -> !cir.ptr<!s32i>
// CIR: cir.store {{.*}} %[[ONE]], %[[CAST]] : !s32i, !cir.ptr<!s32i>
// CIR: cir.return

// LLVM-LABEL: define {{.*}}void @_Z23reinterpret_cast_lvaluev
// LLVM: %[[X:.*]] = alloca i64
// LLVM: store i64 0, ptr %[[X]]
// LLVM: store i32 1, ptr %[[X]]
// LLVM: ret void
10 changes: 0 additions & 10 deletions clang/test/CIR/crashes/const-cast-expr-lvalue.cpp

This file was deleted.

1 change: 0 additions & 1 deletion clang/test/CIR/crashes/const-cast-lvalue.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// XFAIL: *
//
// CXXConstCastExpr l-value emission not implemented
// Location: CIRGenExpr.cpp:2799
Expand Down