93 Commits

Author SHA1 Message Date
Andy Kaylor
729480c4ae
[CIR] Generalize cxx alloc new size handling (#187790)
The non-constant size handling in `emitCXXNewAllocSize` was making the
incorrect assumption that the default behavior of the size value being
explicitly cast to size_t would be the only behavior we'd see. This is
actually only true with C++14 and later. To properly handle earlier
standards, we need the more robust checking that classic codegen does in
the equivalent function. This change adds that handling.

Assisted-by: Cursor / claude-4.6-opus-high
2026-03-23 11:47:16 -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
Andy Kaylor
ab10f0848b
[CIR] Fix a crash when source location is unknown (#185059)
When we call `getLoc()` with an invalid `SourceLocation` and
`currSrcLoc` is also invalid, we were crashing or asserting. I tracked
down one case where this was happening (generating an argument in a
vtable thunk) and fixed that to provide a location. I also am updating
the `getLoc()` implementation so that it will use an unknown location in
release builds rather than crashing because the location isn't critical
for correct compilation.
2026-03-06 12:03:44 -08:00
Erich Keane
c186db874b
[CIR] Implement 'typeid' operator lowering (#184449)
This patch adds typeid lowering, which uses a lot of the infrastructure
from dynamic_cast. However, this adds a `get_type_info` operation that
gets the type info out of a vtable pointer as well, which lets the
offset be handled by the ABI specific lowering code.
2026-03-05 06:07:13 -08:00
Andy Kaylor
a14d8b2e36
[CIR] Upstream vtable thunk handling (#183629)
This implements vtable thunk handling in CIR based on the incubator
code, but also compared against the latest Clang LLVM IR codegen.

Eventually, we'll want to create CIR abstractions for all of this and
move the CXXABI-specific details into the CXXABI lowering pass. For now,
we just implement it directly in codegen.
2026-03-02 14:15:52 -08:00
Andy Kaylor
decb5d3ff6
[CIR] Remove branch through cleanup fixups (#182953)
Because we are using a structured representation of cleanups in CIR, we
don't need to handle branching through cleanups during codegen. These
branches are created during CFG flattening instead. However, we had
already committed some code that copied the classic codegen behavior for
branching through cleanups. This change deletes that unneeded code.

The most significant change here is that when we encounter a return
statement we emit the return directly in the current location.

The coroutine implementation still creates a return block in the current
lexical scope and branches to that block. Cleaning up that
representation is left as future work.

The popCleanupBlock handling still has a significant amount of logic
that is carried over from the classic codegen implementation. It is left
in place until we can be sure we won't need it.
2026-02-26 17:18:25 -08:00
Andy Kaylor
19c862dd27
[CIR][NFC] Fix unused variable warnings (#183604)
We have accumulated four places where variables were only being used in
asserts. This change silences the warnings for that.
2026-02-26 12:17:24 -08:00
Vishruth Thimmaiah
8e5b9cab58
[CIR] Upstream support for pure virtual destructors (#182857)
Upstreams support for emitting traps for abstract destructors.

Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
2026-02-26 10:12:59 -08:00
Erich Keane
f927ffe0f9
[CIR] Implement LValue SubstNonTypeTemplateParmExpr lowering (#182920)
This just lowers to the expression that is its replacement, which in
this case causes it to just be the l-value in the expression.
2026-02-24 06:23:57 -08:00
Erich Keane
a9e29e7ae3
[CIR] Implement LValue reinterpret/const cast (#182926)
These two are very simple and call into the Rvalue code/LValue lowering
code we already had for these, but weren't exposed as top-level LValues.
This patch adds them to the list (plus adds a comment for those that
    we're missing!), as well as adds a test.
2026-02-24 06:23:29 -08:00
Amr Hesham
990996358d
[CIR] Represent Cleanups with Cleanup scopes (#180276)
Represent the Cleanups stack explicitly with Cleanup scopes
2026-02-23 18:03:37 +01:00
Chaitanya
cb82236896
[CIR] Handle Type::OverflowBehavior in CIR CodeGen (#182469)
This PR adds OverflowBehavior  case to CIR CodeGen.
Fixes CI failures in clangIR introduced by
https://github.com/llvm/llvm-project/pull/148914
2026-02-20 21:22:10 +05:30
Ayokunle Amodu
260f6fedc7
[CIR][NFC] Upstream support for FP environments and RAII options (#179121)
This adds support for FP environment descriptions and RAII options for
FP operations, i.e.,`CIRGenFPOptionsRAII`).
2026-02-17 16:10:26 -08:00
David Rivera
2d12279528
[CIR][CUDA] Upstream device stub body emission and name mangling (#177790)
Part of #175871 

This patch adds the initial implementation of the CUDA/NV Runtimes
generating code for the device stub body. tested on CUDA. HIP coverage
to be added in a later PR.
2026-02-03 05:20:43 -05:00
Andres-Salamanca
626e3423f8
[CIR] Upstream coroutine builtin coro_end (#176598)
This PR adds support for emitting the `__builtin_coro_end` builtin in
CIR.
2026-01-22 19:02:01 -05:00
Mariya Podchishchaeva
d714a6c210
Reland [MS][clang] Add support for vector deleting destructors (#170337)
This reverts commit
54a4da9df6.

MSVC supports an extension allowing to delete an array of objects via
pointer whose static type doesn't match its dynamic type. This is done
via generation of special destructors - vector deleting destructors.
MSVC's virtual tables always contain a pointer to the vector deleting
destructor for classes with virtual destructors, so not having this
extension implemented causes clang to generate code that is not
compatible with the code generated by MSVC, because clang always puts a
pointer to a scalar deleting destructor to the vtable. As a bonus the
deletion of an array of polymorphic object will work just like it does
with MSVC - no memory leaks and correct destructors are called.

This patch will cause clang to emit code that is compatible with code
produced by MSVC but not compatible with code produced with clang of
older versions, so the new behavior can be disabled via passing
-fclang-abi-compat=21 (or lower).

Fixes https://github.com/llvm/llvm-project/issues/19772
2025-12-12 09:54:32 +01:00
adams381
84b9e44445
[CIR] Add Function Argument Demotion support (#170915)
This PR migrates the Function Argument Demotion feature from the
incubator repository to upstream. The feature handles K&R-style function
parameters that are promoted (e.g., short->int, float->double) and
demotes them back to their declared types.

## Changes
- Add emitArgumentDemotion helper function for type demotion
- Create emitFunctionProlog function to handle function prologue setup
(addresses existing TODO to move parameter handling logic)
- Move parameter handling logic into emitFunctionProlog
- Add test case kr-func-promote.c to verify the feature

Tested: All CIR tests pass (320/321, 99.69%). The one unsupported test
is an expected failure.
2025-12-09 15:09:25 -08:00
Andres-Salamanca
762a171b3d
[CIR] Upstream support for cir.indirectbr (#169967)
This PR upstreams support for the `cir.indirectBr` operation, which is
used to implement GCC’s labels-as-values `indirect goto`.
To ensure correct lowering, we introduce precise bookkeeping to
associate each `block_address` operation with its corresponding `label`
op. This is required because a `block_address` may be emitted before the
`label` it refers to. In such cases, the reference is deferred and later
resolved by `resolveBlockAddresses`, which guarantees that all
`indirectBr` successors are emitted in the correct and fully resolved
order.
2025-12-05 16:12:37 -08:00
Andy Kaylor
cabcb5ae55
[CIR][NFC] Fix build problem inside an assert (#169715)
A recent change introduced a failure in debug builds due to an incorrect
level of indirection inside an assert. This fixes that.
2025-11-26 19:59:44 +00:00
Amr Hesham
18805b6ce9
[CIR] CountOf VLA with Array element type (#169404)
Implement CountOf on VariableArrayType with IntegerConstant SizeExpr
2025-11-26 19:22:05 +01:00
Zequan Wu
54a4da9df6
Revert "Reland [MS][clang] Add support for vector deleting destructors" (#169116)
This reverts 4d10c1165442cbbbc0017b48fcdd7dae1ccf3678 and its two
dependent commits: e6b9805b574bb5c90263ec7fbcb94df76d2807a4 and
c243406a695ca056a07ef4064b0f9feee7685320, see discussion in
https://github.com/llvm/llvm-project/pull/165598#issuecomment-3563825509.
2025-11-21 17:14:34 -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
Amr Hesham
3d01d6ebfd
[CIR] Upstream non-empty Try block with catch all (#165158)
Upstream support for try block and catch all block with a function call
that may throw an exception.

Issue https://github.com/llvm/llvm-project/issues/154992
2025-11-16 10:50:04 +01:00
Andy Kaylor
518b38cf87
[CIR] Upstream handling for C++ default argument l-values (#167999)
This adds handling emitting C++ default arguments as l-values.
2025-11-14 09:46:33 -08:00
Andy Kaylor
cfad41c450
[CIR] Upstream l-value emission for ExprWithCleanups (#167938)
This adds the necessary handler for emitting an l-value for an
ExprWithCleanups expression.
2025-11-13 17:00:22 -08:00
Andy Kaylor
e6b9805b57
[CIR][NFC] Add missing code markers for Dtor_VectorDeleting (#167969)
This adds some minimal code to mark locations where handling is needed
for Dtor_VectorDeleting type dtors, which were added in
https://github.com/llvm/llvm-project/pull/165598

This is not a comprehensive mark-up of the missing code, as some code
will be needed in places where the surrounding function has larger
missing pieces in CIR currently.

This fixes a warning for an uncovered switch case that was causing CI
builds to fail.
2025-11-13 15:24:18 -08:00
Amr Hesham
9216e17fd2
[CIR] Upstream basic support for ExtVector element expr (#167570)
Upstream the basic support for the ExtVectorType element expr
2025-11-13 18:23:11 +01:00
Andres-Salamanca
cf9cb542f2
[CIR] Emit promise declaration in coroutine (#166683)
This PR adds support for emitting the promise declaration in coroutines
and obtaining the `get_return_object()`.
2025-11-12 16:29:11 -05:00
Morris Hafner
1de696b6e2
[CIR] Fix multiple returns in switch statements (#164468)
Add support for multiple return statements in switch statements. Cases
in switch statements don't have their own scopes but are distinct
regions nonetheless. Insert multiple return blocks for each case and
handle them in the cleanup code.
2025-10-31 11:42:48 +00: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
Morris Hafner
3155b05044
[CIR] Implement inline builtin functions (#163911)
This patch implements the handling of inline builtin functions in CIR.
There is a known limitation in CIR where direct calls to shadowed inline
builtin functions are generated instead of the intrinsic. This is
expected to be fixed by the introduction of the nobuiltin attribute in a
future patch.
2025-10-22 00:17:52 +08:00
Morris Hafner
babecd41a8
[CIR] Add support for ternary operator as lvalue (#163580)
Added support for ConditionalOperator, BinaryConditionalOperator and
OpaqueValueExpr as lvalue.

Implemented support for ternary operators with one branch being a throw
expression. This required weakening the requirement that the true and
false regions of the ternary operator must terminate with a `YieldOp`.
Instead the true and false regions are now allowed to terminate with an
`UnreachableOp` and no `YieldOp` gets emitted when the block throws.
2025-10-21 00:18:43 +07:00
Andy Kaylor
85265a93cc
[CIR] Upstream support for variable length arrays (#163297)
This adds the code needed to emit alloca operations for variable length
array local variables and the necessary calls to stacksave and
stackrestore to adjust the local stack as the array variables go in an
out of scope.
2025-10-15 13:55:18 -07: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
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
Andres-Salamanca
16f5a85fb6
[CIR] Initial support for emitting coroutine body (#161616)
This PR adds new `FuncOp` attributes (`coroutine` and `builtin`) and
begins the implementation of the `emitCoroutineBody` function. Feature
markers were also added for guidance in future PRs.
2025-10-03 13:56:53 -05:00
Andy Kaylor
d6449b55cd
[CIR] Add support for emitting predefined expressions (#161757)
This adds support for emitting pseudo-macro expressions that represent
some form of the name of a function (such as `__func__` or
`__PRETTY_FUNCTION__`) as l-values.
2025-10-03 10:37:06 -07:00
Amr Hesham
0e17fb52da
[CIR] Implement GenericSelectionExpr for AggregateExpr (#161003)
Implement the GenericSelectionExpr for AggregateExpr
2025-10-01 17:34:14 +02:00
Andy Kaylor
ca84f2aa3b
[CIR] Upstream support for generating global ctor regions (#161298)
This adds support for handling global variables with non-trivial
constructors. The constructor call is emitted in CIR as a 'ctor' region
associated with the global definition. This form of global definition
cannot be lowered to LLVM IR yet.

A later change will add support in LoweringPrepare to move the ctor code
into a __cxx_global_var_init() function and add that function to the
list of global global ctors, but for now we must stop at the initial CIR
generation.
2025-09-30 14:20:13 -07:00
Amr Hesham
ee8394d946
[CIR] Implement ChooseExpr for AggregateExpr (#160999)
Implement the ChooseExpr for aggregate expr
2025-09-30 19:16:31 +02: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
Andy Kaylor
aa9af2a3ec
[CIR] Add support for copy elision (#157713)
This adds basic support for eliding copy constructors. In order to make
this possible, it also adds support for returning structures. This
support does not include setting an NRVO flag when the class whose copy
is being elided has a non-trivial destructor.
2025-09-09 13:32:44 -07:00
Andy Kaylor
27c543076b
[CIR][NFC] Fix build warnings after #154142 (#157724)
A recent change introduced a new dtor kind, which caused a build warning
in the CIR code where this dtor kind wasn't handled in a switch. This
fixes the problem.
2025-09-09 11:22:09 -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
Matheus Izvekov
dc8596d548
[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)
This changes a bunch of places which use getAs<TagType>, including
derived types, just to obtain the tag definition.

This is preparation for #155028, offloading all the changes that PR used
to introduce which don't depend on any new helpers.
2025-08-25 20:18:56 -03:00
Morris Hafner
b5e5794534
[CIR] Implement Statement Expressions (#153677)
Depends on #153625

This patch adds support for statement expressions. It also changes
emitCompoundStmt and emitCompoundStmtWithoutScope to accept an Address
that the optional result is written to. This allows the creation of the
alloca ahead of the creation of the scope which saves us from hoisting
the alloca to its parent scope.
2025-08-19 10:11:15 +02:00
Morris Hafner
b44e47a68f
[CIR] Upstream __builtin_va_start and __builtin_va_end (#153819)
Part of #153286
2025-08-19 09:16:11 +02:00
Morris Hafner
e56ae9651b
[CIR][NFC] Add Symbol Table to CIRGenFunction (#153625)
This patchs adds a symbol table to CIRGenFunction plus scopes and
insertions to the table where we were missing them previously.
2025-08-14 22:53:09 +02:00