[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-05-04 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

See also the response from the Clang Area Team: 
https://discourse.llvm.org/t/rfc-implement-gcc-bound-pmf-in-clang/85951/7.


https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-05-04 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw closed 
https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-22 Thread Zhihao Yuan via cfe-commits

lichray wrote:

> Perhaps we could provide a builtin function that takes an object pointer and 
> a pointer-to-member-function and returns a devirtualized 
> pointer-to-member-function (or returns the original PMF if it wasn't a 
> pointer to a virtual function)? Unlike the GCC extension, that kind of 
> interface can actually work in general.

I suggest viewing the demands at the same time and taking a leveled approach:

1. invoking base implementation via a handle
2. saving a snapshot of a pending virtual call (delegate)
3. resolve virtual call on one object, apply the results on other objects

Each level is less safe than the previous one. 1 slightly troubles Liskov 
substitution, 2 doesn't work before the object establishes the runtime type 
[(in a 
constructor)](https://discourse.llvm.org/t/rfc-implement-gcc-bound-pmf-in-clang/85951/5?u=lichray),
 and 3 can apply the call to objects without such a runtime type.

1 is addressed by [p2825](https://wg21.link/p2825).

C++26 `std::function_ref` (with `nontype`) can address 2 at the cost of a 
thunk, usually optimized by sibling call optimization, and safe to use, but you 
can argue that "simply" assigning from the bit pattern of a C++Builder 
`__closure` object may just be what user wants.

The dynamic portion of GCC's bound method can address 3, but the feature can 
also be deemed a building block of `__closure`.

Imagine that you can evaluate `p->mem_fn`, literally a pending virtual call, 
and get a struct of two members, this will allow the use of structured binding:

```cpp
auto [bpf, pobj] = p->mem_fn;
```

Then, to fulfill 3, we only need a way to package the components back into such 
a struct to substitute the `pobj` with a pointer to a different object:

```cpp
auto rebound_method = decltype(p->mem_fn){ bpf, pother };
rebound_method();
```

This option is explored by C folks in 
[n2862](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2862.pdf). In which 
paper, the rebinding procedure is done by the `wide_set_context` API.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-22 Thread Zhihao Yuan via cfe-commits

lichray wrote:

> > We used this extension to improve virtual function calling performance, 
> > there are simple and small virtual functions which are frequently called 
> > and can not be eliminated and it is in a delegation thus compiler can not 
> > optimize. [...]
> 
> Can `declcall` (https://wg21.link/p2825) be used for this? It is on track for 
> C++26.

Not according to the design as of R5, because the operand of `declcall` is an 
unevaluated operand, hence it will not walk into `this` value to find the entry 
in the actual vtable. Devirtualized pointer in p2825r5 can only be obtained 
when _qualified-id_ is involved.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-22 Thread Richard Smith via cfe-commits

zygoloid wrote:

> We don't know which function is called until the object `p` is provided. See 
> case 2 in 
> https://discourse.llvm.org/t/rfc-implement-gcc-bound-pmf-in-clang/85951.

Perhaps we could provide a builtin function that takes an object pointer and a 
pointer-to-member-function and returns a devirtualized 
pointer-to-member-function (or returns the original PMF if it wasn't a pointer 
to a virtual function)? Unlike the GCC extension, that kind of interface can 
actually work in general.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Sirui Mu via cfe-commits


@@ -0,0 +1,105 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --version 5
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wno-pmf-conversions %s -O3 
-emit-llvm -o - | FileCheck %s
+
+struct A {
+  int data;
+//.
+// CHECK: @method = local_unnamed_addr global ptr @_ZN1A6methodEv, align 8
+//.
+// CHECK-LABEL: define linkonce_odr noundef i32 @_ZN1A6methodEv(
+// CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(12) [[THIS:%.*]]) 
#[[ATTR0:[0-9]+]] comdat align 2 {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:ret i32 0
+//
+  int method() { return 0; }
+  virtual int virtual_method() { return 1; }
+  virtual ~A() = default;
+};
+
+struct C {
+  int data;
+};
+
+struct B : C, A {
+  virtual int virtual_method() override { return 2; }
+};
+
+using pmf_type = int (A::*)();
+using pf_type = int (*)(A*);
+
+pf_type method = reinterpret_cast(&A::method);
+
+// CHECK-LABEL: define dso_local noundef ptr @_Z11convert_pmfP1AMS_FivE(
+// CHECK-SAME: ptr noundef readonly captures(none) [[P:%.*]], i64 
[[METHOD_COERCE0:%.*]], i64 [[METHOD_COERCE1:%.*]]) local_unnamed_addr 
#[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[TMP0:%.*]] = and i64 [[METHOD_COERCE0]], 1
+// CHECK-NEXT:[[MEMPTR_ISVIRTUAL_NOT:%.*]] = icmp eq i64 [[TMP0]], 0
+// CHECK-NEXT:br i1 [[MEMPTR_ISVIRTUAL_NOT]], label 
%[[MEMPTR_NONVIRTUAL:.*]], label %[[MEMPTR_VIRTUAL:.*]]
+// CHECK:   [[MEMPTR_VIRTUAL]]:
+// CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 
[[METHOD_COERCE1]]
+// CHECK-NEXT:[[VTABLE:%.*]] = load ptr, ptr [[TMP1]], align 8, !tbaa 
[[TBAA2:![0-9]+]]
+// CHECK-NEXT:[[TMP2:%.*]] = getelementptr i8, ptr [[VTABLE]], i64 
[[METHOD_COERCE0]]
+// CHECK-NEXT:[[TMP3:%.*]] = getelementptr i8, ptr [[TMP2]], i64 -1
+// CHECK-NEXT:[[MEMPTR_VIRTUALFN:%.*]] = load ptr, ptr [[TMP3]], align 8, 
!nosanitize [[META5:![0-9]+]]
+// CHECK-NEXT:br label %[[MEMPTR_END:.*]]
+// CHECK:   [[MEMPTR_NONVIRTUAL]]:
+// CHECK-NEXT:[[MEMPTR_NONVIRTUALFN:%.*]] = inttoptr i64 
[[METHOD_COERCE0]] to ptr
+// CHECK-NEXT:br label %[[MEMPTR_END]]

Lancern wrote:

Seems like the non-virtual path does not take into account the offset in the 
pmf, and unfortunately this is also what gcc is doing. Although this PR is 
primarily for the virtual path, the erroneous non-virtual path could really 
cause problems very easily.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> > IIRC this feature is orthogonal to GCC bound member functions. `declcall` 
> > with a virtual method just returns a pmf, and we still need to perform 
> > vtable lookup at the callsite: https://compiler-explorer.com/z/YrT3nPTEz
> 
> Try `declcall(p->B::virtual_method())`?: 
> https://compiler-explorer.com/z/7d9KPE8zK

We don't know which function is called until the object `p` is provided.
See case 2 in 
https://discourse.llvm.org/t/rfc-implement-gcc-bound-pmf-in-clang/85951.


https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread via cfe-commits

rockeet wrote:

> > Yes, I'm very eager for this feature, let me investigate the RFC proposal 
> > routine.
> 
> I would recommend you also include details about how the extension meets our 
> [usual criteria](https://clang.llvm.org/get_involved.html#criteria) when you 
> write the RFC.

Thank you for your information, I'm new to llvm project, I've written the 
[[RFC] Implement gcc Bound PMF in clang 
](https://discourse.llvm.org/t/rfc-implement-gcc-pmf-in-clang/85951).

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Hubert Tong via cfe-commits

hubert-reinterpretcast wrote:

> IIRC this feature is orthogonal to GCC bound member functions. `declcall` 
> with a virtual method just returns a pmf, and we still need to perform vtable 
> lookup at the callsite: https://compiler-explorer.com/z/YrT3nPTEz

Try `declcall(p->B::virtual_method())`?: 
https://compiler-explorer.com/z/7d9KPE8zK

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> > We used this extension to improve virtual function calling performance, 
> > there are simple and small virtual functions which are frequently called 
> > and can not be eliminated and it is in a delegation thus compiler can not 
> > optimize.
> > [toplingdb](https://github.com/topling/toplingdb) and 
> > [topling-zip](https://github.com/topling/topling-zip) used pmf to pre-bind 
> > the functions in several places, like this:
> 
> Can `declcall` (https://wg21.link/p2825) be used for this? It is on track for 
> C++26.

IIRC this feature is orthogonal to GCC bound member functions. `declcall` with 
a virtual method just returns a pmf, and we still need to perform vtable lookup 
at the callsite: https://compiler-explorer.com/z/YrT3nPTEz


https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Richard Smith via cfe-commits

zygoloid wrote:

> Not sure if anyone has mentioned this elsewhere, but there's a significant 
> problem with the type of the returned function pointer: a normal function 
> pointer doesn't necessarily have the correct calling convention. In practice, 
> this is likely to cause problems on Windows.

The GCC extension [is also broken if a `this` adjustment is 
needed](https://godbolt.org/z/Ma8GGhK7n), even when the calling convention 
happens to line up. (And it's not possible to detect this problem locally -- it 
can happen even if [there is no multiple inheritance visible at the point where 
the extension is used](https://godbolt.org/z/GGExc1W8b).)

`declcall` doesn't have these problems and seems like a more robust way 
forward. (It does introduce *some* unnecessary overhead still, though, such as 
branching on whether the pointer-to-member is for a virtual function and 
emitting dead code for a virtual call; maybe we could consider some mechanism 
to declaratively state that a pointer-to-member type is known to not be a 
virtual pointer if we really care about that.)

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Hubert Tong via cfe-commits

hubert-reinterpretcast wrote:

> We used this extension to improve virtual function calling performance, there 
> are simple and small virtual functions which are frequently called and can 
> not be eliminated and it is in a delegation thus compiler can not optimize.
> 
> [toplingdb](https://github.com/topling/toplingdb) and 
> [topling-zip](https://github.com/topling/topling-zip) used pmf to pre-bind 
> the functions in several places, like this:

Can `declcall` (https://wg21.link/p2825) be used for this? It is on track for 
C++26.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Not sure if anyone has mentioned this elsewhere, but there's a significant 
problem with the type of the returned function pointer: a normal function 
pointer doesn't necessarily have the correct calling convention.  In practice, 
this is likely to cause problems on Windows.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-21 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Yes, I'm very eager for this feature, let me investigate the RFC proposal 
> routine.

I would recommend you also include details about how the extension meets our 
[usual criteria](https://clang.llvm.org/get_involved.html#criteria) when you 
write the RFC.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-18 Thread via cfe-commits

rockeet wrote:

> > > This patch adds support for GCC bound member functions extension: 
> > > https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html
> > > Related issue: #22495 Closes #82727
> > 
> > 
> > I think this requires an RFC justifying carrying the extension. It's a 
> > non-conforming extension that we previously decided we would not implement 
> > (#22495 was closed as `WONTFIX`), and there's no real motivation for the 
> > feature request listed in #82727.
> > (Personally, I think #82727 should be closed as a duplicate of #22495 
> > unless there's a very strong justification for carrying the extension.)
> 
> #82727 was filed because this extension is used by topling-zip: 
> https://github.com/topling/topling-zip/blob/4c57da837bf1a1612a1524ddf8d258a69f1c3874/src/terark/zbs/blob_store.hpp#L56-L68
> 
> I decided to implement this feature after I read the post by @rockeet 
> :https://zhuanlan.zhihu.com/p/683534962 (in Chinese). TBH I don't think this 
> feature is useful as modern compilers should be smart enough to optimize out 
> redundant vtable lookups.
> 
> cc @rockeet Are you willing to propose an RFC in https://discourse.llvm.org/ 
> to demonstrate its real-world usefulness in ToplingDB?

Yes, I'm very eager for this feature, let me investigate the RFC proposal 
routine.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-18 Thread via cfe-commits

rockeet wrote:

We used this extension to improve virtual function calling performance, there 
are simple and small virtual functions which are frequently called and can not 
be eliminated and it is in a delegation thus compiler can not optimize, so we 
use pmf to bound the virtual function, like this:
```c++
#if defined(_MSC_VER) || defined(__clang__)
  #define IF_BOUND_PMF(Then, Else) Else
#else
  #define IF_BOUND_PMF(Then, Else) Then
#endif
  void SetSubReader(const ToplingZipSubReader* sub) {
subReader_ = sub;
iter_ = sub->index_->NewIterator();
store_ = sub->store_.get();
get_record_append_ = store_->m_get_record_append_CacheOffsets;
   #if defined(_MSC_VER) || defined(__clang__)
   #else
iter_next_ = (IterScanFN)(iter_->*(&COIndex::Iterator::Next));
iter_prev_ = (IterScanFN)(iter_->*(&COIndex::Iterator::Prev));
   #endif
tag_rs_kind_ = sub->tag_rs_kind_;
  }

  inline bool IndexIterInvokeNext() {
return IF_BOUND_PMF(iter_next_(iter_), iter_->Next());
  }
  inline bool IndexIterInvokePrev() {
return IF_BOUND_PMF(iter_prev_(iter_), iter_->Prev());
  }
```
In which `iter_->Next()` is a small virtual function for different index type, 
we save the pmf as a member, thus reduced the virtual function calling overhead.


https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-18 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I am going to chime in, in support of both Aaron's and Erich's position here. 
This does not seem like an extension we want to support.

So given the objections, we need at minimum an RFC and see how that goes. Maybe 
during that discussion a more compelling case can be made.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Erich Keane via cfe-commits

erichkeane wrote:

I too don't think this is an extension that we really want.  It is a pretty 
awful extension that does some pretty awful things to the language (and isn't 
implemented in a way that 'works right' in GCC anyway).  Unless there is a 
REALLY important workload that we absolutely need to compile, I'd prefer we 
don't.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> > This patch adds support for GCC bound member functions extension: 
> > https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html
> > Related issue: #22495 Closes #82727
> 
> I think this requires an RFC justifying carrying the extension. It's a 
> non-conforming extension that we previously decided we would not implement 
> (#22495 was closed as `WONTFIX`), and there's no real motivation for the 
> feature request listed in #82727.
> 
> (Personally, I think #82727 should be closed as a duplicate of #22495 unless 
> there's a very strong justification for carrying the extension.)

#82727 was filed because this extension is used by topling-zip: 
https://github.com/topling/topling-zip/blob/4c57da837bf1a1612a1524ddf8d258a69f1c3874/src/terark/zbs/blob_store.hpp#L56-L68

I decided to implement this feature after I read the post by @rockeet 
:https://zhuanlan.zhihu.com/p/683534962 (in Chinese). TBH I don't think this 
feature is useful as modern compilers should be smart enough to optimize out 
redundant vtable lookups.

cc @rockeet Are you willing to propose an RFC in https://discourse.llvm.org/ to 
demonstrate its real-world usefulness in ToplingDB?




https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman requested changes to this pull request.

> This patch adds support for GCC bound member functions extension: 
> https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html
> 
> Related issue: #22495 Closes #82727

I think this requires an RFC justifying carrying the extension. It's a 
non-conforming extension that we previously decided we would not implement 
(#22495 was closed as `WONTFIX`), and there's no real motivation for the 
feature request listed in #82727.

(Personally, I think #82727 should be closed as a duplicate of #22495 unless 
there's a very strong justification for carrying the extension.)

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw edited 
https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Yingwei Zheng via cfe-commits


@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only %s -verify

dtcxzyw wrote:

For reference: https://godbolt.org/z/Mf719b3en


https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch adds support for GCC bound member functions extension: 
https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html

Closes https://github.com/llvm/llvm-project/issues/82727

---

Patch is 29.68 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/135649.diff


19 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/include/clang/AST/OperationKinds.def (+4) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+16-16) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+1) 
- (modified) clang/lib/AST/Expr.cpp (+7) 
- (modified) clang/lib/AST/ExprConstant.cpp (+2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+2) 
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+32) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+20-2) 
- (modified) clang/lib/Edit/RewriteObjCFoundationAPI.cpp (+1) 
- (modified) clang/lib/Sema/SemaCast.cpp (+40-20) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+2-1) 
- (added) clang/test/CodeGenCXX/pmf-conversions.cpp (+105) 
- (added) clang/test/SemaCXX/pmf-conversions.cpp (+54) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5af4c08f64cd8..768497712ecd6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,11 @@ C++ Language Changes
   asm((std::string_view("nop")) ::: (std::string_view("memory")));
 }
 
+- Implemented `GCC bound member functions extension 
`_ for Itanium 
ABI.
+  This extension allows extracting the function pointer from a bound pointer 
to member function.
+  It is useful to save vtable lookups when the same member function is 
executed multiple times inside a loop.
+  When using this extension, a warning is emitted unless 
``-Wno-pmf-conversions`` is passed.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-   

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch adds support for GCC bound member functions extension: 
https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html

Closes https://github.com/llvm/llvm-project/issues/82727

---

Patch is 29.68 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/135649.diff


19 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/include/clang/AST/OperationKinds.def (+4) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+16-16) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+1) 
- (modified) clang/lib/AST/Expr.cpp (+7) 
- (modified) clang/lib/AST/ExprConstant.cpp (+2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+2) 
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+32) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+20-2) 
- (modified) clang/lib/Edit/RewriteObjCFoundationAPI.cpp (+1) 
- (modified) clang/lib/Sema/SemaCast.cpp (+40-20) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+2-1) 
- (added) clang/test/CodeGenCXX/pmf-conversions.cpp (+105) 
- (added) clang/test/SemaCXX/pmf-conversions.cpp (+54) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5af4c08f64cd8..768497712ecd6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,11 @@ C++ Language Changes
   asm((std::string_view("nop")) ::: (std::string_view("memory")));
 }
 
+- Implemented `GCC bound member functions extension 
`_ for Itanium 
ABI.
+  This extension allows extracting the function pointer from a bound pointer 
to member function.
+  It is useful to save vtable lookups when the same member function is 
executed multiple times inside a loop.
+  When using this extension, a warning is emitted unless 
``-Wno-pmf-conversions`` is passed.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch adds support for GCC bound member functions extension: 
https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html

Closes https://github.com/llvm/llvm-project/issues/82727

---

Patch is 29.68 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/135649.diff


19 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/include/clang/AST/OperationKinds.def (+4) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+16-16) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+1) 
- (modified) clang/lib/AST/Expr.cpp (+7) 
- (modified) clang/lib/AST/ExprConstant.cpp (+2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+2) 
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+1) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+32) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+20-2) 
- (modified) clang/lib/Edit/RewriteObjCFoundationAPI.cpp (+1) 
- (modified) clang/lib/Sema/SemaCast.cpp (+40-20) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+2-1) 
- (added) clang/test/CodeGenCXX/pmf-conversions.cpp (+105) 
- (added) clang/test/SemaCXX/pmf-conversions.cpp (+54) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5af4c08f64cd8..768497712ecd6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,11 @@ C++ Language Changes
   asm((std::string_view("nop")) ::: (std::string_view("memory")));
 }
 
+- Implemented `GCC bound member functions extension 
`_ for Itanium 
ABI.
+  This extension allows extracting the function pointer from a bound pointer 
to member function.
+  It is useful to save vtable lookups when the same member function is 
executed multiple times inside a loop.
+  When using this extension, a warning is emitted unless 
``-Wno-pmf-conversions`` is passed.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
- 

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw ready_for_review 
https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-16 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 24ed3a2a46bf6aef3678a474eb4babd65baf551a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Wed, 16 Apr 2025 00:13:34 +0800
Subject: [PATCH] [Clang] Add support for GCC bound member functions extension

---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/OperationKinds.def|   4 +
 clang/include/clang/Basic/DiagnosticGroups.td |  32 +++---
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |   1 +
 clang/lib/AST/Expr.cpp|   7 ++
 clang/lib/AST/ExprConstant.cpp|   2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |   2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |   1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  32 ++
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  22 +++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |   1 +
 clang/lib/Sema/SemaCast.cpp   |  60 ++
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   3 +-
 clang/test/CodeGenCXX/pmf-conversions.cpp | 105 ++
 clang/test/SemaCXX/pmf-conversions.cpp|  54 +
 19 files changed, 299 insertions(+), 39 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pmf-conversions.cpp
 create mode 100644 clang/test/SemaCXX/pmf-conversions.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5af4c08f64cd8..768497712ecd6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,11 @@ C++ Language Changes
   asm((std::string_view("nop")) ::: (std::string_view("memory")));
 }
 
+- Implemented `GCC bound member functions extension 
`_ for Itanium 
ABI.
+  This extension allows extracting the function pointer from a bound pointer 
to member function.
+  It is useful to save vtable lookups when the same member function is 
executed multiple times inside a loop.
+  When using this extension, a warning is emitted unless 
``-Wno-pmf-conversions`` is passed.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSize

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 43c487cd6206a215542a7711b1e2b5c48e4d4ecb Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Wed, 16 Apr 2025 00:13:34 +0800
Subject: [PATCH] [Clang] Add support for GCC bound member functions extension

---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/OperationKinds.def|   4 +
 clang/include/clang/Basic/DiagnosticGroups.td |  32 +++---
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |   1 +
 clang/lib/AST/Expr.cpp|   7 ++
 clang/lib/AST/ExprConstant.cpp|   2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |   2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |   1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  32 ++
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  22 +++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |   1 +
 clang/lib/Sema/SemaCast.cpp   |  60 ++
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   3 +-
 clang/test/CodeGenCXX/pmf-conversions.cpp | 105 ++
 clang/test/SemaCXX/pmf-conversions.cpp|  54 +
 19 files changed, 299 insertions(+), 39 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pmf-conversions.cpp
 create mode 100644 clang/test/SemaCXX/pmf-conversions.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 304d9ac3d8ab5..b3408d263335e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -93,6 +93,11 @@ C++ Language Changes
   asm((std::string_view("nop")) ::: (std::string_view("memory")));
 }
 
+- Implemented `GCC bound member functions extension 
`_.
+  This extension allows extracting the function pointer from a bound pointer 
to member function.
+  It is useful to save vtable lookups when the same member function is 
executed multiple times inside a loop.
+  When using this extension, a warning is emitted unless 
``-Wno-pmf-conversions`` is passed.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, Ze

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw edited 
https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 445c08bcb007f157f6c66c5fabb01c2aa88b3a89 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 22:58:44 +0800
Subject: [PATCH 1/2] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|   4 +
 clang/include/clang/Basic/DiagnosticGroups.td |  32 +++---
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |   1 +
 clang/lib/AST/Expr.cpp|   7 ++
 clang/lib/AST/ExprConstant.cpp|   2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |   2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |   1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  32 ++
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  22 +++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |   1 +
 clang/lib/Sema/SemaCast.cpp   |  31 --
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   3 +-
 clang/test/CodeGenCXX/pmf-conversions.cpp | 105 ++
 clang/test/SemaCXX/pmf-conversions.cpp|  50 +
 18 files changed, 271 insertions(+), 29 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pmf-conversions.cpp
 create mode 100644 clang/test/SemaCXX/pmf-conversions.cpp

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloa

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/4] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 445c08bcb007f157f6c66c5fabb01c2aa88b3a89 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 22:58:44 +0800
Subject: [PATCH] [Clang] Add support for GCC bound member functions extension

---
 clang/include/clang/AST/OperationKinds.def|   4 +
 clang/include/clang/Basic/DiagnosticGroups.td |  32 +++---
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |   1 +
 clang/lib/AST/Expr.cpp|   7 ++
 clang/lib/AST/ExprConstant.cpp|   2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExpr.cpp  |   1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |   2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |   1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  32 ++
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  22 +++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |   1 +
 clang/lib/Sema/SemaCast.cpp   |  31 --
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   3 +-
 clang/test/CodeGenCXX/pmf-conversions.cpp | 105 ++
 clang/test/SemaCXX/pmf-conversions.cpp|  50 +
 18 files changed, 271 insertions(+), 29 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pmf-conversions.cpp
 create mode 100644 clang/test/SemaCXX/pmf-conversions.cpp

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/7] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/6] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-15 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/5] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/3] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH 1/2] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacr

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6f0a3ba5852134d8bd04679438866e6f373f494a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 12:12:19 +0800
Subject: [PATCH] [Clang] Add support for GCC bound member functions extension

---
 clang/include/clang/AST/OperationKinds.def|  4 ++
 clang/include/clang/Basic/DiagnosticGroups.td | 32 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/AST/Expr.cpp|  5 ++
 clang/lib/AST/ExprConstant.cpp|  2 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExpr.cpp  |  1 +
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +
 clang/lib/CodeGen/CGExprComplex.cpp   |  1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 24 ++-
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |  1 +
 clang/lib/Sema/SemaCast.cpp   | 63 +++
 .../StaticAnalyzer/Core/BasicValueFactory.cpp |  3 +-
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |  3 +-
 17 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 790dd572a7c99..489d89a697dc3 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -152,6 +152,10 @@ CAST_OPERATION(MemberPointerToBoolean)
 /// many ABIs do not guarantee this on all possible intermediate types).
 CAST_OPERATION(ReinterpretMemberPointer)
 
+/// CK_BoundPointerToMemberFunctionToFunctionPointer - Convert a bound
+/// member function pointer to a function pointer.  This is a GNU extension.
+CAST_OPERATION(BoundMemberFunctionToFunctionPointer)
+
 /// CK_UserDefinedConversion - Conversion using a user defined type
 /// conversion function.
 ///struct A { operator int(); }; int i = int(A());
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d97bbfee2e4d5..8e5a4cba87c95 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def DuplicateDeclSpecifier : 
DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
 def GNUUnionCast : DiagGroup<"gnu-union-cast">;
 def GNUVariableSizedTypeNotAtEnd : 
DiagGroup<"gnu-variable-sized-type-not-at-end">;
+def GNUPMFCast : DiagGroup<"pmf-conversions">;
 def Varargs : DiagGroup<"varargs">;
 def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
 
@@ -1294,22 +1295,21 @@ def C2y : DiagGroup<"c2y-extensions">;
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
-GNUAutoType, GNUBinaryLiteral, GNUCaseRange,
-GNUComplexInteger, GNUCompoundLiteralInitializer,
-GNUConditionalOmittedOperand, GNUDesignator,
-GNUEmptyStruct,
-VLAExtension, GNUFlexibleArrayInitializer,
-GNUFlexibleArrayUnionMember, GNUFoldingConstant,
-GNUImaginaryConstant, GNUIncludeNext,
-GNULabelsAsValue, GNULineMarker, 
GNUNullPointerArithmetic,
-GNUOffsetofExtensions, GNUPointerArith,
-RedeclaredClassMember, GNURedeclaredEnum,
-GNUStatementExpression, GNUStaticFloatInit,
-GNUStringLiteralOperatorTemplate, GNUUnionCast,
-GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
-GNUZeroLineDirective,
-GNUZeroVariadicMacroArguments]>;
+def GNU
+: DiagGroup<
+  "gnu", [GNUAlignofExpression, GNUAnonymousStruct, GNUAutoType,
+  GNUBinaryLiteral, GNUCaseRange, GNUComplexInteger,
+  GNUCompoundLiteralInitializer, GNUConditionalOmittedOperand,
+  GNUDesignator, GNUEmptyStruct, VLAExtension,
+  GNUFlexibleArrayInitializer, GNUFlexibleArrayUnionMember,
+  GNUFoldingConstant, GNUImaginaryConstant, GNUIncludeNext,
+  GNULabelsAsValue, GNULineMarker, GNUNullPointerArithmetic,
+  GNUOffsetofExtensions, GNUPointerArith, 
RedeclaredClassMember,
+  GNURedeclaredEnum, GNUStatementExpression, 
GNUStaticFloatInit,
+  GNUStringLiteralOperatorTemplate, GNUUnionCast,
+  GNUVariableSizedTypeNotAtEnd, ZeroLengthArray,
+  GNUZeroLineDirective, GNUZeroVariadicMacroArgu

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/135649

>From 6795a5143129520d2db343d768507174a70da453 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 01:24:10 +0800
Subject: [PATCH 1/2] [Clang] Add support for GCC bound member functions
 extension

---
 clang/include/clang/AST/ExprCXX.h | 37 +++
 clang/include/clang/AST/RecursiveASTVisitor.h |  4 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 .../include/clang/Serialization/ASTBitCodes.h |  3 +
 clang/lib/AST/ExprConstant.cpp|  6 ++
 clang/lib/AST/StmtPrinter.cpp | 12 
 clang/lib/AST/StmtProfile.cpp |  8 +++
 clang/lib/Sema/SemaCast.cpp   | 64 +++
 clang/lib/Sema/TreeTransform.h| 35 ++
 clang/lib/Serialization/ASTReaderStmt.cpp | 16 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  7 ++
 11 files changed, 195 insertions(+)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 844f6dd90ae1d..7918ea0b20d41 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5448,6 +5448,43 @@ class BuiltinBitCastExpr final
   }
 };
 
+/// Represents a GCC extension bound pointer-to-member-function -> function
+/// pointer conversion.
+class BoundPointerToMemberFunctionToFunctionPointerCastExpr final
+: public ExplicitCastExpr,
+  private llvm::TrailingObjects {
+  friend class ASTStmtReader;
+  friend class CastExpr;
+
+  Expr *BaseExpr;
+
+public:
+  BoundPointerToMemberFunctionToFunctionPointerCastExpr(
+  QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
+  TypeSourceInfo *DstType, Expr *BaseExpr)
+  : ExplicitCastExpr(
+BoundPointerToMemberFunctionToFunctionPointerCastExprClass, T, VK,
+CK, SrcExpr, 0, false, DstType),
+BaseExpr(BaseExpr) {}
+
+  BoundPointerToMemberFunctionToFunctionPointerCastExpr(EmptyShell Empty)
+  : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {}
+
+  Expr *getBaseExpr() const LLVM_READONLY { return BaseExpr; }
+
+  SourceLocation getBeginLoc() const LLVM_READONLY {
+return BaseExpr ? BaseExpr->getBeginLoc() : getSubExpr()->getBeginLoc();
+  }
+  SourceLocation getEndLoc() const LLVM_READONLY {
+return getSubExpr()->getEndLoc();
+  }
+
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() ==
+   BoundPointerToMemberFunctionToFunctionPointerCastExprClass;
+  }
+};
+
 } // namespace clang
 
 #endif // LLVM_CLANG_AST_EXPRCXX_H
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3edc8684d0a19..e917f468b322f 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2567,6 +2567,10 @@ DEF_TRAVERSE_STMT(BuiltinBitCastExpr, {
   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
 })
 
+DEF_TRAVERSE_STMT(BoundPointerToMemberFunctionToFunctionPointerCastExpr, {
+  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
+})
+
 template 
 bool RecursiveASTVisitor::TraverseSynOrSemInitListExpr(
 InitListExpr *S, DataRecursionQueue *Queue) {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..5f5d53c968bbc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5120,6 +5120,9 @@ def err_ovl_unresolvable : Error<
 def err_bound_member_function : Error<
   "reference to non-static member function must be called"
   "%select{|; did you mean to call it with no arguments?}0">;
+def warn_bound_member_function_conversion
+: Warning<
+  "converting the bound member function %0 to a function pointer %1">;
 def note_possible_target_of_call : Note<"possible target for call">;
 def err_no_viable_destructor : Error<
   "no viable destructor found for class %0">;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5cb9998126a85..98ec32d0e5b98 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1869,6 +1869,9 @@ enum StmtCode {
   /// A BuiltinBitCastExpr record.
   EXPR_BUILTIN_BIT_CAST,
 
+  /// A BoundPointerToMemberFunctionToFunctionPointerCastExpr record.
+  EXPR_PMF_CAST,
+
   /// A UserDefinedLiteral record.
   EXPR_USER_DEFINED_LITERAL,
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d1cc722fb7945..4382bb05e7b97 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8121,6 +8121,10 @@ class ExprEvaluatorBase
   bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E) {
 return static_cast(this)->VisitCastExpr(E);
   }
+  bool VisitBoundPointerToMemberFunctionToFunctionPointerCastExpr(

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw edited 
https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-14 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw created 
https://github.com/llvm/llvm-project/pull/135649

None

>From 6795a5143129520d2db343d768507174a70da453 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 15 Apr 2025 01:24:10 +0800
Subject: [PATCH] [Clang] Add support for GCC bound member functions extension

---
 clang/include/clang/AST/ExprCXX.h | 37 +++
 clang/include/clang/AST/RecursiveASTVisitor.h |  4 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 .../include/clang/Serialization/ASTBitCodes.h |  3 +
 clang/lib/AST/ExprConstant.cpp|  6 ++
 clang/lib/AST/StmtPrinter.cpp | 12 
 clang/lib/AST/StmtProfile.cpp |  8 +++
 clang/lib/Sema/SemaCast.cpp   | 64 +++
 clang/lib/Sema/TreeTransform.h| 35 ++
 clang/lib/Serialization/ASTReaderStmt.cpp | 16 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  7 ++
 11 files changed, 195 insertions(+)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 844f6dd90ae1d..7918ea0b20d41 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5448,6 +5448,43 @@ class BuiltinBitCastExpr final
   }
 };
 
+/// Represents a GCC extension bound pointer-to-member-function -> function
+/// pointer conversion.
+class BoundPointerToMemberFunctionToFunctionPointerCastExpr final
+: public ExplicitCastExpr,
+  private llvm::TrailingObjects {
+  friend class ASTStmtReader;
+  friend class CastExpr;
+
+  Expr *BaseExpr;
+
+public:
+  BoundPointerToMemberFunctionToFunctionPointerCastExpr(
+  QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
+  TypeSourceInfo *DstType, Expr *BaseExpr)
+  : ExplicitCastExpr(
+BoundPointerToMemberFunctionToFunctionPointerCastExprClass, T, VK,
+CK, SrcExpr, 0, false, DstType),
+BaseExpr(BaseExpr) {}
+
+  BoundPointerToMemberFunctionToFunctionPointerCastExpr(EmptyShell Empty)
+  : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {}
+
+  Expr *getBaseExpr() const LLVM_READONLY { return BaseExpr; }
+
+  SourceLocation getBeginLoc() const LLVM_READONLY {
+return BaseExpr ? BaseExpr->getBeginLoc() : getSubExpr()->getBeginLoc();
+  }
+  SourceLocation getEndLoc() const LLVM_READONLY {
+return getSubExpr()->getEndLoc();
+  }
+
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() ==
+   BoundPointerToMemberFunctionToFunctionPointerCastExprClass;
+  }
+};
+
 } // namespace clang
 
 #endif // LLVM_CLANG_AST_EXPRCXX_H
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3edc8684d0a19..e917f468b322f 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2567,6 +2567,10 @@ DEF_TRAVERSE_STMT(BuiltinBitCastExpr, {
   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
 })
 
+DEF_TRAVERSE_STMT(BoundPointerToMemberFunctionToFunctionPointerCastExpr, {
+  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
+})
+
 template 
 bool RecursiveASTVisitor::TraverseSynOrSemInitListExpr(
 InitListExpr *S, DataRecursionQueue *Queue) {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..5f5d53c968bbc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5120,6 +5120,9 @@ def err_ovl_unresolvable : Error<
 def err_bound_member_function : Error<
   "reference to non-static member function must be called"
   "%select{|; did you mean to call it with no arguments?}0">;
+def warn_bound_member_function_conversion
+: Warning<
+  "converting the bound member function %0 to a function pointer %1">;
 def note_possible_target_of_call : Note<"possible target for call">;
 def err_no_viable_destructor : Error<
   "no viable destructor found for class %0">;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5cb9998126a85..98ec32d0e5b98 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1869,6 +1869,9 @@ enum StmtCode {
   /// A BuiltinBitCastExpr record.
   EXPR_BUILTIN_BIT_CAST,
 
+  /// A BoundPointerToMemberFunctionToFunctionPointerCastExpr record.
+  EXPR_PMF_CAST,
+
   /// A UserDefinedLiteral record.
   EXPR_USER_DEFINED_LITERAL,
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d1cc722fb7945..4382bb05e7b97 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8121,6 +8121,10 @@ class ExprEvaluatorBase
   bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E) {
 return static_cast(this)->VisitCastExpr(E);
   }
+  bool VisitBoundPointerToMemberFunctionToFunctionPointerCastExpr(