Commit Graph

61884 Commits

Author SHA1 Message Date
Nico Weber 20d5c42e0e Revert "OpaquePtr: Turn inalloca into a type attribute"
This reverts commit 4fefed6563.
Broke check-clang everywhere.
2021-03-28 13:02:52 -04:00
Zakk Chen 821547cabb [RISCV][Clang] Update new overloading rules for RVV intrinsics.
RVV intrinsics has new overloading rule, please see
82aac7dad4

Changed:
1. Rename `generic` to `overloaded` because the new rule is not using C11 generic.
2. Change HasGeneric to HasNoMaskedOverloaded because all masked operations
   support overloading api.
3. Add more overloaded tests due to overloading rule changed.

Differential Revision: https://reviews.llvm.org/D99189
2021-03-28 09:04:35 -07:00
Matt Arsenault 4fefed6563 OpaquePtr: Turn inalloca into a type attribute
I think byval/sret and the others are close to being able to rip out
the code to support the missing type case. A lot of this code is
shared with inalloca, so catch this up to the others so that can
happen.
2021-03-28 11:12:23 -04:00
Björn Schäpers c5243c63cd [clang-format] Fix aligning with linebreaks
Breaking a string literal or a function calls arguments with
AlignConsecutiveDeclarations or AlignConsecutiveAssignments did misalign
the continued line. E.g.:

void foo() {
  int myVar = 5;
  double x  = 3.14;
  auto str  = "Hello"
            "World";
}

or

void foo() {
  int    myVar = 5;
  double x = 3.14;
  auto   str = "Hello"
             "World";
}

Differential Revision: https://reviews.llvm.org/D98214
2021-03-28 16:26:27 +02:00
Fangrui Song 8e2f5f95b5 [Driver] Simplify mips multilib path and fix comments. NFC 2021-03-28 00:30:38 -07:00
Fangrui Song 87a9f42fc1 [Driver] Remove an incorrect library path for multilib
This is incorrect (adding a path with unrelated libraries) but benign in practice because previous paths take precedence.
2021-03-27 16:36:21 -07:00
Fangrui Song 19e45696f5 [Driver] Remove an unneeded multiarch library path which ends with ../../..
Neither vanilla nor Debian GCC has the patch, which usually duplicates $sysroot/usr/lib.
2021-03-27 15:46:06 -07:00
Aaron Puchert c61ae6e6d5 Deduplicate branches and adjust comment [NFC]
Currently we want to allow calling non-const methods even when only a
shared lock is held, because -Wthread-safety-reference is already quite
sensitive and not all code is const-correct. Even if it is, this might
require users to add std::as_const around the implicit object argument.

See D52395 for a discussion.

Fixes PR46963.
2021-03-27 23:08:43 +01:00
Sean Perry 7e0cc45ced [SystemZ][z/OS] Save strings for CC_PRINT env vars
The contents of the string returned by getenv() is not guaranteed across calls to getenv(). The code to handle the CC_PRINT etc env vars calls getenv() and saves the results in just a char *. The string returned by getenv() needs to be copied and saved. Switching the type of the strings from char * to std::string will do this and manage the alloated memory.

Differential Revision: https://reviews.llvm.org/D98554
2021-03-26 16:38:36 -04:00
Fanbo Meng 6f91cf75d7 [SystemZ][z/OS] Ignore leading zero width bitfield alignment on z/OS target
Zero length bitfield alignment is not respected if they are leading members on z/OS target.

Reviewed By: abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D98890
2021-03-26 10:10:33 -04:00
Abhina Sreeskantharajan bc5d4bcc2d [Windows] Turn off text mode in TableGen and Rewriter to stop CRLF translation
This patch should fix the errors shown on the Windows bots by turning off text mode. I plan to investigate a better fix but this should unblock the buildbots for now.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D99363
2021-03-26 07:12:46 -04:00
Fangrui Song ed956554f9 [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker
Differential Revision: https://reviews.llvm.org/D99308
2021-03-25 16:25:47 -07:00
David Stone 4b5baa5b82 Handle 128-bits IntegerLiterals in StmtPrinter
This fixes PR35677: "int128_t or uint128_t as non-type template
parameter causes crash when considering invalid constructor".
2021-03-25 17:27:13 -04:00
Xun Li f490a5969b [OpenMP][InstrProfiling] Fix a missing instr profiling counter
When emitting a function body there needs to be a instr profiling counter emitted. Otherwise instr profiling won't work for this function.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D98135
2021-03-25 13:52:36 -07:00
Richard Smith 622f8de4f2 PR49724: Fix deduction of null member pointers.
Previously we created an implicit cast of the wrong kind, which we'd
later fail to constant-evaluate, resulting in deduction failure.
2021-03-25 13:47:22 -07:00
Xun Li c7a39c833a [Coroutine][Clang] Force emit lifetime intrinsics for Coroutines
tl;dr Correct implementation of Corouintes requires having lifetime intrinsics available.

Coroutine functions are functions that can be suspended and resumed latter. To do so, data that need to stay alive after suspension must be put on the heap (i.e. the coroutine frame).
The optimizer is responsible for analyzing each AllocaInst and figure out whether it should be put on the stack or the frame.
In most cases, for data that we are unable to accurately analyze lifetime, we can just conservatively put them on the heap.
Unfortunately, there exists a few cases where certain data MUST be put on the stack, not on the heap. Without lifetime intrinsics, we are unable to correctly analyze those data's lifetime.

To dig into more details, there exists cases where at certain code points, the current coroutine frame may have already been destroyed. Hence no frame access would be allowed beyond that point.
The following is a common code pattern called "Symmetric Transfer" in coroutine:
```
auto tmp = await_suspend();
__builtin_coro_resume(tmp.address());
return;
```
In the above code example, `await_suspend()` returns a new coroutine handle, which we will obtain the address and then resume that coroutine. This essentially "transfered" from the current coroutine to a different coroutine.
During the call to `await_suspend()`, the current coroutine may be destroyed, which should be fine because we are not accessing any data afterwards.
However when LLVM is emitting IR for the above code, it needs to emit an AllocaInst for `tmp`. It will then call the `address` function on tmp. `address` function is a member function of coroutine, and there is no way for the LLVM optimizer to know that it does not capture the `tmp` pointer. So when the optimizer looks at it, it has to conservatively assume that `tmp` may escape and hence put it on the heap. Furthermore, in some cases `address` call would be inlined, which will generate a bunch of store/load instructions that move the `tmp` pointer around. Those stores will also make the compiler to think that `tmp` might escape.
To summarize, it's really difficult for the mid-end to figure out that the `tmp` data is short-lived.
I made some attempt in D98638, but it appears to be way too complex and is basically doing the same thing as inserting lifetime intrinsics in coroutines.

Also, for reference, we already force emitting lifetime intrinsics in O0 for AlwaysInliner: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilder.cpp#L1893

Differential Revision: https://reviews.llvm.org/D99227
2021-03-25 13:46:20 -07:00
Leonard Chan 1abaadb30d [clang][driver] Support HWASan in the Fuchsia toolchain
These contain clang driver changes for supporting HWASan on Fuchsia.
This includes hwasan multilibs and the dylib path change.

Differential Revision: https://reviews.llvm.org/D99361
2021-03-25 13:36:23 -07:00
Yaxun (Sam) Liu cc9477166a [CUDA][HIP] add __builtin_get_device_side_mangled_name
Add builtin function __builtin_get_device_side_mangled_name
to get device side manged name for functions and global
variables, which can be used to get symbol address of kernels
or variables by mangled name in dynamically loaded
bundled code objects at run time.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D99301
2021-03-25 15:25:29 -04:00
Utkarsh Saxena aa979084df [clang][Syntax] Optimize expandedTokens for token ranges.
`expandedTokens(SourceRange)` used to do a binary search to get the
expanded tokens belonging to a source range. Each binary search uses
`isBeforeInTranslationUnit` to order two source locations. This is
inherently very slow.
By profiling clangd we found out that users like clangd::SelectionTree
spend 95% of time in `isBeforeInTranslationUnit`. Also it is worth
noting that users of `expandedTokens(SourceRange)` majorly use ranges
provided by AST to query this funciton. The ranges provided by AST are
token ranges (starting at the beginning of a token and ending at the
beginning of another token).

Therefore we can avoid the binary search in majority of the cases by
maintaining an index of ExpandedToken by their SourceLocations. We still
do binary search for ranges which are not token ranges but such
instances are quite low.

Performance:
`~/build/bin/clangd --check=clang/lib/Serialization/ASTReader.cpp`
Before: Took 2:10s to complete.
Now: Took 1:13s to complete.

Differential Revision: https://reviews.llvm.org/D99086
2021-03-25 18:54:15 +01:00
Gabor Marton 015c39882e [Analyzer] Infer 0 value when the divisible is 0 (bug fix)
Currently, we infer 0 if the divisible of the modulo op is 0:
  int a = x < 0; // a can be 0
  int b = a % y; // b is either 1 % sym or 0
However, we don't when the op is / :
  int a = x < 0; // a can be 0
  int b = a / y; // b is either 1 / sym or 0 / sym

This commit fixes the discrepancy.

Differential Revision: https://reviews.llvm.org/D99343
2021-03-25 18:25:06 +01:00
Arnamoy Bhattacharyya 4c7ebf79e9 [flang][driver] Add options for -std=f2018
Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D97119
2021-03-25 13:03:16 -04:00
Sven van Haastregt 8fbfc92a5c Reuse `os` variable in AllocateTarget; NFC 2021-03-25 14:38:02 +00:00
Abhina Sreeskantharajan c83cd8feef [NFC] Reordering parameters in getFile and getFileOrSTDIN
In future patches I will be setting the IsText parameter frequently so I will refactor the args to be in the following order. I have removed the FileSize parameter because it is never used.

```
  static ErrorOr<std::unique_ptr<MemoryBuffer>>
  getFile(const Twine &Filename, bool IsText = false,
          bool RequiresNullTerminator = true, bool IsVolatile = false);

  static ErrorOr<std::unique_ptr<MemoryBuffer>>
  getFileOrSTDIN(const Twine &Filename, bool IsText = false,
                 bool RequiresNullTerminator = true);

 static ErrorOr<std::unique_ptr<MB>>
 getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
            bool IsText, bool RequiresNullTerminator, bool IsVolatile);

  static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
  getFile(const Twine &Filename, bool IsVolatile = false);
```

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D99182
2021-03-25 09:47:49 -04:00
Abhina Sreeskantharajan ea61708c6d [SystemZ][z/OS] csv files should be text files
This patch sets the OF_Text flag correctly for the csv file.

Reviewed By: anirudhp

Differential Revision: https://reviews.llvm.org/D99285
2021-03-25 09:19:15 -04:00
Djordje Todorovic 8420a53324 [Debugify] Expose original debug info preservation check as CC1 option
In order to test the preservation of the original Debug Info metadata
in your projects, a front end option could be very useful, since users
usually report that a concrete entity (e.g. variable x, or function fn2())
is missing debug info. The [0] is an example of running the utility
on GDB Project.

This depends on: D82546 and D82545.

Differential Revision: https://reviews.llvm.org/D82547
2021-03-25 05:29:42 -07:00
Nemanja Ivanovic 06411edb9f [PowerPC][NFC] Provide legacy names for VSX loads and stores
Before we unified the names of the builtins across all the
compilers, there were a number of synonyms between them. There
is code out there that uses XL naming for some of these loads and
stores. This just adds those names.
2021-03-25 06:32:40 -05:00
Krasimir Georgiev d9abcdd9f4 [clang-format] Fix ObjC method indent after f7f9f94b
Commit
f7f9f94b2e
changed the indent of ObjC method arguments from +4 to +2, if the method
occurs after a block statement.  I believe this was unintentional and there
was insufficient ObjC test coverage to catch this.

Example: `clang-format -style=google test.mm`

before:
```
void aaaaaaaaaaaaaaaaaaaaa(int c) {
  if (c) {
    f();
  }
  [dddddddddddddddddddddddddddddddddddddddddddddddddddddddd
      eeeeeeeeeeeeeeeeeeeeeeeeeeeee:^(fffffffffffffff gggggggg) {
        f(SSSSS, c);
      }];
}
```

after:
```
void aaaaaaaaaaaaaaaaaaaaa(int c) {
  if (c) {
    f();
  }
  [dddddddddddddddddddddddddddddddddddddddddddddddddddddddd
    eeeeeeeeeeeeeeeeeeeeeeeeeeeee:^(fffffffffffffff gggggggg) {
      f(SSSSS, c);
    }];
}
```

Differential Revision: https://reviews.llvm.org/D99063
2021-03-25 10:52:08 +01:00
Chuanqi Xu 20b4f484d1 [Driver] Add -fno-split-stack
Summary: Add -fno-split-stack and rename CC1 option from `-split-stacks`
to `-fsplit-stack`.

Test Plan: check-all

Differential Revision: https://reviews.llvm.org/D99245
2021-03-25 14:18:28 +08:00
Fangrui Song cdd993fab3 [Driver] Use -dynamic-linker /lib/ld-musl-i386.so.1 for i?86-linux-musl
Noticed by Khem Raj
2021-03-24 19:44:53 -07:00
Nathan Chancellor ef58ae86ba
[RISCV] Fix mcount name
GCC's name for this symbol is _mcount, which the Linux kernel expects in
a few different place:

  $ echo 'int main(void) { return 0; }' | riscv32-linux-gcc -c -pg -o tmp.o -x c -

  $ llvm-objdump -dr tmp.o | grep mcount
                          0000000c:  R_RISCV_CALL _mcount

  $ echo 'int main(void) { return 0; }' | riscv64-linux-gcc -c -pg -o tmp.o -x c -

  $ llvm-objdump -dr tmp.o | grep mcount
                  000000000000000c:  R_RISCV_CALL _mcount

  $ echo 'int main(void) { return 0; }' | clang -c -pg -o tmp.o --target=riscv32-linux-gnu -x c -

  $ llvm-objdump -dr tmp.o | grep mcount
                          0000000a:  R_RISCV_CALL_PLT     mcount

  $ echo 'int main(void) { return 0; }' | clang -c -pg -o tmp.o --target=riscv64-linux-gnu -x c -

  $ llvm-objdump -dr tmp.o | grep mcount
                  000000000000000a:  R_RISCV_CALL_PLT     mcount

Set MCountName to "_mcount" in RISCVTargetInfo then prevent it from
getting overridden in certain OSTargetInfo constructors.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D98881

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
2021-03-24 18:11:37 -07:00
Yuanfang Chen 217f0f735a [Clang][Sema] Implement GCC -Wcast-function-type
```
Warn when a function pointer is cast to an incompatible function
pointer. In a cast involving function types with a variable argument
list only the types of initial arguments that are provided are
considered. Any parameter of pointer-type matches any other
pointer-type. Any benign differences in integral types are ignored, like
int vs. long on ILP32 targets. Likewise type qualifiers are ignored. The
function type void (*) (void) is special and matches everything, which
can be used to suppress this warning. In a cast involving pointer to
member types this warning warns whenever the type cast is changing the
pointer to member type. This warning is enabled by -Wextra.
```

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D97831
2021-03-24 16:04:18 -07:00
Fangrui Song 35dd6470de [Driver] Bring back "Clean up Debian multiarch /usr/include/<triplet> madness"
This reverts commit aae84b8e39.

The chromium goma folks want to use a Debian sysroot without
lib/x86_64-linux-gnu to perform `clang -c` but no link action. The previous
commit has removed D.getVFS().exists check to make such usage work.
2021-03-24 15:25:37 -07:00
Fangrui Song bfbfd83f14 [Driver] Linux.cpp: delete unneeded D.getVFS().exists checks
Not only can this save unneeded filesystem stats, it can make `clang
--sysroot=/path/to/debian-sysroot -c a.cc` work (get `-internal-isystem
$sysroot/usr/include/x86_64-linux-gnu`) even without `lib/x86_64-linux-gnu/`.
This should make thakis happy.
2021-03-24 15:25:36 -07:00
Janusz Nykiel e030ce3ec7 [Tooling] Handle compilation databases containing commands with double dashes
As of CMake commit https://gitlab.kitware.com/cmake/cmake/-/commit/d993ebd4,
which first appeared in CMake 3.19.x series, in the compile commands for
clang-cl, CMake puts `--` before the input file. When operating on such a
database, the `InterpolatingCompilationDatabase` - specifically, the
`TransferableCommand` constructor - does not recognize that pattern and so, does
not strip the input, or the double dash when 'transferring' the compile command.
This results in a incorrect compile command - with the double dash and old input
file left in, and the language options and new input file appended after them,
where they're all treated as inputs, including the language version option.

Test files for some tests have names similar enough to be matched to commands
from the database, e.g.:

`.../path-mappings.test.tmp/server/bar.cpp`

can be matched to:

`.../Driver/ToolChains/BareMetal.cpp`

etc. When that happens, the tool being tested tries to use the matched, and
incorrectly 'transferred' compile command, and fails, reporting errors similar
to:

`error: no such file or directory: '/std:c++14'; did you mean '/std:c++14'? [clang-diagnostic-error]`

This happens in at least 4 tests:

  Clang Tools :: clang-tidy/checkers/performance-trivially-destructible.cpp
  Clangd :: check-fail.test
  Clangd :: check.test
  Clangd :: path-mappings.test

The fix for `TransferableCommand` removes the `--` and everything after it when
determining the arguments that apply to the new file. `--` is inserted in the
'transferred' command if the new file name starts with `-` and when operating in
clang-cl mode, also `/`. Additionally, other places in the code known to do
argument adjustment without accounting for the `--` and causing the tests to
fail are fixed as well.

Differential Revision: https://reviews.llvm.org/D98824
2021-03-24 16:01:47 -04:00
Alexey Bataev 9e9f6eba84 [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.
The emty declare target/end declare target region should not cause an
error emission.

Differential Revision: https://reviews.llvm.org/D99288
2021-03-24 12:53:33 -07:00
Heejin Ahn a6aae5f7fc [WebAssembly] Don't inline -emscripten-cxx-exceptions-allowed functions
Functions specified in `-emscripten-cxx-exceptions-allowed`, which is
set by Emscripten's `EXCEPTION_CATCHING_ALLOWED` setting, can be inlined
in LLVM middle ends before we reach WebAssemblyLowerEmscriptenEHSjLj
pass in the wasm backend and thus don't get transformed for exception
catching.

This fixes the issue by adding `--force-attribute=FUNC_NAME:noinline`
for each function name in `-emscripten-cxx-exceptions-allowed`, which
adds `noinline` attribute to the specified function and thus excludes
the function from inlining candidates in optimization passes.

Fixes the remaining half of
https://github.com/emscripten-core/emscripten/issues/10721.

Reviewed By: sbc100

Differential Revision: https://reviews.llvm.org/D99259
2021-03-24 12:27:49 -07:00
Nathan James 279ea930fa
[clang] Add fixit for Wreorder-ctor
Create fix-it hints to fix the order of constructors.
To make this a lot simpler, I've grouped all the warnings for each out of order initializer into 1.
This is necessary as fixing one initializer would often interfere with other initializers.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98745
2021-03-24 19:22:53 +00:00
Abhina Sreeskantharajan 0bf833f670 [SystemZ][z/OS] JSON file should be text files
This patch sets the OF_Text flag correctly for the json file created in Clang::DumpCompilationDatabaseFragmentToDir.

Reviewed By: amccarth

Differential Revision: https://reviews.llvm.org/D99200
2021-03-24 13:28:08 -04:00
Alexey Bataev 7654bb6303 [OPENMP]Fix PR48571: critical/master in outlined contexts cause crash.
If emit inlined region for master/critical directives, no need to clear
lambda/block context data, otherwise the variables cannot be found and
it causes a crash at compile time.

Differential Revision: https://reviews.llvm.org/D99280
2021-03-24 10:15:24 -07:00
Aaron Puchert a6a1c3051d Fix false negative in -Wthread-safety-attributes
The original implementation didn't fire on non-template classes when a
base class was an instantiation of a template with a dependent base.
In that case the base of the base is dependent as seen from the base,
but not from the class we're interested in, which isn't a template.

Also it simplifies the code a lot.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98724
2021-03-24 17:45:25 +01:00
Marek Kurdej 0620e6f4b7 [clang] [C++2b] [P1102] Accept lambdas without parameter list ().
As an extension, accept such lambdas in previous standards with a warning.

* http://eel.is/c++draft/expr.prim.lambda
* http://wg21.link/P1102

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98433
2021-03-24 14:42:27 +01:00
Stefan Pintilie 91f4c11133 [PowerPC] Add mprivileged option
Add an option to tell the compiler that it can use privileged instructions.

This patch only adds the option. Backend implementation will be added in a
future patch.

Reviewed By: lei, amyk

Differential Revision: https://reviews.llvm.org/D99193
2021-03-24 08:33:22 -05:00
Haojian Wu cfc36bf017 [clang] Treat variable-length array of incomplete element type as
incomplete type.

Differential Revision: https://reviews.llvm.org/D99165
2021-03-24 14:22:15 +01:00
Anastasia Stulova d1c8a151df [OpenCL] Added distinct file extension for C++ for OpenCL.
Files compiled with C++ for OpenCL mode can now have a distinct
file extension - clcpp, then clang driver picks the compilation
mode automatically (-x clcpp) without the use of -cl-std=clc++.

Differential Revision: https://reviews.llvm.org/D96771
2021-03-24 13:07:04 +00:00
Jan Svoboda 772e9f88dd [clang][deps] NFC: Document collector, rename members
This patch documents how `ModuleDepCollector{,PP}` work and what their members store. Also renames somewhat vague `MainDeps` to `FileDeps` and `Deps` to `ModularDeps`.

Depends on D98943.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D98950
2021-03-24 11:58:43 +01:00
Jan Svoboda 3190cf2017 [clang][deps] NFC: Extract ModuleID struct
This patch extracts the `ModuleName` and `ContextHash` members of `ClangModuleDep`, `FullDependencies` and `ModuleDeps` into a single struct `ModuleID`. This makes it easier to understand how the full dependency graph works.

Reviewed By: Bigcheese, dexonsmith

Differential Revision: https://reviews.llvm.org/D98943
2021-03-24 11:57:43 +01:00
Stefan Pintilie 0e4f5f3ea6 [PowerPC] Change option to mrop-protect
In order to have the same option on power PC LLVM and power PC gcc
the option will be changed from -mrop-protection to -mrop-protect.

The feature will be off by default and turned on when the option is used.

Reviewed By: lei, amyk

Differential Revision: https://reviews.llvm.org/D99185
2021-03-24 05:51:35 -05:00
Gabor Marton f8a850ccf4 [Analyzer][NFC] Fix typos in comments 2021-03-24 11:46:10 +01:00
Balázs Kéri f6cdb2c0a7 [clang][ASTImporter] Add import of DeducedTemplateSpecializationType.
Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D99188
2021-03-24 09:43:58 +01:00
Fangrui Song 7c5222e4d1 [Driver] Bring back i586-linxu-gnu
This is used by Fuchsia for a Debian jessie based sysroot.
2021-03-23 23:37:43 -07:00
Fangrui Song 0361e64975 [Driver] Gnu.cpp: remove unneeded getMultiarchTriple normalization 2021-03-23 23:12:19 -07:00
Nemanja Ivanovic 4020932706 [PowerPC] Make altivec.h work with AIX which has no __int128
There are a number of functions in altivec.h that use
vector __int128 which isn't supported on AIX. Those functions
need to be guarded for targets that don't support the type.
Furthermore, the functions that produce quadword instructions
without using the type need a builtin. This patch adds the
macro guards to altivec.h using the __SIZEOF_INT128__ which
is only defined on targets that support the __int128 type.
2021-03-24 00:35:51 -05:00
Zequan Wu aae84b8e39 Revert "[Driver] Bring back "Clean up Debian multiarch /usr/include/<triplet> madness" and restore i586-linux-gnu"
This breaks bots in chromium goma building.

This reverts commit 424bf5d891.
2021-03-23 20:12:09 -07:00
Richard Smith 4259301aaf Support #__private_macro and #__public_macro in local submodule
visibility mode.
2021-03-23 16:54:28 -07:00
Richard Smith 4cd109891c Improve const-correctness. NFC. 2021-03-23 16:54:27 -07:00
Bruno Cardoso Lopes 431e3138a1 [CGAtomic] Lift stronger requirements on cmpxch and support acquire failure mode
- Fix `emitAtomicCmpXchgFailureSet` to support release/acquire (succ/fail) memory order.
- Remove stronger checks for cmpxch.

Effectively, this addresses http://wg21.link/p0418

Differential Revision: https://reviews.llvm.org/D98995
2021-03-23 16:45:37 -07:00
Arthur O'Dwyer 5f1de9cab1 [C++20] [P1825] Fix bugs with implicit-move from variables of reference type.
Review D88220 turns out to have some pretty severe bugs, but I *think*
this patch fixes them.

Paper P1825 is supposed to enable implicit move from "non-volatile objects
and rvalue references to non-volatile object types." Instead, what was committed
seems to have enabled implicit move from "non-volatile things of all kinds,
except that if they're rvalue references then they must also refer to non-volatile
things." In other words, D88220 accidentally enabled implicit move from
lvalue object references (super yikes!) and also from non-object references
(such as references to functions).

These two cases are now fixed and regression-tested.

Differential Revision: https://reviews.llvm.org/D98971
2021-03-23 14:12:06 -04:00
Nathan James 8298899e56
[ASTMatchers][NFC] Use SmallVector when building variadic matcher descriptor
Saves having to manually deallocate storage and keeps InnerArgs will have good cache locality.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D99106
2021-03-23 16:38:45 +00:00
Arnamoy Bhattacharyya cd4abc5242 [flang][driver] Add -fintrinsic-modules-path option
Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D97080
2021-03-23 12:28:19 -04:00
Timm Bäder bc6b139392 [clang][parser] Don't prohibit attributes on objc @try/@throw
This line has a TODO comment, but the answer to it seems to be "no"
given that clang itself uses attributes on @try statements in its tests.

This ProhibitAttributes() statement is also dead code since
ProhibitAttributs() does not handle GNU attributes at the moment but
those are the only attributes valid in objc.

Differential Revision: https://reviews.llvm.org/D97371
2021-03-23 15:26:25 +01:00
Nemanja Ivanovic 4146864735 [PowerPC][NFC] Use valid type for offset in altivec.h
We currently use signed long long instead of ptrdiff_t for offsets
in altivec.h. This has never really presented a problem because
all platforms where we use these are 64-bit. However, now that
we have 32-bit targets, we need to use a meaningful type.
2021-03-23 08:45:37 -05:00
Kadir Cetinkaya 8f80c66bd2
[clang] Fix a crash when CTAD fails
Differential Revision: https://reviews.llvm.org/D99145
2021-03-23 13:03:30 +01:00
Nemanja Ivanovic 2f782a796a [PowerPC] Add more missing overloads to altivec.h
Add overloads that perform subtraction on v1i128 that take and
produce vector unsigned char to avoid needing to use __int128.
The overloads are suffixed with _u128 and are needed for targets
where __int128 isn't supported (AIX).
2021-03-23 05:52:36 -05:00
Sven van Haastregt 1c6521a0dd [OpenCL] Remove mixed signedness atomic_fetch_ from opencl-c.h
The OpenCL C specification v3.0.6 s6.15.12.7.5 mentions:

    For atomic_fetch and modify functions with key = or, xor, and, min
    and max on atomic type atomic_intptr_t, M is intptr_t, and on
    atomic type atomic_uintptr_t, M is uintptr_t.

Remove the atomic_fetch_* overloads from opencl-c.h that mix intptr_t
and uintptr_t in the same declaration.

Differential Revision: https://reviews.llvm.org/D98418
2021-03-23 10:20:13 +00:00
Nemanja Ivanovic 54e4654f04 [PowerPC] Add more missing overloads to altivec.h
Add overloads that perform addition on v1i128 that take and produce
vector unsigned char to avoid needing to use __int128. The overloads
are suffixed with _u128 and are needed for targets where __int128
isn't supported (AIX).
2021-03-23 05:09:19 -05:00
Balázs Kéri 3cde27bc56 [clang][ASTImporter] Import "CapturedVLAType" in FieldDecl.
Update ASTImporter to import value of FieldDecl::getCapturedVLAType.

Reviewed By: shafik, martong

Differential Revision: https://reviews.llvm.org/D99062
2021-03-23 09:54:25 +01:00
Nemanja Ivanovic 10cc5bcd86 [PowerPC] Add more missing overloads to altivec.h
Add vec_permi as a synonym for vec_xxpermdi (but only for
doubleword vectors).
2021-03-22 23:09:41 -05:00
Nemanja Ivanovic b5e96e0ad6 [PowerPC] Add more missing overloads to altivec.h
Add vec_gbb as a synonym for vec_vgbbd but for doubleword vectors.
2021-03-22 22:25:28 -05:00
Nemanja Ivanovic d8e574c8e6 [PowerPC] Add more missing overloads to altivec.h
Add vec_cvf as a synonym for vec_doublee/vec_floate.
2021-03-22 22:08:43 -05:00
Richard Smith 3775d811ff Improve module dumping for debugging.
* List inferred lists of imports in `#pragma clang __debug module_map`.

  * Add `#pragma clang __debug modules {all,visible,building}` to dump
    lists of known / visible module names or the building modules stack.
2021-03-22 19:07:46 -07:00
Nemanja Ivanovic bef2cb9062 [PowerPC] Add more missing overloads to altivec.h
Add vec_ctd which is similar to vec_ctf except the return type is
vector double rather than vector float.
2021-03-22 20:23:07 -05:00
Amara Emerson 66af90b46e [darwin][driver] Pass through -global-isel LLVM flags to ld.
GlobalISel is currently not enabled when using -flto since the front-end
-mvllm flags don't get passed through. This change fixes this for Darwin
platforms. We have to do this in the driver because the code generator choice
isn't embedded into the bitcode file.

Differential Revision: https://reviews.llvm.org/D99126
2021-03-22 17:23:06 -07:00
Stephen Kelly 4c65dfc895 [AST] Add introspection support for Decls
The test code has lots of interesting locations which are not yet
introspected, but those will come later:

 http://ce.steveire.com/z/3T90hR

Differential Revision: https://reviews.llvm.org/D98775
2021-03-22 23:16:02 +00:00
Joshua Haberman c3134d7c44 [clang] Replaced some manual pointer tagging with llvm::PointerIntPair.
There is no functional change here (hence no new tests). The only change
is to replace a couple uintptr_t members with llvm::PointerIntPair<> to
clean up the code, making it more readable and less error prone.

This cleanup highlighted that the old code was effectively casting away
const. This is fixed by changing some function signatures.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D98889
2021-03-22 14:13:42 -07:00
Fangrui Song 424bf5d891 [Driver] Bring back "Clean up Debian multiarch /usr/include/<triplet> madness" and restore i586-linux-gnu
This reverts commit 933d146f38 and 21b211a8f2
(which mis-identified the issue) but restores i586-linux-gnu which was
removed by `Gnu.cpp: remove obsoleted i386 triple detection from end-of-life distribution versions`.

Looks like i586-linux-gnu was not dead enough (used in a sysroot by Fuchsia build bot based on Debian jessie:)
but i486-linux-gnu should be very dead by now.
2021-03-22 13:25:35 -07:00
Yaxun (Sam) Liu 282bf9eaf7 [HIP] Fix ROCm detection
ROCm has changed installation path to /opt/rocm-{release}. Add detection
for that. Also support ROCM_PATH environment variable.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D98867
2021-03-22 16:10:02 -04:00
Petr Hosek 21b211a8f2 Revert "[Driver] Clean up Debian multiarch /usr/include/<triplet> madness"
This reverts commit 874bdc8e61 which
broke the use of older Debian sysroots.
2021-03-22 11:58:28 -07:00
Petr Hosek 933d146f38 Revert "[Driver] -m32: Add /usr/include/i386-linux-gnu for Debian"
This reverts commit 82f6e0dde2 which
hasn't addressed the 874bdc8e61 issue.
2021-03-22 11:58:28 -07:00
Arthur Eubanks 5184f69041 Revert "[Driver] Gnu.cpp: drop an unneeded special rule related to sysroot"
This reverts commits 56700e9379 and c2f9086b61.

Breaks multiple Android bots, e.g. https://lab.llvm.org/buildbot/#/builders/77/builds/4777.
2021-03-22 10:16:19 -07:00
Raphael Isemann e421a74108 [ASTImporter] Fix import of ObjCPropertyDecl that share the same name
Objective-C apparently allows name conflicts between instance and class
properties, so this is valid code:

```
@protocol DupProp
@property (class, readonly) int prop;
@property (readonly) int prop;
@end
```

The ASTImporter however isn't aware of this and will consider the two properties
as if they are the same property because it just compares their name and types.
This causes that when importing both properties we only end up with one property
(whatever is imported first from what I can see).

Beside generating a different AST this also leads to a bunch of asserts and
crashes as we still correctly import the two different getters for both
properties (the import code for methods does the correct check where it
differentiated between instance and class methods). As one of the setters will
not have its associated ObjCPropertyDecl imported, any call to
`ObjCMethodDecl::findPropertyDecl` will just lead to an assert or crash.

Fixes rdar://74322659

Reviewed By: shafik, kastiglione

Differential Revision: https://reviews.llvm.org/D99077
2021-03-22 18:05:50 +01:00
Balázs Kéri ce9bade1f2 [clang][ASTImporter] Add import API for 'const Type *' (NFC).
There was only an `Import` function for `QualType` but not for `Type`.
For correct import of some AST nodes where not `QualType` is used
an import of `Type *` is needed. (It is the case with
`FieldDecl::getCapturedVLAType`.)

Reviewed By: shafik, teemperor, martong

Differential Revision: https://reviews.llvm.org/D98951
2021-03-22 14:38:49 +01:00
Bradley Smith 48f5a392cb [IR] Add vscale_range IR function attribute
This attribute represents the minimum and maximum values vscale can
take. For now this attribute is not hooked up to anything during
codegen, this will be added in the future when such codegen is
considered stable.

Additionally hook up the -msve-vector-bits=<x> clang option to emit this
attribute.

Differential Revision: https://reviews.llvm.org/D98030
2021-03-22 12:05:06 +00:00
Sven van Haastregt 2bbc9bccf0 [OpenCL] Support template parameters for as_type
Implement the TreeTransform for AsTypeExpr.  Split `BuildAsTypeExpr`
out of `ActOnAsTypeExpr`, such that we can call the Build method from
the TreeTransform.

Fixes PR47979.

Differential Revision: https://reviews.llvm.org/D98855
2021-03-22 11:59:05 +00:00
Valeriy Savchenko 02b51e5316 [analyzer][solver] Redesign constraint ranges data structure
ImmutableSet doesn't seem like the perfect fit for the RangeSet
data structure.  It is good for saving memory in a persistent
setting, but not for the case when the population of the container
is tiny.  This commit replaces RangeSet implementation and
redesigns the most common operations to be more efficient.

Differential Revision: https://reviews.llvm.org/D86465
2021-03-22 13:52:35 +03:00
Fangrui Song 82f6e0dde2 [Driver] -m32: Add /usr/include/i386-linux-gnu for Debian 2021-03-22 01:27:06 -07:00
Valeriy Savchenko 3085bda2b3 [analyzer][solver] Fix infeasible constraints (PR49642)
Additionally, this patch puts an assertion checking for feasible
constraints in every place where constraints are assigned to states.

Differential Revision: https://reviews.llvm.org/D98948
2021-03-22 11:02:02 +03:00
Fangrui Song f263418402 [Driver] Gnu.cpp: remove obsoleted i386 triple detection from end-of-life distribution versions
This saves 16 openat syscalls for `clang a.cc` on x86_64.
2021-03-22 00:23:55 -07:00
Fangrui Song 874bdc8e61 [Driver] Clean up Debian multiarch /usr/include/<triplet> madness
Debian multiarch additionally adds /usr/include/<triplet> and somehow
Android borrowed the idea. (Note /usr/<triplet>/include is already an
include dir...). On Debian, we should just assume a GCC installation is
available and use its triple.
2021-03-21 22:40:38 -07:00
Chuanqi Xu 55486161fa [ASTMatcher] Add AST Matcher support for C++20 coroutine keywords
Summary: Try to enable the support for C++20 coroutine keywords for AST
Matchers.

Reviewers: sammccall, njames93, aaron.ballman

Differential Revision: https://reviews.llvm.org/D96316
2021-03-22 10:27:46 +08:00
Fangrui Song 74933efeb6 [Driver] Detect Debian hack g++-multiarch-incdir.diff to simplify addLibStdCXXIncludePaths call sites 2021-03-21 17:33:31 -07:00
Roman Lebedev be87321280
[clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at -O0
This restores the original behaviour before i unadvertedly broke it in
e3a4701627 and clang/test/Profile/ caught it.
2021-03-21 23:24:27 +03:00
Roman Lebedev e3a4701627
[clang][CodeGen] Lower Likelihood attributes to @llvm.expect intrin instead of branch weights
08196e0b2e exposed LowerExpectIntrinsic's
internal implementation detail in the form of
LikelyBranchWeight/UnlikelyBranchWeight options to the outside.

While this isn't incorrect from the results viewpoint,
this is suboptimal from the layering viewpoint,
and causes confusion - should transforms also use those weights,
or should they use something else, D98898?

So go back to status quo by making LikelyBranchWeight/UnlikelyBranchWeight
internal again, and fixing all the code that used it directly,
which currently is only clang codegen, thankfully,
to emit proper @llvm.expect intrinsics instead.
2021-03-21 22:50:21 +03:00
Roman Lebedev 37d6be9052
Revert "[BranchProbability] move options for 'likely' and 'unlikely'"
Upon reviewing D98898 i've come to realization that these are
implementation detail of LowerExpectIntrinsicPass,
and they should not be exposed to outside of it.

This reverts commit ee8b53815d.
2021-03-21 22:50:21 +03:00
Fangrui Song bcaca360f8 [Driver] Gnu.cpp: fix libstdc++ search path for multilib
With this change, on Debian x86-64 (with a MULTILIB_OSDIRNAMES local patch
../lib64 -> ../lib; this does not matter because /usr/lib64/crt{1,i,n}.o do not exist),
`clang++ --target=aarch64-linux-gnu a.cc -Wl,--dynamic-linker=/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 -Wl,-rpath,/usr/aarch64-linux-gnu/lib`
built executable can run under qemu-user. Previously this failed with
`/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../include/c++/10/iostream:38:10: fatal error: 'bits/c++config.h' file not found`

On Arch Linux, due to the MULTILIB_OSDIRNAMES patch and the existence of
/usr/lib64/crt{1,i,n}.o, clang driver may pick
/usr/lib64/crt{1,i,n}.o and cause a linker error. -B can work around the problem.
`clang++ --target=aarch64-linux-gnu -B /usr/aarch64-linux-gnu/lib a.cc -Wl,--dynamic-linker=/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 -Wl,-rpath,/usr/aarch64-linux-gnu/lib64:/usr/aarch64-linux-gnu/lib`
2021-03-21 12:01:44 -07:00
Fangrui Song 2288a75d9e [Driver] Linux.cpp: add -internal-isystem lib/../$triple/include
With this change, for `#include <ar.h>`, `clang --target=aarch64-linux-gnu`
will read `/usr/lib/gcc/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/include/ar.h`
(on Debian gcc->gcc-cross)
instead of `/usr/include/ar.h`. Some glibc headers (e.g. gnu/stubs.h) are different across architectures.
2021-03-21 00:56:03 -07:00
Fangrui Song c2f9086b61 [Driver] Gnu.cpp: drop an unneeded special rule related to sysroot 2021-03-20 21:37:49 -07:00
Fangrui Song 56700e9379 [Driver] Gnu.cpp: drop an unneeded special rule related to sysroot
Seem unnecessary to diverge from GCC here.
Beside, lib/../$OSLibDir can be considered closer to the GCC
installation then the system root. The comment should not apply.
2021-03-20 21:32:55 -07:00
Fangrui Song 0ad0c476ef [Driver] Gnu.cpp: remove unneeded -L detection hack for -mx32
Removing the hack actually improves our compatibility with gcc -mx32.
2021-03-20 20:12:45 -07:00
Fangrui Song 775a294820 [Driver] Gnu.cpp: remove unneeded -L detection for libc++
If clang is installed in the system, the other -L suffice;
otherwise $ccc_install_dir/../lib below suffices.
2021-03-20 18:56:40 -07:00
Fangrui Song 06d6b1471e [Driver] Gnu.cpp: remove unneeded -L lib/gcc/$triple/$version/../../../$triple
After path resolution, it duplicates a subsequent -L entry. The entry below
(lib/gcc/$triple/$version/../../../../$OSLibDir) usually does not exist (e.g.
Arch Linux; Debian cross gcc). When it exists, it typically just has ld.so (e.g.
Debian native gcc) which cannot cause collision. Removing the -L (similar to
reordering it) is therefore justified.
2021-03-20 18:50:14 -07:00
Sanjay Patel ee8b53815d [BranchProbability] move options for 'likely' and 'unlikely'
This makes the settings available for use in other passes by housing
them within the Support lib, but NFC otherwise.

See D98898 for the proposed usage in SimplifyCFG
(where this change was originally included).

Differential Revision: https://reviews.llvm.org/D98945
2021-03-20 14:46:46 -04:00
Stephen Kelly 188405bc19 [AST] Ensure that an empty json file is generated if compile errors
Differential Revision: https://reviews.llvm.org/D98827
2021-03-20 18:08:01 +00:00
Fangrui Song dc3b438c8f Revert "Revert "[Driver] Drop obsoleted Ubuntu 11.04 gcc detection""
This reverts commit 243333ef3e.
2021-03-20 09:57:05 -07:00
David Zarzycki 243333ef3e Revert "[Driver] Drop obsoleted Ubuntu 11.04 gcc detection"
This reverts commit bdf39e6b0e.

The change is failing on Fedora 33 (x86-64).
2021-03-20 07:29:01 -04:00
Fangrui Song bdf39e6b0e [Driver] Drop obsoleted Ubuntu 11.04 gcc detection
It has a very broken gcc installation path (usr/lib/i386-linux-gnu/gcc/i686-linux-gnu).
2021-03-19 23:23:28 -07:00
Fangrui Song a6a15dde5a [Driver] Delete toplevel i386-gnu/gcc detection in favor of i386-gnu alias triple detection
This is used by hurd.c (usr/lib/gcc/i386-gnu/4.6.0) but we can leverage
the existing alias triple detection.
2021-03-19 22:50:36 -07:00
Fangrui Song 1f4959b276 [Driver] Drop unneeded $triple/gcc/$triple detection 2021-03-19 22:45:50 -07:00
Fangrui Song 28d58d8fe2 [Driver] Stop searching other prefixes once a GCC installation is found in one prefix
so that when --sysroot is specified, the detected GCC installation will not be
overridden by another from /usr which happens to have a larger version.

This behavior is particularly inconvenient when the system has a larger version
GCC while the user wants to try out an older sysroot.

Delete some tests from linux-ld.c which overlap with cross-linux.c
2021-03-19 20:35:59 -07:00
Fangrui Song 4c2da86410 [Driver] Suppress GCC detection under -B
In GCC, if `-B $prefix` is specified, `$prefix` is used to find executable files and startup files.
`$prefix/include` is added as an include search directory.

Clang overloads -B with GCC installation detection semantics which make the
behavior less predictable (due to the "largest GCC version wins" rule) and
interact poorly with --gcc-toolchain (--gcc-toolchain can be overridden by -B).

* `clang++ foo.cpp` detects GCC installation under `/usr`.
* `clang++ --gcc-toolchain=Inputs foo.cpp` detects GCC installation under `Inputs`.
* `clang++ -BA --gcc-toolchain=B foo.cpp` detects GCC installation under A and B and the larger version wins. With this patch, only B is used for detection.
* `clang++ -BA foo.cpp` detects GCC installation under `A` and `/usr`, and the larger GCC version wins. With this patch `A` is not used for detection.

This patch changes -B to drop the GCC detection semantics.  Its executable
searching semantics are preserved.  --gcc-toolchain is the recommended option to
specify the GCC installation detection directory.

(
Note: Clang detects GCC installation in various target dependent directories.
`$sysroot/usr` (sysroot defaults to "") is a common directory used by most targets.
Such a directory is expected to contain something like `lib{,32,64}/gcc{,-cross}/$triple`.
Clang will then construct library/include paths from the directory.
)

Differential Revision: https://reviews.llvm.org/D97993
2021-03-19 15:42:18 -07:00
Benjamin Kramer 19d2c65ddd [CodeGen] Don't crash on for loops with cond variables and no increment
This looks like an oversight from a875721d8a, creating IR that refers
to `for.inc` even if it doesn't exist.

Differential Revision: https://reviews.llvm.org/D98980
2021-03-19 20:43:52 +01:00
Markus Böck aafc3f7be8 [Driver] Add -print-runtime-dir
This patch adds a new command line option to clang which outputs the directory containing clangs runtime libraries to stdout.

The primary use case for this command line flag is for build systems using clang-cl. Build systems when using clang-cl invoke the linker, that is either link or lld-link in this case, directly instead of invoking the compiler for the linking process as is common with the other drivers. This leads to issues when runtime libraries of clang, such as sanitizers or profiling, have to be linked in as the compiler cannot communicate the link directory to the linker.

Using this flag, build systems would be capable of getting the directory containing all of clang's runtime libraries and add it to the linker path.

Differential Revision: https://reviews.llvm.org/D98868
2021-03-19 17:48:03 +01:00
Balázs Kéri 96e675bdd5 [clang][ASTImporter] Add import support for SourceLocExpr.
It is possible that imported `SourceLocExpr` can cause not expected behavior (if `__builtin_LINE()` is used together with `__LINE__` for example) but still it may be worth to import these because some projects use it.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D98876
2021-03-19 16:33:04 +01:00
Maxim Kuvyrkov 2049fe5890 [WoA][MSVC] Use default linker setting in MSVC-compatible driver [take 2]
At the moment "link.exe" is hard-coded as default linker in MSVC.cpp,
so there's no way to use LLD as default linker for MSVC driver.

This patch adds checking of CLANG_DEFAULT_LINKER to MSVC.cpp and
updates unit-tests that expect link.exe linker to explicitly select it
via -fuse-ld=link, so that buildbots and other builds that set
-DCLANG_DEFAULT_LINKER=foobar don't fail these tests.

This is a squash of
- https://reviews.llvm.org/D98493 (MSVC.cpp change) and
- https://reviews.llvm.org/D98862 (unit-tests change)

Reviewed By: maxim-kuvyrkov

Differential Revision: https://reviews.llvm.org/D98935
2021-03-19 13:38:03 +00:00
Aaron Ballman fa4e72971e Automate common diagnostic checking for statement attributes
Clang currently automates a fair amount of diagnostic checking for
declaration attributes based on the declarations in Attr.td. It checks
for things like subject appertainment, number of arguments, language
options, etc. This patch uses the same machinery to perform diagnostic
checking on statement attributes.
2021-03-19 08:35:38 -04:00
Abhina Sreeskantharajan 4f750f6ebc [SystemZ][z/OS] Distinguish between text and binary files on z/OS
This patch consists of the initial changes to help distinguish between text and binary content correctly on z/OS. I would like to get feedback from Windows users on setting OF_None for all ToolOutputFiles. This seems to have been done as an optimization to prevent CRLF translation on Windows in the past.

Reviewed By: zibi

Differential Revision: https://reviews.llvm.org/D97785
2021-03-19 08:09:57 -04:00
Petr Hosek ce97d8e6c7 Revert "[WoA][MSVC] Use default linker setting in MSVC-compatible driver"
This reverts commit ace56d41ac which
broke builders that set CLANG_DEFAULT_LINKER.
2021-03-18 23:42:31 -07:00
Hongtao Yu fc1812a0ad [UniqueLinkageName] Use consistent checks when mangling symbo linkage name and debug linkage name.
C functions may be declared and defined in different prototypes like below. This patch unifies the checks for mangling names in symbol linkage name emission and debug linkage name emission so that the two names are consistent.

static int go(int);

static int go(a) int a;
{
  return a;
}

Test Plan:

Differential Revision: https://reviews.llvm.org/D98799
2021-03-18 22:11:16 -07:00
Thomas Lively cbab2cd6bf [WebAssembly] Remove experimental instructions from wasm_simd128.h
These experimental builtin functions and the feature macro they were gated
behind have been removed.

Reviewed By: aheejin

Differential Revision: https://reviews.llvm.org/D98907
2021-03-18 17:13:50 -07:00
Thomas Lively f5764a8654 [WebAssembly] Finalize SIMD names and opcodes
Updates the names (e.g. widen => extend, saturate => sat) and opcodes of all
SIMD instructions to match the finalized SIMD spec. Deliberately does not change
the public interface in wasm_simd128.h yet; that will require more care.

Depends on D98466.

Differential Revision: https://reviews.llvm.org/D98676
2021-03-18 11:21:25 -07:00
Thomas Lively 2f2ae08da9 [WebAssembly] Remove experimental SIMD instructions
Removes the instruction definitions, intrinsics, and builtins for qfma/qfms,
signselect, and prefetch instructions, which were not included in the final
WebAssembly SIMD spec.

Depends on D98457.

Differential Revision: https://reviews.llvm.org/D98466
2021-03-18 11:21:24 -07:00
Thomas Lively 8638c897f4 [WebAssembly] Remove unimplemented-simd target feature
Now that the WebAssembly SIMD specification is finalized and engines are
generally up-to-date, there is no need for a separate target feature for gating
SIMD instructions that engines have not implemented. With this change,
v128.const is now enabled by default with the simd128 target feature.

Differential Revision: https://reviews.llvm.org/D98457
2021-03-18 10:23:12 -07:00
Mike Rice c2f8e158f5 [OPENMP51]Support for the 'destroy' clause with interop variable.
Added basic parsing/sema/serialization support to extend the
existing 'destroy' clause for use with the 'interop' directive.

Differential Revision: https://reviews.llvm.org/D98834
2021-03-18 09:12:56 -07:00
Sid Manning c539be1dcb [Hexagon] Add support for named registers cs0 and cs1
Allow inline assembly code to referece cs0 and cs1.
2021-03-18 09:53:22 -05:00
Sven van Haastregt c5c4a88a84 [OpenCL] Remove spurious atomic_fetch tablegen builtins
The `int` and `long` versions of these builtins already provide the
necessary overloads for `intptr_t` and `uintptr_t` arguments, as
`ASTContext` defines `atomic_(u)intptr_t` in terms of the `int` or
`long` types.

Prior to this patch, calls to those builtins with particular argument
types resulted in call-is-ambiguous errors.

Differential Revision: https://reviews.llvm.org/D98520
2021-03-18 12:17:12 +00:00
Balazs Benics c1fb23c1aa [clang][ASTImporter] Fix import of VarDecl regarding thread local storage spec
After the import, we did not copy the `TSCSpec`.
This commit resolves that.

Reviewed By: balazske

Differential Revision: https://reviews.llvm.org/D98707
2021-03-18 13:06:38 +01:00
Valeriy Savchenko 8b8b9af8c9 [-Wcalled-once-parameter][NFC] Fix GCC compilation error 2021-03-18 14:49:24 +03:00
Elizabeth Andrews d8b8f544d9 [Reland] "Do not apply calling conventions to MSVC entry points"
This patch is a second attempt at fixing a link error for MSVC
entry points when calling conventions are specified using a flag.

Calling conventions specified using flags should not be applied to MSVC
entry points. The default calling convention is set in this case. The
default calling convention for MSVC entry points main and wmain is cdecl.
For WinMain, wWinMain and DllMain, the default calling convention is
stdcall on 32 bit Windows.

Explicitly specified calling conventions are applied to MSVC entry points.

For MinGW, the default calling convention for all MSVC entry points is
cdecl.

First attempt: 4cff1b40da
Revert of first attempt: bebfc3b92d

Differential Revision: https://reviews.llvm.org/D97941
2021-03-18 04:26:47 -07:00
Valeriy Savchenko 4a7afc9a88 [-Wcalled-once-parameter] Fix false positives for cleanup attr
Cleanup attribute allows users to attach a destructor-like functions
to variable declarations to be called whenever they leave the scope.
The logic of such functions is not supported by the Clang's CFG and
is too hard to be reasoned about.  In order to avoid false positives
in this situation, we assume that we didn't see ALL of the executtion
paths of the function and, thus, can warn only about multiple call
violation.

rdar://74441906

Differential Revision: https://reviews.llvm.org/D98694
2021-03-18 12:32:16 +03:00
Valeriy Savchenko f1a7d5a7b0 [-Wcalled-once-parameter] Harden analysis in terms of block use
This patch introduces a very simple inter-procedural analysis
between blocks and enclosing functions.

We always analyze blocks first (analysis is done as part of semantic
analysis that goes side-by-side with the parsing process), and at the
moment of reporting we don't know how that block will be actually
used.

This patch introduces new logic delaying reports of the "never called"
warnings on blocks.  If we are not sure that the block will be called
exactly once, we shouldn't warn our users about that.  Double calls,
however, don't require such delays.  While analyzing the enclosing
function, we can actually decide what we should do with those
warnings.

Additionally, as a side effect, we can be more confident about blocks
in such context and can treat them not as escapes, but as direct
calls.

rdar://74090107

Differential Revision: https://reviews.llvm.org/D98688
2021-03-18 12:12:18 +03:00
Maxim Kuvyrkov 62948c4532 Revert "[NFC] Minor cleanup to use default setting of getLastArg()"
The patch was wrong.  We use "const Arg *A" at the end of
GetLinkerPath, so can't remove it.

This reverts commit 6802fdf887.
2021-03-18 08:07:02 +00:00
Maxim Kuvyrkov 6802fdf887 [NFC] Minor cleanup to use default setting of getLastArg()
Noticed this while I was looking at linker defaults.

Reviewed By: asl

Differential Revision: https://reviews.llvm.org/D98494
2021-03-18 07:47:31 +00:00
Maxim Kuvyrkov ace56d41ac [WoA][MSVC] Use default linker setting in MSVC-compatible driver
At the moment "link.exe" is hard-coded as default linker in MSVC.cpp,
so there's no way to use LLD as default linker for MSVC driver.

This patch adds checking of CLANG_DEFAULT_LINKER to MSVC.cpp.

Reviewed By: asl

Differential Revision: https://reviews.llvm.org/D98493
2021-03-18 07:42:55 +00:00
Artem Dergachev c75b2261a0 [analyzer] Introduce common bug category "Unused code".
This category is generic enough to hold a variety of checkers.
Currently it contains the Dead Stores checker and an alpha unreachable
code checker.

Differential Revision: https://reviews.llvm.org/D98741
2021-03-17 20:58:27 -07:00
Alex Lorenz d672d5219a Revert "[CodeGenModule] Set dso_local for Mach-O GlobalValue"
This reverts commit 809a1e0ffd.

Mach-O doesn't support dso_local and this change broke XNU because of the use of dso_local.

Differential Revision: https://reviews.llvm.org/D98458
2021-03-17 17:27:41 -07:00
Richard Smith 3315bd0beb PR49619: Remove delayed call to noteFailed.
This would assert if we hit the evaluation step limit between starting
to delay the call and finishing. In any case, delaying the call was
largely pointless as it doesn't really matter when we mark the
evaluation as having had side effects.
2021-03-17 17:25:18 -07:00
Richard Smith a875721d8a PR49585: Emit the jump destination for a for loop 'continue' from within the scope of the condition variable.
The condition variable is in scope in the loop increment, so we need to
emit the jump destination from wthin the scope of the condition
variable.

For GCC compatibility (and compatibility with real-world 'FOR_EACH'
macros), 'continue' is permitted in a statement expression within the
condition of a for loop, though, so there are two cases here:

* If the for loop has no condition variable, we can emit the jump
  destination before emitting the condition.

* If the for loop has a condition variable, we must defer emitting the
  jump destination until after emitting the variable. We diagnose a
  'continue' appearing in the initializer of the condition variable,
  because it would jump past the initializer into the scope of that
  variable.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D98816
2021-03-17 16:24:04 -07:00
Mike Rice c615927c8e [OPENMP51]Initial support for the use clause.
Added basic parsing/sema/serialization support for the 'use' clause.

Differential Revision: https://reviews.llvm.org/D98815
2021-03-17 15:46:14 -07:00
Mike Rice 410f09af09 [OPENMP51]Initial support for the interop directive.
Added basic parsing/sema/serialization support for interop directive.
Support for the 'init' clause.

Differential Revision: https://reviews.llvm.org/D98558
2021-03-17 09:42:07 -07:00
Aaron Ballman c165a99a1b [SYCL] Rework the SYCL driver options
SYCL compilations initiated by the driver will spawn off one or more
frontend compilation jobs (one for device and one for host). This patch
reworks the driver options to make upstreaming this from the downstream
SYCL fork easier.

This patch introduces a language option to identify host executions
(SYCLIsHost) and a -cc1 frontend option to enable this mode. -fsycl and
-fno-sycl become driver-only options that are rejected when passed to
-cc1. This is because the frontend and beyond should be looking at
whether the user is doing a device or host compilation specifically.
Because the frontend should only ever be in one mode or the other,
-fsycl-is-device and -fsycl-is-host are mutually exclusive options.
2021-03-17 08:27:19 -04:00
Bradley Smith cf0da91ba5 [AArch64][SVE/NEON] Add support for FROUNDEVEN for both NEON and fixed length SVE
Previously NEON used a target specific intrinsic for frintn, given that
the FROUNDEVEN ISD node now exists, move over to that instead and add
codegen support for that node for both NEON and fixed length SVE.

Differential Revision: https://reviews.llvm.org/D98487
2021-03-17 11:41:22 +00:00
Jay Foad 967b64beb4 [AMDGPU] Split dot2-insts feature
Split out some of the instructions predicated on the dot2-insts target
feature into a new dot7-insts, in preparation for subtargets that have
some but not all of these instructions. NFCI.

Differential Revision: https://reviews.llvm.org/D98717
2021-03-17 09:42:21 +00:00
Vassil Vassilev 0cb7e7ca0c Make iteration over the DeclContext::lookup_result safe.
The idiom:
```
DeclContext::lookup_result R = DeclContext::lookup(Name);
for (auto *D : R) {...}
```

is not safe when in the loop body we trigger deserialization from an AST file.
The deserialization can insert new declarations in the StoredDeclsList whose
underlying type is a vector. When the vector decides to reallocate its storage
the pointer we hold becomes invalid.

This patch replaces a SmallVector with an singly-linked list. The current
approach stores a SmallVector<NamedDecl*, 4> which is around 8 pointers.
The linked list is 3, 5, or 7. We do better in terms of memory usage for small
cases (and worse in terms of locality -- the linked list entries won't be near
each other, but will be near their corresponding declarations, and we were going
to fetch those memory pages anyway). For larger cases: the vector uses a
doubling strategy for reallocation, so will generally be between half-full and
full. Let's say it's 75% full on average, so there's N * 4/3 + 4 pointers' worth
of space allocated currently and will be 2N pointers with the linked list. So we
break even when there are N=6 entries and slightly lose in terms of memory usage
after that. We suspect that's still a win on average.

Thanks to @rsmith!

Differential revision: https://reviews.llvm.org/D91524
2021-03-17 08:59:04 +00:00
Valeriy Savchenko c86dacd1a4 [-Wcalled-once-parameter] Let escapes overwrite MaybeCalled states
This commit makes escapes symmetrical, meaning that having escape
before and after the branching, where parameter is not called on
one of the paths, will have the same effect.

Differential Revision: https://reviews.llvm.org/D98622
2021-03-17 11:12:55 +03:00
Bing1 Yu 320b72e9cd [X86][AMX] Rename amx-bf16 intrinsic according to correct naming convention
__tile_tdpbf16ps should be renamed with __tile_dpbf16ps

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D98685
2021-03-17 11:22:52 +08:00
Stephen Kelly f5030f1a8e [AST] Suppress diagnostic output when generating code 2021-03-17 01:30:22 +00:00
Stephen Kelly a00d440128 [AST] Hide errors from the attempt to introspect nodes 2021-03-16 23:46:31 +00:00
Fangrui Song 6ab8927931 [RISCV] Support clang -fpatchable-function-entry && GNU function attribute 'patchable_function_entry'
Similar to D72215 (AArch64) and D72220 (x86).

```
% clang -target riscv32 -march=rv64g -c -fpatchable-function-entry=2 a.c && llvm-objdump -dr a.o
...
0000000000000000 <main>:
       0: 13 00 00 00   nop
       4: 13 00 00 00   nop

% clang -target riscv32 -march=rv64gc -c -fpatchable-function-entry=2 a.c && llvm-objdump -dr a.o
...
00000002 <main>:
       2: 01 00         nop
       4: 01 00         nop
```

Recently the mainline kernel started to use -fpatchable-function-entry=8 for riscv (https://git.kernel.org/linus/afc76b8b80112189b6f11e67e19cf58301944814).

Differential Revision: https://reviews.llvm.org/D98610
2021-03-16 10:02:35 -07:00
Luke Drummond 440f6bdf34 [OpenCL][NFCI] Prefer CodeGenFunction::EmitRuntimeCall
`CodeGenFunction::EmitRuntimeCall` automatically sets the right calling
convention for the callee so we can avoid setting it ourselves.

As requested in https://reviews.llvm.org/D98411

Reviewed by: anastasia
Differential Revision: https://reviews.llvm.org/D98705
2021-03-16 16:22:19 +00:00
Aaron Puchert 1cb15b10ea Correct Doxygen syntax for inline code
There is no syntax like {@code ...} in Doxygen, @code is a block command
that ends with @endcode, and generally these are not enclosed in braces.
The correct syntax for inline code snippets is @c <code>.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98665
2021-03-16 15:17:45 +01:00
Sam McCall 128ce70eef [CodeCompletion] Avoid spurious signature help for init-list args
Somewhat surprisingly, signature help is emitted as a side-effect of
computing the expected type of a function argument.
The reason is that both actions require enumerating the possible
function signatures and running partial overload resolution, and doing
this twice would be wasteful and complicated.

Change #1: document this, it's subtle :-)

However, sometimes we need to compute the expected type without having
reached the code completion cursor yet - in particular to allow
completion of designators.
eb4ab3358c did this but introduced a
regression - it emits signature help in the wrong location as a side-effect.

Change #2: only emit signature help if the code completion cursor was reached.

Currently there is PP.isCodeCompletionReached(), but we can't use it
because it's set *after* running code completion.
It'd be nice to set this implicitly when the completion token is lexed,
but ConsumeCodeCompletionToken() makes this complicated.

Change #3: call cutOffParsing() *first* when seeing a completion token.

After this, the fact that the Sema::Produce*SignatureHelp() functions
are even more confusing, as they only sometimes do that.
I don't want to rename them in this patch as it's another large
mechanical change, but we should soon.

Change #4: prepare to rename ProduceSignatureHelp() to GuessArgumentType() etc.

Differential Revision: https://reviews.llvm.org/D98488
2021-03-16 12:46:40 +01:00