[PATCH] D83079: [clang][aarch64] Generate preprocessor macros for -march=armv8.6a+sve.

2020-07-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/Preprocessor/aarch64-target-features.c:415
 // CHECK-BFLOAT: __ARM_FEATURE_BF16_VECTOR_ARITHMETIC 1
-

nit: unrelated change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83079



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


[PATCH] D83268: [OpenMP][NFC] Remove unused (always fixed) arguments

2020-07-07 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

This is definitely not NFC and breaks ABI compatibility (but apparently nobody 
cares anymore).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83268



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


[clang] 3cbfe98 - [X86] Merge X86TargetInfo::setFeatureEnabled and X86TargetInfo::setFeatureEnabledImpl. NFC

2020-07-07 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2020-07-06T23:54:56-07:00
New Revision: 3cbfe988bc5cd366fb0f62e597f899b489c3834d

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

LOG: [X86] Merge X86TargetInfo::setFeatureEnabled and 
X86TargetInfo::setFeatureEnabledImpl. NFC

setFeatureEnabled is a virtual function. setFeatureEnabledImpl
was its implementation. This split was to avoid virtual calls
when we need to call setFeatureEnabled in initFeatureMap.

With C++11 we can use 'final' on setFeatureEnabled to enable
the compiler to perform de-virtualization for the initFeatureMap
calls.

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 9ea0925cb535..e280a7216645 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -108,14 +108,14 @@ bool X86TargetInfo::initFeatureMap(
   // FIXME: This *really* should not be here.
   // X86_64 always has SSE2.
   if (getTriple().getArch() == llvm::Triple::x86_64)
-setFeatureEnabledImpl(Features, "sse2", true);
+setFeatureEnabled(Features, "sse2", true);
 
   using namespace llvm::X86;
 
   SmallVector CPUFeatures;
   getFeaturesForCPU(CPU, CPUFeatures);
   for (auto &F : CPUFeatures)
-setFeatureEnabledImpl(Features, F, true);
+setFeatureEnabled(Features, F, true);
 
   if (!TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec))
 return false;
@@ -145,8 +145,8 @@ bool X86TargetInfo::initFeatureMap(
   return true;
 }
 
-void X86TargetInfo::setFeatureEnabledImpl(llvm::StringMap &Features,
-  StringRef Name, bool Enabled) {
+void X86TargetInfo::setFeatureEnabled(llvm::StringMap &Features,
+  StringRef Name, bool Enabled) const {
   if (Name == "sse4") {
 // We can get here via the __target__ attribute since that's not controlled
 // via the -msse4/-mno-sse4 command line alias. Handle this the same way

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index b783decd72be..4d76193e7e95 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -263,14 +263,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
 MacroBuilder &Builder) const override;
 
   void setFeatureEnabled(llvm::StringMap &Features, StringRef Name,
- bool Enabled) const override {
-setFeatureEnabledImpl(Features, Name, Enabled);
-  }
-
-  // This exists purely to cut down on the number of virtual calls in
-  // initFeatureMap which calls this repeatedly.
-  static void setFeatureEnabledImpl(llvm::StringMap &Features,
-StringRef Name, bool Enabled);
+ bool Enabled) const final;
 
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
@@ -279,7 +272,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
 
   bool isValidFeatureName(StringRef Name) const override;
 
-  bool hasFeature(StringRef Feature) const override;
+  bool hasFeature(StringRef Feature) const final;
 
   bool handleTargetFeatures(std::vector &Features,
 DiagnosticsEngine &Diags) override;



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


[PATCH] D83173: [VE] Correct stack alignment

2020-07-07 Thread Kazushi Marukawa via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdf3bda047d5a: [VE] Correct stack alignment (authored by 
kaz7).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83173

Files:
  clang/lib/Basic/Targets/VE.h
  clang/test/CodeGen/target-data.c
  llvm/lib/Target/VE/VETargetMachine.cpp


Index: llvm/lib/Target/VE/VETargetMachine.cpp
===
--- llvm/lib/Target/VE/VETargetMachine.cpp
+++ llvm/lib/Target/VE/VETargetMachine.cpp
@@ -41,8 +41,8 @@
   // VE supports 32 bit and 64 bits integer on registers
   Ret += "-n32:64";
 
-  // Stack alignment is 64 bits
-  Ret += "-S64";
+  // Stack alignment is 128 bits
+  Ret += "-S128";
 
   return Ret;
 }
Index: clang/test/CodeGen/target-data.c
===
--- clang/test/CodeGen/target-data.c
+++ clang/test/CodeGen/target-data.c
@@ -250,3 +250,7 @@
 // RUN: %clang_cc1 -triple bpfeb -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=BPFEB
 // BPFEB: target datalayout = "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+
+// RUN: %clang_cc1 -triple ve -o - -emit-llvm %s | \
+// RUN: FileCheck %s -check-prefix=VE
+// VE: target datalayout = "e-m:e-i64:64-n32:64-S128"
Index: clang/lib/Basic/Targets/VE.h
===
--- clang/lib/Basic/Targets/VE.h
+++ clang/lib/Basic/Targets/VE.h
@@ -45,7 +45,7 @@
 WCharType = UnsignedInt;
 WIntType = UnsignedInt;
 UseZeroLengthBitfieldAlignment = true;
-resetDataLayout("e-m:e-i64:64-n32:64-S64");
+resetDataLayout("e-m:e-i64:64-n32:64-S128");
   }
 
   void getTargetDefines(const LangOptions &Opts,


Index: llvm/lib/Target/VE/VETargetMachine.cpp
===
--- llvm/lib/Target/VE/VETargetMachine.cpp
+++ llvm/lib/Target/VE/VETargetMachine.cpp
@@ -41,8 +41,8 @@
   // VE supports 32 bit and 64 bits integer on registers
   Ret += "-n32:64";
 
-  // Stack alignment is 64 bits
-  Ret += "-S64";
+  // Stack alignment is 128 bits
+  Ret += "-S128";
 
   return Ret;
 }
Index: clang/test/CodeGen/target-data.c
===
--- clang/test/CodeGen/target-data.c
+++ clang/test/CodeGen/target-data.c
@@ -250,3 +250,7 @@
 // RUN: %clang_cc1 -triple bpfeb -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=BPFEB
 // BPFEB: target datalayout = "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+
+// RUN: %clang_cc1 -triple ve -o - -emit-llvm %s | \
+// RUN: FileCheck %s -check-prefix=VE
+// VE: target datalayout = "e-m:e-i64:64-n32:64-S128"
Index: clang/lib/Basic/Targets/VE.h
===
--- clang/lib/Basic/Targets/VE.h
+++ clang/lib/Basic/Targets/VE.h
@@ -45,7 +45,7 @@
 WCharType = UnsignedInt;
 WIntType = UnsignedInt;
 UseZeroLengthBitfieldAlignment = true;
-resetDataLayout("e-m:e-i64:64-n32:64-S64");
+resetDataLayout("e-m:e-i64:64-n32:64-S128");
   }
 
   void getTargetDefines(const LangOptions &Opts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82442: [Coroutines] Warning if the return type of coroutine_handle::address is not void*

2020-07-07 Thread JunMa via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8849831d55a2: [Coroutines] Warning if return type of 
coroutine_handle::address is not void* (authored by ChuanqiXu, committed by 
junparser).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D82442?vs=273926&id=275587#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82442

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/test/SemaCXX/coroutine_handle-addres-return-type.cpp

Index: clang/test/SemaCXX/coroutine_handle-addres-return-type.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/coroutine_handle-addres-return-type.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -verify %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template 
+struct coroutine_handle;
+
+template <>
+struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+  void *address() const;
+};
+
+template 
+struct coroutine_handle : public coroutine_handle<> {
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+} // namespace std::experimental
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() noexcept { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_void() {}
+  };
+};
+
+namespace std::experimental {
+template <>
+struct coroutine_handle : public coroutine_handle<> {
+  coroutine_handle *address() const; // expected-warning {{return type of 'coroutine_handle<>::address should be 'void*'}}
+};
+} // namespace std::experimental
+
+struct awaitable {
+  bool await_ready();
+
+  std::experimental::coroutine_handle
+  await_suspend(std::experimental::coroutine_handle<> handle);
+  void await_resume();
+} a;
+
+task f() {
+  co_await a;
+}
+
+int main() {
+  f();
+  return 0;
+}
Index: clang/lib/Sema/SemaCoroutine.cpp
===
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -391,7 +391,13 @@
 return nullptr;
 
   Expr *JustAddress = AddressExpr.get();
-  // FIXME: Check that the type of AddressExpr is void*
+
+  // Check that the type of AddressExpr is void*
+  if (!JustAddress->getType().getTypePtr()->isVoidPointerType())
+S.Diag(cast(JustAddress)->getCalleeDecl()->getLocation(),
+   diag::warn_coroutine_handle_address_invalid_return_type)
+<< JustAddress->getType();
+
   return buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume,
   JustAddress);
 }
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -1751,6 +1751,7 @@
   ~InlinedRegionBodyRAII() { CGF.AllocaInsertPt = OldAllocaIP; }
 };
   };
+
 private:
   /// CXXThisDecl - When generating code for a C++ member function,
   /// this will hold the implicit 'this' declaration.
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10527,6 +10527,9 @@
 def note_await_ready_no_bool_conversion : Note<
   "return type of 'await_ready' is required to be contextually convertible to 'bool'"
 >;
+def warn_coroutine_handle_address_invalid_return_type : Warning <
+  "return type of 'coroutine_handle<>::address should be 'void*' (have %0) in order to get capability with existing async C API.">,
+  InGroup;
 def err_coroutine_promise_final_suspend_requires_nothrow : Error<
   "the expression 'co_await __promise.final_suspend()' is required to be non-throwing"
 >;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82728: [clang] Add -Wsuggest-override

2020-07-07 Thread Logan Smith via Phabricator via cfe-commits
logan-5 updated this revision to Diff 275928.
logan-5 marked 6 inline comments as done.
logan-5 added a comment.

Addressed some feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82728

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-suggest-destructor-override
  clang/test/SemaCXX/warn-suggest-override

Index: clang/test/SemaCXX/warn-suggest-override
===
--- /dev/null
+++ clang/test/SemaCXX/warn-suggest-override
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wsuggest-override
+
+class A {
+ public:
+  ~A() {}
+  void run() {}
+};
+
+class B : public A {
+ public:
+  ~B() {}
+  void run() {}
+};
+
+class C {
+ public:
+  virtual void run() {} // expected-note 2{{overridden virtual function is here}}
+  virtual ~C() {}
+};
+
+class D : public C {
+ public:
+  void run() {}
+  // expected-warning@-1 {{'run()' overrides a member function but is not marked 'override'}}
+  ~D() {}
+};
+
+class E : public C {
+ public:
+  virtual void run() {}
+  // expected-warning@-1 {{'run()' overrides a member function but is not marked 'override'}}
+  virtual ~E() {}
+};
+
+class F : public C {
+ public:
+  void run() override {}
+  ~F() override {}
+};
+
+class G : public C {
+ public:
+  void run() final {}
+  ~G() final {}
+};
Index: clang/test/SemaCXX/warn-suggest-destructor-override
===
--- /dev/null
+++ clang/test/SemaCXX/warn-suggest-destructor-override
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wsuggest-destructor-override
+
+class A {
+ public:
+  ~A() {}
+  virtual void run() {}
+};
+
+class B : public A {
+ public:
+  ~B() {}
+};
+
+class C {
+ public:
+  virtual void run() {}
+  virtual ~C() {}  // expected-note 2{{overridden virtual function is here}}
+};
+
+class D : public C {
+ public:
+  void run() {}
+  ~D() {}
+  // expected-warning@-1 {{'~D' overrides a destructor but is not marked 'override'}}
+};
+
+class E : public C {
+ public:
+  void run() {}
+  virtual ~E() {}
+  // expected-warning@-1 {{'~E' overrides a destructor but is not marked 'override'}}
+};
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3045,7 +3045,7 @@
   << MD->getDeclName();
 }
 
-void Sema::DiagnoseAbsenceOfOverrideControl(NamedDecl *D) {
+void Sema::DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent) {
   if (D->isInvalidDecl() || D->hasAttr())
 return;
   CXXMethodDecl *MD = dyn_cast(D);
@@ -3061,12 +3061,20 @@
   return;
 
   if (MD->size_overridden_methods() > 0) {
-unsigned DiagID = isa(MD)
-  ? diag::warn_destructor_marked_not_override_overriding
-  : diag::warn_function_marked_not_override_overriding;
-Diag(MD->getLocation(), DiagID) << MD->getDeclName();
-const CXXMethodDecl *OMD = *MD->begin_overridden_methods();
-Diag(OMD->getLocation(), diag::note_overridden_virtual_function);
+auto EmitDiag = [this, MD](unsigned DiagDtor, unsigned DiagFn) {
+  unsigned DiagID = isa(MD) ? DiagDtor : DiagFn;
+  Diag(MD->getLocation(), DiagID) << MD->getDeclName();
+  const CXXMethodDecl *OMD = *MD->begin_overridden_methods();
+  Diag(OMD->getLocation(), diag::note_overridden_virtual_function);
+};
+if (Inconsistent)
+  EmitDiag(
+  diag::warn_inconsistent_destructor_marked_not_override_overriding,
+  diag::warn_inconsistent_function_marked_not_override_overriding);
+else
+  EmitDiag(
+  diag::warn_suggest_destructor_marked_not_override_overriding,
+  diag::warn_suggest_function_marked_not_override_overriding);
   }
 }
 
@@ -6749,13 +6757,10 @@
 }
   }
 
-  if (HasMethodWithOverrideControl &&
-  HasOverridingMethodWithoutOverrideControl) {
-// At least one method has the 'override' control declared.
-// Diagnose all other overridden methods which do not have 'override'
-// specified on them.
+  if (HasOverridingMethodWithoutOverrideControl) {
+bool HasInconsistentOverrideControl = HasMethodWithOverrideControl;
 for (auto *M : Record->methods())
-  DiagnoseAbsenceOfOverrideControl(M);
+  DiagnoseAbsenceOfOverrideControl(M, HasInconsistentOverrideControl);
   }
 
   // Check the defaulted secondary comparisons after any other member functions.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -6961,7 +6961,7 @@
 
   /// DiagnoseAbsenceOfOverrideControl - Diagnose if '

[PATCH] D81761: [analyzer] Force dependency checkers to be hidden

2020-07-07 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG690ff37a2869: [analyzer] Force dependency checkers to be 
hidden (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D81761?vs=274466&id=275598#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81761

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp

Index: clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
===
--- clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
+++ clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
@@ -42,17 +42,16 @@
 
 void addCustomChecker(AnalysisASTConsumer &AnalysisConsumer,
   AnalyzerOptions &AnOpts) {
-  AnOpts.CheckersAndPackages = {{"custom.CustomChecker", true}};
+  AnOpts.CheckersAndPackages = {{"test.CustomChecker", true}};
   AnalysisConsumer.AddCheckerRegistrationFn([](CheckerRegistry &Registry) {
-Registry.addChecker("custom.CustomChecker", "Description",
-   "");
+Registry.addChecker("test.CustomChecker", "Description", "");
   });
 }
 
 TEST(RegisterCustomCheckers, RegisterChecker) {
   std::string Diags;
   EXPECT_TRUE(runCheckerOnCode("void f() {;}", Diags));
-  EXPECT_EQ(Diags, "custom.CustomChecker:Custom diagnostic description\n");
+  EXPECT_EQ(Diags, "test.CustomChecker:Custom diagnostic description\n");
 }
 
 //===--===//
@@ -121,7 +120,7 @@
 void addCheckerRegistrationOrderPrinter(CheckerRegistry &Registry) {
   Registry.addChecker(registerCheckerRegistrationOrderPrinter,
   shouldRegisterCheckerRegistrationOrderPrinter,
-  "custom.RegistrationOrder", "Description", "", false);
+  "test.RegistrationOrder", "Description", "", false);
 }
 
 #define UNITTEST_CHECKER(CHECKER_NAME, DIAG_MSG)   \
@@ -142,7 +141,7 @@
   }\
   void add##CHECKER_NAME(CheckerRegistry &Registry) {  \
 Registry.addChecker(register##CHECKER_NAME, shouldRegister##CHECKER_NAME,  \
-"custom." #CHECKER_NAME, "Description", "", false);\
+"test." #CHECKER_NAME, "Description", "", false);  \
   }
 
 UNITTEST_CHECKER(StrongDep, "Strong")
@@ -155,22 +154,22 @@
 
 void addDep(AnalysisASTConsumer &AnalysisConsumer,
   AnalyzerOptions &AnOpts) {
-  AnOpts.CheckersAndPackages = {{"custom.Dep", true},
-{"custom.RegistrationOrder", true}};
+  AnOpts.CheckersAndPackages = {{"test.Dep", true},
+{"test.RegistrationOrder", true}};
   AnalysisConsumer.AddCheckerRegistrationFn([](CheckerRegistry &Registry) {
 Registry.addChecker(registerStrongDep, shouldRegisterStrongFALSE,
-"custom.Strong", "Description", "", false);
+"test.Strong", "Description", "", false);
 addStrongDep(Registry);
 addDep(Registry);
 addCheckerRegistrationOrderPrinter(Registry);
-Registry.addDependency("custom.Dep", "custom.Strong");
+Registry.addDependency("test.Dep", "test.Strong");
   });
 }
 
 TEST(RegisterDeps, UnsatisfiedDependency) {
   std::string Diags;
   EXPECT_TRUE(runCheckerOnCode("void f() {int i;}", Diags));
-  EXPECT_EQ(Diags, "custom.RegistrationOrder:custom.RegistrationOrder\n");
+  EXPECT_EQ(Diags, "test.RegistrationOrder:test.RegistrationOrder\n");
 }
 
 //===--===//
@@ -181,52 +180,52 @@
 
 void addWeakDepCheckerBothEnabled(AnalysisASTConsumer &AnalysisConsumer,
   AnalyzerOptions &AnOpts) {
-  AnOpts.CheckersAndPackages = {{"custom.Dep", true},
-{"custom.WeakDep", true},
-{"custom.RegistrationOrder", true}};
+  AnOpts.CheckersAndPackages = {{"test.Dep", true},
+{"test.WeakDep", true},
+{"test.RegistrationOrder", true}};
   AnalysisConsumer.AddCheckerRegistrationFn([=](CheckerRegistry &Registry) {
 addWeakDep(Registry);
 addDep(Registry);
 addCheckerRegistrationOrderPrinter(Registry);
-Registry.addWeakDependency("custom.Dep", "custom.WeakDep");
+Registry.addWeakDependency("test.Dep", "test.WeakDep");
   });
 }
 
 void addWeakDepCheckerBothEnabledSwitched(AnalysisASTConsumer &AnalysisConsumer,
   AnalyzerOptions &AnOpts) {
-  AnOpts.CheckersAndPackages = {{"custom.Dep", true},
-   

[PATCH] D78126: [analyzer][NFC] Don't allow dependency checkers to emit diagnostics

2020-07-07 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2956076976c: [analyzer][NFC] Don't allow dependency 
checkers to emit diagnostics (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D78126?vs=270372&id=275605#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78126

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -34,6 +34,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/CheckerRegistryData.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
@@ -2107,6 +2108,32 @@
 // Methods for BugReport and subclasses.
 //===--===//
 
+static bool isDependency(const CheckerRegistryData &Registry,
+ StringRef CheckerName) {
+  for (const std::pair &Pair : Registry.Dependencies) {
+if (Pair.second == CheckerName)
+  return true;
+  }
+  return false;
+}
+
+PathSensitiveBugReport::PathSensitiveBugReport(
+const BugType &bt, StringRef shortDesc, StringRef desc,
+const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique,
+const Decl *DeclToUnique)
+: BugReport(Kind::PathSensitive, bt, shortDesc, desc), ErrorNode(errorNode),
+  ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : SourceRange()),
+  UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
+  assert(!isDependency(ErrorNode->getState()
+   ->getAnalysisManager()
+   .getCheckerManager()
+   ->getCheckerRegistryData(),
+   bt.getCheckerName()) &&
+ "Some checkers depend on this one! We don't allow dependency "
+ "checkers to emit warnings, because checkers should depend on "
+ "*modeling*, not *diagnostics*.");
+}
+
 void PathSensitiveBugReport::addVisitor(
 std::unique_ptr visitor) {
   if (!visitor)
@@ -2195,12 +,12 @@
   return;
 case bugreporter::TrackingKind::Condition:
   return;
-  }
+}
 
-  llvm_unreachable(
-  "BugReport::markInteresting currently can only handle 2 different "
-  "tracking kinds! Please define what tracking kind should this entitiy"
-  "have, if it was already marked as interesting with a different kind!");
+llvm_unreachable(
+"BugReport::markInteresting currently can only handle 2 different "
+"tracking kinds! Please define what tracking kind should this entitiy"
+"have, if it was already marked as interesting with a different kind!");
 }
 
 void PathSensitiveBugReport::markInteresting(SymbolRef sym,
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -19,6 +19,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -135,7 +136,7 @@
   SmallVector Fixits;
 
   BugReport(Kind kind, const BugType &bt, StringRef desc)
-  : K(kind), BT(bt), Description(desc) {}
+  : BugReport(kind, bt, "", desc) {}
 
   BugReport(Kind K, const BugType &BT, StringRef ShortDescription,
 StringRef Description)
@@ -369,16 +370,13 @@
 public:
   PathSensitiveBugReport(const BugType &bt, StringRef desc,
  const ExplodedNode *errorNode)
-  : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
-ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
- : SourceRange()) {}
+  : PathSensitiveBugReport(bt, desc, desc, errorNode) {}
 
   PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef desc,
  const ExplodedNode *errorNode)
-  : BugReport(Kind::PathSensitive, bt, shortDesc, desc),
-ErrorNode(errorNode),
-ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()

[PATCH] D82921: Removed a RecursiveASTVisitor feature to visit operator kinds with different methods

2020-07-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5689b38c6a42: Removed a RecursiveASTVisitor feature to visit 
operator kinds with different… (authored by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D82921?vs=275064&id=275601#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82921

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/lib/ARCMigrate/TransProperties.cpp
  clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
@@ -403,622 +403,40 @@
 }
 )cpp";
 
-  // TraverseUnaryOperator is not called because RecursiveASTVisitor treats
-  // individual operators as subclasses, for which it calls their Traverse
-  // methods.
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::No), Code,
   R"txt(
 WalkUpFromStmt CompoundStmt
 WalkUpFromStmt IntegerLiteral(1)
-WalkUpFromStmt UnaryOperator(-)
-WalkUpFromStmt IntegerLiteral(2)
-WalkUpFromStmt IntegerLiteral(3)
-)txt"));
-
-  EXPECT_TRUE(visitorCallbackLogEqual(
-  RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
-  R"txt(
-WalkUpFromStmt IntegerLiteral(1)
-WalkUpFromStmt IntegerLiteral(2)
-WalkUpFromStmt UnaryOperator(-)
-WalkUpFromStmt IntegerLiteral(3)
-WalkUpFromStmt CompoundStmt
-)txt"));
-}
-
-TEST(RecursiveASTVisitor,
- StmtCallbacks_TraverseUnaryOperator_WalkUpFromUnaryOperator) {
-  class RecordingVisitor : public RecordingVisitorBase {
-  public:
-RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
-: RecordingVisitorBase(ShouldTraversePostOrderValue) {}
-
-bool TraverseUnaryOperator(UnaryOperator *UO) {
-  recordCallback(__func__, UO, [&]() {
-RecordingVisitorBase::TraverseUnaryOperator(UO);
-  });
-  return true;
-}
-
-bool WalkUpFromStmt(Stmt *S) {
-  recordCallback(__func__, S,
- [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
-  return true;
-}
-
-bool WalkUpFromExpr(Expr *E) {
-  recordCallback(__func__, E,
- [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
-  return true;
-}
-
-bool WalkUpFromUnaryOperator(UnaryOperator *UO) {
-  recordCallback(__func__, UO, [&]() {
-RecordingVisitorBase::WalkUpFromUnaryOperator(UO);
-  });
-  return true;
-}
-  };
-
-  StringRef Code = R"cpp(
-void test() {
-  1;
-  -2;
-  3;
-}
-)cpp";
-
-  // TraverseUnaryOperator is not called because RecursiveASTVisitor treats
-  // individual operators as subclasses, for which it calls their Traverse
-  // methods.
-  EXPECT_TRUE(visitorCallbackLogEqual(
-  RecordingVisitor(ShouldTraversePostOrder::No), Code,
-  R"txt(
-WalkUpFromStmt CompoundStmt
-WalkUpFromExpr IntegerLiteral(1)
-  WalkUpFromStmt IntegerLiteral(1)
-WalkUpFromUnaryOperator UnaryOperator(-)
-  WalkUpFromExpr UnaryOperator(-)
-WalkUpFromStmt UnaryOperator(-)
-WalkUpFromExpr IntegerLiteral(2)
-  WalkUpFromStmt IntegerLiteral(2)
-WalkUpFromExpr IntegerLiteral(3)
-  WalkUpFromStmt IntegerLiteral(3)
-)txt"));
-
-  EXPECT_TRUE(visitorCallbackLogEqual(
-  RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
-  R"txt(
-WalkUpFromExpr IntegerLiteral(1)
-  WalkUpFromStmt IntegerLiteral(1)
-WalkUpFromExpr IntegerLiteral(2)
-  WalkUpFromStmt IntegerLiteral(2)
-WalkUpFromUnaryOperator UnaryOperator(-)
-  WalkUpFromExpr UnaryOperator(-)
-WalkUpFromStmt UnaryOperator(-)
-WalkUpFromExpr IntegerLiteral(3)
-  WalkUpFromStmt IntegerLiteral(3)
-WalkUpFromStmt CompoundStmt
-)txt"));
-}
-
-TEST(RecursiveASTVisitor, StmtCallbacks_WalkUpFromUnaryOperator) {
-  class RecordingVisitor : public RecordingVisitorBase {
-  public:
-RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
-: RecordingVisitorBase(ShouldTraversePostOrderValue) {}
-
-bool WalkUpFromStmt(Stmt *S) {
-  recordCallback(__func__, S,
- [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
-  return true;
-}
-
-bool WalkUpFromExpr(Expr *E) {
-  recordCallback(__func__, E,
- [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
-  return true;
-}
-
-bool WalkUpFromUnaryOperator(UnaryOperator *UO) {
-  recordCallback(__func__, UO, [&]() {
-RecordingVisitorBase::WalkUpFromUnaryOperator(UO);
-  });
-  return true;
-}
-  };
-
-  StringRef Code = R"cpp(
-void test() {
-  1;
-  -2;
-  3;
-}
-)cpp";
-
-  EXPECT_TRUE(vis

[PATCH] D76291: [Support] Fix formatted_raw_ostream for UTF-8

2020-07-07 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe80b81d1cbf8: [Support] Fix formatted_raw_ostream for UTF-8 
(authored by ostannard).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76291

Files:
  clang/test/Analysis/checker-plugins.c
  llvm/include/llvm/Support/FormattedStream.h
  llvm/lib/Support/FormattedStream.cpp
  llvm/test/MC/ARM/lsl-zero.s
  llvm/unittests/Support/formatted_raw_ostream_test.cpp

Index: llvm/unittests/Support/formatted_raw_ostream_test.cpp
===
--- llvm/unittests/Support/formatted_raw_ostream_test.cpp
+++ llvm/unittests/Support/formatted_raw_ostream_test.cpp
@@ -29,4 +29,143 @@
   }
 }
 
+TEST(formatted_raw_ostreamTest, Test_LineColumn) {
+  // Test tracking of line and column numbers in a stream.
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  formatted_raw_ostream C(B);
+
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(0U, C.getColumn());
+
+  C << "a";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(1U, C.getColumn());
+
+  C << "bcdef";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(6U, C.getColumn());
+
+  // '\n' increments line number, sets column to zero.
+  C << "\n";
+  EXPECT_EQ(1U, C.getLine());
+  EXPECT_EQ(0U, C.getColumn());
+
+  // '\r sets column to zero without changing line number
+  C << "foo\r";
+  EXPECT_EQ(1U, C.getLine());
+  EXPECT_EQ(0U, C.getColumn());
+
+  // '\t' advances column to the next multiple of 8.
+  // FIXME: If the column number is already a multiple of 8 this will do
+  // nothing, is this behaviour correct?
+  C << "1\t";
+  EXPECT_EQ(8U, C.getColumn());
+  C << "\t";
+  EXPECT_EQ(8U, C.getColumn());
+  C << "1234567\t";
+  EXPECT_EQ(16U, C.getColumn());
+  EXPECT_EQ(1U, C.getLine());
+}
+
+TEST(formatted_raw_ostreamTest, Test_Flush) {
+  // Flushing the buffer causes the characters in the buffer to be scanned
+  // before the buffer is emptied, so line and column numbers will still be
+  // tracked properly.
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(32);
+  formatted_raw_ostream C(B);
+
+  C << "\nabc";
+  EXPECT_EQ(4U, C.GetNumBytesInBuffer());
+  C.flush();
+  EXPECT_EQ(1U, C.getLine());
+  EXPECT_EQ(3U, C.getColumn());
+  EXPECT_EQ(0U, C.GetNumBytesInBuffer());
+}
+
+TEST(formatted_raw_ostreamTest, Test_UTF8) {
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(32);
+  formatted_raw_ostream C(B);
+
+  // U+00A0 Non-breaking space: encoded as two bytes, but only one column wide.
+  C << u8"\u00a0";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(1U, C.getColumn());
+  EXPECT_EQ(2U, C.GetNumBytesInBuffer());
+
+  // U+2468 CIRCLED DIGIT NINE: encoded as three bytes, but only one column
+  // wide.
+  C << u8"\u2468";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(2U, C.getColumn());
+  EXPECT_EQ(5U, C.GetNumBytesInBuffer());
+
+  // U+0001 LINEAR B SYLLABLE B008 A: encoded as four bytes, but only one
+  // column wide.
+  C << u8"\U0001";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(3U, C.getColumn());
+  EXPECT_EQ(9U, C.GetNumBytesInBuffer());
+
+  // U+55B5, CJK character, encodes as three bytes, takes up two columns.
+  C << u8"\u55b5";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(5U, C.getColumn());
+  EXPECT_EQ(12U, C.GetNumBytesInBuffer());
+
+  // U+200B, zero-width space, encoded as three bytes but has no effect on the
+  // column or line number.
+  C << u8"\u200b";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(5U, C.getColumn());
+  EXPECT_EQ(15U, C.GetNumBytesInBuffer());
+}
+
+TEST(formatted_raw_ostreamTest, Test_UTF8Buffered) {
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(4);
+  formatted_raw_ostream C(B);
+
+  // U+2468 encodes as three bytes, so will cause the buffer to be flushed after
+  // the first byte (4 byte buffer, 3 bytes already written). We need to save
+  // the first part of the UTF-8 encoding until after the buffer is cleared and
+  // the remaining two bytes are written, at which point we can check the
+  // display width. In this case the display width is 1, so we end at column 4,
+  // with 6 bytes written into total, 2 of which are in the buffer.
+  C << u8"123\u2468";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(4U, C.getColumn());
+  EXPECT_EQ(2U, C.GetNumBytesInBuffer());
+  C.flush();
+  EXPECT_EQ(6U, A.size());
+
+  // Same as above, but with a CJK character which displays as two columns.
+  C << u8"123\u55b5";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(9U, C.getColumn());
+  EXPECT_EQ(2U, C.GetNumBytesInBuffer());
+  C.flush();
+  EXPECT_EQ(12U, A.size());
+}
+
+TEST(formatted_raw_ostreamTest, Test_UTF8TinyBuffer) {
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(1);
+  formatted_raw_ostream C(B);
+
+  // The stream has a one-byte buffer, so 

[PATCH] D83114: [clang] Fix the incorrect dependence bits for DependentExtIntType.

2020-07-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd9a241f1650: [clang] Fix the incorrect dependence bits for 
DependentExtIntType. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83114

Files:
  clang/lib/AST/Type.cpp
  clang/test/Sema/invalid-bitwidth-expr.mm


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- clang/test/Sema/invalid-bitwidth-expr.mm
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -32,3 +32,8 @@
   int X : func(); // expected-note {{in instantiation of function 
template}}
 };
 constexpr int  = sizeof(Z);
+
+struct Z2 {
+  int X : sizeof(_ExtInt(invalid())); // expected-error {{use of undeclared 
identifier}}
+};
+constexpr int s = sizeof(Z2);
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -347,15 +347,7 @@
 DependentExtIntType::DependentExtIntType(const ASTContext &Context,
  bool IsUnsigned, Expr *NumBitsExpr)
 : Type(DependentExtInt, QualType{},
-   ((NumBitsExpr->isValueDependent() || NumBitsExpr->isTypeDependent())
-? TypeDependence::Dependent
-: TypeDependence::None) |
-   (NumBitsExpr->isInstantiationDependent()
-? TypeDependence::Instantiation
-: TypeDependence::None) |
-   (NumBitsExpr->containsUnexpandedParameterPack()
-? TypeDependence::VariablyModified
-: TypeDependence::None)),
+   toTypeDependence(NumBitsExpr->getDependence())),
   Context(Context), ExprAndUnsigned(NumBitsExpr, IsUnsigned) {}
 
 bool DependentExtIntType::isUnsigned() const {


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- clang/test/Sema/invalid-bitwidth-expr.mm
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -32,3 +32,8 @@
   int X : func(); // expected-note {{in instantiation of function template}}
 };
 constexpr int  = sizeof(Z);
+
+struct Z2 {
+  int X : sizeof(_ExtInt(invalid())); // expected-error {{use of undeclared identifier}}
+};
+constexpr int s = sizeof(Z2);
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -347,15 +347,7 @@
 DependentExtIntType::DependentExtIntType(const ASTContext &Context,
  bool IsUnsigned, Expr *NumBitsExpr)
 : Type(DependentExtInt, QualType{},
-   ((NumBitsExpr->isValueDependent() || NumBitsExpr->isTypeDependent())
-? TypeDependence::Dependent
-: TypeDependence::None) |
-   (NumBitsExpr->isInstantiationDependent()
-? TypeDependence::Instantiation
-: TypeDependence::None) |
-   (NumBitsExpr->containsUnexpandedParameterPack()
-? TypeDependence::VariablyModified
-: TypeDependence::None)),
+   toTypeDependence(NumBitsExpr->getDependence())),
   Context(Context), ExprAndUnsigned(NumBitsExpr, IsUnsigned) {}
 
 bool DependentExtIntType::isUnsigned() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81750: [analyzer] Don't allow hidden checkers to emit diagnostics

2020-07-07 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfd6b4b811aa: [analyzer] Don't allow hidden checkers to 
emit diagnostics (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D81750?vs=270447&id=275607#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81750

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
  clang/test/Analysis/weak-dependencies.c

Index: clang/test/Analysis/weak-dependencies.c
===
--- clang/test/Analysis/weak-dependencies.c
+++ clang/test/Analysis/weak-dependencies.c
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 %s -verify \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=core
 
 typedef __typeof(sizeof(int)) size_t;
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false \
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -2,7 +2,7 @@
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -12,7 +12,7 @@
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2108,8 +2108,8 @@
 // Methods for BugReport and subclasses.
 //===--===//
 
-static bool isDependency(const CheckerRegistryData &Registry,
- StringRef CheckerName) {
+LLVM_ATTRIBUTE_USED static bool
+isDependency(const CheckerRegistryData &Registry, StringRef CheckerName) {
   for (const std::pair &Pair : Registry.Dependencies) {
 if (Pair.second == CheckerName)
   return true;
@@ -2117,6 +2117,17 @@
   return false;
 }
 
+LLVM_ATTRIBUTE_USED static bool isHidden(const CheckerRegistryData &Registry,
+ StringRef CheckerName) {
+  for (const CheckerInfo &Checker : Registry.Checkers) {
+if (Checker.FullName == CheckerName)
+  return Checker.IsHidden;
+  }
+  llvm_unreachable(
+  "Checker name not found in CheckerRegistry -- did you retrieve it "
+  "correctly from CheckerManager::getCurrentCheckerName?");
+}
+
 PathSensitiveBugReport::PathSensitiveBugReport(
 const BugType &bt, StringRef shortDesc, StringRef desc,
 const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique,
@@ -2132,6 +2143,16 @@
  "Some checkers depend on this one! We don't allow dependency "
  "checkers to emit warnings, because checkers should depend on "
  "*modeling*, not *diagnostics*.");
+
+  assert(
+  bt.getCheckerName().startswith("debug") ||
+  !isHidden(ErrorNode->getState()
+->getAnalysisManager()
+.getCheckerManager()
+->getCheckerRegistryData(),
+bt.getCheckerName()) &&
+  "Hidden checkers musn't emit dia

[PATCH] D82825: [clang-tidy] Added alias llvm-else-after-return.

2020-07-07 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc3c693b617f: [clang-tidy] Added alias 
llvm-else-after-return. (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82825

Files:
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm-else-after-return.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst
@@ -77,3 +77,13 @@
the ``if`` statement is the last statement in its parents scope.
Default value is `true`.
 
+
+LLVM alias
+--
+
+There is an alias of this check called llvm-else-after-return.
+In that version the options :option:`WarnOnUnfixable` and 
+:option:`WarnOnConditionVariables` are both set to `false` by default.
+
+This check helps to enforce this `LLVM Coding Standards recommendation
+`_.
Index: clang-tools-extra/docs/clang-tidy/checks/llvm-else-after-return.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvm-else-after-return.rst
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - llvm-else-after-return
+.. meta::
+   :http-equiv=refresh: 5;URL=readability-else-after-return.html
+
+llvm-else-after-return
+==
+
+The llvm-else-after-return check is an alias, please see
+`readability-else-after-return `_
+for more information.
+
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -423,4 +423,5 @@
`hicpp-use-nullptr `_, `modernize-use-nullptr 
`_, "Yes"
`hicpp-use-override `_, `modernize-use-override 
`_, "Yes"
`hicpp-vararg `_, `cppcoreguidelines-pro-type-vararg 
`_,
+   `llvm-else-after-return `_, 
`readability-else-after-return `_, "Yes"
`llvm-qualified-auto `_, 
`readability-qualified-auto `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -192,6 +192,11 @@
   :doc:`bugprone-signed-char-misuse
   ` was added.
 
+- New alias :doc:`llvm-else-after-return
+  ` to
+  :doc:`readability-else-after-return
+  ` was added.
+
 Changes in existing checks
 ^^
 
Index: clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "../readability/ElseAfterReturnCheck.h"
 #include "../readability/NamespaceCommentCheck.h"
 #include "../readability/QualifiedAutoCheck.h"
 #include "HeaderGuardCheck.h"
@@ -24,6 +25,8 @@
 class LLVMModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"llvm-else-after-return");
 CheckFactories.registerCheck("llvm-header-guard");
 CheckFactories.registerCheck("llvm-include-order");
 CheckFactories.registerCheck(
@@ -40,6 +43,9 @@
   ClangTidyOptions getModuleOptions() override {
 ClangTidyOptions Options;
 Options.CheckOptions["llvm-qualified-auto.AddConstToQualified"] = "0";
+Options.CheckOptions["llvm-else-after-return.WarnOnUnfixable"] = "0";
+Options.CheckOptions["llvm-else-after-return.RefactorConditionVariables"] =
+"0";
 return Options;
   }
 };


Index: clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-else-after-return.rst
@@ -77,3 +77,13 @@
the ``if`` statement is the last statement in its parents scope.
Default value is `true`.
 
+
+LLVM alias
+--
+
+There is an alias of this check called llvm-else-after-return.
+In that version the options :option:`WarnOnUnfixable` and 
+:option:`WarnOnConditionVariables` are both set to `false` by default.
+
+This check helps to enforce this `LLVM Coding Standards recommen

[PATCH] D80952: [FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support.

2020-07-07 Thread Kevin P. Neal via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39d2ae0afb23: [FPEnv][Clang][Driver] Disable constrained 
floating point on targets lacking… (authored by kpn).

Changed prior to commit:
  https://reviews.llvm.org/D80952?vs=272530&id=275620#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80952

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/CodeGen/aarch64-neon-misc-constrained.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
  clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
  clang/test/CodeGen/arm64-vrnd-constrained.c
  clang/test/CodeGen/builtins-ppc-fpconstrained.c
  clang/test/CodeGen/fp-strictfp.cpp

Index: clang/test/CodeGen/fp-strictfp.cpp
===
--- /dev/null
+++ clang/test/CodeGen/fp-strictfp.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple mips64-linux-gnu -frounding-math -ffp-exception-behavior=strict -O2 -verify=rounding,exception -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple mips64-linux-gnu -ffp-exception-behavior=strict -O2 -verify=exception -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple mips64-linux-gnu -frounding-math -O2 -verify=rounding -emit-llvm -o - %s | FileCheck %s
+//
+// Verify that constrained intrinsics are not used.
+// As more targets gain support for constrained intrinsics the triple
+// in this test will need to change.
+
+// rounding-warning@* {{overriding currently unsupported rounding mode on this target}}
+// exception-warning@* {{overriding currently unsupported use of floating point exceptions on this target}}
+float fp_precise_1(float a, float b, float c) {
+// CHECK: _Z12fp_precise_1fff
+// CHECK: %[[M:.+]] = fmul float{{.*}}
+// CHECK: fadd float %[[M]], %c
+  return a * b + c;
+}
+
+
Index: clang/test/CodeGen/builtins-ppc-fpconstrained.c
===
--- clang/test/CodeGen/builtins-ppc-fpconstrained.c
+++ clang/test/CodeGen/builtins-ppc-fpconstrained.c
@@ -12,6 +12,9 @@
 // RUN: -o - %s | FileCheck --check-prefix=CHECK-ASM \
 // RUN: --check-prefix=FIXME-CHECK  %s
 
+// Disabled until constrained floating point is completed for PowerPC.
+// XFAIL: *
+
 typedef __attribute__((vector_size(4 * sizeof(float float vec_float;
 typedef __attribute__((vector_size(2 * sizeof(double double vec_double;
 
Index: clang/test/CodeGen/arm64-vrnd-constrained.c
===
--- clang/test/CodeGen/arm64-vrnd-constrained.c
+++ clang/test/CodeGen/arm64-vrnd-constrained.c
@@ -9,6 +9,9 @@
 
 // REQUIRES: aarch64-registered-target
 
+// Disabled until constrained floating point is implemented for arm64.
+// XFAIL: *
+
 #include 
 
 float64x2_t rnd5(float64x2_t a) { return vrndq_f64(a); }
Index: clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
===
--- clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
+++ clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
@@ -32,6 +32,9 @@
 
 // REQUIRES: arm-registered-target,aarch64-registered-target
 
+// Disabled until constrained floating point is implemented for arm64.
+// XFAIL: *
+
 #include 
 
 // COMMON-LABEL: test_vrndi_f32
Index: clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
@@ -19,6 +19,9 @@
 
 // REQUIRES: aarch64-registered-target
 
+// Disabled until constrained floating point is implemented for arm64.
+// XFAIL: *
+
 #include 
 
 // COMMON-LABEL: test_vsqrt_f16
Index: clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
+++ clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
@@ -15,6 +15,9 @@
 
 // REQUIRES: aarch64-registered-target
 
+// Disabled until constrained floating point is implemented for arm64.
+// XFAIL: *
+
 // Test new aarch64 intrinsics and types but constrained
 
 #include 
Index: clang/test/CodeGen/aarch64-neon-misc-constrained.c
===
--- clang/test/CodeGen/aarch64-neon-misc-constrained.c
+++ clang/test/CodeGen/aarc

[PATCH] D82425: [SemaCXX] Fix false positive of -Wuninitialized-const-reference in empty function body.

2020-07-07 Thread Zequan Wu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG054704082b46: [SemaCXX] Fix false positive of 
-Wuninitialized-const-reference in empty… (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82425

Files:
  clang/lib/Analysis/UninitializedValues.cpp
  clang/test/SemaCXX/warn-uninitialized-const-reference.cpp


Index: clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
===
--- clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
+++ clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-const-reference -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions 
-Wuninitialized-const-reference -verify %s
 
 class A {
 public:
@@ -9,6 +9,16 @@
   bool operator!=(const A &);
 };
 
+template 
+void ignore_template(const T &) {}
+void ignore(const int &i) {}
+void dont_ignore_non_empty(const int &i) { ; } // Calling this won't silence 
the warning for you
+void dont_ignore_block(const int &i) {
+  {}
+} // Calling this won't silence the warning for you
+void ignore_function_try_block_maybe_who_knows(const int &) try {
+} catch (...) {
+}
 A const_ref_use_A(const A &a);
 int const_ref_use(const int &i);
 A const_use_A(const A a);
@@ -33,4 +43,13 @@
   if (a < 42)
 m = 1;
   const_ref_use(m);
+
+  int l;
+  ignore_template(l); // This is a pattern to avoid "unused variable" warnings 
(e.g. boost::ignore_unused).
+  ignore(l);
+  dont_ignore_non_empty(l); // expected-warning {{variable 'l' is 
uninitialized when passed as a const reference argument here}}
+  int l1;
+  dont_ignore_block(l1); // expected-warning {{variable 'l1' is uninitialized 
when passed as a const reference argument here}}
+  int l2;
+  ignore_function_try_block_maybe_who_knows(l2); // expected-warning 
{{variable 'l2' is uninitialized when passed as a const reference argument 
here}}
 }
Index: clang/lib/Analysis/UninitializedValues.cpp
===
--- clang/lib/Analysis/UninitializedValues.cpp
+++ clang/lib/Analysis/UninitializedValues.cpp
@@ -405,6 +405,15 @@
   return QT->isAnyPointerType() && QT->getPointeeType().isConstQualified();
 }
 
+static bool hasTrivialBody(CallExpr *CE) {
+  if (FunctionDecl *FD = CE->getDirectCallee()) {
+if (FunctionTemplateDecl *FTD = FD->getPrimaryTemplate())
+  return FTD->getTemplatedDecl()->hasTrivialBody();
+return FD->hasTrivialBody();
+  }
+  return false;
+}
+
 void ClassifyRefs::VisitCallExpr(CallExpr *CE) {
   // Classify arguments to std::move as used.
   if (CE->isCallToStdMove()) {
@@ -413,7 +422,7 @@
   classify(CE->getArg(0), Use);
 return;
   }
-
+  bool isTrivialBody = hasTrivialBody(CE);
   // If a value is passed by const pointer to a function,
   // we should not assume that it is initialized by the call, and we
   // conservatively do not assume that it is used.
@@ -423,7 +432,7 @@
I != E; ++I) {
 if ((*I)->isGLValue()) {
   if ((*I)->getType().isConstQualified())
-classify((*I), ConstRefUse);
+classify((*I), isTrivialBody ? Ignore : ConstRefUse);
 } else if (isPointerToConst((*I)->getType())) {
   const Expr *Ex = stripCasts(DC->getParentASTContext(), *I);
   const auto *UO = dyn_cast(Ex);


Index: clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
===
--- clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
+++ clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-const-reference -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wuninitialized-const-reference -verify %s
 
 class A {
 public:
@@ -9,6 +9,16 @@
   bool operator!=(const A &);
 };
 
+template 
+void ignore_template(const T &) {}
+void ignore(const int &i) {}
+void dont_ignore_non_empty(const int &i) { ; } // Calling this won't silence the warning for you
+void dont_ignore_block(const int &i) {
+  {}
+} // Calling this won't silence the warning for you
+void ignore_function_try_block_maybe_who_knows(const int &) try {
+} catch (...) {
+}
 A const_ref_use_A(const A &a);
 int const_ref_use(const int &i);
 A const_use_A(const A a);
@@ -33,4 +43,13 @@
   if (a < 42)
 m = 1;
   const_ref_use(m);
+
+  int l;
+  ignore_template(l); // This is a pattern to avoid "unused variable" warnings (e.g. boost::ignore_unused).
+  ignore(l);
+  dont_ignore_non_empty(l); // expected-warning {{variable 'l' is uninitialized when passed as a const reference argument here}}
+  int l1;
+  dont_ignore_block(l1); // expected-warning {{variable 'l1' is uninitialized when passed as

[PATCH] D83084: DomTree: Remove the releaseMemory() method

2020-07-07 Thread Nicolai Hähnle via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG723a44c9b5d6: DomTree: Remove the releaseMemory() method 
(authored by nhaehnle).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83084

Files:
  clang/include/clang/Analysis/Analyses/Dominators.h
  llvm/include/llvm/Analysis/PostDominators.h
  llvm/include/llvm/IR/Dominators.h
  llvm/include/llvm/Support/GenericDomTree.h


Index: llvm/include/llvm/Support/GenericDomTree.h
===
--- llvm/include/llvm/Support/GenericDomTree.h
+++ llvm/include/llvm/Support/GenericDomTree.h
@@ -325,8 +325,6 @@
 return false;
   }
 
-  void releaseMemory() { reset(); }
-
   /// getNode - return the (Post)DominatorTree node for the specified basic
   /// block.  This is the same as using operator[] on this class.  The result
   /// may (but is not required to) be null for a forward (backwards)
@@ -760,9 +758,6 @@
 return DomTreeBuilder::Verify(*this, VL);
   }
 
-protected:
-  void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
-
   void reset() {
 DomTreeNodes.clear();
 Roots.clear();
@@ -772,6 +767,9 @@
 SlowQueries = 0;
   }
 
+protected:
+  void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
+
   // NewBB is split and now it has one successor. Update dominator tree to
   // reflect this change.
   template 
Index: llvm/include/llvm/IR/Dominators.h
===
--- llvm/include/llvm/IR/Dominators.h
+++ llvm/include/llvm/IR/Dominators.h
@@ -277,7 +277,7 @@
 AU.setPreservesAll();
   }
 
-  void releaseMemory() override { DT.releaseMemory(); }
+  void releaseMemory() override { DT.reset(); }
 
   void print(raw_ostream &OS, const Module *M = nullptr) const override;
 };
Index: llvm/include/llvm/Analysis/PostDominators.h
===
--- llvm/include/llvm/Analysis/PostDominators.h
+++ llvm/include/llvm/Analysis/PostDominators.h
@@ -88,9 +88,7 @@
 AU.setPreservesAll();
   }
 
-  void releaseMemory() override {
-DT.releaseMemory();
-  }
+  void releaseMemory() override { DT.reset(); }
 
   void print(raw_ostream &OS, const Module*) const override;
 };
Index: clang/include/clang/Analysis/Analyses/Dominators.h
===
--- clang/include/clang/Analysis/Analyses/Dominators.h
+++ clang/include/clang/Analysis/Analyses/Dominators.h
@@ -167,9 +167,7 @@
   }
 
   /// Releases the memory held by the dominator tree.
-  virtual void releaseMemory() {
-DT.releaseMemory();
-  }
+  virtual void releaseMemory() { DT.reset(); }
 
   /// Converts the dominator tree to human readable form.
   virtual void print(raw_ostream &OS, const llvm::Module* M= nullptr) const {


Index: llvm/include/llvm/Support/GenericDomTree.h
===
--- llvm/include/llvm/Support/GenericDomTree.h
+++ llvm/include/llvm/Support/GenericDomTree.h
@@ -325,8 +325,6 @@
 return false;
   }
 
-  void releaseMemory() { reset(); }
-
   /// getNode - return the (Post)DominatorTree node for the specified basic
   /// block.  This is the same as using operator[] on this class.  The result
   /// may (but is not required to) be null for a forward (backwards)
@@ -760,9 +758,6 @@
 return DomTreeBuilder::Verify(*this, VL);
   }
 
-protected:
-  void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
-
   void reset() {
 DomTreeNodes.clear();
 Roots.clear();
@@ -772,6 +767,9 @@
 SlowQueries = 0;
   }
 
+protected:
+  void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
+
   // NewBB is split and now it has one successor. Update dominator tree to
   // reflect this change.
   template 
Index: llvm/include/llvm/IR/Dominators.h
===
--- llvm/include/llvm/IR/Dominators.h
+++ llvm/include/llvm/IR/Dominators.h
@@ -277,7 +277,7 @@
 AU.setPreservesAll();
   }
 
-  void releaseMemory() override { DT.releaseMemory(); }
+  void releaseMemory() override { DT.reset(); }
 
   void print(raw_ostream &OS, const Module *M = nullptr) const override;
 };
Index: llvm/include/llvm/Analysis/PostDominators.h
===
--- llvm/include/llvm/Analysis/PostDominators.h
+++ llvm/include/llvm/Analysis/PostDominators.h
@@ -88,9 +88,7 @@
 AU.setPreservesAll();
   }
 
-  void releaseMemory() override {
-DT.releaseMemory();
-  }
+  void releaseMemory() override { DT.reset(); }
 
   void print(raw_ostream &OS, const Module*) const override;
 };
Index: clang/include/clang/Analysis/Analyses/Dominators.h
===
--- clang/include/clang/Analysis/Analyses/Dominators.h
+++ clang/include/clang/Analysis/Analyses/Dominators.

[PATCH] D82821: [WebAssembly] Added 64-bit memory.grow/size/init/copy/fill

2020-07-07 Thread Wouter van Oortmerssen via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16d83c395a1f: [WebAssembly] Added 64-bit 
memory.grow/size/copy/fill (authored by aardappel).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D82821?vs=275258&id=275627#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82821

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td
  llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
  llvm/test/CodeGen/WebAssembly/bulk-memory-intrinsics.ll
  llvm/test/CodeGen/WebAssembly/bulk-memory64.ll
  llvm/test/CodeGen/WebAssembly/memory-addr64.ll
  llvm/test/MC/WebAssembly/bulk-memory-encodings.s

Index: llvm/test/MC/WebAssembly/bulk-memory-encodings.s
===
--- llvm/test/MC/WebAssembly/bulk-memory-encodings.s
+++ llvm/test/MC/WebAssembly/bulk-memory-encodings.s
@@ -1,4 +1,5 @@
 # RUN: llvm-mc -show-encoding -triple=wasm32-unknown-unknown -mattr=+bulk-memory < %s | FileCheck %s
+# RUN: llvm-mc -show-encoding -triple=wasm64-unknown-unknown -mattr=+bulk-memory < %s | FileCheck %s
 
 main:
 .functype main () -> ()
Index: llvm/test/CodeGen/WebAssembly/memory-addr64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/memory-addr64.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
+
+; Test that basic memory operations assemble as expected with 64-bit addresses.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm64-unknown-unknown"
+
+declare i64 @llvm.wasm.memory.size.i64(i32) nounwind readonly
+declare i64 @llvm.wasm.memory.grow.i64(i32, i64) nounwind
+
+; CHECK-LABEL: memory_size:
+; CHECK-NEXT: .functype memory_size () -> (i64){{$}}
+; CHECK-NEXT: memory.size $push0=, 0{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i64 @memory_size() {
+  %a = call i64 @llvm.wasm.memory.size.i64(i32 0)
+  ret i64 %a
+}
+
+; CHECK-LABEL: memory_grow:
+; CHECK-NEXT: .functype memory_grow (i64) -> (i64){{$}}
+; CHECK: memory.grow $push0=, 0, $0{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i64 @memory_grow(i64 %n) {
+  %a = call i64 @llvm.wasm.memory.grow.i64(i32 0, i64 %n)
+  ret i64 %a
+}
Index: llvm/test/CodeGen/WebAssembly/bulk-memory64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/bulk-memory64.ll
@@ -0,0 +1,210 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+bulk-memory | FileCheck %s --check-prefixes CHECK,BULK-MEM
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=-bulk-memory | FileCheck %s --check-prefixes CHECK,NO-BULK-MEM
+
+; Test that basic bulk memory codegen works correctly
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm64-unknown-unknown"
+
+declare void @llvm.memcpy.p0i8.p0i8.i8(i8*, i8*, i8, i1)
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1)
+declare void @llvm.memcpy.p0i32.p0i32.i64(i32*, i32*, i64, i1)
+
+declare void @llvm.memmove.p0i8.p0i8.i8(i8*, i8*, i8, i1)
+declare void @llvm.memmove.p0i8.p0i8.i64(i8*, i8*, i64, i1)
+declare void @llvm.memmove.p0i32.p0i32.i64(i32*, i32*, i64, i1)
+
+declare void @llvm.memset.p0i8.i8(i8*, i8, i8, i1)
+declare void @llvm.memset.p0i8.i64(i8*, i8, i64, i1)
+declare void @llvm.memset.p0i32.i64(i32*, i8, i64, i1)
+
+; CHECK-LABEL: memcpy_i8:
+; NO-BULK-MEM-NOT: memory.copy
+; BULK-MEM-NEXT: .functype memcpy_i8 (i64, i64, i32) -> ()
+; BULK-MEM-NEXT: i64.extend_i32_u $push0=, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop0
+; BULK-MEM-NEXT: return
+define void @memcpy_i8(i8* %dest, i8* %src, i8 zeroext %len) {
+  call void @llvm.memcpy.p0i8.p0i8.i8(i8* %dest, i8* %src, i8 %len, i1 0)
+  ret void
+}
+
+; CHECK-LABEL: memmove_i8:
+; NO-BULK-MEM-NOT: memory.copy
+; BULK-MEM-NEXT: .functype memmove_i8 (i64, i64, i32) -> ()
+; BULK-MEM-NEXT: i64.extend_i32_u $push0=, $2
+; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop0
+; BULK-MEM-NEXT: return
+define void @memmove_i8(i8* %dest, i8* %src, i8 zeroext %len) {
+  call void @llvm.memmove.p0i8.p0i8.i8(i8* %dest, i8* %src, i8 %len, i1 0)
+  ret void
+}
+
+; CHECK-LABEL: memset_i8:
+; NO-BULK-MEM-NOT: memory.fill
+; BULK-MEM-NEXT

[PATCH] D83183: [clang] Rework how and when APValues are dumped

2020-07-07 Thread Bruno Ricci via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf63e3ea558bb: [clang] Rework how and when APValues are 
dumped (authored by riccibruno).

Changed prior to commit:
  https://reviews.llvm.org/D83183?vs=275575&id=275633#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83183

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTDumper.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/alignas_maybe_odr_cleanup.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-APValue-arithmetic.cpp
  clang/test/AST/ast-dump-APValue-array.cpp
  clang/test/AST/ast-dump-APValue-struct.cpp
  clang/test/AST/ast-dump-APValue-todo.cpp
  clang/test/AST/ast-dump-APValue-union.cpp
  clang/test/AST/ast-dump-APValue-vector.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/AST/ast-dump-color.cpp
  clang/test/AST/ast-dump-constant-expr.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-records.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/AST/pr43983.cpp
  clang/test/Import/switch-stmt/test.cpp
  clang/test/Tooling/clang-check-ast-dump.cpp

Index: clang/test/Tooling/clang-check-ast-dump.cpp
===
--- clang/test/Tooling/clang-check-ast-dump.cpp
+++ clang/test/Tooling/clang-check-ast-dump.cpp
@@ -33,6 +33,7 @@
 // CHECK-ATTR-NEXT: FieldDecl{{.*}}n
 // CHECK-ATTR-NEXT:   AlignedAttr
 // CHECK-ATTR-NEXT: ConstantExpr
+// CHECK-ATTR-NEXT:   value: Int 2
 // CHECK-ATTR-NEXT:   BinaryOperator
 //
 // RUN: clang-check -ast-dump -ast-dump-filter test_namespace::AfterNullNode "%s" -- 2>&1 | FileCheck -check-prefix CHECK-AFTER-NULL %s
Index: clang/test/Import/switch-stmt/test.cpp
===
--- clang/test/Import/switch-stmt/test.cpp
+++ clang/test/Import/switch-stmt/test.cpp
@@ -5,20 +5,26 @@
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 1
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 2
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: BreakStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 3
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 4
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 5
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 5
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: BreakStmt
 
@@ -30,16 +36,20 @@
 // CHECK-NEXT: CompoundStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 1
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: BreakStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 2
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: BreakStmt
 // CHECK-NEXT: CaseStmt
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 3
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: ConstantExpr
+// CHECK-NEXT: value: Int 5
 // CHECK-NEXT: IntegerLiteral
 // CHECK-NEXT: BreakStmt
 
Index: clang/test/AST/pr43983.cpp
===
--- clang/test/AST/pr43983.cpp
+++ clang/test/AST/pr43983.cpp
@@ -9,6 +9,7 @@
 
 struct B { _Alignas(64) struct { int b; };   };
 
-// CHECK: AlignedAttr {{.*}} _Alignas
-// CHECK: ConstantExpr {{.*}} 64
-// CHECK: IntegerLiteral {{.*}} 64
+// CHECK:  | `-AlignedAttr {{.*}}  _Alignas
+// CHECK-NEXT:  |   `-ConstantExpr {{.*}}  'int'
+// CHECK-NEXT:  | |-value: Int 64
+// CHECK-NEXT:  | `-IntegerLiteral {{.*}}  'int' 64
Index: clang/test/AST/ast-dump-stmt.cpp
===
--- clang/test/AST/ast-dump-stmt.cpp
+++ clang/test/AST/ast-dump-stmt.cpp
@@ -130,6 +130,7 @@
 ;
   // CHECK: IfStmt 0x{{[^ ]*}} 
   // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}}  'bool'
+  // CHECK-NEXT: value: Int 1
   // CHECK-NEXT: BinaryOperator
   // CHECK-NEXT: UnaryExprOrTypeTraitExpr
   // CHECK-NEXT: ParenExpr
@@ -144,6 +145,7 @@
 ;
   // CHECK: IfStmt 0x{{[^ ]*}}  has_else
   // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}}  'bool'
+  // CHECK-NEXT: value: Int 1
   // CHECK-NEXT: BinaryOperator
   // CHECK-NEXT: UnaryExprOrTypeTraitExpr
   // CHECK-NEXT: ParenExpr
Index: clang/test/AST/ast-dump-records.cpp
===
--- clang/test/AST/ast-dump-records.cpp
+++ clang/test/AST/ast-dump-records.cpp
@@ -15,7 +15,7 @@
 // CHECK: CXXRe

[PATCH] D83233: [clangd] Enable reading config from files by default.

2020-07-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:436
+"Project config is from a .clangd file in the project directory.\n"
+"User config is from clangd/config.yaml in the following 
directories:\n"
+"\tWindows: %USERPROFILE%\\AppData\\Local\n"

nit: maybe worth mentioning that the user config has higher privilege.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:440
+"\tOthers: $XDG_CONFIG_HOME, usually ~/.config"),
+init(true),
+};

nit: I'd keep this flag off in this patch, and flip it in a new patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83233



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


[PATCH] D82520: [Power10] Implement Vector Splat Immediate Builtins in LLVM/Clang

2020-07-07 Thread Lei Huang via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c6b6e28e70c: [PowerPC] Implement Vector Splat Immediate 
Builtins in Clang (authored by biplmish, committed by lei).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D82520?vs=274748&id=275642#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82520

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/test/CodeGen/PowerPC/p10-splatImm.ll

Index: llvm/test/CodeGen/PowerPC/p10-splatImm.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm.ll
@@ -286,3 +286,21 @@
 entry:
   ret double 0.00e+00
 }
+
+define dso_local <4 x i32> @vec_splati() local_unnamed_addr {
+; CHECK-LABEL: vec_splati:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xxspltiw vs34, -17
+; CHECK-NEXT:blr
+entry:
+  ret <4 x i32> 
+}
+
+define dso_local <2 x double> @vec_splatid() local_unnamed_addr {
+; CHECK-LABEL: vec_splatid:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xxspltidp vs34, 1065353216
+; CHECK-NEXT:blr
+entry:
+  ret <2 x double> 
+}
Index: clang/test/CodeGen/builtins-ppc-p10vector.c
===
--- clang/test/CodeGen/builtins-ppc-p10vector.c
+++ clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -512,3 +512,72 @@
   // CHECK-LE-NEXT: ret <4 x i32>
   return vec_inserth(vuia, vuib, uia);
 }
+
+vector signed int test_vec_vec_splati_si(void) {
+  // CHECK-BE: ret <4 x i32> 
+  // CHECK: ret <4 x i32> 
+  return vec_splati(-17);
+}
+
+vector unsigned int test_vec_vec_splati_ui(void) {
+  // CHECK-BE: ret <4 x i32> 
+  // CHECK: ret <4 x i32> 
+  return vec_splati(16U);
+}
+
+vector float test_vec_vec_splati_f(void) {
+  // CHECK-BE: ret <4 x float> 
+  // CHECK: ret <4 x float> 
+  return vec_splati(1.0f);
+}
+
+vector double test_vec_vec_splatid(void) {
+  // CHECK-BE: [[T1:%.+]] = fpext float %{{.+}} to double
+  // CHECK-BE-NEXT: [[T2:%.+]] = insertelement <2 x double> undef, double [[T1:%.+]], i32 0
+  // CHECK-BE-NEXT: [[T3:%.+]] = shufflevector <2 x double> [[T2:%.+]], <2 x double> undef, <2 x i32> zeroinitialize
+  // CHECK-BE-NEXT: ret <2 x double> [[T3:%.+]]
+  // CHECK: [[T1:%.+]] = fpext float %{{.+}} to double
+  // CHECK-NEXT: [[T2:%.+]] = insertelement <2 x double> undef, double [[T1:%.+]], i32 0
+  // CHECK-NEXT: [[T3:%.+]] = shufflevector <2 x double> [[T2:%.+]], <2 x double> undef, <2 x i32> zeroinitialize
+  // CHECK-NEXT: ret <2 x double> [[T3:%.+]]
+  return vec_splatid(1.0);
+}
+
+vector signed int test_vec_vec_splati_ins_si(void) {
+  // CHECK-BE: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 %{{.+}}
+  // CHECK-BE:  [[T1:%.+]] = add i32 2, %{{.+}}
+  // CHECK-BE: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 [[T1]]
+  // CHECK-BE: ret <4 x i32>
+  // CHECK:  [[T1:%.+]] = sub i32 1, %{{.+}}
+  // CHECK: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 [[T1]]
+  // CHECK:  [[T2:%.+]] = sub i32 3, %{{.+}}
+  // CHECK: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 [[T2]]
+  // CHECK: ret <4 x i32>
+  return vec_splati_ins(vsia, 0, -17);
+}
+
+vector unsigned int test_vec_vec_splati_ins_ui(void) {
+  // CHECK-BE: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 %{{.+}}
+  // CHECK-BE:  [[T1:%.+]] = add i32 2, %{{.+}}
+  // CHECK-BE: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 [[T1]]
+  // CHECK-BE: ret <4 x i32>
+  // CHECK:  [[T1:%.+]] = sub i32 1, %{{.+}}
+  // CHECK: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 [[T1]]
+  // CHECK:  [[T2:%.+]] = sub i32 3, %{{.+}}
+  // CHECK: insertelement <4 x i32> %{{.+}}, i32 %{{.+}}, i32 [[T2]]
+  // CHECK: ret <4 x i32>
+  return vec_splati_ins(vuia, 1, 16U);
+}
+
+vector float test_vec_vec_splati_ins_f(void) {
+  // CHECK-BE: insertelement <4 x float> %{{.+}}, float %{{.+}}, i32 %{{.+}}
+  // CHECK-BE:  [[T1:%.+]] = add i32 2, %{{.+}}
+  // CHECK-BE: insertelement <4 x float> %{{.+}}, float %{{.+}}, i32 [[T1]]
+  // CHECK-BE: ret <4 x float>
+  // CHECK:  [[T1:%.+]] = sub i32 1, %{{.+}}
+  // CHECK: insertelement <4 x float> %{{.+}}, float %{{.+}}, i32 [[T1]]
+  // CHECK:  [[T2:%.+]] = sub i32 3, %{{.+}}
+  // CHECK: insertelement <4 x float> %{{.+}}, float %{{.+}}, i32 [[T2]]
+  // CHECK: ret <4 x float>
+  return vec_splati_ins(vfa, 0, 1.0f);
+}
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -17094,6 +17094,58 @@
vector unsigned long long __c) {
   return __builtin_vsx_xxblendvd(__a, __b, __c);
 }
+
+/* vec_splati */
+
+#define vec_splati(__a)  

[PATCH] D83121: [AMDGPU] Change Clang AMDGCN atomic inc/dec builtins to take unsigned values

2020-07-07 Thread Saiyedul Islam via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0882c9d4fc49: [AMDGPU] Change Clang AMDGCN atomic inc/dec 
builtins to take unsigned values (authored by saiislam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83121

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/Sema/builtin-amdgcn-atomic-inc-dec-failure.cpp
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl

Index: clang/test/SemaOpenCL/builtins-amdgcn-error.cl
===
--- clang/test/SemaOpenCL/builtins-amdgcn-error.cl
+++ clang/test/SemaOpenCL/builtins-amdgcn-error.cl
@@ -146,7 +146,7 @@
 }
 
 void test_atomic_inc32() {
-  int val = 17;
+  uint val = 17;
   val = __builtin_amdgcn_atomic_inc32(&val, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_inc32(&val, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_inc32(4);// expected-error {{too few arguments to function call, expected 4}}
@@ -155,10 +155,12 @@
   val = __builtin_amdgcn_atomic_inc32(&val, val, __ATOMIC_ACQUIRE, 5);   // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
   const char ptr[] = "workgroup";
   val = __builtin_amdgcn_atomic_inc32(&val, val, __ATOMIC_ACQUIRE, ptr); // expected-error {{expression is not a string literal}}
+  int signedVal = 15;
+  signedVal = __builtin_amdgcn_atomic_inc32(&signedVal, signedVal, __ATOMIC_ACQUIRE, ""); // expected-warning {{passing '__private int *' to parameter of type 'volatile __private unsigned int *' converts between pointers to integer types with different sign}}
 }
 
 void test_atomic_inc64() {
-  __INT64_TYPE__ val = 17;
+  __UINT64_TYPE__ val = 17;
   val = __builtin_amdgcn_atomic_inc64(&val, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_inc64(&val, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_inc64(4);// expected-error {{too few arguments to function call, expected 4}}
@@ -167,10 +169,12 @@
   val = __builtin_amdgcn_atomic_inc64(&val, val, __ATOMIC_ACQUIRE, 5);   // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
   const char ptr[] = "workgroup";
   val = __builtin_amdgcn_atomic_inc64(&val, val, __ATOMIC_ACQUIRE, ptr); // expected-error {{expression is not a string literal}}
+  __INT64_TYPE__ signedVal = 15;
+  signedVal = __builtin_amdgcn_atomic_inc64(&signedVal, signedVal, __ATOMIC_ACQUIRE, ""); // expected-warning {{passing '__private long *' to parameter of type 'volatile __private unsigned long *' converts between pointers to integer types with different sign}}
 }
 
 void test_atomic_dec32() {
-  int val = 17;
+  uint val = 17;
   val = __builtin_amdgcn_atomic_dec32(&val, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_dec32(&val, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_dec32(4);// expected-error {{too few arguments to function call, expected 4}}
@@ -179,10 +183,12 @@
   val = __builtin_amdgcn_atomic_dec32(&val, val, __ATOMIC_ACQUIRE, 5);   // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
   const char ptr[] = "workgroup";
   val = __builtin_amdgcn_atomic_dec32(&val, val, __ATOMIC_ACQUIRE, ptr); // expected-error {{expression is not a string literal}}
+  int signedVal = 15;
+  signedVal = __builtin_amdgcn_atomic_dec32(&signedVal, signedVal, __ATOMIC_ACQUIRE, ""); // expected-warning {{passing '__private int *' to parameter of type 'volatile __private unsigned int *' converts between pointers to integer types with different sign}}
 }
 
 void test_atomic_dec64() {
-  __INT64_TYPE__ val = 17;
+  __UINT64_TYPE__ val = 17;
   val = __builtin_amdgcn_atomic_dec64(&val, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_dec64(&val, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
   val = __builtin_amdgcn_atomic_dec64(4);

[PATCH] D83111: [X86-64] Support Intel AMX Intrinsic

2020-07-07 Thread Xiang Zhang via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG939d8309dbd4: [X86-64] Support Intel AMX Intrinsic (authored 
by xiangzhangllvm).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D83111?vs=275537&id=275644#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83111

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/BuiltinsX86_64.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/amxintrin.h
  clang/lib/Headers/cpuid.h
  clang/lib/Headers/immintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/AMX/amx.c
  clang/test/CodeGen/AMX/amx_errors.c
  clang/test/CodeGen/AMX/amx_inline_asm.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_amx_target_features.c
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrAMX.td
  llvm/test/CodeGen/X86/AMX/amx-bf16-intrinsics.ll
  llvm/test/CodeGen/X86/AMX/amx-int8-intrinsics.ll
  llvm/test/CodeGen/X86/AMX/amx-tile-intrinsics.ll

Index: llvm/test/CodeGen/X86/AMX/amx-tile-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/AMX/amx-tile-intrinsics.ll
@@ -0,0 +1,36 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+amx-tile -verify-machineinstrs | FileCheck %s
+
+define void @test_amx(i8* %pointer, i8* %base, i64 %stride) {
+; CHECK-LABEL: test_amx:
+; CHECK:   # %bb.0:
+  call void @llvm.x86.ldtilecfg(i8* %pointer)
+; CHECK-NEXT:ldtilecfg (%rdi)
+
+  call void @llvm.x86.sttilecfg(i8* %pointer)
+; CHECK-NEXT:sttilecfg (%rdi)
+
+  call void @llvm.x86.tilerelease()
+; CHECK-NEXT:tilerelease
+
+  call void @llvm.x86.tilezero(i8 3)
+; CHECK-NEXT:tilezero %tmm3
+
+  call void @llvm.x86.tileloadd64(i8 3, i8* %base, i64 %stride)
+; CHECK-NEXT:tileloadd (%rsi,%rdx), %tmm3
+
+  call void @llvm.x86.tileloaddt164(i8 3, i8* %base, i64 %stride)
+; CHECK-NEXT:tileloaddt1 (%rsi,%rdx), %tmm3
+
+  call void @llvm.x86.tilestored64(i8 3, i8* %base, i64 %stride)
+; CHECK-NEXT:tilestored %tmm3, (%rsi,%rdx)
+  ret void
+}
+
+declare void @llvm.x86.tileloadd64(i8 %tile, i8* %base, i64 %stride)
+declare void @llvm.x86.tileloaddt164(i8 %tile, i8* %base, i64 %stride)
+declare void @llvm.x86.tilestored64(i8 %tile, i8* %base, i64 %stride)
+declare void @llvm.x86.ldtilecfg(i8* %pointer)
+declare void @llvm.x86.sttilecfg(i8* %pointer)
+declare void @llvm.x86.tilerelease()
+declare void @llvm.x86.tilezero(i8 %tile)
Index: llvm/test/CodeGen/X86/AMX/amx-int8-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/AMX/amx-int8-intrinsics.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+amx-int8 -verify-machineinstrs | FileCheck %s
+
+define void @test_amx() {
+; CHECK-LABEL: test_amx:
+; CHECK:   # %bb.0:
+  call void @llvm.x86.tdpbssd(i8 3, i8 4, i8 7)
+; CHECK-NEXT:tdpbssd %tmm7, %tmm4, %tmm3
+
+  call void @llvm.x86.tdpbsud(i8 3, i8 4, i8 7)
+; CHECK-NEXT:tdpbsud %tmm7, %tmm4, %tmm3
+
+  call void @llvm.x86.tdpbusd(i8 3, i8 0, i8 7)
+; CHECK-NEXT:tdpbusd %tmm7, %tmm0, %tmm3
+
+  call void @llvm.x86.tdpbuud(i8 3, i8 4, i8 1)
+; CHECK-NEXT:tdpbuud %tmm1, %tmm4, %tmm3
+  ret void
+}
+
+declare void @llvm.x86.tdpbssd(i8 %tile0, i8 %tile1, i8 %tile2)
+declare void @llvm.x86.tdpbsud(i8 %tile0, i8 %tile1, i8 %tile2)
+declare void @llvm.x86.tdpbusd(i8 %tile0, i8 %tile1, i8 %tile2)
+declare void @llvm.x86.tdpbuud(i8 %tile0, i8 %tile1, i8 %tile2)
Index: llvm/test/CodeGen/X86/AMX/amx-bf16-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/AMX/amx-bf16-intrinsics.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+amx-tile -mattr=+amx-bf16 -verify-machineinstrs | FileCheck %s
+
+define void @test_amx() {
+; CHECK-LABEL: test_amx:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tdpbf16ps %tmm7, %tmm4, %tmm3
+; CHECK-NEXT:retq
+  call void @llvm.x86.tdpbf16ps(i8 3, i8 4, i8 7)
+  ret void
+}
+
+declare void @llvm.x86.tdpbf16ps(i8 %tile0, i8 %tile1, i8 %tile2)
Index: llvm/lib/Target/X86/X86InstrAMX.td
=

[PATCH] D82436: [clangd] Implement textDocument/foldingRange

2020-07-07 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 275929.
kbobyrev marked 7 inline comments as done.
kbobyrev added a comment.

Hide FoldingRanges feature behind the flag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -296,6 +296,14 @@
 Hidden,
 };
 
+opt FoldingRanges{
+"folding-rangees",
+cat(Features),
+desc("Enable preview of FoldingRanges feature"),
+init(false),
+Hidden,
+};
+
 opt WorkerThreadsCount{
 "j",
 cat(Misc),
@@ -659,6 +667,7 @@
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;
   Opts.PreserveRecoveryASTType = RecoveryASTType;
+  Opts.FoldingRanges = FoldingRanges;
 
   clangd::CodeCompleteOptions CCOpts;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
Index: clang-tools-extra/clangd/SemanticSelection.h
===
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -25,6 +25,9 @@
 /// If pos is not in any interesting range, return [Pos, Pos).
 llvm::Expected getSemanticRanges(ParsedAST &AST, Position Pos);
 
+/// Retrieves folding ranges in the "main file" section of given AST.
+llvm::Expected> getFoldingRanges(ParsedAST &AST);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===
--- clang-tools-extra/clangd/SemanticSelection.cpp
+++ clang-tools-extra/clangd/SemanticSelection.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 #include "SemanticSelection.h"
+#include "FindSymbols.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Selection.h"
@@ -18,6 +19,7 @@
 namespace clang {
 namespace clangd {
 namespace {
+
 // Adds Range \p R to the Result if it is distinct from the last added Range.
 // Assumes that only consecutive ranges can coincide.
 void addIfDistinct(const Range &R, std::vector &Result) {
@@ -25,6 +27,20 @@
 Result.push_back(R);
   }
 }
+
+// Recursively collects FoldingRange from a symbol and its children.
+void collectFoldingRanges(DocumentSymbol Symbol,
+  std::vector &Result) {
+  FoldingRange Range;
+  Range.startLine = Symbol.range.start.line;
+  Range.startCharacter = Symbol.range.start.character;
+  Range.endLine = Symbol.range.end.line;
+  Range.endCharacter = Symbol.range.end.character;
+  Result.push_back(Range);
+  for (const auto &Child : Symbol.children)
+collectFoldingRanges(Child, Result);
+}
+
 } // namespace
 
 llvm::Expected getSemanticRanges(ParsedAST &AST, Position Pos) {
@@ -81,5 +97,23 @@
   return std::move(Head);
 }
 
+// FIXME(kirillbobyrev): Collect comments, PP conditional regions, includes and
+// other code regions (e.g. public/private/protected sections of classes,
+// control flow statement bodies).
+// Related issue:
+// https://github.com/clangd/clangd/issues/310
+llvm::Expected> getFoldingRanges(ParsedAST &AST) {
+  // FIXME(kirillbobyrev): getDocumentSymbols() is conveniently available but
+  // limited (e.g. doesn't yield blocks inside functions). Replace this with a
+  // more general RecursiveASTVisitor implementation instead.
+  auto DocumentSymbols = getDocumentSymbols(AST);
+  if (!DocumentSymbols)
+return DocumentSymbols.takeError();
+  std::vector Result;
+  for (const auto &Symbol : *DocumentSymbols)
+collectFoldingRanges(Symbol, Result);
+  return Result;
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -1510,6 +1510,23 @@
 };
 llvm::json::Value toJSON(const DocumentLink &DocumentLink);
 
+// FIXME(kirillbobyrev): Add FoldingRangeClientCapabilities so we can support
+// per-line-folding editors.
+struct FoldingRangeParams {
+  TextDocumentIdentifier textDocument;
+};
+bool fromJSON(const llvm::json::Value &, FoldingRangeParams &);
+
+/// Stores information about a region of code that can be folded.
+struct FoldingRange {
+  unsigned startLine;
+  llvm::Optional startCharacter;
+  unsigned endLine;
+  llvm::Optional endCharacter;
+  llvm

[PATCH] D83099: [clangd] Store index in '.cache/clangd/index' instead of '.clangd/index'

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

looks good from my side.




Comment at: .gitignore:58
+.clangd/
+.cache
 # static analyzer regression testing project files

I'm afraid that many projects have to update their `.gitignore`, but this is a 
tradeoff...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83099



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275930.
eduucaldas added a comment.

`->*` and `,` are binary operators.
Unit tests covering most of the operator kinds


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2189,20 +2189,29 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+class osstream {};
 struct X {
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend osstream operator<<(osstream&, const X&);
 };
-void test(X x, X y) {
+void test(X x, X y, osstream out) {
   x = y;
   x + y;
   x < y;
+  out << x;
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
+| |-class
+| |-osstream
+| |-{
+| |-}
+| `-;
+|-SimpleDeclaration
 | |-struct
 | |-X
 | |-{
@@ -2262,6 +2271,27 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-osstream
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-osstream
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2279,6 +2309,11 @@
   |   | |-X
   |   | `-SimpleDeclarator
   |   |   `-y
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-osstream
+  |   | `-SimpleDeclarator
+  |   |   `-out
   |   `-)
   `-CompoundStatement
 |-{
@@ -2319,6 +2354,242 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-out
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedRareBinaryOperators) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator,(X&);
+};
+void test(X x, X y) {
+  x, y;
+  // TODO: Test for `->*`. That introduced a crash
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-y
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-Id

[PATCH] D82629: [libclang] Fix crash when visiting a captured VLA.

2020-07-07 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

In D82629#2134521 , @jkorous wrote:

> @ckandeler do you have commit access or do you want me to land the patch?


I do not, so it'd be great if you could do it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82629



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


[PATCH] D82728: [clang] Add -Wsuggest-override

2020-07-07 Thread Logan Smith via Phabricator via cfe-commits
logan-5 added a comment.

Glad this is generating some discussion. For my $0.02, I would also (obviously) 
love to be able to enable this warning on all the codebases I work on, and this 
patch was born out of a discussion on the C++ Slack with another user who had 
found this warning very useful in GCC and was wondering why Clang didn't have 
it yet.

In D82728#2134072 , @dblaikie wrote:

> The issue is that such a warning then needs to be off by default, because we 
> can't assume the user's intent. And Clang's historically been fairly averse 
> to off-by-default warnings due to low user-penetration (not zero, like I 
> said, I imagine LLVM itself would use such a warning, were it implemented) & 
> so concerns about the cost/benefit tradeoff of the added complexity (source 
> code and runtime) of the feature.


I agree `-Wsuggest-override` should be off by default, yet I suspect its 
user-penetration will be much higher than other off-by-default warnings, due to 
numerous instances of people on the Internet asking for 
 this feature 
, as well as the precedent for it 
set by GCC. Moreover, since this implementation of this warning lies along the 
exact same code paths as the already existing 
`-Winconsistent-missing-override`, the added complexity from this patch is 
absolutely minimal.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:3075
+  : diag::
+warn_inconsistent_function_marked_not_override_overriding);
+else

Quuxplusone wrote:
> These linebreaks are super unfortunate. Could they be improved by doing it 
> like this?
> ```
> auto EmitDiag = [this, MD](unsigned DiagDtor, unsigned DiagFn) {
>   unsigned DiagID = isa(MD) ? DiagDtor : DiagFn;
>   Diag(MD->getLocation(), DiagID) << MD->getDeclName();
>   const CXXMethodDecl *OMD = *MD->begin_overridden_methods();
>   Diag(OMD->getLocation(), diag::note_overridden_virtual_function);
> };
> if (Inconsistent)
>   
> EmitDiag(diag::warn_inconsistent_destructor_marked_not_override_overriding,
>
> diag::warn_inconsistent_function_marked_not_override_overriding);
> else
>   EmitDiag(diag::warn_suggest_destructor_marked_not_override_overriding
>diag::warn_suggest_function_marked_not_override_overriding);
> ```
Agreed. Good idea on the fix--needed one more line break (the first one still 
hit column 81), but it looks much better now.



Comment at: clang/test/SemaCXX/warn-suggest-destructor-override:6
+  ~A() {}
+  void virtual run() {}
+};

Quuxplusone wrote:
> Surely this doesn't compile?!
Because of `void virtual`? It does, surprisingly, as it does in the test for 
warn-inconsistent-missing-destructor-override, where I pilfered this from.

Nevertheless, changed to `virtual void` for sanity's sake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82728



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


[PATCH] D79773: [clang-format] Improve clang-formats handling of concepts

2020-07-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

https://reviews.llvm.org/D79773#2131680 has something to do with your 
.clang-format file, the base LLVM style seems fine.

  template 
  concept bool EqualityComparable = requires(T a, T b) {
  { a == b } -> bool;
  };

vs

  template 
  concept bool EqualityComparable = requires(T a, T b)
  {
  {
  a == b
  } -> bool;
  };

From what I can tell its because of the "BreakBeforeBraces: Allman or GNU" 
styles.


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

https://reviews.llvm.org/D79773



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


[PATCH] D82728: [clang] Add -Wsuggest-override

2020-07-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D82728#2135142 , @logan-5 wrote:

> Glad this is generating some discussion. For my $0.02, I would also 
> (obviously) love to be able to enable this warning on all the codebases I 
> work on, and this patch was born out of a discussion on the C++ Slack with 
> another user who had found this warning very useful in GCC and was wondering 
> why Clang didn't have it yet.
>
> In D82728#2134072 , @dblaikie wrote:
>
> > The issue is that such a warning then needs to be off by default, because 
> > we can't assume the user's intent. And Clang's historically been fairly 
> > averse to off-by-default warnings due to low user-penetration (not zero, 
> > like I said, I imagine LLVM itself would use such a warning, were it 
> > implemented) & so concerns about the cost/benefit tradeoff of the added 
> > complexity (source code and runtime) of the feature.
>
>
> I agree `-Wsuggest-override` should be off by default, yet I suspect its 
> user-penetration will be much higher than other off-by-default warnings, due 
> to numerous instances of people on the Internet asking for 
>  this feature 
> , as well as the precedent for 
> it set by GCC.


Ah, I hadn't checked/wasn't mentioned whether GCC has this warning. If GCC 
already has it, there's usually an easy enough argument to be made for GCC 
compatibility being worthwhile that overcomes most of the objections unless the 
GCC warning is particularly problematic in some way that I doubt this is.

Is the implementation you're proposing fairly consistent with GCC's? Run it 
over any big codebases to check it warns in the same places GCC does?

> Moreover, since this implementation of this warning lies along the exact same 
> code paths as the already existing `-Winconsistent-missing-override`, the 
> added complexity from this patch is absolutely minimal.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82728



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


[PATCH] D79842: [clang][Driver] Correct tool search path priority

2020-07-07 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

I saw similar behaviour on Mac OSX and fixed that in the reland. 
(https://reviews.llvm.org/rGd6efc9811646edbfe13f06c2676fb469f1c155b1)

Are you still seeing a failure with that applied?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79842



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


[PATCH] D82740: [libclang]: check validity before visiting Stmt node

2020-07-07 Thread Milian Wolff via Phabricator via cfe-commits
milianw abandoned this revision.
milianw added a comment.

great, thanks for the help - please land the other change then


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82740



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


[PATCH] D69318: [analyzer] Add SufficientSizeArrayIndexingChecker

2020-07-07 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 275938.
gamesh411 added a comment.

fix detection logic
fix license header
add missing warning to test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69318

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp
  clang/test/Analysis/sufficient-size-array-indexing-32bit.c
  clang/test/Analysis/sufficient-size-array-indexing-64bit.c

Index: clang/test/Analysis/sufficient-size-array-indexing-64bit.c
===
--- /dev/null
+++ clang/test/Analysis/sufficient-size-array-indexing-64bit.c
@@ -0,0 +1,127 @@
+// RUN: %clang_analyze_cc1 -triple x86_64 -analyzer-checker=core,alpha.core.SufficientSizeArrayIndexing %s -verify
+
+#include "Inputs/system-header-simulator.h"
+
+const unsigned long long one_byte_signed_max = (1ULL << 7) - 1;
+const unsigned long long two_byte_signed_max = (1ULL << 15) - 1;
+const unsigned long long four_byte_signed_max = (1ULL << 31) - 1;
+
+const unsigned long long one_byte_unsigned_max = (1ULL << 8) - 1;
+const unsigned long long two_byte_unsigned_max = (1ULL << 16) - 1;
+const unsigned long long four_byte_unsigned_max = (1ULL << 32) - 1;
+
+char smaller_than_1byte_signed_range[one_byte_signed_max];
+char exactly_1byte_signed_range[one_byte_signed_max + 1];
+char greater_than_1byte_signed_range[one_byte_signed_max + 2];
+
+char smaller_than_2byte_signed_range[two_byte_signed_max];
+char exactly_2byte_signed_range[two_byte_signed_max + 1];
+char greater_than_2byte_signed_range[two_byte_signed_max + 2];
+
+char smaller_than_4byte_signed_range[four_byte_signed_max];
+char exactly_4byte_signed_range[four_byte_signed_max + 1];
+char greater_than_4byte_signed_range[four_byte_signed_max + 2];
+
+char smaller_than_1byte_unsigned_range[one_byte_unsigned_max];
+char exactly_1byte_unsigned_range[one_byte_unsigned_max + 1];
+char greater_than_1byte_unsigned_range[one_byte_unsigned_max + 2];
+
+char smaller_than_2byte_unsigned_range[two_byte_unsigned_max];
+char exactly_2byte_unsigned_range[two_byte_unsigned_max + 1];
+char greater_than_2byte_unsigned_range[two_byte_unsigned_max + 2];
+
+char smaller_than_4byte_unsigned_range[four_byte_unsigned_max];
+char exactly_4byte_unsigned_range[four_byte_unsigned_max + 1];
+char greater_than_4byte_unsigned_range[four_byte_unsigned_max + 2];
+
+const char one_byte_signed_index = 1;  // sizeof(char) == 1
+const short two_byte_signed_index = 1; // sizeof(short) == 2
+const int four_byte_signed_index = 1;  // sizeof(int) == 4
+
+const unsigned char one_byte_unsigned_index = 1;
+const unsigned short two_byte_unsigned_index = 1;
+const unsigned int four_byte_unsigned_index = 1;
+
+void ignore_literal_indexing() {
+  char a = exactly_4byte_unsigned_range[32]; // nowarning
+}
+
+void ignore_literal_indexing_with_parens() {
+  char a = exactly_4byte_unsigned_range[(32)]; // nowarning
+}
+
+void range_check_one_byte_index() {
+  char r;
+  char *pr = &r;
+  *pr = smaller_than_1byte_signed_range[one_byte_signed_index]; // nowarning
+  *pr = exactly_1byte_signed_range[one_byte_signed_index];  // nowarning
+  *pr = greater_than_1byte_signed_range[one_byte_signed_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+  *pr = smaller_than_1byte_unsigned_range[one_byte_unsigned_index]; // nowarning
+  *pr = exactly_1byte_unsigned_range[one_byte_unsigned_index];  // nowarning
+  *pr = greater_than_1byte_unsigned_range[one_byte_unsigned_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+}
+
+void range_check_two_byte_index() {
+  char r;
+  char *pr = &r;
+  *pr = smaller_than_2byte_signed_range[two_byte_signed_index]; // nowarning
+  *pr = exactly_2byte_signed_range[two_byte_signed_index];  // nowarning
+  *pr = greater_than_2byte_signed_range[two_byte_signed_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+  *pr = smaller_than_2byte_unsigned_range[two_byte_unsigned_index]; // nowarning
+  *pr = exactly_2byte_unsigned_range[two_byte_unsigned_index];  // nowarning
+  *pr = greater_than_2byte_unsigned_range[two_byte_unsigned_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+}
+
+void range_

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275940.
eduucaldas marked 9 inline comments as done.
eduucaldas added a comment.

Answering comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2189,20 +2189,29 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+class osstream {};
 struct X {
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend osstream operator<<(osstream&, const X&);
 };
-void test(X x, X y) {
+void test(X x, X y, osstream out) {
   x = y;
   x + y;
   x < y;
+  out << x;
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
+| |-class
+| |-osstream
+| |-{
+| |-}
+| `-;
+|-SimpleDeclaration
 | |-struct
 | |-X
 | |-{
@@ -2262,6 +2271,27 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-osstream
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-osstream
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2279,6 +2309,11 @@
   |   | |-X
   |   | `-SimpleDeclarator
   |   |   `-y
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-osstream
+  |   | `-SimpleDeclarator
+  |   |   `-out
   |   `-)
   `-CompoundStatement
 |-{
@@ -2319,6 +2354,242 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-out
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedRareBinaryOperators) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator,(X&);
+};
+void test(X x, X y) {
+  x, y;
+  // TODO: Test for `->*`. That introduced a crash
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-y
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |

[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a comment.






Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:741
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
+if (S->getLocation().isInvalid())
+  return true;

gribozavr2 wrote:
> WDYT about overriding `TraverseCXXOperatorCallExpr`, so that we don't even 
> visit the synthetic argument of the postfix unary `++`? I would prefer to not 
> introduce blanket "if invalid then ignore" checks in the code.
>>! In D82954#2125300, @eduucaldas wrote:
> [[ https://godbolt.org/z/CWVEJ2 | Code that reproduces the crash ]]
> Notice that when using a postfix unary operator ++ one argument is introduced 
> to differ it from its prefix counterpart, but that argument is not used. This 
> phantom argument shows up in the ClangAST in the form of an `IntegerLiteral` 
> with `invalid sloc`. This invalid sloc in a valid AST node was causing the 
> SyntaxTree generation to crash.
> We can address this problems at two different levels:
> 1. At the `TraverseCXXOperatorCallExpr`, by overriding it and replacing the 
> children iteration to not iterate over this phantom argument.
> 2. At the `WalkUpFromIntegerLiteral`, by skipping the visitation of the 
> phantom node.
> We preferred the latter.
> 1. Cons: We would have to duplicate the implementation of RecursiveASTVisitor 
> in BuildTree, to handle this subtle change in traversal. That would add code 
> complexity.
> 2. Cons: We are handling a problem of `CXXOperatorCallExpr` in 
> `IntegerLiteral`. 
> 
> We chose the latter as, anyways, if an AST node has an invalid sloc, it was 
> either a problem with parsing or the node is supposed to be ignored

I've explained my reasoning in my first comment for this patch. But as it was a 
long time ago, I guess it got lost, even by me.
 
I'll sketch how the Traverse solution would look like, to be able to give more 
concrete arguments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2376
+| | |   `-x
+| | `-IdExpression
+| |   `-UnqualifiedId

gribozavr2 wrote:
> I'm not sure about this part where `++` is wrapped in IdExpression -- 
> shouldn't the syntax tree look identical to a builtin postfix `++` (see 
> another test in this file)?
This comes back to a discussion we had a month ago about operators ( `+`, `!`, 
etc)
**Question**: Should we represent operators (built-in or overloaded) in the 
syntax tree uniformly? If so in which way?
**Context**: The ClangAST stores built-in operators as mere tokens, whereas 
overloaded operators are represented as a `DeclRefExpr`. That makes a lot of 
sense for the ClangAST, as we might refer back to the declaration of the 
overloaded operator, but the declaration of built-in operator doesn't exist.
**Conclusion**: Have the same representation for both types of operators. I 
have implemented the "unboxed" representation of overloaded operators, i.e. 
just storing their token in the syntax tree. I have not committed that, but I 
can do it just after this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[PATCH] D83013: [LPM] Port CGProfilePass from NPM to LPM

2020-07-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

> I don't want to block this patch, but I do agree with Eric's point. We 
> *really* want to focus more on the switch then invest into more LPM infra. 
> Short term resolutions to unblock folks, with the best split possible, sure, 
> keeping in mind they'll need to be cleaned up.

Sounds good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83013



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


[PATCH] D83013: [LPM] Port CGProfilePass from NPM to LPM

2020-07-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83013



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


[PATCH] D69318: [analyzer] Add SufficientSizeArrayIndexingChecker

2020-07-07 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 8 inline comments as done.
gamesh411 added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:42
+BugType &
+SufficientSizeArrayIndexingChecker::GetBugTypeForType(const QualType T) const {
+  auto BT = BugTypeCache.find(T);

NoQ wrote:
> The whole point of bug types is to remain the same regardless of the specific 
> message. They're more like a category. Please use only one bug type for the 
> whole checker (unless you really find different categories of bugs).
I have removed the whole BugType factory think, that was really stupid in 
retrospect.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:103
+  const auto *SuperSubRegion = dyn_cast(SuperMemRegion);
+  // The checker has to access the extent of both the sub and the superregion.
+  if (!SuperSubRegion)

NoQ wrote:
> This deserves comments on what kinds of regions do you expect to see here. Do 
> i understand correctly that you expect `BaseMemRegion` to be an 
> `ElementRegion` and its superregion to be the whole array? 'Cause the former 
> is super unobvious and most likely //shouldn't// be that way.
I feel a bit more familiar now with the infrastructure now, and I used 
getDynamicElementCount as it now an available utility. Thanks for the comments, 
they were helpful for discovering how things work! :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69318



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


[PATCH] D69318: [analyzer] Add SufficientSizeArrayIndexingChecker

2020-07-07 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 4 inline comments as done.
gamesh411 added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:622
+
 } // end: "alpha.cplusplus"
 

NoQ wrote:
> What makes this checker C++-specific? All your tests are in plain C.
Very true, I have moved to `core.alpha`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69318



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


[PATCH] D83233: [clangd] Enable reading config from files by default.

2020-07-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:700
+ProviderStack.push_back(
+config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS));
+llvm::SmallString<256> UserConfig;

should we first update the background index storage location?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83233



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


[PATCH] D83233: [clangd] Enable reading config from files by default.

2020-07-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LG from my side


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83233



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


[clang] 9a1a7d8 - [SVE] Add more warnings checks to clang and LLVM SVE tests

2020-07-07 Thread David Sherwood via cfe-commits

Author: David Sherwood
Date: 2020-07-07T09:33:20+01:00
New Revision: 9a1a7d888b53ebe5a934a8193de37da86e276f1e

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

LOG: [SVE] Add more warnings checks to clang and LLVM SVE tests

There are now more SVE tests in LLVM and Clang that do not
emit warnings related to invalid use of EVT::getVectorNumElements()
and VectorType::getNumElements(). For these tests I have added
additional checks that there are no warnings in order to prevent
any future regressions.

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_index.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sb.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sh.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sw.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1ub.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1uh.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1uw.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sb.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sh.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sw.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1ub.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1uh.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1uw.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sb.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sh.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sw.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1ub.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1uh.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1uw.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_pnext.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ptrue.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rev.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_setffr.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn1.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn2.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_undef.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_unpkhi.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_unpklo.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp1.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp2.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_whilele.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_whilelt.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip1.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip2.c
llvm/test/CodeGen/AArch64/sve-callbyref-notailcall.ll
llvm/test/CodeGen/AArch64/sve-calling-convention-byref.ll
llvm/test/CodeGen/AArch64/sve-fcmp.ll
llvm/test/CodeGen/AArch64/sve-gather-scatter-dag-combine.ll
llvm/test/CodeGen/AArch64/sve-gep.ll
llvm/test/CodeGen/AArch64/sve-int-arith-imm.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-32bit-scaled-offsets.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-32bit-unscaled-offsets.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-64bit-scaled-offset.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-64bit-unscaled-offset.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-vector-base-imm-offset.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-vector-base-scalar-offset.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-32bit-scaled-offsets.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-32bit-unscaled-offsets.ll
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-64bit-scaled-offset.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-64bit-unscaled-offset.ll

llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-vector-base-imm-offset.ll

llvm/test/CodeGen/AArch64/sve

[PATCH] D82943: [SVE] Add more warnings checks to clang and LLVM SVE tests

2020-07-07 Thread David Sherwood via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a1a7d888b53: [SVE] Add more warnings checks to clang and 
LLVM SVE tests (authored by david-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82943

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_index.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1ub.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1uh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1uw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1ub.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1uh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1uw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1ub.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1uh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1uw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_pnext.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ptrue.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rev.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_setffr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_undef.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_unpkhi.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_unpklo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_whilele.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_whilelt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip2.c
  llvm/test/CodeGen/AArch64/sve-callbyref-notailcall.ll
  llvm/test/CodeGen/AArch64/sve-calling-convention-byref.ll
  llvm/test/CodeGen/AArch64/sve-fcmp.ll
  llvm/test/CodeGen/AArch64/sve-gather-scatter-dag-combine.ll
  llvm/test/CodeGen/AArch64/sve-gep.ll
  llvm/test/CodeGen/AArch64/sve-int-arith-imm.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-32bit-scaled-offsets.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-32bit-unscaled-offsets.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-64bit-scaled-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-64bit-unscaled-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-vector-base-imm-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-vector-base-scalar-offset.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-32bit-scaled-offsets.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-32bit-unscaled-offsets.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-64bit-scaled-offset.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-64bit-unscaled-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-vector-base-imm-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-vector-base-scalar-offset.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-imm.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1-addressing-mode-reg-imm.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1-addressing-mode-reg-reg.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1ro-addressing-mode-reg-reg.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-loads-ff.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-loads-nf.ll

Index: llvm/test/CodeG

[PATCH] D69318: [analyzer] Add SufficientSizeArrayIndexingChecker

2020-07-07 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

The checker has been updated, the comments and the logic polished. I would 
still take a stab at this being a ClangSa checker (as opposed to being a Tidy 
check). What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69318



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 275942.
eduucaldas added a comment.

Unifying user defined binary operator tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2189,20 +2189,32 @@
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
+class osstream {};
 struct X {
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend osstream operator<<(osstream&, const X&);
+  X operator,(X&);
+  // TODO: Test for `->*`. Fix crash before
 };
-void test(X x, X y) {
+void test(X x, X y, osstream out) {
   x = y;
   x + y;
   x < y;
+  out << x;
+  x, y;
 }
 )cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
+| |-class
+| |-osstream
+| |-{
+| |-}
+| `-;
+|-SimpleDeclaration
 | |-struct
 | |-X
 | |-{
@@ -2262,6 +2274,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-osstream
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-osstream
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2279,6 +2325,11 @@
   |   | |-X
   |   | `-SimpleDeclarator
   |   |   `-y
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-osstream
+  |   | `-SimpleDeclarator
+  |   |   `-out
   |   `-)
   `-CompoundStatement
 |-{
@@ -2319,6 +2370,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-out
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |

[PATCH] D83218: Hand Allocator and IdentifierTable into FormatTokenLexer.

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



Comment at: clang/lib/Format/FormatTokenLexer.h:121
   llvm::Regex MacroBlockEndRegex;
+  llvm::SpecificBumpPtrAllocator &Allocator;
 

this seems a little odd, like it fit better where it was, up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83218



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


[PATCH] D83013: [LPM] Port CGProfilePass from NPM to LPM

2020-07-07 Thread Nikita Popov via Phabricator via cfe-commits
nikic requested changes to this revision.
nikic added inline comments.
This revision now requires changes to proceed.



Comment at: llvm/test/Other/opt-O2-pipeline.ll:289
+; CHECK-NEXT: Branch Probability Analysis
+; CHECK-NEXT: Block Frequency Analysis
 ; CHECK-NEXT: FunctionPass Manager

Is it possible to switch this pass to use LazyBPI / LazyBFA, only fetched if 
PGO is actually in use?

PGO functionality that most people don't use adding expensive analysis passes 
like PDT should be avoided.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83013



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


[PATCH] D82938: [clangd] Implement path and URI translation for remote index

2020-07-07 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 275945.
kbobyrev added a comment.

Don't convert test paths to system native, UNIX native is good enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82938

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/index/remote/unimplemented/UnimplementedClient.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -7,16 +7,30 @@
 //===--===//
 
 #include "../TestTU.h"
+#include "TestFS.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
 namespace remote {
 namespace {
 
+const char *unittestURIToFilesystem(const char *UnittestURI,
+llvm::UniqueStringSaver &Strings) {
+  auto URI = URI::parse(UnittestURI);
+  EXPECT_TRUE(bool(URI));
+  const auto FileSystemURI =
+  URI::createFile(testPath(llvm::sys::path::relative_path(URI->body(;
+  return Strings.save(FileSystemURI.toString()).begin();
+}
+
 TEST(RemoteMarshallingTest, SymbolSerialization) {
   const auto *Header = R"(
   // This is a class.
@@ -39,9 +53,18 @@
   EXPECT_GE(Symbols.size(), 5UL);
   llvm::BumpPtrAllocator Arena;
   llvm::UniqueStringSaver Strings(Arena);
-  for (auto &Sym : Symbols) {
-const auto ProtobufMeessage = toProtobuf(Sym);
-const auto SymToProtobufAndBack = fromProtobuf(ProtobufMeessage, &Strings);
+  for (auto Sym : Symbols) {
+Sym.CanonicalDeclaration.FileURI =
+unittestURIToFilesystem(Sym.CanonicalDeclaration.FileURI, Strings);
+if (std::strlen(Sym.Definition.FileURI))
+  Sym.Definition.FileURI =
+  unittestURIToFilesystem(Sym.Definition.FileURI, Strings);
+for (auto &Header : Sym.IncludeHeaders)
+  Header.IncludeHeader =
+  unittestURIToFilesystem(Header.IncludeHeader.str().c_str(), Strings);
+auto ProtobufMessage = toProtobuf(Sym, "/");
+const auto SymToProtobufAndBack =
+fromProtobuf(ProtobufMessage, &Strings, "/");
 EXPECT_TRUE(SymToProtobufAndBack.hasValue());
 EXPECT_EQ(toYAML(Sym), toYAML(*SymToProtobufAndBack));
   }
@@ -79,13 +102,46 @@
   // Sanity check: there are more than 5 references available.
   EXPECT_GE(References.numRefs(), 5UL);
   for (const auto &SymbolWithRefs : References) {
-for (const auto &Ref : SymbolWithRefs.second) {
-  const auto RefToProtobufAndBack = fromProtobuf(toProtobuf(Ref), &Strings);
+for (auto Ref : SymbolWithRefs.second) {
+  Ref.Location.FileURI =
+  unittestURIToFilesystem(Ref.Location.FileURI, Strings);
+  const auto RefToProtobufAndBack =
+  fromProtobuf(toProtobuf(Ref, "/"), &Strings, "/");
   EXPECT_TRUE(RefToProtobufAndBack.hasValue());
   EXPECT_EQ(toYAML(Ref), toYAML(*RefToProtobufAndBack));
 }
   }
-} // namespace
+}
+
+TEST(RemoteMarshallingTest, URITranslation) {
+  llvm::BumpPtrAllocator Arena;
+  llvm::UniqueStringSaver Strings(Arena);
+  clangd::Ref Original;
+  const std::string RemoteIndexPrefix = testPath("remote/machine/project/");
+  std::string RelativePath = "llvm-project/clang-tools-extra/clangd/"
+ "unittests/remote/MarshallingTests.cpp";
+  const auto URI = URI::createFile(RemoteIndexPrefix + RelativePath);
+  Original.Location.FileURI = Strings.save(URI.toString()).begin();
+  Ref Serialized = toProtobuf(Original, RemoteIndexPrefix);
+  EXPECT_EQ(Serialized.location().file_path(), RelativePath);
+  const std::string LocalIndexPrefix = testPath("local/machine/project/");
+  auto Deserialized = fromProtobuf(Serialized, &Strings, LocalIndexPrefix);
+  EXPECT_TRUE(Deserialized);
+  EXPECT_EQ(Deserialized->Location.FileURI,
+URI::createFile(LocalIndexPrefix + RelativePath).toString());
+
+  clangd::Ref WithInvalidURI;
+  WithInvalidURI.Location.FileURI = "This is not a URI";
+  Serialized = toProtobuf(WithInvalidURI, RemoteIndexPrefix);
+  // Invalid URI results in empty path.
+  EXPECT_EQ(Serialized.location().file_path(), "");
+
+  Ref WithAbsolutePath;
+  *WithAbsolute

[PATCH] D82943: [SVE] Add more warnings checks to clang and LLVM SVE tests

2020-07-07 Thread David Sherwood via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a1a7d888b53: [SVE] Add more warnings checks to clang and 
LLVM SVE tests (authored by david-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82943

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_index.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1sw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1ub.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1uh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1uw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1sw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1ub.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1uh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldff1uw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1sw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1ub.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1uh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ldnf1uw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_pnext.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ptrue.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rev.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_setffr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_undef.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_unpkhi.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_unpklo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_whilele.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_whilelt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip2.c
  llvm/test/CodeGen/AArch64/sve-callbyref-notailcall.ll
  llvm/test/CodeGen/AArch64/sve-calling-convention-byref.ll
  llvm/test/CodeGen/AArch64/sve-fcmp.ll
  llvm/test/CodeGen/AArch64/sve-gather-scatter-dag-combine.ll
  llvm/test/CodeGen/AArch64/sve-gep.ll
  llvm/test/CodeGen/AArch64/sve-int-arith-imm.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-32bit-scaled-offsets.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-32bit-unscaled-offsets.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-64bit-scaled-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-64bit-unscaled-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-vector-base-imm-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-ff-gather-loads-vector-base-scalar-offset.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-32bit-scaled-offsets.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-32bit-unscaled-offsets.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-64bit-scaled-offset.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-64bit-unscaled-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-vector-base-imm-offset.ll
  
llvm/test/CodeGen/AArch64/sve-intrinsics-gather-loads-vector-base-scalar-offset.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-imm.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1-addressing-mode-reg-imm.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1-addressing-mode-reg-reg.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-ld1ro-addressing-mode-reg-reg.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-loads-f

[PATCH] D82436: [clangd] Implement textDocument/foldingRange

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



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:281
+  Range.startCharacter = Symbol.range.start.character;
+  Range.endLine = Symbol.range.end.line;
+  Range.endCharacter = Symbol.range.end.character;

sammccall wrote:
> kbobyrev wrote:
> > sammccall wrote:
> > > How useful are folding ranges when symbols start/end on the same line? Do 
> > > we really want to emit them?
> > I think they are useful from the LSP perspective, if characters didn't 
> > matter in the ranges they wouldn't be included in the protocol at all and 
> > there wouldn't be any way for clients to specify their preferences.
> > 
> > I don't think it's a common use case, but I do think it's a totally valid 
> > one. Maybe those should be the first candidates for excluding when there is 
> > a limit and maybe we could completely cut them for performance. But from 
> > the LSP perspective it seems logical to have those.
> > 
> > What do you think?
> Well, I don't think "the protocol allows regions within a line, therefore we 
> must emit them" is a great argument. You mention a valid use case, but you 
> haven't *described* any use cases - what specific C++ intra-line region is 
> the user likely to fold in a way that's useful?
> 
> I think that it's hard to point to concrete benefits, but the costs are clear 
> enough:
>  - responses will be (much) bigger, which we know some clients don't deal 
> well with
>  - clients are not likely to do any smart filtering, so I think this will 
> lead to performance/ux problems in practice (especially if most 
> implementations only support folding blocks etc)
>  - it makes decisions on what folding regions to emit harder, e.g. should we 
> fold function calls, not fold them, or fold them only if start/end are on 
> different lines?
>  - we need two different modes, to handle clients that support line-folds vs 
> clients that support char-folds. (If we only emit multi-line folds we could 
> also only emit the inner (or the outer) fold for a pair of lines, and the 
> result would be suitable for both types of editors)
> 
> > when there is a limit
> It's pretty important that this feature behaves consistently, for it to be 
> useful. If we're going to only-sometimes enable folding of certain 
> constructs, it better be for a reason that's pretty obvious to the user (I 
> believe single vs multiline qualifies, but "the document complexity exceeds 
> X" certainly doesn't.) For this reason I don't think we should implement that 
> capabilities feature (or should do it in some totally naive and unobtrusive 
> way, like truncation)
As discussed online, we should emit single-line ranges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82436



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


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 275949.
vsavchenko added a comment.

Fix comments and add a test for downcasts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c

Index: clang/test/Analysis/equality_tracking.c
===
--- /dev/null
+++ clang/test/Analysis/equality_tracking.c
@@ -0,0 +1,167 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false
+
+#define NULL (void *)0
+
+#define UCHAR_MAX (unsigned char)(~0U)
+#define CHAR_MAX (char)(UCHAR_MAX & (UCHAR_MAX >> 1))
+#define CHAR_MIN (char)(UCHAR_MAX & ~(UCHAR_MAX >> 1))
+
+void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
+
+int getInt();
+
+void zeroImpliesEquality(int a, int b) {
+  clang_analyzer_eval((a - b) == 0); // expected-warning{{UNKNOWN}}
+  if ((a - b) == 0) {
+clang_analyzer_eval(b != a);// expected-warning{{FALSE}}
+clang_analyzer_eval(b == a);// expected-warning{{TRUE}}
+clang_analyzer_eval(!(a != b)); // expected-warning{{TRUE}}
+clang_analyzer_eval(!(b == a)); // expected-warning{{FALSE}}
+return;
+  }
+  clang_analyzer_eval((a - b) == 0); // expected-warning{{FALSE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+}
+
+void zeroImpliesReversedEqual(int a, int b) {
+  clang_analyzer_eval((b - a) == 0); // expected-warning{{UNKNOWN}}
+  if ((b - a) == 0) {
+clang_analyzer_eval(b != a); // expected-warning{{FALSE}}
+clang_analyzer_eval(b == a); // expected-warning{{TRUE}}
+return;
+  }
+  clang_analyzer_eval((b - a) == 0); // expected-warning{{FALSE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+}
+
+void canonicalEqual(int a, int b) {
+  clang_analyzer_eval(a == b); // expected-warning{{UNKNOWN}}
+  if (a == b) {
+clang_analyzer_eval(b == a); // expected-warning{{TRUE}}
+return;
+  }
+  clang_analyzer_eval(a == b); // expected-warning{{FALSE}}
+  clang_analyzer_eval(b == a); // expected-warning{{FALSE}}
+}
+
+void test(int a, int b, int c, int d) {
+  if (a == b && c == d) {
+if (a == 0 && b == d) {
+  clang_analyzer_eval(c == 0); // expected-warning{{TRUE}}
+}
+c = 10;
+if (b == d) {
+  clang_analyzer_eval(c == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(d == 10); // expected-warning{{UNKNOWN}}
+// expected-warning@-1{{FALSE}}
+  clang_analyzer_eval(b == a);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a == d);  // expected-warning{{TRUE}}
+
+  b = getInt();
+  clang_analyzer_eval(a == d); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a == b); // expected-warning{{UNKNOWN}}
+}
+  }
+
+  if (a != b && b == c) {
+if (c == 42) {
+  clang_analyzer_eval(b == 42); // expected-warning{{TRUE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(a != 42); // expected-warning{{UNKNOWN}}
+}
+  }
+}
+
+void testIntersection(int a, int b, int c) {
+  if (a < 42 && b > 15 && c >= 25 && c <= 30) {
+if (a != b)
+  return;
+
+clang_analyzer_eval(a > 15);  // expected-warning{{TRUE}}
+clang_analyzer_eval(b < 42);  // expected-warning{{TRUE}}
+clang_analyzer_eval(a <= 30); // expected-warning{{UNKNOWN}}
+
+if (c == b) {
+  // For all equal symbols, we should track the minimal common range.
+  //
+  // Also, it should be noted that c is dead at this point, but the
+  // constraint initially associated with c is still around.
+  clang_analyzer_eval(a >= 25 && a <= 30); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 25 && b <= 30); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testPromotion(int a, char b) {
+  if (b > 10) {
+if (a == b) {
+  // FIXME: support transferring char ranges onto equal int symbols
+  //when char is promoted to int
+  clang_analyzer_eval(a > 10);// expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a <= CHAR_MAX); // expected-warning{{UNKNOWN}}
+}
+  }
+}
+
+void testPromotionOnlyTypes(int a, char b) {
+  if (a == b) {
+// FIXME: support transferring char ranges onto equal int symbols
+//when c

[PATCH] D83055: [clang][Driver] Fix tool path priority test failure

2020-07-07 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 275950.
DavidSpickett added a comment.

- Removed \ from regex, not needed for POSIX syntax.
- Reflowed text in commit description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055

Files:
  clang/test/Driver/program-path-priority.c

Index: clang/test/Driver/program-path-priority.c
===
--- clang/test/Driver/program-path-priority.c
+++ clang/test/Driver/program-path-priority.c
@@ -13,6 +13,11 @@
 /// so only name priority is accounted for, unless we fail to find
 /// anything at all in the prefix.
 
+/// Note: All matches are expected to be at the end of file paths.
+/// So we match " on the end to account for build systems that
+/// put the name of the compiler in the build path.
+/// E.g. /build/gcc_X.Y.Z/0/...
+
 /// Symlink clang to a new dir which will be its
 /// "program path" for these tests
 // RUN: rm -rf %t && mkdir -p %t
@@ -21,14 +26,18 @@
 /// No gccs at all, nothing is found
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO_NOTREAL_GCC %s
-// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
-// NO_NOTREAL_GCC-NOT: /gcc
+// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"
+/// Some systems will have "gcc-x.y.z" so for this first check
+/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either
+/// then there is no point continuing as this copy of clang is not
+/// isolated as we expected.
+// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}
 
 /// -gcc in program path is found
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
-// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
+// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc"
 
 /// -gcc on the PATH is found
 // RUN: mkdir -p %t/env
@@ -36,36 +45,36 @@
 // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
-// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
+// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"
 
 /// -gcc in program path is preferred to one on the PATH
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=BOTH_NOTREAL_GCC %s
-// BOTH_NOTREAL_GCC: notreal-none-elf-gcc
-// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc
+// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"
+// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"
 
 /// On program path, -gcc is preferred to plain gcc
 // RUN: touch %t/gcc && chmod +x %t/gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
-// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
-// NOTREAL_GCC_PREFERRED-NOT: /gcc
+// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc"
+// NOTREAL_GCC_PREFERRED-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc in program path
 // RUN: rm %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s
-// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc on the PATH
 // RUN: rm %t/gcc
 // RUN: touch %t/env/gcc && chmod +x %t/env/gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s
-// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc"
 
 /// -gcc has lowest priority so -gcc
 /// on PATH beats default triple in program path
@@ -75,22 +84,22 @@
 // RUN: touch %t/$DEFAULT_TRIPLE-gcc && chmod +x %t/$DEFAULT_TRIPLE-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=DEFAULT_TRIPLE_GCC %s
-// DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc
+// DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc"
 
 /// plain gcc on PATH beats default triple in program path
 // RUN: rm %t/env/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=DEFAULT_TRIPLE_NO_NOTREAL %s
-// DEFAULT_TRIPLE_NO_NOTREAL: env/gcc
-// DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc
+// DEFAULT_TRIPLE_NO_NOTREAL: env/gcc"
+// DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc"
 
 /// default triple only chosen when no oth

[PATCH] D83286: [analyzer][solver] Track symbol disequalities

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, dcoughlin, ASDenysPetrov, xazax.hun, Szelethus.
Herald added subscribers: cfe-commits, martong, Charusso, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a project: clang.

This commmit adds another relation that we can track separately from
range constraints.  Symbol disequality can help us understand that
two equivalence classes are not equal to each other.  We can generalize
this knowledge to classes because for every a,b,c, and d that
a == b, c == d, and b != c it is true that a != d.

As a result, we can reason about other equalities/disequalities of symbols
that we know nothing else about, i.e. no constraint ranges associated
with them.  However, we also benefit from the knowledge of disequal
symbols by following the rule:

  if a != b and b == C where C is a constant, a != C

This information can refine associated ranges for different classes
and reduce the number of false positives and paths to explore.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83286

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c
  clang/test/Analysis/mutually_exclusive_null_fp.cpp

Index: clang/test/Analysis/mutually_exclusive_null_fp.cpp
===
--- /dev/null
+++ clang/test/Analysis/mutually_exclusive_null_fp.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+
+// rdar://problem/56586853
+// expected-no-diagnostics
+
+struct Data {
+  int x;
+  Data *data;
+};
+
+int compare(Data &a, Data &b) {
+  Data *aData = a.data;
+  Data *bData = b.data;
+
+  // Covers the cases where both pointers are null as well as both pointing to the same buffer.
+  if (aData == bData)
+return 0;
+
+  if (aData && !bData)
+return 1;
+
+  if (!aData && bData)
+return -1;
+
+  return compare(*aData, *bData);
+}
Index: clang/test/Analysis/equality_tracking.c
===
--- clang/test/Analysis/equality_tracking.c
+++ clang/test/Analysis/equality_tracking.c
@@ -23,9 +23,8 @@
 return;
   }
   clang_analyzer_eval((a - b) == 0); // expected-warning{{FALSE}}
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b == a);   // expected-warning{{FALSE}}
+  clang_analyzer_eval(b != a);   // expected-warning{{TRUE}}
 }
 
 void zeroImpliesReversedEqual(int a, int b) {
@@ -36,9 +35,8 @@
 return;
   }
   clang_analyzer_eval((b - a) == 0); // expected-warning{{FALSE}}
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b == a);   // expected-warning{{FALSE}}
+  clang_analyzer_eval(b != a);   // expected-warning{{TRUE}}
 }
 
 void canonicalEqual(int a, int b) {
@@ -73,8 +71,7 @@
   if (a != b && b == c) {
 if (c == 42) {
   clang_analyzer_eval(b == 42); // expected-warning{{TRUE}}
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(a != 42); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a != 42); // expected-warning{{TRUE}}
 }
   }
 }
@@ -144,8 +141,31 @@
 
   if (a != b && b == c) {
 if (c == NULL) {
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(a != NULL); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a != NULL); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testDisequalitiesAfter(int a, int b, int c) {
+  if (a >= 10 && b <= 42) {
+if (a == b && c == 15 && c != a) {
+  clang_analyzer_eval(b != c);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a <= 42); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testDisequalitiesBefore(int a, int b, int c) {
+  if (a >= 10 && b <= 42 && c == 15) {
+if (a == b && c != a) {
+  clang_analyzer_eval(b != c);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a <= 42); // expected-warning{{TRUE}}
 }
   }
 }
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -401,6 +401,9 @@
 REGISTER_MAP_WITH_P

[PATCH] D83013: [LPM] Port CGProfilePass from NPM to LPM

2020-07-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp:170
 
 PassManagerBuilder::PassManagerBuilder() {
 OptLevel = 2;

Oh, just noticed: I think CallGraphProfile should be initialized along with the 
other flags here.



Comment at: llvm/test/Other/opt-O2-pipeline.ll:289
+; CHECK-NEXT: Branch Probability Analysis
+; CHECK-NEXT: Block Frequency Analysis
 ; CHECK-NEXT: FunctionPass Manager

nikic wrote:
> Is it possible to switch this pass to use LazyBPI / LazyBFA, only fetched if 
> PGO is actually in use?
> 
> PGO functionality that most people don't use adding expensive analysis passes 
> like PDT should be avoided.
I wonder if just switching to LazyBlockFrequencyInfo would help though. It 
looks to me like the CGProfile would request info about each function anyway.

I was surprised to see that Clang sets Opts.CallGraphProfile solely based on 
whether the integrated assembler is used. Maybe a better fix is to only set 
that to true when a profile is actually being used?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83013



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


[PATCH] D83190: [analyzer] Model iterator random incrementation symmetrically

2020-07-07 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 275954.
gamesh411 added a comment.

fix tidy diagnostic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83190

Files:
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/test/Analysis/iterator-modeling.cpp

Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -149,7 +149,7 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end(){{$
 }
 
-void plus(const std::vector &v) {
+void lhs_plus(const std::vector &v) {
   auto i1 = v.begin();
 
   clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
@@ -161,7 +161,19 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re{{$v.begin() + 2{{$
 }
 
-void plus_negative(const std::vector &v) {
+void rhs_plus(const std::vector &v) {
+  auto i1 = v.begin();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
+
+  auto i2 = 2 + i1;
+
+  clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re{{$v.begin(){{$
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re{{$v.begin() + 2{{$
+}
+
+void lhs_plus_negative(const std::vector &v) {
   auto i1 = v.end();
 
   clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
@@ -173,6 +185,18 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$
 }
 
+void rhs_plus_negative(const std::vector &v) {
+  auto i1 = v.end();
+
+  clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
+
+  auto i2 = (-2) + i1;
+
+  clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$
+}
+
 void minus(const std::vector &v) {
   auto i1 = v.end();
 
@@ -1948,7 +1972,7 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 2}}
 }
 
-void plus_ptr_iterator(const cont_with_ptr_iterator &c) {
+void lhs_plus_ptr_iterator(const cont_with_ptr_iterator &c) {
   auto i1 = c.begin();
 
   clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
@@ -1960,6 +1984,18 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.begin() + 2}}
 }
 
+void rhs_plus_ptr_iterator(const cont_with_ptr_iterator &c) {
+  auto i1 = c.begin();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
+
+  auto i2 = 2 + i1;
+
+  clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.begin()}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.begin() + 2}}
+}
+
 void minus_ptr_iterator(const cont_with_ptr_iterator &c) {
   auto i1 = c.end();
 
Index: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -109,7 +109,7 @@
bool Postfix) const;
   void handleRandomIncrOrDecr(CheckerContext &C, const Expr *CE,
   OverloadedOperatorKind Op, const SVal &RetVal,
-  const SVal &LHS, const SVal &RHS) const;
+  const SVal &Iterator, const SVal &Offset) const;
   void handlePtrIncrOrDecr(CheckerContext &C, const Expr *Iterator,
OverloadedOperatorKind OK, SVal Offset) const;
   void handleAdvance(CheckerContext &C, const Expr *CE, SVal RetVal, SVal Iter,
@@ -262,18 +262,25 @@
 
 void IteratorModeling::checkPostStmt(const BinaryOperator *BO,
  CheckerContext &C) const {
-  ProgramStateRef State = C.getState();
-  BinaryOperatorKind OK = BO->getOpcode();
-  SVal RVal = State->getSVal(BO->getRHS(), C.getLocationContext());
+  const ProgramStateRef State = C.getState();
+  const BinaryOperatorKind OK = BO->getOpcode();
+  const Expr *const LHS = BO->getLHS();
+  const Expr *const RHS = BO->getRHS();
+  const SVal LVal = State->getSVal(LHS, C.getLocationContext());
+  const SVal RVal = State->getSVal(RHS, C.getLocationContext());
 
   if (isSimpleComparisonOperator(BO->getOpcode())) {
-SVal LVal = State->getSVal(BO->getLHS(

[PATCH] D82381: [analyzer] Introduce small improvements to the solver infra

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 275955.
vsavchenko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82381

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -89,7 +89,7 @@
   }
 
   TriStateKind getCmpOpState(BinaryOperatorKind CurrentOP,
- BinaryOperatorKind QueriedOP) const {
+ BinaryOperatorKind QueriedOP) const {
 return CmpOpTable[getIndexFromOp(CurrentOP)][getIndexFromOp(QueriedOP)];
   }
 
@@ -364,6 +364,18 @@
   return newRanges;
 }
 
+RangeSet RangeSet::Delete(BasicValueFactory &BV, Factory &F,
+  const llvm::APSInt &Point) const {
+  llvm::APSInt Upper = Point;
+  llvm::APSInt Lower = Point;
+
+  ++Upper;
+  --Lower;
+
+  // Notice that the lower bound is greater than the upper bound.
+  return Intersect(BV, F, Upper, Lower);
+}
+
 void RangeSet::print(raw_ostream &os) const {
   bool isFirst = true;
   os << "{ ";
@@ -381,6 +393,107 @@
 
 namespace {
 
+//===--===//
+//Intersection functions
+//===--===//
+
+template 
+LLVM_NODISCARD inline RangeSet intersect(BasicValueFactory &BV,
+ RangeSet::Factory &F, RangeSet Head,
+ SecondTy Second, RestTy... Tail);
+
+template  struct IntersectionTraits;
+
+template  struct IntersectionTraits {
+  // Found RangeSet, no need to check any further
+  using Type = RangeSet;
+};
+
+template <> struct IntersectionTraits<> {
+  // We ran out of types, and we didn't find any RangeSet, so the result should
+  // be optional.
+  using Type = Optional;
+};
+
+template 
+struct IntersectionTraits {
+  // If current type is Optional or a raw pointer, we should keep looking.
+  using Type = typename IntersectionTraits::Type;
+};
+
+template 
+LLVM_NODISCARD inline EndTy intersect(BasicValueFactory &BV,
+  RangeSet::Factory &F, EndTy End) {
+  // If the list contains only RangeSet or Optional, simply return
+  // that range set.
+  return End;
+}
+
+LLVM_NODISCARD LLVM_ATTRIBUTE_UNUSED inline Optional
+intersect(BasicValueFactory &BV, RangeSet::Factory &F, const RangeSet *End) {
+  // This is an extraneous conversion from a raw pointer into Optional
+  if (End) {
+return *End;
+  }
+  return llvm::None;
+}
+
+template 
+LLVM_NODISCARD inline RangeSet intersect(BasicValueFactory &BV,
+ RangeSet::Factory &F, RangeSet Head,
+ RangeSet Second, RestTy... Tail) {
+  // Here we call either the  or  version
+  // of the function and can be sure that the result is RangeSet.
+  return intersect(BV, F, Head.Intersect(BV, F, Second), Tail...);
+}
+
+template 
+LLVM_NODISCARD inline RangeSet intersect(BasicValueFactory &BV,
+ RangeSet::Factory &F, RangeSet Head,
+ SecondTy Second, RestTy... Tail) {
+  if (Second) {
+// Here we call the  version of the function...
+return intersect(BV, F, Head, *Second, Tail...);
+  }
+  // ...and here it is either  or , which
+  // means that the result is definitely RangeSet.
+  return intersect(BV, F, Head, Tail...);
+}
+
+/// Main generic intersect function.
+/// It intersects all of the given range sets.  If some of the given arguments
+/// don't hold a range set (nullptr or llvm::None), the function will skip them.
+///
+/// Available representations for the arguments are:
+///   * RangeSet
+///   * Optional
+///   * RangeSet *
+/// Pointer to a RangeSet is automatically assumed to be nullable and will get
+/// checked as well as the optional version.  If this behaviour is undesired,
+/// please dereference the pointer in the call.
+///
+/// Return type depends on the arguments' types.  If we can be sure in compile
+/// time that there will be a range set as a result, the returning type is
+/// simply RangeSet, in other cases we have to back off to Optional.
+///
+/// Please, prefer optional range sets to raw pointers.  If the last argument is
+/// a raw pointer and all previous arguments are None, it will cost one
+/// additional check to convert RangeSet * into Optional.
+template 
+LLVM_NODISCARD inline
+typename IntersectionTraits::Type
+intersect(BasicValueFactory &BV, RangeSet::Factory &F, HeadTy Head,
+  SecondTy Second, RestTy...

[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 275956.
vsavchenko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c

Index: clang/test/Analysis/equality_tracking.c
===
--- /dev/null
+++ clang/test/Analysis/equality_tracking.c
@@ -0,0 +1,167 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false
+
+#define NULL (void *)0
+
+#define UCHAR_MAX (unsigned char)(~0U)
+#define CHAR_MAX (char)(UCHAR_MAX & (UCHAR_MAX >> 1))
+#define CHAR_MIN (char)(UCHAR_MAX & ~(UCHAR_MAX >> 1))
+
+void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
+
+int getInt();
+
+void zeroImpliesEquality(int a, int b) {
+  clang_analyzer_eval((a - b) == 0); // expected-warning{{UNKNOWN}}
+  if ((a - b) == 0) {
+clang_analyzer_eval(b != a);// expected-warning{{FALSE}}
+clang_analyzer_eval(b == a);// expected-warning{{TRUE}}
+clang_analyzer_eval(!(a != b)); // expected-warning{{TRUE}}
+clang_analyzer_eval(!(b == a)); // expected-warning{{FALSE}}
+return;
+  }
+  clang_analyzer_eval((a - b) == 0); // expected-warning{{FALSE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+}
+
+void zeroImpliesReversedEqual(int a, int b) {
+  clang_analyzer_eval((b - a) == 0); // expected-warning{{UNKNOWN}}
+  if ((b - a) == 0) {
+clang_analyzer_eval(b != a); // expected-warning{{FALSE}}
+clang_analyzer_eval(b == a); // expected-warning{{TRUE}}
+return;
+  }
+  clang_analyzer_eval((b - a) == 0); // expected-warning{{FALSE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+}
+
+void canonicalEqual(int a, int b) {
+  clang_analyzer_eval(a == b); // expected-warning{{UNKNOWN}}
+  if (a == b) {
+clang_analyzer_eval(b == a); // expected-warning{{TRUE}}
+return;
+  }
+  clang_analyzer_eval(a == b); // expected-warning{{FALSE}}
+  clang_analyzer_eval(b == a); // expected-warning{{FALSE}}
+}
+
+void test(int a, int b, int c, int d) {
+  if (a == b && c == d) {
+if (a == 0 && b == d) {
+  clang_analyzer_eval(c == 0); // expected-warning{{TRUE}}
+}
+c = 10;
+if (b == d) {
+  clang_analyzer_eval(c == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(d == 10); // expected-warning{{UNKNOWN}}
+// expected-warning@-1{{FALSE}}
+  clang_analyzer_eval(b == a);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a == d);  // expected-warning{{TRUE}}
+
+  b = getInt();
+  clang_analyzer_eval(a == d); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a == b); // expected-warning{{UNKNOWN}}
+}
+  }
+
+  if (a != b && b == c) {
+if (c == 42) {
+  clang_analyzer_eval(b == 42); // expected-warning{{TRUE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(a != 42); // expected-warning{{UNKNOWN}}
+}
+  }
+}
+
+void testIntersection(int a, int b, int c) {
+  if (a < 42 && b > 15 && c >= 25 && c <= 30) {
+if (a != b)
+  return;
+
+clang_analyzer_eval(a > 15);  // expected-warning{{TRUE}}
+clang_analyzer_eval(b < 42);  // expected-warning{{TRUE}}
+clang_analyzer_eval(a <= 30); // expected-warning{{UNKNOWN}}
+
+if (c == b) {
+  // For all equal symbols, we should track the minimal common range.
+  //
+  // Also, it should be noted that c is dead at this point, but the
+  // constraint initially associated with c is still around.
+  clang_analyzer_eval(a >= 25 && a <= 30); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 25 && b <= 30); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testPromotion(int a, char b) {
+  if (b > 10) {
+if (a == b) {
+  // FIXME: support transferring char ranges onto equal int symbols
+  //when char is promoted to int
+  clang_analyzer_eval(a > 10);// expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a <= CHAR_MAX); // expected-warning{{UNKNOWN}}
+}
+  }
+}
+
+void testPromotionOnlyTypes(int a, char b) {
+  if (a == b) {
+// FIXME: support transferring char ranges onto equal int symbols
+//when char is promoted to int
+clang_a

[PATCH] D83286: [analyzer][solver] Track symbol disequalities

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 275957.
vsavchenko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83286

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c
  clang/test/Analysis/mutually_exclusive_null_fp.cpp

Index: clang/test/Analysis/mutually_exclusive_null_fp.cpp
===
--- /dev/null
+++ clang/test/Analysis/mutually_exclusive_null_fp.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+
+// rdar://problem/56586853
+// expected-no-diagnostics
+
+struct Data {
+  int x;
+  Data *data;
+};
+
+int compare(Data &a, Data &b) {
+  Data *aData = a.data;
+  Data *bData = b.data;
+
+  // Covers the cases where both pointers are null as well as both pointing to the same buffer.
+  if (aData == bData)
+return 0;
+
+  if (aData && !bData)
+return 1;
+
+  if (!aData && bData)
+return -1;
+
+  return compare(*aData, *bData);
+}
Index: clang/test/Analysis/equality_tracking.c
===
--- clang/test/Analysis/equality_tracking.c
+++ clang/test/Analysis/equality_tracking.c
@@ -23,9 +23,8 @@
 return;
   }
   clang_analyzer_eval((a - b) == 0); // expected-warning{{FALSE}}
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b == a);   // expected-warning{{FALSE}}
+  clang_analyzer_eval(b != a);   // expected-warning{{TRUE}}
 }
 
 void zeroImpliesReversedEqual(int a, int b) {
@@ -36,9 +35,8 @@
 return;
   }
   clang_analyzer_eval((b - a) == 0); // expected-warning{{FALSE}}
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b == a);   // expected-warning{{FALSE}}
+  clang_analyzer_eval(b != a);   // expected-warning{{TRUE}}
 }
 
 void canonicalEqual(int a, int b) {
@@ -73,8 +71,7 @@
   if (a != b && b == c) {
 if (c == 42) {
   clang_analyzer_eval(b == 42); // expected-warning{{TRUE}}
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(a != 42); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a != 42); // expected-warning{{TRUE}}
 }
   }
 }
@@ -144,8 +141,31 @@
 
   if (a != b && b == c) {
 if (c == NULL) {
-  // FIXME: we should track disequality information as well
-  clang_analyzer_eval(a != NULL); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a != NULL); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testDisequalitiesAfter(int a, int b, int c) {
+  if (a >= 10 && b <= 42) {
+if (a == b && c == 15 && c != a) {
+  clang_analyzer_eval(b != c);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a <= 42); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testDisequalitiesBefore(int a, int b, int c) {
+  if (a >= 10 && b <= 42 && c == 15) {
+if (a == b && c != a) {
+  clang_analyzer_eval(b != c);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b != 15); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a <= 42); // expected-warning{{TRUE}}
 }
   }
 }
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -401,6 +401,9 @@
 REGISTER_MAP_WITH_PROGRAMSTATE(ClassMembers, EquivalenceClass, SymbolSet)
 REGISTER_MAP_WITH_PROGRAMSTATE(ConstraintRange, EquivalenceClass, RangeSet)
 
+REGISTER_SET_FACTORY_WITH_PROGRAMSTATE(ClassSet, EquivalenceClass)
+REGISTER_MAP_WITH_PROGRAMSTATE(DisequalityMap, EquivalenceClass, ClassSet)
+
 namespace {
 /// This class encapsulates a set of symbols equal to each other.
 ///
@@ -450,6 +453,24 @@
   LLVM_NODISCARD inline bool isTriviallyDead(ProgramStateRef State,
  SymbolReaper &Reaper);
 
+  LLVM_NODISCARD static inline ProgramStateRef
+  markDisequal(BasicValueFactory &BV, RangeSet::Factory &F,
+   ProgramStateRef State, SymbolRef First, SymbolRef Second);
+  LLVM_NODISCARD static inline ProgramStateRef
+  markDisequal(BasicValueFactory &BV, RangeSet::Factory &F,
+   ProgramStateRef State, EquivalenceClass First,
+  

[PATCH] D81676: [MSP430] Align the toolchain definition with the TI's msp430-gcc v9.2.0

2020-07-07 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko marked 3 inline comments as done.
atrosinenko added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:154
 
+  SmallString<128> MultilibInclude(GCCInstallation.getInstallPath());
+  llvm::sys::path::append(MultilibInclude, "include");

krisb wrote:
> I'd guard this by `if (GCCInstallation.isValid())` to avoid adding include 
> directories with relative paths if `GCCInstallation.getInstallPath()` is 
> empty.
Fixed.



Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:239
+  Arg *SspFlag = Args.getLastArg(
+  options::OPT_fno_stack_protector, options::OPT_fstack_protector,
+  options::OPT_fstack_protector_all, options::OPT_fstack_protector_strong);

krisb wrote:
> Is the check for `fno-stack-protector` necessary here? Looks as the checks 
> for 'positive' options should be enough to do the trick.
While the "negative" option is not mentioned at all by the specs:
```
$ msp430-elf-gcc -dumpspecs | grep stack-protector
%{fstack-protector|fstack-protector-all|fstack-protector-strong|fstack-protector-explicit:-lssp_nonshared
 -lssp}
```
it seems these options are already basically preprocessed by gcc driver:
```
$ msp430-elf-gcc -### empty.o 2>&1 | grep -Eo " -l[a-z_0-9]*" | tr "\n" " "
 -lgcc  -lmul_none  -lc  -lgcc  -lcrt  -lnosys  -lgcc  -lgcc
$ msp430-elf-gcc -### empty.o -fstack-protector 2>&1 | grep -Eo " -l[a-z_0-9]*" 
| tr "\n" " "
 -lssp_nonshared  -lssp  -lgcc  -lmul_none  -lc  -lgcc  -lcrt  -lnosys  -lgcc  
-lgcc
$ msp430-elf-gcc -### empty.o -fstack-protector -fno-stack-protector 2>&1 | 
grep -Eo " -l[a-z_0-9]*" | tr "\n" " "
 -lgcc  -lmul_none  -lc  -lgcc  -lcrt  -lnosys  -lgcc  -lgcc
```
and they seem to have the usual semantics of "the last one takes effect".



Comment at: clang/test/Driver/msp430-toolchain.c:5
+
+// Test for include paths (cannot use -###)
+

krisb wrote:
> This way looks okay to me, but I believe you should be able to check cc1 
> command (though -###) for `-internal-isystem`, right?
It works, thank you! Will wait for unit test results on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81676



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


[PATCH] D81676: [MSP430] Align the toolchain definition with the TI's msp430-gcc v9.2.0

2020-07-07 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 275959.
atrosinenko added a comment.

Address the review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81676

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend_no_eh.o
  clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin_no_eh.o
  clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/include-fixed/limits.h
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/include/stddef.h
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend_no_eh.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/include/stdio.h
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/crtn.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/exceptions/crt0.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/crt0.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/exceptions/crt0.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/crt0.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/exceptions/crt0.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/crt0.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/exceptions/crt0.o
  clang/test/Driver/msp430-toolchain.c

Index: clang/test/Driver/msp430-toolchain.c
===
--- clang/test/Driver/msp430-toolchain.c
+++ clang/test/Driver/msp430-toolchain.c
@@ -1,78 +1,249 @@
-// A basic clang -cc1 command-line, and simple environment check.
+// Tests for the 

[PATCH] D80202: [ASTMatchers] Performance optimization for memoization

2020-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:902
   // Maps (matcher, node) -> the match result for memoization.
-  typedef std::map MemoizationMap;
+  typedef std::map> MemoizationMap;
   MemoizationMap ResultCache;

klimek wrote:
> Ok, if this actually matters, we should also not use a std::map here, but a 
> llvm::DenseMap (or do we rely on iteration invalidation semantics here?).
Belated +1. 5% seems like this performance *does* matter, so DenseMap::find_as 
should be yet faster.
It looks like BoundNodesTreeBuilder would need a DenseMapInfo, but all the 
other members are hashable already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80202



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


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:506
+  APSIntType Type(Int);
+  return Int == Type.getZeroValue();
+}

Does the semantics if this differ from ` llvm::APInt::isNullValue`?



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1254
+//   sufficient.
+return S1->get() == S2->get() &&
+   S1->get() == S2->get();

Sorry, but I am a bit confused here.

Does `haveEqualConstraints` have anything to do with equivalence classes?

I.e., what if I have two symbols with the same constraints (but those two 
symbols were never compared).
```
void f(int a, int b) {
  int c = clamp(a, 5, 10);
  int d = clamp(b, 5, 10);
}
```

In the code above if analyzer understands clamp, the range for `c` and `d` will 
be the same. Even though we never really compared them.
I would expect `haveEqualConstraints` to return true, even if they do not 
belong to the same equivalence class.

Do I miss something?



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1380
 
+ConstraintMap ento::getConstraintMap(ProgramStateRef State) {
+  ConstraintMap::Factory &F = State->get_context();

So we basically do a conversion to Symbol -> Ranges from Class -> Ranges.
I wonder if it is possible to get rid of this conversion in the future to get 
some performance benefits.
We could either make all code work with both kind of range maps or have 
something like (Symbol + Class) -> Ranges to avoid conversion.
What do you think?

I am not opposed to this code at the moment, I just wonder if there is a 
relatively low hanging fruit for some performance gains in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445



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


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1254
+//   sufficient.
+return S1->get() == S2->get() &&
+   S1->get() == S2->get();

xazax.hun wrote:
> Sorry, but I am a bit confused here.
> 
> Does `haveEqualConstraints` have anything to do with equivalence classes?
> 
> I.e., what if I have two symbols with the same constraints (but those two 
> symbols were never compared).
> ```
> void f(int a, int b) {
>   int c = clamp(a, 5, 10);
>   int d = clamp(b, 5, 10);
> }
> ```
> 
> In the code above if analyzer understands clamp, the range for `c` and `d` 
> will be the same. Even though we never really compared them.
> I would expect `haveEqualConstraints` to return true, even if they do not 
> belong to the same equivalence class.
> 
> Do I miss something?
Never mind, I misunderstood this function. It operates on program states not on 
symbols.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445



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


[PATCH] D83212: [Fixed Point] Add fixed-point shift operations and consteval.

2020-07-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 275962.
ebevhan added a comment.

Fix test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83212

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Frontend/fixed_point_errors.c
  clang/test/Frontend/fixed_point_shift.c

Index: clang/test/Frontend/fixed_point_shift.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_shift.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+short _Accum sa_const1 = 1.0hk << 2;   // CHECK-DAG: @sa_const1 = {{.*}}global i16 512
+short _Accum sa_const2 = 0.5hk << 2;   // CHECK-DAG: @sa_const2 = {{.*}}global i16 256
+short _Accum sa_const3 = 10.0hk >> 3;  // CHECK-DAG: @sa_const3 = {{.*}}global i16 160
+short _Accum sa_const4 = 0.0546875hk << 8; // CHECK-DAG: @sa_const4 = {{.*}}global i16 1792
+short _Accum sa_const5 = -1.0hk << 2;  // CHECK-DAG: @sa_const5 = {{.*}}global i16 -512
+short _Accum sa_const6 = -255.0hk >> 8;// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128
+
+_Fract f_const1 = -1.0r >> 5;  // CHECK-DAG: @f_const1 = {{.*}}global i16 -1024
+_Fract f_const2 = 0.0052490234375r >> 3;   // CHECK-DAG: @f_const2 = {{.*}}global i16 21
+_Fract f_const3 = -0.0001r << 5;   // CHECK-DAG: @f_const3 = {{.*}}global i16 -96
+_Fract f_const4 = -0.75r >> 15;// CHECK-DAG: @f_const4 = {{.*}}global i16 -1
+_Fract f_const5 = 0.078216552734375r << 3; // CHECK-DAG: @f_const5 = {{.*}}global i16 20504
+
+unsigned _Fract uf_const1 = 0.375ur >> 13;
+// SIGNED-DAG:   @uf_const1 = {{.*}}global i16 3
+// UNSIGNED-DAG: @uf_const1 = {{.*}}global i16 1
+unsigned _Fract uf_const2 = 0.0546875ur << 3;
+// SIGNED-DAG:   @uf_const2 = {{.*}}global i16 28672
+// UNSIGNED-DAG: @uf_const2 = {{.*}}global i16 14336
+
+_Sat short _Accum ssa_const1 = (_Sat short _Accum)31.875hk << 4; // CHECK-DAG: @ssa_const1 = {{.*}}global i16 32767
+_Sat short _Accum ssa_const2 = (_Sat short _Accum) - 1.0hk << 8; // CHECK-DAG: @ssa_const2 = {{.*}}global i16 -32768
+_Sat short _Accum ssa_const3 = (_Sat short _Accum)128.0hk << 8;  // CHECK-DAG: @ssa_const3 = {{.*}}global i16 32767
+_Sat short _Fract ssf_const1 = (_Sat short _Fract) - 0.5hr << 3; // CHECK-DAG: @ssf_const1 = {{.*}}global i8 -128
+
+_Sat unsigned _Fract suf_const1 = (_Sat unsigned _Fract)0.5r << 1;
+// SIGNED-DAG:   @suf_const1 = {{.*}}global i16 -1
+// UNSIGNED-DAG: @suf_const1 = {{.*}}global i16 32767
+_Sat unsigned _Fract suf_const2 = (_Sat unsigned _Fract)0.25r << 1;
+// SIGNED-DAG:   @suf_const2 = {{.*}}global i16 -32768
+// UNSIGNED-DAG: @suf_const2 = {{.*}}global i16 16384
+_Sat unsigned _Accum sua_const2 = (_Sat unsigned _Accum)128.0uk << 10;
+// SIGNED-DAG:   @sua_const2 = {{.*}}global i32 -1
+// UNSIGNED-DAG: @sua_const2 = {{.*}}global i32 2147483647
Index: clang/test/Frontend/fixed_point_errors.c
===
--- clang/test/Frontend/fixed_point_errors.c
+++ clang/test/Frontend/fixed_point_errors.c
@@ -259,11 +259,30 @@
 short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr);  // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
 short _Accum div_ovf1 = 255.0hk / 0.5hk;  // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}}
 
+short _Accum shl_ovf1 = 255.0hk << 8;   // expected-warning {{overflow in expression; result is -256.0 with type 'short _Accum'}}
+short _Fract shl_ovf2 = -0.25hr << 3;   // expected-warning {{overflow in expression; result is 0.0 with type 'short _Fract'}}
+unsigned short _Accum shl_ovf3 = 100.5uhk << 3; // expected-warning {{overflow in expression; result is 36.0 with type 'unsigned short _Accum'}}
+short _Fract shl_ovf4 = 0.25hr << 2;// expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
+
+_Accum shl_bw1 = 0.91552734375k << 32;   // expected-warning {{shift count >= width of type}} \
+ expected-warning {{overflow in expression; result is -65536.0 with type '_Accum'}}
+unsigned _Fract shl_bw2 = 0.65ur << 16;  // expected-warning {{shift count >= width of type}} \
+ expected-warning {{overflow in expression; result is 0.0 with type 'unsigned _Fract'}}
+_Sat short _Accum shl_bw3 = (_Sat short _Accum)80.0hk << 17; // expected-warning {{shift count >= width of type}}
+short _Accum shr_bw1 = 1.0hk >> 17; 

[PATCH] D83215: [AST][RecoveryExpr] Clarify the documentation of RecoveryExpr.

2020-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/AST/Expr.h:6229
+///
+/// FIXME: RecoveryExpr is C++ only, make it work for C by supporting 
dependence
+/// mechanism for C language in clang.

this could be a little more specific (e.g. what does C++ only mean)...
FIXME: RecoveryExpr is currently generated by default in C++ mode only, as 
dependence isn't handled properly on several C-only codepaths.



Comment at: clang/lib/AST/ComputeDependence.cpp:498
 ExprDependence clang::computeDependence(RecoveryExpr *E) {
-  // Mark the expression as value- and instantiation- dependent to reuse
-  // existing suppressions for dependent code, e.g. avoiding
-  // constant-evaluation.
-  // FIXME: drop type+value+instantiation once Error is sufficient to suppress
-  // bogus dianostics.
+  // RecoveryExpr dependence-bits setting:
+  //   - type-dep is set if we don't know about the type (fallback to an opaque

I can't really follow this explanation.
- The first bullet  says when, the other two bullets say why
- the reasons given don't seem to be very principled ones (e.g. suppressing 
constant-evaluation is indeed a nice effect of value-dependency, but I don't 
think it's the *reason* for the value-dependency, rather that the value depends 
on how the error is resolved)
- I don't understand the connection between the "setting" list and the 
"explanations" one.





Comment at: clang/lib/AST/ComputeDependence.cpp:499
+  // RecoveryExpr dependence-bits setting:
+  //   - type-dep is set if we don't know about the type (fallback to an opaque
+  // dependent type);

, or if the type is known and dependent


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83215



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


[PATCH] D83218: Hand Allocator and IdentifierTable into FormatTokenLexer.

2020-07-07 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 275964.
klimek added a comment.

Address review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83218

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnalyzer.cpp


Index: clang/lib/Format/TokenAnalyzer.cpp
===
--- clang/lib/Format/TokenAnalyzer.cpp
+++ clang/lib/Format/TokenAnalyzer.cpp
@@ -64,11 +64,16 @@
 
 std::pair TokenAnalyzer::process() {
   tooling::Replacements Result;
-  FormatTokenLexer Tokens(Env.getSourceManager(), Env.getFileID(),
-  Env.getFirstStartColumn(), Style, Encoding);
+  llvm::SpecificBumpPtrAllocator Allocator;
+  IdentifierTable IdentTable(getFormattingLangOpts(Style));
+  FormatTokenLexer Lex(Env.getSourceManager(), Env.getFileID(),
+   Env.getFirstStartColumn(), Style, Encoding, Allocator,
 
-  UnwrappedLineParser Parser(Style, Tokens.getKeywords(),
- Env.getFirstStartColumn(), Tokens.lex(), *this);
+   IdentTable);
+  ArrayRef Toks(Lex.lex());
+  SmallVector Tokens(Toks.begin(), Toks.end());
+  UnwrappedLineParser Parser(Style, Lex.getKeywords(),
+ Env.getFirstStartColumn(), Tokens, *this);
   Parser.parse();
   assert(UnwrappedLines.rbegin()->empty());
   unsigned Penalty = 0;
@@ -76,14 +81,14 @@
 LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
 SmallVector AnnotatedLines;
 
-TokenAnnotator Annotator(Style, Tokens.getKeywords());
+TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) {
   AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i]));
   Annotator.annotate(*AnnotatedLines.back());
 }
 
 std::pair RunResult =
-analyze(Annotator, AnnotatedLines, Tokens);
+analyze(Annotator, AnnotatedLines, Lex);
 
 LLVM_DEBUG({
   llvm::dbgs() << "Replacements for run " << Run << ":\n";
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -38,7 +38,9 @@
 class FormatTokenLexer {
 public:
   FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, unsigned Column,
-   const FormatStyle &Style, encoding::Encoding Encoding);
+   const FormatStyle &Style, encoding::Encoding Encoding,
+   llvm::SpecificBumpPtrAllocator &Allocator,
+   IdentifierTable &IdentTable);
 
   ArrayRef lex();
 
@@ -103,10 +105,10 @@
   const SourceManager &SourceMgr;
   FileID ID;
   const FormatStyle &Style;
-  IdentifierTable IdentTable;
+  IdentifierTable &IdentTable;
   AdditionalKeywords Keywords;
   encoding::Encoding Encoding;
-  llvm::SpecificBumpPtrAllocator Allocator;
+  llvm::SpecificBumpPtrAllocator &Allocator;
   // Index (in 'Tokens') of the last token that starts a new line.
   unsigned FirstInLineIndex;
   SmallVector Tokens;
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -22,13 +22,15 @@
 namespace clang {
 namespace format {
 
-FormatTokenLexer::FormatTokenLexer(const SourceManager &SourceMgr, FileID ID,
-   unsigned Column, const FormatStyle &Style,
-   encoding::Encoding Encoding)
+FormatTokenLexer::FormatTokenLexer(
+const SourceManager &SourceMgr, FileID ID, unsigned Column,
+const FormatStyle &Style, encoding::Encoding Encoding,
+llvm::SpecificBumpPtrAllocator &Allocator,
+IdentifierTable &IdentTable)
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
   Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
-  Style(Style), IdentTable(getFormattingLangOpts(Style)),
-  Keywords(IdentTable), Encoding(Encoding), FirstInLineIndex(0),
+  Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
+  Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
   Lex.reset(new Lexer(ID, SourceMgr.getBuffer(ID), SourceMgr,


Index: clang/lib/Format/TokenAnalyzer.cpp
===
--- clang/lib/Format/TokenAnalyzer.cpp
+++ clang/lib/Format/TokenAnalyzer.cpp
@@ -64,11 +64,16 @@
 
 std::pair TokenAnalyzer::process() {
   tooling::Replacements Result;
-  FormatTokenLexer Tokens(Env.getSourceManager(), Env.getFileID(),
-  Env.getFirstStartColumn(), Style, Encoding);
+  llvm::SpecificBumpPtrAll

[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12944
+  Fn->getBeginLoc(), RParenLoc, SubExprs,
+  ReturnType.isNull()
+  ? ReturnType

here we're splitting the type (e.g. int&&) into a type + VK, and passing both 
to createrecoveryexpr.

Why not do that on recoveryexpr side? e.g. if we request a recoveryexpr of type 
int&, return an LValue recoveryexpr of type int?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201



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


[clang] 8c2a613 - Hand Allocator and IdentifierTable into FormatTokenLexer.

2020-07-07 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2020-07-07T11:56:34+02:00
New Revision: 8c2a613976075368a1f6e3ac3c9c8b1927b465ec

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

LOG: Hand Allocator and IdentifierTable into FormatTokenLexer.

This allows us to share the allocator in the future so we can create tokens 
while parsing.

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnalyzer.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index dbbe6f814ace..1fd153d1112e 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -22,13 +22,15 @@
 namespace clang {
 namespace format {
 
-FormatTokenLexer::FormatTokenLexer(const SourceManager &SourceMgr, FileID ID,
-   unsigned Column, const FormatStyle &Style,
-   encoding::Encoding Encoding)
+FormatTokenLexer::FormatTokenLexer(
+const SourceManager &SourceMgr, FileID ID, unsigned Column,
+const FormatStyle &Style, encoding::Encoding Encoding,
+llvm::SpecificBumpPtrAllocator &Allocator,
+IdentifierTable &IdentTable)
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
   Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
-  Style(Style), IdentTable(getFormattingLangOpts(Style)),
-  Keywords(IdentTable), Encoding(Encoding), FirstInLineIndex(0),
+  Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
+  Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
   Lex.reset(new Lexer(ID, SourceMgr.getBuffer(ID), SourceMgr,

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 219cd46f98ed..6b08677e3369 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -38,7 +38,9 @@ enum LexerState {
 class FormatTokenLexer {
 public:
   FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, unsigned Column,
-   const FormatStyle &Style, encoding::Encoding Encoding);
+   const FormatStyle &Style, encoding::Encoding Encoding,
+   llvm::SpecificBumpPtrAllocator &Allocator,
+   IdentifierTable &IdentTable);
 
   ArrayRef lex();
 
@@ -103,10 +105,10 @@ class FormatTokenLexer {
   const SourceManager &SourceMgr;
   FileID ID;
   const FormatStyle &Style;
-  IdentifierTable IdentTable;
+  IdentifierTable &IdentTable;
   AdditionalKeywords Keywords;
   encoding::Encoding Encoding;
-  llvm::SpecificBumpPtrAllocator Allocator;
+  llvm::SpecificBumpPtrAllocator &Allocator;
   // Index (in 'Tokens') of the last token that starts a new line.
   unsigned FirstInLineIndex;
   SmallVector Tokens;

diff  --git a/clang/lib/Format/TokenAnalyzer.cpp 
b/clang/lib/Format/TokenAnalyzer.cpp
index eb98a205d526..f1459a808ff8 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -64,11 +64,16 @@ TokenAnalyzer::TokenAnalyzer(const Environment &Env, const 
FormatStyle &Style)
 
 std::pair TokenAnalyzer::process() {
   tooling::Replacements Result;
-  FormatTokenLexer Tokens(Env.getSourceManager(), Env.getFileID(),
-  Env.getFirstStartColumn(), Style, Encoding);
+  llvm::SpecificBumpPtrAllocator Allocator;
+  IdentifierTable IdentTable(getFormattingLangOpts(Style));
+  FormatTokenLexer Lex(Env.getSourceManager(), Env.getFileID(),
+   Env.getFirstStartColumn(), Style, Encoding, Allocator,
 
-  UnwrappedLineParser Parser(Style, Tokens.getKeywords(),
- Env.getFirstStartColumn(), Tokens.lex(), *this);
+   IdentTable);
+  ArrayRef Toks(Lex.lex());
+  SmallVector Tokens(Toks.begin(), Toks.end());
+  UnwrappedLineParser Parser(Style, Lex.getKeywords(),
+ Env.getFirstStartColumn(), Tokens, *this);
   Parser.parse();
   assert(UnwrappedLines.rbegin()->empty());
   unsigned Penalty = 0;
@@ -76,14 +81,14 @@ std::pair 
TokenAnalyzer::process() {
 LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
 SmallVector AnnotatedLines;
 
-TokenAnnotator Annotator(Style, Tokens.getKeywords());
+TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) {
   AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i]));
   Annotator.annotate(*AnnotatedLines.back());
 }
 
 std::pair RunResult =
-  

[PATCH] D83218: Hand Allocator and IdentifierTable into FormatTokenLexer.

2020-07-07 Thread Manuel Klimek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c2a61397607: Hand Allocator and IdentifierTable into 
FormatTokenLexer. (authored by klimek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83218

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnalyzer.cpp


Index: clang/lib/Format/TokenAnalyzer.cpp
===
--- clang/lib/Format/TokenAnalyzer.cpp
+++ clang/lib/Format/TokenAnalyzer.cpp
@@ -64,11 +64,16 @@
 
 std::pair TokenAnalyzer::process() {
   tooling::Replacements Result;
-  FormatTokenLexer Tokens(Env.getSourceManager(), Env.getFileID(),
-  Env.getFirstStartColumn(), Style, Encoding);
+  llvm::SpecificBumpPtrAllocator Allocator;
+  IdentifierTable IdentTable(getFormattingLangOpts(Style));
+  FormatTokenLexer Lex(Env.getSourceManager(), Env.getFileID(),
+   Env.getFirstStartColumn(), Style, Encoding, Allocator,
 
-  UnwrappedLineParser Parser(Style, Tokens.getKeywords(),
- Env.getFirstStartColumn(), Tokens.lex(), *this);
+   IdentTable);
+  ArrayRef Toks(Lex.lex());
+  SmallVector Tokens(Toks.begin(), Toks.end());
+  UnwrappedLineParser Parser(Style, Lex.getKeywords(),
+ Env.getFirstStartColumn(), Tokens, *this);
   Parser.parse();
   assert(UnwrappedLines.rbegin()->empty());
   unsigned Penalty = 0;
@@ -76,14 +81,14 @@
 LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
 SmallVector AnnotatedLines;
 
-TokenAnnotator Annotator(Style, Tokens.getKeywords());
+TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) {
   AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i]));
   Annotator.annotate(*AnnotatedLines.back());
 }
 
 std::pair RunResult =
-analyze(Annotator, AnnotatedLines, Tokens);
+analyze(Annotator, AnnotatedLines, Lex);
 
 LLVM_DEBUG({
   llvm::dbgs() << "Replacements for run " << Run << ":\n";
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -38,7 +38,9 @@
 class FormatTokenLexer {
 public:
   FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, unsigned Column,
-   const FormatStyle &Style, encoding::Encoding Encoding);
+   const FormatStyle &Style, encoding::Encoding Encoding,
+   llvm::SpecificBumpPtrAllocator &Allocator,
+   IdentifierTable &IdentTable);
 
   ArrayRef lex();
 
@@ -103,10 +105,10 @@
   const SourceManager &SourceMgr;
   FileID ID;
   const FormatStyle &Style;
-  IdentifierTable IdentTable;
+  IdentifierTable &IdentTable;
   AdditionalKeywords Keywords;
   encoding::Encoding Encoding;
-  llvm::SpecificBumpPtrAllocator Allocator;
+  llvm::SpecificBumpPtrAllocator &Allocator;
   // Index (in 'Tokens') of the last token that starts a new line.
   unsigned FirstInLineIndex;
   SmallVector Tokens;
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -22,13 +22,15 @@
 namespace clang {
 namespace format {
 
-FormatTokenLexer::FormatTokenLexer(const SourceManager &SourceMgr, FileID ID,
-   unsigned Column, const FormatStyle &Style,
-   encoding::Encoding Encoding)
+FormatTokenLexer::FormatTokenLexer(
+const SourceManager &SourceMgr, FileID ID, unsigned Column,
+const FormatStyle &Style, encoding::Encoding Encoding,
+llvm::SpecificBumpPtrAllocator &Allocator,
+IdentifierTable &IdentTable)
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
   Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
-  Style(Style), IdentTable(getFormattingLangOpts(Style)),
-  Keywords(IdentTable), Encoding(Encoding), FirstInLineIndex(0),
+  Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
+  Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
   Lex.reset(new Lexer(ID, SourceMgr.getBuffer(ID), SourceMgr,


Index: clang/lib/Format/TokenAnalyzer.cpp
===
--- clang/lib/Format/TokenAnalyzer.cpp
+++ clang/lib/Format/TokenAnalyzer.cpp
@@ -64,11 +64,16 @@
 
 std::pair TokenAnalyzer::process() {
   tooling::Replacements Result;
-  FormatTokenLexer Tokens(Env.getSourceManager(), Env.getFileID(),
- 

[PATCH] D83213: [AST][RecoveryExpr] Don't set the instantiation-bit.

2020-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

What's the rationale/motivation for this? I'd expect this to break a lot of 
subtle assumptions, because the invariant "nothing can be dependent without 
being instantiation-dependent" is a useful one.

It also doesn't seem correct from first principles. My mental model is:

- dependence describes code where some properties are unknown because a 
template wasn't instantiated yet
- we've generalized this to "some properties are unknown because we don't know 
what this piece of code is supposed to say"
- we can never know the value at compile-time even in contexts where we should, 
so RecoveryExpr is value-dependent
- we only know the type at compile-time if the RecoveryExpr's type is known and 
not itself dependent, so RecoveryExpr is usually value-dependent
- the code may intend to refer to entities valid only in certain instantiations 
(consider `(void)f(T())` where f is an overloaded function). So RecoveryExpr is 
at least sometimes instantiation-dependent

At best I think we could say that the expr is only instantiation-dependent if 
it occurs in a template scope - otherwise there's no template we might fail to 
instantiate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83213



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


[PATCH] D83290: [clangd] Enable async preambles by default

2020-07-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
javed.absar, ilya-biryukov.
Herald added a project: clang.

We've been testing this internally for a couple weeks now and it seems
to be stable enough. Let's flip the flag before branch cut to increase testing
coverage and have enough time to revert if need be.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83290

Files:
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/TUScheduler.h


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -194,7 +194,7 @@
 
 /// Whether to run PreamblePeer asynchronously.
 /// No-op if AsyncThreadsCount is 0.
-bool AsyncPreambleBuilds = false;
+bool AsyncPreambleBuilds = true;
 
 /// Used to create a context that wraps each single operation.
 /// Typically to inject per-file configuration.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -100,7 +100,7 @@
 bool StorePreamblesInMemory = true;
 /// Reuse even stale preambles, and rebuild them in the background.
 /// This improves latency at the cost of accuracy.
-bool AsyncPreambleBuilds = false;
+bool AsyncPreambleBuilds = true;
 
 /// If true, ClangdServer builds a dynamic in-memory index for symbols in
 /// opened files and uses the index to augment code completion results.


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -194,7 +194,7 @@
 
 /// Whether to run PreamblePeer asynchronously.
 /// No-op if AsyncThreadsCount is 0.
-bool AsyncPreambleBuilds = false;
+bool AsyncPreambleBuilds = true;
 
 /// Used to create a context that wraps each single operation.
 /// Typically to inject per-file configuration.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -100,7 +100,7 @@
 bool StorePreamblesInMemory = true;
 /// Reuse even stale preambles, and rebuild them in the background.
 /// This improves latency at the cost of accuracy.
-bool AsyncPreambleBuilds = false;
+bool AsyncPreambleBuilds = true;
 
 /// If true, ClangdServer builds a dynamic in-memory index for symbols in
 /// opened files and uses the index to augment code completion results.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko marked 8 inline comments as done.
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:506
+  APSIntType Type(Int);
+  return Int == Type.getZeroValue();
+}

xazax.hun wrote:
> Does the semantics if this differ from ` llvm::APInt::isNullValue`?
Good catch!



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1254
+//   sufficient.
+return S1->get() == S2->get() &&
+   S1->get() == S2->get();

xazax.hun wrote:
> xazax.hun wrote:
> > Sorry, but I am a bit confused here.
> > 
> > Does `haveEqualConstraints` have anything to do with equivalence classes?
> > 
> > I.e., what if I have two symbols with the same constraints (but those two 
> > symbols were never compared).
> > ```
> > void f(int a, int b) {
> >   int c = clamp(a, 5, 10);
> >   int d = clamp(b, 5, 10);
> > }
> > ```
> > 
> > In the code above if analyzer understands clamp, the range for `c` and `d` 
> > will be the same. Even though we never really compared them.
> > I would expect `haveEqualConstraints` to return true, even if they do not 
> > belong to the same equivalence class.
> > 
> > Do I miss something?
> Never mind, I misunderstood this function. It operates on program states not 
> on symbols.
Nothing to be sorry about, I'm happy to clarify!

`haveEqualConstraints` is here for our join heuristic that helps removing 
duplicating paths.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1380
 
+ConstraintMap ento::getConstraintMap(ProgramStateRef State) {
+  ConstraintMap::Factory &F = State->get_context();

xazax.hun wrote:
> So we basically do a conversion to Symbol -> Ranges from Class -> Ranges.
> I wonder if it is possible to get rid of this conversion in the future to get 
> some performance benefits.
> We could either make all code work with both kind of range maps or have 
> something like (Symbol + Class) -> Ranges to avoid conversion.
> What do you think?
> 
> I am not opposed to this code at the moment, I just wonder if there is a 
> relatively low hanging fruit for some performance gains in the future.
This is here only for a very specific mode - when we double check found 
warnings with Z3.  That mode needs constraints assigned to symbols, so here we 
construct such a set on-the-fly.  So, we store ALL of the ranges in the map 
Class -> Ranges and construct Symbol -> Ranges on very special occasions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445



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


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 275981.
vsavchenko added a comment.

Get rid of 'isZero'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c

Index: clang/test/Analysis/equality_tracking.c
===
--- /dev/null
+++ clang/test/Analysis/equality_tracking.c
@@ -0,0 +1,167 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false
+
+#define NULL (void *)0
+
+#define UCHAR_MAX (unsigned char)(~0U)
+#define CHAR_MAX (char)(UCHAR_MAX & (UCHAR_MAX >> 1))
+#define CHAR_MIN (char)(UCHAR_MAX & ~(UCHAR_MAX >> 1))
+
+void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
+
+int getInt();
+
+void zeroImpliesEquality(int a, int b) {
+  clang_analyzer_eval((a - b) == 0); // expected-warning{{UNKNOWN}}
+  if ((a - b) == 0) {
+clang_analyzer_eval(b != a);// expected-warning{{FALSE}}
+clang_analyzer_eval(b == a);// expected-warning{{TRUE}}
+clang_analyzer_eval(!(a != b)); // expected-warning{{TRUE}}
+clang_analyzer_eval(!(b == a)); // expected-warning{{FALSE}}
+return;
+  }
+  clang_analyzer_eval((a - b) == 0); // expected-warning{{FALSE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+}
+
+void zeroImpliesReversedEqual(int a, int b) {
+  clang_analyzer_eval((b - a) == 0); // expected-warning{{UNKNOWN}}
+  if ((b - a) == 0) {
+clang_analyzer_eval(b != a); // expected-warning{{FALSE}}
+clang_analyzer_eval(b == a); // expected-warning{{TRUE}}
+return;
+  }
+  clang_analyzer_eval((b - a) == 0); // expected-warning{{FALSE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(b == a); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b != a); // expected-warning{{UNKNOWN}}
+}
+
+void canonicalEqual(int a, int b) {
+  clang_analyzer_eval(a == b); // expected-warning{{UNKNOWN}}
+  if (a == b) {
+clang_analyzer_eval(b == a); // expected-warning{{TRUE}}
+return;
+  }
+  clang_analyzer_eval(a == b); // expected-warning{{FALSE}}
+  clang_analyzer_eval(b == a); // expected-warning{{FALSE}}
+}
+
+void test(int a, int b, int c, int d) {
+  if (a == b && c == d) {
+if (a == 0 && b == d) {
+  clang_analyzer_eval(c == 0); // expected-warning{{TRUE}}
+}
+c = 10;
+if (b == d) {
+  clang_analyzer_eval(c == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(d == 10); // expected-warning{{UNKNOWN}}
+// expected-warning@-1{{FALSE}}
+  clang_analyzer_eval(b == a);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(a == d);  // expected-warning{{TRUE}}
+
+  b = getInt();
+  clang_analyzer_eval(a == d); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a == b); // expected-warning{{UNKNOWN}}
+}
+  }
+
+  if (a != b && b == c) {
+if (c == 42) {
+  clang_analyzer_eval(b == 42); // expected-warning{{TRUE}}
+  // FIXME: we should track disequality information as well
+  clang_analyzer_eval(a != 42); // expected-warning{{UNKNOWN}}
+}
+  }
+}
+
+void testIntersection(int a, int b, int c) {
+  if (a < 42 && b > 15 && c >= 25 && c <= 30) {
+if (a != b)
+  return;
+
+clang_analyzer_eval(a > 15);  // expected-warning{{TRUE}}
+clang_analyzer_eval(b < 42);  // expected-warning{{TRUE}}
+clang_analyzer_eval(a <= 30); // expected-warning{{UNKNOWN}}
+
+if (c == b) {
+  // For all equal symbols, we should track the minimal common range.
+  //
+  // Also, it should be noted that c is dead at this point, but the
+  // constraint initially associated with c is still around.
+  clang_analyzer_eval(a >= 25 && a <= 30); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b >= 25 && b <= 30); // expected-warning{{TRUE}}
+}
+  }
+}
+
+void testPromotion(int a, char b) {
+  if (b > 10) {
+if (a == b) {
+  // FIXME: support transferring char ranges onto equal int symbols
+  //when char is promoted to int
+  clang_analyzer_eval(a > 10);// expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a <= CHAR_MAX); // expected-warning{{UNKNOWN}}
+}
+  }
+}
+
+void testPromotionOnlyTypes(int a, char b) {
+  if (a == b) {
+// FIXME: support transferring char ranges onto equal int symbols
+//when char is promoted to int

[PATCH] D81676: [MSP430] Align the toolchain definition with the TI's msp430-gcc v9.2.0

2020-07-07 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 275983.
atrosinenko added a comment.

Fix path separators in unit test on Windows


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81676

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/430/exceptions/crtend_no_eh.o
  clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtbegin_no_eh.o
  clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/exceptions/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/include-fixed/limits.h
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/include/stddef.h
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/exceptions/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/crtend_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtbegin_no_eh.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend.o
  
clang/test/Driver/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/8.3.1/large/full-memory-range/exceptions/crtend_no_eh.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/include/stdio.h
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/crtn.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/430/exceptions/crt0.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/crt0.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/exceptions/crt0.o
  clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/crt0.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/exceptions/crt0.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/crt0.o
  
clang/test/Driver/Inputs/basic_msp430_tree/msp430-elf/lib/large/full-memory-range/exceptions/crt0.o
  clang/test/Driver/msp430-toolchain.c

Index: clang/test/Driver/msp430-toolchain.c
===
--- clang/test/Driver/msp430-toolchain.c
+++ clang/test/Driver/msp430-toolchain.c
@@ -1,78 +1,249 @@
-// A basic clang -cc1 command-line, and simple environment check.
+//

[PATCH] D83099: [clangd] Store index in '.cache/clangd/index' instead of '.clangd/index'

2020-07-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: .gitignore:57
+# clangd index. (".clangd" is a config file now, thus trailing slash)
+.clangd/
+.cache

why do we still need this ? i thought index (and other caches) would reside in 
`.cache` ?



Comment at: clang-tools-extra/clangd/index/Background.h:61
+  // CDBDirectory is the first directory containing a CDB in parent directories
+  // of a file, or user's home directory if none was found, e.g. stdlib 
headers.
   static Factory createDiskBackedStorageFactory(

nit: maybe talk about XDG_CACHE instead of home directory as fallback location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83099



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


[PATCH] D83293: [clang-tidy] Fix an unused-raii check crash on objective-c++.

2020-07-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83293

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct Foo {
+  ~Foo() {}
+};
+
+@interface ABC {
+}
+- (Foo)set:(int)p;
+@end
+
+void test(ABC* s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct Foo {
+  ~Foo() {}
+};
+
+@interface ABC {
+}
+- (Foo)set:(int)p;
+@end
+
+void test(ABC* s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:149
+  case OO_PipePipe:
+  // Less common binary operators
+  case OO_ArrowStar:

Please drop this comment, I don't think it helps understand the code.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

I don't think we need a separate class to show the left shift operator. The 
declaration below can be:

```
  friend X operator<<(X&, const X&);
```



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2199
+  X operator,(X&);
+  // TODO: Test for `->*`. Fix crash before
 };

"TODO: Fix the crash on `->*` and add a test for it."



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2376
+| | |   `-x
+| | `-IdExpression
+| |   `-UnqualifiedId

eduucaldas wrote:
> gribozavr2 wrote:
> > I'm not sure about this part where `++` is wrapped in IdExpression -- 
> > shouldn't the syntax tree look identical to a builtin postfix `++` (see 
> > another test in this file)?
> This comes back to a discussion we had a month ago about operators ( `+`, 
> `!`, etc)
> **Question**: Should we represent operators (built-in or overloaded) in the 
> syntax tree uniformly? If so in which way?
> **Context**: The ClangAST stores built-in operators as mere tokens, whereas 
> overloaded operators are represented as a `DeclRefExpr`. That makes a lot of 
> sense for the ClangAST, as we might refer back to the declaration of the 
> overloaded operator, but the declaration of built-in operator doesn't exist.
> **Conclusion**: Have the same representation for both types of operators. I 
> have implemented the "unboxed" representation of overloaded operators, i.e. 
> just storing their token in the syntax tree. I have not committed that, but I 
> can do it just after this patch.
SGTM. Please just leave a FIXME or TODO in this patch that shows that certain 
parts of tests are not final.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[PATCH] D83293: [clang-tidy] Fix an unused-raii check crash on objective-c++.

2020-07-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm:3
+
+struct Foo {
+  ~Foo() {}

Foo => CxxClass
ABC => ObjcClass


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83293



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


[PATCH] D83294: [Fixed Point] Add codegen for fixed-point shifts.

2020-07-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan, bjope.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds codegen to Clang for fixed-point shift
operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83294

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_compound.c
  clang/test/Frontend/fixed_point_shift.c

Index: clang/test/Frontend/fixed_point_shift.c
===
--- clang/test/Frontend/fixed_point_shift.c
+++ clang/test/Frontend/fixed_point_shift.c
@@ -35,3 +35,361 @@
 _Sat unsigned _Accum sua_const2 = (_Sat unsigned _Accum)128.0uk << 10;
 // SIGNED-DAG:   @sua_const2 = {{.*}}global i32 -1
 // UNSIGNED-DAG: @sua_const2 = {{.*}}global i32 2147483647
+
+// CHECK-LABEL: @SignedLeftShift(
+void SignedLeftShift() {
+  short _Accum sa;
+  _Accum a;
+  long _Accum la;
+
+  short _Fract sf;
+  _Fract f;
+  long _Fract lf;
+
+  int i;
+  unsigned u;
+
+  // CHECK: [[TMP0:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP2:%.*]] = trunc i32 [[TMP1]] to i16
+  // CHECK-NEXT:[[TMP3:%.*]] = shl i16 [[TMP0]], [[TMP2]]
+  // CHECK-NEXT:store i16 [[TMP3]], i16* %sa, align 2
+  sa = sa << i;
+
+  // CHECK: [[TMP4:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:[[TMP5:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP6:%.*]] = shl i32 [[TMP4]], [[TMP5]]
+  // CHECK-NEXT:store i32 [[TMP6]], i32* %a, align 4
+  a = a << i;
+
+  // CHECK: [[TMP7:%.*]] = load i64, i64* %la, align 8
+  // CHECK-NEXT:[[TMP8:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP9:%.*]] = zext i32 [[TMP8]] to i64
+  // CHECK-NEXT:[[TMP10:%.*]] = shl i64 [[TMP7]], [[TMP9]]
+  // CHECK-NEXT:store i64 [[TMP10]], i64* %la, align 8
+  la = la << i;
+
+  // CHECK: [[TMP11:%.*]] = load i8, i8* %sf, align 1
+  // CHECK-NEXT:[[TMP12:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP13:%.*]] = trunc i32 [[TMP12]] to i8
+  // CHECK-NEXT:[[TMP14:%.*]] = shl i8 [[TMP11]], [[TMP13]]
+  // CHECK-NEXT:store i8 [[TMP14]], i8* %sf, align 1
+  sf = sf << i;
+
+  // CHECK: [[TMP15:%.*]] = load i16, i16* %f, align 2
+  // CHECK-NEXT:[[TMP16:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP17:%.*]] = trunc i32 [[TMP16]] to i16
+  // CHECK-NEXT:[[TMP18:%.*]] = shl i16 [[TMP15]], [[TMP17]]
+  // CHECK-NEXT:store i16 [[TMP18]], i16* %f, align 2
+  f = f << i;
+
+  // CHECK: [[TMP19:%.*]] = load i32, i32* %lf, align 4
+  // CHECK-NEXT:[[TMP20:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP21:%.*]] = shl i32 [[TMP19]], [[TMP20]]
+  // CHECK-NEXT:store i32 [[TMP21]], i32* %lf, align 4
+  lf = lf << i;
+
+  // CHECK: [[TMP22:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:[[TMP23:%.*]] = load i32, i32* %u, align 4
+  // CHECK-NEXT:[[TMP24:%.*]] = shl i32 [[TMP22]], [[TMP23]]
+  // CHECK-NEXT:store i32 [[TMP24]], i32* %a, align 4
+  a = a << u;
+
+  // CHECK: [[TMP25:%.*]] = load i16, i16* %f, align 2
+  // CHECK-NEXT:[[TMP26:%.*]] = load i32, i32* %u, align 4
+  // CHECK-NEXT:[[TMP27:%.*]] = trunc i32 [[TMP26]] to i16
+  // CHECK-NEXT:[[TMP28:%.*]] = shl i16 [[TMP25]], [[TMP27]]
+  // CHECK-NEXT:store i16 [[TMP28]], i16* %f, align 2
+  f = f << u;
+}
+
+// CHECK-LABEL: @UnsignedLeftShift(
+void UnsignedLeftShift() {
+  unsigned short _Accum usa;
+  unsigned _Accum ua;
+  unsigned long _Accum ula;
+
+  unsigned short _Fract usf;
+  unsigned _Fract uf;
+  unsigned long _Fract ulf;
+
+  int i;
+  unsigned u;
+
+  // CHECK: [[TMP0:%.*]] = load i16, i16* %usa, align 2
+  // CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP2:%.*]] = trunc i32 [[TMP1]] to i16
+  // CHECK-NEXT:[[TMP3:%.*]] = shl i16 [[TMP0]], [[TMP2]]
+  // CHECK-NEXT:store i16 [[TMP3]], i16* %usa, align 2
+  usa = usa << i;
+
+  // CHECK: [[TMP4:%.*]] = load i32, i32* %ua, align 4
+  // CHECK-NEXT:[[TMP5:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP6:%.*]] = shl i32 [[TMP4]], [[TMP5]]
+  // CHECK-NEXT:store i32 [[TMP6]], i32* %ua, align 4
+  ua = ua << i;
+
+  // CHECK: [[TMP7:%.*]] = load i64, i64* %ula, align 8
+  // CHECK-NEXT:[[TMP8:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP9:%.*]] = zext i32 [[TMP8]] to i64
+  // CHECK-NEXT:[[TMP10:%.*]] = shl i64 [[TMP7]], [[TMP9]]
+  // CHECK-NEXT:store i64 [[TMP10]], i64* %ula, align 8
+  ula = ula << i;
+
+  // CHECK: [[TMP11:%.*]] = load i8, i8* %usf, align 1
+  // CHECK-NEXT:[[TMP12:%.*]] = load i32, i32* %i, align 4
+  // CHECK-NEXT:[[TMP13:%.*]] = trunc i32 [[TMP12]] to i8
+  // CHECK-NEXT:[[TMP14:%.*]] = shl i8 [[TMP11]], [[TMP13]]
+  // CHECK-NEXT:store i8 [[TMP14]

[PATCH] D81552: [ASTMatchers] Added hasDirectBase and hasClass Matchers

2020-07-07 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 275991.
njames93 added a comment.

Removed all hasClass related changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81552

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

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3125,5 +3125,44 @@
  cxxRecordDecl(hasAnyBase(isVirtual();
 }
 
+TEST(BaseSpecifier, hasDirectBase) {
+  EXPECT_TRUE(matches(
+  R"cc(
+class Base {};
+class Derived : Base{};
+)cc",
+  cxxRecordDecl(hasName("Derived"),
+hasDirectBase(hasType(cxxRecordDecl(hasName("Base")));
+
+  StringRef MultiDerived = R"cc(
+class Base {};
+class Base2 {};
+class Derived : Base, Base2{};
+)cc";
+
+  EXPECT_TRUE(matches(
+  MultiDerived,
+  cxxRecordDecl(hasName("Derived"),
+hasDirectBase(hasType(cxxRecordDecl(hasName("Base")));
+  EXPECT_TRUE(matches(
+  MultiDerived,
+  cxxRecordDecl(hasName("Derived"),
+hasDirectBase(hasType(cxxRecordDecl(hasName("Base2")));
+
+  StringRef Indirect = R"cc(
+class Base {};
+class Intermediate : Base {};
+class Derived : Intermediate{};
+)cc";
+
+  EXPECT_TRUE(
+  matches(Indirect, cxxRecordDecl(hasName("Derived"),
+  hasDirectBase(hasType(cxxRecordDecl(
+  hasName("Intermediate")));
+  EXPECT_TRUE(notMatches(
+  Indirect,
+  cxxRecordDecl(hasName("Derived"),
+hasDirectBase(hasType(cxxRecordDecl(hasName("Base")));
+}
 } // namespace ast_matchers
 } // namespace clang
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -278,6 +278,7 @@
   REGISTER_MATCHER(hasDefinition);
   REGISTER_MATCHER(hasDescendant);
   REGISTER_MATCHER(hasDestinationType);
+  REGISTER_MATCHER(hasDirectBase);
   REGISTER_MATCHER(hasDynamicExceptionSpec);
   REGISTER_MATCHER(hasEitherOperand);
   REGISTER_MATCHER(hasElementType);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2862,7 +2862,7 @@
 /// BaseSpecMatcher.
 ///
 /// Example:
-/// matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase")
+/// matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase"
 /// \code
 ///   class Foo;
 ///   class Bar : Foo {};
@@ -2878,6 +2878,27 @@
   return internal::matchesAnyBase(Node, BaseSpecMatcher, Finder, Builder);
 }
 
+/// Matches C++ classes that have a direct base matching \p BaseSpecMatcher.
+///
+/// Example:
+/// matcher hasDirectBase(hasType(cxxRecordDecl(hasName("SpecialBase"
+/// \code
+///   class Foo;
+///   class Bar : Foo {};
+///   class Baz : Bar {};
+///   class SpecialBase;
+///   class Proxy : SpecialBase {};  // matches Proxy
+///   class IndirectlyDerived : Proxy {};  // doesn't match
+/// \endcode
+AST_MATCHER_P(CXXRecordDecl, hasDirectBase, internal::Matcher,
+  BaseSpecMatcher) {
+
+  return Node.hasDefinition() &&
+ llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &Base) {
+   return BaseSpecMatcher.matches(Base, Finder, Builder);
+ });
+}
+
 /// Similar to \c isDerivedFrom(), but also matches classes that directly
 /// match \c Base.
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -5658,7 +5658,7 @@
 Matches C++ classes that have a direct or indirect base matching BaseSpecMatcher.
 
 Example:
-matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase")
+matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase"
   class Foo;
   class Bar : Foo {};
   class Baz : Bar {};
@@ -5670,6 +5670,20 @@
 
 
 
+MatcherCXXRecordDecl>hasDirectBaseMatcherCXXBaseSpecifier> BaseSpecMatcher
+Matches C++ classes that have a direct base matching BaseSpecMatcher.
+
+Example:
+matcher hasDirectBase(hasType(cxxRecordDecl(hasName("SpecialBase"
+  class Foo;
+  class Bar : Foo {};
+  class Baz : Bar {}

[PATCH] D81552: [ASTMatchers] Added hasDirectBase Matcher

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

I've removed the hasClass changes as they dont entirely belong in here and 
weren't well received. Now with just the hasDirectBase this should be in a good 
state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81552



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


[PATCH] D83268: [OpenMP][NFC] Remove unused (always fixed) arguments

2020-07-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D83268#2135081 , @Hahnfeld wrote:

> This is definitely not NFC and breaks API compatibility (but apparently 
> nobody cares anymore?).


+1. Better to introduce new entry points and mark these ones as deprecated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83268



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


[PATCH] D83293: [clang-tidy] Fix an unused-raii check crash on objective-c++.

2020-07-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 275994.
hokein marked an inline comment as done.
hokein added a comment.

fix names.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83293

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct CxxClass {
+  ~CxxClass() {}
+};
+
+@interface ObjcClass {
+}
+- (CxxClass)set:(int)p;
+@end
+
+void test(ObjcClass *s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct CxxClass {
+  ~CxxClass() {}
+};
+
+@interface ObjcClass {
+}
+- (CxxClass)set:(int)p;
+@end
+
+void test(ObjcClass *s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 3b1e3d2 - [clang-tidy] Fix an unused-raii check crash on objective-c++.

2020-07-07 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-07-07T13:36:20+02:00
New Revision: 3b1e3d22735b37eea3ce52d655009f5cd4ad2262

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

LOG: [clang-tidy] Fix an unused-raii check crash on objective-c++.

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

Added: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm

Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
index 34a489e324e4..70ce413d20ff 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@ void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@ void UnusedRaiiCheck::check(const MatchFinder::MatchResult 
&Result) {
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
new file mode 100644
index ..432fd5329c56
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct CxxClass {
+  ~CxxClass() {}
+};
+
+@interface ObjcClass {
+}
+- (CxxClass)set:(int)p;
+@end
+
+void test(ObjcClass *s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}



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


[PATCH] D83293: [clang-tidy] Fix an unused-raii check crash on objective-c++.

2020-07-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3b1e3d22735b: [clang-tidy] Fix an unused-raii check crash on 
objective-c++. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83293

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct CxxClass {
+  ~CxxClass() {}
+};
+
+@interface ObjcClass {
+}
+- (CxxClass)set:(int)p;
+@end
+
+void test(ObjcClass *s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct CxxClass {
+  ~CxxClass() {}
+};
+
+@interface ObjcClass {
+}
+- (CxxClass)set:(int)p;
+@end
+
+void test(ObjcClass *s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}
Index: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-  cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()
-  .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+  unless(has(ignoringParenImpCasts(callExpr(,
+  unless(has(ignoringParenImpCasts(objcMessageExpr()
+  .bind("temp");
   Finder->addMatcher(
   traverse(ast_type_traits::TK_AsIs,
exprWithCleanups(
@@ -79,6 +80,7 @@
   auto Matches =
   match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
   Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
  getLangOpts()),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62574: Initial draft of target-configurable address spaces.

2020-07-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a subscriber: danilaml.
ebevhan added a comment.

In D62574#2133160 , @danilaml wrote:

> What are the remaining roadblocks left before this patch can be merged? I'm 
> interested in having a target-specific way to define the allowed 
> explicit/implicit address space conversions.


This has been on my backburner for various reasons, so I'm not sure what the 
status is any more. I could try rebasing it and seeing where things are at.
I don't believe that the issues I mentioned last have been dealt with, though.

This was also only an initial concept. I think that even once all the issues 
with the patch have been ironed out, it would require a round of wider review 
since it's a fairly hefty API change.

> Also, it appears that currently whether implicit casts between pointers of 
> different AS are allowed is determined by the superset relations only, 
> however https://reviews.llvm.org/D73360 introduced another (openCL-specific) 
> variable into the mix: whether the conversion is a top level or not. IMHO, 
> this should also be configured by the target, although I'm not sure whether 
> it needs a separate hook (isBitcastNoop or similar?) or it needs to check the 
> legality of the implicit casts differently.

That patch only seems to apply to C++, I think? The restriction on 
top-level-only conversion should be correct, at least in C++.
It's generally not safe to alter address spaces below the top level. C is just 
very permissive about it.


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

https://reviews.llvm.org/D62574



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


[PATCH] D83295: [Analyzer] Hotfix for various crashes in iterator checkers

2020-07-07 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, gamesh411, martong, balazske.
baloghadamsoftware added a project: clang.
Herald added subscribers: ASDenysPetrov, steakhal, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun, 
whisperity.
Herald added a reviewer: Szelethus.

The patch that introduces handling pointers implemented as iterators may cause 
crash in some projects because pointer difference is mistakenly handled as 
pointer decrement. (Similair case for iterators implemented as class instances 
are already handled correctly.) This patch fixes this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83295

Files:
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/test/Analysis/iterator-modeling.cpp
  clang/test/Analysis/iterator-range.cpp


Index: clang/test/Analysis/iterator-range.cpp
===
--- clang/test/Analysis/iterator-range.cpp
+++ clang/test/Analysis/iterator-range.cpp
@@ -935,3 +935,7 @@
   // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
+void ptr_iter_diff(cont_with_ptr_iterator &c) {
+  auto i0 = c.begin(), i1 = c.end();
+  ptrdiff_t len = i1 - i0; // no-crash
+}
Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -1972,6 +1972,11 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // 
expected-warning{{$c.end() - 2}}
 }
 
+void ptr_iter_diff(cont_with_ptr_iterator &c) {
+  auto i0 = c.begin(), i1 = c.end();
+  ptrdiff_t len = i1 - i0; // no-crash
+}
+
 void clang_analyzer_printState();
 
 void print_state(std::vector &V) {
Index: clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -169,6 +169,8 @@
 verifyDereference(C, LVal);
   } else if (isRandomIncrOrDecrOperator(OK)) {
 SVal RVal = State->getSVal(BO->getRHS(), C.getLocationContext());
+if (!BO->getRHS()->getType()->isIntegralOrEnumerationType())
+  return;
 verifyRandomIncrOrDecr(C, BinaryOperator::getOverloadedOperator(OK), LVal,
RVal);
   }
Index: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -272,6 +272,8 @@
 handleComparison(C, BO, Result, LVal, RVal,
  BinaryOperator::getOverloadedOperator(OK));
   } else if (isRandomIncrOrDecrOperator(OK)) {
+if (!BO->getRHS()->getType()->isIntegralOrEnumerationType())
+  return;
 handlePtrIncrOrDecr(C, BO->getLHS(),
 BinaryOperator::getOverloadedOperator(OK), RVal);
   }
@@ -461,6 +463,9 @@
 RPos = getIteratorPosition(State, RVal);
   }
 
+  if (!LPos || !RPos)
+return;
+
   // We cannot make assumptions on `UnknownVal`. Let us conjure a symbol
   // instead.
   if (RetVal.isUnknown()) {


Index: clang/test/Analysis/iterator-range.cpp
===
--- clang/test/Analysis/iterator-range.cpp
+++ clang/test/Analysis/iterator-range.cpp
@@ -935,3 +935,7 @@
   // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
+void ptr_iter_diff(cont_with_ptr_iterator &c) {
+  auto i0 = c.begin(), i1 = c.end();
+  ptrdiff_t len = i1 - i0; // no-crash
+}
Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -1972,6 +1972,11 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.end() - 2}}
 }
 
+void ptr_iter_diff(cont_with_ptr_iterator &c) {
+  auto i0 = c.begin(), i1 = c.end();
+  ptrdiff_t len = i1 - i0; // no-crash
+}
+
 void clang_analyzer_printState();
 
 void print_state(std::vector &V) {
Index: clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -169,6 +169,8 @@
 verifyDereference(C, LVal);
   } else if (isRandomIncrOrDecrOperator(OK)) {
 SVal RVal = State->getSVal(BO->getRHS(), C.getLocationContext());
+if (!BO->getRHS()->getType()->isIntegralOrEnumerationType())
+  return;
 verifyRandomIncrOrDecr(C, BinaryOperator::getOverloadedOperator(OK), LVal,

[PATCH] D83296: [clang-format] Add a MacroExpander.

2020-07-07 Thread Manuel Klimek via Phabricator via cfe-commits
klimek created this revision.
klimek added a reviewer: sammccall.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

The MacroExpander allows to expand simple (non-resursive) macro
definitions from a macro identifier token and macro arguments. It
annotates the tokens with a newly introduced MacroContext that keeps
track of the role a token played in expanding the macro in order to
be able to reconstruct the macro expansion from an expanded (formatted)
token stream.

Made Token explicitly copy-able to enable copying tokens from the parsed
macro definition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83296

Files:
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/FormatToken.h
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Format/MacroExpander.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/MacroExpanderTest.cpp
  clang/unittests/Format/TestLexer.h

Index: clang/unittests/Format/TestLexer.h
===
--- /dev/null
+++ clang/unittests/Format/TestLexer.h
@@ -0,0 +1,88 @@
+//===--- TestLexer.h - Format C++ code --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file contains a TestLexer to create FormatTokens from strings.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_UNITTESTS_FORMAT_TEST_LEXER_H
+#define LLVM_CLANG_UNITTESTS_FORMAT_TEST_LEXER_H
+
+#include "../../lib/Format/FormatTokenLexer.h"
+
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+
+#include 
+#include 
+
+namespace clang {
+namespace format {
+
+typedef llvm::SmallVector TokenList;
+
+inline std::ostream &operator<<(std::ostream &Stream, const FormatToken &Tok) {
+  Stream << "(" << Tok.Tok.getName() << ", \"" << Tok.TokenText.str() << "\")";
+  return Stream;
+}
+inline std::ostream &operator<<(std::ostream &Stream, const TokenList &Tokens) {
+  Stream << "{";
+  for (size_t I = 0, E = Tokens.size(); I != E; ++I) {
+Stream << (I > 0 ? ", " : "") << *Tokens[I];
+  }
+  Stream << "}";
+  return Stream;
+}
+
+inline TokenList uneof(const TokenList &Tokens) {
+  assert(!Tokens.empty() && Tokens.back()->is(tok::eof));
+  return TokenList(Tokens.begin(), std::prev(Tokens.end()));
+}
+
+inline std::string text(llvm::ArrayRef Tokens) {
+  return std::accumulate(Tokens.begin(), Tokens.end(), std::string(),
+ [](const std::string &R, FormatToken *Tok) {
+   return (R + Tok->TokenText).str();
+ });
+}
+
+class TestLexer {
+public:
+  TestLexer() : SourceMgr("test.cpp", "") {}
+
+  TokenList lex(llvm::StringRef Code) {
+Buffers.push_back(
+llvm::MemoryBuffer::getMemBufferCopy(Code, ""));
+clang::FileID FID = SourceMgr.get().createFileID(SourceManager::Unowned,
+ Buffers.back().get());
+FormatTokenLexer Lex(SourceMgr.get(), FID, 0, Style, Encoding, Allocator,
+ IdentTable);
+auto Result = Lex.lex();
+return TokenList(Result.begin(), Result.end());
+  }
+
+  FormatToken *id(llvm::StringRef Code) {
+auto Result = uneof(lex(Code));
+assert(Result.size() == 1U && "Code must expand to 1 token.");
+return Result[0];
+  }
+
+  FormatStyle Style = getLLVMStyle();
+  encoding::Encoding Encoding = encoding::Encoding_UTF8;
+  std::vector> Buffers;
+  clang::SourceManagerForFile SourceMgr;
+  llvm::SpecificBumpPtrAllocator Allocator;
+  IdentifierTable IdentTable;
+};
+
+} // namespace format
+} // namespace clang
+
+#endif // LLVM_CLANG_UNITTESTS_FORMAT_TEST_LEXER_H
Index: clang/unittests/Format/MacroExpanderTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/MacroExpanderTest.cpp
@@ -0,0 +1,167 @@
+#include "../../lib/Format/MacroExpander.h"
+#include "TestLexer.h"
+#include "clang/Basic/FileManager.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+
+namespace {
+
+class MacroExpanderTest : public ::testing::Test {
+public:
+  std::unique_ptr
+  create(const std::vector &MacroDefinitions) {
+return std::make_unique(
+MacroDefinitions, Lex.SourceMgr.get(), Lex.Style, Lex.Encoding,
+Lex.Allocator, Lex.IdentTable);
+  }
+
+  std::string expand(MacroExpander &Macros, llvm::StringRef Name,
+ const std::vector &Args = {}) {
+EXPECT_TRUE(Macros.defined(Name));
+return text(Macros.expand(Lex.id(Name), lexArgs(Args)));
+  }
+
+  llvm::SmallVector
+  lexArgs(const std::vector &Args) {
+llvm::SmallVector Result;
+for (con

[PATCH] D83099: [clangd] Store index in '.cache/clangd/index' instead of '.clangd/index'

2020-07-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 5 inline comments as done.
sammccall added inline comments.



Comment at: .gitignore:57
+# clangd index. (".clangd" is a config file now, thus trailing slash)
+.clangd/
+.cache

kadircet wrote:
> why do we still need this ? i thought index (and other caches) would reside 
> in `.cache` ?
Otherwise we're going to end up with indexes from old versions of clangd 
checked in :-(



Comment at: .gitignore:58
+.clangd/
+.cache
 # static analyzer regression testing project files

hokein wrote:
> I'm afraid that many projects have to update their `.gitignore`, but this is 
> a tradeoff...
Yeah. This is a consequence of naming the config file `.clangd`, which I think 
is pretty desirable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83099



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


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-07-07 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.

Thanks, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445



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


[PATCH] D83268: [OpenMP][NFC] Remove unused (always fixed) arguments

2020-07-07 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D83268#2135081 , @Hahnfeld wrote:

> This is definitely not NFC and breaks API compatibility (but apparently 
> nobody cares anymore?).


This is the device RTL. I am not aware we (want to) keep the API stable. If we 
are, I'm not sure why:

- Dynamic linking (among other things) is not really an option so people that 
link against the device runtime (should) do so statically.
- Linking against an old device runtime with a new clang seems unreasonable to 
me. If you replace clang you must replace the static runtime as the new clang 
might use new functions.



In D83268#2135655 , @ABataev wrote:

> In D83268#2135081 , @Hahnfeld wrote:
>
> > This is definitely not NFC and breaks API compatibility (but apparently 
> > nobody cares anymore?).
>
>
> +1. Better to introduce new entry points and mark these ones as deprecated.


Same response as above. What is the use case here which we want to continue to 
support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83268



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


[PATCH] D83298: Add ability to make fixups to CompilerInvocation after option parsing

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83211 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83298

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -256,6 +256,14 @@
   return KeyPath & Value;
 }
 
+static void FixupInvocation(CompilerInvocation &Invocation) {
+  LangOptions &LangOpts = *Invocation.getLangOpts();
+  CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
+  CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
+  CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
+  CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
+}
+
 
//===--===//
 // Deserialization (from args)
 
//===--===//
@@ -1180,16 +1188,8 @@
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
 
-  Opts.XRayInstrumentFunctions =
-  Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
-  Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
-  Opts.XRayOmitFunctionIndex = Args.hasArg(OPT_fno_xray_function_index);
 
   auto XRayInstrBundles =
   Args.getAllArgValues(OPT_fxray_instrumentation_bundle);
@@ -3350,13 +3350,6 @@
   systemBlacklists.begin(),
   systemBlacklists.end());
 
-  // -fxray-instrument
-  Opts.XRayInstrument = Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
-
   // -fxray-{always,never}-instrument= filenames.
   Opts.XRayAlwaysInstrumentFiles =
   Args.getAllArgValues(OPT_fxray_always_instrument);
@@ -3710,6 +3703,7 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
+  FixupInvocation(Res);
 
   llvm::sys::Process::UseANSIEscapeCodes(
   Res.DiagnosticOpts->UseANSIEscapeCodes);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1281,7 +1281,7 @@
   Alias, AliasArgs<["full"]>,
   HelpText<"Enable cf-protection in 'full' mode">;
 
-defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit">;
+defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit", "", "", [], 
"LangOpts->XRayInstrument">;
 
 def fxray_instruction_threshold_EQ :
   JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
@@ -1309,15 +1309,15 @@
   HelpText<"List of modes to link in by default into XRay instrumented 
binaries.">;
 
 defm xray_always_emit_customevents : 
OptInFFlag<"xray-always-emit-customevents",
-  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented">;
+  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented", "", "", [], 
"LangOpts->XRayAlwaysEmitCustomEvents">;
 
 defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents",
-  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented">;
+  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitTypedEvents">;
 
 defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops",
-  "Don't instrument functions with loops unless they also meet the minimum 
function size">;
+  "Don't instrument functions with loops unless they also meet the minimum 
function size", "", "", [], "CodeGenOpts.XRayIgnoreLoops">;
 defm xray_function_index : OptOutFFlag<"xray-function-index", "",
-  "Omit function index section at the expense of single-function patching 
performance">;
+  "Omit function index section at the expense of single-function patching 
performance", "", [], "CodeGenOpts.XRayOmitFunctionIndex">;
 
 def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group,
   Flags<[CC1Option]>,


Index: clang/lib/Frontend/CompilerInvocation.cpp
=

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276007.
dang added a comment.

Make mergers use values directly instead of constant references


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -200,12 +238,11 @@
 }
 
 template 
-static T mergeForwardValue(T KeyPath, const U &Value) {
+static T mergeForwardValue(T KeyPath, U Value) {
   return Value;
 }
 
-template 
-static T mergeMaskValue(T KeyPath, const U &Value) {
+template  static T mergeMaskValue(T KeyPath, U Value) {
   return KeyPath | Value;
 }
 
@@ -782,10 +819,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3895,13 +3928,7 @@
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
   if (((FLAGS)&options::CC1Option) &&   

[PATCH] D82860: Port ObjCMTAction to new option parsing system

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276008.
dang added a comment.

Make mergers use values directly instead of constant references.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82860

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -59,70 +59,20 @@
   OS << "[" << PrefixLength << "]";
 }
 
-class MarshallingKindInfo {
+class MarshallingInfo {
 public:
+  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+
   const Record &R;
-  const char *MacroName;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
   StringRef DefaultValue;
   StringRef NormalizedValuesScope;
-
-  void emit(raw_ostream &OS) const {
-write_cstring(OS, StringRef(getOptionSpelling(R)));
-OS << ", ";
-OS << ShouldAlwaysEmit;
-OS << ", ";
-OS << KeyPath;
-OS << ", ";
-emitScopedNormalizedValue(OS, DefaultValue);
-OS << ", ";
-emitSpecific(OS);
-  }
-
-  virtual Optional emitValueTable(raw_ostream &OS) const {
-return None;
-  }
-
-  virtual ~MarshallingKindInfo() = default;
-
-  static std::unique_ptr create(const Record &R);
-
-protected:
-  void emitScopedNormalizedValue(raw_ostream &OS,
- StringRef NormalizedValue) const {
-if (!NormalizedValuesScope.empty())
-  OS << NormalizedValuesScope << "::";
-OS << NormalizedValue;
-  }
-
-  virtual void emitSpecific(raw_ostream &OS) const = 0;
-  MarshallingKindInfo(const Record &R, const char *MacroName)
-  : R(R), MacroName(MacroName) {}
-};
-
-class MarshallingFlagInfo final : public MarshallingKindInfo {
-public:
-  bool IsPositive;
-
-  void emitSpecific(raw_ostream &OS) const override { OS << IsPositive; }
-
-  static std::unique_ptr create(const Record &R) {
-std::unique_ptr Ret(new MarshallingFlagInfo(R));
-Ret->IsPositive = R.getValueAsBit("IsPositive");
-return Ret;
-  }
-
-private:
-  MarshallingFlagInfo(const Record &R)
-  : MarshallingKindInfo(R, "OPTION_WITH_MARSHALLING_FLAG") {}
-};
-
-class MarshallingStringInfo final : public MarshallingKindInfo {
-public:
   StringRef NormalizerRetTy;
   StringRef Normalizer;
   StringRef Denormalizer;
+  StringRef ValueMerger;
+  StringRef ValueExtractor;
   int TableIndex = -1;
   std::vector Values;
   std::vector NormalizedValues;
@@ -143,17 +93,29 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emitSpecific(raw_ostream &OS) const override {
+  void emit(raw_ostream &OS) const {
+write_cstring(OS, StringRef(getOptionSpelling(R)));
+OS << ", ";
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
 emitScopedNormalizedValue(OS, NormalizerRetTy);
 OS << ", ";
 OS << Normalizer;
 OS << ", ";
 OS << Denormalizer;
 OS << ", ";
+OS << ValueMerger;
+OS << ", ";
+OS << ValueExtractor;
+OS << ", ";
 OS << TableIndex;
   }
 
-  Optional emitValueTable(raw_ostream &OS) const override {
+  Optional emitValueTable(raw_ostream &OS) const {
 if (TableIndex == -1)
   return {};
 OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
@@ -169,23 +131,32 @@
 return StringRef(ValueTableName);
   }
 
-  static std::unique_ptr create(const Record &R) {
-assert(!isa(R.getValueInit("NormalizerRetTy")) &&
-   "String options must have a type");
-
-std::unique_ptr Ret(new MarshallingStringInfo(R));
-Ret->NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret->Normalizer = R.getValueAsString("Normalizer");
-Ret->Denormalizer = R.getValueAsString("Denormalizer");
+  static MarshallingInfo create(const Record &R) {
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   !isa(R.getValueInit("NormalizerRetTy")) &&
+   !isa(R.getValueInit("ValueMerger")) &&
+   "MarshallingInfo must have a type");
+
+MarshallingInfo Ret(R);
+Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
+Ret.KeyPath = R.getValueAsString("KeyPath");
+Ret.DefaultValue = R.getValueAsString("DefaultValue");
+Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
+Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
+
+Ret.Normalizer = R.getValueAsString("Normalizer");
+Ret.Denormalizer = R.getValueAsString("Denormalizer");
+Ret.ValueMerger = R.getValueAsString("ValueMerger");
+Ret.ValueExtractor = R.getValueAsString("ValueExtractor");

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276009.
dang added a comment.

Rebase on top of some changes to parent patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -781,10 +819,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3894,13 +3928,7 @@
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
   if (((FLAGS)&options::CC1Option) &&  \
   (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-if (Option::KIND##Class == Option::FlagClass) {\
-  Args.push_back(SPELLING);\
-}   

[PATCH] D83298: Add ability to make fixups to CompilerInvocation after option parsing

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276010.
dang added a comment.

Move the UseANSIEscapeCodes fixup to the correct place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83298

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -255,6 +255,17 @@
   return KeyPath & Value;
 }
 
+static void FixupInvocation(CompilerInvocation &Invocation) {
+  LangOptions &LangOpts = *Invocation.getLangOpts();
+  DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
+  CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
+  CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
+  CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
+  CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
+
+  llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
+}
+
 
//===--===//
 // Deserialization (from args)
 
//===--===//
@@ -1179,16 +1190,8 @@
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
 
-  Opts.XRayInstrumentFunctions =
-  Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
-  Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
-  Opts.XRayOmitFunctionIndex = Args.hasArg(OPT_fno_xray_function_index);
 
   auto XRayInstrBundles =
   Args.getAllArgValues(OPT_fxray_instrumentation_bundle);
@@ -3349,13 +3352,6 @@
   systemBlacklists.begin(),
   systemBlacklists.end());
 
-  // -fxray-instrument
-  Opts.XRayInstrument = Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
-
   // -fxray-{always,never}-instrument= filenames.
   Opts.XRayAlwaysInstrumentFiles =
   Args.getAllArgValues(OPT_fxray_always_instrument);
@@ -3709,9 +3705,7 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
-
-  llvm::sys::Process::UseANSIEscapeCodes(
-  Res.DiagnosticOpts->UseANSIEscapeCodes);
+  FixupInvocation(Res);
 
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1281,7 +1281,7 @@
   Alias, AliasArgs<["full"]>,
   HelpText<"Enable cf-protection in 'full' mode">;
 
-defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit">;
+defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit", "", "", [], 
"LangOpts->XRayInstrument">;
 
 def fxray_instruction_threshold_EQ :
   JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
@@ -1309,15 +1309,15 @@
   HelpText<"List of modes to link in by default into XRay instrumented 
binaries.">;
 
 defm xray_always_emit_customevents : 
OptInFFlag<"xray-always-emit-customevents",
-  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented">;
+  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented", "", "", [], 
"LangOpts->XRayAlwaysEmitCustomEvents">;
 
 defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents",
-  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented">;
+  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitTypedEvents">;
 
 defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops",
-  "Don't instrument functions with loops unless they also meet the minimum 
function size">;
+  "Don't instrument functions with loops unless they also meet the minimum 
function size", "", "", [], "CodeGenOpts.XRayIgnoreLoops">;
 defm xray_function_index : OptOutFFlag<"xray-function-index", "",
-  "Omit function index section at the expense of single-function patching 
performance">;
+  "Omit function index section at the expense of single-fu

[PATCH] D83268: [OpenMP][NFC] Remove unused (always fixed) arguments

2020-07-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D83268#2135724 , @jdoerfert wrote:

> In D83268#2135081 , @Hahnfeld wrote:
>
> > This is definitely not NFC and breaks API compatibility (but apparently 
> > nobody cares anymore?).
>
>
> This is the device RTL. I am not aware we (want to) keep the API stable. If 
> we are, I'm not sure why:
>
> - Dynamic linking (among other things) is not really an option so people that 
> link against the device runtime (should) do so statically.
> - Linking against an old device runtime with a new clang seems unreasonable 
> to me. If you replace clang you must replace the static runtime as the new 
> clang might use new functions.
>
>
>
> In D83268#2135655 , @ABataev wrote:
>
> > In D83268#2135081 , @Hahnfeld 
> > wrote:
> >
> > > This is definitely not NFC and breaks API compatibility (but apparently 
> > > nobody cares anymore?).
> >
> >
> > +1. Better to introduce new entry points and mark these ones as deprecated.
>
>
> Same response as above. What is the use case here which we want to continue 
> to support?


Use of the new library with the previous version of the compiler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83268



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


[PATCH] D81583: Update SystemZ ABI to handle C++20 [[no_unique_address]] attribute

2020-07-07 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

Another ping ...

See also http://lists.llvm.org/pipermail/cfe-dev/2020-July/066162.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81583



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


[PATCH] D83188: [clang-tidy] bugprone-bool-pointer-implicit-conversion doesn't handle members

2020-07-07 Thread Alex Cameron via Phabricator via cfe-commits
tetsuo-cpp updated this revision to Diff 276022.
tetsuo-cpp added a comment.

Address comments: Rename variables, remove unnecessary tests and avoid 
unnecessary check.


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

https://reviews.llvm.org/D83188

Files:
  clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-bool-pointer-implicit-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-bool-pointer-implicit-conversion.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-bool-pointer-implicit-conversion.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-bool-pointer-implicit-conversion.cpp
@@ -74,9 +74,31 @@
 bool *b;
   } d = { SomeFunction() };
 
-  if (d.b)
+  if (d.b) {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: dubious check of 'bool *' against 'nullptr'
+// CHECK-FIXES: if (*d.b) {
+  }
+
+  if (d.b) {
 (void)*d.b; // no-warning
+  }
 
-#define CHECK(b) if (b) {}
+#define CHECK(b) \
+  if (b) {   \
+  }
   CHECK(c)
 }
+
+struct H {
+  bool *b;
+  void foo() const {
+if (b) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: dubious check of 'bool *' against 'nullptr'
+  // CHECK-FIXES: if (*b) {
+}
+
+if (b) {
+  (void)*b; // no-warning
+}
+  }
+};
Index: clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
@@ -20,53 +20,73 @@
   Finder->addMatcher(
   traverse(
   ast_type_traits::TK_AsIs,
-  ifStmt(hasCondition(findAll(implicitCastExpr(
- unless(hasParent(unaryOperator(hasOperatorName("!",
- hasSourceExpression(expr(
- hasType(pointerType(pointee(booleanType(,
- ignoringParenImpCasts(declRefExpr().bind("expr",
- hasCastKind(CK_PointerToBoolean,
- unless(isInTemplateInstantiation()))
+  ifStmt(
+  hasCondition(findAll(implicitCastExpr(
+  unless(hasParent(unaryOperator(hasOperatorName("!",
+  hasSourceExpression(expr(
+  hasType(pointerType(pointee(booleanType(,
+  ignoringParenImpCasts(anyOf(declRefExpr().bind("expr"),
+  memberExpr().bind("expr"),
+  hasCastKind(CK_PointerToBoolean,
+  unless(isInTemplateInstantiation()))
   .bind("if")),
   this);
 }
 
-void BoolPointerImplicitConversionCheck::check(
-const MatchFinder::MatchResult &Result) {
-  auto *If = Result.Nodes.getNodeAs("if");
-  auto *Var = Result.Nodes.getNodeAs("expr");
-
+static void checkImpl(const MatchFinder::MatchResult &Result, const Expr *Ref,
+  const IfStmt *If,
+  const ast_matchers::internal::Matcher &RefMatcher,
+  ClangTidyCheck &Check) {
   // Ignore macros.
-  if (Var->getBeginLoc().isMacroID())
+  if (Ref->getBeginLoc().isMacroID())
 return;
 
-  // Only allow variable accesses for now, no function calls or member exprs.
+  // Only allow variable accesses and member exprs for now, no function calls.
   // Check that we don't dereference the variable anywhere within the if. This
   // avoids false positives for checks of the pointer for nullptr before it is
   // dereferenced. If there is a dereferencing operator on this variable don't
   // emit a diagnostic. Also ignore array subscripts.
-  const Decl *D = Var->getDecl();
-  auto DeclRef = ignoringParenImpCasts(declRefExpr(to(equalsNode(D;
-  if (!match(findAll(
- unaryOperator(hasOperatorName("*"), hasUnaryOperand(DeclRef))),
+  if (!match(findAll(unaryOperator(hasOperatorName("*"),
+   hasUnaryOperand(RefMatcher))),
  *If, *Result.Context)
.empty() ||
-  !match(findAll(arraySubscriptExpr(hasBase(DeclRef))), *If,
+  !match(findAll(arraySubscriptExpr(hasBase(RefMatcher))), *If,
  *Result.Context)
.empty() ||
   // FIXME: We should still warn if the paremater is implicitly converted to
   // bool.
-  !match(findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(DeclRef,
- *If, *Result.Context)
+  !match(
+   findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(RefMatcher,
+   *If, *Result.Context)
.empty() ||
-  !match(findAll(cxxDeleteExpr(has(ignoringParenImpCasts(expr(DeclRef),
- *If, *Result.Context)
+  !match(
+   findAll(cxxDeleteExpr(has(ignoringPar

[PATCH] D83099: [clangd] Store index in '.cache/clangd/index' instead of '.clangd/index'

2020-07-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked 2 inline comments as done.
Closed by commit rG9b55bc4d1197: [clangd] Store index in 
'.cache/clangd/index' instead of '.clangd/index' (authored 
by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D83099?vs=275645&id=276027#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83099

Files:
  .gitignore
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
  clang-tools-extra/clangd/test/background-index.test
  llvm/.gitignore


Index: llvm/.gitignore
===
--- llvm/.gitignore
+++ llvm/.gitignore
@@ -59,8 +59,6 @@
 # VS2017 and VSCode config files.
 .vscode
 .vs
-# clangd index
-.clangd
 
 
#==#
 # Files created in tree by the Go bindings.
Index: clang-tools-extra/clangd/test/background-index.test
===
--- clang-tools-extra/clangd/test/background-index.test
+++ clang-tools-extra/clangd/test/background-index.test
@@ -15,8 +15,8 @@
 # RUN: clangd -background-index -lit-test < %t/definition.jsonrpc | FileCheck 
%t/definition.jsonrpc --check-prefixes=CHECK,BUILD
 
 # Test that the index is writing files in the expected location.
-# RUN: ls %t/.clangd/index/foo.cpp.*.idx
-# RUN: ls %t/sub_dir/.clangd/index/foo.h.*.idx
+# RUN: ls %t/.cache/clangd/index/foo.cpp.*.idx
+# RUN: ls %t/sub_dir/.cache/clangd/index/foo.h.*.idx
 
 # Test the index is read from disk: delete code and restart clangd.
 # RUN: rm %t/foo.cpp
Index: clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
===
--- clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
+++ clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
@@ -95,8 +95,8 @@
 };
 
 // Creates and owns IndexStorages for multiple CDBs.
-// When a CDB root is found, shards are stored in $ROOT/.clangd/index.
-// When no root is found, the fallback path is ~/.cache/clangd/index.
+// When a CDB root is found, shards are stored in $ROOT/.cache/clangd/index/.
+// When no root is found, the fallback path is ~/.cache/clangd/index/.
 class DiskBackedIndexStorageManager {
 public:
   DiskBackedIndexStorageManager(
@@ -115,7 +115,7 @@
 llvm::SmallString<128> StorageDir(FallbackDir);
 if (auto PI = GetProjectInfo(File)) {
   StorageDir = PI->SourceRoot;
-  llvm::sys::path::append(StorageDir, ".clangd", "index");
+  llvm::sys::path::append(StorageDir, ".cache", "clangd", "index");
 }
 auto &IndexStorage = IndexStorageMap[StorageDir];
 if (!IndexStorage)
Index: clang-tools-extra/clangd/index/Background.h
===
--- clang-tools-extra/clangd/index/Background.h
+++ clang-tools-extra/clangd/index/Background.h
@@ -56,9 +56,9 @@
   using Factory = llvm::unique_function;
 
   // Creates an Index Storage that saves shards into disk. Index storage uses
-  // CDBDirectory + ".clangd/index/" as the folder to save shards. CDBDirectory
-  // is the first directory containing a CDB in parent directories of a file, 
or
-  // user's home directory if none was found, e.g. standard library headers.
+  // CDBDirectory + ".cache/clangd/index/" as the folder to save shards.
+  // CDBDirectory is the first directory containing a CDB in parent directories
+  // of a file, or user cache directory if none was found, e.g. stdlib headers.
   static Factory createDiskBackedStorageFactory(
   std::function(PathRef)> GetProjectInfo);
 };
Index: .gitignore
===
--- .gitignore
+++ .gitignore
@@ -53,10 +53,11 @@
 # VS2017 and VSCode config files.
 .vscode
 .vs
-# clangd index
-.clangd
+# clangd index. (".clangd" is a config file now, thus trailing slash)
+.clangd/
+.cache
 # static analyzer regression testing project files
 /clang/utils/analyzer/projects/*/CachedSource
 /clang/utils/analyzer/projects/*/PatchedSource
 /clang/utils/analyzer/projects/*/ScanBuildResults
-/clang/utils/analyzer/projects/*/RefScanBuildResults
\ No newline at end of file
+/clang/utils/analyzer/projects/*/RefScanBuildResults


Index: llvm/.gitignore
===
--- llvm/.gitignore
+++ llvm/.gitignore
@@ -59,8 +59,6 @@
 # VS2017 and VSCode config files.
 .vscode
 .vs
-# clangd index
-.clangd
 
 #==#
 # Files created in tree by the Go bindings.
Index: clang-tools-extra/clangd/test/background-index.test
===
--- clang-tools-extra/clangd/test/background-index.test
+++ clang-tools-extra/clangd/test/backg

[PATCH] D82938: [clangd] Implement path and URI translation for remote index

2020-07-07 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 276029.
kbobyrev added a comment.

Convert prefix paths to native slash format for _serialization_ calls
(deserializations should use UNIX slashes).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82938

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/index/remote/unimplemented/UnimplementedClient.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -7,16 +7,30 @@
 //===--===//
 
 #include "../TestTU.h"
+#include "TestFS.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
 namespace remote {
 namespace {
 
+const char *unittestURIToFilesystem(const char *UnittestURI,
+llvm::UniqueStringSaver &Strings) {
+  auto URI = URI::parse(UnittestURI);
+  EXPECT_TRUE(bool(URI));
+  const auto FileSystemURI =
+  URI::createFile(testPath(llvm::sys::path::relative_path(URI->body(;
+  return Strings.save(FileSystemURI.toString()).begin();
+}
+
 TEST(RemoteMarshallingTest, SymbolSerialization) {
   const auto *Header = R"(
   // This is a class.
@@ -39,9 +53,19 @@
   EXPECT_GE(Symbols.size(), 5UL);
   llvm::BumpPtrAllocator Arena;
   llvm::UniqueStringSaver Strings(Arena);
-  for (auto &Sym : Symbols) {
-const auto ProtobufMeessage = toProtobuf(Sym);
-const auto SymToProtobufAndBack = fromProtobuf(ProtobufMeessage, &Strings);
+  for (auto Sym : Symbols) {
+Sym.CanonicalDeclaration.FileURI =
+unittestURIToFilesystem(Sym.CanonicalDeclaration.FileURI, Strings);
+if (std::strlen(Sym.Definition.FileURI))
+  Sym.Definition.FileURI =
+  unittestURIToFilesystem(Sym.Definition.FileURI, Strings);
+for (auto &Header : Sym.IncludeHeaders)
+  Header.IncludeHeader =
+  unittestURIToFilesystem(Header.IncludeHeader.str().c_str(), Strings);
+auto ProtobufMessage =
+toProtobuf(Sym, llvm::sys::path::convert_to_slash("/"));
+const auto SymToProtobufAndBack =
+fromProtobuf(ProtobufMessage, &Strings, "/");
 EXPECT_TRUE(SymToProtobufAndBack.hasValue());
 EXPECT_EQ(toYAML(Sym), toYAML(*SymToProtobufAndBack));
   }
@@ -79,13 +103,51 @@
   // Sanity check: there are more than 5 references available.
   EXPECT_GE(References.numRefs(), 5UL);
   for (const auto &SymbolWithRefs : References) {
-for (const auto &Ref : SymbolWithRefs.second) {
-  const auto RefToProtobufAndBack = fromProtobuf(toProtobuf(Ref), &Strings);
+for (auto Ref : SymbolWithRefs.second) {
+  Ref.Location.FileURI =
+  unittestURIToFilesystem(Ref.Location.FileURI, Strings);
+  const auto RefToProtobufAndBack =
+  fromProtobuf(toProtobuf(Ref, llvm::sys::path::convert_to_slash("/")),
+   &Strings, "/");
   EXPECT_TRUE(RefToProtobufAndBack.hasValue());
   EXPECT_EQ(toYAML(Ref), toYAML(*RefToProtobufAndBack));
 }
   }
-} // namespace
+}
+
+TEST(RemoteMarshallingTest, URITranslation) {
+  llvm::BumpPtrAllocator Arena;
+  llvm::UniqueStringSaver Strings(Arena);
+  clangd::Ref Original;
+  const auto RemoteIndexPrefix = testPath("remote/machine/project/");
+  const auto RelativePath = llvm::sys::path::convert_to_slash(
+  "llvm-project/clang-tools-extra/clangd/unittests/remote/"
+  "MarshallingTests.cpp");
+  const auto URI = URI::createFile(RemoteIndexPrefix + RelativePath);
+  Original.Location.FileURI = Strings.save(URI.toString()).begin();
+  Ref Serialized = toProtobuf(Original, RemoteIndexPrefix);
+  EXPECT_EQ(Serialized.location().file_path(), RelativePath);
+  // Local index prefix should have UNIX slashes since the relative path in
+  // Protobuf message will.
+  const auto LocalIndexPrefix = llvm::sys::path::convert_to_slash(
+  testPath("local/machine/project/"), llvm::sys::path::Style::posix);
+  auto Deserialized = fromProtobuf(Serialized, &Strings, LocalIndexPrefix);
+  EXPECT_TRUE(Deserialized);
+  EXPECT_EQ(Deserialized->Location.FileURI,
+URI::createFile(LocalI

  1   2   3   >