49 Commits

Author SHA1 Message Date
Henrich Lauko
57ee29a2a1
[CIR] Implement isMemcpyEquivalentSpecialMember for trivial copy/move ctors (#186700)
Implements isMemcpyEquivalentSpecialMember in CIR codegen so that
trivial copy/move constructors and defaulted union copy/move ops emit a
cir.copy directly instead of making a real constructor call. The logic
is shared with OG codegen by moving the implementation into ASTContext,
where it also gains the pointer field protection (PFP) check that was
previously missing in CIR.
2026-04-02 12:31:53 +02:00
Andy Kaylor
ccfba7736f
[CIR] Add support for cleanups after calling a delegating ctor (#189513)
This adds support for calling the destructor of types with a non-trivial
destructor if the initialization throws an exception after a delegating
constructor has been called.
2026-03-31 11:04:55 -07:00
Andy Kaylor
410558aa4d
[CIR] Use per-element zero-initialization with array new (#187760)
There was a discrepancy between the CIR and classic codegen handling of
zero-initialization of constructed objects with array new. Classic
codegen performs zero-initialization on a per-element basis, while CIR
had been inserting a single zero-initialization of the entire array
before individually constructing the elements.

This change aligns the CIR behavior with the classic codegen behavior.
2026-03-24 11:36:35 -07:00
Andy Kaylor
4a5da64759
[CIR][NFC] Minor cleanups to missing feature markers (#187754)
This fixes a few places where MissingFeatures asserts were incorrect,
extends the text of two errorNYI diagnostics to disambiguate them, and
fixes a typo in an adjacent comment.
2026-03-20 18:00:21 +00:00
Erich Keane
b16e7de0f2
[CIR] Implement func/call return-attributes (#181052)
This patch implements the infrastructure for return attributes on
function/call operations, a little of the common infrastructure for arg
attributes on the same, and 4 return attributes lowering: noundef
nonnull
dereferenceable
align

These 4 common attributes are all pretty reasonable/common, so these
will change a lot of tests.

This patch chooses to just use the LLVM-IR-Dialect variant of these
attributes (as a NamedAttr), which means no changes to the dialect or
lowering are necessary.
2026-02-13 06:20:27 -08:00
Henrich Lauko
3eef288447
[CIR] Add BuildableType traits to relevant constraints (NFC) (#172224)
This also eliminates some explicit uses of buildable types.
2025-12-15 19:15:21 +01:00
Andy Kaylor
4c21e460ed
[CIR] Add support for runtime data member pointer access (#171510)
This adds support for a CIR operation to represent runtime data member
access.
2025-12-11 10:19:00 -08:00
Andy Kaylor
e067be3389
[CIR][NFC] Add flag support for eh cleanups (#170753)
This adds the `flags` variable to the EHScopeStack::Cleanup class and
routes it through the existing handlers. None of the currently
implemented handlers use these flags, but the flag will be needed for
array and NRVO variable cleanup handling.
2025-12-04 15:16:44 -08:00
Andy Kaylor
ca3de05eca
[CIR][NFC] Fix a release build warning (#170359)
This moves a call inside an assert to avoid a warning about the result
variable being unused in release builds.
2025-12-02 20:29:04 +00:00
Andy Kaylor
1c9368e01e
[CIR] Upstream non-record array init handling (#169429)
This upstreams the code to handle member initialization for non-record
arrays.
2025-11-25 12:33:18 -08:00
Hendrik Hübner
03f4d4d492
[CIR] Add CxxCTorAttr, CxxDTorAttr, CxxAssignAttr, CxxSpecialMemberAttr to cir::FuncOp (#167975)
This PR adds a special member attribute to `cir::FuncOp`. This attribute
is also present in the incubator repo. Additionally, I added a
"is_trivial" flag, to mark trivial members. I think that might be useful
when trying to replace calls to the copy constructor with memcpy for
example, but please let me know your thoughts on this. [Here in the
incubator
repo](823e943d1b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp (L1537-L1550))
this function is called `LowerTrivialConstructorCall`, but I don't see a
check that ensures the constructor is actually trivial.
2025-11-19 15:57:34 -08:00
Andy Kaylor
0c8464330a
[CIR] Upstream handling for BaseToDerived casts (#167769)
Upstream handling for BaseToDerived casts, adding the
cir.base_class_addr operation and lowering to LLVM IR.
2025-11-17 09:09:46 -08:00
Andres-Salamanca
217f0e54c9
[CIR][NFC] Update TypeCache file to use MLIR-style camel case (#165060)
This PR updates the file `CIRGenTypeCache` to use MLIR-style camel case
naming.The change was inspired by the discussion here:
https://github.com/llvm/llvm-project/pull/164180#discussion_r2461444730
2025-10-28 19:26:33 -05:00
Jakub Kuderski
9a2e825c13
[clang][CIR][mlir] Migrate to free create functions. NFC. (#164656)
See
https://discourse.llvm.org/t/psa-opty-create-now-with-100-more-tab-complete/87339.

I plan to make these deprecated in
https://github.com/llvm/llvm-project/pull/164649.
2025-10-22 14:30:19 -04:00
Matheus Izvekov
b516dcc998
[clang] NFC: rename TagType::getOriginalDecl back to getDecl (#163271)
This rename was made as part of
https://github.com/llvm/llvm-project/pull/147835 in order to ease
rebasing the PR, and give a nice window for other patches to get rebased
as well.

It has been a while already, so lets go ahead and rename it back.
2025-10-15 16:11:17 -03:00
Andy Kaylor
d81e8c02d4
[CIR] Add support for virtual destructor calls (#162725)
This adds support for calling virtual destructors.
2025-10-13 10:31:10 -07:00
Andy Kaylor
1b627da8cf
[CIR] Call base class destructors (#162562)
This adds handling for calling virtual and non-virtual base class
destructors. Non-virtual base class destructors are call from the base
(D2) destructor body for derived classes. Virtual base class destructors
are called only from the complete (D1) destructor.
2025-10-09 11:19:57 -07:00
Andy Kaylor
05e723e25e
[CIR][NFC] Remove dead member function from EHScopeStack::Cleanup (#162565)
This removes the `getSize()` member function from EHScopeStack::Cleanup
and all its subclasses. This function had originally been added as a
temporary measure before EHCleanupScope was implemented, but it is no
longer used.
2025-10-09 10:11:59 -07:00
Andy Kaylor
81c6f53c19
[CIR] Add support for destructing class members (#162196)
This adds the necessary cleanup handling to get class destructors to
call the destructor for fields that require it.
2025-10-08 11:46:31 -07:00
Andy Kaylor
b4a95fe9f1
[CIR] Fix destructor calls with temporary objects (#161922)
This fixes a few problems where destructors were not called for
temporary objects and, after calling was enabled, they were placed
incorrectly relative to cir.yield operations.
2025-10-06 15:46:47 -07:00
Morris Hafner
b629981a6d
[CIR] Add virtual base support to getAddressOfBaseClass (#159162)
This patch enables calling virtual functions of virtual base classes of
a derived class.
2025-09-29 13:17:52 -07:00
Andy Kaylor
be7444becf
[CIR] Implement static lambda invoker (#160137)
This adds support for handling static lambda invokers.
2025-09-23 08:40:34 -07:00
Andy Kaylor
9b9b9c631b
[CIR] Add support for lambda expressions (#157751)
This adds support for lambda operators and lambda calls. This does not
include support for static lambda invoke, which will be added in a later
change.
2025-09-22 08:29:08 -07:00
Morris Hafner
7165cf3e12
[CIR] Fix structors for multidimensional arrrays (#159820)
This patchs implements array constructors and destructors for
multidimensional arrays. This works by bitcasting the pointer to the
first element to a one-dimensional array type of the same extent before
lowering to a loop.
2025-09-19 23:44:33 +02:00
Andy Kaylor
e1021bb9bd
[CIR] Implement CXX field default initialization (#157140)
This adds the code needed to handle default initialization for fields of
various types.
2025-09-05 13:19:43 -07:00
Andy Kaylor
66f93dff6e
[CIR] Add support for delegating constructors with VTT args (#156970)
This adds support for handling delegating constructors with VTT
arguments.
2025-09-05 13:19:13 -07:00
Andy Kaylor
88c3825889
[CIR] Add support for constructors with VTT parameters (#156521)
This adds the support for implicit VTT arguments in constructors.
2025-09-03 12:06:56 -07:00
Andy Kaylor
e7c9f2db41
[CIR] Add initial support for virtual base classes (#155534)
This adds support for declaring a class with a virtual base class and
initializing the vptr in the constructor. This does not yet handle
constructors that require a virtual table table (VTT) implicit argument.
2025-08-27 15:40:40 -07:00
Matheus Izvekov
249167a898
[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`,
as a redirection to `TypeBase.h`, and redirects most users to include
the former instead.

This is a preparatory patch for being able to provide inline definitions
for `Type` methods which would otherwise cause a circular dependency
with `Decl{,CXX}.h`.

Doing these operations into their own NFC patch helps the git rename
detection logic work, preserving the history.

This patch makes clang just a little slower to build (~0.17%), just
because it makes more code indirectly include `DeclCXX.h`.
2025-08-27 13:11:34 -03:00
Matheus Izvekov
bcd1530836
[clang] NFC: rename clang/include/clang/AST/Type.h to TypeBase.h (#155049)
This is a preparatory patch, to be able to provide inline definitions
for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also
depends on `Type.h`, this would not be possible without some
reorganizing.

Splitting this rename into its own patch allows git to track this as a
rename, and preserve all git history, and not force any code
reformatting.

A later NFC patch will reintroduce `Type.h` as redirection to
`TypeBase.h`, rewriting most places back to directly including `Type.h`
instead of `TypeBase.h`, leaving only a handful of places where this is
necessary.

Then yet a later patch will exploit this by making more stuff inline.
2025-08-27 13:09:48 -03:00
Andy Kaylor
5d54d348f2
[CIR] Add support for initializing classes with multiple vtables (#155275)
This adds support for initializing the vptr members in a class that
requires multiple vtables because of multiple inheritence. This still
does not handle virtual bases.
2025-08-26 17:19:47 -07:00
Matheus Izvekov
2ec71d93ad
[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all TagDecls (#155463)
And make use of those.

These changes are split from prior PR #155028, in order to decrease the
size of that PR and facilitate review.
2025-08-26 16:05:59 -03:00
Andy Kaylor
7ac4d9bd53
[CIR] Add support for calling virtual functions (#153893)
This change adds support for calling virtual functions. This includes
adding the cir.vtable.get_virtual_fn_addr operation to lookup the
address of the function being called from an object's vtable.
2025-08-18 15:56:33 -07:00
Andy Kaylor
0cd35e7afd
[CIR] Add cir.vtable.get_vptr operation (#153630)
This adds support for the cir.vtable.get_vptr operation and uses it to
initialize the vptr member during constructors of dynamic classes.
2025-08-15 15:14:51 -07:00
Michael Liao
c1f797ea6d [CIR] Fix build due to the improvement after 91cdd35008e9 2025-08-12 13:42:12 -04:00
Andy Kaylor
7f195b36ee
[CIR] Initialize vptr in dynamic classes (#152574)
This adds support for initializing the vptr member of a dynamic class in
the constructor of that class.

This does not include support for lowering the
`cir.vtable.address_point` operation to the LLVM dialect. That handling
will be added in a follow-up patch.
2025-08-12 10:00:38 -07:00
Michael Liao
c9b6242771 [CIR] Fix build after the improved nested name specifier AST repr (91cdd35008e9) 2025-08-09 16:38:49 -04:00
Henrich Lauko
4820b183a8
[CIR] Simplify ConstantOp accesses and its getDefiningOp (#151216)
- Replaces  dyn_cast<cir::ConstantOp>(v.getDefiningOp()) and similar with v.getDefiningOp<cir::ConstantOp>()
- Adds `getValueAttr` method to ConstantOp
2025-08-01 21:04:54 +02:00
Andy Kaylor
47b5917348
[CIR] Add support for normal cleanups (#149948)
This change adds basic handling for normal cleanups. This is a very
minimal implemention. In particular, it uses a naive substitute for the
rich cleanup and EH stack handling that is present in classic codegen
and the CIR incubator. This is intended as a temporary implementation to
allow incremental progress. It is not expected to scale well enough to
be used in a production environment. It will be replaced with the full
EHScopeStack handling when such an implementation is needed.
2025-07-24 11:38:42 -07:00
Morris Hafner
3e9d369c5c
[CIR] Add support for array constructors (#149142)
This patch upstreams support for creating arrays of classes that require
calling a constructor.

* Adds the ArrayCtor operation
* New lowering pass for lowering ArrayCtor to a loop

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
2025-07-24 17:15:34 +02:00
Andy Kaylor
8f26a301bc
[CIR] Add complete destructor handling (#149552)
The initial implementation for emitting destructors emitted the complete
destructor body for both D1 and D2 destructors. This change updates the
code to have the D1 destructor call the D2 destructor.
2025-07-21 15:34:46 -07:00
Bogdan Vetrenko
a35b290c3c
[CIR][NFC] Fix typo in assertion message (Must) (#148704) 2025-07-15 18:27:14 +02:00
Andy Kaylor
13c897093f
[CIR] Add support for non-virtual base class initialization (#148080)
This change adds support for initializing non-virtual base classes
during the prologue of a derived class' constructor.
2025-07-11 09:57:15 -07:00
Andy Kaylor
32180cf9f9
[CIR] Upstream support for operator assign (#145979)
This adds support for assignment operators, including implicit operator
definitions.
2025-06-27 16:56:26 -07:00
Andy Kaylor
418b409df8
[CIR] Add support for member initialization from constructors (#144583)
Upstream the code to handle member variable initialization in a
constructor. At this point only simple scalar values (including members
of anonymous unions) are handled.
2025-06-24 10:05:48 -07:00
Andy Kaylor
4a4035c86b
[CIR] Add support for delegating constructors (#143932)
This change adds the necessary support for handling delegating
constructors in ClangIR. The implementation is kept as small as possible
by not handling any other sort of initialization (members, base classes,
etc.). That will be added in a future commit.
2025-06-12 14:52:07 -07:00
Andy Kaylor
77834a40cf
[CIR] Upstream support for emitting constructors (#143639)
This change upstreams the code to emit simple constructor defintions.
2025-06-12 09:24:26 -07:00
Andy Kaylor
b9329fe88e
[CIR] Upstream support for calling constructors (#143579)
This change adds support for calling C++ constructors. The support for
actually defining a constructor is still missing and will be added in a
later change.
2025-06-10 16:50:29 -07:00
Andy Kaylor
6559831025
[CIR] Add support for accessing members of base classes (#143195)
This change adds the support for accessing a member of a base class from
a derived class object.
2025-06-09 13:11:12 -07:00