https://github.com/amanmaurya92 updated https://github.com/llvm/llvm-project/pull/237420
>From 5a41f4cbece204ba22fa90b0e3cd4e8601535fbc Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Sat, 31 Oct 2026 03:58:58 +0530 Subject: [PATCH 1/6] [CIR] Support calling static member functions via instance in emitCXXMemberCallExpr When a member call expression targets a static method (e.g. obj.static_func()), emit the base object expression for side effects, retrieve the direct callee, and emit the call without passing a 'this' pointer. Fixes #237402 --- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 6 ++-- .../CIR/CodeGenCXX/static-member-call.cpp | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 clang/test/CIR/CodeGenCXX/static-member-call.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 2637266cf3feed..5764e14fd81223 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -2843,8 +2843,10 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce, const auto *md = cast<CXXMethodDecl>(me->getMemberDecl()); if (md->isStatic()) { - cgm.errorNYI(ce->getSourceRange(), "emitCXXMemberCallExpr: static method"); - return RValue::get(nullptr); + emitIgnoredExpr(me->getBase()); + CIRGenCallee callee = emitDirectCallee(md); + return emitCall(getContext().getPointerType(md->getType()), callee, ce, + returnValue); } bool hasQualifier = me->hasQualifier(); diff --git a/clang/test/CIR/CodeGenCXX/static-member-call.cpp b/clang/test/CIR/CodeGenCXX/static-member-call.cpp new file mode 100644 index 00000000000000..5dc5ffe7d252c0 --- /dev/null +++ b/clang/test/CIR/CodeGenCXX/static-member-call.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -disable-llvm-passes %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG + +struct S { + static int static_func(int a); +}; + +// CIR-LABEL: cir.func {{.*}} @_Z18test_instance_call1S +// OGCG-LABEL: define {{.*}} @_Z18test_instance_call1S +int test_instance_call(S s) { + // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> + // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i + // CIR: cir.return %[[RES]] : !s32i + + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) + // OGCG: ret i32 %[[CALL_OGCG]] + return s.static_func(42); +} + +// CIR-LABEL: cir.func {{.*}} @_Z15test_arrow_callP1S +// OGCG-LABEL: define {{.*}} @_Z15test_arrow_callP1S +int test_arrow_call(S *p) { + // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> + // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i + // CIR: cir.return %[[RES]] : !s32i + + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) + // OGCG: ret i32 %[[CALL_OGCG]] + return p->static_func(100); +} >From 6a2fb738ffaa18973f3b77c5cc424371c40420d0 Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Wed, 4 Nov 2026 03:22:43 +0530 Subject: [PATCH 2/6] [CIR] Add defensive parity comment in emitCXXMemberCallExpr and side-effect tests --- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 3 ++ .../CIR/CodeGenCXX/static-member-call.cpp | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 5764e14fd81223..078ddf1b95334f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -2842,6 +2842,9 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce, const auto *me = cast<MemberExpr>(callee); const auto *md = cast<CXXMethodDecl>(me->getMemberDecl()); + // Although Sema normally represents static method calls as ordinary + // CallExpr nodes, retain defensive handling here for parity with classic + // Clang (CGExprCXX.cpp:200) in case a CXXMemberCallExpr node is encountered. if (md->isStatic()) { emitIgnoredExpr(me->getBase()); CIRGenCallee callee = emitDirectCallee(md); diff --git a/clang/test/CIR/CodeGenCXX/static-member-call.cpp b/clang/test/CIR/CodeGenCXX/static-member-call.cpp index 5dc5ffe7d252c0..a6495c8974095d 100644 --- a/clang/test/CIR/CodeGenCXX/static-member-call.cpp +++ b/clang/test/CIR/CodeGenCXX/static-member-call.cpp @@ -7,6 +7,8 @@ struct S { static int static_func(int a); }; +S get_s(); + // CIR-LABEL: cir.func {{.*}} @_Z18test_instance_call1S // OGCG-LABEL: define {{.*}} @_Z18test_instance_call1S int test_instance_call(S s) { @@ -34,3 +36,33 @@ int test_arrow_call(S *p) { // OGCG: ret i32 %[[CALL_OGCG]] return p->static_func(100); } + +// Verify that the instance expression is evaluated for side effects: +// CIR-LABEL: cir.func {{.*}} @_Z16test_side_effectv +// OGCG-LABEL: define {{.*}} @_Z16test_side_effectv +int test_side_effect() { + // CIR: cir.call @_Z5get_sv() + // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.return %{{.*}} : !s32i + + // OGCG: call void @_Z5get_sv() + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) + // OGCG: ret i32 %[[CALL_OGCG]] + return get_s().static_func(42); +} + +// Verify that pointer expressions are evaluated for side effects: +// CIR-LABEL: cir.func {{.*}} @_Z20test_ptr_side_effectP1S +// OGCG-LABEL: define {{.*}} @_Z20test_ptr_side_effectP1S +int test_ptr_side_effect(S *p) { + // CIR: cir.ptr_stride + // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.return %{{.*}} : !s32i + + // OGCG: getelementptr + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) + // OGCG: ret i32 %[[CALL_OGCG]] + return (p++)->static_func(100); +} >From 6f008242a35041abcf271b84c0bb33afa01b4c14 Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Thu, 5 Nov 2026 22:47:31 +0530 Subject: [PATCH 3/6] [CIR] Remove static member call tests in favor of PR #239291 Remove the test file from this branch now that test coverage has been split into #239291, keeping this PR focused solely on the emitCXXMemberCallExpr defensive handling. --- .../CIR/CodeGenCXX/static-member-call.cpp | 68 ------------------- 1 file changed, 68 deletions(-) delete mode 100644 clang/test/CIR/CodeGenCXX/static-member-call.cpp diff --git a/clang/test/CIR/CodeGenCXX/static-member-call.cpp b/clang/test/CIR/CodeGenCXX/static-member-call.cpp deleted file mode 100644 index a6495c8974095d..00000000000000 --- a/clang/test/CIR/CodeGenCXX/static-member-call.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -disable-llvm-passes %s -o %t.ll -// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG - -struct S { - static int static_func(int a); -}; - -S get_s(); - -// CIR-LABEL: cir.func {{.*}} @_Z18test_instance_call1S -// OGCG-LABEL: define {{.*}} @_Z18test_instance_call1S -int test_instance_call(S s) { - // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> - // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i - // CIR: cir.return %[[RES]] : !s32i - - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) - // OGCG: ret i32 %[[CALL_OGCG]] - return s.static_func(42); -} - -// CIR-LABEL: cir.func {{.*}} @_Z15test_arrow_callP1S -// OGCG-LABEL: define {{.*}} @_Z15test_arrow_callP1S -int test_arrow_call(S *p) { - // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> - // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i - // CIR: cir.return %[[RES]] : !s32i - - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) - // OGCG: ret i32 %[[CALL_OGCG]] - return p->static_func(100); -} - -// Verify that the instance expression is evaluated for side effects: -// CIR-LABEL: cir.func {{.*}} @_Z16test_side_effectv -// OGCG-LABEL: define {{.*}} @_Z16test_side_effectv -int test_side_effect() { - // CIR: cir.call @_Z5get_sv() - // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.return %{{.*}} : !s32i - - // OGCG: call void @_Z5get_sv() - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) - // OGCG: ret i32 %[[CALL_OGCG]] - return get_s().static_func(42); -} - -// Verify that pointer expressions are evaluated for side effects: -// CIR-LABEL: cir.func {{.*}} @_Z20test_ptr_side_effectP1S -// OGCG-LABEL: define {{.*}} @_Z20test_ptr_side_effectP1S -int test_ptr_side_effect(S *p) { - // CIR: cir.ptr_stride - // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.return %{{.*}} : !s32i - - // OGCG: getelementptr - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) - // OGCG: ret i32 %[[CALL_OGCG]] - return (p++)->static_func(100); -} >From f43aea6964f29ee787fb593fc07e2c1d46341640 Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Mon, 9 Nov 2026 22:52:57 +0530 Subject: [PATCH 4/6] [CIR] Restore test coverage in static-member-call.cpp --- .../CIR/CodeGenCXX/static-member-call.cpp | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 clang/test/CIR/CodeGenCXX/static-member-call.cpp diff --git a/clang/test/CIR/CodeGenCXX/static-member-call.cpp b/clang/test/CIR/CodeGenCXX/static-member-call.cpp new file mode 100644 index 00000000000000..de9a81dd01b849 --- /dev/null +++ b/clang/test/CIR/CodeGenCXX/static-member-call.cpp @@ -0,0 +1,94 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -disable-llvm-passes %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG + +struct S { + static int static_func(int a); +}; + +S get_s(); + +// CIR-LABEL: cir.func {{.*}} @_Z18test_instance_call1S +// LLVM-LABEL: define {{.*}} @_Z18test_instance_call1S +// OGCG-LABEL: define {{.*}} @_Z18test_instance_call1S +int test_instance_call(S s) { + // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> + // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i + // CIR: cir.return %[[RES]] : !s32i + + // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}42) + // LLVM: ret i32 %{{.*}} + + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) + // OGCG: ret i32 %[[CALL_OGCG]] + return s.static_func(42); +} + +// CIR-LABEL: cir.func {{.*}} @_Z15test_arrow_callP1S +// LLVM-LABEL: define {{.*}} @_Z15test_arrow_callP1S +// OGCG-LABEL: define {{.*}} @_Z15test_arrow_callP1S +int test_arrow_call(S *p) { + // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> + // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i + // CIR: cir.return %[[RES]] : !s32i + + // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}100) + // LLVM: ret i32 %{{.*}} + + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) + // OGCG: ret i32 %[[CALL_OGCG]] + return p->static_func(100); +} + +// Verify that the instance expression is evaluated for side effects: +// CIR-LABEL: cir.func {{.*}} @_Z16test_side_effectv +// LLVM-LABEL: define {{.*}} @_Z16test_side_effectv +// OGCG-LABEL: define {{.*}} @_Z16test_side_effectv +int test_side_effect() { + // CIR: cir.call @_Z5get_sv() + // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.return %{{.*}} : !s32i + + // LLVM: call void @_Z5get_sv() + // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}42) + // LLVM: ret i32 %{{.*}} + + // OGCG: call void @_Z5get_sv() + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) + // OGCG: ret i32 %[[CALL_OGCG]] + return get_s().static_func(42); +} + +// Verify that pointer expressions are evaluated for side effects: +// CIR-LABEL: cir.func {{.*}} @_Z20test_ptr_side_effectP1S +// LLVM-LABEL: define {{.*}} @_Z20test_ptr_side_effectP1S +// OGCG-LABEL: define {{.*}} @_Z20test_ptr_side_effectP1S +int test_ptr_side_effect(S *p) { + // CIR: %[[P_ADDR:.*]] = cir.alloca "p" + // CIR: %[[P_INC:.*]] = cir.ptr_stride + // CIR: cir.store{{.*}} %[[P_INC]], %[[P_ADDR]] + // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i + // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) + // CIR: cir.return %{{.*}} : !s32i + + // LLVM: %[[P_ADDR:.*]] = alloca ptr + // LLVM: %[[P_INC:.*]] = getelementptr {{.*}} + // LLVM: store ptr %[[P_INC]], ptr %[[P_ADDR]] + // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}100) + // LLVM: ret i32 %{{.*}} + + // OGCG: %[[P_ADDR:.*]] = alloca ptr + // OGCG: %[[P_INC:.*]] = getelementptr inbounds {{.*}}%struct.S, ptr %{{.*}}, i32 1 + // OGCG: store ptr %[[P_INC]], ptr %[[P_ADDR]] + // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) + // OGCG: ret i32 %[[CALL_OGCG]] + return (p++)->static_func(100); +} >From 1ec74483e1c81697c4bace936657b9e6e6ced390 Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Wed, 11 Nov 2026 22:13:26 +0530 Subject: [PATCH 5/6] [CIR] Assert static member calls are unexpected in emitCXXMemberCallExpr --- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 13 +-- .../CIR/CodeGenCXX/static-member-call.cpp | 94 ------------------- 2 files changed, 4 insertions(+), 103 deletions(-) delete mode 100644 clang/test/CIR/CodeGenCXX/static-member-call.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 078ddf1b95334f..6694a379562d5d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -2842,15 +2842,10 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce, const auto *me = cast<MemberExpr>(callee); const auto *md = cast<CXXMethodDecl>(me->getMemberDecl()); - // Although Sema normally represents static method calls as ordinary - // CallExpr nodes, retain defensive handling here for parity with classic - // Clang (CGExprCXX.cpp:200) in case a CXXMemberCallExpr node is encountered. - if (md->isStatic()) { - emitIgnoredExpr(me->getBase()); - CIRGenCallee callee = emitDirectCallee(md); - return emitCall(getContext().getPointerType(md->getType()), callee, ce, - returnValue); - } + // Sema represents calls to static member functions as ordinary CallExpr + // nodes rather than CXXMemberCallExpr. + assert(!md->isStatic() && + "static member call is unexpected in emitCXXMemberCallExpr"); bool hasQualifier = me->hasQualifier(); NestedNameSpecifier qualifier = me->getQualifier(); diff --git a/clang/test/CIR/CodeGenCXX/static-member-call.cpp b/clang/test/CIR/CodeGenCXX/static-member-call.cpp deleted file mode 100644 index de9a81dd01b849..00000000000000 --- a/clang/test/CIR/CodeGenCXX/static-member-call.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll -// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm -disable-llvm-passes %s -o %t.ll -// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG - -struct S { - static int static_func(int a); -}; - -S get_s(); - -// CIR-LABEL: cir.func {{.*}} @_Z18test_instance_call1S -// LLVM-LABEL: define {{.*}} @_Z18test_instance_call1S -// OGCG-LABEL: define {{.*}} @_Z18test_instance_call1S -int test_instance_call(S s) { - // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> - // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i - // CIR: cir.return %[[RES]] : !s32i - - // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}42) - // LLVM: ret i32 %{{.*}} - - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) - // OGCG: ret i32 %[[CALL_OGCG]] - return s.static_func(42); -} - -// CIR-LABEL: cir.func {{.*}} @_Z15test_arrow_callP1S -// LLVM-LABEL: define {{.*}} @_Z15test_arrow_callP1S -// OGCG-LABEL: define {{.*}} @_Z15test_arrow_callP1S -int test_arrow_call(S *p) { - // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.store %[[CALL]], %[[RET:.*]] : !s32i, !cir.ptr<!s32i> - // CIR: %[[RES:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i - // CIR: cir.return %[[RES]] : !s32i - - // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}100) - // LLVM: ret i32 %{{.*}} - - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) - // OGCG: ret i32 %[[CALL_OGCG]] - return p->static_func(100); -} - -// Verify that the instance expression is evaluated for side effects: -// CIR-LABEL: cir.func {{.*}} @_Z16test_side_effectv -// LLVM-LABEL: define {{.*}} @_Z16test_side_effectv -// OGCG-LABEL: define {{.*}} @_Z16test_side_effectv -int test_side_effect() { - // CIR: cir.call @_Z5get_sv() - // CIR: %[[ARG:.*]] = cir.const #cir.int<42> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.return %{{.*}} : !s32i - - // LLVM: call void @_Z5get_sv() - // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}42) - // LLVM: ret i32 %{{.*}} - - // OGCG: call void @_Z5get_sv() - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 42) - // OGCG: ret i32 %[[CALL_OGCG]] - return get_s().static_func(42); -} - -// Verify that pointer expressions are evaluated for side effects: -// CIR-LABEL: cir.func {{.*}} @_Z20test_ptr_side_effectP1S -// LLVM-LABEL: define {{.*}} @_Z20test_ptr_side_effectP1S -// OGCG-LABEL: define {{.*}} @_Z20test_ptr_side_effectP1S -int test_ptr_side_effect(S *p) { - // CIR: %[[P_ADDR:.*]] = cir.alloca "p" - // CIR: %[[P_INC:.*]] = cir.ptr_stride - // CIR: cir.store{{.*}} %[[P_INC]], %[[P_ADDR]] - // CIR: %[[ARG:.*]] = cir.const #cir.int<100> : !s32i - // CIR: %[[CALL:.*]] = cir.call @_ZN1S11static_funcEi(%[[ARG]]) : (!s32i {{.*}}) -> (!s32i {{.*}}) - // CIR: cir.return %{{.*}} : !s32i - - // LLVM: %[[P_ADDR:.*]] = alloca ptr - // LLVM: %[[P_INC:.*]] = getelementptr {{.*}} - // LLVM: store ptr %[[P_INC]], ptr %[[P_ADDR]] - // LLVM: %[[CALL_LLVM:.*]] = call {{.*}}i32 @_ZN1S11static_funcEi(i32 {{.*}}100) - // LLVM: ret i32 %{{.*}} - - // OGCG: %[[P_ADDR:.*]] = alloca ptr - // OGCG: %[[P_INC:.*]] = getelementptr inbounds {{.*}}%struct.S, ptr %{{.*}}, i32 1 - // OGCG: store ptr %[[P_INC]], ptr %[[P_ADDR]] - // OGCG: %[[CALL_OGCG:.*]] = call noundef i32 @_ZN1S11static_funcEi(i32 noundef 100) - // OGCG: ret i32 %[[CALL_OGCG]] - return (p++)->static_func(100); -} >From 71dba36d701d95551b37c7604957f6c9b8e73aed Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Sat, 14 Nov 2026 14:42:00 +0530 Subject: [PATCH 6/6] [CIR][CodeGen] Assert static member calls are unexpected in EmitCXXMemberCallExpr In Clang AST, calls to static member functions are lowered by Sema into ordinary CallExpr nodes rather than CXXMemberCallExpr. Replace the defensive check in classic CodeGen (CGExprCXX.cpp) with an assertion, matching the assertion in CIRGenFunction::emitCXXMemberCallExpr. Assisted-by: Antigravity (Gemini 3.8 Flash) --- clang/lib/CodeGen/CGExprCXX.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 60bb27a6fab69d..fd76476a98e1c2 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -197,13 +197,10 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE, const MemberExpr *ME = cast<MemberExpr>(callee); const CXXMethodDecl *MD = cast<CXXMethodDecl>(ME->getMemberDecl()); - if (MD->isStatic()) { - // The method is static, emit it as we would a regular call. - CGCallee callee = - CGCallee::forDirect(CGM.GetAddrOfFunction(MD), GlobalDecl(MD)); - return EmitCall(getContext().getPointerType(MD->getType()), callee, CE, - ReturnValue, /*Chain=*/nullptr, CallOrInvoke); - } + // Sema represents calls to static member functions as ordinary CallExpr + // nodes rather than CXXMemberCallExpr. + assert(!MD->isStatic() && + "static member call is unexpected in EmitCXXMemberCallExpr"); bool HasQualifier = ME->hasQualifier(); NestedNameSpecifier Qualifier = ME->getQualifier(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
