Commit Graph

103358 Commits

Author SHA1 Message Date
Guillot Tony
5d78b78c85 [C2X] N3007 Type inference for object definitions
This patches implements the auto keyword from the N3007 standard
specification.
This allows deducing the type of the variable like in C++:
```
auto nb = 1;
auto chr = 'A';
auto str = "String";
```
The list of statements which allows the usage of auto:

    * Basic variables declarations (int, float, double, char, char*...)
    * Macros declaring a variable with the auto type

The list of statements which will not work with the auto keyword:

    * auto arrays
    * sizeof(), alignas()
    * auto parameters, auto return type
    * auto as a struct/typedef member
    * uninitialized auto variables
    * auto in an union
    * auto as a enum type specifier
    * auto casts
    * auto in an compound literals

Differential Revision: https://reviews.llvm.org/D133289
2023-10-05 08:11:02 -04:00
Bogdan Graur
821dfc392a Revert "[X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2 (#67410)"
Does not respect `__attribute__((target("avx"))`.

This reverts commit ccd5b8db48.
2023-10-05 10:33:44 +00:00
Jonas Hahnfeld
abb9eb2778 [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()
This fixes many unit tests when trying to enable IncrementalExtensions
by default for testing purposes.

Differential Revision: https://reviews.llvm.org/D158415
2023-10-05 12:09:14 +02:00
cor3ntin
c72d3a0966
[Clang] Handle consteval expression in array bounds expressions (#66222)
The bounds of a c++ array is a _constant-expression_. And in C++ it is
also a constant expression.

But we also support VLAs, ie arrays with non-constant bounds.

We need to take care to handle the case of a consteval function (which
are specified to be only immediately called in non-constant contexts)
that appear in arrays bounds.

This introduces `Sema::isAlwayConstantEvaluatedContext`, and a flag in
ExpressionEvaluationContextRecord, such that immediate functions in
array bounds are always immediately invoked.

Sema had both `isConstantEvaluatedContext` and
`isConstantEvaluated`, so I took the opportunity to cleanup that.

The change in `TimeProfilerTest.cpp` is an unfortunate manifestation of
the problem that #66203 seeks to address.

Fixes #65520
2023-10-05 11:36:27 +02:00
Jonas Hahnfeld
3116d60494 [Lex] Introduce Preprocessor::LexTokensUntilEOF()
This new method repeatedly calls Lex() until end of file is reached
and optionally fills a std::vector of Tokens. Use it in Clang's unit
tests to avoid quite some code duplication.

Differential Revision: https://reviews.llvm.org/D158413
2023-10-05 11:04:07 +02:00
Owen Pan
8902f12e61 [clang-format][doc] Update the Linux kernel coding style URL 2023-10-05 01:18:49 -07:00
cor3ntin
49666ec038
[Clang] Fix constant evaluating a captured variable in a lambda (#68090)
with an explicit parameter.

We tried to read a pointer to a non-existent `This` APValue when
constant-evaluating an explicit object lambda call operator (the `this`
pointer is never set in explicit object member functions)

Fixes #68070
2023-10-05 10:17:50 +02:00
Timm Bäder
57147bb253 [clang][Interp] Support LambdaThisCaptures
Differential Revision: https://reviews.llvm.org/D154262
2023-10-05 09:46:15 +02:00
Timm Bäder
4d7f4a7c82 [clang][Interp] Only lazily visit constant globals
Differential Revision: https://reviews.llvm.org/D158516
2023-10-05 09:37:37 +02:00
Timm Baeder
5ef904b5da
[clang][ExprConst] Don't try to evaluate value-dependent DeclRefExprs (#67778)
The Expression here migth be value dependent, which makes us run into an
assertion later on. Just bail out early.

Fixes #67690
2023-10-05 08:42:34 +02:00
Yaxun (Sam) Liu
c6ed5a6125 Revert "[HIP] Support compressing device binary (#67162)"
This reverts commit a1e81d2ead.

Revert "Fix test hip-offload-compress-zlib.hip"

This reverts commit ba01ce6066.

Revert due to sanity fail at

https://lab.llvm.org/buildbot/#/builders/5/builds/37188

https://lab.llvm.org/buildbot/#/builders/238/builds/5955

/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Driver/OffloadBundler.cpp:1012:25: runtime error: load of misaligned address 0xaaaae2d90e7c for type 'const uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment
0xaaaae2d90e7c: note: pointer points here
  bc 00 00 00 94 dc 29 9a  89 fb ca 2b 78 9c 8b 8f  77 f6 71 f4 73 8f f7 77  73 f3 f1 77 74 89 77 0a
              ^
    #0 0xaaaaba125f70 in clang::CompressedOffloadBundle::decompress(llvm::MemoryBuffer const&, bool) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Driver/OffloadBundler.cpp:1012:25
    #1 0xaaaaba126150 in clang::OffloadBundler::ListBundleIDsInFile(llvm::StringRef, clang::OffloadBundlerConfig const&) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Driver/OffloadBundler.cpp:1089:7

Will reland after fixing it.
2023-10-05 00:29:42 -04:00
Kazu Hirata
f37028c2cc
[Support] Rename HashBuilderImpl to HashBuilder (NFC) (#68173)
Commit 9370271ec5 made HashBuilder an
alias for HashBuilderImpl:

  template <class HasherT, support::endianness Endianness>
  using HashBuilder = HashBuilderImpl<HasherT, Endianness>;

This patch renames HashBuilderImpl to HashBuilder while removing the
alias above.
2023-10-04 20:33:38 -07:00
Bill Wendling
9a954c6935 [Clang] Implement the 'counted_by' attribute
The 'counted_by' attribute is used on flexible array members. The
argument for the attribute is the name of the field member in the same
structure holding the count of elements in the flexible array. This
information can be used to improve the results of the array bound sanitizer
and the '__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
    size_t count;
     /* ... */
    struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically
that 'p->array' must have *at least* 'p->count' number of elements available.
It's the user's responsibility to ensure that this relationship is maintained
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than
what's specified by 'p->count'. This would result in an out-of-bounds access not
not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
    p = malloc(MAX(sizeof(struct foo),
                   offsetof(struct foo, array[0]) + count *
                       sizeof(struct bar *)));
    p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement that
'p->array' must have at least 'p->count' number of elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
    p = malloc(MAX(sizeof(struct foo),
                   offsetof(struct foo, array[0]) + count *
                       sizeof(struct bar *)));
    p->count = count + 42;
  }

  void use_foo(int index) {
    p->count += 42;
    p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148381
2023-10-04 18:26:15 -07:00
Matheus Izvekov
6da382d27b
[Clang][Driver] Add new flags to control IR verification (#68172)
Enables or disables verification of the generated LLVM IR.

Users can pass this to turn on extra verification to catch certain types of
compiler bugs at the cost of extra compile time.
2023-10-05 00:50:30 +02:00
Ian Anderson
4ee8c676ee
[Modules] no_undeclared_includes modules (Apple Darwin) don't work the clang modules (#68241)
All of the _Builtin_stdarg and _Builtin_stddef submodules need to be
allowed from [no_undeclared_includes] modules. Split the builtin headers
tests out from the compiler_builtins test so that the testing modules
can be modified without affecting the other many tests that use
Inputs/System/usr/include.
2023-10-04 15:43:17 -07:00
Alexander Richardson
e599422954
[runtimes] Fix parsing of LIB{CXX,CXXABI,UNWIND}_TEST_PARAMS (#67691)
Since 78d649a417 the recommended way to
pass an executor is to use the _TEST_PARAMS variable, which means we now
pass more complicated value (including ones that may contain multiple
`=`) as part of this variable. However, the `REGEX REPLACE` being used
has greedy matches so everything up to the last = becomes part of the
variable name which results in invalid syntax in the generated lit
config file.

This was noticed due to builder failures for those using the
CrossWinToARMLinux.cmake cache file.

---------

Co-authored-by: Vladimir Vereschaka <vvereschaka@accesssoftek.com>
2023-10-04 18:11:37 -04:00
Matheus Izvekov
5099dc341f
[Clang][CodeGen] Fix use of CXXThisValue with StrictVTablePointers (#68169) 2023-10-04 23:41:49 +02:00
Matheus Izvekov
0fb1ad564e
[Clang][CodeGen][NFC] Add (broken) test case for GH67937
This adds a test case for yet unfixed https://github.com/llvm/llvm-project/issues/67937
2023-10-04 22:36:20 +02:00
Björn Schäpers
b6f29191ad
[clang-format][NFC] AlignTokenSequence: Skip loop iteration
When Shift is 0 there does nothing happen in the remainder of the loop,
express that directly.
2023-10-04 22:20:33 +02:00
Arthur Eubanks
b7ac16c70f
[clang] Default x86-64's medium code model -mlarge-data-threshold to 65535 (#67506)
This matches gcc.

This means that by default, under x86-64's medium code model we treat
globals < 2^16 bytes as "small data" and globals >= 2^16 bytes as "large
data".

The previous clang behavior of treating all data as "large data" can be
set with `-mlarge-data-threshold=0`.

See
https://discourse.llvm.org/t/rfc-matching-gccs-mlarge-data-threshold-for-x86-64s-medium-code-model/73727.
2023-10-04 13:06:23 -07:00
Björn Schäpers
7539bcf994
[clang-format][NFC] AlignTokenSequence: Rename Changes[i] to CurrentC…
…hange

To improve debugging experience.
2023-10-04 21:19:56 +02:00
Björn Schäpers
b4a076a12d
[clang-format][NFC] AlignTokens: Rename Changes[i] to CurrentChange (#68152)
To improve debugging experience.
2023-10-04 21:19:21 +02:00
Joseph Huber
49d8a559d3
[LinkerWrapper] Fix resolution of weak symbols during LTO (#68215)
Summary:
Weak symbols are supposed to have the semantics that they can be
overriden by a strong (i.e. global) definition. This wasn't being
respected by the LTO pass because we simply used the first definition
that was available. This patch fixes that logic by doing a first pass
over the symbols to check for strong resolutions that could override a
weak one.

A lot of fake linker logic is ending up in the linker wrapper. If there
were an option to handle this in `lld` it would be a lot cleaner, but
unfortunately supporting NVPTX is a big restriction as their binaries
require the `nvlink` tool.
2023-10-04 14:13:52 -05:00
Pranav Kant
7d21086d0c Revert "[clang] Predefined macros for float128 support (#67196)"
This reverts commit 457f582ffe.
2023-10-04 18:19:24 +00:00
Botond István Hprváth
66c19167f1
[clang] Choose non-templated ctor as deduction guide unambiguously (#66487)
If there are two guides, one of them generated from a non-templated
constructor
and the other from a templated constructor, then the standard gives
priority to
the first. Clang detected ambiguity before, now the correct guide is
chosen.
The correct behavior is described in this paper:
http://wg21.link/P0620R0

Example for the bug: http://godbolt.org/z/ee3e9qG78

As an unrelated minor change, fix the issue
https://github.com/llvm/llvm-project/issues/64020,
which could've led to incorrect behavior if further development inserted
code after a call to
`isAddressSpaceSubsetOf()`, which specified the two parameters in the
wrong order.

---------

Co-authored-by: hobois <horvath.botond.istvan@gmial.com>
2023-10-04 09:11:43 -07:00
Yaxun (Sam) Liu
ba01ce6066 Fix test hip-offload-compress-zlib.hip
and hip-offload-compress-zstd.hip.

For failure https://lab.llvm.org/buildbot/#/builders/231/builds/16710

We cannot do real linking for x86_64 on certain systems, so we
do -### instead.
2023-10-04 11:05:16 -04:00
Aaron Ballman
0152669671 Fix Clang Sphinx build 2023-10-04 10:22:06 -04:00
Alex Bradbury
ca003ee06d
[clang-repl] Disable InterpreterExceptionTest on RISC-V (#68216)
This test fails as .eh_frame handling is not yet implemented for RISC-V
in JITLink. #66067 is proposed to address this.

Skip the test until the issue is resolved. It seems that D159167 enabled
this test for more than just ppc64. As the test always failed, it just
wasn't run until now, I think skipping is the correct interim approach
(as is already done for Arm, Darwin, and others).
2023-10-04 14:33:31 +01:00
Yaxun (Sam) Liu
a1e81d2ead
[HIP] Support compressing device binary (#67162)
Add option -f[no-]offload-compress to clang to enable/disable
compression of device binary for HIP. By default it is disabled.

Add option -compress to clang-offload-bundler to enable compression of
offload bundle. By default it is disabled.

When enabled, zstd or zlib is used for compression when available.

When disabled, it is NFC compared to previous behavior. The same offload
bundle format is used as before.

Clang-offload-bundler automatically detects whether the input file to be
unbundled is compressed and the compression method and decompress if
necessary.
2023-10-04 09:32:56 -04:00
Nikita Popov
39d55321bd
[CodeGen] Respect pointer-overflow sanitizer for void pointers (#67772)
Pointer arithmetic on void pointers (a GNU extension) was going through
a different code path and bypassed the pointer-overflow sanitizer.

Fixes https://github.com/llvm/llvm-project/issues/66451.
2023-10-04 15:16:00 +02:00
martinboehme
2be7c651c4
[clang][dataflow] HTML logger: Mark iterations that have converged. (#68204)
I've eliminated the `logText("Block converged")` call entirely because

a) These logs are associated with an individual `CFGElement`, while
convergence
   should be associated with a block, and

b) The log message was being associated with the wrong block:
`recordState()`
dumps all of the pending log messages, but `blockConverged()` is called
after
   the last `recordState()` call for a given block, so that the "Block
converged" log message was being associated with the first element of
the
   _next_ block to be processed.

Example:


![image](https://github.com/llvm/llvm-project/assets/29098113/6a19095c-2dbb-4771-9485-e8e45c9d26fb)
2023-10-04 13:47:24 +02:00
Alex Voicu
9f406e450b [HIP][Clang][Driver] Correctly specify test requirements as Linux + x86 + AMDGPU; temporarily retain targeted XFAILs for Hexagon & PS.
Differential Revision: https://reviews.llvm.org/D155775
2023-10-04 12:04:13 +01:00
zyn0217
077e1b892d
[clang] Preserve UDL nodes in RemoveNestedImmediateInvocation (#66641)
D63960 performs a tree transformation on AST to prevent evaluating
constant expressions eagerly by removing recorded immediate consteval
invocations from subexpressions. (See
https://reviews.llvm.org/D63960#inline-600736 for its motivation.)

However, the UDL node has been replaced with a CallExpr in the default
TreeTransform since ca844ab0 (inadvertently?). This confuses clangd as
it relies on the exact AST node type to decide whether or not to present
inlay hints for an expression.

With regard to the fix, I think it's enough to return the UDL expression
as-is during the transformation: We've bound it to temporary in its
construction, and there's no ConstantExpr to visit under a UDL.

Fixes https://github.com/llvm/llvm-project/issues/63898.
2023-10-04 04:45:46 -05:00
Owen Pan
7e856d1894 Reland "[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)"
Reland 6a621ed8e4 which failed on Windows but not macOS.

The failures were caused by moving the annotation of the children from the
top to the bottom of TokenAnnotator::annotate(), resulting in invalid lines
including incomplete ones being skipped.
2023-10-03 22:26:48 -07:00
Takuya Shimizu
2176c5e510 [Clang][Sema] Fix display of characters on static assertion failure
This patch fixes the display of characters appearing in LHS or RHS of == expression in notes to static assertion failure.
This applies C-style escape if the printed character is a special character. This also adds a numerical value displayed next to the character representation.
This also tries to print multi-byte characters if the user-provided expression is multi-byte char type.

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D155610
2023-10-04 14:09:06 +09:00
Sheng
548d67a039
[clang][Sema] Fix a bug when instantiating a lambda with requires clause (#65193)
Instantiating a lambda at a scope different from where it is defined
will paralyze clang if the trailing require clause refers to local
variables. This patch fixes this by re-adding the local variables to
`LocalInstantiationScope`.

Fixes #64462
2023-10-04 10:19:35 +08:00
Owen Pan
d08fcc817e Revert "[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)"
This reverts commit 6a621ed8e4 as it caused
buildbots to fail.
2023-10-03 18:19:23 -07:00
Owen Pan
6a621ed8e4
[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)
After annotating constructors/destructors as FunctionDeclarationName in
commit 0863051208, we have seen several issues because ctors/dtors had
been treated differently than functions in aligning, wrapping, and
indenting.

This patch annotates ctors/dtors as CtorDtorDeclName instead and would
effectively revert commit 0468fa07f8, which is obsolete now.

Fixed #67903.
Fixed #67907.
2023-10-03 18:02:09 -07:00
tripleCC
1dceba3a36
[analyzer] Fix false negative when accessing a nonnull property from … (#67563)
```
@interface A : NSObject
@property (nonnull, nonatomic, strong) NSString *name;
+ (nullable instancetype)shared;
@end

@[[A shared].name];
```
Consider the code above, the nullability of the name property should
depend on the result of the shared method. A warning is expected because
of adding a nullable object to array.
ObjCMessageExpr gets the actual type through
Sema::getMessageSendResultType, instead of using the return type of
MethodDecl directly. The final type is generated by considering the
nullability of receiver and MethodDecl together.
Thus, the RetType in NullabilityChecker should all be replaced with
M.getOriginExpr()->getType().

Co-authored-by: tripleCC <triplecc@gmail.com>
2023-10-04 08:38:10 +08:00
PiJoules
496d00b267
[clang][RelativeVTables] Make the rtti_proxy LinkOnceODR instead of External linkage (#67755)
This way, it the rtti_proxies can be candidates for being replaced
altogether with GOTPCREL relocations because they are discardable.
Functionally, this shouldn't change the final ELF linkage of the
proxies.
2023-10-03 17:05:21 -07:00
Ian Anderson
b855ae9903
Fix the Modules/compiler_builtins.m test (#68163)
Sometimes unwind.h needs uint32_t also.
2023-10-03 15:58:38 -07:00
Alex Voicu
1cfaa863bc [HIP][Clang][Driver] Disable hipstdpar driver test on SIE to unblock build bot, pending test refactor.
Differential Revision: https://reviews.llvm.org/D155775
2023-10-03 23:00:13 +01:00
Pavel Iliin
b04fe222d2
[AArch64][FMV] Add rcpc3 support, introduce bits for features extensi… (#68104)
…on and initialization.

The patch implements FEAT_LRCPC3 support (Load-Acquire RCpc instructions
version 3) in Function Multi Versioning. To maintain compatibility while
features list grows extension bit FEAT_EXT and initialization bit
FEAT_INIT are reserved.
2023-10-03 22:52:01 +01:00
Douglas Yung
344e735c17 Bump up DIAG_SIZE_DRIVER as we are very close to the limit as of 9a40858. 2023-10-03 14:27:53 -07:00
Alex Voicu
dce54eae46 [HIP][Clang][Driver] Disable hipstdpar driver test on SCEI to unblock build bot, pending test refactor.
Differential Revision: https://reviews.llvm.org/D155775
2023-10-03 22:17:12 +01:00
Noah Goldstein
2da4960f20 [Inliner] Also propagate noundef and align ret attributes during inlining
Both of these can potentially be lost otherwise.
2023-10-03 16:12:19 -05:00
Jan Svoboda
25a6b891cb
[clang] NFC: Remove unused FileEntry::getLastRef() (#68156)
The last usage of the deprecated `FileEntry::getLastRef()` was removed
in #67838, let's remove it entirely.
2023-10-03 13:37:39 -07:00
Jan Svoboda
27254ae511
[clang] NFCI: Use FileEntryRef for FileID creation (#67838)
This patch removes the `SourceManager` APIs that create `FileID` from a
`const FileEntry *` in favor of APIs that take `FileEntryRef`. This also
removes a misleading documentation that claims `nullptr` file entry
represents stdin. I don't think that's right, since we just try to
dereference that pointer anyways.
2023-10-03 13:07:46 -07:00
Shoaib Meenai
c6fed74f6f
[diag] Silence -Wfixed-enum-extension in C23 (#68060)
The C23 standard supports enums with fixed underlying types (N3030 [1]),
so we shouldn't emit `-Wfixed-enum-extension` in C23 mode (since it's no
longer a Clang extension at that point).

[1]
https://thephd.dev/_vendor/future_cxx/papers/C%20-%20Enhanced%20Enumerations.html
2023-10-03 13:04:22 -07:00
Ian Anderson
9a7a6dd3c3 [Modules] Make clang modules for the C standard library headers
Make top level modules for all the C standard library headers.

The `__stddef` implementation headers need header guards now that they're all modular. stdarg.h and stddef.h will be textual headers in the builtin modules, and so need to be repeatedly included in both the system and builtin module case. Define their header guards for consistency, but ignore them when building with modules.

`__stddef_null.h` needs to ignore its header guard when modules aren't being used to fulfill its redefinition obligation.
`__stddef_nullptr_t.h` needs to add a guard for C23 so that `_Builtin_stddef` can compile in C17 and earlier modes. `_Builtin_stddef.nullptr_t` can't require C23 because it also needs to be usable from C++.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D159064
2023-10-03 12:41:11 -07:00