Commit Graph

103027 Commits

Author SHA1 Message Date
Zequan Wu
816144bfd2 [Coverage] Skip visiting ctor member initializers with invalid source locations. 2023-09-19 14:59:41 -04:00
Corentin Jabot
a041572353 Let the c(xx)_status pages reflect that clang 17 is released 2023-09-19 20:28:45 +02:00
Erich Keane
11bb5e55dc
In ExprRequirement building, treat OverloadExpr as dependent (#66683)
As reported in #66612, we aren't correctly treating the placeholder
expression type correctly, so we ended up trying to get a reference
version of it, and this resulted in an assertion, since the placeholder
type cannot have a reference added.

Fixes: #66612
2023-09-19 08:31:18 -07:00
mgudim
8f8f4493d5
[RISCV] Recognize veyron-v1 processor in clang driver. (#66703)
Subsequent PRs will add the scheduling model and support for macro
fusions.
2023-09-19 10:39:43 -04:00
Timm Bäder
cf8e189a99 [clang][TSA] Thread safety cleanup functions
Consider cleanup functions in thread safety analysis.

Differential Revision: https://reviews.llvm.org/D152504
2023-09-19 16:00:33 +02:00
Zahira Ammarguellat
a292e7edf8
Fix math-errno issue (#66381)
Update handling of math errno. This change updates the logic for
generation of math intrinics in place of math library function calls.
The previous logic https://reviews.llvm.org/D151834 was incorrectly
using intrinsics when math errno handling was needed at optimization
levels above -O0.
This also fixes issue mentioned in https://reviews.llvm.org/D151834 by
@uabelho
This is joint work with @andykaylor Andy.
2023-09-19 09:13:02 -04:00
Timm Bäder
ad4a513027 [clang][CFG] Cleanup functions
Add declarations declared with attribute(cleanup(...)) to the CFG,
similar to destructors.

Differential Revision: https://reviews.llvm.org/D157385
2023-09-19 11:56:44 +02:00
Daniel Krupp
97495d3159
[analyzer] TaintPropagation checker strlen() should not propagate (#66086)
strlen(..) call should not propagate taintedness,
because it brings in many false positive findings. It is a common
pattern to copy user provided input to another buffer. In these cases we
always
get warnings about tainted data used as the malloc parameter:

buf = malloc(strlen(tainted_txt) + 1); // false warning

This pattern can lead to a denial of service attack only, when the
attacker can directly specify the size of the allocated area as an
arbitrary large number (e.g. the value is converted from a user provided
string).

Later, we could reintroduce strlen() as a taint propagating function
with the consideration not to emit warnings when the tainted value
cannot be "arbitrarily large" (such as the size of an already allocated
memory block).

The change has been evaluated on the following open source projects:

- memcached: [1 lost false
positive](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=memcached_1.6.8_ednikru_taint_nostrlen_baseline&newcheck=memcached_1.6.8_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved)

- tmux: 0 lost reports
- twin [3 lost false
positives](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=twin_v0.8.1_ednikru_taint_nostrlen_baseline&newcheck=twin_v0.8.1_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved)
- vim [1 lost false
positive](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=vim_v8.2.1920_ednikru_taint_nostrlen_baseline&newcheck=vim_v8.2.1920_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved)
- openssl 0 lost reports
- sqliste [2 lost false
positives](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=sqlite_version-3.33.0_ednikru_taint_nostrlen_baseline&newcheck=sqlite_version-3.33.0_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved)
- ffmpeg 0 lost repots
- postgresql [3 lost false
positives](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=postgres_REL_13_0_ednikru_taint_nostrlen_baseline&newcheck=postgres_REL_13_0_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved)
- tinyxml 0 lost reports
- libwebm 0 lost reports
- xerces 0 lost reports

In all cases the lost reports are originating from copying untrusted
environment variables into another buffer.

There are 2 types of lost false positive reports:
1) [Where the warning is emitted at the malloc call by the
TaintPropagation Checker
](https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=memcached_1.6.8_ednikru_taint_nostrlen_baseline&newcheck=memcached_1.6.8_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved&report-id=2648506&report-hash=2079221954026f17e1ecb614f5f054db&report-filepath=%2amemcached.c)
`
            len = strlen(portnumber_filename)+4+1;
            temp_portnumber_filename = malloc(len);
`

2) When pointers are set based on the length of the tainted string by
the ArrayOutofBoundsv2 checker.
For example [this
](https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=vim_v8.2.1920_ednikru_taint_nostrlen_baseline&newcheck=vim_v8.2.1920_ednikru_taint_nostrlen_new&is-unique=on&diff-type=Resolved&report-id=2649310&report-hash=79dc8522d2cd34ca8e1b2dc2db64b2df&report-filepath=%2aos_unix.c)case.
2023-09-19 11:04:50 +02:00
Clement Courbet
c809051215
[NFC] Preparatory work for D153131 (#66750) 2023-09-19 11:02:00 +02:00
martinboehme
1d7b59ca8d
[clang][dataflow] Fix two null pointer dereferences in getMemberForAccessor(). (#66742)
The additions to the test trigger crashes without the fixes.
2023-09-19 09:03:20 +02:00
Piotr Fusik
c724ac9330
[clang] Fix null dereference on return in lambda attribute statement expr (#66643)
clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes https://github.com/llvm/llvm-project/issues/48527
2023-09-19 04:02:04 +02:00
Shoaib Meenai
915ebb07df [driver] Address missed feedback from https://reviews.llvm.org/D158476
I missed this before I committed.
2023-09-18 16:28:04 -07:00
Shoaib Meenai
58288c6c12 [driver] Search for compatible Android runtime directories
Android triples include a version number, which makes direct triple
comparisons for per-target runtime directory searching not always work.
Instead, look for the triple with the highest compatible version number
and use that per-target runtime directory instead. This maintains the
existing fallback to a triple without any version number, but I'm hoping
we can remove that in the future. https://discourse.llvm.org/t/62717
discusses this further.

The one remaining triple mismatch after this is that Android armv7
triples usually have an environment of `androideabi`, which Clang
normalizes to `android`. If you use the `androideabi` triple when
building the runtimes with a per-target runtimes dir, the directory will
get created with `androideabi` in its name, but Clang's triple search
uses the normalized triple and will look for an `android` directory
instead. https://reviews.llvm.org/D140925 will fix that by normalizing
triples when creating the per-target runtimes directories as well.

Reviewed By: phosek, pirama

Differential Revision: https://reviews.llvm.org/D158476
2023-09-18 16:14:18 -07:00
cor3ntin
cacdb90bd7
[Clang] Fix a crash in the diagnostic emission of invalid immediate calls (#66699)
`CXXCtorInitializer` may not refer to a FieldDecl because it might also
denote another constructor call.

Fixes #66324
2023-09-19 00:24:43 +02:00
Bjorn Pettersson
929662b489 Revert "[analyzer] Fix crash analyzing _BitInt() in evalIntegralCast (#65887)"
This reverts commit 4898c33527.

Lots of buildbots are failing, probably because lots of targets not supporting
large _BitInt types.
2023-09-18 23:35:48 +02:00
vabridgers
4898c33527
[analyzer] Fix crash analyzing _BitInt() in evalIntegralCast (#65887)
evalIntegralCast was using makeIntVal, and when _BitInt() types were
introduced this exposed a crash in evalIntegralCast as a result.

Improve evalIntegralCast to use makeIntVal more efficiently to avoid the
crash exposed by use of _BitInt.

This was caught with our internal randomized testing.

<src-root>/llvm/include/llvm/ADT/APInt.h:1510:
  int64_t llvm::APInt::getSExtValue() const: Assertion
  `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.a

...
 #9 <address> llvm::APInt::getSExtValue() const
  <src-root>/llvm/include/llvm/ADT/APInt.h:1510:5
  llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>,
  clang::ento::SVal, clang::QualType, clang::QualType)
  <src-root>/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:607:24
clang::Expr const*, clang::ento::ExplodedNode*,
clang::ento::ExplodedNodeSet&)
  <src-root>/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:413:61
...

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

 Reviewed By: donat.nagy
2023-09-18 15:18:33 -05:00
Tom Honermann
256a0b298c [clang] Correct source locations for instantiations of function templates.
This change corrects some cases where the source location for an
instantiated specialization of a function template or a member function
of a class template was assigned the location of a non-defining
declaration rather than the location of the definition the
specialization was instantiated from.

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

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D64087
2023-09-18 12:51:45 -07:00
Shoaib Meenai
1212d1b511 [driver] Perform fallback target searches for stdlib
Searching for target-specific standard library header and library paths
should perform fallback searches for targets, the same way searching for
the runtime libraries does. It's important for the header and library
searches to be consistent, otherwise we could end up using mismatched
headers and libraries. (See also https://reviews.llvm.org/D146664.)

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D159293
2023-09-18 12:18:51 -07:00
Shoaib Meenai
b1e3cd1d79 [driver] Conditionally include installed libc++ headers for Android
https://reviews.llvm.org/D71154 prevented Clang from search for libc++
headers installed alongside the driver when targeting Android. The
motivation was the NDK's use of a different libc++ inline namespace
(`__ndk1` instead of the standard `__1`), which made regular libc++
headers incompatible with the NDK's libc++ library.

Since then, libc++ has gained the ability to install its `__config_site`
header (which controls the inline namespace, among other things) to a
per-target include directory, which enables per-target customizations.
If this directory is present, the user has expressly built libc++ for
Android, and we should use those headers.

The motivation is that, with the current setup, if a user builds their
own libc++ for Android, they'll use the library they built themselves
but the NDK's headers instead of their own, which is surprising at best
and can cause all sorts of problems (e.g. if you built your own libc++
with a different ABI configuration). It's important to match the headers
and libraries in that scenario, and checking for an Android per-target
include directory lets us do so without regressing the original scenario
which https://reviews.llvm.org/D71154 was addressing.

While I'm here, switch to using sys::path::append instead of slashes
directly, to get system path separators on Windows, which is consistent
with how library paths are constructed (and that consistency will be
important in a follow-up, where we use a common search function for the
include and library path construction).

(As an aside, one of the motivations for https://reviews.llvm.org/D71154
was to support targeting both Android and Apple platforms, which
expected libc++ headers to be provided by the toolcain at the time.
Apple has since switched to including libc++ headers in the platform SDK
instead of in the toolchain, so that specific motivation no longer
applies either.)

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D159292
2023-09-18 12:18:45 -07:00
Takuya Shimizu
b2cd9db589 [clang][Sema] Remove irrelevant diagnostics from constraint satisfaction failure
BEFORE this patch, when clang handles constraints like C1 || C2 where C1 evaluates to false and C2 evaluates to true, it emitted irrelevant diagnostics about the falsity of C1.
This patch removes the irrelevant diagnostic information generated during the evaluation of C1 if C2 evaluates to true.

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

Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D157526
2023-09-18 18:14:44 +09:00
Timm Bäder
52a55a7178 [clang][Interp] Allow zero-init of primitives with an empty init list
Differential Revision: https://reviews.llvm.org/D158595
2023-09-18 11:09:30 +02:00
Kinuko Yasuda
03be486ecc
[clang][dataflow] Model the fields that are accessed via inline accessors (#66368)
So that the values that are accessed via such accessors can be analyzed
as a limited version of context-sensitive analysis. We can potentially
do this only when some option is set, but doing additional modeling like
this won't be expensive and intrusive, so we do it by default for now.
2023-09-18 10:46:36 +02:00
Clement Courbet
75b76c4b47
[clang-transformer] Allow stencils to read from system headers. (#66480)
We were previously checking that stencil input ranges were writable. It
suffices for them to be readable.
2023-09-18 10:07:30 +02:00
Yeting Kuo
9ea083f2d4
[Clang][test] Replace legacy -target with --target=. (#66572) 2023-09-18 15:35:57 +08:00
Nuno Lopes
de56ceb54a
[clang] fix stray whitespace in release notes to fix CI failure 2023-09-17 10:25:53 +01:00
antangelo
da35b2e57a
[clang][Docs] Document X86 interrupt attribute (#65662)
Adds documentation for the X86 `__attribute__((interrupt))` attribute,
in a similar format to interrupt attributes of
other platforms.

Migrated from https://reviews.llvm.org/D159317
2023-09-17 01:26:26 -04:00
faisal vali
5bdd5d064d Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32
See issue https://github.com/llvm/llvm-project/issues/62594

This code does not work on win32:

  auto lstatic = []()  static  { return 0;  };
  int (*f2)(void) = lstatic;

Since a calling convention such as CC_X86ThisCall can rightly interfere with the implicit pointer to function conversion if erroneously marked on a static function, the fix entails checking the 'static' specifier on the lambda declarator prior to assigning it a calling convention of an non-static member (which pre-c++23 made sense).
2023-09-16 13:29:59 -05:00
sstwcw
00e794b4dd
[clang-format] Properly indent lines inside Verilog case structure (#65861)
When a statement following a case label had to be broken into multiple
lines, the continuation parts were not indented correctly.

Old:

```Verilog
case (data)
  16'd0:
    result = // break here
    10'b0111111111;
endcase
```

New:

```Verilog
case (data)
  16'd0:
    result = // break here
        10'b0111111111;
endcase
```

Verilog case labels and the following statements are on the same
unwrapped line due to the difficulty of identifying them. So there was a
rule in `getNewLineColumn` to add a level of indentation to the part
following the case label. However, in case the line had to be broken
again, the code at the end of the function would see that the line was
already broken with the continuation part indented, so it would not
indent it more. Now `State.FirstIndent` is changed as well for the part
following the case label, so the logic for determining when to add a
continuation indentation works.
2023-09-16 14:30:19 +00:00
Fangrui Song
4da1c180b9
[Driver] Change default PCH extension name from .gch to .pch (#66165)
For `c-header` and `c++-header` inputs, Clang driver selects the
`-emit-pch` frontend action and defaults the output suffix name to
`.gch` (except clang-cl, which uses `.pch`) to follow GCC.
```
clang -c a.h               # a.h.gch
clang -xc++-header -c a.h  # a.h.gch
```

In every other place we prefer `.pch` to `.gch`. E.g. `-include a.h`
probes `a.h.pch` before `a.h.gch`, and we have `-include-pch` instead of
`-include-gch`. (Clang and GCC use different extension names for C++
modules as well.)

This change isn't disruptive because:

* Most newer build systems specify explicit output filenames and are
unaffected
* Implicit output name users almost assuredly use something like
  `-include a.h`, which probes both `a.h.pch` and `a.h.gch`[^1]

[^1]: In the future, we shall stop probing `a.h.gch` for `-include a.h`
as the
compatibility intended behavior actually gets in the way

(https://discourse.llvm.org/t/how-to-have-clang-ignore-gch-directories/51835).
This patch is a prerequisite.
2023-09-16 00:27:45 -07:00
Louis Dionne
a52560c8dd [clang] Remove spurious trailing whitespace 2023-09-15 17:26:16 -04:00
Owen Pan
5ed94c6e3d
[clang-format] Fix a bug in ContinuationIndenter (#66354)
See https://reviews.llvm.org/D136154#3890747 for context.

Fixes part of #58592.
2023-09-15 14:20:41 -07:00
Zequan Wu
0b8df841f9
[Coverage] Add coverage for constructor member initializers. (#66441)
Before, constructor member initializers are shown as not covered. This
adds coverage info for them.
2023-09-15 17:06:04 -04:00
Timm Baeder
d462bd527a
[clang][Interp] Handle AttributedStmts (#66495)
Just ignore the attributes.
2023-09-15 21:03:18 +02:00
Zequan Wu
1f33bfc23f Fix test case in 32db121b29. 2023-09-15 14:42:55 -04:00
Zequan Wu
32db121b29 [Coverage] Allow Clang coverage to be used with debug info correlation.
Debug info correlation is an option in InstrProfiling pass, which is used by
both IR instrumentation and front-end instrumentation. So, Clang coverage can
also benefits the binary size saving from it.

Reviewed By: ellis

Differential Revision: https://reviews.llvm.org/D157913
2023-09-15 13:47:23 -04:00
Anton Korobeynikov
51d5d7bbae
Extend retcon.once coroutines lowering to optionally produce a normal result (#66333)
One of the main user of these kind of coroutines is swift. There yield-once (`retcon.once`) coroutines are used to temporary "expose" pointers to internal fields of various objects creating borrow scopes.

However, in some cases it might be useful also to allow these coroutines to produce a normal result, but there is no convenient way to represent this (as compared to switched-resume kind of coroutines where C++ `co_return`
is transformed to a member / callback call on promise object).

The extension is simple: we allow continuation function to have a non-void result and accept optional extra arguments via a special `llvm.coro.end.result` intrinsic that would essentially forward them as normal results.
2023-09-15 09:54:38 -07:00
dingfei
7c9abbd8a4 Reapply [analyzer] Simplify SVal for simple NonLoc->Loc casts
Reapply after fixing the test by enabling the `debug.ExprInspection` checker.

-----

NonLoc symbolic SVal to Loc casts are not supported except for
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can
go through nonloc::ConcreteInt->loc::ConcreteInt path. For example:

  void test_simplified_before_cast_add(long long t1) {
    long long t2 = t1 + 3;
    if (!t2) {
      int *p = (int *) t2;
      clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
    }
  }

If simplified, 't2' is 0, resulting 'p' is nullptr, otherwise 'p'
is unknown.

Fixes #62232
2023-09-15 15:07:39 +02:00
sstwcw
a20f485bb0 [clang-format] Generate the style options
I was in a hurry and I forgot to do it for the last commit.
2023-09-15 12:37:21 +00:00
sstwcw
ae90f689a5
[clang-format] Disable string breaking in JS for now (#66372)
See the discussion

[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.
2023-09-15 12:36:09 +00:00
martinboehme
0069004856
[clang][dataflow] Add a test for context-sensitive analysis on a self-referential class. (#66359)
The test demonstrates that the `this` pointer seen in the constructor
has the
same value as the address of the variable the object is constructed
into.
2023-09-15 14:31:10 +02:00
Timm Bäder
73371faf05 [clang][Interp][NFC] Remove unused includes 2023-09-15 13:37:35 +02:00
Benjamin Kramer
7af24c765d Disable writing an output file to the source directory in Driver test 2023-09-15 13:19:13 +02:00
Balazs Benics
03693d5b40 Revert "[analyzer] Simplify SVal for simple NonLoc->Loc casts (#66463)"
This reverts commit 3ebf3dd30d.

I thought "Mergeing" will wait and confirm if the checks pass, and only
merge it if they succeed. Apparently, it's not the case here xD

The test is just broken in x86. See:
https://lab.llvm.org/buildbot/#/builders/109/builds/73686
2023-09-15 13:18:34 +02:00
Timm Bäder
23c39f9a9e [clang][Interp] Diagnose unknown parameter values
Differential Revision: https://reviews.llvm.org/D156509
2023-09-15 13:10:19 +02:00
Timm Bäder
177f9ab2fb [clang][Interp] Check pointer inc/dec ops for initialization
Differential Revision: https://reviews.llvm.org/D158702
2023-09-15 13:04:04 +02:00
Ding Fei
3ebf3dd30d
[analyzer] Simplify SVal for simple NonLoc->Loc casts (#66463)
NonLoc symbolic SVal to Loc casts are not supported except for
nonloc::ConcreteInt.

This change simplifies the source SVals so that the more casts can go
through nonloc::ConcreteInt->loc::ConcreteInt path. For example:

```c
  void test_simplified_before_cast_add(long long t1) {
    long long t2 = t1 + 3;
    if (!t2) {
      int *p = (int *) t2;
      clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
    }
  }
```
If simplified, `t2` is 0, resulting `p` is nullptr, otherwise `p` is
unknown.

Fixes #62232
2023-09-15 13:00:32 +02:00
Mariya Podchishchaeva
38b4df5e2e
[clang] Fix wrong warning about missing init for flexible array members (#66341)
91088978d7 shouldn't have removed an
additional check that field has incomplete array type.

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

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2023-09-15 10:57:51 +02:00
Timm Bäder
cd2f2c1662 [clang][Interp] Visit Logical-not operand as bool
Differential Revision: https://reviews.llvm.org/D157200
2023-09-15 10:12:20 +02:00
Timm Bäder
d485fc40f3 [clang][Interp][NFC] Fix a comment typo 2023-09-15 09:55:52 +02:00
Timm Bäder
a259005a21 [clang][Interp] Convert logical binop operands to bool
Differential Revision: https://reviews.llvm.org/D157174
2023-09-15 09:52:41 +02:00