[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks, this looks great.




Comment at: clang-tools-extra/clangd/XRefs.cpp:1387
+if (auto LSPLoc =
+toLSPLocation(Object.CanonicalDeclaration, *MainFilePath)) {
+  ReferencesResult::Reference Result;

I guess we should include the definition location as well? 



Comment at: clang-tools-extra/clangd/XRefs.h:86
 Definition = 1 << 1,
+OverriddenBy = 1 << 2,
   };

nit: add some doc, I'd just name it `override` as this field indicates this is 
an occurrence overrides the base method.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

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


[PATCH] D95737: [NFC][Docs] Fix RAVFrontendAction doc's CMakelists.txt for Shared build

2021-02-01 Thread Shivam Gupta 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 rG6ee1f64a2e82: [NFC][Docs] Fix RAVFrontendAction doc's 
CMakelists.txt for Shared build (authored by xgupta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95737

Files:
  clang/docs/RAVFrontendAction.rst


Index: clang/docs/RAVFrontendAction.rst
===
--- clang/docs/RAVFrontendAction.rst
+++ clang/docs/RAVFrontendAction.rst
@@ -207,7 +207,14 @@
 
 add_clang_executable(find-class-decls FindClassDecls.cpp)
 
-target_link_libraries(find-class-decls clangTooling)
+target_link_libraries(find-class-decls 
+  PRIVATE
+  clangAST
+  clangBasic
+  clangFrontend
+  clangSerialization
+  clangTooling
+  )
 
 When running this tool over a small code snippet it will output all
 declarations of a class n::m::C it found:


Index: clang/docs/RAVFrontendAction.rst
===
--- clang/docs/RAVFrontendAction.rst
+++ clang/docs/RAVFrontendAction.rst
@@ -207,7 +207,14 @@
 
 add_clang_executable(find-class-decls FindClassDecls.cpp)
 
-target_link_libraries(find-class-decls clangTooling)
+target_link_libraries(find-class-decls 
+  PRIVATE
+  clangAST
+  clangBasic
+  clangFrontend
+  clangSerialization
+  clangTooling
+  )
 
 When running this tool over a small code snippet it will output all
 declarations of a class n::m::C it found:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6ee1f64 - [NFC][Docs] Fix RAVFrontendAction doc's CMakelists.txt for Shared build

2021-02-01 Thread via cfe-commits

Author: xgupta
Date: 2021-02-02T13:08:40+05:30
New Revision: 6ee1f64a2e828d27a6c20839232b3ac828367123

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

LOG: [NFC][Docs] Fix RAVFrontendAction doc's CMakelists.txt for Shared build

[[ https://clang.llvm.org/docs/RAVFrontendAction.html | Example tutorial ]] 
giving undefine reference error while building with BUILD_SHARED_LIBS=ON.

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

Added: 


Modified: 
clang/docs/RAVFrontendAction.rst

Removed: 




diff  --git a/clang/docs/RAVFrontendAction.rst 
b/clang/docs/RAVFrontendAction.rst
index 2c168a0577e1..71722a15936a 100644
--- a/clang/docs/RAVFrontendAction.rst
+++ b/clang/docs/RAVFrontendAction.rst
@@ -207,7 +207,14 @@ following CMakeLists.txt to link it:
 
 add_clang_executable(find-class-decls FindClassDecls.cpp)
 
-target_link_libraries(find-class-decls clangTooling)
+target_link_libraries(find-class-decls 
+  PRIVATE
+  clangAST
+  clangBasic
+  clangFrontend
+  clangSerialization
+  clangTooling
+  )
 
 When running this tool over a small code snippet it will output all
 declarations of a class n::m::C it found:



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


[PATCH] D95737: [NFC][Docs] Fix RAVFrontendAction doc's CMakelists.txt for Shared build

2021-02-01 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta accepted this revision.
xgupta added a comment.
This revision is now accepted and ready to land.

I build the project on my system x64 with shared libraries enable. It is 
working correctly. It is also NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95737

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy marked an inline comment as done.
hoy added inline comments.



Comment at: clang/test/Driver/pseudo-probe-lto.c:6
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+

wmi wrote:
> Better add another check of NOPROBE when neither -fpseudo-probe-for-profiling 
> or -fno-pseudo-probe-for-profiling is provided. 
Good point, test case added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95271

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 320686.
hoy added a comment.

Addressing Wei's comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling, false))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling, false))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/inclu

[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:609-610
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");

wmi wrote:
> The third arg of Args.hasFlag defaults to true, which means 
> -plugin-opt=pseudo-probe-for-profiling will be inserted even if no 
> -fpseudo-probe-for-profiling or -fno-pseudo-probe-for-profiling is provided. 
> Is it expected?
Good catch, it's not expected. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95271

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Wei Mi via Phabricator via cfe-commits
wmi added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:609-610
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");

The third arg of Args.hasFlag defaults to true, which means 
-plugin-opt=pseudo-probe-for-profiling will be inserted even if no 
-fpseudo-probe-for-profiling or -fno-pseudo-probe-for-profiling is provided. Is 
it expected?



Comment at: clang/test/Driver/pseudo-probe-lto.c:6
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+

Better add another check of NOPROBE when neither -fpseudo-probe-for-profiling 
or -fno-pseudo-probe-for-profiling is provided. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95271

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


[PATCH] D68682: format::cleanupAroundReplacements removes whole line when Removals leave previously non-blank line blank

2021-02-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc marked 14 inline comments as done.
poelmanc added inline comments.



Comment at: clang/lib/Format/Format.cpp:2381
+// if so adds a Replacement to NewReplacements that removes the entire line.
+llvm::Error MaybeRemoveBlankLine(tooling::Replacements &NewReplaces,
+ StringRef FilePath, StringRef Code,

kadircet wrote:
> kadircet wrote:
> > can we rather make this function return a `tooling::Replacement` ?
> name should be `maybeRemoveBlankLine`
`maybeRemoveBlankLine` needs to be called twice so I tried to put maximum logic 
in it so to avoid replicating logic at the two calling sites. It doesn't always 
create a replacement, so I believe we could return 
`optional`. Then the caller would have to check the 
`optional`, and if set  call `NewReplaces.add()`, then check that result... I 
can do that if you like but please take a fresh look at the updated 
implementation. Thanks!



Comment at: clang/lib/Format/Format.cpp:2394
+assert(LineEndPos >= CheckedThroughPos);
+StringRef TrailingText(FileText + CheckedThroughPos,
+   LineEndPos - CheckedThroughPos);

kadircet wrote:
> ```
> if(!isAllWhiteSpace(Code.substr(CheckedThroughPos, LineEndPos - 
> CheckedThroughPos))
>   return llvm::Error::success();
> ```
Coming back after a year I found my own code here a bit hard to read... Your 
feedback prompted me to use `StringRef` over `char*` and reduce the number of 
intermediate variables. I put your two suggested `isAllWhiteSpace` calls 
`isAllWhiteSpace` together with `&&`, feel free to suggest further improvement.




Comment at: clang/lib/Format/Format.cpp:2397
+assert(LineEndPos >= LineStartPos);
+StringRef OriginalLine(FileText + LineStartPos, LineEndPos - LineStartPos);
+if (isAllWhitespace(TrailingText) && !isAllWhitespace(OriginalLine)) {

kadircet wrote:
> ```
> if(isAllWhiteSpace(Code.substr(LineStartPos, CheckedThroughPos - 
> LineStartPos))
>   return llvm::Error::success();
> ```
> 
> Also move this to the top, as it doesn't actually require any of the 
> computations you performed.
> 
> I would actually keep a `HasDeleted` flag in the caller, updating it by 
> looking at length of replacements, and call this function iff we've deleted 
> something in that line, but up to you.
Used suggested `isAllWhitespace` together in the `if` clause with above 
`isAllWhitespace`.



Comment at: clang/lib/Format/Format.cpp:2403
+  (CheckedThroughPos > 0 &&
+   isVerticalWhitespace(FileText[CheckedThroughPos - 1]))
+  ? (FileText + LineEndPos)

kadircet wrote:
> i don't follow what this check is about.
> 
> the comment talks about a replacement removing a trailing newline, but check 
> is for a preceding whitespace, and it is not even at the `LineEndPos` ?
> how come we get a vertical whitespace, in the middle of a line?
I clarified the comment to include an example: when the code is `...  
foo\n\n...` and `foo\n` is removed by a replacement already, the second `\n` 
actually represents the //next// line which we don't want to remove.



Comment at: clang/unittests/Format/CleanupTest.cpp:368
+TEST_F(CleanUpReplacementsTest, RemoveLineWhenAllNonWhitespaceRemoved) {
+  std::string Code = "namespace A { // Useless comment\n"
+ "  int x\t = 0;\t\n"

kadircet wrote:
> poelmanc wrote:
> > kadircet wrote:
> > > could you replace these with raw string literals instead to get rid of 
> > > `\n`s.
> > I like that modernization suggestion but as a fairly new llvm contributor I 
> > follow the style I see in the surrounding code. Perhaps we should submit a 
> > seperate patch to modernize whole files at a time to use raw string 
> > literals and see how the change is received by the community.
> modernization of the existing code, and introducing old code are different 
> things. former is harder because we would like to keep the history clean, but 
> we tend to do the latter to make sure quality improves over time.
> 
> feel free to keep it if you want though, this one isn't so important.
I tried raw string literals, but these particular tests are all about tabs, 
spaces, and newlines which I found harder to see and reason about using raw 
string literals. I kept the raw string literals in 
`RemoveLinesWhenAllNonWhitespaceRemoved`.



Comment at: clang/unittests/Format/CleanupTest.cpp:376
+  tooling::Replacements Replaces =
+  toReplacements({createReplacement(getOffset(Code, 1, 14), 19, ""),
+  createReplacement(getOffset(Code, 2, 3), 3, ""),

kadircet wrote:
> poelmanc wrote:
> > kadircet wrote:
> > > can you make use of `Annotations` library in 
> > > `llvm/include/llvm/Testing/Support/Annotations.h` for getting offsets 
> > > into the code?
> > > 
> > > same for the following test ca

[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 320685.
usaxena95 added a comment.

Remove unintended changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1706,6 +1706,10 @@
   for (const auto &R : T.ranges("decl"))
 ExpectedLocations.push_back(
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration)));
+  for (const auto &R : T.ranges("override"))
+ExpectedLocations.push_back(
+AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
+   ReferencesResult::OverriddenBy)));
   EXPECT_THAT(
   findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
   .References,
@@ -1862,7 +1866,7 @@
 checkFindRefs(Test);
 }
 
-TEST(FindReferences, IncludeOverrides) {
+TEST(FindReferences, IncludeOverrideDeclaration) {
   llvm::StringRef Test =
   R"cpp(
 class Base {
@@ -1871,10 +1875,10 @@
 };
 class Derived : public Base {
 public:
-  void [[func]]() override;
+  void $override[[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -83,6 +83,7 @@
   enum ReferenceAttributes : unsigned {
 Declaration = 1 << 0,
 Definition = 1 << 1,
+OverriddenBy = 1 << 2,
   };
   struct Reference {
 Location Loc;
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1300,7 +1300,7 @@
 return {};
   }
 
-  llvm::DenseSet IDs, Overrides;
+  llvm::DenseSet IDs;
 
   const auto *IdentifierAtCursor =
   syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
@@ -1339,25 +1339,19 @@
   if (auto ID = getSymbolID(D))
 Targets.insert(ID);
 
+RelationsRequest OverriddenBy;
 if (Index) {
-  RelationsRequest FindOverrides;
-  FindOverrides.Predicate = RelationKind::OverriddenBy;
+  OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
-// Special case: virtual void meth^od() = 0 includes refs of overrides.
+// Special case: Inlcude declaration of overridding methods.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isPure())
+  if (CMD->isVirtual())
 if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
   IdentifierAtCursor->location())
   if (auto ID = getSymbolID(CMD))
-FindOverrides.Subjects.insert(ID);
+OverriddenBy.Subjects.insert(ID);
 }
   }
-  if (!FindOverrides.Subjects.empty())
-Index->relations(FindOverrides,
- [&](const SymbolID &Subject, const Symbol &Object) {
-   Overrides.insert(Object.ID);
- });
-  Targets.insert(Overrides.begin(), Overrides.end());
 }
 
 // We traverse the AST to find references in the main file.
@@ -1376,17 +1370,29 @@
   ReferencesResult::Reference Result;
   Result.Loc.range = Ref.range(SM);
   Result.Loc.uri = URIMainFile;
-  // Overrides are always considered references, not defs/decls.
-  if (!Overrides.contains(Ref.Target)) {
-if (Ref.Role & static_cast(index::SymbolRole::Declaration))
-  Result.Attributes |= ReferencesResult::Declaration;
-// clang-index doesn't report definitions as declarations, but they are.
-if (Ref.Role & static_cast(index::SymbolRole::Definition))
-  Result.Attributes |=
-  ReferencesResult::Definition | ReferencesResult::Declaration;
-  }
+  if (Ref.Role & static_cast(index::SymbolRole::Declaration))
+Result.Attributes |= ReferencesResult::Declaration;
+  // clang-index doesn't report definitions as declarations, but they are.
+  if (Ref.Role & static_cast(index::SymbolRole::Definition))
+Result.Attributes |=
+ReferencesResult::Definition | ReferencesResult::Declaration;
   Results.References.push_back(std::move(Result));
 }
+// Add declaration of overridding methods.
+if (Index && Results.References.size() <= Limit &&
+!

[PATCH] D95849: [FileCheck] Default --allow-unused-prefixes to false

2021-02-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: jdoerfert, jhenderson, mtrofin.
Herald added subscribers: okura, kuter, thopre.
MaskRay requested review of this revision.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added subscribers: llvm-commits, cfe-commits, bbn.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95849

Files:
  clang/test/OpenMP/lit.local.cfg
  clang/test/lit.cfg.py
  llvm/test/FileCheck/lit.local.cfg
  llvm/test/Other/opt-bisect-legacy-pass-manager.ll
  llvm/test/Reduce/lit.local.cfg
  llvm/test/Transforms/Attributor/lit.local.cfg
  llvm/test/lit.cfg.py
  llvm/utils/FileCheck/FileCheck.cpp

Index: llvm/utils/FileCheck/FileCheck.cpp
===
--- llvm/utils/FileCheck/FileCheck.cpp
+++ llvm/utils/FileCheck/FileCheck.cpp
@@ -78,7 +78,7 @@
  "checks that some error message does not occur, for example."));
 
 static cl::opt AllowUnusedPrefixes(
-"allow-unused-prefixes", cl::init(true),
+"allow-unused-prefixes", cl::init(false),
 cl::desc("Allow prefixes to be specified but not appear in the test."));
 
 static cl::opt MatchFullLines(
Index: llvm/test/lit.cfg.py
===
--- llvm/test/lit.cfg.py
+++ llvm/test/lit.cfg.py
@@ -83,20 +83,6 @@
 return found_dylibs[0]
 
 
-
-# FIXME: remove this when we flip the default value for --allow-unused-prefixes
-# to false.
-fc = ToolSubst('FileCheck', unresolved='fatal')
-# Insert this first. Then, we'll first update the blank FileCheck command; then,
-# the default substitution of FileCheck will replace it to its full path.
-config.substitutions.insert(0, (fc.regex,
-'FileCheck --allow-unused-prefixes=false'))
-# When addressing this fixme, replace %FileCheckRaw% with just FileCheck.
-config.substitutions.append(('%FileCheckRaw%', 'FileCheck'))
-# Also remove the lit.local.cfg under llvm/test/Reduce
-# and the pertinent FIXME in llvm/test/FileCheck
-
-
 llvm_config.use_default_substitutions()
 
 # Add site-specific substitutions.
@@ -162,8 +148,8 @@
 # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
 tools.extend([
 'dsymutil', 'lli', 'lli-child-target', 'llvm-ar', 'llvm-as',
-'llvm-addr2line', 'llvm-bcanalyzer', 'llvm-bitcode-strip', 'llvm-config', 
-'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis', 
+'llvm-addr2line', 'llvm-bcanalyzer', 'llvm-bitcode-strip', 'llvm-config',
+'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis',
 'llvm-dwarfdump', 'llvm-dlltool', 'llvm-exegesis', 'llvm-extract',
 'llvm-isel-fuzzer', 'llvm-ifs',
 'llvm-install-name-tool', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
Index: llvm/test/Transforms/Attributor/lit.local.cfg
===
--- llvm/test/Transforms/Attributor/lit.local.cfg
+++ llvm/test/Transforms/Attributor/lit.local.cfg
@@ -2,10 +2,4 @@
 from lit.llvm.subst import ToolSubst
 
 fc = ToolSubst('FileCheck', unresolved='fatal')
-# the parent introduced the opposite rule, so we replace it if we see it.
-if len(config.substitutions) > 0 and config.substitutions[0] == (fc.regex, 'FileCheck --allow-unused-prefixes=false'):
-config.substitutions[0] = (
-fc.regex, 'FileCheck --allow-unused-prefixes=true')
-else:
-config.substitutions.insert(0, (fc.regex, 
-'FileCheck --allow-unused-prefixes=true'))
+config.substitutions.insert(0, (fc.regex, 'FileCheck --allow-unused-prefixes=true'))
Index: llvm/test/Reduce/lit.local.cfg
===
--- llvm/test/Reduce/lit.local.cfg
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
-# FIXME: remove this file when we flip the default for --allow-unused-prefixes.
-from lit.llvm.subst import ToolSubst
-
-fc = ToolSubst('FileCheck', unresolved='fatal')
-# the parent introduced the opposite rule, so we replace it if we see it.
-if len(config.substitutions) > 0 and config.substitutions[0] == (fc.regex, 'FileCheck --allow-unused-prefixes=false'):
-del config.substitutions[0]
Index: llvm/test/Other/opt-bisect-legacy-pass-manager.ll
===
--- llvm/test/Other/opt-bisect-legacy-pass-manager.ll
+++ llvm/test/Other/opt-bisect-legacy-pass-manager.ll
@@ -39,7 +39,7 @@
 ; f2() in f3().
 
 ; RUN: %python %S/opt-bisect-helper.py --start=0 --end=256 --optcmd=opt \
-; RUN: --filecheckcmd=%FileCheckRaw% --test=%s \
+; RUN: --filecheckcmd=FileCheck --test=%s \
 ; RUN: --prefix=CHECK-BISECT-INLINE-HELPER \
 ; RUN: | FileCheck %s --check-prefix=CHECK-BISECT-INLINE-RESULT
 ; The h

[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 320683.
usaxena95 added a comment.

Print value of new OverriddenBy flag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1706,6 +1706,10 @@
   for (const auto &R : T.ranges("decl"))
 ExpectedLocations.push_back(
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration)));
+  for (const auto &R : T.ranges("override"))
+ExpectedLocations.push_back(
+AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
+   ReferencesResult::OverriddenBy)));
   EXPECT_THAT(
   findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
   .References,
@@ -1862,7 +1866,7 @@
 checkFindRefs(Test);
 }
 
-TEST(FindReferences, IncludeOverrides) {
+TEST(FindReferences, IncludeOverrideDeclaration) {
   llvm::StringRef Test =
   R"cpp(
 class Base {
@@ -1871,10 +1875,10 @@
 };
 class Derived : public Base {
 public:
-  void [[func]]() override;
+  void $override[[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -83,6 +83,7 @@
   enum ReferenceAttributes : unsigned {
 Declaration = 1 << 0,
 Definition = 1 << 1,
+OverriddenBy = 1 << 2,
   };
   struct Reference {
 Location Loc;
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1300,7 +1300,7 @@
 return {};
   }
 
-  llvm::DenseSet IDs, Overrides;
+  llvm::DenseSet IDs, BaseMethod;
 
   const auto *IdentifierAtCursor =
   syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
@@ -1339,25 +1339,23 @@
   if (auto ID = getSymbolID(D))
 Targets.insert(ID);
 
+RelationsRequest OverriddenBy;
 if (Index) {
-  RelationsRequest FindOverrides;
-  FindOverrides.Predicate = RelationKind::OverriddenBy;
+  OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
-// Special case: virtual void meth^od() = 0 includes refs of overrides.
+// Special case: Inlcude declaration of overridding methods.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isPure())
+  if (CMD->isVirtual())
 if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location())
+  IdentifierAtCursor->location()) {
   if (auto ID = getSymbolID(CMD))
-FindOverrides.Subjects.insert(ID);
+OverriddenBy.Subjects.insert(ID);
+  for (const auto &Base : CMD->overridden_methods())
+if (auto ID = getSymbolID(Base))
+  BaseMethod.insert(ID);
+}
 }
   }
-  if (!FindOverrides.Subjects.empty())
-Index->relations(FindOverrides,
- [&](const SymbolID &Subject, const Symbol &Object) {
-   Overrides.insert(Object.ID);
- });
-  Targets.insert(Overrides.begin(), Overrides.end());
 }
 
 // We traverse the AST to find references in the main file.
@@ -1376,17 +1374,29 @@
   ReferencesResult::Reference Result;
   Result.Loc.range = Ref.range(SM);
   Result.Loc.uri = URIMainFile;
-  // Overrides are always considered references, not defs/decls.
-  if (!Overrides.contains(Ref.Target)) {
-if (Ref.Role & static_cast(index::SymbolRole::Declaration))
-  Result.Attributes |= ReferencesResult::Declaration;
-// clang-index doesn't report definitions as declarations, but they are.
-if (Ref.Role & static_cast(index::SymbolRole::Definition))
-  Result.Attributes |=
-  ReferencesResult::Definition | ReferencesResult::Declaration;
-  }
+  if (Ref.Role & static_cast(index::SymbolRole::Declaration))
+Result.Attributes |= ReferencesResult::Declaration;
+  // clang-index doesn't report definitions as declarations, but they are.
+  if (Ref.Role & static_cast(index::SymbolRole::Definition))
+

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: compiler-rt/test/profile/instrprof-gc-sections.c:30
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: diff %t.nocode.syms %t.code.syms
+

MaskRay wrote:
> This fails on my machine (cc @akuegel). If I use `diff -u`:
> 
> ```
> --- 
> /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.nocode.syms
>2021-02-01 22:14:22.850222346 -0800
> +++ 
> /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.code.syms
>  2021-02-01 22:14:22.854222358 -0800
> @@ -3,6 +3,5 @@
>  __prof_cnts_sect_data
>  __prof_data_sect_data
>  __prof_nms_sect_data
> -__prof_orderfile_sect_data
>  __prof_vnodes_sect_data
>  lprofDirMode
> ```
> 
> At the worst we can temporarily disable it (if others report issues as well).
What's your build setup? I ran `check-profile` on my Linux workstation just now 
but haven't seen this issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76802

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


[clang-tools-extra] af6be9a - [test] Fix unused FileCheck prefixes in clang-tidy and one llvm/test/Reduce test

2021-02-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-02-01T22:51:29-08:00
New Revision: af6be9a7bb0fca891ec60138608902cd37b9f84f

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

LOG: [test] Fix unused FileCheck prefixes in clang-tidy and one 
llvm/test/Reduce test

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-reverse.cpp
llvm/test/Reduce/remove-function-bodies-used-in-globals.ll

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-reverse.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-reverse.cpp
index 63da130e74c6..c82c29173604 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-reverse.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-reverse.cpp
@@ -30,6 +30,13 @@
 // RUN:   | FileCheck %s -check-prefix=CHECK-HEADER-NO-FUNC \
 // RUN:   -implicit-check-not="{{warning|error}}:"
 
+/// Suppress FileCheck --allow-unused-prefixes=false diagnostics.
+// CHECK-MESSAGES-RANGES: {{^}}
+// CHECK-MESSAGES-CUSTOM: {{^}}
+// CHECK-MESSAGES-CUSTOM-SYS: {{^}}
+// CHECK-MESSAGES-CUSTOM-NO-SYS: {{^}}
+// CHECK-MESSAGES-CUSTOM-NO-HEADER: {{^}}
+
 // CHECK-HEADER-NO-FUNC: warning: modernize-loop-convert: 
'MakeReverseRangeHeader' is set but 'MakeReverseRangeFunction' is not, 
disabling reverse loop transformation
 
 // Make sure appropiate headers are included

diff  --git a/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll 
b/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
index 6e441c231287..0832456b6bf0 100644
--- a/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
+++ b/llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
@@ -1,5 +1,5 @@
-; RUN: llvm-reduce --test FileCheck --test-arg 
--check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg 
--input-file %s -o %t
-; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
+; RUN: llvm-reduce --test FileCheck --test-arg 
--check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s 
-o %t
+; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
 
 ; We cannot change the @alias to undef, because it would result in invalid IR
 ; (Aliasee should be either GlobalValue or ConstantExpr).



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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 320680.
hoy added a comment.

Rebasing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,9 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,9 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegF

[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2021-02-01 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 320679.
hliao added a comment.

Revise comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69322

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/MangleNumberingContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/CXXABI.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ItaniumCXXABI.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGenCUDA/ms-linker-options.cu
  clang/test/CodeGenCUDA/unnamed-types.cu

Index: clang/test/CodeGenCUDA/unnamed-types.cu
===
--- clang/test/CodeGenCUDA/unnamed-types.cu
+++ clang/test/CodeGenCUDA/unnamed-types.cu
@@ -1,12 +1,17 @@
 // RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-linux-gnu -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
+// RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-pc-windows-msvc -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=MSVC
 // RUN: %clang_cc1 -std=c++11 -x hip -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm %s -o - | FileCheck %s --check-prefix=DEVICE
 
 #include "Inputs/cuda.h"
 
 // HOST: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+// HOST: @1 = private unnamed_addr constant [60 x i8] c"_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_\00", align 1
+// Check that, on MSVC, the same device kernel mangling name is generated.
+// MSVC: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+// MSVC: @1 = private unnamed_addr constant [60 x i8] c"_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_\00", align 1
 
 __device__ float d0(float x) {
-  return [](float x) { return x + 2.f; }(x);
+  return [](float x) { return x + 1.f; }(x);
 }
 
 __device__ float d1(float x) {
@@ -14,11 +19,21 @@
 }
 
 // DEVICE: amdgpu_kernel void @_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_(
+// DEVICE: define internal float @_ZZZ2f1PfENKUlS_E_clES_ENKUlfE_clEf(
 template 
 __global__ void k0(float *p, F f) {
   p[0] = f(p[0]) + d0(p[1]) + d1(p[2]);
 }
 
+// DEVICE: amdgpu_kernel void @_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_(
+// DEVICE: define internal float @_ZZ2f1PfENKUlfE_clEf(
+// DEVICE: define internal float @_ZZ2f1PfENKUlffE_clEff(
+// DEVICE: define internal float @_ZZ2f1PfENKUlfE0_clEf(
+template 
+__global__ void k1(float *p, F0 f0, F1 f1, F2 f2) {
+  p[0] = f0(p[0]) + f1(p[1], p[2]) + f2(p[3]);
+}
+
 void f0(float *p) {
   [](float *p) {
 *p = 1.f;
@@ -29,11 +44,17 @@
 // linkages are still required to keep the original `internal` linkage.
 
 // HOST: define internal void @_ZZ2f1PfENKUlS_E_clES_(
-// DEVICE: define internal float @_ZZZ2f1PfENKUlS_E_clES_ENKUlfE_clEf(
 void f1(float *p) {
   [](float *p) {
-k0<<<1,1>>>(p, [] __device__ (float x) { return x + 1.f; });
+k0<<<1,1>>>(p, [] __device__ (float x) { return x + 3.f; });
   }(p);
+  k1<<<1,1>>>(p,
+  [] __device__ (float x) { return x + 4.f; },
+  [] __device__ (float x, float y) { return x * y; },
+  [] __device__ (float x) { return x + 5.f; });
 }
 // HOST: @__hip_register_globals
 // HOST: __hipRegisterFunction{{.*}}@_Z17__device_stub__k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_{{.*}}@0
+// HOST: __hipRegisterFunction{{.*}}@_Z17__device_stub__k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_{{.*}}@1
+// MSVC: __hipRegisterFunction{{.*}}@"??$k0@V@?0???R1?0??f1@@YAXPEAM@Z@QEBA@0@Z@@@YAXPEAMV@?0???R0?0??f1@@YAX0@Z@QEBA@0@Z@@Z{{.*}}@0
+// MSVC: __hipRegisterFunction{{.*}}@"??$k1@V@?0??f1@@YAXPEAM@Z@V@?0??2@YAX0@Z@V@?0??2@YAX0@Z@@@YAXPEAMV@?0??f1@@YAX0@Z@V@?0??1@YAX0@Z@V@?0??1@YAX0@Z@@Z{{.*}}@1
Index: clang/test/CodeGenCUDA/ms-linker-options.cu
===
--- clang/test/CodeGenCUDA/ms-linker-options.cu
+++ clang/test/CodeGenCUDA/ms-linker-options.cu
@@ -2,12 +2,12 @@
 // RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
 // RUN:   | FileCheck -check-prefix=DEV %s
 // RUN: %clang_cc1 -emit-llvm -o - -fms-extensions -x hip %s -triple \
-// RUN:x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+// RUN:x86_64-pc-windows-msvc -aux-triple amdgcn | FileCheck -check-prefix=HOST %s
 // RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -fms-extensions %s \
 // RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
 // RUN:   | FileCheck -check-prefix=DEV %s
 // RUN: %clang_cc1 -emit-llvm -o - -fms-extensions %s -triple \
-// RUN:x86_64-pc-windows-

[PATCH] D68682: format::cleanupAroundReplacements removes whole line when Removals leave previously non-blank line blank

2021-02-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc updated this revision to Diff 320678.
poelmanc changed the repository for this revision from rCTE Clang Tools Extra 
to rG LLVM Github Monorepo.
poelmanc added a comment.
Herald added subscribers: dexonsmith, mgorny.

Glad to be back after a year away from clang-tidy, and sorry to have let this 
patch linger. Running clang-tidy over a large codebase shows this patch still 
to be needed. I believe I've addressed all identified issues but welcome 
feedback.

@gribozavr @gribozavr2 requested changes to a very early version of this patch 
and I later reworked it to follow the `cleanupAroundReplacements` approach he 
suggested on 2019-10-11.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68682

Files:
  clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-control-flow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-member-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
  clang/include/clang/Basic/CharInfo.h
  clang/include/clang/Format/Format.h
  clang/lib/AST/CommentLexer.cpp
  clang/lib/AST/CommentParser.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/CleanupTest.cpp

Index: clang/unittests/Format/CleanupTest.cpp
===
--- clang/unittests/Format/CleanupTest.cpp
+++ clang/unittests/Format/CleanupTest.cpp
@@ -12,6 +12,7 @@
 #include "clang/Tooling/Core/Replacement.h"
 
 #include "gtest/gtest.h"
+#include "llvm/Testing/Support/Annotations.h"
 
 using clang::tooling::ReplacementTest;
 using clang::tooling::toReplacements;
@@ -320,6 +321,11 @@
 return tooling::Replacement(FileName, Offset, Length, Text);
   }
 
+  tooling::Replacement createReplacement(llvm::Annotations::Range Range,
+ StringRef Text) {
+return createReplacement(Range.Begin, Range.End - Range.Begin, Text);
+  }
+
   tooling::Replacement createInsertion(StringRef IncludeDirective) {
 return createReplacement(UINT_MAX, 0, IncludeDirective);
   }
@@ -373,10 +379,12 @@
  "namespace C {\n"
  "namespace D { int i; }\n"
  "inline namespace E { namespace { int y; } }\n"
+ "\n"
  "int x= 0;"
  "}";
-  std::string Expected = "\n\nnamespace C {\n"
- "namespace D { int i; }\n\n"
+  std::string Expected = "\nnamespace C {\n"
+ "namespace D { int i; }\n"
+ "\n"
  "int x= 0;"
  "}";
   tooling::Replacements Replaces =
@@ -386,6 +394,104 @@
   EXPECT_EQ(Expected, formatAndApply(Code, Replaces));
 }
 
+TEST_F(CleanUpReplacementsTest, RemoveLineWhenAllNonWhitespaceRemoved) {
+  llvm::Annotations Code = "namespace A {$r1[[ // Useless comment]]\n"
+   "  $r2[[int]] $r3[[x]]\t $r4[[=]] $r5[[0;]]\t\n"
+   "  int y\t = 0;$r6[[\t]]\n"
+   "} // namespace A\n";
+  std::string Expected = "namespace A {\n"
+ "  int y\t = 0;\n"
+ "} // namespace A\n";
+  tooling::Replacements Replaces =
+  toReplacements({createReplacement(Code.range("r1"), ""),
+  createReplacement(Code.range("r2"), ""),
+  createReplacement(Code.range("r3"), ""),
+  createReplacement(Code.range("r4"), ""),
+  createReplacement(Code.range("r5"), ""),
+  createReplacement(Code.range("r6"), "")});
+
+  EXPECT_EQ(Expected, apply(Code.code(), Replaces));
+}
+
+TEST_F(CleanUpReplacementsTest, RemoveLinesWhenAllNonWhitespaceRemoved) {
+  llvm::Annotations Code = R"cpp(struct A {
+  A()
+  $r3[[:]] $r1[[f()]]$r2[[,]]
+$r4[[g()]]
+  {}
+  int f = 0;
+  int g = 0;
+};)cpp";
+  std::string Expected = R"cpp(struct A {
+  A()
+  {}
+  int f = 0;
+  int g = 0;
+};)cpp";
+  tooling::Replacements Replaces =
+  toReplacements({createReplacement(Code.range("r1"), ""),
+  createReplacement(Code.range("r2"), ""),
+  createReplacement(Code.range("r3"), ""),
+  createReplacement(Code.range("r4"), "")});
+
+  EXPECT_EQ(Expected, apply(Code.code(), Replaces));
+}
+
+TEST_F(CleanUpReplacementsTest, KeepLinesWithInsertsOrReplacesEvenIfBlank) {
+  // Not using raw string literals so newlines and spaces are clear and explicit
+  llvm::Annotations Code = "struct A {\

[PATCH] D93179: [X86] Convert fmin/fmax _mm_reduce_* intrinsics to emit llvm.reduction intrinsics (PR47506)

2021-02-01 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

Hi @RKSimon, what's the status of updating these reduce intrinsics? Is there 
any difficulty for always assigning them fast math flag? I received bug report 
for the previous change D92940 . Can we revert 
it if the problem is not easy to fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93179

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


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a subscriber: akuegel.
MaskRay added inline comments.



Comment at: compiler-rt/test/profile/instrprof-gc-sections.c:30
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: diff %t.nocode.syms %t.code.syms
+

This fails on my machine (cc @akuegel). If I use `diff -u`:

```
--- 
/tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.nocode.syms
   2021-02-01 22:14:22.850222346 -0800
+++ 
/tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.code.syms
 2021-02-01 22:14:22.854222358 -0800
@@ -3,6 +3,5 @@
 __prof_cnts_sect_data
 __prof_data_sect_data
 __prof_nms_sect_data
-__prof_orderfile_sect_data
 __prof_vnodes_sect_data
 lprofDirMode
```

At the worst we can temporarily disable it (if others report issues as well).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76802

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


[clang] 80f5395 - [test] Default clang/test to FileCheck --allow-unused-prefixes=false

2021-02-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-02-01T22:02:59-08:00
New Revision: 80f539526eec31f03aadd96753648686312b1ad1

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

LOG: [test] Default clang/test to FileCheck --allow-unused-prefixes=false

Added: 
clang/test/OpenMP/lit.local.cfg

Modified: 
clang/test/Analysis/lit.local.cfg
clang/test/lit.cfg.py

Removed: 
clang/test/CodeGen/lit.local.cfg
clang/test/CodeGenCXX/lit.local.cfg
clang/test/Driver/lit.local.cfg



diff  --git a/clang/test/Analysis/lit.local.cfg 
b/clang/test/Analysis/lit.local.cfg
index 1560848b1f75..1e8cf4c3b7c4 100644
--- a/clang/test/Analysis/lit.local.cfg
+++ b/clang/test/Analysis/lit.local.cfg
@@ -26,9 +26,3 @@ config.substitutions.append(('%normalize_sarif',
 
 if not config.root.clang_staticanalyzer:
 config.unsupported = True
-
-fc = ToolSubst('FileCheck', unresolved='fatal')
-# Insert this first. Then, we'll first update the blank FileCheck command; 
then,
-# the default substitution of FileCheck will replace it to its full path.
-config.substitutions.insert(0, (fc.regex,
-'FileCheck --allow-unused-prefixes=false'))

diff  --git a/clang/test/CodeGen/lit.local.cfg 
b/clang/test/CodeGen/lit.local.cfg
deleted file mode 100644
index c5bb8b60a52a..
--- a/clang/test/CodeGen/lit.local.cfg
+++ /dev/null
@@ -1,9 +0,0 @@
-# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
-from lit.llvm.subst import ToolSubst
-
-fc = ToolSubst('FileCheck', unresolved='fatal')
-# Insert this first. Then, we'll first update the blank FileCheck command; 
then,
-# the default substitution of FileCheck will replace it to its full path.
-config.substitutions.insert(0, (fc.regex,
-'FileCheck --allow-unused-prefixes=false'))
-

diff  --git a/clang/test/CodeGenCXX/lit.local.cfg 
b/clang/test/CodeGenCXX/lit.local.cfg
deleted file mode 100644
index c5bb8b60a52a..
--- a/clang/test/CodeGenCXX/lit.local.cfg
+++ /dev/null
@@ -1,9 +0,0 @@
-# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
-from lit.llvm.subst import ToolSubst
-
-fc = ToolSubst('FileCheck', unresolved='fatal')
-# Insert this first. Then, we'll first update the blank FileCheck command; 
then,
-# the default substitution of FileCheck will replace it to its full path.
-config.substitutions.insert(0, (fc.regex,
-'FileCheck --allow-unused-prefixes=false'))
-

diff  --git a/clang/test/Driver/lit.local.cfg b/clang/test/Driver/lit.local.cfg
deleted file mode 100644
index 7dbadaeed12f..
--- a/clang/test/Driver/lit.local.cfg
+++ /dev/null
@@ -1,26 +0,0 @@
-from lit.llvm.subst import ToolSubst
-
-fc = ToolSubst('FileCheck', unresolved='fatal')
-# Insert this first. Then, we'll first update the blank FileCheck command; 
then,
-# the default substitution of FileCheck will replace it to its full path.
-config.substitutions.insert(0, (fc.regex,
-'FileCheck --allow-unused-prefixes=false'))
-
-config.suffixes = ['.c', '.cpp', '.h', '.m', '.mm', '.S', '.s', '.f90', 
'.F90', '.f95',
-   '.cu', '.rs', '.cl', '.hip']
-config.substitutions = list(config.substitutions)
-config.substitutions.insert(0,
-('%clang_cc1',
- """*** Do not use 'clang -cc1' in Driver tests. ***""") )
-
-# Remove harmful environmental variables for clang Driver tests.
-# Some might be useful for other tests so they are only removed here.
-driver_overwrite_env_vars = ['MACOSX_DEPLOYMENT_TARGET',
- 'IPHONEOS_DEPLOYMENT_TARGET',
- 'SDKROOT', 'CCC_OVERRIDE_OPTIONS',
- 'CC_PRINT_OPTIONS', 'CC_PRINT_HEADERS',
- 'CC_LOG_DIAGNOSTICS']
-
-for name in driver_overwrite_env_vars:
-  if name in config.environment:
-del config.environment[name]

diff  --git a/clang/test/OpenMP/lit.local.cfg b/clang/test/OpenMP/lit.local.cfg
new file mode 100644
index ..ac72c2de9777
--- /dev/null
+++ b/clang/test/OpenMP/lit.local.cfg
@@ -0,0 +1,10 @@
+# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
+from lit.llvm.subst import ToolSubst
+
+fc = ToolSubst('FileCheck', unresolved='fatal')
+# the parent introduced the opposite rule, so we replace it if we see it.
+if len(config.substitutions) > 0 and config.substitutions[0] == (fc.regex, 
'FileCheck --allow-unused-prefixes=false'):
+config.substitutions[0] = (
+fc.regex, 'FileCheck --allow-unused-prefixes=true')
+else:
+config.substitutions.insert(0, (fc.regex, 'FileCheck 
--allow-unused-prefixes=true'))

diff  --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 863ab444fb02..a47ebe74ddba 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -43,6 +43,14 @@
 
 llvm_config.use_clang()
 
+# FIXME: remove this when we flip the default val

[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 added a comment.

In D95812#2535077 , @sammccall wrote:

> This looks about right to me...
> Unfortunately I landed ff4832dbff0ccf1fd29f726efe72fd1220cd645a 
>  and 
> 1eb7fd089e2fcf3fe211f865b28e2fed12128c3f 
>  
> meanwhile so this will need a rebase :-(
>
> The first of those patches introduces flags on returned refs to indicate 
> which are decls/defs. I'd suggest adding an "override" flag and populating it 
> for these results.

Thanks.

> (I guess the bug includes the other side of this, where if the method is an 
> override, calls to base methods are reported. Makes sense to split it into a 
> separate patch...)

Yes. I plan to do that in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

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


[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 320673.
usaxena95 added a comment.

Rebase + Add OverriddenBy flag for such references.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1706,6 +1706,10 @@
   for (const auto &R : T.ranges("decl"))
 ExpectedLocations.push_back(
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration)));
+  for (const auto &R : T.ranges("override"))
+ExpectedLocations.push_back(
+AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
+   ReferencesResult::OverriddenBy)));
   EXPECT_THAT(
   findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
   .References,
@@ -1862,7 +1866,7 @@
 checkFindRefs(Test);
 }
 
-TEST(FindReferences, IncludeOverrides) {
+TEST(FindReferences, IncludeOverrideDeclaration) {
   llvm::StringRef Test =
   R"cpp(
 class Base {
@@ -1871,10 +1875,10 @@
 };
 class Derived : public Base {
 public:
-  void [[func]]() override;
+  void $override[[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -83,6 +83,7 @@
   enum ReferenceAttributes : unsigned {
 Declaration = 1 << 0,
 Definition = 1 << 1,
+OverriddenBy = 1 << 2,
   };
   struct Reference {
 Location Loc;
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1300,7 +1300,7 @@
 return {};
   }
 
-  llvm::DenseSet IDs, Overrides;
+  llvm::DenseSet IDs;
 
   const auto *IdentifierAtCursor =
   syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
@@ -1339,25 +1339,19 @@
   if (auto ID = getSymbolID(D))
 Targets.insert(ID);
 
+RelationsRequest OverriddenBy;
 if (Index) {
-  RelationsRequest FindOverrides;
-  FindOverrides.Predicate = RelationKind::OverriddenBy;
+  OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
-// Special case: virtual void meth^od() = 0 includes refs of overrides.
+// Special case: Inlcude declaration of overridding methods.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isPure())
+  if (CMD->isVirtual())
 if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
   IdentifierAtCursor->location())
   if (auto ID = getSymbolID(CMD))
-FindOverrides.Subjects.insert(ID);
+OverriddenBy.Subjects.insert(ID);
 }
   }
-  if (!FindOverrides.Subjects.empty())
-Index->relations(FindOverrides,
- [&](const SymbolID &Subject, const Symbol &Object) {
-   Overrides.insert(Object.ID);
- });
-  Targets.insert(Overrides.begin(), Overrides.end());
 }
 
 // We traverse the AST to find references in the main file.
@@ -1376,17 +1370,29 @@
   ReferencesResult::Reference Result;
   Result.Loc.range = Ref.range(SM);
   Result.Loc.uri = URIMainFile;
-  // Overrides are always considered references, not defs/decls.
-  if (!Overrides.contains(Ref.Target)) {
-if (Ref.Role & static_cast(index::SymbolRole::Declaration))
-  Result.Attributes |= ReferencesResult::Declaration;
-// clang-index doesn't report definitions as declarations, but they are.
-if (Ref.Role & static_cast(index::SymbolRole::Definition))
-  Result.Attributes |=
-  ReferencesResult::Definition | ReferencesResult::Declaration;
-  }
+  if (Ref.Role & static_cast(index::SymbolRole::Declaration))
+Result.Attributes |= ReferencesResult::Declaration;
+  // clang-index doesn't report definitions as declarations, but they are.
+  if (Ref.Role & static_cast(index::SymbolRole::Definition))
+Result.Attributes |=
+ReferencesResult::Definition | ReferencesResult::Declaration;
   Results.References.push_back(std::move(Result));
 }
+// Add declaration of overridding methods.
+if (Index && Results.References.size

[PATCH] D95608: [OpenCL][PR48896] Fix address space in binding of initializer lists to references

2021-02-01 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, LGTM with the value-kind fix.




Comment at: clang/lib/Sema/SemaInit.cpp:4308
+  if (T1Quals.hasAddressSpace())
+Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+} else

Anastasia wrote:
> rjmccall wrote:
> > This should only be `VK_XValue` if we're binding a r-value reference, I 
> > think.
> Yes, I think so too.
Did you mean to fix this to conditionally use VK_LValue?


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

https://reviews.llvm.org/D95608

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


[PATCH] D95725: clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)

2021-02-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b70c86e2007: clang-extra: fix incorrect use of 
std::lock_guard by adding variable name… (authored by poelmanc, committed by 
kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95725

Files:
  clang-tools-extra/clangd/support/Function.h


Index: clang-tools-extra/clangd/support/Function.h
===
--- clang-tools-extra/clangd/support/Function.h
+++ clang-tools-extra/clangd/support/Function.h
@@ -51,7 +51,7 @@
 Subscription &operator=(Subscription &&Other) {
   // If *this is active, unsubscribe.
   if (Parent) {
-std::lock_guard(Parent->ListenersMu);
+std::lock_guard Lock(Parent->ListenersMu);
 llvm::erase_if(Parent->Listeners,
[&](const std::pair &P) {
  return P.second == ListenerID;


Index: clang-tools-extra/clangd/support/Function.h
===
--- clang-tools-extra/clangd/support/Function.h
+++ clang-tools-extra/clangd/support/Function.h
@@ -51,7 +51,7 @@
 Subscription &operator=(Subscription &&Other) {
   // If *this is active, unsubscribe.
   if (Parent) {
-std::lock_guard(Parent->ListenersMu);
+std::lock_guard Lock(Parent->ListenersMu);
 llvm::erase_if(Parent->Listeners,
[&](const std::pair &P) {
  return P.second == ListenerID;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 0b70c86 - clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)

2021-02-01 Thread Kadir Cetinkaya via cfe-commits

Author: Conrad Poelman
Date: 2021-02-02T06:02:59+01:00
New Revision: 0b70c86e2007d3f32968f0a7d9efe8eab3bf0f0a

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

LOG: clang-extra: fix incorrect use of std::lock_guard by adding variable name 
(identified by MSVC [[nodiscard]] error)

`std::lock_guard` is an RAII class that needs a variable name whose scope 
determines the guard's lifetime. This particular usage lacked a variable name, 
meaning the guard could be destroyed before the line that it was indented to 
protect.

This line was identified by building clang with the latest MSVC preview 
release, which declares the std::lock_guard constructor to be `[[nodiscard]]` 
to draw attention to such issues.

Reviewed By: kadircet

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

Added: 


Modified: 
clang-tools-extra/clangd/support/Function.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Function.h 
b/clang-tools-extra/clangd/support/Function.h
index 2cac1b1e7f67..936800d56985 100644
--- a/clang-tools-extra/clangd/support/Function.h
+++ b/clang-tools-extra/clangd/support/Function.h
@@ -51,7 +51,7 @@ template  class Event {
 Subscription &operator=(Subscription &&Other) {
   // If *this is active, unsubscribe.
   if (Parent) {
-std::lock_guard(Parent->ListenersMu);
+std::lock_guard Lock(Parent->ListenersMu);
 llvm::erase_if(Parent->Listeners,
[&](const std::pair &P) {
  return P.second == ListenerID;



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


[PATCH] D94844: [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.

2021-02-01 Thread Nathan Hawes 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 rGecb00a77624c: [VFS] Add support to RedirectingFileSystem for 
mapping a virtual directory to… (authored by nathawes).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94844

Files:
  clang/test/VFS/Inputs/vfsoverlay-directory-relative.yaml
  clang/test/VFS/Inputs/vfsoverlay-directory.yaml
  clang/test/VFS/directory.c
  lldb/source/Host/common/FileSystem.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp

Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -1328,6 +1328,7 @@
 
 TEST_F(VFSFromYAMLTest, MappedFiles) {
   IntrusiveRefCntPtr Lower(new DummyFileSystem());
+  Lower->addDirectory("//root/foo/bar");
   Lower->addRegularFile("//root/foo/bar/a");
   IntrusiveRefCntPtr FS = getFromYAMLString(
   "{ 'roots': [\n"
@@ -1343,6 +1344,17 @@
   "  'type': 'file',\n"
   "  'name': 'file2',\n"
   "  'external-contents': '//root/foo/b'\n"
+  "},\n"
+  "{\n"
+  "  'type': 'directory-remap',\n"
+  "  'name': 'mappeddir',\n"
+  "  'external-contents': '//root/foo/bar'\n"
+  "},\n"
+  "{\n"
+  "  'type': 'directory-remap',\n"
+  "  'name': 'mappeddir2',\n"
+  "  'use-external-name': false,\n"
+  "  'external-contents': '//root/foo/bar'\n"
   "}\n"
   "  ]\n"
   "}\n"
@@ -1380,12 +1392,221 @@
   EXPECT_TRUE(S->isDirectory());
   EXPECT_TRUE(S->equivalent(*O->status("//root/"))); // non-volatile UniqueID
 
+  // remapped directory
+  S = O->status("//root/mappeddir");
+  ASSERT_FALSE(S.getError());
+  EXPECT_TRUE(S->isDirectory());
+  EXPECT_TRUE(S->IsVFSMapped);
+  EXPECT_TRUE(S->equivalent(*O->status("//root/foo/bar")));
+
+  SLower = O->status("//root/foo/bar");
+  EXPECT_EQ("//root/foo/bar", SLower->getName());
+  EXPECT_TRUE(S->equivalent(*SLower));
+  EXPECT_FALSE(SLower->IsVFSMapped);
+
+  // file in remapped directory
+  S = O->status("//root/mappeddir/a");
+  ASSERT_FALSE(S.getError());
+  ASSERT_FALSE(S->isDirectory());
+  ASSERT_TRUE(S->IsVFSMapped);
+  ASSERT_EQ("//root/foo/bar/a", S->getName());
+
+  // file in remapped directory, with use-external-name=false
+  S = O->status("//root/mappeddir2/a");
+  ASSERT_FALSE(S.getError());
+  ASSERT_FALSE(S->isDirectory());
+  ASSERT_TRUE(S->IsVFSMapped);
+  ASSERT_EQ("//root/mappeddir2/a", S->getName());
+
+  // file contents in remapped directory
+  OpenedF = O->openFileForRead("//root/mappeddir/a");
+  ASSERT_FALSE(OpenedF.getError());
+  OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("//root/foo/bar/a", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
+  // file contents in remapped directory, with use-external-name=false
+  OpenedF = O->openFileForRead("//root/mappeddir2/a");
+  ASSERT_FALSE(OpenedF.getError());
+  OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("//root/mappeddir2/a", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
   // broken mapping
   EXPECT_EQ(O->status("//root/file2").getError(),
 llvm::errc::no_such_file_or_directory);
   EXPECT_EQ(0, NumDiagnostics);
 }
 
+TEST_F(VFSFromYAMLTest, MappedRoot) {
+  IntrusiveRefCntPtr Lower(new DummyFileSystem());
+  Lower->addDirectory("//root/foo/bar");
+  Lower->addRegularFile("//root/foo/bar/a");
+  IntrusiveRefCntPtr FS =
+  getFromYAMLString("{ 'roots': [\n"
+"{\n"
+"  'type': 'directory-remap',\n"
+"  'name': '//mappedroot/',\n"
+"  'external-contents': '//root/foo/bar'\n"
+"}\n"
+"]\n"
+"}",
+Lower);
+  ASSERT_TRUE(FS.get() != nullptr);
+
+  IntrusiveRefCntPtr O(
+  new vfs::OverlayFileSystem(Lower));
+  O->pushOverlay(FS);
+
+  // file
+  ErrorOr S = O->status("//mappedroot/a");
+  ASSERT_FALSE(S.getError());
+  EXPECT_EQ("//root/foo/bar/a", S->getName());
+  EXPECT_TRUE(S->IsVFSMapped);
+
+  ErrorOr SLower = O->status("//root/foo/bar/a");
+  EXPECT_EQ("//root/foo/bar/a", SLower->getName());
+  EXPECT_TRUE(S->equivalent(*SLower));
+  EXPECT_FALSE(SLower->IsVFSMapped);
+
+  // file after opening
+  auto OpenedF = O->openFileForRead("//mappedroot/a");
+  ASSERT_FALSE(OpenedF.getError

[clang] ecb00a7 - [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.

2021-02-01 Thread Nathan Hawes via cfe-commits

Author: Nathan Hawes
Date: 2021-02-02T14:56:17+10:00
New Revision: ecb00a77624c94ce38fccf9b4095e026ecf14aed

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

LOG: [VFS] Add support to RedirectingFileSystem for mapping a virtual directory 
to one in the external FS.

Previously file entries in the -ivfsoverlay yaml could map to a file in the
external file system, but directories had to list their contents in the form of
other file entries or directories. Allowing directory entries to map to a
directory in the external file system makes it possible to present an external
directory's contents in a different location and (in combination with the
'fallthrough' option) overlay one directory's contents on top of another.

rdar://problem/72485443
Differential Revision: https://reviews.llvm.org/D94844

Added: 
clang/test/VFS/Inputs/vfsoverlay-directory-relative.yaml
clang/test/VFS/Inputs/vfsoverlay-directory.yaml
clang/test/VFS/directory.c

Modified: 
lldb/source/Host/common/FileSystem.cpp
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/VirtualFileSystem.cpp
llvm/unittests/Support/VirtualFileSystemTest.cpp

Removed: 




diff  --git a/clang/test/VFS/Inputs/vfsoverlay-directory-relative.yaml 
b/clang/test/VFS/Inputs/vfsoverlay-directory-relative.yaml
new file mode 100644
index ..635460a4a9b0
--- /dev/null
+++ b/clang/test/VFS/Inputs/vfsoverlay-directory-relative.yaml
@@ -0,0 +1,11 @@
+{
+  'version': 0,
+  'fallthrough': true,
+  'overlay-relative': true,
+  'roots': [
+{ 'name': 'OUT_DIR',
+  'type': 'directory-remap',
+  'external-contents': 'INPUT_DIR'
+}
+  ]
+}

diff  --git a/clang/test/VFS/Inputs/vfsoverlay-directory.yaml 
b/clang/test/VFS/Inputs/vfsoverlay-directory.yaml
new file mode 100644
index ..d8a283ee3f19
--- /dev/null
+++ b/clang/test/VFS/Inputs/vfsoverlay-directory.yaml
@@ -0,0 +1,10 @@
+{
+  'version': 0,
+  'fallthrough': true,
+  'roots': [
+{ 'name': 'OUT_DIR',
+  'type': 'directory-remap',
+  'external-contents': 'INPUT_DIR'
+}
+  ]
+}

diff  --git a/clang/test/VFS/directory.c b/clang/test/VFS/directory.c
new file mode 100644
index ..b850ace54c93
--- /dev/null
+++ b/clang/test/VFS/directory.c
@@ -0,0 +1,48 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/Underlying
+// RUN: mkdir -p %t/Overlay
+// RUN: mkdir -p %t/Middle
+// RUN: echo '// B.h in Underlying' > %t/Underlying/B.h
+// RUN: echo '#ifdef NESTED' >> %t/Underlying/B.h
+// RUN: echo '#include "C.h"' >> %t/Underlying/B.h
+// RUN: echo '#endif' >> %t/Underlying/B.h
+// RUN: echo '// C.h in Underlying' > %t/Underlying/C.h
+// RUN: echo '// C.h in Middle' > %t/Middle/C.h
+// RUN: echo '// C.h in Overlay' > %t/Overlay/C.h
+
+// 1) Underlying -> Overlay (C.h found, B.h falling back to Underlying)
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}/Overlay@g" -e 
"s@OUT_DIR@%{/t:regex_replacement}/Underlying@g" 
%S/Inputs/vfsoverlay-directory.yaml > %t/vfs.yaml
+// RUN: %clang_cc1 -Werror -I %t/Underlying -ivfsoverlay %t/vfs.yaml 
-fsyntax-only -E -C %s 2>&1 | FileCheck --check-prefix=DIRECT %s
+// RUN: %clang_cc1 -Werror -I %t/Underlying -ivfsoverlay %t/vfs.yaml 
-fsyntax-only -DNESTED -E -C %s 2>&1 | FileCheck --check-prefix=DIRECT %s
+// RUN: sed -e "s@INPUT_DIR@Overlay@g" -e 
"s@OUT_DIR@%{/t:regex_replacement}/Underlying@g" 
%S/Inputs/vfsoverlay-directory-relative.yaml > %t/vfs-relative.yaml
+// RUN: %clang_cc1 -Werror -I %t/Underlying -ivfsoverlay %t/vfs-relative.yaml 
-fsyntax-only -E -C %s 2>&1 | FileCheck --check-prefix=DIRECT %s
+
+// DIRECT: {{^}}// B.h in Underlying
+// DIRECT: {{^}}// C.h in Overlay
+
+// 2) Underlying -> Middle -> Overlay (C.h found, B.h falling back to 
Underlying)
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}/Overlay@g" -e 
"s@OUT_DIR@%{/t:regex_replacement}/Middle@g" 
%S/Inputs/vfsoverlay-directory.yaml > %t/vfs.yaml
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}/Middle@g" -e 
"s@OUT_DIR@%{/t:regex_replacement}/Underlying@g" 
%S/Inputs/vfsoverlay-directory.yaml > %t/vfs2.yaml
+// RUN: %clang_cc1 -Werror -I %t/Underlying -ivfsoverlay %t/vfs.yaml 
-ivfsoverlay %t/vfs2.yaml -fsyntax-only -E -C %s 2>&1 | FileCheck 
--check-prefix=DIRECT %s
+// RUN: %clang_cc1 -Werror -I %t/Underlying -ivfsoverlay %t/vfs.yaml 
-ivfsoverlay %t/vfs2.yaml -DNESTED -fsyntax-only -E -C %s 2>&1 | FileCheck 
--check-prefix=DIRECT %s
+
+// Same as direct above
+
+// 3) Underlying -> Middle -> Overlay (C.h falling back to Middle, B.h falling 
back to Underlying)
+// RUN: rm -f %t/Overlay/C.h
+// RUN: %clang_cc1 -Werror -I %t/Underlying -ivfsoverlay %t/vfs.yaml 
-ivfsoverlay %t/vfs2.yaml -fsyntax-only -E -C %s 2>&1 | FileCheck 
--check-prefix=FALLBACK %s
+
+// FALLBACK: {{^}}// B.h in Underlying
+// FALLBA

[PATCH] D95793: [clang][cli] Generate and round-trip language options

2021-02-01 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1196
 const std::vector &Sanitizers,
 DiagnosticsEngine &Diags, SanitizerSet &S) {
+  bool Success = true;

Can the caller use `Diags.hasErrorOccurred()` to avoid this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95793

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


[PATCH] D95792: [clang][cli] Report result of ParseLangArgs

2021-02-01 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3096
+
+  return Success;
 }

Would this avoid the changes above?
```
return Success && !Diags.hasErrorOccurred();
```
?

Alternatively, might it be cleaner to shove the `Success = false` into a helper 
lambda or something?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95792

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


[PATCH] D95846: [analyzer] Updated comments to reflect D85817

2021-02-01 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD created this revision.
RedDocMD added reviewers: NoQ, vsavchenko.
Herald added subscribers: steakhal, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
RedDocMD requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed DeclaratorDecl in comment to NamedDecl


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95846

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -511,10 +511,10 @@
 /// This value is qualified as NonLoc because neither loading nor storing
 /// operations are applied to it. Instead, the analyzer uses the L-value coming
 /// from pointer-to-member applied to an object.
-/// This SVal is represented by a DeclaratorDecl which can be a member function
-/// pointer or a member data pointer and a list of CXXBaseSpecifiers. This list
-/// is required to accumulate the pointer-to-member cast history to figure out
-/// the correct subobject field.
+/// This SVal is represented by a NamedDecl which can be a member function
+/// pointer or a member data pointer and an optional list of CXXBaseSpecifiers.
+/// This list is required to accumulate the pointer-to-member cast history to
+/// figure out the correct subobject field.
 class PointerToMember : public NonLoc {
   friend class ento::SValBuilder;
 


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -511,10 +511,10 @@
 /// This value is qualified as NonLoc because neither loading nor storing
 /// operations are applied to it. Instead, the analyzer uses the L-value coming
 /// from pointer-to-member applied to an object.
-/// This SVal is represented by a DeclaratorDecl which can be a member function
-/// pointer or a member data pointer and a list of CXXBaseSpecifiers. This list
-/// is required to accumulate the pointer-to-member cast history to figure out
-/// the correct subobject field.
+/// This SVal is represented by a NamedDecl which can be a member function
+/// pointer or a member data pointer and an optional list of CXXBaseSpecifiers.
+/// This list is required to accumulate the pointer-to-member cast history to
+/// figure out the correct subobject field.
 class PointerToMember : public NonLoc {
   friend class ento::SValBuilder;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95845: [ObjC] Add a command line flag that disables recognition of objc_direct for testability

2021-02-01 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: arphaman, MadCoder, rjmccall.
Herald added subscribers: dexonsmith, dang, ributzka, jkorous.
Herald added a reviewer: jansvoboda11.
erik.pilkington requested review of this revision.

Programmers would like to be able to test direct methods by calling them from a 
different linkage unit or mocking them, both of which are  impossible. This 
patch adds a flag that effectively disables the attribute, which will fix this 
when enabled in testable builds.

rdar://71190891


https://reviews.llvm.org/D95845

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenObjC/disable-direct-method.m
  clang/test/Driver/clang_f_opts.c


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -568,3 +568,8 @@
 
 // RUN: %clang -### -S -fno-temp-file %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-TEMP-FILE %s
 // CHECK-NO-TEMP-FILE: "-fno-temp-file"
+
+// RUN: %clang -### -xobjective-c -fobjc-disable-direct-methods-for-testing %s 
2>&1 | FileCheck -check-prefix=CHECK_DISABLE_DIRECT %s
+// RUN: %clang -### -xobjective-c %s 2>&1 | FileCheck 
-check-prefix=CHECK_NO_DISABLE_DIRECT %s
+// CHECK_DISABLE_DIRECT: -fobjc-disable-direct-methods-for-testing
+// CHECK_NO_DISABLE_DIRECT-NOT: -fobjc-disable-direct-methods-for-testing
Index: clang/test/CodeGenObjC/disable-direct-method.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/disable-direct-method.m
@@ -0,0 +1,11 @@
+// _RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 
-fobjc-disable-direct-methods-for-testing %s -o - | FileCheck %s
+
+@interface X
+-(void)m __attribute__((objc_direct));
+@end
+
+void f(X *x) {
+  [x m];
+
+  // CHECK: call void bitcast ({{.*}} @objc_msgSend to {{.*}})
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2350,6 +2350,9 @@
 if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime))
   Opts.ObjCSubscriptingLegacyRuntime =
 (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX);
+
+if (Args.hasArg(OPT_fobjc_disable_direct_methods_for_testing))
+  Opts.ObjCDisableDirectMethodsForTesting = true;
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3600,6 +3600,9 @@
   WeakArg->render(Args, CmdArgs);
 }
   }
+
+  if (Args.hasArg(options::OPT_fobjc_disable_direct_methods_for_testing))
+CmdArgs.push_back("-fobjc-disable-direct-methods-for-testing");
 }
 
 static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args,
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -826,7 +826,8 @@
 }
 
 bool ObjCMethodDecl::isDirectMethod() const {
-  return hasAttr();
+  return hasAttr() &&
+ !getASTContext().getLangOpts().ObjCDisableDirectMethodsForTesting;
 }
 
 bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2135,6 +2135,11 @@
 def fno_objc_nonfragile_abi : Flag<["-"], "fno-objc-nonfragile-abi">, 
Group;
 
 def fobjc_sender_dependent_dispatch : Flag<["-"], 
"fobjc-sender-dependent-dispatch">, Group;
+def fobjc_disable_direct_methods_for_testing :
+  Flag<["-"], "fobjc-disable-direct-methods-for-testing">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Ignore attribute objc_direct so that direct methods can be 
tested">;
+
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group;
 def fopenmp : Flag<["-"], "fopenmp">, Group, Flags<[CC1Option, 
NoArgumentUnused]>,
   HelpText<"Parse OpenMP pragmas and generate parallel code.">,
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -292,6 +292,8 @@
 BENIGN_LANGOPT(CompatibilityQualifiedIdBlockParamTypeChecking, 1, 0,
"compatibility mode for type checking block parameters "
"involving qualified id types")
+LANGOPT(ObjCDisableDirectMethodsForTesting, 1, 0,
+"Disable recognition of objc_direct methods")
 LANGOPT(CFProtection

[clang] 98768ba - [test] Fix unuses FileCheck prefixes in clang/test/Modules

2021-02-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-02-01T19:46:23-08:00
New Revision: 98768bab19b27db71f497b0e5d87dfa9e5a0f05a

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

LOG: [test] Fix unuses FileCheck prefixes in clang/test/Modules

Added: 


Modified: 
clang/test/Modules/codegen.test
clang/test/Modules/preprocess-nested.cpp

Removed: 




diff  --git a/clang/test/Modules/codegen.test b/clang/test/Modules/codegen.test
index 2d20b078a753..9d0aea502cc9 100644
--- a/clang/test/Modules/codegen.test
+++ b/clang/test/Modules/codegen.test
@@ -18,8 +18,7 @@ was implemented to workaround/support the initialization of 
iostreams
 (implemented as a namespace scope static in the header - only to be provided
 when that specific header is included in the program).
 
-FOO: module asm "narf"
-USE: module asm "narf"
+BOTH: module asm "narf"
 
 FOO: $_Z2f1PKcz = comdat any
 FOO: $_ZN13implicit_dtorD1Ev = comdat any

diff  --git a/clang/test/Modules/preprocess-nested.cpp 
b/clang/test/Modules/preprocess-nested.cpp
index f26b65507ece..507514ce54cd 100644
--- a/clang/test/Modules/preprocess-nested.cpp
+++ b/clang/test/Modules/preprocess-nested.cpp
@@ -29,7 +29,12 @@
 // CHECK:   }
 // CHECK: }
 
+// NO-REWRITE-NOT: #include
+// REWRITE: #include "a.h"
+
 // CHECK: #pragma clang module begin nested.a
+// NO-REWRITE-NOT: #include
+// REWRITE: #include "c.h"
 // CHECK: #pragma clang module begin nested.c
 // CHECK: using T = int;
 // CHECK: #pragma clang module end



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


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

2021-02-01 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

We could run another pass to clean up the IR after inlining, but I think it's 
better to do the cleanup right after the callee function is cloned in the 
caller function.




Comment at: llvm/include/llvm/IR/Intrinsics.td:449
 [llvm_vararg_ty]>;
+def int_objc_clang_arc_noop_use : Intrinsic<[],
+[llvm_vararg_ty],

fhahn wrote:
> Can this be a `DefaultAttrIntrinsics` (which adds ` nofree nosync nounwind 
> willreturn`)?
> 
> Same probably for all/most objc_* intrinsics.
I'll change the other intrinsics in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


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

2021-02-01 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 320663.
ahatanak marked 4 inline comments as done.
ahatanak added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenObjC/arc-rv-attr.m
  clang/test/CodeGenObjC/arc-unsafeclaim.m
  llvm/include/llvm/Analysis/ObjCARCUtil.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/LLVMContext.h
  llvm/lib/Analysis/ObjCARCInstKind.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/LLVMContext.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
  llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARC.h
  llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.h
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
  llvm/test/CodeGen/AArch64/call-rv-marker.ll
  llvm/test/Transforms/DeadArgElim/deadretval.ll
  llvm/test/Transforms/Inline/inline-retainRV-call.ll
  llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
  llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
  llvm/test/Transforms/ObjCARC/contract.ll
  llvm/test/Transforms/ObjCARC/intrinsic-use.ll
  llvm/test/Transforms/ObjCARC/rv.ll
  llvm/test/Transforms/TailCallElim/deopt-bundle.ll
  llvm/test/Transforms/TailCallElim/operand-bundles.ll

Index: llvm/test/Transforms/TailCallElim/operand-bundles.ll
===
--- llvm/test/Transforms/TailCallElim/operand-bundles.ll
+++ llvm/test/Transforms/TailCallElim/operand-bundles.ll
@@ -55,3 +55,13 @@
 exit:
   ret void
 }
+
+; CHECK-LABEL: @test_clang_arc_rv(
+; CHECK: tail call i8* @getObj(
+
+declare i8* @getObj()
+
+define i8* @test_clang_arc_rv() {
+  %r = call i8* @getObj() [ "clang.arc.rv"(i64 0) ]
+  ret i8* %r
+}
Index: llvm/test/Transforms/ObjCARC/rv.ll
===
--- llvm/test/Transforms/ObjCARC/rv.ll
+++ llvm/test/Transforms/ObjCARC/rv.ll
@@ -452,6 +452,29 @@
   ret i8* %v3
 }
 
+; Remove operand bundle "clang.arc.rv" and the autoreleaseRV call if the call
+; is a tail call.
+
+; CHECK-LABEL: define i8* @test31(
+; CHECK: %[[CALL:.*]] = tail call i8* @returner()
+; CHECK: ret i8* %[[CALL]]
+
+define i8* @test31() {
+  %call = tail call i8* @returner() [ "clang.arc.rv"(i64 0) ]
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
+; CHECK-LABEL: define i8* @test32(
+; CHECK: %[[CALL:.*]] = call i8* @returner() [ "clang.arc.rv"(i64 0) ]
+; CHECK: call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[CALL]])
+
+define i8* @test32() {
+  %call = call i8* @returner() [ "clang.arc.rv"(i64 0) ]
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
 !0 = !{}
 
 ; CHECK: attributes [[NUW]] = { nounwind }
Index: llvm/test/Transforms/ObjCARC/intrinsic-use.ll
===
--- llvm/test/Transforms/ObjCARC/intrinsic-use.ll
+++ llvm/test/Transforms/ObjCARC/intrinsic-use.ll
@@ -8,8 +8,10 @@
 declare i8* @llvm.objc.autorelease(i8*)
 
 declare void @llvm.objc.clang.arc.use(...)
+declare void @llvm.objc.clang.arc.noop.use(...)
 
 declare void @test0_helper(i8*, i8**)
+declare void @can_release(i8*)
 
 ; Ensure that we honor clang.arc.use as a use and don't miscompile
 ; the reduced test case from .
@@ -108,6 +110,21 @@
   ret void
 }
 
+; ARC optimizer should be able to safely remove the retain/release pair as the
+; call to @llvm.objc.clang.arc.noop.use is a no-op.
+
+; CHECK-LABEL: define void @test_arc_noop_use(
+; CHECK-NEXT:call void @can_release(i8* %x)
+; CHECK-NEXT:call void (...) @llvm.objc.clang.arc.noop.use(
+; CHECK-NEXT:ret void
+
+define void @test_arc_noop_use(i8** %out, i8* %x) {
+  call i8* @llvm.objc.retain(i8* %x)
+  call void @can_release(i8* %x)
+  call void (...) @llvm.objc.clang.arc.noop.use(i8* %x)
+  call void @llvm.objc.release(i8* %x), !clang.imprecise_release !0
+  ret void
+}
 
 !0 = !{}
 
Index: llvm/test/Transforms/ObjCARC/contract.ll
===
--- llvm/test/Transforms/ObjCARC/contract.ll
+++ llvm/test/Transforms/ObjCARC/contract.ll
@@ -227,7 +227,15 @@
   ret void
 }
 
+; CHECK-LABEL: define void @test14(
+; CHECK-NOT: clang.arc.noop.use
+; CHECK: ret void
+define void @test14(i8* %a, i8* %b) {
+  call void (...) @llvm.objc.clang.arc.noop.use(i8* %a, i8* %b) nounwind
+  ret void
+}
 
 declare void 

[PATCH] D94973: [clang][OpenMP] Use OpenMPIRBuilder for workshare loops.

2021-02-01 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94973

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


[PATCH] D95842: [NFC] Remove unused prefixes under clang/test/OpenMP

2021-02-01 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin created this revision.
mtrofin added a reviewer: jdoerfert.
Herald added subscribers: guansong, yaxunl.
mtrofin requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The full list of pertinent tests is larger, so chunking the changes.
This is the first such chunk.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95842

Files:
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/declare_reduction_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c

Index: clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
===
--- clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
+++ clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix=ALL
 //  %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o /tmp/t1 %s
 //  %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch /tmp/t1 -verify %s -emit-llvm -o - | FileCheck --check-prefixes=ALL-DEBUG,IRBUILDER-DEBUG %s
 
@@ -12,10 +12,10 @@
 
 // ALL-LABEL: @_Z17nested_parallel_0v(
 // ALL-NEXT:  entry:
-// ALL-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1)
+// ALL-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* [[GLOB1:@.*]])
 // ALL-NEXT:br label [[OMP_PARALLEL:%.*]]
 // ALL:   omp_parallel:
-// ALL-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @1, i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @_Z17nested_parallel_0v..omp_par.1 to void (i32*, i32*, ...)*))
+// ALL-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @_Z17nested_parallel_0v..omp_par.1 to void (i32*, i32*, ...)*))
 // ALL-NEXT:br label [[OMP_PAR_OUTLINED_EXIT12:%.*]]
 // ALL:   omp.par.outlined.exit12:
 // ALL-NEXT:br label [[OMP_PAR_EXIT_SPLIT:%.*]]
@@ -39,10 +39,10 @@
 // ALL-NEXT:store float* [[R:%.*]], float** [[R_ADDR]], align 8
 // ALL-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
 // ALL-NEXT:store double [[B:%.*]], double* [[B_ADDR]], align 8
-// ALL-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1)
+// ALL-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* [[GLOB1]])
 // ALL-NEXT:br label [[OMP_PARALLEL:%.*]]
 // ALL:   omp_parallel:
-// ALL-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @1, i32 3, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*, double*, float**)* @_Z17nested_parallel_1Pfid..omp_par.2 to void (i32*, i32*, ...)*), i32* [[A_ADDR]], double* [[B_ADDR]], float** [[R_ADDR]])
+// ALL-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[GLOB1]], i32 3, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*, double*, float**)* @_Z17nested_parallel_1Pfid..omp_par.2 to void (i32*, i32*, ...)*), i32* [[A_ADDR]], double* [[B_ADDR]], float** [[R_ADDR]])
 // ALL-NEXT:br label [[OMP_PAR_OUTLINED_EXIT13:%.*]]
 // ALL:   omp.par.outlined.exit13:
 // ALL-NEXT:br label [[OMP_PAR_EXIT_SPLIT:%.*]]
@@ -67,10 +67,10 @@
 // ALL-NEXT:store float* [[R:%.*]], float** [[R_ADDR]], align 8
 // ALL-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
 // ALL-NEXT:store double [[B:%.*]], double* [[B_ADDR]], align 8
-// ALL-NEXT:

[PATCH] D94961: [OpenMP] Add OpenMP offloading toolchain for AMDGPU

2021-02-01 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Generally OK, the more I look at it the more things pop up. Other than my 
comments, I'm fine with this going in.




Comment at: clang/lib/Driver/Driver.cpp:767
+  }
+  TC = AMDGPUOpenMPTC.get();
 } else

 what if we say `TT.isNVPTX() || TT.isAMDGCN()` in line 745, rename the Cuda 
things to "device" and the toolchain stuff is in a conditional? I see the 
triple is hardcoded here for some reason and I don't know why not to use TT. 
Neverhteless, it seems less copying is better, we will eventually have more 
architectures and 3 * 13 lines means 3 times the bugs and 3 times the required 
changes in the future.



Comment at: clang/lib/Driver/Driver.cpp:3004
+}
+  }
+  // amdgcn does not support linking of object files, therefore we skip

This does not look right. IsAMDGCN is not a question that should be answered by 
a `-Xopenmp-target` flag. 

In general, why skip these passes here. Isn't what you really want to do, pass 
`-emit-llvm[-bc]` to the device compilation job?



Comment at: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp:66
+ .Default("2");
+}
+CmdArgs.push_back(Args.MakeArgString("-O" + OOpt));

Just to make it clear, we should default to O0.



Comment at: clang/test/Driver/amdgpu-openmp-toolchain.c:2
+// REQUIRES: amdgpu-registered-target
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
-fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa 
-march=gfx906 %s 2>&1 \
+// RUN:   | FileCheck %s

Would this at all work without the march flag?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94961

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


[PATCH] D94844: [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.

2021-02-01 Thread Nathan Hawes via Phabricator via cfe-commits
nathawes updated this revision to Diff 320646.
nathawes added a comment.

Made the following changes as a speculative fix for the windows test failures 
in the pre-merge checks:

- When appending the remaining path components to the external redirect path of 
a directory-remap entry, use the separator type of the redirect path rather 
than the host system.
- For a directory-remap entry, when changing the paths returned in the external 
file system's directory iterator to appear to be in the virtual file system's 
directory, use the separator type from the virtual directory's path rather than 
the host system's.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94844

Files:
  clang/test/VFS/Inputs/vfsoverlay-directory-relative.yaml
  clang/test/VFS/Inputs/vfsoverlay-directory.yaml
  clang/test/VFS/directory.c
  lldb/source/Host/common/FileSystem.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp

Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -1328,6 +1328,7 @@
 
 TEST_F(VFSFromYAMLTest, MappedFiles) {
   IntrusiveRefCntPtr Lower(new DummyFileSystem());
+  Lower->addDirectory("//root/foo/bar");
   Lower->addRegularFile("//root/foo/bar/a");
   IntrusiveRefCntPtr FS = getFromYAMLString(
   "{ 'roots': [\n"
@@ -1343,6 +1344,17 @@
   "  'type': 'file',\n"
   "  'name': 'file2',\n"
   "  'external-contents': '//root/foo/b'\n"
+  "},\n"
+  "{\n"
+  "  'type': 'directory-remap',\n"
+  "  'name': 'mappeddir',\n"
+  "  'external-contents': '//root/foo/bar'\n"
+  "},\n"
+  "{\n"
+  "  'type': 'directory-remap',\n"
+  "  'name': 'mappeddir2',\n"
+  "  'use-external-name': false,\n"
+  "  'external-contents': '//root/foo/bar'\n"
   "}\n"
   "  ]\n"
   "}\n"
@@ -1380,12 +1392,221 @@
   EXPECT_TRUE(S->isDirectory());
   EXPECT_TRUE(S->equivalent(*O->status("//root/"))); // non-volatile UniqueID
 
+  // remapped directory
+  S = O->status("//root/mappeddir");
+  ASSERT_FALSE(S.getError());
+  EXPECT_TRUE(S->isDirectory());
+  EXPECT_TRUE(S->IsVFSMapped);
+  EXPECT_TRUE(S->equivalent(*O->status("//root/foo/bar")));
+
+  SLower = O->status("//root/foo/bar");
+  EXPECT_EQ("//root/foo/bar", SLower->getName());
+  EXPECT_TRUE(S->equivalent(*SLower));
+  EXPECT_FALSE(SLower->IsVFSMapped);
+
+  // file in remapped directory
+  S = O->status("//root/mappeddir/a");
+  ASSERT_FALSE(S.getError());
+  ASSERT_FALSE(S->isDirectory());
+  ASSERT_TRUE(S->IsVFSMapped);
+  ASSERT_EQ("//root/foo/bar/a", S->getName());
+
+  // file in remapped directory, with use-external-name=false
+  S = O->status("//root/mappeddir2/a");
+  ASSERT_FALSE(S.getError());
+  ASSERT_FALSE(S->isDirectory());
+  ASSERT_TRUE(S->IsVFSMapped);
+  ASSERT_EQ("//root/mappeddir2/a", S->getName());
+
+  // file contents in remapped directory
+  OpenedF = O->openFileForRead("//root/mappeddir/a");
+  ASSERT_FALSE(OpenedF.getError());
+  OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("//root/foo/bar/a", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
+  // file contents in remapped directory, with use-external-name=false
+  OpenedF = O->openFileForRead("//root/mappeddir2/a");
+  ASSERT_FALSE(OpenedF.getError());
+  OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("//root/mappeddir2/a", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
   // broken mapping
   EXPECT_EQ(O->status("//root/file2").getError(),
 llvm::errc::no_such_file_or_directory);
   EXPECT_EQ(0, NumDiagnostics);
 }
 
+TEST_F(VFSFromYAMLTest, MappedRoot) {
+  IntrusiveRefCntPtr Lower(new DummyFileSystem());
+  Lower->addDirectory("//root/foo/bar");
+  Lower->addRegularFile("//root/foo/bar/a");
+  IntrusiveRefCntPtr FS =
+  getFromYAMLString("{ 'roots': [\n"
+"{\n"
+"  'type': 'directory-remap',\n"
+"  'name': '//mappedroot/',\n"
+"  'external-contents': '//root/foo/bar'\n"
+"}\n"
+"]\n"
+"}",
+Lower);
+  ASSERT_TRUE(FS.get() != nullptr);
+
+  IntrusiveRefCntPtr O(
+  new vfs::OverlayFileSystem(Lower));
+  O->pushOverlay(FS);
+
+  // file
+  ErrorOr S = O->status("//mappedroot/a");
+  ASSERT_FALSE(S.getError());
+  EXPECT_EQ("//root/foo/b

[PATCH] D95558: [NFC][CUDA] Refactor registering device variable

2021-02-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:924
+
+void CGNVCUDARuntime::adjustShadowVarLinkage(
+const VarDecl *D, llvm::GlobalValue::LinkageTypes &Linkage) {

tra wrote:
> yaxunl wrote:
> > tra wrote:
> > > The name and the functionality do not match -- despite what the name 
> > > says, the function will set internal linkage on any var with device-side 
> > > attributes.
> > > 
> > > Rename to `internalizeDeviceSideVars` ?
> > done
> My suggestion could be improved, too. `Vars` -> `Var` as we're dealing with 
> only one VarDecl here.
will do



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4270-4271
 } else {
-  // Host-side shadows of external declarations of device-side
-  // global variables become internal definitions. These have to
-  // be internal in order to prevent name conflicts with global
-  // host variables with the same name in a different TUs.
-  if (D->hasAttr() || D->hasAttr()) {
-Linkage = llvm::GlobalValue::InternalLinkage;
-// Shadow variables and their properties must be registered with CUDA
-// runtime. Skip Extern global variables, which will be registered in
-// the TU where they are defined.
-//
-// Don't register a C++17 inline variable. The local symbol can be
-// discarded and referencing a discarded local symbol from outside the
-// comdat (__cuda_register_globals) is disallowed by the ELF spec.
-// TODO: Reject __device__ constexpr and __device__ inline in Sema.
-if (!D->hasExternalStorage() && !D->isInline())
-  getCUDARuntime().registerDeviceVar(D, *GV, !D->hasDefinition(),
- D->hasAttr());
-  } else if (D->hasAttr()) {
-// __shared__ variables are odd. Shadows do get created, but
-// they are not registered with the CUDA runtime, so they
-// can't really be used to access their device-side
-// counterparts. It's not clear yet whether it's nvcc's bug or
-// a feature, but we've got to do the same for compatibility.
-Linkage = llvm::GlobalValue::InternalLinkage;
-  } else if (D->getType()->isCUDADeviceBuiltinSurfaceType() ||
- D->getType()->isCUDADeviceBuiltinTextureType()) {
-// Builtin surfaces and textures and their template arguments are
-// also registered with CUDA runtime.
-Linkage = llvm::GlobalValue::InternalLinkage;
-const ClassTemplateSpecializationDecl *TD =
-cast(
-D->getType()->getAs()->getDecl());
-const TemplateArgumentList &Args = TD->getTemplateArgs();
-if (TD->hasAttr()) {
-  assert(Args.size() == 2 &&
- "Unexpected number of template arguments of CUDA device "
- "builtin surface type.");
-  auto SurfType = Args[1].getAsIntegral();
-  if (!D->hasExternalStorage())
-getCUDARuntime().registerDeviceSurf(D, *GV, !D->hasDefinition(),
-SurfType.getSExtValue());
-} else {
-  assert(Args.size() == 3 &&
- "Unexpected number of template arguments of CUDA device "
- "builtin texture type.");
-  auto TexType = Args[1].getAsIntegral();
-  auto Normalized = Args[2].getAsIntegral();
-  if (!D->hasExternalStorage())
-getCUDARuntime().registerDeviceTex(D, *GV, !D->hasDefinition(),
-   TexType.getSExtValue(),
-   Normalized.getZExtValue());
-}
-  }
+  getCUDARuntime().internalizeDeviceSideVars(D, Linkage);
+  getCUDARuntime().handleVarRegistration(D, *GV);
 }

tra wrote:
> Should we fold `internalizeDeviceSideVar` into `handleVarRegistration` or 
> call it from there?
> I don't think we'll have any independent use for it in CGM.  It seems to be 
> an implementation detail for `handleVarRegistration` and may not even need to 
> be virtual.
> 
For function scope static variable, I only need to call handleVarRegistration 
since the variable already has internal linkage. If internalizeDeviceSideVars 
is absorbed into handleVarRegistration, there be useless work and I also need 
to define a useless automatic variable `Linkage` and pass it to 
handleVarRegistration.


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

https://reviews.llvm.org/D95558

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


[PATCH] D95822: [FE][AIX] Use i8 as guard variable type in both load and store operation

2021-02-01 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/CodeGenCXX/aix-static-init.cpp:143
 // CHECK: init.check:
-// CHECK:   %1 = call i32 @__cxa_guard_acquire(i64* 
@_ZGVZN5test41fEvE11staticLocal)
+// CHECK:   %1 = call i32 @__cxa_guard_acquire(i8* 
@_ZGVZN5test41fEvE11staticLocal)
 // CHECK:   %tobool = icmp ne i32 %1, 0

What actually does the definition of `_ZGVZN5test41fEvE11staticLocal` look 
like? The test seems to be missing something pertinent for the change being 
proposed here. I will note that the symbol is 8-bytes (and aligned accordingly) 
from XL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95822

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


[PATCH] D95560: [CUDA][HIP] Fix function scope static variable

2021-02-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 320644.
yaxunl marked 6 inline comments as done.
yaxunl added a comment.

Revised by Artem's comments


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

https://reviews.llvm.org/D95560

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-func-scope-static-var.cu
  clang/test/CodeGenCUDA/func-scope-static-var.cu
  clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
  clang/test/SemaCUDA/func-scope-static-var.cu

Index: clang/test/SemaCUDA/func-scope-static-var.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/func-scope-static-var.cu
@@ -0,0 +1,115 @@
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=host,com -x hip %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcuda-is-device -verify=dev,com -x hip %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fgpu-rdc -verify=host,com -x hip %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fgpu-rdc -fcuda-is-device -verify=dev,com -x hip %s
+
+#include "Inputs/cuda.h"
+
+struct A {
+  static int a;
+  static __device__ int fun(); 
+};
+
+int A::a;
+__device__ int A::fun() {
+  return a;
+  // dev-error@-1 {{reference to __host__ variable 'a' in __device__ function}}
+}
+
+// Assuming this function accepts a pointer to a device variable and calculate some result.
+__device__ __host__ int work(const int *x);
+
+int fun1(int x) {
+  static __device__ int a = sizeof(a);
+  static __device__ int b = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const __device__ int c = sizeof(a);
+  static constexpr __device__ int d = sizeof(a);
+  static __constant__ __device__ int e = sizeof(a);
+  static __managed__ __device__ int f = sizeof(a);
+  static int a2 = sizeof(a);
+  static int b2 = x;
+  static const int c2 = sizeof(a);
+  static constexpr int d2 = sizeof(a);
+  static __constant__ int e2 = sizeof(a);
+  static __managed__ int f2 = sizeof(a);
+  return work(&a) + work(&b) + work(&c) + work(&d) + work(&e) + f + a2 + b2 + c2 + d2 + work(&e2) + f2;
+}
+
+__device__ int fun2(int x) {
+  static __device__ int a = sizeof(a);
+  static __device__ int b = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const __device__ int c = sizeof(a);
+  static constexpr __device__ int d = sizeof(a);
+  static __constant__ __device__ int e = sizeof(a);
+  static __managed__ __device__ int f = sizeof(a);
+  static int a2 = sizeof(a);
+  static int b2 = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const int c2 = sizeof(a);
+  static constexpr int d2 = sizeof(a);
+  static __constant__ int e2 = sizeof(a);
+  static __managed__ int f2 = sizeof(a);
+  return a + b + c + d + e + f + a2 + b2 + c2 + d2 + e2 + f2;
+}
+
+__device__ __host__ int fun3(int x) {
+  static __device__ int a = sizeof(a);
+  static __device__ int b = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const __device__ int c = sizeof(a);
+  static constexpr __device__ int d = sizeof(a);
+  static __constant__ __device__ int e = sizeof(a);
+  static __managed__ __device__ int f = sizeof(a);
+  static int a2 = sizeof(a);
+  static int b2 = x;
+  // dev-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const int c2 = sizeof(a);
+  static constexpr int d2 = sizeof(a);
+  static __constant__ int e2 = sizeof(a);
+  static __managed__ int f2 = sizeof(a);
+  return work(&a) + work(&b) + work(&c) + work(&d) + work(&e) + f + a2 + b2 + c2 + d2 + work(&e2) + f2;
+}
+
+template
+__device__ __host__ int fun4(T x) {
+  static __device__ int a = sizeof(x);
+  static __device__ int b = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const __device__ int c = sizeof(x);
+  static constexpr __device__ int d = sizeof(x);
+  static __constant__ __device__ int e = sizeof(a);
+  static __managed__ __device__ int f = sizeof(a);
+  static int a2 = sizeof(x);
+  static int b2 = x;
+  // dev-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  static const int c2 = sizeof(x);
+  static constexpr int d2 = sizeof(x);
+  static __constant__ int e2 = sizeof(a);
+  static __managed__ int f2 = sizeof(a);
+  return work(&a) + work(&b) + work(&c) + work(&d) + work(&e) + f + a2 + b2 + c2 + d2 + work(&e2) + f2;
+}
+
+__device__ __host__ int fun4_caller() {
+  return fun4(1);
+  // com-note@-1 {{in instantiation of function t

[PATCH] D95840: [CUDA][HIP] Fix checking dependent initalizer

2021-02-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

Defer constant checking of dependent initializer to template instantiation
since it cannot be done for dependent values.

This is separated from https://reviews.llvm.org/D95560


https://reviews.llvm.org/D95840

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/test/SemaCUDA/dependent-device-var.cu


Index: clang/test/SemaCUDA/dependent-device-var.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/dependent-device-var.cu
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=host,com -x hip %s
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify=dev,com -x hip %s
+
+#include "Inputs/cuda.h"
+
+template
+__device__ int fun1(T x) {
+  static __device__ int a = sizeof(x);
+  static __device__ int b = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, 
__constant__, __shared__, and __managed__ variables}}
+  return  a + b;
+}
+
+__device__ int fun1_caller() {
+  return fun1(1);
+  // com-note@-1 {{in instantiation of function template specialization 
'fun1' requested here}}
+}
Index: clang/lib/Sema/SemaCUDA.cpp
===
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -530,9 +530,12 @@
 if (!AllowedInit &&
 (VD->hasAttr() || VD->hasAttr())) {
   auto *Init = VD->getInit();
+  // isConstantInitializer cannot be called with dependent value, therefore
+  // we skip checking dependent value here. This is OK since
+  // checkAllowedCUDAInitializer is called again when the template is
+  // instantiated.
   AllowedInit =
-  ((VD->getType()->isDependentType() || Init->isValueDependent()) &&
-   VD->isConstexpr()) ||
+  (VD->getType()->isDependentType() || Init->isValueDependent()) ||
   Init->isConstantInitializer(Context,
   VD->getType()->isReferenceType());
 }


Index: clang/test/SemaCUDA/dependent-device-var.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/dependent-device-var.cu
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=host,com -x hip %s
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify=dev,com -x hip %s
+
+#include "Inputs/cuda.h"
+
+template
+__device__ int fun1(T x) {
+  static __device__ int a = sizeof(x);
+  static __device__ int b = x;
+  // com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+  return  a + b;
+}
+
+__device__ int fun1_caller() {
+  return fun1(1);
+  // com-note@-1 {{in instantiation of function template specialization 'fun1' requested here}}
+}
Index: clang/lib/Sema/SemaCUDA.cpp
===
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -530,9 +530,12 @@
 if (!AllowedInit &&
 (VD->hasAttr() || VD->hasAttr())) {
   auto *Init = VD->getInit();
+  // isConstantInitializer cannot be called with dependent value, therefore
+  // we skip checking dependent value here. This is OK since
+  // checkAllowedCUDAInitializer is called again when the template is
+  // instantiated.
   AllowedInit =
-  ((VD->getType()->isDependentType() || Init->isValueDependent()) &&
-   VD->isConstexpr()) ||
+  (VD->getType()->isDependentType() || Init->isValueDependent()) ||
   Init->isConstantInitializer(Context,
   VD->getType()->isReferenceType());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95560: [CUDA][HIP] Fix function scope static variable

2021-02-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 6 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:101
+// does that.
+class CUDAStaticDeviceVarEmitter
+: public StmtVisitor {

tra wrote:
> Nit. "This class does that" could be dropped. I'd generally follow a `" thing> does  for "` structure.
> E.g something along these lines:
> ```
> Helper class for emitting device-side static variables created in host-side 
> functions. While we do not emit host-side functions on device, we still need 
> to emit the static variables the host code will expect to see on the device.
> ```
done



Comment at: clang/lib/Sema/SemaCUDA.cpp:533-540
+  // isConstantInitializer cannot be called with dependent value, therefore
+  // we skip checking dependent value here. This is OK since
+  // checkAllowedCUDAInitializer is called again when the template is
+  // instantiated.
   AllowedInit =
-  ((VD->getType()->isDependentType() || Init->isValueDependent()) &&
-   VD->isConstexpr()) ||
+  (VD->getType()->isDependentType() || Init->isValueDependent()) ||
   Init->isConstantInitializer(Context,

tra wrote:
> This does not seem to be directly relevant for this patch. Perhaps move it 
> into a separate patch?
separated to another patch



Comment at: clang/lib/Sema/SemaDecl.cpp:7247-7250
+  // CUDA/HIP: Function-scope static variables in device or global functions
+  // have implicit device or constant attribute. Function-scope static 
variables
+  // in host device functions have implicit device or constant attribute in
+  // device compilation only.

tra wrote:
> This is somewhat confusing. I guess the issue is that we're conflating all 
> the functionality implied by the `__device__` attribute and the `accessible 
> on device` which is a subset of it. For the static vars in D functions you 
> only need for it to be accessible on device, IMO. For HD functions, you do 
> need the full `__device__` functionality, with host shadow and runtime 
> registration.
> 
> While adding implicit `__device__` works for statics in the device-only 
> functions, it's a bit of an overkill. It also gives us a somewhat different 
> AST between host/device compilations.
> 
> Perhaps we can handle statics in device-only functions w/o adding implicit 
> `__device__`. Can we check the parent of the variable instead when we check 
> whether we're allowed to reference the variable? 
Before we consider a function scope static variable without explicit device 
attribute, let's consider the difference between a static variable with 
explicit device attribute and a global device variable. They are both emitted 
in device compilation and have shadow variables in host compilation. The only 
difference is the linkage. A global device variable is supposed to be visible 
to other compilation units, whereas a static device variable is supposed to be 
visible to the same compilation unit only. A function scope static variable 
with device attribute has similar traits: It needs to be emitted in device 
compilation, and it needs a shadow variable in host compilation in case it 
needs to be accessed in host code. The only difference is that it is only 
visible inside the function.

Now let's consider a static var without device attribute in a device function. 
From sema and codegen point of view, it should have difference from a function 
scope static var with device attribute. Adding an implicit device attribute 
would simplify its handling.

Now let's consider a static var without device attribute in a host device 
function. The following code is valid for both nvcc and cuda-clang:

```
int __device__ __host__ func(int x) {
  static int a = 1;
  return a + x;
}
```
This requires the static variable is directly accessible in both device and 
host compilation. This requires that in device compilation, the static var 
behaves like a static var with explicit device attribute, whereas in host 
compilation, the static var behaves like a normal host static var. By adding 
implicit device attribute, we can clearly distinguish these situations and 
reuse the sema and codegen logic of device attribute.



Comment at: clang/test/CodeGenCUDA/func-scope-static-var.cu:54
+// NORDC: @_ZZ4fun2vE1b = dso_local addrspace(1) global i32 2
+// RDC: @_ZZ4fun2vE1b = internal addrspace(1) global i32 2
+// HOST: @_ZZ4fun2vE1b = internal global i32 2

tra wrote:
> What's the reason for externalizing the variables for no-rdc only?
> If we do not externalize them, then we'll potentially have a problem with the 
> host code attempting to get variable's device-side address and fail at 
> runtime, because it's not visible on device.
> 
> I think the right thing to do here is to always externalize them, but add 
> unique suffix for RDC.
Yes this will be fixed by the patch for externalizing static 

[PATCH] D95714: [clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons

2021-02-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc updated this revision to Diff 320637.
poelmanc added a comment.

Add period to end of comment.


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

https://reviews.llvm.org/D95714

Files:
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp
@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+}
+
+class A {
+public:
+  auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  // should not change next line to (a1 nullptr a2)
+  result = (a1 < a2);
+  // CHECK-FIXES: result = (a1 < a2);
+  // should not change next line to (a1 nullptr a2)
+  result = (a1 >= a2);
+  // CHECK-FIXES: result = (a1 >= a2);
+  int *ptr = 0;
+  // CHECK-FIXES: int *ptr = nullptr;
+  result = (a1 > (ptr == 0 ? a1 : a2));
+  // CHECK-FIXES: result = (a1 > (ptr == nullptr ? a1 : a2));
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));
+  // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : 
a2));
+}
Index: clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -41,12 +41,28 @@
   
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType(,
   unless(hasSourceExpression(hasType(sugaredNullptrType();
 
+  auto isOrHasDescendant = [](auto InnerMatcher) {
+return anyOf(InnerMatcher, hasDescendant(InnerMatcher));
+  };
+
   return traverse(
   TK_AsIs,
-  castExpr(anyOf(ImplicitCastToNull,
- explicitCastExpr(hasDescendant(ImplicitCastToNull))),
-   unless(hasAncestor(explicitCastExpr(
-  .bind(CastSequence));
+  anyOf(castExpr(anyOf(ImplicitCastToNull,
+   
explicitCastExpr(hasDescendant(ImplicitCastToNull))),
+ unless(hasAncestor(explicitCastExpr())),
+ unless(hasAncestor(cxxRewrittenBinaryOperator(
+.bind(CastSequence),
+cxxRewrittenBinaryOperator(
+// Match rewritten operators, but verify (in the check method)
+// that if an implicit cast is found, it is not from another
+// nested rewritten operator.
+expr().bind("matchBinopOperands"),
+hasEitherOperand(isOrHasDescendant(
+implicitCastExpr(
+ImplicitCastToNull,
+hasAncestor(cxxRewrittenBinaryOperator().bind(
+"checkBinopOperands")))
+.bind(CastSequence));
 }
 
 bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -480,6 +496,11 @@
   const auto *NullCast = Result.Nodes.getNodeAs(CastSequence);
   assert(NullCast && "Bad Callback. No node provided");
 
+  if (Result.Nodes.getNodeAs(
+  "matchBinopOperands") !=
+  Result.Nodes.getNodeAs("checkBinopOperands"))
+return;
+
   // Given an implicit null-ptr cast or an explicit cast with an implicit
   // null-to-pointer cast within use CastSequenceVisitor to identify sequences
   // of explicit casts that can be converted into 'nullptr'.


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp
@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+}
+
+class A {
+public:
+  auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  // should not change next line to (a1 nullptr a2)
+  result = (a1 < a2);
+  // CHECK-FIXES: result = (a1 < a2);
+  // should not change next line to (a1 nullptr a2)
+  result = (a1 >= a2);

[PATCH] D95822: [FE][AIX] Use i8 as guard variable type in both load and store operation

2021-02-01 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: 
clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp:193
 // CHECK:   %1 = call i32 @atexit(void ()* @__dtor__ZN5test12t1IiEE)
-// CHECK:   store i64 1, i64* @_ZGVN5test12t1IiEE
 // CHECK:   br label %init.end

Okay, so the store here is wrong, but it's got nothing to do with AIX.

The ABI doc (http://itanium-cxx-abi.github.io/cxx-abi/abi.html#once-ctor) says:
> the first byte (i.e., the byte with lowest address)

So the bug here seems to be that the Itanium ABI implementation in Clang is 
incorrect for big-endian systems.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95822

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


[PATCH] D76342: [OpenMP] Implement '#pragma omp tile'

2021-02-01 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

Thank you for the update.

From comparing the diffs, here is the list of main changes I found:

1. Create `OMPLoopBasedDirective` as a new base class for OMPLoopDirective (and 
OMPTileDirective) for CollapsedNum and some utility methods for analyzing the 
CapturedStmt/ForStmt structure (replacing getTopmostAssociatedStructuredBlock, 
collectAssociatedLoops)
2. Add PreInits child to OMPTileDirective (instead of wrapping them in a 
CompoundStmt of the transformed body/collectAssociatedLoops)
3. Use meaningful SourceLocations instead of my placeholder `{}`
4. New OMPTransformDirectiveScopeRAII
  1. to collect nested PreInits (instead by collectAssociatedLoops)
  2. to assign values to CapturedDecls (instead of adding a `Capturing` 
argument to various function)
5. no call to checkOpenMPLoop for the entire lop nest (but still once per loop)

My remarks to these changes:

1. Saves us to store all the loop-specific subexpressions in the AST node. 
However, they are still computed in ActOnOpenMPTileDirective. With the 
OpenMPIRBuilder (D94973 ) these will also not 
be necessary for other loop-associated statements.
2. looks more consistent with other directives
3. This was just laziness on my size. Thank you.
4. is what I just did not know. 4.b. still feels like a hack because there are 
captures variables outside of any CapturedStmt and therefore complicated the 
AST. Comparable directive such as `master` don't do this.
5. The additional call on the entire loop nest felt necessary to check 
constraints such as invariant loop bounds and disallow nesting. However, both 
properties are still checked now.




Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2790-2791
 
+DEF_TRAVERSE_STMT(OMPTileDirective,
+  { TRY_TO(TraverseOMPExecutableDirective(S)); })
+

[no change request] OMPLoopBasedDirective is not represented in the visitor.

Well, nor does anything call TraverseOMPLoopDirective, so the possibility to 
only override the base class traverse-function is unused.



Comment at: clang/include/clang/AST/StmtOpenMP.h:443
 
+class OMPLoopBasedDirective : public OMPExecutableDirective {
+  friend class ASTStmtReader;

Please add a documentation what this class represents.



Comment at: clang/include/clang/AST/StmtOpenMP.h:448
+  /// Number of collapsed loops as specified by 'collapse' clause.
+  unsigned CollapsedNum = 0;
+

Inaccurate for the tile directive.



Comment at: clang/include/clang/AST/StmtOpenMP.h:456
+  /// \param EndLoc Ending location of the directive.
+  /// \param CollapsedNum Number of collapsed loops from 'collapse' clause.
+  ///

Inaccurate for the tile directive.



Comment at: clang/include/clang/AST/StmtOpenMP.h:651-677
+  static bool
+  doForAllLoops(Stmt *CurStmt, bool TryImperfectlyNestedLoops,
+unsigned NumLoops,
+llvm::function_ref Callback);
+  static bool
+  doForAllLoops(const Stmt *CurStmt, bool TryImperfectlyNestedLoops,
+unsigned NumLoops,

Please add doxygen comments.

IMHO, using callbacks makes the callers significantly more complicated. Why not 
fill a SmallVectorImpl with the result?



Comment at: clang/include/clang/AST/StmtOpenMP.h:659
+llvm::function_ref Callback) {
+auto &&NewCallback = [Callback](unsigned Cnt, Stmt *CurStmt) {
+  return Callback(Cnt, CurStmt);

I do not see why making this a forwarding reference.



Comment at: clang/include/clang/AST/StmtOpenMP.h:680-709
+return T->getStmtClass() == OMPSimdDirectiveClass ||
+   T->getStmtClass() == OMPForDirectiveClass ||
+   T->getStmtClass() == OMPTileDirectiveClass ||
+   T->getStmtClass() == OMPForSimdDirectiveClass ||
+   T->getStmtClass() == OMPParallelForDirectiveClass ||
+   T->getStmtClass() == OMPParallelForSimdDirectiveClass ||
+   T->getStmtClass() == OMPTaskLoopDirectiveClass ||

Use `isOpenMPLoopDirective()` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76342

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


[PATCH] D95765: [OpenMP] Introduce the `disable_selector_propagation` variant selector trait

2021-02-01 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Yes, OK. I'm a little nervous that variant is evolving into a turing complete 
sublanguage, but I see the use of opting out of the implicit inheritance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95765

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


[PATCH] D95764: [OpenMP] Do not propagate match extensions to nested contexts

2021-02-01 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

That sounds reasonable. We can probably expect features to be renamed and 
semantically adjusted on their way to standardisation anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95764

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


[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This looks about right to me...
Unfortunately I landed ff4832dbff0ccf1fd29f726efe72fd1220cd645a 
 and 
1eb7fd089e2fcf3fe211f865b28e2fed12128c3f 
 meanwhile 
so this will need a rebase :-(

The first of those patches introduces flags on returned refs to indicate which 
are decls/defs. I'd suggest adding an "override" flag and populating it for 
these results.
Hopefully we'll have a sensible way to expose these flags over LSP someday, 
meanwhile I think our internal embedders may like to surface that.

(I guess the bug includes the other side of this, where if the method is an 
override, calls to base methods are reported. Makes sense to split it into a 
separate patch...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

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


[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-02-01 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 320617.
arnamoy10 added a comment.

A few more comments addressed and a new test case added for write-module check.


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

https://reviews.llvm.org/D95448

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-module.f90
  flang/test/Flang-Driver/write-module.f90

Index: flang/test/Flang-Driver/write-module.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/write-module.f90
@@ -0,0 +1,10 @@
+! RUN: mkdir -p %t/dir-f18 && %f18 -fparse-only -I tools/flang/include/flang -module %t/dir-f18 %s  2>&1
+! RUN: ls %t/dir-f18/testmodule.mod && not ls %t/testmodule.mod
+
+! RUN: mkdir -p %t/dir-flang-new && %flang-new -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: ls %t/dir-flang-new/testmodule.mod && not ls %t/testmodule.mod
+
+module testmodule
+  type::t2
+  end type
+end
Index: flang/test/Flang-Driver/include-module.f90
===
--- flang/test/Flang-Driver/include-module.f90
+++ flang/test/Flang-Driver/include-module.f90
@@ -7,12 +7,26 @@
 !--
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
 
 !-
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
 
 !-
 ! EXPECTED OUTPUT FOR MISSING MODULE FILE
@@ -22,6 +36,11 @@
 ! SINGLEINCLUDE-NOT:error: Derived type 't1' not found
 ! SINGLEINCLUDE:error: Derived type 't2' not found
 
+!-
+! EXPECTED OUTPUT FOR MISSING MODULE FILE
+!-
+! DOUBLEINCLUDE:error: Only one '-module-dir/-J' option allowed
+
 !---
 ! EXPECTED OUTPUT FOR ALL MODULES FOUND
 !---
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -26,6 +26,7 @@
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-NEXT: -modul

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdf3e39f60b35: [InstrProfiling] Use !associated metadata for 
counters, data and values (authored by phosek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen,instrprof -counter-link-order -S | FileCheck %s
+
+; CHECK: @__profc_foo = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8, !associated !0
+; CHECK: @__profd_foo = private global {{.*}}, section "__llvm_prf_data", align 8, !associated !1
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{void ()* @foo}
+; CHECK: !1 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !1
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !2
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !3
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !4
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !5
 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
 define internal void @foo_internal() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !6
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !7
 ; COFF: @__profc_foo_inline = internal global{{.*}} section ".lprfc$M", align 8
 ; COFF: @__p

[clang] df3e39f - [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2021-02-01T15:01:43-08:00
New Revision: df3e39f60b356ca9dbfc11e96e5fdda30afa7acb

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

LOG: [InstrProfiling] Use !associated metadata for counters, data and values

C identifier name input sections such as __llvm_prf_* are GC roots so
they cannot be discarded. In LLD, the SHF_LINK_ORDER flag overrides the
C identifier name semantics.

The !associated metadata may be attached to a global object declaration
with a single argument that references another global object, and it
gets lowered to SHF_LINK_ORDER flag. When a function symbol is discarded
by the linker, setting up !associated metadata allows linker to discard
counters, data and values associated with that function symbol.

Note that !associated metadata is only supported by ELF, it does not have
any effect on non-ELF targets.

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

Added: 
compiler-rt/test/profile/instrprof-gc-sections.c
llvm/test/Transforms/PGOProfile/associated.ll

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Transforms/Instrumentation.h
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/icall.ll
llvm/test/Instrumentation/InstrProfiling/linkage.ll
llvm/test/Transforms/PGOProfile/counter_promo.ll
llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 52bcd971dc8c..f995c4702419 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -615,6 +615,9 @@ getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
   Options.NoRedZone = CodeGenOpts.DisableRedZone;
   Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
   Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
+  std::pair BinutilsVersion =
+  llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion);
+  Options.CounterLinkOrder = BinutilsVersion >= std::make_pair(2, 36);
   return Options;
 }
 

diff  --git a/compiler-rt/test/profile/instrprof-gc-sections.c 
b/compiler-rt/test/profile/instrprof-gc-sections.c
new file mode 100644
index ..b1f0720846af
--- /dev/null
+++ b/compiler-rt/test/profile/instrprof-gc-sections.c
@@ -0,0 +1,91 @@
+// REQUIRES: linux, lld-available
+
+// RUN: %clang_profgen=%t.profraw -fuse-ld=lld -fcoverage-mapping -mllvm 
-counter-link-order -mllvm -enable-name-compression=false -DCODE=1 
-ffunction-sections -fdata-sections -Wl,--gc-sections -o %t %s
+// RUN: %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s 
-check-prefix=PROF
+// RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s 
-check-prefix=COV
+// RUN: llvm-nm %t | FileCheck %s -check-prefix=NM
+// RUN: llvm-readelf -x __llvm_prf_names %t | FileCheck %s 
-check-prefix=PRF_NAMES
+// RUN: llvm-readelf -x __llvm_prf_cnts %t | FileCheck %s 
-check-prefix=PRF_CNTS
+
+// RUN: %clang_lto_profgen=%t.lto.profraw -fuse-ld=lld -fcoverage-mapping 
-mllvm -counter-link-order -mllvm -enable-name-compression=false -DCODE=1 
-ffunction-sections -fdata-sections -Wl,--gc-sections -flto -o %t.lto %s
+// RUN: %run %t.lto
+// RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw
+// RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s 
-check-prefix=PROF
+// RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s 
-check-prefix=COV
+// RUN: llvm-nm %t.lto | FileCheck %s -check-prefix=NM
+// RUN: llvm-readelf -x __llvm_prf_names %t.lto | FileCheck %s 
-check-prefix=PRF_NAMES
+// RUN: llvm-readelf -x __llvm_prf_cnts %t.lto | FileCheck %s 
-check-prefix=PRF_CNTS
+
+// Note: We expect foo() and some of the profiling data associated with it to
+// be garbage collected.
+
+// Note: When there is no code in a program, we expect to see the exact same
+// set of external functions provided by the profile runtime.
+
+// RUN: %clang_profgen -fuse-ld=lld -fcoverage-mapping -mllvm 
-counter-link-order -ffunction-sections -fdata-sections -Wl,--gc-sections 
-shared -o %t.nocode.so %s
+// RUN: llvm-nm -jgU %t.nocode.so | grep -vE "__start_.*|__stop_.*" > 
%t.nocode.syms
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: 
diff  %t.nocode.syms %t.code.syms
+
+// Note: We also check the IR instrumentation and expect foo() to be garbage
+// collected as well.
+
+// RUN: %clang_pgogen=%t.pgo.profraw -fuse-ld=lld -mllvm -counter-link-order 
-DCODE=1 -ffunction-sections -fdata-sections -Wl,--gc-sections -o %t.pgo %s
+// RUN: %run %t.pgo
+// 

[PATCH] D95824: [clangd] Sketch: interning filenames

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

This is an idea to attack two problems:

- simplify string tracking, copies, comparisons. Should be worth some perf, 
maybe reduce complexity in some places.
- make it easy+efficient to treat paths as case-insensitive where needed (we've 
been stomping these bugs as they get reported, but there are more...)

Three main limitations I'm running into:

- It's really painful to try to convert all of clangd to use this at once, but 
it's hard to measure the performance by converting only part.
- Conversion back and forth to URIs limits our wins, we're copying+re-interning 
all the time. For the index, fix is to eliminate URIs, we have ideas for this. 
URIs on the wire are fine, we can just slap a cache on them.
- Pulling filenames out of clang APIs (FileManager) limits our wins too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95824

Files:
  clang-tools-extra/clangd/support/Path.cpp
  clang-tools-extra/clangd/support/Path.h

Index: clang-tools-extra/clangd/support/Path.h
===
--- clang-tools-extra/clangd/support/Path.h
+++ clang-tools-extra/clangd/support/Path.h
@@ -9,7 +9,9 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_PATH_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_PATH_H
 
+#include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include 
 
 namespace clang {
@@ -17,18 +19,67 @@
 
 /// A typedef to represent a file path. Used solely for more descriptive
 /// signatures.
-using Path = std::string;
+// using Path = std::string;
 /// A typedef to represent a ref to file path. Used solely for more descriptive
 /// signatures.
-using PathRef = llvm::StringRef;
+// using PathRef = llvm::StringRef;
 
 // For platforms where paths are case-insensitive (but case-preserving),
 // we need to do case-insensitive comparisons and use lowercase keys.
 // FIXME: Make Path a real class with desired semantics instead.
-std::string maybeCaseFoldPath(PathRef Path);
-bool pathEqual(PathRef, PathRef);
+std::string maybeCaseFoldPath(llvm::StringRef Path);
+bool pathEqual(llvm::StringRef, llvm::StringRef);
+
+class IPath {
+  const char *Data;
+  unsigned Length;
+  unsigned Hash;
+
+  IPath(unsigned Sentinel) : Data(nullptr), Length(0), Hash(Sentinel) {}
+  struct CanonicalTag {};
+  IPath(llvm::StringRef Value, CanonicalTag);
+
+public:
+  IPath() : Data(0), Length(0), Hash(0) {}
+  explicit IPath(llvm::StringRef Value);
+  IPath &operator=(const IPath &) = default;
+  IPath &operator=(llvm::StringRef V) { return *this = IPath(V); }
+
+  bool empty() const { return !Length; }
+
+  operator llvm::StringRef() const { return llvm::StringRef(Data, Length); }
+  operator llvm::Twine() const { return llvm::Twine(llvm::StringRef(*this)); }
+  friend bool operator==(IPath L, IPath R) {
+if (L.Data == R.Data)
+  return true;
+if (L.Hash != R.Hash)
+  return false;
+return pathEqual(L, R);
+  }
+  friend llvm::hash_code hash_value(IPath P) {
+// Just mix the stored 32-bit hash, should be enough?!
+return llvm::hash_value(P.Hash);
+  }
+
+  friend struct llvm::DenseMapInfo;
+  friend class PathTable;
+};
+inline bool operator!=(IPath L, IPath R) { return !(L == R); }
+
+using Path = IPath;
+using PathRef = IPath;
 
 } // namespace clangd
 } // namespace clang
 
+namespace llvm {
+template <> struct llvm::DenseMapInfo {
+  using IPath = clang::clangd::IPath;
+  static inline IPath getEmptyKey() { return IPath(); }
+  static inline IPath getTombstoneKey() { return IPath(1); }
+  static unsigned getHashValue(IPath Val) { return Val.Hash; }
+  static bool isEqual(IPath L, clang::clangd::IPath R) { return L == R; }
+};
+} // namespace llvm
+
 #endif
Index: clang-tools-extra/clangd/support/Path.cpp
===
--- clang-tools-extra/clangd/support/Path.cpp
+++ clang-tools-extra/clangd/support/Path.cpp
@@ -7,10 +7,16 @@
 //===--===//
 
 #include "support/Path.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
+#include 
+#include 
+
 namespace clang {
 namespace clangd {
 
-std::string maybeCaseFoldPath(PathRef Path) {
+std::string maybeCaseFoldPath(llvm::StringRef Path) {
 #if defined(_WIN32) || defined(__APPLE__)
   return Path.lower();
 #else
@@ -18,7 +24,7 @@
 #endif
 }
 
-bool pathEqual(PathRef A, PathRef B) {
+bool pathEqual(llvm::StringRef A, llvm::StringRef B) {
 #if defined(_WIN32) || defined(__APPLE__)
   return A.equals_lower(B);
 #else
@@ -26,5 +32,88 @@
 #endif
 }
 
+static unsigned pathHash(llvm::StringRef Path) {
+  llvm::SmallString<256> Upper = Path;
+  for (char 

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:77-79
+  Builder.defineMacro("M68k");
+  Builder.defineMacro("__M68k__");
+  Builder.defineMacro("__M68K__");

jrtc27 wrote:
> myhsu wrote:
> > jrtc27 wrote:
> > > Where are these coming from? GCC only defines `__m68k__`.
> > I think GCC does: 
> > https://github.com/gcc-mirror/gcc/blob/b90d051ecbc1d8972ae1bf0cd7588fcc66df0722/gcc/config/m68k/m68k.h#L64
> > 
> > Also I found this page: https://sourceforge.net/p/predef/wiki/Architectures
> Yes, and as you can see none of those three are defined by GCC. Defining 
> `M68k` is particularly bad as it will collide with the C++ namespace used by 
> this very backend so you won't be able to build Clang with Clang on m68k! And 
> the others are just a waste of time. Defining fewer macros is best, that way 
> people don't come to rely on non-standard ones and instead use the single 
> option that exists everywhere (`__m68k__`).
> it will collide with the C++ namespace used by this very backend so you won't 
> be able to build Clang with Clang on m68k

good point :-)

> Defining fewer macros is best, that way people don't come to rely on 
> non-standard ones and instead use the single option that exists everywhere

fair enough


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

https://reviews.llvm.org/D88393

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 320604.
myhsu added a comment.

- Addressed feedback
  - Remove redundant target macro definitions


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_BASIC

[clang] 8e661d3 - [AMDGPU] Set s-memtime-inst feature from clang

2021-02-01 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2021-02-01T14:20:43-08:00
New Revision: 8e661d3d9c52ea9e5e68cbf699701d9cfa071a8f

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

LOG: [AMDGPU] Set s-memtime-inst feature from clang

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

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 91c1e83f61cb..e6450c9f9ff8 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -210,6 +210,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
   Features["gfx9-insts"] = true;
   Features["gfx10-insts"] = true;
   Features["s-memrealtime"] = true;
+  Features["s-memtime-inst"] = true;
   break;
 case GK_GFX908:
   Features["dot3-insts"] = true;
@@ -252,6 +253,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
 case GK_GFX602:
 case GK_GFX601:
 case GK_GFX600:
+  Features["s-memtime-inst"] = true;
   break;
 case GK_NONE:
   break;

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 740521aa3bca..a796d07cb2e5 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -32,30 +32,30 @@
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1032 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1032 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1033 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1033 %s
 
-// GFX600-NOT: "target-features"
-// GFX601-NOT: "target-features"
-// GFX602-NOT: "target-features"
-// GFX700: "target-features"="+ci-insts,+flat-address-space"
-// GFX701: "target-features"="+ci-insts,+flat-address-space"
-// GFX702: "target-features"="+ci-insts,+flat-address-space"
-// GFX703: "target-features"="+ci-insts,+flat-address-space"
-// GFX704: "target-features"="+ci-insts,+flat-address-space"
-// GFX705: "target-features"="+ci-insts,+flat-address-space"
-// GFX801: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
-// GFX802: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
-// GFX803: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
-// GFX805: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
-// GFX810: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
-// GFX900: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX902: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX904: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX906: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX908: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+mai-insts,+s-memrealtime"
-// GFX909: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX90C: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX1010: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX1011: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX1012: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
+// GFX600: "target-features"="+s-memtime-inst"
+// GFX601: "target-features"="+s-memtime-inst"
+// GFX602: "target-features"="+s-memtime-inst"
+// GFX700: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst"
+// GFX701: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst"
+// GFX702: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst"
+// GFX703: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst"
+// GFX704: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst"
+// GFX705: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst"
+// GFX801: 
"target-fe

[PATCH] D95822: [FE][AIX] Use i8 as guard variable type in both load and store operation

2021-02-01 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L created this revision.
Xiangling_L added reviewers: hubert.reinterpretcast, jasonliu, 
abhina.sreeskantharajan.
Herald added a subscriber: jfb.
Xiangling_L requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For static init, use i8 as guard variable type in both load and store 
operation. And this matches XL behavior on AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95822

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp

Index: clang/test/CodeGenCXX/aix-static-init.cpp
===
--- clang/test/CodeGenCXX/aix-static-init.cpp
+++ clang/test/CodeGenCXX/aix-static-init.cpp
@@ -135,19 +135,19 @@
 
 // CHECK: define void @_ZN5test41fEv() [[ATTR:#[0-9]+]] {
 // CHECK: entry:
-// CHECK:   %0 = load atomic i8, i8* bitcast (i64* @_ZGVZN5test41fEvE11staticLocal to i8*) acquire
+// CHECK:   %0 = load atomic i8, i8* @_ZGVZN5test41fEvE11staticLocal acquire, align 1
 // CHECK:   %guard.uninitialized = icmp eq i8 %0, 0
 // CHECK:   br i1 %guard.uninitialized, label %init.check, label %init.end
 
 // CHECK: init.check:
-// CHECK:   %1 = call i32 @__cxa_guard_acquire(i64* @_ZGVZN5test41fEvE11staticLocal)
+// CHECK:   %1 = call i32 @__cxa_guard_acquire(i8* @_ZGVZN5test41fEvE11staticLocal)
 // CHECK:   %tobool = icmp ne i32 %1, 0
 // CHECK:   br i1 %tobool, label %init, label %init.end
 
 // CHECK: init:
 // CHECK:   call void @_ZN5test45Test4C1Ev(%"struct.test4::Test4"* {{[^,]*}} @_ZZN5test41fEvE11staticLocal)
 // CHECK:   %2 = call i32 @atexit(void ()* @__dtor__ZZN5test41fEvE11staticLocal)
-// CHECK:   call void @__cxa_guard_release(i64* @_ZGVZN5test41fEvE11staticLocal)
+// CHECK:   call void @__cxa_guard_release(i8* @_ZGVZN5test41fEvE11staticLocal)
 // CHECK:   br label %init.end
 
 // CHECK: init.end:
Index: clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
===
--- clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
+++ clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
@@ -77,12 +77,12 @@
 
 // CHECK: define internal void @__cxx_global_var_init.1() [[ATTR:#[0-9]+]] {
 // CHECK: entry:
-// CHECK:   %0 = load atomic i8, i8* bitcast (i64* @_ZGVN5test12t2E to i8*) acquire
+// CHECK:   %0 = load atomic i8, i8* @_ZGVN5test12t2E acquire, align 1
 // CHECK:   %guard.uninitialized = icmp eq i8 %0, 0
 // CHECK:   br i1 %guard.uninitialized, label %init.check, label %init.end
 
 // CHECK: init.check:
-// CHECK:   %1 = call i32 @__cxa_guard_acquire(i64* @_ZGVN5test12t2E)
+// CHECK:   %1 = call i32 @__cxa_guard_acquire(i8* @_ZGVN5test12t2E)
 // CHECK:   %tobool = icmp ne i32 %1, 0
 // CHECK:   br i1 %tobool, label %init, label %init.end
 
@@ -90,7 +90,7 @@
 // CHECK32: call void @_ZN5test15Test1C1Ei(%"struct.test1::Test1"* {{[^,]*}} @_ZN5test12t2E, i32 2)
 // CHECK64: call void @_ZN5test15Test1C1Ei(%"struct.test1::Test1"* {{[^,]*}} @_ZN5test12t2E, i32 signext 2)
 // CHECK:   %2 = call i32 @atexit(void ()* @__dtor__ZN5test12t2E)
-// CHECK:   call void @__cxa_guard_release(i64* @_ZGVN5test12t2E)
+// CHECK:   call void @__cxa_guard_release(i8* @_ZGVN5test12t2E)
 // CHECK:   br label %init.end
 
 // CHECK: init.end:
@@ -119,14 +119,14 @@
 
 // CHECK: define internal void @__cxx_global_var_init.2() [[ATTR:#[0-9]+]] {
 // CHECK: entry:
-// CHECK:   %0 = load i8, i8* bitcast (i64* @_ZGVN5test21AIvE8instanceE to i8*)
+// CHECK:   %0 = load i8, i8* @_ZGVN5test21AIvE8instanceE, align 1
 // CHECK:   %guard.uninitialized = icmp eq i8 %0, 0
 // CHECK:   br i1 %guard.uninitialized, label %init.check, label %init.end
 
 // CHECK: init.check:
 // CHECK:   call void @_ZN5test21AIvEC1Ev(%"struct.test2::A"* {{[^,]*}} @_ZN5test21AIvE8instanceE)
 // CHECK:   %1 = call i32 @atexit(void ()* @__dtor__ZN5test21AIvE8instanceE)
-// CHECK:   store i64 1, i64* @_ZGVN5test21AIvE8instanceE
+// CHECK:   store i8 1, i8* @_ZGVN5test21AIvE8instanceE, align 1
 // CHECK:   br label %init.end
 
 // CHECK: init.end:
@@ -182,7 +182,7 @@
 
 // CHECK: define internal void @__cxx_global_var_init.4() [[ATTR:#[0-9]+]] {
 // CHECK: entry:
-// CHECK:   %0 = load i8, i8* bitcast (i64* @_ZGVN5test12t1IiEE to i8*)
+// CHECK:   %0 = load i8, i8* @_ZGVN5test12t1IiEE, align 1
 // CHECK:   %guard.uninitialized = icmp eq i8 %0, 0
 // CHECK:   br i1 %guard.uninitialized, label %init.check, label %init.end
 
@@ -190,7 +190,7 @@
 // CHECK32: call void @_ZN5test15Test1C1Ei(%"struct.test1::Test1"* {{[^,]*}} @_ZN5test12t1IiEE, i32 2)
 // CHECK64: call void @_ZN5test15Test1C1Ei(%"struct.test1::Test1"* {{[^,]*}} @_ZN5test12t1IiEE, i32 signext 2)
 // CHECK:   %1 = call i32 @atexit(void ()* @__dtor__ZN5test12t1IiEE)
-// CHECK:   store i64 1, i64* @_ZGVN5test12t1IiEE
+// CHECK:   store i8 1, i8* @_ZGVN5test12t1IiEE, align 1
 // CHECK

[PATCH] D95753: [CoverageMapping] Don't absolutize source paths

2021-02-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for pointing DW_AT_comp_dir out. For coverage, gating the use of 
relative paths on a flag sounds reasonable to me. It should also be possible to 
extend the .covmapping format to include something like DW_AT_comp_dir: 
compared to adding a flag, this would take a lot more work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95753

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


[PATCH] D95725: clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)

2021-02-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc marked an inline comment as done.
poelmanc added a comment.

s/Guard/Lock/! I don't have commit access so appreciate a push.


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

https://reviews.llvm.org/D95725

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


[PATCH] D95725: clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)

2021-02-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc updated this revision to Diff 320594.
poelmanc added a comment.

Change Guard to Lock.


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

https://reviews.llvm.org/D95725

Files:
  clang-tools-extra/clangd/support/Function.h


Index: clang-tools-extra/clangd/support/Function.h
===
--- clang-tools-extra/clangd/support/Function.h
+++ clang-tools-extra/clangd/support/Function.h
@@ -51,7 +51,7 @@
 Subscription &operator=(Subscription &&Other) {
   // If *this is active, unsubscribe.
   if (Parent) {
-std::lock_guard(Parent->ListenersMu);
+std::lock_guard Lock(Parent->ListenersMu);
 llvm::erase_if(Parent->Listeners,
[&](const std::pair &P) {
  return P.second == ListenerID;


Index: clang-tools-extra/clangd/support/Function.h
===
--- clang-tools-extra/clangd/support/Function.h
+++ clang-tools-extra/clangd/support/Function.h
@@ -51,7 +51,7 @@
 Subscription &operator=(Subscription &&Other) {
   // If *this is active, unsubscribe.
   if (Parent) {
-std::lock_guard(Parent->ListenersMu);
+std::lock_guard Lock(Parent->ListenersMu);
 llvm::erase_if(Parent->Listeners,
[&](const std::pair &P) {
  return P.second == ListenerID;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-01 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:697
 
-  if (IsPolymorphic) {
-OS << "Matcher " << Name << "(Matcher";
+  std::string TypedText = std::string(Name);
+

aaron.ballman wrote:
> Any reason this declaration needed to move?
It's used after the if-else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

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


[PATCH] D94880: Add clang-query support for mapAnyOf

2021-02-01 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 320593.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94880

Files:
  clang/include/clang/ASTMatchers/Dynamic/Diagnostics.h
  clang/include/clang/ASTMatchers/Dynamic/Parser.h
  clang/include/clang/ASTMatchers/Dynamic/Registry.h
  clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
  clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/ASTMatchers/Dynamic/Parser.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -32,6 +32,17 @@
 return M.getID().second;
   }
 
+  bool isBuilderMatcher(MatcherCtor) const override { return false; }
+
+  ASTNodeKind nodeMatcherType(MatcherCtor) const override { return {}; }
+
+  internal::MatcherDescriptorPtr
+  buildMatcherCtor(MatcherCtor, SourceRange NameRange,
+   ArrayRef Args,
+   Diagnostics *Error) const override {
+return internal::MatcherDescriptorPtr{nullptr};
+  }
+
   void parse(StringRef Code) {
 Diagnostics Error;
 VariantValue Value;
@@ -329,7 +340,7 @@
 "1:5: Invalid token <(> found when looking for a value.",
 ParseWithError("Foo(("));
   EXPECT_EQ("1:7: Expected end of code.", ParseWithError("expr()a"));
-  EXPECT_EQ("1:11: Malformed bind() expression.",
+  EXPECT_EQ("1:11: Period not followed by valid chained call.",
 ParseWithError("isArrow().biind"));
   EXPECT_EQ("1:15: Malformed bind() expression.",
 ParseWithError("isArrow().bind"));
@@ -340,6 +351,20 @@
   EXPECT_EQ("1:1: Error building matcher isArrow.\n"
 "1:1: Matcher does not support binding.",
 ParseWithError("isArrow().bind(\"foo\")"));
+  EXPECT_EQ("1:1: Error building matcher isArrow.\n"
+"1:11: Matcher does not support with call.",
+ParseWithError("isArrow().with"));
+  EXPECT_EQ(
+  "1:22: Error parsing matcher. Found token  while looking for '('.",
+  ParseWithError("mapAnyOf(ifStmt).with"));
+  EXPECT_EQ(
+  "1:22: Error parsing matcher. Found end-of-code while looking for ')'.",
+  ParseWithError("mapAnyOf(ifStmt).with("));
+  EXPECT_EQ("1:1: Failed to build matcher: mapAnyOf.",
+ParseWithError("mapAnyOf()"));
+  EXPECT_EQ("1:1: Error parsing argument 1 for matcher mapAnyOf.\n1:1: Failed "
+"to build matcher: mapAnyOf.",
+ParseWithError("mapAnyOf(\"foo\")"));
   EXPECT_EQ("Input value has unresolved overloaded type: "
 "Matcher",
 ParseMatcherWithError("hasBody(stmt())"));
@@ -470,7 +495,8 @@
 )matcher";
 M = Parser::parseMatcherExpression(Code, nullptr, &NamedValues, &Error);
 EXPECT_FALSE(M.hasValue());
-EXPECT_EQ("1:11: Malformed bind() expression.", Error.toStringFull());
+EXPECT_EQ("1:11: Period not followed by valid chained call.",
+  Error.toStringFull());
   }
 
   {
@@ -515,6 +541,29 @@
   ASSERT_EQ(1u, Comps.size());
   EXPECT_EQ("bind(\"", Comps[0].TypedText);
   EXPECT_EQ("bind", Comps[0].MatcherDecl);
+
+  Code = "mapAny";
+  Comps = Parser::completeExpression(Code, 6);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("Of(", Comps[0].TypedText);
+  EXPECT_EQ("Matcher "
+"mapAnyOf(NestedNameSpecifierLoc|QualType|TypeLoc|"
+"NestedNameSpecifier|Decl|Stmt|Type...)",
+Comps[0].MatcherDecl);
+
+  Code = "mapAnyOf(ifStmt).";
+  Comps = Parser::completeExpression(Code, 17);
+  ASSERT_EQ(2u, Comps.size());
+  EXPECT_EQ("bind(\"", Comps[0].TypedText);
+  EXPECT_EQ("bind", Comps[0].MatcherDecl);
+  EXPECT_EQ("with(\"", Comps[1].TypedText);
+  EXPECT_EQ("with", Comps[1].MatcherDecl);
+
+  Code = "mapAnyOf(ifS";
+  Comps = Parser::completeExpression(Code, 12);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("tmt", Comps[0].TypedText);
+  EXPECT_EQ("ifStmt", Comps[0].MatcherDecl);
 }
 
 TEST(ParserTest, CompletionNamedValues) {
Index: clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
===
--- clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -22,9 +22,11 @@
 std::string ArgKind::asString() const {
   switch (getArgKind()) {
   case AK_Matcher:
-return (Twine("Matcher<") + MatcherKind.asStringRef() + ">").str();
+return (Twine("Matcher<") + NodeKind.asStringRef() + ">").str();
   case AK_Boolean:
 return "boolean";
+  case AK_Node:
+return NodeKind.asStringRef().str();
   case AK_Double:
 return "double";
   case AK_Unsigned:
@@ -38,13 +40,13 @@

[PATCH] D93844: [clang-format] Add possibility to be based on parent directory

2021-02-01 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 320589.
HazardyKnusperkeks marked an inline comment as done.
HazardyKnusperkeks added a comment.

Fixed documentation (and rebased).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93844

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  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
@@ -17914,6 +17914,111 @@
   auto StyleTd = getStyle("file", "x.td", "llvm", "", &FS);
   ASSERT_TRUE((bool)StyleTd);
   ASSERT_EQ(*StyleTd, getLLVMStyle(FormatStyle::LK_TableGen));
+
+  // Test 9.1: overwriting a file style, when parent no file exists with no
+  // fallback style
+  ASSERT_TRUE(FS.addFile(
+  "/e/sub/.clang-format", 0,
+  llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: InheritParentConfig\n"
+   "ColumnLimit: 20")));
+  ASSERT_TRUE(FS.addFile("/e/sub/code.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+  auto Style9 = getStyle("file", "/e/sub/code.cpp", "none", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getNoStyle();
+Style.ColumnLimit = 20;
+return Style;
+  }());
+
+  // Test 9.2: with LLVM fallback style
+  Style9 = getStyle("file", "/e/sub/code.cpp", "LLVM", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getLLVMStyle();
+Style.ColumnLimit = 20;
+return Style;
+  }());
+
+  // Test 9.3: with a parent file
+  ASSERT_TRUE(
+  FS.addFile("/e/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google\n"
+  "UseTab: Always")));
+  Style9 = getStyle("file", "/e/sub/code.cpp", "none", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getGoogleStyle();
+Style.ColumnLimit = 20;
+Style.UseTab = FormatStyle::UT_Always;
+return Style;
+  }());
+
+  // Test 9.4: propagate more than one level
+  ASSERT_TRUE(FS.addFile("/e/sub/sub/code.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+  ASSERT_TRUE(FS.addFile("/e/sub/sub/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer(
+ "BasedOnStyle: InheritParentConfig\n"
+ "WhitespaceSensitiveMacros: ['FOO', 'BAR']")));
+  std::vector NonDefaultWhiteSpaceMacros{"FOO", "BAR"};
+
+  const auto SubSubStyle = [&NonDefaultWhiteSpaceMacros] {
+auto Style = getGoogleStyle();
+Style.ColumnLimit = 20;
+Style.UseTab = FormatStyle::UT_Always;
+Style.WhitespaceSensitiveMacros = NonDefaultWhiteSpaceMacros;
+return Style;
+  }();
+
+  ASSERT_NE(Style9->WhitespaceSensitiveMacros, NonDefaultWhiteSpaceMacros);
+  Style9 = getStyle("file", "/e/sub/sub/code.cpp", "none", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.5: use InheritParentConfig as style name
+  Style9 =
+  getStyle("inheritparentconfig", "/e/sub/sub/code.cpp", "none", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.6: use command line style with inheritance
+  Style9 = getStyle("{BasedOnStyle: InheritParentConfig}", "/e/sub/code.cpp",
+"none", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.7: use command line style with inheritance and own config
+  Style9 = getStyle("{BasedOnStyle: InheritParentConfig, "
+"WhitespaceSensitiveMacros: ['FOO', 'BAR']}",
+"/e/sub/code.cpp", "none", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, SubSubStyle);
+
+  // Test 9.8: use inheritance from a file without BasedOnStyle
+  ASSERT_TRUE(FS.addFile("/e/withoutbase/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("ColumnLimit: 123")));
+  ASSERT_TRUE(
+  FS.addFile("/e/withoutbase/sub/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer(
+ "BasedOnStyle: InheritParentConfig\nIndentWidth: 7")));
+  // Make sure we do not use the fallback style
+  Style9 = getStyle("file", "/e/withoutbase/code.cpp", "google", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getLLVMStyle();
+Style.ColumnLimit = 123;
+return Style;
+  }());
+
+  Style9 = getStyle("file", "/e/withoutbase/sub/code.cpp", "google", "", &FS);
+  ASSERT_TRUE(static_cast(Style9));
+  ASSERT_EQ(*Style9, [] {
+auto Style = getLLVMStyle();
+Style.ColumnLimit = 123;
+Styl

[PATCH] D92257: [clang-format] Add option to control the space at the front of a line comment

2021-02-01 Thread Björn Schäpers 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 rG772eb24e0062: [clang-format] Add option to control the 
spaces in a line comment (authored by HazardyKnusperkeks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92257

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestComments.cpp

Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3144,7 +3144,7 @@
 "  # commen6\n"
 "  # commen7",
 format("k:val#commen1 commen2\n"
-   " # commen3\n"
+   " #commen3\n"
"# commen4\n"
"a:1#commen5 commen6\n"
" #commen7",
@@ -3275,6 +3275,526 @@
JSStyle20));
 }
 
+TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
+  FormatStyle Style = getLLVMStyle();
+  StringRef NoTextInComment = " //   \n"
+  "\n"
+  "void foo() {// \n"
+  "// \n"
+  "}";
+
+  EXPECT_EQ("//\n"
+"\n"
+"void foo() { //\n"
+"  //\n"
+"}",
+format(NoTextInComment, Style));
+
+  Style.SpacesInLineCommentPrefix.Minimum = 0;
+  EXPECT_EQ("//\n"
+"\n"
+"void foo() { //\n"
+"  //\n"
+"}",
+format(NoTextInComment, Style));
+
+  Style.SpacesInLineCommentPrefix.Minimum = 5;
+  EXPECT_EQ("//\n"
+"\n"
+"void foo() { //\n"
+"  //\n"
+"}",
+format(NoTextInComment, Style));
+
+  Style = getLLVMStyle();
+  StringRef Code =
+  "//Free comment without space\n"
+  "\n"
+  "//   Free comment with 3 spaces\n"
+  "\n"
+  "///Free Doxygen without space\n"
+  "\n"
+  "///   Free Doxygen with 3 spaces\n"
+  "\n"
+  "/// A Doxygen Comment with a nested list:\n"
+  "/// - Foo\n"
+  "/// - Bar\n"
+  "///   - Baz\n"
+  "///   - End\n"
+  "/// of the inner list\n"
+  "///   .\n"
+  "/// .\n"
+  "\n"
+  "namespace Foo {\n"
+  "bool bar(bool b) {\n"
+  "  bool ret1 = true; ///TokenText;
   if (NamespaceTok->is(TT_NamespaceMacro))
 text += "(";
@@ -278,7 +280,8 @@
   EndCommentNextTok->NewlinesBefore == 0 &&
   EndCommentNextTok->isNot(tok::eof);
 const std::string EndCommentText =
-computeEndCommentText(NamespaceName, AddNewline, NamespaceTok);
+computeEndCommentText(NamespaceName, AddNewline, NamespaceTok,
+  Style.SpacesInLineCommentPrefix.Minimum);
 if (!hasEndComment(EndCommentPrevTok)) {
   bool isShort = I - StartLineIndex <= kShortNamespaceMaxLines + 1;
   if (!isShort)
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -661,6 +661,8 @@
Style.SpacesInContainerLiterals);
 IO.mapOptional("SpacesInCStyleCastParentheses",
Style.SpacesInCStyleCastParentheses);
+IO.mapOptional("SpacesInLineCommentPrefix",
+   Style.SpacesInLineCommentPrefix);
 IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
 IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
 IO.mapOptional("SpaceBeforeSquareBrackets",
@@ -710,6 +712,20 @@
   }
 };
 
+template <> struct MappingTraits {
+  static void mapping(IO &IO, FormatStyle::SpacesInLineComment &Space) {
+// Transform the maximum to signed, to parse "-1" correctly
+int signedMaximum = static_cast(Space.Maximum);
+IO.mapOptional("Minimum", Space.Minimum);
+IO.mapOptional("Maximum", signedMaximum);
+Space.Maximum = static_cast(signedMaximum);
+
+if (Space.Maximum != -1u) {
+  Space.Minimum = std::min(Space.Minimum, Space.Maximum);
+}
+  }
+};
+
 // Allows to read vector while keeping default values.
 // IO.getContext() should contain a pointer to the FormatStyle structure, that
 // will be used to get default values for missing keys.
@@ -986,6 +1002,7 @@
   LLVMStyle.SpaceInEmptyParentheses = false;
   LLVMStyle.SpacesInContainerLiterals = true;
   LLVMStyle.SpacesInCStyleCastParentheses = false;
+  LLVMStyle.SpacesInLineCommentPrefix = {/

[clang] 772eb24 - [clang-format] Add option to control the spaces in a line comment

2021-02-01 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2021-02-01T22:48:50+01:00
New Revision: 772eb24e00629faaae0244aa0d6d6204542c579b

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

LOG: [clang-format] Add option to control the spaces in a line comment

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/BreakableToken.cpp
clang/lib/Format/BreakableToken.h
clang/lib/Format/Format.cpp
clang/lib/Format/NamespaceEndCommentsFixer.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3458575119e2..a28efa5dad04 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3335,6 +3335,43 @@ the configuration (without a prefix: ``Auto``).
  var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
  f({a : 1, b : 2, c : 3});  f({a: 1, b: 2, c: 3});
 
+**SpacesInLineCommentPrefix** (``SpacesInLineComment``)
+  How many spaces are allowed at the start of a line comment. To disable the
+  maximum set it to ``-1``, apart from that the maximum takes precedence
+  over the minimum.
+  Minimum = 1 Maximum = -1
+  // One space is forced
+
+  //  but more spaces are possible
+
+  Minimum = 0
+  Maximum = 0
+  //Forces to start every comment directly after the slashes
+
+  Note that in line comment sections the relative indent of the subsequent
+  lines is kept, that means the following:
+
+  .. code-block:: c++
+
+  before:   after:
+  Minimum: 1
+  //if (b) {// if (b) {
+  //  return true;  //   return true;
+  //}   // }
+
+  Maximum: 0
+  /// List: ///List:
+  ///  - Foo/// - Foo
+  ///- Bar  ///   - Bar
+
+  Nested configuration flags:
+
+
+  * ``unsigned Minimum`` The minimum number of spaces at the start of the 
comment.
+
+  * ``unsigned Maximum`` The maximum number of spaces at the start of the 
comment.
+
+
 **SpacesInParentheses** (``bool``)
   If ``true``, spaces will be inserted after ``(`` and before ``)``.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 454355af4c41..6c5c993f98b1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -156,8 +156,8 @@ AST Matchers
 clang-format
 
 
-- ...
-
+- Option ``SpacesInLineCommentPrefix`` has been added to control the
+  number of spaces in a line comments prefix.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 96c2a74e97db..269707fedaac 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2894,6 +2894,43 @@ struct FormatStyle {
   /// \endcode
   bool SpacesInCStyleCastParentheses;
 
+  /// Control of spaces within a single line comment
+  struct SpacesInLineComment {
+/// The minimum number of spaces at the start of the comment.
+unsigned Minimum;
+/// The maximum number of spaces at the start of the comment.
+unsigned Maximum;
+  };
+
+  /// How many spaces are allowed at the start of a line comment. To disable 
the
+  /// maximum set it to ``-1``, apart from that the maximum takes precedence
+  /// over the minimum.
+  /// \code Minimum = 1 Maximum = -1
+  /// // One space is forced
+  ///
+  /// //  but more spaces are possible
+  ///
+  /// Minimum = 0
+  /// Maximum = 0
+  /// //Forces to start every comment directly after the slashes
+  /// \endcode
+  ///
+  /// Note that in line comment sections the relative indent of the subsequent
+  /// lines is kept, that means the following:
+  /// \code
+  /// before:   after:
+  /// Minimum: 1
+  /// //if (b) {// if (b) {
+  /// //  return true;  //   return true;
+  /// //}   // }
+  ///
+  /// Maximum: 0
+  /// /// List: ///List:
+  /// ///  - Foo/// - Foo
+  /// ///- Bar  ///   - Bar
+  /// \endcode
+  SpacesInLineComment SpacesInLineCommentPrefix;
+
   /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
   /// \code
   ///true:  false:
@@ -3145,6 +3182,10 @@ struct FormatStyle {
SpacesInConditionalStatement == R.SpacesInConditionalStatem

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:77-79
+  Builder.defineMacro("M68k");
+  Builder.defineMacro("__M68k__");
+  Builder.defineMacro("__M68K__");

myhsu wrote:
> jrtc27 wrote:
> > Where are these coming from? GCC only defines `__m68k__`.
> I think GCC does: 
> https://github.com/gcc-mirror/gcc/blob/b90d051ecbc1d8972ae1bf0cd7588fcc66df0722/gcc/config/m68k/m68k.h#L64
> 
> Also I found this page: https://sourceforge.net/p/predef/wiki/Architectures
Yes, and as you can see none of those three are defined by GCC. Defining `M68k` 
is particularly bad as it will collide with the C++ namespace used by this very 
backend so you won't be able to build Clang with Clang on m68k! And the others 
are just a waste of time. Defining fewer macros is best, that way people don't 
come to rely on non-standard ones and instead use the single option that exists 
everywhere (`__m68k__`).


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

https://reviews.llvm.org/D88393

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


[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2101
 
+  static const char *const M68kLibDirs[] = {"/lib"};
+  static const char *const M68kTriples[] = {

MaskRay wrote:
> The second `const ` is redundant
I don't think so...first, `const char *const` means "a pointer points to const 
char, and you can't modify this pointer", which make sense in this context. 
Second, all the surrounding code here are using `const char *const`.


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

https://reviews.llvm.org/D88394

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


[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 320586.
myhsu marked 5 inline comments as done.
myhsu added a comment.
Herald added a reviewer: jansvoboda11.

- Addressed feedbacks


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

https://reviews.llvm.org/D88394

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-sub-archs.cpp

Index: clang/test/Driver/m68k-sub-archs.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-sub-archs.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-MX00 %s
+// CHECK-MX00: "-target-cpu" "M68000"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: "-target-cpu" "M68010"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: "-target-cpu" "M68020"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: "-target-cpu" "M68030"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-MX40 %s
+// CHECK-MX40: "-target-cpu" "M68040"
+
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-MX60 %s
+// CHECK-MX60: "-target-cpu" "M68060"
Index: clang/test/Driver/m68k-features.cpp
===
--- /dev/null
+++ clang/test/Driver/m68k-features.cpp
@@ -0,0 +1,45 @@
+// Check macro definitions
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// CHECK-MX: #define __mc68000 1
+// CHECK-MX: #define __mc68000__ 1
+// CHECK-MX: #define mc68000 1
+
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// CHECK-MX10: #define __mc68000 1
+// CHECK-MX10: #define __mc68000__ 1
+// CHECK-MX10: #define __mc68010 1
+// CHECK-MX10: #define __mc68010__ 1
+// CHECK-MX10: #define mc68000 1
+// CHECK-MX10: #define mc68010 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// CHECK-MX20: #define __mc68000 1
+// CHECK-MX20: #define __mc68000__ 1
+// CHECK-MX20: #define __mc68020 1
+// CHECK-MX20: #define __mc68020__ 1
+// CHECK-MX20: #define mc68000 1
+// CHECK-MX20: #define mc68020 1
+
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// CHECK-MX30: #define __mc68000 1
+// CHECK-MX30: #define __mc68000__ 1
+// CHECK-MX30: #define __mc68030 1
+// CHECK-MX30: #define

[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:63
+.Case("generic", CK_68000)
+.Case("M68000", CK_68000)
+.Case("M68010", CK_68010)

jrtc27 wrote:
> GCC's -mcpu excludes any M prefix and is just the number.
we also support -mcpu with just number via `m68k::getM68kTargetCPU`



Comment at: clang/lib/Basic/Targets/M68k.cpp:77-79
+  Builder.defineMacro("M68k");
+  Builder.defineMacro("__M68k__");
+  Builder.defineMacro("__M68K__");

jrtc27 wrote:
> Where are these coming from? GCC only defines `__m68k__`.
I think GCC does: 
https://github.com/gcc-mirror/gcc/blob/b90d051ecbc1d8972ae1bf0cd7588fcc66df0722/gcc/config/m68k/m68k.h#L64

Also I found this page: https://sourceforge.net/p/predef/wiki/Architectures


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

https://reviews.llvm.org/D88393

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2021-02-01 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 320585.
myhsu marked 4 inline comments as done.
myhsu added a comment.

- Addressed feedbacks
  - Now M68k tries to use ABI that is compatible with GCC


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

https://reviews.llvm.org/D88393

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6306,6 +6306,39 @@
   D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind));
 }
 
+static void handleM68kInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgExpr(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant;
+return;
+  }
+
+  // FIXME: Check for decl - it should be void ()(void).
+
+  Expr *NumParamsExpr = static_cast(AL.getArgAsExpr(0));
+  auto MaybeNumParams = NumParamsExpr->getIntegerConstantExpr(S.Context);
+  if (!MaybeNumParams) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIntegerConstant
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  unsigned Num = MaybeNumParams->getLimitedValue(255);
+  if ((Num & 1) || Num > 30) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
+<< AL << (int)MaybeNumParams->getSExtValue()
+<< NumParamsExpr->getSourceRange();
+return;
+  }
+
+  D->addAttr(::new (S.Context) M68kInterruptAttr(S.Context, AL, Num));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}
+
 static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Semantic checks for a function with the 'interrupt' attribute.
   // a) Must be a function.
@@ -6578,6 +6611,9 @@
   case llvm::Triple::mips:
 handleMipsInterruptAttr(S, D, AL);
 break;
+  case llvm::Triple::m68k:
+handleM68kInterruptAttr(S, D, AL);
+break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 handleAnyX86InterruptAttr(S, D, AL);
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8066,6 +8066,43 @@
   return false;
 }
 
+//===--===//
+// M68k ABI Implementation
+//===--===//
+
+namespace {
+
+class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  M68kTargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
+};
+
+} // namespace
+
+void M68kTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (const auto *FD = dyn_cast_or_null(D)) {
+if (const auto *attr = FD->getAttr()) {
+  // Handle 'interrupt' attribute:
+  llvm::Function *F = cast(GV);
+
+  // Step 1: Set ISR calling convention.
+  F->setCallingConv(llvm::CallingConv::M68k_INTR);
+
+  // Step 2: Add attributes goodness.
+  F->addFnAttr(llvm::Attribute::NoInline);
+
+  // Step 3: Emit ISR vector alias.
+  unsigned Num = attr->getNumber() / 2;
+  llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
+"__isr_" + Twine(Num), F);
+}
+  }
+}
+
 //===--===//
 // AVR ABI Implementation.
 //===--===//
@@ -10877,6 +10914,8 @@
 
   case llvm::Triple::le32:
 return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+  case llvm::Triple::m68k:
+return SetCGInfo(new M68kTargetCodeGenInfo(Types));
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
Index: clang/lib/Basic/Targets/M68k.h
===
--- /dev/null
+++ clang/lib/Basic/Targets/M68k.h
@@ -0,0 +1,57 @@
+//===--- M68k.h - Declare M68k target feature support ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares M68k TargetInfo objects.
+//
+//===--

[PATCH] D93844: [clang-format] Add possibility to be based on parent directory

2021-02-01 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks marked 3 inline comments as done.
HazardyKnusperkeks added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:160
+parent directory (or its parent if there is none). If there is no parent
+file found it falls back to the ``LLVM`` style.
+

curdeius wrote:
> Why should it fallback to LLVM and not the fallback style?
> It seems to me that it's a documentation problem.
Yap, fixed that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93844

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


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

2021-02-01 Thread Alexey Bader via Phabricator via cfe-commits
bader added a subscriber: svenvh.
bader added a comment.

> Regarding SYCLDevice and SYCLAddrSpaceMap I am still not very convinced about 
> the flow. Have you had any design discussion regarding this already that you 
> could point to?

We discussed this with you in https://github.com/intel/llvm/pull/1039/.

> My main concern is that I am not sure it fits with the main design of Clang - 
> producing IR that is to be consumed by multiple targets rather than only one 
> specific target or even an external tool. Why do you add a triple component 
> that is used only for one target SPIR:
>
> How would existing toolchains that consume LLVM-IR for SPIR cope with the 
> fact that the Default address space is different for C++ and SYCL.

High level languages differences doesn't matter for toolchains consuming LLVM 
IR - it can python, D or SYCL. Toolchains are assuming that LLVM IR follows the 
sematic defined in SPIR-1.2 document - 
https://www.khronos.org/registry/SPIR/specs/spir_spec-1.2.pdf.

> Why is changing of `the address space map necessary for SPIR but not the 
> other targets?

The main reason is the difference in handling Default address space in C++ for 
OpenCL mode and SYCL. C++ for OpenCL doesn't always deduce address space and 
there are cases when Default is used and SPIR target maps it AS 0 (equivalent 
of SPIR-V Function storage class). This lead to inconsistencies like reported 
here: https://bugs.llvm.org/show_bug.cgi?id=45472.

SYCL doesn't deduce language address space at all relies on mapping Default in 
LLVM AS equivalent of SPIR-V generic.

NOTE: other GPU targets like AMDGPU and NVPTX do the same i.e. maps Default 
language AS to LLVM IR AS equivalent of SPIR-V generic, so there is no need to 
update. I believe SPIR target must apply the same mapping.

We use alternative map to not impact OpenCL language modes.

I provided clang lit tests results for changing the default map below. Most of 
the failures are caused by valid changes in LLVM IR and can be fixed by 
updating FileCheck comments, but there are a few crashes in CodeGen for "C++ 
for OpenCL" mode (with the root cause similar t o 
https://bugs.llvm.org/show_bug.cgi?id=45472). AFAIK, it's the only blocker for 
using unified map for any language mode. @svenvh, do you think we can address 
https://bugs.llvm.org/show_bug.cgi?id=45472 and update SPIRAddrSpaceMap (i.e. 
SPIRAddrSpaceMap[0] <- 4)?

Failed Tests (22):

  Clang :: CodeGen/ext-int-cc.c
  Clang :: CodeGen/spir-half-type.cpp
  Clang :: CodeGenCXX/builtin-calling-conv.cpp
  Clang :: CodeGenOpenCL/addr-space-struct-arg.cl
  Clang :: CodeGenOpenCL/atomic-ops-libcall.cl
  Clang :: CodeGenOpenCL/blocks.cl
  Clang :: CodeGenOpenCL/intel-subgroups-avc-ext-types.cl
  Clang :: CodeGenOpenCL/opencl_types.cl
  Clang :: CodeGenOpenCL/partial_initializer.cl
  Clang :: CodeGenOpenCL/private-array-initialization.cl
  Clang :: CodeGenOpenCL/sampler.cl
  Clang :: CodeGenOpenCL/vectorLoadStore.cl
  Clang :: CodeGenOpenCLCXX/address-space-castoperators.cpp
  Clang :: CodeGenOpenCLCXX/address-space-deduction.cl
  Clang :: CodeGenOpenCLCXX/addrspace-derived-base.cl
  Clang :: CodeGenOpenCLCXX/addrspace-of-this.cl
  Clang :: CodeGenOpenCLCXX/addrspace-operators.cl
  Clang :: CodeGenOpenCLCXX/addrspace-references.cl
  Clang :: CodeGenOpenCLCXX/addrspace-with-class.cl
  Clang :: CodeGenOpenCLCXX/atexit.cl
  Clang :: CodeGenOpenCLCXX/template-address-spaces.cl
  Clang :: Index/pipe-size.cl




Comment at: clang/include/clang/AST/Type.h:499
+other.getAddressSpace()) ||
+   (!hasAddressSpace() &&
+(other.getAddressSpace() == LangAS::sycl_private ||

Anastasia wrote:
> This should be done in the method above.
Will do.



Comment at: clang/include/clang/Sema/ParsedAttr.h:624
 
+  // TBD: SYCL-specific ParsedAttr?
+  /// If this is an OpenCL address space attribute returns its SYCL

Anastasia wrote:
> Do you still plan to resolve this?
> Do you still plan to resolve this?

If re-using OpenCL ParsedAttr is okay, I can just remove this comment. Do you 
think we should add new ParsedAttr for SYCL?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

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


[clang] 68b0595 - NFC: Re-generate out-of-date matchers docs

2021-02-01 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-01T21:25:29Z
New Revision: 68b0595ccb8de1b0a9459f958dda17164341ee87

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

LOG: NFC: Re-generate out-of-date matchers docs

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index ffad8acbeab6..aac02bc4effe 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -721,6 +721,18 @@ Node Matchers
 
 
 
+MatcherDecl>decompositionDeclMatcherDecompositionDecl>...
+Matches 
decomposition-declarations.
+
+Examples matches the declaration node with foo and bar, but not
+number.
+(matcher = declStmt(has(decompositionDecl(
+
+  int number = 42;
+  auto [foo, bar] = std::make_pair{42, 42};
+
+
+
 MatcherDecl>enumConstantDeclMatcherEnumConstantDecl>...
 Matches enum 
constants.
 
@@ -1126,18 +1138,6 @@ Node Matchers
 
 
 
-MatcherDecompositionDecl>decompositionDeclMatcherDecompositionDecl>...
-Matches 
decomposition-declarations.
-
-Examples matches the declaration node with foo and bar, but not
-number.
-(matcher = declStmt(has(decompositionDecl(
-
-  int number = 42;
-  auto [foo, bar] = std::make_pair{42, 42};
-
-
-
 MatcherNestedNameSpecifierLoc>nestedNameSpecifierLocMatcherNestedNameSpecifierLoc>...
 Same as 
nestedNameSpecifier but matches NestedNameSpecifierLoc.
 
@@ -5613,40 +5613,6 @@ AST Traversal Matchers
 
 
 
-Matcher<*>invocationMatcher<*>...Matcher<*>
-Matches function calls 
and constructor calls
-
-Because CallExpr and CXXConstructExpr do not share a common
-base class with API accessing arguments etc, AST Matchers for code
-which should match both are typically duplicated. This matcher
-removes the need for duplication.
-
-Given code
-struct ConstructorTakesInt
-{
-  ConstructorTakesInt(int i) {}
-};
-
-void callTakesInt(int i)
-{
-}
-
-void doCall()
-{
-  callTakesInt(42);
-}
-
-void doConstruct()
-{
-  ConstructorTakesInt cti(42);
-}
-
-The matcher
-invocation(hasArgument(0, integerLiteral(equals(42
-matches the expression in both doCall and doConstruct
-
-
-
 Matcher<*>eachOfMatcher<*>, ..., 
Matcher<*>
 Matches if any of the given 
matchers matches.
 
@@ -5790,6 +5756,40 @@ AST Traversal Matchers
 
 
 
+Matcher<*>invocationMatcher<*>...Matcher<*>
+Matches function calls 
and constructor calls
+
+Because CallExpr and CXXConstructExpr do not share a common
+base class with API accessing arguments etc, AST Matchers for code
+which should match both are typically duplicated. This matcher
+removes the need for duplication.
+
+Given code
+struct ConstructorTakesInt
+{
+  ConstructorTakesInt(int i) {}
+};
+
+void callTakesInt(int i)
+{
+}
+
+void doCall()
+{
+  callTakesInt(42);
+}
+
+void doConstruct()
+{
+  ConstructorTakesInt cti(42);
+}
+
+The matcher
+invocation(hasArgument(0, integerLiteral(equals(42
+matches the expression in both doCall and doConstruct
+
+
+
 Matcher<*>optionallyMatcher<*>
 Matches any node 
regardless of the submatcher.
 



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


[PATCH] D95739: [ASTMatchers] Add matchers for decomposition decls

2021-02-01 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 320578.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95739

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2129,6 +2129,37 @@
   EXPECT_TRUE(matchesObjC(ObjCString, objcFinallyStmt()));
 }
 
+TEST(ASTMatchersTest, DecompositionDecl) {
+  StringRef Code = R"cpp(
+void foo()
+{
+int arr[3];
+auto &[f, s, t] = arr;
+
+f = 42;
+}
+  )cpp";
+  EXPECT_TRUE(matchesConditionally(
+  Code, decompositionDecl(hasBinding(0, bindingDecl(hasName("f", true,
+  {"-std=c++17"}));
+  EXPECT_FALSE(matchesConditionally(
+  Code, decompositionDecl(hasBinding(42, bindingDecl(hasName("f", true,
+  {"-std=c++17"}));
+  EXPECT_FALSE(matchesConditionally(
+  Code, decompositionDecl(hasBinding(0, bindingDecl(hasName("s", true,
+  {"-std=c++17"}));
+  EXPECT_TRUE(matchesConditionally(
+  Code, decompositionDecl(hasBinding(1, bindingDecl(hasName("s", true,
+  {"-std=c++17"}));
+
+  EXPECT_TRUE(matchesConditionally(
+  Code,
+  bindingDecl(decl().bind("self"), hasName("f"),
+  forDecomposition(decompositionDecl(
+  hasAnyBinding(bindingDecl(equalsBoundNode("self")),
+  true, {"-std=c++17"}));
+}
+
 TEST(ASTMatchersTestObjC, ObjCAutoreleasePoolStmt) {
   StringRef ObjCString = "void f() {"
  "@autoreleasepool {"
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -144,6 +144,7 @@
   REGISTER_MATCHER(binaryConditionalOperator);
   REGISTER_MATCHER(binaryOperator);
   REGISTER_MATCHER(binaryOperation);
+  REGISTER_MATCHER(bindingDecl);
   REGISTER_MATCHER(blockDecl);
   REGISTER_MATCHER(blockExpr);
   REGISTER_MATCHER(blockPointerType);
@@ -226,6 +227,7 @@
   REGISTER_MATCHER(exprWithCleanups);
   REGISTER_MATCHER(fieldDecl);
   REGISTER_MATCHER(floatLiteral);
+  REGISTER_MATCHER(forDecomposition);
   REGISTER_MATCHER(forEach);
   REGISTER_MATCHER(forEachArgumentWithParam);
   REGISTER_MATCHER(forEachArgumentWithParamType);
@@ -248,6 +250,7 @@
   REGISTER_MATCHER(hasAncestor);
   REGISTER_MATCHER(hasAnyArgument);
   REGISTER_MATCHER(hasAnyBase);
+  REGISTER_MATCHER(hasAnyBinding);
   REGISTER_MATCHER(hasAnyClause);
   REGISTER_MATCHER(hasAnyConstructorInitializer);
   REGISTER_MATCHER(hasAnyDeclaration);
@@ -266,6 +269,7 @@
   REGISTER_MATCHER(hasAttr);
   REGISTER_MATCHER(hasAutomaticStorageDuration);
   REGISTER_MATCHER(hasBase);
+  REGISTER_MATCHER(hasBinding);
   REGISTER_MATCHER(hasBitWidth);
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -347,6 +347,16 @@
 extern const internal::VariadicDynCastAllOfMatcher
 decompositionDecl;
 
+/// Matches binding declarations
+/// Example matches \c foo and \c bar
+/// (matcher = bindingDecl()
+///
+/// \code
+///   auto [foo, bar] = std::make_pair{42, 42};
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+bindingDecl;
+
 /// Matches a declaration of a linkage specification.
 ///
 /// Given
@@ -7379,6 +7389,80 @@
 Expr::NPC_ValueDependentIsNull);
 }
 
+/// Matches the DecompositionDecl the binding belongs to.
+///
+/// For example, in:
+/// \code
+/// void foo()
+/// {
+/// int arr[3];
+/// auto &[f, s, t] = arr;
+///
+/// f = 42;
+/// }
+/// \endcode
+/// The matcher:
+/// \code
+///   bindingDecl(hasName("f"),
+/// forDecomposition(decompositionDecl())
+/// \endcode
+/// matches 'f' in 'auto &[f, s, t]'.
+AST_MATCHER_P(BindingDecl, forDecomposition, internal::Matcher,
+  InnerMatcher) {
+  if (const ValueDecl *VD = Node.getDecomposedDecl())
+return InnerMatcher.matches(*VD, Finder, Builder);
+  return false;
+}
+
+/// Matches the Nth binding of a DecompositionDecl.
+///
+/// For example, in:
+/// \code
+/// void foo()
+/// {
+/// int arr[3];
+/// auto &[f, s, t] = arr;
+///
+/// f = 42;
+/// }
+/// \endcode
+/// The matcher:
+/// \code
+///   decompositionDecl(hasBinding(0,
+///   bindingDecl(hasName("f").bind("fBinding"
+/// \endcode
+/// matches the decomposition decl with 'f' bound to "fBinding".

[PATCH] D95740: [ASTMatchers] Ignore parts of BindingDecls which are not spelled in source

2021-02-01 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 320572.
steveire added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95740

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2591,6 +2591,48 @@
 Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
 std::make_unique>("allExprs", 1)));
   }
+
+  Code = R"cpp(
+void foo()
+{
+int arr[3];
+auto &[f, s, t] = arr;
+
+f = 42;
+}
+  )cpp";
+  {
+auto M = bindingDecl(hasName("f"));
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_AsIs, M), true, {"-std=c++17"}));
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
+ true, {"-std=c++17"}));
+  }
+  {
+auto M = bindingDecl(hasName("f"), has(expr()));
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_AsIs, M), true, {"-std=c++17"}));
+EXPECT_FALSE(
+matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
+ true, {"-std=c++17"}));
+  }
+  {
+auto M = integerLiteral(hasAncestor(bindingDecl(hasName("f";
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_AsIs, M), true, {"-std=c++17"}));
+EXPECT_FALSE(
+matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
+ true, {"-std=c++17"}));
+  }
+  {
+auto M = declRefExpr(hasAncestor(bindingDecl(hasName("f";
+EXPECT_TRUE(
+matchesConditionally(Code, traverse(TK_AsIs, M), true, {"-std=c++17"}));
+EXPECT_FALSE(
+matchesConditionally(Code, traverse(TK_IgnoreUnlessSpelledInSource, M),
+ true, {"-std=c++17"}));
+  }
 }
 
 TEST(Traversal, traverseNoImplicit) {
Index: clang/unittests/AST/ASTTraverserTest.cpp
===
--- clang/unittests/AST/ASTTraverserTest.cpp
+++ clang/unittests/AST/ASTTraverserTest.cpp
@@ -1148,6 +1148,15 @@
 {
   hasDefaultArg(42);
 }
+
+void decomposition()
+{
+int arr[3];
+auto &[f, s, t] = arr;
+
+f = 42;
+}
+
 )cpp",
{"-std=c++20"});
 
@@ -1443,6 +1452,46 @@
 CallExpr
 |-DeclRefExpr 'hasDefaultArg'
 `-IntegerLiteral
+)cpp");
+  }
+
+  {
+auto FN = ast_matchers::match(
+functionDecl(hasName("decomposition"),
+ hasDescendant(decompositionDecl().bind("decomp"))),
+AST2->getASTContext());
+EXPECT_EQ(FN.size(), 1u);
+
+EXPECT_EQ(
+dumpASTString(TK_AsIs, FN[0].getNodeAs("decomp")),
+R"cpp(
+DecompositionDecl ''
+|-DeclRefExpr 'arr'
+|-BindingDecl 'f'
+| `-ArraySubscriptExpr
+|   |-ImplicitCastExpr
+|   | `-DeclRefExpr ''
+|   `-IntegerLiteral
+|-BindingDecl 's'
+| `-ArraySubscriptExpr
+|   |-ImplicitCastExpr
+|   | `-DeclRefExpr ''
+|   `-IntegerLiteral
+`-BindingDecl 't'
+  `-ArraySubscriptExpr
+|-ImplicitCastExpr
+| `-DeclRefExpr ''
+`-IntegerLiteral
+)cpp");
+
+EXPECT_EQ(dumpASTString(TK_IgnoreUnlessSpelledInSource,
+FN[0].getNodeAs("decomp")),
+  R"cpp(
+DecompositionDecl ''
+|-DeclRefExpr 'arr'
+|-BindingDecl 'f'
+|-BindingDecl 's'
+`-BindingDecl 't'
 )cpp");
   }
 }
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1216,6 +1216,8 @@
   ScopedChildren = true;
 if (FD->isTemplateInstantiation())
   ScopedTraversal = true;
+  } else if (isa(DeclNode)) {
+ScopedChildren = true;
   }
 
   ASTNodeNotSpelledInSourceScope RAII1(this, ScopedTraversal);
Index: clang/include/clang/AST/ASTNodeTraverser.h
===
--- clang/include/clang/AST/ASTNodeTraverser.h
+++ clang/include/clang/AST/ASTNodeTraverser.h
@@ -438,6 +438,8 @@
   }
 
   void VisitBindingDecl(const BindingDecl *D) {
+if (Traversal == TK_IgnoreUnlessSpelledInSource)
+  return;
 if (const auto *E = D->getBinding())
   Visit(E);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95808: [test] Use host platform specific error message substitution in lit tests - continued

2021-02-01 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 320571.
abhina.sreeskantharajan edited the summary of this revision.
abhina.sreeskantharajan added a comment.
Herald added subscribers: rupprecht, arphaman, steven_wu, hiraditya.

I've previously changed Permission denied errors before. Fixing these testcases 
with a lit substitution as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95808

Files:
  clang/test/Analysis/taint-generic.c
  clang/test/Format/style-on-command-line.cpp
  lld/test/COFF/thinlto-emit-imports.ll
  lld/test/ELF/lto/resolution-err.ll
  lld/test/ELF/lto/thinlto-cant-write-index.ll
  lld/test/ELF/lto/thinlto-emit-imports.ll
  llvm/test/tools/llvm-ar/error-opening-permission.test
  llvm/test/tools/llvm-elfabi/fail-file-write.test
  llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
  llvm/utils/lit/lit/llvm/config.py

Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -349,12 +349,18 @@
 if (sys.platform == 'zos'):
 self.config.substitutions.append(('%errc_ENOENT', '\'EDC5129I No such file or directory.\''))
 self.config.substitutions.append(('%errc_EISDIR', '\'EDC5123I Is a directory.\''))
+self.config.substitutions.append(('%errc_EINVAL', '\'EDC5121I Invalid argument.\''))
+self.config.substitutions.append(('%errc_EACCES', '\'EDC5111I Permission denied.\''))
 elif (sys.platform == 'win32'):
 self.config.substitutions.append(('%errc_ENOENT', '\'no such file or directory\''))
 self.config.substitutions.append(('%errc_EISDIR', '\'is a directory\''))
+self.config.substitutions.append(('%errc_EINVAL', '\'invalid argument\''))
+self.config.substitutions.append(('%errc_EACCES', '\'permission denied\''))
 else:
 self.config.substitutions.append(('%errc_ENOENT', '\'No such file or directory\''))
 self.config.substitutions.append(('%errc_EISDIR', '\'Is a directory\''))
+self.config.substitutions.append(('%errc_EINVAL', '\'Invalid argument\''))
+self.config.substitutions.append(('%errc_EACCES', '\'Permission denied\''))
 
 def use_default_substitutions(self):
 tool_patterns = [
Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
===
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
+++ llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
@@ -225,12 +225,12 @@
 
 ## h) Test that yaml2obj emits an error if 'Descriptor' is missing.
 
-# RUN: not yaml2obj --docnum=8 %s -o %t8.o 2>&1 | FileCheck %s --check-prefix=MISSING-KEY --ignore-case
+# RUN: not yaml2obj --docnum=8 %s -o %t8.o 2>&1 | FileCheck -DMSG=%errc_EINVAL %s --check-prefix=MISSING-KEY --ignore-case
 
 #  MISSING-KEY: YAML:{{.*}}:9: error: missing required key 'Descriptor'
 # MISSING-KEY-NEXT:   - DieOffset: 0x12345678
 # MISSING-KEY-NEXT: ^
-# MISSING-KEY-NEXT: yaml2obj: error: failed to parse YAML input: Invalid argument
+# MISSING-KEY-NEXT: yaml2obj: error: failed to parse YAML input: [[MSG]]
 
 --- !ELF
 FileHeader:
Index: llvm/test/tools/llvm-elfabi/fail-file-write.test
===
--- llvm/test/tools/llvm-elfabi/fail-file-write.test
+++ llvm/test/tools/llvm-elfabi/fail-file-write.test
@@ -5,7 +5,7 @@
 # RUN: mkdir %t.TestDir
 # RUN: touch %t.TestDir/Output.TestFile
 # RUN: chmod 400 %t.TestDir
-# RUN: not llvm-elfabi %s --output-target=elf64-little %t.TestDir/Output.TestFile 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-elfabi %s --output-target=elf64-little %t.TestDir/Output.TestFile 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR
 # RUN: chmod 777 %t.TestDir
 # RUN: rm -rf %t.TestDir
 
@@ -15,4 +15,4 @@
 Symbols: {}
 ...
 
-# ERR: {{.*}}Permission denied{{.*}} when trying to open `{{.*}}.TestDir/Output.TestFile` for writing
+# ERR: [[MSG]] when trying to open `{{.*}}.TestDir/Output.TestFile` for writing
Index: llvm/test/tools/llvm-ar/error-opening-permission.test
===
--- llvm/test/tools/llvm-ar/error-opening-permission.test
+++ llvm/test/tools/llvm-ar/error-opening-permission.test
@@ -9,6 +9,6 @@
 # RUN: llvm-ar rc %t/permission.b %t/1.txt
 # RUN: chmod 100 %t/permission.b
 # RUN: not llvm-ar p %t/permission.b 2>&1 | \
-# RUN:   FileCheck %s --check-prefix=NO-PERMISSION -DARCHIVE=%t/permission.b
+# RUN:   FileCheck %s --check-prefix=NO-PERMISSION -DARCHIVE=%t/permission.b -DMSG=%errc_EACCES
 
-# NO-PERMISSION: error: unable to open '[[ARCHIVE]]': {{.*}}{{[pP]}}ermission denied
+# NO-PERMISSION: error: unable to open '[[ARCHIVE]]': [[MSG]]
Index: lld/test/ELF/lto/thinlto-emi

[PATCH] D95740: [ASTMatchers] Ignore parts of BindingDecls which are not spelled in source

2021-02-01 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2607
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }

aaron.ballman wrote:
> Can you help me to better understand the proposed change? I find this to be 
> surprising behavior -- the thing the user wrote in the source are the binding 
> declarations, the hidden thing they didn't write in the source was the 
> decomposition declaration. e.g., the user introduced some names `f`, `s`, and 
> `t` in the declaration so I would imagine that these *are* spelled in source. 
> What I don't think is necessarily spelled in source is the decomposition 
> declaration for the `int[3]` to bind to. So I was expecting this to be 
> `EXPECT_TRUE` instead of `EXPECT_FALSE`.
> Can you help me to better understand the proposed change? I find this to be 
> surprising behavior -- the thing the user wrote in the source are the binding 
> declarations, the hidden thing they didn't write in the source was the 
> decomposition declaration. e.g., the user introduced some names `f`, `s`, and 
> `t` in the declaration so I would imagine that these *are* spelled in source. 
> What I don't think is necessarily spelled in source is the decomposition 
> declaration for the `int[3]` to bind to. 

Indeed. The `bindingDecl` matches, but the `has(expr())` part does not, after 
this change: https://godbolt.org/z/Mqb9Mx




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95740

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


[PATCH] D95735: [ASTMatchers] Fix matching after generic top-level matcher

2021-02-01 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D95735#2534400 , @aaron.ballman 
wrote:

> I'm a bit confused -- I only get one match when I try out your example: 
> https://godbolt.org/z/xn9efY Are there other changes in-flight that 
> necessitate this, or is something else going on?

Yes, only `IgnoreUnlessSpelledInSource` mode is affected: 
https://godbolt.org/z/ffareK


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95735

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


[PATCH] D95403: [clang-tidy][analyzer][WIP] Clang-tidy reverse integration into Static Analyzer.

2021-02-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this, I think it's fantastic effort!

> I'll make sure to implement (and hopefully test) a reasonable behavior for 
> all various combinations of CMake flags (eg., clang-tidy enabled/disabled, 
> static analyzer enabled/disabled, static-analyzer-into-clang-tidy integration 
> enabled/disabled, etc.).

Will we be able to stand up a buildbot to explicitly test this configuration?

> This patch introduces a frontend flag -analyzer-tidy-checker=...

FWIW, the usual clang-tidy nomenclature is to call these "checks" rather than 
"checkers", so it might make sense to expose `-analyzer-tidy-checks=...` to be 
analogous to `clang-tidy -checks=...`

> As long as at least one such flag is supplied, ClangTidyContext is 
> instantiated with the given checker list and a clang-tidy AST consumer gets 
> multiplexed with AnalysisConsumer so that to run clang-tidy checkers.

clang-tidy currently runs the clang static analyzer, so I worry a little bit 
about duplicated diagnostics. I assume that we'll disable running the static 
analyzer checks a second time through clang-tidy?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95403

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


[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2021-02-01 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 320568.
hliao added a comment.

- Remove `DeviceManglingNumber` to reduce memory usage.
- Add a table in ASTContext for device lambda mangling numbers if that lamba 
requires.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69322

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/MangleNumberingContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/CXXABI.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ItaniumCXXABI.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGenCUDA/ms-linker-options.cu
  clang/test/CodeGenCUDA/unnamed-types.cu

Index: clang/test/CodeGenCUDA/unnamed-types.cu
===
--- clang/test/CodeGenCUDA/unnamed-types.cu
+++ clang/test/CodeGenCUDA/unnamed-types.cu
@@ -1,12 +1,17 @@
 // RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-linux-gnu -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
+// RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-pc-windows-msvc -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=MSVC
 // RUN: %clang_cc1 -std=c++11 -x hip -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm %s -o - | FileCheck %s --check-prefix=DEVICE
 
 #include "Inputs/cuda.h"
 
 // HOST: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+// HOST: @1 = private unnamed_addr constant [60 x i8] c"_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_\00", align 1
+// Check that, on MSVC, the same device kernel mangling name is generated.
+// MSVC: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+// MSVC: @1 = private unnamed_addr constant [60 x i8] c"_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_\00", align 1
 
 __device__ float d0(float x) {
-  return [](float x) { return x + 2.f; }(x);
+  return [](float x) { return x + 1.f; }(x);
 }
 
 __device__ float d1(float x) {
@@ -14,11 +19,21 @@
 }
 
 // DEVICE: amdgpu_kernel void @_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_(
+// DEVICE: define internal float @_ZZZ2f1PfENKUlS_E_clES_ENKUlfE_clEf(
 template 
 __global__ void k0(float *p, F f) {
   p[0] = f(p[0]) + d0(p[1]) + d1(p[2]);
 }
 
+// DEVICE: amdgpu_kernel void @_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_(
+// DEVICE: define internal float @_ZZ2f1PfENKUlfE_clEf(
+// DEVICE: define internal float @_ZZ2f1PfENKUlffE_clEff(
+// DEVICE: define internal float @_ZZ2f1PfENKUlfE0_clEf(
+template 
+__global__ void k1(float *p, F0 f0, F1 f1, F2 f2) {
+  p[0] = f0(p[0]) + f1(p[1], p[2]) + f2(p[3]);
+}
+
 void f0(float *p) {
   [](float *p) {
 *p = 1.f;
@@ -29,11 +44,17 @@
 // linkages are still required to keep the original `internal` linkage.
 
 // HOST: define internal void @_ZZ2f1PfENKUlS_E_clES_(
-// DEVICE: define internal float @_ZZZ2f1PfENKUlS_E_clES_ENKUlfE_clEf(
 void f1(float *p) {
   [](float *p) {
-k0<<<1,1>>>(p, [] __device__ (float x) { return x + 1.f; });
+k0<<<1,1>>>(p, [] __device__ (float x) { return x + 3.f; });
   }(p);
+  k1<<<1,1>>>(p,
+  [] __device__ (float x) { return x + 4.f; },
+  [] __device__ (float x, float y) { return x * y; },
+  [] __device__ (float x) { return x + 5.f; });
 }
 // HOST: @__hip_register_globals
 // HOST: __hipRegisterFunction{{.*}}@_Z17__device_stub__k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_{{.*}}@0
+// HOST: __hipRegisterFunction{{.*}}@_Z17__device_stub__k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_{{.*}}@1
+// MSVC: __hipRegisterFunction{{.*}}@"??$k0@V@?0???R1?0??f1@@YAXPEAM@Z@QEBA@0@Z@@@YAXPEAMV@?0???R0?0??f1@@YAX0@Z@QEBA@0@Z@@Z{{.*}}@0
+// MSVC: __hipRegisterFunction{{.*}}@"??$k1@V@?0??f1@@YAXPEAM@Z@V@?0??2@YAX0@Z@V@?0??2@YAX0@Z@@@YAXPEAMV@?0??f1@@YAX0@Z@V@?0??1@YAX0@Z@V@?0??1@YAX0@Z@@Z{{.*}}@1
Index: clang/test/CodeGenCUDA/ms-linker-options.cu
===
--- clang/test/CodeGenCUDA/ms-linker-options.cu
+++ clang/test/CodeGenCUDA/ms-linker-options.cu
@@ -2,12 +2,12 @@
 // RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
 // RUN:   | FileCheck -check-prefix=DEV %s
 // RUN: %clang_cc1 -emit-llvm -o - -fms-extensions -x hip %s -triple \
-// RUN:x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+// RUN:x86_64-pc-windows-msvc -aux-triple amdgcn | FileCheck -check-prefix=HOST %s
 // RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -fms-extensions %s \
 // RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
 // RUN:   |

[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

2021-02-01 Thread Sylvain Audi via Phabricator via cfe-commits
saudi added a comment.

Ping!


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

https://reviews.llvm.org/D95099

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


[PATCH] D93110: [analyzer] Implement fine-grained suppressions via attributes

2021-02-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D93110#2529917 , @NoQ wrote:

>> What I want to avoid is having a static analyzer-specific suppression 
>> attribute, and a different one for clang-tidy, and a third one for the 
>> frontend.
>
> Given that there are already multiple suppression mechanisms circulating 
> around (clang-tidy's `// NOLINT`, frontend pragmas, static analyzer's `#ifdef 
> __clang_analyzer__`, now also attribute), i guess a path forward would be to 
> eventually add support for multiple mechanisms everywhere.  This may be 
> tedious to implement but benefits may be well worth it. Consistency across 
> tools is important when tools are used together; for instance, when 
> clang-tidy integrates static analyzer, static analyzer automatically starts 
> supporting `// NOLINT` through clang-tidy's diagnostic consumer magic. This 
> would also be amazing for discoverability: users can keep using their 
> preferred mechanism and it'd just work out of the box when they add a new 
> tool to their arsenal.

To be clear, I'm fine with multiple mechanisms, but not fine with multiple of 
the same mechanisms. e.g., I don't think it's an issue that we can suppress via 
the command line, pragmas, NOLINT comments, and attribute usage, but I do think 
it's a problem if there's one attribute used by clang-tidy and a different 
attribute used by the static analyzer, and a third attribute for clang itself. 
Using different attributes causes users to have to consider what basically 
amount to implementation details of their toolchain and makes it harder to do 
things like integrate clang-tidy and the clang static analyzer together.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93110

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


[PATCH] D95558: [NFC][CUDA] Refactor registering device variable

2021-02-01 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

Couple of minor nits LGTM otherwise,




Comment at: clang/lib/CodeGen/CGCUDANV.cpp:924
+
+void CGNVCUDARuntime::adjustShadowVarLinkage(
+const VarDecl *D, llvm::GlobalValue::LinkageTypes &Linkage) {

yaxunl wrote:
> tra wrote:
> > The name and the functionality do not match -- despite what the name says, 
> > the function will set internal linkage on any var with device-side 
> > attributes.
> > 
> > Rename to `internalizeDeviceSideVars` ?
> done
My suggestion could be improved, too. `Vars` -> `Var` as we're dealing with 
only one VarDecl here.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4270-4271
 } else {
-  // Host-side shadows of external declarations of device-side
-  // global variables become internal definitions. These have to
-  // be internal in order to prevent name conflicts with global
-  // host variables with the same name in a different TUs.
-  if (D->hasAttr() || D->hasAttr()) {
-Linkage = llvm::GlobalValue::InternalLinkage;
-// Shadow variables and their properties must be registered with CUDA
-// runtime. Skip Extern global variables, which will be registered in
-// the TU where they are defined.
-//
-// Don't register a C++17 inline variable. The local symbol can be
-// discarded and referencing a discarded local symbol from outside the
-// comdat (__cuda_register_globals) is disallowed by the ELF spec.
-// TODO: Reject __device__ constexpr and __device__ inline in Sema.
-if (!D->hasExternalStorage() && !D->isInline())
-  getCUDARuntime().registerDeviceVar(D, *GV, !D->hasDefinition(),
- D->hasAttr());
-  } else if (D->hasAttr()) {
-// __shared__ variables are odd. Shadows do get created, but
-// they are not registered with the CUDA runtime, so they
-// can't really be used to access their device-side
-// counterparts. It's not clear yet whether it's nvcc's bug or
-// a feature, but we've got to do the same for compatibility.
-Linkage = llvm::GlobalValue::InternalLinkage;
-  } else if (D->getType()->isCUDADeviceBuiltinSurfaceType() ||
- D->getType()->isCUDADeviceBuiltinTextureType()) {
-// Builtin surfaces and textures and their template arguments are
-// also registered with CUDA runtime.
-Linkage = llvm::GlobalValue::InternalLinkage;
-const ClassTemplateSpecializationDecl *TD =
-cast(
-D->getType()->getAs()->getDecl());
-const TemplateArgumentList &Args = TD->getTemplateArgs();
-if (TD->hasAttr()) {
-  assert(Args.size() == 2 &&
- "Unexpected number of template arguments of CUDA device "
- "builtin surface type.");
-  auto SurfType = Args[1].getAsIntegral();
-  if (!D->hasExternalStorage())
-getCUDARuntime().registerDeviceSurf(D, *GV, !D->hasDefinition(),
-SurfType.getSExtValue());
-} else {
-  assert(Args.size() == 3 &&
- "Unexpected number of template arguments of CUDA device "
- "builtin texture type.");
-  auto TexType = Args[1].getAsIntegral();
-  auto Normalized = Args[2].getAsIntegral();
-  if (!D->hasExternalStorage())
-getCUDARuntime().registerDeviceTex(D, *GV, !D->hasDefinition(),
-   TexType.getSExtValue(),
-   Normalized.getZExtValue());
-}
-  }
+  getCUDARuntime().internalizeDeviceSideVars(D, Linkage);
+  getCUDARuntime().handleVarRegistration(D, *GV);
 }

Should we fold `internalizeDeviceSideVar` into `handleVarRegistration` or call 
it from there?
I don't think we'll have any independent use for it in CGM.  It seems to be an 
implementation detail for `handleVarRegistration` and may not even need to be 
virtual.



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

https://reviews.llvm.org/D95558

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


[PATCH] D95814: [NFC] Simplify test to use multiple FileCheck prefixes.

2021-02-01 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: aschwaighofer.
varungandhi-apple requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Minor cleanup where we can avoid calling the compiler
twice with the same arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95814

Files:
  clang/test/CodeGen/64bit-swiftcall.c


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=X86-64
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s --check-prefix=ARM64
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=X86-64
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM64
 
 // REQUIRES: aarch64-registered-target,x86-registered-target
 


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=X86-64
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM64
 
 // REQUIRES: aarch64-registered-target,x86-registered-target
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

Thanks!


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

https://reviews.llvm.org/D76802

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


[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 320563.
usaxena95 added a comment.

Move Index query to more logical place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95812

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1850,14 +1850,14 @@
   R"cpp(
 class Base {
 public:
-  virtual void [[f^unc]]() = 0;
+  virtual void [[f^unc]]();
 };
 class Derived : public Base {
 public:
   void [[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   Annotations T(Test);
   auto TU = TestTU::withCode(T.code());
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1332,26 +1332,19 @@
   if (auto ID = getSymbolID(D))
 Targets.insert(ID);
 
-llvm::DenseSet Overrides;
+RelationsRequest OverriddenBy;
 if (Index) {
-  RelationsRequest FindOverrides;
-  FindOverrides.Predicate = RelationKind::OverriddenBy;
+  OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
-// Special case: virtual void meth^od() = 0 includes refs of overrides.
+// Special case: Inlcude declaration of overridding methods.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isPure())
+  if (CMD->isVirtual())
 if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
   IdentifierAtCursor->location())
   if (auto ID = getSymbolID(CMD))
-FindOverrides.Subjects.insert(ID);
+OverriddenBy.Subjects.insert(ID);
 }
   }
-  if (!FindOverrides.Subjects.empty())
-Index->relations(FindOverrides,
- [&](const SymbolID &Subject, const Symbol &Object) {
-   Overrides.insert(Object.ID);
- });
-  Targets.insert(Overrides.begin(), Overrides.end());
 }
 
 // We traverse the AST to find references in the main file.
@@ -1372,8 +1365,17 @@
   Result.uri = URIMainFile;
   Results.References.push_back(std::move(Result));
 }
+// Add declaration of overridding methods.
+if (Index && Results.References.size() <= Limit &&
+!OverriddenBy.Subjects.empty())
+  Index->relations(
+  OverriddenBy, [&](const SymbolID &Subject, const Symbol &Object) {
+if (auto LSPLoc =
+toLSPLocation(Object.CanonicalDeclaration, *MainFilePath))
+  Results.References.push_back(std::move(*LSPLoc));
+  });
+
 if (Index && Results.References.size() <= Limit) {
-  Req.IDs = std::move(Overrides);
   for (const Decl *D : Decls) {
 // Not all symbols can be referenced from outside (e.g.
 // function-locals).
@@ -1386,6 +1388,7 @@
   }
 }
   }
+
   // Now query the index for references from other files.
   if (!Req.IDs.empty() && Index && Results.References.size() <= Limit) {
 Req.Limit = Limit;


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1850,14 +1850,14 @@
   R"cpp(
 class Base {
 public:
-  virtual void [[f^unc]]() = 0;
+  virtual void [[f^unc]]();
 };
 class Derived : public Base {
 public:
   void [[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   Annotations T(Test);
   auto TU = TestTU::withCode(T.code());
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1332,26 +1332,19 @@
   if (auto ID = getSymbolID(D))
 Targets.insert(ID);
 
-llvm::DenseSet Overrides;
+RelationsRequest OverriddenBy;
 if (Index) {
-  RelationsRequest FindOverrides;
-  FindOverrides.Predicate = RelationKind::OverriddenBy;
+  OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
-// Special case: virtual void meth^od() = 0 includes refs of overrides.
+// Special case: Inlcude declaration of over

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D76802#2534118 , @MaskRay wrote:

> "prevents discarding" is not accurate in the context. `__llvm_prf_*` cannot 
> be discarded because C identifier name input sections are GC roots.
>
> Add "C identifier name input sections are GC roots. In LLD, the 
> SHF_LINK_ORDER flag overrides the C identifier name semantics." in 
> appropriate place.

Done, I have revised the change description.

> This C identifier name GC currently only works with LLD but does no harm to 
> gold/GNU ld.
>
> Do you think `__llvm_prf_*` can link to the text section so that the 
> self-link trick is not needed? 
> (https://sourceware.org/bugzilla/show_bug.cgi?id=27259)

I associated the counter with the function symbol which seems to be working and 
we no longer need the self-link trick.


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

https://reviews.llvm.org/D76802

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


[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 320562.

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

https://reviews.llvm.org/D76802

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/test/profile/instrprof-gc-sections.c
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/icall.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll
  llvm/test/Transforms/PGOProfile/associated.ll
  llvm/test/Transforms/PGOProfile/counter_promo.ll
  llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Index: llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll
@@ -69,7 +69,7 @@
 ; PROMO-NEXT:  %pgocount{{.*}} = load {{.*}} @__profc_foo{{.*}} 4)
 ; PROMO-NEXT: add 
 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}4)
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 bb15: ; preds = %bb14, %bb4
Index: llvm/test/Transforms/PGOProfile/counter_promo.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo.ll
@@ -60,7 +60,7 @@
 ; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}0), i64 %[[LIVEOUT1]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
 ; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
-; PROMO-NOT: @__profc_foo
+; PROMO-NOT: @__profc_foo{{.*}})
 
 
 }
Index: llvm/test/Transforms/PGOProfile/associated.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/associated.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -pgo-instr-gen -instrprof -counter-link-order -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen,instrprof -counter-link-order -S | FileCheck %s
+
+; CHECK: @__profc_foo = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8, !associated !0
+; CHECK: @__profd_foo = private global {{.*}}, section "__llvm_prf_data", align 8, !associated !1
+
+define void @foo() {
+  ret void
+}
+
+; CHECK: !0 = !{void ()* @foo}
+; CHECK: !1 = !{[1 x i64]* @__profc_foo}
Index: llvm/test/Instrumentation/InstrProfiling/linkage.ll
===
--- llvm/test/Instrumentation/InstrProfiling/linkage.ll
+++ llvm/test/Instrumentation/InstrProfiling/linkage.ll
@@ -8,6 +8,8 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s -mtriple=x86_64-unknown-fuchsia -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -counter-link-order -S | FileCheck %s --check-prefixes=LINUX,POSIX,METADATA
 
 ; MACHO: @__llvm_profile_runtime = external global i32
 ; LINUX-NOT: @__llvm_profile_runtime = external global i32
@@ -19,7 +21,9 @@
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
 
 ; POSIX: @__profc_foo = hidden global
+; METADATA-SAME: !associated !0
 ; POSIX: @__profd_foo = hidden global
+; METADATA-SAME: !associated !1
 ; COFF: @__profc_foo = internal global
 ; COFF-NOT: comdat
 ; COFF: @__profd_foo = internal global
@@ -29,7 +33,9 @@
 }
 
 ; POSIX: @__profc_foo_weak = weak hidden global
+; METADATA: !associated !2
 ; POSIX: @__profd_foo_weak = weak hidden global
+; METADATA: !associated !3
 ; COFF: @__profc_foo_weak = internal global
 ; COFF: @__profd_foo_weak = internal global
 define weak void @foo_weak() {
@@ -38,7 +44,9 @@
 }
 
 ; POSIX: @"__profc_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !4
 ; POSIX: @"__profd_linkage.ll:foo_internal" = internal global
+; METADATA-SAME: !associated !5
 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
 define internal void @foo_internal() {
@@ -47,7 +55,9 @@
 }
 
 ; POSIX: @__profc_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !6
 ; POSIX: @__profd_foo_inline = linkonce_odr hidden global
+; METADATA-SAME: !associated !7
 ; COFF: @__profc_foo_inline = internal global{{.*}} section ".lprfc$M", align 8
 ; COFF: @__profd_foo_inline = internal global{{.*}} section ".lprfd$M", align 8
 define linkonce_odr void @foo_inline() {
@@ -56,7 +66,9 @@
 }
 
 ; LINUX: @__profc_foo_extern = linkonce_odr hidden global {{.*

[PATCH] D95812: [clangd] Report only decl of overridding method in xref.

2021-02-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 created this revision.
Herald added subscribers: kadircet, arphaman.
usaxena95 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

See: https://github.com/clangd/clangd/issues/668

  struct A { virtual void foo() = 0; };
  struct B : A { void foo() override; };

Find refs on `A::foo()` will show:

- decls of `A::foo()`
- decls of `B::foo()`
- refs to `A::foo()`
- no refs to `B::foo()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95812

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1850,14 +1850,14 @@
   R"cpp(
 class Base {
 public:
-  virtual void [[f^unc]]() = 0;
+  virtual void [[f^unc]]();
 };
 class Derived : public Base {
 public:
   void [[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   Annotations T(Test);
   auto TU = TestTU::withCode(T.code());
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1298,6 +1298,7 @@
   }
 
   RefsRequest Req;
+  RelationsRequest OverriddenBy;
 
   const auto *IdentifierAtCursor =
   syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
@@ -1332,26 +1333,18 @@
   if (auto ID = getSymbolID(D))
 Targets.insert(ID);
 
-llvm::DenseSet Overrides;
 if (Index) {
-  RelationsRequest FindOverrides;
-  FindOverrides.Predicate = RelationKind::OverriddenBy;
+  OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
-// Special case: virtual void meth^od() = 0 includes refs of overrides.
+// Special case: Inlcude declaration of overridding methods.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isPure())
+  if (CMD->isVirtual())
 if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
   IdentifierAtCursor->location())
   if (auto ID = getSymbolID(CMD))
-FindOverrides.Subjects.insert(ID);
+OverriddenBy.Subjects.insert(ID);
 }
   }
-  if (!FindOverrides.Subjects.empty())
-Index->relations(FindOverrides,
- [&](const SymbolID &Subject, const Symbol &Object) {
-   Overrides.insert(Object.ID);
- });
-  Targets.insert(Overrides.begin(), Overrides.end());
 }
 
 // We traverse the AST to find references in the main file.
@@ -1373,7 +1366,6 @@
   Results.References.push_back(std::move(Result));
 }
 if (Index && Results.References.size() <= Limit) {
-  Req.IDs = std::move(Overrides);
   for (const Decl *D : Decls) {
 // Not all symbols can be referenced from outside (e.g.
 // function-locals).
@@ -1386,6 +1378,15 @@
   }
 }
   }
+  // Add declaration of overridding methods.
+  if (Index && !OverriddenBy.Subjects.empty())
+Index->relations(
+OverriddenBy, [&](const SymbolID &Subject, const Symbol &Object) {
+  if (auto LSPLoc =
+  toLSPLocation(Object.CanonicalDeclaration, *MainFilePath))
+Results.References.push_back(std::move(*LSPLoc));
+});
+
   // Now query the index for references from other files.
   if (!Req.IDs.empty() && Index && Results.References.size() <= Limit) {
 Req.Limit = Limit;


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1850,14 +1850,14 @@
   R"cpp(
 class Base {
 public:
-  virtual void [[f^unc]]() = 0;
+  virtual void [[f^unc]]();
 };
 class Derived : public Base {
 public:
   void [[func]]() override;
 };
 void test(Derived* D) {
-  D->[[func]]();
+  D->func();  // No references to the overrides.
 })cpp";
   Annotations T(Test);
   auto TU = TestTU::withCode(T.code());
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1298,6 +1298,7 @@
   }
 
   RefsRequest Req;
+  RelationsRequest OverriddenBy;
 
   const auto *IdentifierAtCursor =
   syntax::spelledIdentifierTouching(*C

[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

2021-02-01 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:1479
+Unsupported,
+Init,
+C11LoadStore,

yaxunl wrote:
> rjmccall wrote:
> > `atomic_init` is not actually an atomic operation, so there's never an 
> > inherent reason it can't be supported.
> > 
> > In general, I am torn about this list, because it's simultaneously rather 
> > fine-grained while not seeming nearly fine-grained enough to be truly 
> > general.  What's actually going on on your target?  You have ISA support 
> > for doing some specific operations atomically, but not a general atomic 
> > compare-and-swap operation?  Which means that you then cannot support 
> > support other operations?
> > 
> > It is unfortunate that our layering prevents TargetInfo from simply being 
> > passed the appropriate expression.
> The target hook getAtomicSupport needs an argument for atomic operation. 
> Since not all targets support fp add/sub, we need an enum for add/sub. Since 
> certain release of iOS/macOS does not support C11 load/store, we need an enum 
> for C11 load/store. We could define the enums as {AddSub, C11LoadStore, 
> Other}. However, this would cause a difficulty for emitting diagnostic 
> message for unsupported atomic operations since we map this enum to a string 
> for the atomic operation and use it in the diagnostic message. 'Other' would 
> be mapped to 'other atomic operation' which is not clear what it is.
It's not obviously true that not all targets support FP add/sub, though.  Any 
target that provides compare-and-swap at the width of an FP type can do an 
atomic FP add/sub at that width; it might be less efficient than it would be 
with specific ISA support, but that's true for a lot of atomic operations.  
Surely it's better to just fix whatever bugs LLVM has with lowering atomic FP 
add/sub than to add more abstraction to Clang to handle a special case that 
shouldn't exist.

I don't know what issues Darwin has with C11 load/store; that might be a more 
compelling reason to have this abstraction, although again it seems strange 
that we're outlawing a specific operation when in principle we can just emit it 
less efficiently.



Comment at: clang/lib/Basic/Targets/AArch64.h:143
+}
+  }
 };

yaxunl wrote:
> rjmccall wrote:
> > Why can't targets reliably expand this to an atomic compare-and-exchange if 
> > they support that for the target width?
> There are some bugs in either the middle end or backend causing this not 
> working. For example, half type atomic fadd on amdgcn is not lowered to 
> cmpxchg and the backend has isel failure, bf16 type atomic fadd on arm is not 
> lowered to cmpxchg and the backend has isel failure. The support for each fp 
> type needs to be done case by case. So far there is no target support atomic 
> fadd/sub with half and bf16 type.
Are we legalizing atomicrmw to cmpxchg loops in the backend instead of as LLVM 
IR pass?  That seems like an architectural mistake.  Regardless, this bug 
should just be fixed.


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

https://reviews.llvm.org/D71726

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


[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

2021-02-01 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

I still have the same fundamental objection as before to the parts of this 
patch for prohibiting FP add/sub on some targets.

If a particular LLVM target cannot handle transforming an FP add/sub (or any 
other RMW operations!) into the correct cmpxchg or LL/SC loop, that's a bug in 
the backend which should be fixed. I don't see why we ought to add a bunch of 
functionality in the frontend to workaround this?

(Some of the other changes, e.g. to diagnose lack of support for large atomics 
is useful, though.)


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

https://reviews.llvm.org/D71726

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


[PATCH] D95753: [CoverageMapping] Don't absolutize source paths

2021-02-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D95753#2534061 , @vsk wrote:

> For context, the reason abspaths are used here is because users don't expect 
> coverage results to go missing if the build directory changes (e.g. given `cd 
> A; cc x.c; cd ../B; cc x.c`, the expectation is that coverage for two 
> distinct x.c's is reported).
>
> I think it's important that this continues to work by default. 
> Default-enabling the suggested `-fcoverage-mapping-abspath` option sounds 
> like a workable solution. I haven't kept up with the work on 
> -f(debug-)?compilation-dir, but if that option were specified, it could make 
> sense to make coverage filenames "absolute" (relative to `chroot 
> `).

That's a useful context, thank you!

In the case of debug info, we store the compilation directory 
(`DW_AT_comp_dir`)  separately from the file (`DW_AT_decl_file`) so even if we 
use relative path for the file by default, you can still get the absolute path 
by concatenating it with the directory which is absolute by default. In the 
case of coverage, there's no separate directory field, hence using the absolute 
path by default.

To produce a fully relocatable debug info, you can use `-fdebug-compilation-dir 
.`, but then it's the responsibility of the developer/build system to ensure 
that processing is done from the correct build directory to avoid the issue you 
mentioned. Given that, I think it makes sense to similarly gate the use of 
relative paths in coverage mapping on a flag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95753

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


[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-02-01 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

I saw this on LLVM Weekly, and I like it a lot :)

Now if only Windows could case-correct their SDKs so we didn't need VFS 
overlays and symlinks for the linker...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95534

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


[PATCH] D95808: [test] Use host platform specific error message substitution in lit tests - continued

2021-02-01 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan created this revision.
abhina.sreeskantharajan added reviewers: muiez, fanbo-meng, Kai, jhenderson, 
grimar.
Herald added subscribers: delcypher, emaste.
abhina.sreeskantharajan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

On z/OS, the another error message is not matched correctly in lit tests.

  EDC5121I Invalid argument.

This patch adds a lit substitution to fix it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95808

Files:
  clang/test/Analysis/taint-generic.c
  clang/test/Format/style-on-command-line.cpp
  llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
  llvm/utils/lit/lit/llvm/config.py


Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -349,12 +349,15 @@
 if (sys.platform == 'zos'):
 self.config.substitutions.append(('%errc_ENOENT', '\'EDC5129I No 
such file or directory.\''))
 self.config.substitutions.append(('%errc_EISDIR', '\'EDC5123I Is a 
directory.\''))
+self.config.substitutions.append(('%errc_EINVAL', '\'EDC5121I 
Invalid argument.\''))
 elif (sys.platform == 'win32'):
 self.config.substitutions.append(('%errc_ENOENT', '\'no such file 
or directory\''))
 self.config.substitutions.append(('%errc_EISDIR', '\'is a 
directory\''))
+self.config.substitutions.append(('%errc_EINVAL', '\'invalid 
argument\''))
 else:
 self.config.substitutions.append(('%errc_ENOENT', '\'No such file 
or directory\''))
 self.config.substitutions.append(('%errc_EISDIR', '\'Is a 
directory\''))
+self.config.substitutions.append(('%errc_EINVAL', '\'Invalid 
argument\''))
 
 def use_default_substitutions(self):
 tool_patterns = [
Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
===
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
+++ llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml
@@ -225,12 +225,12 @@
 
 ## h) Test that yaml2obj emits an error if 'Descriptor' is missing.
 
-# RUN: not yaml2obj --docnum=8 %s -o %t8.o 2>&1 | FileCheck %s 
--check-prefix=MISSING-KEY --ignore-case
+# RUN: not yaml2obj --docnum=8 %s -o %t8.o 2>&1 | FileCheck -DMSG=%errc_EINVAL 
%s --check-prefix=MISSING-KEY --ignore-case
 
 #  MISSING-KEY: YAML:{{.*}}:9: error: missing required key 'Descriptor'
 # MISSING-KEY-NEXT:   - DieOffset: 0x12345678
 # MISSING-KEY-NEXT: ^
-# MISSING-KEY-NEXT: yaml2obj: error: failed to parse YAML input: Invalid 
argument
+# MISSING-KEY-NEXT: yaml2obj: error: failed to parse YAML input: [[MSG]]
 
 --- !ELF
 FileHeader:
Index: clang/test/Format/style-on-command-line.cpp
===
--- clang/test/Format/style-on-command-line.cpp
+++ clang/test/Format/style-on-command-line.cpp
@@ -1,7 +1,7 @@
 // RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %s | 
FileCheck -strict-whitespace -check-prefix=CHECK1 %s
 // RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %s | 
FileCheck -strict-whitespace -check-prefix=CHECK2 %s
-// RUN: not clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" 
-fallback-style=LLVM %s 2>&1 | FileCheck -strict-whitespace 
-check-prefix=CHECK3 %s
-// RUN: not clang-format -style="{lsjd}" %s -fallback-style=LLVM 2>&1 | 
FileCheck -strict-whitespace -check-prefix=CHECK4 %s
+// RUN: not clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" 
-fallback-style=LLVM %s 2>&1 | FileCheck -DMSG=%errc_EINVAL -strict-whitespace 
-check-prefix=CHECK3 %s
+// RUN: not clang-format -style="{lsjd}" %s -fallback-style=LLVM 2>&1 | 
FileCheck -DMSG=%errc_EINVAL -strict-whitespace -check-prefix=CHECK4 %s
 // RUN: mkdir -p %t
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK5 %s
@@ -24,8 +24,8 @@
 // CHECK1: {{^int\* i;$}}
 // CHECK2: {{^   int \*i;$}}
 // CHECK3: Unknown value for BasedOnStyle: invalid
-// CHECK3: Error parsing -style: {{I|i}}nvalid argument
-// CHECK4: Error parsing -style: {{I|i}}nvalid argument
+// CHECK3: Error parsing -style: [[MSG]]
+// CHECK4: Error parsing -style: [[MSG]]
 // CHECK5: {{^ int\* i;$}}
 // CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
 // CHECK7: {{^  int\* i;$}}
Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -28,11 +28,11 @@
 // RUN:   -analyzer-checker=alpha.security.taint \
 // RUN:   -analyzer-config \
 // RUN: 

[PATCH] D95534: clang-cl: Invent a /winsysroot concept

2021-02-01 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added subscribers: smeenai, compnerd.
rnk added a comment.

+People who have spent time on cross-compilation Windows sysroots in the past: 
@smeenai @compnerd


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95534

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


[PATCH] D95735: [ASTMatchers] Fix matching after generic top-level matcher

2021-02-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm a bit confused -- I only get one match when I try out your example: 
https://godbolt.org/z/xn9efY Are there other changes in-flight that necessitate 
this, or is something else going on?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95735

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


[PATCH] D95482: [PATCH] [clang] Fix bug 48848 by removing assertion related to recoverFromMSUnqualifiedLookup

2021-02-01 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

Sorry, yeah, I'm OK with this change.




Comment at: clang/test/SemaCXX/lambda-expressions.cpp:671
+#else
+template 
+void Decider(const RT &sp, ET &ep) {

I think it makes more sense for this test to be in its own file since entire 
rest of the test is `#ifndef`ed out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95482

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


[PATCH] D95523: [OpenCL] Add cl_khr_subgroup_ballot to TableGen BIFs

2021-02-01 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:35
+// Enable extensions that are enabled in opencl-c-base.h.
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+#define cl_khr_subgroup_ballot 1

Not related to this patch - I think we should have included `opencl-c-base.h` 
by default when passing `-fdeclare-opencl-builtins` or do you see any issues 
with that?





Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:141
+kernel void extended_subgroup(global uint4 *out) {
+  out[0] = get_sub_group_eq_mask();
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(__OPENCL_CPP_VERSION__)

I appreciate we haven't addressed the standard header testing holistically yet 
and this functionality was added in `opencl-c.h` without testing the functions, 
but would it be better to test each function at least here?

Even though the final goal should be testing all overloads, this is outside of 
the scope of this work that is closing the gap between `opencl-c.h` and this 
experimental function declaration mechanism.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95523

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


[PATCH] D95482: [PATCH] [clang] Fix bug 48848 by removing assertion related to recoverFromMSUnqualifiedLookup

2021-02-01 Thread Melanie Blower 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 rG08d46d50599a: [clang][PATCH] Fix bug 48848 assertion related 
to recoverFromMSUnqualifiedLookup (authored by mibintc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95482

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/lambda-expressions.cpp


Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks 
%s
+// RUN: %clang_cc1 -std=c++17 -fblocks -DSHOW_MS -Wno-unused-value 
-fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify %s
 
+#ifndef SHOW_MS
 namespace std { class type_info; };
 
 namespace ExplicitCapture {
@@ -664,3 +666,22 @@
 
 }
 };
+
+#else
+template 
+void Decider(const RT &sp, ET &ep) {
+  [=](auto i) { ep[i] = sp[i + j]; };
+// expected-error@-1 {{use of undeclared identifier 'j'}}
+}
+
+template  void LS() {
+  int *ep;
+  Decider(5, ep);
+}
+
+void runChapter4()
+{
+  LS(); // expected-note {{in instantiation of}}
+}
+
+#endif
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1176,15 +1176,11 @@
   }
 
   if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
-  inTemplateInstantiation()) {
-
-assert(isa(DC) &&
-   "Trying to get 'this' type from static method?");
+  inTemplateInstantiation() && isa(DC)) {
 
 // This is a lambda call operator that is being instantiated as a default
 // initializer. DC must point to the enclosing class type, so we can 
recover
 // the 'this' type from it.
-
 QualType ClassTy = Context.getTypeDeclType(cast(DC));
 // There are no cv-qualifiers for 'this' within default initializers,
 // per [expr.prim.general]p4.


Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks %s
+// RUN: %clang_cc1 -std=c++17 -fblocks -DSHOW_MS -Wno-unused-value -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify %s
 
+#ifndef SHOW_MS
 namespace std { class type_info; };
 
 namespace ExplicitCapture {
@@ -664,3 +666,22 @@
 
 }
 };
+
+#else
+template 
+void Decider(const RT &sp, ET &ep) {
+  [=](auto i) { ep[i] = sp[i + j]; };
+// expected-error@-1 {{use of undeclared identifier 'j'}}
+}
+
+template  void LS() {
+  int *ep;
+  Decider(5, ep);
+}
+
+void runChapter4()
+{
+  LS(); // expected-note {{in instantiation of}}
+}
+
+#endif
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1176,15 +1176,11 @@
   }
 
   if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
-  inTemplateInstantiation()) {
-
-assert(isa(DC) &&
-   "Trying to get 'this' type from static method?");
+  inTemplateInstantiation() && isa(DC)) {
 
 // This is a lambda call operator that is being instantiated as a default
 // initializer. DC must point to the enclosing class type, so we can recover
 // the 'this' type from it.
-
 QualType ClassTy = Context.getTypeDeclType(cast(DC));
 // There are no cv-qualifiers for 'this' within default initializers,
 // per [expr.prim.general]p4.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 08d46d5 - [clang][PATCH] Fix bug 48848 assertion related to recoverFromMSUnqualifiedLookup

2021-02-01 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2021-02-01T10:56:47-08:00
New Revision: 08d46d50599a7005380e1a9eebb276ceb2b0ad93

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

LOG: [clang][PATCH] Fix bug 48848 assertion related to 
recoverFromMSUnqualifiedLookup

Reviewed By: rnk

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/lambda-expressions.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d91db60f17a0..a708ccd58dd4 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1176,15 +1176,11 @@ QualType Sema::getCurrentThisType() {
   }
 
   if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
-  inTemplateInstantiation()) {
-
-assert(isa(DC) &&
-   "Trying to get 'this' type from static method?");
+  inTemplateInstantiation() && isa(DC)) {
 
 // This is a lambda call operator that is being instantiated as a default
 // initializer. DC must point to the enclosing class type, so we can 
recover
 // the 'this' type from it.
-
 QualType ClassTy = Context.getTypeDeclType(cast(DC));
 // There are no cv-qualifiers for 'this' within default initializers,
 // per [expr.prim.general]p4.

diff  --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 22e0939379f5..03bf13733d7b 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks 
%s
+// RUN: %clang_cc1 -std=c++17 -fblocks -DSHOW_MS -Wno-unused-value 
-fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify %s
 
+#ifndef SHOW_MS
 namespace std { class type_info; };
 
 namespace ExplicitCapture {
@@ -664,3 +666,22 @@ void Test() {
 
 }
 };
+
+#else
+template 
+void Decider(const RT &sp, ET &ep) {
+  [=](auto i) { ep[i] = sp[i + j]; };
+// expected-error@-1 {{use of undeclared identifier 'j'}}
+}
+
+template  void LS() {
+  int *ep;
+  Decider(5, ep);
+}
+
+void runChapter4()
+{
+  LS(); // expected-note {{in instantiation of}}
+}
+
+#endif



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


  1   2   >