103008 Commits

Author SHA1 Message Date
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 32db121b29f78e4c41116b2a8f1c730f9522b202. 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 3ebf3dd30da219f9f9aee12f42d45d18d55e7580.

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)
91088978d712cd7b33610c59f69d87d5a39e3113 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
Timm Bäder
bdac5de428 [clang][Interp] Specify C standard in test case
Looks like some builders default to c99, which is a problem:
https://lab.llvm.org/buildbot/#/builders/139/builds/49750
2023-09-15 09:34:10 +02:00
Timm Bäder
6d73cca186 [clang][Interp] Lazily visit unknown global declarations
In C, we don't get a evaluateAsInitializer() call for all global
declarations, yet we have to handle DeclRefExpr pointing to them.

Differential Revision: https://reviews.llvm.org/D156794
2023-09-15 08:50:21 +02:00
Brad Smith
1e40dfc5d4
[Driver] Also respect SysRoot for the system library paths on DragonFly (#66056) 2023-09-14 21:18:37 -04:00
Arthur Eubanks
0a1aa6cda2
[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (#66295)
This will make it easy for callers to see issues with and fix up calls
to createTargetMachine after a future change to the params of
TargetMachine.

This matches other nearby enums.

For downstream users, this should be a fairly straightforward
replacement,
e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive
or s/CGFT_/CodeGenFileType::
2023-09-14 14:10:14 -07:00
Yaxun (Sam) Liu
d7e1932f85
[HIP] Fix comdat of template kernel handle (#66283)
Currently, clang emits LLVM IR that fails verifier for the following
code:

```
template<typename T>
__global__ void foo(T x);

void bar() {
  foo<<<1, 1>>>(0);
}
```
This is due to clang putting the kernel handle for foo into comdat,
which is not allowed, since the kernel handle is a declaration.

The siutation is similar to calling a declaration-only template
function. The callee will be a declaration in LLVM IR and won't be put
into comdat. This is in contrast to calling a template function with
body, which will be put into comdat.

Fixes: SWDEV-419769
2023-09-14 15:56:02 -04:00
Kinuko Yasuda
0612c9b09a
[clang][dataflow] Ignore assignment where base class's operator is used (#66364)
In C++ it seems it is legit to use base class's operator (e.g. `using
Base::operator=`) to perform copy if the base class is the common
ancestor of the source and destination object. In such a case we
shouldn't try to access fields beyond that of the base class, however
such a case seems to be very rare (typical code would implement a copy
constructor instead), and could add complexities, so in this patch we
simply bail if the method operator's parent class is different from the
type of the destination object that this framework recognizes.
2023-09-14 20:45:56 +02:00
Leonard Chan
f45f1c3585 Reland "[clang] Add experimental option to omit the RTTI component from the vtable when -fno-rtti is used"
This reverts commit 070493ddbd9473499d6f00ca62bc6aa92808ed79 (and
relands the original change). This removes a test run that makes an
assumption of RTTI being on by default for a given target.
2023-09-14 18:28:37 +00:00
Sam McCall
21ab252f97
[dataflow] Add global invariant condition to DataflowAnalysisContext (#65949)
This records facts that are not sensitive to the current flow condition,
and should apply to all environments.

The motivating case is recording information about where a Value
originated, such as nullability:
 - we may see the same Value for multiple expressions (e.g. reads of the
   same field) in multiple environments (multiple blocks or iterations)
 - we want to record information only when we first see the Value
   (e.g. Nullability annotations on fields only add information if we
   don't know where the value came from)
 - this information should be expressible as a SAT condition
 - we must add this SAT condition to every environment where the
   Value may appear

We solve this by recording the information in the global condition.
This doesn't seem particularly elegant, but solves the problem and is
a fairly small and natural extension of the Environment.

Alternatives considered:
 - store the constraint directly as a property on the Value.
   But it's more composable for such properties to always be variables
   (AtomicBoolValue), and constrain them with SAT conditions.
 - add a hook whenever values are created, giving the analysis the
   chance to populate them.
   However the framework relies on/provides the ability to construct
   values in arbitrary places without providing the context such a hook
   would need, this would be a very invasive change.
2023-09-14 19:30:04 +02:00
Aaron Ballman
1db6b127a1 [C23] Remove N2713 from the list
This paper was obsoleted by the changes in N3138 and US-045
2023-09-14 12:08:51 -04:00
Matt Arsenault
ddc3346a6b
clang/AMDGPU: Fix accidental behavior change for __builtin_amdgcn_ldexph (#66340) 2023-09-14 18:15:44 +03:00
sstwcw
cb479e7d7d [clang-format] More on unbreakable strings in TypeScript (#66321)
Now. string literals in lines beginning with `export type` will not be
broken.

The case was missed in 5db201fb75e6.  I don't know TypeScript.  And
merging GitHub pull requests seems to be a little too easy.  So it got
committed before the reviewers had a chance to find edge cases.
2023-09-14 12:41:21 +00:00
Timm Bäder
d61ba038a9 [clang][Interp][NFC] Call delegate() for the RHS of a comma op 2023-09-14 13:36:51 +02:00
Benjamin Kramer
263fc4c79a Turn off memory leaks in unit test 2023-09-14 13:16:22 +02:00
Balazs Benics
2dee316a04 Fixup "[analyzer] Propagate taint for wchar variants of some APIs"
Fix build bot: https://lab.llvm.org/buildbot/#/builders/139/builds/49699

clang/test/Analysis/taint-generic.c:
```
Line 100: redefinition of typedef 'size_t' is a C11 feature
Line 59: previous definition is here
```

This commit fixups 61924da630532c91f00351b7e84548eb42e2e1e0
Committed in this PR: https://github.com/llvm/llvm-project/pull/66074
2023-09-14 12:22:11 +02:00
M Iyengar
09ffb9ee19
[AArch64][Clang] Implement ACLE rintn intrinsics (#66112)
This patch adds support for two missing ACLE intrinsics for floating
point round with ties to even:

- rintn
- rintnf

These are specified in ACLE section 8.6:
[https://arm-software.github.io/acle/main/acle.html#floating-point-data-processing-intrinsics]
2023-09-14 11:00:49 +01:00
Balazs Benics
61924da630 [analyzer] Propagate taint for wchar variants of some APIs (#66074)
Functions like `fgets`, `strlen`, `strcat` propagate taint.
However, their `wchar_t` variants don't. This patch fixes that.

Notice, that there could be many more APIs missing.
This patch intends to fix those that so far surfaced,
instead of exhaustively fixing this issue.

https://github.com/llvm/llvm-project/pull/66074
2023-09-14 11:55:10 +02:00
Balazs Benics
8243bc4045 [analyzer] Make socket accept() propagate taint (#66074)
This allows to track taint on real code from `socket()`
to reading into a buffer using `recv()`.

https://github.com/llvm/llvm-project/pull/66074
2023-09-14 11:55:10 +02:00
Balazs Benics
909c963999 [analyzer] Fix stdin declaration in C++ tests (#66074)
The `stdin` declaration should be within `extern "C" {...}`, in C++
mode. In addition, it should be also marked `extern` in both C and
C++ modes.

I tightened the check to ensure we only accept `stdin` if both of these
match. However, from the Juliet test suite's perspective, this commit
should not matter.

https://github.com/llvm/llvm-project/pull/66074
2023-09-14 11:55:10 +02:00
DonatNagyE
0b2778d5e5
[analyzer] Fix StdLibraryFunctionsChecker crash on surprising sink node (#66109)
Recent changes in StdLibraryFunctionsChecker introduced a situation
where the checker sequentially performed two state transitions to add
two separate note tags.

In the unlikely case when the updated state (the variable `NewState`)
was posteriorly overconstrained, the engine marked the node after the
first state transition as a sink to stop the "natural" graph exploration
after that point.

However, in this particular case the checker tried to directly add a
second node, and this triggered an assertion in the `addPredecessor()`
method of `ExplodedNode`.

This commit introduces an explicit `isSink()` check to avoid this crash.
To avoid similar bugs in the future, perhaps it would be possible to
tweak `addTransition()` and ensure that it returns `nullptr` when it
would return a sink node (to unify the two possible error conditions).

This crash was observed in an analysis of the curl project (in a very
long and complex function), and there I validated that this is the root
cause, but I don't have a self-contained testcase that can trigger the
creation of a PosteriorlyOverconstrained node in this situation.
2023-09-14 11:51:46 +02:00