49 Commits

Author SHA1 Message Date
Henrich Lauko
348295ac05
[CIR] Use data size in emitAggregateCopy for overlapping copies (#186702)
Add skip_tail_padding property to cir.copy to handle
potentially-overlapping
subobject copies directly, instead of falling back to cir.libc.memcpy.
When
set, the lowering uses the record's data size (excluding tail padding)
for
the memcpy length. This keeps typed semantics and promotability of
cir.copy.

Also fix CXXABILowering to preserve op properties when recreating
operations,
and expose RecordType::computeStructDataSize() for computing data size
of
padded record types.
2026-04-06 18:24:10 +02:00
Erich Keane
58b719660c
[CIR] Implement union aggregate init (#190057)
This ends up being a pretty trivial amount of work, since we just have
to forward the initialization for a union on to the 'active' field,
which this patch does.
2026-04-02 06:00:36 -07:00
Amr Hesham
90d3944c4a
[CIR] Implement VisitCXXStdInitializerListExpr for 2 ptr layout (#186679)
Implement support for CXXStdInitializerListExpr for two pointers (begin,
end) layout
2026-03-19 19:21:28 +01:00
Hendrik Hübner
b2c2422c2e
[CIR] Upstream ThreeWayCmpOp (#169963)
This PR upstreams the three way compare op from the incubator repo

---------

Co-authored-by: Hendrik Hübner <hhuebner@Hendriks-MacBook-Pro.local>
2026-03-18 11:35:43 -07:00
Andy Kaylor
d49701bba3
[CIR] Implement abstract conditional operator handling for aggregates (#186284)
This implements AggExprEmitter::VisitAbstractConditionalOperator for
CIR.
2026-03-17 17:21:51 -07:00
Amr Hesham
298ef5155e
[CIR] Add support for CXXStdInitializerListExpr (#185279)
Add support for the CXXStdInitializerListExpr
2026-03-09 19:21:00 +01: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
Andrzej Warzyński
aca0df927f
[Clang][CIR] Implement CIRGen logic for __builtin_bit_cast (#176782)
NOTE: This PR upstreams code from
  * https://github.com/llvm/clangir.

This logic was originally implemented by Sirui Mu in
https://github.com/llvm/clangir/pull/762. Further
modification were made by other ClangIR contributors.

Co-authored-by: Sirui Mu <msrlancern@gmail.com>
2026-01-22 18:24:58 +00:00
Andres-Salamanca
387e6e2b70
[CIR] Upstream support co_return of values from co_await (#173174)
This PR adds support for returning the result of a `co_await` via
`co_return`. A new variable, `__coawait_resume_rval`, is introduced to
store the returned value.
2026-01-16 21:38:45 -05:00
Amr Hesham
4bd84a9f33
[CIR] Implement AtomicExpr for Aggregate expr (#173775)
Implement support for AtomicExpr for Aggregate expr
2026-01-08 18:55:31 +01:00
adams381
c2f33b5a28
[CIR] Implement AggExprEmitter::VisitVAArgExpr (#172551)
This PR implements support for aggregate va_arg expressions in CIR
codegen.

## Changes

- **CIRGenBuiltin.cpp**: Modified `emitVAArg` to return a pointer type
for aggregate types. For aggregate types, `va_arg` returns a pointer to
the aggregate rather than the aggregate value itself.

- **CIRGenExprAggregate.cpp**: Implemented
`AggExprEmitter::VisitVAArgExpr` to handle aggregate va_arg expressions
by:
  - Getting the va_arg pointer from `emitVAArg()`
  - Creating an `Address` from the pointer with proper alignment
  - Creating an `LValue` from the `Address`
- Copying the aggregate value to the destination using
`emitFinalDestCopy()`

- **Test**: Added comprehensive test `var-arg-aggregate.c` with CIR,
LLVM, and OGCG checks to verify the implementation matches original
codegen behavior.

## Testing

All tests pass:
- `check-clang-cir-codegen`: 180/181 passed (99.45%)
- `check-clang-cir`: 423/424 passed (99.76%)
2025-12-18 15:53:04 -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
Amr Hesham
6a0ba8b7a4
[CIR] Prepare a 'this' for CXXDefaultInitExprs (#165994)
Prepare a 'this' for CXXDefaultInitExprs
2025-11-13 17:05:48 +01:00
Andy Kaylor
a22834a4d2
[CIR] Handle null base class initialization (#167023)
This adds handling for null base class initialization, but only for the
trivial case where the class is empty. This also moves
emitCXXConstructExpr to CIRGenExprCXX.cpp for consistency with classic
codegen and the incubator repo.
2025-11-12 10:13:36 -08:00
Amr Hesham
ecd67a7a95
[CIR] Upstream CXXDefaultArgExpr for AggregateExpr (#165991)
Upstream the CXXDefaultArgExpr support for AggregateExpr
2025-11-04 18:40:42 +01: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
Andy Kaylor
ab1765d765
[CIR] Upstream trivial constructor const handling (#164849)
This adds handling for records with trivial constructors in CIR's
ConstExprEmitter.
2025-10-24 10:33:25 -07:00
Amr Hesham
41cc0de595
[CIR] Const member expr for struct type (#164172)
Upstream support the const member expr for struct type
2025-10-21 22:33:54 +02:00
Andy Kaylor
437cad9121
[CIR] Upstream aggregate binary assign handling (#163877)
This upstreams the implementation for handling binary assignment
involving aggregate types.
2025-10-20 15:05:10 -07:00
Morris Hafner
cd05383a46
[CIR] Add Aggregate Expression LValue Visitors (#163410)
This patch implements visitors for MemberExpr, UnaryDeref,
StringLiteral and CompoundLiteralExpr inside aggregate
expressions.
2025-10-20 23:56:24 +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
Amr Hesham
3149a7720f
[CIR] Implement DesignatedInitUpdateExpr for AggregateExpr (#161897)
Implement the DesignatedInitUpdateExpr support for AggregateExpr
2025-10-05 11:38:27 +00:00
Amr Hesham
7c666e2480
[CIR] Implement UnaryExtension for AggregateExpr (#161820)
Implement the UnaryExtension support for AggregateExpr
2025-10-04 09:52:09 +00:00
Amr Hesham
8243c368b7
[CIR] Upstream CXXParenListInitExpr for AggregateExpr (#161876)
Upstream the CXXParenListInitExpr support for AggregateExpr
2025-10-04 11:25:40 +02:00
Amr Hesham
47361e7e0d
[CIR] Implement BinComma Expr for AggregateExpr (#161823)
Implement the BinComma Expr support for AggregateExpr
2025-10-04 11:09:01 +02:00
Amr Hesham
0e17fb52da
[CIR] Implement GenericSelectionExpr for AggregateExpr (#161003)
Implement the GenericSelectionExpr for AggregateExpr
2025-10-01 17:34:14 +02:00
Amr Hesham
ee8394d946
[CIR] Implement ChooseExpr for AggregateExpr (#160999)
Implement the ChooseExpr for aggregate expr
2025-09-30 19:16:31 +02:00
Amr Hesham
71d8ddc78a
[CIR] Upstream ParenExpr for AggregateExpr (#160998)
Upstream ParenExpr support for AggregateExpr
2025-09-30 18:44:40 +02:00
Amr Hesham
2d6a6714f3
[CIR] Upstream support Agg init with lvalue ComplexType (#159974)
Upstream the support of Agg init with lvalue ComplexType

Issue: https://github.com/llvm/llvm-project/issues/141365
2025-09-23 21:07:55 +02: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
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
8c716bec1d
[CIR] Emit copy for aggregate initialization (#155697)
This adds the implementation of aggEmitFinalDestCopy for the case where
the destination value is not ignored. This requires adding the cir.copy
operation and associated interface code.
2025-09-03 11:08:40 -07:00
Andy Kaylor
95d3ecee82
[CIR] Add handling for volatile loads and stores (#156124)
This fills in the missing pieces to handle volatile loads and stores in
CIR.

This addresses https://github.com/llvm/llvm-project/issues/153280
2025-09-02 11:36:47 -07:00
Andy Kaylor
ab6ff0e432
[CIR][NFC] Add errors for unhandled AggExprEmitter visitors (#155469)
There are a lot of required handlers in AggExprEmitter that are
currently missing. Because the ASTVisitor has fallbacks, this means we
just silently ignore whatever expressions are not explicitly handled.
This patch adds handlers where we know they will be needed and just
issues a diagnostic.

This exposed failures in a few tests. In one case, we should have
handled constant initialization earlier, which would have avoided going
to the AggExprEmitter at all. I added a stub with a missing feature
marker to allow that case to work as it had. Another test required us to
ignore cast expressions that should be ignored, so I partially
implemented the cast visitor. Finally, there's a case where the test was
just accepting a bad result. I changed that case to XFAIL until it can
be properly fixed.
2025-08-27 12:54:07 -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
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
Andy Kaylor
f2d76b58f8
[CIR] Use a loop for array initialization (#153499)
This updates the array initialization loop to use a do..while loop
rather than a fully serialized initialization. It also allows the
initialization of destructed objects when exception handling is not
enabled.

Array initialization when exception handling is enabled remains
unimplemented, but more precise messages are now emitted.
2025-08-13 16:14:32 -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
Amr Hesham
cf1abe67b9
[CIR][NFC] Fix an unused variable warning (#150758)
This fixes a warning where a variable assigned in 'if' statement wasn't
referenced again.
2025-07-27 11:54:38 +02:00
Andy Kaylor
64704c6346
[CIR] Add support for C++ initializer lists (#150681)
This adds basic support for using C++ initializer lists to initialize
fields of a record.
2025-07-25 13:39:43 -07: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
Sirui Mu
8ba62fdb3d
[CIR] Function calls with aggregate arguments and return values (#143377)
This patch updates cir.call operation and allows function calls with
aggregate arguments and return values.

It seems that C++ class support is still at a minimum now. I tried to
make a call to a C++ function with an argument of aggregate type but it
failed because the initialization of C++ class / struct is NYI. I also
tried to inline this part of support into this patch, but the mixed
patch quickly blows in size and becomes unsuitable for review. Thus,
tests for calling functions with aggregate arguments are added only for
C for now.
2025-06-13 16:47:56 +08: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
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
Morris Hafner
4b2cb118bc
[CIR] Upstream lowering of conditional operators to TernaryOp (#138156)
This patch adds visitors for BinLAnd, BinLOr and
AbstractConditionalOperator. Note that this patch still lacks visitation
of OpaqueValueExpr which is needed for the GNU ?: operator.

---------

Co-authored-by: Erich Keane <ekeane@nvidia.com>
2025-06-03 13:29:23 +02:00
Andy Kaylor
ea3c225786
[CIR] Add alignment support for global, store, and load ops (#141163)
This adds alignment support for GlobalOp, LoadOp, and StoreOp.

Tests which failed because cir.store/cir.load now print alignment were
updated with wildcard matches, except where the alignment was relevant
to the test. Tests which check for cir.store/cir.load in cases that
don't have explicit alignment were not updated.

New tests for alignment are alignment.c, align-load.c, and
align-store.c.
2025-05-23 15:34:59 -07:00
Iris Shi
708053cd7e
[CIR] Upstream initial support for union type (#137501)
Closes #136059
2025-05-01 07:56:38 +08:00
Andy Kaylor
58b91d10a4
[CIR][NFC] Upstream LValueBaseInfo handling (#134928)
Previous implementations that used the cir::LValue class omitted hanling
of the LValueBaseInfo class, which tracks information about the basis
for the LValue's alignment. As more code was upstreamed from the
incubator, we were accumulating technical debt by adding more places
where this wasn't handled correctly. This change puts the interfaces in
place to track this information.

The information being tracked isn't used yet, so no functional change is
intended. The tracking is being added now because it will become more
difficult to add it as more features are implemented.
2025-04-09 15:27:50 -07:00
Amr Hesham
262b9b5153
[CIR][Upstream] Local initialization for ArrayType (#132974)
This change adds local initialization for ArrayType

Issue #130197
2025-04-03 19:25:25 +02:00