[PATCH] D87587: [clang-format][PR47290] Add ShortNamespaceLines format option

2021-03-04 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D87587#2597241 , @kuzkry wrote:

> Thank you for delivering it, @HazardyKnusperkeks.
>
> One thing concerns me though. I'm not an author of changes done in 
> clang/docs/ClangFormatStyleOptions.rst in lines 2372, 3069-3073, 3075, 3077, 
> 3082-3086, 3088, 3093-3097, 3099, 3104-3108, and 3110-3111. Perhaps it's just 
> a mistake (something might have slipped through `git add`). Please let me 
> know.

I've just run `dump_format_style.py`, why the other lines were changed (or not 
correct before) I don't know, but this is the result of the official script.

If that bothers you I can revert and split it in two commits. But I don't think 
that's necessary as the real author of those lines is the script, not what's 
written in the git history.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87587/new/

https://reviews.llvm.org/D87587

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97362: [clang][parser] Allow attributes in explicit template instantiations

2021-03-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:1618
+
+if (Tok && (*Tok).is(tok::l_square)) {
+  Diag(Attrs.Range.getBegin(), diag::err_attributes_not_allowed) << 
Attrs.Range;

aaron.ballman wrote:
> This will incorrectly classify an empty MS attribute `[]` as being a 
> prohibited `[[]]` attribute. I think we need something like:
> ```
> if (Tok && Tok->is(tok::l_square)) {  
>  SourceLocation NextTokLoc = 
> Lexer::findLocationAfterToken(Attrs.Range.getBegin(), Tok.getKind(), SM, 
> getLangOpts(), true);
>  auto NextTok = Lexer::findNextToken(NextTokLoc, SM, getLangOpts());
>  if (NextTok && NextTok->is(tok::l_square)) {
>...
>  }
> }
> ```
> Also, I think it should use `DiagID` rather than hard-coding the diagnostic 
> to use.
The `findNextToken()` here returns the second `[` in `[[]]`, so would return 
the `]` for `[]`. The code you proposed doesn't work because the second 
`findNextToken()` returns the first `]`, so not a `tok::l_square`. I know your 
code makes more sense since we're looking for `[[`, but I couldn't find a way 
to get the first `[` from the Lexer.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97362/new/

https://reviews.llvm.org/D97362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97916: [Driver][RISCV] Support parsing multi-lib config from GCC.

2021-03-04 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/RISCV.cpp:727
+{
+  /* Default code model is small(medlow).  */
+  StringRef CodeModel;

`//`



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1595
+return GCCPath.str().str();
+  else
+return "";

https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1625
+
+bool ScanGCCMultilibConfig(
+const Driver &D,

camelCase. Just ignore older functions which use CamelCase.



Comment at: clang/test/Driver/riscv64-toolchain.c:158
+// RUN: %clang %s \
+// RUN:   -target riscv64-unknown-elf \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv64_elf_sdk \

Hmm. I happened to have posted 
https://lists.llvm.org/pipermail/cfe-dev/2021-March/067820.html about how folks 
use --gcc-toolchain.

Is this an useful option on non-riscv host?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97916/new/

https://reviews.llvm.org/D97916

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96586: [analyzer][CTU][NFC] Add an extra regression test

2021-03-04 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D96586#2601856 , @NoQ wrote:

>> `-analyzer-opt-analyze-headers`
>
> I'm actually shocked that we provide such option at all. And that it's the 
> first option in the list in `scan-build --help`. And that I haven't noticed 
> it until now despite that.

I didn't know about this option either xD

> How did you discover the crash? Are people actually using it?

If I remember correctly, one of our test runs, analyzing the clang's source 
code with shallow and deep CTU configuration crashed.
The CodeChecker was driving the analysis, but if a configuration can crash the 
analyzer that is a problem for sure.
We always provide this flag here 
.

Luckily, Richard's commit fixed this without any direct intent :D That is why I 
want to pin this via this regression test.

The funny thing is that no headers are involved, yet the crash depends on the 
`-analyzer-opt-analyze-headers` flag.

> "Force the static analyzer to analyze functions defined in header files"

I'm not sure how can this flag influence that, as no header files are involved 
in this reproducer.
I didn't feel like the time not worth investigating this more thoroughly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96586/new/

https://reviews.llvm.org/D96586

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97916: [Driver][RISCV] Support parsing multi-lib config from GCC.

2021-03-04 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/test/Driver/riscv64-toolchain.c:158
+// RUN: %clang %s \
+// RUN:   -target riscv64-unknown-elf \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv64_elf_sdk \

MaskRay wrote:
> Hmm. I happened to have posted 
> https://lists.llvm.org/pipermail/cfe-dev/2021-March/067820.html about how 
> folks use --gcc-toolchain.
> 
> Is this an useful option on non-riscv host?
`--gcc-toolchain` should be useful for non-pure LLVM toolchain especially for 
bare-metal cross toolchain, IIRC GCC_INSTALL_PREFIX is not support relative 
path well like DEFAULT_SYSROOT[1], so I think this option is necessary even we 
have GCC_INSTALL_PREFIX cmake option.

[1] https://reviews.llvm.org/D76653


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97916/new/

https://reviews.llvm.org/D97916

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97894: [Driver] Drop $sysroot/usr special case from Gentoo gcc-config detection

2021-03-04 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Well, I think this was mostly 'just in case' condition, so I guess it's fine. 
Let's just wait for @manojgupta to give it some more testing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97894/new/

https://reviews.llvm.org/D97894

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97916: [Driver][RISCV] Support parsing multi-lib config from GCC.

2021-03-04 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 328062.
kito-cheng added a comment.

Address MaskRay's comment and apply clang-format.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97916/new/

https://reviews.llvm.org/D97916

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/bin/riscv32-unknown-elf-gcc
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/rv32iac/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/rv32iac/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/rv32imafc/ilp32f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/rv32imafc/ilp32f/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/rv64imafdc/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/lib/gcc/riscv32-unknown-elf/8.2.0/rv64imafdc/lp64d/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/riscv32-unknown-elf/lib/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/riscv32-unknown-elf/lib/rv32iac/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/riscv32-unknown-elf/lib/rv32imafc/ilp32f/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv32_elf_sdk/riscv32-unknown-elf/lib/rv64imac/lp64/crt0.o
  clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/bin/riscv64-unknown-elf-gcc
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp32f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp32f/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imafdc/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imafdc/lp64d/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/riscv64-unknown-elf/lib/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/riscv64-unknown-elf/lib/rv32iac/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/riscv64-unknown-elf/lib/rv32imafc/ilp32f/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk/riscv64-unknown-elf/lib/rv64imac/lp64/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv64_elf_sdk_bad/bin/riscv64-unknown-elf-gcc
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c

Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -153,6 +153,24 @@
 // C-RV64-RTLIB-COMPILERRT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "{{.*}}libclang_rt.builtins-riscv64.a"
 // C-RV64-RTLIB-COMPILERRT-LP64: "{{.*}}clang_rt.crtend-riscv64.o"
 
+// Test for multi-lib config from GCC.
+// RUN: %clang %s \
+// RUN:   -target riscv64-unknown-elf \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv64_elf_sdk \
+// RUN:   --print-multi-lib \
+// RUN:   | FileCheck -check-prefix=C-RV64-GCC-MULTI-LIB %s
+// C-RV64-GCC-MULTI-LIB: rv32iac/ilp32;@march=rv32iac@mabi=ilp32
+// C-RV64-GCC-MULTI-LIB-NEXT: rv32imafc/ilp32f;@march=rv32iac@mabi=ilp32f
+// C-RV64-GCC-MULTI-LIB-NEXT: rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d
+// C-RV64-GCC-MULTI-LIB-NOT:  {{^.+$}}
+
+// RUN: %clang %s \
+// RUN:   -target riscv64-unknown-elf \
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv64_elf_sdk_bad \
+// RUN:   --print-multi-lib 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV64-GCC-MULTI-LIB-BAD %s
+// C-RV64-GCC-MULTI-LIB-BAD: warning: xxx option unrecognized in multi-lib configuration when parsing config from GCC, falling back to built-in multi-lib configuration. [-Wmultilib-fallback]
+
 // RUN: %clang -target riscv64 %s -emit-llvm -S -o - | FileCheck %s
 
 typedef __builtin_va_list va_list;
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -197,6 +

[PATCH] D97916: [Driver][RISCV] Support parsing multi-lib config from GCC.

2021-03-04 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng marked 3 inline comments as done.
kito-cheng added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/RISCV.cpp:727
+{
+  /* Default code model is small(medlow).  */
+  StringRef CodeModel;

MaskRay wrote:
> `//`
Thanks, I guess some time my brain still in GCC development mode :P


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97916/new/

https://reviews.llvm.org/D97916

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97058: [OpenCL] Refactor diagnostic for OpenCL extension/feature

2021-03-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:364
   for (auto &I : Atomic64BitTypes)
 setOpenCLExtensionForType(I,
 "cl_khr_int64_base_atomics cl_khr_int64_extended_atomics");

Anastasia wrote:
> I think this should be lifted into the above if statement? Although since we 
> are adding the types conditionally we could even drop this code completely 
> and let the developers just use the types as they are already added and made 
> available by the frontend.
>  I think this should be lifted into the above if statement?

No, this is needed to be here as `atomic_double` added above.

>  Although since we are adding the types conditionally we could even drop this 
> code completely and let the developers just use the types as they are already 
> added and made available by the frontend.

I'm now worried about diagnostics  with that change:

```
tmp.cl:2:17: error: expected ';' after expression
atomic_ulong a;
^
;
tmp.cl:2:5: error: use of undeclared identifier 'atomic_ulong'
atomic_ulong a;
^
tmp.cl:2:18: error: use of undeclared identifier 'a'
atomic_ulong a;
 ^
tmp.cl:3:5: error: unknown type name 'atomic_uintptr_t'; did you mean 
'atomic_uint'?
atomic_uintptr_t u;
^~~~
atomic_uint
note: 'atomic_uint' declared here
4 errors generated.
```
Is this expected behaviour when `cl_khr_int64_base_atomics` and 
'cl_khr_int64_extended_atomics' not supported? I think we need o be more 
careful with reserved identifiers. However,  I didn't find explicit wording 
about it, but I'm pretty sure that all of these atomic types identifiers should 
be reserved. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97058/new/

https://reviews.llvm.org/D97058

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92808: [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of explicitly emitting retainRV or claimRV calls in the IR

2021-03-04 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D92808#2601408 , @fhahn wrote:

> In D92808#2600245 , @hans wrote:
>
>> Reverted in 
>> https://github.com/llvm/llvm-project/commit/0a5dd067181dac2a8882a139ea3bd19bdea5fa44
>>  until this can be fixed.
>
> Thanks! I pushed a fix for the issue in 75805dce5ff8 
> . @Hans, 
> would it be possible to check if D92808  + 
> 75805dce5ff8 
>  fixes 
> the issue or should we just recommit D92808 ?

Yes, I confirmed that 75805dce5ff8 
 fixes the 
test case I was looking at. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92808/new/

https://reviews.llvm.org/D92808

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94500: [clang-format] Rework Whitesmiths mode to use line-level values in UnwrappedLineParser

2021-03-04 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Could you please rebase your patch an reupload the diff, it doesn't apply 
anymore. (And doing it by hand is too much work for me.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94500/new/

https://reviews.llvm.org/D94500

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97548: [clangd] Introduce client state invalidation

2021-03-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 328067.
kadircet marked an inline comment as done.
kadircet added a comment.

- Rename method and update comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97548/new/

https://reviews.llvm.org/D97548

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/semantic-tokens-refresh.test

Index: clang-tools-extra/clangd/test/semantic-tokens-refresh.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/semantic-tokens-refresh.test
@@ -0,0 +1,42 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"capabilities":{
+  "workspace":{"semanticTokens":{"refreshSupport":true}}
+}}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
+  "uri": "test:///foo.cpp",
+  "languageId": "cpp",
+  "text": "int x = 2;"
+}}}
+# Expect a request after initial preamble build.
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }
+---
+# Reply with success.
+{"jsonrpc":"2.0","id":0}
+---
+# Preamble stays the same, no refresh requests.
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{
+  "textDocument": {"uri":"test:///foo.cpp","version":2},
+  "contentChanges":[{"text":"int x = 2;\nint y = 3;"}]
+}}
+# CHECK-NOT:  "method": "workspace/semanticTokens/refresh"
+---
+# Preamble changes
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{
+  "textDocument": {"uri":"test:///foo.cpp","version":2},
+  "contentChanges":[{"text":"#define FOO"}]
+}}
+# Expect a request after initial preamble build.
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }
+---
+# Reply with error, to make sure there are no crashes.
+{"jsonrpc":"2.0","id":1,"error":{"code": 0, "message": "msg"}}
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
+
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -261,6 +261,7 @@
 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out, llvm::json::Path);
 
 struct NoParams {};
+inline llvm::json::Value toJSON(const NoParams &) { return nullptr; }
 inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
   return true;
 }
@@ -473,6 +474,10 @@
   /// This is a clangd extension.
   /// window.implicitWorkDoneProgressCreate
   bool ImplicitProgressCreation = false;
+
+  /// Whether the client implementation supports a refresh request sent from the
+  /// server to the client.
+  bool SemanticTokenRefreshSupport = false;
 };
 bool fromJSON(const llvm::json::Value &, ClientCapabilities &,
   llvm::json::Path);
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -403,6 +403,10 @@
 }
   }
 }
+if (auto *SemanticTokens = Workspace->getObject("semanticTokens")) {
+  if (auto RefreshSupport = SemanticTokens->getBoolean("refreshSupport"))
+R.SemanticTokenRefreshSupport = *RefreshSupport;
+}
   }
   if (auto *Window = O->getObject("window")) {
 if (auto WorkDoneProgress = Window->getBoolean("workDoneProgress"))
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -27,6 +27,7 @@
 #include "support/Cancellation.h"
 #include "support/Function.h"
 #include "support/MemoryTree.h"
+#include "support/Path.h"
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -73,6 +74,14 @@
 /// Not called concurrently.
 virtual void
 onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) {}
+
+/// Called when the meaning of a source code may have changed without an
+/// edit. Usually clients assume that responses to requests are valid until
+/// they next edit the file. If they're invalidated at other times, we
+/// should tell the client. In particular, when an asynchronous preamble
+/// build finishes, we can provide more accurate semantic tokens, so we
+/// should tell the client to refresh.
+virtual void onSemanticsMaybeChanged(PathRef File) {}
   };
   /// Creates a context provider that loads and installs config.
   /// Errors in loading config are repor

[PATCH] D96760: [clang-format] Suppress diagnostics on second parse

2021-03-04 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 328075.
HazardyKnusperkeks added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96760/new/

https://reviews.llvm.org/D96760

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1398,8 +1398,9 @@
 }
 
 std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
-   FormatStyle *Style,
-   bool AllowUnknownOptions) {
+   FormatStyle *Style, bool AllowUnknownOptions,
+   llvm::SourceMgr::DiagHandlerTy DiagHandler,
+   void *DiagHandlerCtxt) {
   assert(Style);
   FormatStyle::LanguageKind Language = Style->Language;
   assert(Language != FormatStyle::LK_None);
@@ -1407,7 +1408,8 @@
 return make_error_code(ParseError::Error);
   Style->StyleSet.Clear();
   std::vector Styles;
-  llvm::yaml::Input Input(Config);
+  llvm::yaml::Input Input(Config, /*Ctxt=*/nullptr, DiagHandler,
+  DiagHandlerCtxt);
   // DocumentListTraits> uses the context to get default
   // values for the fields, keys for which are missing from the configuration.
   // Mapping also uses the context to get the language to find the correct
@@ -2994,6 +2996,8 @@
   FilesToLookFor.push_back(".clang-format");
   FilesToLookFor.push_back("_clang-format");
 
+  auto dropDiagnosticHandler = [](const llvm::SMDiagnostic &, void *) {};
+
   for (StringRef Directory = Path; !Directory.empty();
Directory = llvm::sys::path::parent_path(Directory)) {
 
@@ -3038,7 +3042,8 @@
   LLVM_DEBUG(llvm::dbgs() << "Applying child configurations\n");
 
   for (const auto& MemBuf : llvm::reverse(ChildFormatTextToApply)){
-auto Ec = parseConfiguration(*MemBuf, &Style, AllowUnknownOptions);
+auto Ec = parseConfiguration(*MemBuf, &Style, AllowUnknownOptions,
+ dropDiagnosticHandler);
 // It was already correctly parsed.
 assert(!Ec);
 static_cast(Ec);
@@ -3073,8 +3078,9 @@
 LLVM_DEBUG(llvm::dbgs()
<< "Applying child configuration on fallback style\n");
 
-auto Ec = parseConfiguration(*ChildFormatTextToApply.front(),
- &FallbackStyle, AllowUnknownOptions);
+auto Ec =
+parseConfiguration(*ChildFormatTextToApply.front(), &FallbackStyle,
+   AllowUnknownOptions, dropDiagnosticHandler);
 // It was already correctly parsed.
 assert(!Ec);
 static_cast(Ec);
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -19,6 +19,7 @@
 #include "clang/Tooling/Inclusions/IncludeStyle.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Regex.h"
+#include "llvm/Support/SourceMgr.h"
 #include 
 
 namespace llvm {
@@ -3320,9 +3321,11 @@
 private:
   FormatStyleSet StyleSet;
 
-  friend std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
-FormatStyle *Style,
-bool AllowUnknownOptions);
+  friend std::error_code
+  parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
+ bool AllowUnknownOptions,
+ llvm::SourceMgr::DiagHandlerTy DiagHandler,
+ void *DiagHandlerCtxt);
 };
 
 /// Returns a format style complying with the LLVM coding standards:
@@ -3380,9 +3383,13 @@
 ///
 /// If AllowUnknownOptions is true, no errors are emitted if unknown
 /// format options are occured.
-std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
-   FormatStyle *Style,
-   bool AllowUnknownOptions = false);
+///
+/// If set all diagnostics are emitted through the DiagHandler.
+std::error_code
+parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
+   bool AllowUnknownOptions = false,
+   llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
+   void *DiagHandlerCtx = nullptr);
 
 /// Like above but accepts an unnamed buffer.
 inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97803: [clangd] Overload bundles are only deprecated if each overloads is.

2021-03-04 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

So, if my understanding is correct, this will make the whole bundle 
non-deprecated if at least one overload is not deprecated? This is probably an 
improvement over the existing behaviour. However, do we maybe want to split the 
bundles into deprecated and non-deprecated groups?




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:410
+if (Completion.Deprecated) {
+  Completion.Deprecated =
+  (C.SemaResult &&

The comment you added says "cleared" which means this should probably be `|=` 
rather than `=`, right?

Also, I this looks longer but probably more readable at least for me.

Also, the sources might be `SemaResult`, `IndexResult` or `IdentifierResult`, 
right? :( Otherwise could've been `Completion.Deprecated |= C.SemaResult ? 
C.SemaResult->Availability == CXAvailability_Deprecated : C.IndexResult->Flags 
& Symbol::Deprecated;`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97803/new/

https://reviews.llvm.org/D97803

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97555: [clangd] Add diagnostic augmentation hook to Modules

2021-03-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Module.h:97
 
+  /// Called by auxilary threads as diagnostics encountered to generate fixes.
+  /// So this can be called concurrently from multiple threads. If a module

sammccall wrote:
> This seems too specialized to me - maybe we want to observe diagnostics only, 
> or mutate some other property of them.
> 
> Consider just passing in the (mutable) clangd::Diag, and returning void? 
> Maybe call it `handleDiagnostic` or so
> 
> Maybe also the clang::Diagnostic if you really need it.
passing in `clangd::Diag` and mutating it sounds pretty neat, thanks!

I do think it is also useful to pass `clang::Diagnostic` though, as it usually 
contains extra semantic information that might be used to generate a fix.
For example in case of missing module deps:
- it knows about the particular include/import that triggered the diagnostic
- name of the current module.

The former can be inferred from diagnostic range and reading the source code 
(we'll need to pass in sourcemanager somehow though, to ensure we read the same 
version of the file), and the latter can be inferred by looking at the compile 
commands (or implementations can query the build system with TUs name etc.). 
But this is one particular case, it might tie our hands when we want to 
generate fixes that require deeper semantic analysis (like type info) in the 
future. So i think we should really be passing `clang::Diagnostic` too.

So I'll update this to take in a read-only `clang::Diagnostic`, `Level` and a 
mutable `clangd::Diag`, does that SG?



Comment at: clang-tools-extra/clangd/Module.h:98
+  /// Called by auxilary threads as diagnostics encountered to generate fixes.
+  /// So this can be called concurrently from multiple threads. If a module
+  /// provides a code action with a custom, it should also register itself as

sammccall wrote:
> random thoughts about how this gets called... (definitely not for now though!)
> 
> There are other things we might want to do while building ASTs.
> e.g. *generate* diagnostics (maybe IWYU or clang-tidy can be modules)
> At that point maybe we want something like
> ```
> virtual unique_ptr Module::parseAST() { return nullptr; } // 
> threadsafe
> class ParseASTHooks { // implementations need not be threadsafe
>   virtual void sawDiagnostic(clangd::Diag &D);
>   virtual void finish(ParsedAST&);
> };
> ```
> That way it's easier to reason about call sequences. (and it eliminates the 
> problem of calling an empty virtual method on each module for each diagnostic)
SG indeed, I'd be happy to do that in a follow-up change.

Though this might still have the problem of calling an empty virtual method 
with each diag, for example if a module doesn't do anything per-diagnostic but 
only does something on `finish`, but it definitely limits the scope.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97555/new/

https://reviews.llvm.org/D97555

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97688: clang-format: use `pb` as a canonical raw string delimiter for google style

2021-03-04 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 328079.
krasimir added a comment.

Update tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97688/new/

https://reviews.llvm.org/D97688

Files:
  clang/unittests/Format/FormatTestRawStrings.cpp


Index: clang/unittests/Format/FormatTestRawStrings.cpp
===
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -782,11 +782,16 @@
 }
 
 TEST_F(FormatTestRawStrings, UpdatesToCanonicalDelimiters) {
-  FormatStyle Style = getRawStringPbStyleWithColumns(25);
+  FormatStyle Style = getRawStringPbStyleWithColumns(35);
   Style.RawStringFormats[0].CanonicalDelimiter = "proto";
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO");
+
   expect_eq(R"test(a = R"proto(key: value)proto";)test",
 format(R"test(a = R"pb(key:value)pb";)test", Style));
 
+  expect_eq(R"test(PARSE_TEXT_PROTO(R"proto(key: value)proto");)test",
+format(R"test(PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
   // Don't update to canonical delimiter if it occurs as a raw string suffix in
   // the raw string content.
   expect_eq(R"test(a = R"pb(key: ")proto")pb";)test",


Index: clang/unittests/Format/FormatTestRawStrings.cpp
===
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -782,11 +782,16 @@
 }
 
 TEST_F(FormatTestRawStrings, UpdatesToCanonicalDelimiters) {
-  FormatStyle Style = getRawStringPbStyleWithColumns(25);
+  FormatStyle Style = getRawStringPbStyleWithColumns(35);
   Style.RawStringFormats[0].CanonicalDelimiter = "proto";
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO");
+
   expect_eq(R"test(a = R"proto(key: value)proto";)test",
 format(R"test(a = R"pb(key:value)pb";)test", Style));
 
+  expect_eq(R"test(PARSE_TEXT_PROTO(R"proto(key: value)proto");)test",
+format(R"test(PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
   // Don't update to canonical delimiter if it occurs as a raw string suffix in
   // the raw string content.
   expect_eq(R"test(a = R"pb(key: ")proto")pb";)test",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97688: clang-format: use `pb` as a canonical raw string delimiter for google style

2021-03-04 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 328081.
krasimir added a comment.

Collect commits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97688/new/

https://reviews.llvm.org/D97688

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTestRawStrings.cpp


Index: clang/unittests/Format/FormatTestRawStrings.cpp
===
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -782,11 +782,16 @@
 }
 
 TEST_F(FormatTestRawStrings, UpdatesToCanonicalDelimiters) {
-  FormatStyle Style = getRawStringPbStyleWithColumns(25);
+  FormatStyle Style = getRawStringPbStyleWithColumns(35);
   Style.RawStringFormats[0].CanonicalDelimiter = "proto";
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO");
+
   expect_eq(R"test(a = R"proto(key: value)proto";)test",
 format(R"test(a = R"pb(key:value)pb";)test", Style));
 
+  expect_eq(R"test(PARSE_TEXT_PROTO(R"proto(key: value)proto");)test",
+format(R"test(PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
   // Don't update to canonical delimiter if it occurs as a raw string suffix in
   // the raw string content.
   expect_eq(R"test(a = R"pb(key: ")proto")pb";)test",
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1135,7 +1135,7 @@
   "ParseTestProto",
   "ParsePartialTestProto",
   },
-  /*CanonicalDelimiter=*/"",
+  /*CanonicalDelimiter=*/"pb",
   /*BasedOnStyle=*/"google",
   },
   };
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1651,7 +1651,7 @@
   StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
   StringRef NewDelimiter =
   getCanonicalRawStringDelimiter(Style, RawStringStyle.Language);
-  if (NewDelimiter.empty() || OldDelimiter.empty())
+  if (NewDelimiter.empty())
 NewDelimiter = OldDelimiter;
   // The text of a raw string is between the leading 'R"delimiter(' and the
   // trailing 'delimiter)"'.


Index: clang/unittests/Format/FormatTestRawStrings.cpp
===
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -782,11 +782,16 @@
 }
 
 TEST_F(FormatTestRawStrings, UpdatesToCanonicalDelimiters) {
-  FormatStyle Style = getRawStringPbStyleWithColumns(25);
+  FormatStyle Style = getRawStringPbStyleWithColumns(35);
   Style.RawStringFormats[0].CanonicalDelimiter = "proto";
+  Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO");
+
   expect_eq(R"test(a = R"proto(key: value)proto";)test",
 format(R"test(a = R"pb(key:value)pb";)test", Style));
 
+  expect_eq(R"test(PARSE_TEXT_PROTO(R"proto(key: value)proto");)test",
+format(R"test(PARSE_TEXT_PROTO(R"(key:value)");)test", Style));
+
   // Don't update to canonical delimiter if it occurs as a raw string suffix in
   // the raw string content.
   expect_eq(R"test(a = R"pb(key: ")proto")pb";)test",
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1135,7 +1135,7 @@
   "ParseTestProto",
   "ParsePartialTestProto",
   },
-  /*CanonicalDelimiter=*/"",
+  /*CanonicalDelimiter=*/"pb",
   /*BasedOnStyle=*/"google",
   },
   };
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1651,7 +1651,7 @@
   StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
   StringRef NewDelimiter =
   getCanonicalRawStringDelimiter(Style, RawStringStyle.Language);
-  if (NewDelimiter.empty() || OldDelimiter.empty())
+  if (NewDelimiter.empty())
 NewDelimiter = OldDelimiter;
   // The text of a raw string is between the leading 'R"delimiter(' and the
   // trailing 'delimiter)"'.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97901: [SystemZ] Test for infinity in testFPKind().

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:7229
+  case Builtin::BI__builtin_isfinite:
+Invert = true;
+LLVM_FALLTHROUGH;

jonpa wrote:
> What are these variants all about...?
> 
They were introduced in https://reviews.llvm.org/D24483


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97901/new/

https://reviews.llvm.org/D97901

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97548: [clangd] Introduce client state invalidation

2021-03-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d7b328198a7: [clangd] Introduce client state invalidation 
(authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D97548?vs=328067&id=328086#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97548/new/

https://reviews.llvm.org/D97548

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/semantic-tokens-refresh.test

Index: clang-tools-extra/clangd/test/semantic-tokens-refresh.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/semantic-tokens-refresh.test
@@ -0,0 +1,42 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"capabilities":{
+  "workspace":{"semanticTokens":{"refreshSupport":true}}
+}}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
+  "uri": "test:///foo.cpp",
+  "languageId": "cpp",
+  "text": "int x = 2;"
+}}}
+# Expect a request after initial preamble build.
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }
+---
+# Reply with success.
+{"jsonrpc":"2.0","id":0}
+---
+# Preamble stays the same, no refresh requests.
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{
+  "textDocument": {"uri":"test:///foo.cpp","version":2},
+  "contentChanges":[{"text":"int x = 2;\nint y = 3;"}]
+}}
+# CHECK-NOT:  "method": "workspace/semanticTokens/refresh"
+---
+# Preamble changes
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{
+  "textDocument": {"uri":"test:///foo.cpp","version":2},
+  "contentChanges":[{"text":"#define FOO"}]
+}}
+# Expect a request after initial preamble build.
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }
+---
+# Reply with error, to make sure there are no crashes.
+{"jsonrpc":"2.0","id":1,"error":{"code": 0, "message": "msg"}}
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
+
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -261,6 +261,7 @@
 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out, llvm::json::Path);
 
 struct NoParams {};
+inline llvm::json::Value toJSON(const NoParams &) { return nullptr; }
 inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
   return true;
 }
@@ -473,6 +474,10 @@
   /// This is a clangd extension.
   /// window.implicitWorkDoneProgressCreate
   bool ImplicitProgressCreation = false;
+
+  /// Whether the client implementation supports a refresh request sent from the
+  /// server to the client.
+  bool SemanticTokenRefreshSupport = false;
 };
 bool fromJSON(const llvm::json::Value &, ClientCapabilities &,
   llvm::json::Path);
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -403,6 +403,10 @@
 }
   }
 }
+if (auto *SemanticTokens = Workspace->getObject("semanticTokens")) {
+  if (auto RefreshSupport = SemanticTokens->getBoolean("refreshSupport"))
+R.SemanticTokenRefreshSupport = *RefreshSupport;
+}
   }
   if (auto *Window = O->getObject("window")) {
 if (auto WorkDoneProgress = Window->getBoolean("workDoneProgress"))
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -28,6 +28,7 @@
 #include "support/Cancellation.h"
 #include "support/Function.h"
 #include "support/MemoryTree.h"
+#include "support/Path.h"
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -74,6 +75,14 @@
 /// Not called concurrently.
 virtual void
 onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) {}
+
+/// Called when the meaning of a source code may have changed without an
+/// edit. Usually clients assume that responses to requests are valid until
+/// they next edit the file. If they're invalidated at other times, we
+/// should tell the client. In particular, when an asynchronous preamble
+/// build finishes, we can provide more accurate semantic tokens, so we
+/// should tell the client to refresh.
+vir

[clang-tools-extra] 1d7b328 - [clangd] Introduce client state invalidation

2021-03-04 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-03-04T11:15:10+01:00
New Revision: 1d7b328198a7dd1e26ffd76256a3427134d39951

URL: 
https://github.com/llvm/llvm-project/commit/1d7b328198a7dd1e26ffd76256a3427134d39951
DIFF: 
https://github.com/llvm/llvm-project/commit/1d7b328198a7dd1e26ffd76256a3427134d39951.diff

LOG: [clangd] Introduce client state invalidation

Clangd can invalidate client state of features like semantic higlighting
without client explicitly triggering, for example after a preamble build
caused by an onSave notification on a different file.

This patch introduces a mechanism to let client know of such actions,
and also calls the workspace/semanticTokens/refresh request to
demonstrate the situation after each preamble build.

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

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

Added: 
clang-tools-extra/clangd/test/semantic-tokens-refresh.test

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 0efc7124477a..ba263d123f1d 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -579,7 +579,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
 
   {
 LSPBinder Binder(Handlers, *this);
-bindMethods(Binder);
+bindMethods(Binder, Params.capabilities);
 if (Opts.Modules)
   for (auto &Mod : *Opts.Modules)
 Mod.initializeLSP(Binder, Params.rawCapabilities, ServerCaps);
@@ -1406,8 +1406,7 @@ void ClangdLSPServer::onAST(const ASTParams &Params,
   Server->getAST(Params.textDocument.uri.file(), Params.range, std::move(CB));
 }
 
-ClangdLSPServer::ClangdLSPServer(Transport &Transp,
- const ThreadsafeFS &TFS,
+ClangdLSPServer::ClangdLSPServer(Transport &Transp, const ThreadsafeFS &TFS,
  const ClangdLSPServer::Options &Opts)
 : ShouldProfile(/*Period=*/std::chrono::minutes(5),
 /*Delay=*/std::chrono::minutes(1)),
@@ -1427,7 +1426,8 @@ ClangdLSPServer::ClangdLSPServer(Transport &Transp,
   Bind.method("initialize", this, &ClangdLSPServer::onInitialize);
 }
 
-void ClangdLSPServer::bindMethods(LSPBinder &Bind) {
+void ClangdLSPServer::bindMethods(LSPBinder &Bind,
+  const ClientCapabilities &Caps) {
   // clang-format off
   Bind.notification("initialized", this, &ClangdLSPServer::onInitialized);
   Bind.method("shutdown", this, &ClangdLSPServer::onShutdown);
@@ -1481,6 +1481,8 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind) {
   BeginWorkDoneProgress = Bind.outgoingNotification("$/progress");
   ReportWorkDoneProgress = Bind.outgoingNotification("$/progress");
   EndWorkDoneProgress = Bind.outgoingNotification("$/progress");
+  if(Caps.SemanticTokenRefreshSupport)
+SemanticTokensRefresh = 
Bind.outgoingMethod("workspace/semanticTokens/refresh");
   // clang-format on
 }
 
@@ -1656,5 +1658,14 @@ void ClangdLSPServer::onFileUpdated(PathRef File, const 
TUStatus &Status) {
   NotifyFileStatus(Status.render(File));
 }
 
+void ClangdLSPServer::onSemanticsMaybeChanged(PathRef File) {
+  if (SemanticTokensRefresh) {
+SemanticTokensRefresh(NoParams{}, [](llvm::Expected E) {
+  if (E)
+return;
+  elog("Failed to refresh semantic tokens: {0}", E.takeError());
+});
+  }
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 4a6b4c41dc2f..01d0ec20f098 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -87,6 +87,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   std::vector Diagnostics) override;
   void onFileUpdated(PathRef File, const TUStatus &Status) override;
   void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) override;
+  void onSemanticsMaybeChanged(PathRef File) override;
 
   // LSP methods. Notifications have signature void(const Params&).
   // Calls have signature void(const Params&, Callback).
@@ -181,11 +182,12 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   ReportWorkDoneProgress;
   LSPBinder::OutgoingNotification>
   EndWorkDoneProgress;
+  LSPBinder::OutgoingMethod SemanticTokensRefresh;
 
   void applyEdit(WorkspaceEdit WE, llvm::json::Value Success,
  Callback Reply);
 
-  void bindMethods(LSPBinder &);
+  void bindMethods(LSPBinder &, const ClientCapabilities &Caps);
   std::vector getFixes(StringRef File, const 

[PATCH] D97927: [clang-format] Rename case sorting

2021-03-04 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: kentsommer, curdeius, MyDeveloperDay, 
PragmaNull.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As discussed in D95017  the names case 
sensitive and insensitive should be switched.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97927

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -599,9 +599,9 @@
 }
 
 TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) {
-  EXPECT_FALSE(FmtStyle.SortIncludes == FormatStyle::SI_CaseSensitive);
+  EXPECT_FALSE(FmtStyle.SortIncludes == FormatStyle::SI_CaseInsensitive);
 
-  FmtStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
+  FmtStyle.SortIncludes = FormatStyle::SI_CaseInsensitive;
 
   EXPECT_EQ("#include \"A/B.h\"\n"
 "#include \"A/b.h\"\n"
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16007,7 +16007,7 @@
 
   Style.SortIncludes = FormatStyle::SI_Never;
   CHECK_PARSE("SortIncludes: true", SortIncludes,
-  FormatStyle::SI_CaseInsensitive);
+  FormatStyle::SI_CaseSensitive);
   CHECK_PARSE("SortIncludes: false", SortIncludes, FormatStyle::SI_Never);
   CHECK_PARSE("SortIncludes: CaseInsensitive", SortIncludes,
   FormatStyle::SI_CaseInsensitive);
@@ -18131,7 +18131,7 @@
 "#include \"b.h\"\n")});
 
   format::FormatStyle Style = format::getLLVMStyle();
-  Style.SortIncludes = FormatStyle::SI_CaseInsensitive;
+  Style.SortIncludes = FormatStyle::SI_CaseSensitive;
   auto FormattedReplaces = formatReplacements(Code, Replaces, Style);
   EXPECT_TRUE(static_cast(FormattedReplaces))
   << llvm::toString(FormattedReplaces.takeError()) << "\n";
Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -404,7 +404,7 @@
 
   if (SortIncludes.getNumOccurrences() != 0) {
 if (SortIncludes)
-  FormatStyle->SortIncludes = FormatStyle::SI_CaseInsensitive;
+  FormatStyle->SortIncludes = FormatStyle::SI_CaseSensitive;
 else
   FormatStyle->SortIncludes = FormatStyle::SI_Never;
   }
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -423,7 +423,7 @@
 
 // For backward compatibility.
 IO.enumCase(Value, "false", FormatStyle::SI_Never);
-IO.enumCase(Value, "true", FormatStyle::SI_CaseInsensitive);
+IO.enumCase(Value, "true", FormatStyle::SI_CaseSensitive);
   }
 };
 
@@ -1047,7 +1047,7 @@
   LLVMStyle.PenaltyIndentedWhitespace = 0;
 
   LLVMStyle.DisableFormat = false;
-  LLVMStyle.SortIncludes = FormatStyle::SI_CaseInsensitive;
+  LLVMStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
   LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
   LLVMStyle.SortUsingDeclarations = true;
   LLVMStyle.StatementAttributeLikeMacros.push_back("Q_EMIT");
@@ -1250,7 +1250,7 @@
 "java",
 "javax",
 };
-ChromiumStyle.SortIncludes = FormatStyle::SI_CaseInsensitive;
+ChromiumStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
   } else if (Language == FormatStyle::LK_JavaScript) {
 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
 ChromiumStyle.AllowShortLoopsOnASingleLine = false;
@@ -2248,7 +2248,7 @@
 Indices.push_back(i);
   }
 
-  if (Style.SortIncludes == FormatStyle::SI_CaseSensitive) {
+  if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive) {
 llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
   const auto LHSFilenameLower = Includes[LHSI].Filename.lower();
   const auto RHSFilenameLower = Includes[RHSI].Filename.lower();
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2679,7 +2679,7 @@
 ///#include "B/a.h"
 /// \endcode
 SI_Never,
-/// Includes are sorted in an ASCIIbetical or case insensitive fashion.
+/// Includes are sorted in an ASCIIbetical or case sensitive fashion.
 /// \code

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-04 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc added a comment.

I agree with @richard.barton.arm that we could add `-std=` now, even if only 
for a subset of possible language standards. I expect that standard conformance 
checks would be quite pervasive, and it would be better to design the 
infrastructure for such checks earlier rather than try to retrofit them at a 
later stage when we have to start supporting f202x, etc.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96245: [clangd] Propagate CodeActions in addition to Fixes for diagnostics

2021-03-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D96245#2602293 , @sammccall wrote:

> Will the fixes/actions this enables really be available synchronously?

The fixes stay as is today, but the action might be just a command that needs 
to be invoked by the client (so it is still synchronous, in a sense, but 
instead of an edit embedder just initiates another action on the clangdserver, 
which will synchronously do "something")

> AFAIK the only reasons we attach fixes to diagnostics are:
>
> - because clang fixes are generated at parse time and need to be stored 
> somewhere
> - for the benefit of embedders that need the fix content synchronously with 
> the diagnostic
> - to trigger the "fix available" text
>
> The first two points don't apply if the fix content is too slow to compute 
> synchronously. (And the third can be more simply solved with a boolean flag 
> instead)
> The alternative is just to discover these fixes through the code action flow 
> (and allow modules to contribute code actions, which we should do anyway)

Agreed, I was going this way because currently there was no way to provide a 
code action to clangd::diagnostic apart from storing it in the fixes map while 
generating it. I suppose it is more sensible to just go with a new hook on 
modules that can provide a codeaction given a clangd::diagnostic. (and when the 
diagnostic is seen, the module can just set a boolean flag or increment some 
fix counter as you suggested).

Does `std::vector contributeActions(const CodeActionParams&);` look 
like a good signature for the module hook?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96245/new/

https://reviews.llvm.org/D96245

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88905: [Clang] Allow "ext_vector_type" applied to Booleans

2021-03-04 Thread Simon Moll via Phabricator via cfe-commits
simoll added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88905/new/

https://reviews.llvm.org/D88905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-03-04 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 328100.
bader marked 4 inline comments as done.
bader added a comment.

Apply suggestions from Aaron.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89909/new/

https://reviews.llvm.org/D89909

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenSYCL/address-space-cond-op.cpp
  clang/test/CodeGenSYCL/address-space-of-returns.cpp
  clang/test/CodeGenSYCL/address-space-parameter-conversions.cpp
  clang/test/CodeGenSYCL/address-spaces-struct.cpp
  clang/test/CodeGenSYCL/address-spaces.cpp
  clang/test/SemaSYCL/address-space-parameter-conversions.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -247,6 +247,8 @@
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case SYCLDevice:
+return "sycldevice";
   case Simulator: return "simulator";
   }
 
@@ -554,6 +556,7 @@
   .StartsWith("itanium", Triple::Itanium)
   .StartsWith("cygnus", Triple::Cygnus)
   .StartsWith("coreclr", Triple::CoreCLR)
+  .StartsWith("sycldevice", Triple::SYCLDevice)
   .StartsWith("simulator", Triple::Simulator)
   .StartsWith("macabi", Triple::MacABI)
   .Default(Triple::UnknownEnvironment);
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -222,8 +222,9 @@
 Itanium,
 Cygnus,
 CoreCLR,
+SYCLDevice,
 Simulator, // Simulator variants of other systems, e.g., Apple's iOS
-MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
+MacABI,// Mac Catalyst variant of Apple's iOS deployment target.
 LastEnvironmentType = MacABI
   };
   enum ObjectFormatType {
@@ -497,6 +498,10 @@
isMacCatalystEnvironment()));
   }
 
+  bool isSYCLDeviceEnvironment() const {
+return getEnvironment() == Triple::SYCLDevice;
+  }
+
   bool isOSNetBSD() const {
 return getOS() == Triple::NetBSD;
   }
Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388593)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x71>();
+  correct<0x7FFFED>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/SemaSYCL/address-space-parameter-conversions.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/address-space-parameter-conversions.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fsycl -fsycl-is-device -verify -fsyntax-only -x c++ %s
+
+void bar(int &Data) {}
+void bar2(int &Data) {}
+void bar(__attribute__((opencl_private)) int &Data) {}
+void foo(int *Data) {}
+void foo2(int *Data) {}
+void foo(__attribute__((opencl_private)) int *Data) {}
+
+template 
+void tmpl(T *t) {}
+
+void usages() {
+  __attribute__((opencl_global)) int *GLOB;
+  __attribute__((opencl_private)) int *PRIV;
+  __attribute__((opencl_local)) int *LOC;
+  int *NoAS;
+
+  bar(*GLOB);
+  bar2(*GLOB);
+
+  bar(*PRIV);
+  bar2(*PRIV);
+
+  bar(*NoAS);
+  bar2(*NoAS);
+
+  bar(*LOC);
+  bar2(*LOC);
+
+  foo(GLOB);
+  foo2(GLOB);
+  foo(PRIV);
+  foo2(PRIV);
+  foo(NoAS);
+  foo2(NoAS);
+  foo(LOC);
+  foo2(LOC);
+
+  tmpl(GLOB);
+  tmpl(PRIV);
+  tmpl(NoAS);
+  tmpl(LOC);
+
+  (void)static_cast(GLOB);
+  (void)static_cast(GLOB);
+  // FIXME: determine if we can warn on the below conversions.
+  int 

[PATCH] D97869: [OpenCL][Draft] Add OpenCL builtin test generator

2021-03-04 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

> ``
>
>   float test6092_cos(float arg1) {
> return cos(arg1);
>   }
>   double test6093_cos(double arg1) {
> return cos(arg1);
>   }
>   half test6094_cos(half arg1) {
> return cos(arg1);
>   }
>   float2 test6095_cos(float2 arg1) {
> return cos(arg1);
>   }
>   double2 test6096_cos(double2 arg1) {
> return cos(arg1);
>   }
>   ``

I was just thinking if we could combine the calls into one function to minimize 
the number of lines to parse? Perhaps this will make the Tablegen generator too 
complex?

Also would it be possible to handle optional functionality - extensions and 
functions available in certain versions?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97869/new/

https://reviews.llvm.org/D97869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-03-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 328105.
ASDenysPetrov added a comment.

Rebased on main.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96090/new/

https://reviews.llvm.org/D96090

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp

Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -394,48 +394,6 @@
   return UnknownVal();
 }
 
-static bool hasSameUnqualifiedPointeeType(QualType ty1, QualType ty2) {
-  return ty1->getPointeeType().getCanonicalType().getTypePtr() ==
- ty2->getPointeeType().getCanonicalType().getTypePtr();
-}
-
-/// CastRetrievedVal - Used by subclasses of StoreManager to implement
-///  implicit casts that arise from loads from regions that are reinterpreted
-///  as another region.
-SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
-return V;
-
-  // The dispatchCast() call below would convert the int into a float.
-  // What we want, however, is a bit-by-bit reinterpretation of the int
-  // as a float, which usually yields nothing garbage. For now skip casts
-  // from ints to floats.
-  // TODO: What other combinations of types are affected?
-  if (castTy->isFloatingType()) {
-SymbolRef Sym = V.getAsSymbol();
-if (Sym && !Sym->getType()->isFloatingType())
-  return UnknownVal();
-  }
-
-  // When retrieving symbolic pointer and expecting a non-void pointer,
-  // wrap them into element regions of the expected type if necessary.
-  // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
-  // make sure that the retrieved value makes sense, because there's no other
-  // cast in the AST that would tell us to cast it to the correct pointer type.
-  // We might need to do that for non-void pointers as well.
-  // FIXME: We really need a single good function to perform casts for us
-  // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
-if (const auto *SR = dyn_cast_or_null(V.getAsRegion())) {
-  QualType sr = SR->getSymbol()->getType();
-  if (!hasSameUnqualifiedPointeeType(sr, castTy))
-  return loc::MemRegionVal(castRegion(SR, castTy));
-}
-
-  return svalBuilder.dispatchCast(V, castTy);
-}
-
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {
   if (Base.isUnknownOrUndef())
 return Base;
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -65,12 +65,12 @@
 // Transfer function for Casts.
 //===--===//
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::dispatchCast(SVal Val, QualType CastTy) {
-  assert(Val.getAs() || Val.getAs());
-  return Val.getAs() ? evalCastFromLoc(Val.castAs(), CastTy)
-   : evalCastFromNonLoc(Val.castAs(), CastTy);
+  return evalCast(Val, CastTy);
 }
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
   bool isLocType = Loc::isLocType(castTy);
   if (val.getAs())
@@ -127,6 +127,7 @@
 return makeIntVal(i);
 }
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::evalCastFromLoc(Loc val, QualType castTy) {
 
   // Casts from pointers -> pointers, just return the lval.
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -536,22 +536,33 @@
 // `evalCastKind` and `evalCastSubKind` are helpers
 //===--===//
 
-SVal SValBuilder::evalCast(SVal V, QualType CastTy, QualType OriginalTy) {
-  CastTy = Context.getCanonicalType(CastTy);
-  OriginalTy = Context.getCanonicalType(OriginalTy);
-  if (CastTy == OriginalTy)
+// In case when `OriginalTy.isNull() == true` we cast `V` less accurately.
+SVal SValBuilder::evalCast(SVal V, QualType CastTy,
+   QualType OriginalTy /*= QualType{}*/) {
+  if (CastTy.isNull())
 return V;
 
-  // FIXME: Move this check to the most appropriate evalCastKind/evalCastSubKind
-  // function.
-  // For const 

[PATCH] D97277: [analyzer] Eliminate dispatchCast, evalCastFromNonLoc and evalCastFromLoc functions from SValBuilder

2021-03-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 328106.
ASDenysPetrov added a comment.

Rebased on main.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97277/new/

https://reviews.llvm.org/D97277

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -22,11 +22,6 @@
 
 namespace {
 class SimpleSValBuilder : public SValBuilder {
-protected:
-  SVal dispatchCast(SVal val, QualType castTy) override;
-  SVal evalCastFromNonLoc(NonLoc val, QualType castTy) override;
-  SVal evalCastFromLoc(Loc val, QualType castTy) override;
-
 public:
   SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
 ProgramStateManager &stateMgr)
@@ -61,134 +56,6 @@
   return new SimpleSValBuilder(alloc, context, stateMgr);
 }
 
-//===--===//
-// Transfer function for Casts.
-//===--===//
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::dispatchCast(SVal Val, QualType CastTy) {
-  return evalCast(Val, CastTy);
-}
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-  bool isLocType = Loc::isLocType(castTy);
-  if (val.getAs())
-return val;
-
-  if (Optional LI = val.getAs()) {
-if (isLocType)
-  return LI->getLoc();
-// FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getIntWidth(castTy);
-if (castSize == LI->getNumBits())
-  return val;
-return makeLocAsInteger(LI->getLoc(), castSize);
-  }
-
-  if (SymbolRef se = val.getAsSymbol()) {
-QualType T = Context.getCanonicalType(se->getType());
-// If types are the same or both are integers, ignore the cast.
-// FIXME: Remove this hack when we support symbolic truncation/extension.
-// HACK: If both castTy and T are integers, ignore the cast.  This is
-// not a permanent solution.  Eventually we want to precisely handle
-// extension/truncation of symbolic integers.  This prevents us from losing
-// precision when we assign 'x = y' and 'y' is symbolic and x and y are
-// different integer types.
-   if (haveSameType(T, castTy))
-  return val;
-
-if (!isLocType)
-  return makeNonLoc(se, T, castTy);
-return UnknownVal();
-  }
-
-  // If value is a non-integer constant, produce unknown.
-  if (!val.getAs())
-return UnknownVal();
-
-  // Handle casts to a boolean type.
-  if (castTy->isBooleanType()) {
-bool b = val.castAs().getValue().getBoolValue();
-return makeTruthVal(b, castTy);
-  }
-
-  // Only handle casts from integers to integers - if val is an integer constant
-  // being cast to a non-integer type, produce unknown.
-  if (!isLocType && !castTy->isIntegralOrEnumerationType())
-return UnknownVal();
-
-  llvm::APSInt i = val.castAs().getValue();
-  BasicVals.getAPSIntType(castTy).apply(i);
-
-  if (isLocType)
-return makeIntLocVal(i);
-  else
-return makeIntVal(i);
-}
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::evalCastFromLoc(Loc val, QualType castTy) {
-
-  // Casts from pointers -> pointers, just return the lval.
-  //
-  // Casts from pointers -> references, just return the lval.  These
-  //   can be introduced by the frontend for corner cases, e.g
-  //   casting from va_list* to __builtin_va_list&.
-  //
-  if (Loc::isLocType(castTy) || castTy->isReferenceType())
-return val;
-
-  // FIXME: Handle transparent unions where a value can be "transparently"
-  //  lifted into a union type.
-  if (castTy->isUnionType())
-return UnknownVal();
-
-  // Casting a Loc to a bool will almost always be true,
-  // unless this is a weak function or a symbolic region.
-  if (castTy->isBooleanType()) {
-switch (val.getSubKind()) {
-  case loc::MemRegionValKind: {
-const MemRegion *R = val.castAs().getRegion();
-if (const FunctionCodeRegion *FTR = dyn_cast(R))
-  if (const FunctionDecl *FD = dyn_cast(FTR->getDecl()))
-if (FD->isWeak())
-  // FIXME: Currently we are using an extent symbol here,
-  // because there are no generic region address metadata
-  // symbols to use, only content metadata.
-  return nonloc::SymbolVal(SymMgr.getExtentSymbol(FTR));
-
-if (const SymbolicRegion *SymR = R->getSymbolicBase())
-  return makeNonLoc(SymR->getSymbol(), BO_NE,
-BasicVals.getZeroWithPtrWi

[PATCH] D97296: [analyzer] Add a new parameter ProgramStateRef to SValBuilder::evalCast function

2021-03-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 328107.
ASDenysPetrov added a comment.

Rebased on main.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97296/new/

https://reviews.llvm.org/D97296

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp

Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -43,7 +43,7 @@
 : svalBuilder(stateMgr.getSValBuilder()), StateMgr(stateMgr),
   MRMgr(svalBuilder.getRegionManager()), Ctx(stateMgr.getContext()) {}
 
-StoreRef StoreManager::enterStackFrame(Store OldStore,
+StoreRef StoreManager::enterStackFrame(ProgramStateRef State, Store OldStore,
const CallEvent &Call,
const StackFrameContext *LCtx) {
   StoreRef Store = StoreRef(OldStore, *this);
@@ -52,7 +52,7 @@
   Call.getInitialStackFrameContents(LCtx, InitialBindings);
 
   for (const auto &I : InitialBindings)
-Store = Bind(Store.getStore(), I.first.castAs(), I.second);
+Store = Bind(State, Store.getStore(), I.first.castAs(), I.second);
 
   return Store;
 }
@@ -439,8 +439,8 @@
   return getLValueFieldOrIvar(decl, base);
 }
 
-SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
-SVal Base) {
+SVal StoreManager::getLValueElement(ProgramStateRef State, QualType elementType,
+NonLoc Offset, SVal Base) {
   // If the base is an unknown or undefined value, just return it back.
   // FIXME: For absolute pointer addresses, we just return that value back as
   //  well, although in reality we should return the offset added to that
@@ -458,7 +458,7 @@
   const auto *ElemR = dyn_cast(BaseRegion);
 
   // Convert the offset to the appropriate size and signedness.
-  Offset = svalBuilder.convertToArrayIndex(Offset).castAs();
+  Offset = svalBuilder.convertToArrayIndex(State, Offset).castAs();
 
   if (!ElemR) {
 // If the base region is not an ElementRegion, create one.
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -45,8 +45,9 @@
   /// with their known values (in the sense of the getKnownValue() method).
   SVal simplifySVal(ProgramStateRef State, SVal V) override;
 
-  SVal MakeSymIntVal(const SymExpr *LHS, BinaryOperator::Opcode op,
- const llvm::APSInt &RHS, QualType resultTy);
+  SVal MakeSymIntVal(ProgramStateRef State, const SymExpr *LHS,
+ BinaryOperator::Opcode op, const llvm::APSInt &RHS,
+ QualType resultTy);
 };
 } // end anonymous namespace
 
@@ -82,10 +83,10 @@
 // Transfer function for binary operators.
 //===--===//
 
-SVal SimpleSValBuilder::MakeSymIntVal(const SymExpr *LHS,
-BinaryOperator::Opcode op,
-const llvm::APSInt &RHS,
-QualType resultTy) {
+SVal SimpleSValBuilder::MakeSymIntVal(ProgramStateRef State, const SymExpr *LHS,
+  BinaryOperator::Opcode op,
+  const llvm::APSInt &RHS,
+  QualType resultTy) {
   bool isIdempotent = false;
 
   // Check for a few special cases with known reductions first.
@@ -147,7 +148,7 @@
   // Wrap the LHS up in a NonLoc again and let evalCast do the
   // dirty work.
   if (isIde

[PATCH] D97388: [analyzer] Replace StoreManager::evalIntegralCast with SValBuilder::evalCast

2021-03-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 328108.
ASDenysPetrov added a comment.

Rebased on main.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97388/new/

https://reviews.llvm.org/D97388

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -493,44 +493,6 @@
   return true;
 }
 
-// Handles casts of type CK_IntegralCast.
-// At the moment, this function will redirect to evalCast, except when the range
-// of the original value is known to be greater than the max of the target type.
-SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val,
-   QualType castTy, QualType originalTy) {
-  // No truncations if target type is big enough.
-  if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy))
-return evalCast(state, val, castTy, originalTy);
-
-  SymbolRef se = val.getAsSymbol();
-  if (!se) // Let evalCast handle non symbolic expressions.
-return evalCast(state, val, castTy, originalTy);
-
-  // Find the maximum value of the target type.
-  APSIntType ToType(getContext().getTypeSize(castTy),
-castTy->isUnsignedIntegerType());
-  llvm::APSInt ToTypeMax = ToType.getMaxValue();
-  NonLoc ToTypeMaxVal =
-  makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
-: ToTypeMax.getSExtValue(),
- castTy)
-  .castAs();
-  // Check the range of the symbol being casted against the maximum value of the
-  // target type.
-  NonLoc FromVal = val.castAs();
-  QualType CmpTy = getConditionType();
-  NonLoc CompVal =
-  evalBinOpNN(state, BO_LE, FromVal, ToTypeMaxVal, CmpTy).castAs();
-  ProgramStateRef IsNotTruncated, IsTruncated;
-  std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
-  if (!IsNotTruncated && IsTruncated) {
-// Symbol is truncated so we evaluate it as a cast.
-NonLoc CastVal = makeNonLoc(se, originalTy, castTy);
-return CastVal;
-  }
-  return evalCast(state, val, castTy, originalTy);
-}
-
 //===--===//
 // Cast methods.
 // `evalCast` is the main method
@@ -917,6 +879,37 @@
   return makeNonLoc(SE, BO_NE, BVF.getValue(0, SE->getType()), CastTy);
 }
   } else {
+// Symbol to integer.
+if (!OriginalTy.isNull() && CastTy->isIntegralOrEnumerationType()) {
+  // Symbolic integer to integer.
+  if (OriginalTy->isIntegralOrEnumerationType()) {
+// Truncation.
+if (getContext().getTypeSize(CastTy) <
+getContext().getTypeSize(OriginalTy)) {
+  // Find the maximum value of the target type.
+  llvm::APSInt ToTypeMax =
+  llvm::APSInt::getMaxValue(getContext().getTypeSize(CastTy),
+CastTy->isUnsignedIntegerType());
+  NonLoc ToTypeMaxVal =
+  makeIntVal(ToTypeMax.getExtValue(), CastTy).castAs();
+  // Check the range of the symbol being casted against the maximum
+  // value of the target type.
+  NonLoc FromVal = V.castAs();
+  QualType CmpTy = getConditionType();
+  NonLoc CompVal =
+  evalBinOpNN(State, BO_LE, FromVal, ToTypeMaxVal, CmpTy)
+  .castAs();
+  ProgramStateRef IsNotTruncated, IsTruncated;
+  std::tie(IsNotTruncated, IsTruncated) = State->assume(CompVal);
+  if (!IsNotTruncated && IsTruncated) {
+// Symbol is truncated so we evaluate it as a cast.
+NonLoc CastVal = makeNonLoc(SE, OriginalTy, CastTy);
+return CastVal;
+  }
+}
+  }
+}
+
 // Symbol to integer, float.
 QualType T = Context.getCanonicalType(SE->getType());
 // If types are the same or both are integers, ignore the cast.
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -431,7 +431,7 @@
   case CK_IntegralCast: {
 // Delegate to SValBuilder to process.
 SVal V = state->getSVal(Ex, LCtx);
-V = svalBuilder.evalIntegralCast(state, V, T, ExTy);
+V = svalBuilder.evalCast(state, V, T, ExTy);
 state = state->BindExpr(CastE, LCtx, V);
 Bldr.generateNode(CastE, Pred, state);
 continue;
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ clang/include/

[PATCH] D97874: [analyzer] Improve SVal cast from integer to bool using known RangeSet

2021-03-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 328109.
ASDenysPetrov added a comment.

Rebased on main.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97874/new/

https://reviews.llvm.org/D97874

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/cast_symbolic_ints_to_bool.cpp

Index: clang/test/Analysis/cast_symbolic_ints_to_bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/cast_symbolic_ints_to_bool.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+template 
+void clang_analyzer_dump(T);
+
+void test_int_to_bool(bool b, int x) {
+  clang_analyzer_dump(b); // expected-warning{{reg_$0<_Bool b>}}
+  b = x;
+  clang_analyzer_dump(b); // expected-warning{{reg_$1}}
+  if (x < 0) {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  } else if (x > 0) {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  } else {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{0 U1b}}
+  }
+}
+
+void test_char_to_bool(char x) {
+  bool b = x;
+  clang_analyzer_dump(b); // expected-warning{{reg_$0}}
+  if (x < 0) {
+bool b = x;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  } else if (x > 0) {
+bool b = x;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  } else {
+bool b = x;
+clang_analyzer_dump(b); // expected-warning{{0 U1b}}
+  }
+}
+
+void test_unsigned_to_bool(bool b, unsigned x) {
+  clang_analyzer_dump(b); // expected-warning{{reg_$0<_Bool b>}}
+  b = x;
+  clang_analyzer_dump(b); // expected-warning{{reg_$1}}
+  if (x) {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  } else {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{0 U1b}}
+  }
+}
+
+void test_unsigned_to_bool(unsigned char x) {
+  bool b = x;
+  clang_analyzer_dump(b); // expected-warning{{reg_$0}}
+  if (x < 42) {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{reg_$0}}
+if (x) {
+  b = x;
+  clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+} else {
+  b = x;
+  clang_analyzer_dump(b); // expected-warning{{0 U1b}}
+}
+  } else {
+b = x;
+clang_analyzer_dump(b); // expected-warning{{1 U1b}}
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -872,11 +872,18 @@
   // Symbol to bool.
   if (!OriginalTy.isNull() && CastTy->isBooleanType()) {
 // Non-float to bool.
-if (Loc::isLocType(OriginalTy) ||
-OriginalTy->isIntegralOrEnumerationType() ||
-OriginalTy->isMemberPointerType()) {
+if (OriginalTy->isIntegralOrEnumerationType()) {
   BasicValueFactory &BVF = getBasicValueFactory();
-  return makeNonLoc(SE, BO_NE, BVF.getValue(0, SE->getType()), CastTy);
+  const llvm::APSInt &Zero = BVF.getValue(0, OriginalTy);
+  bool IsZero, IsNotZero;
+  std::tie(IsZero, IsNotZero) =
+  getStateManager().getConstraintManager().isSymValWithinOrOutsideRange(
+  State, SE, Zero, Zero);
+  // Symbolic pointer, integer to bool.
+  if (IsZero || IsNotZero)
+return makeTruthVal(IsNotZero, CastTy);
+  // Symbolic integer to bool.
+  return V;
 }
   } else {
 // Symbol to integer.
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1278,6 +1278,9 @@
 
   const llvm::APSInt *getSymVal(ProgramStateRef State,
 SymbolRef Sym) const override;
+  std::pair
+  isSymValWithinOrOutsideRange(ProgramStateRef State, SymbolRef Sym,
+   llvm::APSInt lower, llvm::APSInt upper) override;
 
   ProgramStateRef removeDeadBindings(ProgramStateRef State,
  SymbolReaper &SymReaper) override;
@@ -1875,6 +1878,15 @@
   return T ? T->getConcreteValue() : nullptr;
 }
 
+std::pair RangeConstraintManager::isSymValWithinOrOutsideRange(
+ProgramStateRef St, SymbolRef Sym, llvm::APSInt lower, llvm::APSInt upper) {
+  if (const RangeSet *T = getConstraint(St, Sym)) {
+RangeSet RS = T->Intersect(getBasicVals(), F, lower, upper);
+return {RS == *T, RS.isEmpty()};
+  }
+  return {false, false};
+}
+
 //===--===//
 //Remove dead symbols from existing constraints
 //===--===//
Index: clang/include/clang/StaticAnalyzer/Co

[PATCH] D97834: [WebAssembly] Disable uses of __clang_call_terminate

2021-03-04 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 328116.
aheejin added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97834/new/

https://reviews.llvm.org/D97834

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp
  llvm/lib/CodeGen/WasmEHPrepare.cpp
  llvm/lib/Target/WebAssembly/CMakeLists.txt
  llvm/lib/Target/WebAssembly/WebAssembly.h
  llvm/lib/Target/WebAssembly/WebAssemblyHandleEHTerminatePads.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
  llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.ll
  llvm/test/CodeGen/WebAssembly/eh-lsda.ll
  llvm/test/CodeGen/WebAssembly/exception.ll
  llvm/test/CodeGen/WebAssembly/wasmehprepare.ll

Index: llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
===
--- llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
+++ llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
@@ -132,59 +132,6 @@
   ret void
 }
 
-; A cleanuppad with a call to __clang_call_terminate().
-;
-; void foo();
-; void test2() {
-;   try {
-; foo();
-;   } catch (...) {
-; foo();
-;   }
-; }
-define void @test2() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
-; CHECK-LABEL: @test2
-entry:
-  invoke void @foo()
-  to label %try.cont unwind label %catch.dispatch
-
-catch.dispatch:   ; preds = %entry
-  %0 = catchswitch within none [label %catch.start] unwind to caller
-
-catch.start:  ; preds = %catch.dispatch
-  %1 = catchpad within %0 [i8* null]
-  %2 = call i8* @llvm.wasm.get.exception(token %1)
-  %3 = call i32 @llvm.wasm.get.ehselector(token %1)
-  %4 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
-  invoke void @foo() [ "funclet"(token %1) ]
-  to label %invoke.cont1 unwind label %ehcleanup
-
-invoke.cont1: ; preds = %catch.start
-  call void @__cxa_end_catch() [ "funclet"(token %1) ]
-  catchret from %1 to label %try.cont
-
-try.cont: ; preds = %entry, %invoke.cont1
-  ret void
-
-ehcleanup:; preds = %catch.start
-  %5 = cleanuppad within %1 []
-  invoke void @__cxa_end_catch() [ "funclet"(token %5) ]
-  to label %invoke.cont2 unwind label %terminate
-
-invoke.cont2: ; preds = %ehcleanup
-  cleanupret from %5 unwind to caller
-
-terminate:; preds = %ehcleanup
-  %6 = cleanuppad within %5 []
-  %7 = call i8* @llvm.wasm.get.exception(token %6)
-  call void @__clang_call_terminate(i8* %7) [ "funclet"(token %6) ]
-  unreachable
-; CHECK: terminate:
-; CHECK-NEXT: cleanuppad
-; CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.catch
-; CHECK-NEXT:   call void @__clang_call_terminate(i8* %[[EXN]])
-}
-
 ; PHI demotion test. Only the phi before catchswitch should be demoted; the phi
 ; before cleanuppad should NOT.
 ;
@@ -194,7 +141,7 @@
 ;   ~Temp() {}
 ; };
 ;
-; void test3() {
+; void test2() {
 ;   int num;
 ;   try {
 ; Temp t;
@@ -214,8 +161,8 @@
 ; bar(num);
 ;   }
 ; }
-define void @test3() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
-; CHECK-LABEL: @test3
+define void @test2() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
+; CHECK-LABEL: @test2
 entry:
   %t = alloca %struct.Temp, align 1
   invoke void @foo()
@@ -279,8 +226,8 @@
 ; Tests if instructions after a call to @llvm.wasm.throw are deleted and the
 ; BB's dead children are deleted.
 
-; CHECK-LABEL: @test4
-define i32 @test4(i1 %b, i8* %p) {
+; CHECK-LABEL: @test3
+define i32 @test3(i1 %b, i8* %p) {
 entry:
   br i1 %b, label %bb.true, label %bb.false
 
@@ -308,14 +255,22 @@
 declare void @bar(i32)
 declare %struct.Temp* @_ZN4TempD2Ev(%struct.Temp* returned)
 declare i32 @__gxx_wasm_personality_v0(...)
-declare i8* @llvm.wasm.get.exception(token)
-declare i32 @llvm.wasm.get.ehselector(token)
-declare i32 @llvm.eh.typeid.for(i8*)
-declare void @llvm.wasm.throw(i32, i8*)
-declare void @llvm.wasm.rethrow()
+; Function Attrs: nounwind
+declare i8* @llvm.wasm.get.exception(token) #0
+; Function Attrs: nounwind
+declare i32 @llvm.wasm.get.ehselector(token) #0
+; Function Attrs: nounwind
+declare i32 @llvm.eh.typeid.for(i8*) #0
+; Function Attrs: noreturn
+declare void @llvm.wasm.throw(i32, i8*) #1
+; Function Attrs: noreturn
+declare void @llvm.wasm.rethrow() #1
 declare i8* @__cxa_begin_catch(i8*)
 declare void @__cxa_end_catch()
-declare void @__clang_call_terminate(i8*)
+declare void @_ZSt9terminatev()
+
+attributes #0 = { nounwind }
+attributes #1 = { noreturn }
 
 ; CHECK-DAG: declare void @llvm.wasm.landingpad.index(token, i32 immarg)
 ; CHECK-D

[PATCH] D97901: [SystemZ] Test for infinity in testFPKind().

2021-03-04 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:7229
+  case Builtin::BI__builtin_isfinite:
+Invert = true;
+LLVM_FALLTHROUGH;

thopre wrote:
> jonpa wrote:
> > What are these variants all about...?
> > 
> They were introduced in https://reviews.llvm.org/D24483
This "invert" logic doesn't look correct.   "isfinite" and "isinf" **both** 
need to return false on NaNs.  I think you should just drop the invert logic 
and use a TDC mask of 0xFC0 (zero, normal, or subnormal) to implement 
"isfinite".


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97901/new/

https://reviews.llvm.org/D97901

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97930: [OpenCL] Fix builtins that require multiple extensions

2021-03-04 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
svenvh added a project: clang.
Herald added a subscriber: yaxunl.
svenvh requested review of this revision.
Herald added a subscriber: cfe-commits.

Builtins that require multiple extensions, such as certain
`write_imagef` forms, were not exposed because of the Sema check not
splitting the extension string.

This was found using the prototype of D97869 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97930

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -17,6 +17,10 @@
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 #endif
 
+#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2
+#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
+#endif
+
 // First, test that Clang gracefully handles missing types.
 #ifdef NO_HEADER
 void test_without_header() {
@@ -169,13 +173,18 @@
 }
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
-kernel void basic_image_writeonly(write_only image1d_buffer_t 
image_write_only_image1d_buffer) {
+kernel void basic_image_writeonly(write_only image1d_buffer_t 
image_write_only_image1d_buffer, write_only image3d_t image3dwo) {
   half4 h4;
   float4 f4;
   int i;
 
   write_imagef(image_write_only_image1d_buffer, i, f4);
   write_imageh(image_write_only_image1d_buffer, i, h4);
+
+#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200
+  int4 i4;
+  write_imagef(image3dwo, i4, i, f4);
+#endif
 }
 
 kernel void basic_subgroup(global uint *out) {
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -815,9 +815,20 @@
 // Ignore this builtin function if it carries an extension macro that is
 // not defined. This indicates that the extension is not supported by the
 // target, so the builtin function should not be available.
-StringRef Ext = FunctionExtensionTable[OpenCLBuiltin.Extension];
-if (!Ext.empty() && !S.getPreprocessor().isMacroDefined(Ext))
-  continue;
+StringRef Extensions = FunctionExtensionTable[OpenCLBuiltin.Extension];
+if (!Extensions.empty()) {
+  SmallVector ExtVec;
+  Extensions.split(ExtVec, " ");
+  bool AllExtensionsDefined = true;
+  for (StringRef Ext : ExtVec) {
+if (!S.getPreprocessor().isMacroDefined(Ext)) {
+  AllExtensionsDefined = false;
+  break;
+}
+  }
+  if (!AllExtensionsDefined)
+continue;
+}
 
 SmallVector RetTypes;
 SmallVector, 5> ArgTypes;


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -17,6 +17,10 @@
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 #endif
 
+#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2
+#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
+#endif
+
 // First, test that Clang gracefully handles missing types.
 #ifdef NO_HEADER
 void test_without_header() {
@@ -169,13 +173,18 @@
 }
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
-kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_image1d_buffer) {
+kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_image1d_buffer, write_only image3d_t image3dwo) {
   half4 h4;
   float4 f4;
   int i;
 
   write_imagef(image_write_only_image1d_buffer, i, f4);
   write_imageh(image_write_only_image1d_buffer, i, h4);
+
+#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200
+  int4 i4;
+  write_imagef(image3dwo, i4, i, f4);
+#endif
 }
 
 kernel void basic_subgroup(global uint *out) {
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -815,9 +815,20 @@
 // Ignore this builtin function if it carries an extension macro that is
 // not defined. This indicates that the extension is not supported by the
 // target, so the builtin function should not be available.
-StringRef Ext = FunctionExtensionTable[OpenCLBuiltin.Extension];
-if (!Ext.empty() && !S.getPreprocessor().isMacroDefined(Ext))
-  continue;
+StringRef Extensions = FunctionExtensionTable[OpenCLBuiltin.Extension];
+if (!Extensions.empty()) {
+  SmallVector ExtVec;
+  Extensions.split(ExtVec, " ");
+  bool AllExtensionsDefined = true;
+  for (StringRef Ext : ExtVec) {
+if (!S.getPreprocessor().isMacroDefined(Ext)) {
+  AllExtensionsDefined = false;
+  break;
+}
+  

[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-03-04 Thread Karl-Johan Karlsson via Phabricator via cfe-commits
Ka-Ka added a comment.

This patch seems to introduce warnings for the case

#include 
#include 
void foo(void* ptr)
{

  free((void*)(intptr_t) ptr);

}

something that gcc don't warn for (see https://godbolt.org/z/1WT9c6 ).

As intptr_t is suppose to be used to pass pointers in I think its a bit strange 
that clang warns in this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94640/new/

https://reviews.llvm.org/D94640

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97901: [SystemZ] Test for infinity in testFPKind().

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:7229
+  case Builtin::BI__builtin_isfinite:
+Invert = true;
+LLVM_FALLTHROUGH;

uweigand wrote:
> thopre wrote:
> > jonpa wrote:
> > > What are these variants all about...?
> > > 
> > They were introduced in https://reviews.llvm.org/D24483
> This "invert" logic doesn't look correct.   "isfinite" and "isinf" **both** 
> need to return false on NaNs.  I think you should just drop the invert logic 
> and use a TDC mask of 0xFC0 (zero, normal, or subnormal) to implement 
> "isfinite".
My bad, I made the same mistake in https://reviews.llvm.org/D97125. I'll revert 
for now and will notify this review once I've got it fixed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97901/new/

https://reviews.llvm.org/D97901

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-03-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! I think we can resolve the question of which way to ignore implicit nodes 
and make any necessary changes post-commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97512/new/

https://reviews.llvm.org/D97512

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b7aeece - Revert "Stop traping on sNaN in __builtin_isinf"

2021-03-04 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2021-03-04T12:07:35Z
New Revision: b7aeece47ce58fc44d699979f1ce80ab42837fd6

URL: 
https://github.com/llvm/llvm-project/commit/b7aeece47ce58fc44d699979f1ce80ab42837fd6
DIFF: 
https://github.com/llvm/llvm-project/commit/b7aeece47ce58fc44d699979f1ce80ab42837fd6.diff

LOG: Revert "Stop traping on sNaN in __builtin_isinf"

This reverts commit 1b6eb56aa0ea2931866455a21a138fc09c08e905 because the
invert logic for isfinite is incorrect.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/X86/strictfp_builtins.c
clang/test/CodeGen/aarch64-strictfp-builtins.c
clang/test/CodeGen/builtin_float_strictfp.c
clang/test/CodeGen/strictfp_builtins.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 6b3d385c411e..35717168b2e0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3078,37 +3078,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 // isfinite(x) --> fabs(x) != infinity
 // x != NaN via the ordered compare in either case.
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+// FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here.
 Value *V = EmitScalarExpr(E->getArg(0));
-llvm::Type *Ty = V->getType();
-if (!Builder.getIsFPConstrained() ||
-Builder.getDefaultConstrainedExcept() == fp::ebIgnore ||
-!Ty->isIEEE()) {
-  Value *Fabs = EmitFAbs(*this, V);
-  Constant *Infinity = ConstantFP::getInfinity(V->getType());
-  CmpInst::Predicate Pred = (BuiltinID == Builtin::BI__builtin_isinf)
-? CmpInst::FCMP_OEQ
-: CmpInst::FCMP_ONE;
-  Value *FCmp = Builder.CreateFCmp(Pred, Fabs, Infinity, "cmpinf");
-  return RValue::get(Builder.CreateZExt(FCmp, ConvertType(E->getType(;
-}
-
-if (Value *Result = getTargetHooks().testFPKind(V, BuiltinID, Builder, 
CGM))
-  return RValue::get(Result);
-
-// Inf values have all exp bits set and a zero significand. Therefore:
-// isinf(V) == ((V << 1) == ((exp mask) << 1))
-unsigned bitsize = Ty->getScalarSizeInBits();
-llvm::IntegerType *IntTy = Builder.getIntNTy(bitsize);
-Value *IntV = Builder.CreateBitCast(V, IntTy);
-Value *Shl1 = Builder.CreateShl(IntV, 1);
-const llvm::fltSemantics &Semantics = Ty->getFltSemantics();
-APInt ExpMask = APFloat::getInf(Semantics).bitcastToAPInt();
-Value *ExpMaskShl1 = llvm::ConstantInt::get(IntTy, ExpMask.shl(1));
-if (BuiltinID == Builtin::BI__builtin_isinf)
-  V = Builder.CreateICmpEQ(Shl1, ExpMaskShl1);
-else
-  V = Builder.CreateICmpNE(Shl1, ExpMaskShl1);
-return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType(;
+Value *Fabs = EmitFAbs(*this, V);
+Constant *Infinity = ConstantFP::getInfinity(V->getType());
+CmpInst::Predicate Pred = (BuiltinID == Builtin::BI__builtin_isinf)
+  ? CmpInst::FCMP_OEQ
+  : CmpInst::FCMP_ONE;
+Value *FCmp = Builder.CreateFCmp(Pred, Fabs, Infinity, "cmpinf");
+return RValue::get(Builder.CreateZExt(FCmp, ConvertType(E->getType(;
   }
 
   case Builtin::BI__builtin_isinf_sign: {

diff  --git a/clang/test/CodeGen/X86/strictfp_builtins.c 
b/clang/test/CodeGen/X86/strictfp_builtins.c
index 4be64a6fafd7..d7eda34fb45e 100644
--- a/clang/test/CodeGen/X86/strictfp_builtins.c
+++ b/clang/test/CodeGen/X86/strictfp_builtins.c
@@ -26,24 +26,6 @@ void p(char *str, int x) {
 
 #define P(n,args) p(#n #args, __builtin_##n args)
 
-// CHECK-LABEL: @test_long_double_isinf(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca x86_fp80, align 16
-// CHECK-NEXT:store x86_fp80 [[D:%.*]], x86_fp80* [[LD_ADDR]], align 16
-// CHECK-NEXT:[[TMP0:%.*]] = load x86_fp80, x86_fp80* [[LD_ADDR]], align 16
-// CHECK-NEXT:[[BITCAST:%.*]] = bitcast x86_fp80 [[TMP0]] to i80
-// CHECK-NEXT:[[SHL1:%.*]] = shl i80 [[BITCAST]], 1
-// CHECK-NEXT:[[CMP:%.*]] = icmp eq i80 [[SHL1]], -18446744073709551616
-// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([10 x i8], [10 x 
i8]* @.str.1, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
-// CHECK-NEXT:ret void
-//
-void test_long_double_isinf(long double ld) {
-  P(isinf, (ld));
-
-  return;
-}
-
 // CHECK-LABEL: @test_long_double_isnan(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[LD_ADDR:%.*]] = alloca x86_fp80, align 16
@@ -54,7 +36,7 @@ void test_long_double_isinf(long double ld) {
 // CHECK-NEXT:[[TMP1:%.*]] = sub i80 604453686435277732577280, [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i80 [[TMP1]], 79
 // CHECK-NEXT:[[RES:%.*]] = trunc i80 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds (

[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-03-04 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

> <...>

Is the patch still not reverted?
That should have happened almost a week ago.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94640/new/

https://reviews.llvm.org/D94640

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97869: [OpenCL][Draft] Add OpenCL builtin test generator

2021-03-04 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D97869#2602943 , @Anastasia wrote:

> I was just thinking if we could combine the calls into one function to 
> minimize the number of lines to parse? Perhaps this will make the Tablegen 
> generator too complex?

That will increase the emitter's complexity.  Especially when taking into 
account the next point about handling optional functionality.  Hard to say in 
advance if paying for the added emitter complexity is worth the parsing time 
reduction, though the parsing time reduction is probably not going to be an 
order of magnitude difference.

> Also would it be possible to handle optional functionality - extensions and 
> functions available in certain versions?

Yes, I think this should be possible; I already have a TODO in the emitter.  It 
will make the resulting file bigger of course, because parts will have to be 
guarded with #ifdefs.  But I believe it would be a good way to test extension 
and version handling for builtins.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97869/new/

https://reviews.llvm.org/D97869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-03-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D94640#2603054 , @lebedev.ri wrote:

>> <...>
>
> Is the patch still not reverted?
> That should have happened almost a week ago.

FWIW, the fix for the issue was just approved.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94640/new/

https://reviews.llvm.org/D94640

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6d6e713 - Revert "Add __builtin_isnan(__fp16) testcase"

2021-03-04 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2021-03-04T12:18:03Z
New Revision: 6d6e7132f9c7bb1fc7b6771ae90ccf8810e9f22e

URL: 
https://github.com/llvm/llvm-project/commit/6d6e7132f9c7bb1fc7b6771ae90ccf8810e9f22e
DIFF: 
https://github.com/llvm/llvm-project/commit/6d6e7132f9c7bb1fc7b6771ae90ccf8810e9f22e.diff

LOG: Revert "Add __builtin_isnan(__fp16) testcase"

This reverts commit e77b5c40d57633a66842e75410585696895ecf4d because it
fails without 1b6eb56aa0ea2931866455a21a138fc09c08e905.

Added: 


Modified: 
clang/test/CodeGen/strictfp_builtins.c

Removed: 




diff  --git a/clang/test/CodeGen/strictfp_builtins.c 
b/clang/test/CodeGen/strictfp_builtins.c
index 6f7d2f3f91d3..131c9406fab6 100644
--- a/clang/test/CodeGen/strictfp_builtins.c
+++ b/clang/test/CodeGen/strictfp_builtins.c
@@ -92,25 +92,6 @@ void test_isinf_sign(double d) {
   return;
 }
 
-// CHECK-LABEL: @test_fp16_isnan(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[H_ADDR:%.*]] = alloca half, align 2
-// CHECK-NEXT:store half [[H:%.*]], half* [[H_ADDR]], align 2
-// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[H_ADDR]], align 2
-// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
-// CHECK-NEXT:[[ABS:%.*]] = and i16 [[BITCAST]], [[#%u,0x7FFF]]
-// CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
-// CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
-// CHECK-NEXT:[[RES:%.*]] = zext i16 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
-// CHECK-NEXT:ret void
-//
-void test_fp16_isnan(__fp16 h) {
-  P(isnan, (h));
-
-  return;
-}
-
 // CHECK-LABEL: @test_float_isnan(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[F_ADDR:%.*]] = alloca float, align 4



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97927: [clang-format] Rename case sorting

2021-03-04 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM. It's indeed more logical this way.
Hopefully the original author will confirm.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97927/new/

https://reviews.llvm.org/D97927

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-03-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:58-62
+  bool IsPointer = false;
+  // IsConstant indices are "int", but have the constant expression.
+  bool IsImmediate = false;
+  // const qualifier.
+  bool IsConstant = false;

craig.topper wrote:
> jrtc27 wrote:
> > This isn't expressive enough for the grammar you defined. `PCPCec` is 
> > supposed to give `const i8 * const i8 *`, whereas this will interpret it as 
> > `const i8 *`. Given such types are presumably not needed you need to 
> > tighten the rules of your grammar.
> @jrtc, are you asking for RVVType::applyModifier to verify that that C 
> doesn't appear twice for example?
Oops I meant to write @jrtc27 above. Are you asking for RVVType::applyModifier 
to verify that that C doesn't appear twice for example?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95016/new/

https://reviews.llvm.org/D95016

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81678: Introduce noundef attribute at call sites for stricter poison analysis

2021-03-04 Thread Gui Andrade via Phabricator via cfe-commits
guiand updated this revision to Diff 328055.
guiand added a comment.

Reupload patch to trigger build


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81678/new/

https://reviews.llvm.org/D81678

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp

Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+
+union u1 {
+  int val;
+};
+
+// CHECK: @indirect_callee_int_ptr = [[GLOBAL:(dso_local )?global]] i32 (i32)*
+int (*indirect_callee_int_ptr)(int);
+// CHECK: @indirect_callee_union_ptr = [[GLOBAL]] i32 (i32)*
+union u1 (*indirect_callee_union_ptr)(union u1);
+
+// CHECK: [[DEFINE:define( dso_local)?]] noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef %
+int indirect_callee_int(int a) { return a; }
+// CHECK: [[DEFINE]] i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
+union u1 indirect_callee_union(union u1 a) {
+  return a;
+}
+
+int main() {
+  // CHECK: call noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef 0)
+  indirect_callee_int(0);
+  // CHECK: call i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
+  indirect_callee_union((union u1){0});
+
+  indirect_callee_int_ptr = indirect_callee_int;
+  indirect_callee_union_ptr = indirect_callee_union;
+
+  // CHECK: call noundef i32 %{{.*}}(i32 noundef 0)
+  indirect_callee_int_ptr(0);
+  // CHECK: call i32 %{{.*}}(i32 %
+  indirect_callee_union_ptr((union u1){});
+
+  return 0;
+}
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -0,0 +1,162 @@
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+
+// Passing structs by value
+// TODO: No structs may currently be marked noundef
+
+namespace check_structs {
+struct Trivial {
+  int a;
+};
+Trivial ret_trivial() { return {}; }
+void pass_trivial(Trivial e) {}
+// CHECK-INTEL: [[DEFINE:define( dso_local)?]] i32 @{{.*}}ret_trivial
+// CHECK-AARCH: [[DEFINE:define( dso_local)?]] i64 @{{.*}}ret_trivial
+// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
+// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
+
+struct NoCopy {
+  int a;
+  NoCopy(NoCopy &) = delete;
+};
+NoCopy ret_nocopy() { return {}; }
+void pass_nocopy(NoCopy e) {}
+// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noalias sret({{[^)]+}}) align 4 %
+// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noundef %
+
+struct Huge {
+  int a[1024];
+};
+Huge ret_huge() { return {}; }
+void pass_huge(Huge h) {}
+// CHECK: [[DEFINE]] void @{{.*}}ret_huge{{.*}}(%"struct.check_structs::Huge"* noalias sret({{[^)]+}}) align 4 %
+// CHECK: [[DEFINE]] void @{{.*}}pass_huge{{.*}}(%"struct.check_structs::Huge"* noundef
+} // namespace check_structs
+
+// Passing unions by value
+// No unions may be marked noundef
+
+namespace check_unions {
+union Trivial {
+  int a;
+};
+Trivial ret_trivial() { return {}; }
+void pass_trivial(Trivial e) {}
+// CHECK-INTEL: [[DEFINE]] i32 @{{.*}}ret_trivial
+// CHECK-AARCH: [[DEFINE]] i64 @{{.*}}ret_trivial
+// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
+// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
+
+union NoCopy {
+  int a;
+  NoCopy(NoCopy &) = delete;
+};
+NoCopy ret_nocopy() { return {}; }
+void pass_nocopy(NoCopy e) {}
+// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"union.check_unions::NoCopy"* noalias sret({{[^)]+}}) align 4 %
+// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"union.check_unions::NoCopy"* noundef %
+} // namespace check_unions
+
+// Passing `this` pointers
+// `this` pointer must always be defined
+
+namespace check_this {
+struct Object {
+  int data[];
+
+  Object() {
+this->data[0] = 0;
+  }
+  int getData() {
+return this->data[0];
+  }
+  Object *getThis() {
+return this;
+  }
+};
+
+void use_object() {
+  Object obj;
+  obj.getData();
+  obj.getThis();
+}
+// CHECK: define linkonce_odr void @{{.*}}Object{{.*}}(%"struct.check_this::Object"* noundef %
+// CHECK: define linkonce_odr noundef i32 @{{.*}}Object{{.*}}getData{{.*}}(%"struct.check_this::Object"* noundef %
+// CHECK: define linkonce_odr noundef %"s

[PATCH] D81678: Introduce noundef attribute at call sites for stricter poison analysis

2021-03-04 Thread Gui Andrade via Phabricator via cfe-commits
guiand updated this revision to Diff 328060.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81678/new/

https://reviews.llvm.org/D81678

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp

Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+
+union u1 {
+  int val;
+};
+
+// CHECK: @indirect_callee_int_ptr = [[GLOBAL:(dso_local )?global]] i32 (i32)*
+int (*indirect_callee_int_ptr)(int);
+// CHECK: @indirect_callee_union_ptr = [[GLOBAL]] i32 (i32)*
+union u1 (*indirect_callee_union_ptr)(union u1);
+
+// CHECK: [[DEFINE:define( dso_local)?]] noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef %
+int indirect_callee_int(int a) { return a; }
+// CHECK: [[DEFINE]] i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
+union u1 indirect_callee_union(union u1 a) {
+  return a;
+}
+
+int main() {
+  // CHECK: call noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef 0)
+  indirect_callee_int(0);
+  // CHECK: call i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
+  indirect_callee_union((union u1){0});
+
+  indirect_callee_int_ptr = indirect_callee_int;
+  indirect_callee_union_ptr = indirect_callee_union;
+
+  // CHECK: call noundef i32 %{{.*}}(i32 noundef 0)
+  indirect_callee_int_ptr(0);
+  // CHECK: call i32 %{{.*}}(i32 %
+  indirect_callee_union_ptr((union u1){});
+
+  return 0;
+}
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -0,0 +1,162 @@
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+
+// Passing structs by value
+// TODO: No structs may currently be marked noundef
+
+namespace check_structs {
+struct Trivial {
+  int a;
+};
+Trivial ret_trivial() { return {}; }
+void pass_trivial(Trivial e) {}
+// CHECK-INTEL: [[DEFINE:define( dso_local)?]] i32 @{{.*}}ret_trivial
+// CHECK-AARCH: [[DEFINE:define( dso_local)?]] i64 @{{.*}}ret_trivial
+// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
+// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
+
+struct NoCopy {
+  int a;
+  NoCopy(NoCopy &) = delete;
+};
+NoCopy ret_nocopy() { return {}; }
+void pass_nocopy(NoCopy e) {}
+// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noalias sret({{[^)]+}}) align 4 %
+// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noundef %
+
+struct Huge {
+  int a[1024];
+};
+Huge ret_huge() { return {}; }
+void pass_huge(Huge h) {}
+// CHECK: [[DEFINE]] void @{{.*}}ret_huge{{.*}}(%"struct.check_structs::Huge"* noalias sret({{[^)]+}}) align 4 %
+// CHECK: [[DEFINE]] void @{{.*}}pass_huge{{.*}}(%"struct.check_structs::Huge"* noundef
+} // namespace check_structs
+
+// Passing unions by value
+// No unions may be marked noundef
+
+namespace check_unions {
+union Trivial {
+  int a;
+};
+Trivial ret_trivial() { return {}; }
+void pass_trivial(Trivial e) {}
+// CHECK-INTEL: [[DEFINE]] i32 @{{.*}}ret_trivial
+// CHECK-AARCH: [[DEFINE]] i64 @{{.*}}ret_trivial
+// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
+// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
+
+union NoCopy {
+  int a;
+  NoCopy(NoCopy &) = delete;
+};
+NoCopy ret_nocopy() { return {}; }
+void pass_nocopy(NoCopy e) {}
+// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"union.check_unions::NoCopy"* noalias sret({{[^)]+}}) align 4 %
+// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"union.check_unions::NoCopy"* noundef %
+} // namespace check_unions
+
+// Passing `this` pointers
+// `this` pointer must always be defined
+
+namespace check_this {
+struct Object {
+  int data[];
+
+  Object() {
+this->data[0] = 0;
+  }
+  int getData() {
+return this->data[0];
+  }
+  Object *getThis() {
+return this;
+  }
+};
+
+void use_object() {
+  Object obj;
+  obj.getData();
+  obj.getThis();
+}
+// CHECK: define linkonce_odr void @{{.*}}Object{{.*}}(%"struct.check_this::Object"* noundef %
+// CHECK: define linkonce_odr noundef i32 @{{.*}}Object{{.*}}getData{{.*}}(%"struct.check_this::Object"* noundef %
+// CHECK: define linkonce_odr noundef %"struct.check_this::Object"* @{{.*}}Object{{.*}}getThis{{.*}

[clang-tools-extra] 3ea0e11 - [clang-tidy][NFC] Update docs for bugprone-use-after-move

2021-03-04 Thread Martin Boehme via cfe-commits

Author: martinboehme
Date: 2021-03-04T13:22:19+01:00
New Revision: 3ea0e119b9fce4c4754313d03824c9c4bcddad66

URL: 
https://github.com/llvm/llvm-project/commit/3ea0e119b9fce4c4754313d03824c9c4bcddad66
DIFF: 
https://github.com/llvm/llvm-project/commit/3ea0e119b9fce4c4754313d03824c9c4bcddad66.diff

LOG: [clang-tidy][NFC] Update docs for bugprone-use-after-move

- Create a separate section on silencing erroneous warnings and add more 
material to it
- Add note that the check is flow-sensitive but not path-sensitive

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-use-after-move.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone-use-after-move.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone-use-after-move.rst
index 9fde912837d8..aab7cfd0ccd4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone-use-after-move.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone-use-after-move.rst
@@ -24,6 +24,9 @@ move and before the use. For example, no warning will be 
output for this code:
 str = "Greetings, stranger!\n";
 std::cout << str;
 
+Subsections below explain more precisely what exactly the check considers to be
+a move, use, and reinitialization.
+
 The check takes control flow into account. A warning is only emitted if the use
 can be reached from the move. This means that the following code does not
 produce a warning:
@@ -60,7 +63,12 @@ mutually exclusive. For example (assuming that ``i`` is an 
int):
 }
 
 In this case, the check will erroneously produce a warning, even though it is
-not possible for both the move and the use to be executed.
+not possible for both the move and the use to be executed. More formally, the
+analysis is `flow-sensitive but not path-sensitive
+`_.
+
+Silencing erroneous warnings
+
 
 An erroneous warning can be silenced by reinitializing the object after the
 move:
@@ -75,8 +83,30 @@ move:
   std::cout << str;
 }
 
-Subsections below explain more precisely what exactly the check considers to be
-a move, use, and reinitialization.
+If you want to avoid the overhead of actually reinitializing the object, you 
can
+create a dummy function that causes the check to assume the object was
+reinitialized:
+
+.. code-block:: c++
+
+template 
+void IS_INITIALIZED(T&) {}
+
+You can use this as follows:
+
+.. code-block:: c++
+
+if (i == 1) {
+  messages.emplace_back(std::move(str));
+}
+if (i == 2) {
+  IS_INITIALIZED(str);
+  std::cout << str;
+}
+
+The check will not output a warning in this case because passing the object to 
a
+function as a non-const pointer or reference counts as a reinitialization (see 
section
+`Reinitialization`_ below).
 
 Unsequenced moves, uses, and reinitializations
 --



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-03-04 Thread Karl-Johan Karlsson via Phabricator via cfe-commits
Ka-Ka added a comment.

Thanks for the information. I found the review now in 
https://reviews.llvm.org/D97512


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94640/new/

https://reviews.llvm.org/D94640

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96245: [clangd] Propagate CodeActions in addition to Fixes for diagnostics

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

One little curveball I'm still kind of hoping we can integrate clang-format 
into our codeAction workflow, in the hopes of addressing 
https://github.com/clangd/clangd/issues/429.
While we compute the edits eagerly we don't actually send them until the client 
request for codeActions so it may be possible to pipe them into clang-format 
then.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96245/new/

https://reviews.llvm.org/D96245

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97935: [clangd] Add config support for ResourceDir

2021-03-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97935

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Support/SMLoc.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -164,6 +165,17 @@
   EXPECT_THAT(*Results[0].Index.External.getValue()->Server, Val("bar"));
 }
 
+TEST(ParseYAML, ResourceDir) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+CompileFlags:
+  ResourceDir: "foo")yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_EQ(Results.size(), 1u);
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  EXPECT_THAT(Results[0].CompileFlags.ResourceDir, llvm::ValueIs(Val("foo")));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -171,6 +171,22 @@
   EXPECT_THAT(Diags.Diagnostics, IsEmpty());
 }
 
+TEST_F(ConfigCompileTests, ResourceDir) {
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_TRUE(Conf.CompileFlags.ResourceDir.empty());
+
+  auto ResourceDir = testPath("foo");
+  Frag.CompileFlags.ResourceDir.emplace(ResourceDir);
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_EQ(Conf.CompileFlags.ResourceDir, ResourceDir);
+
+  ResourceDir = "foo";
+  Frag.Source.Directory = testRoot();
+  Frag.CompileFlags.ResourceDir.emplace(ResourceDir);
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_EQ(Conf.CompileFlags.ResourceDir, testPath("foo"));
+}
+
 TEST_F(ConfigCompileTests, Index) {
   Frag.Index.Background.emplace("Skip");
   EXPECT_TRUE(compileAndApply());
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -52,10 +52,22 @@
 
 TEST(CommandMangler, ResourceDir) {
   auto Mangler = CommandMangler::forTests();
-  Mangler.ResourceDir = testPath("fake/resources");
+
+  // Check config works.
+  Config Cfg;
+  auto ResourceDir = testPath("config/resources");
+  Cfg.CompileFlags.ResourceDir = ResourceDir;
+  WithContextValue WithConfig(Config::Key, std::move(Cfg));
   std::vector Cmd = {"clang++", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
+  EXPECT_THAT(Cmd, Contains("-resource-dir=" + ResourceDir));
+
+  // Check that explicit option overrides config.
+  ResourceDir = testPath("explicit/resources");
+  Mangler.ResourceDir = ResourceDir;
+  Cmd = {"clang++", "foo.cc"};
+  Mangler.adjust(Cmd);
+  EXPECT_THAT(Cmd, Contains("-resource-dir=" + ResourceDir));
 }
 
 TEST(CommandMangler, Sysroot) {
@@ -378,4 +390,3 @@
 } // namespace
 } // namespace clangd
 } // namespace clang
-
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -98,6 +98,9 @@
 Dict.handle("CompilationDatabase", [&](Node &N) {
   F.CompilationDatabase = scalarValue(N, "CompilationDatabase");
 });
+Dict.handle("ResourceDir", [&](Node &N) {
+  F.ResourceDir = scalarValue(N, "ResourceDir");
+});
 Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -158,6 +158,11 @@
 /// - Ancestors: search all parent directories (the default)
 /// - None: do not use a compilation database, just default flags.
 llvm::Optional> CompilationDatabase;
+
+/// Path to a directory on user's machine, that'll be used to search for
+/// built-in headers. Relative paths may be used, if confi

[PATCH] D96245: [clangd] Propagate CodeActions in addition to Fixes for diagnostics

2021-03-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D96245#2602896 , @kadircet wrote:

> Agreed, I was going this way because currently there was no way to provide a 
> code action to clangd::diagnostic apart from storing it in the fixes map 
> while generating it. I suppose it is more sensible to just go with a new hook 
> on modules that can provide a codeaction given a clangd::diagnostic.

I think this is what you meant, but just to be sure... there's no fundamental 
need in LSP to make any association between code actions and diagnostics until 
a codeAction request comes in.
There's no need to put anything into FixesMap. (We do have an extension/C++ API 
that exposes a different model, but as discussed offline I think we should just 
not expose this through the extension for now)

> Does `std::vector contributeActions(const CodeActionParams&);` 
> look like a good signature for the module hook?

A couple of issues:

- this will require modules to duplicate protocol details (e.g. 
CodeActionContext.only)
- many modules that want to provide code actions will want an AST, and we build 
one for the codeAction request, we should be able to share it
- it's not obvious how to use these without ClangdLSPServer if the CodeAction 
wraps a Command whose handler must be bound

We have the Tweak infrastructure that's basically designed to solve all these 
problems. It has some issues (like you can only return one fix per "class") but 
these are fixable and would be nice to have fixed in any case.
This means we'd be using a fixed LSP applyTweak command rather than binding a 
custom command for this action as planned, but it might work well?

Interface would just look like `contributeTweaks(vector>&)` 
or something

WDYT


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96245/new/

https://reviews.llvm.org/D96245

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97777: Add __builtin_isnan(__fp16) testcase

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre updated this revision to Diff 328130.
thopre added a comment.

Adapt to revert of __builtin_isinf


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D9/new/

https://reviews.llvm.org/D9

Files:
  clang/test/CodeGen/strictfp_builtins.c


Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -o - -triple 
x86_64-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap 
-fallow-half-arguments-and-returns -o - -triple x86_64-unknown-unknown | 
FileCheck %s
 
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
@@ -92,6 +92,25 @@
   return;
 }
 
+// CHECK-LABEL: @test_fp16_isnan(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[H_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[ABS:%.*]] = and i16 [[BITCAST]], [[#%u,0x7FFF]]
+// CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
+// CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
+// CHECK-NEXT:[[RES:%.*]] = zext i16 [[ISNAN]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.4, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_fp16_isnan(__fp16 h) {
+  P(isnan, (h));
+
+  return;
+}
+
 // CHECK-LABEL: @test_float_isnan(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[F_ADDR:%.*]] = alloca float, align 4
@@ -101,7 +120,7 @@
 // CHECK-NEXT:[[ABS:%.*]] = and i32 [[BITCAST]], [[#%u,0x7FFF]]
 // CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[#%u,0x7F80]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i32 [[TMP1]], 31
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.4, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.5, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_float_isnan(float f) {
@@ -120,7 +139,7 @@
 // CHECK-NEXT:[[TMP1:%.*]] = sub i64 [[#%u,0x7FF0]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i64 [[TMP1]], 63
 // CHECK-NEXT:[[RES:%.*]] = trunc i64 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.5, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.6, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_double_isnan(double d) {
@@ -141,7 +160,7 @@
 // CHECK-NEXT:[[AND:%.*]] = and i1 [[ISEQ]], [[ISINF]]
 // CHECK-NEXT:[[AND1:%.*]] = and i1 [[AND]], [[ISNORMAL]]
 // CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[AND1]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x 
i8]* @.str.6, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x 
i8]* @.str.7, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_isnormal(double d) {


Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -o - -triple x86_64-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -fallow-half-arguments-and-returns -o - -triple x86_64-unknown-unknown | FileCheck %s
 
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
@@ -92,6 +92,25 @@
   return;
 }
 
+// CHECK-LABEL: @test_fp16_isnan(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[H_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[ABS:%.*]] = and i16 [[BITCAST]], [[#%u,0x7FFF]]
+// CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
+// CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
+// CHECK-NEXT:[[RES:%.*]] = zext i16 [[ISNAN]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i

[PATCH] D97936: [analyzer][docs][NFC] Fix typo in checkers.rst

2021-03-04 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, vsavchenko, martong, ASDenysPetrov, Szelethus.
Herald added subscribers: Charusso, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, whisperity.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Move `alpha.core.BoolAssignment` out of the `alpha.clone` enumeration.
F15732376: fix-doc-typo.PNG 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97936

Files:
  clang/docs/analyzer/checkers.rst


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1476,6 +1476,9 @@
return y;
  }
 
+alpha.core
+^^
+
 .. _alpha-core-BoolAssignment:
 
 alpha.core.BoolAssignment (ObjC)
@@ -1488,9 +1491,6 @@
BOOL b = -1; // warn
  }
 
-alpha.core
-^^
-
 .. _alpha-core-C11Lock:
 
 alpha.core.C11Lock


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1476,6 +1476,9 @@
return y;
  }
 
+alpha.core
+^^
+
 .. _alpha-core-BoolAssignment:
 
 alpha.core.BoolAssignment (ObjC)
@@ -1488,9 +1491,6 @@
BOOL b = -1; // warn
  }
 
-alpha.core
-^^
-
 .. _alpha-core-C11Lock:
 
 alpha.core.C11Lock
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 52bfe66 - Add __builtin_isnan(__fp16) testcase

2021-03-04 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2021-03-04T13:03:48Z
New Revision: 52bfe6605ab735bfe353682a5ced78aee6bacdbd

URL: 
https://github.com/llvm/llvm-project/commit/52bfe6605ab735bfe353682a5ced78aee6bacdbd
DIFF: 
https://github.com/llvm/llvm-project/commit/52bfe6605ab735bfe353682a5ced78aee6bacdbd.diff

LOG: Add __builtin_isnan(__fp16) testcase

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/test/CodeGen/strictfp_builtins.c

Removed: 




diff  --git a/clang/test/CodeGen/strictfp_builtins.c 
b/clang/test/CodeGen/strictfp_builtins.c
index 131c9406fab6..2d55b07ccc11 100644
--- a/clang/test/CodeGen/strictfp_builtins.c
+++ b/clang/test/CodeGen/strictfp_builtins.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -o - -triple 
x86_64-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap 
-fallow-half-arguments-and-returns -o - -triple x86_64-unknown-unknown | 
FileCheck %s
 
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
@@ -92,6 +92,25 @@ void test_isinf_sign(double d) {
   return;
 }
 
+// CHECK-LABEL: @test_fp16_isnan(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[H_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[ABS:%.*]] = and i16 [[BITCAST]], [[#%u,0x7FFF]]
+// CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
+// CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
+// CHECK-NEXT:[[RES:%.*]] = zext i16 [[ISNAN]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.4, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_fp16_isnan(__fp16 h) {
+  P(isnan, (h));
+
+  return;
+}
+
 // CHECK-LABEL: @test_float_isnan(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[F_ADDR:%.*]] = alloca float, align 4
@@ -101,7 +120,7 @@ void test_isinf_sign(double d) {
 // CHECK-NEXT:[[ABS:%.*]] = and i32 [[BITCAST]], [[#%u,0x7FFF]]
 // CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[#%u,0x7F80]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i32 [[TMP1]], 31
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.4, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.5, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_float_isnan(float f) {
@@ -120,7 +139,7 @@ void test_float_isnan(float f) {
 // CHECK-NEXT:[[TMP1:%.*]] = sub i64 [[#%u,0x7FF0]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i64 [[TMP1]], 63
 // CHECK-NEXT:[[RES:%.*]] = trunc i64 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.5, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.6, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_double_isnan(double d) {
@@ -141,7 +160,7 @@ void test_double_isnan(double d) {
 // CHECK-NEXT:[[AND:%.*]] = and i1 [[ISEQ]], [[ISINF]]
 // CHECK-NEXT:[[AND1:%.*]] = and i1 [[AND]], [[ISNORMAL]]
 // CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[AND1]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x 
i8]* @.str.6, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x 
i8]* @.str.7, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_isnormal(double d) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97777: Add __builtin_isnan(__fp16) testcase

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG52bfe6605ab7: Add __builtin_isnan(__fp16) testcase (authored 
by thopre).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D9/new/

https://reviews.llvm.org/D9

Files:
  clang/test/CodeGen/strictfp_builtins.c


Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -o - -triple 
x86_64-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap 
-fallow-half-arguments-and-returns -o - -triple x86_64-unknown-unknown | 
FileCheck %s
 
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
@@ -92,6 +92,25 @@
   return;
 }
 
+// CHECK-LABEL: @test_fp16_isnan(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[H_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[ABS:%.*]] = and i16 [[BITCAST]], [[#%u,0x7FFF]]
+// CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
+// CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
+// CHECK-NEXT:[[RES:%.*]] = zext i16 [[ISNAN]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.4, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_fp16_isnan(__fp16 h) {
+  P(isnan, (h));
+
+  return;
+}
+
 // CHECK-LABEL: @test_float_isnan(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[F_ADDR:%.*]] = alloca float, align 4
@@ -101,7 +120,7 @@
 // CHECK-NEXT:[[ABS:%.*]] = and i32 [[BITCAST]], [[#%u,0x7FFF]]
 // CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[#%u,0x7F80]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i32 [[TMP1]], 31
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.4, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.5, i64 0, i64 0), i32 [[ISNAN]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_float_isnan(float f) {
@@ -120,7 +139,7 @@
 // CHECK-NEXT:[[TMP1:%.*]] = sub i64 [[#%u,0x7FF0]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i64 [[TMP1]], 63
 // CHECK-NEXT:[[RES:%.*]] = trunc i64 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.5, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* 
@.str.6, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_double_isnan(double d) {
@@ -141,7 +160,7 @@
 // CHECK-NEXT:[[AND:%.*]] = and i1 [[ISEQ]], [[ISINF]]
 // CHECK-NEXT:[[AND1:%.*]] = and i1 [[AND]], [[ISNORMAL]]
 // CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[AND1]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x 
i8]* @.str.6, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x 
i8]* @.str.7, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_isnormal(double d) {


Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -o - -triple x86_64-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -ffp-exception-behavior=maytrap -fallow-half-arguments-and-returns -o - -triple x86_64-unknown-unknown | FileCheck %s
 
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
@@ -92,6 +92,25 @@
   return;
 }
 
+// CHECK-LABEL: @test_fp16_isnan(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[H_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[H_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[ABS:%.*]] = and i16 [[BITCAST]], [[#%u,0x7FFF]]
+// CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
+// CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
+// CHECK-NEXT:[[RES:%.*]] = zext i

[PATCH] D97850: Fix PCM read from ModuleCache for ext4 filesystem

2021-03-04 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

If I understand this correctly, then the inode caching logic in FileManager 
isn't just breaking PCMs but all file operations:

  TEST_F(FileManagerTest, InodeReuse) {
{
  std::ofstream myfile;
  myfile.open("a.cpp");
  myfile << "content\n";
}
llvm::ErrorOr fe1 = manager.getFile("a.cpp");
EXPECT_TRUE(fe1);
const FileEntry *f1 = *fe1;
remove("a.cpp");
{
  std::ofstream myfile;
  myfile.open("b.cpp");
  myfile << "different content\n";
}
llvm::ErrorOr fe2 = manager.getFile("b.cpp");
EXPECT_TRUE(fe2);
const FileEntry *f2 = *fe2;
EXPECT_NE(f2->getSize(), f1->getSize());
EXPECT_NE(f2->getUniqueID().getFile(), f1->getUniqueID().getFile());
  }

This fails consistently for me when running in an empty ext4 directory with:

  Expected: (f2->getSize()) != (f1->getSize()), actual: 8 vs 8
  Expected: (f2->getUniqueID().getFile()) != (f1->getUniqueID().getFile()), 
actual: 57855544 vs 57855544

I guess this wasn't considered a valid use case for the normal `#include` logic 
within Clang (which I believe is the primary beneficiary of this cache and 
doesn't really care about a changing file system). But with PCMs and Clang 
REPLs this is probably causing some strange bugs.

Anyway, I don't think I know the FileManager code well enough to come up with a 
real fix (beside just removing the inode cache).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97850/new/

https://reviews.llvm.org/D97850

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97896: [Clang][RISCV][RFC] Add byval parameter attribute?

2021-03-04 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

I think I may have had the impression from some previous discussions that byval 
may have limited positive impact, and that letting Clang add the copies to the 
IR might in some cases help optimisations (that may not be written to reason 
about byval). You've got a good example of a case where the lack of byval 
causes weaker optimisation though.

Just running this across the GCC torture suite on rv32imafdc_{ilp32,ilp32d}, 
rv64imafdc_{lp64, lp64d} and {O0,O1 
,O2 
,O3 
,Os}, I see `22394 insertions(+), 
17462 deletions(-)` in the generated .s. Obviously not a representative 
benchmark, but it does seem there are potential regressions to consider.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97896/new/

https://reviews.llvm.org/D97896

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97805: [clang-query] Add option to enable only displaying main file matches

2021-03-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a typo fix.




Comment at: clang-tools-extra/clang-query/Query.cpp:56
+"include-headers "
+"Match nodes included from head files. This mode is the "
+"default.\n"




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97805/new/

https://reviews.llvm.org/D97805

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97121: [clang-tidy] Add a single fix mode to clang-tidy

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 328134.
njames93 added a comment.

Rename mode to self contained diags.
Added support for modernize-loop-convert. Currently transforming a loop will 
prevent any nested loops being transformed if they are affected by the first 
transformation. This is counter productive in self contained diags mode.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97121/new/

https://reviews.llvm.org/D97121

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -30,8 +30,9 @@
 public:
   IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
utils::IncludeSorter::IncludeStyle Style =
-   utils::IncludeSorter::IS_Google)
-  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
+   utils::IncludeSorter::IS_Google,
+   bool SingleFixMode = false)
+  : ClangTidyCheck(CheckName, Context), Inserter(Style, SingleFixMode) {}
 
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -85,6 +86,18 @@
   }
 };
 
+class MultipleHeaderSingleInserterCheck : public IncludeInserterCheckBase {
+public:
+  MultipleHeaderSingleInserterCheck(StringRef CheckName,
+ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google, true) {}
+
+  std::vector headersToInclude() const override {
+return {"path/to/header.h", "path/to/header2.h", "path/to/header.h"};
+  }
+};
+
 class CSystemIncludeInserterCheck : public IncludeInserterCheckBase {
 public:
   CSystemIncludeInserterCheck(StringRef CheckName, ClangTidyContext *Context)
@@ -246,6 +259,41 @@
 PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
+TEST(IncludeInserterTest, InsertMultipleIncludesNoDeduplicate) {
+  const char *PreCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // FIXME ClangFormat bug - https://bugs.llvm.org/show_bug.cgi?id=49298
+  // clang-format off
+  const char *PostCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+#include "path/to/header.h"
+#include "path/to/header2.h"
+#include "path/to/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // clang-format on
+
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
+}
+
 TEST(IncludeInserterTest, InsertBeforeFirstNonSystemInclude) {
   const char *PreCode = R"(
 #include "clang_tidy/tests/insert_includes_test_header.h"
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -517,6 +517,67 @@
   ElementsAre(Diag(Main.range(), "do not use 'else' after 'return'")));
 }
 
+TEST(DiagnosticTest, ClangTidySingleFixMode) {
+  Annotations Main(R"cpp($MathHeader[[]]
+struct Foo{
+  int A, B;
+  Foo()$Fix[[]] {
+$A[[A = 1;]]
+$B[[B = 1;]]
+  }
+};
+void InitVariables() {
+  fl

[PATCH] D93594: [X86] Pass to transform amx intrinsics to scalar operation.

2021-03-04 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp:82
+  DTU.applyUpdatesPermissive({
+  {DominatorTree::Delete, Preheader, Tmp},
+  {DominatorTree::Insert, Header, Body},

pengfei wrote:
> Do we need to remove the successor? Isn't it still being dominated?
I think this is to remove edge from preheader to tmp, because we insert a loop 
between them.



Comment at: llvm/test/CodeGen/X86/AMX/amx-low-intrinsics-no-amx-bitcast.ll:1
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple=x86_64 -lower-amx-intrinsics %s -S | FileCheck %s

pengfei wrote:
> I think we should move the files to llvm/test/Transforms/
Not sure about it. Our .cpp code is under lib/Target/X86/ folder.



Comment at: llvm/test/CodeGen/X86/AMX/amx-type.ll:2
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -lower-amx-type %s -S | FileCheck %s
+; RUN: opt --codegen-opt-level=2 -mtriple=x86_64 -lower-amx-type %s -S | 
FileCheck %s
 

pengfei wrote:
> Why adding this? Is it O2 by default?
I think this is to test with opt level 2 this pass do nothing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93594/new/

https://reviews.llvm.org/D93594

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97805: [clang-query] Add option to enable only displaying main file matches

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 328135.
njames93 added a comment.

Fix typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97805/new/

https://reviews.llvm.org/D97805

Files:
  clang-tools-extra/clang-query/Query.cpp
  clang-tools-extra/clang-query/QueryParser.cpp
  clang-tools-extra/clang-query/QueryParser.h
  clang-tools-extra/clang-query/QuerySession.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-query/Inputs/foo.h
  clang-tools-extra/test/clang-query/headers.cpp

Index: clang-tools-extra/test/clang-query/headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-query/headers.cpp
@@ -0,0 +1,55 @@
+// RUN: clang-query -c "set match-scope include-headers" -c "match functionDecl(hasName('foo'))" %s -- | FileCheck %s --check-prefix=CHECK-ALL-FOO
+// RUN: clang-query -c "set match-scope main-file-only" -c "match functionDecl(hasName('foo'))" %s -- | FileCheck %s --check-prefix=CHECK-MAIN-FOO
+// RUN: clang-query -c "set match-scope include-headers" -c "match functionDecl(hasName('bar'))" %s -- | FileCheck %s --check-prefix=CHECK-ALL-BAR
+// RUN: clang-query -c "set match-scope main-file-only" -c "match functionDecl(hasName('bar'))" %s -- | FileCheck %s --check-prefix=CHECK-MAIN-BAR
+// RUN: clang-query -c "set match-scope include-headers" -c "match functionDecl()" %s -- | FileCheck %s --check-prefix=CHECK-ALL-ANY
+// RUN: clang-query -c "set match-scope main-file-only" -c "match functionDecl()" %s -- | FileCheck %s --check-prefix=CHECK-MAIN-ANY
+
+// Test to ensure default behavious only includes main file matches.
+// RUN: clang-query -c "match functionDecl()" %s -- | FileCheck %s --check-prefix=CHECK-ALL-ANY
+
+// Test to ensure the warnings about selecting match-scope is only shown once
+// RUN: clang-query -c "set match-scope include-headers" -c "match functionDecl()" -c "match functionDecl()" %s | FileCheck %s --check-prefix=CHECK-SINGLE-WARN-ALL
+// RUN: clang-query -c "set match-scope main-file-only" -c "match functionDecl()" -c "match functionDecl()" %s | FileCheck %s --check-prefix=CHECK-SINGLE-WARN-MAIN
+
+#include "Inputs/foo.h"
+
+void foo() {}
+
+// CHECK-ALL-FOO: /Inputs/foo.h:4:1: note: "root" binds here
+// CHECK-ALL-FOO: /headers.cpp:17:1: note: "root" binds here
+// CHECK-ALL-FOO: 2 matches.
+// CHECK-ALL-FOO-NEXT: Included 1 match from header files
+// CHECK-ALL-FOO-NEXT: Use 'set match-mode main-file-only' to hide them.
+
+// CHECK-MAIN-FOO: /headers.cpp:17:1: note: "root" binds here
+// CHECK-MAIN-FOO: 1 match.
+// CHECK-MAIN-FOO-Next: Skipped 1 match from header files.
+// CHECK-MAIN-FOO-Next: Use 'set match-mode include-headers' to display them.
+
+// CHECK-ALL-BAR: /Inputs/foo.h:5:1: note: "root" binds here
+// CHECK-ALL-BAR: 1 match.
+// CHECK-ALL-BAR-NEXT: Included 1 match from header files
+// CHECK-ALL-BAR-NEXT: Use 'set match-mode main-file-only' to hide them.
+
+// CHECK-MAIN-BAR: 0 matches.
+// CHECK-MAIN-BAR-Next: Skipped 1 match from header files.
+// CHECK-MAIN-BAR-Next: Use 'set match-mode include-headers' to display them.
+
+// CHECK-ALL-ANY: /Inputs/foo.h:4:1: note: "root" binds here
+// CHECK-ALL-ANY: /Inputs/foo.h:5:1: note: "root" binds here
+// CHECK-ALL-ANY: /headers.cpp:17:1: note: "root" binds here
+// CHECK-ALL-ANY: 3 matches.
+// CHECK-ALL-ANY-NEXT: Included 2 matches from header files
+// CHECK-ALL-ANY-NEXT: Use 'set match-mode main-file-only' to hide them.
+
+// CHECK-MAIN-ANY: /headers.cpp:17:1: note: "root" binds here
+// CHECK-MAIN-ANY: 1 match.
+// CHECK-MAIN-ANY-Next: Skipped 2 matches from header files.
+// CHECK-MAIN-ANY-Next: Use 'set match-mode include-headers' to display them.
+
+// CHECK-SINGLE-WARN-ALL: Use 'set match-mode main-file-only' to hide them.
+// CHECK-SINGLE-WARN-ALL-NOT: Use 'set match-mode main-file-only' to hide them.
+
+// CHECK-SINGLE-WARN-MAIN: Use 'set match-mode include-headers' to display them.
+// CHECK-SINGLE-WARN-MAIN-NOT: Use 'set match-mode include-headers' to display them.
Index: clang-tools-extra/test/clang-query/Inputs/foo.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-query/Inputs/foo.h
@@ -0,0 +1,7 @@
+#ifndef INPUTS_FOO_HH
+#define INPUTS_FOO_HH
+
+void foo();
+void bar();
+
+#endif // INPUTS_FOO_HH
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -57,7 +57,8 @@
 Improvements to clang-query
 ---
 
-The improvements are...
+ - Added a option `set match-scope` to control displaying matches that occur 
+   in header files.
 
 Improvements to clang-rename
 
Index: clang-tools-extra/clang-query/QuerySession.h
===
--- clang-tools-extra/cla

[PATCH] D97869: [OpenCL][Draft] Add OpenCL builtin test generator

2021-03-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

That's awesome!

I'm thinking of how can you track correctness of generated built-ins according 
to spec.  Perhaps you can compare the number of distinct declarations for each  
built-in in the spec and in tablegen and diagnose if they are not equal. This 
is a very straightforward, but I can't think of on other solution yet (with the 
absence of CTS coverage)...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97869/new/

https://reviews.llvm.org/D97869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ab971c2 - [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-03-04 Thread Andrzej Warzynski via cfe-commits

Author: Arnamoy Bhattacharyya
Date: 2021-03-04T13:29:07Z
New Revision: ab971c29a56a4c24359b499d05c30c8c9fc4dea3

URL: 
https://github.com/llvm/llvm-project/commit/ab971c29a56a4c24359b499d05c30c8c9fc4dea3
DIFF: 
https://github.com/llvm/llvm-project/commit/ab971c29a56a4c24359b499d05c30c8c9fc4dea3.diff

LOG: [flang][driver] Add options for -fdefault* and -flarge-sizes

Add support for the following Fortran dialect options:
  - -default*
  - -flarge-sizes

It also adds two test cases:
  # For checking whether `flang-new` is passing options correctly to `flang-new 
-fc1`.
  # For checking if `fdefault-` arguments are processed properly.

Also moves the Dialect related option parsing to a dedicated function
and adds a member `defaultKinds()` to `CompilerInvocation`

Depends on: D96032

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

Added: 
flang/test/Flang-Driver/fdefault.f90
flang/test/Flang-Driver/flarge_sizes.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/frontend-forwarding.f90
flang/unittests/Frontend/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2f57895d4c23..583d08151e1a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4238,9 +4238,6 @@ defm check_array_temporaries : 
BooleanFFlag<"check-array-temporaries">, Group, Group;
 defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group;
 defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, 
Group;
-defm default_double_8 : BooleanFFlag<"default-double-8">, 
Group;
-defm default_integer_8 : BooleanFFlag<"default-integer-8">, 
Group;
-defm default_real_8 : BooleanFFlag<"default-real-8">, Group;
 defm dollar_ok : BooleanFFlag<"dollar-ok">, Group;
 defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, 
Group;
 defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, 
Group;
@@ -4307,6 +4304,14 @@ file}]>;
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
 def fopenacc : Flag<["-"], "fopenacc">, Group,
   HelpText<"Enable OpenACC">;
+def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group,
+  HelpText<"Set the default double precision kind to an 8 byte wide type">;
+def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group,
+  HelpText<"Set the default integer kind to an 8 byte wide type">;
+def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
+  HelpText<"Set the default real kind to an 8 byte wide type">;
+def flarge_sizes : Flag<["-"],"flarge-sizes">, Group,
+  HelpText<"Use INTEGER(KIND=8) for the result type in size-related 
intrinsics">;
 def fbackslash : Flag<["-"], "fbackslash">, Group,
   HelpText<"Specify that backslash in string introduces an escape character">,
   DocBrief<[{Change the interpretation of backslashes in string literals from

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b79b94a11956..1a812589d473 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -21,16 +21,18 @@ using namespace llvm::opt;
 
 void Flang::AddFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  Args.AddAllArgs(CmdArgs,
-  {options::OPT_ffixed_form, options::OPT_ffree_form,
-   options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
-   options::OPT_fopenacc, options::OPT_finput_charset_EQ,
-   options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
-   options::OPT_fbackslash, options::OPT_fno_backslash,
-   options::OPT_flogical_abbreviations,
-   options::OPT_fno_logical_abbreviations,
-   options::OPT_fxor_operator, options::OPT_fno_xor_operator,
-   options::OPT_falternative_parameter_statement});
+  Args.AddAllArgs(
+  CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
+options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
+options::OPT_fopenacc, options::OPT_finput_charset_EQ,
+options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
+options::OPT_fbackslash, options::OPT_fno_backslash,
+options::OPT_flogical_abbreviations,
+options::OPT_fno_logical_abbreviations,
+options::OPT_fxor_operator, options::OPT_fno_xor_operator,
+options::OPT_falternative_parameter_statement,
+options::OPT_fdefault_real_

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-03-04 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab971c29a56a: [flang][driver] Add options for -fdefault* and 
-flarge-sizes (authored by arnamoy10, committed by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D96344?vs=327789&id=328138#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/flarge_sizes.f90
  flang/test/Flang-Driver/frontend-forwarding.f90
  flang/unittests/Frontend/CMakeLists.txt

Index: flang/unittests/Frontend/CMakeLists.txt
===
--- flang/unittests/Frontend/CMakeLists.txt
+++ flang/unittests/Frontend/CMakeLists.txt
@@ -10,4 +10,5 @@
   flangFrontendTool
   FortranParser
   FortranSemantics
+  FortranCommon
 )
Index: flang/test/Flang-Driver/frontend-forwarding.f90
===
--- flang/test/Flang-Driver/frontend-forwarding.f90
+++ flang/test/Flang-Driver/frontend-forwarding.f90
@@ -5,6 +5,14 @@
 
 ! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
 ! RUN: -finput-charset=utf-8 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
 ! RUN:   | FileCheck %s
 
 ! CHECK: "-finput-charset=utf-8"
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
Index: flang/test/Flang-Driver/flarge_sizes.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/flarge_sizes.f90
@@ -0,0 +1,36 @@
+! Ensure argument -flarge-sizes works as expected.
+! TODO: Add checks when actual codegen is possible.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! EXPECTED OUTPUT WITHOUT -flarge-sizes
+!-
+! NOLARGE: real(4)::z(1_8:10_8)
+! NOLARGE-NEXT: integer(4),parameter::size_kind=4_4
+
+!-
+! EXPECTED OUTPUT FOR -flarge-sizes
+!-
+! LARGE: real(4)::z(1_8:10_8)
+! LARGE-NEXT: integer(4),parameter::size_kind=8_4
+
+module m
+  implicit none
+  real :: z(10)
+  integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
+end
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,58 @@
+! Ensure argument -fdefault* work as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
+! RUN: not %flang -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=ERROR
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-

[PATCH] D97889: [clang-tidy] Fix assert in modernize-loop-convert

2021-03-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:316-317
 return nullptr;
+  if (!Member->getMemberDecl()->getDeclName().isIdentifier())
+return nullptr;
   StringRef Name = Member->getMemberDecl()->getName();

It's really strange to me that we're even getting to this point in the check -- 
the only way for the assertion to fail is for the member call expression to be 
on something without a name. The cases I can think of for that would be 
something like `foo.operator+(RHS)` or something similarly nonsensical within 
this context (we're looking for things named `begin` or `end`). I think it'd 
make more sense to handle this at the matcher level (or early in the call 
chain) so that we never get here.

I think having a test case would be really useful to trying to understand what 
changes are appropriate. I don't think these changes are wrong so much as I 
wonder if we're in the wrong place to make them (and we'll hit other confused 
code elsewhere).



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:549
 const auto *AliasVar = cast(AliasDecl->getSingleDecl());
+assert(AliasVar->getDeclName().isIdentifier());
 VarName = AliasVar->getName().str();

This doesn't seem necessary? Calling `NamedDecl::getName()` already asserts 
that the name is an identifier.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97889/new/

https://reviews.llvm.org/D97889

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97940: [clang-tidy] Extend LoopConvert on array with `!=` comparison

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh.
Herald added a subscriber: xazax.hun.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Enables transforming loops of the form:

  for (int i = 0; I != container.size(); ++I) { container[I]...; }
  for (int i = 0; I != N; ++I) { FixedArrSizeN[I]...; }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97940

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp
@@ -95,6 +95,33 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & Tea : Teas)
   // CHECK-FIXES-NEXT: Tea.g();
+
+  for (int I = 0; N > I; ++I) {
+printf("Fibonacci number %d has address %p\n", Arr[I], &Arr[I]);
+Sum += Arr[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : Arr)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0; N != I; ++I) {
+printf("Fibonacci number %d has address %p\n", Arr[I], &Arr[I]);
+Sum += Arr[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : Arr)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0; I != N; ++I) {
+printf("Fibonacci number %d has address %p\n", Arr[I], &Arr[I]);
+Sum += Arr[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : Arr)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
 }
 
 const int *constArray() {
@@ -589,6 +616,33 @@
   // CHECK-FIXES: for (int I : *Cv)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = V.size(); E > I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = V.size(); I != E; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = V.size(); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -83,6 +83,17 @@
   return declRefExpr(to(varDecl(equalsBoundNode(InitVarName;
 }
 
+static StatementMatcher
+arrayConditionMatcher(internal::Matcher LimitExpr) {
+  return binaryOperator(
+  anyOf(allOf(hasOperatorName("<"), hasLHS(integerComparisonMatcher()),
+  hasRHS(LimitExpr)),
+allOf(hasOperatorName(">"), hasLHS(LimitExpr),
+  hasRHS(integerComparisonMatcher())),
+allOf(hasOperatorName("!="),
+  hasOperands(integerComparisonMatcher(), LimitExpr;
+}
+
 /// The matcher for loops over arrays.
 /// \code
 ///   for (int i = 0; i < 3 + 2; ++i) { ... }
@@ -99,18 +110,12 @@
   StatementMatcher ArrayBoundMatcher =
   expr(hasType(isInteger())).bind(ConditionBoundName);
 
-  return forStmt(
- unless(isInTemplateInstantiation()),
- hasLoopInit(declStmt(hasSingleDecl(initToZeroMatcher(,
- hasCondition(anyOf(
- binaryOperator(hasOperatorName("<"),
-hasLHS(integerComparisonMatcher()),
-hasRHS(ArrayBoundMatcher)),
- binaryOperator(hasOperatorName(">"), hasLHS(ArrayBoundMatcher),
-   

[PATCH] D97889: [clang-tidy] Fix assert in modernize-loop-convert

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:316-317
 return nullptr;
+  if (!Member->getMemberDecl()->getDeclName().isIdentifier())
+return nullptr;
   StringRef Name = Member->getMemberDecl()->getName();

aaron.ballman wrote:
> It's really strange to me that we're even getting to this point in the check 
> -- the only way for the assertion to fail is for the member call expression 
> to be on something without a name. The cases I can think of for that would be 
> something like `foo.operator+(RHS)` or something similarly nonsensical within 
> this context (we're looking for things named `begin` or `end`). I think it'd 
> make more sense to handle this at the matcher level (or early in the call 
> chain) so that we never get here.
> 
> I think having a test case would be really useful to trying to understand 
> what changes are appropriate. I don't think these changes are wrong so much 
> as I wonder if we're in the wrong place to make them (and we'll hit other 
> confused code elsewhere).
It is very strange. At the matcher level we are looking for calls to methods 
named `begin` or `end` or (c/r) variants. 
I'm gonna try and put some debug prints and see if I can figure out the code 
actually causing the assert in the first place.

In the mean time, I have a patch in the works that moves a lot of the logic 
into the matchers and this whole function is removed in there, however a few 
creases still need to be ironed out in there.



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:549
 const auto *AliasVar = cast(AliasDecl->getSingleDecl());
+assert(AliasVar->getDeclName().isIdentifier());
 VarName = AliasVar->getName().str();

aaron.ballman wrote:
> This doesn't seem necessary? Calling `NamedDecl::getName()` already asserts 
> that the name is an identifier.
I put that in there to figure out which `getName` assertion was firing as the 
call stack was optimized away on RelWithAssert builds. Probably can be removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97889/new/

https://reviews.llvm.org/D97889

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97941: [Reland] "Do not apply calling conventions to MSVC entry points"

2021-03-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, akhuang, dmajor.
Herald added a subscriber: mstorsjo.
eandrews requested review of this revision.

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.

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: 4cff1b40dacf6 
 
(https://reviews.llvm.org/D87701)
Revert of first attempt: bebfc3b92d5e8 



https://reviews.llvm.org/D97941

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/default_calling_conv.cpp

Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WINDOWS
+// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2  -emit-llvm -o - %s -DEXPLICITCC | FileCheck %s --check-prefix=EXPLICITCC
 
 // CDECL: define{{.*}} void @_Z5test1v
 // FASTCALL: define{{.*}} x86_fastcallcc void @_Z5test1v
@@ -50,3 +52,41 @@
 int main() {
   return 1;
 }
+
+#ifdef WINDOWS
+// WINDOWS: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+// WINDOWS: define dso_local x86_stdcallcc i32 @WinMain
+int WinMain() {
+  return 1;
+}
+// WINDOWS: define dso_local x86_stdcallcc i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+// WINDOWS: define dso_local x86_stdcallcc i32 @DllMain
+int DllMain() {
+  return 1;
+}
+#endif // Windows
+
+#ifdef EXPLICITCC
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @wmain
+int __fastcall wmain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @WinMain
+int __fastcall WinMain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @wWinMain
+int __fastcall wWinMain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @DllMain
+int __fastcall DllMain() {
+  return 1;
+}
+#endif // ExplicitCC
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11169,6 +11169,17 @@
   }
 }
 
+static bool isDefaultCDecl(FunctionDecl *FD, Sema &S) {
+  // Default calling convention for MinGW is __cdecl
+  const llvm::Triple &T = S.Context.getTargetInfo().getTriple();
+  if (T.isWindowsGNUEnvironment())
+return true;
+
+  return llvm::StringSwitch(FD->getName())
+  .Cases("main", "wmain", true)
+  .Default(false);
+}
+
 void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
   QualType T = FD->getType();
   assert(T->isFunctionType() && "function decl is not of function type");
@@ -11183,6 +11194,23 @@
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  // Explicity specified calling conventions are applied to MSVC entry points
+  if (!hasExplicitCallingConv(T)) {
+if (isDefaultCDecl(FD, *this)) {
+  if (FT->getCallConv() != CC_C) {
+FT = Context.adjustFunctionType(FT,
+FT->getExtInfo().withCallingConv(CC_C));
+FD->setType(QualType(FT, 0));
+  }
+} else if (FT->getCallConv() != CC_X86StdCall) {
+  // Default calling convention for WinMain, wWinMain and DllMain is
+  // __stdcall
+  FT = Context.adjustFunctionType(
+  FT, FT->getExtInfo().withCallingConv(CC_X86StdCall));
+  FD->setType(QualType(FT, 0));
+}
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fe5c2c3 - Revert "[Coverage] Emit gap region between statements if first statements contains terminate statements."

2021-03-04 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-03-04T08:53:30-05:00
New Revision: fe5c2c3ca682b140dd5e640e75948363b6b25ef9

URL: 
https://github.com/llvm/llvm-project/commit/fe5c2c3ca682b140dd5e640e75948363b6b25ef9
DIFF: 
https://github.com/llvm/llvm-project/commit/fe5c2c3ca682b140dd5e640e75948363b6b25ef9.diff

LOG: Revert "[Coverage] Emit gap region between statements if first statements 
contains terminate statements."

This reverts commit 2d7374a0c680f96bdcdb3d05034a93bf145d140f.
Breaks ContinuousSyncMode/basic.c in check-profile on macOS.

Added: 
clang/test/CoverageMapping/deferred-region.cpp

Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/break.c
clang/test/CoverageMapping/classtemplate.cpp
clang/test/CoverageMapping/continue.c
clang/test/CoverageMapping/coroutine.cpp
clang/test/CoverageMapping/label.cpp
clang/test/CoverageMapping/return.c
clang/test/CoverageMapping/switch.cpp
clang/test/CoverageMapping/switchmacro.c
clang/test/CoverageMapping/trycatch.cpp
clang/test/CoverageMapping/unreachable-macro.c
compiler-rt/test/profile/ContinuousSyncMode/runtime-counter-relocation.c

Removed: 
clang/test/CoverageMapping/terminate-statements.cpp



diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 8a11da600e4a..4a008b4ef632 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -104,21 +104,26 @@ class SourceMappingRegion {
   /// The region's ending location.
   Optional LocEnd;
 
+  /// Whether this region should be emitted after its parent is emitted.
+  bool DeferRegion;
+
   /// Whether this region is a gap region. The count from a gap region is set
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
 public:
   SourceMappingRegion(Counter Count, Optional LocStart,
-  Optional LocEnd, bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  Optional LocEnd, bool DeferRegion = 
false,
+  bool GapRegion = false)
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd),
+DeferRegion(DeferRegion), GapRegion(GapRegion) {}
 
   SourceMappingRegion(Counter Count, Optional FalseCount,
   Optional LocStart,
-  Optional LocEnd, bool GapRegion = false)
+  Optional LocEnd, bool DeferRegion = 
false,
+  bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), LocStart(LocStart),
-LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocEnd(LocEnd), DeferRegion(DeferRegion), GapRegion(GapRegion) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -150,6 +155,10 @@ class SourceMappingRegion {
 return *LocEnd;
   }
 
+  bool isDeferred() const { return DeferRegion; }
+
+  void setDeferred(bool Deferred) { DeferRegion = Deferred; }
+
   bool isGap() const { return GapRegion; }
 
   void setGap(bool Gap) { GapRegion = Gap; }
@@ -535,6 +544,10 @@ struct CounterCoverageMappingBuilder
   /// A stack of currently live regions.
   std::vector RegionStack;
 
+  /// The currently deferred region: its end location and count can be set once
+  /// its parent has been popped from the region stack.
+  Optional DeferredRegion;
+
   CounterExpressionBuilder Builder;
 
   /// A location in the most recently visited file or macro.
@@ -543,11 +556,8 @@ struct CounterCoverageMappingBuilder
   /// expressions cross file or macro boundaries.
   SourceLocation MostRecentLocation;
 
-  /// Whether the visitor at a terminate statement.
-  bool HasTerminateStmt = false;
-
-  /// Gap region counter after terminate statement.
-  Counter GapRegionCounter;
+  /// Location of the last terminated region.
+  Optional> LastTerminatedRegion;
 
   /// Return a counter for the subtraction of \c RHS from \c LHS
   Counter subtractCounters(Counter LHS, Counter RHS) {
@@ -580,13 +590,77 @@ struct CounterCoverageMappingBuilder
 
 if (StartLoc && !FalseCount.hasValue()) {
   MostRecentLocation = *StartLoc;
+  completeDeferred(Count, MostRecentLocation);
 }
 
-RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
+RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc,
+ FalseCount.hasValue());
 
 return RegionStack.size() - 1;
   }
 
+  /// Complete any pending deferred region by setting its end location and
+  /// count, and then pushing it onto the region stack.
+  size_t completeDeferred(Counter Count, SourceLocation DeferredEndLoc) {
+size_t Index = RegionStack.size();
+if (!DeferredRegion)
+  return Index;
+
+// Consume the pending region.
+SourceMappingRegion DR = DeferredRegion.getValue();
+DeferredRegion = None;
+
+// If t

[PATCH] D96760: [clang-format] Suppress diagnostics on second parse

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

LGTM, but see what @MyDeveloperDay has to say.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96760/new/

https://reviews.llvm.org/D96760

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97101: [Coverage] Emit gap region between statements if first statements contains terminate statements.

2021-03-04 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This broke ContinuousSyncMode/basic.c in check-profile on macOS (see e.g. end 
of 
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8853690069583264896/+/steps/package_clang/0/stdout?format=raw),
 so I reverted it for now.

It repros on my laptop, so let me know if you want me to try things :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97101/new/

https://reviews.llvm.org/D97101

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97936: [analyzer][docs][NFC] Fix typo in checkers.rst

2021-03-04 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Neat!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97936/new/

https://reviews.llvm.org/D97936

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97849: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member

2021-03-04 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 328149.
martong added a comment.
Herald added a reviewer: Szelethus.

Add a test case which fails if lit --vg is used.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97849/new/

https://reviews.llvm.org/D97849

Files:
  clang/include/clang/AST/Stmt.h
  clang/test/Analysis/Inputs/ctu-other.c
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/ctu-main.c


Index: clang/test/Analysis/ctu-main.c
===
--- clang/test/Analysis/ctu-main.c
+++ clang/test/Analysis/ctu-main.c
@@ -69,3 +69,8 @@
   d.b = 0;
   clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} 
expected-warning{{FALSE}}
 }
+
+int switchWithoutCases(int);
+void testSwitchStmtCrash(int x) {
+  switchWithoutCases(x);
+}
Index: clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
===
--- clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
+++ clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
@@ -4,3 +4,4 @@
 c:@F@enumCheck ctu-other.c.ast
 c:@F@identImplicit ctu-other.c.ast
 c:@F@structInProto ctu-other.c.ast
+c:@F@switchWithoutCases ctu-other.c.ast
Index: clang/test/Analysis/Inputs/ctu-other.c
===
--- clang/test/Analysis/Inputs/ctu-other.c
+++ clang/test/Analysis/Inputs/ctu-other.c
@@ -49,3 +49,9 @@
 int structInProto(struct DataType {int a;int b; } * d) {
   return 0;
 }
+
+int switchWithoutCases(int x) {
+  switch (x) {
+  };
+  return 0;
+}
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -2119,7 +2119,7 @@
   friend TrailingObjects;
 
   /// Points to a linked list of case and default statements.
-  SwitchCase *FirstCase;
+  SwitchCase *FirstCase = nullptr;
 
   // SwitchStmt is followed by several trailing objects,
   // some of which optional. Note that it would be more convenient to


Index: clang/test/Analysis/ctu-main.c
===
--- clang/test/Analysis/ctu-main.c
+++ clang/test/Analysis/ctu-main.c
@@ -69,3 +69,8 @@
   d.b = 0;
   clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}
 }
+
+int switchWithoutCases(int);
+void testSwitchStmtCrash(int x) {
+  switchWithoutCases(x);
+}
Index: clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
===
--- clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
+++ clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
@@ -4,3 +4,4 @@
 c:@F@enumCheck ctu-other.c.ast
 c:@F@identImplicit ctu-other.c.ast
 c:@F@structInProto ctu-other.c.ast
+c:@F@switchWithoutCases ctu-other.c.ast
Index: clang/test/Analysis/Inputs/ctu-other.c
===
--- clang/test/Analysis/Inputs/ctu-other.c
+++ clang/test/Analysis/Inputs/ctu-other.c
@@ -49,3 +49,9 @@
 int structInProto(struct DataType {int a;int b; } * d) {
   return 0;
 }
+
+int switchWithoutCases(int x) {
+  switch (x) {
+  };
+  return 0;
+}
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -2119,7 +2119,7 @@
   friend TrailingObjects;
 
   /// Points to a linked list of case and default statements.
-  SwitchCase *FirstCase;
+  SwitchCase *FirstCase = nullptr;
 
   // SwitchStmt is followed by several trailing objects,
   // some of which optional. Note that it would be more convenient to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2e90fc2 - [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member

2021-03-04 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-03-04T15:10:04+01:00
New Revision: 2e90fc2c407bb9a85e14fa2c75533a984e5a765a

URL: 
https://github.com/llvm/llvm-project/commit/2e90fc2c407bb9a85e14fa2c75533a984e5a765a
DIFF: 
https://github.com/llvm/llvm-project/commit/2e90fc2c407bb9a85e14fa2c75533a984e5a765a.diff

LOG: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member

The SwitchStmt::FirstCase member is not initialized when the AST is
built by the ASTStmtReader. See the below code of
ASTStmtReader::VisitSwitchStmt in the case where the for loop does not
have any iterations:
```
// ... more code ...
SwitchCase *PrevSC = nullptr;
for (auto E = Record.size(); Record.getIdx() != E; ) {
  SwitchCase *SC = Record.getSwitchCaseWithID(Record.readInt());
  if (PrevSC)
PrevSC->setNextSwitchCase(SC);
  else
S->setSwitchCaseList(SC); // Sets FirstCase !!!

  PrevSC = SC;
}
  } // return
```
Later, in ASTNodeImporter::VisitSwitchStmt,
we have a condition that depends on this uninited value:
```
  for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
   SC = SC->getNextSwitchCase()) {
   // ... more code ...
  }

```
This is clearly an UB. This causes non-deterministic crashes when
ClangSA analyzes some code with CTU. See the below report by valgrind
(the whole valgrind output is attached):
```
==31019== Conditional jump or move depends on uninitialised value(s)
==31019==at 0x12ED1983: 
clang::ASTNodeImporter::VisitSwitchStmt(clang::SwitchStmt*) 
(ASTImporter.cpp:6195)
==31019==by 0x12F1D509: clang::StmtVisitorBase>::Visit(clang::Stmt*) 
(StmtNodes.inc:591)
==31019==by 0x12EE4FDF: clang::ASTImporter::Import(clang::Stmt*) 
(ASTImporter.cpp:8484)
==31019==by 0x12F09498: llvm::Expected 
clang::ASTNodeImporter::import(clang::Stmt*) (ASTImporter.cpp:164)
==31019==by 0x12F3A1F5: llvm::Error 
clang::ASTNodeImporter::ImportArrayChecked(clang::Stmt**, clang::Stmt**, clang::Stmt**) 
(ASTImporter.cpp:653)
==31019==by 0x12F13152: llvm::Error 
clang::ASTNodeImporter::ImportContainerChecked,
 llvm::SmallVector >(llvm::iterator_range 
const&, llvm::SmallVector&) (ASTImporter.cpp:669)
==31019==by 0x12ED099F: 
clang::ASTNodeImporter::VisitCompoundStmt(clang::CompoundStmt*) 
(ASTImporter.cpp:6077)
==31019==by 0x12F1CC2D: clang::StmtVisitorBase>::Visit(clang::Stmt*) 
(StmtNodes.inc:73)
==31019==by 0x12EE4FDF: clang::ASTImporter::Import(clang::Stmt*) 
(ASTImporter.cpp:8484)
==31019==by 0x12F09498: llvm::Expected 
clang::ASTNodeImporter::import(clang::Stmt*) (ASTImporter.cpp:164)
==31019==by 0x12F13275: clang::Stmt* 
clang::ASTNodeImporter::importChecked(llvm::Error&, clang::Stmt* 
const&) (ASTImporter.cpp:197)
==31019==by 0x12ED0CE6: 
clang::ASTNodeImporter::VisitCaseStmt(clang::CaseStmt*) (ASTImporter.cpp:6098)
```

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

Added: 


Modified: 
clang/include/clang/AST/Stmt.h
clang/test/Analysis/Inputs/ctu-other.c
clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
clang/test/Analysis/ctu-main.c

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index c2e69a91e55d..2085904b7f01 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -2119,7 +2119,7 @@ class SwitchStmt final : public Stmt,
   friend TrailingObjects;
 
   /// Points to a linked list of case and default statements.
-  SwitchCase *FirstCase;
+  SwitchCase *FirstCase = nullptr;
 
   // SwitchStmt is followed by several trailing objects,
   // some of which optional. Note that it would be more convenient to

diff  --git a/clang/test/Analysis/Inputs/ctu-other.c 
b/clang/test/Analysis/Inputs/ctu-other.c
index 16ebb3506f60..48a3f322cbd5 100644
--- a/clang/test/Analysis/Inputs/ctu-other.c
+++ b/clang/test/Analysis/Inputs/ctu-other.c
@@ -49,3 +49,9 @@ int identImplicit(int in) {
 int structInProto(struct DataType {int a;int b; } * d) {
   return 0;
 }
+
+int switchWithoutCases(int x) {
+  switch (x) {
+  };
+  return 0;
+}

diff  --git 
a/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt 
b/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
index 9abaa501a4cb..a6de9304551b 100644
--- a/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
+++ b/clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
@@ -4,3 +4,4 @@ c:@F@f ctu-other.c.ast
 c:@F@enumCheck ctu-other.c.ast
 c:@F@identImplicit ctu-other.c.ast
 c:@F@structInProto ctu-other.c.ast
+c:@F@switchWithoutCases ctu-other.c.ast

diff  --git a/clang/test/Analysis/ctu-main.c b/clang/test/Analysis/ctu-main.c
index d991eb73a95c..1415490668ba 100644
--- a/clang/test/Analysis/ctu-main.c
+++ b/clang/test/Analysis/ctu-main.c
@@ -69,3 +69,8 @@ void testStructDefInArgument() {
   d.b = 0;
   clang_analyzer_eval(structInProto(&d) == 0); // exp

[PATCH] D97849: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member

2021-03-04 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e90fc2c407b: [AST][PCH][ASTImporter] Fix UB caused by 
uninited SwitchStmt member (authored by martong).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97849/new/

https://reviews.llvm.org/D97849

Files:
  clang/include/clang/AST/Stmt.h
  clang/test/Analysis/Inputs/ctu-other.c
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/ctu-main.c


Index: clang/test/Analysis/ctu-main.c
===
--- clang/test/Analysis/ctu-main.c
+++ clang/test/Analysis/ctu-main.c
@@ -69,3 +69,8 @@
   d.b = 0;
   clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} 
expected-warning{{FALSE}}
 }
+
+int switchWithoutCases(int);
+void testSwitchStmtCrash(int x) {
+  switchWithoutCases(x);
+}
Index: clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
===
--- clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
+++ clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
@@ -4,3 +4,4 @@
 c:@F@enumCheck ctu-other.c.ast
 c:@F@identImplicit ctu-other.c.ast
 c:@F@structInProto ctu-other.c.ast
+c:@F@switchWithoutCases ctu-other.c.ast
Index: clang/test/Analysis/Inputs/ctu-other.c
===
--- clang/test/Analysis/Inputs/ctu-other.c
+++ clang/test/Analysis/Inputs/ctu-other.c
@@ -49,3 +49,9 @@
 int structInProto(struct DataType {int a;int b; } * d) {
   return 0;
 }
+
+int switchWithoutCases(int x) {
+  switch (x) {
+  };
+  return 0;
+}
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -2119,7 +2119,7 @@
   friend TrailingObjects;
 
   /// Points to a linked list of case and default statements.
-  SwitchCase *FirstCase;
+  SwitchCase *FirstCase = nullptr;
 
   // SwitchStmt is followed by several trailing objects,
   // some of which optional. Note that it would be more convenient to


Index: clang/test/Analysis/ctu-main.c
===
--- clang/test/Analysis/ctu-main.c
+++ clang/test/Analysis/ctu-main.c
@@ -69,3 +69,8 @@
   d.b = 0;
   clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}
 }
+
+int switchWithoutCases(int);
+void testSwitchStmtCrash(int x) {
+  switchWithoutCases(x);
+}
Index: clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
===
--- clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
+++ clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
@@ -4,3 +4,4 @@
 c:@F@enumCheck ctu-other.c.ast
 c:@F@identImplicit ctu-other.c.ast
 c:@F@structInProto ctu-other.c.ast
+c:@F@switchWithoutCases ctu-other.c.ast
Index: clang/test/Analysis/Inputs/ctu-other.c
===
--- clang/test/Analysis/Inputs/ctu-other.c
+++ clang/test/Analysis/Inputs/ctu-other.c
@@ -49,3 +49,9 @@
 int structInProto(struct DataType {int a;int b; } * d) {
   return 0;
 }
+
+int switchWithoutCases(int x) {
+  switch (x) {
+  };
+  return 0;
+}
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -2119,7 +2119,7 @@
   friend TrailingObjects;
 
   /// Points to a linked list of case and default statements.
-  SwitchCase *FirstCase;
+  SwitchCase *FirstCase = nullptr;
 
   // SwitchStmt is followed by several trailing objects,
   // some of which optional. Note that it would be more convenient to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97849: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member

2021-03-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks for the review!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97849/new/

https://reviews.llvm.org/D97849

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93031: Enable fexec-charset option

2021-03-04 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 328151.
abhina.sreeskantharajan added a comment.

Addressing some more comments. Updating the argument parsing, lit tests, some 
more renaming.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93031/new/

https://reviews.llvm.org/D93031

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/LiteralConverter.h
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Lex/LiteralConverter.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CodeGen/systemz-charset.c
  clang/test/CodeGen/systemz-charset.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/clang_f_opts.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1038,6 +1038,13 @@
   return Tmp.split('-').second;  // Strip second component
 }
 
+// System charset on z/OS is IBM-1047 and UTF-8 otherwise
+StringRef Triple::getSystemCharset() const {
+  if (getOS() == llvm::Triple::ZOS)
+return "IBM-1047";
+  return "UTF-8";
+}
+
 static unsigned EatNumber(StringRef &Str) {
   assert(!Str.empty() && isDigit(Str[0]) && "Not a number");
   unsigned Result = 0;
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -395,6 +395,9 @@
   /// if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// getSystemCharset - Get the system charset of the triple.
+  StringRef getSystemCharset() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -209,8 +209,14 @@
 // RUN: %clang -### -S -finput-charset=iso-8859-1 -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-CHARSET %s
 // CHECK-INVALID-CHARSET: error: invalid value 'iso-8859-1' in '-finput-charset=iso-8859-1'
 
-// RUN: %clang -### -S -fexec-charset=iso-8859-1 -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-INPUT-CHARSET %s
-// CHECK-INVALID-INPUT-CHARSET: error: invalid value 'iso-8859-1' in '-fexec-charset=iso-8859-1'
+// RUN: %clang -### -S -fexec-charset=invalid-charset -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-INPUT-CHARSET %s
+// CHECK-INVALID-INPUT-CHARSET: error: invalid value 'invalid-charset' in '-fexec-charset=invalid-charset'
+
+// Test that we support the following exec charsets.
+// RUN: %clang -### -S -fexec-charset=UTF-8 -o /dev/null %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// RUN: %clang -### -S -fexec-charset=ISO8859-1 -o /dev/null %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// RUN: %clang -### -S -fexec-charset=IBM-1047 -o /dev/null %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// INVALID-NOT: error: invalid value
 
 // Test that we don't error on these.
 // RUN: %clang -### -S -Werror\
@@ -224,7 +230,7 @@
 // RUN: -fident -fno-ident\
 // RUN: -fimplicit-templates -fno-implicit-templates  \
 // RUN: -finput-charset=UTF-8 \
-// RUN: -fexec-charset=UTF-8 \
+// RUN: -fexec-charset=UTF-8  \
 // RUN: -fivopts -fno-ivopts  \
 // RUN: -fnon-call-exceptions -fno-non-call-exceptions\
 // RUN: -fpermissive -fno-permissive  \
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -209,10 +209,11 @@
 // RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=source-charset-utf-16 %s
 // source-charset-utf-16: invalid value 'utf-16' in '/source-charset:utf-16'
 
-// /execution-charset: should warn on everything except UTF-8.
-// RUN: %clang_cl /execution-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-utf-16 %s
-// execution-charset-utf-16: invalid value 'utf-16' in '/execution-charset:utf-16'
+// /execution-charset: should warn on invalid charsets.
+// RUN: %clang_cl /execution-charset:invalid-charset -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-invalid %s
+// execution-charset-invalid: in

[PATCH] D93031: Enable fexec-charset option

2021-03-04 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan marked 4 inline comments as done.
abhina.sreeskantharajan added inline comments.



Comment at: clang/include/clang/Lex/Preprocessor.h:145
   ModuleLoader  &TheModuleLoader;
+  LiteralConverter  LT;
 

rsmith wrote:
> Please give this a longer name. Abbreviation names should only be used in 
> fairly small scopes where it's easy to look up what they refer to.
> 
> Also: why `LT`? What does the `T` stand for?
Thanks for catching this. This was a change I missed when renaming 
LiteralTranslator to LiteralConverter. I've added a longer name.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6178
+  CmdArgs.push_back(Args.MakeArgString(Triple.getSystemCharset()));
+  for (auto it = vList.begin(), ie = vList.end(); it != ie; ++it) {
+llvm::ErrorOr ErrorOrConverter =

rsmith wrote:
> Looping over all the arguments is a little unusual. Normally we'd get the 
> last argument value and only check that one. Do you need to pass more than 
> one value onto the frontend?
Thanks, I've changed it back to get the LastArg only and use the spelling of 
the argument to fix the diagnostic error message in the driver lit tests.



Comment at: clang/lib/Lex/LiteralSupport.cpp:1363-1364
+  if (!HadError && Converter) {
+assert(Kind != tok::wide_char_constant &&
+   "Wide character translation not supported");
+SmallString<1> ConvertedChar;

rsmith wrote:
> Why is this case not possible?
This case should be handled when fwide-exec-charset option is implemented. 
Until then, we thought it was best to emit a error message that wide literal 
translation is not supported.



Comment at: clang/lib/Lex/LiteralSupport.cpp:234
+SmallString<8> ResultCharConv;
+Converter->convert(std::string(1, ByteChar), ResultCharConv);
+memcpy((void *)&ResultChar, ResultCharConv.data(), sizeof(unsigned));

rsmith wrote:
> abhina.sreeskantharajan wrote:
> > tahonermann wrote:
> > > Conversion can fail here, particularly in the scenario corresponding to 
> > > the default switch case above; `ResultChar` could contain, for example, a 
> > > lead byte of a UTF-8 sequence.  Something sensible should be done here; 
> > > either rejecting the code with an error or substituting `?` (in the 
> > > execution encoding) seems appropriate to me.
> > Thanks, I added the substitution with the '?' character for invalid escapes.
> This is a regression. Our prior behavior for unknown escapes was to leave the 
> character alone. We should still do that wherever possible -- eg, `\q` should 
> produce `q` -- and take fallback action only if the character is unencodable. 
> Producing a `?` seems unlikely to ever be what anyone wants; producing a hard 
> error would seem preferable.
Hi @tahonermann, do you also agree we should use the original behaviour or give 
a hard error instead?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93031/new/

https://reviews.llvm.org/D93031

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97889: [clang-tidy] Fix assert in modernize-loop-convert

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:316-317
 return nullptr;
+  if (!Member->getMemberDecl()->getDeclName().isIdentifier())
+return nullptr;
   StringRef Name = Member->getMemberDecl()->getName();

njames93 wrote:
> aaron.ballman wrote:
> > It's really strange to me that we're even getting to this point in the 
> > check -- the only way for the assertion to fail is for the member call 
> > expression to be on something without a name. The cases I can think of for 
> > that would be something like `foo.operator+(RHS)` or something similarly 
> > nonsensical within this context (we're looking for things named `begin` or 
> > `end`). I think it'd make more sense to handle this at the matcher level 
> > (or early in the call chain) so that we never get here.
> > 
> > I think having a test case would be really useful to trying to understand 
> > what changes are appropriate. I don't think these changes are wrong so much 
> > as I wonder if we're in the wrong place to make them (and we'll hit other 
> > confused code elsewhere).
> It is very strange. At the matcher level we are looking for calls to methods 
> named `begin` or `end` or (c/r) variants. 
> I'm gonna try and put some debug prints and see if I can figure out the code 
> actually causing the assert in the first place.
> 
> In the mean time, I have a patch in the works that moves a lot of the logic 
> into the matchers and this whole function is removed in there, however a few 
> creases still need to be ironed out in there.
So I put some debugprints in there and managed to find the cause of the crash
```
  // llvm/lib/Option/OptTable.cpp:150
  for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
   E = PrefixesUnion.end(); I != E; ++I) {
StringRef Prefix = I->getKey();
for (StringRef::const_iterator C = Prefix.begin(), CE = Prefix.end();
   C != CE; ++C)
  if (!is_contained(PrefixChars, *C))
PrefixChars.push_back(*C);
  }```
However I'm still not 100% sure of the cause of the crash. Its nothing to do 
with `begin()` being a member of the bast class StringMap. I tried testing with 
inherited begin/end methods and no crash.
My best guess is Prefix.begin() returns `StringMapIterator<>`, that class 
contains a conversion operator to `StringMapConstIterator<>`. Conversion 
operators names aren't Identifiers so that would explain the assert.
If that is the case, the actual issue is in `digThroughConstructors` being 
fooled by the `CXXMemberCallExpr` that's just a conversion operator.

The other patch in the works doesn't use that function so the bug is not 
present there, maybe its easier to just get that ready. WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97889/new/

https://reviews.llvm.org/D97889

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97945: [OPENMP]Fix PR48759: "fatal error" when compile with preprocessed file.

2021-03-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added reviewers: jdoerfert, mibintc.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

If the file in line directive does not exist on the system we need, to
use the original file to get its file id.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97945

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_unknown_file.cpp


Index: clang/test/OpenMP/target_unknown_file.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_unknown_file.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 
-emit-llvm -o - %s 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-NOT: fatal error: cannot open file
+
+// CHECK: call void @__omp_offloading_{{.+}}()
+# 1 "unknown."
+void a() {
+#pragma omp target
+  ;
+}
+
+// CHECK-NOT: fatal error: cannot open file
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@
   assert(PLoc.isValid() && "Source location is expected to be always valid.");
 
   llvm::sys::fs::UniqueID ID;
-  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
-SM.getDiagnostics().Report(diag::err_cannot_open_file)
-<< PLoc.getFilename() << EC.message();
+  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+PLoc = SM.getPresumedLoc(Loc, /*UseLineDirectives=*/false);
+assert(PLoc.isValid() && "Source location is expected to be always 
valid.");
+if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+  SM.getDiagnostics().Report(diag::err_cannot_open_file)
+  << PLoc.getFilename() << EC.message();
+  }
 
   DeviceID = ID.getDevice();
   FileID = ID.getFile();


Index: clang/test/OpenMP/target_unknown_file.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_unknown_file.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-NOT: fatal error: cannot open file
+
+// CHECK: call void @__omp_offloading_{{.+}}()
+# 1 "unknown."
+void a() {
+#pragma omp target
+  ;
+}
+
+// CHECK-NOT: fatal error: cannot open file
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@
   assert(PLoc.isValid() && "Source location is expected to be always valid.");
 
   llvm::sys::fs::UniqueID ID;
-  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
-SM.getDiagnostics().Report(diag::err_cannot_open_file)
-<< PLoc.getFilename() << EC.message();
+  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+PLoc = SM.getPresumedLoc(Loc, /*UseLineDirectives=*/false);
+assert(PLoc.isValid() && "Source location is expected to be always valid.");
+if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+  SM.getDiagnostics().Report(diag::err_cannot_open_file)
+  << PLoc.getFilename() << EC.message();
+  }
 
   DeviceID = ID.getDevice();
   FileID = ID.getFile();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97849: [AST][PCH][ASTImporter] Fix UB caused by uninited SwitchStmt member

2021-03-04 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

Sorry for the delay. Yes, I meant the `--vg` flag which is I think the only 
valid way to test this from your description. That it can't be 
deterministically tested without this (or in configurations that don't run 
valgrind) is fine IMHO.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97849/new/

https://reviews.llvm.org/D97849

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97945: [OPENMP]Fix PR48759: "fatal error" when compile with preprocessed file.

2021-03-04 Thread Melanie Blower via Phabricator via cfe-commits
mibintc accepted this revision.
mibintc added a comment.
This revision is now accepted and ready to land.

Thanks @ABataev !


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97945/new/

https://reviews.llvm.org/D97945

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97950: [clangd] Rename Module -> FeatureModule to avoid confusion. NFC

2021-03-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, mgorny.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

As pointed out in D96244 , "Module" is already 
pretty overloaded to refer
to clang and llvm modules. (And clangd deals directly with the former).

FeatureModule is a bit of a mouthful but it's pretty self-descriptive.
I think it might be better than "Component" which doesn't really capture
the "common interface" aspect - it's IMO confusing to refer to
"components" but exclude CDB for example.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97950

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/FeatureModule.cpp
  clang-tools-extra/clangd/FeatureModule.h
  clang-tools-extra/clangd/Module.cpp
  clang-tools-extra/clangd/Module.h
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -42,7 +42,7 @@
 Base = ClangdServer::optsForTest();
 // This is needed to we can test index-based operations like call hierarchy.
 Base.BuildDynamicSymbolIndex = true;
-Base.Modules = &Modules;
+Base.FeatureModules = &FeatureModules;
   }
 
   LSPClient &start() {
@@ -70,7 +70,7 @@
 
   MockFS FS;
   ClangdLSPServer::Options Opts;
-  ModuleSet Modules;
+  FeatureModuleSet FeatureModules;
 
 private:
   // Color logs so we can distinguish them from test output.
@@ -227,7 +227,7 @@
 }
 
 TEST_F(LSPTest, ModulesTest) {
-  class MathModule final : public Module {
+  class MathModule final : public FeatureModule {
 OutgoingNotification Changed;
 void initializeLSP(LSPBinder &Bind, const llvm::json::Object &ClientCaps,
llvm::json::Object &ServerCaps) override {
@@ -248,7 +248,7 @@
   [Reply(std::move(Reply)), Value(Value)]() mutable { Reply(Value); });
 }
   };
-  Modules.add(std::make_unique());
+  FeatureModules.add(std::make_unique());
 
   auto &Client = start();
   Client.notify("add", 2);
@@ -266,10 +266,10 @@
   return [&Out](llvm::Expected V) { Out.emplace(std::move(V)); };
 }
 
-TEST_F(LSPTest, ModulesThreadingTest) {
-  // A module that does its work on a background thread, and so exercises the
-  // block/shutdown protocol.
-  class AsyncCounter final : public Module {
+TEST_F(LSPTest, FeatureModulesThreadingTest) {
+  // A feature module that does its work on a background thread, and so
+  // exercises the block/shutdown protocol.
+  class AsyncCounter final : public FeatureModule {
 bool ShouldStop = false;
 int State = 0;
 std::deque> Queue; // null = increment, non-null = read.
@@ -347,19 +347,19 @@
 }
   };
 
-  Modules.add(std::make_unique());
+  FeatureModules.add(std::make_unique());
   auto &Client = start();
 
   Client.notify("increment", nullptr);
   Client.notify("increment", nullptr);
   Client.notify("increment", nullptr);
   EXPECT_THAT_EXPECTED(Client.call("sync", nullptr).take(), Succeeded());
-  EXPECT_EQ(3, Modules.get()->getSync());
+  EXPECT_EQ(3, FeatureModules.get()->getSync());
   // Throw some work on the queue to make sure shutdown blocks on it.
   Client.notify("increment", nullptr);
   Client.notify("increment", nullptr);
   Client.notify("increment", nullptr);
-  // And immediately shut down. Module destructor verifies that we blocked.
+  // And immediately shut down. FeatureModule destructor verifies we blocked.
 }
 
 } // namespace
Index: clang-tools-extra/clangd/FeatureModule.h
===
--- clang-tools-extra/clangd/FeatureModule.h
+++ clang-tools-extra/clangd/FeatureModule.h
@@ -1,4 +1,4 @@
-//===--- Module.h - Plugging features into clangd -*-C++-*-===//
+//===--- FeatureModule.h - Plugging features into clangd --*-C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATUREMODULE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATUREMODULE_H
 
 #include "support/Function.h"
 #include "support/Threading.h"
@@ -26,11 +26,11 @@
 class ThreadsafeFS;
 class TUScheduler;
 
-/// A Module contributes a vertical feature to clangd.
+/// A FeatureModule contributes a ve

[PATCH] D97950: [clangd] Rename Module -> FeatureModule to avoid confusion. NFC

2021-03-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I know we talked about names a bunch and i'm being a bit intransigent here.
Happy to go with Component if you think it's a better name, but wanted to see 
how this looks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97950/new/

https://reviews.llvm.org/D97950

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 711179b - [OPENMP]Fix PR48759: "fatal error" when compile with preprocessed file.

2021-03-04 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-03-04T07:26:57-08:00
New Revision: 711179b5816a65eccad22a7111494d609b899fb2

URL: 
https://github.com/llvm/llvm-project/commit/711179b5816a65eccad22a7111494d609b899fb2
DIFF: 
https://github.com/llvm/llvm-project/commit/711179b5816a65eccad22a7111494d609b899fb2.diff

LOG: [OPENMP]Fix PR48759:  "fatal error" when compile with preprocessed file.

If the file in line directive does not exist on the system we need, to
use the original file to get its file id.

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

Added: 
clang/test/OpenMP/target_unknown_file.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index d0876056268d..f9c79e6c95f5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@ static void getTargetEntryUniqueInfo(ASTContext &C, 
SourceLocation Loc,
   assert(PLoc.isValid() && "Source location is expected to be always valid.");
 
   llvm::sys::fs::UniqueID ID;
-  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
-SM.getDiagnostics().Report(diag::err_cannot_open_file)
-<< PLoc.getFilename() << EC.message();
+  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+PLoc = SM.getPresumedLoc(Loc, /*UseLineDirectives=*/false);
+assert(PLoc.isValid() && "Source location is expected to be always 
valid.");
+if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+  SM.getDiagnostics().Report(diag::err_cannot_open_file)
+  << PLoc.getFilename() << EC.message();
+  }
 
   DeviceID = ID.getDevice();
   FileID = ID.getFile();

diff  --git a/clang/test/OpenMP/target_unknown_file.cpp 
b/clang/test/OpenMP/target_unknown_file.cpp
new file mode 100644
index ..8700c74ea5de
--- /dev/null
+++ b/clang/test/OpenMP/target_unknown_file.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 
-emit-llvm -o - %s 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-NOT: fatal error: cannot open file
+
+// CHECK: call void @__omp_offloading_{{.+}}()
+# 1 "unknown."
+void a() {
+#pragma omp target
+  ;
+}
+
+// CHECK-NOT: fatal error: cannot open file



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97945: [OPENMP]Fix PR48759: "fatal error" when compile with preprocessed file.

2021-03-04 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG711179b5816a: [OPENMP]Fix PR48759:  "fatal error" 
when compile with preprocessed file. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97945/new/

https://reviews.llvm.org/D97945

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_unknown_file.cpp


Index: clang/test/OpenMP/target_unknown_file.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_unknown_file.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 
-emit-llvm -o - %s 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-NOT: fatal error: cannot open file
+
+// CHECK: call void @__omp_offloading_{{.+}}()
+# 1 "unknown."
+void a() {
+#pragma omp target
+  ;
+}
+
+// CHECK-NOT: fatal error: cannot open file
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@
   assert(PLoc.isValid() && "Source location is expected to be always valid.");
 
   llvm::sys::fs::UniqueID ID;
-  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
-SM.getDiagnostics().Report(diag::err_cannot_open_file)
-<< PLoc.getFilename() << EC.message();
+  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+PLoc = SM.getPresumedLoc(Loc, /*UseLineDirectives=*/false);
+assert(PLoc.isValid() && "Source location is expected to be always 
valid.");
+if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+  SM.getDiagnostics().Report(diag::err_cannot_open_file)
+  << PLoc.getFilename() << EC.message();
+  }
 
   DeviceID = ID.getDevice();
   FileID = ID.getFile();


Index: clang/test/OpenMP/target_unknown_file.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_unknown_file.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -emit-llvm -o - %s 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-NOT: fatal error: cannot open file
+
+// CHECK: call void @__omp_offloading_{{.+}}()
+# 1 "unknown."
+void a() {
+#pragma omp target
+  ;
+}
+
+// CHECK-NOT: fatal error: cannot open file
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1648,9 +1648,13 @@
   assert(PLoc.isValid() && "Source location is expected to be always valid.");
 
   llvm::sys::fs::UniqueID ID;
-  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
-SM.getDiagnostics().Report(diag::err_cannot_open_file)
-<< PLoc.getFilename() << EC.message();
+  if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+PLoc = SM.getPresumedLoc(Loc, /*UseLineDirectives=*/false);
+assert(PLoc.isValid() && "Source location is expected to be always valid.");
+if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+  SM.getDiagnostics().Report(diag::err_cannot_open_file)
+  << PLoc.getFilename() << EC.message();
+  }
 
   DeviceID = ID.getDevice();
   FileID = ID.getFile();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97125: Stop traping on sNaN in __builtin_isinf

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre updated this revision to Diff 328170.
thopre added a comment.

Fix isfinite logic


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97125/new/

https://reviews.llvm.org/D97125

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/strictfp_builtins.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/builtin_float_strictfp.c
  clang/test/CodeGen/strictfp_builtins.c

Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -55,18 +55,55 @@
   return;
 }
 
-// CHECK-LABEL: @test_isinf(
+// CHECK-LABEL: @test_fp16_isinf(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[D_ADDR:%.*]] = alloca double, align 8
-// CHECK-NEXT:store double [[D:%.*]], double* [[D_ADDR]], align 8
-// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
-// CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.fabs.f64(double [[TMP0]]) [[ATTR5]]
-// CHECK-NEXT:[[CMPINF:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP1]], double 0x7FF0, metadata !"oeq", metadata !"fpexcept.strict") [[ATTR4]]
-// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CMPINF]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[LD_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[LD_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[SHL1:%.*]] = shl i16 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i16 [[SHL1]], -2048
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:2]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_fp16_isinf(__fp16 h) {
+  P(isinf, (h));
+
+  return;
+}
+
+// CHECK-LABEL: @test_float_isinf(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca float, align 4
+// CHECK-NEXT:store float [[F:%.*]], float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load float, float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast float [[TMP0]] to i32
+// CHECK-NEXT:[[SHL1:%.*]] = shl i32 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[SHL1]], -16777216
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_float_isinf(float f) {
+  P(isinf, (f));
+
+  return;
+}
+
+// CHECK-LABEL: @test_double_isinf(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store double [[D:%.*]], double* [[LD_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[LD_ADDR]], align 8
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast double [[TMP0]] to i64
+// CHECK-NEXT:[[SHL1:%.*]] = shl i64 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i64 [[SHL1]], -9007199254740992
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
-void test_isinf(double d) {
+void test_double_isinf(double d) {
   P(isinf, (d));
 
   return;
@@ -83,7 +120,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = icmp slt i64 [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = select i1 [[TMP3]], i32 -1, i32 1
 // CHECK-NEXT:[[TMP5:%.*]] = select i1 [[ISINF]], i32 [[TMP4]], i32 0
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 [[TMP5]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[TMP5]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_isinf_sign(double d) {
@@ -102,7 +139,7 @@
 // CHECK-NEXT:[[TMP1:%.*]] = sub i16 [[#%u,0x7C00]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i16 [[TMP1]], 15
 // CHECK-NEXT:[[RES:%.*]] = zext i16 [[ISNAN]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
 void test_fp16_isnan(__fp16 h) {
@@ -120,7 +157,7 @@
 // CHECK-NEXT:[[ABS:%.*]] = and i32 [[BITCAST]], [[#%u,0x7FFF]]
 // CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[#%u,0x7F80]], [[ABS]]
 // CHECK-NEXT:[[ISNAN:%.*]] = lshr i32 [[TMP1]], 31
-// CHE

[PATCH] D97889: [clang-tidy] Fix assert in modernize-loop-convert

2021-03-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:316-317
 return nullptr;
+  if (!Member->getMemberDecl()->getDeclName().isIdentifier())
+return nullptr;
   StringRef Name = Member->getMemberDecl()->getName();

njames93 wrote:
> njames93 wrote:
> > aaron.ballman wrote:
> > > It's really strange to me that we're even getting to this point in the 
> > > check -- the only way for the assertion to fail is for the member call 
> > > expression to be on something without a name. The cases I can think of 
> > > for that would be something like `foo.operator+(RHS)` or something 
> > > similarly nonsensical within this context (we're looking for things named 
> > > `begin` or `end`). I think it'd make more sense to handle this at the 
> > > matcher level (or early in the call chain) so that we never get here.
> > > 
> > > I think having a test case would be really useful to trying to understand 
> > > what changes are appropriate. I don't think these changes are wrong so 
> > > much as I wonder if we're in the wrong place to make them (and we'll hit 
> > > other confused code elsewhere).
> > It is very strange. At the matcher level we are looking for calls to 
> > methods named `begin` or `end` or (c/r) variants. 
> > I'm gonna try and put some debug prints and see if I can figure out the 
> > code actually causing the assert in the first place.
> > 
> > In the mean time, I have a patch in the works that moves a lot of the logic 
> > into the matchers and this whole function is removed in there, however a 
> > few creases still need to be ironed out in there.
> So I put some debugprints in there and managed to find the cause of the crash
> ```
>   // llvm/lib/Option/OptTable.cpp:150
>   for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
>E = PrefixesUnion.end(); I != E; ++I) {
> StringRef Prefix = I->getKey();
> for (StringRef::const_iterator C = Prefix.begin(), CE = Prefix.end();
>C != CE; ++C)
>   if (!is_contained(PrefixChars, *C))
> PrefixChars.push_back(*C);
>   }```
> However I'm still not 100% sure of the cause of the crash. Its nothing to do 
> with `begin()` being a member of the bast class StringMap. I tried testing 
> with inherited begin/end methods and no crash.
> My best guess is Prefix.begin() returns `StringMapIterator<>`, that class 
> contains a conversion operator to `StringMapConstIterator<>`. Conversion 
> operators names aren't Identifiers so that would explain the assert.
> If that is the case, the actual issue is in `digThroughConstructors` being 
> fooled by the `CXXMemberCallExpr` that's just a conversion operator.
> 
> The other patch in the works doesn't use that function so the bug is not 
> present there, maybe its easier to just get that ready. WDYT?
> The other patch in the works doesn't use that function so the bug is not 
> present there, maybe its easier to just get that ready. WDYT?

I think that makes sense. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97889/new/

https://reviews.llvm.org/D97889

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97125: Stop traping on sNaN in __builtin_isinf

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre updated this revision to Diff 328171.
thopre added a comment.

Add isfinite testcases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97125/new/

https://reviews.llvm.org/D97125

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/strictfp_builtins.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/builtin_float_strictfp.c
  clang/test/CodeGen/strictfp_builtins.c

Index: clang/test/CodeGen/strictfp_builtins.c
===
--- clang/test/CodeGen/strictfp_builtins.c
+++ clang/test/CodeGen/strictfp_builtins.c
@@ -55,23 +55,114 @@
   return;
 }
 
-// CHECK-LABEL: @test_isinf(
+// CHECK-LABEL: @test_fp16_isinf(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[D_ADDR:%.*]] = alloca double, align 8
-// CHECK-NEXT:store double [[D:%.*]], double* [[D_ADDR]], align 8
-// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
-// CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.fabs.f64(double [[TMP0]]) [[ATTR5]]
-// CHECK-NEXT:[[CMPINF:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[TMP1]], double 0x7FF0, metadata !"oeq", metadata !"fpexcept.strict") [[ATTR4]]
-// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CMPINF]] to i32
-// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 [[TMP2]]) [[ATTR4]]
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[LD_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[LD_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[SHL1:%.*]] = shl i16 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i16 [[SHL1]], -2048
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:2]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
 // CHECK-NEXT:ret void
 //
-void test_isinf(double d) {
+void test_fp16_isinf(__fp16 h) {
+  P(isinf, (h));
+
+  return;
+}
+
+// CHECK-LABEL: @test_float_isinf(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca float, align 4
+// CHECK-NEXT:store float [[F:%.*]], float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load float, float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast float [[TMP0]] to i32
+// CHECK-NEXT:[[SHL1:%.*]] = shl i32 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[SHL1]], -16777216
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_float_isinf(float f) {
+  P(isinf, (f));
+
+  return;
+}
+
+// CHECK-LABEL: @test_double_isinf(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store double [[D:%.*]], double* [[LD_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load double, double* [[LD_ADDR]], align 8
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast double [[TMP0]] to i64
+// CHECK-NEXT:[[SHL1:%.*]] = shl i64 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq i64 [[SHL1]], -9007199254740992
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_double_isinf(double d) {
   P(isinf, (d));
 
   return;
 }
 
+// CHECK-LABEL: @test_fp16_isfinite(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[H:%.*]], half* [[LD_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* [[LD_ADDR]], align 2
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast half [[TMP0]] to i16
+// CHECK-NEXT:[[SHL1:%.*]] = shl i16 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp ult i16 [[SHL1]], -2048
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.[[#STRID:STRID+1]], i64 0, i64 0), i32 [[RES]]) [[ATTR4]]
+// CHECK-NEXT:ret void
+//
+void test_fp16_isfinite(__fp16 h) {
+  P(isfinite, (h));
+
+  return;
+}
+
+// CHECK-LABEL: @test_float_isfinite(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LD_ADDR:%.*]] = alloca float, align 4
+// CHECK-NEXT:store float [[F:%.*]], float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load float, float* [[LD_ADDR]], align 4
+// CHECK-NEXT:[[BITCAST:%.*]] = bitcast float [[TMP0]] to i32
+// CHECK-NEXT:[[SHL1:%.*]] = shl i32 [[BITCAST]], 1
+// CHECK-NEXT:[[CMP:%.*]] = icmp ult i32 [[SHL1]], -16777216
+// CHECK-NEXT:[[RES:%.*]] = zext i1 [[CMP]] to i32
+// CHECK-NEXT:call void @p(i8* getelementptr inb

[PATCH] D97901: [SystemZ] Test for infinity in testFPKind().

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:7229
+  case Builtin::BI__builtin_isfinite:
+Invert = true;
+LLVM_FALLTHROUGH;

thopre wrote:
> uweigand wrote:
> > thopre wrote:
> > > jonpa wrote:
> > > > What are these variants all about...?
> > > > 
> > > They were introduced in https://reviews.llvm.org/D24483
> > This "invert" logic doesn't look correct.   "isfinite" and "isinf" **both** 
> > need to return false on NaNs.  I think you should just drop the invert 
> > logic and use a TDC mask of 0xFC0 (zero, normal, or subnormal) to implement 
> > "isfinite".
> My bad, I made the same mistake in https://reviews.llvm.org/D97125. I'll 
> revert for now and will notify this review once I've got it fixed.
I've fixed https://reviews.llvm.org/D97125 and added some isfinite cases.. 
Thanks @uweigand for pointing the NaN case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97901/new/

https://reviews.llvm.org/D97901

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97940: [clang-tidy] Extend LoopConvert on array with `!=` comparison

2021-03-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97940/new/

https://reviews.llvm.org/D97940

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97951: [Sema] Fix diagnostics for one-byte length modifier

2021-03-04 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev created this revision.
AntonBikineev added a reviewer: jordan_rose.
AntonBikineev added a project: clang.
AntonBikineev requested review of this revision.

In case a char-literal of type int (C/ObjectiveC) corresponds to a
format specifier with the %hh length modifier, don't treat the literal
as of type char for issuing diagnostics, as otherwise this results in:

printf("%hhd", 'e');
warning: format specifies type 'char' but the argument has type 'char'.


Repository:
  rC Clang

https://reviews.llvm.org/D97951

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m


Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -169,6 +169,12 @@
 
   NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but 
the argument has type 'int'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+
+  NSLog(@"%hhd", 'a'); // expected-warning{{format specifies type 'char' but 
the argument has type 'int'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:15}:"%d"
+
+  NSLog(@"%hhu", 'a'); // expected-warning{{format specifies type 'unsigned 
char' but the argument has type 'int'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:15}:"%d"
 }
 
 void multichar_constants_false_negative() {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8650,8 +8650,11 @@
   } else if (const CharacterLiteral *CL = dyn_cast(E)) {
 // Special case for 'a', which has type 'int' in C.
 // Note, however, that we do /not/ want to treat multibyte constants like
-// 'MooV' as characters! This form is deprecated but still exists.
-if (ExprTy == S.Context.IntTy)
+// 'MooV' as characters! This form is deprecated but still exists. In
+// addition, don't treat expressions as of type 'char' if one byte length
+// modifier is provided.
+if (ExprTy == S.Context.IntTy &&
+FS.getLengthModifier().getKind() != LengthModifier::AsChar)
   if (llvm::isUIntN(S.Context.getCharWidth(), CL->getValue()))
 ExprTy = S.Context.CharTy;
   }


Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -169,6 +169,12 @@
 
   NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+
+  NSLog(@"%hhd", 'a'); // expected-warning{{format specifies type 'char' but the argument has type 'int'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:15}:"%d"
+
+  NSLog(@"%hhu", 'a'); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'int'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:15}:"%d"
 }
 
 void multichar_constants_false_negative() {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8650,8 +8650,11 @@
   } else if (const CharacterLiteral *CL = dyn_cast(E)) {
 // Special case for 'a', which has type 'int' in C.
 // Note, however, that we do /not/ want to treat multibyte constants like
-// 'MooV' as characters! This form is deprecated but still exists.
-if (ExprTy == S.Context.IntTy)
+// 'MooV' as characters! This form is deprecated but still exists. In
+// addition, don't treat expressions as of type 'char' if one byte length
+// modifier is provided.
+if (ExprTy == S.Context.IntTy &&
+FS.getLengthModifier().getKind() != LengthModifier::AsChar)
   if (llvm::isUIntN(S.Context.getCharWidth(), CL->getValue()))
 ExprTy = S.Context.CharTy;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97955: [clang-tidy] Refactor loop-convert to bring most of the checking into matchers

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh.
Herald added a subscriber: xazax.hun.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Move all checking on the for loop declaration into the matchers.
Once a match is generated clients only need to examine the body of the for loop 
to ensure its convertible.
This also brings the handling of match results for Iterator and PseudoArray 
loops much more inline.

This supercedes D97889 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97955

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
  clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-basic.cpp
@@ -447,6 +447,14 @@
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (int It : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
+
+  for (dependent::const_iterator It{V.begin()}, E = V.end();
+   It != E; ++It) {
+printf("Fibonacci number is %d\n", *It);
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHEfCK-FIXES: for (int It : V)
+  // CHECfK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
 }
 
 // Tests to ensure that an implicit 'this' is picked up as the container.
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
@@ -68,9 +68,6 @@
 const UsageResult &Usages,
 RangeDescriptor &Descriptor);
 
-  bool isConvertible(ASTContext *Context, const ast_matchers::BoundNodes &Nodes,
- const ForStmt *Loop, LoopFixerKind FixerKind);
-
   StringRef getReverseFunction() const;
   StringRef getReverseHeader() const;
 
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -61,9 +61,8 @@
 static const char LoopNameReverseIterator[] = "forLoopReverseIterator";
 static const char LoopNamePseudoArray[] = "forLoopPseudoArray";
 static const char ConditionBoundName[] = "conditionBound";
+static const char ContainerMemberExpr[] = "containerMemberExpr";
 static const char InitVarName[] = "initVar";
-static const char BeginCallName[] = "beginCall";
-static const char EndCallName[] = "endCall";
 static const char EndVarName[] = "endVar";
 static const char DerefByValueResultName[] = "derefByValueResult";
 static const char DerefByRefResultName[] = "derefByRefResult";
@@ -114,6 +113,59 @@
   .bind(LoopNameArray);
 }
 
+namespace {
+
+AST_MATCHER(ParmVarDecl, hasDefaultArg) {
+  return Node.getDefaultArg() != nullptr;
+}
+
+AST_MATCHER(VarDecl, isCStyleInit) {
+  return Node.getInitStyle() == VarDecl::CInit;
+}
+
+AST_MATCHER(VarDecl, samePtrTypeAsBeginResult) {
+  struct Predicate {
+bool operator()(const ast_matchers::internal::BoundNodesMap &Nodes) const {
+  const auto *BeginMember =
+  Nodes.getNodeAs(ContainerMemberExpr);
+  assert(BeginMember);
+  QualType RetType = cast(BeginMember->getMemberDecl())
+ ->getReturnType()
+ .getCanonicalType();
+  if (RetType->isPointerType())
+return !Context.hasSameUnqualifiedType(VarType->getPointeeType(),
+   RetType->getPointeeType());
+  return false;
+}
+
+QualType VarType;
+const ASTContext &Context;
+  };
+  QualType VarType = Node.getType().getCanonicalType();
+  if (!VarType->isPointerType())
+return true;
+  return Builder->removeBindings(Predicate{VarType, Finder->getASTContext()});
+}
+
+AST_MATCHER(MemberExpr, matchesBoundBeginContainer) {
+  struct Predicate {
+bool operator()(const ast_matchers::internal::BoundNodesMap &Nodes) const {
+  const auto *BeginMember =
+  Nodes.getNodeAs(ContainerMemberExpr);
+  assert(BeginMember);
+  if (BeginMember->isArrow() != Node.isArrow())
+return true;
+
+  return !areSameExpr(Context, BeginMember->getBase(), Node.getBase());
+}
+
+const MemberExpr &Node;
+ASTContext *Context;
+  };
+  return Builder->removeBindings(Predicate{Node, &Finder->getASTContext()});
+}
+} // namespace

[PATCH] D97927: [clang-format] Rename case sorting

2021-03-04 Thread Chris Johnson via Phabricator via cfe-commits
PragmaNull accepted this revision.
PragmaNull added a comment.

Thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97927/new/

https://reviews.llvm.org/D97927

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96760: [clang-format] Suppress diagnostics on second parse

2021-03-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96760/new/

https://reviews.llvm.org/D96760

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97959: [HIP] do not use -mconstructor-aliases for device

2021-03-04 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a subscriber: tpr.
yaxunl requested review of this revision.

Like nvptx and some other targets, -mconstructor-aliases does not work well 
with amdgpu,
therefore we disable it in the same approach.


https://reviews.llvm.org/D97959

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/hip-options.hip


Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -40,3 +40,10 @@
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck 
-check-prefix=FIX-OVERLOAD %s
 // FIX-OVERLOAD: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-fgpu-exclude-wrong-side-overloads" "-fgpu-defer-diag"
 // FIX-OVERLOAD: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-fgpu-exclude-wrong-side-overloads" "-fgpu-defer-diag"
+
+// Check -mconstructor-aliases is not passed to device compilation.
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=CTA %s
+// CTA: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-mconstructor-aliases"
+// CTA-NOT: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-mconstructor-aliases"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4916,9 +4916,11 @@
   }
 
   // Enable -mconstructor-aliases except on darwin, where we have to work 
around
-  // a linker bug (see ), and CUDA device code, where
-  // aliases aren't supported. Similarly, aliases aren't yet supported for AIX.
-  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() && !RawTriple.isOSAIX())
+  // a linker bug (see ), and CUDA/AMDGPU device code,
+  // where aliases aren't supported. Similarly, aliases aren't yet supported
+  // for AIX.
+  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() &&
+  !RawTriple.isAMDGPU() && !RawTriple.isOSAIX())
 CmdArgs.push_back("-mconstructor-aliases");
 
   // Darwin's kernel doesn't support guard variables; just die if we


Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -40,3 +40,10 @@
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=FIX-OVERLOAD %s
 // FIX-OVERLOAD: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fgpu-exclude-wrong-side-overloads" "-fgpu-defer-diag"
 // FIX-OVERLOAD: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-fgpu-exclude-wrong-side-overloads" "-fgpu-defer-diag"
+
+// Check -mconstructor-aliases is not passed to device compilation.
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=CTA %s
+// CTA: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-mconstructor-aliases"
+// CTA-NOT: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-mconstructor-aliases"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4916,9 +4916,11 @@
   }
 
   // Enable -mconstructor-aliases except on darwin, where we have to work around
-  // a linker bug (see ), and CUDA device code, where
-  // aliases aren't supported. Similarly, aliases aren't yet supported for AIX.
-  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() && !RawTriple.isOSAIX())
+  // a linker bug (see ), and CUDA/AMDGPU device code,
+  // where aliases aren't supported. Similarly, aliases aren't yet supported
+  // for AIX.
+  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() &&
+  !RawTriple.isAMDGPU() && !RawTriple.isOSAIX())
 CmdArgs.push_back("-mconstructor-aliases");
 
   // Darwin's kernel doesn't support guard variables; just die if we
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97960: [clang-tidy] bugprone-signal-handler improvements: display call chain

2021-03-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp, xazax.hun, 
whisperity.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add a new feature to display the call chain if an unsafe function is
found in a signal handler or function called from it.
Warning messages are improved too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97960

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.cpp
@@ -19,11 +19,11 @@
   S(int) {
 std::other_call();
 // Should be fixed.
-// CHECK-MESSAGES-NOT: :[[@LINE-2]]:5: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:5: warning: system call 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   };
   int operator-() const {
 std::other_call();
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: system call 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   }
 };
 
@@ -31,14 +31,14 @@
   static int memberInit() {
 std::other_call();
 // Should be fixed.
-// CHECK-MESSAGES-NOT: :[[@LINE-2]]:5: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:5: warning: system call 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   }
   int M = memberInit();
 };
 
 int defaultInit() {
   std::other_call();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: system call 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void testDefaultInit(int I = defaultInit()) {
@@ -70,13 +70,13 @@
 
 void handler_bad1(int) {
   std::other_call();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: system call 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void handler_bad2(int) {
   std::SysStruct S;
   S << 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator<<' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: system call 'operator<<' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void handler_bad3(int) {
@@ -98,7 +98,7 @@
 
 void handler_bad7(int) {
   int I = []() { std::other_call(); return 2; }();
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: system call 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 }
 
@@ -110,16 +110,23 @@
   std::signal(SIGINT, handler_abort);
   std::signal(SIGINT, handler__Exit);
   std::signal(SIGINT, handler_signal);
+
   std::signal(SIGINT, handler_bad1);
+
   std::signal(SIGINT, handler_bad2);
+
   // test call of user-defined operator
   std::signal(SIGINT, handler_bad3);
+
   // test call of constructor
   std::signal(SIGINT, handler_bad4);
+
   // test call of default member initializer
   std::signal(SIGINT, handler_bad5);
+
   // test call of default argument initializer
   std::signal(SIGINT, handler_bad6);
+
   // test lambda call in handler
   std::signal(SIGINT, handler_bad7);
 
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
==

[PATCH] D97125: Stop traping on sNaN in __builtin_isinf

2021-03-04 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre requested review of this revision.
thopre added a comment.

Requesting review since the logic has changed. This time I've also tested 
isfinite against glibc's result. All looks good.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97125/new/

https://reviews.llvm.org/D97125

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.

2021-03-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95244/new/

https://reviews.llvm.org/D95244

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97963: [ASTMatchers][Dynamic] Provide Fallback and suggestions for typos.

2021-03-04 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, klimek, steveire.
Herald added a subscriber: mgorny.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If there is a typo in parsing and we can see a close match, offer a suggestion 
hint and in the case of matchers carry on parsing to see if more diags are 
generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97963

Files:
  clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h
  clang/include/clang/ASTMatchers/Dynamic/Parser.h
  clang/include/clang/ASTMatchers/Dynamic/Registry.h
  clang/lib/ASTMatchers/Dynamic/CMakeLists.txt
  clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
  clang/lib/ASTMatchers/Dynamic/Parser.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/ASTMatchers/Dynamic/TypoSuggester.cpp
  clang/lib/ASTMatchers/Dynamic/TypoSuggester.h

Index: clang/lib/ASTMatchers/Dynamic/TypoSuggester.h
===
--- /dev/null
+++ clang/lib/ASTMatchers/Dynamic/TypoSuggester.h
@@ -0,0 +1,54 @@
+//===- TypoSuggester.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ASTMATCHERS_DYNAMIC_TYPOSUGGESTER_H
+#define LLVM_CLANG_ASTMATCHERS_DYNAMIC_TYPOSUGGESTER_H
+
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+namespace ast_matchers {
+namespace dynamic {
+// Helper class for getting the closest match for a typo string.
+// If OwnSuggestions is true, temporary strings can be passed to addSuggestion.
+class TypoSuggester {
+  llvm::StringRef Current;
+  const llvm::StringRef Value;
+  unsigned BestDistance;
+  bool HasMatch = false;
+
+public:
+  enum AutoMaxEditT { AutoMaxEdit };
+  TypoSuggester(llvm::StringRef Value, AutoMaxEditT)
+  : Value(Value), BestDistance((Value.size() + 3U) / 5U) {
+// This BestDistance is rather arbitrary but prevents generating suggestions
+// for single character values and grows more lenient as the value grows.
+  }
+  TypoSuggester(llvm::StringRef Target,
+unsigned MaxEdit = std::numeric_limits::max())
+  : Value(Target), BestDistance(MaxEdit) {
+assert(MaxEdit > 0);
+  }
+
+  // Returns true if we reach a state where we can never find a unique closest
+  // match.
+  bool addSuggestion(llvm::StringRef Suggest);
+  // If true, we are in a state where we can never find a unique closest match.
+  bool hasFailed() const { return BestDistance == 0; }
+  bool foundSuggestion() const { return HasMatch; }
+  llvm::StringRef getSuggestion() const {
+assert(foundSuggestion());
+return Current;
+  }
+};
+
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
+
+#endif // LLVM_CLANG_ASTMATCHERS_DYNAMIC_TYPOSUGGESTER_H
Index: clang/lib/ASTMatchers/Dynamic/TypoSuggester.cpp
===
--- /dev/null
+++ clang/lib/ASTMatchers/Dynamic/TypoSuggester.cpp
@@ -0,0 +1,39 @@
+//===- TypoSuggester.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TypoSuggester.h"
+
+namespace clang {
+namespace ast_matchers {
+namespace dynamic {
+bool TypoSuggester::addSuggestion(llvm::StringRef Suggest) {
+  unsigned Dist = Value.edit_distance(Suggest, true, BestDistance);
+  if (Dist > BestDistance)
+return false;
+  if (Dist == BestDistance) {
+if (HasMatch) {
+  // If we already have a completion candidate with the same edit
+  // distance, we can't be sure so disregard both.
+  HasMatch = false;
+  --BestDistance;
+  // As we assume Target will never appear in Suggest, once we reach a
+  // case where we need 0 edits, we can stop work.
+  return BestDistance == 0;
+}
+Current = Suggest;
+HasMatch = true;
+return false;
+  }
+  Current = Suggest;
+  HasMatch = true;
+  BestDistance = Dist;
+  return false;
+}
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
\ No newline at end of file
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -13,6 +13,7 @@
 
 #include "clang/ASTMatchers/Dynamic/Registry.h"
 #include "Marshallers.h"
+#include "TypoSuggester.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include

  1   2   >