[PATCH] D118969: [clang-format][NFC] Fix a bug in setting type FunctionLBrace

2022-02-04 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 405881.
owenpan added a comment.

Added a test case.


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

https://reviews.llvm.org/D118969

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -91,6 +91,12 @@
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_RecordLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
+  auto Tokens = annotate("#define BEGIN NS {");
+  EXPECT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1571,7 +1571,8 @@
 } else if (Style.BraceWrapping.AfterFunction) {
   addUnwrappedLine();
 }
-FormatTok->setType(TT_FunctionLBrace);
+if (!Line->InPPDirective)
+  FormatTok->setType(TT_FunctionLBrace);
 parseBlock();
 addUnwrappedLine();
 return;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -91,6 +91,12 @@
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_RecordLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
+  auto Tokens = annotate("#define BEGIN NS {");
+  EXPECT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1571,7 +1571,8 @@
 } else if (Style.BraceWrapping.AfterFunction) {
   addUnwrappedLine();
 }
-FormatTok->setType(TT_FunctionLBrace);
+if (!Line->InPPDirective)
+  FormatTok->setType(TT_FunctionLBrace);
 parseBlock();
 addUnwrappedLine();
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118969: [clang-format][NFC] Fix a bug in setting type FunctionLBrace

2022-02-04 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D118969#3295909 , @curdeius wrote:

> Well, I thought about this approach but actually a macro line should never be 
> merged together with a preceding line, so I went for a generic approach.

That's why I didn't say yours would be obsolete. :)

> That's because one never knows what's in a macro, it can well be a function 
> brace after all depending on what goes before...

This is exactly why we should //not// set the type to `FunctionLBrace`.

> Apart from that, could you add an annotator test please?

Done.


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

https://reviews.llvm.org/D118969

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


[PATCH] D118935: [SYCL] Disallow explicit casts between mismatching address spaces

2022-02-04 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118935

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


[PATCH] D118927: [clang-tidy] Fix invalid fix-it for cppcoreguidelines-prefer-member-initializer

2022-02-04 Thread Simon Giesecke via Phabricator via cfe-commits
simon.giesecke added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:537
 
+struct PR53515 {
+  int M;

Can this be renamed to something describing the test case? E.g. 
`AlreadyHasInitializer` (and the case above might be renamed to 
`AlreadyHasDefaultInitializer` to differentiate the two cases)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118927

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


[clang] 2189960 - [pseudo] Rename Tests.cpp => Test.cpp

2022-02-04 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-02-04T09:48:14+01:00
New Revision: 2189960e65a9c4a7056d1f07f8de5c3fda1888c3

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

LOG: [pseudo] Rename Tests.cpp => Test.cpp

To be consistent with other files in clang unittest directory.

Added: 
clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp

Modified: 
clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
llvm/utils/gn/secondary/clang/unittests/Tooling/Syntax/Pseudo/BUILD.gn

Removed: 
clang/unittests/Tooling/Syntax/Pseudo/GrammarTests.cpp



diff  --git a/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt 
b/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
index 77c6cbac026de..eea3245274529 100644
--- a/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
+++ b/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
@@ -3,7 +3,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_clang_unittest(ClangPseudoTests
-  GrammarTests.cpp
+  GrammarTest.cpp
 )
 
 clang_target_link_libraries(ClangPseudoTests

diff  --git a/clang/unittests/Tooling/Syntax/Pseudo/GrammarTests.cpp 
b/clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
similarity index 98%
rename from clang/unittests/Tooling/Syntax/Pseudo/GrammarTests.cpp
rename to clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
index 7954e53d786c3..dc57f16cf3b93 100644
--- a/clang/unittests/Tooling/Syntax/Pseudo/GrammarTests.cpp
+++ b/clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
@@ -1,4 +1,4 @@
-//===--- GrammarTests.cpp - grammar tests  --*- C++ 
-*-===//
+//===--- GrammarTest.cpp - grammar tests  ---*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

diff  --git 
a/llvm/utils/gn/secondary/clang/unittests/Tooling/Syntax/Pseudo/BUILD.gn 
b/llvm/utils/gn/secondary/clang/unittests/Tooling/Syntax/Pseudo/BUILD.gn
index 0082011192179..cf59af384 100644
--- a/llvm/utils/gn/secondary/clang/unittests/Tooling/Syntax/Pseudo/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/unittests/Tooling/Syntax/Pseudo/BUILD.gn
@@ -10,5 +10,5 @@ unittest("ClangPseudoTests") {
 "//llvm/lib/Support",
 "//llvm/lib/Testing/Support",
   ]
-  sources = [ "GrammarTests.cpp" ]
+  sources = [ "GrammarTest.cpp" ]
 }



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


[PATCH] D118969: [clang-format][NFC] Fix a bug in setting type FunctionLBrace

2022-02-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!


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

https://reviews.llvm.org/D118969

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


[clang] b94f095 - [pseudo] NFC, clangSyntaxPsuedo => clangToolingSyntaxPseudo

2022-02-04 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-02-04T09:57:20+01:00
New Revision: b94f09524efe2789598eb8c1bf5f44f5b17148d6

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

LOG: [pseudo] NFC, clangSyntaxPsuedo => clangToolingSyntaxPseudo

To be consistent with existing name pattern.

Added: 


Modified: 
clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt 
b/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
index 77dce4b70ea11..223ea52b6f75e 100644
--- a/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
+++ b/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(LLVM_LINK_COMPONENTS Support)
 
-add_clang_library(clangSyntaxPseudo
+add_clang_library(clangToolingSyntaxPseudo
   Grammar.cpp
   GrammarBNF.cpp
   

diff  --git a/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt 
b/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
index eea3245274529..d609d94bbff77 100644
--- a/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
+++ b/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
@@ -10,7 +10,7 @@ clang_target_link_libraries(ClangPseudoTests
   PRIVATE
   clangBasic
   clangLex
-  clangSyntaxPseudo
+  clangToolingSyntaxPseudo
   clangTesting
   )
 



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


[PATCH] D118755: [clangd] Crash in __memcmp_avx2_movbe

2022-02-04 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 405886.
ivanmurashko added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118755

Files:
  clang-tools-extra/clangd/test/repeated_includes.test
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp


Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -333,7 +333,7 @@
 int Priority = Categories.getIncludePriority(
 CurInclude.Name, /*CheckMainHeader=*/FirstIncludeOffset < 0);
 CategoryEndOffsets[Priority] = NextLineOffset;
-IncludesByPriority[Priority].push_back(&CurInclude);
+IncludesByPriority[Priority].push_back(CurInclude);
 if (FirstIncludeOffset < 0)
   FirstIncludeOffset = CurInclude.R.getOffset();
   }
@@ -361,9 +361,9 @@
   unsigned InsertOffset = CatOffset->second; // Fall back offset
   auto Iter = IncludesByPriority.find(Priority);
   if (Iter != IncludesByPriority.end()) {
-for (const auto *Inc : Iter->second) {
-  if (QuotedName < Inc->Name) {
-InsertOffset = Inc->R.getOffset();
+for (const auto &Inc : Iter->second) {
+  if (QuotedName < Inc.Name) {
+InsertOffset = Inc.R.getOffset();
 break;
   }
 }
Index: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
===
--- clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
+++ clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
@@ -105,8 +105,7 @@
   /// in the order they appear in the source file.
   /// See comment for "FormatStyle::IncludeCategories" for details about 
include
   /// priorities.
-  std::unordered_map>
-  IncludesByPriority;
+  std::unordered_map> IncludesByPriority;
 
   int FirstIncludeOffset;
   // All new headers should be inserted after this offset (e.g. after header
Index: clang-tools-extra/clangd/test/repeated_includes.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/repeated_includes.test
@@ -0,0 +1,33 @@
+# RUN: rm -rf %/t
+# RUN: mkdir -p %t && touch %t/t.h && touch %t/t2.h && touch %t/t3.h
+# RUN: echo '#pragma once' > %t/t.h
+# RUN: echo '#include "t2.h"' >> %t/t.h
+# RUN: echo 'void bar();' >> %t/t.h
+# RUN: echo '#pragma once' > %t/t2.h
+# RUN: echo 'void bar2();' >> %t/t2.h
+
+
+# Run clangd
+# RUN: clangd -lit-test -log error --path-mappings 'C:\client=%t' < %s | 
FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///C:/client/main.cpp","languageId":"cpp","version":1,"text":"#include
 \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include 
\"t.h\"\n#include \"t.h\"\n#include \"t.h\"\n#include \"t.h\"\nbar();\n"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///C:/client/main.cpp"},"position":{"line":40,"character":3}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": false,
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"detail": "void",
+# CHECK-NEXT:"documentation": {
+# CHECK-NEXT:  "kind": "plaintext",
+# CHECK-NEXT:  "value": "From \"t.h\""
+# CHECK-NEXT:},
+# CHECK-NEXT:"filterText": "bar",
+# CHECK-NEXT:"insertText": "bar",
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}


Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -333,7 +333,7 @@
 int Priority = Categories.getIncludePriority(
 CurInclude.Name, /*CheckMainHeader=*/FirstIncludeOffset < 0);
 CategoryEndOffsets[Priority] = NextLineOffset;
-IncludesByPriority[Priority].push_back(&CurInclude);
+IncludesByPriority[Priority].pu

[PATCH] D114790: [syntax][pseudo] Add grammar facilities for the pseudo-parser

2022-02-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt:3
+
+add_clang_library(clangSyntaxPseudo
+  Grammar.cpp

thakis wrote:
> (i think the usual name would be "clangToolingSyntaxPseudo")
 (the name is too verbose, and we have a rough plan to lift Syntax directory up 
to Tooling, no timeline yet. For now, it might be better to follow the existing 
name pattern, fixed in b94f09524efe2789598eb8c1bf5f44f5b17148d6.



Comment at: clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt:6
+add_clang_unittest(ClangPseudoTests
+  GrammarTests.cpp
+)

thakis wrote:
> ```
> thakis@thakis:~/src/llvm-project$ ls clang/unittests/**/*Test.cpp | wc -l
> 127
> thakis@thakis:~/src/llvm-project$ ls clang/unittests/**/*Tests.cpp | wc -l
> 1
> ```
fixed in  2189960e65a9c4a7056d1f07f8de5c3fda1888c3 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114790

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


[PATCH] D118875: [compiler-rt][builtins] build the macOS compiler-rt built-ins with Mac Catalyst support

2022-02-04 Thread Byoungchan Lee via Phabricator via cfe-commits
bc-lee added a comment.

Hi, I built and tested clang using this patch and 
https://reviews.llvm.org/D118862. It works great.
The current patch adds the -darwin-target-variant flag to all object files for 
MacOS targets in the compiler_rt's builtin library. However, users building 
compiler_rt may have compilers that don't support such flag, so it would be 
nice to have a CMake option to enable compiler flags like 
`COMPILER_RT_ENABLE_CATALYST`.


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

https://reviews.llvm.org/D118875

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


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-04 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D110869#3295912 , @craig.topper 
wrote:

> In D110869#3295906 , @void wrote:
>
>> In D110869#3295578 , 
>> @nickdesaulniers wrote:
>>
>>> In D110869#3295559 , @void wrote:
>>>
 Weird. We generate similar code to GCC:

   Clang:
   _paravirt_ident_64: # @_paravirt_ident_64
   movq%rdi, %rax
   xorq%rdi, %rdi
   retq
   
   GCC:
   _paravirt_ident_64:
   movq%rdi, %rax  # tmp85, x
   xorl%edi, %edi  #
   ret
>>>
>>> Does `xorl` not zero the upper 32b?
>>
>> I'm thinking no. But it's odd, because both are using `%rdi` but GCC is only 
>> zeroing out the bottom 32-bits. Seems a bit counter-intuitive.
>
> Every write to a 32-bit register on x86-64 zeros bits 63:32 of the register. 
> `xorl %edi, %edi` has the same behavior as `xorq %rdi, %rdi`, but is 1 byte 
> shorter to encode.

Oh, interesting! TIL. So it's really not profitable to use `xorq` at all 
here...Though it does beg the question of why `xorq` exists. :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D110869#3296031 , @void wrote:

> In D110869#3295912 , @craig.topper 
> wrote:
>
>> In D110869#3295906 , @void wrote:
>>
>>> In D110869#3295578 , 
>>> @nickdesaulniers wrote:
>>>
 In D110869#3295559 , @void wrote:

> Weird. We generate similar code to GCC:
>
>   Clang:
>   _paravirt_ident_64: # @_paravirt_ident_64
>   movq%rdi, %rax
>   xorq%rdi, %rdi
>   retq
>   
>   GCC:
>   _paravirt_ident_64:
>   movq%rdi, %rax  # tmp85, x
>   xorl%edi, %edi  #
>   ret

 Does `xorl` not zero the upper 32b?
>>>
>>> I'm thinking no. But it's odd, because both are using `%rdi` but GCC is 
>>> only zeroing out the bottom 32-bits. Seems a bit counter-intuitive.
>>
>> Every write to a 32-bit register on x86-64 zeros bits 63:32 of the register. 
>> `xorl %edi, %edi` has the same behavior as `xorq %rdi, %rdi`, but is 1 byte 
>> shorter to encode.
>
> Oh, interesting! TIL. So it's really not profitable to use `xorq` at all 
> here...Though it does beg the question of why `xorq` exists. :-)

xorq is still useful when the registers are different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

... if there is a match.
This is needed to that clients can can make a connection between a
diagnostic and an associated quickfix-tweak.
Ideally, quickfix-kind tweak code actions would be provided inline along
with the non-tweak fixes, but this doesn't seem easily achievable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118976

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,7 +986,7 @@
 
   // Now enumerate the semantic code actions.
   auto ConsumeActions =
-  [Reply = std::move(Reply), File, Selection = Params.range,
+  [Diags = Params.context.diagnostics, Reply = std::move(Reply), File, 
Selection = Params.range,
FixIts = std::move(FixIts), this](
   llvm::Expected> Tweaks) mutable {
 if (!Tweaks)
@@ -994,8 +994,17 @@
 
 std::vector Actions = std::move(FixIts);
 Actions.reserve(Actions.size() + Tweaks->size());
-for (const auto &T : *Tweaks)
+for (const auto &T : *Tweaks) {
   Actions.push_back(toCodeAction(T, File, Selection));
+  if (T.Kind != CodeAction::QUICKFIX_KIND)
+continue;
+  for (const Diagnostic &D : Diags) {
+if (D.range == Selection) {
+  Actions.back().diagnostics = {D};
+  break;
+}
+  }
+}
 
 // If there's exactly one quick-fix, call it "preferred".
 // We never consider refactorings etc as preferred.


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,7 +986,7 @@
 
   // Now enumerate the semantic code actions.
   auto ConsumeActions =
-  [Reply = std::move(Reply), File, Selection = Params.range,
+  [Diags = Params.context.diagnostics, Reply = std::move(Reply), File, Selection = Params.range,
FixIts = std::move(FixIts), this](
   llvm::Expected> Tweaks) mutable {
 if (!Tweaks)
@@ -994,8 +994,17 @@
 
 std::vector Actions = std::move(FixIts);
 Actions.reserve(Actions.size() + Tweaks->size());
-for (const auto &T : *Tweaks)
+for (const auto &T : *Tweaks) {
   Actions.push_back(toCodeAction(T, File, Selection));
+  if (T.Kind != CodeAction::QUICKFIX_KIND)
+continue;
+  for (const Diagnostic &D : Diags) {
+if (D.range == Selection) {
+  Actions.back().diagnostics = {D};
+  break;
+}
+  }
+}
 
 // If there's exactly one quick-fix, call it "preferred".
 // We never consider refactorings etc as preferred.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118782: clangd: Add a break for every case in the PopulateSwitch tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 405893.
ckandeler added a comment.

Improved code as per review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118782

Files:
  clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
  clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
@@ -123,7 +123,7 @@
   )"",
   R""(
 enum class Enum {A,B};
-switch (Enum::A) {case Enum::A:case Enum::B:break;}
+switch (Enum::A) {case Enum::A:break;case Enum::B:break;}
   )"",
   },
   {
@@ -135,7 +135,7 @@
   )"",
   R""(
 enum Enum {A,B,C};
-switch (A) {case B:break;case A:case C:break;}
+switch (A) {case B:break;case A:break;case C:break;}
   )"",
   },
   {
@@ -148,7 +148,7 @@
   )"",
   R""(
 enum Enum {A,B=1,C};
-switch (A) {case 1:break;case A:case C:break;}
+switch (A) {case 1:break;case A:break;case C:break;}
   )"",
   },
   {
@@ -162,7 +162,7 @@
   R""(
 enum class Enum {A,B,C};
 switch (Enum::A)
-{case Enum::B:break;case Enum::A:case Enum::C:break;}
+{case Enum::B:break;case Enum::A:break;case Enum::C:break;}
   )"",
   },
   {
@@ -193,12 +193,12 @@
   // Duplicated constant names
   Function,
   R""(enum Enum {A,B,b=B}; ^switch (A) {})"",
-  R""(enum Enum {A,B,b=B}; switch (A) {case A:case B:break;})"",
+  R""(enum Enum {A,B,b=B}; switch (A) {case A:break;case B:break;})"",
   },
   {
   // Duplicated constant names all in switch
   Function,
-  R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
+  R""(enum Enum {A,B,b=B}; ^switch (A) {case A:break;case B:break;})"",
   "unavailable",
   },
   {
@@ -217,7 +217,7 @@
R""(
 enum CEnum {A,B,C};
 enum CEnum val = A;
-switch (val) {case B:break;case A:case C:break;}
+switch (val) {case B:break;case A:break;case C:break;}
   )"",
"TestTU.c"},
   {// C: Only filling in missing enumerators w/ typedefs
@@ -236,7 +236,7 @@
 typedef enum ControlState ControlState;
 enum ControlState : UInteger {A,B,C};
 ControlState controlState = A;
-switch (controlState) {case A:break;case B:case C:break;}
+switch (controlState) {case A:break;case B:break;case C:break;}
   )"",
"TestTU.c"},
   };
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -22,7 +22,9 @@
 //   void f(Color color) {
 // switch (color) {
 // case RED:
+//   break;
 // case GREEN:
+//   break;
 // case BLUE:
 //   break;
 // }
@@ -203,11 +205,10 @@
 Text.append({"case ", getQualification(DeclASTCtx, DeclCtx, Loc, EnumD)});
 if (EnumD->isScoped())
   Text.append({EnumD->getName(), "::"});
-Text.append({EnumConstant.second.getEnumConstant()->getName(), ":"});
+Text.append({EnumConstant.second.getEnumConstant()->getName(), ":break;"});
   }
 
   assert(!Text.empty() && "No enumerators to insert!");
-  Text += "break;";
 
   const SourceManager &SM = Ctx.getSourceManager();
   return Effect::mainFileEdit(


Index: clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
@@ -123,7 +123,7 @@
   )"",
   R""(
 enum class Enum {A,B};
-switch (Enum::A) {case Enum::A:case Enum::B:break;}
+switch (Enum::A) {case Enum::A:break;case Enum::B:break;}
   )"",
   },
   {
@@ -135,7 +135,7 @@
   )"",
   R""(
 enum Enum {A,B,C};
-switch (A) {case B:break;case A:case C:break;}
+switch (A) {case B:break;case A:break;case C:break;}
   )"",
   },
   {
@@ -148,7 +148,7 @@
   )"",
   R""(
 enum Enum {A,B=1,C};
-switch (A) {case 1:break;case A:case C:break;}
+switch (A) {case 1:break;case A:break;case C:break;}
   )"",
   },
   {
@@ -162,7 +162,7 @@
  

[PATCH] D118977: [NVPTX] Add more FMA intriniscs/builtins

2022-02-04 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda created this revision.
jchlanda added reviewers: tra, csigg, bkramer.
Herald added subscribers: asavonic, hiraditya, jholewinski.
jchlanda requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert.
Herald added projects: clang, LLVM.

This patch adds builtins/intrinsics for the following variants of FMA:

- f16
  - rn
  - rn_ftz
  - rn_sat
  - rn_ftz_sat
  - rn_relu
  - rn_ftz_relu
- f16x2
  - rn
  - rn_ftz
  - rn_sat
  - rn_ftz_sat
  - rn_relu
  - rn_ftz_relu
- bf16
  - rn
  - rn_relu
- bf16x2
  - rn
  - rn_relu

They all require PTX 7.0, SM_80.

`ptxas` (Cuda compilation tools, release 11.0, V11.0.194) is happy with the 
generated assembly.

Depends on D<117887>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118977

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  clang/test/CodeGen/builtins-nvptx.c
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
  llvm/test/CodeGen/NVPTX/math-intrins-sm80-ptx70-instcombine.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm80-ptx70.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll

Index: llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
===
--- llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
+++ llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
@@ -36,6 +36,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f16
 define half @fmin_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -43,6 +44,7 @@
 
 ; CHECK-LABEL: fmin_ftz_xorsign_abs_f16
 define half @fmin_ftz_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.ftz.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -50,6 +52,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_f16
 define half @fmin_nan_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.nan.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -57,6 +60,7 @@
 
 ; CHECK-LABEL: fmin_ftz_nan_xorsign_abs_f16
 define half @fmin_ftz_nan_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.NaN.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.ftz.nan.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -64,6 +68,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f16x2
 define <2 x half> @fmin_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -71,6 +76,7 @@
 
 ; CHECK-LABEL: fmin_ftz_xorsign_abs_f16x2
 define <2 x half> @fmin_ftz_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.ftz.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -78,6 +84,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_f16x2
 define <2 x half> @fmin_nan_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.nan.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -85,6 +92,7 @@
 
 ; CHECK-LABEL: fmin_ftz_nan_xorsign_abs_f16x2
 define <2 x half> @fmin_ftz_nan_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.NaN.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.ftz.nan.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -92,6 +100,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_bf16
 define i16 @fmin_xorsign_abs_bf16(i16 %0, i16 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.bf16
   %res = call i16 @llvm.nvvm.fmin.xorsign.abs.bf16(i16 %0, i16 %1)
   ret i16 %res
@@ -99,6 +108,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_bf16
 define i16 @fmin_nan_xorsign_abs_bf16(i16 %0, i16 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.bf16
   %res = call i16 @llvm.nvvm.fmin.nan.xorsign.abs.bf16(i16 %0, i16 %1)
   ret i16 %res
@@ -106,6 +116,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_bf16x2
 define i32 @fmin_xorsign_abs_bf16x2(i32 %0, i32 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.bf16x2
   %res = call i32 @llvm.nvvm.fmin.xorsign.abs.bf16x2(i32 %0, i32 %1)
   ret i32 %res
@@ -113,6 +124,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_bf16x2
 define i32 @fmin_nan_xorsign_abs_bf16x2(i32 %0, i32 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.bf16x2
   %res = call i32 @llvm.nvvm.fmin.nan.xorsign.abs.bf16x2(i32 %0, i32 %1)
   ret i32 %res
@@ -120,6 +132,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f
 define float @fmin_xorsign_abs_f(float %0, float %1) {
+  ;

[PATCH] D118044: [ARM] Undeprecate complex IT blocks

2022-02-04 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

The actual code change looks fine to me, providing we can clean up these test 
changes a bit and no-one else has any other comments.




Comment at: llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll:196
 ; Hard-coded registers comes from the ABI.
 ; CHECK-LABEL: wrapDistance:
 ; CHECK: cmp r1, #59

If you autogenerate check lines we have to make sure we remove the old ones, 
but I'm not sure the new check lines are filling in all the details. They can 
do that if the check lines dont match between multiple run lines with the same 
check-prefix.

It is probably simplest to change the check lines to
; RUN: llc < %s -mtriple=thumbv8 -arm-restrict-it | FileCheck 
-check-prefix=CHECK-V8 %s
; RUN: llc < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck 
-check-prefix=CHECK-V8 %s
And remove all the other differences from this file.



Comment at: llvm/test/CodeGen/ARM/arm-bf16-pcs.ll:190
 ; BASE-THUMB-NEXT:strh.w r0, [sp, #6]
+; BASE-THUMB-NEXT:uxth r1, r0
 ; BASE-THUMB-NEXT:mov r0, r5

john.brawn wrote:
> This, and the cases in other tests where we have a uxth/uxtb that moves, 
> looks rather strange and not something I'd expect given that there's no IT 
> here. Do you know what's going on here?
Given restrictIT we run Thumb2SizeReduce earlier, which can change the 
scheduling.



Comment at: llvm/test/CodeGen/ARM/ifcvt-branch-weight.ll:22
+; CHECK: bb.1.bb2:
+; CHECK: successors: %bb.2(0x4000)
 

MarkMurrayARM wrote:
> dmgreen wrote:
> > I'm not sure this is still checking anything useful. How has the full 
> > output changed? Is there not a block with two outputs anymore?
> It is a failure caused by my change. 
From what I can tell, this test is trying test that the block weights are 
correct after ifcvt. It would be best to make sure that is still being tested.

It's probably best to add -arm-restrict-it to this test, so it can keep testing 
the same thing.



Comment at: llvm/test/CodeGen/ARM/speculation-hardening-sls.ll:38
 ; NOHARDENARM: {{bxgt lr$}}
-; NOHARDENTHUMB:   {{bx lr$}}
 ; ISBDSB-NEXT: dsb sy

dmgreen wrote:
> What happened to this check line? Should it be bxgt lr now?
Change this to `; NOHARDENTHUMB:   {{bxgt lr$}}`
It should then be the only change needed in this file, the other checks will 
fall into place without needing any modification. It looks like different lines 
were matching than what was expected, which threw off the ones below.



Comment at: llvm/test/CodeGen/Thumb2/v8_IT_3.ll:4
 ; RUN: llc < %s -mtriple=thumbv8 -arm-atomic-cfg-tidy=0 -relocation-model=pic 
| FileCheck %s --check-prefix=CHECK-PIC
-; RUN: llc < %s -mtriple=thumbv7 -arm-atomic-cfg-tidy=0 -arm-restrict-it 
-relocation-model=pic | FileCheck %s --check-prefix=CHECK-PIC
+; RUN: llc < %s -mtriple=thumbv7 -arm-atomic-cfg-tidy=0 -arm-restrict-it 
-relocation-model=pic | FileCheck %s --check-prefix=CHECK-PIC-RESTRICT-IT 
--check-prefix=CHECK-RESTRICT-IT
 

MarkMurrayARM wrote:
> dmgreen wrote:
> > I'm not sure what this test is doing. Can you just remove -arm-restrict-it 
> > and update the check lines?
> It's checking restricted ID blocks in position-independent code. I don't see 
> what your request will achieve?
Oh OK. I hadn't realized this test was for restricts it blocks specifically. In 
that case maybe just add -arm-restrict-it to the thumbv8 lines and leave the 
check lines as-is. That would then be the same as v8_IT_5.ll.

Otherwise, this needn't have both CHECK-PIC-RESTRICT-IT and CHECK-RESTRICT-IT, 
one of the two should be fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118044

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


[PATCH] D118755: [clangd] Crash in __memcmp_avx2_movbe

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks! This fix makes sense to me.




Comment at: clang-tools-extra/clangd/test/repeated_includes.test:1
+# RUN: rm -rf %/t
+# RUN: mkdir -p %t && touch %t/t.h && touch %t/t2.h && touch %t/t3.h

This should be tested more directly rather than via clangd, e.g. rather in 
`clang/unittests/Tooling/HeaderIncludesTest.cpp`



Comment at: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h:100
   // and "x" will be treated as the same header when deleting #includes.
   llvm::StringMap> ExistingIncludes;
 

An alternative would be to use a std::forward_list here.

This guarantees pointer stability, it's an extra allocation but seems unlikely 
to matter.

It would be more robust if the data structure changes (e.g. becomes large, or 
is mutated after creation) but probably none of this will ever happen.

Up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118755

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


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-04 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 405897.
void added a comment.

Only need to zero out 32-bit registers with xor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/zero-call-used-regs.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/zero_call_used_regs.c
  llvm/include/llvm/CodeGen/MachineRegisterInfo.h
  llvm/include/llvm/CodeGen/TargetFrameLowering.h
  llvm/include/llvm/CodeGen/TargetRegisterInfo.h
  llvm/include/llvm/Support/CodeGen.h
  llvm/include/llvm/Target/Target.td
  llvm/lib/CodeGen/MachineRegisterInfo.cpp
  llvm/lib/CodeGen/PrologEpilogInserter.cpp
  llvm/lib/Target/X86/X86FrameLowering.cpp
  llvm/lib/Target/X86/X86FrameLowering.h
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/lib/Target/X86/X86RegisterInfo.h
  llvm/lib/Target/X86/X86RegisterInfo.td
  llvm/test/CodeGen/X86/zero-call-used-regs-fmod.ll
  llvm/test/CodeGen/X86/zero-call-used-regs.ll
  llvm/utils/TableGen/CodeGenRegisters.cpp
  llvm/utils/TableGen/CodeGenRegisters.h
  llvm/utils/TableGen/RegisterInfoEmitter.cpp

Index: llvm/utils/TableGen/RegisterInfoEmitter.cpp
===
--- llvm/utils/TableGen/RegisterInfoEmitter.cpp
+++ llvm/utils/TableGen/RegisterInfoEmitter.cpp
@@ -1176,6 +1176,10 @@
  << "unsigned RegUnit) const override;\n"
  << "  ArrayRef getRegMaskNames() const override;\n"
  << "  ArrayRef getRegMasks() const override;\n"
+ << "  bool isGeneralPurposeRegister(const MachineFunction &, "
+ << "MCRegister) const override;\n"
+ << "  bool isFixedRegister(const MachineFunction &, "
+ << "MCRegister) const override;\n"
  << "  /// Devirtualized TargetFrameLowering.\n"
  << "  static const " << TargetName << "FrameLowering *getFrameLowering(\n"
  << "  const MachineFunction &MF);\n"
@@ -1620,6 +1624,36 @@
   }
   OS << "}\n\n";
 
+  const std::list &RegCategories =
+  RegBank.getRegCategories();
+  OS << "bool " << ClassName << "::\n"
+ << "isGeneralPurposeRegister(const MachineFunction &MF, "
+ << "MCRegister PhysReg) const {\n"
+ << "  return\n";
+  for (const auto &Category : RegCategories)
+if (Category.getName() == "GeneralPurposeRegisters") {
+  for (const auto *RC : Category.getClasses())
+OS << "  " << RC->getQualifiedName()
+   << "RegClass.contains(PhysReg) ||\n";
+  break;
+}
+  OS << "  false;\n";
+  OS << "}\n\n";
+
+  OS << "bool " << ClassName << "::\n"
+ << "isFixedRegister(const MachineFunction &MF, "
+ << "MCRegister PhysReg) const {\n"
+ << "  return\n";
+  for (const auto &Category : RegCategories)
+if (Category.getName() == "FixedRegisters") {
+  for (const auto *RC : Category.getClasses())
+OS << "  " << RC->getQualifiedName()
+   << "RegClass.contains(PhysReg) ||\n";
+  break;
+}
+  OS << "  false;\n";
+  OS << "}\n\n";
+
   OS << "ArrayRef " << ClassName
  << "::getRegMaskNames() const {\n";
   if (!CSRSets.empty()) {
Index: llvm/utils/TableGen/CodeGenRegisters.h
===
--- llvm/utils/TableGen/CodeGenRegisters.h
+++ llvm/utils/TableGen/CodeGenRegisters.h
@@ -476,6 +476,26 @@
 static void computeSubClasses(CodeGenRegBank&);
   };
 
+  // Register categories are used when we need to deterine the category a
+  // register falls into (GPR, vector, fixed, etc.) without having to know
+  // specific information about the target architecture.
+  class CodeGenRegisterCategory {
+Record *TheDef;
+std::string Name;
+std::list Classes;
+
+  public:
+CodeGenRegisterCategory(CodeGenRegBank &, Record *R);
+CodeGenRegisterCategory(CodeGenRegisterCategory &) = delete;
+
+// Return the Record that defined this class, or NULL if the class was
+// created by TableGen.
+Record *getDef() const { return TheDef; }
+
+std::string getName() const { return Name; }
+std::list getClasses() const { return Classes; }
+  };
+
   // Register units are used to model interference and register pressure.
   // Every register is assigned one or more register units such that two
   // registers overlap if and only if they have a register unit in common.
@@ -559,6 +579,13 @@
 typedef std::map RCKeyMap;
 RCKeyMap Key2RC;
 
+// Register categories.
+std::list RegCategories;
+DenseMap Def2RCat;
+typedef std::map
+RCatKeyMap;
+RCatKeyMap Key2RCat;
+
 // Remember each unique set of register units. Initially, this contains a
 // uniqu

[clang] 31fa3a4 - [OpenCL] Move OpenCL 2.0 atomics into multiclass; NFC

2022-02-04 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-04T10:17:48Z
New Revision: 31fa3a4d44316fd36e11f92729ea9596ee3bf3f8

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

LOG: [OpenCL] Move OpenCL 2.0 atomics into multiclass; NFC

This is in preparation for adding the OpenCL 3.0 builtins with named
address space arguments.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 516653681331e..08f8630a67e22 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1040,6 +1040,8 @@ let Extension = FuncExtOpenCLCxx in {
   }
 }
 
+// OpenCL v2.0 s6.13.11 - Atomic Functions.
+
 // An atomic builtin with 2 additional _explicit variants.
 multiclass BuiltinAtomicExplicit Types> {
   // Without explicit MemoryOrder or MemoryScope.
@@ -1052,31 +1054,29 @@ multiclass BuiltinAtomicExplicit Types> {
   def : Builtin;
 }
 
-// OpenCL v2.0 s6.13.11 - Atomic Functions.
-let MinVersion = CL20 in {
-  def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, 
MemoryScope]>;
-
+// OpenCL 2.0 atomic functions that have a pointer argument in a given address 
space.
+multiclass OpenCL2Atomics {
   foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
   [AtomicLong, Long], [AtomicULong, ULong],
   [AtomicFloat, Float], [AtomicDouble, Double]] in {
 def : Builtin<"atomic_init",
-[Void, PointerType, GenericAS>, 
TypePair[1]]>;
+[Void, PointerType, addrspace>, 
TypePair[1]]>;
 defm : BuiltinAtomicExplicit<"atomic_store",
-[Void, PointerType, GenericAS>, 
TypePair[1]]>;
+[Void, PointerType, addrspace>, 
TypePair[1]]>;
 defm : BuiltinAtomicExplicit<"atomic_load",
-[TypePair[1], PointerType, GenericAS>]>;
+[TypePair[1], PointerType, addrspace>]>;
 defm : BuiltinAtomicExplicit<"atomic_exchange",
-[TypePair[1], PointerType, GenericAS>, 
TypePair[1]]>;
+[TypePair[1], PointerType, addrspace>, 
TypePair[1]]>;
 foreach Variant = ["weak", "strong"] in {
   def : Builtin<"atomic_compare_exchange_" # Variant,
-  [Bool, PointerType, GenericAS>,
-   PointerType, TypePair[1]]>;
+  [Bool, PointerType, addrspace>,
+   PointerType, TypePair[1]]>;
   def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, GenericAS>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder]>;
+  [Bool, PointerType, addrspace>,
+   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder]>;
   def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, GenericAS>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder, MemoryScope]>;
+  [Bool, PointerType, addrspace>,
+   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder, MemoryScope]>;
 }
   }
 
@@ -1085,22 +1085,28 @@ let MinVersion = CL20 in {
   [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
 foreach ModOp = ["add", "sub"] in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
+  [TypePair[1], PointerType, addrspace>, 
TypePair[2]]>;
 }
   }
   foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
   [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] 
in {
 foreach ModOp = ["or", "xor", "and", "min", "max"] in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
+  [TypePair[1], PointerType, addrspace>, 
TypePair[2]]>;
 }
   }
 
   defm : BuiltinAtomicExplicit<"atomic_flag_clear",
-  [Void, PointerType, GenericAS>]>;
+  [Void, PointerType, addrspace>]>;
 
   defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set",
-  [Bool, PointerType, GenericAS>]>;
+  [Bool, PointerType, addrspace>]>;
+}
+
+let MinVersion = CL20 in {
+  def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, 
MemoryScope]>;
+
+  defm : OpenCL2Atomics;
 }
 
 // The functionality added by cl_ext_float_atomics extension



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


[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This is assuming a semantic connection that we don't know exists.
Without any more specific reason to draw this connection, this seems like a 
heuristic that could equally be applied by the client.

Is there a particular action/diagnostic pair you want this for?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

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


[PATCH] D118980: Don't dllexport reference temporaries

2022-02-04 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added reviewers: thakis, mstorsjo, rnk.
hans requested review of this revision.
Herald added a project: clang.

Even if the reference itself is dllexport, the temporary should not be -- in 
fact, we're already giving it internal linkage, so dllexporting it is not just 
wasteful, but will fail to link, as in the example below:

  $ cat /tmp/a.cc
  void _DllMainCRTStartup() {}
  const int __declspec(dllexport) &foo = 42;
  
  $ clang-cl -fuse-ld=lld /tmp/a.cc /Zl /link /dll /out:a.dll
  lld-link: error: : undefined symbol: int const &foo::$RT1


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118980

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/reference-temporary-ms.cpp


Index: clang/test/CodeGenCXX/reference-temporary-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/reference-temporary-ms.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | 
FileCheck %s
+
+const int __declspec(dllexport) &Exported = 42;
+
+// The reference temporary shouldn't be dllexport, even if the reference is.
+// CHECK: @"?$RT1@Exported@@3ABHB" = internal constant i32 42
+
+// CHECK: @"?Exported@@3ABHB" = dso_local dllexport constant i32* 
@"?$RT1@Exported@@3ABHB"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5725,6 +5725,9 @@
   /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, 
TargetAS);
   if (emitter) emitter->finalize(GV);
   setGVProperties(GV, VD);
+  if (GV->getDLLStorageClass() == llvm::GlobalVariable::DLLExportStorageClass)
+// The reference temporary should never be dllexport.
+GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
   GV->setAlignment(Align.getAsAlign());
   if (supportsCOMDAT() && GV->isWeakForLinker())
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));


Index: clang/test/CodeGenCXX/reference-temporary-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/reference-temporary-ms.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | FileCheck %s
+
+const int __declspec(dllexport) &Exported = 42;
+
+// The reference temporary shouldn't be dllexport, even if the reference is.
+// CHECK: @"?$RT1@Exported@@3ABHB" = internal constant i32 42
+
+// CHECK: @"?Exported@@3ABHB" = dso_local dllexport constant i32* @"?$RT1@Exported@@3ABHB"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5725,6 +5725,9 @@
   /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
   if (emitter) emitter->finalize(GV);
   setGVProperties(GV, VD);
+  if (GV->getDLLStorageClass() == llvm::GlobalVariable::DLLExportStorageClass)
+// The reference temporary should never be dllexport.
+GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
   GV->setAlignment(Align.getAsAlign());
   if (supportsCOMDAT() && GV->isWeakForLinker())
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118782: clangd: Add a break for every case in the PopulateSwitch tweak

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

FWIW I prefer the existing behaviour (reasons below). @kadircet, thoughts?

- The output with `break` is harder to visually scan. (In styles where `break` 
goes on its own line)
- The output is annoying to edit when you *do* want to deal with blocks of 
cases at once. When editing cases individually anyway, I don't find typing 
`break` a burden.
- The goal isn't to provide a correct body, but to avoid having to 
remember/type all the cases. Any extra output is a distraction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118782

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


[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

> This is assuming a semantic connection that we don't know exists.
> Without any more specific reason to draw this connection, this seems like a 
> heuristic that could equally be applied by the client.

The difference being that the client would have to poke around in the 
technically opaque Command structure to find the range.
Seems possible, but presumably there are no guarantees about the properties?

> Is there a particular action/diagnostic pair you want this for?

Yes, -Wswitch/PopulateSwitch (which is the only quickfix kind of tweak at the 
moment).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

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


[clang] ffe8720 - Reduce dependencies on llvm/BinaryFormat/Dwarf.h

2022-02-04 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-02-04T11:44:03+01:00
New Revision: ffe8720aa060d66297500f30bb8ad02114e40326

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

LOG: Reduce dependencies on llvm/BinaryFormat/Dwarf.h

This header is very large (3M Lines once expended) and was included in location
where dwarf-specific information were not needed.

More specifically, this commit suppresses the dependencies on
llvm/BinaryFormat/Dwarf.h in two headers: llvm/IR/IRBuilder.h and
llvm/IR/DebugInfoMetadata.h. As these headers (esp. the former) are widely used,
this has a decent impact on number of preprocessed lines generated during
compilation of LLVM, as showcased below.

This is achieved by moving some definitions back to the .cpp file, no
performance impact implied[0].

As a consequence of that patch, downstream user may need to manually some extra
files:

llvm/IR/IRBuilder.h no longer includes llvm/BinaryFormat/Dwarf.h
llvm/IR/DebugInfoMetadata.h no longer includes llvm/BinaryFormat/Dwarf.h

In some situations, codes maybe relying on the fact that
llvm/BinaryFormat/Dwarf.h was including llvm/ADT/Triple.h, this hidden
dependency now needs to be explicit.

$ clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Transforms/Scalar/*.cpp 
-std=c++14 -fno-rtti -fno-exceptions | wc -l
after:   10978519
before:  11245451

Related Discourse thread: 
https://llvm.discourse.group/t/include-what-you-use-include-cleanup
[0] 
https://llvm-compile-time-tracker.com/compare.php?from=fa7145dfbf94cb93b1c3e610582c495cb806569b&to=995d3e326ee1d9489145e20762c65465a9caeab4&stat=instructions

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

Added: 


Modified: 
clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/LiveDebugVariables.cpp
llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
llvm/lib/CodeGen/TargetInstrInfo.cpp
llvm/lib/CodeGen/TargetRegisterInfo.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
llvm/lib/Target/BPF/BPFPreserveDIType.cpp
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/unittests/IR/DebugTypeODRUniquingTest.cpp
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp 
b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
index d2ef284232547..a576ade322d83 100644
--- a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
@@ -14,6 +14,7 @@
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
 using namespace llvm;

diff  --git a/llvm/include/llvm/IR/DIBuilder.h 
b/llvm/include/llvm/IR/DIBuilder.h
index fc461fc3f49fa..d3aad3719900e 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -21,6 +21,7 @@
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/TrackingMDRef.h"
 #include "llvm/Support/Casting.h"

diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h 
b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 96569179060f3..c6ef69eed24b9 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -22,7 +22,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
-#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/Support/Casting.h"
@@ -61,6 +60,10 @@
 
 namespace llvm {
 
+namespace dwarf {
+enum Tag : uint16_t;
+}
+
 extern cl::opt EnableFSDiscriminator;
 
 class DITypeRefArray {
@@ -156,7 +159,7 @@ class DINode : public MDNode {
   void setTag(unsigned Tag) { SubclassData16 = Tag; }
 
 public:
-  dwarf::Tag getTag() const { return (dwarf::Tag)SubclassData16; }
+  dwarf::Tag getTag() const;
 
   /// Debug info flags.
   //

[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2022-02-04 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54943#3292552 , @0x8000- wrote:

> @aaron.ballman - can this land for Clang14, or does it have wait for 15?
>
> Are there any other reviewers that can approve this?

Sadly, cherry-picking to 14 is very unlikely, as this is not a bugfix. :/
On the other hand, it missed so many releases so lets stay positive :)

Aaron did the review and I think he should accept too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D118781: Reduce dependencies on llvm/BinaryFormat/Dwarf.h

2022-02-04 Thread serge 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 rGffe8720aa060: Reduce dependencies on 
llvm/BinaryFormat/Dwarf.h (authored by serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118781

Files:
  clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/CodeGen/LiveDebugVariables.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/TargetInstrInfo.cpp
  llvm/lib/CodeGen/TargetRegisterInfo.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
  llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
  llvm/lib/Target/BPF/BPFPreserveDIType.cpp
  llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
  llvm/unittests/IR/DebugTypeODRUniquingTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/IRBuilder.h"
 
 using namespace mlir;
Index: llvm/unittests/IR/DebugTypeODRUniquingTest.cpp
===
--- llvm/unittests/IR/DebugTypeODRUniquingTest.cpp
+++ llvm/unittests/IR/DebugTypeODRUniquingTest.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/LLVMContext.h"
 #include "gtest/gtest.h"
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constant.h"
Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -13,6 +13,7 @@
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/EHPersonalities.h"
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/IR/CFG.h"
Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/BasicBlock.h"
Index: llvm/lib/Transforms/Coroutines/CoroSplit.cpp
===
--- llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Analysis/CallGraphSCCPass.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/LazyCallGraph.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/Argument.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/BasicBlock.h"
Index: llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
===
--- llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
@@ -14,6 +14,7 @@
 #include "RISCV.h"
 #include "RISCVMachineFunctionInfo.h"
 #include "RISCVSubtarget.h

[PATCH] D115856: [syntax][pseudo] Introduce the spec C++ grammar.

2022-02-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 405904.
hokein marked 2 inline comments as done.
hokein added a comment.

rebase and address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115856

Files:
  clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
  clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
  clang/test/CMakeLists.txt
  clang/test/Syntax/check-cxx-bnf.test
  clang/test/Syntax/lit.local.cfg
  clang/tools/CMakeLists.txt
  clang/tools/clang-pseudo/CMakeLists.txt
  clang/tools/clang-pseudo/ClangPseudo.cpp

Index: clang/tools/clang-pseudo/ClangPseudo.cpp
===
--- /dev/null
+++ clang/tools/clang-pseudo/ClangPseudo.cpp
@@ -0,0 +1,47 @@
+//===-- ClangPseudo.cpp - Clang pseudo parser tool ===//
+//
+// 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 "clang/Tooling/Syntax/Pseudo/Grammar.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using clang::syntax::pseudo::Grammar;
+using llvm::cl::desc;
+using llvm::cl::init;
+using llvm::cl::opt;
+
+static opt
+CheckGrammar("check-grammar", desc("Parse and check a BNF grammar file."),
+ init(""));
+
+int main(int argc, char *argv[]) {
+  llvm::cl::ParseCommandLineOptions(argc, argv, "");
+
+  if (CheckGrammar.getNumOccurrences()) {
+llvm::ErrorOr> Text =
+llvm::MemoryBuffer::getFile(CheckGrammar);
+if (std::error_code EC = Text.getError()) {
+  llvm::errs() << "Error: can't read grammar file '" << CheckGrammar
+   << "': " << EC.message() << "\n";
+  return 1;
+}
+std::vector Diags;
+auto RSpecs = Grammar::parseBNF(Text.get()->getBuffer(), Diags);
+
+if (!Diags.empty()) {
+  llvm::errs() << llvm::join(Diags, "\n");
+  return 2;
+}
+llvm::errs() << llvm::formatv("grammar file {0} is parsed successfully\n",
+  CheckGrammar);
+return 0;
+  }
+  return 0;
+}
Index: clang/tools/clang-pseudo/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/clang-pseudo/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_tool(clang-pseudo
+  ClangPseudo.cpp
+  )
+
+set(CLANG_PSEUDO_LIB_DEPS
+  clangBasic
+  clangToolingSyntaxPseudo
+  )
+
+clang_target_link_libraries(clang-pseudo
+  PRIVATE
+  ${CLANG_PSEUDO_LIB_DEPS}
+  )
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -14,6 +14,7 @@
 add_clang_subdirectory(clang-offload-wrapper)
 add_clang_subdirectory(clang-scan-deps)
 add_clang_subdirectory(clang-repl)
+add_clang_subdirectory(clang-pseudo)
 
 add_clang_subdirectory(c-index-test)
 
Index: clang/test/Syntax/lit.local.cfg
===
--- /dev/null
+++ clang/test/Syntax/lit.local.cfg
@@ -0,0 +1,4 @@
+cxx_bnf_file = os.path.join(config.clang_src_dir, 'lib', 'Tooling', 'Syntax',
+'Pseudo', 'cxx.bnf')
+config.substitutions.append(('%cxx-bnf-file',
+ '%s' % (cxx_bnf_file)))
Index: clang/test/Syntax/check-cxx-bnf.test
===
--- /dev/null
+++ clang/test/Syntax/check-cxx-bnf.test
@@ -0,0 +1,2 @@
+// verify clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
+// RUN: clang-pseudo -check-grammar=%cxx-bnf-file
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -76,6 +76,7 @@
   clang-repl
   clang-diff
   clang-scan-deps
+  clang-pseudo
   diagtool
   hmaptool
   )
Index: clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
===
--- /dev/null
+++ clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
@@ -0,0 +1,739 @@
+# This is a C++ grammar from the C++ standard [1].
+#
+# The grammar is a superset of the true grammar requring semantic constraints to
+# resolve ambiguties. The grammar is context-free and ambiguous (beyond the
+# limit of LR(k)). We use general parsing algorithm (e.g GLR) to handle the
+# grammar and generate a transition table which is used to drive the parsing.
+#
+# It aims to align with the ISO C++ grammar as much as possible. We adjust it
+# to fit the need for the grammar-based parser:
+#  - attributes are omitted, which will be handled as comments;
+#  - we don't allow nullable non-terminal symbols. There are few null

[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

TL;DR: I think this makes sense to add, but we should make it slightly more 
restrictive.

In D118976#3296182 , @ckandeler wrote:

>> This is assuming a semantic connection that we don't know exists.
>> Without any more specific reason to draw this connection, this seems like a 
>> heuristic that could equally be applied by the client.
>
> The difference being that the client would have to poke around in the 
> technically opaque Command structure to find the range.
> Seems possible, but presumably there are no guarantees about the properties?

FWIW, I don't think poking in command is required: the test you're adding here 
is that:

- tweak kind is quickfix: tweak kind is exposed as CodeAction.kind
- diag range == params.range: both diag and params are supplied by the client

However the protocol is complicated enough here as it is without adding 
client-side heuristics, we should probably have the server signal them 
explicitly if we think they're safe.

>> Is there a particular action/diagnostic pair you want this for?
>
> Yes, -Wswitch/PopulateSwitch (which is the only quickfix kind of tweak at the 
> moment).

Yes, makes sense. I think we added the "preferred" logic as a hack.
FWIW, VSCode accepts this as associating the diagnostic with the fix, even 
without CodeAction.Diagnostics set.

But doing this with CodeAction.diagnostics makes at least as much sense, so 
let's support that.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1011
 // We never consider refactorings etc as preferred.
 CodeAction *OnlyFix = nullptr;
 for (auto &Action : Actions) {

This loop is closely related to what you're doing (and the one above isn't).

Maybe we can refactor/combine as something like:

```
Optional OnlyFix; // nullptr means multiple fixes
// ... loop over actions and set OnlyFix ...
if (OnlyFix && *OnlyFix) {
  (*OnlyFix)->isPreferred = true;
  if (Diags.size() == 1 && Diags.front().range == Selection)
(*OnlyFix)->diagnostics = {Diags.front()];
}
```

Note this adds the conditions:
 - should be only one diagnostic in context
 - should be only one quickfix action

I think these reduce the chance of false positives.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

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


[clang] e1db505 - [syntax][pseudo] Introduce the C++ spec grammar.

2022-02-04 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-02-04T11:58:50+01:00
New Revision: e1db505b42f4d0799640988bbdf1ab83a661a46c

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

LOG: [syntax][pseudo] Introduce the C++ spec grammar.

Add a dummy clang-pseudo tool (right now it accepts and parses the
grammar file).

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

Added: 
clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
clang/test/Syntax/check-cxx-bnf.test
clang/test/Syntax/lit.local.cfg
clang/tools/clang-pseudo/CMakeLists.txt
clang/tools/clang-pseudo/ClangPseudo.cpp

Modified: 
clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
clang/test/CMakeLists.txt
clang/tools/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp 
b/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
index 40181e049f253..cf3e3e10ec540 100644
--- a/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
+++ b/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
@@ -92,7 +92,7 @@ class GrammarBuilder {
   return It->second;
 };
 for (const auto &Spec : Specs) {
-  assert(Spec.Sequence.size() < Rule::MaxElements);
+  assert(Spec.Sequence.size() <= Rule::MaxElements);
   Symbols.clear();
   for (const RuleSpec::Element &Elt : Spec.Sequence)
 Symbols.push_back(Lookup(Elt.Symbol));

diff  --git a/clang/lib/Tooling/Syntax/Pseudo/cxx.bnf 
b/clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
new file mode 100644
index 0..ee83abfa00626
--- /dev/null
+++ b/clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
@@ -0,0 +1,739 @@
+# This is a C++ grammar from the C++ standard [1].
+#
+# The grammar is a superset of the true grammar requring semantic constraints 
to
+# resolve ambiguties. The grammar is context-free and ambiguous (beyond the
+# limit of LR(k)). We use general parsing algorithm (e.g GLR) to handle the
+# grammar and generate a transition table which is used to drive the parsing.
+#
+# It aims to align with the ISO C++ grammar as much as possible. We adjust it
+# to fit the need for the grammar-based parser:
+#  - attributes are omitted, which will be handled as comments;
+#  - we don't allow nullable non-terminal symbols. There are few nullable
+#non-terminals in the spec grammar, they are adjusted to be non-nullable;
+#  - the file merely describes the core C++ grammar. Preprocessor directives 
and
+#lexical conversions are omitted as we reuse clang's lexer and run a fake
+#preprocessor;
+#
+# Guidelines:
+#   - non-terminals are lower_case; terminals (aka tokens) correspond to
+# clang::TokenKind, written as "IDENTIFIER", "USING", "::" etc;
+#   - optional symbols are supported, with a _opt suffix;
+#
+# [1] https://isocpp.org/files/papers/N4860.pdf
+#
+#
+# _ serves as a "fake" start symbol, coming with real grammar symbols.
+_ := translation-unit
+
+# gram.key
+typedef-name := IDENTIFIER
+typedef-name := simple-template-id
+namespace-name := IDENTIFIER
+namespace-name := namespace-alias
+namespace-alias := IDENTIFIER
+class-name := IDENTIFIER
+class-name := simple-template-id
+enum-name := IDENTIFIER
+template-name := IDENTIFIER
+
+# gram.basic
+#! Custom modifications to eliminate optional declaration-seq
+translation-unit := declaration-seq
+translation-unit := global-module-fragment_opt module-declaration 
declaration-seq_opt private-module-fragment_opt
+
+# gram.expr
+# expr.prim
+primary-expression := literal
+primary-expression := THIS
+primary-expression := ( expression )
+primary-expression := id-expression
+primary-expression := lambda-expression
+primary-expression := fold-expression
+primary-expression := requires-expression
+id-expression := unqualified-id
+id-expression := qualified-id
+unqualified-id := IDENTIFIER
+unqualified-id := operator-function-id
+unqualified-id := conversion-function-id
+unqualified-id := literal-operator-id
+unqualified-id := ~ type-name
+unqualified-id := ~ decltype-specifier
+unqualified-id := template-id
+qualified-id := nested-name-specifier TEMPLATE_opt unqualified-id
+nested-name-specifier := ::
+nested-name-specifier := type-name ::
+nested-name-specifier := namespace-name ::
+nested-name-specifier := decltype-specifier ::
+nested-name-specifier := nested-name-specifier IDENTIFIER ::
+nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id 
::
+lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
+lambda-expression := lambda-introducer < template-parameter-list > 
requires-clause_opt lambda-declarator_opt compound-statement
+lambda-introducer := [ lambda-capture_opt ]
+lambda-declarator := ( parameter-declaration-clause ) decl-specifier-seq_opt 
noexcept-specifier_opt trailing-return-type_opt requires-clause_opt
+lambda-capture := capture-default
+lambda-

[PATCH] D115856: [syntax][pseudo] Introduce the spec C++ grammar.

2022-02-04 Thread Haojian Wu 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 rGe1db505b42f4: [syntax][pseudo] Introduce the C++ spec 
grammar. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115856

Files:
  clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
  clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
  clang/test/CMakeLists.txt
  clang/test/Syntax/check-cxx-bnf.test
  clang/test/Syntax/lit.local.cfg
  clang/tools/CMakeLists.txt
  clang/tools/clang-pseudo/CMakeLists.txt
  clang/tools/clang-pseudo/ClangPseudo.cpp

Index: clang/tools/clang-pseudo/ClangPseudo.cpp
===
--- /dev/null
+++ clang/tools/clang-pseudo/ClangPseudo.cpp
@@ -0,0 +1,47 @@
+//===-- ClangPseudo.cpp - Clang pseudo parser tool ===//
+//
+// 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 "clang/Tooling/Syntax/Pseudo/Grammar.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using clang::syntax::pseudo::Grammar;
+using llvm::cl::desc;
+using llvm::cl::init;
+using llvm::cl::opt;
+
+static opt
+CheckGrammar("check-grammar", desc("Parse and check a BNF grammar file."),
+ init(""));
+
+int main(int argc, char *argv[]) {
+  llvm::cl::ParseCommandLineOptions(argc, argv, "");
+
+  if (CheckGrammar.getNumOccurrences()) {
+llvm::ErrorOr> Text =
+llvm::MemoryBuffer::getFile(CheckGrammar);
+if (std::error_code EC = Text.getError()) {
+  llvm::errs() << "Error: can't read grammar file '" << CheckGrammar
+   << "': " << EC.message() << "\n";
+  return 1;
+}
+std::vector Diags;
+auto RSpecs = Grammar::parseBNF(Text.get()->getBuffer(), Diags);
+
+if (!Diags.empty()) {
+  llvm::errs() << llvm::join(Diags, "\n");
+  return 2;
+}
+llvm::errs() << llvm::formatv("grammar file {0} is parsed successfully\n",
+  CheckGrammar);
+return 0;
+  }
+  return 0;
+}
Index: clang/tools/clang-pseudo/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/clang-pseudo/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_tool(clang-pseudo
+  ClangPseudo.cpp
+  )
+
+set(CLANG_PSEUDO_LIB_DEPS
+  clangBasic
+  clangToolingSyntaxPseudo
+  )
+
+clang_target_link_libraries(clang-pseudo
+  PRIVATE
+  ${CLANG_PSEUDO_LIB_DEPS}
+  )
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -14,6 +14,7 @@
 add_clang_subdirectory(clang-offload-wrapper)
 add_clang_subdirectory(clang-scan-deps)
 add_clang_subdirectory(clang-repl)
+add_clang_subdirectory(clang-pseudo)
 
 add_clang_subdirectory(c-index-test)
 
Index: clang/test/Syntax/lit.local.cfg
===
--- /dev/null
+++ clang/test/Syntax/lit.local.cfg
@@ -0,0 +1,4 @@
+cxx_bnf_file = os.path.join(config.clang_src_dir, 'lib', 'Tooling', 'Syntax',
+'Pseudo', 'cxx.bnf')
+config.substitutions.append(('%cxx-bnf-file',
+ '%s' % (cxx_bnf_file)))
Index: clang/test/Syntax/check-cxx-bnf.test
===
--- /dev/null
+++ clang/test/Syntax/check-cxx-bnf.test
@@ -0,0 +1,2 @@
+// verify clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
+// RUN: clang-pseudo -check-grammar=%cxx-bnf-file
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -76,6 +76,7 @@
   clang-repl
   clang-diff
   clang-scan-deps
+  clang-pseudo
   diagtool
   hmaptool
   )
Index: clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
===
--- /dev/null
+++ clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
@@ -0,0 +1,739 @@
+# This is a C++ grammar from the C++ standard [1].
+#
+# The grammar is a superset of the true grammar requring semantic constraints to
+# resolve ambiguties. The grammar is context-free and ambiguous (beyond the
+# limit of LR(k)). We use general parsing algorithm (e.g GLR) to handle the
+# grammar and generate a transition table which is used to drive the parsing.
+#
+# It aims to align with the ISO C++ grammar as much as possible. We adjust it
+# to fit the need for the grammar-based parser:
+#  - attributes are omitted, which will 

[PATCH] D118904: [clang][CodeGen] Use memory type representation in `va_arg`

2022-02-04 Thread Jan Svoboda 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 rG42afaf7f472c: [clang][CodeGen] Use memory type 
representation in `va_arg` (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D118904?vs=405644&id=405909#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118904

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm64-arguments.c


Index: clang/test/CodeGen/arm64-arguments.c
===
--- clang/test/CodeGen/arm64-arguments.c
+++ clang/test/CodeGen/arm64-arguments.c
@@ -196,6 +196,16 @@
 __builtin_va_end(ap);
 return ll;
 }
+_Bool t3(int i, ...) {
+  // CHECK: t3
+  __builtin_va_list ap;
+  __builtin_va_start(ap, i);
+  // CHECK:  %0 = va_arg {{.*}}* %ap, i8
+  // CHECK-NEXT: store i8 %0, i8* %varet, align 1
+  _Bool b = __builtin_va_arg(ap, _Bool);
+  __builtin_va_end(ap);
+  return b;
+}
 
 #include 
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -709,7 +709,8 @@
"Unexpected CoerceToType seen in arginfo in generic VAArg 
emitter!");
 
 Address Temp = CGF.CreateMemTemp(Ty, "varet");
-Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(), 
CGF.ConvertType(Ty));
+Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(),
+  CGF.ConvertTypeForMem(Ty));
 CGF.Builder.CreateStore(Val, Temp);
 return Temp;
   }


Index: clang/test/CodeGen/arm64-arguments.c
===
--- clang/test/CodeGen/arm64-arguments.c
+++ clang/test/CodeGen/arm64-arguments.c
@@ -196,6 +196,16 @@
 __builtin_va_end(ap);
 return ll;
 }
+_Bool t3(int i, ...) {
+  // CHECK: t3
+  __builtin_va_list ap;
+  __builtin_va_start(ap, i);
+  // CHECK:  %0 = va_arg {{.*}}* %ap, i8
+  // CHECK-NEXT: store i8 %0, i8* %varet, align 1
+  _Bool b = __builtin_va_arg(ap, _Bool);
+  __builtin_va_end(ap);
+  return b;
+}
 
 #include 
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -709,7 +709,8 @@
"Unexpected CoerceToType seen in arginfo in generic VAArg emitter!");
 
 Address Temp = CGF.CreateMemTemp(Ty, "varet");
-Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(), CGF.ConvertType(Ty));
+Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(),
+  CGF.ConvertTypeForMem(Ty));
 CGF.Builder.CreateStore(Val, Temp);
 return Temp;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 42afaf7 - [clang][CodeGen] Use memory type representation in `va_arg`

2022-02-04 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-02-04T12:10:57+01:00
New Revision: 42afaf7f472ce8ae14f1aa3858f1a8f3abc4ac67

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

LOG: [clang][CodeGen] Use memory type representation in `va_arg`

Some types (e.g. `_Bool`) have different scalar and memory representations. 
CodeGen for `va_arg` didn't take this into account, leading to an assertion 
failures with different types.

This patch makes sure we use memory representation for `va_arg`.

Reviewed By: ahatanak

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/arm64-arguments.c

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 9af3004ebcc5b..18967237280f8 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -709,7 +709,8 @@ Address EmitVAArgInstr(CodeGenFunction &CGF, Address 
VAListAddr, QualType Ty,
"Unexpected CoerceToType seen in arginfo in generic VAArg 
emitter!");
 
 Address Temp = CGF.CreateMemTemp(Ty, "varet");
-Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(), 
CGF.ConvertType(Ty));
+Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(),
+  CGF.ConvertTypeForMem(Ty));
 CGF.Builder.CreateStore(Val, Temp);
 return Temp;
   }

diff  --git a/clang/test/CodeGen/arm64-arguments.c 
b/clang/test/CodeGen/arm64-arguments.c
index 9b1046269375d..16997cae573de 100644
--- a/clang/test/CodeGen/arm64-arguments.c
+++ b/clang/test/CodeGen/arm64-arguments.c
@@ -196,6 +196,16 @@ double t2(int i, ...) {
 __builtin_va_end(ap);
 return ll;
 }
+_Bool t3(int i, ...) {
+  // CHECK: t3
+  __builtin_va_list ap;
+  __builtin_va_start(ap, i);
+  // CHECK:  %0 = va_arg {{.*}}* %ap, i8
+  // CHECK-NEXT: store i8 %0, i8* %varet, align 1
+  _Bool b = __builtin_va_arg(ap, _Bool);
+  __builtin_va_end(ap);
+  return b;
+}
 
 #include 
 



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


[PATCH] D118921: [Format] Don't derive pointers right based on space before method ref-qualifiers

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added a comment.

Thanks!




Comment at: clang/unittests/Format/FormatTest.cpp:9689-9692
+  // There's always a space between the function and its trailing qualifiers.
+  // This isn't evidence for PAS_Right (or for PAS_Left).
+  std::string Prefix = "void a() &;\n"
+   "void b() &;\n";

benhamilton wrote:
> Worth a test with `&&`?
> 
Good idea, merged it with the overloaded-operator test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118921

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


[clang] acc3ce9 - [Format] Don't derive pointers right based on space before method ref-qualifiers

2022-02-04 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-02-04T12:13:58+01:00
New Revision: acc3ce945c32a71ec077df379c99d859f31cc741

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

LOG: [Format] Don't derive pointers right based on space before method 
ref-qualifiers

The second space in `void foo() &` is always produced by clang-format,
and isn't evidence of any particular style.

Before this patch, it was considered evidence of PAS_Right, because
there is a space before a pointerlike ampersand.

This caused the following code to have "unstable" pointer alignment:
  void a() &;
  void b() &;
  int *x;
PAS_Left, Derive=false would produce 'int* x' with other lines unchanged.
But subsequent formatting with Derive=true would produce 'int *x' again.

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index daa815106049..551d8cfe7ec1 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -18,6 +18,7 @@
 #include "ContinuationIndenter.h"
 #include "DefinitionBlockSeparator.h"
 #include "FormatInternal.h"
+#include "FormatToken.h"
 #include "FormatTokenLexer.h"
 #include "NamespaceEndCommentsFixer.h"
 #include "QualifierAlignmentFixer.h"
@@ -1940,6 +1941,14 @@ class Formatter : public TokenAnalyzer {
   for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
 if (!Tok->is(TT_PointerOrReference))
   continue;
+// Don't treat space in `void foo() &&` as evidence.
+if (const auto *Prev = Tok->getPreviousNonComment()) {
+  if (Prev->is(tok::r_paren) && Prev->MatchingParen)
+if (const auto *Func = 
Prev->MatchingParen->getPreviousNonComment())
+  if (Func->isOneOf(TT_FunctionDeclarationName, TT_StartOfName,
+TT_OverloadedOperator))
+continue;
+}
 bool SpaceBefore = Tok->hasWhitespaceBefore();
 bool SpaceAfter = Tok->Next->hasWhitespaceBefore();
 if (SpaceBefore && !SpaceAfter)

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 96efc0e029e0..565b125dd1bc 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9710,6 +9710,25 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
AlignLeftBreakTemplate);
 
   verifyFormat("void (*foopt)(int) = &func;");
+
+  FormatStyle DerivePointerAlignment = getLLVMStyle();
+  DerivePointerAlignment.DerivePointerAlignment = true;
+  // There's always a space between the function and its trailing qualifiers.
+  // This isn't evidence for PAS_Right (or for PAS_Left).
+  std::string Prefix = "void a() &;\n"
+   "void b() &;\n";
+  verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
+  verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
+  // Same if the function is an overloaded operator instead.
+  Prefix = "void operator()() &;\n"
+   "void operator()() &;\n";
+  verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
+  verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
+  // However a space between cv-qualifiers and ref-qualifiers *is* evidence.
+  Prefix = "void a() const &;\n"
+   "void b() const &;\n";
+  EXPECT_EQ(Prefix + "int *x;",
+format(Prefix + "int* x;", DerivePointerAlignment));
 }
 
 TEST_F(FormatTest, UnderstandsNewAndDelete) {



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


[PATCH] D118921: [Format] Don't derive pointers right based on space before method ref-qualifiers

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGacc3ce945c32: [Format] Don't derive pointers right 
based on space before method ref-qualifiers (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118921

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9710,6 +9710,25 @@
AlignLeftBreakTemplate);
 
   verifyFormat("void (*foopt)(int) = &func;");
+
+  FormatStyle DerivePointerAlignment = getLLVMStyle();
+  DerivePointerAlignment.DerivePointerAlignment = true;
+  // There's always a space between the function and its trailing qualifiers.
+  // This isn't evidence for PAS_Right (or for PAS_Left).
+  std::string Prefix = "void a() &;\n"
+   "void b() &;\n";
+  verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
+  verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
+  // Same if the function is an overloaded operator instead.
+  Prefix = "void operator()() &;\n"
+   "void operator()() &;\n";
+  verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
+  verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
+  // However a space between cv-qualifiers and ref-qualifiers *is* evidence.
+  Prefix = "void a() const &;\n"
+   "void b() const &;\n";
+  EXPECT_EQ(Prefix + "int *x;",
+format(Prefix + "int* x;", DerivePointerAlignment));
 }
 
 TEST_F(FormatTest, UnderstandsNewAndDelete) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -18,6 +18,7 @@
 #include "ContinuationIndenter.h"
 #include "DefinitionBlockSeparator.h"
 #include "FormatInternal.h"
+#include "FormatToken.h"
 #include "FormatTokenLexer.h"
 #include "NamespaceEndCommentsFixer.h"
 #include "QualifierAlignmentFixer.h"
@@ -1940,6 +1941,14 @@
   for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
 if (!Tok->is(TT_PointerOrReference))
   continue;
+// Don't treat space in `void foo() &&` as evidence.
+if (const auto *Prev = Tok->getPreviousNonComment()) {
+  if (Prev->is(tok::r_paren) && Prev->MatchingParen)
+if (const auto *Func = 
Prev->MatchingParen->getPreviousNonComment())
+  if (Func->isOneOf(TT_FunctionDeclarationName, TT_StartOfName,
+TT_OverloadedOperator))
+continue;
+}
 bool SpaceBefore = Tok->hasWhitespaceBefore();
 bool SpaceAfter = Tok->Next->hasWhitespaceBefore();
 if (SpaceBefore && !SpaceAfter)


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9710,6 +9710,25 @@
AlignLeftBreakTemplate);
 
   verifyFormat("void (*foopt)(int) = &func;");
+
+  FormatStyle DerivePointerAlignment = getLLVMStyle();
+  DerivePointerAlignment.DerivePointerAlignment = true;
+  // There's always a space between the function and its trailing qualifiers.
+  // This isn't evidence for PAS_Right (or for PAS_Left).
+  std::string Prefix = "void a() &;\n"
+   "void b() &;\n";
+  verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
+  verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
+  // Same if the function is an overloaded operator instead.
+  Prefix = "void operator()() &;\n"
+   "void operator()() &;\n";
+  verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
+  verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
+  // However a space between cv-qualifiers and ref-qualifiers *is* evidence.
+  Prefix = "void a() const &;\n"
+   "void b() const &;\n";
+  EXPECT_EQ(Prefix + "int *x;",
+format(Prefix + "int* x;", DerivePointerAlignment));
 }
 
 TEST_F(FormatTest, UnderstandsNewAndDelete) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -18,6 +18,7 @@
 #include "ContinuationIndenter.h"
 #include "DefinitionBlockSeparator.h"
 #include "FormatInternal.h"
+#include "FormatToken.h"
 #include "FormatTokenLexer.h"
 #include "NamespaceEndCommentsFixer.h"
 #include "QualifierAlignmentFixer.h"
@@ -1940,6 +1941,14 @@
   for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) {
 if (!Tok->is(TT_PointerOrReference))
   continue;
+// Don't treat sp

[clang] cc8ed7b - [Format] Also test rvalue-qualified functions

2022-02-04 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-02-04T12:17:25+01:00
New Revision: cc8ed7b5aaa4ab9d11cb8a5bc97222df966e0f58

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

LOG: [Format] Also test rvalue-qualified functions

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 565b125dd1bc..14942d1ba420 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9719,9 +9719,9 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
"void b() &;\n";
   verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
   verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
-  // Same if the function is an overloaded operator instead.
-  Prefix = "void operator()() &;\n"
-   "void operator()() &;\n";
+  // Same if the function is an overloaded operator, and with &&.
+  Prefix = "void operator()() &&;\n"
+   "void operator()() &&;\n";
   verifyFormat(Prefix + "int* x;", DerivePointerAlignment);
   verifyFormat(Prefix + "int *x;", DerivePointerAlignment);
   // However a space between cv-qualifiers and ref-qualifiers *is* evidence.



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


[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 405911.
ckandeler added a comment.

Formatting & logic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,9 +986,9 @@
 
   // Now enumerate the semantic code actions.
   auto ConsumeActions =
-  [Reply = std::move(Reply), File, Selection = Params.range,
-   FixIts = std::move(FixIts), this](
-  llvm::Expected> Tweaks) mutable {
+  [Diags = Params.context.diagnostics, Reply = std::move(Reply), File,
+   Selection = Params.range, FixIts = std::move(FixIts), this](
+llvm::Expected> Tweaks) mutable {
 if (!Tweaks)
   return Reply(Tweaks.takeError());
 
@@ -999,17 +999,21 @@
 
 // If there's exactly one quick-fix, call it "preferred".
 // We never consider refactorings etc as preferred.
-CodeAction *OnlyFix = nullptr;
+Optional OnlyFix; // nullptr means multiple fixes
 for (auto &Action : Actions) {
   if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND) {
 if (OnlyFix) {
-  OnlyFix->isPreferred = false;
+  *OnlyFix = nullptr;
   break;
 }
-Action.isPreferred = true;
 OnlyFix = &Action;
   }
 }
+if (OnlyFix && *OnlyFix) {
+  (*OnlyFix)->isPreferred = true;
+  if (Diags.size() == 1 && Diags.front().range == Selection)
+(*OnlyFix)->diagnostics = {Diags.front()};
+}
 
 if (SupportsCodeAction)
   return Reply(llvm::json::Array(Actions));


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,9 +986,9 @@
 
   // Now enumerate the semantic code actions.
   auto ConsumeActions =
-  [Reply = std::move(Reply), File, Selection = Params.range,
-   FixIts = std::move(FixIts), this](
-  llvm::Expected> Tweaks) mutable {
+  [Diags = Params.context.diagnostics, Reply = std::move(Reply), File,
+   Selection = Params.range, FixIts = std::move(FixIts), this](
+llvm::Expected> Tweaks) mutable {
 if (!Tweaks)
   return Reply(Tweaks.takeError());
 
@@ -999,17 +999,21 @@
 
 // If there's exactly one quick-fix, call it "preferred".
 // We never consider refactorings etc as preferred.
-CodeAction *OnlyFix = nullptr;
+Optional OnlyFix; // nullptr means multiple fixes
 for (auto &Action : Actions) {
   if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND) {
 if (OnlyFix) {
-  OnlyFix->isPreferred = false;
+  *OnlyFix = nullptr;
   break;
 }
-Action.isPreferred = true;
 OnlyFix = &Action;
   }
 }
+if (OnlyFix && *OnlyFix) {
+  (*OnlyFix)->isPreferred = true;
+  if (Diags.size() == 1 && Diags.front().range == Selection)
+(*OnlyFix)->diagnostics = {Diags.front()};
+}
 
 if (SupportsCodeAction)
   return Reply(llvm::json::Array(Actions));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1011
 // We never consider refactorings etc as preferred.
 CodeAction *OnlyFix = nullptr;
 for (auto &Action : Actions) {

sammccall wrote:
> This loop is closely related to what you're doing (and the one above isn't).
> 
> Maybe we can refactor/combine as something like:
> 
> ```
> Optional OnlyFix; // nullptr means multiple fixes
> // ... loop over actions and set OnlyFix ...
> if (OnlyFix && *OnlyFix) {
>   (*OnlyFix)->isPreferred = true;
>   if (Diags.size() == 1 && Diags.front().range == Selection)
> (*OnlyFix)->diagnostics = {Diags.front()];
> }
> ```
> 
> Note this adds the conditions:
>  - should be only one diagnostic in context
>  - should be only one quickfix action
> 
> I think these reduce the chance of false positives.
Done. Though it seems the code would work just as well with OnlyFix staying a 
normal pointer. Did I misunderstand something?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

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


[PATCH] D118980: Don't dllexport reference temporaries

2022-02-04 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

LGTM, seems reasonable!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118980

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


[PATCH] D118985: [flang][driver] Add support for `-emit-mlir`

2022-02-04 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added reviewers: rovka, kiranchandramohan, clementval, schweitz.
Herald added subscribers: sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, 
cota, teijeong, rdzhabarov, tatianashp, dang, msifontes, jurahul, Kayjukh, 
grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, 
shauheen, rriddle, mehdi_amini, mgorny.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache, 
jdoerfert.
Herald added a project: clang.

This patch adds support for generating MLIR files in Flang's frontend
driver (i.e. `flang-new -fc1`). `-emit-fir` is added as an alias for
`-emit-mlir`. We may want to decide to split the two in the future.

A new parent class for code-gen frontend actions is introduced:
`CodeGenAction`. We will be using this class to encapsulate logic shared
between all code-generation actions, but not required otherwise. For
now, it will:

- run prescanning, parsing and semantic checks,
- lower the input to MLIR.

`EmitObjAction` is updated to inherit from this class. This means that
the behaviour of `flang-new -fc1 -emit-obj` is also updated (previously,
it would just exit immediately). This change required
`flang/test/Driver/syntax-only.f90` to be updated.

For `-emit-fir`, a specialisation of `CodeGenAction` is introduced:
`EmitMLIRAction`. The key logic for this class is implemented in
`EmitMLIRAction::ExecuteAction`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118985

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-mlir.f90
  flang/test/Driver/syntax-only.f90

Index: flang/test/Driver/syntax-only.f90
===
--- flang/test/Driver/syntax-only.f90
+++ flang/test/Driver/syntax-only.f90
@@ -1,24 +1,28 @@
-! Verify that the compiler driver correctly processes `-fsyntax-only`. By
-! default it will try to run code-generation, but that's not supported yet. We
-! don't need to test the frontend driver here - it runs `-fsyntax-only` by
-! default.
+! Verify that the driver correctly processes `-fsyntax-only`.
+!
+! By default, the compiler driver (`flang`) will create actions/phases to
+! generate machine code (i.e. object files). The `-fsyntax-only` flag is a
+! "phase-control" flag that controls this behavior and makes the driver stop
+! once the semantic checks have been run. The frontend driver (`flang -fc1`)
+! runs `-fsyntax-only` by default (i.e. that's the default action), so the flag
+! can be skipped.
 
 !---
 ! RUN LINES
 !---
-! RUN: not %flang -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=FSYNTAX_ONLY
+! RUN: %flang -fsyntax-only %s 2>&1 | FileCheck %s --allow-empty
+! RUN: %flang_fc1 %s 2>&1 | FileCheck %s --allow-empty
+
 ! RUN: not %flang  %s 2>&1 | FileCheck %s --check-prefix=NO_FSYNTAX_ONLY
+! RUN: not %flang_fc1 -emit-obj %s 2>&1 | FileCheck %s --check-prefix=NO_FSYNTAX_ONLY
 
 !-
 ! EXPECTED OUTPUT
 !-
-! FSYNTAX_ONLY: IF statement is not allowed in IF statement
-! FSYNTAX_ONLY_NEXT: Semantic errors in {{.*}}syntax-only.f90
-
+! CHECK-NOT: error
 ! NO_FSYNTAX_ONLY: error: code-generation is not available yet
 
 !---
 ! INPUT
 !---
-IF (A > 0.0) IF (B < 0.0) A = LOG (A)
-END
+end program
Index: flang/test/Driver/emit-mlir.f90
===
--- /dev/null
+++ flang/test/Driver/emit-mlir.f90
@@ -0,0 +1,21 @@
+! The the `-emit-fir` option
+
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang_fc1 -emit-mlir %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK: module attributes {
+! CHECK-LABEL: func @_QQmain() {
+! CHECK-NEXT:  return
+! CHECK-NEXT: }
+! CHECK-NEXT: }
+
+!--
+! INPUT
+!--
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -65,6 +65,7 @@
 ! HELP-FC1-NEXT:OPTIONS:
 ! HELP-FC1-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -emit-mlir Build the parse tree, then lower it to MLIR
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -falternative-parameter-statement
Index: fl

[PATCH] D118985: [flang][driver] Add support for `-emit-mlir`

2022-02-04 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

`fir-dev` PR: https://github.com/flang-compiler/f18-llvm-project/pull/1008. 
I've also incorporated a few small changes from the subsequent PRs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118985

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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a subscriber: sammccall.
njames93 added a comment.

In D54943#3296191 , @JonasToth wrote:

> In D54943#3292552 , @0x8000- 
> wrote:
>
>> @aaron.ballman - can this land for Clang14, or does it have wait for 15?
>>
>> Are there any other reviewers that can approve this?
>
> Sadly, cherry-picking to 14 is very unlikely, as this is not a bugfix. :/
> On the other hand, it missed so many releases so lets stay positive :)
>
> Aaron did the review and I think he should accept too.

This won't get backported now, besides giving it a few months to test(and 
potentially iron out) on the dev branch isn't such a bad thing.




Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt:33
   LINK_LIBS
+  clangAnalysis
   clangTidy

Will this work under clangd as I don't think that links in the clangAnalysis 
libraries @sammccall?



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:27
+AST_MATCHER(VarDecl, isLocal) { return Node.isLocalVarDecl(); }
+AST_MATCHER_P(DeclStmt, containsDeclaration2,
+  ast_matchers::internal::Matcher, InnerMatcher) {

nit



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:84
+  compoundStmt(
+  findAll(declStmt(allOf(containsDeclaration2(
+ LocalValDecl.bind("local-value")),

`allOf` is unnecessary here as `declStmt` is implicitly an `allOf` matcher.
Also `findAll` isn't the right matcher in this case, you likely want 
`forEachDescendant`. `findAll` will try and match on the `CompoundStmt` which 
is always going to fail.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:102-105
+  // There have been crashes on 'Variable == nullptr', even though the matcher
+  // is not conditional. This comes probably from 'findAll'-matching.
+  if (!Variable || !LocalScope)
+return;

This sounds like a bug that should be raised with ASTMatchers, if its 
reproducible.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:160
+  using namespace utils::fixit;
+  using llvm::Optional;
+  if (VC == VariableCategory::Value && TransformValues) {

This is unnecessary, `llvm::Optional` already has an alias inside the clang 
namespace.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:162-168
+if (Optional Fix = addQualifierToVarDecl(
+*Variable, *Result.Context, DeclSpec::TQ_const,
+QualifierTarget::Value, QualifierPolicy::Right)) {
+  Diag << *Fix;
+  // FIXME: Add '{}' for default initialization if no user-defined default
+  // constructor exists and there is no initializer.
+}

DiagnosticBuilders accept optional fixits as syntactic sugar.
Same goes for below.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:108-112
+- New :doc:`cppcoreguidelines-const-correctness
+  ` check.
+
+  Detects unmodified local variables and suggest adding ``const`` if the 
transformation is possible.
+

This'll need rebasing after branching.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-templates.cpp:3-6
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformValues', value: 
1}, \
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformReferences', 
value: 1}, \
+// RUN:   {key: 'cppcoreguidelines-const-correctness.WarnPointersAsValues', 
value: 0}, \
+// RUN:   {key: 
'cppcoreguidelines-const-correctness.TransformPointersAsValues', value: 0}, \





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp:3-5
+// RUN:  [{key: "cppcoreguidelines-const-correctness.AnalyzeValues", value: 
1},\
+// RUN:   {key: "cppcoreguidelines-const-correctness.WarnPointersAsValues", 
value: 1}, \
+// RUN:   {key: 
"cppcoreguidelines-const-correctness.TransformPointersAsValues", value: 1},\





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp:3-5
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformValues', value: 
1},\
+// RUN:   {key: 'cppcoreguidelines-const-correctness.WarnPointersAsValues', 
value: 0}, \
+// RUN:   {key: 
'cppcoreguidelines-const-correctness.TransformPointersAsValues', value: 0}, \





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-unaligned.cpp:3-5
+// RUN:   {key: 'cppcoreguidelines-const-correctness.TransformValues', 

[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-02-04 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

In D118104#3292862 , @JesApp wrote:

> Well, since this was more of source of confusion than actual incorrect 
> behaviour, I don't think there should be a test for it.
>
> In general though, I think the script is complex enough to warrant some 
> testing. That being said: I don't think they should be part of this patch. 
> Also, I'm doing this on company time and I don't think my boss would be to 
> happy if I wrote a testsuite from scratch when I just wanted to fix one bug. 
> :D

I wasn't asking about creating a new test suite from scratch. I guess I wasn't 
clear. 
The idea I had was a file in `clang-tools-extra\test\clang-tidy\infrastructure` 
with something like this:

  // RUN: %run_clang_tidy 
-checks="-*,google-explicit-constructor,modernize-use-auto" %s | FileCheck 
-check-prefix=CHECK-ENABLED-CHECKS-1 %s
  // CHECK-ENABLED-CHECKS-1: Enabled checks:
  // CHECK-ENABLED-CHECKS-1-NEXT: google-explicit-constructor
  // CHECK-ENABLED-CHECKS-1-NEXT: modernize-use-auto
  
  // RUN: %run_clang_tidy 
-checks="-*,google-explicit-constructor,modernize-use-auto" -config "Checks: 
-modernize-use-auto" %s | FileCheck -check-prefix=CHECK-ENABLED-CHECKS-2 %s
  // CHECK-ENABLED-CHECKS-2: Enabled checks:
  // CHECK-ENABLED-CHECKS-2-NEXT: google-explicit-constructor
  // CHECK-ENABLED-CHECKS-2-NOT: modernize-use-auto

Note: I haven't tested this. If it doesn't work, then it's probably a minor 
tweak away from working.

This would confirm that the "Enabled checks:" message reflects the combined 
results of `-checks` and `-config` arguments.


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

https://reviews.llvm.org/D118104

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


[PATCH] D118927: [clang-tidy] Fix invalid fix-it for cppcoreguidelines-prefer-member-initializer

2022-02-04 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:550
+  // CHECK-FIXES-NEXT: }
+  PR53515(PR53515 &&Other) : M() {
+M = Other.M;

could you please add a test-case for initializer lists, like `std::vector`? Or 
is this not supported?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118927

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


[PATCH] D118927: [clang-tidy] Fix invalid fix-it for cppcoreguidelines-prefer-member-initializer

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 405919.
njames93 added a comment.

Rename test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118927

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -526,14 +526,32 @@
   }
 };
 
-struct AlreadyHasInit {
+struct HasInClassInit {
   int m = 4;
-  AlreadyHasInit() {
+  HasInClassInit() {
 m = 3;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm' should be initialized in a member initializer of the constructor
   }
 };
 
+struct HasInitListInit {
+  int M;
+  // CHECK-MESSAGES: :[[@LINE+5]]:5: warning: 'M' should be initialized in a member initializer of the constructor
+  // CHECK-FIXES: HasInitListInit(const HasInitListInit &Other) : M(Other.M) {
+  // CHECK-FIXES-NEXT: {{^$}}
+  // CHECK-FIXES-NEXT: }
+  HasInitListInit(const HasInitListInit &Other) : M(4) {
+M = Other.M;
+  }
+  // CHECK-MESSAGES: :[[@LINE+5]]:5: warning: 'M' should be initialized in a member initializer of the constructor
+  // CHECK-FIXES: HasInitListInit(HasInitListInit &&Other) : M(Other.M) {
+  // CHECK-FIXES-NEXT: {{^$}}
+  // CHECK-FIXES-NEXT: }
+  HasInitListInit(HasInitListInit &&Other) : M() {
+M = Other.M;
+  }
+};
+
 #define ASSIGN_IN_MACRO(FIELD, VALUE) FIELD = (VALUE);
 
 struct MacroCantFix {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -105,6 +105,12 @@
 Changes in existing checks
 ^^
 
+- Improved :doc:`cppcoreguidelines-prefer-member-initializer
+  ` check.
+
+  Fixed an issue when there was already an initializer in the constructor and
+  the check would try to create another initializer for the same member.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -217,14 +217,25 @@
 }
   } else {
 StringRef InsertPrefix = "";
+bool HasInitAlready = false;
 SourceLocation InsertPos;
+SourceRange ReplaceRange;
 bool AddComma = false;
 bool InvalidFix = false;
 unsigned Index = Field->getFieldIndex();
 const CXXCtorInitializer *LastInListInit = nullptr;
 for (const CXXCtorInitializer *Init : Ctor->inits()) {
-  if (!Init->isWritten())
+  if (!Init->isWritten() || Init->isInClassMemberInitializer())
 continue;
+  if (Init->getMember() == Field) {
+HasInitAlready = true;
+if (isa(Init->getInit()))
+  InsertPos = Init->getRParenLoc();
+else {
+  ReplaceRange = Init->getInit()->getSourceRange();
+}
+break;
+  }
   if (Init->isMemberInitializer() &&
   Index < Init->getMember()->getFieldIndex()) {
 InsertPos = Init->getSourceLocation();
@@ -235,30 +246,38 @@
   }
   LastInListInit = Init;
 }
-if (InsertPos.isInvalid()) {
-  if (LastInListInit) {
-InsertPos = Lexer::getLocForEndOfToken(
-LastInListInit->getRParenLoc(), 0, *Result.SourceManager,
-getLangOpts());
-// Inserting after the last constructor initializer, so we need a
-// comma.
-InsertPrefix = ", ";
-  } else {
-InsertPos = Lexer::getLocForEndOfToken(
-Ctor->getTypeSourceInfo()
-->getTypeLoc()
-.getAs()
-.getLocalRangeEnd(),
-0, *Result.SourceManager, getLangOpts());
-
-// If this is first time in the loop, there are no initializers so
-// `:` declares member initialization list. If this is a subsequent
-// pass then we have already inserted a `:` so continue with a
-// comma.
-InsertPrefix = FirstToCtorInits ? " : " : ", ";
+if (HasInitAlready) {
+  if (InsertPos.isValid())
+InvalidFix |= InsertPos.isMacroID();
+  else
+InvalidFix |= R

[PATCH] D118927: [clang-tidy] Fix invalid fix-it for cppcoreguidelines-prefer-member-initializer

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 2 inline comments as done.
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp:550
+  // CHECK-FIXES-NEXT: }
+  PR53515(PR53515 &&Other) : M() {
+M = Other.M;

JonasToth wrote:
> could you please add a test-case for initializer lists, like `std::vector`? 
> Or is this not supported?
That's not what this fix is about.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118927

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


[clang] ae9c074 - [OpenMP][Clang] Allow ancestor device modifier only with reverse offloading

2022-02-04 Thread Saiyedul Islam via cfe-commits

Author: Saiyedul Islam
Date: 2022-02-04T12:10:14Z
New Revision: ae9c0740648fd8f7010c895ddcf78380da94dd57

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

LOG: [OpenMP][Clang] Allow ancestor device modifier only with reverse offloading

OpenMP Spec 5.0 [2.12.5, Restrictions]: If a device clause in which the
ancestor device-modifier appears is present on the target construct,
then a requires directive with the reverse_offload clause must be
specified.

Reviewed By: ABataev

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

Added: 
clang/test/OpenMP/target_device_ancestor_messages.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_ast_print.cpp
clang/test/OpenMP/target_device_codegen.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 46316bd5d6b2b..d5e653a7fa192 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10696,6 +10696,8 @@ def err_omp_directive_before_requires : Error <
   "'%0' region encountered before requires directive with '%1' clause">;
 def note_omp_requires_encountered_directive : Note <
   "'%0' previously encountered here">;
+def err_omp_device_ancestor_without_requires_reverse_offload : Error <
+  "Device clause with ancestor device-modifier used without specifying 
'requires reverse_offload'">;
 def err_omp_invalid_scope : Error <
   "'#pragma omp %0' directive must appear only in file scope">;
 def note_omp_invalid_length_on_this_ptr_mapping : Note <

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index a500ad4f02209..a4092f0d2b543 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -18759,6 +18759,18 @@ OMPClause 
*Sema::ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
   if (ErrorFound)
 return nullptr;
 
+  // OpenMP 5.0 [2.12.5, Restrictions]
+  // In case of ancestor device-modifier, a requires directive with
+  // the reverse_offload clause must be specified.
+  if (Modifier == OMPC_DEVICE_ancestor) {
+if (!DSAStack->hasRequiresDeclWithClause()) {
+  targetDiag(
+  StartLoc,
+  diag::err_omp_device_ancestor_without_requires_reverse_offload);
+  ErrorFound = true;
+}
+  }
+
   OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
   OpenMPDirectiveKind CaptureRegion =
   getOpenMPCaptureRegionForClause(DKind, OMPC_device, LangOpts.OpenMP);

diff  --git a/clang/test/OpenMP/target_ast_print.cpp 
b/clang/test/OpenMP/target_ast_print.cpp
index 8464b6b3d16df..7d6cd9e14c4e3 100644
--- a/clang/test/OpenMP/target_ast_print.cpp
+++ b/clang/test/OpenMP/target_ast_print.cpp
@@ -342,7 +342,7 @@ int main (int argc, char **argv) {
 // RUN: %clang_cc1 -DOMP5 -verify -fopenmp-simd -fopenmp-version=50 -ast-print 
%s | FileCheck %s --check-prefix OMP5
 // RUN: %clang_cc1 -DOMP5 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -DOMP5 -fopenmp-simd -fopenmp-version=50 -std=c++11 
-include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s 
--check-prefix OMP5
-
+#pragma omp requires reverse_offload
 typedef void **omp_allocator_handle_t;
 extern const omp_allocator_handle_t omp_null_allocator;
 extern const omp_allocator_handle_t omp_default_mem_alloc;

diff  --git a/clang/test/OpenMP/target_device_ancestor_messages.cpp 
b/clang/test/OpenMP/target_device_ancestor_messages.cpp
new file mode 100644
index 0..bc1d668d19143
--- /dev/null
+++ b/clang/test/OpenMP/target_device_ancestor_messages.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple=x86_64 -verify -fopenmp -fopenmp-targets=x86_64 -x 
c++ -fexceptions -fcxx-exceptions %s
+// RUN: %clang_cc1 -triple=x86_64 -verify -fopenmp-simd 
-fopenmp-targets=x86_64 -x c++ -fexceptions -fcxx-exceptions %s
+
+void bar() {
+#pragma omp target device(ancestor : 1) // expected-error {{Device clause with 
ancestor device-modifier used without specifying 'requires reverse_offload'}}
+  ;
+}

diff  --git a/clang/test/OpenMP/target_device_codegen.cpp 
b/clang/test/OpenMP/target_device_codegen.cpp
index abdefef5cc076..f77d2362ddf9a 100644
--- a/clang/test/OpenMP/target_device_codegen.cpp
+++ b/clang/test/OpenMP/target_device_codegen.cpp
@@ -11,7 +11,7 @@
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
-
+#pragma omp requires reverse_offload
 void foo(int n) {
 
   // CHECK:   [[N:%.+]] = load i32, i32* [[N_ADDR:%.+]],



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


[PATCH] D118887: [OpenMP][Clang] Allow ancestor device modifier only with reverse offloading

2022-02-04 Thread Saiyedul Islam 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 rGae9c0740648f: [OpenMP][Clang] Allow ancestor device modifier 
only with reverse offloading (authored by saiislam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118887

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_device_ancestor_messages.cpp
  clang/test/OpenMP/target_device_codegen.cpp


Index: clang/test/OpenMP/target_device_codegen.cpp
===
--- clang/test/OpenMP/target_device_codegen.cpp
+++ clang/test/OpenMP/target_device_codegen.cpp
@@ -11,7 +11,7 @@
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
-
+#pragma omp requires reverse_offload
 void foo(int n) {
 
   // CHECK:   [[N:%.+]] = load i32, i32* [[N_ADDR:%.+]],
Index: clang/test/OpenMP/target_device_ancestor_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_device_ancestor_messages.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple=x86_64 -verify -fopenmp -fopenmp-targets=x86_64 -x 
c++ -fexceptions -fcxx-exceptions %s
+// RUN: %clang_cc1 -triple=x86_64 -verify -fopenmp-simd 
-fopenmp-targets=x86_64 -x c++ -fexceptions -fcxx-exceptions %s
+
+void bar() {
+#pragma omp target device(ancestor : 1) // expected-error {{Device clause with 
ancestor device-modifier used without specifying 'requires reverse_offload'}}
+  ;
+}
Index: clang/test/OpenMP/target_ast_print.cpp
===
--- clang/test/OpenMP/target_ast_print.cpp
+++ clang/test/OpenMP/target_ast_print.cpp
@@ -342,7 +342,7 @@
 // RUN: %clang_cc1 -DOMP5 -verify -fopenmp-simd -fopenmp-version=50 -ast-print 
%s | FileCheck %s --check-prefix OMP5
 // RUN: %clang_cc1 -DOMP5 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -DOMP5 -fopenmp-simd -fopenmp-version=50 -std=c++11 
-include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s 
--check-prefix OMP5
-
+#pragma omp requires reverse_offload
 typedef void **omp_allocator_handle_t;
 extern const omp_allocator_handle_t omp_null_allocator;
 extern const omp_allocator_handle_t omp_default_mem_alloc;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -18759,6 +18759,18 @@
   if (ErrorFound)
 return nullptr;
 
+  // OpenMP 5.0 [2.12.5, Restrictions]
+  // In case of ancestor device-modifier, a requires directive with
+  // the reverse_offload clause must be specified.
+  if (Modifier == OMPC_DEVICE_ancestor) {
+if (!DSAStack->hasRequiresDeclWithClause()) {
+  targetDiag(
+  StartLoc,
+  diag::err_omp_device_ancestor_without_requires_reverse_offload);
+  ErrorFound = true;
+}
+  }
+
   OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
   OpenMPDirectiveKind CaptureRegion =
   getOpenMPCaptureRegionForClause(DKind, OMPC_device, LangOpts.OpenMP);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10696,6 +10696,8 @@
   "'%0' region encountered before requires directive with '%1' clause">;
 def note_omp_requires_encountered_directive : Note <
   "'%0' previously encountered here">;
+def err_omp_device_ancestor_without_requires_reverse_offload : Error <
+  "Device clause with ancestor device-modifier used without specifying 
'requires reverse_offload'">;
 def err_omp_invalid_scope : Error <
   "'#pragma omp %0' directive must appear only in file scope">;
 def note_omp_invalid_length_on_this_ptr_mapping : Note <


Index: clang/test/OpenMP/target_device_codegen.cpp
===
--- clang/test/OpenMP/target_device_codegen.cpp
+++ clang/test/OpenMP/target_device_codegen.cpp
@@ -11,7 +11,7 @@
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
-
+#pragma omp requires reverse_offload
 void foo(int n) {
 
   // CHECK:   [[N:%.+]] = load i32, i32* [[N_ADDR:%.+]],
Index: clang/test/OpenMP/target_device_ancestor_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_device_ancestor_messages.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple=x86_64 -verify -fopenmp -fopenmp-targets=x86_64 -x c++ -fexceptions -fcxx-exceptions %s
+// RUN: %clang_cc1 -triple=x86_64 -verify -fopenmp-simd -fopenmp-targets=x86_64 -x c++ -fexceptions -fcxx-exceptions %s
+
+void bar() {
+#pragma omp target device(ances

[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D118104#3296340 , @salman-javed-nz 
wrote:

> In D118104#3292862 , @JesApp wrote:
>
>> Well, since this was more of source of confusion than actual incorrect 
>> behaviour, I don't think there should be a test for it.
>>
>> In general though, I think the script is complex enough to warrant some 
>> testing. That being said: I don't think they should be part of this patch. 
>> Also, I'm doing this on company time and I don't think my boss would be to 
>> happy if I wrote a testsuite from scratch when I just wanted to fix one bug. 
>> :D
>
> The idea I had was a file in 
> `clang-tools-extra\test\clang-tidy\infrastructure` with something like this:
>
>   // RUN: %run_clang_tidy 
> -checks="-*,google-explicit-constructor,modernize-use-auto" %s | FileCheck 
> -check-prefix=CHECK-ENABLED-CHECKS-1 %s
>   // CHECK-ENABLED-CHECKS-1: Enabled checks:
>   // CHECK-ENABLED-CHECKS-1-NEXT: google-explicit-constructor
>   // CHECK-ENABLED-CHECKS-1-NEXT: modernize-use-auto
>   
>   // RUN: %run_clang_tidy 
> -checks="-*,google-explicit-constructor,modernize-use-auto" -config "Checks: 
> -modernize-use-auto" %s | FileCheck -check-prefix=CHECK-ENABLED-CHECKS-2 %s
>   // CHECK-ENABLED-CHECKS-2: Enabled checks:
>   // CHECK-ENABLED-CHECKS-2-NEXT: google-explicit-constructor
>   // CHECK-ENABLED-CHECKS-2-NOT: modernize-use-auto
>
> Note: I haven't tested this. If it doesn't work, then it's probably a minor 
> tweak away from working.
>
> This would confirm that the "Enabled checks:" message reflects the combined 
> results of `-checks` and `-config` arguments.
> I was wondering whether a test like the one above was an easy enough win to 
> consider bundling in with the fix. In my initial comment I just wanted to 
> bring up the topic, not to make a call on whether it should be done or not.

FWIW the `--checks` option takes priority over the `--config` option. 
If a check is enabled via `--checks`, but disabled via `--config`, the check 
will be enabled. 
If a check is disabled via `--checks`, but enabled via `--config`, the check 
will be disabled.


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

https://reviews.llvm.org/D118104

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


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 405921.
azabaznov added a comment.

Reimplement with checking language options only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible in

[PATCH] D118986: [clang][deps] Return the whole TU command line

2022-02-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The dependency scanner already generates canonical -cc1 command lines that can 
be used to compile discovered modular dependencies.

For translation unit command lines, the scanner only generates additional 
driver arguments the build system is expected to append to the original command 
line.

While this works most of the time, there are situations where this doesn't work 
quite well. For example with `-Wunused-command-line-argument`, Clang will 
complain about the `-fmodules-cache-path=` argument that's not being used in 
explicit modular builds. Combine that with `-Werror` and the build outright 
fails.

To prevent such failures, this patch changes the dependency scanner to return 
the full driver command line to compile the original translation unit. This 
gives us more opportunities to massage the arguments into something reasonable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118986

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/modules-symlink.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -296,14 +296,13 @@
   Modules.insert(I, {{MD.ID, InputIndex}, std::move(MD)});
 }
 
-ID.AdditionalCommandLine =
-GenerateModulesPathArgs
-? FD.getAdditionalArgs(
-  [&](ModuleID MID) { return lookupPCMPath(MID); },
-  [&](ModuleID MID) -> const ModuleDeps & {
-return lookupModuleDeps(MID);
-  })
-: FD.getAdditionalArgsWithoutModulePaths();
+ID.CommandLine = GenerateModulesPathArgs
+ ? FD.getCommandLine(
+   [&](ModuleID MID) { return lookupPCMPath(MID); },
+   [&](ModuleID MID) -> const ModuleDeps & {
+ return lookupModuleDeps(MID);
+   })
+ : FD.getCommandLineWithoutModulePaths();
 
 Inputs.push_back(std::move(ID));
   }
@@ -353,7 +352,7 @@
   {"clang-context-hash", I.ContextHash},
   {"file-deps", I.FileDeps},
   {"clang-module-deps", toJSONSorted(I.ModuleDeps)},
-  {"command-line", I.AdditionalCommandLine},
+  {"command-line", I.CommandLine},
   };
   TUs.push_back(std::move(O));
 }
@@ -415,7 +414,7 @@
 std::string ContextHash;
 std::vector FileDeps;
 std::vector ModuleDeps;
-std::vector AdditionalCommandLine;
+std::vector CommandLine;
   };
 
   std::mutex Lock;
Index: clang/test/ClangScanDeps/modules-symlink.c
===
--- clang/test/ClangScanDeps/modules-symlink.c
+++ clang/test/ClangScanDeps/modules-symlink.c
@@ -49,8 +49,7 @@
 // RUN:   --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod.cc1.rsp
-// RUN: %clang -x c-header %t/pch.h -fmodules -gmodules -fimplicit-module-maps \
-// RUN:   -fmodules-cache-path=%t/cache -o %t/pch.h.gch -I %t @%t/pch.rsp
+// RUN: %clang @%t/pch.rsp
 
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb_tu.json > %t/cdb.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -91,7 +91,7 @@
 // CHECK-PCH-NEXT: }
 // CHECK-PCH-NEXT:   ],
 // CHECK-PCH-NEXT:   "command-line": [
-// CHECK-PCH-NEXT: "-fno-implicit-modules",
+// CHECK-PCH:  "-fno-implicit-modules",
 // CHECK-PCH-NEXT: "-fno-implicit-module-maps",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_1]]/ModCommon1-{{.*}}.pcm",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm",
@@ -120,8 +120,7 @@
 // RUN: %clang @%t/mod_common_1.cc1.rsp
 // RUN: %clang @%t/mod_common_2.cc1.rsp
 // RUN: %clang @%t/mod_pch.cc1.rsp
-// RUN: %clang -x c-

[PATCH] D118986: [clang][deps] Return the whole TU command line

2022-02-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 405925.
jansvoboda11 added a comment.

Undo one test change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118986

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/modules-symlink.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -296,14 +296,13 @@
   Modules.insert(I, {{MD.ID, InputIndex}, std::move(MD)});
 }
 
-ID.AdditionalCommandLine =
-GenerateModulesPathArgs
-? FD.getAdditionalArgs(
-  [&](ModuleID MID) { return lookupPCMPath(MID); },
-  [&](ModuleID MID) -> const ModuleDeps & {
-return lookupModuleDeps(MID);
-  })
-: FD.getAdditionalArgsWithoutModulePaths();
+ID.CommandLine = GenerateModulesPathArgs
+ ? FD.getCommandLine(
+   [&](ModuleID MID) { return lookupPCMPath(MID); },
+   [&](ModuleID MID) -> const ModuleDeps & {
+ return lookupModuleDeps(MID);
+   })
+ : FD.getCommandLineWithoutModulePaths();
 
 Inputs.push_back(std::move(ID));
   }
@@ -353,7 +352,7 @@
   {"clang-context-hash", I.ContextHash},
   {"file-deps", I.FileDeps},
   {"clang-module-deps", toJSONSorted(I.ModuleDeps)},
-  {"command-line", I.AdditionalCommandLine},
+  {"command-line", I.CommandLine},
   };
   TUs.push_back(std::move(O));
 }
@@ -415,7 +414,7 @@
 std::string ContextHash;
 std::vector FileDeps;
 std::vector ModuleDeps;
-std::vector AdditionalCommandLine;
+std::vector CommandLine;
   };
 
   std::mutex Lock;
Index: clang/test/ClangScanDeps/modules-symlink.c
===
--- clang/test/ClangScanDeps/modules-symlink.c
+++ clang/test/ClangScanDeps/modules-symlink.c
@@ -49,8 +49,7 @@
 // RUN:   --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod.cc1.rsp
-// RUN: %clang -x c-header %t/pch.h -fmodules -gmodules -fimplicit-module-maps \
-// RUN:   -fmodules-cache-path=%t/cache -o %t/pch.h.gch -I %t @%t/pch.rsp
+// RUN: %clang @%t/pch.rsp
 
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb_tu.json > %t/cdb.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -91,7 +91,7 @@
 // CHECK-PCH-NEXT: }
 // CHECK-PCH-NEXT:   ],
 // CHECK-PCH-NEXT:   "command-line": [
-// CHECK-PCH-NEXT: "-fno-implicit-modules",
+// CHECK-PCH:  "-fno-implicit-modules",
 // CHECK-PCH-NEXT: "-fno-implicit-module-maps",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_1]]/ModCommon1-{{.*}}.pcm",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm",
@@ -120,8 +120,7 @@
 // RUN: %clang @%t/mod_common_1.cc1.rsp
 // RUN: %clang @%t/mod_common_2.cc1.rsp
 // RUN: %clang @%t/mod_pch.cc1.rsp
-// RUN: %clang -x c-header %t/pch.h -fmodules -gmodules -fimplicit-module-maps \
-// RUN:   -fmodules-cache-path=%t/cache -o %t/pch.h.gch @%t/pch.rsp
+// RUN: %clang @%t/pch.rsp
 
 // Scan dependencies of the TU:
 //
@@ -161,7 +160,7 @@
 // CHECK-TU-NEXT: }
 // CHECK-TU-NEXT:   ],
 // CHECK-TU-NEXT:   "command-line": [
-// CHECK-TU-NEXT: "-fno-implicit-modules",
+// CHECK-TU:  "-fno-implicit-modules",
 // CHECK-TU-NEXT: "-fno-implicit-module-maps",
 // CHECK-TU-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_TU]]/ModTU-{{.*}}.pcm"
 // CHECK-TU-NEXT:   ],
@@ -183,8 +182,7 @@
 // RUN:   --tu-index=0 > %t/tu.rsp
 //
 // RUN: %clang @%t/mod_tu.cc1.rsp
-// RUN: %clang -fsyntax-only %t/tu.c -fmodules -gmodules -fimplicit-module-maps \
-// RUN:   -fmodules-cache-path=%t/cache -include %t/pch.h -o %t/tu.o @%t/tu.rsp
+// RUN: %clang @%t/tu.rsp
 
 //

[PATCH] D118986: [clang][deps] Return the whole TU command line

2022-02-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/ClangScanDeps/modules-inferred-explicit-build.m:15
 // RUN: %clang @%t.system.cc1.rsp -pedantic -Werror
-// RUN: %clang -x objective-c -fsyntax-only %t.dir/modules_cdb_input.cpp \
-// RUN:   -F%S/Inputs/frameworks -fmodules -fimplicit-module-maps \
-// RUN:   -pedantic -Werror @%t.tu.rsp
+// RUN: %clang @%t.tu.rsp -pedantic -Werror -Wno-unused-command-line-argument
 

This patch will make it possible to strip out `-fmodules-cache-path=`, allowing 
us to remove `-Wno-unused-command-line-argument` in this test. Note that 
previously, we needed to strip the argument ourselves manually to get the same 
effect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118986

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


[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1011
 // We never consider refactorings etc as preferred.
 CodeAction *OnlyFix = nullptr;
 for (auto &Action : Actions) {

ckandeler wrote:
> sammccall wrote:
> > This loop is closely related to what you're doing (and the one above isn't).
> > 
> > Maybe we can refactor/combine as something like:
> > 
> > ```
> > Optional OnlyFix; // nullptr means multiple fixes
> > // ... loop over actions and set OnlyFix ...
> > if (OnlyFix && *OnlyFix) {
> >   (*OnlyFix)->isPreferred = true;
> >   if (Diags.size() == 1 && Diags.front().range == Selection)
> > (*OnlyFix)->diagnostics = {Diags.front()];
> > }
> > ```
> > 
> > Note this adds the conditions:
> >  - should be only one diagnostic in context
> >  - should be only one quickfix action
> > 
> > I think these reduce the chance of false positives.
> Done. Though it seems the code would work just as well with OnlyFix staying a 
> normal pointer. Did I misunderstand something?
Oops, I missed the `break` in the loop.
Yes a normal pointer would be better, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

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


[PATCH] D118257: [AArch64] Generate fcmps when appropriate for neon intrinsics

2022-02-04 Thread John Brawn 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 rGbca998ed3c9a: [AArch64] Generate fcmps when appropriate for 
neon intrinsics (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118257

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -585,7 +585,7 @@
 
 // COMMON-LABEL: test_vcges_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -596,7 +596,7 @@
 
 // COMMON-LABEL: test_vcged_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -607,7 +607,7 @@
 
 // COMMON-LABEL: test_vcgezs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -618,7 +618,7 @@
 
 // COMMON-LABEL: test_vcgezd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double 0.00e+00, metadata !"oge", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -629,7 +629,7 @@
 
 // COMMON-LABEL: test_vcgts_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -640,7 +640,7 @@
 
 // COMMON-LABEL: test_vcgtd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -651,7 +651,7 @@
 
 // COMMON-LABEL: test_vcgtzs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float %a, float 0.00e+00, metadata !"ogt", metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, #0.0
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, gt
 // COMMONIR:  [[VCGTZ_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -662,7 +662,7 @@
 
 // COMMON-LABEL: test_vcgtzd_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp ogt double %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double %a, double 0.00e+00, metadata !"ogt", meta

[clang] bca998e - [AArch64] Generate fcmps when appropriate for neon intrinsics

2022-02-04 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-02-04T12:55:38Z
New Revision: bca998ed3c9a2e520724baa5d9395f6a5d8ca49d

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

LOG: [AArch64] Generate fcmps when appropriate for neon intrinsics

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d071c7a5b4a47..a3905e0ea4105 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7294,7 +7294,10 @@ Value *CodeGenFunction::EmitAArch64CompareBuiltinExpr(
 
   Op = Builder.CreateBitCast(Op, OTy);
   if (OTy->getScalarType()->isFloatingPointTy()) {
-Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy));
+if (Fp == CmpInst::FCMP_OEQ)
+  Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy));
+else
+  Op = Builder.CreateFCmpS(Fp, Op, Constant::getNullValue(OTy));
   } else {
 Op = Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy));
   }
@@ -10299,7 +10302,10 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Ops.push_back(EmitScalarExpr(E->getArg(1)));
 Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy);
 Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy);
-Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+if (P == llvm::FCmpInst::FCMP_OEQ)
+  Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+else
+  Ops[0] = Builder.CreateFCmpS(P, Ops[0], Ops[1]);
 return Builder.CreateSExt(Ops[0], Int64Ty, "vcmpd");
   }
   case NEON::BI__builtin_neon_vceqs_f32:
@@ -10319,7 +10325,10 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Ops.push_back(EmitScalarExpr(E->getArg(1)));
 Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy);
 Ops[1] = Builder.CreateBitCast(Ops[1], FloatTy);
-Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+if (P == llvm::FCmpInst::FCMP_OEQ)
+  Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+else
+  Ops[0] = Builder.CreateFCmpS(P, Ops[0], Ops[1]);
 return Builder.CreateSExt(Ops[0], Int32Ty, "vcmpd");
   }
   case NEON::BI__builtin_neon_vceqh_f16:
@@ -10339,7 +10348,10 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Ops.push_back(EmitScalarExpr(E->getArg(1)));
 Ops[0] = Builder.CreateBitCast(Ops[0], HalfTy);
 Ops[1] = Builder.CreateBitCast(Ops[1], HalfTy);
-Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+if (P == llvm::FCmpInst::FCMP_OEQ)
+  Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+else
+  Ops[0] = Builder.CreateFCmpS(P, Ops[0], Ops[1]);
 return Builder.CreateSExt(Ops[0], Int16Ty, "vcmpd");
   }
   case NEON::BI__builtin_neon_vceqd_s64:

diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
index 25e205193ca79..fccafefd9d30c 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -585,7 +585,7 @@ uint64_t test_vceqzd_f64(float64_t a) {
 
 // COMMON-LABEL: test_vcges_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"oge", 
metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"oge", 
metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -596,7 +596,7 @@ uint32_t test_vcges_f32(float32_t a, float32_t b) {
 
 // COMMON-LABEL: test_vcged_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"oge", 
metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"oge", 
metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -607,7 +607,7 @@ uint64_t test_vcged_f64(float64_t a, float64_t b) {
 
 // COMMON-LABEL: test_vcgezs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata 
!"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmps.f32(float %a

[PATCH] D118976: clangd: Set a diagnostic on a code action resulting from a tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 405929.
ckandeler added a comment.

Simplified code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118976

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,9 +986,9 @@
 
   // Now enumerate the semantic code actions.
   auto ConsumeActions =
-  [Reply = std::move(Reply), File, Selection = Params.range,
-   FixIts = std::move(FixIts), this](
-  llvm::Expected> Tweaks) mutable {
+  [Diags = Params.context.diagnostics, Reply = std::move(Reply), File,
+   Selection = Params.range, FixIts = std::move(FixIts), this](
+llvm::Expected> Tweaks) mutable {
 if (!Tweaks)
   return Reply(Tweaks.takeError());
 
@@ -1003,13 +1003,17 @@
 for (auto &Action : Actions) {
   if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND) {
 if (OnlyFix) {
-  OnlyFix->isPreferred = false;
+  OnlyFix = nullptr;
   break;
 }
-Action.isPreferred = true;
 OnlyFix = &Action;
   }
 }
+if (OnlyFix) {
+  OnlyFix->isPreferred = true;
+  if (Diags.size() == 1 && Diags.front().range == Selection)
+OnlyFix->diagnostics = {Diags.front()};
+}
 
 if (SupportsCodeAction)
   return Reply(llvm::json::Array(Actions));


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,9 +986,9 @@
 
   // Now enumerate the semantic code actions.
   auto ConsumeActions =
-  [Reply = std::move(Reply), File, Selection = Params.range,
-   FixIts = std::move(FixIts), this](
-  llvm::Expected> Tweaks) mutable {
+  [Diags = Params.context.diagnostics, Reply = std::move(Reply), File,
+   Selection = Params.range, FixIts = std::move(FixIts), this](
+llvm::Expected> Tweaks) mutable {
 if (!Tweaks)
   return Reply(Tweaks.takeError());
 
@@ -1003,13 +1003,17 @@
 for (auto &Action : Actions) {
   if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND) {
 if (OnlyFix) {
-  OnlyFix->isPreferred = false;
+  OnlyFix = nullptr;
   break;
 }
-Action.isPreferred = true;
 OnlyFix = &Action;
   }
 }
+if (OnlyFix) {
+  OnlyFix->isPreferred = true;
+  if (Diags.size() == 1 && Diags.front().range == Selection)
+OnlyFix->diagnostics = {Diags.front()};
+}
 
 if (SupportsCodeAction)
   return Reply(llvm::json::Array(Actions));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-02-04 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

My bad. Test should have called clang-tidy with `--checks` in one test case, 
and with `--config` in the second. In both cases, the disabled check should not 
appear in the `Enabled checks:` printout.


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

https://reviews.llvm.org/D118104

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


[PATCH] D118965: [OpenMP] Add search path for llvm-strip

2022-02-04 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

LG, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118965

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


[PATCH] D110445: [NFC] Avoid some AttrBuilder redundant initialization

2022-02-04 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

This one can probably be abandoned after the AttrMask/AttrBuilder changes that 
have been made?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110445

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-04 Thread Luís Marques via Phabricator via cfe-commits
luismarques added a comment.

Assuming this will be merged soon, do you want to submit a backport request for 
the 14.0 branch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D118782: clangd: Add a break for every case in the PopulateSwitch tweak

2022-02-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

I agree with Sam on this one and remember having some (possibly offline) 
discussions around not having those breaks explicitly (we should've documented 
the reasoning, sorry).

As pointed out, I believe the main benefit is not spelling out each enum value 
(it's usually hard to figure out which ones are missing, requires constant 
switching between enum declaration and switch body, and then do some copy/paste 
or write them).
After those are spelled the developer needs to make a decision about how 
they'll be handled anyway and if some enum value requires special handling 
adding the extra break by hand is not too much of a burden, but deleting those 
when the intent is to have fall through, is extra burden and it might be 
unclear which ones are new labels.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118782

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


[PATCH] D118782: clangd: Add a break for every case in the PopulateSwitch tweak

2022-02-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler abandoned this revision.
ckandeler added a comment.

Fair enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118782

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


[PATCH] D118990: [pseudo] Add first and follow set computation in Grammar.

2022-02-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
hokein requested review of this revision.
Herald added a project: clang.

These will be used when building parsing table for LR parsers.

Separate from https://reviews.llvm.org/D118196.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118990

Files:
  clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
  clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp
  clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp

Index: clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
@@ -1,4 +1,4 @@
-//===--- GrammarTest.cpp - grammar tests  ---*- C++ -*-===//
+//===--- GrammarTest.cpp - grammar tests  *- C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -19,6 +19,7 @@
 using testing::AllOf;
 using testing::ElementsAre;
 using testing::IsEmpty;
+using testing::Pair;
 using testing::UnorderedElementsAre;
 
 MATCHER_P(TargetID, SID, "") { return arg.Target == SID; }
@@ -33,7 +34,7 @@
 G = Grammar::parseBNF(BNF, Diags);
   }
 
-  SymbolID lookup(llvm::StringRef Name) const {
+  SymbolID id(llvm::StringRef Name) const {
 for (unsigned I = 0; I < NumTerminals; ++I)
   if (G->table().Terminals[I] == Name)
 return tokenSymbol(static_cast(I));
@@ -54,9 +55,9 @@
   EXPECT_THAT(Diags, IsEmpty());
 
   auto ExpectedRule =
-  AllOf(TargetID(lookup("expression")),
-Sequence(lookup("IDENTIFIER"), lookup("+"), lookup("expression")));
-  auto ExpressionID = lookup("expression");
+  AllOf(TargetID(id("expression")),
+Sequence(id("IDENTIFIER"), id("+"), id("expression")));
+  auto ExpressionID = id("expression");
   EXPECT_EQ(G->symbolName(ExpressionID), "expression");
   EXPECT_THAT(G->rulesFor(ExpressionID), UnorderedElementsAre(ExpectedRule));
   const auto &Rule = G->lookupRule(/*RID=*/0);
@@ -70,11 +71,10 @@
   build("_ := CONST_opt INT ;_opt");
   EXPECT_THAT(Diags, IsEmpty());
   EXPECT_THAT(G->table().Rules,
-  UnorderedElementsAre(
-  Sequence(lookup("INT")),
-  Sequence(lookup("CONST"), lookup("INT")),
-  Sequence(lookup("CONST"), lookup("INT"), lookup(";")),
-  Sequence(lookup("INT"), lookup(";";
+  UnorderedElementsAre(Sequence(id("INT")),
+   Sequence(id("CONST"), id("INT")),
+   Sequence(id("CONST"), id("INT"), id(";")),
+   Sequence(id("INT"), id(";";
 }
 
 TEST_F(GrammarTest, Diagnostics) {
@@ -96,6 +96,66 @@
  "No rules for nonterminal: IDENFIFIE"));
 }
 
+TEST_F(GrammarTest, FirstAndFollowSets) {
+  build(
+  R"bnf(
+_ := expr
+expr := expr - term
+expr := term
+term := IDENTIFIER
+term := ( expr )
+)bnf");
+  ASSERT_TRUE(Diags.empty());
+  auto ToPair = [](std::vector> Input) {
+std::vector>> Sets;
+for (SymbolID ID = 0; ID < Input.size(); ++ID)
+  Sets.emplace_back(ID, std::move(Input[ID]));
+return Sets;
+  };
+
+  EXPECT_THAT(
+  ToPair(firstSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("IDENTIFIER"), id("("))),
+  Pair(id("expr"), UnorderedElementsAre(id("IDENTIFIER"), id("("))),
+  Pair(id("term"), UnorderedElementsAre(id("IDENTIFIER"), id("(");
+  EXPECT_THAT(
+  ToPair(followSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("EOF"))),
+  Pair(id("expr"), UnorderedElementsAre(id("-"), id("EOF"), id(")"))),
+  Pair(id("term"), UnorderedElementsAre(id("-"), id("EOF"), id(")");
+
+  build(R"bnf(
+# A simplfied C++ decl-specifier-seq.
+_ := decl-specifier-seq
+decl-specifier-seq := decl-specifier decl-specifier-seq
+decl-specifier-seq := decl-specifier
+decl-specifier := simple-type-specifier
+decl-specifier := INLINE
+simple-type-specifier := INT
+   )bnf");
+  ASSERT_TRUE(Diags.empty());
+  EXPECT_THAT(
+  ToPair(firstSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("INLINE"), id("INT"))),
+  Pair(id("decl-specifier-seq"),
+   UnorderedElementsAre(id("INLINE"), id("INT"))),
+  Pair(id("simple-type-specifier"), UnorderedElementsAre(id("INT"))),
+  Pair(id("decl-specifier"),
+   UnorderedElementsAre(id("INLINE"), id("INT");
+  EXPECT_THAT(
+  ToPair(followSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("EOF"))),
+  Pair(id("decl-specifier-seq"), UnorderedElementsAre(id("EOF"))),
+  Pair(id("decl-specifier"),
+   UnorderedElementsAre

[PATCH] D118782: clangd: Add a break for every case in the PopulateSwitch tweak

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

The only way I'd suggest supporting this is via an option in config(like we do 
with the add using tweak), but I don't think even then it would get much use.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118782

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


[PATCH] D118196: [syntax][pseudo] Implement LR parsing table.

2022-02-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked 7 inline comments as done.
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h:130
+
+  // Returns the SymbolID of the augmented symbol '_'
+  SymbolID augmentedSymbol() const { return 0; }

sammccall wrote:
> this "augmented symbol" name doesn't seem widely used. (search for `lr 
> "augmented symbol"` produces few results, mostly unrelated). It's also a 
> confusing name, because it's IIUC it's not the symbol that's augmented, but 
> rather the grammar has been augmented with the symbol...
> 
> I'd suggest just calling it the start symbol, unless the distinction is 
> critical (I don't yet understand why it's important - I added it in the 
> prototype just to avoid having the language-specific name "translation-unit" 
> hardcoded).
> 
> Otherwise it's hard to suggest a good name without understanding what it's 
> for, but it should be descriptive...
yeah, it is about augmented grammar. Strictly speaking, it is a start symbol of 
augmented symbol. Maybe we should not speak augmented stuff in the code, it is 
not a well-known term, and causes confusion. rename it to start symbol instead.

It looks like using augmented grammar is a "standard" LR technique,  it 
introduces a converged start state and accepting state in the LR graph, which 
makes it easier for the implementation. And it is a good fit for support 
multiple start symbols.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h:133
+
+  // Computes the FIRST(X) for all non-terminal symbol X.
+  std::vector> firstSets() const;

sammccall wrote:
> sammccall wrote:
> > In about the same number of words you could explain what this actually is 
> > :-)
> > 
> > // Computes the set of terminals that could appear at the start of each 
> > non-terminal.
> is there some reason these functions need to be part of the grammar class?
> 
> They seem like part of the LR building to me, it could be local to 
> LRBuilder.cpp, or exposed from LRTable.h or so for testing
as discussed, made them as free functions in Grammar.h. Separate the first and 
follow set changes to https://reviews.llvm.org/D118990, comments around them 
should be addressed there.



Comment at: clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp:88
+for (const auto &R : T->Rules) {
+  // Rule 2: for a rule X := ...Yz, we add all symbols from FIRST(z) to
+  // FOLLOW(Y).

sammccall wrote:
> nit: `... Y Z`, with consistent spaces/capitalization
> Unless case is meant to imply something here?
Y was for nonterminal while z was for nonterminal or terminals. They are not 
super important, changed all to Uppercase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118196

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


[PATCH] D118922: [ASTMatchers] The `isInline` matcher now accepts inline variables

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I had the same idea in D118900 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118922

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


[PATCH] D118990: [pseudo] Add first and follow set computation in Grammar.

2022-02-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 405939.
hokein added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118990

Files:
  clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
  clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp
  clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp

Index: clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp
@@ -19,6 +19,7 @@
 using testing::AllOf;
 using testing::ElementsAre;
 using testing::IsEmpty;
+using testing::Pair;
 using testing::UnorderedElementsAre;
 
 MATCHER_P(TargetID, SID, "") { return arg.Target == SID; }
@@ -33,7 +34,7 @@
 G = Grammar::parseBNF(BNF, Diags);
   }
 
-  SymbolID lookup(llvm::StringRef Name) const {
+  SymbolID id(llvm::StringRef Name) const {
 for (unsigned I = 0; I < NumTerminals; ++I)
   if (G->table().Terminals[I] == Name)
 return tokenSymbol(static_cast(I));
@@ -54,9 +55,9 @@
   EXPECT_THAT(Diags, IsEmpty());
 
   auto ExpectedRule =
-  AllOf(TargetID(lookup("expression")),
-Sequence(lookup("IDENTIFIER"), lookup("+"), lookup("expression")));
-  auto ExpressionID = lookup("expression");
+  AllOf(TargetID(id("expression")),
+Sequence(id("IDENTIFIER"), id("+"), id("expression")));
+  auto ExpressionID = id("expression");
   EXPECT_EQ(G->symbolName(ExpressionID), "expression");
   EXPECT_THAT(G->rulesFor(ExpressionID), UnorderedElementsAre(ExpectedRule));
   const auto &Rule = G->lookupRule(/*RID=*/0);
@@ -70,11 +71,10 @@
   build("_ := CONST_opt INT ;_opt");
   EXPECT_THAT(Diags, IsEmpty());
   EXPECT_THAT(G->table().Rules,
-  UnorderedElementsAre(
-  Sequence(lookup("INT")),
-  Sequence(lookup("CONST"), lookup("INT")),
-  Sequence(lookup("CONST"), lookup("INT"), lookup(";")),
-  Sequence(lookup("INT"), lookup(";";
+  UnorderedElementsAre(Sequence(id("INT")),
+   Sequence(id("CONST"), id("INT")),
+   Sequence(id("CONST"), id("INT"), id(";")),
+   Sequence(id("INT"), id(";";
 }
 
 TEST_F(GrammarTest, Diagnostics) {
@@ -87,6 +87,7 @@
 invalid
   )cpp");
 
+  EXPECT_EQ(G->startSymbol(), id("_"));
   EXPECT_THAT(Diags, UnorderedElementsAre(
  "Rule '_ := ,_opt' has a nullable RHS",
  "Rule 'null := ' has a nullable RHS",
@@ -96,6 +97,66 @@
  "No rules for nonterminal: IDENFIFIE"));
 }
 
+TEST_F(GrammarTest, FirstAndFollowSets) {
+  build(
+  R"bnf(
+_ := expr
+expr := expr - term
+expr := term
+term := IDENTIFIER
+term := ( expr )
+)bnf");
+  ASSERT_TRUE(Diags.empty());
+  auto ToPair = [](std::vector> Input) {
+std::vector>> Sets;
+for (SymbolID ID = 0; ID < Input.size(); ++ID)
+  Sets.emplace_back(ID, std::move(Input[ID]));
+return Sets;
+  };
+
+  EXPECT_THAT(
+  ToPair(firstSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("IDENTIFIER"), id("("))),
+  Pair(id("expr"), UnorderedElementsAre(id("IDENTIFIER"), id("("))),
+  Pair(id("term"), UnorderedElementsAre(id("IDENTIFIER"), id("(");
+  EXPECT_THAT(
+  ToPair(followSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("EOF"))),
+  Pair(id("expr"), UnorderedElementsAre(id("-"), id("EOF"), id(")"))),
+  Pair(id("term"), UnorderedElementsAre(id("-"), id("EOF"), id(")");
+
+  build(R"bnf(
+# A simplfied C++ decl-specifier-seq.
+_ := decl-specifier-seq
+decl-specifier-seq := decl-specifier decl-specifier-seq
+decl-specifier-seq := decl-specifier
+decl-specifier := simple-type-specifier
+decl-specifier := INLINE
+simple-type-specifier := INT
+   )bnf");
+  ASSERT_TRUE(Diags.empty());
+  EXPECT_THAT(
+  ToPair(firstSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("INLINE"), id("INT"))),
+  Pair(id("decl-specifier-seq"),
+   UnorderedElementsAre(id("INLINE"), id("INT"))),
+  Pair(id("simple-type-specifier"), UnorderedElementsAre(id("INT"))),
+  Pair(id("decl-specifier"),
+   UnorderedElementsAre(id("INLINE"), id("INT");
+  EXPECT_THAT(
+  ToPair(followSets(*G)),
+  UnorderedElementsAre(
+  Pair(id("_"), UnorderedElementsAre(id("EOF"))),
+  Pair(id("decl-specifier-seq"), UnorderedElementsAre(id("EOF"))),
+  Pair(id("decl-specifier"),
+   UnorderedElementsAre(id("INLINE"), id("INT"), id("EOF"))),
+  Pair(id("simple-type-specifier"),
+   UnorderedElementsAre(id("INLINE"), id("INT"), id("EOF");
+}
+
 } // names

[PATCH] D118964: Fix broken 2-stage build when -tblgen tools may depend on runpath that is not yet built

2022-02-04 Thread Arcadiy Ivanov via Phabricator via cfe-commits
arcivanov added a comment.

So this change is insufficient as additional tools (lldb-tblgen and 
clang-ast-dump) will fail thereafter.
Since all those tools depend on libc++ being available for stage2-bins, the 
libc++ needs to be built on stage two (along with unwind and compiler-rt in my 
case).
The way I've tried to fix above is treating the symptom and not the cause.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118964

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


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:10
+// RUN: %clang_cc1 -DOMP51 -verify=omp51 -fopenmp -fopenmp-version=51 
-ast-print %s | FileCheck --check-prefixes=CHECK,CHECK-51 %s
+
+// RUN: %clang_cc1 -DOMP51 -verify=omp51 -fopenmp-simd -fopenmp-version=51 
-ast-print %s | FileCheck --check-prefixes=CHECK,CHECK-51 %s

tianshilei1992 wrote:
> @ABataev But still in this path, we cannot test `-emit-pch` because we will 
> emit `atomic compare is not supported for now` anyway, and it cannot be 
> worked around. I'll add it in the codegen patch or in a following patch of 
> codegen.
Why? It should be tested.
```
// RUN: %clang_cc1 -fopenmp -DOMP51 -fopenmp-version=51 -x c++ -std=c++11 
-emit-pch -o %t %s
// RUN: %clang_cc1 -fopenmp -DOMP51 -fopenmp-version=51 -std=c++11 -include-pch 
%t -fsyntax-only -verify %s -ast-print | FileCheck %s
```
Could you try this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions and initializer lists in annotate attribute

2022-02-04 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

1 question, otherwise happy.




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8153
+
+  bool AttrHasVariadicArg = AL.hasVariadicArg();
+  unsigned AttrNumArgs = AL.getNumArgMembers();

This still doesn't work if the VariadicExprArgument isn't last, right?  Do we 
ensure that is the case in clang-attr-emitter?


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

https://reviews.llvm.org/D114439

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


[PATCH] D118991: [clang-format][docs] Fix incorrect 'clang-format 14' configuration options markers

2022-02-04 Thread Krystian Kuzniarek via Phabricator via cfe-commits
kuzkry created this revision.
kuzkry added a reviewer: MyDeveloperDay.
kuzkry requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[clang-format][docs] Fix incorrect 'clang-format 14' configuration options 
markers

Introduced by 23a5090c6 
, some 
style option markers indicated 'clang-format 14',
though their respective options were available in earlier releases.

Note: Even though the value type of 'SpacesInAngles' option changed,
this option has been already present from version 3.4.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118991

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2110,7 +2110,7 @@
   /// Defines when to put an empty line after access modifiers.
   /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
   /// empty lines between two access modifiers.
-  /// \version 14
+  /// \version 13
   EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier;
 
   /// Different styles for empty line before access modifiers.
@@ -2285,7 +2285,7 @@
   ///
   /// For example: `KJ_IF_MAYBE
   /// `_
-  /// \version 14
+  /// \version 13
   std::vector IfMacros;
 
   /// \brief A vector of macros that should be interpreted as type declarations
@@ -2956,7 +2956,7 @@
   ///# define BAR
   ///#endif
   /// \endcode
-  /// \version 14
+  /// \version 13
   int PPIndentWidth;
 
   /// See documentation of ``RawStringFormats``.
@@ -3042,7 +3042,7 @@
 
   /// \brief Reference alignment style (overrides ``PointerAlignment`` for
   /// references).
-  /// \version 14
+  /// \version 13
   ReferenceAlignmentStyle ReferenceAlignment;
 
   // clang-format off
@@ -3193,7 +3193,7 @@
   ///  int bar;   int bar;
   ///} // namespace b   } // namespace b
   /// \endcode
-  /// \version 14
+  /// \version 13
   unsigned ShortNamespaceLines;
 
   /// Include sorting options.
@@ -3610,7 +3610,7 @@
 SIAS_Leave
   };
   /// The SpacesInAnglesStyle to use for template argument lists.
-  /// \version 14
+  /// \version 3.4
   SpacesInAnglesStyle SpacesInAngles;
 
   /// If ``true``, spaces will be inserted around if/for/switch/while
@@ -3678,7 +3678,7 @@
   ///   ///  - Foo/// - Foo
   ///   ///- Bar  ///   - Bar
   /// \endcode
-  /// \version 14
+  /// \version 13
   SpacesInLineComment SpacesInLineCommentPrefix;
 
   /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -2209,7 +2209,7 @@
 **DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7`
   Disables formatting completely.
 
-**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 14`
+**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13`
   Defines when to put an empty line after access modifiers.
   ``EmptyLineBeforeAccessModifier`` configuration handles the number of
   empty lines between two access modifiers.
@@ -2375,7 +2375,7 @@
 
   For example: BOOST_FOREACH.
 
-**IfMacros** (``List of Strings``) :versionbadge:`clang-format 14`
+**IfMacros** (``List of Strings``) :versionbadge:`clang-format 13`
   A vector of macros that should be interpreted as conditionals
   instead of as function calls.
 
@@ -3127,7 +3127,7 @@
   Add a space in front of an Objective-C protocol list, i.e. use
   ``Foo `` instead of ``Foo``.
 
-**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 14`
+**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13`
   The number of columns to use for indentation of preprocessor statements.
   When set to -1 (default) ``IndentWidth`` is used also for preprocessor
   statements.
@@ -3371,7 +3371,7 @@
   BasedOnStyle: llvm
   CanonicalDelimiter: 'cc'
 
-**ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 14`
+**ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13`
   Reference alignment style (overrides ``PointerAlignment`` for
   references).
 
@@ -3535,7 +3535,7 @@
 
 
 
-**ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 14`
+**ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13`
   The maximal number of unwrapped lines that a short namespace spans.
   Defaults to 1.
 
@@ -3969,7 +3969,7 @@
} // foo
  

[PATCH] D114439: [Annotation] Allow parameter pack expansions and initializer lists in annotate attribute

2022-02-04 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen marked 2 inline comments as done.
steffenlarsen added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8153
+
+  bool AttrHasVariadicArg = AL.hasVariadicArg();
+  unsigned AttrNumArgs = AL.getNumArgMembers();

erichkeane wrote:
> This still doesn't work if the VariadicExprArgument isn't last, right?  Do we 
> ensure that is the case in clang-attr-emitter?
Good point. I don't think there's a check as there are select few attributes 
that use multiple variadic (`OMPDeclareSimdDecl` and `OMPDeclareVariant` are 
the only ones, I think.)

Since I don't think it's safe to check for all, should I make a check similar 
to the one for type/identifier arguments in attributes marked 
`AcceptsExprPack`? Would that suffice?


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

https://reviews.llvm.org/D114439

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions and initializer lists in annotate attribute

2022-02-04 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8153
+
+  bool AttrHasVariadicArg = AL.hasVariadicArg();
+  unsigned AttrNumArgs = AL.getNumArgMembers();

steffenlarsen wrote:
> erichkeane wrote:
> > This still doesn't work if the VariadicExprArgument isn't last, right?  Do 
> > we ensure that is the case in clang-attr-emitter?
> Good point. I don't think there's a check as there are select few attributes 
> that use multiple variadic (`OMPDeclareSimdDecl` and `OMPDeclareVariant` are 
> the only ones, I think.)
> 
> Since I don't think it's safe to check for all, should I make a check similar 
> to the one for type/identifier arguments in attributes marked 
> `AcceptsExprPack`? Would that suffice?
I'm fine rejecting a case that has anything besides expression-arguments(and 
ones create-able from expression arguments) and limited-to-only-1-must-be-last 
variadic-expr-list in ClangAttrEmitter.

I believe we discussed that at one point, but I didn't see it here.


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

https://reviews.llvm.org/D114439

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


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:10
+// RUN: %clang_cc1 -DOMP51 -verify=omp51 -fopenmp -fopenmp-version=51 
-ast-print %s | FileCheck --check-prefixes=CHECK,CHECK-51 %s
+
+// RUN: %clang_cc1 -DOMP51 -verify=omp51 -fopenmp-simd -fopenmp-version=51 
-ast-print %s | FileCheck --check-prefixes=CHECK,CHECK-51 %s

ABataev wrote:
> tianshilei1992 wrote:
> > @ABataev But still in this path, we cannot test `-emit-pch` because we will 
> > emit `atomic compare is not supported for now` anyway, and it cannot be 
> > worked around. I'll add it in the codegen patch or in a following patch of 
> > codegen.
> Why? It should be tested.
> ```
> // RUN: %clang_cc1 -fopenmp -DOMP51 -fopenmp-version=51 -x c++ -std=c++11 
> -emit-pch -o %t %s
> // RUN: %clang_cc1 -fopenmp -DOMP51 -fopenmp-version=51 -std=c++11 
> -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
> ```
> Could you try this?
I did, but since the first command can emit errors, the test fails. It should 
be tested. I'll add it back when we don't emit error in Sema.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:10
+// RUN: %clang_cc1 -DOMP51 -verify=omp51 -fopenmp -fopenmp-version=51 
-ast-print %s | FileCheck --check-prefixes=CHECK,CHECK-51 %s
+
+// RUN: %clang_cc1 -DOMP51 -verify=omp51 -fopenmp-simd -fopenmp-version=51 
-ast-print %s | FileCheck --check-prefixes=CHECK,CHECK-51 %s

tianshilei1992 wrote:
> ABataev wrote:
> > tianshilei1992 wrote:
> > > @ABataev But still in this path, we cannot test `-emit-pch` because we 
> > > will emit `atomic compare is not supported for now` anyway, and it cannot 
> > > be worked around. I'll add it in the codegen patch or in a following 
> > > patch of codegen.
> > Why? It should be tested.
> > ```
> > // RUN: %clang_cc1 -fopenmp -DOMP51 -fopenmp-version=51 -x c++ -std=c++11 
> > -emit-pch -o %t %s
> > // RUN: %clang_cc1 -fopenmp -DOMP51 -fopenmp-version=51 -std=c++11 
> > -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
> > ```
> > Could you try this?
> I did, but since the first command can emit errors, the test fails. It should 
> be tested. I'll add it back when we don't emit error in Sema.
Ah, I see. Add a TODO to the tests to add pch testing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D110869#3295477 , @nathanchance 
wrote:

> Rather interesting function to have problems with as a result of this patch 
> but it seems like this function is being used in a very specific way further 
> down the file with the `__PV_IS_CALLEE_SAVE` macro.

AFAICT, `__PV_IS_CALLEE_SAVE` is just bogus. It appears to be used in order to 
promise that a given function preserves all GPR registers (including those 
registers that are normally caller-saved), as an optimized alternative to 
generating a wrapper for the function with `PC_CALLEE_SAVE_REGS_THUNK`, to save 
the extra registers. That would be fine if the functions it was making the 
promise about were written in asm, or the compiler was informed about the 
adjusted calling convention expectation...

However, it's being applied to functions which are implemented in C with no 
special calling-convention attributes on them . That's a promise that simply 
cannot be upheld -- I mean, I guess it //happens// to work currently, but 
that's super-fragile.

Also the whole mechanism (including the asm thunk) should be unnecessary in 
Clang, as it provides an attribute you can put on a function to use a calling 
convention that'll preserve all GPRs except r11. I imagine the call locations 
could easily be adjusted to avoid needing to have r11 preserved, if that's not 
already the case. 
https://clang.llvm.org/docs/AttributeReference.html#preserve-most


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D118924: [clang-format] Fix formatting of macro definitions with a leading comment.

2022-02-04 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Indeed, I get the hash on the 2nd line merged into the first one in this test 
case:

  verifyFormat("/* comment */ #define A (parentheses)\n"
  "#");

But! It's unrelated to whether `PreviousWasComment` is updated inside the loop 
or not.
Actually it should not be important because `#` always starts a preprocessor 
macro and no other statement (at least in C and C++).
On the other hand, `FirstNonCommentOnLine` should be updated in the loop but I 
still don't have a test case for this (again, because there's no statement that 
starts with `#`).

Interestingly, the problem I encountered with the test case above doesn't 
happen when there's a new line after `#`:

  verifyFormat("/* comment */ #define A (parentheses)\n"
   "#\n");

Anyway, this merging happens due to something else, but I don't know yet what 
exactly.
Investigating...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118924

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


[PATCH] D118520: [clang-tidy] Output currently processing check and nodes on crash

2022-02-04 Thread Nathan James via Phabricator via cfe-commits
njames93 added a subscriber: thakis.
njames93 added a comment.

@thakis I tried to test this on the gn build and got no issues, however I'm 
aware that the CTCrashTestTrace plugin isn't even compiled on the gn build. Not 
sure its worth the effort fixing that. The lit test should be disabled anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118520

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


[clang] d4e4ef2 - [HIP] Support code object v5

2022-02-04 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2022-02-04T09:55:08-05:00
New Revision: d4e4ef2e81e03246e29e9b6eaa2929ebd4e77784

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

LOG: [HIP] Support code object v5

New device library supporting v4 and v5 has abi_version_400.bc and abi
version_500.bc.

For v5, abi_version_500.bc is linked.

For v2-4, abi_version_400.bc is linked.

For old device library, for v2-4, none of the above is linked. For v5,
error is emitted about unsupported ABI version.

Reviewed by: Artem Belevich

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

Fixes: SWDEV-321313

Added: 
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/asanrtl.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/hip.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/ockl.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_correctly_rounded_sqrt_off.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_correctly_rounded_sqrt_on.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_daz_opt_off.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_daz_opt_on.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_finite_only_off.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_finite_only_on.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_1010.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_1011.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_1012.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_803.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_900.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_908.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_unsafe_math_off.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_unsafe_math_on.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_wavefrontsize64_off.bc

clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_wavefrontsize64_on.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/ocml.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/opencl.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode/abi_version_400.bc
clang/test/Driver/Inputs/rocm/amdgcn/bitcode/abi_version_500.bc

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/ROCm.h
clang/test/Driver/hip-code-object-version.hip
clang/test/Driver/hip-device-libs.hip

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 3efedbe0f6428..51a10ab54953c 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -67,7 +67,7 @@ def err_drv_no_cuda_libdevice : Error<
   "libdevice">;
 
 def err_drv_no_rocm_device_lib : Error<
-  "cannot find ROCm device library%select{| for %1}0; provide its path via "
+  "cannot find ROCm device library%select{| for %1|for ABI version %1}0; 
provide its path via "
   "'--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build "
   "without ROCm device library">;
 def err_drv_no_hip_runtime : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5aa1e851c2585..c57d9cde094de 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3440,8 +3440,8 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
   NegFlag>, Group;
 
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
-  HelpText<"Specify code object ABI version. Defaults to 3. (AMDGPU only)">,
-  MetaVarName<"">, Values<"2,3,4">;
+  HelpText<"Specify code object ABI version. Defaults to 4. (AMDGPU only)">,
+  MetaVarName<"">, Values<"2,3,4,5">;
 
 defm code_object_v3_legacy : SimpleMFlag<"code-object-v3",
   "Legacy option to specify code object ABI V3",

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 43ce33750ebac..7d2b9e3b46c2f 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -91,6 +91,7 @@ void 
RocmInstallationDetector::scanLibDevicePath(llvm::StringRef Path) {
 else if (FileName.endswith(Suffix))
   BaseName = FileName.drop_back(Suffix.size());
 
+const StringRef ABIVersionPrefix = "abi_version_";

[PATCH] D118949: [HIP] Support code object v5

2022-02-04 Thread Yaxun Liu 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 rGd4e4ef2e81e0: [HIP] Support code object v5 (authored by 
yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D118949?vs=405796&id=405953#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118949

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/ROCm.h
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/asanrtl.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/hip.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/ockl.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_correctly_rounded_sqrt_off.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_correctly_rounded_sqrt_on.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_daz_opt_off.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_daz_opt_on.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_finite_only_off.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_finite_only_on.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_1010.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_1011.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_1012.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_803.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_900.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_isa_version_908.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_unsafe_math_off.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_unsafe_math_on.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_wavefrontsize64_off.bc
  
clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/oclc_wavefrontsize64_on.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/ocml.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode-no-abi-ver/opencl.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode/abi_version_400.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode/abi_version_500.bc
  clang/test/Driver/hip-code-object-version.hip
  clang/test/Driver/hip-device-libs.hip

Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -137,6 +137,49 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=DIVSQRT
 
+// Test default code object version.
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ABI4
+
+// Test default code object version with old device library without abi_version_400.bc
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   --hip-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode-no-abi-ver   \
+// RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=NOABI4
+
+// Test -mcode-object-version=3
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   -mcode-object-version=3 \
+// RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ABI4
+
+// Test -mcode-object-version=4
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   -mcode-object-version=4 \
+// RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ABI4
+
+// Test -mcode-object-version=4 with old device library without abi_version_400.bc
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   -mcode-object-version=4 \
+// RUN:   --hip-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode-no-abi-ver   \
+// RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=NOABI4
+
+// Test -mcode-object-version=5
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   -mcode-object-version=5 \
+// RUN:   --rocm-path=%S/Inputs/rocm %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ABI5
+
+// Test -mcode-object-version=5 with old device library without abi_version_400.bc
+// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx900 \
+// RUN:   -mcode-object-version=5 \
+// RUN:   --h

[PATCH] D118996: [clang-tidy] Support C++14 in bugprone-signal-handler.

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

Check `bugprone-signal-handler` is improved to check for
C++-specific constructs in signal handlers. This check is
valid until C++17.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118996

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-signal-handler.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-msc54-cpp.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-signal-handler/stdcpp.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
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.cpp
@@ -0,0 +1,229 @@
+// RUN: %check_clang_tidy -std=c++14 %s bugprone-signal-handler %t -- -- -isystem %S/Inputs/Headers -isystem %S/Inputs/bugprone-signal-handler
+
+#include "stdcpp.h"
+#include "stdio.h"
+//#include "signal.h"
+
+// Functions called "signal" that are different from the system version.
+typedef void (*callback_t)(int);
+void signal(int, callback_t, int);
+namespace ns {
+void signal(int, callback_t);
+}
+
+extern "C" void handler_unsafe(int) {
+  printf("xxx");
+}
+
+extern "C" void handler_unsafe_1(int) {
+  printf("xxx");
+}
+
+namespace test_invalid_handler {
+
+void handler_non_extern_c(int) {
+  printf("xxx");
+}
+
+struct A {
+  static void handler_member(int) {
+printf("xxx");
+  }
+};
+
+void test() {
+  std::signal(SIGINT, handler_unsafe_1);
+  // CHECK-NOTES: :[[@LINE-17]]:3: warning: system call 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:23: note: function 'handler_unsafe_1' registered here as signal handler
+
+  std::signal(SIGINT, handler_non_extern_c);
+  // CHECK-NOTES: :[[@LINE-1]]:23: warning: functions with other than C linkage are not allowed as signal handler (until C++17) [bugprone-signal-handler]
+  std::signal(SIGINT, A::handler_member);
+  // CHECK-NOTES: :[[@LINE-1]]:23: warning: functions with other than C linkage are not allowed as signal handler (until C++17) [bugprone-signal-handler]
+  std::signal(SIGINT, [](int) { printf("xxx"); });
+  // CHECK-NOTES: :[[@LINE-1]]:23: warning: lambda function is not allowed as signal handler (until C++17) [bugprone-signal-handler]
+
+  // This case is (deliberately) not found by the checker.
+  std::signal(SIGINT, [](int) -> callback_t { return &handler_unsafe; }(1));
+}
+
+} // namespace test_invalid_handler
+
+namespace test_non_standard_signal_call {
+
+struct Signal {
+  static void signal(int, callback_t);
+};
+
+void test() {
+  // Do not find problems here.
+  signal(SIGINT, handler_unsafe, 1);
+  ns::signal(SIGINT, handler_unsafe);
+  Signal::signal(SIGINT, handler_unsafe);
+  system_other::signal(SIGINT, handler_unsafe);
+}
+
+} // namespace test_non_standard_signal_call
+
+namespace test_cpp_construct_in_handler {
+
+struct Struct {
+  virtual ~Struct() {}
+  void f1();
+  int *begin();
+  int *end();
+  static void f2();
+};
+struct Derived : public Struct {
+};
+
+struct X {
+  X(int, float);
+};
+
+Struct *S_Global;
+const Struct *S_GlobalConst;
+
+void f_non_extern_c() {
+}
+
+void f_default_arg(int P1 = 0) {
+}
+
+extern "C" void handler_cpp(int) {
+  using namespace ::test_cpp_construct_in_handler;
+
+  // These calls are not found as problems.
+  // (Called functions are not analyzed if the current function has already
+  // other problems.)
+  f_non_extern_c();
+  Struct::f2();
+  // 'auto' is not disallowed
+  auto Auto = 28u;
+
+  Struct S;
+  // CHECK-NOTES: :[[@LINE-1]]:10: warning: C++ only construct is not allowed in signal handler (until C++17) [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:10: note: statement class is: 'CXXConstructExpr'
+  // CHECK-NOTES: :199:23: note: function 'handler_cpp' registered here as signal handler
+  S_Global->f1();
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: C++ only construct is not allowed in signal handler (until C++17) [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-2]]:3: note: statement class is: 'CXXMemberCallExpr'
+  // CHECK-NOTES: :199:23: note

[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-04 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:6271
+This attribute, when attached to a function, causes the compiler to zero a
+subset of all call-used registers before the function returns. It's used to
+increase program security by either mitigating `Return-Oriented Programming`_

I think we need to define "call-used" here. It's not a very common name for 
this concept, and it's especially confusing because of the double-use of the 
word "used". I was really confused by the definition of the "all" choice when 
first reading it -- thinking "Wait, 'all' also only clears the registers which 
were used? How's that different than 'used', then? O, 'call-used' 
doesn't mean it IS USED in the call, only that it's not guaranteed to be 
PRESERVED."

Suggestion for text:
The term "call-used" means registers which are not guaranteed to be preserved 
unchanged for the caller by the current calling convention. This could also be 
described as "caller-saved" or "not callee-saved".




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

OpenCL C 3.0 __opencl_c_subgroups feature is slightly different
then other equivalent features and extensions (fp64 and 3d image writes):
OpenCL C 3.0 device can support the extension but not the feature.
cl_khr_subgroups requires subgroup independent forward progress.

This patch adjusts the check which is used when translating language
builtins to check either the extension or feature is supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118999

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -236,12 +236,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires support of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 
3.0 feature}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires support 
of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature}}
 }
 #endif // ifdef cl_khr_subgroups
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,11 @@
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
-S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
+S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_subgroups)
+<< 1 << Call->getDirectCallee();
 return true;
   }
   return false;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10175,6 +10175,9 @@
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
   "use of %select{type|declaration}0 %1 requires %2 support">;
+def err_opencl_requires_subgroups : Error<
+  "use of %select{type|declaration}0 %1 requires support of cl_khr_subgroups 
extension "
+  "or __opencl_c_subgroups OpenCL C 3.0 feature">;
 def ext_opencl_double_without_pragma : Extension<
   "Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is"
   " supported">;


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -236,12 +236,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires support of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires support of cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature}}
 }
 #endif // i

[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-04 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/Builtins.h:39
+  COR_LANG = 0x80, // builtin requires use of 'fcoroutine-ts' option.
+  OCLC2P_LANG = 0x100, // builtin for OpenCL C 2.0+ versions.
+  OCLC1X_LANG = 0x200, // builtin for OpenCL C 1.x only.

I am thinking that we probably don't need this combined mode now... I think it 
is enough to just have GAS, PIPES and BLOCKS separately. Then in 
`Builtin::Context::builtinIsSupported` we will have 3 separate checks against 
`LangOpts.OpenCLGenericAddressSpace`, `LangOpts.OpenCLPipes` and 
`LangOpts.Blocks` as they can be used for both OpenCL 2.0 and OpenCL 3.0. This 
could simplify this list.

Then we can also remove `OCL2P_WITH_GAS`, `OCL2P_WITH_PIPES` and 
`OCL2P_WITH_BLOCKS`.



Comment at: clang/include/clang/Basic/Builtins.h:40
+  OCLC2P_LANG = 0x100, // builtin for OpenCL C 2.0+ versions.
+  OCLC1X_LANG = 0x200, // builtin for OpenCL C 1.x only.
+  OCL_GAS = 0x400, // builtin requires OpenCL generic address space.

Btw is this field needed? I can't see any builtins that are using this... If 
it's unused we should just remove this entry.



Comment at: clang/include/clang/Basic/Builtins.h:43
+  OCL_PIPE = 0x800,// builtin requires OpenCL pipe.
+  BLOCKS = 0x1000, // builtin requires blocks.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.

let's use `OCL_BLOCKS` since `enqueue_kernel`, etc are OpenCL-only builtins.



Comment at: clang/include/clang/Basic/Builtins.h:53
+  OCLC2P_LANG | BLOCKS, // builtin requires OpenCL C 2.0+ and blocks.
+  ALL_OCLC_LANGUAGES = OCLC1X_LANG | OCLC2P_LANG // builtin for OCLC languages.
 };

For consistency `ALL_OCLC_LANGUAGES` -> `ALL_OCL_LANGUAGES`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

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


[clang] 853e0aa - Don't dllexport reference temporaries

2022-02-04 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2022-02-04T16:31:51+01:00
New Revision: 853e0aa424e40b80d0bda1dd8a3471a361048e4b

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

LOG: Don't dllexport reference temporaries

Even if the reference itself is dllexport, the temporary should not be.
In fact, we're already giving it internal linkage, so dllexporting it
is not just wasteful, but will fail to link, as in the example below:

  $ cat /tmp/a.cc
  void _DllMainCRTStartup() {}
  const int __declspec(dllexport) &foo = 42;

  $ clang-cl -fuse-ld=lld /tmp/a.cc /Zl /link /dll /out:a.dll
  lld-link: error: : undefined symbol: int const &foo::$RT1

Differential revision: https://reviews.llvm.org/D118980

Added: 
clang/test/CodeGenCXX/reference-temporary-ms.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 2346176a15628..5ffb954642a6b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5725,6 +5725,9 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, 
TargetAS);
   if (emitter) emitter->finalize(GV);
   setGVProperties(GV, VD);
+  if (GV->getDLLStorageClass() == llvm::GlobalVariable::DLLExportStorageClass)
+// The reference temporary should never be dllexport.
+GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
   GV->setAlignment(Align.getAsAlign());
   if (supportsCOMDAT() && GV->isWeakForLinker())
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));

diff  --git a/clang/test/CodeGenCXX/reference-temporary-ms.cpp 
b/clang/test/CodeGenCXX/reference-temporary-ms.cpp
new file mode 100644
index 0..dd12ad8ec59f9
--- /dev/null
+++ b/clang/test/CodeGenCXX/reference-temporary-ms.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | 
FileCheck %s
+
+const int __declspec(dllexport) &Exported = 42;
+
+// The reference temporary shouldn't be dllexport, even if the reference is.
+// CHECK: @"?$RT1@Exported@@3ABHB" = internal constant i32 42
+
+// CHECK: @"?Exported@@3ABHB" = dso_local dllexport constant i32* 
@"?$RT1@Exported@@3ABHB"



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


[PATCH] D114439: [Annotation] Allow parameter pack expansions and initializer lists in annotate attribute

2022-02-04 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 405963.
steffenlarsen added a comment.

Added check restricting variadic expression arguments to the last argument of 
attributes set to support parameter packs.
Added release notes.


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

https://reviews.llvm.org/D114439

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/annotate.c
  clang/test/SemaCXX/attr-annotate.cpp
  clang/test/SemaTemplate/attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -202,9 +202,9 @@
 bool Fake;
 
   public:
-Argument(const Record &Arg, StringRef Attr)
-: lowerName(std::string(Arg.getValueAsString("Name"))),
-  upperName(lowerName), attrName(Attr), isOpt(false), Fake(false) {
+Argument(StringRef Arg, StringRef Attr)
+: lowerName(std::string(Arg)), upperName(lowerName), attrName(Attr),
+  isOpt(false), Fake(false) {
   if (!lowerName.empty()) {
 lowerName[0] = std::tolower(lowerName[0]);
 upperName[0] = std::toupper(upperName[0]);
@@ -215,6 +215,8 @@
   if (lowerName == "interface")
 lowerName = "interface_";
 }
+Argument(const Record &Arg, StringRef Attr)
+: Argument(Arg.getValueAsString("Name"), Attr) {}
 virtual ~Argument() = default;
 
 StringRef getLowerName() const { return lowerName; }
@@ -666,6 +668,11 @@
   ArgName(getLowerName().str() + "_"), ArgSizeName(ArgName + "Size"),
   RangeName(std::string(getLowerName())) {}
 
+VariadicArgument(StringRef Arg, StringRef Attr, std::string T)
+: Argument(Arg, Attr), Type(std::move(T)),
+  ArgName(getLowerName().str() + "_"), ArgSizeName(ArgName + "Size"),
+  RangeName(std::string(getLowerName())) {}
+
 const std::string &getType() const { return Type; }
 const std::string &getArgName() const { return ArgName; }
 const std::string &getArgSizeName() const { return ArgSizeName; }
@@ -688,6 +695,18 @@
  << "); }\n";
 }
 
+void writeSetter(raw_ostream &OS) const {
+  OS << "  void set" << getUpperName() << "(ASTContext &Ctx, ";
+  writeCtorParameters(OS);
+  OS << ") {\n";
+  OS << "" << ArgSizeName << " = " << getUpperName() << "Size;\n";
+  OS << "" << ArgName << " = new (Ctx, 16) " << getType() << "["
+ << ArgSizeName << "];\n";
+  OS << "  ";
+  writeCtorBody(OS);
+  OS << "  }\n";
+}
+
 void writeCloneArgs(raw_ostream &OS) const override {
   OS << ArgName << ", " << ArgSizeName;
 }
@@ -1169,6 +1188,9 @@
   : VariadicArgument(Arg, Attr, "Expr *")
 {}
 
+VariadicExprArgument(StringRef ArgName, StringRef Attr)
+: VariadicArgument(ArgName, Attr, "Expr *") {}
+
 void writeASTVisitorTraversal(raw_ostream &OS) const override {
   OS << "  {\n";
   OS << "" << getType() << " *I = A->" << getLowerName()
@@ -2138,6 +2160,11 @@
   }
 }
 
+static bool isTypeArgument(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ Arg->getSuperClasses().back().first->getName() == "TypeArgument";
+}
+
 /// Emits the first-argument-is-type property for attributes.
 static void emitClangAttrTypeArgList(RecordKeeper &Records, raw_ostream &OS) {
   OS << "#if defined(CLANG_ATTR_TYPE_ARG_LIST)\n";
@@ -2149,7 +2176,7 @@
 if (Args.empty())
   continue;
 
-if (Args[0]->getSuperClasses().back().first->getName() != "TypeArgument")
+if (!isTypeArgument(Args[0]))
   continue;
 
 // All these spellings take a single type argument.
@@ -2179,7 +2206,7 @@
   OS << "#endif // CLANG_ATTR_ARG_CONTEXT_LIST\n\n";
 }
 
-static bool isIdentifierArgument(Record *Arg) {
+static bool isIdentifierArgument(const Record *Arg) {
   return !Arg->getSuperClasses().empty() &&
 llvm::StringSwitch(Arg->getSuperClasses().back().first->getName())
 .Case("IdentifierArgument", true)
@@ -2188,7 +2215,7 @@
 .Default(false);
 }
 
-static bool isVariadicIdentifierArgument(Record *Arg) {
+static bool isVariadicIdentifierArgument(const Record *Arg) {
   return !Arg->getSuperClasses().empty() &&
  llvm::StringSwitch(
  Arg->getSuperClasses().back().first->getName())
@@ -2264,6 +2291,26 @@
   OS << "#endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST\n\n";
 }
 
+static void emitClangAttrAcc

[PATCH] D118980: Don't dllexport reference temporaries

2022-02-04 Thread Hans Wennborg 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 rG853e0aa424e4: Don't dllexport reference temporaries 
(authored by hans).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118980

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/reference-temporary-ms.cpp


Index: clang/test/CodeGenCXX/reference-temporary-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/reference-temporary-ms.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | 
FileCheck %s
+
+const int __declspec(dllexport) &Exported = 42;
+
+// The reference temporary shouldn't be dllexport, even if the reference is.
+// CHECK: @"?$RT1@Exported@@3ABHB" = internal constant i32 42
+
+// CHECK: @"?Exported@@3ABHB" = dso_local dllexport constant i32* 
@"?$RT1@Exported@@3ABHB"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5725,6 +5725,9 @@
   /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, 
TargetAS);
   if (emitter) emitter->finalize(GV);
   setGVProperties(GV, VD);
+  if (GV->getDLLStorageClass() == llvm::GlobalVariable::DLLExportStorageClass)
+// The reference temporary should never be dllexport.
+GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
   GV->setAlignment(Align.getAsAlign());
   if (supportsCOMDAT() && GV->isWeakForLinker())
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));


Index: clang/test/CodeGenCXX/reference-temporary-ms.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/reference-temporary-ms.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | FileCheck %s
+
+const int __declspec(dllexport) &Exported = 42;
+
+// The reference temporary shouldn't be dllexport, even if the reference is.
+// CHECK: @"?$RT1@Exported@@3ABHB" = internal constant i32 42
+
+// CHECK: @"?Exported@@3ABHB" = dso_local dllexport constant i32* @"?$RT1@Exported@@3ABHB"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5725,6 +5725,9 @@
   /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
   if (emitter) emitter->finalize(GV);
   setGVProperties(GV, VD);
+  if (GV->getDLLStorageClass() == llvm::GlobalVariable::DLLExportStorageClass)
+// The reference temporary should never be dllexport.
+GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
   GV->setAlignment(Align.getAsAlign());
   if (supportsCOMDAT() && GV->isWeakForLinker())
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 405967.
tianshilei1992 added a comment.

add TODO for PCH test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_ast_print.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -ferror-limit 150 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -ferror-limit 150 %s -Wuninitialized
-// RUN: %clang_cc1 -verify=expected,omp50,omp51 -fopenmp -fopenmp-version=51 -ferror-limit 150 %s -Wuninitialized
+// RUN: %clang_cc1 -DOMP51 -verify=expected,omp50,omp51 -fopenmp -fopenmp-version=51 -ferror-limit 150 %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -ferror-limit 150 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -ferror-limit 150 %s -Wuninitialized
-// RUN: %clang_cc1 -verify=expected,omp50,omp51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 150 %s -Wuninitialized
+// RUN: %clang_cc1 -DOMP51 -verify=expected,omp50,omp51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 150 %s -Wuninitialized
 
 int foo() {
 L1:
@@ -914,6 +914,16 @@
 // expected-note@+1 2 {{'capture' clause used here}}
 #pragma omp atomic capture read
   a = ++b;
+#ifdef OMP51
+// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
+// expected-note@+1 2 {{'write' clause used here}}
+#pragma omp atomic write compare
+  a = b;
+// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
+// expected-note@+1 2 {{'read' clause used here}}
+#pragma omp atomic read compare
+  a = b;
+#endif
   return T();
 }
 
@@ -935,6 +945,16 @@
 // expected-note@+1 {{'write' clause used here}}
 #pragma omp atomic write capture
   a = b;
+#ifdef OMP51
+// expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
+// expected-note@+1 {{'write' clause used here}}
+#pragma omp atomic write compare
+  a = b;
+// expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
+// expected-note@+1 {{'read' clause used here}}
+#pragma omp atomic read compare
+  a = b;
+#endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
 }
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -DOMP51 -verify=expected,omp50,omp51 -fopenmp -fopenmp-version=51 -ferror-limit 100 %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -DOMP51 -verify=expected,omp50,omp51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 100 %s -Wuninitialized
 
 void xxx(int argc) {
   int x; // expected-note {{initialize the variable 'x' to silence this warning}}
@@ -394,3 +396,92 @@
 #pragma omp atomic hint(1) hint(1) // omp45-error 2 {{unexpected OpenMP clause 'hint' in directive '#pragma omp atomic'}} expected-error {{directive '#pragma omp atomic' cannot contain more than one 'hint' clause}}
   a += 1;
 }
+
+#ifdef OMP51
+extern void bbar();
+extern int ffoo();
+
+void compare() {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+// omp51-error@+3 {{the statement for 'atomic compare' must be a compound statement of form '{x = expr ordop x ? expr : x;}', '{x = x ordop expr? expr : x;}', '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare
+  {}
+// omp51-error@+3 {{the statement for 'atomic compare' must be a compound statement of form '{x = expr ordop x ? expr : x;}', '{x = x or

[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:40
+#ifdef OMP51
+// omp51-error@+1 2 {{atomic compare is not supported for now}}
+#pragma omp atomic compare

Try to add `-fsyntax-only` in RUN to avoid error message in the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D114439: [Annotation] Allow parameter pack expansions and initializer lists in annotate attribute

2022-02-04 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:545
+  // Set to true if this attribute accepts parameter pack expansion 
expressions.
+  bit AcceptsExprPack = 0;
   // Lists language options, one of which is required to be true for the

aaron.ballman wrote:
> You should probably add a release note about this new feature.
I have added a release note about this under "Internal API Changes". Let me 
know if you think the wording needs changes.



Comment at: clang/include/clang/Basic/Attr.td:789
   let PragmaAttributeSupport = 1;
+  let AcceptsExprPack = 1;
   let Documentation = [Undocumented];

aaron.ballman wrote:
> You should definitely add a release note about this new behavior for annotate.
I have added a release note about this under "Attribute Changes in Clang". As 
with the other note, let me know if wording needs changes.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8153
+
+  bool AttrHasVariadicArg = AL.hasVariadicArg();
+  unsigned AttrNumArgs = AL.getNumArgMembers();

erichkeane wrote:
> steffenlarsen wrote:
> > erichkeane wrote:
> > > This still doesn't work if the VariadicExprArgument isn't last, right?  
> > > Do we ensure that is the case in clang-attr-emitter?
> > Good point. I don't think there's a check as there are select few 
> > attributes that use multiple variadic (`OMPDeclareSimdDecl` and 
> > `OMPDeclareVariant` are the only ones, I think.)
> > 
> > Since I don't think it's safe to check for all, should I make a check 
> > similar to the one for type/identifier arguments in attributes marked 
> > `AcceptsExprPack`? Would that suffice?
> I'm fine rejecting a case that has anything besides expression-arguments(and 
> ones create-able from expression arguments) and 
> limited-to-only-1-must-be-last variadic-expr-list in ClangAttrEmitter.
> 
> I believe we discussed that at one point, but I didn't see it here.
I have added a check to ClangAttrEmitter next to the check ensuring that the 
relevant attributes don't have identifier or type arguments.


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

https://reviews.llvm.org/D114439

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


[PATCH] D99436: [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

2022-02-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 405968.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99436

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/taskloop_loop_messages.cpp

Index: clang/test/OpenMP/taskloop_loop_messages.cpp
===
--- clang/test/OpenMP/taskloop_loop_messages.cpp
+++ clang/test/OpenMP/taskloop_loop_messages.cpp
@@ -691,7 +691,7 @@
 
 void test_loop_eh() {
   const int N = 100;
-  float a[N], b[N], c[N];
+  float a[N], b[N], c[N]; // expected-note {{declared here}}
 #pragma omp parallel
 #pragma omp taskloop
   for (int i = 0; i < 10; i++) {
@@ -729,6 +729,13 @@
   void g() { throw 0; }
 };
   }
+// expected-error@+5 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+4 {{read of non-constexpr variable 'c' is not allowed in a constant expression}}
+#pragma omp taskloop untied
+  {
+  for (int i = 0; i < 10; ++i)
+int array[(int)c[0]];
+  }
 }
 
 void test_loop_firstprivate_lastprivate() {
Index: clang/test/OpenMP/task_messages.cpp
===
--- clang/test/OpenMP/task_messages.cpp
+++ clang/test/OpenMP/task_messages.cpp
@@ -173,7 +173,7 @@
   int &b = a;
   S sa;
   S &sb = sa;
-  int r;
+  int r; // expected-note {{declared here}}
 #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
   foo();
 #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
@@ -330,6 +330,12 @@
 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
 #pragma omp task mergeable mergeable
   ++r;
+// expected-error@+4 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+3 {{read of non-const variable 'r' is not allowed in a constant expression}}
+#pragma omp task untied
+  {
+int array[r];
+  }
   volatile omp_event_handle_t evt;
   omp_event_handle_t sevt;
   const omp_event_handle_t cevt = evt;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2458,6 +2458,9 @@
   } else if (isSFINAEContext()) {
 VLADiag = diag::err_vla_in_sfinae;
 VLAIsError = true;
+  } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) {
+VLADiag = diag::err_openmp_vla_in_task_untied;
+VLAIsError = true;
   } else {
 VLADiag = diag::ext_vla;
 VLAIsError = false;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -175,6 +175,7 @@
 bool HasMutipleLoops = false;
 const Decl *PossiblyLoopCounter = nullptr;
 bool NowaitRegion = false;
+bool UntiedRegion = false;
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
@@ -850,6 +851,15 @@
   return Parent->NowaitRegion;
 return false;
   }
+  /// Marks current region as untied (it has a 'untied' clause).
+  void setUntiedRegion(bool IsUntied = true) {
+getTopOfStack().UntiedRegion = IsUntied;
+  }
+  /// Return true if current region is untied.
+  bool isUntiedRegion() const {
+const SharingMapTy *Top = getTopOfStackOrNull();
+return Top ? Top->UntiedRegion : false;
+  }
   /// Marks parent region as cancel region.
   void setParentCancelRegion(bool Cancel = true) {
 if (SharingMapTy *Parent = getSecondOnStackOrNull())
@@ -2157,6 +2167,11 @@
   return DSAStack->getNestingLevel();
 }
 
+bool Sema::isInOpenMPTaskUntiedContext() const {
+  return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
+ DSAStack->isUntiedRegion();
+}
+
 bool Sema::isInOpenMPTargetExecutionDirective() const {
   return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
   !DSAStack->isClauseParsingMode()) ||
@@ -15400,6 +15415,7 @@
 
 OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
  SourceLocation EndLoc) {
+  DSAStack->setUntiedRegion();
   return new (Context) OMPUntiedClause(StartLoc, EndLoc);
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10661,6 +10661,10 @@
   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
  const FunctionDecl *Callee,
  SourceLocation Loc);
+
+  /// Return tru

[PATCH] D117306: [clang-tidy] Add new check 'shared-ptr-array-mismatch'.

2022-02-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h:40
+  /// in this class.
+  virtual SmartPtrClassMatcher getSmartPointerClassMatcher() const = 0;
+

njames93 wrote:
> LegalizeAdulthood wrote:
> > There's only one implementation of this abstract method declared here.
> > 
> > Why the extra level in the class hierarchy if there's only one 
> > implementation?
> The idea I think is so that this can be used to make a similar check for 
> `unique_ptr`. However I almost don't see the need for this, and I'd argue 
> that they should both be implemented in one check. So this will detect 
> ```lang=c++
> std::shared_ptr X = new int[5];
> std::unique_ptr Y = new int[5];
> ```
If I remember correctly the idea was to make the possible check for 
`unique_ptr`. Putting it into a separate check allows to independently turn the 
checks for shared or unique pointer on or off (like `MakeSmartPtrCheck`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117306

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


[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-04 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Btw can you point us to the spec reference please, I can't seem to find 
anything related to this: 
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#subgroup-functions.

It would be nice to add the reference in the code comment too.




Comment at: clang/lib/Sema/SemaChecking.cpp:1048
+S.getLangOpts())) {
+S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_subgroups)
+<< 1 << Call->getDirectCallee();

Ideally we should reduce the number of separate diagnostics, so could we just 
print something like:
`"cl_khr_subgroups extension or __opencl_c_subgroups OpenCL C 3.0 feature"`
when using `diag::err_opencl_requires_extension`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118999

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


[PATCH] D117306: [clang-tidy] Add new check 'shared-ptr-array-mismatch'.

2022-02-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 405971.
balazske added a comment.

Code simplification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117306

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.h
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-shared-ptr-array-mismatch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-shared-ptr-array-mismatch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-shared-ptr-array-mismatch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-shared-ptr-array-mismatch.cpp
@@ -0,0 +1,95 @@
+// RUN: %check_clang_tidy %s bugprone-shared-ptr-array-mismatch %t
+
+namespace std {
+
+template 
+struct shared_ptr {
+  template 
+  explicit shared_ptr(Y *) {}
+  template 
+  shared_ptr(Y *, Deleter) {}
+};
+
+} // namespace std
+
+struct A {};
+
+void f1() {
+  std::shared_ptr P1{new int};
+  std::shared_ptr P2{new int[10]};
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  // CHECK-FIXES: std::shared_ptr P2{new int[10]};
+  // clang-format off
+  std::shared_ptr<  int  > P3{new int[10]};
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  // CHECK-FIXES: std::shared_ptr<  int[]  > P3{new int[10]};
+  // clang-format on
+  std::shared_ptr P4(new int[10]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  // CHECK-FIXES: std::shared_ptr P4(new int[10]);
+  new std::shared_ptr(new int[10]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  std::shared_ptr P5(new int[10]);
+  std::shared_ptr P6(new int[10], [](const int *Ptr) {});
+}
+
+void f2() {
+  std::shared_ptr P1(new A);
+  std::shared_ptr P2(new A[10]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  // CHECK-FIXES: std::shared_ptr P2(new A[10]);
+  std::shared_ptr P3(new A[10]);
+}
+
+void f3() {
+  std::shared_ptr P1{new int}, P2{new int[10]}, P3{new int[10]};
+  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  // CHECK-MESSAGES: :[[@LINE-2]]:57: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+}
+
+struct S {
+  std::shared_ptr P1;
+  std::shared_ptr P2{new int[10]};
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  std::shared_ptr P3{new int}, P4{new int[10]};
+  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  S() : P1{new int[10]} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+};
+
+void f_parm(std::shared_ptr);
+
+void f4() {
+  f_parm(std::shared_ptr{new int[10]});
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+}
+
+std::shared_ptr f_ret() {
+  return std::shared_ptr(new int[10]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+}
+
+template 
+void f_tmpl() {
+  std::shared_ptr P1{new T[10]};
+}
+
+void f5() {
+  f_tmpl();
+}
+
+#define CHAR_PTR_TYPE std::shared_ptr
+#define CHAR_PTR_VAR(X) \
+  X { new char[10] }
+#define CHAR_PTR_INIT(X, Y) \
+  std::shared_ptr X { Y }
+
+void f6() {
+  CHAR_PTR_TYPE P1{new char[10]};
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  std::shared_ptr CHAR_PTR_VAR(P2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: shared pointer to non-array is initialized with array [bugprone-shared-ptr-array-mismatch]
+  // CHECK-FIXES: std::shared_ptr CHAR_PTR_VAR(P2);
+  CHAR_PTR_INIT(P3, new char[10]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: shared pointer to non-array is initialized with array [bugprone-shared-p

[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:40
+#ifdef OMP51
+// omp51-error@+1 2 {{atomic compare is not supported for now}}
+#pragma omp atomic compare

ABataev wrote:
> Try to add `-fsyntax-only` in RUN to avoid error message in the test
Adding `-fsyntax-only` will not print the AST, just the error message.
```
➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print atomic.cpp
atomic.cpp:12:20: error: atomic compare is not supported for now
#pragma omp atomic compare
   ^
class C {
int x;
public:
int &val() {
return this->x;
}
};
void compare() {
C x;
C e;
C d;
#pragma omp atomic compare
if (x.val() == e.val())
x.val() = d.val();
}
1 error generated.
➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print -fsyntax-only 
atomic.cpp
atomic.cpp:12:20: error: atomic compare is not supported for now
#pragma omp atomic compare
   ^
1 error generated.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:40
+#ifdef OMP51
+// omp51-error@+1 2 {{atomic compare is not supported for now}}
+#pragma omp atomic compare

tianshilei1992 wrote:
> ABataev wrote:
> > Try to add `-fsyntax-only` in RUN to avoid error message in the test
> Adding `-fsyntax-only` will not print the AST, just the error message.
> ```
> ➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print atomic.cpp
> atomic.cpp:12:20: error: atomic compare is not supported for now
> #pragma omp atomic compare
>^
> class C {
> int x;
> public:
> int &val() {
> return this->x;
> }
> };
> void compare() {
> C x;
> C e;
> C d;
> #pragma omp atomic compare
> if (x.val() == e.val())
> x.val() = d.val();
> }
> 1 error generated.
> ➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print -fsyntax-only 
> atomic.cpp
> atomic.cpp:12:20: error: atomic compare is not supported for now
> #pragma omp atomic compare
>^
> 1 error generated.
> ```
Ah, yes. Can you move the error message to codegen from Sema to avoid all these 
problems?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:40
+#ifdef OMP51
+// omp51-error@+1 2 {{atomic compare is not supported for now}}
+#pragma omp atomic compare

ABataev wrote:
> tianshilei1992 wrote:
> > ABataev wrote:
> > > Try to add `-fsyntax-only` in RUN to avoid error message in the test
> > Adding `-fsyntax-only` will not print the AST, just the error message.
> > ```
> > ➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print atomic.cpp
> > atomic.cpp:12:20: error: atomic compare is not supported for now
> > #pragma omp atomic compare
> >^
> > class C {
> > int x;
> > public:
> > int &val() {
> > return this->x;
> > }
> > };
> > void compare() {
> > C x;
> > C e;
> > C d;
> > #pragma omp atomic compare
> > if (x.val() == e.val())
> > x.val() = d.val();
> > }
> > 1 error generated.
> > ➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print -fsyntax-only 
> > atomic.cpp
> > atomic.cpp:12:20: error: atomic compare is not supported for now
> > #pragma omp atomic compare
> >^
> > 1 error generated.
> > ```
> Ah, yes. Can you move the error message to codegen from Sema to avoid all 
> these problems?
Do we support error message in code gen? I didn't see similar code in 
`clang/lib/CodeGen/CGStmtOpenMP.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D116637: [Clang][Sema][OpenMP] Sema support for `atomic compare`

2022-02-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_ast_print.cpp:40
+#ifdef OMP51
+// omp51-error@+1 2 {{atomic compare is not supported for now}}
+#pragma omp atomic compare

tianshilei1992 wrote:
> ABataev wrote:
> > tianshilei1992 wrote:
> > > ABataev wrote:
> > > > Try to add `-fsyntax-only` in RUN to avoid error message in the test
> > > Adding `-fsyntax-only` will not print the AST, just the error message.
> > > ```
> > > ➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print atomic.cpp
> > > atomic.cpp:12:20: error: atomic compare is not supported for now
> > > #pragma omp atomic compare
> > >^
> > > class C {
> > > int x;
> > > public:
> > > int &val() {
> > > return this->x;
> > > }
> > > };
> > > void compare() {
> > > C x;
> > > C e;
> > > C d;
> > > #pragma omp atomic compare
> > > if (x.val() == e.val())
> > > x.val() = d.val();
> > > }
> > > 1 error generated.
> > > ➜  clang -cc1 -x c++ -fopenmp -fopenmp-version=51 -ast-print 
> > > -fsyntax-only atomic.cpp
> > > atomic.cpp:12:20: error: atomic compare is not supported for now
> > > #pragma omp atomic compare
> > >^
> > > 1 error generated.
> > > ```
> > Ah, yes. Can you move the error message to codegen from Sema to avoid all 
> > these problems?
> Do we support error message in code gen? I didn't see similar code in 
> `clang/lib/CodeGen/CGStmtOpenMP.cpp`.
Check lib/CodeGen/CGOpenMPRuntime.cpp, `getDiagnostics().Report()` calls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116637

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


[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-04 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

It seems hard to find a direct mention in the spec, but in the API spec:

//CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: Is CL_TRUE if this device 
supports independent forward progress of sub-groups, CL_FALSE otherwise. This 
query must return CL_TRUE for devices that support the cl_khr_subgroups 
extension, and must return CL_FALSE for devices that do not support subgroups.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118999

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


  1   2   3   >