[PATCH] D92826: [clang][cli] CompilerInvocationTest: rename member variable in fixture

2020-12-08 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf825ec86e14b: [clang][cli] CompilerInvocationTest: rename 
member variable in fixture (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92826

Files:
  clang/unittests/Frontend/CompilerInvocationTest.cpp

Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -27,7 +27,7 @@
   IntrusiveRefCntPtr Diags;
   SmallVector GeneratedArgs;
   SmallVector GeneratedArgsStorage;
-  CompilerInvocation CInvok;
+  CompilerInvocation Invocation;
 
   const char *operator()(const Twine ) {
 return GeneratedArgsStorage.emplace_back(Arg.str()).c_str();
@@ -40,41 +40,41 @@
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
   const char *Args[] = {"clang", "-xc++"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  ASSERT_TRUE(CInvok.getFrontendOpts().UseTemporary);
+  ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
   const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  ASSERT_FALSE(CInvok.getFrontendOpts().UseTemporary);
+  ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   // Explicitly provided flag.
-  ASSERT_TRUE(CInvok.getLangOpts()->CLUnsafeMath);
+  ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
 
   // Flags directly implied by explicitly provided flag.
-  ASSERT_TRUE(CInvok.getCodeGenOpts().LessPreciseFPMAD);
-  ASSERT_TRUE(CInvok.getLangOpts()->UnsafeFPMath);
+  ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
+  ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath);
 
   // Flag transitively implied by explicitly provided flag.
-  ASSERT_TRUE(CInvok.getLangOpts()->AllowRecip);
+  ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip);
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
   const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
 }
@@ -83,9 +83,9 @@
   const char *TripleCStr = "i686-apple-darwin9";
   const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
 }
@@ -96,9 +96,9 @@
   const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
 "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
@@ -109,9 +109,9 @@
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
@@ -122,9 +122,9 @@
   const char *Args[] = {"clang", "-xc++", "-mrelocation-model",
 RelocationModelCStr, "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Non default relocation 

[clang] 35621cc - [clang][cli] CompilerInvocationTest: add tests for boolean options

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:46+01:00
New Revision: 35621cc2e3b3778abc2bacf37f3b1e9dfac52895

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

LOG: [clang][cli] CompilerInvocationTest: add tests for boolean options

Add more tests of the command line marshalling infrastructure.

The new tests now make a "round-trip": from arguments, to CompilerInvocation 
instance to arguments again in a single test case.

The TODOs are resolved in a follow-up patch.

Depends on D92830.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index c3bdd6bff65c..b0fe11dd8d5b 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -77,6 +77,150 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultTrueSingleFlagUnknownPresent) {
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
+// Boolean option with a keypath that defaults to true.
+// The flag with negative spelling can set the keypath to false.
+// The flag with positive spelling can reset the keypath to true.
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNegChange) {
+  const char *Args[] = {"-fno-autolink"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().Autolink);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentPosReset) {
+  const char *Args[] = {"-fautolink"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
+}
+
+// Boolean option with a keypath that defaults to false.
+// The flag with negative spelling can set the keypath to true.
+// The flag with positive spelling can reset the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegChange) {
+  const char *Args[] = {"-gno-inline-line-tables"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().NoInlineLineTables);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosReset) {
+  const char *Args[] = {"-ginline-line-tables"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
+}
+
+// Boolean option with a keypath that defaults to false.
+// The flag with positive spelling can set the keypath to true.
+// The flag with negative spelling can reset the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNoneX) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosChange) {
+  const char *Args[] = {"-gcodeview-ghash"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().CodeViewGHash);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegReset) {
+  const char *Args[] = {"-gno-codeview-ghash"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
+}
+
+// Boolean option with a keypath that defaults to an arbitrary expression.
+// The flag with positive spelling can set the keypath to true.
+// The flag with negative spelling can set the keypath to false.
+
+// NOTE: The following tests need to be updated 

[PATCH] D92825: [clang][cli] CompilerInvocationTest: join two test fixtures into one

2020-12-08 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf2bb2239252: [clang][cli] CompilerInvocationTest: join two 
test fixtures into one (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92825

Files:
  clang/unittests/Frontend/CompilerInvocationTest.cpp

Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -22,29 +22,22 @@
 using ::testing::StrNe;
 
 namespace {
-struct OptsPopulationTest : public ::testing::Test {
-  IntrusiveRefCntPtr Diags;
-  CompilerInvocation CInvok;
-
-  OptsPopulationTest()
-  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
-};
-
-class CC1CommandLineGenerationTest : public ::testing::Test {
+class CommandLineTest : public ::testing::Test {
 public:
   IntrusiveRefCntPtr Diags;
   SmallVector GeneratedArgs;
   SmallVector GeneratedArgsStorage;
+  CompilerInvocation CInvok;
 
   const char *operator()(const Twine ) {
 return GeneratedArgsStorage.emplace_back(Arg.str()).c_str();
   }
 
-  CC1CommandLineGenerationTest()
+  CommandLineTest()
   : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
 };
 
-TEST_F(OptsPopulationTest, OptIsInitializedWithCustomDefaultValue) {
+TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
   const char *Args[] = {"clang", "-xc++"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -52,7 +45,7 @@
   ASSERT_TRUE(CInvok.getFrontendOpts().UseTemporary);
 }
 
-TEST_F(OptsPopulationTest, OptOfNegativeFlagIsPopulatedWithFalse) {
+TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
   const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -60,7 +53,7 @@
   ASSERT_FALSE(CInvok.getFrontendOpts().UseTemporary);
 }
 
-TEST_F(OptsPopulationTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
+TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -76,10 +69,9 @@
   ASSERT_TRUE(CInvok.getLangOpts()->AllowRecip);
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineFlag) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
   const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -87,11 +79,10 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineSeparate) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
   const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -99,14 +90,12 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
 }
 
-TEST_F(CC1CommandLineGenerationTest,
-   CanGenerateCC1CommandLineSeparateRequiredPresent) {
+TEST_F(CommandLineTest,  CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
 "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -115,13 +104,11 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
 }
 
-TEST_F(CC1CommandLineGenerationTest,
-   CanGenerateCC1CommandLineSeparateRequiredAbsent) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -130,12 +117,11 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineSeparateEnum) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnum) {
   const char *RelocationModelCStr = "static";
   const char *Args[] = {"clang", "-xc++", "-mrelocation-model",
 

[clang] 216d430 - [clang][cli] CompilerInvocationTest: join and add test cases

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 216d43053b4e7327e5f9eb5705a7c8e4f6ae850b

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

LOG: [clang][cli] CompilerInvocationTest: join and add test cases

Depends on D92829.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 7712dd00b191..c3bdd6bff65c 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -38,42 +38,43 @@ class CommandLineTest : public ::testing::Test {
   }
 };
 
-TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
+// Boolean option with a keypath that defaults to true.
+// The only flag with a negative spelling can set the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagNotPresent) {
   const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
-
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
+
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file";
 }
 
-TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
+TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagPresent) {
   const char *Args[] = {"-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
-
   ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
-}
 
-TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
-  const char *Args[] = {"-cl-unsafe-math-optimizations"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
+}
 
-  // Explicitly provided flag.
-  ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
+TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagUnknownPresent) {
+  const char *Args[] = {"-ftemp-file"};
 
-  // Flags directly implied by explicitly provided flag.
-  ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
-  ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  // Flag transitively implied by explicitly provided flag.
-  ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip);
+  // Driver-only flag.
+  ASSERT_TRUE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
@@ -157,75 +158,101 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic";
 }
 
-TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) {
-  const char *Args[] = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file";
-}
-
-TEST_F(CommandLineTest, PresentNegativeFlagGenerated) {
-  const char *Args[] = {"-fno-temp-file"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
-}
+// Tree of boolean options that can be (directly or transitively) implied by
+// their parent:
+//
+//   * -cl-unsafe-math-optimizations
+// * -cl-mad-enable
+// * -menable-unsafe-fp-math
+//   * -freciprocal-math
 
-TEST_F(CommandLineTest, NotPresentAndNotImpliedNotGenerated) {
+TEST_F(CommandLineTest, ImpliedBoolOptionsNoFlagPresent) {
   const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getLangOpts()->CLUnsafeMath);
+  ASSERT_FALSE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
+  ASSERT_FALSE(Invocation.getLangOpts()->UnsafeFPMath);
+  ASSERT_FALSE(Invocation.getLangOpts()->AllowRecip);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  // Missing options are not generated.
+  // Not generated - missing.
   ASSERT_THAT(GeneratedArgs,
   Not(Contains(StrEq("-cl-unsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
   

[clang] 03692ba - [clang][cli] CompilerInvocationTest: check arg parsing does not produce diagnostics

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 03692bae1fc9b6232de7caea3b57ad2f3dc2a9d0

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

LOG: [clang][cli] CompilerInvocationTest: check arg parsing does not produce 
diagnostics

Depends on D92828.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 0eb76a13972c..7712dd00b191 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "llvm/Support/Host.h"
 
 #include "gmock/gmock.h"
@@ -32,7 +33,9 @@ class CommandLineTest : public ::testing::Test {
   }
 
   CommandLineTest()
-  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
+  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions(),
+  new TextDiagnosticBuffer())) 
{
+  }
 };
 
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
@@ -40,6 +43,8 @@ TEST_F(CommandLineTest, 
OptIsInitializedWithCustomDefaultValue) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
@@ -48,6 +53,8 @@ TEST_F(CommandLineTest, 
OptOfNegativeFlagIsPopulatedWithFalse) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
 }
 
@@ -56,6 +63,8 @@ TEST_F(CommandLineTest, 
OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   // Explicitly provided flag.
   ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
 
@@ -72,6 +81,8 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
@@ -83,6 +94,8 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
@@ -95,6 +108,8 @@ TEST_F(CommandLineTest,  
CanGenerateCC1CommandLineSeparateRequiredPresent) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
@@ -108,6 +123,8 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
@@ -119,6 +136,8 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateEnumNonDefault) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Non default relocation model.
@@ -130,6 +149,8 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Default relocation model.
@@ -141,6 +162,8 @@ TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) 
{
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file";
@@ -151,6 +174,8 @@ TEST_F(CommandLineTest, PresentNegativeFlagGenerated) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
@@ 

[clang] 4894e42 - [clang][cli] CompilerInvocationTest: remove unnecessary command line arguments

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 4894e423e7b4b121bd4fb23cdba9870ff0f2a6b6

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

LOG: [clang][cli] CompilerInvocationTest: remove unnecessary command line 
arguments

Depends on D92827.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 39929b8fc032..0eb76a13972c 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -36,7 +36,7 @@ class CommandLineTest : public ::testing::Test {
 };
 
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
-  const char *Args[] = {"clang", "-xc++"};
+  const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -44,7 +44,7 @@ TEST_F(CommandLineTest, 
OptIsInitializedWithCustomDefaultValue) {
 }
 
 TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
-  const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
+  const char *Args[] = {"-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -52,7 +52,7 @@ TEST_F(CommandLineTest, 
OptOfNegativeFlagIsPopulatedWithFalse) {
 }
 
 TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
-  const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
+  const char *Args[] = {"-cl-unsafe-math-optimizations"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -68,7 +68,7 @@ TEST_F(CommandLineTest, 
OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
-  const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
+  const char *Args[] = {"-fmodules-strict-context-hash"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -79,7 +79,7 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
-  const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
+  const char *Args[] = {"-triple", TripleCStr};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -91,8 +91,7 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
 TEST_F(CommandLineTest,  CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
-  const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
-"-"};
+  const char *Args[] = {"-triple", DefaultTriple.c_str()};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -105,7 +104,7 @@ TEST_F(CommandLineTest,  
CanGenerateCC1CommandLineSeparateRequiredPresent) {
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
-  const char *Args[] = {"clang", "-xc++", "-"};
+  const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -116,7 +115,7 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) {
-  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "static", "-"};
+  const char *Args[] = {"-mrelocation-model", "static"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -127,7 +126,7 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateEnumNonDefault) {
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) {
-  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "pic", "-"};
+  const char *Args[] = {"-mrelocation-model", "pic"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -138,7 +137,7 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
 }
 
 TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) {
-  const char *Args[] = {"clang", "-xc++"};
+  const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -148,7 +147,7 @@ TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) 
{
 }
 
 TEST_F(CommandLineTest, PresentNegativeFlagGenerated) {
-  const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
+  const char *Args[] = {"-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -158,7 +157,7 

[clang] 5afff86 - [clang][cli] CompilerInvocationTest: split enum test into two

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 5afff86d26163bc3ba93fb299ccfc2522d3fdc94

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

LOG: [clang][cli] CompilerInvocationTest: split enum test into two

Depends on D92826.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 69a807056f29..39929b8fc032 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -17,9 +17,7 @@ using namespace llvm;
 using namespace clang;
 
 using ::testing::Contains;
-using ::testing::Each;
 using ::testing::StrEq;
-using ::testing::StrNe;
 
 namespace {
 class CommandLineTest : public ::testing::Test {
@@ -117,27 +115,26 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
 }
 
-TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnum) {
-  const char *RelocationModelCStr = "static";
-  const char *Args[] = {"clang", "-xc++", "-mrelocation-model",
-RelocationModelCStr, "-"};
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) {
+  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "static", "-"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  // Non default relocation model
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq(RelocationModelCStr)));
-  GeneratedArgs.clear();
+  // Non default relocation model.
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("static")));
+}
+
+TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) {
+  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "pic", "-"};
 
-  RelocationModelCStr = "pic";
-  Args[3] = RelocationModelCStr;
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CompilerInvocation Invocation2;
-  CompilerInvocation::CreateFromArgs(Invocation2, Args, *Diags);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  Invocation2.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_THAT(GeneratedArgs, Each(StrNe(RelocationModelCStr)));
+  // Default relocation model.
+  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic";
 }
 
 TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) {



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


[clang] f825ec8 - [clang][cli] CompilerInvocationTest: rename member variable in fixture

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: f825ec86e14b1369a9edf382d65259351eae679e

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

LOG: [clang][cli] CompilerInvocationTest: rename member variable in fixture

Depends on D92825.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 0394308e8015..69a807056f29 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -27,7 +27,7 @@ class CommandLineTest : public ::testing::Test {
   IntrusiveRefCntPtr Diags;
   SmallVector GeneratedArgs;
   SmallVector GeneratedArgsStorage;
-  CompilerInvocation CInvok;
+  CompilerInvocation Invocation;
 
   const char *operator()(const Twine ) {
 return GeneratedArgsStorage.emplace_back(Arg.str()).c_str();
@@ -40,41 +40,41 @@ class CommandLineTest : public ::testing::Test {
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
   const char *Args[] = {"clang", "-xc++"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  ASSERT_TRUE(CInvok.getFrontendOpts().UseTemporary);
+  ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
   const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  ASSERT_FALSE(CInvok.getFrontendOpts().UseTemporary);
+  ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   // Explicitly provided flag.
-  ASSERT_TRUE(CInvok.getLangOpts()->CLUnsafeMath);
+  ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
 
   // Flags directly implied by explicitly provided flag.
-  ASSERT_TRUE(CInvok.getCodeGenOpts().LessPreciseFPMAD);
-  ASSERT_TRUE(CInvok.getLangOpts()->UnsafeFPMath);
+  ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
+  ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath);
 
   // Flag transitively implied by explicitly provided flag.
-  ASSERT_TRUE(CInvok.getLangOpts()->AllowRecip);
+  ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip);
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
   const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
 }
@@ -83,9 +83,9 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
   const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
 }
@@ -96,9 +96,9 @@ TEST_F(CommandLineTest,  
CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
 "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
@@ -109,9 +109,9 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // 

[clang] cf2bb22 - [clang][cli] CompilerInvocationTest: join two test fixtures into one

2020-12-08 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: cf2bb2239252c0e1970e646308ae6fb552fcb002

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

LOG: [clang][cli] CompilerInvocationTest: join two test fixtures into one

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index cad27749c38e..0394308e8015 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -22,29 +22,22 @@ using ::testing::StrEq;
 using ::testing::StrNe;
 
 namespace {
-struct OptsPopulationTest : public ::testing::Test {
-  IntrusiveRefCntPtr Diags;
-  CompilerInvocation CInvok;
-
-  OptsPopulationTest()
-  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
-};
-
-class CC1CommandLineGenerationTest : public ::testing::Test {
+class CommandLineTest : public ::testing::Test {
 public:
   IntrusiveRefCntPtr Diags;
   SmallVector GeneratedArgs;
   SmallVector GeneratedArgsStorage;
+  CompilerInvocation CInvok;
 
   const char *operator()(const Twine ) {
 return GeneratedArgsStorage.emplace_back(Arg.str()).c_str();
   }
 
-  CC1CommandLineGenerationTest()
+  CommandLineTest()
   : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
 };
 
-TEST_F(OptsPopulationTest, OptIsInitializedWithCustomDefaultValue) {
+TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
   const char *Args[] = {"clang", "-xc++"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -52,7 +45,7 @@ TEST_F(OptsPopulationTest, 
OptIsInitializedWithCustomDefaultValue) {
   ASSERT_TRUE(CInvok.getFrontendOpts().UseTemporary);
 }
 
-TEST_F(OptsPopulationTest, OptOfNegativeFlagIsPopulatedWithFalse) {
+TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
   const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -60,7 +53,7 @@ TEST_F(OptsPopulationTest, 
OptOfNegativeFlagIsPopulatedWithFalse) {
   ASSERT_FALSE(CInvok.getFrontendOpts().UseTemporary);
 }
 
-TEST_F(OptsPopulationTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
+TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -76,10 +69,9 @@ TEST_F(OptsPopulationTest, 
OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   ASSERT_TRUE(CInvok.getLangOpts()->AllowRecip);
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineFlag) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
   const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -87,11 +79,10 @@ TEST_F(CC1CommandLineGenerationTest, 
CanGenerateCC1CommandLineFlag) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineSeparate) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
   const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -99,14 +90,12 @@ TEST_F(CC1CommandLineGenerationTest, 
CanGenerateCC1CommandLineSeparate) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
 }
 
-TEST_F(CC1CommandLineGenerationTest,
-   CanGenerateCC1CommandLineSeparateRequiredPresent) {
+TEST_F(CommandLineTest,  CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
 "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -115,13 +104,11 @@ TEST_F(CC1CommandLineGenerationTest,
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
 }
 
-TEST_F(CC1CommandLineGenerationTest,
-   CanGenerateCC1CommandLineSeparateRequiredAbsent) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   const std::string DefaultTriple =
   

[PATCH] D92893: [CUDA] Do not diagnose host/device variable access in dependent types.

2020-12-08 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

LGTM if there's a regression test available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92893

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


[PATCH] D92917: [Driver] Pass -plugin-opt=no-new-pass-manager to the linker

2020-12-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: aeubanks, asbirlea, ychen.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

So that if -fno-new-pass-manager is requested for an
-DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=on build, ld.bfd/gold/ld.lld can know to
use the legacy PM.

Actually we only need to pass an option when the specified option is different
from the configured default, but that is difficult to test.  So we conditionally
pass a linker option.

Depends on D92916 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92917

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fnew-pass-manager.c


Index: clang/test/Driver/fnew-pass-manager.c
===
--- clang/test/Driver/fnew-pass-manager.c
+++ clang/test/Driver/fnew-pass-manager.c
@@ -19,7 +19,7 @@
 
 // NEW_LINK:"-plugin-opt=new-pass-manager"
 
-/// TODO Add the negative option and pass it to the linker.
-// RUN: %clang -### -target x86_64 -flto -fno-new-pass-manager %s 2>&1 | 
FileCheck --check-prefixes=LEGACY_LINK %s
+// RUN: %clang -### -target x86_64-linux -flto -fno-new-pass-manager %s 2>&1 | 
FileCheck --check-prefixes=LEGACY_LINK %s
+// RUN: %clang -### -target x86_64-linux -flto=thin 
-fno-experimental-new-pass-manager %s 2>&1 | FileCheck 
--check-prefixes=LEGACY_LINK %s
 
-// LEGACY_LINK-NOT: "-plugin-opt=new-pass-manager"
+// LEGACY_LINK: "-plugin-opt=no-new-pass-manager"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -595,12 +595,13 @@
  Path));
   }
 
-  // Need this flag to turn on new pass manager via Gold plugin.
+  // Pass an option to enable/disable the new pass manager.
   if (Args.hasFlag(options::OPT_fnew_pass_manager,
options::OPT_fno_new_pass_manager,
-   /* Default */ LLVM_ENABLE_NEW_PASS_MANAGER)) {
+   LLVM_ENABLE_NEW_PASS_MANAGER))
 CmdArgs.push_back("-plugin-opt=new-pass-manager");
-  }
+  else
+CmdArgs.push_back("-plugin-opt=no-new-pass-manager");
 
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);


Index: clang/test/Driver/fnew-pass-manager.c
===
--- clang/test/Driver/fnew-pass-manager.c
+++ clang/test/Driver/fnew-pass-manager.c
@@ -19,7 +19,7 @@
 
 // NEW_LINK:"-plugin-opt=new-pass-manager"
 
-/// TODO Add the negative option and pass it to the linker.
-// RUN: %clang -### -target x86_64 -flto -fno-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=LEGACY_LINK %s
+// RUN: %clang -### -target x86_64-linux -flto -fno-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=LEGACY_LINK %s
+// RUN: %clang -### -target x86_64-linux -flto=thin -fno-experimental-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=LEGACY_LINK %s
 
-// LEGACY_LINK-NOT: "-plugin-opt=new-pass-manager"
+// LEGACY_LINK: "-plugin-opt=no-new-pass-manager"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -595,12 +595,13 @@
  Path));
   }
 
-  // Need this flag to turn on new pass manager via Gold plugin.
+  // Pass an option to enable/disable the new pass manager.
   if (Args.hasFlag(options::OPT_fnew_pass_manager,
options::OPT_fno_new_pass_manager,
-   /* Default */ LLVM_ENABLE_NEW_PASS_MANAGER)) {
+   LLVM_ENABLE_NEW_PASS_MANAGER))
 CmdArgs.push_back("-plugin-opt=new-pass-manager");
-  }
+  else
+CmdArgs.push_back("-plugin-opt=no-new-pass-manager");
 
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92915: [Driver] Add -f[no-]new-pass-manager to supersede -f[no-]experimental-new-pass-manager

2020-12-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: aeubanks, reames, rsmith.
Herald added subscribers: dang, steven_wu, hiraditya.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The new PM is considered stable and many downstream groups have adopted it (some
have adopted it for more than two years). Add -fnew-pass-manager to reflect the
fact that it is no longer experimental.

In the future, when the legacy PM eventually goes away,
-fno-experimental-new-pass-manager and -fno-new-pass-manager will be removed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92915

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fnew-pass-manager.c
  clang/test/Driver/gold-lto-new-pass-man.c

Index: clang/test/Driver/gold-lto-new-pass-man.c
===
--- clang/test/Driver/gold-lto-new-pass-man.c
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: touch %t.o
-//
-// RUN: %clang -target ppc64le-unknown-linux -### %t.o -flto 2>&1 \
-// RUN: -Wl,-plugin-opt=foo -O3 \
-// RUN: -fexperimental-new-pass-manager \
-// RUN: | FileCheck %s
-// CHECK: "-plugin-opt=new-pass-manager"
Index: clang/test/Driver/fnew-pass-manager.c
===
--- /dev/null
+++ clang/test/Driver/fnew-pass-manager.c
@@ -0,0 +1,25 @@
+// RUN: %clang -### -c -fno-new-pass-manager -fnew-pass-manager %s 2>&1 | FileCheck --check-prefixes=NOWARN,NEW %s
+// RUN: %clang -### -c -fnew-pass-manager -fno-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=NOWARN,LEGACY %s
+
+/// -f[no-]experimental-new-pass-manager are legacy aliases when the new PM was still experimental.
+// RUN: %clang -### -c -fno-experimental-new-pass-manager -fexperimental-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=NOWARN,NEW %s
+// RUN: %clang -### -c -fexperimental-new-pass-manager -fno-experimental-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=NOWARN,LEGACY %s
+
+// NOWARN-NOT: warning: argument unused
+
+// NEW:-fnew-pass-manager
+// NEW-NOT:-fno-new-pass-manager
+
+// LEGACY: -fno-new-pass-manager
+// LEGACY-NOT: -fnew-pass-manager
+
+/// For full/Thin LTO, -fnew-pass-manager passes -plugin-opt=new-pass-manager to the linker (which may not be LLD).
+// RUN: %clang -### -target x86_64-linux -flto -fnew-pass-manager %s 2>&1 | FileCheck --check-prefixes=NEW_LINK %s
+// RUN: %clang -### -target x86_64-linux -flto=thin -fexperimental-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=NEW_LINK %s
+
+// NEW_LINK:"-plugin-opt=new-pass-manager"
+
+/// TODO Add the negative option and pass it to the linker.
+// RUN: %clang -### -target x86_64 -flto -fno-new-pass-manager %s 2>&1 | FileCheck --check-prefixes=LEGACY_LINK %s
+
+// LEGACY_LINK-NOT: "-plugin-opt=new-pass-manager"
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -469,10 +469,10 @@
 // RUN: %clang -### -fno-experimental-new-pass-manager -fexperimental-new-pass-manager %s 2>&1 | FileCheck --check-prefix=CHECK-PM --check-prefix=CHECK-NEW-PM %s
 // RUN: %clang -### -fexperimental-new-pass-manager -fno-experimental-new-pass-manager %s 2>&1 | FileCheck --check-prefix=CHECK-PM --check-prefix=CHECK-NO-NEW-PM %s
 // CHECK-PM-NOT: argument unused
-// CHECK-NEW-PM: -fexperimental-new-pass-manager
-// CHECK-NEW-PM-NOT: -fno-experimental-new-pass-manager
-// CHECK-NO-NEW-PM: -fno-experimental-new-pass-manager
-// CHECK-NO-NEW-PM-NOT: -fexperimental-new-pass-manager
+// CHECK-NEW-PM: -fnew-pass-manager
+// CHECK-NEW-PM-NOT: -fno-new-pass-manager
+// CHECK-NO-NEW-PM: -fno-new-pass-manager
+// CHECK-NO-NEW-PM-NOT: -fnew-pass-manager
 
 // RUN: %clang -### -S -fstrict-return %s 2>&1 | FileCheck -check-prefix=CHECK-STRICT-RETURN %s
 // RUN: %clang -### -S -fno-strict-return %s 2>&1 | FileCheck -check-prefix=CHECK-NO-STRICT-RETURN %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -596,8 +596,8 @@
   }
 
   // Need this flag to turn on new pass manager via Gold plugin.
-  if (Args.hasFlag(options::OPT_fexperimental_new_pass_manager,
-   options::OPT_fno_experimental_new_pass_manager,
+  if (Args.hasFlag(options::OPT_fnew_pass_manager,
+   options::OPT_fno_new_pass_manager,
/* Default */ LLVM_ENABLE_NEW_PASS_MANAGER)) {
 CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp

Buildbot to listen main branch

2020-12-08 Thread Galina Kistanova via cfe-commits
Hello everyone,

To follow the main branch creation I'm going to update the buildbot to
listen for the changes in this branch and instruct all the workers to
checkout this branch.

No work is required on the workers.

Please check your annotated scripts to make sure it accepts the branch name
from the buildbot, or change it if that's hardcoded.

The staging has been updated today. I forced clean builds just to play it
safe. Please check your bots in the staging area, to make sure everything
is good.

If everything will go well, the production buildbot will be updated on this
Saturday, December, 12th.

Thanks

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


[PATCH] D92617: [DWARF] Allow toolchain to adjust specified DWARF version.

2020-12-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/Driver/cuda-unsupported-debug-options.cu:18
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gembed-source 
2>&1 | FileCheck %s --check-prefix=DWARF-CLAMP
+// CHECK: debug information option 
'{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}'
 is not supported{{.*}} target 'nvptx64-nvidia-cuda'
 // CHECK-NOT: debug information option '{{.*}}' is not supported for target 
'x86

tra wrote:
> dblaikie wrote:
> > What's the purpose of the {{.*}} in this line? 
> The wildcard eats the differences between two warnings -- a generic one:
>  - `warning: debug information option '-glldb' is not supported for target 
> 'nvptx64-nvidia-cuda'` 
> and the more specific one for `-gembed-source` : 
>  - `warning: debug information option '-gembed-source' is not supported. It 
> needs DWARF-5 but target 'nvptx64-nvidia-cuda' only provides DWARF-2.`
> 
> 
Is that necessary? Or is the -gembed-source+CHECK test redundant with/less 
precise than the -gembed-source+DWARF-CLAMP test? (ie: would it be effective 
(not a loss in test coverage) to remove the gembed-source+CHECK test and only 
have the gembed-source+DWARF-CLAMP test, and keep the CHECK line precise as it 
was before for all the CHECK tests)

Effectively: Rather than adding a new RUN line, and generalizing the CHECK over 
the new/old message and checking the new message separately - instead, change 
the existing gembed-source test to use DWARF-CLAMP instead of CHECK, and leave 
everything the same?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92617

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2020-12-08 Thread Alex Orlov via Phabricator via cfe-commits
aorlov updated this revision to Diff 310416.
aorlov added a comment.

Simplify the patch.
@Quuxplusone,
Actually you've pushed me to some thinking of what more syntactic cases it 
could be. And I came to that we can get rid of this hack and simplify the patch 
pretty much. Hope, this fix will be more admissible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/temp/temp.spec/func.spec.cpp
  clang/test/CXX/temp/temp.spec/part.spec.cpp

Index: clang/test/CXX/temp/temp.spec/part.spec.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.spec/part.spec.cpp
@@ -0,0 +1,640 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// C++20 [temp.class.spec] 17.6.5/10:
+//   The usual access checking rules do not apply to non-dependent names used
+//   to specify template arguments of the simple-template-id of the partial
+//   specialization.
+
+// TODO: add test cases for `enum`
+
+// class for tests
+class TestClass {
+public:
+  class PublicClass {};
+  template  class TemplatePublicClass {};
+
+  using AliasPublicClass = unsigned char;
+
+  void publicFunc();
+  void publicFuncOverloaded();
+  void publicFuncOverloaded(int);
+
+  static void publicStaticFunc();
+  static void publicStaticFuncOverloaded();
+  static void publicStaticFuncOverloaded(int);
+
+  static constexpr int publicStaticInt = 42;
+
+protected:
+  // expected-note@+1 8{{declared protected here}}
+  class ProtectedClass {};
+  template  class TemplateProtectedClass {};
+
+  // expected-note@+1 2{{declared protected here}}
+  using AliasProtectedClass = const char;
+
+  // expected-note@+1 3{{declared protected here}}
+  void protectedFunc();
+  void protectedFuncOverloaded();
+  void protectedFuncOverloaded(int);
+
+  // expected-note@+1 2{{declared protected here}}
+  static void protectedStaticFunc();
+  // expected-note@+1 2{{declared protected here}}
+  static void protectedStaticFuncOverloaded();
+  static void protectedStaticFuncOverloaded(int);
+
+  // expected-note@+1 2{{declared protected here}}
+  static constexpr int protectedStaticInt = 43;
+
+private:
+  // expected-note@+1 10{{declared private here}}
+  class PrivateClass {};
+  // expected-note@+1 {{declared private here}}
+  template  class TemplatePrivateClass {};
+
+  using AliasPrivateClass = char *;
+
+  void privateFunc();
+  void privateFuncOverloaded();
+  void privateFuncOverloaded(int);
+
+  static void privateStaticFunc();
+  static void privateStaticFuncOverloaded();
+  static void privateStaticFuncOverloaded(int);
+
+  static constexpr int privateStaticInt = 44;
+};
+
+void globalFunction() {}
+
+//--//
+
+// template declarations for explicit instantiations
+template  class IT1 {};
+template  class IT2 {};
+template  class IT3 {};
+template  class IT4 {};
+template  class IT5 {};
+template  class IT6 {
+  template  class NIT1 {};
+};
+template  class IT7 {};
+template  class IT8 {};
+template  class IT9 {};
+
+// explicit instantiations
+
+// public
+template class IT1;
+template struct IT1>;
+template class IT1;
+template struct IT2;
+template class IT3;
+template struct IT4<::publicFunc>;
+template class IT4<::publicFuncOverloaded>;
+template class IT5<::publicStaticFunc>;
+template class IT5<::publicStaticFuncOverloaded>;
+template class IT5<>;
+template class IT6::template NIT1;
+template class IT7;
+template struct IT7>;
+template class IT8<::publicFunc, TestClass::publicStaticInt>;
+template class IT8<::publicFuncOverloaded, TestClass::publicStaticInt>;
+template class IT9;
+template class IT9;
+template class IT9;
+
+// protected
+template class IT1;
+template struct IT1>;
+template class IT1;
+template struct IT2;
+template class IT3;
+template struct IT4<::protectedFunc>;
+template class IT4<::protectedFuncOverloaded>;
+template class IT5<::protectedStaticFunc>;
+template class IT5<::protectedStaticFuncOverloaded>;
+template class IT6::template NIT1;
+template class IT7;
+template struct IT7>;
+template class IT8<::protectedFunc, TestClass::protectedStaticInt>;
+template class IT8<::protectedFuncOverloaded, TestClass::protectedStaticInt>;
+template class IT9;
+template class IT9;
+template class IT9;
+
+// private
+template class IT1;
+template struct IT1>;
+template class IT1;
+template struct IT2;
+template class IT3;
+template struct IT4<::privateFunc>;
+template class IT4<::privateFuncOverloaded>;
+template class IT5<::privateStaticFunc>;
+template class IT5<::privateStaticFuncOverloaded>;
+template class IT6::template NIT1;
+template class IT7;
+template struct IT7>;
+template class IT8<::privateFunc, TestClass::privateStaticInt>;
+template class 

[PATCH] D85474: Add -fbinutils-version= to gate ELF features on the specified binutils version

2020-12-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85474

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


[PATCH] D92155: Load plugins when creating a CompilerInvocation.

2020-12-08 Thread Yafei Liu via Phabricator via cfe-commits
psionic12 added a comment.

> (One idea we've been playing with is that traversal of the AST usually goes 
> through TranslationUnitDecls::decls_begin(), which triggers loading from the 
> preamble. We could add a stateful flag to DeclContext that causes this to 
> behave like noload_decls_begin instead...)

I agree with that, since the C++20 released the "module" feature, projects with 
PCHs should be a little more common than before, the traverse algorithm should 
not load external source by default... I tried to modify the code, but it seems 
no easy as I though... Currently out team set scopes manually on an AST to 
avoid `decls_begin()` get called. Maybe we should mention this on the documents?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92155

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


[PATCH] D92857: [clang][cli] Don't always emit -f[no-]experimental-new-pass-manager

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

This seems fine to me, I agree this option doesn't need to be present all the 
time. Thanks for clarifying that `-triple` is still there.

@Bigcheese, WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92857

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


[PATCH] D92006: Refactoring the attrubute plugin example to fit the new API

2020-12-08 Thread Yafei Liu via Phabricator via cfe-commits
psionic12 updated this revision to Diff 310401.
psionic12 added a comment.

Fix grammar
Simplify the test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92006

Files:
  clang/examples/Attribute/Attribute.cpp
  clang/test/Frontend/plugin-attribute.cpp

Index: clang/test/Frontend/plugin-attribute.cpp
===
--- clang/test/Frontend/plugin-attribute.cpp
+++ clang/test/Frontend/plugin-attribute.cpp
@@ -1,25 +1,22 @@
-// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -emit-llvm -S %s -o - 2>&1 | FileCheck %s --check-prefix=ATTRIBUTE
-// RUN: not %clang -fplugin=%llvmshlibdir/Attribute%pluginext -emit-llvm -DBAD_ATTRIBUTE -S %s -o - 2>&1 | FileCheck %s --check-prefix=BADATTRIBUTE
+// RUN: split-file %s %t
+// RUN: %clang -cc1 -load %llvmshlibdir/Attribute%pluginext -fsyntax-only -ast-dump -verify %t/good_attr.cpp | FileCheck %s
+// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -fsyntax-only -Xclang -verify %t/bad_attr.cpp
 // REQUIRES: plugins, examples
+//--- good_attr.cpp
+// expected-no-diagnostics
+void fn1a() __attribute__((example)) {}
+[[example]] void fn1b() {}
+[[plugin::example]] void fn1c() {}
+void fn2() __attribute__((example("somestring", 1, 2.0))) {}
+// CHECK-COUNT-4: -AnnotateAttr 0x{{[0-9a-z]+}} {{}} "example"
+// CHECK: -StringLiteral 0x{{[0-9a-z]+}} {{}} 'const char [{{[0-9]+}}]' lvalue "somestring"
+// CHECK: -IntegerLiteral 0x{{[0-9a-z]+}} {{}} 'int' 1
+// CHECK: -FloatingLiteral 0x{{[0-9a-z]+}} {{}} 'double' 2.00e+00
 
-void fn1a() __attribute__((example)) { }
-[[example]] void fn1b() { }
-[[plugin::example]] void fn1c() { }
-void fn2() __attribute__((example("somestring"))) { }
-// ATTRIBUTE: warning: 'example' attribute only applies to functions
-int var1 __attribute__((example("otherstring"))) = 1;
-
-// ATTRIBUTE: [[STR1_VAR:@.+]] = private unnamed_addr constant [10 x i8] c"example()\00"
-// ATTRIBUTE: [[STR2_VAR:@.+]] = private unnamed_addr constant [20 x i8] c"example(somestring)\00"
-// ATTRIBUTE: @llvm.global.annotations = {{.*}}@{{.*}}fn1a{{.*}}[[STR1_VAR]]{{.*}}@{{.*}}fn1b{{.*}}[[STR1_VAR]]{{.*}}@{{.*}}fn1c{{.*}}[[STR1_VAR]]{{.*}}@{{.*}}fn2{{.*}}[[STR2_VAR]]
-
-#ifdef BAD_ATTRIBUTE
+//--- bad_attr.cpp
+int var1 __attribute__((example("otherstring"))) = 1; // expected-warning {{'example' attribute only applies to functions}}
 class Example {
-  // BADATTRIBUTE: error: 'example' attribute only allowed at file scope
-  void __attribute__((example)) fn3();
+  void __attribute__((example)) fn3(); // expected-error {{'example' attribute only allowed at file scope}}
 };
-// BADATTRIBUTE: error: 'example' attribute requires a string
-void fn4() __attribute__((example(123))) { }
-// BADATTRIBUTE: error: 'example' attribute takes no more than 1 argument
-void fn5() __attribute__((example("a","b"))) { }
-#endif
+void fn4() __attribute__((example(123))) { } // expected-error {{'example's first argument should be a string literal}}
+void fn5() __attribute__((example("a","b", 3, 4.0))) { } // expected-error {{'example' attribute only allowed at most three arguments}}
Index: clang/examples/Attribute/Attribute.cpp
===
--- clang/examples/Attribute/Attribute.cpp
+++ clang/examples/Attribute/Attribute.cpp
@@ -23,9 +23,10 @@
 
 struct ExampleAttrInfo : public ParsedAttrInfo {
   ExampleAttrInfo() {
-// Can take an optional string argument (the check that the argument
-// actually is a string happens in handleDeclAttribute).
-OptArgs = 1;
+// Can take up to 15 optional arguments, to emulate accepting a variadic
+// number of arguments. This just illustrates how many arguments a
+// `ParsedAttrInfo` can hold, we will not use that much in this example.
+OptArgs = 15;
 // GNU-style __attribute__(("example")) and C++-style [[example]] and
 // [[plugin::example]] supported.
 static constexpr Spelling S[] = {{ParsedAttr::AS_GNU, "example"},
@@ -39,7 +40,7 @@
 // This attribute appertains to functions only.
 if (!isa(D)) {
   S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)
-<< Attr << "functions";
+  << Attr << "functions";
   return false;
 }
 return true;
@@ -55,23 +56,39 @@
   S.Diag(Attr.getLoc(), ID);
   return AttributeNotApplied;
 }
-// Check if we have an optional string argument.
-StringRef Str = "";
+// We make some rules here:
+// 1. Only accept at most 3 arguments here.
+// 2. The first argument must be a string literal if it exists.
+if (Attr.getNumArgs() > 3) {
+  unsigned ID = S.getDiagnostics().getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "'example' attribute only accepts at most three arguments");
+  S.Diag(Attr.getLoc(), ID);
+  return AttributeNotApplied;
+}
+// If there are arguments, 

[PATCH] D92897: Set legacy pass manager OptBisect to same as NPM OptBisect

2020-12-08 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

Oh and in the description

> This means that when using OptBisect under the NPM it runs twice when it 
> should only run once.

doesn't really make sense. I'd say something like

> e.g. -opt-bisect-limit=1 will run both the first optional optimization pass 
> and the first optional codegen pass, when really it should skip the codegen 
> pass


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92897

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


[PATCH] D92627: Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Thanks for the reviews! Pushed 2878e965af27ce037378a4f0409e89039108c09f 
.




Comment at: clang/include/clang/Basic/DirectoryEntry.h:104
+  bool isSpecialDenseMapKey() const {
+return ME == llvm::DenseMapInfo::getEmptyKey() ||
+   ME == llvm::DenseMapInfo::getTombstoneKey();

dexonsmith wrote:
> jansvoboda11 wrote:
> > Nit: would it make sense to avoid copy-pasting the constructor logic here 
> > (`llvm::DenseMapInfo::getEmptyKey()`) and call the 
> > constructor instead?
> > For example: `isSameRef(DirectoryEntryRef(dense_map_empty_tag{}))`.
> > 
> > The same goes for `FileEntryRef`.
> Yes, that seems decent; I hadn't considered using `isSameRef` when the 
> `MapEntry` is a bogus pointer, but that's probably better too. I'll update 
> this and the instance of that below.
Incorporated those suggestions (and the nit below) in the commit I pushed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92627

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


[PATCH] D92897: Set legacy pass manager OptBisect to same as NPM OptBisect

2020-12-08 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

Thanks for looking into this!

Can you upload the diff with full context (e.g. use `diff -U ` or use 
arcanist to upload)?




Comment at: clang/lib/CodeGen/BackendUtil.cpp:1153
+  // Sets legacy pass manager OptBisect to the same one as npm so passes are 
properly skipped
+  TheModule->getContext().setOptPassGate(SI.getOptBisect());
+

I took another look, if you look in `LLVMContextImpl::getOptPassGate`, it says 
the `OptBisect` instance must outlive the `LLVMContext`, which isn't true here. 
There's actually a global `OptBisect` there that we should use.

So I think we should go the opposite way. The NPM's StandardInstrumentations 
shouldn't contain its own `OptBisect`, it should inspect the IR it's receiving 
to get the IR's `LLVMContext` and call `LLVMContext::getOptPassGate()`.

e.g. after unwrapping `Any` to `Function *`, `F->getContext().getOptPassGate()`.



Comment at: clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c:1
+// Test NPM with -O1/opt-bisect
+//

Something like "Make sure opt-bisect works through both pass managers" is 
probably better.
Also the test name doesn't need "O1" in it, just 
"new-pass-manager-opt-bisect.c" is good



Comment at: clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c:3
+//
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 
-fexperimental-new-pass-manager %s -fdebug-pass-manager -mllvm 
-opt-bisect-limit=-1 -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+

don't need this



Comment at: clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c:3
+//
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 
-fexperimental-new-pass-manager %s -fdebug-pass-manager -mllvm 
-opt-bisect-limit=-1 -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+

aeubanks wrote:
> don't need this
does this actually run the codegen passes? I thought we needed `-emit-obj`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92897

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


[PATCH] D92627: Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
dexonsmith marked an inline comment as done.
Closed by commit rG2878e965af27: Basic: Add hashing support for FileEntryRef 
and DirectoryEntryRef (authored by dexonsmith).

Changed prior to commit:
  https://reviews.llvm.org/D92627?vs=309440=310400#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92627

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  clang/include/clang/Basic/FileEntry.h
  clang/unittests/Basic/FileEntryTest.cpp

Index: clang/unittests/Basic/FileEntryTest.cpp
===
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Basic/FileEntry.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "gtest/gtest.h"
 
@@ -22,11 +23,21 @@
   FileMap Files;
   DirMap Dirs;
 
-  DirectoryEntry D;
-  DirectoryEntryRef DR;
   SmallVector, 5> FEs;
+  SmallVector, 5> DEs;
+  DirectoryEntryRef DR;
 
-  RefMaps() : DR(*Dirs.insert({"dir", D}).first) {}
+  RefMaps() : DR(addDirectory("dir")) {}
+
+  DirectoryEntryRef addDirectory(StringRef Name) {
+DEs.push_back(std::make_unique());
+return DirectoryEntryRef(*Dirs.insert({Name, *DEs.back()}).first);
+  }
+  DirectoryEntryRef addDirectoryAlias(StringRef Name, DirectoryEntryRef Base) {
+return DirectoryEntryRef(
+*Dirs.insert({Name, const_cast(Base.getDirEntry())})
+ .first);
+  }
 
   FileEntryRef addFile(StringRef Name) {
 FEs.push_back(std::make_unique());
@@ -112,4 +123,74 @@
   EXPECT_FALSE(R1.isSameRef(R1Also));
 }
 
+TEST(FileEntryTest, DenseMapInfo) {
+  RefMaps Refs;
+  FileEntryRef R1 = Refs.addFile("1");
+  FileEntryRef R2 = Refs.addFile("2");
+  FileEntryRef R1Also = Refs.addFileAlias("1-also", R1);
+
+  // Insert R1Also first and confirm it "wins".
+  {
+SmallDenseSet Set;
+Set.insert(R1Also);
+Set.insert(R1);
+Set.insert(R2);
+EXPECT_TRUE(Set.find(R1Also)->isSameRef(R1Also));
+EXPECT_TRUE(Set.find(R1)->isSameRef(R1Also));
+EXPECT_TRUE(Set.find(R2)->isSameRef(R2));
+  }
+
+  // Insert R1Also second and confirm R1 "wins".
+  {
+SmallDenseSet Set;
+Set.insert(R1);
+Set.insert(R1Also);
+Set.insert(R2);
+EXPECT_TRUE(Set.find(R1Also)->isSameRef(R1));
+EXPECT_TRUE(Set.find(R1)->isSameRef(R1));
+EXPECT_TRUE(Set.find(R2)->isSameRef(R2));
+  }
+}
+
+TEST(DirectoryEntryTest, isSameRef) {
+  RefMaps Refs;
+  DirectoryEntryRef R1 = Refs.addDirectory("1");
+  DirectoryEntryRef R2 = Refs.addDirectory("2");
+  DirectoryEntryRef R1Also = Refs.addDirectoryAlias("1-also", R1);
+
+  EXPECT_TRUE(R1.isSameRef(DirectoryEntryRef(R1)));
+  EXPECT_TRUE(R1.isSameRef(DirectoryEntryRef(R1.getMapEntry(;
+  EXPECT_FALSE(R1.isSameRef(R2));
+  EXPECT_FALSE(R1.isSameRef(R1Also));
+}
+
+TEST(DirectoryEntryTest, DenseMapInfo) {
+  RefMaps Refs;
+  DirectoryEntryRef R1 = Refs.addDirectory("1");
+  DirectoryEntryRef R2 = Refs.addDirectory("2");
+  DirectoryEntryRef R1Also = Refs.addDirectoryAlias("1-also", R1);
+
+  // Insert R1Also first and confirm it "wins".
+  {
+SmallDenseSet Set;
+Set.insert(R1Also);
+Set.insert(R1);
+Set.insert(R2);
+EXPECT_TRUE(Set.find(R1Also)->isSameRef(R1Also));
+EXPECT_TRUE(Set.find(R1)->isSameRef(R1Also));
+EXPECT_TRUE(Set.find(R2)->isSameRef(R2));
+  }
+
+  // Insert R1Also second and confirm R1 "wins".
+  {
+SmallDenseSet Set;
+Set.insert(R1);
+Set.insert(R1Also);
+Set.insert(R2);
+EXPECT_TRUE(Set.find(R1Also)->isSameRef(R1));
+EXPECT_TRUE(Set.find(R1)->isSameRef(R1));
+EXPECT_TRUE(Set.find(R2)->isSameRef(R2));
+  }
+}
+
 } // end namespace
Index: clang/include/clang/Basic/FileEntry.h
===
--- clang/include/clang/Basic/FileEntry.h
+++ clang/include/clang/Basic/FileEntry.h
@@ -16,6 +16,8 @@
 
 #include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -88,6 +90,12 @@
 return !(LHS == RHS);
   }
 
+  /// Hash code is based on the FileEntry, not the specific named reference,
+  /// just like operator==.
+  friend llvm::hash_code hash_value(FileEntryRef Ref) {
+return llvm::hash_value(());
+  }
+
   struct MapValue;
 
   /// Type used in the StringMap.
@@ -154,6 +162,20 @@
   FileEntryRef(optional_none_tag) : ME(nullptr) {}
   bool hasOptionalValue() const { return ME; }
 
+  friend struct llvm::DenseMapInfo;
+  struct dense_map_empty_tag {};
+  struct dense_map_tombstone_tag {};
+
+  // Private constructors for use by DenseMapInfo.
+  

[clang] 2878e96 - Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T18:10:53-08:00
New Revision: 2878e965af27ce037378a4f0409e89039108c09f

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

LOG: Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

Allow hashing FileEntryRef and DirectoryEntryRef via `hash_value`, and
use that to implement `DenseMapInfo`. This hash should be equal whenever
the entry is the same (the name used to reference it is not relevant).

Also add `DirectoryEntryRef::isSameRef` to simplify the implementation
and facilitate testing.

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

Added: 


Modified: 
clang/include/clang/Basic/DirectoryEntry.h
clang/include/clang/Basic/FileEntry.h
clang/unittests/Basic/FileEntryTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index 4e229962bdcc..e0f4ae28321a 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -15,6 +15,8 @@
 #define LLVM_CLANG_BASIC_DIRECTORYENTRY_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -46,10 +48,19 @@ class DirectoryEntryRef {
 
   StringRef getName() const { return ME->getKey(); }
 
+  /// Hash code is based on the DirectoryEntry, not the specific named
+  /// reference.
+  friend llvm::hash_code hash_value(DirectoryEntryRef Ref) {
+return llvm::hash_value(());
+  }
+
   using MapEntry = llvm::StringMapEntry>;
 
   const MapEntry () const { return *ME; }
 
+  /// Check if RHS referenced the file in exactly the same way.
+  bool isSameRef(DirectoryEntryRef RHS) const { return ME == RHS.ME; }
+
   DirectoryEntryRef() = delete;
   DirectoryEntryRef(const MapEntry ) : ME() {}
 
@@ -80,6 +91,20 @@ class DirectoryEntryRef {
   DirectoryEntryRef(optional_none_tag) : ME(nullptr) {}
   bool hasOptionalValue() const { return ME; }
 
+  friend struct llvm::DenseMapInfo;
+  struct dense_map_empty_tag {};
+  struct dense_map_tombstone_tag {};
+
+  // Private constructors for use by DenseMapInfo.
+  DirectoryEntryRef(dense_map_empty_tag)
+  : ME(llvm::DenseMapInfo::getEmptyKey()) {}
+  DirectoryEntryRef(dense_map_tombstone_tag)
+  : ME(llvm::DenseMapInfo::getTombstoneKey()) {}
+  bool isSpecialDenseMapKey() const {
+return isSameRef(DirectoryEntryRef(dense_map_empty_tag())) ||
+   isSameRef(DirectoryEntryRef(dense_map_tombstone_tag()));
+  }
+
   const MapEntry *ME;
 };
 
@@ -164,6 +189,38 @@ static_assert(
 "Optional should be trivially copyable");
 
 } // end namespace optional_detail
+
+/// Specialisation of DenseMapInfo for DirectoryEntryRef.
+template <> struct DenseMapInfo {
+  static inline clang::DirectoryEntryRef getEmptyKey() {
+return clang::DirectoryEntryRef(
+clang::DirectoryEntryRef::dense_map_empty_tag());
+  }
+
+  static inline clang::DirectoryEntryRef getTombstoneKey() {
+return clang::DirectoryEntryRef(
+clang::DirectoryEntryRef::dense_map_tombstone_tag());
+  }
+
+  static unsigned getHashValue(clang::DirectoryEntryRef Val) {
+return hash_value(Val);
+  }
+
+  static bool isEqual(clang::DirectoryEntryRef LHS,
+  clang::DirectoryEntryRef RHS) {
+// Catch the easy cases: both empty, both tombstone, or the same ref.
+if (LHS.isSameRef(RHS))
+  return true;
+
+// Confirm LHS and RHS are valid.
+if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())
+  return false;
+
+// It's safe to use operator==.
+return LHS == RHS;
+  }
+};
+
 } // end namespace llvm
 
 namespace clang {

diff  --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 75158d44bf5a..8db5446aa8d4 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -16,6 +16,8 @@
 
 #include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -88,6 +90,12 @@ class FileEntryRef {
 return !(LHS == RHS);
   }
 
+  /// Hash code is based on the FileEntry, not the specific named reference,
+  /// just like operator==.
+  friend llvm::hash_code hash_value(FileEntryRef Ref) {
+return llvm::hash_value(());
+  }
+
   struct MapValue;
 
   /// Type used in the StringMap.
@@ -154,6 +162,20 @@ class FileEntryRef {
   FileEntryRef(optional_none_tag) : ME(nullptr) {}
   bool hasOptionalValue() const { return ME; }
 
+  friend struct llvm::DenseMapInfo;
+  struct dense_map_empty_tag 

[PATCH] D91317: Support: Add RedirectingFileSystem::create from simple list of redirections

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75cd8d756d6e: Support: Add RedirectingFileSystem::create 
from simple list of redirections (authored by dexonsmith).

Changed prior to commit:
  https://reviews.llvm.org/D91317?vs=304702=310398#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91317

Files:
  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
@@ -2287,3 +2287,89 @@
   EXPECT_FALSE(FS->exists(_b.path("b")));
   EXPECT_FALSE(FS->exists(_c.path("c")));
 }
+
+TEST(VFSFromRemappedFilesTest, Basic) {
+  IntrusiveRefCntPtr BaseFS =
+  new vfs::InMemoryFileSystem;
+  BaseFS->addFile("//root/b", 0, MemoryBuffer::getMemBuffer("contents of b"));
+  BaseFS->addFile("//root/c", 0, MemoryBuffer::getMemBuffer("contents of c"));
+
+  std::vector> RemappedFiles = {
+  {"//root/a/a", "//root/b"},
+  {"//root/a/b/c", "//root/c"},
+  };
+  auto RemappedFS = vfs::RedirectingFileSystem::create(
+  RemappedFiles, /*UseExternalNames=*/false, *BaseFS);
+
+  auto StatA = RemappedFS->status("//root/a/a");
+  auto StatB = RemappedFS->status("//root/a/b/c");
+  ASSERT_TRUE(StatA);
+  ASSERT_TRUE(StatB);
+  EXPECT_EQ("//root/a/a", StatA->getName());
+  EXPECT_EQ("//root/a/b/c", StatB->getName());
+
+  auto BufferA = RemappedFS->getBufferForFile("//root/a/a");
+  auto BufferB = RemappedFS->getBufferForFile("//root/a/b/c");
+  ASSERT_TRUE(BufferA);
+  ASSERT_TRUE(BufferB);
+  EXPECT_EQ("contents of b", (*BufferA)->getBuffer());
+  EXPECT_EQ("contents of c", (*BufferB)->getBuffer());
+}
+
+TEST(VFSFromRemappedFilesTest, UseExternalNames) {
+  IntrusiveRefCntPtr BaseFS =
+  new vfs::InMemoryFileSystem;
+  BaseFS->addFile("//root/b", 0, MemoryBuffer::getMemBuffer("contents of b"));
+  BaseFS->addFile("//root/c", 0, MemoryBuffer::getMemBuffer("contents of c"));
+
+  std::vector> RemappedFiles = {
+  {"//root/a/a", "//root/b"},
+  {"//root/a/b/c", "//root/c"},
+  };
+  auto RemappedFS = vfs::RedirectingFileSystem::create(
+  RemappedFiles, /*UseExternalNames=*/true, *BaseFS);
+
+  auto StatA = RemappedFS->status("//root/a/a");
+  auto StatB = RemappedFS->status("//root/a/b/c");
+  ASSERT_TRUE(StatA);
+  ASSERT_TRUE(StatB);
+  EXPECT_EQ("//root/b", StatA->getName());
+  EXPECT_EQ("//root/c", StatB->getName());
+
+  auto BufferA = RemappedFS->getBufferForFile("//root/a/a");
+  auto BufferB = RemappedFS->getBufferForFile("//root/a/b/c");
+  ASSERT_TRUE(BufferA);
+  ASSERT_TRUE(BufferB);
+  EXPECT_EQ("contents of b", (*BufferA)->getBuffer());
+  EXPECT_EQ("contents of c", (*BufferB)->getBuffer());
+}
+
+TEST(VFSFromRemappedFilesTest, LastMappingWins) {
+  IntrusiveRefCntPtr BaseFS =
+  new vfs::InMemoryFileSystem;
+  BaseFS->addFile("//root/b", 0, MemoryBuffer::getMemBuffer("contents of b"));
+  BaseFS->addFile("//root/c", 0, MemoryBuffer::getMemBuffer("contents of c"));
+
+  std::vector> RemappedFiles = {
+  {"//root/a", "//root/b"},
+  {"//root/a", "//root/c"},
+  };
+  auto RemappedFSKeepName = vfs::RedirectingFileSystem::create(
+  RemappedFiles, /*UseExternalNames=*/false, *BaseFS);
+  auto RemappedFSExternalName = vfs::RedirectingFileSystem::create(
+  RemappedFiles, /*UseExternalNames=*/true, *BaseFS);
+
+  auto StatKeepA = RemappedFSKeepName->status("//root/a");
+  auto StatExternalA = RemappedFSExternalName->status("//root/a");
+  ASSERT_TRUE(StatKeepA);
+  ASSERT_TRUE(StatExternalA);
+  EXPECT_EQ("//root/a", StatKeepA->getName());
+  EXPECT_EQ("//root/c", StatExternalA->getName());
+
+  auto BufferKeepA = RemappedFSKeepName->getBufferForFile("//root/a");
+  auto BufferExternalA = RemappedFSExternalName->getBufferForFile("//root/a");
+  ASSERT_TRUE(BufferKeepA);
+  ASSERT_TRUE(BufferExternalA);
+  EXPECT_EQ("contents of c", (*BufferKeepA)->getBuffer());
+  EXPECT_EQ("contents of c", (*BufferExternalA)->getBuffer());
+}
Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1272,7 +1272,8 @@
 return true;
   }
 
-  RedirectingFileSystem::Entry *
+public:
+  static RedirectingFileSystem::Entry *
   lookupOrCreateEntry(RedirectingFileSystem *FS, StringRef Name,
   RedirectingFileSystem::Entry *ParentEntry = nullptr) {
 if (!ParentEntry) { // Look for a existent root
@@ -1314,6 +1315,7 @@
 return DE->getLastContent();
   }
 
+private:
   void uniqueOverlayTree(RedirectingFileSystem *FS,
  RedirectingFileSystem::Entry *SrcE,
   

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-08 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder marked 2 inline comments as done.
tmroeder added inline comments.



Comment at: clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c:1
+void f() {
+  int x;

aaron.ballman wrote:
> Should we also have a C++ test for a result-dependent use of _Generic? (We 
> support use of _Generic in C++ as an extension.)
Added in a new file test.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-08 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310394.
tmroeder edited the summary of this revision.
tmroeder added a comment.

Added C++ tests for result-dependent uses, and added that fact to the 
description as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,68 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int 

[PATCH] D92888: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread Duncan P. N. Exon Smith 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 rG5207f19d103d: ADT: Allow IntrusiveRefCntPtr construction 
from std::unique_ptr, NFC (authored by dexonsmith).

Changed prior to commit:
  https://reviews.llvm.org/D92888?vs=310358=310390#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92888

Files:
  clang-tools-extra/clangd/support/ThreadsafeFS.cpp
  clang/lib/Tooling/AllTUsExecution.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
  llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp


Index: llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
===
--- llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
+++ llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
@@ -42,6 +42,17 @@
   EXPECT_EQ(0, NumInstances);
 }
 
+TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
+  EXPECT_EQ(0, NumInstances);
+  {
+auto S1 = std::make_unique();
+IntrusiveRefCntPtr R1 = std::move(S1);
+EXPECT_EQ(1, NumInstances);
+EXPECT_EQ(S1, nullptr);
+  }
+  EXPECT_EQ(0, NumInstances);
+}
+
 struct InterceptRefCounted : public RefCountedBase {
   InterceptRefCounted(bool *Released, bool *Retained)
 : Released(Released), Retained(Retained) {}
Index: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
===
--- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -175,6 +176,11 @@
 S.Obj = nullptr;
   }
 
+  template 
+  IntrusiveRefCntPtr(std::unique_ptr S) : Obj(S.release()) {
+retain();
+  }
+
   template 
   IntrusiveRefCntPtr(const IntrusiveRefCntPtr ) : Obj(S.get()) {
 retain();
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -154,7 +154,7 @@
 : Format(Service.getFormat()) {
   DiagOpts = new DiagnosticOptions();
   PCHContainerOps = std::make_shared();
-  RealFS = llvm::vfs::createPhysicalFileSystem().release();
+  RealFS = llvm::vfs::createPhysicalFileSystem();
   if (Service.canSkipExcludedPPRanges())
 PPSkipMappings =
 std::make_unique();
Index: clang/lib/Tooling/AllTUsExecution.cpp
===
--- clang/lib/Tooling/AllTUsExecution.cpp
+++ clang/lib/Tooling/AllTUsExecution.cpp
@@ -124,7 +124,7 @@
 // Each thread gets an indepent copy of a VFS to allow different
 // concurrent working directories.
 IntrusiveRefCntPtr FS =
-llvm::vfs::createPhysicalFileSystem().release();
+llvm::vfs::createPhysicalFileSystem();
 ClangTool Tool(Compilations, {Path},
std::make_shared(), FS);
 Tool.appendArgumentsAdjuster(Action.second);
Index: clang-tools-extra/clangd/support/ThreadsafeFS.cpp
===
--- clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -87,8 +87,7 @@
   // Avoid using memory-mapped files.
   // FIXME: Try to use a similar approach in Sema instead of relying on
   //propagation of the 'isVolatile' flag through all layers.
-  return new VolatileFileSystem(
-  llvm::vfs::createPhysicalFileSystem().release());
+  return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem());
 }
 } // namespace clangd
 } // namespace clang


Index: llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
===
--- llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
+++ llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
@@ -42,6 +42,17 @@
   EXPECT_EQ(0, NumInstances);
 }
 
+TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
+  EXPECT_EQ(0, NumInstances);
+  {
+auto S1 = std::make_unique();
+IntrusiveRefCntPtr R1 = std::move(S1);
+EXPECT_EQ(1, NumInstances);
+EXPECT_EQ(S1, nullptr);
+  }
+  EXPECT_EQ(0, NumInstances);
+}
+
 struct InterceptRefCounted : public RefCountedBase {
   InterceptRefCounted(bool *Released, bool *Retained)
 : Released(Released), Retained(Retained) {}
Index: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
===
--- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -175,6 +176,11 @@
 S.Obj = nullptr;
   }
 
+  template 
+  

[clang-tools-extra] 5207f19 - ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T17:33:19-08:00
New Revision: 5207f19d103dc3e0ec974fa64d2c031d84d497a8

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

LOG: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`,
and remove a couple of now-unnecessary `release()` calls.

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

Added: 


Modified: 
clang-tools-extra/clangd/support/ThreadsafeFS.cpp
clang/lib/Tooling/AllTUsExecution.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp 
b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index cadda8efa095..ae9450f17411 100644
--- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -87,8 +87,7 @@ RealThreadsafeFS::viewImpl() const {
   // Avoid using memory-mapped files.
   // FIXME: Try to use a similar approach in Sema instead of relying on
   //propagation of the 'isVolatile' flag through all layers.
-  return new VolatileFileSystem(
-  llvm::vfs::createPhysicalFileSystem().release());
+  return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem());
 }
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/lib/Tooling/AllTUsExecution.cpp 
b/clang/lib/Tooling/AllTUsExecution.cpp
index 7707c99c21d0..5565da9b548a 100644
--- a/clang/lib/Tooling/AllTUsExecution.cpp
+++ b/clang/lib/Tooling/AllTUsExecution.cpp
@@ -124,7 +124,7 @@ llvm::Error AllTUsToolExecutor::execute(
 // Each thread gets an indepent copy of a VFS to allow 
diff erent
 // concurrent working directories.
 IntrusiveRefCntPtr FS =
-llvm::vfs::createPhysicalFileSystem().release();
+llvm::vfs::createPhysicalFileSystem();
 ClangTool Tool(Compilations, {Path},
std::make_shared(), FS);
 Tool.appendArgumentsAdjuster(Action.second);

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index f10b60252715..63264b0dda2d 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -154,7 +154,7 @@ DependencyScanningWorker::DependencyScanningWorker(
 : Format(Service.getFormat()) {
   DiagOpts = new DiagnosticOptions();
   PCHContainerOps = std::make_shared();
-  RealFS = llvm::vfs::createPhysicalFileSystem().release();
+  RealFS = llvm::vfs::createPhysicalFileSystem();
   if (Service.canSkipExcludedPPRanges())
 PPSkipMappings =
 std::make_unique();

diff  --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h 
b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
index 173fad3aeafa..dcd35253c5f2 100644
--- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -175,6 +176,11 @@ template  class IntrusiveRefCntPtr {
 S.Obj = nullptr;
   }
 
+  template 
+  IntrusiveRefCntPtr(std::unique_ptr S) : Obj(S.release()) {
+retain();
+  }
+
   template 
   IntrusiveRefCntPtr(const IntrusiveRefCntPtr ) : Obj(S.get()) {
 retain();

diff  --git a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp 
b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
index 3d8041fcbf48..f69239162e3a 100644
--- a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
+++ b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
@@ -42,6 +42,17 @@ TYPED_TEST(IntrusiveRefCntPtrTest, 
RefCountedBaseCopyDoesNotLeak) {
   EXPECT_EQ(0, NumInstances);
 }
 
+TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
+  EXPECT_EQ(0, NumInstances);
+  {
+auto S1 = std::make_unique();
+IntrusiveRefCntPtr R1 = std::move(S1);
+EXPECT_EQ(1, NumInstances);
+EXPECT_EQ(S1, nullptr);
+  }
+  EXPECT_EQ(0, NumInstances);
+}
+
 struct InterceptRefCounted : public RefCountedBase {
   InterceptRefCounted(bool *Released, bool *Retained)
 : Released(Released), Retained(Retained) {}



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


[PATCH] D92893: [CUDA] Do not diagnose host/device variable access in dependent types.

2020-12-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

LGTM. Can we have a test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92893

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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2020-12-08 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2328
+  CGF.CGM.getTarget().getTriple().isAArch64() &&
+  !CGF.CGM.getTarget().getTriple().isOSWindows()) {
+auto *callBase = cast(value);

rjmccall wrote:
> It would be good to explain why this is target-specific in a comment.
I didn't really have a reason for limiting this to arm64 and non-windows OS 
other than I didn't want to do too many things in the initial patch. I don't 
think it would be hard to do this on x86-64. For windows, it looks like we'll 
have to emit the markers and the ARC calls before CodeGen (before WinEHPrepare) 
is run, but I haven't thought it through.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2334
+   IsRetainRV ? "retainRV" : "claimRV");
+if (CGF.CGM.getModule().getModuleFlag(markerKey))
+  attrs = attrs.addAttribute(CGF.getLLVMContext(),

rjmccall wrote:
> Didn't we just add this?  Can that fail to add the marker?
The check for module flag was here because the initial version of this patch 
added the attribute when the target wasn't arm64 (e.g., x86-64) too. I've 
removed the check for now.


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] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2020-12-08 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 310387.
ahatanak marked 2 inline comments as done.
ahatanak edited the summary of this revision.

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/test/CodeGenObjC/arc-rv-attr.m
  clang/test/CodeGenObjC/arc-unsafeclaim.m
  llvm/include/llvm/Analysis/ObjCARCRVAttr.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Transforms/IPO/DeadArgumentElimination.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/Utils/InlineFunction.cpp
  llvm/test/Transforms/DeadArgElim/deadretval.ll
  llvm/test/Transforms/Inline/inline-retainRV-call.ll
  llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
  llvm/test/Transforms/ObjCARC/rv.ll

Index: llvm/test/Transforms/ObjCARC/rv.ll
===
--- llvm/test/Transforms/ObjCARC/rv.ll
+++ llvm/test/Transforms/ObjCARC/rv.ll
@@ -452,6 +452,28 @@
   ret i8* %v3
 }
 
+; Remove attributes 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 "retainRV" "rv_marker" i8* @returner()
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
+; CHECK-LABEL: define i8* @test32(
+; CHECK: %[[CALL:.*]] = call "retainRV" "rv_marker" i8* @returner()
+; CHECK: call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[CALL]])
+
+define i8* @test32() {
+  %call = call "retainRV" "rv_marker" i8* @returner()
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
 !0 = !{}
 
 ; CHECK: attributes [[NUW]] = { nounwind }
Index: llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
===
--- /dev/null
+++ llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
@@ -0,0 +1,63 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+; RUN: opt -passes=objc-arc-contract -S < %s | FileCheck %s
+
+; CHECK-LABEL: define void @test0() {
+; CHECK: %[[CALL:.*]] = notail call "rv_marker" i8* @foo()
+; CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+define void @test0() {
+  %call1 = call "retainRV" "rv_marker" i8* @foo()
+  ret void
+}
+
+; CHECK-LABEL: define void @test1() {
+; CHECK: %[[CALL:.*]] = notail call "rv_marker" i8* @foo()
+; CHECK: call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %[[CALL]])
+
+define void @test1() {
+  %call1 = call "claimRV" "rv_marker" i8* @foo()
+  ret void
+}
+
+; CHECK-LABEL:define i8* @test2(
+; CHECK: %[[CALL1:.*]] = invoke "rv_marker" i8* @foo()
+
+; CHECK: %[[V0:.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL1]])
+; CHECK-NEXT: br
+
+; CHECK: %[[CALL3:.*]] = invoke "rv_marker" i8* @foo()
+
+; CHECK: %[[V2:.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL3]])
+; CHECK-NEXT: br
+
+; CHECK: %[[RETVAL:.*]] = phi i8* [ %[[V0]], {{.*}} ], [ %[[V2]], {{.*}} ]
+; CHECK: ret i8* %[[RETVAL]]
+
+define i8* @test2(i1 zeroext %b) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  br i1 %b, label %if.then, label %if.end
+
+if.then:
+  %call1 = invoke "retainRV" "rv_marker" i8* @foo()
+  to label %cleanup unwind label %lpad
+
+lpad:
+  %0 = landingpad { i8*, i32 }
+  cleanup
+  resume { i8*, i32 } undef
+
+if.end:
+  %call3 = invoke "retainRV" "rv_marker" i8* @foo()
+  to label %cleanup unwind label %lpad
+
+cleanup:
+  %retval.0 = phi i8* [ %call1, %if.then ], [ %call3, %if.end ]
+  ret i8* %retval.0
+}
+
+declare i8* @foo()
+declare i32 @__gxx_personality_v0(...)
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"clang.arc.retainAutoreleasedReturnValueMarker", !"mov\09fp, fp\09\09// marker for objc_retainAutoreleaseReturnValue"}
Index: llvm/test/Transforms/Inline/inline-retainRV-call.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-retainRV-call.ll
@@ -0,0 +1,175 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+
+@g0 = global i8* null, align 8
+declare i8* @foo0()
+
+define i8* @callee0_autoreleaseRV() {
+  %call = call "retainRV" i8* @foo0()
+  %1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %call
+}
+
+; CHECK-LABEL: define void @test0_autoreleaseRV(
+; CHECK: call "retainRV" i8* @foo0()
+
+define void @test0_autoreleaseRV() {
+  %call = call "retainRV" "rv_marker" i8* @callee0_autoreleaseRV()
+  ret void
+}
+
+; CHECK-LABEL: define void 

[PATCH] D91673: [PGO] Enable preinline and cleanup when optimize for size

2020-12-08 Thread Rong Xu via Phabricator via cfe-commits
xur accepted this revision.
xur added a comment.

Sorry to the late response (I somehow missed the reply).

(1) Can we add some comments to explain the reason for enabling this for -Oz -- 
I think the comments from @rnk is useful to some people (at least to me).

(2) Also please add a testcase.

Feel free to commit to address the above two issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91673

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


[PATCH] D92897: Set legacy pass manager OptBisect to same as NPM OptBisect

2020-12-08 Thread Samuel Eubanks via Phabricator via cfe-commits
swamulism created this revision.
swamulism added a reviewer: aeubanks.
swamulism requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Currently there is an issue where the legacy pass manager uses a different 
OptBisect counter than the new pass manager.
This means that when using OptBisect under the NPM it runs twice when it should 
only run once.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92897

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c
  llvm/include/llvm/Passes/StandardInstrumentations.h


Index: llvm/include/llvm/Passes/StandardInstrumentations.h
===
--- llvm/include/llvm/Passes/StandardInstrumentations.h
+++ llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -281,6 +281,7 @@
   void registerCallbacks(PassInstrumentationCallbacks );
 
   TimePassesHandler () { return TimePasses; }
+  OptBisectInstrumentation () { return OptBisect; }
 };
 
 extern template class ChangeReporter;
Index: clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c
===
--- /dev/null
+++ clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c
@@ -0,0 +1,8 @@
+// Test NPM with -O1/opt-bisect
+//
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 
-fexperimental-new-pass-manager %s -fdebug-pass-manager -mllvm 
-opt-bisect-limit=-1 -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: BISECT: running pass (1)
+// CHECK-NOT: BISECT: running pass (1)
+
+int func(int a) { return a; }
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1149,6 +1149,9 @@
   SI.registerCallbacks(PIC);
   PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, );
 
+  // Sets legacy pass manager OptBisect to the same one as npm so passes are 
properly skipped
+  TheModule->getContext().setOptPassGate(SI.getOptBisect());
+
   // Attempt to load pass plugins and register their callbacks with PB.
   for (auto  : CodeGenOpts.PassPlugins) {
 auto PassPlugin = PassPlugin::Load(PluginFN);


Index: llvm/include/llvm/Passes/StandardInstrumentations.h
===
--- llvm/include/llvm/Passes/StandardInstrumentations.h
+++ llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -281,6 +281,7 @@
   void registerCallbacks(PassInstrumentationCallbacks );
 
   TimePassesHandler () { return TimePasses; }
+  OptBisectInstrumentation () { return OptBisect; }
 };
 
 extern template class ChangeReporter;
Index: clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c
===
--- /dev/null
+++ clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c
@@ -0,0 +1,8 @@
+// Test NPM with -O1/opt-bisect
+//
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 -fexperimental-new-pass-manager %s -fdebug-pass-manager -mllvm -opt-bisect-limit=-1 -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: BISECT: running pass (1)
+// CHECK-NOT: BISECT: running pass (1)
+
+int func(int a) { return a; }
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1149,6 +1149,9 @@
   SI.registerCallbacks(PIC);
   PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, );
 
+  // Sets legacy pass manager OptBisect to the same one as npm so passes are properly skipped
+  TheModule->getContext().setOptPassGate(SI.getOptBisect());
+
   // Attempt to load pass plugins and register their callbacks with PB.
   for (auto  : CodeGenOpts.PassPlugins) {
 auto PassPlugin = PassPlugin::Load(PluginFN);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92617: [DWARF] Allow toolchain to adjust specified DWARF version.

2020-12-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:296
+def warn_drv_dwarf_version_limited_by_target : Warning<
+  "debug information option '%0' is not supported. It needs DWARF-%2 but 
target '%1' only provides DWARF-%3.">,
+  InGroup;

dblaikie wrote:
> Probably worth testing the rest of this error message to check the versions 
> and target names all show up as intended (looks like the test currently 
> glosses over the differences between this warning and the other error?) - and 
> also testing that it's emitted as a warning, whereas the other/pre-existing 
> diagnostic was emitted as an error (oh, I guess perhaps it already is, just 
> in another file - could you check that it is tested narrowly/ensured it's an 
> error elsewhere?)
> Probably worth testing the rest of this error message to check the versions 
> and target names all show up as intended 

Done.

> (looks like the test currently glosses over the differences between this 
> warning and the other error?) - and also testing that it's emitted as a 
> warning, whereas the other/pre-existing diagnostic was emitted as an error 
> (oh, I guess perhaps it already is, just in another file - could you check 
> that it is tested narrowly/ensured it's an error elsewhere?)

The error case is already tested in  
https://github.com/llvm-mirror/clang/blob/master/test/Driver/debug-options.c#L355




Comment at: clang/test/Driver/cuda-unsupported-debug-options.cu:18
+// RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf-5 -gembed-source 
2>&1 | FileCheck %s --check-prefix=DWARF-CLAMP
+// CHECK: debug information option 
'{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}'
 is not supported{{.*}} target 'nvptx64-nvidia-cuda'
 // CHECK-NOT: debug information option '{{.*}}' is not supported for target 
'x86

dblaikie wrote:
> What's the purpose of the {{.*}} in this line? 
The wildcard eats the differences between two warnings -- a generic one:
 - `warning: debug information option '-glldb' is not supported for target 
'nvptx64-nvidia-cuda'` 
and the more specific one for `-gembed-source` : 
 - `warning: debug information option '-gembed-source' is not supported. It 
needs DWARF-5 but target 'nvptx64-nvidia-cuda' only provides DWARF-2.`





Comment at: clang/test/Driver/openmp-unsupported-debug-options.c:17
 // RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -c %s -g -gcolumn-info 
-fdebug-types-section 2>&1 | FileCheck %s
-// CHECK: debug information option 
'{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}'
 is not supported for target 'nvptx64-nvidia-cuda' [-Wunsupported-target-opt]
+// CHECK: debug information option 
'{{-gz|-fdebug-info-for-profiling|-gsplit-dwarf|-glldb|-gcodeview|-gmodules|-gembed-source|-fdebug-macro|-ggnu-pubnames|-gdwarf-aranges|-fdebug-types-section}}'
 is not supported{{.*}} target 'nvptx64-nvidia-cuda'{{.*}} 
[-Wunsupported-target-opt]
 // CHECK-NOT: debug information option '{{.*}}' is not supported for target 
'x86

dblaikie wrote:
> also curious about the {{.*}} here too - but I guess it's the same answer as 
> the other spot?
Yes, same here. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92617

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


[PATCH] D85788: [Clang test] Update to allow passing extra default clang arguments in use_clang

2020-12-08 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis requested changes to this revision.
eugenis added a comment.
This revision now requires changes to proceed.

I wonder if we could just disable unused argument warning for both

  -disable-noundef-analysis
  -Xclang -disable-noundef-analysis

I don't see any precedents for this kind of thing in the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85788

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


[PATCH] D85788: [Clang test] Update to allow passing extra default clang arguments in use_clang

2020-12-08 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

> simply naming it as %clang_noundef would be clearer,

Hmm, yeah, that's a little better.

> This new substitution is going to be used for the noundef checks in D81678 
>  only anyway.

I'm not sure what you mean by this. The substitution is used ~380 times in this 
patch alone.
In the future, any attempt to use %clang -### or -%clang -cc1as will produce 
the same unused argument warning, and it is very unclear that is can be fixed 
with %clang_bin. Note that code search for "-disable-noundef-analysis" does NOT 
lead you to the definition of %clang_bin!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85788

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


[PATCH] D91281: [CUDA][HIP] Diagnose reference of host variable

2020-12-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D91281#2441147 , @tra wrote:

> I think `isCUDADeviceBuiltinTextureType` has problem handling texture refs 
> within templates.

Proposed fix: https://reviews.llvm.org/D92893


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91281

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


[PATCH] D92198: [clangd] Log remote index connectivity status

2020-12-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 310381.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.

Resolve the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92198

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp

Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -6,10 +6,10 @@
 //
 //===--===//
 
-#include 
-
 #include "Client.h"
 #include "Service.grpc.pb.h"
+#include "grpc/impl/codegen/connectivity_state.h"
+#include "grpcpp/channel.h"
 #include "index/Index.h"
 #include "marshalling/Marshalling.h"
 #include "support/Logger.h"
@@ -17,14 +17,33 @@
 #include "clang/Basic/Version.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include 
 
 #include 
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace remote {
 namespace {
 
+llvm::StringRef toString(const grpc_connectivity_state ) {
+  switch (State) {
+  case GRPC_CHANNEL_IDLE:
+return "idle";
+  case GRPC_CHANNEL_CONNECTING:
+return "connecting";
+  case GRPC_CHANNEL_READY:
+return "ready";
+  case GRPC_CHANNEL_TRANSIENT_FAILURE:
+return "transient failure";
+  case GRPC_CHANNEL_SHUTDOWN:
+return "shutdown";
+  }
+  llvm_unreachable("Not a valid grpc_connectivity_state.");
+}
+
 class IndexClient : public clangd::SymbolIndex {
   template 
   using StreamingCall = std::unique_ptr> (
@@ -36,6 +55,7 @@
   bool streamRPC(ClangdRequestT Request,
  StreamingCall RPCCall,
  CallbackT Callback) const {
+auto OldStatus = Channel->GetState(/*try_to_connect=*/false);
 bool FinalResult = false;
 trace::Span Tracer(RequestT::descriptor()->name());
 const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request);
@@ -68,14 +88,18 @@
 SPAN_ATTACH(Tracer, "Status", Reader->Finish().ok());
 SPAN_ATTACH(Tracer, "Successful", Successful);
 SPAN_ATTACH(Tracer, "Failed to parse", FailedToParse);
+vlog("Remote index ({0}): {1} -> {2}", ServerAddress, toString(OldStatus),
+ toString(Channel->GetState(/*try_to_connect=*/false)));
 return FinalResult;
   }
 
 public:
   IndexClient(
-  std::shared_ptr Channel, llvm::StringRef ProjectRoot,
+  std::shared_ptr Channel, llvm::StringRef Address,
+  llvm::StringRef ProjectRoot,
   std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000))
-  : Stub(remote::v1::SymbolIndex::NewStub(Channel)),
+  : Stub(remote::v1::SymbolIndex::NewStub(Channel)), Channel(Channel),
+ServerAddress(Address),
 ProtobufMarshaller(new Marshaller(/*RemoteIndexRoot=*/"",
   /*LocalIndexRoot=*/ProjectRoot)),
 DeadlineWaitingTime(DeadlineTime) {
@@ -118,6 +142,8 @@
 
 private:
   std::unique_ptr Stub;
+  std::shared_ptr Channel;
+  llvm::SmallString<256> ServerAddress;
   std::unique_ptr ProtobufMarshaller;
   // Each request will be terminated if it takes too long.
   std::chrono::milliseconds DeadlineWaitingTime;
@@ -129,9 +155,9 @@
llvm::StringRef ProjectRoot) {
   const auto Channel =
   grpc::CreateChannel(Address.str(), grpc::InsecureChannelCredentials());
-  Channel->GetState(true);
+  Channel->GetState(/*try_to_connect=*/true);
   return std::unique_ptr(
-  new IndexClient(Channel, ProjectRoot));
+  new IndexClient(Channel, Address, ProjectRoot));
 }
 
 } // namespace remote
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92198: [clangd] Log remote index connectivity status

2020-12-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/Client.cpp:114
 assert(!ProjectRoot.empty());
+ChannelStatusWatcher = std::thread([]() {
+  grpc_connectivity_state Status =

sammccall wrote:
> The thread is a bit surprising here. I was assuming we'd use some 
> callback-based API to watch rather than spawn a thread to do the "work" of 
> blocking on a change.
> Also this is going to "wake up" periodically to refresh the watch, which 
> seems undesirable if we want to go truly idle.
> 
> Ah, so there's no callback-type connection-changed API! Sorry to mislead you 
> :-( I hadn't read the API carefully. (I think this is coming as some point - 
> they're talking about replacing CompletionQueue with EventManager which is a 
> callback-based abstraction)
> 
> Seems the "async" option is to subscribe on a CompletionQueue, but then we 
> have to poll it. We can use a zero timeout so the poll doesn't block... But 
> then we might as well poll GetStatus directly.
> 
> Then the question is where to do that from. What if we called GetStatus 
> before/after each request, and reported whenever it has changed? That means:
> 
> - no idle background work
> - we know the connection state for each request
> - we know when a request triggered a connection, and whether that connection 
> succeeded in time for the request
> - if a connection goes idle, we don't know *when*, it gets reported on the 
> next request
("resolved" in this version)

I can understand your point and I support the arguments but this would mean 
that we only get status during requests and can't query it at arbitrary time 
which seems like a loss. Maybe it's OK because there might not be many 
interesting cases when we want to query the server status but not do any 
requests and your proposal makes it easier to implement & maintain. But also 
maybe it could be nice to have some kind of callback on status change.

As you mentioned, I was looking for something like this in gRPC itself but 
couldn't find it there outside the CompletionQueue and EvenManager things. 
Sadly, I don't think we'd be in a position to use the replacement even when 
it's there since we have to support older gRPC versions :(

When I see the logs and the server connectivity updates are following the 
requests, it looks OK but I'm not entirely sure giving up on _watching_ the 
status is great. But it still makes life easier so maybe this change should be 
about it.



Comment at: clang-tools-extra/clangd/index/remote/Client.cpp:124
+  Status = Channel->GetState(/*try_to_connect=*/true);
+  log("Remote index connection status changed: {0}", Status);
+}

sammccall wrote:
> Can we include the remote address and prior status?
> 
> e.g. `"Remote index ({0}): {1} => {2}"`
I can see how it'd be nice but I'm not sure how to do this properly. My only 
idea is to query prior status in the beginning of the request? Otherwise it 
needs to be stored somewhere and gRPC interfaces require `const` functions, so 
`IndexClient` does not change the state within requests. I could either wrap it 
into something or have global `grpc_connnectivity_state` for the last observed 
status but neither look OK. Maybe querying the prior status right before the 
request is OK (that's what I've done here) but I'm not sure if that's exactly 
what you suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92198

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


[PATCH] D91317: Support: Add RedirectingFileSystem::create from simple list of redirections

2020-12-08 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

LGTM with the other patches. Thanks!


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

https://reviews.llvm.org/D91317

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


[PATCH] D92888: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92888

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


[PATCH] D92267: [clang-tidy][NFC] Use moves instead of copies when constructing OptionsProviders.

2020-12-08 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 310378.
njames93 marked 2 inline comments as done.
njames93 added a comment.

Use pass by value for FileOptionsBaseProvider constructor.
Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92267

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -318,9 +318,9 @@
 parseConfiguration(Configuration);
 if (ParsedConfig)
   return std::make_unique(
-  GlobalOptions,
+  std::move(GlobalOptions),
   ClangTidyOptions::getDefaults().merge(DefaultOptions, 0),
-  *ParsedConfig, OverrideOptions, std::move(FS));
+  std::move(*ParsedConfig), std::move(OverrideOptions), std::move(FS));
 llvm::errs() << "Error: invalid configuration specified.\n"
  << ParsedConfig.getError().message() << "\n";
 return nullptr;
@@ -347,8 +347,9 @@
   if (Config.getNumOccurrences() > 0)
 return LoadConfig(Config);
 
-  return std::make_unique(GlobalOptions, DefaultOptions,
-OverrideOptions, std::move(FS));
+  return std::make_unique(
+  std::move(GlobalOptions), std::move(DefaultOptions),
+  std::move(OverrideOptions), std::move(FS));
 }
 
 llvm::IntrusiveRefCntPtr
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.h
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -173,9 +173,10 @@
 /// returns the same options for all files.
 class DefaultOptionsProvider : public ClangTidyOptionsProvider {
 public:
-  DefaultOptionsProvider(const ClangTidyGlobalOptions ,
- const ClangTidyOptions )
-  : GlobalOptions(GlobalOptions), DefaultOptions(Options) {}
+  DefaultOptionsProvider(ClangTidyGlobalOptions GlobalOptions,
+ ClangTidyOptions Options)
+  : GlobalOptions(std::move(GlobalOptions)),
+DefaultOptions(std::move(Options)) {}
   const ClangTidyGlobalOptions () override {
 return GlobalOptions;
   }
@@ -187,7 +188,7 @@
 };
 
 class FileOptionsBaseProvider : public DefaultOptionsProvider {
-public:
+protected:
   // A pair of configuration file base name and a function parsing
   // configuration from text in the corresponding format.
   typedef std::pair(
@@ -213,16 +214,15 @@
   /// take precedence over ".clang-tidy" if both reside in the same directory.
   typedef std::vector ConfigFileHandlers;
 
-  FileOptionsBaseProvider(
-  const ClangTidyGlobalOptions ,
-  const ClangTidyOptions ,
-  const ClangTidyOptions ,
-  llvm::IntrusiveRefCntPtr FS = nullptr);
+  FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
+  ClangTidyOptions DefaultOptions,
+  ClangTidyOptions OverrideOptions,
+  llvm::IntrusiveRefCntPtr FS);
 
-  FileOptionsBaseProvider(const ClangTidyGlobalOptions ,
-  const ClangTidyOptions ,
-  const ClangTidyOptions ,
-  const ConfigFileHandlers );
+  FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
+  ClangTidyOptions DefaultOptions,
+  ClangTidyOptions OverrideOptions,
+  ConfigFileHandlers ConfigHandlers);
 
 protected:
   void addRawFileOptions(llvm::StringRef AbsolutePath,
@@ -243,10 +243,8 @@
 class ConfigOptionsProvider : public FileOptionsBaseProvider {
 public:
   ConfigOptionsProvider(
-  const ClangTidyGlobalOptions ,
-  const ClangTidyOptions ,
-  const ClangTidyOptions ,
-  const ClangTidyOptions ,
+  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
+  ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions,
   llvm::IntrusiveRefCntPtr FS = nullptr);
   std::vector getRawOptions(llvm::StringRef FileName) override;
 
@@ -275,9 +273,8 @@
   /// If any of the \param OverrideOptions fields are set, they will override
   /// whatever options are read from the configuration file.
   FileOptionsProvider(
-  const ClangTidyGlobalOptions ,
-  const ClangTidyOptions ,
-  const ClangTidyOptions ,
+  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
+  ClangTidyOptions OverrideOptions,
   llvm::IntrusiveRefCntPtr FS = nullptr);
 
   /// Initializes the \c FileOptionsProvider instance with a custom set
@@ -297,10 +294,10 @@
   /// that can parse configuration from this file type. The 

[PATCH] D92886: [Sema] Warn about unused functions even when they're inline

2020-12-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I'm not sure this direction really makes sense.

There's a long history of defining utility functions in headers as "static 
inline".  Non-static inline functions in C have confusing semantics.  In C++, 
the semantics are less confusing, but "static inline" still isn't rare.  The 
warning is designed to be compatible with that reality: it allows people to 
define "static inline" functions, and still get warnings about other functions 
that might be unused unintentionally.  I don't think the warning is 
realistically usable if it doesn't allow "static inline" functions in headers.

The fact that the "inline" keyword isn't really significant on a "static 
inline" function doesn't necessarily mean the warning shouldn't exist in its 
current form.

Have you tried to see what the practical impact of this change is on real-world 
codebases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92886

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


[PATCH] D92888: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Thanks for the review!




Comment at: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:180
+  template 
+  IntrusiveRefCntPtr(std::unique_ptr &) : Obj(S.release()) {
+retain();

dblaikie wrote:
> Pass 'S' by value here - that's the usual way to pass ownership of 
> unique_ptr, and unlike the IntrusiveRefCntPtr's copy/move ctors there's no 
> issue with invoking the operation in its implementation (infinitely 
> recursively).
Right, thanks; I'll update it that way before pushing the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92888

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


[PATCH] D92888: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good with one minor tweak




Comment at: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:180
+  template 
+  IntrusiveRefCntPtr(std::unique_ptr &) : Obj(S.release()) {
+retain();

Pass 'S' by value here - that's the usual way to pass ownership of unique_ptr, 
and unlike the IntrusiveRefCntPtr's copy/move ctors there's no issue with 
invoking the operation in its implementation (infinitely recursively).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92888

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


[PATCH] D92893: [CUDA] Do not diagnose host/device variable access in dependent types.

2020-12-08 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added reviewers: yaxunl, hliao.
Herald added a subscriber: bixia.
tra requested review of this revision.
Herald added a project: clang.

`isCUDADeviceBuiltinSurfaceType()`/`isCUDADeviceBuiltinTextureType()` do not
work on dependent types as they rely on specific type attributes and that 
results in mis-diagnosing access when the check happens on class templates used 
as texture references.
 https://godbolt.org/z/B7rtxR


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92893

Files:
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -362,8 +362,9 @@
 auto Target = IdentifyCUDATarget(FD);
 if (FD && Target != CFT_Host) {
   const auto *VD = dyn_cast(D);
-  if (VD && VD->hasGlobalStorage() && !VD->hasAttr() &&
-  !VD->hasAttr() && !VD->hasAttr() &&
+  if (VD && VD->hasGlobalStorage() && !VD->getType()->isDependentType() &&
+  !VD->hasAttr() && !VD->hasAttr() &&
+  !VD->hasAttr() &&
   !VD->getType()->isCUDADeviceBuiltinSurfaceType() &&
   !VD->getType()->isCUDADeviceBuiltinTextureType() &&
   !VD->isConstexpr() && !VD->getType().isConstQualified())
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4299,6 +4299,7 @@
 
 /// Check if the specified type is the CUDA device builtin surface type.
 bool Type::isCUDADeviceBuiltinSurfaceType() const {
+  assert(!isDependentType());
   if (const auto *RT = getAs())
 return RT->getDecl()->hasAttr();
   return false;
@@ -4306,6 +4307,7 @@
 
 /// Check if the specified type is the CUDA device builtin texture type.
 bool Type::isCUDADeviceBuiltinTextureType() const {
+  assert(!isDependentType());
   if (const auto *RT = getAs())
 return RT->getDecl()->hasAttr();
   return false;


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -362,8 +362,9 @@
 auto Target = IdentifyCUDATarget(FD);
 if (FD && Target != CFT_Host) {
   const auto *VD = dyn_cast(D);
-  if (VD && VD->hasGlobalStorage() && !VD->hasAttr() &&
-  !VD->hasAttr() && !VD->hasAttr() &&
+  if (VD && VD->hasGlobalStorage() && !VD->getType()->isDependentType() &&
+  !VD->hasAttr() && !VD->hasAttr() &&
+  !VD->hasAttr() &&
   !VD->getType()->isCUDADeviceBuiltinSurfaceType() &&
   !VD->getType()->isCUDADeviceBuiltinTextureType() &&
   !VD->isConstexpr() && !VD->getType().isConstQualified())
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4299,6 +4299,7 @@
 
 /// Check if the specified type is the CUDA device builtin surface type.
 bool Type::isCUDADeviceBuiltinSurfaceType() const {
+  assert(!isDependentType());
   if (const auto *RT = getAs())
 return RT->getDecl()->hasAttr();
   return false;
@@ -4306,6 +4307,7 @@
 
 /// Check if the specified type is the CUDA device builtin texture type.
 bool Type::isCUDADeviceBuiltinTextureType() const {
+  assert(!isDependentType());
   if (const auto *RT = getAs())
 return RT->getDecl()->hasAttr();
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92627: Basic: Add hashing support for FileEntryRef and DirectoryEntryRef

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/include/clang/Basic/DirectoryEntry.h:104
+  bool isSpecialDenseMapKey() const {
+return ME == llvm::DenseMapInfo::getEmptyKey() ||
+   ME == llvm::DenseMapInfo::getTombstoneKey();

jansvoboda11 wrote:
> Nit: would it make sense to avoid copy-pasting the constructor logic here 
> (`llvm::DenseMapInfo::getEmptyKey()`) and call the 
> constructor instead?
> For example: `isSameRef(DirectoryEntryRef(dense_map_empty_tag{}))`.
> 
> The same goes for `FileEntryRef`.
Yes, that seems decent; I hadn't considered using `isSameRef` when the 
`MapEntry` is a bogus pointer, but that's probably better too. I'll update this 
and the instance of that below.



Comment at: clang/unittests/Basic/FileEntryTest.cpp:126
 
+TEST(FileEntryTest, DenseMapInfo) {
+  RefMaps Refs;

jansvoboda11 wrote:
> Question: do we prefer naming tests with the function/data structure under 
> test, or using more descriptive names? (e.g. `DenseMapFindsOldestEntry`)
Likely depends on the primary motivation of the test; I have a bit of tendency 
for the former in case expected behaviour changes, unless the whole point of 
the test is to test an interesting behaviour or corner case.

In this case, the main purpose of the test is to demonstrate that these can be 
used as DenseMap-family keys -- i.e., that the `insert` calls successfully 
compile. It's important that the behaviour is correct, too, of course.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92627

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


[PATCH] D92886: [Sema] Warn about unused functions even when they're inline

2020-12-08 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added subscribers: mpark, Quuxplusone.
Quuxplusone added a comment.

I agree with your reasoning, but in practice I still see a lot of people using 
`static inline` for functions (especially function templates) in .h files. I'm 
not sure exactly why — maybe to reduce the burden on the linker, which would 
otherwise have to make sure all the symbols had the same address, whereas with 
`static` it doesn't have to worry about that?

Have you run this patch over Clang's own codebase, and over libc++? How many 
positives are there, and do they fall into any thought-provoking patterns?

@mpark, you added some `static inline` to libc++ in D68840 
 — any thoughts on this subject?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92886

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


[PATCH] D91317: Support: Add RedirectingFileSystem::create from simple list of redirections

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:735
+  /// Redirect each of the remapped files from first to second.
+  static std::unique_ptr
+  create(ArrayRef> RemappedFiles,

dexonsmith wrote:
> JDevlieghere wrote:
> >  - Do you need to know that this is a `RedirectingFileSystem` or can it be 
> > a `FileSystem`? 
> >  - Is there a reason this should be a `unique_ptr` instead of an 
> > `IntrusiveRefCntPtr` (which is more prevalent across the VFS, although I'm 
> > not sure why)
> For my use case it doesn't matter what kind of `FileSystem` is returned; I 
> figure this could be convenient for a future client. I would tend toward 
> keeping it this type to match the other overload of 
> `RedirectingFileSystem::create`, but happy to change it if you disagree.
> 
> Regarding `unique_ptr`, I chose that as a sounder alternative to the raw 
> pointer above; leaves options open to clients if they do want unique 
> ownership, which seems nice to support since it's trivial. My use case will 
> ultimately assign it to an `IntrusiveRefCntPtr` so if you disagree I can 
> change it.
It does seem nicer to be consistent, so I just sent out 
https://reviews.llvm.org/D92888, which allows constructing an 
`IntrusiveRefCntPtr` from a moved `unique_ptr`, and 
https://reviews.llvm.org/D92890, which update existing APIs to use `unique_ptr`.


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

https://reviews.llvm.org/D91317

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


[PATCH] D92888: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added reviewers: JDevlieghere, dblaikie.
Herald added subscribers: usaxena95, ributzka, kadircet, arphaman.
dexonsmith requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`,
and remove a couple of now-unnecessary `release()` calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92888

Files:
  clang-tools-extra/clangd/support/ThreadsafeFS.cpp
  clang/lib/Tooling/AllTUsExecution.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
  llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp


Index: llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
===
--- llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
+++ llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
@@ -42,6 +42,17 @@
   EXPECT_EQ(0, NumInstances);
 }
 
+TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
+  EXPECT_EQ(0, NumInstances);
+  {
+auto S1 = std::make_unique();
+IntrusiveRefCntPtr R1 = std::move(S1);
+EXPECT_EQ(1, NumInstances);
+EXPECT_EQ(S1, nullptr);
+  }
+  EXPECT_EQ(0, NumInstances);
+}
+
 struct InterceptRefCounted : public RefCountedBase {
   InterceptRefCounted(bool *Released, bool *Retained)
 : Released(Released), Retained(Retained) {}
Index: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
===
--- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -175,6 +176,11 @@
 S.Obj = nullptr;
   }
 
+  template 
+  IntrusiveRefCntPtr(std::unique_ptr &) : Obj(S.release()) {
+retain();
+  }
+
   template 
   IntrusiveRefCntPtr(const IntrusiveRefCntPtr ) : Obj(S.get()) {
 retain();
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -154,7 +154,7 @@
 : Format(Service.getFormat()) {
   DiagOpts = new DiagnosticOptions();
   PCHContainerOps = std::make_shared();
-  RealFS = llvm::vfs::createPhysicalFileSystem().release();
+  RealFS = llvm::vfs::createPhysicalFileSystem();
   if (Service.canSkipExcludedPPRanges())
 PPSkipMappings =
 std::make_unique();
Index: clang/lib/Tooling/AllTUsExecution.cpp
===
--- clang/lib/Tooling/AllTUsExecution.cpp
+++ clang/lib/Tooling/AllTUsExecution.cpp
@@ -124,7 +124,7 @@
 // Each thread gets an indepent copy of a VFS to allow different
 // concurrent working directories.
 IntrusiveRefCntPtr FS =
-llvm::vfs::createPhysicalFileSystem().release();
+llvm::vfs::createPhysicalFileSystem();
 ClangTool Tool(Compilations, {Path},
std::make_shared(), FS);
 Tool.appendArgumentsAdjuster(Action.second);
Index: clang-tools-extra/clangd/support/ThreadsafeFS.cpp
===
--- clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -87,8 +87,7 @@
   // Avoid using memory-mapped files.
   // FIXME: Try to use a similar approach in Sema instead of relying on
   //propagation of the 'isVolatile' flag through all layers.
-  return new VolatileFileSystem(
-  llvm::vfs::createPhysicalFileSystem().release());
+  return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem());
 }
 } // namespace clangd
 } // namespace clang


Index: llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
===
--- llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
+++ llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
@@ -42,6 +42,17 @@
   EXPECT_EQ(0, NumInstances);
 }
 
+TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) {
+  EXPECT_EQ(0, NumInstances);
+  {
+auto S1 = std::make_unique();
+IntrusiveRefCntPtr R1 = std::move(S1);
+EXPECT_EQ(1, NumInstances);
+EXPECT_EQ(S1, nullptr);
+  }
+  EXPECT_EQ(0, NumInstances);
+}
+
 struct InterceptRefCounted : public RefCountedBase {
   InterceptRefCounted(bool *Released, bool *Retained)
 : Released(Released), Retained(Retained) {}
Index: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
===
--- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -175,6 +176,11 @@
 S.Obj = nullptr;
   }
 
+  template 
+ 

[PATCH] D92198: [clangd] Log remote index connectivity status

2020-12-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

Need to resolve review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92198

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


[PATCH] D92220: [clangd] Add support for static fields in rename

2020-12-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

Need to check this patch again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92220

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


[PATCH] D92181: [clangd] NFC: Add client-side logging for remote index requests

2020-12-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 310357.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92181

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp


Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -15,6 +15,7 @@
 #include "support/Logger.h"
 #include "support/Trace.h"
 #include "clang/Basic/Version.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -42,10 +43,13 @@
 SPAN_ATTACH(Tracer, "Request", RPCRequest.DebugString());
 grpc::ClientContext Context;
 Context.AddMetadata("version", clang::getClangToolFullVersion("clangd"));
-std::chrono::system_clock::time_point Deadline =
-std::chrono::system_clock::now() + DeadlineWaitingTime;
+std::chrono::system_clock::time_point StartTime =
+std::chrono::system_clock::now();
+auto Deadline = StartTime + DeadlineWaitingTime;
 Context.set_deadline(Deadline);
 auto Reader = (Stub.get()->*RPCCall)(, RPCRequest);
+dlog("Sending {0}: {1}", RequestT::descriptor()->name(),
+ RPCRequest.DebugString());
 ReplyT Reply;
 unsigned Successful = 0;
 unsigned FailedToParse = 0;
@@ -65,6 +69,11 @@
   Callback(*Response);
   ++Successful;
 }
+auto Millis = std::chrono::duration_cast(
+  std::chrono::system_clock::now() - StartTime)
+  .count();
+vlog("Remote index: {0} => {1} results in {2}ms. [{3}]",
+ RequestT::descriptor()->name(), Successful, Millis, ServerAddress);
 SPAN_ATTACH(Tracer, "Status", Reader->Finish().ok());
 SPAN_ATTACH(Tracer, "Successful", Successful);
 SPAN_ATTACH(Tracer, "Failed to parse", FailedToParse);
@@ -74,11 +83,12 @@
 public:
   IndexClient(
   std::shared_ptr Channel, llvm::StringRef ProjectRoot,
+  llvm::StringRef Address,
   std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000))
   : Stub(remote::v1::SymbolIndex::NewStub(Channel)),
 ProtobufMarshaller(new Marshaller(/*RemoteIndexRoot=*/"",
   /*LocalIndexRoot=*/ProjectRoot)),
-DeadlineWaitingTime(DeadlineTime) {
+ServerAddress(Address), DeadlineWaitingTime(DeadlineTime) {
 assert(!ProjectRoot.empty());
   }
 
@@ -119,6 +129,7 @@
 private:
   std::unique_ptr Stub;
   std::unique_ptr ProtobufMarshaller;
+  llvm::SmallString<256> ServerAddress;
   // Each request will be terminated if it takes too long.
   std::chrono::milliseconds DeadlineWaitingTime;
 };
@@ -131,7 +142,7 @@
   grpc::CreateChannel(Address.str(), grpc::InsecureChannelCredentials());
   Channel->GetState(true);
   return std::unique_ptr(
-  new IndexClient(Channel, ProjectRoot));
+  new IndexClient(Channel, ProjectRoot, Address));
 }
 
 } // namespace remote


Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -15,6 +15,7 @@
 #include "support/Logger.h"
 #include "support/Trace.h"
 #include "clang/Basic/Version.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -42,10 +43,13 @@
 SPAN_ATTACH(Tracer, "Request", RPCRequest.DebugString());
 grpc::ClientContext Context;
 Context.AddMetadata("version", clang::getClangToolFullVersion("clangd"));
-std::chrono::system_clock::time_point Deadline =
-std::chrono::system_clock::now() + DeadlineWaitingTime;
+std::chrono::system_clock::time_point StartTime =
+std::chrono::system_clock::now();
+auto Deadline = StartTime + DeadlineWaitingTime;
 Context.set_deadline(Deadline);
 auto Reader = (Stub.get()->*RPCCall)(, RPCRequest);
+dlog("Sending {0}: {1}", RequestT::descriptor()->name(),
+ RPCRequest.DebugString());
 ReplyT Reply;
 unsigned Successful = 0;
 unsigned FailedToParse = 0;
@@ -65,6 +69,11 @@
   Callback(*Response);
   ++Successful;
 }
+auto Millis = std::chrono::duration_cast(
+  std::chrono::system_clock::now() - StartTime)
+  .count();
+vlog("Remote index: {0} => {1} results in {2}ms. [{3}]",
+ RequestT::descriptor()->name(), Successful, Millis, ServerAddress);
 SPAN_ATTACH(Tracer, "Status", Reader->Finish().ok());
 SPAN_ATTACH(Tracer, "Successful", Successful);
 SPAN_ATTACH(Tracer, "Failed to parse", FailedToParse);
@@ -74,11 +83,12 @@
 public:
   IndexClient(
   std::shared_ptr Channel, llvm::StringRef ProjectRoot,

[PATCH] D92886: [Sema] Warn about unused functions even when they're inline

2020-12-08 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, efriedma, rsmith.
aaronpuchert requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Being inline doesn't change anything about a function having internal
linkage, see [basic.link]p3 for 'static' and p4 for unnamed namespaces.
An internal linkage function can only be used in the same translation
unit, so if it's not being used or needed, that's suspicious.

Also don't recommend "static inline" since for all intents and purposes
it has the same effect as just using "static", which should thus be
preferred.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92886

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/warn-static-function-inheader.cpp
  clang/test/SemaCXX/warn-static-function-inheader.h
  clang/test/SemaCXX/warn-unused-filescoped.cpp

Index: clang/test/SemaCXX/warn-unused-filescoped.cpp
===
--- clang/test/SemaCXX/warn-unused-filescoped.cpp
+++ clang/test/SemaCXX/warn-unused-filescoped.cpp
@@ -5,26 +5,26 @@
 #ifdef HEADER
 
 static void headerstatic() {} // expected-warning{{unused function 'headerstatic'}}
-static inline void headerstaticinline() {}
+static inline void headerstaticinline() {} // expected-warning{{unused function 'headerstaticinline'}}
 
 namespace {
 void headeranon() {} // expected-warning{{unused function 'headeranon'}}
-inline void headerinlineanon() {}
+inline void headerinlineanon() {} // expected-warning{{unused function 'headerinlineanon'}}
 }
 
 namespace test7
 {
   template
-  static inline void foo(T) { }
+  static inline void foo(T) { } // expected-warning{{unused function template 'foo'}}
 
-  // This should not emit an unused-function warning since it inherits
+  // This should emit an unused-function warning since it inherits
   // the static storage type from the base template.
   template<>
-  inline void foo(int) {  }
+  inline void foo(int) {  } // expected-warning{{unused function 'foo'}}
 
   // Partial specialization
   template
-  static inline void bar(T, U) { }
+  static inline void bar(T, U) { } // expected-warning{{unused function template 'bar'}}
 
   template
   inline void bar(int, U) { }
@@ -35,7 +35,7 @@
 
 namespace pr19713 {
 #if __cplusplus >= 201103L
-  static constexpr int constexpr1() { return 1; }
+  static constexpr int constexpr1() { return 1; } // expected-warning{{unused function 'constexpr1'}}
   constexpr int constexpr2() { return 2; }
 #endif
 }
Index: clang/test/SemaCXX/warn-static-function-inheader.h
===
--- clang/test/SemaCXX/warn-static-function-inheader.h
+++ clang/test/SemaCXX/warn-static-function-inheader.h
@@ -1,3 +1,13 @@
-static void thing(void) { // expected-warning {{'static' function 'thing' declared in header file should be declared 'static inline'}}
+static void thing(void) { // expected-warning {{function 'thing' declared in header file should be declared 'inline' instead of 'static'}}
 }
 
+static inline void inline_thing(void) { // expected-warning {{function 'inline_thing' declared in header file should not be declared 'static'}}
+}
+
+namespace {
+void anon_thing(void) { // expected-warning {{function 'anon_thing' declared in header file should be declared 'inline' instead of in an anonymous namespace}}
+}
+
+inline void anon_inline_thing(void) { // expected-warning {{function 'anon_inline_thing' declared in header file should not be declared in an anonymous namespace}}
+}
+} // namespace
Index: clang/test/SemaCXX/warn-static-function-inheader.cpp
===
--- clang/test/SemaCXX/warn-static-function-inheader.cpp
+++ clang/test/SemaCXX/warn-static-function-inheader.cpp
@@ -7,6 +7,9 @@
 
 template 
 void foo(void) {
-thing();
-	another();
+  thing();
+  inline_thing();
+  anon_thing();
+  anon_inline_thing();
+  another();
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1697,10 +1697,6 @@
 if (const CXXMethodDecl *MD = dyn_cast(FD)) {
   if (MD->isVirtual() || IsDisallowedCopyOrAssign(MD))
 return false;
-} else {
-  // 'static inline' functions are defined in headers; don't warn.
-  if (FD->isInlined() && !isMainFileLoc(*this, FD->getLocation()))
-return false;
 }
 
 if (FD->doesThisDeclarationHaveABody() &&
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1211,13 +1211,12 @@
 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
 << DiagD;
   else {
-if 

[PATCH] D92874: [clangd] Validate clang-tidy Checks in clangd config.

2020-12-08 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 310352.
njames93 added a comment.

Made GlobList::specifies const.
Made check validation function static and only taking a StringRef. This will 
make it easier to refactor out at a later date if this functionality wants to 
be used elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92874

Files:
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -200,6 +200,28 @@
   EXPECT_EQ(Conf.ClangTidy.CheckOptions.lookup("StrictMode"), "true");
   EXPECT_EQ(Conf.ClangTidy.CheckOptions.lookup("example-check.ExampleOption"),
 "0");
+  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
+}
+
+TEST_F(ConfigCompileTests, TidyBadChecks) {
+  Frag.ClangTidy.Add.emplace_back("unknown-check");
+  Frag.ClangTidy.Add.emplace_back("unknown-module-*");
+  Frag.ClangTidy.Remove.emplace_back("*");
+  Frag.ClangTidy.Remove.emplace_back("llvm-includeorder");
+  EXPECT_TRUE(compileAndApply());
+  // Ensure bad checks are stripped from the glob.
+  EXPECT_EQ(Conf.ClangTidy.Checks, "-*");
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  ElementsAre(AllOf(DiagMessage("Check glob 'unknown-check' doesn't "
+"specify any known clang-tidy check"),
+DiagKind(llvm::SourceMgr::DK_Warning)),
+  AllOf(DiagMessage("Check glob 'unknown-module-*' doesn't "
+"specify any known clang-tidy check"),
+DiagKind(llvm::SourceMgr::DK_Warning)),
+  AllOf(DiagMessage("Check glob 'llvm-includeorder' doesn't "
+"specify any known clang-tidy check"),
+DiagKind(llvm::SourceMgr::DK_Warning;
 }
 
 TEST_F(ConfigCompileTests, ExternalBlockWarnOnMultipleSource) {
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -23,6 +23,8 @@
 //
 //===--===//
 
+#include "../clang-tidy/ClangTidyModuleRegistry.h"
+#include "../clang-tidy/GlobList.h"
 #include "CompileCommands.h"
 #include "Config.h"
 #include "ConfigFragment.h"
@@ -30,12 +32,14 @@
 #include "Features.inc"
 #include "support/Logger.h"
 #include "support/Trace.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -347,6 +351,41 @@
 }
   }
 
+  // Warn against any Add or Remove check items that doesn't specify a valid
+  // tidy check, most likely due to a typo.
+  static bool isValidCheckGlob(StringRef CheckGlob) {
+static llvm::ArrayRef AllChecks = [] {
+  // In a simple world this would be a std::vector. However,
+  // using the bump allocator and an ArrayRef, we can drastically reduce
+  // number of allocations while simultaneously increasing cache locality.
+  static llvm::BumpPtrAllocator Alloc;
+  tidy::ClangTidyCheckFactories Factories;
+  for (tidy::ClangTidyModuleRegistry::entry E :
+   tidy::ClangTidyModuleRegistry::entries())
+E.instantiate()->addCheckFactories(Factories);
+  llvm::MutableArrayRef AllChecks(
+  Alloc.Allocate(Factories.size()), Factories.size());
+  llvm::StringRef *Iter = AllChecks.begin();
+  for (const auto  : Factories) {
+StringRef Key = Factory.getKey();
+assert(!Key.empty() && "All checks should have valid names");
+char *Ptr = Alloc.Allocate(Key.size());
+// Copy the Key into our newly allocated buffer, We don't need to worry
+// about writing a null terminator.
+memcpy(Ptr, Key.data(), Key.size());
+*Iter++ = StringRef(Ptr, Key.size());
+  }
+  assert(Iter == AllChecks.end());
+  return AllChecks;
+}();
+tidy::GlobList List(CheckGlob);
+// Looping over the list of checks is not great in complexity, but given the
+// intricacies of glob lists, a set based approach wouldn't really be
+// feasible.
+return llvm::any_of(
+AllChecks, [](const StringRef ) { return List.specifies(S); });
+  }

[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2020-12-08 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D52050#2441141 , @jrtc27 wrote:

> What gets done currently for i386? That suffers potentially the same problem 
> given both /usr/lib/gcc/x86_64-linux-gnu/$V/32 and 
> /usr/lib/gcc/i386-linux-gnu/$V are possible locations for an i386 GCC 
> toolchain.

Very good suggestion. I will look into that tomorrow. Thanks for the pointer!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2020-12-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Your patch description doesn't mention the changes to the inliner.




Comment at: clang/lib/CodeGen/CGObjC.cpp:2282
 
+static const char *markerKey = "clang.arc.retainAutoreleasedReturnValueMarker";
+

This is too generic for a global variable name.

It should also be `const`.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2328
+  CGF.CGM.getTarget().getTriple().isAArch64() &&
+  !CGF.CGM.getTarget().getTriple().isOSWindows()) {
+auto *callBase = cast(value);

It would be good to explain why this is target-specific in a comment.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2334
+   IsRetainRV ? "retainRV" : "claimRV");
+if (CGF.CGM.getModule().getModuleFlag(markerKey))
+  attrs = attrs.addAttribute(CGF.getLLVMContext(),

Didn't we just add this?  Can that fail to add the marker?


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


[clang-tools-extra] 86436a4 - [clang-tidy][NFC] Made Globlist::contains const

2020-12-08 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-12-08T22:26:55Z
New Revision: 86436a4343628f0f98d72169a013cf99a3be5973

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

LOG: [clang-tidy][NFC] Made Globlist::contains const

Added: 


Modified: 
clang-tools-extra/clang-tidy/GlobList.cpp
clang-tools-extra/clang-tidy/GlobList.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/GlobList.cpp 
b/clang-tools-extra/clang-tidy/GlobList.cpp
index 88e6ea22d675..5b70b8d8c577 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -52,7 +52,7 @@ GlobList::GlobList(StringRef Globs) {
   } while (!Globs.empty());
 }
 
-bool GlobList::contains(StringRef S) {
+bool GlobList::contains(StringRef S) const {
   // Iterating the container backwards as the last match determins if S is in
   // the list.
   for (const GlobListItem  : llvm::reverse(Items)) {

diff  --git a/clang-tools-extra/clang-tidy/GlobList.h 
b/clang-tools-extra/clang-tidy/GlobList.h
index 5acb6a5b878c..fe68a3497c92 100644
--- a/clang-tools-extra/clang-tidy/GlobList.h
+++ b/clang-tools-extra/clang-tidy/GlobList.h
@@ -33,7 +33,7 @@ class GlobList {
 
   /// Returns \c true if the pattern matches \p S. The result is the last
   /// matching glob's Positive flag.
-  bool contains(StringRef S);
+  bool contains(StringRef S) const;
 
 private:
 



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


[PATCH] D91317: Support: Add RedirectingFileSystem::create from simple list of redirections

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:735
+  /// Redirect each of the remapped files from first to second.
+  static std::unique_ptr
+  create(ArrayRef> RemappedFiles,

JDevlieghere wrote:
>  - Do you need to know that this is a `RedirectingFileSystem` or can it be a 
> `FileSystem`? 
>  - Is there a reason this should be a `unique_ptr` instead of an 
> `IntrusiveRefCntPtr` (which is more prevalent across the VFS, although I'm 
> not sure why)
For my use case it doesn't matter what kind of `FileSystem` is returned; I 
figure this could be convenient for a future client. I would tend toward 
keeping it this type to match the other overload of 
`RedirectingFileSystem::create`, but happy to change it if you disagree.

Regarding `unique_ptr`, I chose that as a sounder alternative to the raw 
pointer above; leaves options open to clients if they do want unique ownership, 
which seems nice to support since it's trivial. My use case will ultimately 
assign it to an `IntrusiveRefCntPtr` so if you disagree I can change it.


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

https://reviews.llvm.org/D91317

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


[PATCH] D91281: [CUDA][HIP] Diagnose reference of host variable

2020-12-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

It appears that we need to add special handling for texture/surface references. 
Nominally they are host-side objects, but they are accessed/used from device 
functions as far as Sema is concerned.

E.g. https://godbolt.org/z/z1YnE3 
NVCC and older clang compile it, but the recent one fails because this patch 
does not let the change through.
I think `isCUDADeviceBuiltinTextureType` has problem handling texture refs 
within templates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91281

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2020-12-08 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

i.e. can we not just support both approaches and prefer x86_64-linux-gnux32 if 
it exists?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2020-12-08 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D52050#2441133 , @glaubitz wrote:

> In D52050#2441094 , @hvdijk wrote:
>
>> I've been able to check what Ubuntu 20.10 offers in terms of x32 support. 
>> Its kernel supports x32 binaries, it provides x32 versions of core system 
>> libraries in separate packages (e.g. libc6-x32, libx32stdc++6, libx32z1), 
>> and it provides a compiler that targets x32 by default 
>> (gcc-x86-64-linux-gnux32).
>
> I did that, too. In fact, Ubuntu is identical to Debian in this regard as 
> both the Ubuntu and the Debian gcc packages are maintained by the same 
> maintainer (Matthias Klose whom I also happen to know personally) who first 
> uploads these packages to Debian unstable, then syncs to Ubuntu.
>
> However:
>
>> These Ubuntu packages do not use the Debian/Ubuntu multiarch approach: the 
>> packages are completely independent of the corresponding x64 and i386 
>> versions with separate names, and nothing in Ubuntu installs any libraries 
>> into any /lib/x86_64-linux-gnux32-like path. They are intended to allow x32 
>> cross compilation on an Ubuntu system, not intended to act as a basis for 
>> running an x32 Ubuntu system. This appears to be very different from 
>> Debian's x32 support. That said, cross-compiled binaries do run on Ubuntu 
>> and it should be possible to build an x32-native LLVM with the 
>> Ubuntu-provided toolchain.
>
> Well, Debian has both as - as I already mentioned - the gcc packages in 
> Debian and Ubuntu are the same. The only difference is that Ubuntu does not 
> provide an x32 port so there is no possibility to install Ubuntu x32 packages 
> in the commonly known MultiArch manner.
>
> Since MultiArch and the -cross packages are somewhat redundant, I'm not so 
> sure yet which approach to address this issue would be best. I will talk to 
> Matthias regarding this.

What gets done currently for i386? That suffers potentially the same problem 
given both /usr/lib/gcc/x86_64-linux-gnu/$V/32 and 
/usr/lib/gcc/i386-linux-gnu/$V are possible locations for an i386 GCC toolchain.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2020-12-08 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D52050#2441094 , @hvdijk wrote:

> I've been able to check what Ubuntu 20.10 offers in terms of x32 support. Its 
> kernel supports x32 binaries, it provides x32 versions of core system 
> libraries in separate packages (e.g. libc6-x32, libx32stdc++6, libx32z1), and 
> it provides a compiler that targets x32 by default (gcc-x86-64-linux-gnux32).

I did that, too. In fact, Ubuntu is ndentical to Debian in this regard as both 
the Ubuntu and the Debian gcc packages are maintained by the same maintainer 
(Matthias Klose whom I also happen to know personally) who first uploads these 
packages to Debian unstable, then syncs to Ubuntu.

However:

> These Ubuntu packages do not use the Debian/Ubuntu multiarch approach: the 
> packages are completely independent of the corresponding x64 and i386 
> versions with separate names, and nothing in Ubuntu installs any libraries 
> into any /lib/x86_64-linux-gnux32-like path. They are intended to allow x32 
> cross compilation on an Ubuntu system, not intended to act as a basis for 
> running an x32 Ubuntu system. This appears to be very different from Debian's 
> x32 support. That said, cross-compiled binaries do run on Ubuntu and it 
> should be possible to build an x32-native LLVM with the Ubuntu-provided 
> toolchain.

Well, Debian has both as - as I already mentioned - the gcc packages in Debian 
and Ubuntu are the same. The only difference is that Ubuntu does not provide an 
x32 port so there is no possibility to install Ubuntu x32 packages in the 
commonly known MultiArch manner.

Since MultiArch and the -cross packages are somewhat redundant, I'm not so sure 
yet which approach to address this issue would be best. I will talk to Matthias 
regarding this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D92883: De-templatify EmitCallArgs argument type checking, NFCI

2020-12-08 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/CGCall.cpp:3824
+// that may have type parameters in its signature.
+static bool isObjCMethodWithTypeParams(const ObjCMethodDecl *method) {
+  const DeclContext *dc = method->getDeclContext();

This doesn't entirely match the style, but it is a shuffle after all.  Id say 
that `DC`, and using `if (const auto *CD =` due to the `dyn_cast` would be 
nice, but that isn't important.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92883

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2020-12-08 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added a comment.

I've been able to check what Ubuntu 20.10 offers in terms of x32 support. Its 
kernel supports x32 binaries, it provides x32 versions of core system libraries 
in separate packages (e.g. libc6-x32, libx32stdc++6, libx32z1), and it provides 
a compiler that targets x32 by default (gcc-x86-64-linux-gnux32). These Ubuntu 
packages do not use the Debian/Ubuntu multiarch approach: the packages are 
completely independent of the corresponding x64 and i386 versions with separate 
names, and nothing in Ubuntu installs any libraries into any 
/lib/x86_64-linux-gnux32-like path. They are intended to allow x32 cross 
compilation on an Ubuntu system, not intended to act as a basis for running an 
x32 Ubuntu system. This appears to be very different from Debian's x32 support. 
That said, cross-compiled binaries do run on Ubuntu and it should be possible 
to build an x32-native LLVM with the Ubuntu-provided toolchain.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D91317: Support: Add RedirectingFileSystem::create from simple list of redirections

2020-12-08 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added inline comments.



Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:735
+  /// Redirect each of the remapped files from first to second.
+  static std::unique_ptr
+  create(ArrayRef> RemappedFiles,

 - Do you need to know that this is a `RedirectingFileSystem` or can it be a 
`FileSystem`? 
 - Is there a reason this should be a `unique_ptr` instead of an 
`IntrusiveRefCntPtr` (which is more prevalent across the VFS, although I'm not 
sure why)


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

https://reviews.llvm.org/D91317

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


[PATCH] D92883: De-templatify EmitCallArgs argument type checking, NFCI

2020-12-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added reviewers: compnerd, aeubanks, rsmith.
rnk requested review of this revision.
Herald added a project: clang.

This template exists to abstract over FunctionPrototype and
ObjCMethodDecl, which have similar APIs for storing parameter types. In
place of a template, use a PointerUnion with two cases to handle this.
Hopefully this improves readability, since the type of the prototype is
easier to discover. This allows me to sink this code, which is mostly
assertions, out of the header file and into the cpp file. I can also
simplify the overloaded methods for computing isGenericMethod, and get
rid of the second EmitCallArgs overload.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92883

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h

Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4560,26 +4560,6 @@
Address Loc);
 
 public:
-#ifndef NDEBUG
-  // Determine whether the given argument is an Objective-C method
-  // that may have type parameters in its signature.
-  static bool isObjCMethodWithTypeParams(const ObjCMethodDecl *method) {
-const DeclContext *dc = method->getDeclContext();
-if (const ObjCInterfaceDecl *classDecl= dyn_cast(dc)) {
-  return classDecl->getTypeParamListAsWritten();
-}
-
-if (const ObjCCategoryDecl *catDecl = dyn_cast(dc)) {
-  return catDecl->getTypeParamList();
-}
-
-return false;
-  }
-
-  template
-  static bool isObjCMethodWithTypeParams(const T *) { return false; }
-#endif
-
   enum class EvaluationOrder {
 ///! No language constraints on evaluation order.
 Default,
@@ -4589,56 +4569,16 @@
 ForceRightToLeft
   };
 
-  /// EmitCallArgs - Emit call arguments for a function.
-  template 
-  void EmitCallArgs(CallArgList , const T *CallArgTypeInfo,
-llvm::iterator_range ArgRange,
-AbstractCallee AC = AbstractCallee(),
-unsigned ParamsToSkip = 0,
-EvaluationOrder Order = EvaluationOrder::Default) {
-SmallVector ArgTypes;
-CallExpr::const_arg_iterator Arg = ArgRange.begin();
-
-assert((ParamsToSkip == 0 || CallArgTypeInfo) &&
-   "Can't skip parameters if type info is not provided");
-if (CallArgTypeInfo) {
-#ifndef NDEBUG
-  bool isGenericMethod = isObjCMethodWithTypeParams(CallArgTypeInfo);
-#endif
-
-  // First, use the argument types that the type info knows about
-  for (auto I = CallArgTypeInfo->param_type_begin() + ParamsToSkip,
-E = CallArgTypeInfo->param_type_end();
-   I != E; ++I, ++Arg) {
-assert(Arg != ArgRange.end() && "Running over edge of argument list!");
-assert((isGenericMethod ||
-((*I)->isVariablyModifiedType() ||
- (*I).getNonReferenceType()->isObjCRetainableType() ||
- getContext()
- .getCanonicalType((*I).getNonReferenceType())
- .getTypePtr() ==
- getContext()
- .getCanonicalType((*Arg)->getType())
- .getTypePtr())) &&
-   "type mismatch in call argument!");
-ArgTypes.push_back(*I);
-  }
-}
-
-// Either we've emitted all the call args, or we have a call to variadic
-// function.
-assert((Arg == ArgRange.end() || !CallArgTypeInfo ||
-CallArgTypeInfo->isVariadic()) &&
-   "Extra arguments in non-variadic function!");
-
-// If we still have any arguments, emit them using the type of the argument.
-for (auto *A : llvm::make_range(Arg, ArgRange.end()))
-  ArgTypes.push_back(CallArgTypeInfo ? getVarArgType(A) : A->getType());
+  // Wrapper for function prototype sources. Wraps either a FunctionProtoType or
+  // an ObjCMethodDecl.
+  struct PrototypeWrapper {
+llvm::PointerUnion P;
 
-EmitCallArgs(Args, ArgTypes, ArgRange, AC, ParamsToSkip, Order);
-  }
+PrototypeWrapper(const FunctionProtoType *FT) : P(FT) {}
+PrototypeWrapper(const ObjCMethodDecl *MD) : P(MD) {}
+  };
 
-  void EmitCallArgs(CallArgList , ArrayRef ArgTypes,
+  void EmitCallArgs(CallArgList , PrototypeWrapper Prototype,
 llvm::iterator_range ArgRange,
 AbstractCallee AC = AbstractCallee(),
 unsigned ParamsToSkip = 0,
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1329,7 +1329,7 @@
  const CallExpr *TheCall,
  bool IsDelete) {
   CallArgList Args;
-  EmitCallArgs(Args, 

[PATCH] D92721: [PATCH] [clang] Create SPIRABIInfo to enable SPIR_FUNC calling convention

2020-12-08 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 310338.
mibintc added a comment.

Thanks @Anastasia ; I modified CGBuiltin.cpp to use EmitRuntimeCall when 
creating calls to runtime functions instead of Builder.CreateCall so this is 
setting the CallingConvention on the Call node using the ABIInfo.  I changed a 
few lit tests that were failing because of this.

I have a question, the clang test CodeGenOpenCL/cl20-device-side-enqueue.cl has 
this function, device_side_enqueue_block_invoke_9 which is defined with 
spir_func CC. The call doesn't have that CC. Where is that call created?  Seems 
like the call should have spir_func CC, I want to fix that.

Likewise device_side_enqueue_block_invoke_9_kernel has spir_kernel CC.  How 
does the CC get set to spir_kernel, I don't see where that is happening

define internal spir_func void @__device_side_enqueue_block_invoke_9(i8 
addrspace(4)* %.block_descriptor, i8 addrspace(3)* %p1, i8 addrspace(3)* %p2, 
i8 addrspace(3)* %p3) #1 {
define internal spir_kernel void 
@__device_side_enqueue_block_invoke_9_kernel(i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #5 {

  call void @__device_side_enqueue_block_invoke_9(i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92721

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/complex-math.c
  clang/test/CodeGenOpenCL/builtins.cl
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/CodeGenOpenCLCXX/atexit.cl

Index: clang/test/CodeGenOpenCLCXX/atexit.cl
===
--- clang/test/CodeGenOpenCLCXX/atexit.cl
+++ clang/test/CodeGenOpenCLCXX/atexit.cl
@@ -5,7 +5,7 @@
 };
 S s;
 
-//CHECK-LABEL: define internal void @__cxx_global_var_init()
-//CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* @__dso_handle)
+//CHECK-LABEL: define internal spir_func void @__cxx_global_var_init()
+//CHECK: call spir_func i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* @__dso_handle)
 
-//CHECK: declare i32 @__cxa_atexit(void (i8*)*, i8*, i8 addrspace(1)*)
+//CHECK: declare spir_func i32 @__cxa_atexit(void (i8*)*, i8*, i8 addrspace(1)*)
Index: clang/test/CodeGenOpenCL/to_addr_builtin.cl
===
--- clang/test/CodeGenOpenCL/to_addr_builtin.cl
+++ clang/test/CodeGenOpenCL/to_addr_builtin.cl
@@ -14,74 +14,74 @@
   generic int *gen;
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call spir_func i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(glob);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call spir_func i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(loc);
  
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call spir_func i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(priv);
  
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call spir_func i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(gen);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call spir_func i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(glob);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call spir_func i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 

[PATCH] D92630: ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb85c6e5bcd1a: ARCMigrate: Use hash_combine in the 
DenseMapInfo for EditEntry (authored by dexonsmith).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92630

Files:
  clang/lib/ARCMigrate/ObjCMT.cpp


Index: clang/lib/ARCMigrate/ObjCMT.cpp
===
--- clang/lib/ARCMigrate/ObjCMT.cpp
+++ clang/lib/ARCMigrate/ObjCMT.cpp
@@ -2054,12 +2054,8 @@
 return Entry;
   }
   static unsigned getHashValue(const EditEntry& Val) {
-llvm::FoldingSetNodeID ID;
-ID.AddPointer(Val.File);
-ID.AddInteger(Val.Offset);
-ID.AddInteger(Val.RemoveLen);
-ID.AddString(Val.Text);
-return ID.ComputeHash();
+return (unsigned)llvm::hash_combine(Val.File, Val.Offset, Val.RemoveLen,
+Val.Text);
   }
   static bool isEqual(const EditEntry , const EditEntry ) {
 return LHS.File == RHS.File &&


Index: clang/lib/ARCMigrate/ObjCMT.cpp
===
--- clang/lib/ARCMigrate/ObjCMT.cpp
+++ clang/lib/ARCMigrate/ObjCMT.cpp
@@ -2054,12 +2054,8 @@
 return Entry;
   }
   static unsigned getHashValue(const EditEntry& Val) {
-llvm::FoldingSetNodeID ID;
-ID.AddPointer(Val.File);
-ID.AddInteger(Val.Offset);
-ID.AddInteger(Val.RemoveLen);
-ID.AddString(Val.Text);
-return ID.ComputeHash();
+return (unsigned)llvm::hash_combine(Val.File, Val.Offset, Val.RemoveLen,
+Val.Text);
   }
   static bool isEqual(const EditEntry , const EditEntry ) {
 return LHS.File == RHS.File &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b85c6e5 - ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T13:46:21-08:00
New Revision: b85c6e5bcd1a9de941c318f9a5dc742818752a56

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

LOG: ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry

Simplify the DenseMapInfo for `EditEntry` by migrating from
`FoldingSetNodeID` to `llvm::hash_combine`. Besides the cleanup, this
reduces the diff for a future patch which changes the type of one of the
fields.

There should be no real functionality change here, although I imagine
the hash value will churn since its a different hashing infrastructure.

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

Added: 


Modified: 
clang/lib/ARCMigrate/ObjCMT.cpp

Removed: 




diff  --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index ef2985d16d23..dfc0d9353165 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -2054,12 +2054,8 @@ template<> struct DenseMapInfo {
 return Entry;
   }
   static unsigned getHashValue(const EditEntry& Val) {
-llvm::FoldingSetNodeID ID;
-ID.AddPointer(Val.File);
-ID.AddInteger(Val.Offset);
-ID.AddInteger(Val.RemoveLen);
-ID.AddString(Val.Text);
-return ID.ComputeHash();
+return (unsigned)llvm::hash_combine(Val.File, Val.Offset, Val.RemoveLen,
+Val.Text);
   }
   static bool isEqual(const EditEntry , const EditEntry ) {
 return LHS.File == RHS.File &&



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


[PATCH] D92809: [Driver] Add -gno-split-dwarf which can disable debug fission

2020-12-08 Thread Fangrui Song 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 rG85c18d3521e8: [Driver] Add -gno-split-dwarf which can 
disable debug fission (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92809

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/split-debug.c


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -17,12 +17,22 @@
 // RUN: %clang -### -c -target amdgcn-amd-amdhsa -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=SPLIT
 
 /// -gsplit-dwarf is a no-op on a non-ELF platform.
-// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=NOSPLIT
-// NOSPLIT-NOT: "-split-dwarf
+// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=DARWIN
+// DARWIN: "-debug-info-kind=standalone"
+// DARWIN-NOT: "-split-dwarf
 
 /// -gsplit-dwarf is a no-op if no -g is specified.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=G0
 
+/// -gno-split-dwarf disables debug fission.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -gno-split-dwarf %s 
2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g -gno-split-dwarf 
%s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gno-split-dwarf -g -gsplit-dwarf %s 
2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
+
+// NOSPLIT: "-debug-info-kind=limited"
+// NOSPLIT-NOT: "-ggnu-pubnames"
+// NOSPLIT-NOT: "-split-dwarf
+
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | 
FileCheck %s --check-prefix=SINGLE
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3705,9 +3705,9 @@
 
 static DwarfFissionKind getDebugFissionKind(const Driver ,
 const ArgList , Arg *) {
-  Arg =
-  Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ);
-  if (!Arg)
+  Arg = Args.getLastArg(options::OPT_gsplit_dwarf, 
options::OPT_gsplit_dwarf_EQ,
+options::OPT_gno_split_dwarf);
+  if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
 return DwarfFissionKind::None;
 
   if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2213,6 +2213,7 @@
 def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group,
   HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
   Values<"split,single">;
+def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group;
 def gpubnames : Flag<["-"], "gpubnames">, Group, 
Flags<[CC1Option]>;


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -17,12 +17,22 @@
 // RUN: %clang -### -c -target amdgcn-amd-amdhsa -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=SPLIT
 
 /// -gsplit-dwarf is a no-op on a non-ELF platform.
-// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
-// NOSPLIT-NOT: "-split-dwarf
+// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=DARWIN
+// DARWIN: "-debug-info-kind=standalone"
+// DARWIN-NOT: "-split-dwarf
 
 /// -gsplit-dwarf is a no-op if no -g is specified.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=G0
 
+/// -gno-split-dwarf disables debug fission.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -gno-split-dwarf %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g -gno-split-dwarf %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gno-split-dwarf -g -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
+
+// NOSPLIT: "-debug-info-kind=limited"
+// NOSPLIT-NOT: "-ggnu-pubnames"
+// NOSPLIT-NOT: "-split-dwarf
+
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | FileCheck %s --check-prefix=SINGLE
 
Index: 

[clang] 85c18d3 - [Driver] Add -gno-split-dwarf which can disable debug fission

2020-12-08 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-12-08T13:24:59-08:00
New Revision: 85c18d3521e87a22c742be512245665d6bb5bfe2

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

LOG: [Driver] Add -gno-split-dwarf which can disable debug fission

Currently when -gsplit-dwarf is specified (could be buried in a build system),
there is no convenient way to cancel debug fission without affecting the debug
information amount (all of -g0, -g1 -fsplit-dwarf-inlining and 
-gline-directives-only
can, but they affect the debug information amount).

Reviewed By: #debug-info, dblaikie

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/split-debug.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8cabcd671161..896ccbe3b275 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2213,6 +2213,7 @@ def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, 
Group;
 def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group,
   HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
   Values<"split,single">;
+def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group;
 def gpubnames : Flag<["-"], "gpubnames">, Group, 
Flags<[CC1Option]>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f3a6b12609e2..6c78a5d9555c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3705,9 +3705,9 @@ enum class DwarfFissionKind { None, Split, Single };
 
 static DwarfFissionKind getDebugFissionKind(const Driver ,
 const ArgList , Arg *) {
-  Arg =
-  Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ);
-  if (!Arg)
+  Arg = Args.getLastArg(options::OPT_gsplit_dwarf, 
options::OPT_gsplit_dwarf_EQ,
+options::OPT_gno_split_dwarf);
+  if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
 return DwarfFissionKind::None;
 
   if (Arg->getOption().matches(options::OPT_gsplit_dwarf))

diff  --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index bd9ec32e0010..7d3fcf078c56 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -17,12 +17,22 @@
 // RUN: %clang -### -c -target amdgcn-amd-amdhsa -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=SPLIT
 
 /// -gsplit-dwarf is a no-op on a non-ELF platform.
-// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=NOSPLIT
-// NOSPLIT-NOT: "-split-dwarf
+// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=DARWIN
+// DARWIN: "-debug-info-kind=standalone"
+// DARWIN-NOT: "-split-dwarf
 
 /// -gsplit-dwarf is a no-op if no -g is specified.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=G0
 
+/// -gno-split-dwarf disables debug fission.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -gno-split-dwarf %s 
2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g -gno-split-dwarf 
%s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gno-split-dwarf -g -gsplit-dwarf %s 
2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
+
+// NOSPLIT: "-debug-info-kind=limited"
+// NOSPLIT-NOT: "-ggnu-pubnames"
+// NOSPLIT-NOT: "-split-dwarf
+
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | 
FileCheck %s --check-prefix=SINGLE
 



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


[PATCH] D92809: [Driver] Add -gno-split-dwarf which can disable debug fission

2020-12-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 310331.
MaskRay added a comment.

Test there is no -ggnu-pubnames


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92809

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/split-debug.c


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -17,12 +17,22 @@
 // RUN: %clang -### -c -target amdgcn-amd-amdhsa -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=SPLIT
 
 /// -gsplit-dwarf is a no-op on a non-ELF platform.
-// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=NOSPLIT
-// NOSPLIT-NOT: "-split-dwarf
+// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=DARWIN
+// DARWIN: "-debug-info-kind=standalone"
+// DARWIN-NOT: "-split-dwarf
 
 /// -gsplit-dwarf is a no-op if no -g is specified.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=G0
 
+/// -gno-split-dwarf disables debug fission.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -gno-split-dwarf %s 
2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g -gno-split-dwarf 
%s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gno-split-dwarf -g -gsplit-dwarf %s 
2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
+
+// NOSPLIT: "-debug-info-kind=limited"
+// NOSPLIT-NOT: "-ggnu-pubnames"
+// NOSPLIT-NOT: "-split-dwarf
+
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | 
FileCheck %s --check-prefix=SINGLE
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3705,9 +3705,9 @@
 
 static DwarfFissionKind getDebugFissionKind(const Driver ,
 const ArgList , Arg *) {
-  Arg =
-  Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ);
-  if (!Arg)
+  Arg = Args.getLastArg(options::OPT_gsplit_dwarf, 
options::OPT_gsplit_dwarf_EQ,
+options::OPT_gno_split_dwarf);
+  if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
 return DwarfFissionKind::None;
 
   if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2213,6 +2213,7 @@
 def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group,
   HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
   Values<"split,single">;
+def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group;
 def gpubnames : Flag<["-"], "gpubnames">, Group, 
Flags<[CC1Option]>;


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -17,12 +17,22 @@
 // RUN: %clang -### -c -target amdgcn-amd-amdhsa -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=SPLIT
 
 /// -gsplit-dwarf is a no-op on a non-ELF platform.
-// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
-// NOSPLIT-NOT: "-split-dwarf
+// RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=DARWIN
+// DARWIN: "-debug-info-kind=standalone"
+// DARWIN-NOT: "-split-dwarf
 
 /// -gsplit-dwarf is a no-op if no -g is specified.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=G0
 
+/// -gno-split-dwarf disables debug fission.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g -gno-split-dwarf %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g -gno-split-dwarf %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
+// RUN: %clang -### -c -target x86_64 -gno-split-dwarf -g -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
+
+// NOSPLIT: "-debug-info-kind=limited"
+// NOSPLIT-NOT: "-ggnu-pubnames"
+// NOSPLIT-NOT: "-split-dwarf
+
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | FileCheck %s --check-prefix=SINGLE
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- 

[clang] b13f741 - APINotes: add bitcode format schema definitions

2020-12-08 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2020-12-08T21:15:41Z
New Revision: b13f74151137f33327e0549adc9778aebf98a299

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

LOG: APINotes: add bitcode format schema definitions

This adds the bitcode format schema required for serialization of the
YAML data to a binary format.  APINotes are pre-compiled and re-used in
the binary format from the frontend.  These definitions provide the data
layout representation enabling writing (and eventually) reading of the
data in bitcode format.

This is extracted from the code contributed by Apple at
https://github.com/llvm/llvm-project-staging/tree/staging/swift/apinotes.

Differential Revision: https://reviews.llvm.org/D91997
Reviewed By: Gabor Marton

Added: 
clang/lib/APINotes/APINotesFormat.h

Modified: 


Removed: 




diff  --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
new file mode 100644
index ..6b76ecfc2567
--- /dev/null
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -0,0 +1,255 @@
+//===-- APINotesWriter.h - API Notes Writer -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
+#define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
+
+#include "llvm/ADT/PointerEmbeddedInt.h"
+#include "llvm/Bitcode/BitcodeConvenience.h"
+
+namespace clang {
+namespace api_notes {
+/// Magic number for API notes files.
+const unsigned char API_NOTES_SIGNATURE[] = {0xE2, 0x9C, 0xA8, 0x01};
+
+/// API notes file major version number.
+const uint16_t VERSION_MAJOR = 0;
+
+/// API notes file minor version number.
+///
+/// When the format changes IN ANY WAY, this number should be incremented.
+const uint16_t VERSION_MINOR = 24; // EnumExtensibility + FlagEnum
+
+using IdentifierID = llvm::PointerEmbeddedInt;
+using IdentifierIDField = llvm::BCVBR<16>;
+
+using SelectorID = llvm::PointerEmbeddedInt;
+using SelectorIDField = llvm::BCVBR<16>;
+
+/// The various types of blocks that can occur within a API notes file.
+///
+/// These IDs must \em not be renumbered or reordered without incrementing
+/// VERSION_MAJOR.
+enum BlockID {
+  /// The control block, which contains all of the information that needs to
+  /// be validated prior to committing to loading the API notes file.
+  ///
+  /// \sa control_block
+  CONTROL_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
+
+  /// The identifier data block, which maps identifier strings to IDs.
+  IDENTIFIER_BLOCK_ID,
+
+  /// The Objective-C context data block, which contains information about
+  /// Objective-C classes and protocols.
+  OBJC_CONTEXT_BLOCK_ID,
+
+  /// The Objective-C property data block, which maps Objective-C
+  /// (class name, property name) pairs to information about the
+  /// property.
+  OBJC_PROPERTY_BLOCK_ID,
+
+  /// The Objective-C property data block, which maps Objective-C
+  /// (class name, selector, is_instance_method) tuples to information
+  /// about the method.
+  OBJC_METHOD_BLOCK_ID,
+
+  /// The Objective-C selector data block, which maps Objective-C
+  /// selector names (# of pieces, identifier IDs) to the selector ID
+  /// used in other tables.
+  OBJC_SELECTOR_BLOCK_ID,
+
+  /// The global variables data block, which maps global variable names to
+  /// information about the global variable.
+  GLOBAL_VARIABLE_BLOCK_ID,
+
+  /// The (global) functions data block, which maps global function names to
+  /// information about the global function.
+  GLOBAL_FUNCTION_BLOCK_ID,
+
+  /// The tag data block, which maps tag names to information about
+  /// the tags.
+  TAG_BLOCK_ID,
+
+  /// The typedef data block, which maps typedef names to information about
+  /// the typedefs.
+  TYPEDEF_BLOCK_ID,
+
+  /// The enum constant data block, which maps enumerator names to
+  /// information about the enumerators.
+  ENUM_CONSTANT_BLOCK_ID,
+};
+
+namespace control_block {
+// These IDs must \em not be renumbered or reordered without incrementing
+// VERSION_MAJOR.
+enum {
+  METADATA = 1,
+  MODULE_NAME = 2,
+  MODULE_OPTIONS = 3,
+  SOURCE_FILE = 4,
+};
+
+using MetadataLayout =
+llvm::BCRecordLayout, // Module format major version
+ llvm::BCFixed<16>  // Module format minor version
+ >;
+
+using ModuleNameLayout = llvm::BCRecordLayout;
+
+using ModuleOptionsLayout =
+llvm::BCRecordLayout // SwiftInferImportAsMember
+ >;
+
+using SourceFileLayout = llvm::BCRecordLayout, // file size
+   

[PATCH] D91997: APINotes: add bitcode format schema definitions

2020-12-08 Thread Saleem Abdulrasool 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 rGb13f74151137: APINotes: add bitcode format schema 
definitions (authored by compnerd).

Changed prior to commit:
  https://reviews.llvm.org/D91997?vs=307193=310329#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91997

Files:
  clang/lib/APINotes/APINotesFormat.h

Index: clang/lib/APINotes/APINotesFormat.h
===
--- /dev/null
+++ clang/lib/APINotes/APINotesFormat.h
@@ -0,0 +1,255 @@
+//===-- APINotesWriter.h - API Notes Writer -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
+#define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
+
+#include "llvm/ADT/PointerEmbeddedInt.h"
+#include "llvm/Bitcode/BitcodeConvenience.h"
+
+namespace clang {
+namespace api_notes {
+/// Magic number for API notes files.
+const unsigned char API_NOTES_SIGNATURE[] = {0xE2, 0x9C, 0xA8, 0x01};
+
+/// API notes file major version number.
+const uint16_t VERSION_MAJOR = 0;
+
+/// API notes file minor version number.
+///
+/// When the format changes IN ANY WAY, this number should be incremented.
+const uint16_t VERSION_MINOR = 24; // EnumExtensibility + FlagEnum
+
+using IdentifierID = llvm::PointerEmbeddedInt;
+using IdentifierIDField = llvm::BCVBR<16>;
+
+using SelectorID = llvm::PointerEmbeddedInt;
+using SelectorIDField = llvm::BCVBR<16>;
+
+/// The various types of blocks that can occur within a API notes file.
+///
+/// These IDs must \em not be renumbered or reordered without incrementing
+/// VERSION_MAJOR.
+enum BlockID {
+  /// The control block, which contains all of the information that needs to
+  /// be validated prior to committing to loading the API notes file.
+  ///
+  /// \sa control_block
+  CONTROL_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
+
+  /// The identifier data block, which maps identifier strings to IDs.
+  IDENTIFIER_BLOCK_ID,
+
+  /// The Objective-C context data block, which contains information about
+  /// Objective-C classes and protocols.
+  OBJC_CONTEXT_BLOCK_ID,
+
+  /// The Objective-C property data block, which maps Objective-C
+  /// (class name, property name) pairs to information about the
+  /// property.
+  OBJC_PROPERTY_BLOCK_ID,
+
+  /// The Objective-C property data block, which maps Objective-C
+  /// (class name, selector, is_instance_method) tuples to information
+  /// about the method.
+  OBJC_METHOD_BLOCK_ID,
+
+  /// The Objective-C selector data block, which maps Objective-C
+  /// selector names (# of pieces, identifier IDs) to the selector ID
+  /// used in other tables.
+  OBJC_SELECTOR_BLOCK_ID,
+
+  /// The global variables data block, which maps global variable names to
+  /// information about the global variable.
+  GLOBAL_VARIABLE_BLOCK_ID,
+
+  /// The (global) functions data block, which maps global function names to
+  /// information about the global function.
+  GLOBAL_FUNCTION_BLOCK_ID,
+
+  /// The tag data block, which maps tag names to information about
+  /// the tags.
+  TAG_BLOCK_ID,
+
+  /// The typedef data block, which maps typedef names to information about
+  /// the typedefs.
+  TYPEDEF_BLOCK_ID,
+
+  /// The enum constant data block, which maps enumerator names to
+  /// information about the enumerators.
+  ENUM_CONSTANT_BLOCK_ID,
+};
+
+namespace control_block {
+// These IDs must \em not be renumbered or reordered without incrementing
+// VERSION_MAJOR.
+enum {
+  METADATA = 1,
+  MODULE_NAME = 2,
+  MODULE_OPTIONS = 3,
+  SOURCE_FILE = 4,
+};
+
+using MetadataLayout =
+llvm::BCRecordLayout, // Module format major version
+ llvm::BCFixed<16>  // Module format minor version
+ >;
+
+using ModuleNameLayout = llvm::BCRecordLayout;
+
+using ModuleOptionsLayout =
+llvm::BCRecordLayout // SwiftInferImportAsMember
+ >;
+
+using SourceFileLayout = llvm::BCRecordLayout, // file size
+  llvm::BCVBR<16>  // creation time
+  >;
+} // namespace control_block
+
+namespace identifier_block {
+enum {
+  IDENTIFIER_DATA = 1,
+};
+
+using IdentifierDataLayout = llvm::BCRecordLayout<
+IDENTIFIER_DATA, // record ID
+llvm::BCVBR<16>, // table offset within the blob (see below)
+llvm::BCBlob // map from identifier strings to decl kinds / decl IDs
+>;
+} // namespace identifier_block
+
+namespace objc_context_block {
+enum {
+  OBJC_CONTEXT_ID_DATA = 1,
+  

[PATCH] D80391: [Driver] Don't make -gsplit-dwarf imply -g2

2020-12-08 Thread Fangrui Song 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 rG843f2dbf003f: [Driver] Dont make -gsplit-dwarf imply 
-g2 (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80391

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/split-debug.c


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -20,8 +20,8 @@
 // RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=NOSPLIT
 // NOSPLIT-NOT: "-split-dwarf
 
-/// -gsplit-dwarf currently enables debug fission even without -g.
-// RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=SPLIT
+/// -gsplit-dwarf is a no-op if no -g is specified.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=G0
 
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | 
FileCheck %s --check-prefix=SINGLE
@@ -59,8 +59,8 @@
 /// Interaction with -g0.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g0 -### %s 2>&1 | 
FileCheck %s --check-prefix=G0
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g0 %s 2>&1 | 
FileCheck %s --check-prefix=G0
-// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefixes=NOINLINE,SPLIT
-// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf=single %s 2>&1 | 
FileCheck %s --check-prefix=SINGLE
+// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefixes=G0
+// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf=single %s 2>&1 | 
FileCheck %s --check-prefix=G0
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g0 
-fsplit-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=G0
 
 // G0-NOT: "-debug-info-kind=
@@ -69,7 +69,7 @@
 /// Interaction with -g1 (-gmlt).
 // RUN: %clang -### -S -target x86_64 -gsplit-dwarf -g1 %s 2>&1 | FileCheck %s 
--check-prefix=G1_WITH_SPLIT
 // RUN: %clang -### -S -target x86_64 -gsplit-dwarf -g1 
-fno-split-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=G1_WITH_SPLIT
-// RUN: %clang -### -S -target x86_64 -gmlt -gsplit-dwarf 
-fno-split-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=SPLIT
+// RUN: %clang -### -S -target x86_64 -gmlt -gsplit-dwarf 
-fno-split-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=G1_WITH_SPLIT
 
 // G1_WITH_SPLIT: "-debug-info-kind=line-tables-only"
 // G1_WITH_SPLIT: "-split-dwarf-file"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3750,20 +3750,15 @@
   Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
options::OPT_fno_split_dwarf_inlining, false);
 
-  Args.ClaimAllArgs(options::OPT_g_Group);
-
-  Arg* SplitDWARFArg;
-  DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
-
-  if (DwarfFission != DwarfFissionKind::None &&
-  !checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) {
-DwarfFission = DwarfFissionKind::None;
-SplitDWARFInlining = false;
-  }
+  if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
+Arg *SplitDWARFArg;
+DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
+if (DwarfFission != DwarfFissionKind::None &&
+!checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) {
+  DwarfFission = DwarfFissionKind::None;
+  SplitDWARFInlining = false;
+}
 
-  if (const Arg *A =
-  Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
-  options::OPT_gsplit_dwarf_EQ)) {
 DebugInfoKind = codegenoptions::LimitedDebugInfo;
 
 // If the last option explicitly specified a debug-info level, use it.
@@ -4896,7 +4891,7 @@
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, , );
 
-  DwarfFissionKind DwarfFission;
+  DwarfFissionKind DwarfFission = DwarfFissionKind::None;
   RenderDebugOptions(TC, D, RawTriple, Args, EmitCodeView, CmdArgs,
  DebugInfoKind, DwarfFission);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -117,6 +117,7 @@
 - Now that `this` pointers are tagged with `nonnull` and `dereferenceable(N)`,
   `-fno-delete-null-pointer-checks` has gained the power to remove the
   `nonnull` attribute on `this` for configurations that need it to be nullable.
+- ``-gsplit-dwarf`` no longer implies ``-g2``.
 
 New Pragmas in Clang
 


Index: clang/test/Driver/split-debug.c

[clang] 843f2db - [Driver] Don't make -gsplit-dwarf imply -g2

2020-12-08 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-12-08T13:14:34-08:00
New Revision: 843f2dbf003f2a51d0d4ab8cf40647c99ded2e93

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

LOG: [Driver] Don't make -gsplit-dwarf imply -g2

RFC: http://lists.llvm.org/pipermail/cfe-dev/2020-May/065430.html
Agreement from GCC: 
https://sourceware.org/pipermail/gcc-patches/2020-May/545688.html

g_flags_Group options generally don't affect the amount of debugging
information. -gsplit-dwarf is an exception. Its order dependency with
other gN_Group options make it inconvenient in a build system:

* -g0 -gsplit-dwarf -> level 2
   -gsplit-dwarf "upgrades" the amount of debugging information despite
   the previous intention (-g0) to drop debugging information
* -g1 -gsplit-dwarf -> level 2
  -gsplit-dwarf "upgrades" the amount of debugging information.
* If we have a higher-level -gN, -gN -gsplit-dwarf will supposedly decrease the
  amount of debugging information. This happens with GCC -g3.

The non-orthogonality has confused many users. GCC 11 will change the semantics
(-gsplit-dwarf no longer implies -g2) despite the backwards compatibility break.
This patch matches its behavior.

New semantics:

* If there is a g_Group, allow split DWARF if useful
  (none of: -g0, -gline-directives-only, -g1 -fno-split-dwarf-inlining)
* Otherwise, no-op.

To restore the original behavior, replace -gsplit-dwarf with -gsplit-dwarf -g.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/split-debug.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d90d059e0659..7d68cdb99b48 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -117,6 +117,7 @@ Modified Compiler Flags
 - Now that `this` pointers are tagged with `nonnull` and `dereferenceable(N)`,
   `-fno-delete-null-pointer-checks` has gained the power to remove the
   `nonnull` attribute on `this` for configurations that need it to be nullable.
+- ``-gsplit-dwarf`` no longer implies ``-g2``.
 
 New Pragmas in Clang
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index baf7d5c58e4a..f3a6b12609e2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3750,20 +3750,15 @@ static void RenderDebugOptions(const ToolChain , 
const Driver ,
   Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
options::OPT_fno_split_dwarf_inlining, false);
 
-  Args.ClaimAllArgs(options::OPT_g_Group);
-
-  Arg* SplitDWARFArg;
-  DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
-
-  if (DwarfFission != DwarfFissionKind::None &&
-  !checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) {
-DwarfFission = DwarfFissionKind::None;
-SplitDWARFInlining = false;
-  }
+  if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
+Arg *SplitDWARFArg;
+DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
+if (DwarfFission != DwarfFissionKind::None &&
+!checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) {
+  DwarfFission = DwarfFissionKind::None;
+  SplitDWARFInlining = false;
+}
 
-  if (const Arg *A =
-  Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
-  options::OPT_gsplit_dwarf_EQ)) {
 DebugInfoKind = codegenoptions::LimitedDebugInfo;
 
 // If the last option explicitly specified a debug-info level, use it.
@@ -4896,7 +4891,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, , );
 
-  DwarfFissionKind DwarfFission;
+  DwarfFissionKind DwarfFission = DwarfFissionKind::None;
   RenderDebugOptions(TC, D, RawTriple, Args, EmitCodeView, CmdArgs,
  DebugInfoKind, DwarfFission);
 

diff  --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index 4b644c8d60ae..bd9ec32e0010 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -20,8 +20,8 @@
 // RUN: %clang -### -c -target x86_64-apple-darwin  -gsplit-dwarf -g %s 2>&1 | 
FileCheck %s --check-prefix=NOSPLIT
 // NOSPLIT-NOT: "-split-dwarf
 
-/// -gsplit-dwarf currently enables debug fission even without -g.
-// RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=SPLIT
+/// -gsplit-dwarf is a no-op if no -g is specified.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s 
--check-prefix=G0
 
 /// Test -gsplit-dwarf=single.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | 
FileCheck %s 

[PATCH] D80391: [Driver] Don't make -gsplit-dwarf imply -g2

2020-12-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I have also notified ChromeOS/Android NDK/Bazel maintainers since they use 
-gsplit-dwarf (though might not be affected).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80391

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


[PATCH] D91296: Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost NFC

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51f3432f4b52: Frontend: Clarify logic for using the preamble 
in ASTUnit::CodeComplete, almost… (authored by dexonsmith).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91296

Files:
  clang/lib/Frontend/ASTUnit.cpp


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -2237,28 +2237,30 @@
 = new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts);
   Clang->setCodeCompletionConsumer(AugmentedConsumer);
 
+  auto getUniqueID =
+  [](StringRef Filename) -> Optional {
+if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
+  return Status->getUniqueID();
+return None;
+  };
+
+  auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {
+if (LHS == RHS)
+  return true;
+if (auto LHSID = getUniqueID(LHS))
+  if (auto RHSID = getUniqueID(RHS))
+return *LHSID == *RHSID;
+return false;
+  };
+
   // If we have a precompiled preamble, try to use it. We only allow
   // the use of the precompiled preamble if we're if the completion
   // point is within the main file, after the end of the precompiled
   // preamble.
   std::unique_ptr OverrideMainBuffer;
-  if (Preamble) {
-std::string CompleteFilePath(File);
-
-auto  = FileMgr.getVirtualFileSystem();
-auto CompleteFileStatus = VFS.status(CompleteFilePath);
-if (CompleteFileStatus) {
-  llvm::sys::fs::UniqueID CompleteFileID = 
CompleteFileStatus->getUniqueID();
-
-  std::string MainPath(OriginalSourceFile);
-  auto MainStatus = VFS.status(MainPath);
-  if (MainStatus) {
-llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
-if (CompleteFileID == MainID && Line > 1)
-  OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
-  PCHContainerOps, Inv, , false, Line - 1);
-  }
-}
+  if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) {
+OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
+PCHContainerOps, Inv, (), false, Line - 
1);
   }
 
   // If the main file has been overridden due to the use of a preamble,


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -2237,28 +2237,30 @@
 = new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts);
   Clang->setCodeCompletionConsumer(AugmentedConsumer);
 
+  auto getUniqueID =
+  [](StringRef Filename) -> Optional {
+if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
+  return Status->getUniqueID();
+return None;
+  };
+
+  auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {
+if (LHS == RHS)
+  return true;
+if (auto LHSID = getUniqueID(LHS))
+  if (auto RHSID = getUniqueID(RHS))
+return *LHSID == *RHSID;
+return false;
+  };
+
   // If we have a precompiled preamble, try to use it. We only allow
   // the use of the precompiled preamble if we're if the completion
   // point is within the main file, after the end of the precompiled
   // preamble.
   std::unique_ptr OverrideMainBuffer;
-  if (Preamble) {
-std::string CompleteFilePath(File);
-
-auto  = FileMgr.getVirtualFileSystem();
-auto CompleteFileStatus = VFS.status(CompleteFilePath);
-if (CompleteFileStatus) {
-  llvm::sys::fs::UniqueID CompleteFileID = CompleteFileStatus->getUniqueID();
-
-  std::string MainPath(OriginalSourceFile);
-  auto MainStatus = VFS.status(MainPath);
-  if (MainStatus) {
-llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
-if (CompleteFileID == MainID && Line > 1)
-  OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
-  PCHContainerOps, Inv, , false, Line - 1);
-  }
-}
+  if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) {
+OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
+PCHContainerOps, Inv, (), false, Line - 1);
   }
 
   // If the main file has been overridden due to the use of a preamble,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 51f3432 - Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost NFC

2020-12-08 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2020-12-08T12:52:17-08:00
New Revision: 51f3432f4b5217b35dc2694c6e46d6cfc7defad6

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

LOG: Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, 
almost NFC

Clarify the logic for using the preamble (and overriding the main file
buffer) in `ASTUnit::CodeComplete` by factoring out a couple of lambdas
(`getUniqueID` and `hasSameUniqueID`).  While refactoring the logic,
hoist the check for `Line > 1` and locally check if the filenames are
equal (both to avoid unnecessary `stat` calls) and skip copying out the
filenames to `std::string`.

Besides fewer calls to `stat`, there's no functionality change here.

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

Added: 


Modified: 
clang/lib/Frontend/ASTUnit.cpp

Removed: 




diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index c8ac7eaa9ab8..d9154e9b459e 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -2237,28 +2237,30 @@ void ASTUnit::CodeComplete(
 = new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts);
   Clang->setCodeCompletionConsumer(AugmentedConsumer);
 
+  auto getUniqueID =
+  [](StringRef Filename) -> Optional {
+if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
+  return Status->getUniqueID();
+return None;
+  };
+
+  auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {
+if (LHS == RHS)
+  return true;
+if (auto LHSID = getUniqueID(LHS))
+  if (auto RHSID = getUniqueID(RHS))
+return *LHSID == *RHSID;
+return false;
+  };
+
   // If we have a precompiled preamble, try to use it. We only allow
   // the use of the precompiled preamble if we're if the completion
   // point is within the main file, after the end of the precompiled
   // preamble.
   std::unique_ptr OverrideMainBuffer;
-  if (Preamble) {
-std::string CompleteFilePath(File);
-
-auto  = FileMgr.getVirtualFileSystem();
-auto CompleteFileStatus = VFS.status(CompleteFilePath);
-if (CompleteFileStatus) {
-  llvm::sys::fs::UniqueID CompleteFileID = 
CompleteFileStatus->getUniqueID();
-
-  std::string MainPath(OriginalSourceFile);
-  auto MainStatus = VFS.status(MainPath);
-  if (MainStatus) {
-llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
-if (CompleteFileID == MainID && Line > 1)
-  OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
-  PCHContainerOps, Inv, , false, Line - 1);
-  }
-}
+  if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) {
+OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
+PCHContainerOps, Inv, (), false, Line - 
1);
   }
 
   // If the main file has been overridden due to the use of a preamble,



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


[PATCH] D92812: [X86] AMD Znver3 (Family 19H) Enablement

2020-12-08 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh added a comment.

In D92812#2439324 , @RKSimon wrote:

> it looks like a very bad merge imo.

Yep, Thank you! I will post smaller incremental patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92812

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


[PATCH] D73413: [clang-tidy] Add check to detect external definitions with no header declaration

2020-12-08 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73413

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


[PATCH] D91885: [clang-tidy] Add support for diagnostics with no location

2020-12-08 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG27553933a869: [clang-tidy] Add support for diagnostics with 
no location (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91885

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-case-violation.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -166,6 +166,10 @@
   ClangTidyOptions Options;
   ClangTidyContext Context(std::make_unique(
   ClangTidyGlobalOptions(), Options));
+  ClangTidyDiagnosticConsumer DiagConsumer(Context);
+  DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions,
+   , false);
+  Context.setDiagnosticsEngine();
   TestCheck TestCheck();
   CHECK_ERROR(TestCheck.getLocal("Opt"), MissingOptionError,
   "option not found 'test.Opt'");
@@ -191,6 +195,10 @@
 
   ClangTidyContext Context(std::make_unique(
   ClangTidyGlobalOptions(), Options));
+  ClangTidyDiagnosticConsumer DiagConsumer(Context);
+  DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions,
+   , false);
+  Context.setDiagnosticsEngine();
   TestCheck TestCheck();
 
 #define CHECK_ERROR_INT(Name, Expected)\
Index: clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
@@ -10,7 +10,9 @@
 class TestCheck : public ClangTidyCheck {
 public:
   TestCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context) {
+diag("DiagWithNoLoc");
+  }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override {
 Finder->addMatcher(ast_matchers::varDecl().bind("var"), this);
   }
@@ -26,9 +28,10 @@
 TEST(ClangTidyDiagnosticConsumer, SortsErrors) {
   std::vector Errors;
   runCheckOnCode("int a;", );
-  EXPECT_EQ(2ul, Errors.size());
-  EXPECT_EQ("type specifier", Errors[0].Message.Message);
-  EXPECT_EQ("variable", Errors[1].Message.Message);
+  EXPECT_EQ(3ul, Errors.size());
+  EXPECT_EQ("DiagWithNoLoc", Errors[0].Message.Message);
+  EXPECT_EQ("type specifier", Errors[1].Message.Message);
+  EXPECT_EQ("variable", Errors[2].Message.Message);
 }
 
 } // namespace test
Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-case-violation.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-case-violation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-case-violation.cpp
@@ -5,11 +5,11 @@
 // RUN:   {key: readability-identifier-naming.ClassCase, value: UUPER_CASE}, \
 // RUN:   {key: readability-identifier-naming.StructCase, value: CAMEL}, \
 // RUN:   {key: readability-identifier-naming.EnumCase, value: AnY_cASe}, \
-// RUN:   ]}" 2>&1 | FileCheck %s --implicit-check-not warning
+// RUN:   ]}" 2>&1 | FileCheck %s --implicit-check-not="{{warning|error}}:"
 
-// CHECK-DAG: warning: invalid configuration value 'camelback' for option 'readability-identifier-naming.FunctionCase'; did you mean 'camelBack'?{{$}}
-// CHECK-DAG: warning: invalid configuration value 'UUPER_CASE' for option 'readability-identifier-naming.ClassCase'; did you mean 'UPPER_CASE'?{{$}}
+// CHECK-DAG: warning: invalid configuration value 'camelback' for option 'readability-identifier-naming.FunctionCase'; did you mean 'camelBack'? [clang-tidy-config]
+// CHECK-DAG: warning: invalid configuration value 'UUPER_CASE' for 

[clang-tools-extra] 2755393 - [clang-tidy] Add support for diagnostics with no location

2020-12-08 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-12-08T20:29:31Z
New Revision: 27553933a8693d508eb7f7c24a14f66b3d006d2c

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

LOG: [clang-tidy] Add support for diagnostics with no location

Add methods for emitting diagnostics with no location as well as a special 
diagnostic for configuration errors.
These show up in the errors as [clang-tidy-config].
The reason to use a custom name rather than the check name is to distinguish 
the error isn't the same category as the check that reported it.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-case-violation.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index be68dfbedb29..af19da2419ab 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -42,7 +42,7 @@ std::string UnparseableIntegerOptionError::message() const {
 
 ClangTidyCheck::ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
 : CheckName(CheckName), Context(Context),
-  Options(CheckName, Context->getOptions().CheckOptions) {
+  Options(CheckName, Context->getOptions().CheckOptions, Context) {
   assert(Context != nullptr);
   assert(!CheckName.empty());
 }
@@ -52,6 +52,17 @@ DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, 
StringRef Message,
   return Context->diag(CheckName, Loc, Message, Level);
 }
 
+DiagnosticBuilder ClangTidyCheck::diag(StringRef Message,
+   DiagnosticIDs::Level Level) {
+  return Context->diag(CheckName, Message, Level);
+}
+
+DiagnosticBuilder
+ClangTidyCheck::configurationDiag(StringRef Description,
+  DiagnosticIDs::Level Level) {
+  return Context->configurationDiag(Description, Level);
+}
+
 void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult ) 
{
   // For historical reasons, checks don't implement the MatchFinder run()
   // callback directly. We keep the run()/check() distinction to avoid 
interface
@@ -59,9 +70,11 @@ void ClangTidyCheck::run(const 
ast_matchers::MatchFinder::MatchResult ) {
   check(Result);
 }
 
-ClangTidyCheck::OptionsView::OptionsView(StringRef CheckName,
- const ClangTidyOptions::OptionMap )
-: NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions) {}
+ClangTidyCheck::OptionsView::OptionsView(
+StringRef CheckName, const ClangTidyOptions::OptionMap ,
+ClangTidyContext *Context)
+: NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions),
+  Context(Context) {}
 
 llvm::Expected
 ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
@@ -121,7 +134,7 @@ bool ClangTidyCheck::OptionsView::get(StringRef 
LocalName,
   llvm::Expected ValueOr = get(LocalName);
   if (ValueOr)
 return *ValueOr;
-  logIfOptionParsingError(ValueOr.takeError());
+  reportOptionParsingError(ValueOr.takeError());
   return Default;
 }
 
@@ -140,7 +153,7 @@ bool 
ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName,
   llvm::Expected ValueOr = getLocalOrGlobal(LocalName);
   if (ValueOr)
 return *ValueOr;
-  logIfOptionParsingError(ValueOr.takeError());
+  reportOptionParsingError(ValueOr.takeError());
   return Default;
 }
 
@@ -199,11 +212,11 @@ llvm::Expected 
ClangTidyCheck::OptionsView::getEnumInt(
   Iter->getValue().Value);
 }
 
-void ClangTidyCheck::OptionsView::logIfOptionParsingError(llvm::Error &) {
+void ClangTidyCheck::OptionsView::reportOptionParsingError(
+llvm::Error &) const {
   if (auto RemainingErrors =
   

[PATCH] D91297: Frontend: Take VFS and MainFileBuffer by reference in PrecompiledPreamble::CanReuse, NFC

2020-12-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

@kadircet, ping, do you still have concerns?


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

https://reviews.llvm.org/D91297

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


[PATCH] D91055: [clang-tidy] Introduce misc No Integer To Pointer Cast check

2020-12-08 Thread Roman Lebedev 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 rG39431e479ffd: [clang-tidy] Introduce misc No Integer To 
Pointer Cast check (authored by lebedev.ri).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91055

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.h
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/performance-no-int-to-ptr.rst
  clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.c
  clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s performance-no-int-to-ptr %t
+
+// can't implicitly cast int to a pointer.
+// can't use static_cast<>() to cast integer to a pointer.
+// can't use dynamic_cast<>() to cast integer to a pointer.
+// can't use const_cast<>() to cast integer to a pointer.
+
+void *t0(long long int x) {
+  return (void *)x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+
+void *t1(int x) {
+  return reinterpret_cast(x);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+
+// Don't diagnose casts from integer literals.
+// It's a widely-used technique in embedded/microcontroller/hardware interfacing.
+void *t3(long long int x) {
+  return (void *)0xFEEDFACE;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.c
@@ -0,0 +1,66 @@
+// RUN: %check_clang_tidy %s performance-no-int-to-ptr %t
+
+void *t0(char x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t1(signed char x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t2(unsigned char x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+
+void *t3(short x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t4(unsigned short x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t5(signed short x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+
+void *t6(int x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t7(unsigned int x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t8(signed int x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+
+void *t9(long x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t10(unsigned long x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t11(signed long x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+
+void *t12(long long x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t13(unsigned long long x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
+}
+void *t14(signed long long x) {
+  return x;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: 

[clang-tools-extra] 39431e4 - [clang-tidy] Introduce misc No Integer To Pointer Cast check

2020-12-08 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-12-08T22:55:13+03:00
New Revision: 39431e479ffddc81120911f031921b2d637e967f

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

LOG: [clang-tidy] Introduce misc No Integer To Pointer Cast check

While casting an (integral) pointer to an integer is obvious - you just get
the integral value of the pointer, casting an integer to an (integral) pointer
is deceivingly different. While you will get a pointer with that integral value,
if you got that integral value via a pointer-to-integer cast originally,
the new pointer will lack the provenance information from the original pointer.

So while (integral) pointer to integer casts are effectively no-ops,
and are transparent to the optimizer, integer to (integral) pointer casts
are *NOT* transparent, and may conceal information from optimizer.

While that may be the intention, it is not always so. For example,
let's take a look at a routine to align the pointer up to the multiple of 16:
The obvious, naive implementation for that is:

```
  char* src(char* maybe_underbiased_ptr) {
uintptr_t maybe_underbiased_intptr = (uintptr_t)maybe_underbiased_ptr;
uintptr_t aligned_biased_intptr = maybe_underbiased_intptr + 15;
uintptr_t aligned_intptr = aligned_biased_intptr & (~15);
return (char*)aligned_intptr; // warning: avoid integer to pointer casts 
[misc-no-inttoptr]
  }
```

The check will rightfully diagnose that cast.

But when provenance concealment is not the goal of the code, but an accident,
this example can be rewritten as follows, without using integer to pointer cast:

```
  char*
  tgt(char* maybe_underbiased_ptr) {
  uintptr_t maybe_underbiased_intptr = (uintptr_t)maybe_underbiased_ptr;
  uintptr_t aligned_biased_intptr = maybe_underbiased_intptr + 15;
  uintptr_t aligned_intptr = aligned_biased_intptr & (~15);
  uintptr_t bias = aligned_intptr - maybe_underbiased_intptr;
  return maybe_underbiased_ptr + bias;
  }
```

See also:
* D71499
* [[ https://www.cs.utah.edu/~regehr/oopsla18.pdf | Juneyoung Lee, Chung-Kil 
Hur, Ralf Jung, Zhengyang Liu, John Regehr, and Nuno P. Lopes. 2018. 
Reconciling High-Level Optimizations and Low-Level Code in LLVM. Proc. ACM 
Program. Lang. 2, OOPSLA, Article 125 (November 2018), 28 pages. ]]

Reviewed By: aaron.ballman

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

Added: 
clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.h
clang-tools-extra/docs/clang-tidy/checks/performance-no-int-to-ptr.rst
clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.c
clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.cpp

Modified: 
clang-tools-extra/clang-tidy/performance/CMakeLists.txt
clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 0e38e9fc5c0c..315364641692 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -13,6 +13,7 @@ add_clang_library(clangTidyPerformanceModule
   MoveConstArgCheck.cpp
   MoveConstructorInitCheck.cpp
   NoAutomaticMoveCheck.cpp
+  NoIntToPtrCheck.cpp
   NoexceptMoveConstructorCheck.cpp
   PerformanceTidyModule.cpp
   TriviallyDestructibleCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
new file mode 100644
index ..bc82a21bbf5a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
@@ -0,0 +1,34 @@
+//===--- NoIntToPtrCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "NoIntToPtrCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace performance {
+
+void NoIntToPtrCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(castExpr(hasCastKind(CK_IntegralToPointer),
+  unless(hasSourceExpression(integerLiteral(
+ .bind("x"),
+ this);
+}
+
+void NoIntToPtrCheck::check(const MatchFinder::MatchResult ) 

[PATCH] D64034: [c++] Implement P1957R0 - narrowing pointer-to-bool

2020-12-08 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray abandoned this revision.
lichray added a comment.

Implemented in 7ef45f45f67 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64034

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


[PATCH] D91055: [clang-tidy] Introduce misc No Integer To Pointer Cast check

2020-12-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D91055#2440344 , @aaron.ballman 
wrote:

> LGTM!

Thank you for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91055

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


[PATCH] D92874: [clangd] Validate clang-tidy Checks in clangd config.

2020-12-08 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Add instrumentation in ConfigCompile to validate that items in 
ClangTidy:[Add|Remove] correspond to actual clang-tidy checks.
If they don't a warning will be presented to the user.

This is especially useful for catching typos in the glob items.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92874

Files:
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -200,6 +200,28 @@
   EXPECT_EQ(Conf.ClangTidy.CheckOptions.lookup("StrictMode"), "true");
   EXPECT_EQ(Conf.ClangTidy.CheckOptions.lookup("example-check.ExampleOption"),
 "0");
+  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
+}
+
+TEST_F(ConfigCompileTests, TidyBadChecks) {
+  Frag.ClangTidy.Add.emplace_back("unknown-check");
+  Frag.ClangTidy.Add.emplace_back("unknown-module-*");
+  Frag.ClangTidy.Remove.emplace_back("*");
+  Frag.ClangTidy.Remove.emplace_back("llvm-includeorder");
+  EXPECT_TRUE(compileAndApply());
+  // Ensure bad checks are stripped from the glob.
+  EXPECT_EQ(Conf.ClangTidy.Checks, "-*");
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  ElementsAre(AllOf(DiagMessage("Check glob 'unknown-check' doesn't "
+"specify any known clang-tidy check"),
+DiagKind(llvm::SourceMgr::DK_Warning)),
+  AllOf(DiagMessage("Check glob 'unknown-module-*' doesn't "
+"specify any known clang-tidy check"),
+DiagKind(llvm::SourceMgr::DK_Warning)),
+  AllOf(DiagMessage("Check glob 'llvm-includeorder' doesn't "
+"specify any known clang-tidy check"),
+DiagKind(llvm::SourceMgr::DK_Warning;
 }
 
 TEST_F(ConfigCompileTests, ExternalBlockWarnOnMultipleSource) {
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -23,6 +23,8 @@
 //
 //===--===//
 
+#include "../clang-tidy/ClangTidyModuleRegistry.h"
+#include "../clang-tidy/GlobList.h"
 #include "CompileCommands.h"
 #include "Config.h"
 #include "ConfigFragment.h"
@@ -30,12 +32,14 @@
 #include "Features.inc"
 #include "support/Logger.h"
 #include "support/Trace.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
@@ -347,6 +351,50 @@
 }
   }
 
+  // Warn against any Add or Remove check items that doesn't specify a valid
+  // tidy check, most likely due to a typo.
+  bool validateCheckGlob(const Located ) {
+static llvm::ArrayRef AllChecks = [] {
+  // In a simple world this would be a std::vector. However,
+  // using the bump allocator and an ArrayRef, we can drastically reduce
+  // number of allocations while simultaneously increasing cache locality.
+  static llvm::BumpPtrAllocator Alloc;
+  tidy::ClangTidyCheckFactories Factories;
+  for (tidy::ClangTidyModuleRegistry::entry E :
+   tidy::ClangTidyModuleRegistry::entries())
+E.instantiate()->addCheckFactories(Factories);
+  llvm::MutableArrayRef AllChecks(
+  Alloc.Allocate(Factories.size()), Factories.size());
+  llvm::StringRef *Iter = AllChecks.begin();
+  for (const auto  : Factories) {
+StringRef Key = Factory.getKey();
+assert(!Key.empty() && "All checks should have valid names");
+char *Ptr = Alloc.Allocate(Key.size());
+// Copy the Key into our newly allocated buffer, We don't need to worry
+// about writing a null terminator.
+memcpy(Ptr, Key.data(), Key.size());
+*Iter++ = StringRef(Ptr, Key.size());
+  }
+  assert(Iter == AllChecks.end());
+  return AllChecks;
+}();
+tidy::GlobList List(*CheckGlob);
+// Looping over the list of checks is not great in complexity, but given the
+// intricacies of glob lists, a set 

[PATCH] D92852: [NFC] Reduce include files dependency and AA header cleanup (part 2).

2020-12-08 Thread Daniil Fukalov via Phabricator via cfe-commits
dfukalov added inline comments.



Comment at: llvm/include/llvm/Analysis/AliasAnalysis.h:800
 case Instruction::Invoke:
-  return getModRefInfo((const InvokeInst *)I, Loc, AAQIP);
+  return getModRefInfo((const CallBase *)I, Loc, AAQIP);
 case Instruction::CatchPad:

RKSimon wrote:
> Is this necessary? It doesn't seem to match the pattern used for all the 
> other Instruction types.
Actually there are no `getModRefInfo(CallInst *` nor `getModRefInfo(InvokeInst 
*` but the only `getModRefInfo(CallBase *`.
There were two implicit casts from `CallInst` and `InvokeInst` in the calls to 
their base `CallBase` and it was masked by included Instructions.h.

My thought was we use explicit cast here so I decided to refine this calls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92852

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


[clang] fc750f6 - [PPC] Fixing a typo in altivec.h. Commenting out an unnecessary macro

2020-12-08 Thread Masoud Ataei via cfe-commits

Author: Masoud Ataei
Date: 2020-12-08T19:21:02Z
New Revision: fc750f609dfb2fd51b6810cc55058568dfe4b3a9

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

LOG: [PPC] Fixing a typo in altivec.h. Commenting out an unnecessary macro

Added: 


Modified: 
clang/lib/Headers/altivec.h

Removed: 




diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 24d600e95201..2b82113de311 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -3502,7 +3502,7 @@ static __inline__ vector signed __int128 __ATTRS_o_ai
 vec_div(vector signed __int128 __a, vector signed __int128 __b) {
   return __a / __b;
 }
-#endif __POWER10_VECTOR__
+#endif /* __POWER10_VECTOR__ */
 
 /* vec_xvtdiv */
 



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


[PATCH] D92847: [clangd] ExpandAutoType: Do not offer code action on lambdas.

2020-12-08 Thread Adam Czachorowski 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 rG3c5bed734f9e: [clangd] ExpandAutoType: Do not offer code 
action on lambdas. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92847

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/test/check-fail.test
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -559,8 +559,7 @@
   EXPECT_THAT(apply("au^to x = ::Func;"),
   StartsWith("fail: Could not expand type of function pointer"));
   // lambda types are not replaced
-  EXPECT_THAT(apply("au^to x = []{};"),
-  StartsWith("fail: Could not expand type of lambda expression"));
+  EXPECT_UNAVAILABLE("au^to x = []{};");
   // inline namespaces
   EXPECT_EQ(apply("au^to x = inl_ns::Visible();"),
 "Visible x = inl_ns::Visible();");
Index: clang-tools-extra/clangd/test/check-fail.test
===
--- clang-tools-extra/clangd/test/check-fail.test
+++ clang-tools-extra/clangd/test/check-fail.test
@@ -11,4 +11,5 @@
 // CHECK: All checks completed, 2 errors
 
 #include "missing.h"
-auto x = []{};
+void fun();
+auto x = fun;
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -63,6 +63,25 @@
   return N && N->ASTNode.get();
 }
 
+// Returns true iff Node is a lambda, and thus should not be expanded. Loc is
+// the location of the auto type.
+bool isDeducedAsLambda(const SelectionTree::Node *Node, SourceLocation Loc) {
+  // getDeducedType() does a traversal, which we want to avoid in prepare().
+  // But at least check this isn't auto x = []{...};, which can't ever be
+  // expanded.
+  // (It would be nice if we had an efficient getDeducedType(), instead).
+  for (const auto *It = Node; It; It = It->Parent) {
+if (const auto *DD = It->ASTNode.get()) {
+  if (DD->getTypeSourceInfo() &&
+  DD->getTypeSourceInfo()->getTypeLoc().getBeginLoc() == Loc) {
+if (auto *RD = DD->getType()->getAsRecordDecl())
+  return RD->isLambda();
+  }
+}
+  }
+  return false;
+}
+
 bool ExpandAutoType::prepare(const Selection& Inputs) {
   CachedLocation = llvm::None;
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
@@ -70,11 +89,13 @@
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
 // Code in apply() does handle 'decltype(auto)' yet.
 if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node))
+!isStructuredBindingType(Node) &&
+!isDeducedAsLambda(Node, Result.getBeginLoc()))
   CachedLocation = Result;
   }
 }
   }
+
   return (bool) CachedLocation;
 }
 


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -559,8 +559,7 @@
   EXPECT_THAT(apply("au^to x = ::Func;"),
   StartsWith("fail: Could not expand type of function pointer"));
   // lambda types are not replaced
-  EXPECT_THAT(apply("au^to x = []{};"),
-  StartsWith("fail: Could not expand type of lambda expression"));
+  EXPECT_UNAVAILABLE("au^to x = []{};");
   // inline namespaces
   EXPECT_EQ(apply("au^to x = inl_ns::Visible();"),
 "Visible x = inl_ns::Visible();");
Index: clang-tools-extra/clangd/test/check-fail.test
===
--- clang-tools-extra/clangd/test/check-fail.test
+++ clang-tools-extra/clangd/test/check-fail.test
@@ -11,4 +11,5 @@
 // CHECK: All checks completed, 2 errors
 
 #include "missing.h"
-auto x = []{};
+void fun();
+auto x = fun;
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -63,6 +63,25 @@
   return N && N->ASTNode.get();
 }
 
+// Returns true iff Node is a lambda, and thus should not be expanded. Loc is
+// the location of the auto type.
+bool isDeducedAsLambda(const SelectionTree::Node *Node, SourceLocation Loc) {
+  // getDeducedType() does a traversal, which we want to avoid in prepare().
+  // But at least check this isn't auto x = []{...};, 

[clang-tools-extra] 3c5bed7 - [clangd] ExpandAutoType: Do not offer code action on lambdas.

2020-12-08 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2020-12-08T20:03:16+01:00
New Revision: 3c5bed734f9e02bd3bc4fbd1e0acc53506823ebf

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

LOG: [clangd] ExpandAutoType: Do not offer code action on lambdas.

We can't expand lambda types anyway. Now we simply not offer the code
action instead of showing it and then returning an error in apply().

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/test/check-fail.test
clang-tools-extra/clangd/unittests/TweakTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 61f68a688252..6d38eb1de82a 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -63,6 +63,25 @@ bool isStructuredBindingType(const SelectionTree::Node *N) {
   return N && N->ASTNode.get();
 }
 
+// Returns true iff Node is a lambda, and thus should not be expanded. Loc is
+// the location of the auto type.
+bool isDeducedAsLambda(const SelectionTree::Node *Node, SourceLocation Loc) {
+  // getDeducedType() does a traversal, which we want to avoid in prepare().
+  // But at least check this isn't auto x = []{...};, which can't ever be
+  // expanded.
+  // (It would be nice if we had an efficient getDeducedType(), instead).
+  for (const auto *It = Node; It; It = It->Parent) {
+if (const auto *DD = It->ASTNode.get()) {
+  if (DD->getTypeSourceInfo() &&
+  DD->getTypeSourceInfo()->getTypeLoc().getBeginLoc() == Loc) {
+if (auto *RD = DD->getType()->getAsRecordDecl())
+  return RD->isLambda();
+  }
+}
+  }
+  return false;
+}
+
 bool ExpandAutoType::prepare(const Selection& Inputs) {
   CachedLocation = llvm::None;
   if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
@@ -70,11 +89,13 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
   if (const AutoTypeLoc Result = TypeNode->getAs()) {
 // Code in apply() does handle 'decltype(auto)' yet.
 if (!Result.getTypePtr()->isDecltypeAuto() &&
-!isStructuredBindingType(Node))
+!isStructuredBindingType(Node) &&
+!isDeducedAsLambda(Node, Result.getBeginLoc()))
   CachedLocation = Result;
   }
 }
   }
+
   return (bool) CachedLocation;
 }
 

diff  --git a/clang-tools-extra/clangd/test/check-fail.test 
b/clang-tools-extra/clangd/test/check-fail.test
index 0ee777f02cc5..dd50b59b2c79 100644
--- a/clang-tools-extra/clangd/test/check-fail.test
+++ b/clang-tools-extra/clangd/test/check-fail.test
@@ -11,4 +11,5 @@
 // CHECK: All checks completed, 2 errors
 
 #include "missing.h"
-auto x = []{};
+void fun();
+auto x = fun;

diff  --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp 
b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index 85edd92d27da..0dcf8feb786f 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -559,8 +559,7 @@ TEST_F(ExpandAutoTypeTest, Test) {
   EXPECT_THAT(apply("au^to x = ::Func;"),
   StartsWith("fail: Could not expand type of function pointer"));
   // lambda types are not replaced
-  EXPECT_THAT(apply("au^to x = []{};"),
-  StartsWith("fail: Could not expand type of lambda expression"));
+  EXPECT_UNAVAILABLE("au^to x = []{};");
   // inline namespaces
   EXPECT_EQ(apply("au^to x = inl_ns::Visible();"),
 "Visible x = inl_ns::Visible();");



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


[PATCH] D92809: [Driver] Add -gno-split-dwarf which can disable debug fission

2020-12-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92809

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


[PATCH] D67429: Improve code generation for thread_local variables:

2020-12-08 Thread Warren Ristow via Phabricator via cfe-commits
wristow added a comment.

This commit appears to be the root cause of a run-time crash related to the 
interaction of global initializers and the wrapper functions to access 
`thread_local` variables -- reported as PR48030 
.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67429

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


[PATCH] D87974: [Builtin] Add __builtin_zero_non_value_bits.

2020-12-08 Thread Jonathan Wakely via Phabricator via cfe-commits
jwakely added a comment.

In D87974#2440533 , @BillyONeal wrote:

> Of course if it's already publicly documented for you the horse has 
> presumably already left the barn which makes the discussion moot?

It's not in a shipping release yet. But the point of documenting such built-ins 
partly so that other compiler implementors (and vendors of tools such as static 
analyzers) know what they're trying to be consistent with.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87974

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


[PATCH] D90275: [clang][IR] Add support for leaf attribute

2020-12-08 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem updated this revision to Diff 310290.
gulfem marked an inline comment as done.
gulfem added a comment.

Add a new line at the end of the test file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90275

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-leaf.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-leaf.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll

Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -404,6 +404,12 @@
   ret void
 }
 
+; CHECK; define void @f69() #43
+define void @f70() nocallback
+{
+  ret void
+}
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -446,4 +452,5 @@
 ; CHECK: attributes #39 = { sanitize_memtag }
 ; CHECK: attributes #40 = { null_pointer_is_valid }
 ; CHECK: attributes #41 = { mustprogress }
+; CHECK: attributes #42 = { nocallback }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -946,6 +946,7 @@
   case Attribute::NoRecurse:
   case Attribute::InlineHint:
   case Attribute::MinSize:
+  case Attribute::NoCallback:
   case Attribute::NoDuplicate:
   case Attribute::NoFree:
   case Attribute::NoImplicitFloat:
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1597,6 +1597,7 @@
   case Attribute::NoReturn:
   case Attribute::NoSync:
   case Attribute::WillReturn:
+  case Attribute::NoCallback:
   case Attribute::NoCfCheck:
   case Attribute::NoUnwind:
   case Attribute::NoInline:
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -371,6 +371,8 @@
 return "noalias";
   if (hasAttribute(Attribute::NoBuiltin))
 return "nobuiltin";
+  if (hasAttribute(Attribute::NoCallback))
+return "nocallback";
   if (hasAttribute(Attribute::NoCapture))
 return "nocapture";
   if (hasAttribute(Attribute::NoDuplicate))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -646,6 +646,8 @@
 return bitc::ATTR_KIND_NO_ALIAS;
   case Attribute::NoBuiltin:
 return bitc::ATTR_KIND_NO_BUILTIN;
+  case Attribute::NoCallback:
+return bitc::ATTR_KIND_NO_CALLBACK;
   case Attribute::NoCapture:
 return bitc::ATTR_KIND_NO_CAPTURE;
   case Attribute::NoDuplicate:
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1433,6 +1433,8 @@
 return Attribute::NoAlias;
   case bitc::ATTR_KIND_NO_BUILTIN:
 return Attribute::NoBuiltin;
+  case bitc::ATTR_KIND_NO_CALLBACK:
+return Attribute::NoCallback;
   case bitc::ATTR_KIND_NO_CAPTURE:
 return Attribute::NoCapture;
   case bitc::ATTR_KIND_NO_DUPLICATE:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -200,6 +200,7 @@
   kw_noalias,
   kw_noundef,
   kw_nobuiltin,
+  kw_nocallback,
   kw_nocapture,
   kw_noduplicate,
   kw_nofree,
Index: llvm/lib/AsmParser/LLParser.cpp
===
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1353,6 +1353,9 @@
   break;
 case lltok::kw_naked: B.addAttribute(Attribute::Naked); break;
 case lltok::kw_nobuiltin: B.addAttribute(Attribute::NoBuiltin); break;
+case lltok::kw_nocallback:
+  B.addAttribute(Attribute::NoCallback);
+  break;
 case lltok::kw_noduplicate: B.addAttribute(Attribute::NoDuplicate); break;
 case lltok::kw_nofree: B.addAttribute(Attribute::NoFree); break;
 case lltok::kw_noimplicitfloat:
Index: llvm/lib/AsmParser/LLLexer.cpp

[PATCH] D92847: [clangd] ExpandAutoType: Do not offer code action on lambdas.

2020-12-08 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added a comment.

Also added some "const" to make clang-tidy happy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92847

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


  1   2   3   >