13020 Commits

Author SHA1 Message Date
Timm Baeder
1b1f352cb9
[clang][bytecode] Handle reads on zero-size arrays (#152706) 2025-08-08 16:03:02 +02:00
Timm Baeder
3ea76af3a1
[clang][bytecode][NFC] Remove a useless local variable (#152711)
We can just check NonNullArgs.empty().
2025-08-08 15:52:23 +02:00
Timm Baeder
d54516b9ad
[clang][bytecode][NFC] Use an existing local variable (#152710)
Instead of calling getSize() again.
2025-08-08 15:41:58 +02:00
Timm Baeder
8d26252eec
[clang][bytecode][NFC] Dead blocks are always uninitialized (#152699)
We always call the descriptor dtor before, so they are never
initialized.
2025-08-08 14:57:38 +02:00
Timm Baeder
fde9ee1ac2
[clang][bytecode] Don't deallocate dynamic blocks with pointers (#152672)
This fixes the edge case we had with variables pointing to dynamic
blocks, which forced us to convert basically *all* dynamic blocks to
DeadBlock when deallocating them.

We now don't run dynamic blocks through InterpState::deallocate() but
instead add them to a DeadAllocations list when they are deallocated but
still have pointers.

As a consequence, not all blocks with Block::IsDead = true are
DeadBlocks.
2025-08-08 13:02:01 +02:00
Helena Kotas
7a16a1ddb2
[HLSL] Add isHLSLResourceRecordArray method to clang::Type (#152450)
Adds the `isHLSLResourceRecordArray()` method to the `Type` class. This method returns `true` if the `Type` represents an array of HLSL resource records. Defining this method on `Type` makes it accessible from both sema and codegen.
2025-08-07 13:38:24 -07:00
Timm Baeder
193995d5a2
[clang][bytecode] Handle more invalid member pointer casts (#152546) 2025-08-07 19:24:01 +02:00
Timm Baeder
3b5cc2dc63
[clang][bytecode][NFC] Refactor DynamicAllocator a bit (#152510)
Use empty()-style functions instead of exposing the size if we don't
need it.
2025-08-07 17:03:53 +02:00
Timm Baeder
4784585747
[clang][bytecode][NFC] Remove unnecessary local variable (#152468)
Desc is only used once and we can get that information from the Block as
well.
2025-08-07 12:39:32 +02:00
Timm Baeder
c869ef6ebc
[clang][bytecode] Refactor Check* functions (#152300)
... so we don't have to create Pointer instances when we don't need
them.
2025-08-07 11:32:39 +02:00
erichkeane
b291d02a93 [OpenACC][NFCI] Add extra data to firstprivate recipe AST node
During implementation I found that I need some additional data in the
AST node for codegen, so this patch adds the second declaration
reference.
2025-08-06 10:18:34 -07:00
Timm Baeder
71dbf1492b
[clang][bytecode][NFC] Remove Descriptor::MoveFn (#152317)
We don't use this anymore.
2025-08-06 17:41:53 +02:00
Timm Baeder
8704ca0fb8
[clang][ExprConst] Consider integer pointers of value 0 nullptr (#150164)
When casting a 0 to a pointer type, the IsNullPtr flag was always set to
false, leading to weird results like a pointer with value 0 that isn't a
null pointer.

This caused

```c++
struct B { const int *p;};
template<B> void f() {}
template void f<B{nullptr}>();
template void f<B{fold(reinterpret_cast<int*>(0))}>();
```

to be valid code, since nullptr and (int*)0 aren't equal. This seems
weird and GCC doesn't behave like this.
2025-08-06 16:49:00 +02:00
Timm Baeder
90d1d23507
[clang][bytecode] Overrride locs for certain CXXConstructExprs (#152185)
Do it only if we will end up skipping the initializer anyway because
it's a trivial copy or move constructor.
2025-08-06 09:07:40 +02:00
keinflue
81ed75679d
[clang] Fix constant evaluation of member pointer access into sibling class. (#150829)
HandleMemberPointerAccess considered whether the lvalue path in a member
pointer access matched the bases of the containing class of the member,
but neglected to check the same for the containing class of the member
itself, thereby ignoring access attempts to members in direct sibling
classes.

Fixes #150705.
Fixes #150709.
2025-08-05 14:44:15 -07:00
erichkeane
258997c16e [OpenACC][NFCI] Add 'InitRecipes' to 'firstprivate' AST node
This patch adds the 'init recipes' to firstprivate like I did for
'private', so that we can properly init these types.  At the moment,
the recipe init isn't generated (just the VarDecl), and this isn't
really used anywhere as it will be used exclusively in Codegen.
2025-08-05 09:26:47 -07:00
Timm Baeder
dc7c3c2b2b
[clang][bytecode] Disable location tracking for implicit field inits (#150190) 2025-08-05 13:14:01 +02:00
Timm Baeder
8f7dfc689c
[clang][bytecode] Call CheckLocalLoad in GetLocal (#152090)
I forgot to call this here as well. It was only used in the EvalEmitter
implementation of the function. Also fix a problem where we didn't
diagnose out-of-lifetime reads here.
2025-08-05 08:46:22 +02:00
Timm Baeder
df3f629735
[clang][bytecode][NFC] Only collect non-null args if we have to (#152074)
Only do this if the function really has a NonNullArg.
2025-08-05 07:54:25 +02:00
Timm Baeder
d02714c85a
[clang][bytecode] Return success for pointers to locals (#151980)
They aren't valid, but we leave them successful here and
CheckLValueConstantExpression will diagnose them later.
2025-08-05 05:18:47 +02:00
Erich Keane
66eadbb235
[OpenACC][CIR] Implement 'init' lowering for private clause vars (#151781)
Previously, #151360 implemented 'private' clause lowering, but didn't
properly initialize the variables. This patch adds that behavior to make
sure we correctly get the constructor or other init called.
2025-08-04 11:14:58 -07:00
Timm Baeder
105963ad5e
[clang][bytecode] Use SmallVector for Function::Code (#151821)
This way we can use resize_for_overwrite, which is slightly more
efficient:

https://llvm-compile-time-tracker.com/compare.php?from=7bdab76350970a3ac471da6a30035dd5b7ef14f3&to=b55bd2c74f230e2150e54b0523db6a8426eab54d&stat=instructions:u
2025-08-04 17:03:58 +02:00
Kazu Hirata
39ca925ffe
[AST] Use llvm::iterator_range::empty (NFC) (#151904) 2025-08-04 07:40:38 -07:00
Michael Buch
cd8f348c69
[clang][Attr] Remove 'literal label' form of AsmLabelAttr (#151858)
This was added purely for the needs of LLDB. However, starting with
https://github.com/llvm/llvm-project/pull/151355 and
https://github.com/llvm/llvm-project/pull/148877 we no longer create
literal AsmLabels in LLDB either. So this is unused and we can get rid
of it.

In the near future LLDB will want to add special support for mangling
`AsmLabel`s (specifically
https://github.com/llvm/llvm-project/pull/149827).
2025-08-04 14:34:45 +01:00
Timm Baeder
76e38ca981
[clang][bytecode] Try to load primitive values directly (#151833)
Instead of doing a GetPtrLocal + Load or GetPtrGlobal + Load pair, try
to load the value directly.
2025-08-04 12:28:33 +02:00
Corentin Jabot
28ed57eda8
[Clang] Initial support for P2841 (Variable template and concept template parameters) (#150823)
This is a first pass at implementing
[P2841R7](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2841r7.pdf).

The implementation is far from complete; however, I'm aiming to do that
in chunks, to make our lives easier.

In particular, this does not implement
 - Subsumption
 - Mangling
- Satisfaction checking is minimal as we should focus on #141776 first
(note that I'm currently very stuck)

FTM, release notes, status page, etc, will be updated once the feature
is more mature. Given the state of the feature, it is not yet allowed in
older language modes.

Of note: 
- Mismatches between template template arguments and template template
parameters are a bit wonky. This is addressed by #130603
- We use `UnresolvedLookupExpr` to model template-id. While this is
pre-existing, I have been wondering if we want to introduce a different
OverloadExpr subclass for that. I did not make the change in this patch.
2025-08-04 08:51:22 +02:00
Timm Baeder
8259be65c7
[clang][bytecode] Remove unused includes (#151848)
UnsignedOrNone.h from PrimType.h and ASTLambda.h from Function.h.
2025-08-03 08:52:03 +02:00
Timm Baeder
c304a2bb0c
[clang][bytecode][NFC] Code size is always aligned (#151824)
We don't need to align Code.size(), since we always resize it to aligned
values, so Code.size() is always aligned.
2025-08-02 17:29:11 +02:00
Kazu Hirata
1b0285671e
[AST] Use llvm::iterator_range::empty (NFC) (#151800)
With empty, we don't have to repeat the whole expression.
2025-08-02 08:09:33 -07:00
Timm Baeder
a1dfcc6e81
[clang][bytecode] Fix D3DCOLORtoUBYTE4 hlsl test (#151819)
HLSL is using CK_FloatingToIntegral casts to cast to vectors, which we
don't support (neither does the current interpreter). Also fix a crash
when trying to promote the HLSL bool, which can't be promoted it seems.
2025-08-02 16:18:38 +02:00
Timm Baeder
834621564f
[clang][bytecode] Don't call ctor of primitive array elements (#151725)
We don't do that for single primitive variables, so avoid it for
primitive array elements as well.
2025-08-02 14:55:07 +02:00
Timm Baeder
41803a2414
[clang][bytecode] Replace MoveFn With DtorFn + memcpy (#151717)
First, the old MoveFn was rather inefficient, since the dead data cannot
ever be accessed anyway.

Second, there was a problem where the only reason a block still had a
pointer to it (and thus was made into a DeadBlock instead of simply
being deallocated) as that a nested field in the block pointed to the
block itself.

Fix this by calling the dtor function unconditionally. If the block
*still* has pointers after that, we really need to create a DeadBlock
for it.
2025-08-02 14:47:49 +02:00
Timm Baeder
d7c75629b2
[clang][ExprConst] Call FastEvaluateAsRValue in isCXX11ConstantExpr (#151466)
This was one case where we didn't call `FastEvaluateAsRValue` before
going through `EvaluateAsRValue`.
Also replace the `EvalResult` parameter with an `APValue` one, since
`FastEvaluateAsRVaule` only needs that.


Small gains:
https://llvm-compile-time-tracker.com/compare.php?from=112af8e62e734938547d50eeb7b416c8dd666f45&to=b2ea804b9e22b7f37eb1b07b01c0a8057275fe4a&stat=instructions:u
2025-08-01 17:46:44 +02:00
Timm Baeder
1e8b65d8cd
[clang][bytecode][NFC] Add a FIXME comment for heap allocations (#151700) 2025-08-01 16:30:43 +02:00
Timm Baeder
d8ca85a184
[clang][ExprConst] Remove Loc param (#151461)
The Loc param to these functions was weird and not always set in error
cases. It wasn't reliable to use.

This was almost entirely unused inside of clang and the one call site
that used the returned source location doesn't make a difference in
practice.
2025-08-01 14:09:06 +02:00
Timm Baeder
f4aaf6fe5c
[clang][bytecode] Fix a crash in codegen (#151515)
getRecord() can return nullptr if any one of the fields does, in this
case because the array is too large for us to allocate.
2025-07-31 15:50:02 +02:00
Timm Baeder
2c00df3c93
[clang][bytecode][NFC] Remove LabelScope (#151498)
It did almost nothing
2025-07-31 13:34:21 +02:00
Timm Baeder
1b9ee0bb74
[clang][bytecode] Fix diagnostics for int128 enums (#151340)
CheckEnumValue was not handling PT_IntAP/PT_IntAPS.
2025-07-31 05:59:17 +02:00
M. Zeeshan Siddiqui
70471f08ee
[Sema] Fix -Wunreachable-code false negative when operands differ only by implicit casts (#149972)
## Motivation  
`-Wunreachable-code` missed—or in rare cases crashed on—tautological
comparisons such as

```cpp
x != 0 || x != 1.0   // always true
x == 0 && x == 1.0   // always false
```

when the *same* variable appears on both sides but one operand goes
through a floating‑rank promotion that is target‑dependent. On back‑ends
with **native half‑precision** (`_Float16` / `__fp16`) such as
AArch64 `+fullfp16`, no promotion occurs, so the cast stacks between the
two operands differ and the existing heuristic bails out.

## Technical description 
* **Extends `Expr::isSameComparisonOperand()`** – the helper now ignores
parentheses **and value‑preserving implicit casts**
(`CK_LValueToRValue`, floating‑rank `CK_FloatingCast`) before comparing
the underlying operands. This prevents floating‑rank promotions and
lvalue‑to‑rvalue conversions from blocking the unreachable‑code
diagnostic on targets with native FP16.
*No change needed in `CheckIncorrectLogicOperator`; it simply benefits
from the improved helper.*
* **Regression test** – `warn-unreachable_crash.cpp` updated to cover
both the promoted case (x86‑64) and the native‑half case
(AArch64 `+fullfp16`).
* **Docs** – release‑note bullet added under *Bug Fixes in This
Version*.

@ziqingluo-90 @yronglin Could you please review promptly? (feel free to
also merge it on my behalf) Thanks!

Fixes #149967

Co-authored-by: Zeeshan Siddiqui <mzs@ntdev.microsoft.com>
2025-07-31 09:21:59 +08:00
Eli Friedman
0bbe1b30fa
[clang] Forbid reinterpret_cast of function pointers in constexpr. (#150557)
This has been explicitly forbidden since C++11, but somehow the edge
case of converting a function pointer to void* using a cast like
`(void*)f` wasn't handled.

Fixes #150340 .
2025-07-30 18:15:17 -07:00
Sander de Smalen
254bfe23e3 [Clang][AArch64] Expect valid FunctionDecl in IsArmStreamingFunction
This follows from a conversation on #150592 where we decided to
split out this change and commit it separately.

The rationale is that FunctionDecl must be sufficiently parsed/created
in order to tell whether it is a streaming function.
2025-07-30 15:04:47 +00:00
Timm Baeder
3c62303ac3
[clang][bytecode] Clean up {Compiler,Interp}.h (#151335)
Remove else after return and remove some unused includes.
2025-07-30 16:04:30 +02:00
Timm Baeder
fb49c6784a
[clang][bytecode] Move Pointer::{Prev,Next} into BlockPointer (#151097)
They are only relevant for block pointers.
2025-07-30 10:17:21 +02:00
Aaron Ballman
30a5d569b2
[C23] AST equivalence of attributes (#151196)
Implicitly declared types (like __NSConstantString_tag, etc) will be
declared with visibility attributes. This causes problems when merging
ASTs because we currently reject declaration merging for declarations
with attributes.

This relaxes that restriction somewhat; implicit declarations can now
have attributes when merging; we assume that if the compiler generated
it, it's fine.
2025-07-29 14:09:02 -04:00
Aaron Ballman
6a22580305
Switch sanity check to assert; NFC (#151181)
This was written out of an abundance of caution because the changes were
being added to the release branch. Now we can be a little less cautious
and switch to using an assert. No behavioral changes are expected.
2025-07-29 13:54:45 -04:00
Aaron Ballman
d2361e43d1
[C23] More improved type compatibility for enumerations (#150946)
The structural equivalence checker was not paying attention to whether
enumerations had compatible fixed underlying types or not.

Fixes #150594
2025-07-29 13:30:52 -04:00
Timm Baeder
4a44a85c89
[clang][bytecode] Add Pointer::initializeAllElements() (#151151)
To initialize all elements of a primitive array at once. This saves us
from creating the InitMap just to destroy it again after all elements
have been initialized.
2025-07-29 19:30:01 +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
Aaron Ballman
315e2e28b1
[C23] Handle type compatibility for enumerations better (#150282)
An enumeration is compatible with its underlying type, which means that
code like the following should be accepted:

  struct A { int h; };
  void func() {
    extern struct A x;
    enum E : int { e };
    struct A { enum E h; };
    extern struct A x;
  }

because the structures are declared in different scopes, the two
declarations of 'x' are both compatible.

Note, the structural equivalence checker does not take scope into
account, but that is something the C standard requires. This means we
are accepting code we should be rejecting per the standard, like:

  void func() {
    struct A { int h; };
    extern struct A x;
    enum E : int { e };
    struct A { enum E h; };
    extern struct A x;
  }

Because the structures are declared in the same scope, the type
compatibility rule require the structures to use the same types, not
merely compatible ones.

Fixes #149965
2025-07-29 08:20:59 -04:00
Timm Baeder
904de95e71
[clang][bytecode][NFC] Fix a few clang-tidy complaints (#150940) 2025-07-28 15:57:49 +02:00