Commit Graph

68336 Commits

Author SHA1 Message Date
gonglingqin c2ec455f18 [LoongArch] Add intrinsics for ibar, break and syscall
Diagnostics for intrinsic input parameters have also been added.

Differential Revision: https://reviews.llvm.org/D138094
2022-11-21 09:31:26 +08:00
Kazu Hirata 30f9eb1eb8 [clang] Remove unused forward declarations (NFC) 2022-11-20 14:32:17 -08:00
Kazu Hirata 1fa870b1bd Use None consistently (NFC)
This patch replaces NoneType() and NoneType::None with None in
preparation for migration from llvm::Optional to std::optional.

In the std::optional world, we are not guranteed to be able to
default-construct std::nullopt_t or peek what's inside it, so neither
NoneType() nor NoneType::None has a corresponding expression in the
std::optional world.

Once we consistently use None, we should even be able to replace the
contents of llvm/include/llvm/ADT/None.h with something like:

  using NoneType = std::nullopt_t;
  inline constexpr std::nullopt_t None = std::nullopt;

to ease the migration from llvm::Optional to std::optional.

Differential Revision: https://reviews.llvm.org/D138376
2022-11-20 00:24:40 -08:00
Noah Goldstein 92bccf5d3d [clang-format] Don't use PPIndentWidth inside multi-line macros
Differential Revision: https://reviews.llvm.org/D137181
2022-11-19 23:53:48 -08:00
Fangrui Song d1163784b5 Remove unused llvm/IRPrinter/IRPrintingPasses.h or reorder #include after D137768 2022-11-19 22:09:05 +00:00
Alex Richardson 0745b0c035 Fix incorrect cast in VisitSYCLUniqueStableNameExpr
Clang language-level address spaces and LLVM pointer address spaces are
not the same thing (even though they will both have a numeric value of
zero in many cases). LangAS is a enum class to avoid implicit conversions,
but eba69b59d1 avoided the compiler error by
adding a `static_cast<>`. While touching this code, simplify it by using
CreatePointerBitCastOrAddrSpaceCast() which is already a no-op if the types
match.

This changes the code generation for spir64 to place the globals in
the sycl_global addreds space, which maps to `addrspace(1)`.

Reviewed By: bader

Differential Revision: https://reviews.llvm.org/D138284
2022-11-19 11:43:17 +00:00
yronglin 80f444646c [CodeGen][ARM] Fix ARMABIInfo::EmitVAAarg crash with empty record type variadic arg
Fix ARMABIInfo::EmitVAAarg crash with empty record type variadic arg

Open issue: https://github.com/llvm/llvm-project/issues/58794

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D138137
2022-11-19 15:14:10 +08:00
Jennifer Yu 9d90cf2fca [OPENMP5.1] Initial support for message clause. 2022-11-18 17:59:23 -08:00
Fazlay Rabbi 56c1660170 [OpenMP] Initial parsing/sema for 'strict' modifier with 'num_tasks' clause
This patch gives basic parsing and semantic analysis support for 'strict'
modifier with 'num_tasks' clause of 'taskloop' construct introduced in
OpenMP 5.1 (section 2.12.2)

Differential Revision: https://reviews.llvm.org/D138328
2022-11-18 16:26:47 -08:00
Doru Bercea 9e595e911e [Clang][OpenMP] Add support for default to/from map types on target enter/exit data 2022-11-18 16:12:35 -06:00
Krzysztof Parzyszek f01b68e4be [Hexagon] Add checks for immediate arguments for remaining builtins
Checks for builtins for the following instructions were aded:
  V6_v6mpyhubs10
  V6_v6mpyhubs10_vxx
  V6_v6mpyvubs10
  V6_v6mpyvubs10_vxx
  V6_vlutvvbi
  V6_vlutvvb_oracci
  V6_vlutvwhi
  V6_vlutvwh_oracci
2022-11-18 11:09:41 -08:00
Krzysztof Parzyszek 7c476697e2 [Hexagon] Add clang flags for v71, v71t, v73 2022-11-18 09:39:47 -08:00
Xing Xue fa7477eb87 [Clang][CodeGen][AIX] Map __builtin_frexpl, __builtin_ldexpl, and __builtin_modfl to 'double' version lib calls in 64-bit 'long double' mode
Summary:
AIX library functions frexpl(), ldexpl(), and modfl() are for 128-bit IBM long double, i.e. __ibm128. Other *l() functions, e.g., acosl(), are for 64-bit long double. The AIX Clang compiler currently maps builtin functions __builtin_frexpl(), __builtin_ldexpl(), and __builtin_modfl() to frexpl(), ldexpl(), and modfl() in 64-bit long double mode which results in seg-faults or incorrect return values. This patch changes to map __builtin_frexpl(), __builtin_ldexpl(), and __builtin_modfl() to double version lib functions frexp(), ldexp() and modf() in 64-bit long double mode.

Reviewed by: hubert.reinterpretcast, daltenty

Differential Revision: https://reviews.llvm.org/D137986
2022-11-18 11:36:56 -05:00
Timm Bäder 2656fb3945 [clang][NFC] Remove unused parameter from ParseConstantExpression 2022-11-18 16:34:52 +01:00
Timm Bäder 25bd9e1009 [clang][parse] Avoid creating StmtVectors every loop iteration 2022-11-18 16:19:09 +01:00
Timm Bäder 096c033634 [clang][sema][NFC] Make some local variables const
We don't modify them. Also use auto here since we already wrote the full
type in the cast.
2022-11-18 16:19:09 +01:00
serge-sans-paille c8ecbaa2eb
[clang] Fix assert message 2022-11-18 10:10:42 +01:00
Alexander Shaposhnikov f102fe7304 Revert "Revert "[opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm""
This reverts commit 7f608a2497
and removes the dependency of Object on IRPrinter.
2022-11-18 08:58:31 +00:00
Mikhail Goncharov 7f608a2497 Revert "[opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm"
This reverts commit 34ab474348.

as it has introduced circular dependency lib - analysis
2022-11-18 09:25:45 +01:00
Matt Jacobson ba7a1d9e4a [Driver] move FreeBSD header search path management to the driver
This matches OpenBSD, and it supports Swift's use of clang for its C interop
functionality.  Recent changes to Swift use AddClangSystemIncludeArgs() to
inspect the cc1 args; this doesn't work for platforms where cc1 adds standard
include paths implicitly.  See:

<cf3354222d>

Also clean up InitHeaderSearch, making it clearer which targets manage header
search paths in the driver.

Differential Revision: https://reviews.llvm.org/D138183
2022-11-18 02:29:49 -05:00
Alexander Shaposhnikov 34ab474348 [opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm
Enable using -module-summary with -S
(similarly to what currently can be achieved with opt <input> -o - | llvm-dis).
This is a recommit of ef9e62469.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D137768
2022-11-18 05:04:07 +00:00
Fazlay Rabbi ab9eac762c [OpenMP] Initial parsing/sema for 'strict' modifier with 'grainsize' clause
This patch gives basic parsing and semantic analysis support for 'strict'
modifier with 'grainsize' clause of 'taskloop' construct introduced in
OpenMP 5.1 (section 2.12.2)

Differential Revision: https://reviews.llvm.org/D138217
2022-11-17 20:59:07 -08:00
Timm Bäder e78a43daca [clang][Parse][NFC] Remove unused CommaLocs parameters 2022-11-18 04:54:00 +01:00
Timm Bäder 9f61479007 [clang][Parser][NFC] Simplify ParseParenExprOrCondition
Differential Revision: https://reviews.llvm.org/D138194
2022-11-18 04:53:59 +01:00
Chuanqi Xu 1614d63405 [NFC] Remove unused codes after 4a7be42d92
There are still some unused codes remained after 4a7be42d92. And this
patch tries to remove them.
2022-11-18 11:52:44 +08:00
Chuanqi Xu d584468581 [C++20] [Modules] Don't emit macro definitions with named module
It is meaningless to emit macro definitions for named modules. With some
small experiments, the size of the module for the named modules reduced
2%~4% after this patch.
2022-11-18 11:11:17 +08:00
Chuanqi Xu 4a7be42d92 [C++20] [Modules] Remove unmaintained Header Module
Currently there is a -emit-header-module mode, which can combine several
headers together as a module interface. However, this breaks our
assumption (for standard c++ modules) about module interface. The module
interface should come from a module interface unit. And if it is a
header, it should be a header unit. And currently we have no ideas to
combine several headers together.

So I think this mode is an experimental one and it is not maintained and
it is not used. So it will be better to remove them.

Reviewed By: Bigcheese, dblaikie, bruno

Differential Revision: https://reviews.llvm.org/D137609
2022-11-18 10:39:33 +08:00
Qiu Chaofan cab9c02bd9 [Clang] Fix behavior of -ffp-model option when overriden
-ffp-model=strict -ffp-model=fast will still enable strict exception
handling behavior, therefore clang still emits constrained FP operations
in IR.

-ffp-model=fast -ffp-model=strict emits two warnings: one for strict
overriding fast, the other for strict overriding strict, which is
confusing.

Reviewed By: zahiraam

Differential Revision: https://reviews.llvm.org/D137618
2022-11-18 10:34:41 +08:00
Volodymyr Sapsai a65d5309d5 [ODRHash] Detect duplicate `ObjCProtocolDecl` ODR mismatches during parsing.
When during parsing we encountered a duplicate `ObjCProtocolDecl`, we
were always emitting an error. With this change we accept
* when a previous `ObjCProtocolDecl` is in a hidden [sub]module;
* parsed `ObjCProtocolDecl` is the same as the previous one.

And in case of mismatches we provide more detailed error messages.

rdar://93069080

Differential Revision: https://reviews.llvm.org/D130327
2022-11-17 18:31:32 -08:00
Alexander Shaposhnikov 7059a6c32c [IR] Split out IR printing passes into IRPrinter
This diff splits out (from LLVMCore) IR printing passes into IRPrinter.
This structure is similar to what we already have for IRReader and
enables us to avoid circular dependencies between LLVMCore and Analysis
(this is a preparation for https://reviews.llvm.org/D137768).
The legacy interface is left unchanged, once the legacy pass manager
is removed (in the future) we will be able to clean it up further.
The bazel build configuration has been updated as well.

Test plan:
1/ Tested the following cmake configurations: static/dynamic linking * lld/gold * clang/gcc
2/ bazel build --config=generic_clang @llvm-project//...

Differential revision: https://reviews.llvm.org/D138081
2022-11-18 01:47:56 +00:00
Volodymyr Sapsai dcb71b5e1d [ODRHash] Hash `ObjCPropertyDecl` and diagnose discovered mismatches.
Differential Revision: https://reviews.llvm.org/D130326
2022-11-17 17:22:03 -08:00
Brad Smith 6536a67338 [Linux] Revert 1e56821bac
The glibc issue mentioned in #47994 has been fixed upstream.
2022-11-17 19:48:01 -05:00
Jennifer Yu 1e054e6b52 [OPENMP5.1] Initial support for severity clause
Differential Revision:https://reviews.llvm.org/D138227
2022-11-17 16:05:02 -08:00
Doru Bercea 98bfd7f976 Fix declare target implementation to support enter. 2022-11-17 17:35:53 -06:00
Fangrui Song fc91c70593 Revert D135411 "Add generic KCFI operand bundle lowering"
This reverts commit eb2a57ebc7.

llvm/include/llvm/Transforms/Instrumentation/KCFI.h including
llvm/CodeGen is a layering violation. We should use an approach where
Instrumementation/ doesn't need to include CodeGen/.
Sorry for not spotting this in the review.
2022-11-17 22:45:30 +00:00
Craig Topper c9320bc871 [X86] Use correctly sized floating point literals in *zero_ps/pd.
This avoids depending on int->float or double->float conversion.
Improving codegen with #pragma STDC FENV_ACCESS ON.

Really we should improve constant folding somewhere, but this was
a cheap and easy improvement.

Fixes PR59052.
2022-11-17 14:28:52 -08:00
Sami Tolvanen eb2a57ebc7 Add generic KCFI operand bundle lowering
The KCFI sanitizer emits "kcfi" operand bundles to indirect
call instructions, which the LLVM back-end lowers into an
architecture-specific type check with a known machine instruction
sequence. Currently, KCFI operand bundle lowering is supported only
on 64-bit X86 and AArch64 architectures.

As a lightweight forward-edge CFI implementation that doesn't
require LTO is also useful for non-Linux low-level targets on
other machine architectures, add a generic KCFI operand bundle
lowering pass that's only used when back-end lowering support is not
available and allows -fsanitize=kcfi to be enabled in Clang on all
architectures.

Reviewed By: nickdesaulniers, MaskRay

Differential Revision: https://reviews.llvm.org/D135411
2022-11-17 21:55:00 +00:00
Ben Langmuir c4436f675d [clang] Use InMemoryModuleCache for readASTFileControlBlock NFC
When a pcm has already been loaded from disk, reuse it from the
InMemoryModuleCache in readASTFileControlBlock. This avoids potentially
reading it again.

As noted in the FIXME, ideally we would also add the module to the cache
if it will be used again later, but that could modify its build state
and we do not have enough context currenlty to know if it's correct.

Differential Revision: https://reviews.llvm.org/D138160
2022-11-17 13:47:46 -08:00
Vaibhav Yenamandra 7b6fe711b2 Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`
Refactor StaticAnalyzer to use clang::SarifDocumentWriter for
serializing sarif diagnostics.

Uses clang::SarifDocumentWriter to generate SARIF output in the
StaticAnalyzer.

Various bugfixes are also made to clang::SarifDocumentWriter.

Summary of changes:

clang/lib/Basic/Sarif.cpp:
  * Fix bug in adjustColumnPos introduced from prev move, it now uses
    FullSourceLoc::getDecomposedExpansionLoc which provides the correct
    location (in the presence of macros) instead of
    FullSourceLoc::getDecomposedLoc.
  * Fix createTextRegion so that it handles caret ranges correctly,
    this should bring it to parity with the previous implementation.

clang/test/Analysis/diagnostics/Inputs/expected-sarif:
  * Update the schema URL to the offical website
  * Add the emitted defaultConfiguration sections to all rules
  * Annotate results with the "level" property

clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:
  * Update SarifDiagnostics class to hold a clang::SarifDocumentWriter
    that it uses to convert diagnostics to SARIF.
2022-11-17 14:47:02 -05:00
Artem Belevich 817340569b [CUDA] make use of deprecated texture API conditional on CUDA version. 2022-11-17 11:38:16 -08:00
Jonas Paulsson 858f347c17 [Clang, SystemZ] Add support for option -mno-pic-data-is-text-relative.
Add support for this GCC option which has the purpose of disallowing text
relative accesses of module local symbols with PIC. In effect, this changes
the code model to "medium".

Reviewed By: uweigand, efriedma, MaskRay

Differential Revision: https://reviews.llvm.org/D137044
2022-11-17 11:32:32 -05:00
Timm Bäder ec782951d7 [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr
Use FastEvaluateAsRValue() in EvaluateAsConstantExpr() as well, to
short-circuit evaluation of simple integrals.

Differential Revision: https://reviews.llvm.org/D138115
2022-11-17 12:01:37 +01:00
Emilia Dreamer 48a932e13e
[clang-format] Remove special case for kw_operator when aligning decls
This change breaks no existing tests but does fix the linked issue.
Declarations of operator overloads are annotated with
`TT_FunctionDeclarationName` on the `operator` keyword, which is already
being checked for when aligning, so the extra `kw_operator` doesn't seem
to be necessary. (just for reference, it was added in
rG92b397fb9d55ccdf4632c2b1b15b4a0ee417cf74 / 92b397fb9d)

Fixes https://github.com/llvm/llvm-project/issues/55733

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D137223
2022-11-17 11:38:28 +02:00
Emilia Dreamer df6f4b8513
[clang-format] Defer formatting of operator< to honor paren spacing
I'm not exactly sure what the intent of that section of
`spaceRequiredBetween` is doing, it seems to handle templates and <<,
but the part which adds spaces before parens is way later, as part
of `spaceRequiredBeforeParens`.

Fixes https://github.com/llvm/llvm-project/issues/58821

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D137474
2022-11-17 11:38:21 +02:00
Serge Pavlov 1ddd586308 [clang] Missed rounding mode use in constant evaluation
Integer-to-float conversion was handled in constant evaluator with
default rounding mode. This change fixes the behavior and the conversion
is made using rounding mode stored in ImplicitCastExpr node.

Differential Revision: https://reviews.llvm.org/D137719
2022-11-17 12:05:28 +07:00
Joshua Batista 083d949f38 [HLSL] add sin library function
This change exposes the sin library function for HLSL,
excluding long, int, and long long doubles.
Sin is supported for all scalar, vector, and matrix types.

Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the sin function only works on floating type arguments.

The full documentation of the HLSL sin function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-sin

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D138161
2022-11-16 18:29:50 -08:00
Richard Smith 45e57a550f Suppress warning on unused static data member.
The member in the specialization is intentionally unused on 32-bit
targets.
2022-11-16 17:42:14 -08:00
Ben Shi 84ef723573 [clang] Fix wrong ABI of AVRTiny.
A scalar which exceeds 4 bytes should be returned via a stack slot,
on an AVRTiny device.

Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D138125
2022-11-17 08:38:44 +08:00
Eli Friedman 0fcb26c5b6 [clang] Fix __try/__finally blocks in C++ constructors.
We were crashing trying to convert a GlobalDecl from a
CXXConstructorDecl.  Instead of trying to do that conversion, just pass
down the original GlobalDecl.

I think we could actually compute the correct constructor/destructor
kind from the context, given the way Microsoft mangling works, but it's
simpler to just pass through the correct constructor/destructor kind.

Differential Revision: https://reviews.llvm.org/D136776
2022-11-16 15:13:33 -08:00
Tom Praschan 0e00611cbc [clangd] Add heuristic for dropping snippet when completing member function pointer
This implements the 1st heuristic mentioned in https://github.com/clangd/clangd/issues/968#issuecomment-1002242704:

When completing a function that names a non-static member of a class, and we are not inside that class's scope, assume the reference will not be a call (and thus don't add the snippetSuffix)

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D137040
2022-11-17 00:37:16 +01:00
Richard Smith 9e52db1827 When we run out of source locations, try to produce useful information
indicating why we ran out.
2022-11-16 14:36:16 -08:00
Tom Honermann 3e25ae605e [Clang] Correct when Itanium ABI guard variables are set for non-block variables with static or thread storage duration.
Previously, Itanium ABI guard variables were set after initialization was
complete for non-block declared variables with static and thread storage
duration. That resulted in initialization of such variables being restarted
in cases where the variable was referenced while it was still under
construction. Per C++20 [class.cdtor]p2, such references are permitted
(though the value obtained by such an access is unspecified). The late
initialization resulted in recursive reinitialization loops for cases like
this:
  template<typename T>
  struct ct {
    struct mc {
      mc() { ct<T>::smf(); }
      void mf() const {}
    };
    thread_local static mc tlsdm;
    static void smf() { tlsdm.mf(); }
  };
  template<typename T>
  thread_local typename ct<T>::mc ct<T>::tlsdm;
  int main() {
    ct<int>::smf();
  }

With this change, guard variables are set before initialization is started
so as to avoid such reinitialization loops.

Fixes https://github.com/llvm/llvm-project/issues/57828

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D135919
2022-11-16 16:31:35 -05:00
Joshua Batista 9777e98a61 [HLSL] add cos library function
This change exposes the cos library function for HLSL,
excluding long, int, and long long doubles.
Cos is supported for all scalar, vector, and matrix types.

Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the cos function only works on floating type arguments.

The full documentation of the HLSL cos function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-cos

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D134921
2022-11-16 12:54:11 -08:00
Louis Dionne 9621b1776a [clang] Don't include C++ Standard Library headers when -nostdinc is used
This is a follow-up to 53c98d85a, which made the same change but only
for GNU. It seems that we should try to provide a consistent behavior
across all targets.

This fixes an issue where clang/test/Driver/nostdincxx.cpp would start
failing on non-GNU targets because that test was too loose in its checks.
It would only check that 'file not found' was part of the error message,
but didn't ensure that the file we had not found was <vector>.

Differential Revision: https://reviews.llvm.org/D138062
2022-11-16 15:25:32 -05:00
Zequan Wu 29c9287917 [AST] Fix class layout when using external layout under MS ABI.
Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D137806
2022-11-16 11:17:50 -08:00
Erich Keane 6c38ffc7b6 [Concepts] Fix friend-checking to include NTTPs
More work for temp.friend p9, this fixes a previous bug where we didn't
properly consider a friend to depend on the enclosing template if it
only did so via an NTTP.
2022-11-16 07:33:15 -08:00
serge-sans-paille cb3f8d53e6
[Lexer] Speedup LexTokenInternal
Only reset "NeedsCleaning" flag in case of re-entrant call.
Do not needlessly blank IdentifierInfo. This information will be set
once the token type is picked.

This yields a nice 1% speedup when pre-processing sqlite amalgamation
through:

valgrind --tool=callgrind ./bin/clang -E sqlite3.c -o/dev/null

Differential Revision: https://reviews.llvm.org/D137960
2022-11-16 15:57:32 +01:00
Michał Górny b3f94fe1c3 [clang][Driver] allow tilde in user config dir
This patch allows users to configure clang with option
e.g. `-DCLANG_CONFIG_FILE_USER_DIR=~/.config/clang` or invoke clang
with `--config-user-dir=~/.config/clang`.

Patch merged on behalf of @paperchalice (LJC)

Differential Revision: https://reviews.llvm.org/D136940
2022-11-16 13:23:25 +01:00
Ties Stuij 983f63f7f0 [AArch64][ARM] add Armv8.9-a/Armv9.4-a identifier support
For both ARM and AArch64 add support for specifying -march=armv8.9a/armv9.4a to
clang. Add backend plumbing like target parser and predicate support.

For a summary of Amv8.9/Armv9.4 features, see:
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-2022

For detailed information, consult the Arm Architecture Reference Manual for
A-profile architecture:
https://developer.arm.com/documentation/ddi0487/latest/

People who contributed to this patch:
- Keith Walker
- Ties Stuij

Reviewed By: tmatheson

Differential Revision: https://reviews.llvm.org/D138010
2022-11-16 10:20:14 +00:00
Timm Bäder 981dac8bd6 [clang][Parse][NFC] Remove unused DenseMap 2022-11-16 10:02:52 +01:00
Timm Bäder 051230359c [clang][NFC] Remove unused CastForMoving parameter
Nothing ever passes a third parameter to CastForMoving.
2022-11-16 10:02:52 +01:00
Timm Bäder d128a03ff3 [clang][Interp][NFC] Use constexpr if in OffsetHelper
Add here is a template parameter, so we can do this.
2022-11-16 09:56:29 +01:00
gonglingqin ddbb21bdb5 [LoongArch] Add immediate operand validity check for __builtin_loongarch_dbar
Differential Revision: https://reviews.llvm.org/D137809
2022-11-16 14:47:45 +08:00
Serge Pavlov 1f67dc8b7c [Driver] Enable nested configuration files
Users may partition parameters specified by configuration file and put
different groups into separate files. These files are inserted into the
main file using constructs `@file`. Relative file names in it are
resolved relative to the including configuration file and this is not
convenient in some cases. A configuration file, which resides in system
directory, may need to include a file with user-defined parameters and
still provide default definitions if such file is absent.

To solve such problems, the option `--config=` is allowed inside
configuration files. Like `@file` it results in insertion of
command-line arguments but the algorithm of file search is different and
allows overriding system definitions with user ones.

Differential Revision: https://reviews.llvm.org/D136354
2022-11-16 13:32:27 +07:00
Akira Hatanaka 81e33602f7 [Sema] Use the value category of the base expression when creating an
ExtVectorElementExpr

This fixes a bug where an lvalue ExtVectorElementExpr was created when
the base expression was an ObjC property dot operator.

This reverts 220d08d942.

Differential Revision: https://reviews.llvm.org/D138058
2022-11-15 17:14:48 -08:00
Akira Hatanaka 063a43b4fd [ObjC] Fix an assertion failure in EvaluateLValue
Look through parentheses when determining whether the expression is a
@selector expression.
2022-11-15 14:41:28 -08:00
eopXD 6dee23919a [Clang][Sema] Refactor category declaration under CheckForIncompatibleAttributes. NFC
This change would allow extension of new categories be aware of adding
more code here.

This patch also updates the comments, which was originally missing the
vector predicate.

Reviewed By: mikerice

Differential Revision: https://reviews.llvm.org/D137570
2022-11-15 14:37:27 -08:00
Jennifer Yu 628fdc3f57 [OPENMP]Initial support for at clause
Error directive is allowed in both declared and executable contexts.
The function ActOnOpenMPAtClause is called in both places during the
parsers.

Adding a param "bool InExContext" to identify context which is used to
emit error massage.

Differential Revision: https://reviews.llvm.org/D137851
2022-11-15 14:06:50 -08:00
Ben Langmuir 05ec16d90d [clang][deps] Avoid leaking modulemap paths across unrelated imports
Use a FileEntryRef when retrieving modulemap paths in the scanner so
that we use a path compatible with the original module import, rather
than a FileEntry which can allow unrelated modules to leak paths into
how we build a module due to FileManager mutating the path.

Note: the current change prevents an "unrelated" path, but does not
change how VFS mapped paths are handled (which would be calling
getNameAsRequested) nor canonicalize the path.

Differential Revision: https://reviews.llvm.org/D137989
2022-11-15 13:59:26 -08:00
Shafik Yaghmour 9332ddfba6 [Clang] Extend the number of case Sema::CheckForIntOverflow covers
Currently Sema::CheckForIntOverflow misses several case that other compilers
diagnose for overflow in integral constant expressions. This includes the
arguments of a CXXConstructExpr as well as the expressions used in an
ArraySubscriptExpr, CXXNewExpr and CompoundLiteralExpr.

This fixes https://github.com/llvm/llvm-project/issues/58944

Differential Revision: https://reviews.llvm.org/D137897
2022-11-15 12:07:03 -08:00
Reed 88eb3c62f2 Add FP8 E4M3 support to APFloat.
NVIDIA, ARM, and Intel recently introduced two new FP8 formats, as described in the paper: https://arxiv.org/abs/2209.05433. The first of the two FP8 dtypes, E5M2, was added in https://reviews.llvm.org/D133823. This change adds the second of the two: E4M3.

There is an RFC for adding the FP8 dtypes here: https://discourse.llvm.org/t/rfc-add-apfloat-and-mlir-type-support-for-fp8-e5m2/65279. I spoke with the RFC's author, Stella, and she gave me the go ahead to implement the E4M3 type. The name of the E4M3 type in APFloat is Float8E4M3FN, as discussed in the RFC. The "FN" means only Finite and NaN values are supported.

Unlike E5M2, E4M3 has different behavior from IEEE types in regards to Inf and NaN values. There are no Inf values, and NaN is represented when the exponent and mantissa bits are all 1s. To represent these differences in APFloat, I added an enum field, fltNonfiniteBehavior, to the fltSemantics struct. The possible enum values are IEEE754 and NanOnly. Only Float8E4M3FN has the NanOnly behavior.

After this change is submitted, I plan on adding the Float8E4M3FN type to MLIR, in the same way as E5M2 was added in https://reviews.llvm.org/D133823.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D137760
2022-11-15 20:26:42 +01:00
Fangrui Song ea5be2571d [AVR] Fix use-of-uninitialized-value after D137520 2022-11-15 11:06:18 -08:00
Ayke van Laethem 09ab9d4d11
[AVR][Clang] Implement __AVR_ARCH__ macro
This macro is defined in avr-gcc, and is very useful especially in
assembly code to check whether particular instructions are supported. It
is also the basis for other macros like __AVR_HAVE_ELPM__.

Differential Revision: https://reviews.llvm.org/D137521
2022-11-15 15:29:37 +01:00
Ayke van Laethem d2563775cd
[AVR][Clang] Move family names into MCU list
This simplifies the code by avoiding some special cases for family names
(as opposed to device names).

Differential Revision: https://reviews.llvm.org/D137520
2022-11-15 15:29:37 +01:00
Alex Richardson 00b1f7a6ab Use TI.hasBuiltinAtomic() when setting ATOMIC_*_LOCK_FREE values. NFCI
I noticed that the values for __{CLANG,GCC}_ATOMIC_POINTER_LOCK_FREE were
incorrectly set to 1 instead of two in downstream CHERI targets because
pointers are handled specially there. While fixing this downstream, I
noticed that the existing code could be refactored to use
TargetInfo::hasBuiltinAtomic instead of repeating the almost identical
logic. In theory there could be a difference here since hasBuiltinAtomic() also
returns true for types less than 1 char in size, but since
InitializePredefinedMacros() never passes such a value this change should
not introduce any functional changes.

Reviewed By: rprichard, efriedma

Differential Revision: https://reviews.llvm.org/D135142
2022-11-15 12:42:19 +00:00
Kadir Cetinkaya ae59131d3e
[clang][Tooling] Make the filename behaviour consistent
Dotdots were removed only when converting a relative path to absolute
one. This patch makes the behaviour consistent for absolute file paths by
removing them in that case as well. Also updates the documentation to mention
the behaviour.

Fixes https://github.com/clangd/clangd/issues/1317

Differential Revision: https://reviews.llvm.org/D137962
2022-11-15 10:47:52 +01:00
Chuanqi Xu cb2289f392 [C++20] [Modules] Attach implicitly declared allocation funcitons to
global module fragment

[basic.stc.dynamic.general]p2 says:
> The library provides default definitions for the global allocation
> and deallocation functions. Some global allocation and
> deallocation
> functions are replaceable ([new.delete]); these are attached to
> the global module ([module.unit]).

But we didn't take this before and the implicitly generated functions
will live in the module purview if we're compiling a module unit. This
is bad since the owning module will affect the linkage of the
declarations. This patch addresses this.

Closes https://github.com/llvm/llvm-project/issues/58560
2022-11-15 17:21:48 +08:00
Michele Scandale b7d7c448df Fix `unsafe-fp-math` attribute emission.
The conditions for which Clang emits the `unsafe-fp-math` function
attribute has been modified as part of
`84a9ec2ff1ee97fd7e8ed988f5e7b197aab84a7`.
In the backend code generators `"unsafe-fp-math"="true"` enable floating
point contraction for the whole function.
The intent of the change in `84a9ec2ff1ee97fd7e8ed988f5e7b197aab84a7`
was to prevent backend code generators performing contractions when that
is not expected.
However the change is inaccurate and incomplete because it allows
`unsafe-fp-math` to be set also when only in-statement contraction is
allowed.

Consider the following example
```
float foo(float a, float b, float c) {
  float tmp = a * b;
  return tmp + c;
}
```
and compile it with the command line
```
clang -fno-math-errno -funsafe-math-optimizations -ffp-contract=on \
  -O2 -mavx512f -S -o -
```
The resulting assembly has a `vfmadd213ss` instruction which corresponds
to a fused multiply-add. From the user perspective there shouldn't be
any contraction because the multiplication and the addition are not in
the same statement.

The optimized IR is:
```
define float @test(float noundef %a, float noundef %b, float noundef %c) #0 {
  %mul = fmul reassoc nsz arcp afn float %b, %a
  %add = fadd reassoc nsz arcp afn float %mul, %c
  ret float %add
}

attributes #0 = {
  [...]
  "no-signed-zeros-fp-math"="true"
  "no-trapping-math"="true"
  [...]
  "unsafe-fp-math"="true"
}
```
The `"unsafe-fp-math"="true"` function attribute allows the backend code
generator to perform `(fadd (fmul a, b), c) -> (fmadd a, b, c)`.

In the current IR representation there is no way to determine the
statement boundaries from the original source code.
Because of this for in-statement only contraction the generated IR
doesn't have instructions with the `contract` fast-math flag and
`llvm.fmuladd` is being used to represent contractions opportunities
that occur within a single statement.
Therefore `"unsafe-fp-math"="true"` can only be emitted when contraction
across statements is allowed.

Moreover the change in `84a9ec2ff1ee97fd7e8ed988f5e7b197aab84a7` doesn't
take into account that the floating point math function attributes can
be refined during IR code generation of a function to handle the cases
where the floating point math options are modified within a compound
statement via pragmas (see `CGFPOptionsRAII`).
For consistency `unsafe-fp-math` needs to be disabled if the contraction
mode for any scope/operation is not `fast`.
Similarly for consistency reason the initialization of `UnsafeFPMath` of
in `TargetOptions` for the backend code generation should take into
account the contraction mode as well.

Reviewed By: zahiraam

Differential Revision: https://reviews.llvm.org/D136786
2022-11-14 20:40:57 -08:00
Chuanqi Xu 9044226ba2 [NFC] [C++20] [Modules] Remove unused Global Module Fragment variables/arguments 2022-11-15 11:51:13 +08:00
Fangrui Song 77bf0df376 Revert "[opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm"
This reverts commit bf8381a8bc.

There is a layering violation: LLVMAnalysis depends on LLVMCore, so
LLVMCore should not include LLVMAnalysis header
llvm/Analysis/ModuleSummaryAnalysis.h
2022-11-14 15:51:03 -08:00
Alexander Shaposhnikov bf8381a8bc [opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm
Enable using -module-summary with -S
(similarly to what currently can be achieved with opt <input> -o - | llvm-dis).
This is a recommit of ef9e62469.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D137768
2022-11-14 23:24:08 +00:00
Alexander Shaposhnikov 8c15c17e3b Revert "[opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm"
This reverts commit ef9e624694
for further investigation offline.
It appears to break the buildbot
llvm-clang-x86_64-sie-ubuntu-fast.
2022-11-14 21:31:30 +00:00
Alexander Shaposhnikov ef9e624694 [opt][clang] Enable using -module-summary/-flto=thin with -S/-emit-llvm
Enable using -module-summary with -S
(similarly to what currently can be achieved with opt <input> -o - | llvm-dis).

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D137768
2022-11-14 21:11:07 +00:00
Matt Arsenault 840a793375 clang/AMDGPU: Use Support's wrapper around getenv
This does some extra stuff for Windows, so might as well
use it just in case.
2022-11-14 11:07:31 -08:00
Arthur Eubanks cbcf123af2 [LegacyPM] Remove cl::opts controlling optimization pass manager passes
Move these to the new PM if they're used there.

Part of removing the legacy pass manager for optimization pipeline.

Reland with UseNewGVN usage in clang removed.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D137915
2022-11-14 09:38:17 -08:00
Akash Banerjee 87f652d31f Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.
This patch removes getOrCreateInternalVariable from Clang OMP CodeGen and replaces it's uses with OMPBuilder::getOrCreateInternalVariable. Also refactors OMPBuilder::getOrCreateInternalVariable to change type of name from Twine to StringRef

Differential Revision: https://reviews.llvm.org/D137720
2022-11-14 17:18:10 +00:00
Haojian Wu dd46a08008 Move the isSelfContainedHeader function from clangd to libtooling.
We plan to reuse it in the include-cleaner library, this patch moves
this functionality from clangd to libtooling, so that this piece of code can be
shared among all clang tools.

Differential Revision: https://reviews.llvm.org/D137697
2022-11-14 09:40:45 +01:00
Chuanqi Xu 360c5fe54c [C++20] [Modules] Emit Macro Definition in -module-file-info action
It is helpful to know whih macro definition is emitted in the module
file without openning it directly. And this is not easy to be tested
with the lit test. So this patch add the facility to emit macro
definitions in `-module-file-info` action. And this should be innnocent
for every other cases.
2022-11-14 13:28:26 +08:00
Micah Weston e864ac6945 [clang-format] Treats &/&& as reference when followed by ',' or ')'
Ran into an issue where function declarations inside function
scopes or uses of sizeof inside a function would treat the && in
'sizeof(Type &&)' as a binary operator.

Attempt to fix this by assuming reference when followed by ',' or
')'. Also adds tests for these.

Also hit an edge case in another test that treated "and" the same
as "&&" since it parses as C++. Changed the "and" to "also" so it
is no longer a keyword.

Fixes #58923.

Differential Revision: https://reviews.llvm.org/D137755
2022-11-12 00:58:58 -08:00
Owen Pan 96e23906b5 [clang-format] Correctly annotate function names before attributes
Fixes #58827.

Differential Revision: https://reviews.llvm.org/D137486
2022-11-12 00:40:46 -08:00
Matt Arsenault 76db4e3c43 clang: Fix unnecessary truncation of resource limit values 2022-11-11 16:38:51 -08:00
Alex Brachet 28e07984c3 Revert "[Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms."
This reverts commit f64802e8d3.
2022-11-11 19:40:08 +00:00
Zahira Ammarguellat 91628f0616 The handling of 'funsafe-math-optimizations' doesn't update the 'MathErrno'
flag. But the driver checks for 'fno-math-errno' before passing
'funsafe-math-optimizations' to the FE. In GCC, the option
'funsafe-math-optimizations' doesn't affect the 'fmath-errno' flag.
This patch aligns clang with GCC.

'-ffast-math' sets the FPContract to 'fast'. But 'funsafe-math-optimizations'
the driver doesn't consider the FPContract when handling the option.
Unfortunately there are places in the BE that interpret unsafe math
mode as allowing FMA. This patch makes -ffast-math' and
'funsafe-math-optimizations' behave similarly in regard to the setting of the
FPContract.

Differential Revision: https://reviews.llvm.org/D137578
2022-11-11 10:24:12 -05:00
wanglei 1da74eeb0e [Clang][LoongArch] Remove duplicate declaration. NFC 2022-11-11 20:36:18 +08:00
Timm Bäder 99d3ead44c [clang][Interp] Protect Record creation against infinite recursion
This happens only in error cases, but we need to handle it anyway.

Differential Revision: https://reviews.llvm.org/D136831
2022-11-11 08:38:06 +01:00
Timm Bäder 0dcfd0ce02 [clang][Interp] Support alignof()
Support alignof() and __alignof() expressions.

Fixes #58816

Differential Revision: https://reviews.llvm.org/D137240
2022-11-11 08:38:06 +01:00
Timm Bäder 7863646fd2 [clang][Interp] DerivedToBase casts
Differential Revision: https://reviews.llvm.org/D137545
2022-11-11 08:38:06 +01:00
Joshua Batista a5d14f757b Add builtin_elementwise_sin and builtin_elementwise_cos
Add codegen for llvm cos and sin elementwise builtins
The sin and cos elementwise builtins are necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered
when these functions are given inputs of incompatible types.
The new builtins are restricted to floating point types only.

Reviewed By: craig.topper, fhahn

Differential Revision: https://reviews.llvm.org/D135011
2022-11-10 23:30:27 -08:00
gonglingqin da34aff90d [Clang][LoongArch] Implement __builtin_loongarch_crc_w_d_w builtin and add diagnostics
This patch adds support to prevent __builtin_loongarch_crc_w_d_w from compiling
on loongarch32 in the front end and adds diagnostics accordingly.

Reference: https://github.com/gcc-mirror/gcc/blob/master/gcc/config/loongarch/larchintrin.h#L175-L184

Depends on D136906

Differential Revision: https://reviews.llvm.org/D137316
2022-11-11 09:16:57 +08:00
Björn Schäpers 316e259902 [clang-format][NFC] More sorting in getLLVMStyle()
Seems I've missed that.

Amends 41a09a07ce
2022-11-10 22:36:25 +01:00
Anastasiia Lukianenko f6b252978c [clang-format] Add BreakBeforeInlineASMColon configuration
If true, colons in ASM parameters will be placed after line breaks.

true:
asm volatile("string",
                     :
                     : val);

false:
asm volatile("string", : : val);

Differential Revision: https://reviews.llvm.org/D91950
2022-11-10 22:31:09 +01:00
Anastasia Stulova 790cbaafc9 [OpenCL] Fix diagnostics with templates in kernel args.
Improve checking for the standard layout type when diagnosing
the kernel argument with templated types. The check doesn't work
correctly for references or pointers due to the lazy template
instantiation.

Current fix only improves cases where nested types in the templates
do not depend on the template parameters.

Differential Revision: https://reviews.llvm.org/D134445
2022-11-10 18:55:12 +00:00
Tarun Prabhu c3821b8d2a [flang] Add -fpass-plugin option to flang
This patch adds the -fpass-plugin option to flang which dynamically loads LLVM
passes from the shared object passed as the argument to the flag. The behavior
of the option is designed to replicate that of the same option in clang and
thus has the same capabilities and limitations.

Features:

  Multiple instances of -fpass-plugin=path-to-file can be specified and each
  of the files will be loaded in that order.

  The flag can be passed to both flang-new and flang-new -fc1.

  The flag will be listed when the -help flag is passed to both flang-new and
  flang-new -fc1. It will also be listed when the --help-hidden flag is passed.

Limitations:

  Dynamically loaded plugins are not supported in clang on Windows and are not
  supported in flang either.

Addenda:

  Some minor stylistic changes are made in the files that were modified to
  enable this functionality. Those changes make the naming of functions more
  consistent, but do not change any functionality that is not directly
  related to enabling -fpass-plugin.

Differential Revision: https://reviews.llvm.org/D129156
2022-11-10 08:03:46 -07:00
Timm Bäder e1b88c8a09 [clang] Only use major version in resource dir
This causes unnecessary churn for downstreams.

For the full discussion, see https://discourse.llvm.org/t/should-we-continue-embed-the-full-llvm-version-in-lib-clang/62094

Differential Revision: https://reviews.llvm.org/D125860
2022-11-10 15:02:03 +01:00
gonglingqin 85f08c4197 [Clang][LoongArch] Implement __builtin_loongarch_dbar builtin
Differential Revision: https://reviews.llvm.org/D136906
2022-11-10 17:27:44 +08:00
Weining Lu 60e5cfe2a4 [Clang][LoongArch] Define more LoongArch specific built-in macros
Define below macros according to LoongArch toolchain conventions [1].

* `__loongarch_grlen`
* `__loongarch_frlen`
* `__loongarch_lp64`
* `__loongarch_hard_float`
* `__loongarch_soft_float`
* `__loongarch_single_float`
* `__loongarch_double_float`

Note:
1. `__loongarch__` has been defined in earlier patch.
2. `__loongarch_arch` is not defined because I don't know how `TargetInfo` can get the arch name specified by `-march`.
3. `__loongarch_tune` will be defined in future.

[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html

Depends on D136146

Differential Revision: https://reviews.llvm.org/D136413
2022-11-10 17:27:29 +08:00
Weining Lu 135a9272a4 [Clang][LoongArch] Handle -march/-m{single,double,soft}-float/-mfpu options
This patch adds options -march, -msingle-float, -mdouble-float,
-msoft-float and -mfpu for LoongArch.

Clang options `msingle_float` and `mdouble_float` are moved from
`m_mips_Features_Group` to `m_Group` because now more than targets use
them.

Reference:
https://github.com/loongson/LoongArch-Documentation/blob/main/docs/LoongArch-toolchain-conventions-EN.adoc

TODO: add -mtune.

Differential Revision: https://reviews.llvm.org/D136146
2022-11-10 17:27:28 +08:00
Matt Jacobson dd9f7963e4 [ObjC] avoid crashing when emitting synthesized getter/setter and ptrdiff_t is smaller than long
On targets where ptrdiff_t is smaller than long, clang crashes when emitting
synthesized getters/setters that call objc_[gs]etProperty.  Explicitly emit a
zext/trunc of the ivar offset value (which is defined to long) to ptrdiff_t,
which objc_[gs]etProperty takes.

Add a test using the AVR target, where ptrdiff_t is smaller than long. Test
failed previously and passes now.

Differential Revision: https://reviews.llvm.org/D112049
2022-11-10 02:10:30 -05:00
Tomasz Kamiński 2fb3bec932 [analyzer] Fix crash for array-delete of UnknownVal values.
We now skip the destruction of array elements for `delete[] p`,
if the value of `p` is UnknownVal and does not have corresponding region.
This eliminate the crash in `getDynamicElementCount` on that
region and matches the behavior for deleting the array of
non-constant range.

Reviewed By: isuckatcs

Differential Revision: https://reviews.llvm.org/D136671
2022-11-09 15:06:46 +01:00
Sven van Haastregt 0f4f246783 [OpenCL] Guard read_write image3d with cl_khr_3d_image_writes
Not all `read_write image3d_t` occurrences in opencl-c.h were guarded
with `cl_khr_3d_image_writes`.  Align with `-fdeclare-opencl-builtins`.
2022-11-09 13:17:59 +00:00
Tomas Matheson 103bbddde6 [ARM] Move Triple::getARMCPUForArch into ARMTargetParser
This is very backend specific so either belongs in Toolchains/ARM or in
ARMTargetParser. Since it is used in lldb, ARMTargetParser made more sense.

This is part of an effort to move information about ARM/AArch64 architecture
versions, extensions and CPUs into their respective TargetParsers.

Differential Revision: https://reviews.llvm.org/D137564
2022-11-09 11:52:35 +00:00
OCHyams 4b6b2b1a42 Reapply: [Assignment Tracking][7/*] Add assignment tracking functionality to clang
Reverted in 98fa95492f.

The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

This patch plumbs the AssignmentTrackingPass (AKA declare-to-assign), added in
the previous patch in this set, into the optimisation pipeline from
clang. clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp is the
main test for this patch.

Note: while clang (with the help of the declare-to-assign pass) can now emit
Assignment Tracking metadata, the llvm middle and back ends don't yet
understand it.

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D132226
2022-11-09 09:28:41 +00:00
Freddy Ye 84a18a260e [X86] Support -march=sierraforest, grandridge, graniterapids.
Reviewed By: skan, pengfei, MaskRay

Differential Revision: https://reviews.llvm.org/D137153
2022-11-09 16:56:03 +08:00
Fangrui Song 8c2c62282f [Driver] Refactor err_drv_unsupported_option_argument call sites to use llvm::opt::Arg::getSpelling
For `-foo=bar`, getSpelling return `-foo=` which is exactly what we need from
the diagnostic. Drop `-` from the err_drv_unsupported_option_argument template.
This change makes `--` long option diagnostics more convenient.

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D137659
2022-11-08 14:39:09 -08:00
Björn Schäpers 41a09a07ce [clang-format][NFCish] Alphabetical sort Format.(h|pp)
I've:
- Sorted the members of FormatStyle alphabetical. The enums and structs
  are kept close to the member.
- Sorted the yaml io functions, based on the type they operate on.
- Sorted the initializers in getLLVMStyle(), except that penalities are
  kept at the end.
- Sorted the io of FormatStyle, this changes the --dump-config behavior.
- Moved the deprecated options into the only input case, this also
  changes --dump-config, it does not put the not directly used options
  in the .clang-format anymore.
- Sorted the comparisons in operator==.
- Added WhiteSpaceMacros in operator==, I've not actively looked if all
  other members are compared.
- This showed flawed tests (or in my opinion a flawed io operation, but
  that is another discussion and change).

Differential Revision: https://reviews.llvm.org/D137409
2022-11-08 21:46:15 +01:00
David Green f0e6c403c2 [AArch64] Allow users-facing feature names in clang target attributes
D133848 added support for the GCC format of target("..") attributes. The
supported formats to match gcc are:
//  "arch=<arch>" - parsed to features as per -march=..
//  "cpu=<cpu>" - parsed to features as per -mcpu=.., with CPU set to <cpu>
//  "tune=<cpu>" - TuneCPU set to <cpu>
//  "+feature", "+nofeature" - Add (or remove) feature.

We also support the existing formats, previously accepted by clang, for
compatibility with the existing code and intrinsics code:
//  "feature", "no-feature" - Add (or remove) feature.

The clang formats would accept and use internal feature names
("fullfp16"/"neon"/"sve") as opposed to the user facing names
("fp16"/"simd"/"sve"). Usually they use the same names, but can be
different for cases like fp, fullfp16 and mte (among others).

This patch makes the clang format also except the user facing names, by
parsing the features through getArchExtFeature. There is a fallback if
the name is not recognized (like "fullfp16"), where we add the existing
string which should then be checked later for consistency. This allows
the internal names to be used as before, so long as they are recognized
as internal names. (Note that we currently don't have an implementation
of isValidFeatureName. The backend will currently give an error like
"'-sid' is not a recognized feature for this target (ignoring feature)."
This should be improved in a later patch once an implementation of
isValidFeatureName in clang is present).

Differential Revision: https://reviews.llvm.org/D137617
2022-11-08 19:30:26 +00:00
Adhemerval Zanella 9e956995db [clang][Headers] Do not define varargs macros for __need___va_list
The glibc uses the define to avoid namespace polution on headers
that requires variadic argument, where the inclusion of stdarg.h is
required to obtain the va_list definition.

For such cases only __gnuc_va_list is required.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D137268
2022-11-08 16:29:35 -03:00
OCHyams 98fa95492f Revert "[Assignment Tracking][7/*] Add assignment tracking functionality to clang"
This reverts commit 28f9636edd.

Bot failure: https://lab.llvm.org/buildbot/#/builders/109/builds/50251
2022-11-08 18:43:05 +00:00
OCHyams 28f9636edd [Assignment Tracking][7/*] Add assignment tracking functionality to clang
The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

This patch plumbs the AssignmentTrackingPass (AKA declare-to-assign), added in
the previous patch in this set, into the optimisation pipeline from
clang. clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp is the
main test for this patch.

Note: while clang (with the help of the declare-to-assign pass) can now emit
Assignment Tracking metadata, the llvm middle and back ends don't yet
understand it.

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D132226
2022-11-08 17:49:08 +00:00
Adhemerval Zanella 92e172309c [clang][Headers] Only define FLT_EVAL_METHOD for C99 and later
It was reported by glibc conform test [1].

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=conform/data/float.h-data;h=7b98fc03447b8918da4a0cf47d41fb3e17f4f791;hb=HEAD

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D137267
2022-11-08 13:58:37 -03:00
Alexander Kornienko a5c18fcf6e Revert "[clang] Instantiate alias templates with sugar"
This reverts commit 279fe6281d, which causes
non-linear compilation time growth. See https://reviews.llvm.org/D136565#3914755
2022-11-08 17:19:54 +01:00
Rageking8 94738a5ac3 Fix duplicate word typos; NFC
This revision fixes typos where there are 2 consecutive words which are
duplicated. There should be no code changes in this revision (only
changes to comments and docs). Do let me know if there are any
undesirable changes in this revision. Thanks.
2022-11-08 07:21:23 -05:00
Timm Bäder 73ecff2333 [clang][Sema][NFC] Remove two nonsensical dyn_cast_or_null
The values used here are never null.
2022-11-08 12:47:41 +01:00
Chuanqi Xu d1f90b6129 [NFC] [C++20] [Modules] Rename ASTWriter::isWritingStdCXXNamedModules
According to the discussion in
https://discourse.llvm.org/t/rfc-unifying-the-terminology-about-modules-in-clang/66054,
this patch rename ASTWriter::isWritingNamedModules to ASTWriter::isWrittingStdCXXNamedModules
to make the name more clear.
2022-11-08 15:58:46 +08:00
haoyuintel 13f83365cd [Driver] Add -fsample-profile-use-profi
This patch enable `-sample-profile-use-profi` in Clang frontend as user-facing
feature. By using this patch, we can use the cflag of `-fsample-profile-use-profi`
instead of `-mllvm -sample-profile-use-profi`.

Reviewed By: hans, MaskRay

Differential Revision: https://reviews.llvm.org/D136846
2022-11-08 15:51:38 +08:00
Sami Tolvanen 41ce74e6e9 [Clang][Sema] Add -Wincompatible-function-pointer-types-strict
Clang supports indirect call Control-Flow Integrity (CFI) sanitizers
(e.g. -fsanitize=cfi-icall), which enforce an exact type match
between a function pointer and the target function. Unfortunately,
Clang doesn't provide diagnostics that help developers avoid
function pointer assignments that can lead to runtime CFI
failures. -Wincompatible-function-pointer-types doesn't warn about
enum to integer mismatches if the types are otherwise compatible, for
example, which isn't sufficient with CFI.

Add -Wincompatible-function-pointer-types-strict, which checks for a
stricter function type compatibility in assignments and helps warn about
assignments that can potentially lead to CFI failures.

Reviewed By: aaron.ballman, nickdesaulniers

Differential Revision: https://reviews.llvm.org/D136790
2022-11-07 23:05:28 +00:00
Amara Emerson f64802e8d3 [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.
Differential Revision: https://reviews.llvm.org/D137269
2022-11-07 15:04:09 -08:00
Grace Jennings 86674f66cc [HLSL] Added HLSL this as a reference
This change makes `this` a reference instead of a pointer in
HLSL. HLSL does not have the `->` operator, and accesses through `this`
are with the `.` syntax.

Tests were added and altered to make sure
the AST accurately reflects the types.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D135721
2022-11-07 13:50:08 -08:00
Arthur Eubanks cd8c6ab084 [NFC] clang-format part of TypePrinter.cpp
Fixes weird clang-format indentation with an upcoming patch.
2022-11-07 13:20:36 -08:00
Matthias Braun cafe50daf5 Explicitly initialize opaque pointer mode in CodeGenAction
Explicitly call `LLVMContext::setOpaquePointers` in `CodeGenAction`
before loading any IR files. With this we use the mode specified on the
command-line rather than lazily initializing it based on the contents of
the IR.

This helps when using `-fthinlto-index` which may end up mixing files
with typed and opaque pointer types which fails when the first file
happened to use typed pointers since we cannot downgrade IR with opaque
pointer types to typed pointer types.

Differential Revision: https://reviews.llvm.org/D137475
2022-11-07 12:31:28 -08:00
Nathan James 108e41d962
[clang][NFC] Use c++17 style variable type traits
This was done as a test for D137302 and it makes sense to push these changes

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D137491
2022-11-07 18:25:48 +00:00
Daniel Grumberg 39dbfa72aa Revert "Only add targetFallback if target is not in defined in current product"
This was an accidental addition of a non-reviewed change.

This reverts commit f63db9159b.
2022-11-07 13:33:59 +00:00
Daniel Grumberg f63db9159b Only add targetFallback if target is not in defined in current product 2022-11-07 13:12:34 +00:00
Daniel Grumberg 671709f0e7 [clang][ExtractAPI] Add targetFallback to relationships in symbol graph
Adds a 'targetFallback' field to relationships in symbol graph that
contains the plain name of the relationship target. This is useful for
clients when the relationship target symbol is not available.

Differential Revision: https://reviews.llvm.org/D136455
2022-11-07 13:12:34 +00:00
Timm Bäder 5dfacb1245 [clang][Interp][NFC] Replace dyn_cast_or_null with _if_present
... in Descriptor.h
2022-11-07 09:42:41 +01:00
Timm Bäder 5bd6bd1227 [clang][Interp][NFC] Simplify visitReturnStmt() 2022-11-07 09:42:41 +01:00
Timm Bäder 6b3e5c595b [clang][Interp][NFC] Remove unused function 2022-11-07 09:42:41 +01:00
Timm Bäder c8341a6615 [clang][Interp][NFC] Avoid a getSource() call in the common case
In the common (successful) case, we don't need the getSource() call, so
move it to the two if statement bodies instead.
2022-11-07 09:42:41 +01:00
Timm Bäder f4707af294 [clang][Interp][NFCI] Cleanup emitConst()
Before, when emitting a regular integer constant, we went:

Int -> APInt -> int -> emit

Fix this by using regular integer constants in emitConst() and instead
converting APInt to those once.
2022-11-07 09:05:29 +01:00
Timm Bäder 05a113e188 [clang][Interp][NFC] Handle discarded ArraySubscriptExprs
This is not exactly a common case, so just pop the pointer at the end if
necessary.
2022-11-07 08:37:43 +01:00
Tobias Hieta 70de684d44
[clang-format] Handle object instansiation in if-statements
Before this patch code like this:

```
if (Class* obj{getObject()}) { }
```

would be mis-formated since the * would be annotated as a
binaryoperator.

This patch changes the * to become a PointerOrReference instead
and fixes the formatting issues.

Reviewed By: HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D137327
2022-11-07 08:34:57 +01:00
Timm Bäder 9a3b969d1f [clang][Interp][NFC] Make InitField() not pop the pointer
This was confusing. InitElem peeks a pointer, while InitElemPop will
pop the pointer. However, for fields, InitField would pop the pointer
and no InitFieldPop exists. At least make InitField and InitElem behave
the same.
2022-11-07 08:30:43 +01:00
Timm Bäder 7c0a2d9cda [clang][Interp][NFC] Use StorePop for assignments with DiscardResult
If we don't need the result anyway, use StorePop, instead of a Store+Pop
combination. That way we save one instruction and not using the result
is the common case anyway.
2022-11-07 07:56:25 +01:00
Timm Bäder 10483ac743 [clang][Interp] Support pointer arithmethic in binary operators
Differential Revision: https://reviews.llvm.org/D135858
2022-11-07 07:47:19 +01:00
Timm Bäder 27f5f33c81 [clang][Interp][NFC] Remove an unused include
And an unnecessary private marker.
2022-11-07 06:34:22 +01:00
Kazu Hirata 94186347a1 [clang] Use llvm::reverse (NFC) 2022-11-06 21:09:20 -08:00
Kazu Hirata 2a67cc77e2 [Sema] Use llvm::is_contained (NFC) 2022-11-06 20:04:53 -08:00
wangpc 7c50bcb441 [RISCV] Support -mcpu/mtune=native
We may need hosted Clang/LLVM to compile and `getHostCpuName`
can be used for native detection.

Tests are added in riscv-cpus.c just like what AArch64/PPC
have done.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D136930
2022-11-07 10:43:32 +08:00
Fangrui Song 7aa90b21b4 [PowerPC] Replace __ppc64__ with __powerpc64__
The lowercase __ppc64__ is not defined by non-darwin GCC, therefore it lures
users to write code which is not portable to GCC. Migrate to __powerpc64__ in
preparation for undefining __ppc64__. __powerpc64__ is much more common than
__PPC64__.
2022-11-06 16:16:50 -08:00
Sylvestre Ledru d1829c308d Add support of the next Ubuntu (Ubuntu 23.04 - Lunar Lobster) 2022-11-05 22:35:54 +01:00
Jennifer Yu de14befa77 Remove redundant loads.
It is caused by regenerate captured var value when processing the
has_device_addr, the captured var value has been generated in
GenerateOpenMPCapturedVars and passed as Arg in generateInfoForCapture.
The fix just use Arg instead regenerated just same as is_device_ptr
2022-11-04 15:22:25 -07:00
Corentin Jabot 35a870c30a Revert "Implement CWG2631"
This reverts commit 7acfe36294.
This reverts commit 5f87a892a7.
This reverts commit 6875ac6927.
2022-11-04 22:10:50 +01:00
Mike Rice c954cfeb57 Some uses of the preprocessor can result in multiple target regions on the
same line. Cases such as those in the associated lit tests, can now be
supported.

This adds a 'Count' field to TargetRegionEntryInfo to differentiate
regions with the same source position.

The OffloadEntriesInfoManager routines are updated to maintain a count of
regions seen at a location. The registration of regions proceeds that same as
before, but now the next available count is always determined and used in the
offload entry.

Fixes: https://github.com/llvm/llvm-project/issues/52707

Differential Revision: https://reviews.llvm.org/D134816
2022-11-04 12:54:22 -07:00
Tom Eccles d0d4b63578 [flang] add -f[no-]reciprocal-math
Only add the option processing and store the result. No attributes are
added to FIR yet.

Differential Revision: https://reviews.llvm.org/D137330
2022-11-04 17:22:35 +00:00
Tom Eccles c4dc3c0294 [flang] Add -f[no-]associative-math and -mreassociate
Only add the option processing and store the result. No attributes are
added to FIR yet.

Clang only forwards -mreassociate
if (AssociativeMath && !SignedZeros && !TrappingMath)

Flang doesn't have -f[no-]trapping-math, so this part of the condition
has been omitted. !TrappingMath is the default.

Differential Revision: https://reviews.llvm.org/D137329
2022-11-04 17:22:35 +00:00
Tom Eccles b5b8a8cfbe [flang] Add -f[no-]signed-zeros
Only add the option processing and store the result. No attributes are
added to FIR yet.

Differential Revision: https://reviews.llvm.org/D137328
2022-11-04 17:22:34 +00:00
Tom Eccles 36b37a1ed5 [flang] Add -f[no-]approx-func
Only add the option processing and store the result. No attributes are
added to FIR yet.

Differential Revision: https://reviews.llvm.org/D137326
2022-11-04 17:22:34 +00:00
Tom Eccles b5e93e390c [flang] Add -f[no-]honor-nans and -menable-no-nans
Only add the option processing and store the result. No attributes are
added to FIR yet.

Differential Revision: https://reviews.llvm.org/D137325
2022-11-04 17:22:34 +00:00
Corentin Jabot 6875ac6927 [clang] Remove an incorrect assert
Compound statements can appear in default arguments
but should not be visited in ImmediateCallVisitor as they are
not subexpressions
2022-11-04 15:46:22 +01:00
Corentin Jabot 5f87a892a7 [clang] Fix assert in SemaEXpr.cpp 2022-11-04 15:37:37 +01:00
Corentin Jabot 7acfe36294 Implement CWG2631
Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

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

Differential Revision: https://reviews.llvm.org/D136554
2022-11-04 14:46:38 +01:00
Nikita Popov 304f1d59ca [IR] Switch everything to use memory attribute
This switches everything to use the memory attribute proposed in
https://discourse.llvm.org/t/rfc-unify-memory-effect-attributes/65579.
The old argmemonly, inaccessiblememonly and inaccessiblemem_or_argmemonly
attributes are dropped. The readnone, readonly and writeonly attributes
are restricted to parameters only.

The old attributes are auto-upgraded both in bitcode and IR.
The bitcode upgrade is a policy requirement that has to be retained
indefinitely. The IR upgrade is mainly there so it's not necessary
to update all tests using memory attributes in this patch, which
is already large enough. We could drop that part after migrating
tests, or retain it longer term, to make it easier to import IR
from older LLVM versions.

High-level Function/CallBase APIs like doesNotAccessMemory() or
setDoesNotAccessMemory() are mapped transparently to the memory
attribute. Code that directly manipulates attributes (e.g. via
AttributeList) on the other hand needs to switch to working with
the memory attribute instead.

Differential Revision: https://reviews.llvm.org/D135780
2022-11-04 10:21:38 +01:00
Owen Pan e787708bcf [clang-format][NFC] Remove parsePPElIf()
Differential Revision: https://reviews.llvm.org/D137308
2022-11-04 00:38:40 -07:00
Pierre van Houtryve c05f1639f7 [clang][cuda/hip] Allow `__noinline__` lambdas
D124866 seem to have had an unintended side effect: __noinline__ on lambdas was no longer accepted.

This fixes the regression and adds a test case for it.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D137251
2022-11-04 07:33:31 +00:00
Corentin Jabot 722a0efe31 Revert "Implement CWG2631"
Breaks the build on some platforms.

This reverts commit bf1e235695.
2022-11-04 08:24:52 +01:00
Corentin Jabot bf1e235695 Implement CWG2631
Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

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

Differential Revision: https://reviews.llvm.org/D136554
2022-11-04 07:58:57 +01:00
Phoebe Wang 5251678297 [X86][CET] Add Diags for targets pre to i686 for `-fcf-protection`
Intel Control-flow Enforcement Technology (CET) provides new instructions `endbr32/64` for the indirect branch control. They are NOPs on i686 and new targets. We need to check for that in case it crashes on older targets.

Fixes #58737

Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D137317
2022-11-04 12:38:29 +08:00
Freddy Ye a806fc2767 [X86] Support -march=raptorlake, meteorlake
Reviewed By: pengfei, skan, MaskRay

Differential Revision: https://reviews.llvm.org/D135937
2022-11-04 09:32:17 +08:00
Yitzhak Mandelbaum c0725865b1 [clang][dataflow] Generalize custom comparison to return tri-value result.
Currently, the API for a model's custom value comparison returns a
boolean. Therefore, models cannot distinguish between situations where the
values are recognized by the model and different and those where the values are
just not recognized.  This patch changes the return value to a tri-valued enum,
allowing models to express "don't know".

This patch is essentially a NFC -- no practical differences result from this
change in this patch. But, it prepares for future patches (particularly,
upcoming patches for widening) which will take advantage of the new flexibility.

Differential Revision: https://reviews.llvm.org/D137334
2022-11-03 23:31:20 +00:00
Manoj Gupta 2497d5aa77 Define _GNU_SOURCE for arm baremetal in C++ mode.
This matches other C++ drivers e.g. Linux that define
_GNU_SOURCE. This lets clang compiler more code by default
without explicitly passing _GNU_SOURCE on command line.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D136712
2022-11-03 13:58:47 -07:00
Sam James 20132d8eaa Link libclangBasic against libatomic when necessary.
This is necessary at least on PPC32.

Depends on D136280.

Bug: https://bugs.gentoo.org/874024
Thanks-to: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Tested-by: erhard_f@mailbox.org <erhard_f@mailbox.org>

Differential Revision: https://reviews.llvm.org/D136282
2022-11-03 21:07:44 +01:00
Jan Sjodin 9ea2b150b5 [OpenMP][OMPIRBuilder] Migrate createOffloadEntriesAndInfoMetadata from clang to OpenMPIRBuilder
This patch moves the createOffloadEntriesAndInfoMetadata to OpenMPIRBuilder,
the createOffloadEntry helper function. The clang specific error handling is
invoked using a callback. This code will also be used by flang in the future.
2022-11-03 10:27:44 -04:00
Aaron Ballman 37f80101a9 Silence a "not all control paths return" MSVC warning; NFC 2022-11-03 10:27:16 -04:00
Haojian Wu 964c4948cd Remove an unused local variable, NFC. 2022-11-03 13:57:46 +01:00
Aaron Ballman b8ceb9f4e4 [C++20] Diagnose invalid and reserved module names
[module.unit]p1 specifies that module and import are invalid components
of a module name, that module names cannot contain reserved
identifiers, and that std followed by zero or more digits is reserved.

The first issue (module and import pseudo-keywords) requires a
diagnostic, the second issue (use of reserved identifiers) does not
require a diagnostic. We diagnose both the same -- the code is ill-
formed unless the module declaration is in a system "header". This
allows STL implementations to use the reserved module names while
preventing users from stealing them out from under us.

Differential Revision: https://reviews.llvm.org/D136953
2022-11-03 08:29:59 -04:00
Corentin Jabot 742970920b [Clang] Implement CWG2358 Explicit capture of value
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D137172
2022-11-03 13:27:11 +01:00
Björn Schäpers f97639ce13 [clang-format] Don't misannotate in CTor init list
They were annotated with TrailingAnnotation, which they are not. And
that resulted in some quirky formatting in some cases.

Differential Revision: https://reviews.llvm.org/D136635
2022-11-03 13:08:48 +01:00
Björn Schäpers cdbe296853 [clang-format] Fix lambda formatting in conditional
Without the patch UnwrappedLineFormatter::analyzeSolutionSpace just ran
out of possible formattings and would put everything just on one line.
The problem was that the the line break was forbidden, but putting the
conditional colon on the same line is also forbidden.

Differential Revision: https://reviews.llvm.org/D135918
2022-11-03 13:08:14 +01:00
Tom Eccles 0fb763e7d0 [flang] Add -f[no-]honor-infinities and -menable-no-infs
Only add the option processing and store the result. No attributes are
added to FIR yet.

This patch follows Clang in forwarding -fno-honor-infinities as
-menable-no-infs.

Reviewed By: kiranchandramohan awarzynski vzakhari

Differential Revision: https://reviews.llvm.org/D137072
2022-11-03 10:38:09 +00:00
Peter Waller 8cb9e3c3ce [AArch64] Install arm_neon_sve_bridge.h
arm_neon_sve_bridge.h is not generated, so the rules which ensure the
generated files get copied into the installation prefix don't apply to
this one.

Add it to the aarch64_only_files set instead, which ensures it ends up
both in the build directory and the installation directory.

Tested with build targets `clang-resource-headers` and
`install-clang-resource-headers`.

Differential Revision: https://reviews.llvm.org/D137239
2022-11-03 07:55:57 +00:00
Fangrui Song 1ada819c23 [asan] Default to -fsanitize-address-use-odr-indicator for non-Windows
This enables odr indicators on all platforms and private aliases on non-Windows.
Note that GCC also uses private aliases: this fixes bogus
`The following global variable is not properly aligned.` errors for interposed global variables

Fix https://github.com/google/sanitizers/issues/398
Fix https://github.com/google/sanitizers/issues/1017
Fix https://github.com/llvm/llvm-project/issues/36893 (we can restore D46665)

Global variables of non-hasExactDefinition() linkages (i.e.
linkonce/linkonce_odr/weak/weak_odr/common/external_weak) are not instrumented.
If an instrumented variable gets interposed to an uninstrumented variable due to
symbol interposition (e.g. in issue 36893, _ZTS1A in foo.so is resolved to _ZTS1A in
the executable), there may be a bogus error.

With private aliases, the register code will not resolve to a definition in
another module, and thus prevent the issue.

Cons: minor size increase. This is mainly due to extra `__odr_asan_gen_*` symbols.
(ELF) In addition, in relocatable files private aliases replace some relocations
referencing global symbols with .L symbols and may introduce some STT_SECTION symbols.

For lld, with -g0, the size increase is 0.07~0.09% for many configurations I
have tested: -O0, -O1, -O2, -O3, -O2 -ffunction-sections -fdata-sections
-Wl,--gc-sections. With -g1 or above, the size increase ratio will be even smaller.

This patch obsoletes D92078.

Don't migrate Windows for now: the static data member of a specialization
`std::num_put<char>::id` is a weak symbol, as well as its ODR indicator.
Unfortunately, link.exe (and lld without -lldmingw) generally doesn't support
duplicate weak definitions (weak symbols in different TUs likely pick different
defined external symbols and conflict).

Differential Revision: https://reviews.llvm.org/D137227
2022-11-02 19:21:33 -07:00
Alex Brachet 78ed64d89f [Driver] Don't preprocess source files when reproducing linker crashes
It's not necessary to redo the source file preprocessing for reproducing linker
crashes because we must have successfully created the object file by this point.
Skip this step, and also don't report the preprocessed source file or create
the clang invocation shell script. The latter is no longer sensible without the
preprocessed source, or helpful given the linker reproducer will have it's own
shell script.

Differential Revision: https://reviews.llvm.org/D137289
2022-11-03 00:12:10 +00:00
Yuanfang Chen 40e9947317 [Clang] follow-up D128745, remove ClangABICompat checks
Per discussions in D128745, remove ClangABICompat checks for implementations
of DR692/DR1395/DR1432. This is a potentially breaking changes, so the release
note is updated accordingly.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D136120
2022-11-02 16:33:10 -07:00
Jennifer Yu ea64e66f7b [OPENMP]Initial support for error directive.
Differential Revision: https://reviews.llvm.org/D137209
2022-11-02 14:25:28 -07:00
Craig Topper b6ad7ab89e [RISCV] Prevent autovectorization using vscale with Zvl32b.
RVVBitsPerBlock is 64. If VLen==32, VLen/RVVBitsPerBlock is 0.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D137280
2022-11-02 13:55:21 -07:00
Alex Lorenz f4be5ed6a3 [clang][pp] only __is_target_environment(unknown) should match unknown target triple environment 2022-11-02 13:49:04 -07:00
Owen Pan 117d792f35 [clang-format] Don't skip #else/#elif of #if 0
Fixes #58188.

Differential Revision: https://reviews.llvm.org/D137052
2022-11-02 13:32:08 -07:00
Martin Storsjö 9b3834ef67 [clang] Fix inline builtin functions of an __asm__ renamed function with symbol prefixes
If a function is renamed with `__asm__`, the name provided is the
exact symbol name, without any extra implicit symbol prefixes.
If the target does use symbol prefixes, the IR level symbol gets
an `\01` prefix to indicate that it's a literal symbol name to be
taken as is.

When a builtin function is specialized by providing an inline
version of it, that inline function is named `<funcname>.inline`.

When the base function has been renamed due to `__asm__`, the inline
function ends up named `<asmname>.inline`. Up to this point,
things did work as expected before.

However, for targets with symbol prefixes, one codepath that produced
the combined name `<asmname>.inline` used the mangled `asmname` with
`\01` prefix, while others didn't. This patch fixes this.

This fixes the combination of asm renamed builtin function, with
inline override of the function, on any target with symbol
prefixes (such as i386 windows and any Darwin target).

Differential Revision: https://reviews.llvm.org/D137073
2022-11-02 22:24:42 +02:00
Craig Topper 6254495c6b [RISCV] Move RVVBitsPerBlock to TargetParser.h so we can use it in clang. NFC
Differential Revision: https://reviews.llvm.org/D137266
2022-11-02 13:09:14 -07:00
Akash Banerjee a3463a9f5c [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder
This patch moves the implementation of the loadOffloadInfoMetadata to the OMPIRbuilder.

Differential Revision: https://reviews.llvm.org/D136872
2022-11-02 18:54:25 +00:00
OCHyams c10a8473f4 [Assignment Tracking][2/*] Add flags to enable Assignment Tracking
The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

Enable in clang: -Xclang -fexperimental-assignment-tracking
Enable in llvm tools: -experimental-assignment-tracking

When assignment tracking is enabled in clang it will pass on the flag to enable
the feature in lllvm. It's undefined behaviour to read IR that contains
assignment tracking metadata without specifying the feature flags.

Tests will come with later patches that add assignment tracking features.

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D132221
2022-11-02 17:06:43 +00:00
Aaron Ballman d7d743621a Reenable POSIX builtin library functions in gnu2x mode
gnu17 and earlier modes automatically expose several POSIX C APIs, and
this was accidentally disabled for gnu2x in
7d644e1215.

This restores the behavior for gnu2x mode (without changing the
behavior in C standards modes instead of GNU modes).

Fixes #56607
2022-11-02 08:00:25 -04:00
Jan Svoboda f33173acd6 [clang][modules][deps] System module maps might not be affecting
The dependency scanner relies on the module map filtering logic in `ASTWriter`. The algorithm currently considers all system module maps affecting, which is not only sub-optimal, but can also cause failures when building a module explicitly (see attached test case).

This patch applies the same filtering logic to system module maps.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D136007
2022-11-01 22:41:40 -07:00
Jan Svoboda 6924a49690 [clang][modules] Account for non-affecting inputs in `ASTWriter`
In D106876, we stopped serializing module map files that didn't affect compilation of the current module.

However, since each `SourceLocation` is simply an offset into `SourceManager`'s global buffer of concatenated input files in, these need to be adjusted during serialization. Otherwise, they can incorrectly point after the buffer or into subsequent input file.

This patch starts adjusting `SourceLocation`s, `FileID`s and other `SourceManager` offsets in `ASTWriter`.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D136624
2022-11-01 19:31:51 -07:00
Jan Svoboda a13122c612 [clang][modules] NFCI: Avoid unnecessary serialization logic for non-affecting files
This patch delays some `ASTWriter` logic until after we've checked whether the source location entry we're serializing as an affecting file or not.

Depends on D137214.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D137216
2022-11-01 19:23:02 -07:00
Jan Svoboda 0bfc97e4f4 [clang][modules] NFCI: Scaffolding for serialization of adjusted SourceManager offsets
This patch is a NFC prep for D136624, where we start adjusting offsets into `SourceManager`.

Depends on D137213.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D137214
2022-11-01 19:06:55 -07:00
Jan Svoboda f61c135a69 [clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation
For pragma diagnostic mappings, we always write/read `SourceLocation` with offset 0. This is equivalent to just writing a `FileID`, which is exactly what this patch starts doing.

Depends on D137211.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D137213
2022-11-01 18:59:17 -07:00
Jan Svoboda fdbc55a51a [clang][modules] NFCI: Unify FileID writing/reading
This patch adds new functions for writing/reading `FileID`s and uses them to replace some ad-hoc code.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D137211
2022-11-01 18:57:13 -07:00
Jan Svoboda 6dda497942 [clang][modules] NFC: Remove unused lambda argument 2022-11-01 16:58:11 -07:00
Arthur Eubanks 29a500b346 [CodeView][clang] Add flag to disable emitting command line into CodeView
In https://reviews.llvm.org/D80833, there were concerns about
determinism emitting the commandline into CodeView. We're actually
hitting these when running clang-cl on Linux (cross compiling) versus on
Windows (e.g. -fmessage-length being inferred on terminals).

Add -g[no-]codeview-command-line to enable/disable this feature.
It's still on by default to preserve the current state of clang.

Reviewed By: thakis, rnk

Differential Revision: https://reviews.llvm.org/D136474
2022-11-01 13:04:37 -07:00
Erich Keane 2cee266333 [Concepts] Correctly handle failure when checking concepts recursively
Based on discussion on the core reflector, it was made clear that a
concept that depends on itself should be a hard error, not a constraint
failure. This patch implements a stack of constraint-checks-in-progress
to make sure we quit, rather than hitting stack-exhaustion.

Note that we DO need to be careful to make sure we still check
constraints properly that are caused by a previous constraint, but not
derived from (such as when a check causes us to check special member
function generation), so we cannot use the existing logic to see if this
is being instantiated.

This fixes https://github.com/llvm/llvm-project/issues/44304 and
https://github.com/llvm/llvm-project/issues/50891.

Differential Revision: https://reviews.llvm.org/D136975
2022-11-01 12:18:58 -07:00
Erich Keane ab4c22e2b7 [Concepts] Improve diagnostics on a missing 'auto' keyword.
As reported in https://github.com/llvm/llvm-project/issues/49192,
we did a pretty poor job diagnosing cases where someone forgot 'auto', a
nd is probably in the middle of a variable declaration.  This patch
makes us properly diagnose in cases where the next token is a reference,
or CVR qualifier.
2022-11-01 11:39:46 -07:00
Troy Johnson 00022c5613 [clang][Lex] Header map search case insensitivity
Correct D135801 to be case insensitive.

Differential Revision: https://reviews.llvm.org/D137179
2022-11-01 11:33:00 -07:00
Yonghong Song 2f047b56ba [clang][Sema] Fix a clang crash with btf_type_tag
For the following program,
  $ cat t.c
  struct t {
   int (__attribute__((btf_type_tag("rcu"))) *f)();
   int a;
  };
  int foo(struct t *arg) {
    return arg->a;
  }
Compiling with 'clang -g -O2 -S t.c' will cause a failure like below:
  clang: /home/yhs/work/llvm-project/clang/lib/Sema/SemaType.cpp:6391: void {anonymous}::DeclaratorLocFiller::VisitParenTypeLoc(clang::ParenTypeLoc):
         Assertion `Chunk.Kind == DeclaratorChunk::Paren' failed.
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  ......
  #5 0x00007f89e4280ea5 abort (/lib64/libc.so.6+0x21ea5)
  #6 0x00007f89e4280d79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)
  #7 0x00007f89e42a6456 (/lib64/libc.so.6+0x47456)
  #8 0x00000000045c2596 GetTypeSourceInfoForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) SemaType.cpp:0:0
  #9 0x00000000045ccfa5 GetFullTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) SemaType.cpp:0:0
  ......

The reason of the failure is due to the mismatch of TypeLoc and D.getTypeObject().Kind. For example,
the TypeLoc is
  BTFTagAttributedType 0x88614e0 'int  btf_type_tag(rcu)()' sugar
  |-ParenType 0x8861480 'int ()' sugar
  | `-FunctionNoProtoType 0x8861450 'int ()' cdecl
  |   `-BuiltinType 0x87fd500 'int'
while corresponding D.getTypeObject().Kind points to DeclaratorChunk::Paren, and
this will cause later assertion.

To fix the issue, similar to AttributedTypeLoc, let us skip BTFTagAttributedTypeLoc in
GetTypeSourceInfoForDeclarator().

Differential Revision: https://reviews.llvm.org/D136807
2022-11-01 08:07:13 -07:00
Aaron Ballman 0933b8c72c Update a stale comment; NFC
This function doesn't return anything these days.
2022-11-01 10:47:30 -04:00
Krzysztof Parzyszek 13918432cf [Hexagon] Add builtins and intrinsics for V6_v[add|sub]carryo 2022-10-31 13:41:31 -07:00
Matheus Izvekov ee1f132d2c
Revert "[clang] ASTImporter: Fix importing of va_list types and declarations"
This reverts commit 5f820c0f55.

Apparently it breaks aarch64 buildbots.
https://lab.llvm.org/buildbot#builders/188/builds/21591
2022-10-31 19:34:23 +01:00
Craig Topper 6fa0e3df97 [X86][Driver] Remove stale FIXME. NFC
We use getHostCPUFeatures in x86::getX86TargetFeatures so I think
this FIXME is taken care of already.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D137054
2022-10-31 10:41:40 -07:00
Craig Topper 06f640d3fb [X86] Enable EVEX GFNI instructions without avx512bw.
We only really need avx512bw for masking 256 or 512 bit GFNI
instructions due to the need for v32i1 or v64i1.

I wanted to enable 128-bit intrinsics with avx512vl, but the
__builtin_ia32_selectb_128 used in the header file requires avx512bw.
The codegen test for the same is also not using a masked instruction
because vselect with v16i1 mask and v16i8 is not legal so is expanded
before isel. To fix these issues we need a mask specific builtin and a
mask specific ISD opcode.

Fixes PR58687.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D137036
2022-10-31 10:31:45 -07:00
Matheus Izvekov 279fe6281d
[clang] Instantiate alias templates with sugar
This makes use of the changes introduced in D134604, in order to
instantiate alias templates witn a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D136565
2022-10-31 17:57:19 +01:00
Matheus Izvekov ab1140874f
[clang] Instantiate NTTPs and template default arguments with sugar
This makes use of the changes introduced in D134604, in order to
instantiate non-type template parameters and default template arguments
with a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D136564
2022-10-31 17:57:18 +01:00
Matheus Izvekov 5f820c0f55
[clang] ASTImporter: Fix importing of va_list types and declarations
This fixes a problem where __va_list_tag was not correctly imported,
possibly leading to multiple definitions with different types.

This adds __va_list_tag to it's proper scope, so that the ASTImporter
can find it.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D136886
2022-10-31 17:57:18 +01:00
Matheus Izvekov edf1a2e893
[clang] Fix handling of unexpanded packs in template argument expressions.
Closes #58679.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D136977
2022-10-31 17:57:17 +01:00
Matheus Izvekov 2492c52a05
[clang] Improve error recovery for pack expansion of expressions
Closes #58673.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D136962
2022-10-31 17:57:13 +01:00
Freddy Ye aee2a35ac4 [X86] Add AVX-NE-CONVERT instructions.
For more details about these instructions, please refer to the latest ISE document: https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D135930
2022-10-31 23:39:38 +08:00
Jan Sjodin 67f8521cd4 [OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target region info
Re-apply of: 3d0e9edd8e
Reverted in: 0cb65b0a58

A function parameter was using the wrong type 'llvm::TargetRegion' instead of
'const llvm:: TargetRegion&', which caused the error in the address sanitizer.
The correct type is now used.

This patch puts the individual target region information attributes into a
struct so that the nested mappings are not needed and passing the information
around is simplified.

Reviewed By: jdoerfert, mikerice

Differential Revision: https://reviews.llvm.org/D136601
2022-10-31 10:49:44 -04:00
Chuanqi Xu 22914a8229 [NFC] Use isa<...> to replace isa<>||isa<> in clang/Serialization
Now isa supports the variant args, which could simplify the codes
further. This patch simplify the uses in clang/Serialization
2022-10-31 21:17:03 +08:00
Tom Eccles a784de783a [flang] Add -ffp-contract option processing
Only add the option processing and store the result. No attributes are
added to FIR yet.

Only the "off" and "fast" options are supported. "fast-honor-pragmas" is not applicable because we do not implement `#pragma clang fp contract()` in Fortran [1]. "on" is not supported because it is unclear how to fuse only within individual statements. gfortran also does not implement "on": treating it as an "off".

Currently the default value is "off" to preserve existing behavior. gfortran uses "fast" by default and that may be the right thing for flang-new after further discussion in the future, but that can be changed separately. gfortran's documentation is available [[ https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html | here ]].

[1] https://clang.llvm.org/docs/LanguageExtensions.html#extensions-to-specify-floating-point-flags

Reviewed By: vzakhari, awarzynski

Differential Revision: https://reviews.llvm.org/D136080
2022-10-31 11:32:31 +00:00
Benjamin Kramer da4b929da7 [clang][Interp] Reorder field destruction to avoid use after dtor
Found by msan -fsanitize-memory-use-after-dtor.

==8259==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55dbec54d2b8 in dtorRecord(clang::interp::Block*, char*, clang::interp::Descriptor*) clang/lib/AST/Interp/Descriptor.cpp:150:22
    #1 0x55dbec54bfcf in dtorArrayDesc(clang::interp::Block*, char*, clang::interp::Descriptor*) clang/lib/AST/Interp/Descriptor.cpp:97:7
    #2 0x55dbec508578 in invokeDtor clang/lib/AST/Interp/InterpBlock.h:79:7
    #3 0x55dbec508578 in clang::interp::Program::~Program() clang/lib/AST/Interp/Program.h:55:19
    #4 0x55dbec50657a in operator() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:55:5
    #5 0x55dbec50657a in std::__msan::unique_ptr<clang::interp::Program, std::__msan::default_delete<clang::interp::Program>>::~unique_ptr() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:261:7
    #6 0x55dbec5035a1 in clang::interp::Context::~Context() clang/lib/AST/Interp/Context.cpp:27:22
    #7 0x55dbebec1daa in operator() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:55:5
    #8 0x55dbebec1daa in std::__msan::unique_ptr<clang::interp::Context, std::__msan::default_delete<clang::interp::Context>>::~unique_ptr() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:261:7
    #9 0x55dbebe285f9 in clang::ASTContext::~ASTContext() clang/lib/AST/ASTContext.cpp:1038:40
    #10 0x55dbe941ff13 in llvm::RefCountedBase<clang::ASTContext>::Release() const llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:101:7
    #11 0x55dbe94353ef in release llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:159:38
    #12 0x55dbe94353ef in release llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:224:7
    #13 0x55dbe94353ef in ~IntrusiveRefCntPtr llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:191:27
    #14 0x55dbe94353ef in clang::CompilerInstance::setASTContext(clang::ASTContext*) clang/lib/Frontend/CompilerInstance.cpp:178:3
    #15 0x55dbe95ad0ad in clang::FrontendAction::EndSourceFile() clang/lib/Frontend/FrontendAction.cpp:1100:8
    #16 0x55dbe9445fcf in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) clang/lib/Frontend/CompilerInstance.cpp:1047:11
    #17 0x55dbe6b3afef in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:25
    #18 0x55dbe6b13288 in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) clang/tools/driver/cc1_main.cpp:250:15
    #19 0x55dbe6b0095f in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) clang/tools/driver/driver.cpp:319:12
    #20 0x55dbe6aff41c in clang_main(int, char**) clang/tools/driver/driver.cpp:395:12
    #21 0x7f9be07fa632 in __libc_start_main
    #22 0x55dbe6a702e9 in _start

  Member fields were destroyed
    #0 0x55dbe6a7da5d in __sanitizer_dtor_callback_fields compiler-rt/lib/msan/msan_interceptors.cpp:949:5
    #1 0x55dbec5094ac in ~SmallVectorImpl llvm/include/llvm/ADT/SmallVector.h:479:7
    #2 0x55dbec5094ac in ~SmallVectorImpl llvm/include/llvm/ADT/SmallVector.h:612:3
    #3 0x55dbec5094ac in llvm::SmallVector<clang::interp::Record::Base, 8u>::~SmallVector() llvm/include/llvm/ADT/SmallVector.h:1207:3
    #4 0x55dbec508e79 in clang::interp::Record::~Record() clang/lib/AST/Interp/Record.h:24:7
    #5 0x55dbec508612 in clang::interp::Program::~Program() clang/lib/AST/Interp/Program.h:49:26
    #6 0x55dbec50657a in operator() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:55:5
    #7 0x55dbec50657a in std::__msan::unique_ptr<clang::interp::Program, std::__msan::default_delete<clang::interp::Program>>::~unique_ptr() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:261:7
    #8 0x55dbec5035a1 in clang::interp::Context::~Context() clang/lib/AST/Interp/Context.cpp:27:22
    #9 0x55dbebec1daa in operator() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:55:5
    #10 0x55dbebec1daa in std::__msan::unique_ptr<clang::interp::Context, std::__msan::default_delete<clang::interp::Context>>::~unique_ptr() third_party/crosstool/v18/stable/toolchain/bin/../include/c++/v1/__memory/unique_ptr.h:261:7
    #11 0x55dbebe285f9 in clang::ASTContext::~ASTContext() clang/lib/AST/ASTContext.cpp:1038:40
    #12 0x55dbe941ff13 in llvm::RefCountedBase<clang::ASTContext>::Release() const llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:101:7
    #13 0x55dbe94353ef in release llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:159:38
    #14 0x55dbe94353ef in release llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:224:7
    #15 0x55dbe94353ef in ~IntrusiveRefCntPtr llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:191:27
    #16 0x55dbe94353ef in clang::CompilerInstance::setASTContext(clang::ASTContext*) clang/lib/Frontend/CompilerInstance.cpp:178:3
    #17 0x55dbe95ad0ad in clang::FrontendAction::EndSourceFile() clang/lib/Frontend/FrontendAction.cpp:1100:8
    #18 0x55dbe9445fcf in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) clang/lib/Frontend/CompilerInstance.cpp:1047:11
    #19 0x55dbe6b3afef in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:25
    #20 0x55dbe6b13288 in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) clang/tools/driver/cc1_main.cpp:250:15
    #21 0x55dbe6b0095f in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) clang/tools/driver/driver.cpp:319:12
    #22 0x55dbe6aff41c in clang_main(int, char**) clang/tools/driver/driver.cpp:395:12
    #23 0x7f9be07fa632 in __libc_start_main
    #24 0x55dbe6a702e9 in _start
2022-10-31 12:20:10 +01:00
Serge Pavlov fd3d7a9f8c Handle errors in expansion of response files
Previously an error raised during an expansion of response files (including
configuration files) was ignored and only the fact of its presence was
reported to the user with generic error messages. This made it difficult to
analyze problems. For example, if a configuration file tried to read an
inexistent file, the error message said that 'configuration file cannot
be found', which is wrong and misleading.

This change enhances handling errors in the expansion so that users
could get more informative error messages.

Differential Revision: https://reviews.llvm.org/D136090
2022-10-31 15:36:41 +07:00
Haojian Wu 21bac59504 Fix unused-variable warning in release build, NFC 2022-10-31 08:53:30 +01:00
Yuanfang Chen e18c2c5548 [Clang] use non-instantiated function declaration for constraints partial ordering
Per wordings in
- https://eel.is/c++draft/over.match#best.general-2.6
- https://eel.is/c++draft/temp.constr.order
- https://eel.is/c++draft/temp.constr#atomic-1

constraints partial ordering should use the unsubstituted template
parameters of the constrained entity, not the instantiated entity.

Fix #56154

Reviewed By: erichkeane, royjacobson, mizvekov

Differential Revision: https://reviews.llvm.org/D136545
2022-10-30 22:39:47 -07:00
Yuanfang Chen 5d086cce8b [Clang] perform "maximum TLS alignment" check for template instantiation
follow up d30e2eefc3

Reviewed By: mizvekov

Differential Revision: https://reviews.llvm.org/D136744
2022-10-30 22:39:47 -07:00
Weining Lu cd0174aacb [Clang][LoongArch] Support inline asm constraint 'J'
'J' is defined in GCC [1] but not documented [2] while Linux [3] has
already used it in LoongArch port.

[1]: https://github.com/gcc-mirror/gcc/blob/master/gcc/config/loongarch/constraints.md#L61
[2]: https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html
[3]: https://github.com/torvalds/linux/blob/master/arch/loongarch/include/asm/cmpxchg.h#L19

Differential Revision: https://reviews.llvm.org/D136835
2022-10-31 09:13:52 +08:00
Yusuke Kadowaki 3edc1210a4 [clang-format] Adds a formatter for aligning trailing comments over empty lines
This patch addresses https://github.com/llvm/llvm-project/issues/19756

Reviewed By: MyDeveloperDay, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D132131
2022-10-30 12:22:39 +00:00
Timm Bäder 74fb770de9 [clang][Interp] Implement bitXor opcode
Differential Revision: https://reviews.llvm.org/D136956
2022-10-30 09:23:33 +01:00
Timm Bäder 6d965c94ba [clang][Interp] Implement left and right shifts
Differential Revision: https://reviews.llvm.org/D136532
2022-10-30 08:59:55 +01:00
Timm Bäder 881547db03 [clang][Interp] Implement add and sub compound assign operators
Differential Revision: https://reviews.llvm.org/D136528
2022-10-30 08:11:04 +01:00
sstwcw d5be1550f1 [clang-format] Don't crash on malformed preprocessor conditions
Previously the program would crash on this input:

```
#else
#if X
```

The problem was that in `parsePPElse`, `PPBranchLevel` would be
incremented when the first `#else` gets parsed, but `PPLevelBranchCount`
and `PPLevelBranchIndex` would not be updated together.

I found the problem when working on D135740.

Differential Revision: https://reviews.llvm.org/D135972
2022-10-30 02:18:58 +00:00
Serge Pavlov c1728a40aa Revert "Handle errors in expansion of response files"
This reverts commit 17eb198de9.
Reverted for investigation, because ClangDriverTests failed on some builders.
2022-10-30 02:03:12 +07:00
Serge Pavlov 17eb198de9 Handle errors in expansion of response files
Previously an error raised during an expansion of response files (including
configuration files) was ignored and only the fact of its presence was
reported to the user with generic error messages. This made it difficult to
analyze problems. For example, if a configuration file tried to read an
inexistent file, the error message said that 'configuration file cannot
be found', which is wrong and misleading.

This change enhances handling errors in the expansion so that users
could get more informative error messages.

Differential Revision: https://reviews.llvm.org/D136090
2022-10-29 22:01:47 +07:00
YingChi Long 0e40a78319
[clang][NFC] sync comments from declaration of InitializePreprocessor 2022-10-29 14:23:03 +08:00
Matt Arsenault 0ebd4638af clang: Improve errors for DiagnosticInfoResourceLimit
Print source location info and demangle the name, compared
to the default behavior.

Several observations:

1. Specially handling this seems to give source locations
without enabling debug info, and also gives columns compared
to the backend diagnostic.

2. We're duplicating diagnostic effort in DiagnosticInfo
and clang. This feels wrong, but clang can demangle and I guess
have better debug info available? Should clang really have any of this
code? For the purposes of this diagnostic, the important piece
is just reading the source location out of the llvm::Function.

3. lld is not duplicating the same effort as clang with LTO, and
just directly printing the DiagnosticInfo as-is. e.g.

  $ clang -fgpu-rdc
	lld: error: local memory (480000) exceeds limit (65536) in function '_Z12use_huge_ldsIiEvv'
	lld: error: local memory (960000) exceeds limit (65536) in function '_Z12use_huge_ldsIdEvv'

  $ clang -fno-gpu-rdc
	backend-resource-limit-diagnostics.hip:8:17: error: local memory (480000) exceeds limit (65536) in 'void use_huge_lds<int>()'
	__global__ void use_huge_lds() {
                ^
	backend-resource-limit-diagnostics.hip:8:17: error: local memory (960000) exceeds limit (65536) in 'void use_huge_lds<double>()'
	2 errors generated when compiling for gfx90a.

4. Backend errors are not observed with -save-temps and -fno-gpu-rdc or -flto,
and the compile incorrectly succeeds.

5. The backend version prints error: <location info>; clang prints <location info>: error:

6. -emit-codegen-only is totally broken for AMDGPU. MC
gets a null target streamer. I do not understand why this
is a thing. This just creates a horrible edge case.
Just work around this by emitting actual code instead of blocking
this patch.
2022-10-28 21:42:57 -07:00
Fangrui Song 0cc9710a0d [Frontend] -MP: remove blank lines
GCC 10 removed blank lines for phony targets during a refactoring.
The blank lines seems unuseful, so let's follow suit.
2022-10-28 20:46:27 -07:00
Fangrui Song ff9576f745 [Frontend] Fix -MP when main file is <stdin>
rC220726 had a bug: `echo "<cstdlib>" | clang -M -MP -x c++ - 2>/dev/null`
(used by glibc/configure.ac find_cxx_header) omitted a `cstdlib:` line. Instead
of filtering out `<stdin>` in `Dependencies`, retain it (so that the number of
entries does not change whether or not main file is `<stdin>`) and filter the
`PhonyTarget` output.
2022-10-28 20:35:29 -07:00
Fangrui Song d3e99d61a4 [Driver] Use addOptInFlag/addOptOutFlag. NFC 2022-10-28 16:15:14 -07:00
Ben Langmuir e1f9983022 Move getenv for AS_SECURE_LOG_FILE to clang
Avoid calling getenv in the MC layer and let the clang driver do it so
that it is reflected in the command-line as an -mllvm option.

rdar://101558354

Differential Revision: https://reviews.llvm.org/D136888
2022-10-28 16:08:04 -07:00
Fangrui Song eb536613a2 [Driver] Fix -fdebug-default-version= -Wunused-command-line-argument after D136707
-fdebug-default-version= is designed to suppress -Wunused-command-line-argument
warnings even without a -g option.
2022-10-28 15:37:46 -07:00
Yaxun (Sam) Liu 36a0253662 [HIP] add float to fp16 convert functions
Reviewed by: Brian Sumner, Artem Belevich

Differential Revision: https://reviews.llvm.org/D136981
2022-10-28 18:17:05 -04:00
Yaxun (Sam) Liu 319444fcf5 [HIP] add fmax/fmin for fp16
Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D136859
2022-10-28 13:38:12 -04:00
Erich Keane b9a77b56d8 [Concepts] Fix an assert when trying to form a recovery expr on a
concept

When we failed the lookup of the function, we tried to form a
RecoveryExpr that caused us to recursively re-check the same constraint,
which caused us to try to double-insert the satisfaction into the cache.

This patch makes us just return the inner-cached version instead. We DO
end up double-evaluating thanks to the recovery-expr, but there isn't a
good way around that.
2022-10-28 10:25:34 -07:00
Timm Bäder f79f64b8d0 [clang][Interp] Implement inc and dec operators
Differential Revision: https://reviews.llvm.org/D136423
2022-10-28 17:47:32 +02:00
Timm Bäder ddec89670d [clang][Interp][NFC] Use right visit() function
visit (lowercase V) sets DiscardValue to false and calls Visit
(uppercase V). So we can't just call Visit (uppercase V) ourselves,
since then we aren't handling DiscardValue correctly.
This is currently irrelevant but will make a difference later.

Also, the naming isn't my fault and might change later.
2022-10-28 17:44:53 +02:00
Yaxun (Sam) Liu 55b4344997 [HIP] add --offload-add-rpath
Add an option --[no-]offload-add-rpath to control whether to
pass -rpath to linker for HIP runtime library. By default it
is off to match gcc/clang behavior for not adding -rpath
for runtime library by default.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D136854
2022-10-28 11:42:38 -04:00
Craig Topper 974e2e690b [RISCV] Adjust RV64I data layout by using n32:64 in layout string
Although i32 type is illegal in the backend, RV64I has pretty good support for i32 types by using W instructions.

By adding n32 to the DataLayout string, middle end optimizations will consider i32 to be a native type. One known effect of this is enabling LoopStrengthReduce on loops with i32 induction variables. This can be beneficial because C/C++ code often has loops with i32 induction variables due to the use of `int` or `unsigned int`.

If this patch exposes performance issues, those are better addressed by tuning LSR or other passes.

Reviewed By: asb, frasercrmck

Differential Revision: https://reviews.llvm.org/D116735
2022-10-28 08:27:03 -07:00
Eduard Zingerman 524c640090 [clang][DebugInfo] Emit DISubprogram for extern functions with reserved names
Callsite `DISubprogram` entries are not generated for:
- builtin functions;
- external functions with reserved names (e.g. names starting from "__").

This limitation was added by the commit [1] as a workaround for the
situation described in [2] that triggered the IR verifier error.
The goal of the present commit is to lift this limitation by adjusting
the IR verifier logic.

The logic behind [1] is to avoid the following situation:
- a `DISubprogram` is added for some builtin function;
- there is some location where this builtin is also emitted by a
  transformation (w/o debug location);
- the `Verifier::visitCallBase` sees a call to a function with
  `DISubprogram` but w/o debug location and emits an error.

Here is an updated example of such situation taken from [2]:

```
extern "C" int memcmp(void *, void *, long);

struct a { int b; int c; int d; };

struct e { int f[1000]; };

bool foo(e g, e &h) {
  // DISubprogram for memcmp is created here when [1] is commented out
  return memcmp(&g, &h, sizeof(e));
}

bool bar(a &g, a &h) {
  // memcmp might be generated here by MergeICmps
  return g.b == h.b && g.c == h.c && g.d == h.d;
}
```

This triggers the verifier error when:
- compiled for AArch64:
  `clang++ -c -g -Oz -target aarch64-unknown-linux-android21 test.cpp`;
- [1] check is commented out.

Instead of forbidding generation of `DISubprogram` entries as in [1]
one can instead adjust the verifier to additionally check if callee
has a body. Functions w/o bodies cannot be inlined and thus verifier
warning is not necessary.

E.g. `llvm::InlineFunction` requires functions for which
`GlobalValue::isDeclaration() == false`.

[1] 568db780bb
[2] https://bugs.chromium.org/p/chromium/issues/detail?id=1022296

Differential Revision: https://reviews.llvm.org/D136041
2022-10-28 08:07:54 -07:00
Timm Bäder ee9bbfa5e6 [clang][Interp] Make sure we free() allocated InitMaps
They get allocated when calling initialize() on a primitive array. And
they get free'd when the array is fully initialized. However, when that
never happens, they get leaked. Fix that by calling the destructor of
global variables.

Differential Revision: https://reviews.llvm.org/D136826
2022-10-28 17:00:15 +02:00
Timm Bäder 38ffc89c87 [clang][Interp] Fix ignoring expression return values
Randomly noticed this. We need to honor DiscardResult here.

Differential Revision: https://reviews.llvm.org/D136013
2022-10-28 16:45:38 +02:00
Timm Bäder 0ccff030f3 [clang][Interp] Fix record members of reference type
When assigning to them, we can't classify the expression type, because
that doesn't contain the right information.

And when reading from them, we need to do the extra deref, just like we
do when reading from a DeclRefExpr.

Differential Revision: https://reviews.llvm.org/D136012
2022-10-28 16:34:45 +02:00
Timm Bäder 8b87cb4853 [clang][Interp] Remove unused getGlobalIdx()
Remove the only use with the version we already use in
VisitDeclRefExpr().
2022-10-28 16:34:29 +02:00