73 Commits

Author SHA1 Message Date
Morris Hafner
0045bfca9c
[CIR} Add support for static member variable instantiation (#153200)
This patch handles both implicit and explicit template instantiations of
template class static member variables.
2025-08-13 18:03:05 +02:00
Andy Kaylor
54f53c988d
[CIR] Introduce the CIR global_view attribute (#153044)
This change introduces the #cir.global_view attribute and adds support
for using that attribute to handle initializing a global variable with
the address of another global variable.

This does not yet include support for the optional list of indices to
get an offset from the base address. Those will be added in a follow-up
patch.
2025-08-12 10:02:00 -07: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
gitoleg
d97f0e9364
[CIR] add support for file scope assembly (#152093)
This PR adds a support for file scope assembly in CIR.
2025-08-07 10:12:58 -07:00
Morris Hafner
4f166513df
[CIR] Upstream support for variable template specializations (#151069) 2025-08-06 16:43:42 +02:00
Andy Kaylor
ba2edbd0c8
[CIR] Fix warnings related to unused variables in release builds (#151412)
This fixes a number of warnings in release builds due to variables that
were only being used in asserts. Some of these variables will later be
used in non-debug code, but for now they are unused in release builds.
2025-07-31 14:54:56 -07:00
Morris Hafner
8a5d363123
[CIR] Upstream support for function-level variable decompositions (#151073)
This implements support for structured bindings on a function scope
level. It does not add support for global structured bindings.
2025-07-31 17:34:41 +02:00
Morris Hafner
77f8a9115e
[CIR] Support more declarations without any codegen (#151076)
This patch adds or completes support for a couple of top level
declaration types that don't emit any code: Most notably these include
Concepts, static_assert and type aliases.
2025-07-31 16:33:20 +02:00
Morris Hafner
1132562bf3
[CIR] Add support for C++ conversion operators (#151066)
This fairly simple addition enables codegen for C++ conversion operators
2025-07-30 03:34:52 +02:00
jeremyd2019
a3228b6bf9
[Clang][Cygwin] Enable few conditions that are shared with MinGW (#149637)
The Cygwin target is generally very similar to the MinGW target. The
default auto-import behavior, the default calling convention, the
`.dll.a` import library extension, the `__GXX_TYPEINFO_EQUALITY_INLINE`
pre-define by `g++`, and the long double configuration.

Co-authored-by: Mateusz Mikuła <oss@mateuszmikula.dev>
2025-07-29 10:01:43 -07:00
Andy Kaylor
32779cd698
[CIR] Add proper handling for no prototype function calls (#150553)
This adds standard-comforming handling for calls to functions that were
declared in C source in the no prototype form.
2025-07-29 09:16:17 -07:00
Amr Hesham
2762a079ee
[CIR] Implement LValueBitcast for ComplexType (#150668)
This change adds support for LValueBitcast for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-28 20:29:38 +02:00
Morris Hafner
f78d6caadc
[CIR] Add Minimal Destructor Definition Support (#144719)
This patch upstreams support for writing inline and out of line C++
destructor definitions. Calling a destructor implcitly or explicitly is
left for a future patch.

Because of that restriction complete destructors (D2 in Itanium
mangling) do not call into the base (D1) destructors yet but simply
behave like a base destructor. Deleting (D0) destructor support is not
part of this patch.

Destructor aliases aren't supported, either. Because of this compilation
with -mno-constructor-aliases may be required to avoid running into NYI
errors.
2025-07-14 19:02:00 +02:00
Andy Kaylor
b415db02e7
[CIR] Add handlers for 'using enum' and namespace alias (#148011)
These decl types don't require any code generation, though when debug
info is implemented, we will need to add handling for that. Until then,
we just need to have a handler so they don't generate an NYI error.
2025-07-10 16:16:37 -07:00
Sirui Mu
1841b021c6
[CIR] Add OptInfo attribute (#146261)
This patch adds the `#cir.opt_info` attribute which holds module-level
optimization information.
2025-07-02 23:29:43 +08: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
74cabdb806
[CIR] Add basic support for operator new (#145802)
This adds the code to handle operator new expressions in ClangIR.
2025-06-27 09:43:26 -07:00
Andy Kaylor
3e9fd4966d
[CIR] Add support for constructor aliases (#145792)
This change adds support for handling the -mconstructor-aliases option
in CIR. Aliases are not yet correctly lowered to LLVM IR. That will be
implemented in a future change.
2025-06-27 09:43:05 -07:00
Amr Hesham
720d7e09b3
[CIR][NFC] Fix an unused variable warning (#145922)
This fixes a warning where a variable assigned in 'if' statement wasn't
referenced again.
2025-06-26 18:32:38 +02:00
Andy Kaylor
1e45ea12db
[CIR] Add support for function linkage and visibility (#145600)
This change adds support for function linkage and visibility and related
attributes. Most of the test changes are generalizations to allow
'dso_local' to be accepted where we aren't specifically testing for it.
Some tests based on CIR inputs have been updated to add 'private' to
function declarations where required by newly supported interfaces.

The dso-local.c test has been updated to add specific tests for
dso_local being set correctly, and a new test, func-linkage.cpp tests
other linkage settings.

This change sets `comdat` correctly in CIR, but it is not yet applied to
functions when lowering to LLVM IR. That will be handled in a later
change.
2025-06-25 10:59:30 -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
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
Andy Kaylor
16dda4d3f4
[CIR] Add support for completing forward-declared types (#143176)
This adds the needed handling for completing record types which were
previously declared leading us to create an incomplete record type.
2025-06-06 12:54:43 -07:00
Andy Kaylor
6c1ca07586
[CIR] Add decl case for template specialization (#143029)
This change adds the switch case to allow template specialization to
pass through emitTopLevelDecl without issuing an error.
2025-06-05 16:50:36 -07:00
Andy Kaylor
e2ae39d0df
[CIR] Add empty handlers for Using and UsingShadow decls (#143032)
This adds emitTopLevelDecl "handlers" for Using and UsingShadow. These
don't actually need any handling, but they need to be present in the
switch to avoid hitting the default handler, which issues a diagnostic
about the decl kind not being implemented.

There are several other decl kinds that don't need any handling. Those
will be added when I have test cases for them.
2025-06-05 16:05:01 -07:00
Andy Kaylor
af54790ca0
[CIR] Defer emitting function definitions (#142862)
This change implements deferring function definition emission until
first use.
2025-06-05 13:08:29 -07:00
Andy Kaylor
f327d6d4c3
[CIR] Defer definitions of global variables until they are used. (#142496)
This change adds support for deferring global variable definitions until
first use whenever it is possible to do so. Although deferring function
definitions uses much of the same implementation, function deferral will
be added in a follow-up change.
2025-06-04 14:34:54 -07:00
Andy Kaylor
19dcec979c
[CIR] Support inline C++ member function definitions (#142484)
This change upstreams the code to support emitting inline C++ function
definitions, including the ASTConsumer handler for inline definitions
and the code to load the 'this' pointer.

This necessitates introducing the Itanium CXXABI class. No other CXXABI
subclasses are supported at this time. The Itanium CXXABI is used for
AppleARM64, which will require its own handler for a few special cases
(such as array cookies) later.
2025-06-02 17:13:19 -07:00
Andy Kaylor
08190e55ab
[CIR] Fix dso_local and comdat handling for global vars (#142214)
This change adds extra processing of global variable definitions to
correctly set the dso_local and comdat attributes.
2025-06-02 13:46:17 -07:00
Andy Kaylor
0e90a846d6
[CIR] Add support for global linkage and visibility (#141973)
This change adds support for the CIRGlobalValueInterface and attributes
for visibility and comdat to GlobalOp.

The comdat attribute isn't correctly calculated yet, but it was required
for the CIRGlobalValueInterface interface. There are also some cases
where dso_local isn't set correctly, but it is better than it was before
this change. Those issues will be addressed in a future patch.
2025-05-30 13:36:48 -07:00
Andy Kaylor
b574c811e8
[CIR] Defer declarations and tentative definitions (#141700)
This change adds code to defer emitting declarations and tentative
definitions until they are referenced or trigger by a call to
CompleteTentativeDefinition. This is needed to avoid premature handling
of declarations and definitions that might not be referenced in the
current translation unit. It also avoids incorrectly adding an
initializer to external declarations.

This change also updates the way the insertion location for globals is
chosen so that all globals will be emitted together at the top of the
module. This makes no functional difference, but it is very useful for
writing sensible tests.

Some tests are modified in this change to reorder global variables so
that they can be checked in the order in which they will be emitted.
2025-05-28 13:53:30 -07: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
Andy Kaylor
3ce74c3b40
[CIR] Upstream support for string literals (#140796)
This adds the minimal support needed to handle string literals.
2025-05-21 11:32:50 -07:00
Andy Kaylor
a0c515a9ef
[CIR] Upstream support for C++ member function calls (#140290)
This change adds the support needed to handle a C++ member function
call, including arranging the function type with an argument added for
the 'this' parameter. It was necessary to introduce the class to handle
the CXXABI, but at this time no target-specific subclasses have been
added.
2025-05-19 14:42:50 -07:00
Andy Kaylor
fa2263b309
[CIR][NFC] Use arrangeFunctionDeclaration to build function types (#139787)
This change replaces the simplified call that we were previously using
to convert the function type provided by a global declaration to the CIR
function type. We now go through 'arrangeGlobalDeclaration' which builds
the function type in a more complicated manner. This change has no
observable differences for the currently upstreamed CIR support, but it
is necessary to prepare for C++ member function calls, which require the
extra handling.
2025-05-16 09:08:16 -07:00
Iris Shi
3f6ef4ecfb
[CIR] Cleanup support for C functions (#136854)
This adds basic handling for non-prototype functions in C.

Closes #130200.
2025-05-13 09:47:21 -07:00
Ankur Ahir
3e393d9aac
[CIR] Upstream enum support (#136807) 2025-05-11 17:52:57 +08:00
Andy Kaylor
e882590083
[CIR] Refactor global variable emission and initialization (#138222)
When global variable support was initially upstreamed, we took some
shortcuts and only implemented the minimum support for simple variables
and constant initializers.

This change refactors the code that creates global variables to
introduce more of the complexities that are present in the incubator and
the classic codegen. I can't really say this is NFC, because the code
executed is very different and it will report different NYI diagnostics,
but for the currently implemented cases, it results in the same output.
2025-05-02 16:54:29 -07:00
Erich Keane
0e07478a5e
[CIR] Implement lowering for LinkageSpecDecl (#137634)
Like the NamespaceDecl, this is just emitted as a decl-context, where
all its internal declarations get emitted for it. The incubator doesn't
seem to have any good tests for this, so I wrote what I could think of
as a half-decent test for this one, though the lowering doesn't manage
whether these should be mangled, so the test is mostly just for
spot-checking purposes.

I'm implementing this as it will make writing further tests for future
features a little easier.
2025-04-28 15:23:10 -07:00
Amr Hesham
e44f7760fa
[CIR][NFC] Fix an unused variable warning (#137466)
This fixes a warning where a variable assigned in 'if' statement wasn't referenced again.
2025-04-28 19:06:20 +02:00
Andy Kaylor
8b98612910
[CIR] Fix calling defined functions (#137271)
Until now our function symbol lookup has been assuming that the function
did not exist and creating a definition for it. This caused us to create
a duplicate definition if we ever tried to call a function that was
already defined.

This change fixes that by adding handling for trying to look up existing
global definitions before creating a new one.
2025-04-25 12:08:52 -07:00
Andy Kaylor
b6746b0657
[CIR] Upstream namepsace handling (#137253)
This adds the handlers for Decl::Namespace and Decl::UsingDirective
(which is needed for anonymous namespaces).
2025-04-24 16:42:36 -07:00
Andy Kaylor
7d71164855
[CIR] Upstream support for name mangling (#137094)
We have been using the default names for global symbols to this point.
This change introduces proper name mangling for functions.

This requires introducing a CXXABI class in the CIRGenModule. Because
only target independent name mangling is handled in this patch, the
CXXABI class does not require a target-specific implementation. The
general mechanism for selecting an implementation is introduced here,
but the actual target-specific subclasses are deferred until needed.
2025-04-24 14:24:19 -07:00
Andy Kaylor
daf3c985f7
[CIR] Upstream support for typedef and type aliases (#136335)
Nothing is actually needed in ClangIR to support typedef and type
aliases, but the Decl kinds need to be explicitly ignored in the
emitDecl handlers to avoid hitting the default NYI errors. This change
does that and adds tests.
2025-04-18 12:52:51 -07:00
Sirui Mu
78857e7263
[CIR] cir.call with scalar return type (#135552)
This PR introduces support for calling functions with a scalar return
type to the upstream. This PR also includes an initial version of
`CIRGenTargetInfo` and related definitions which are essential for the
CIRGen of call ops.

Related to #132487 .
2025-04-17 22:38:37 +08:00
Andy Kaylor
cd7d2c3bf8
[CIR] Upstream minimal support for structure types (#135105)
This change adds minimal support for structure types. To keep the
initial change small, only incomplete declarations are being supported
in this patch. More complete support will follow.
2025-04-14 14:40:19 -07:00
Andy Kaylor
abe3b90b3f
[CIR] Fix warnings, again! (#135284)
The calleeDecl var will be used in the near future, so I left it. At
least for clang, the [[maybe_unused]] attribute takes care of the
warnings related to that variable. The other warning was a simple lack
of return after errorNYI.
2025-04-11 10:57:08 -07:00