Commit Graph

95899 Commits

Author SHA1 Message Date
Ben Shi f45d89d73d [Driver] Support linking to compiler-rt for target AVR
Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D128133
2022-08-16 09:22:50 +08:00
Ben Shi 65c022a75f Revert "[Driver] Support linking to compiler-rt for target AVR"
This reverts commit 44a647d21d.
2022-08-16 07:55:41 +08:00
Sam Estep 2efc8f8d65 [clang][dataflow] Add an option for context-sensitive depth
This patch adds a `Depth` field (default value 2) to `ContextSensitiveOptions`, allowing context-sensitive analysis of functions that call other functions. This also requires replacing the `DeclCtx` field on `Environment` with a `CallString` field that contains a vector of decl contexts, to ensure that the analysis doesn't try to analyze recursive or mutually recursive calls (which would result in a crash, due to the way we handle `StorageLocation`s).

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D131809
2022-08-15 19:58:40 +00:00
Alan Zhao ff8aadf58d [clang][diagnostics] Don't warn about unreachable code in constexpr if
The point of a constexpr if statement is to determine which branch to
take at compile time, so warning on unreachable code is meaningless in
these situations.

Fixes #57123.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D131818
2022-08-15 15:24:39 -04:00
Arthur Eubanks 465d9084ec [test][clang] Opaquify pragma-init_seg.cpp 2022-08-15 10:45:24 -07:00
Aaron Ballman f37b285299 Removing an unused function; NFC
It turns out there are zero in-tree callers of CallExpr::getNumCommas()
so it's reasonable to remove.
2022-08-15 13:35:16 -04:00
Matheus Izvekov b8a1b698af
[clang] fix missing initialization of original number of expansions
When expanding undeclared function parameters, we should initialize
the original number of expansions, if known, before trying to expand
them, otherwise a length mismatch with an outer pack might not be
diagnosed.

Fixes PR56094.

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

Differential Revision: https://reviews.llvm.org/D131802
2022-08-15 17:39:38 +02:00
Kazu Hirata f5a68feab3 Use llvm::none_of (NFC) 2022-08-14 16:25:39 -07:00
Kazu Hirata 6d9cd9199a Use llvm::all_of (NFC) 2022-08-14 16:25:36 -07:00
Yuanfang Chen 6afcc4a459 [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template
DR692 handles two cases: pack expansion (for class/var template) and function parameter pack. The former needs DR1432 as a fix, and the latter needs DR1395 as a fix. However, DR1432 has not yet made a wording change. so I made a tentative fix for DR1432 with the same spirit as DR1395.

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

Differential Revision: https://reviews.llvm.org/D128745
2022-08-14 14:37:40 -07:00
Justin Stitt 333771f355 [Sema] Avoid isNullPointerConstant invocation
DiagnoseNullConversion is needlessly calling isNullPointerConstant which
is an expensive routine due to its calls to a constant evaluator --
which we don't need.

Building the Linux Kernel (x86_64) with this fix has improved build
times by ~2.1%. This is mainly due to the following methods no longer
needing to be called anywhere near as often:
1) ExprConstant::CheckICE (reduced CPU cycles by ~90%)
2) IntExprEvaluator::VisitBinaryOperator (reduced CPU cycles by ~50%)

Reviewed By: rtrieu, nickdesaulniers

Differential Revision: https://reviews.llvm.org/D131532
2022-08-14 13:39:57 -07:00
Nico Weber aacf1a9742 Revert "[clang] adds unary type transformations as compiler built-ins"
This reverts commit bc60cf2368.
Doesn't build on Windows and breaks gcc 9 build, see
https://reviews.llvm.org/D116203#3722094 and
https://reviews.llvm.org/D116203#3722128

Also revert two follow-ups. One fixed a warning added in
bc60cf2368, the other
makes use of the feature added in bc60cf2368
in libc++:

Revert "[libcxx][NFC] utilises compiler builtins for unary transform type-traits"
This reverts commit 06a1d917ef.

Revert "[Sema] Fix a warning"
This reverts commit c85abbe879.
2022-08-14 15:58:21 -04:00
Kazu Hirata c85abbe879 [Sema] Fix a warning
This patch fixes:

  clang/lib/Sema/SemaType.cpp:9469:3: error: default label in switch
  which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2022-08-14 11:25:19 -07:00
Christopher Di Bella bc60cf2368 [clang] adds unary type transformations as compiler built-ins
Adds

* `__add_lvalue_reference`
* `__add_pointer`
* `__add_rvalue_reference`
* `__decay`
* `__make_signed`
* `__make_unsigned`
* `__remove_all_extents`
* `__remove_extent`
* `__remove_const`
* `__remove_volatile`
* `__remove_cv`
* `__remove_pointer`
* `__remove_reference`
* `__remove_cvref`

These are all compiler built-in equivalents of the unary type traits
found in [[meta.trans]][1]. The compiler already has all of the
information it needs to answer these transformations, so we can skip
needing to make partial specialisations in standard library
implementations (we already do this for a lot of the query traits). This
will hopefully improve compile times, as we won't need use as much
memory in such a base part of the standard library.

[1]: http://wg21.link/meta.trans

Co-authored-by: zoecarver

Reviewed By: aaron.ballman, rsmith

Differential Revision: https://reviews.llvm.org/D116203
2022-08-14 17:12:15 +00:00
Mark de Wever 2fd2f2644b [clang][doc] Removes an extra space. 2022-08-14 15:16:43 +02:00
Kazu Hirata 2febc32c9c Use llvm::erase_if (NFC) 2022-08-13 12:55:48 -07:00
Kazu Hirata 2b43bd0bd9 Remove unused forward declarations (NFC) 2022-08-13 12:55:47 -07:00
Zachary Henkel 64f0f7e646 __has_trivial_copy should map to __is_trivially_copyable
Found during clang 15 RC1 testing due to the new diagnostic added by @royjacobson since clang 14.  Uncertain if this fix meets the bar to also be applied to the release branch.

If accepted, I'll need someone with commit access to submit on my behalf.

Reviewed By: royjacobson, aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D131730
2022-08-13 22:54:52 +03:00
Vitaly Buka 2f9be69d84 [OpenMP] Fix another after scope after D129608
https://lab.llvm.org/buildbot/#/builders/5/builds/26770
2022-08-13 12:13:54 -07:00
Kazu Hirata 2117fcb1c0 Use Optional::transform instead of Optional::map (NFC)
I'm planning to deprecate map in favor of transform for consistency
with std::optional::transform in C++23.
2022-08-13 11:48:26 -07:00
Vitaly Buka f385eaf48f [OpenMP] Fix use after scope after D129608
Broken builder https://lab.llvm.org/buildbot/#/builders/5/builds/26764
2022-08-13 09:40:51 -07:00
Aaron Ballman ba79c2a250 Update the implementation status of some C11 features
This also starts to add some test coverage for specific papers to
validate conformance against.
2022-08-13 10:17:47 -04:00
Ben Shi 44a647d21d [Driver] Support linking to compiler-rt for target AVR
Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D128133
2022-08-13 20:40:21 +08:00
Fangrui Song 452fbbda39 [Driver] Use addOptInFlag. NFC 2022-08-13 00:51:04 -07:00
jackh ef71383b0c [clang-format] Distinguish logical and after bracket from reference
Fix commit `b646f0955574` and remove redundant code.

Differential Revision: https://reviews.llvm.org/D131750
2022-08-13 11:52:23 +08:00
Jennifer Yu 2ca27206f9 [OpenMP] Fix segmentation fault when data field is used in is_device_pt
Currently, the field just emit map info for this pointer variable. It is
failed at run time. For the fields, the PartialStruct is created and it
needs call to emitCombinedEntry which create the base that covers all
the pieces.

The change is to generate map info as regular fields.

Differential Revision: https://reviews.llvm.org/D129608
2022-08-12 17:10:26 -07:00
Usman Nadeem 405ad84793 Update hwasan test to fix failure on older Android API versions.
In Android API < 30 there is no HWAsan instrumentation support for globals
so the test fails if API < 30 or if the target triple does not specify the API version.

Add -triple=aarch64-linux-android31 to enable global instrumentation. This is the
same triple as is used in the RUN line for -fsanitize=memtag-globals.

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

Change-Id: I300703bd126b10e3c52505e23c78c5a48acb0309
2022-08-12 16:30:08 -07:00
isuckatcs b4e3e3a3eb [analyzer] Fix a crash on copy elided initialized lambda captures
Inside `ExprEngine::VisitLambdaExpr()` we wasn't prepared for a
copy elided initialized capture's `InitExpr`. This patch teaches
the analyzer how to handle such situation.

Differential Revision: https://reviews.llvm.org/D131784
2022-08-13 00:22:01 +02:00
Sam Estep b3f1a6bf10 [clang][dataflow] Encode options using llvm::Optional
This patch restructures `DataflowAnalysisOptions` and `TransferOptions` to use `llvm::Optional`, in preparation for adding more sub-options to the `ContextSensitiveOptions` struct introduced here.

Reviewed By: sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131779
2022-08-12 16:29:41 +00:00
YingChi Long e5825190b8
[clang] fix frontend crash when evaluating type trait
Before this patch type traits are checked in Parser, so use type traits
directly did not cause assertion faults. However if type traits are initialized
from a template, we didn't perform arity checks before evaluating. This
patch moves arity checks from Parser to Sema, and performing arity
checks in Sema actions, so type traits get checked corretly.

Crash input:

```
template<class... Ts> bool b = __is_constructible(Ts...);
bool x = b<>;
```

After this patch:

```
clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp:5:32: error: type trait requires 1 or more arguments; have 0 arguments
template<class... Ts> bool b = __is_constructible(Ts...);
                               ^~~~~~~~~~~~~~~~~~
clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp:6:10: note: in instantiation of variable template specialization 'b<>' requested here
bool x = b<>;
         ^
1 error generated.
```

See https://godbolt.org/z/q39W78hsK.

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

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131423
2022-08-13 00:02:19 +08:00
Ilya Biryukov fba88adc89 [Sema] Always perform ADL when searching for transormed operators in C++20
This fixes compilation errors in the following code with
latest libc++ and libstdc++:
```cpp

int main() {
  std::tuple<std::string> s;
  std::tuple<std::string_view> sv;
  s < sv;
}
```

See https://gcc.godbolt.org/z/vGvEhxWvh for the error.

This used to happen because repeated template instantiations during
C++20 constraint satisfaction will cause a call to `RebuildCXXRewrittenBinaryOperator`
with `PerformADL` set to false, see 59351fe340/clang/lib/Sema/TreeTransform.h (L2737)

Committing urgently to unbreak breakages we see in our configurations.
The change seems relatively safe and the right thing to do.

However, I will follow-up with tests and investigation on whether we
need to do this extra semantic checking in the first place next week.
2022-08-12 16:07:02 +02:00
Joe Loser e8578968f6
[ADT] Replace STLForwardCompat.h's C++17 equivalents
STLForwardCompat.h defines several utilities and type traits to mimic that of
the ones in the C++17 standard library. Now that LLVM is built with the C++17
standards mode, remove use of these equivalents in favor of the ones from the
standard library.

Differential Revision: https://reviews.llvm.org/D131717
2022-08-12 06:55:59 -06:00
Maciej Gabka 48e1250a91 [clang][SVE] Undefine preprocessor macro defined in
arm_sve.h defines and uses __ai macro which needs to be undefined (as it is
already in arm_neon.h).

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D131580
2022-08-12 12:25:49 +00:00
Utkarsh Saxena 72ac7cac3f Handle explicitly defaulted consteval special members.
Followup patch for D128083

Previously, using a non-consteval constructor from an consteval constructor would code generates the consteval constructor.
Example
```
template <typename T>
struct S {
  T i;
  consteval S() = default;
};
struct Foo {
    Foo() {}
};
void func() {
  S<Foo> three; // incorrectly accepted by clang.
}
```

This happened because clang erroneously disregards `consteval` specifier for a `consteval explicitly defaulted special member functions in a class template` if it has dependent data members without a `consteval default constructor`.

According to
```
C++14 [dcl.constexpr]p6 (CWG DR647/CWG DR1358):
If the instantiated template specialization of a constexpr function
template or member function of a class template would fail to satisfy
the requirements for a constexpr function or constexpr constructor, that
specialization is still a constexpr function or constexpr constructor,
even though a call to such a function cannot appear in a constant
expression.
```

Therefore the `consteval defaulted constructor of a class template` should be considered `consteval` even if the data members' default constructors are not consteval.
Keeping this constructor `consteval` allows complaining while processing the call to data member constructors.
(Same applies for other special member functions).

This works fine even when we have more than one default constructors since we process the constructors after the templates are instantiated.

This does not address initialization issues raised in
[2602](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2602) and compiler divergence seen in https://godbolt.org/z/va9EMvvMe

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

Differential Revision: https://reviews.llvm.org/D131479
2022-08-12 12:13:06 +02:00
Martin Storsjö e6db064394 [doc] Remove release notes from the main branch for changes that were backported to 15.x 2022-08-12 11:21:51 +03:00
Chuanqi Xu e190b7cc90 [Coroutines] Maintain the position of final suspend
Closing https://github.com/llvm/llvm-project/issues/56329

The problem happens when we try to simplify the suspend points. We might
break the assumption that the final suspend lives in the last slot of
Shape.CoroSuspends. This patch tries to main the assumption and fixes
the problem.
2022-08-12 13:05:08 +08:00
Tom Stellard 74384c7fce Disable update_cc_test_checks.py tests in stand-alone builds
The script is located in the llvm/ sub-directory, so it is not available
for when doing a stand-alone build.

See https://discourse.llvm.org/t/rfc-stand-alone-build-support/61291

Differential Revision: https://reviews.llvm.org/D123967
2022-08-11 20:53:37 -07:00
Chuanqi Xu 0bc993edf4 [AST] [Modules] Introduce Decl::getNonTransparentDeclContext to handle exported friends
Closing https://github.com/llvm/llvm-project/issues/56826.

The root cause for pr56826 is: when we collect the template args for the
friend, we need to judge if the friend lives in file context. However,
if the friend lives in ExportDecl lexically, the judgement here is
invalid.

The solution is easy. We should judge the non transparent context and
the ExportDecl is transparent context. So the solution should be good.

A main concern may be the patch doesn't handle all the places of the
same defect. I think it might not be bad since the patch itself should
be innocent.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D131651
2022-08-12 11:50:35 +08:00
Ivan Murashko 557e32e002 [clang] SIGSEGV fix at clang::ASTContext::getRawCommentForDeclNoCacheImpl
The `File` might point to an invalid `FileID` when the AST is broken. That leads to clang/clangd crashes while processing comments. The relevant part of the crash is below
```
 #4 0x00007f1d7fbf95bc std::_Rb_tree<unsigned int, std::pair<unsigned int const, clang::RawComment*>, std::_Select1st<std::pair<unsigned int const, clang::RawComment*>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const
, clang::RawComment*>>>::_M_lower_bound(std::_Rb_tree_node<std::pair<unsigned int const, clang::RawComment*>> const*, std::_Rb_tree_node_base const*, unsigned int const&) const /usr/include/c++/8/bits/stl_tree.h:1911:2
 #5 0x00007f1d7fbf95bc std::_Rb_tree<unsigned int, std::pair<unsigned int const, clang::RawComment*>, std::_Select1st<std::pair<unsigned int const, clang::RawComment*>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>>::lower_bound(unsigned int const&) const /usr/include/c++/8/bits/stl_tree.h:1214:56
 #6 0x00007f1d7fbf95bc std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>>::lower_bound(unsigned int const&) const /usr/include/c++/8/bits/stl_map.h:1264:36
 #7 0x00007f1d7fbf95bc clang::ASTContext::getRawCommentForDeclNoCacheImpl(clang::Decl const*, clang::SourceLocation, std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>> const&) const /home/ivanmurashko/local/llvm-project/clang/lib/AST/ASTContext.cpp:226:57
```

The corresponding LIT test that reproduces the crash was also added

Same issue is described at https://bugs.llvm.org/show_bug.cgi?id=49707

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131675
2022-08-12 00:05:59 +01:00
Shafik Yaghmour 106774515b [Clang] Fix for Tighten restrictions on enum out of range diagnostic
Ok it looks like this is a bit more subtle, I broke the llvm-test-suite file
paq8p.cpp again. We need both conditions to be true Info.EvalMode ==
EvalInfo::EM_ConstantExpression && Info.InConstantContext. We need to be in a
context that requires a constant value but also in a constant expression context.

Differential Revision: https://reviews.llvm.org/D131704
2022-08-11 15:34:58 -07:00
Shafik Yaghmour 2608f553b8 [Clang] Tighten restrictions on enum out of range diagnostic
In D131528 using Info.EvalMode == EvalInfo::EM_ConstantExpression is not strict
enough to restrict the diagnostic to only constant expression contexts. It is
sometimes set in cases where we are still determining if we are in a constant
expression context.

Using InConstantContext will tighten the restriction.

Differential Revision: https://reviews.llvm.org/D131704
2022-08-11 13:44:26 -07:00
Denys Petrov adcd4b1c0b [analyzer] [NFC] Fix comments into more regular form. 2022-08-11 21:28:23 +03:00
Alex Bradbury d17de5479c [clang][RISCV][test] Add test that shows incorrect ABI lowering
As reported in <https://github.com/llvm/llvm-project/issues/57084>,
under hard float ABIs there are issues with lowering structs that
inherit from other structs.

See <https://reviews.llvm.org/D131677> for a fix.
2022-08-11 18:51:37 +01:00
Aaron Ballman b48fb85fe6 Fix crash-on-valid with consteval temporary construction through list initialization
Clang currently crashes when lowering a consteval list initialization
of a temporary. This is partially working around an issue in the
template instantiation code (TreeTransform::TransformCXXTemporaryObjectExpr())
that does not yet know how to handle list initialization of temporaries
in all cases. However, it's also helping reduce fragility by ensuring
we always have a valid QualType when trying to emit a constant
expression during IR generation.

Fixes #55871

Differential Revision: https://reviews.llvm.org/D131194
2022-08-11 13:44:24 -04:00
Craig Topper dacbddf562 [RISCV] Move isValidCPUName to RISCVTargetInfo. NFC
Instead of having separate implementations for RV32 and RV64,
use the triple to control the Is64Bit parameter.

Do the same for isValidTuneCPUName, fillValidCPUList, and
fillValidTuneCPUList.
2022-08-11 10:01:56 -07:00
Mike Rice dd4c838da3 [OpenMP] Allow data members in interop init/use/destroy clauses
Previously a diagnostic was given if the expression was not strictly a
DeclRef. Now also allow use of data members inside member functions.

Differential Revision: https://reviews.llvm.org/D131222
2022-08-11 09:39:12 -07:00
Simon Pilgrim 08a880509e [X86] Add RDPRU instruction CPUID bit masks
As mentioned on D128934 - we weren't including the CPUID bit handling for the RDPRU instruction

AMD's APMv3 (24594) lists it as CPUID Fn8000_0008_EBX Bit#4
2022-08-11 16:07:36 +01:00
Simon Pilgrim 6e19e6ce36 [clang][X86] Add RDPRU predefined macro tests for znver2/znver3 targets
These were missed in D128934
2022-08-11 15:48:39 +01:00
Balazs Benics 5e876c54f2 [analyzer] exploded-graph-rewriter: Fix python3 string encoding issues
This encapsulates 3 changes:
 - `DotDumpVisitor` now aggregates strings instead of *bytes* for both
   `python2` and `python3`. This difference caused crashes when it tried
    to write out the content as *strings*, similarly described at D71746.
 - `graphviz.pipe()` expects the input in *bytes* instead of unicode
   strings. And it results in *bytes*. Due to string concatenations and
   similar operations, I'm using unicode string as the default, and
   converting to *bytes* on demand.
 - `write_temp_file()` now appends the `egraph-` prefix and more
   importantly, it will create the temp file in the **current working
   directory** instead of in the *temp*. This change makes `Firefox` be
   able to open the file even if the `security.sandbox.content.level` is
   set to the (default) most restricting `4`.
   See https://support.mozilla.org/si/questions/1259285

An artifact of the bad byte handling was previously in the `HTML`
produced by the script that it displayed the `b'` string at the top left
corner. Now it won't anymore :)

I've tested that the following command works on `Ubuntu 22.04`:
```
exploded-graph-rewriter my-egraph.dot
```
Both `python2` and `python3` works as expected.

PS: I'm not adding tests, as the current test infra does not support
testing HTML outputs for this script.
Check the `clang/test/Analysis/exploded-graph-rewriter/lit.local.cfg`.
We always pass the `--dump-dot-only` flag to the script.
Along with that, the default invocation will not only create this HTML
report but also try to open it. In addition to this, I'm not sure if the
buildbots have `graphviz` installed and also if this package is installed
on `pip`.
Unless we change some of these, we cannot test this change.
Given that D71746 had no tests, I'm not too worried about this either.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D131553
2022-08-11 16:07:52 +02:00
Jun Zhang efc75a2bae
Remove redundant condition check, NFC
Signed-off-by: Jun Zhang <jun@junz.org>
2022-08-11 21:47:19 +08:00