From 598f1d56756deb759efd2f57cfb9e99afa737918 Mon Sep 17 00:00:00 2001 From: Kirill Yansitov <36601354+YazZz1k@users.noreply.github.com> Date: Wed, 31 Jan 2024 23:35:58 +0300 Subject: [PATCH] [CIR][CIRGen][Bugfix] Fix source location in ctors (#415) --- clang/lib/CIR/CodeGen/CIRGenDecl.cpp | 2 +- clang/test/CIR/CodeGen/ctor-srcloc-fix.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/CIR/CodeGen/ctor-srcloc-fix.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp index ce0c3c4cfa93..51533c2310bf 100644 --- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp @@ -657,8 +657,8 @@ void CIRGenFunction::buildNullabilityCheck(LValue LHS, mlir::Value RHS, void CIRGenFunction::buildScalarInit(const Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit) { // TODO: this is where a lot of ObjC lifetime stuff would be done. - mlir::Value value = buildScalarExpr(init); SourceLocRAIIObject Loc{*this, loc}; + mlir::Value value = buildScalarExpr(init); buildStoreThroughLValue(RValue::get(value), lvalue); return; } diff --git a/clang/test/CIR/CodeGen/ctor-srcloc-fix.cpp b/clang/test/CIR/CodeGen/ctor-srcloc-fix.cpp new file mode 100644 index 000000000000..7012344b8d77 --- /dev/null +++ b/clang/test/CIR/CodeGen/ctor-srcloc-fix.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir-enable -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +struct e { e(int); }; +e *g = new e(0); + +//CHECK: {{%.*}} = cir.const(#cir.int<1> : !u64i) : !u64i loc(#loc11) +//CHECK: {{%.*}} = cir.call @_Znwm(%1) : (!u64i) -> !cir.ptr loc(#loc6)