Skip to content

Conversation

@wannacu
Copy link

@wannacu wannacu commented Aug 27, 2025

Remove redundant call while here

andykaylor and others added 30 commits August 10, 2025 20:01
…m#1559)

During the initial upstreaming of `cir.struct` support, a request was
made to rename `cir.struct` to `cir.record` for consistency with its
multiple uses. This change makes the modification along with renaming
various other related classes. I've attempted to also update variable
names and comments to keep everything consistent.

This creates an unfortunate name collision between cir::RecordType and
clang::RecordType, but the impact of that overlaps was relatively small.

The only intended behavioral change is in the names used in the emitted
CIR files and diagnostics.
…vm#1563)

This change reverse the polarity of the cir::RecordType incomplete
attribute, making the attribute name "complete" and reversing all checks
in the code accordingly. The asm layout still prints "incomplete" for
records that are not complete and treats the absence of this text as
meaning that the definition provided is complete.

No functional change is intended.
When we create a `cir.record` type, we track the `RecordKind` according
to whether the source code declared the type using `struct` or `class`
even though these are semantically equivalent. The distinction is used
in naming the type when we lower to the LLVM dialect.

This change updates the code to remove the last place where we were
handling class and struct records differently.
Negative shift amounts are undefined behavior in C and C++. Because of
that we can always zero-extend the shift amount which is slightly faster
on certain architectures (e. g. x86). This also matches the behavior of
the original clang Codegen.

Backported from llvm/llvm-project#133405

Co-authored-by: Morris Hafner <[email protected]>
`cir.trap` corresponds to two operations, `call @llvm.trap` and
`unreachable`. See the test case `Lowering/intrinsics.cir`.

Co-authored-by: Yue Huang <[email protected]>
Currently, the following code snippet fails with a crash during CodeGen
```
class C {
public:
  ~C();
  void operator=(C);
};

void d() {
  C a, b;
  a = b;
}
```
with error: 
```
mlir::Block* clang::CIRGen::CIRGenFunction::getEHResumeBlock(bool, cir::TryOp): Assertion `tryOp && "expected available cir.try"' failed.
```
in CIRGenCleanup [these
lines](https://github.com/llvm/clangir/blob/204c03efbe898c9f64e477937d869767fdfb1310/clang/lib/CIR/CodeGen/CIRGenCleanup.cpp#L615C1-L617C6)
don't check if there is a TryOp when at the end of the scope chain
before
[getEHResumeBlock](https://github.com/llvm/clangir/blob/204c03efbe898c9f64e477937d869767fdfb1310/clang/lib/CIR/CodeGen/CIRGenException.cpp#L764)
is called causing the crash, because it contains an assertion.

This PR fixes this and adds a simple test for a case like this.
…lvm#1567)

This is a just small fix that cover the case when the global union is
declared with `static` keyword and one of the its users is an array
Add `TypeBuilderWithInferredContext` to each CIR type that supports MLIR
context inference from its parameters.
We have been using RecordLayoutAttr to "cache" data layout information
calculated for records. Unfortunately, it wasn't actually caching the
information, and because each call was calculating more information than
it needed, it was doing extra work.

This replaces the previous implementation with a set of functions that
compute only the information needed. Ideally, we would like to have a
mechanism to properly cache this information, but until such a mechanism
is implemented, these new functions should be a small step forward.
Backport support for zero init Vector type
This changes the alias prefix for record types to make it less general.
Introduce common base class for attributes with single type parameter.
…nups (llvm#1581)

The following code snippet crashes during CIR CodeGen using `clang
tmp.cpp -Xclang -emit-cir -S -o -`:
```
#include <vector>

void foo() {
  std::vector<int> v(1);
}
```
The crash is: 
```
mlir::Operation* mlir::Block::getTerminator(): Assertion `mightHaveTerminator()' failed.
```
What happens is the scope created
[here](https://github.com/llvm/clangir/blob/c7b27ece0971c632f2ebec26bc855ee9b118ffcc/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp#L2370C1-L2381C10)
is malformed. The operations inside the scope using
`--mlir-print-assume-verified` looks something like:
```
%0 = cir.alloca !cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>, !cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>, ["ref.tmp0"] {alignment = 1 : i64}
%1 = cir.load <<UNKNOWN SSA VALUE>> : !cir.ptr<!cir.int<u, 64>>, !cir.int<u, 64>
%2 = cir.load <<UNKNOWN SSA VALUE>> : !cir.ptr<!cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>>, !cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>
cir.call @_ZNSaIiEC1ERKS_(%0, %2) : (!cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>, !cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>) -> () extra(#cir<extra({nothrow = #cir.nothrow})>)
%3 = cir.call @_ZNSt6vectorIiSaIiEE11_S_max_sizeERKS0_(%0) : (!cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>) -> !cir.int<u, 64> extra(#cir<extra({nothrow = #cir.nothrow})>)
%4 = cir.cmp(gt, %1, %3) : !cir.int<u, 64>, !cir.bool
cir.yield %4 : !cir.bool              
cir.call @_ZNSaIiED1Ev(%0) : (!cir.ptr<!cir.record<class "std::allocator<int>" padded {!cir.int<u, 8>} #cir.record.decl.ast>>) -> () extra(#cir<extra({nothrow = #cir.nothrow})>)
```
`_ZNSaIiED1Ev` is `std::allocator<int>::~allocator()`. So, the
destructor comes after the YieldOp has been created, which is wrong. The
destructor comes from the destruction of
[`RunCleanupScope`](https://github.com/llvm/clangir/blob/c7b27ece0971c632f2ebec26bc855ee9b118ffcc/clang/lib/CIR/CodeGen/CIRGenFunction.h#L1369)
since `LexicalScope` inherits from it. RunCleanupsScope's dtor should
come before the yield is created!

This PR fixes this by calling `ForceCleanup` before creating the yield,
so the YieldOp becomes the last operation in the scope. I found this bug
using the code snippet above, but I have added a reduced version, using
[creduce](https://github.com/csmith-project/creduce), as a test, because
[std-cxx.h](https://github.com/llvm/clangir/blob/main/clang/test/CIR/Inputs/std-cxx.h)
doesn't quite replicate `std::vector` correctly.
In this PR I extended the incubator implementation to support global
init for VectorType
Backport `VectorType::verify` implementation with test for invalid cases
- Adds `CIR_` prefixes to integer type constraints types to disambiguate their names from other dialects.
- Renames `PrimitiveInt` to `CIR_AnyFundamentalIntType` to align more with constraint conventions.
- Adds bunch of helper constraint classes to be able to define base types to reduce clutter of necessary type casts.
- Reworks constraints to use `CIR_ConfinedType` to avoid repeating validation checks. 
- Adds `IntOfWidths` variadic bitwidth constraint to reduce boilerplate code needed to handle multi-bitwidth parameters. 
- Constraints are moved into a separate file, which starts decoupling of constraints and types to remove the cyclic dependency between types and attributes and will eventually help fix several outstanding TODOs.
This refactors cir floating point type constraints, and fixes long double verifier to use constraints directly.
Apply `CIR_AnyIntOrFloatType` type constraint on element type and rename `elementTy` to `elementType`.
AmrDeveloper and others added 15 commits August 21, 2025 11:02
Backport the Comma Operator for ComplexType from the upstream
This PR fixes an issue when parsing `TBAAAttr` derived attributes.
The root cause of the issue is that the RTTI system is not capable of
downcasting `mlir::Attribute` to the `BaseType`, which is
`cir::TBAAAttr`, since each attribute has its unique TypeID. As such,
the default generated parser fails, because the `dyn_cast` to
`cir::TBAAAttr` fails (this happens for example with the attached test
case).
If anyone can think of a solution that wouldn't require explicitly
listing all the attributes I'm happy to modify it.
This PR adds support for the **discrete bit-field layout**, which is
used in the Microsoft bit-field ABI.

Since ClangIR does not currently support the Microsoft ABI, this uses
the compiler flag
```bash
-mms-bitfields          Set the default structure layout to be compatible with the Microsoft compiler standard
```
Fixes llvm#1798
Adding these so work can be done in parallel for any PTX related
intrinsic.

related llvm#1813
This PR backports support for volatile bit-fields in AAPCS.  
The corresponding upstream PRs are:  
- llvm/llvm-project#151252
- llvm/llvm-project#151875
…vm#1859)

1. **Catch Entry Parsing**: `parseCatchEntry` in `CIRDialect.cpp` now
properly handles `#cir.unwind` attributes

2. **Resume Operation**: Fix record definition of `cir.resume` in order
to handle locations correctly

## Issue:
- `error: expected '{' to begin a region` when parsing `catch
[#cir.unwind {`
- `error: undefined symbol alias id` when parsing `cir.resume loc(#loc)`
Implemented missing feature for issue llvm#1793. Also implemented LLVM
lowering for the hot attribute, and added a new test case.
@llvm llvm deleted a comment Sep 2, 2025
@llvm llvm deleted a comment Sep 2, 2025
Copy link
Collaborator

@xlauko xlauko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update PR name to contain [CIR] prefix.

Also it would be nice to provide in the PR description the actual bug.

@bcardosolopes bcardosolopes changed the title Fix MLIRCIRInterfaces and clangFrontendTool build error [CIR] Fix MLIRCIRInterfaces and clangFrontendTool build error Sep 3, 2025
@lanza lanza force-pushed the main branch 2 times, most recently from 8acaf96 to 58135ea Compare October 20, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.