[clang] [CIR] Handle CK_UserDefinedConversion and related casts in emitCastLValue (PR #193611)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 23 10:52:44 PDT 2026


================
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -std=c++14 -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++14 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
+
+// Test that CK_UserDefinedConversion and CK_ConstructorConversion
+// are handled in emitCastLValue as pass-through to the sub-expression.
+
+struct Source {
+  int val;
+};
+
+struct Dest {
+  int val;
+  Dest(const Source &s) : val(s.val) {}
+};
+
+void takeRef(const Dest &d);
+
+void testConstructorConversion() {
+  Source s{42};
+  takeRef(s);
+}
+
+// CIR: cir.func {{.*}} @_Z25testConstructorConversionv
----------------
adams381 wrote:

Added a second test function exercising CK_UserDefinedConversion (`operator int()`), and added CHECK lines for both tests verifying the constructor/conversion calls and function calls are emitted correctly in CIR, LLVM, and OGCG.

https://github.com/llvm/llvm-project/pull/193611


More information about the cfe-commits mailing list