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
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.