2894 Commits

Author SHA1 Message Date
Abhina Sree
ec41462d7a
[SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (#75339)
This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files.
2023-12-13 13:13:53 -05:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Kazu Hirata
cc4ecfd68b
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)
This patch renames {starts,ends}with to {starts,ends}_with for
consistency with std::{string,string_view}::{starts,ends}_with in
C++20.  Since there are only a handful of occurrences, this patch
skips the deprecation phase and simply renames them.
2023-12-09 14:28:45 -08:00
Jan Svoboda
0cb0a48cde
[clang] NFC: Remove OptionalFileEntryRefDegradesToFileEntryPtr (#74899) 2023-12-08 18:22:41 -08:00
Aaron Ballman
3293c088c2 Remove dead code; NFC
This code was added 17 years ago but never enabled or tested. GCC warns
that -I- is deprecated for them, and Clang gives an error when passed
-I-, so we may as well remove this code rather than hook it up to the
driver and maintain it.
2023-12-07 08:26:33 -05:00
Chris B
2630d72cb3
[HLSL] Support vector swizzles on scalars (#67700)
HLSL supports vector swizzles on scalars by implicitly converting the
scalar to a single-element vector. This syntax is a convienent way to
initialize vectors based on filling a scalar value.

There are two parts of this change. The first part in the Lexer splits
numeric constant tokens when a `.x` or `.r` suffix is encountered. This
splitting is a bit hacky but allows the numeric constant to be parsed
separately from the vector element expression. There is an ambiguity
here with the `r` suffix used by fixed point types, however fixed point
types aren't supported in HLSL so this should not cause any exposable
problems (a separate issue has been filed to track validating language
options for HLSL: #67689).

The second part of this change is in Sema::LookupMemberExpr. For HLSL,
if the base type is a scalar, we implicit cast the scalar to a
one-element vector then call back to perform the vector lookup.

Fixes #56658 and #67511
2023-11-29 11:25:02 -06:00
Tulio Magno Quites Machado Filho
cf1bde3342
[clang] Fix sorting module headers (#73146)
Struct Module::Header is not a POD type. As such, qsort() and
llvm::array_pod_sort() must not be used to sort it. This became an issue
with the new implementation of qsort() in glibc 2.39 that is not
guaranteed to be a stable sort, causing Headers to be re-ordered and
corrupted.

Replace the usage of llvm::array_pod_sort() with std::stable_sort() in
order to fix this issue. The signature of compareModuleHeaders() has to
be modified.

Fixes #73145.
2023-11-24 09:17:21 -03:00
Chuanqi Xu
0f7aaeb324 [C++20] [Modules] Allow export from language linkage
Close https://github.com/llvm/llvm-project/issues/71347

Previously I misread the concept of module purview. I thought if a
declaration attached to a unnamed module, it can't be part of the module
purview. But after the issue report, I recognized that module purview is
more of a concept about locations instead of semantics.

Concretely, the things in the language linkage after module declarations
can be exported.

This patch refactors `Module::isModulePurview()` and introduces some
possible code cleanups.
2023-11-09 17:44:41 +08:00
Jan Svoboda
bdb309c5fd
[clang][modules] Avoid modules diagnostics for __has_include() (#71450)
After #70144 Clang started resolving module maps even for
`__has_include()` expressions. This had the unintended consequence of
emitting diagnostics around header misuse. These don't make sense if you
actually don't bring contents of the header into the importer, so should
be skipped for `__has_include()`. This patch moves emission of these
diagnostics out of `Preprocessor::LookupFile()` up into
`Preprocessor::LookupHeaderIncludeOrImport()`.
2023-11-06 17:31:27 -08:00
serge-sans-paille
95dd178483
[clang] Change representation of CurLexerKind (#70381)
Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on compile time
tracker are consistent and range form -0.05% to -0.20% for NewPM-O0-g,
see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef&to=608c85ec1283638db949d73e062bcc3355001ce4&stat=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)

---------

Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2023-11-06 07:13:05 +00:00
Fangrui Song
071f3b5b65
[Modules] Fix ModuleDeclState transition when module is used as a regular identifier (#71134)
`ModuleDeclState` is incorrectly changed to `NamedModuleImplementation`
for `struct module {}; void foo(module a);`. This is mostly benign but
leads to a spurious warning after #69555.

A real world example is:
```
// pybind11.h
class module_ { ... };
using module = module_;

// tensorflow
void DefineMetricsModule(pybind11::module main_module);
// `module main_module);` incorrectly changes `ModuleDeclState` to `NamedModuleImplementation`

#include <algorithm> // spurious warning
```
2023-11-02 22:13:08 -07:00
Chuanqi Xu
0d21436114
[C++20] [Modules] Warn if we found #include <filename> in module purview (#69555)
Close https://github.com/llvm/llvm-project/issues/68615.

It is generally wrong to include <filename> in the module purview.
Although there are cases to include files in the module purview,
generally these use cases should include files by quotes instead of by
angles. Here we think the files got included by angles are the system
headers.

This is consistency with MSVC too:
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version?view=msvc-170#warnings-introduced-in-visual-studio-2022-version-170-compiler-version-1930
2023-11-02 16:40:20 +08:00
serge-sans-paille
8116b6dce7
[clang] Change GetCharAndSizeSlow interface to by-value style
Instead of passing the Size by reference, assuming it is initialized,
return it alongside the expected char result as a POD.

This makes the interface less error prone: previous interface expected
the Size reference to be initialized, and it was often forgotten,
leading to uninitialized variable usage. This patch fixes the issue.

This also generates faster code, as the returned POD (a char and an
unsigned) fits in 64 bits. The speedup according to compile time tracker
reach -O.7%, with a good number of -0.4%. Details are available on

        https://llvm-compile-time-tracker.com/compare.php?from=3fe63f81fcb999681daa11b2890c82fda3aaeef5&to=fc76a9202f737472ecad4d6e0b0bf87a013866f3&stat=instructions:u

And icing on the cake, on my setup it also shaves 2kB out of
libclang-cpp :-)

This is a recommit of d8f5a18b6e587aeaa8b99707e87b652f49b160cd for
2023-10-31 00:08:01 +01:00
Nico Weber
1c876ff515 Revert "Perf/lexer faster slow get char and size (#70543)"
This reverts commit d8f5a18b6e587aeaa8b99707e87b652f49b160cd.
Breaks build, see:
https://github.com/llvm/llvm-project/pull/70543#issuecomment-1784227421
2023-10-29 21:11:39 -04:00
serge-sans-paille
d8f5a18b6e
Perf/lexer faster slow get char and size (#70543)
Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-10-29 18:17:02 +00:00
Richard Howell
396b5621f9
[clang] use relative paths for builtin headers during module compilation (#68023)
When including builtin headers as part of a system module, ensure we use
relative paths to those headers. Otherwise the module will fail to compile 
when specifying relative resource directories without extra search paths.
2023-10-27 07:10:46 -07:00
Jan Svoboda
a1b4238eaf
[clang][deps] Fix __has_include behavior with umbrella headers (#70144)
Previously, Clang wouldn't try to resolve the module for the header
being checked via `__has_include`. This meant that such header was
considered textual (a.k.a. part of the module Clang is currently
compiling).

rdar://116926060
2023-10-25 14:58:09 -07:00
Ian Anderson
09ec0004ee
[Modules] textual headers in submodules never resolve their uses (#69651)
When an include from a textual header is resolved, the textual header's
submodule is used as the requesting module. The submodule's uses are
resolved, but that doesn't work because only top level modules have
uses, and only the top level module uses are used for checking uses in
Module::directlyUses. ModuleMap::resolveUses to resolve the top level
module instead of the submodule.
2023-10-20 13:23:34 -07:00
Jan Svoboda
1afb313b26
[clang][modules] Use file name as requested (#68957)
This prevents redefinition errors due to having multiple paths for the
same module map. (rdar://24116019)

Originally implemented and tested downstream by @bcardosolopes, I just
made use of `FileEntryRef::getNameAsRequested()`.
2023-10-20 09:23:19 -07:00
serge-sans-paille
9f0f606081
[clang] Provide an SSE4.2 implementation of identifier token lexer (#68962)
The _mm_cmpistri instruction can be used to quickly parse identifiers.

With this patch activated, clang pre-processes <iostream> 1.8% faster,
and sqlite3.c amalgametion 1.5% faster, based on time measurements and
number of executed instructions as measured by valgrind.

The introduction of an extra helper function in the regular case has no
impact on performance, see


https://llvm-compile-time-tracker.com/compare.php?from=30240e428f0ec7d4a6d1b84f9f807ce12b46cfd1&to=12bcb016cde4579ca7b75397762098c03eb4f264&stat=instructions:u

---------

Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-10-19 08:45:54 +00:00
zijunzhao
3694697003 [clang] Implement C23 <stdckdint.h>
https://github.com/llvm/llvm-project/issues/62248

Reviewed By: yabinc, aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D157331
2023-10-17 00:51:21 +00:00
David Stone
701d804cdb
[clang][Modules] checkModuleIsAvailable should use a const & parameter instead of pointer (#67902)
The `Module` parameter to `checkModuleIsAvailable` is currently passed
by pointer to non-const. However, it requires only const access and it
cannot be null. Change this to be a reference to const instead.

This then makes it obvious that it is an input-only parameter, so move
it to be before the in-out parameter for diagnostics.
2023-10-08 09:49:05 +08:00
Timm Bäder
c654193c22 [clang][Lex][NFC] Make some local variables const 2023-10-07 07:11:45 +02: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
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
David Stone
06a05f3346
[NFC] remove duplicate ModuleId alias (#67899)
[clang] Remove duplicate `ModuleId` alias
2023-10-03 22:43:51 +08:00
Jan Svoboda
2da8f30c5e [clang] NFCI: Use FileEntryRef in SourceManager::overrideFileContents() 2023-09-29 09:30:21 -07:00
Jan Svoboda
b0abc9dd44 [clang] NFCI: Use FileEntryRef in ASTReader::GetHeaderFileInfo()
This is the `ASTReader` counterpart to PR #67383.
2023-09-29 09:07:13 -07:00
Jan Svoboda
12866a2b87 [clang][modules] Use FileEntryRef in ModuleMap (2/2) 2023-09-28 12:59:26 -07:00
Jan Svoboda
12cb98fe04 [clang][modules] Use FileEntryRef in ModuleMap (1/2) 2023-09-28 12:59:26 -07:00
Ian Anderson
0ea3d88bdb [Modules] Add a flag to control builtin headers being in system modules
Including select builtin headers in system modules is a workaround for module cycles, primarily in Apple's Darwin module that includes all of its C standard library headers. The workaround is problematic because it doesn't include all of the builtin headers (inttypes.h is notably absent), and it also doesn't include C++ headers. The straightforward for for this is to make top level modules for all of the C standard library headers and unwind.h in C++, clang, and the OS.

However, doing so in clang before the OS modules are ready re-introduces the module cycles. Add a -fbuiltin-headers-in-system-modules option to control if the special builtin headers belong to system modules or builtin modules. Pass the option by default for Apple.

Reviewed By: ChuanqiXu, Bigcheese, benlangmuir

Differential Revision: https://reviews.llvm.org/D159483
2023-09-28 11:30:09 -07:00
Timm Baeder
17a1cc69a5
[clang][NFC] Preprocessor only needs const LangOptions (#66874) 2023-09-27 06:36:18 +02:00
Kazu Hirata
f435f55d58 [Lex] Use llvm::byteswap instead of sys::getSwappedBytes (NFC) 2023-09-23 13:30:16 -07:00
Ben Barham
265d48a02d
Re-apply "[Parse] Split incremental-extensions" (#66446)
Re-applies #65683 with a fix to always run
`Actions.ActOnEndOfTranslationUnit` regardless of incremental
processing.
2023-09-20 23:35:34 -07:00
Christopher Di Bella
8f3b0b4171 [clang] adds __reference_constructs_from_temporary
This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Differential Revision: https://reviews.llvm.org/D135341
2023-09-13 23:51:43 +00:00
Jan Svoboda
f94695b6eb [clang] NFCI: Use FileEntryRef in FileManager::getBufferForFile() 2023-09-13 15:02:20 -07:00
Ben Barham
f8ced20ad3
Revert "[Parse] Split incremental-extensions" (#66281)
This reverts commit c2fb112021529c635cccd8bb9d846b2c64fc291d, which
breaks:
```
lldb-api.commands/expression/diagnostics.TestExprDiagnostics.py
lldb-api.lang/objc/modules.TestObjCModules.py
lldb-api.lang/objc/modules-incomplete.TestIncompleteModules.py
lldb-api.lang/objc/modules-non-objc-target.TestObjCModulesNonObjCTarget.py
lldb-api.lang/objc/modules-objc-property.TestModulesObjCProperty.py
```
2023-09-13 14:55:01 -07:00
Jan Svoboda
1b07d43298 [clang] NFCI: Use FileEntryRef in ModuleMap::InferredModuleAllowedBy 2023-09-13 13:32:26 -07:00
Ben Barham
4c264c26d7
[Parse] Split incremental-extensions (#65683)
The preprocessor `IncrementalProcessing` option was being used to
control whether or not to teardown the lexer or run the end of
translation unit action. In D127284 this was merged with
`-fincremental-extensions`, which also changes top level parsing.

Split these again so that the former behavior can be achieved without
the latter (ie. to allow managing lifetime without also changing
parsing).

Resolves rdar://113406310.
2023-09-11 17:40:43 -07:00
Christopher Di Bella
dfd1d8d505 Revert "adds __reference_constructs_from_temporary"
I'm reverting this on principle, since it didn't get the Phabricator
approval I thought it had (only an informal LGTM). Will re-apply once
it has been properly approved.

This reverts commit e1bfeb6bcc627a94c5ab3a5417d290c7dc516d54.
2023-09-11 23:44:50 +00:00
Christopher Di Bella
e1bfeb6bcc adds __reference_constructs_from_temporary
This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Differential Revision: https://reviews.llvm.org/D135341
2023-09-11 23:14:08 +00:00
Jan Svoboda
89bacc0bb9 [clang] NFCI: Use FileEntryRef in CreateHeaderMap() 2023-09-09 21:51:04 -07:00
Jan Svoboda
e644f5973b [clang] NFCI: Use FileEntryRef in ModuleMapCallbacks 2023-09-09 21:51:04 -07:00
Jan Svoboda
e483a6e174 [clang] NFCI: Use FileEntryRef in LookupSubframeworkHeader() 2023-09-09 21:50:38 -07:00
Jan Svoboda
6966c06bed [clang] NFCI: Use FileEntryRef in suggestPathToFileForDiagnostics() 2023-09-09 20:29:04 -07:00
Jan Svoboda
37b08892fc [clang] NFCI: Use FileEntryRef in ModuleMap 2023-09-09 09:12:35 -07:00
Jan Svoboda
c23d65b90f [clang] NFCI: Use FileEntryRef in ModuleMapParser 2023-09-09 09:12:35 -07:00
Jan Svoboda
ef996175a7 [clang] NFCI: Use FileEntryRef in diagnoseFrameworkInclude() 2023-09-09 09:12:35 -07:00
Jan Svoboda
358d9dbf4f [clang] NFCI: Use FileEntryRef in checkMSVCHeaderSearch() 2023-09-08 21:28:05 -07:00
Jan Svoboda
5523fefb01 [clang][lex] Use preferred path separator in includer-relative lookup
There is a long-standing FIXME in `HeaderSearch.cpp` to use the path separator preferred by the platform instead of forward slash. There was an attempt to fix that (1cf6c28a) which got reverted (cf385dc8). I couldn't find an explanation, but my guess is that some tests assuming forward slash started failing.

This commit fixes tests with that assumption.

This is intended to be NFC, but there are two exceptions to that:
* Some diagnostic messages might now contain backslash instead of forward slash.
* Arguments to the "-remap-file" option that use forward slash might stop kicking in. Separators between potential includer path and header name need to be replaced by backslash in that case.
2023-09-08 16:38:08 -07:00