[PATCH] D72553: [clang-tidy] Add llvm-prefer-preincrement check

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

It'll be reasonable to submit patches generated by check into trunk. May be 
after branching release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72553



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


[PATCH] D72553: [clang-tidy] Add llvm-prefer-preincrement check

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-preincrement.rst:30
+   both the prefix and postfix operator ``++`` or ``--``.
+   Default value is 1.
+

Please highlight default value with single back-ticks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72553



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


[PATCH] D72553: [clang-tidy] Add llvm-prefer-preincrement check

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, hokein.
njames93 added projects: clang, clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Adds a new clang-tidy check that detects postfix increments and decrements that 
can be swapped for their prefix counterparts. Tried to be as thorough as 
possible with detecting if the result of the operation is used by a parent. I 
ran this check over llvm and clang lib and the result would build OK.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72553

Files:
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/llvm/PreferPreincrementCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferPreincrementCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-preincrement.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement-disable-cpp-opcalls.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement.c
  clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement.cpp
@@ -0,0 +1,82 @@
+// RUN: %check_clang_tidy %s llvm-prefer-preincrement %t
+
+template 
+class Iterator {
+  T *Current;
+
+public:
+  Iterator(T *Pointer) : Current(Pointer) {}
+  T *() const { return *Current; }
+  Iterator ++() { return ++Current, *this; }
+  Iterator operator++(int) {
+Iterator Copy = *this;
+++Current;
+return Copy;
+  }
+  Iterator () { return --Current, *this; }
+  Iterator operator--(int) {
+Iterator Copy = *this;
+--Current;
+return Copy;
+  }
+};
+
+template 
+class PostfixIterator {
+  T *Current;
+
+public:
+  PostfixIterator(T *Pointer) : Current(Pointer) {}
+  T *() const { return *Current; }
+  PostfixIterator operator++(int) {
+PostfixIterator Copy = *this;
+++Current;
+return Copy;
+  }
+  PostfixIterator operator--(int) {
+PostfixIterator Copy = *this;
+--Current;
+return Copy;
+  }
+};
+
+void foo() {
+  int Array[32];
+  Iterator It([0]);
+  It++;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Use Pre-incriment instead of Post-incriment
+  // CHECK-FIXES: {{^}}  ++It;
+  It--;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Use Pre-decriment instead of Post-decriment
+  // CHECK-FIXES: {{^}}  --It;
+  (*It)++;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Use Pre-incriment instead of Post-incriment
+  // CHECK-FIXES: {{^}}  ++(*It);
+  (*It)--;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Use Pre-decriment instead of Post-decriment
+  // CHECK-FIXES: {{^}}  --(*It);
+
+  *It++;
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-incriment instead of Post-incriment
+  *It--;
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-decriment instead of Post-decriment
+
+  PostfixIterator PfIt([0]);
+  PfIt++;
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-incriment instead of Post-incriment
+  // CHECK-FIXES-NOT: {{^}}  ++PfIt;
+  PfIt--;
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-decriment instead of Post-decriment
+  // CHECK-FIXES-NOT: {{^}}  --PfIt;
+  (*PfIt)++;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Use Pre-incriment instead of Post-incriment
+  // CHECK-FIXES: {{^}}  ++(*PfIt);
+  (*PfIt)--;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Use Pre-decriment instead of Post-decriment
+  // CHECK-FIXES: {{^}}  --(*PfIt);
+
+  *PfIt++;
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-incriment instead of Post-incriment
+  *PfIt--;
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-decriment instead of Post-decriment
+}
Index: clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-preincrement.c
@@ -0,0 +1,123 @@
+// RUN: %check_clang_tidy %s llvm-prefer-preincrement %t
+
+#define INC(X) X++
+#define DEC(X) X--
+
+void foo(int A) {
+  for (int I = 0; I < 10; I++) {
+// CHECK-MESSAGES: [[@LINE-1]]:27: warning: Use Pre-incriment instead of Post-incriment
+// CHECK-FIXES: {{^}}  for (int I = 0; I < 10; ++I) {
+  }
+  for (int I = 0; I < 10; ++I) {
+// CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-incriment instead of Post-incriment
+  }
+  for (int I = 0; I < 10; A = I++) {
+// CHECK-MESSAGES-NOT: [[@LINE-1]]:{{\d*}}: warning: Use Pre-incriment instead of Post-incriment
+  }
+
+  for (int I = 10; I < 0; I--) {
+// CHECK-MESSAGES: [[@LINE-1]]:27: warning: Use Pre-decriment instead of Post-decriment
+// CHECK-FIXES: {{^}}  for (int 

[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61771 tests passed, 0 failed 
and 780 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

> what do you think about unwrapping decltype only when it's a return value 
> (optional: of a function whose leading return type is auto) to narrowly catch 
> this idiom?

I think it's worth fixing in the declarations too.

  int (int a, int b);
  
  template 
  auto call(Func &, Args &&... args)
  -> decltype(func(std::forward(args)...));
  
  template  void useRes(T &);
  
  void foo() {
// Under c++11 we don't have decltype(auto), using auto here will lose
// reference.
decltype(call(bar, 5, 6)) res = call(bar, 5, 6);
if (res) {
  // long code to process res
  useRes(res); // User wants to know the type of res here.
} else {
  // long code to process res
  useRes(res);
}
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Wei Mi via Phabricator via cfe-commits
wmi accepted this revision.
wmi added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72538



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


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

2020-01-10 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

Here is a minimal example that shows the problem:

  #include 
  
  template
  struct DoGooder
  {
  DoGooder(void* accessor, SomeValue value)
  {
  }
  
  };
  
  struct Bingus
  {
  static constexpr auto someRandomConstant = 99;
  };
  
  template
  struct HardWorker
  {
  HardWorker()
  {
  const DoGooder anInstanceOf{nullptr, Foo::someRandomConstant};
  }
  };
  
  struct TheContainer
  {
  std::unique_ptr> m_theOtherInstance;
  };

Example run:

  $ /opt/clang10/bin/clang-tidy 
-checks="-*,cppcoreguidelines-const-correctness" -header-filter=".*" 
reproconst.cpp -- -std=c++17 -Wall
  54 warnings generated.
  reproconst.cpp:22:9: warning: variable 'anInstanceOf' of type '' can be declared 'const' [cppcoreguidelines-const-correctness]
  const DoGooder anInstanceOf{nullptr, Foo::someRandomConstant};
  ^
 const
  Suppressed 53 warnings (53 in non-user code).
  Use -header-filter=.* to display errors from all non-system headers. Use 
-system-headers to display errors from system headers as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 237476.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Delete -mno-branches-within-32B-boundaries (GNU as does not support it)
Use comma joined list instead of +. CommaJoined is more conventional. For 
example, `-mrecip=` and `-fsanitize=` a comma separated list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s

Index: clang/test/Driver/x86-malign-branch.s
===
--- /dev/null
+++ clang/test/Driver/x86-malign-branch.s
@@ -0,0 +1,13 @@
+/// Test that -malign-branch* are handled for assembly files.
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY
+// BOUNDARY: "-mllvm" "-x86-align-branch-boundary=16"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused,jcc,jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE
+// TYPE: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
+// PREFIX: "-mllvm" "-x86-align-branch-prefix-size=5"
+
+// RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
+// 32B: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
Index: clang/test/Driver/x86-malign-branch.c
===
--- /dev/null
+++ clang/test/Driver/x86-malign-branch.c
@@ -0,0 +1,42 @@
+/// Test that -malign-branch* options are parsed and converted to -mllvm options.
+
+/// Test -malign-branch-boundary=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY
+// BOUNDARY: "-mllvm" "-x86-align-branch-boundary=16"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=8 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY-ERR
+// RUN: %clang -target x86_64 -malign-branch-boundary=15 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY-ERR
+// BOUNDARY-ERR: invalid argument {{.*}} to -malign-branch-boundary=
+
+/// Test -malign-branch=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused,jcc,jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE0
+// TYPE0: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused,jcc,jmp,ret,call,indirect %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE1
+// TYPE1: "-mllvm" "-x86-align-branch=fused+jcc+jmp+ret+call+indirect"
+
+// RUN: %clang -target x86_64 -malign-branch=fused,foo,bar %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE-ERR
+// TYPE-ERR: invalid argument 'foo' to -malign-branch=; each element must be one of: fused, jcc, jmp, call, ret, indirect
+// TYPE-ERR: invalid argument 'bar' to -malign-branch=; each element must be one of: fused, jcc, jmp, call, ret, indirect
+
+/// Test -malign-branch-prefix-size=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0
+// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0"
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5
+// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5"
+
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6
+// PREFIX-6: invalid argument
+
+/// Test -mbranches-within-32B-boundaries
+// RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
+// 32B: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
+/// Test that -malign-branch* can override individual values of -mbranches-within-32B-boundaries
+// RUN: %clang -target x86_64 -malign-branch=jcc -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B-TYPE
+// 32B-TYPE:  "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=jcc" "-mllvm" "-x86-align-branch-prefix-size=5"
+
+/// Unsupported on other targets.
+// RUN: %clang -target aarch64 -malign-branch=jmp %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -malign-branch-boundary=7 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target 

[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 5 inline comments as done.
MaskRay added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:254
+def err_drv_invalid_malign_branch_EQ : Error<
+  "invalid argument '%0' to -malign-branch=; must be one of: %1">;
+

skan wrote:
> skan wrote:
> > The error information "must be one of: " is kind of misleading.
> > It seems that one kind of branch can be aligned.
> The error information "must be one of: " is kind of misleading.
> It seems that "only" one kind of branch can be aligned.
Added `each element`



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2040
+if (Value.getAsInteger(10, AlignBranchBoundary) ||
+AlignBranchBoundary < 16 || !llvm::isPowerOf2_64(AlignBranchBoundary)) 
{
+  D.Diag(diag::err_drv_invalid_argument_to_option)

skan wrote:
> MaskRay wrote:
> > skan wrote:
> > > Any reason for  precluding 16?
> > I did not preclude 16.
> I am sorry that I misunderstood the word "preclude".  As far as I know, we 
> would like `AlignBranchBoundary>=32`
GNU as allows `-malign-branch-boundary=16`. I think we should allow it as well. 
It may not be optimal, but it does not hurt to give the user more choices.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72552: [Concepts] Constraint Satisfaction Caching

2020-01-10 Thread Saar Raz via Phabricator via cfe-commits
saar.raz created this revision.
saar.raz added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add a simple cache for constraint satisfaction results. This results in a
major speedup (cjdb measured x2 faster than gcc with this caching, compared
to being 'unbearably slow' without caching) and is conformant with gcc's
implementation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72552

Files:
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/AST/ASTConcept.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp

Index: clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
@@ -0,0 +1,25 @@
+// RUN:  %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+// expected-no-diagnostics
+
+template
+concept C = (f(T()), true);
+
+template
+  requires (f(T()), true)
+constexpr bool foo() requires (f(T()), true) { return true; }
+
+namespace a {
+  struct A {};
+  void f(A a);
+}
+
+static_assert(C);
+static_assert(foo());
+
+namespace a {
+  // This makes calls to f ambiguous, but the second check will still succeed
+  // because the constraint satisfaction results are cached.
+  void f(A a, int = 2);
+}
+static_assert(C);
+static_assert(foo());
\ No newline at end of file
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -269,36 +269,49 @@
   return false;
 }
 
-bool Sema::CheckConstraintSatisfaction(TemplateDecl *Template,
-   ArrayRef ConstraintExprs,
-   ArrayRef TemplateArgs,
-   SourceRange TemplateIDRange,
-   ConstraintSatisfaction ) {
-  return ::CheckConstraintSatisfaction(*this, Template, ConstraintExprs,
-   TemplateArgs, TemplateIDRange,
-   Satisfaction);
-}
+bool Sema::CheckConstraintSatisfaction(
+NamedDecl *Template, ArrayRef ConstraintExprs,
+ArrayRef TemplateArgs, SourceRange TemplateIDRange,
+ConstraintSatisfaction ) {
+  if (ConstraintExprs.empty()) {
+Satisfaction.IsSatisfied = true;
+return false;
+  }
 
-bool
-Sema::CheckConstraintSatisfaction(ClassTemplatePartialSpecializationDecl* Part,
-  ArrayRef ConstraintExprs,
-  ArrayRef TemplateArgs,
-  SourceRange TemplateIDRange,
-  ConstraintSatisfaction ) {
-  return ::CheckConstraintSatisfaction(*this, Part, ConstraintExprs,
-   TemplateArgs, TemplateIDRange,
-   Satisfaction);
-}
+  llvm::FoldingSetNodeID ID;
+  void *InsertPos;
+  ConstraintSatisfaction::Profile(ID, Context, Template, TemplateArgs);
+  ConstraintSatisfaction *Cached =
+  SatisfactionCache.FindNodeOrInsertPos(ID, InsertPos);
+  if (!Cached) {
+Cached = new ConstraintSatisfaction(Template, TemplateArgs);
+
+bool Failed;
+if (auto *T = dyn_cast(Template))
+  Failed = ::CheckConstraintSatisfaction(*this, T, ConstraintExprs,
+ TemplateArgs, TemplateIDRange,
+ *Cached);
+else if (auto *P =
+ dyn_cast(Template))
+  Failed = ::CheckConstraintSatisfaction(*this, P, ConstraintExprs,
+ TemplateArgs, TemplateIDRange,
+ *Cached);
+else
+  Failed = ::CheckConstraintSatisfaction(
+  *this, cast(Template),
+  ConstraintExprs, TemplateArgs, TemplateIDRange, *Cached);
+if (Failed) {
+  delete Cached;
+  return true;
+}
 
-bool
-Sema::CheckConstraintSatisfaction(VarTemplatePartialSpecializationDecl* Partial,
-  ArrayRef ConstraintExprs,
-  ArrayRef TemplateArgs,
-  SourceRange TemplateIDRange,
-  ConstraintSatisfaction ) {
-  return ::CheckConstraintSatisfaction(*this, Partial, ConstraintExprs,
-   TemplateArgs, TemplateIDRange,
-   Satisfaction);
+// We cannot use InsertNode here because CheckConstraintSatisfaction might
+// have invalidated it.
+SatisfactionCache.InsertNode(Cached);
+  }
+
+  Satisfaction = *Cached;
+  return false;
 }
 
 bool Sema::CheckConstraintSatisfaction(const Expr *ConstraintExpr,
Index: clang/lib/Sema/Sema.cpp

[PATCH] D72551: Warn when a string literal is used in a range-based for-loop

2020-01-10 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu created this revision.

String literals used in ranged-based for-loops will actually process the 
terminating null character as part of the loop, which may be unexpected.

  // This runs three times, once for c = 'h', then c = 'i', and finally as c = 
'\0'
  for (char c : "hi") 

This patch adds a warning to -Wrange-loop-analysis when this is used.  Two ways 
to silence the warning are proposed, by either handling the null character in 
the first statement of the loop body or by putting the string literal in 
parentheses.

  // warning
  for (char c : "hi") {}
  
  // silence by handling null character
  for (char c : "hi") {
if (c == '\0') {}
  }
  
  // silence by parentheses
  for (char c : ("hi")) {}


https://reviews.llvm.org/D72551

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/warn-range-loop-analysis.cpp

Index: clang/test/SemaCXX/warn-range-loop-analysis.cpp
===
--- clang/test/SemaCXX/warn-range-loop-analysis.cpp
+++ clang/test/SemaCXX/warn-range-loop-analysis.cpp
@@ -297,3 +297,66 @@
   for (int x : I) {}
   // No warning
 }
+
+namespace StringLiteral {
+void test1(int x) {
+  for (int c : "hello world") {}
+  // expected-warning@-1 {{range-based for-loop working over a string literal will process the trailing null character}}
+  // expected-note@-2 {{fix by explicitly handling the null character at the beginning of the loop body with an if statement}}
+  // expected-note@-3 {{place parenthesis around the string literal to silence this warning}}
+  for (char c : "hello world") {}
+  // expected-warning@-1 {{range-based for-loop working over a string literal will process the trailing null character}}
+  // expected-note@-2 {{fix by explicitly handling the null character at the beginning of the loop body with an if statement}}
+  // expected-note@-3 {{place parenthesis around the string literal to silence this warning}}
+
+  // Various methods of silencing the warning.
+  for (char c : ("hello world")) {}
+  for (char c : "hello world") { if (c > 0) {} }
+  for (char c : "hello world") { if (c == '\0') {} }
+  for (char c : "hello world") { if (c != 0) {} }
+  for (char c : "hello world") { if (c) {} }
+  for (char c : "hello world") if (c > 0) {}
+  for (char c : "hello world") if (c == '\0') {}
+  for (char c : "hello world") if (c != 0) {}
+  for (char c : "hello world") if (c) {}
+
+  // Almost silencing the warning.
+  for (char c : "hello world") { if (c >> 0) {} }
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") { if (x > 0) {} }
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") { if (x == '\0') {} }
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") { if (x != 0) {} }
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") { if (x) {} }
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") if (x > 0) {}
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") if (x == '\0') {}
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") if (x != 0) {}
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+  for (char c : "hello world") if (x) {}
+  // expected-warning@-1 {{null character}}
+  // expected-note@-2 {{if statement}}
+  // expected-note@-3 {{silence this warning}}
+}
+
+} // namespace StringLiteral
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -2851,6 +2851,102 @@
   }
 }
 
+// Diagnoses when a string literal is used as the range for a range-based
+// for-loop, because the trailing null will unexpected be handled with the
+// rest of the characters in the string.  The warning can be silenced either
+// by add parentheses around the string literal or by explicitly handling
+// the null character with an if statement at the beginning of the loop body.
+static void DiagnoseForRangeStringLiteral(Sema ,
+  const CXXForRangeStmt *ForStmt) {
+  if (SemaRef.Diags.isIgnored(diag::warn_for_range_string_literal,
+  

[PATCH] D72523: [remark][diagnostics] Using clang diagnostic handler for IR input files

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Thanks for fixing this missing -Rpass support!




Comment at: clang/lib/CodeGen/CodeGenAction.cpp:594
+  // SourceLoc.
+  if (Context == nullptr) {
+return FullSourceLoc();

Does this only happen with IR input? Does it always happen with IR input? If 
not, what happens when we have a non-null Context but IR input? It sounds like 
it should still always return an invalid Loc since there is no SourceManager? 
In that case can you set a flag on the BackendConsumer so we can bail out 
directly in the IR input case, instead of going through the motions only to get 
an invalid Loc back anyway? It would also be more clear.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:650
+  if (!Loc.isValid()) {
+MsgStream << D.getLocationStr() << ": in function "
+  << D.getFunction().getName() << ' '

Can you add a test for this one?

Also, what determines the format of the message when Loc is valid? I was trying 
to figure out where that got determined, but couldn't easily track it down. 



Comment at: clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c:8
+// RUN: llvm-lto -thinlto -o %t %t1.bo
+// RUN: %clang -cc1 -O2 -fexperimental-new-pass-manager -x ir %t1.bo 
-fthinlto-index=%t.thinlto.bc -emit-obj -Rpass-analysis=info 2>&1 | FileCheck 
%s -check-prefix=CHECK-REMARK
+// RUN: llvm-profdata merge -o %t2.profdata %S/Inputs/thinlto_expect2.proftext

In this case (since no -Wmisexpect), presumably we should not be getting the 
warning, whereas without your fix we were, correct? In that case, please add a 
NOT check to confirm that we don't get the message anymore.


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

https://reviews.llvm.org/D72523



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Jeffrey Sorensen via Phabricator via cfe-commits
sorenj updated this revision to Diff 237471.
sorenj added a comment.

- Remove double space.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsignedSubtractionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsignedSubtractionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s bugprone-unsigned-subtraction %t
+
+template 
+class vector {
+ public:
+  unsigned size();
+  bool empty();
+};
+
+#define MACRO_MINUS(x) x - 5
+#define MACRO_INT 20
+
+void signedSubtracted() {
+  unsigned x = 5;
+  int  = 2;
+  if (x -  == 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+// CHECK-FIXES: if (x - static_cast() == 0) {
+return;
+  }
+  if (0 >= x - ) {
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: signed value subtracted from
+// CHECK-FIXES: if (0 >= x - static_cast()) {
+return;
+  }
+  unsigned z = MACRO_MINUS(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: signed value subtracted from
+  z = x - MACRO_INT;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+  // CHECK-FIXES: z = x - static_cast(MACRO_INT);
+}
+
+void signedConstantSubtracted() {
+  unsigned x = 5;
+  if (x - 2 > 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+// CHECK-FIXES: if (x - 2u > 0) {
+return;
+  }
+}
+
+void casesThatShouldBeIgnored() {
+  unsigned x = 5;
+  // If the constant used in subtraction is already explicitly unsigned, do not
+  // warn. This is not safe, but the user presumably knows what they are doing.
+  if (x - 2u > 0u) {
+return;
+  }
+  if (x - 2u > 0) {
+return;
+  }
+  // sizeof operators are strictly positive for all types, and a constexpr, so
+  // any underflow would happen at compile time, so do not warn.
+  x = sizeof(long double) - 1;
+  // If both sides of the subtraction are compile time constants, don't warn.
+  if (5u - 2 > 0) {
+return;
+  }
+  constexpr long y = 4;  // NOLINT(runtime/int)
+  if (y - 4 > 0) {
+return;
+  }
+}
+
+// If the first argument of the subtraction is an expression that was previously
+// used in a comparison, the user is presumed to have done something smart.
+// This isn't perfect, but it greatly reduces false alarms.
+void contextMatters() {
+  unsigned x = 5;
+  if (x < 5) return;
+  if (x - 2 > 0u) {
+return;
+  }
+}
+
+// For loops with a compartor meet the previously described case, and therefore
+// do not warn if the variable is used in a subtraction. Again not perfect, but
+// this code is complex to reason about and it's best not to generate false
+// alarms.
+unsigned forLoops() {
+  unsigned x;
+  for (unsigned i = 1; i < 5; ++i) {
+x += i - 1;
+  }
+  return x;
+}
+
+// Testing for an empty container before subtracting from size() is considered
+// to be the same as comparing against the size - it's still possible to fail
+// but reduces the number of false positives.
+void containersEmpty() {
+  vector x;
+  if (!x.empty()) {
+if (x.size() - 1 > 0) {
+  return;
+}
+  }
+  vector y;
+  if (y.size() - 1 > 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: signed value subtracted from
+// CHECK-FIXES: if (y.size() - 1u > 0) {
+return;
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - bugprone-unsigned-subtraction
+
+bugprone-sizeof-expression
+==
+
+Finds expressions where a signed value is subtracted from an
+unsigned value, a likely cause of unexpected underflow.
+
+Many programmers are unaware that an expression of unsigned - signed
+will promote the signed argument to unsigned, and if an underflow
+occurs it results in a large positive value. Hence the frequent
+errors related to to tests of ``container.size() - 1 <= 0`` when a
+container is empty.
+
+This check suggest a fix-it change that will append a ``u`` to
+constants, thus making the implict cast explicit and signals that
+the the code was intended. In cases where the second argument is
+not a constant, a ``static_cast`` is recommended. Heuristics are
+employed to reduce warnings in contexts where the subtraction

[PATCH] D71734: [Modules] Handle tag types and complain about bad merges in C/Objective-C mode

2020-01-10 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:11007
 
+  // Issue any pending ODR-failure diagnostics.
+  for (auto  : RecordOdrMergeFailures) {

bruno wrote:
> rtrieu wrote:
> > Is this just a copy of the other loop?  That's a lot of code duplication.
> There's a lot of copy but a lot of CXXRecord specific logic got trimmed out 
> and there are small differences in the approach, so a direct refactor of it 
> won't work, but there's certainly more small pieces that can be factored out, 
> will follow up with that.
I like this refactoring much better.  Probably more refactoring could be done 
to this function since it's so long, but that's an issue for another time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst:17
+constants, thus making the implict cast explicit and signals that
+the the code was intended.  In cases where the second argument is
+not a constant, a ``static_cast`` is recommended. Heuristics are

Please fix double space.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607



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


[PATCH] D70854: [Clang] In tests, do not always assume others permissions are set

2020-01-10 Thread Alexandre Ganea 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 rGde0a22471157: Remove umask tests (authored by aganea).

Changed prior to commit:
  https://reviews.llvm.org/D70854?vs=233402=237470#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70854

Files:
  clang/test/Misc/permissions.cpp
  llvm/test/Other/umask.ll


Index: llvm/test/Other/umask.ll
===
--- llvm/test/Other/umask.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; REQUIRES: shell
-; XFAIL: windows-gnu
-
-; RUN: umask 000
-; RUN: rm -f %t.000
-; RUN: llvm-as %s -o %t.000
-; RUN: ls -l %t.000 | FileCheck --check-prefix=CHECK000 %s
-; CHECK000: rw-rw-rw
-
-; RUN: umask 002
-; RUN: rm -f %t.002
-; RUN: llvm-as %s -o %t.002
-; RUN: ls -l %t.002 | FileCheck --check-prefix=CHECK002 %s
-; CHECK002: rw-rw-r-
Index: clang/test/Misc/permissions.cpp
===
--- clang/test/Misc/permissions.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-
-// RUN: umask 000
-// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
-// RUN: ls -l %t | FileCheck --check-prefix=CHECK000 %s
-// CHECK000: rw-rw-rw-
-
-// RUN: umask 002
-// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
-// RUN: ls -l %t | FileCheck --check-prefix=CHECK002 %s
-// CHECK002: rw-rw-r--


Index: llvm/test/Other/umask.ll
===
--- llvm/test/Other/umask.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; REQUIRES: shell
-; XFAIL: windows-gnu
-
-; RUN: umask 000
-; RUN: rm -f %t.000
-; RUN: llvm-as %s -o %t.000
-; RUN: ls -l %t.000 | FileCheck --check-prefix=CHECK000 %s
-; CHECK000: rw-rw-rw
-
-; RUN: umask 002
-; RUN: rm -f %t.002
-; RUN: llvm-as %s -o %t.002
-; RUN: ls -l %t.002 | FileCheck --check-prefix=CHECK002 %s
-; CHECK002: rw-rw-r-
Index: clang/test/Misc/permissions.cpp
===
--- clang/test/Misc/permissions.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-
-// RUN: umask 000
-// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
-// RUN: ls -l %t | FileCheck --check-prefix=CHECK000 %s
-// CHECK000: rw-rw-rw-
-
-// RUN: umask 002
-// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
-// RUN: ls -l %t | FileCheck --check-prefix=CHECK002 %s
-// CHECK002: rw-rw-r--
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] de0a224 - Remove umask tests

2020-01-10 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-01-10T21:05:59-05:00
New Revision: de0a2247115729eade8249267a47f96f070a7666

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

LOG: Remove umask tests

These tests were added in 18627115f4d2db5dc73207e0b5312f52536be7dd and 
e08b59f81d950bd5c8b8528fcb3ac4230c7b736c for validating a refactoring.
Removing because they break on ACL-controlled folders on Ubuntu, and their 
added value is low.

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

Added: 


Modified: 


Removed: 
clang/test/Misc/permissions.cpp
llvm/test/Other/umask.ll



diff  --git a/clang/test/Misc/permissions.cpp b/clang/test/Misc/permissions.cpp
deleted file mode 100644
index 83f6c5720809..
--- a/clang/test/Misc/permissions.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-
-// RUN: umask 000
-// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
-// RUN: ls -l %t | FileCheck --check-prefix=CHECK000 %s
-// CHECK000: rw-rw-rw-
-
-// RUN: umask 002
-// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
-// RUN: ls -l %t | FileCheck --check-prefix=CHECK002 %s
-// CHECK002: rw-rw-r--

diff  --git a/llvm/test/Other/umask.ll b/llvm/test/Other/umask.ll
deleted file mode 100644
index 413458006a5a..
--- a/llvm/test/Other/umask.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; REQUIRES: shell
-; XFAIL: windows-gnu
-
-; RUN: umask 000
-; RUN: rm -f %t.000
-; RUN: llvm-as %s -o %t.000
-; RUN: ls -l %t.000 | FileCheck --check-prefix=CHECK000 %s
-; CHECK000: rw-rw-rw
-
-; RUN: umask 002
-; RUN: rm -f %t.002
-; RUN: llvm-as %s -o %t.002
-; RUN: ls -l %t.002 | FileCheck --check-prefix=CHECK002 %s
-; CHECK002: rw-rw-r-



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Jeffrey Sorensen via Phabricator via cfe-commits
sorenj updated this revision to Diff 237466.
sorenj added a comment.

- Address documentation comments.
- Address documentation comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsignedSubtractionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsignedSubtractionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s bugprone-unsigned-subtraction %t
+
+template 
+class vector {
+ public:
+  unsigned size();
+  bool empty();
+};
+
+#define MACRO_MINUS(x) x - 5
+#define MACRO_INT 20
+
+void signedSubtracted() {
+  unsigned x = 5;
+  int  = 2;
+  if (x -  == 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+// CHECK-FIXES: if (x - static_cast() == 0) {
+return;
+  }
+  if (0 >= x - ) {
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: signed value subtracted from
+// CHECK-FIXES: if (0 >= x - static_cast()) {
+return;
+  }
+  unsigned z = MACRO_MINUS(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: signed value subtracted from
+  z = x - MACRO_INT;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+  // CHECK-FIXES: z = x - static_cast(MACRO_INT);
+}
+
+void signedConstantSubtracted() {
+  unsigned x = 5;
+  if (x - 2 > 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+// CHECK-FIXES: if (x - 2u > 0) {
+return;
+  }
+}
+
+void casesThatShouldBeIgnored() {
+  unsigned x = 5;
+  // If the constant used in subtraction is already explicitly unsigned, do not
+  // warn. This is not safe, but the user presumably knows what they are doing.
+  if (x - 2u > 0u) {
+return;
+  }
+  if (x - 2u > 0) {
+return;
+  }
+  // sizeof operators are strictly positive for all types, and a constexpr, so
+  // any underflow would happen at compile time, so do not warn.
+  x = sizeof(long double) - 1;
+  // If both sides of the subtraction are compile time constants, don't warn.
+  if (5u - 2 > 0) {
+return;
+  }
+  constexpr long y = 4;  // NOLINT(runtime/int)
+  if (y - 4 > 0) {
+return;
+  }
+}
+
+// If the first argument of the subtraction is an expression that was previously
+// used in a comparison, the user is presumed to have done something smart.
+// This isn't perfect, but it greatly reduces false alarms.
+void contextMatters() {
+  unsigned x = 5;
+  if (x < 5) return;
+  if (x - 2 > 0u) {
+return;
+  }
+}
+
+// For loops with a compartor meet the previously described case, and therefore
+// do not warn if the variable is used in a subtraction. Again not perfect, but
+// this code is complex to reason about and it's best not to generate false
+// alarms.
+unsigned forLoops() {
+  unsigned x;
+  for (unsigned i = 1; i < 5; ++i) {
+x += i - 1;
+  }
+  return x;
+}
+
+// Testing for an empty container before subtracting from size() is considered
+// to be the same as comparing against the size - it's still possible to fail
+// but reduces the number of false positives.
+void containersEmpty() {
+  vector x;
+  if (!x.empty()) {
+if (x.size() - 1 > 0) {
+  return;
+}
+  }
+  vector y;
+  if (y.size() - 1 > 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: signed value subtracted from
+// CHECK-FIXES: if (y.size() - 1u > 0) {
+return;
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - bugprone-unsigned-subtraction
+
+bugprone-sizeof-expression
+==
+
+Finds expressions where a signed value is subtracted from an
+unsigned value, a likely cause of unexpected underflow.
+
+Many programmers are unaware that an expression of unsigned - signed
+will promote the signed argument to unsigned, and if an underflow
+occurs it results in a large positive value. Hence the frequent
+errors related to to tests of ``container.size() - 1 <= 0`` when a
+container is empty.
+
+This check suggest a fix-it change that will append a ``u`` to
+constants, thus making the implict cast explicit and signals that
+the the code was intended.  In cases where the second argument is
+not a constant, a ``static_cast`` is recommended. Heuristics are
+employed to 

[PATCH] D69825: [Clang][Driver] Re-use the calling process instead of creating a new process for the cc1 invocation

2020-01-10 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea updated this revision to Diff 237465.
aganea marked 2 inline comments as done.

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

https://reviews.llvm.org/D69825

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fsanitize-blacklist.c
  clang/test/Driver/unknown-arg.c
  clang/test/Driver/warning-options_pedantic.cpp
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -14,6 +14,7 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/Stack.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -30,6 +31,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
@@ -239,6 +241,8 @@
   *NumberSignPtr = '=';
 }
 
+static int ExecuteCC1Tool(ArrayRef argv);
+
 static void SetBackdoorDriverOutputsFromEnvVars(Driver ) {
   // Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
   TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
@@ -254,6 +258,28 @@
   TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
   if (TheDriver.CCLogDiagnostics)
 TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
+
+  // Whether the cc1 tool should be called inside the current process, or if we
+  // should spawn a new clang process (old behavior).
+  // Not having an additional process saves some execution time of Windows,
+  // and makes debugging easier.
+  bool UseNewCC1Process = CLANG_SPAWN_CC1;
+
+  StringRef SpawnCC1Str = ::getenv("CLANG_SPAWN_CC1");
+  if (!SpawnCC1Str.empty()) {
+unsigned long long Enable;
+if (getAsUnsignedInteger(SpawnCC1Str, 10, Enable) || Enable > 1) {
+  llvm::errs() << "error: the value of the environment variable "
+  "CLANG_SPAWN_CC1 must be either 0 or 1.\n";
+  ::exit(1);
+}
+UseNewCC1Process = Enable;
+  }
+  if (!UseNewCC1Process) {
+TheDriver.CC1Main = 
+// Ensure the CC1Command actually catches cc1 crashes
+llvm::CrashRecoveryContext::Enable();
+  }
 }
 
 static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
@@ -303,13 +329,19 @@
 TheDriver.setInstalledDir(InstalledPathParent);
 }
 
-static int ExecuteCC1Tool(ArrayRef argv, StringRef Tool) {
+static int ExecuteCC1Tool(ArrayRef argv) {
+  // If we call the cc1 tool from the clangDriver library (through
+  // Driver::CC1Main), we need to cleanup the options usage count. The options
+  // are currently global, and they might have been used previously by the
+  // driver.
+  llvm::cl::ResetAllOptionOccurrences();
+  StringRef Tool = argv[1];
   void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
-  if (Tool == "")
+  if (Tool == "-cc1")
 return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
-  if (Tool == "as")
+  if (Tool == "-cc1as")
 return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
-  if (Tool == "gen-reproducer")
+  if (Tool == "-cc1gen-reproducer")
 return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP);
 
   // Reject unknown tools.
@@ -379,7 +411,7 @@
   auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
   argv.resize(newEnd - argv.begin());
 }
-return ExecuteCC1Tool(argv, argv[1] + 4);
+return ExecuteCC1Tool(argv);
   }
 
   bool CanonicalPrefixes = true;
@@ -503,7 +535,7 @@
 
 #ifdef _WIN32
   // Exit status should not be negative on Win32, unless abnormal termination.
-  // Once abnormal termiation was caught, negative status should not be
+  // Once abnormal termination was caught, negative status should not be
   // propagated.
   if (Res < 0)
 Res = 1;
Index: clang/test/Driver/warning-options_pedantic.cpp
===
--- clang/test/Driver/warning-options_pedantic.cpp
+++ clang/test/Driver/warning-options_pedantic.cpp
@@ -1,6 +1,6 @@
 // Make sure we don't match the -NOT lines with the linker invocation.
 // Delimiters match the start of the cc1 and the start of the linker lines
-// DELIMITERS: {{^ *"}}
+// DELIMITERS: {{^ (\(in-process\)|")}}
 
 // RUN: %clang -### -pedantic -no-pedantic %s 2>&1 | FileCheck -check-prefix=NO_PEDANTIC -check-prefix=DELIMITERS %s
 // RUN: %clang -### -pedantic -Wno-pedantic %s 2>&1 | FileCheck -check-prefix=PEDANTIC -check-prefix=DELIMITERS %s
Index: 

[PATCH] D69825: [Clang][Driver] Re-use the calling process instead of creating a new process for the cc1 invocation

2020-01-10 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added inline comments.



Comment at: clang/tools/driver/driver.cpp:267
+
+  StringRef SpawnCC1Str = ::getenv("CLANG_SPAWN_CC1");
+  if (!SpawnCC1Str.empty()) {

hans wrote:
> aganea wrote:
> > hans wrote:
> > > Maybe just do the "!!" thing like for the environment variables above? 
> > > It's not pretty, but at least that would be consistent, and it avoids the 
> > > problem of deciding what values mean "on" and what mean "off".
> > Not if we want to negate the `CLANG_SPAWN_CC1` compile-time flag 
> > initialized just above. `!!::getenv` will only say the option is there, it 
> > won't say what we should do. My rationale was, if the env variable is 
> > there, its value overrides the compile-time flag. Unless we want something 
> > along the lines of `CLANG_ENABLE_SPAWN_CC1` / `CLANG_DISABLE_SPAWN_CC1`?
> Ah, I didn't think about that.
> 
> This feels a bit fragile though, for example if the user sets it to "yes" 
> instead of "on", it won't be obvious that it has the opposite effect. What do 
> you think about only supporting 1 and 0, and printing a helpful error for 
> other values?
> 
> Also, the comparisons could be done with equals(_lower) instead of the 
> compare methods.
As requested.


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

https://reviews.llvm.org/D69825



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


[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I just have a few high level comments from looking through it just now. The 
summary needs a fix since Os/Oz are in fact O2 
 so OptLevel > 1 was not doing the 
wrong thing.




Comment at: llvm/include/llvm/Passes/PassBuilder.h:224
+
+bool isOptimizingForSpeed() const { return Level > 0 && Level < 4; }
+bool isOptimizingForSize() const { return Level == 4 || Level == 5; }

Can you add a comment as to why Os and Oz are considered as optimizing for 
speed? I know this is for compatibility with the current code, but would be 
good to document (and consider changing in the future).



Comment at: llvm/include/llvm/Passes/PassBuilder.h:225
+bool isOptimizingForSpeed() const { return Level > 0 && Level < 4; }
+bool isOptimizingForSize() const { return Level == 4 || Level == 5; }
+bool isO2Or3() const { return Level == 2 || Level == 3; }

This one is a little confusing to read, since at this point there is no 
correlation between the values 4 and 5, and the Os and Oz static variables. 
Consider making some constexpr values for each level, used in the methods here 
and in the static variable initializations?



Comment at: llvm/include/llvm/Passes/PassBuilder.h:226
+bool isOptimizingForSize() const { return Level == 4 || Level == 5; }
+bool isO2Or3() const { return Level == 2 || Level == 3; }
+bool operator==(const OptimizationLevel ) const {

Since (as discussed off-patch), in the old PM Os and Oz are also opt level 2, 
this should presumably return true for those as well. That should obviate the 
need for many places in the patch where you are currently checking isO2Or3 || 
isOptimizingForSize, and you can just check isO2Or3.



Comment at: llvm/include/llvm/Passes/PassBuilder.h:274
+  /// This is an interface that can be used to populate a \c
+  /// CGSCCAnalysisManager with all registered CGSCC analyses. Callers can 
still
+  /// manually register any additional analyses. Callers can also pre-register

There are a lot of formatting changes throughout the patch that are unrelated 
to your changes - it seems like you might have clang formatted the whole files? 
Can you only include the changes related to the patch here, it's harder to 
review with lots of spurious diffs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72547



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


[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-10 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin updated this revision to Diff 237464.
mtrofin added a comment.

Speedup level is actually '2' for Os and Oz


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72547

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -192,10 +192,9 @@
cl::Hidden, cl::ZeroOrMore,
cl::desc("Run Partial inlinining pass"));
 
-static cl::opt
-RunNewGVN("enable-npm-newgvn", cl::init(false),
-  cl::Hidden, cl::ZeroOrMore,
-  cl::desc("Run NewGVN instead of GVN"));
+static cl::opt RunNewGVN("enable-npm-newgvn", cl::init(false), cl::Hidden,
+   cl::ZeroOrMore,
+   cl::desc("Run NewGVN instead of GVN"));
 
 static cl::opt EnableGVNHoist(
 "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
@@ -238,20 +237,12 @@
 
 extern cl::opt FlattenedProfileUsed;
 
-static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
-  switch (Level) {
-  case PassBuilder::O0:
-  case PassBuilder::O1:
-  case PassBuilder::O2:
-  case PassBuilder::O3:
-return false;
-
-  case PassBuilder::Os:
-  case PassBuilder::Oz:
-return true;
-  }
-  llvm_unreachable("Invalid optimization level!");
-}
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O0 = {0};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O1 = {1};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O2 = {2};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O3 = {3};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Os = {4};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Oz = {5};
 
 namespace {
 
@@ -386,11 +377,9 @@
 C(LAM);
 }
 
-FunctionPassManager
-PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
- ThinLTOPhase Phase,
- bool DebugLogging) {
-  assert(Level != O0 && "Must request optimizations!");
+FunctionPassManager PassBuilder::buildFunctionSimplificationPipeline(
+OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging) {
+  assert(Level != OptimizationLevel::O0 && "Must request optimizations!");
   FunctionPassManager FPM(DebugLogging);
 
   // Form SSA out of local memory accesses after breaking apart aggregates into
@@ -401,7 +390,7 @@
   FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
 
   // Hoisting of scalars and load expressions.
-  if (Level > O1) {
+  if (Level.isO2Or3() || Level.isOptimizingForSize()) {
 if (EnableGVNHoist)
   FPM.addPass(GVNHoistPass());
 
@@ -413,31 +402,31 @@
   }
 
   // Speculative execution if the target has divergent branches; otherwise nop.
-  if (Level > O1) {
+  if (Level.isO2Or3() || Level.isOptimizingForSize()) {
 FPM.addPass(SpeculativeExecutionPass());
 
-// Optimize based on known information about branches, and cleanup afterward.
+// Optimize based on known information about branches, and cleanup
+// afterward.
 FPM.addPass(JumpThreadingPass());
 FPM.addPass(CorrelatedValuePropagationPass());
   }
   FPM.addPass(SimplifyCFGPass());
-  if (Level == O3)
+  if (Level == OptimizationLevel::O3)
 FPM.addPass(AggressiveInstCombinePass());
   FPM.addPass(InstCombinePass());
 
-  if (!isOptimizingForSize(Level))
+  if (!Level.isOptimizingForSize())
 FPM.addPass(LibCallsShrinkWrapPass());
 
   invokePeepholeEPCallbacks(FPM, Level);
 
   // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
   // using the size value profile. Don't perform this when optimizing for size.
-  if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse &&
-  !isOptimizingForSize(Level) && Level > O1)
+  if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse && Level.isO2Or3())
 FPM.addPass(PGOMemOPSizeOpt());
 
   // TODO: Investigate the cost/benefit of tail call elimination on debugging.
-  if (Level > O1)
+  if (Level.isO2Or3() || Level.isOptimizingForSize())
 FPM.addPass(TailCallElimPass());
   FPM.addPass(SimplifyCFGPass());
 
@@ -464,7 +453,7 @@
   LPM1.addPass(LoopSimplifyCFGPass());
 
   // Rotate Loop - disable header duplication at -Oz
-  LPM1.addPass(LoopRotatePass(Level != Oz));
+  LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
   // TODO: Investigate promotion cap for O1.
   LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
   LPM1.addPass(SimpleLoopUnswitchPass());
@@ -481,7 +470,8 @@
   if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
PGOOpt->Action != PGOOptions::SampleUse) 

[clang] 9b23407 - [Concepts] Fix MarkUsedTemplateParameters for exprs

2020-01-10 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-11T03:16:57+02:00
New Revision: 9b23407063ca41901e9e272bacf8b33eee8251c4

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

LOG: [Concepts] Fix MarkUsedTemplateParameters for exprs

D41910 introduced a recursive visitor to MarkUsedTemplateParameters, but
disregarded the 'Depth' parameter, and had incorrect assertions. This fixes
the visitor and removes the assertions.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index d267ae8572e4..e626948cb5d4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5384,46 +5384,40 @@ bool 
Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
   return isAtLeastAsSpecializedAs(*this, PType, AType, AArg, Info);
 }
 
-struct OccurringTemplateParameterFinder :
-RecursiveASTVisitor {
-  llvm::SmallBitVector 
+namespace {
+struct MarkUsedTemplateParameterVisitor :
+RecursiveASTVisitor {
+  llvm::SmallBitVector 
+  unsigned Depth;
 
-  OccurringTemplateParameterFinder(llvm::SmallBitVector )
-  : OccurringIndices(OccurringIndices) { }
+  MarkUsedTemplateParameterVisitor(llvm::SmallBitVector ,
+   unsigned Depth)
+  : Used(Used), Depth(Depth) { }
 
   bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
-assert(T->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
-noteParameter(T->getIndex());
+if (T->getDepth() == Depth)
+  Used[T->getIndex()] = true;
 return true;
   }
 
   bool TraverseTemplateName(TemplateName Template) {
 if (auto *TTP =
-dyn_cast(Template.getAsTemplateDecl())) {
-  assert(TTP->getDepth() == 0 && "This assumes that we allow concepts at "
- "namespace scope only");
-  noteParameter(TTP->getIndex());
-}
-RecursiveASTVisitor::
+dyn_cast(Template.getAsTemplateDecl()))
+  if (TTP->getDepth() == Depth)
+Used[TTP->getIndex()] = true;
+RecursiveASTVisitor::
 TraverseTemplateName(Template);
 return true;
   }
 
   bool VisitDeclRefExpr(DeclRefExpr *E) {
-if (auto *NTTP = dyn_cast(E->getDecl())) {
-  assert(NTTP->getDepth() == 0 && "This assumes that we allow concepts at "
-  "namespace scope only");
-  noteParameter(NTTP->getIndex());
-}
+if (auto *NTTP = dyn_cast(E->getDecl()))
+  if (NTTP->getDepth() == Depth)
+Used[NTTP->getIndex()] = true;
 return true;
   }
-
-protected:
-  void noteParameter(unsigned Index) {
-OccurringIndices.set(Index);
-  }
 };
+}
 
 /// Mark the template parameters that are used by the given
 /// expression.
@@ -5434,7 +5428,8 @@ MarkUsedTemplateParameters(ASTContext ,
unsigned Depth,
llvm::SmallBitVector ) {
   if (!OnlyDeduced) {
-OccurringTemplateParameterFinder(Used).TraverseStmt(const_cast(E));
+MarkUsedTemplateParameterVisitor(Used, Depth)
+.TraverseStmt(const_cast(E));
 return;
   }
 



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


[PATCH] D72467: [WIP] Remove "mask" operand from shufflevector.

2020-01-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma updated this revision to Diff 237463.
efriedma added a comment.

Figured out the changes necessary to get bitcode reading/writing working.  
ninja check now passes.

Not sure what parts I should split off to get reviewed separately.  Probably 
the GlobalISel changes could be split off without adding too much complexity; 
not sure what else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72467

Files:
  clang/lib/CodeGen/CGExpr.cpp
  llvm/include/llvm/ADT/ArrayRef.h
  llvm/include/llvm/Analysis/ConstantFolding.h
  llvm/include/llvm/Analysis/InstructionSimplify.h
  llvm/include/llvm/Analysis/TargetFolder.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/CodeGen/MachineInstrBuilder.h
  llvm/include/llvm/CodeGen/MachineOperand.h
  llvm/include/llvm/IR/ConstantFolder.h
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Instructions.h
  llvm/include/llvm/IR/NoFolder.h
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
  llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
  llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
  llvm/lib/CodeGen/MIRParser/MIParser.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/MachineVerifier.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/ConstantFold.cpp
  llvm/lib/IR/ConstantFold.h
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/ConstantsContext.h
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
  llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
  llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/MVETailPredication.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/lib/Transforms/Scalar/GVNSink.cpp
  llvm/lib/Transforms/Scalar/NewGVN.cpp
  llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-shuffle-vector.mir
  llvm/unittests/IR/PatternMatch.cpp

Index: llvm/unittests/IR/PatternMatch.cpp
===
--- llvm/unittests/IR/PatternMatch.cpp
+++ llvm/unittests/IR/PatternMatch.cpp
@@ -991,31 +991,31 @@
   EXPECT_TRUE(match(EX3, m_ExtractElement(m_Constant(), m_ConstantInt(;
 
   // Test matching shufflevector
-  EXPECT_TRUE(match(SI1, m_ShuffleVector(m_Value(), m_Undef(), m_Zero(;
-  EXPECT_TRUE(match(SI2, m_ShuffleVector(m_Value(A), m_Value(B), m_Value(C;
+  ArrayRef Mask;
+  EXPECT_TRUE(match(SI1, m_ShuffleVector(m_Value(), m_Undef(), m_ZeroMask(;
+  EXPECT_TRUE(match(SI2, m_ShuffleVector(m_Value(A), m_Value(B), m_Mask(Mask;
   EXPECT_TRUE(A == VI3);
   EXPECT_TRUE(B == VI4);
-  EXPECT_TRUE(C == IdxVec);
   A = B = C = nullptr; // reset
 
   // Test matching the vector splat pattern
   EXPECT_TRUE(match(
   SI1,
   m_ShuffleVector(m_InsertElement(m_Undef(), m_SpecificInt(1), m_Zero()),
-  m_Undef(), m_Zero(;
+  m_Undef(), m_ZeroMask(;
   EXPECT_FALSE(match(
   SI3, m_ShuffleVector(m_InsertElement(m_Undef(), m_Value(), m_Zero()),
-   m_Undef(), m_Zero(;
+   m_Undef(), m_ZeroMask(;
   EXPECT_FALSE(match(
   SI4, m_ShuffleVector(m_InsertElement(m_Undef(), m_Value(), m_Zero()),
-   m_Undef(), m_Zero(;
+   m_Undef(), m_ZeroMask(;
   EXPECT_TRUE(match(
   SP1,
   m_ShuffleVector(m_InsertElement(m_Undef(), m_SpecificInt(2), m_Zero()),
-  m_Undef(), m_Zero(;
+  m_Undef(), m_ZeroMask(;
   EXPECT_TRUE(match(
   SP2, m_ShuffleVector(m_InsertElement(m_Undef(), m_Value(A), m_Zero()),
-   m_Undef(), m_Zero(;
+   m_Undef(), m_ZeroMask(;
   

[clang] 1d2cd2c - [Driver] Fix OptionClass of -fconvergent-functions and -fms-volatile (Joined -> Flag)

2020-01-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-01-10T17:06:40-08:00
New Revision: 1d2cd2c0b7d978e22a50e918af708ba67e87c2c1

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

LOG: [Driver] Fix OptionClass of -fconvergent-functions and -fms-volatile 
(Joined -> Flag)

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index caeed3d7b8ed..0fee90707d40 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -546,7 +546,7 @@ def cxx_isystem : JoinedOrSeparate<["-"], "cxx-isystem">, 
Group,
   MetaVarName<"">;
 def c : Flag<["-"], "c">, Flags<[DriverOption]>, Group,
   HelpText<"Only run preprocess, compile, and assemble steps">;
-def fconvergent_functions : Joined<["-"], "fconvergent-functions">, 
Group, Flags<[CC1Option]>,
+def fconvergent_functions : Flag<["-"], "fconvergent-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Assume functions may be convergent">;
 
 def cuda_device_only : Flag<["--"], "cuda-device-only">,
@@ -1344,7 +1344,7 @@ def fms_extensions : Flag<["-"], "fms-extensions">, 
Group, Flags<[CC1Op
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">;
 def fms_compatibility : Flag<["-"], "fms-compatibility">, Group, 
Flags<[CC1Option, CoreOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">;
-def fms_volatile : Joined<["-"], "fms-volatile">, Group, 
Flags<[CC1Option]>;
+def fms_volatile : Flag<["-"], "fms-volatile">, Group, 
Flags<[CC1Option]>;
 def fmsc_version : Joined<["-"], "fmsc-version=">, Group, 
Flags<[DriverOption, CoreOption]>,
   HelpText<"Microsoft compiler version number to report in _MSC_VER (0 = don't 
define it (default))">;
 def fms_compatibility_version



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


[PATCH] D72467: [WIP] Remove "mask" operand from shufflevector.

2020-01-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma marked an inline comment as done.
efriedma added inline comments.



Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4413
 unsigned MaxRecurse) {
-  if (isa(Mask))
+  if (all_of(Mask, [](int Elem) { return Elem == -1; }))
 return UndefValue::get(RetTy);

xbolva00 wrote:
> maybe introduce new helper function to check if mask is "undef"?
I could introduce ShuffleVectorInst::MaskIsAllUndef and 
ShuffleVectorInst::MaskIsAllZero, I guess.  Not sure how helpful that actually 
is for a predicate that can be expressed on one line anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72467



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


Buildbot numbers for the last week of 12/29/2019 - 01/04/2020

2020-01-10 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the last week of 12/29/2019 -
01/04/2020.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
   buildername|  was_red
--+--
 llvm-clang-win-x-aarch64 | 105:37:31
 lldb-x64-windows-ninja   | 85:27:56
 clang-native-arm-lnt-perf| 26:02:57
 clang-x64-windows-msvc   | 18:04:43
 clang-cmake-thumbv7-full-sh  | 11:50:00
 sanitizer-x86_64-linux-bootstrap | 08:32:06
 sanitizer-x86_64-linux-fast  | 08:12:52
 llvm-clang-win-x-armv7l  | 06:21:53
 clang-with-thin-lto-ubuntu   | 05:59:17
 clang-cmake-armv7-lnt| 05:50:26
 clang-with-lto-ubuntu| 05:47:24
 llvm-clang-x86_64-expensive-checks-win   | 05:23:58
 lld-x86_64-win7  | 05:19:54
 clang-ppc64le-linux-multistage   | 05:10:15
 clang-cmake-armv7-global-isel| 05:02:19
 sanitizer-x86_64-linux   | 04:43:27
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast | 04:25:41
 sanitizer-ppc64le-linux  | 04:21:57
 sanitizer-ppc64be-linux  | 04:00:34
 openmp-clang-x86_64-linux-debian | 03:45:17
 clang-cmake-armv7-quick  | 03:35:16
 sanitizer-x86_64-linux-bootstrap-ubsan   | 03:24:22
 clang-cmake-armv8-lld| 03:21:51
 clang-s390x-linux-multistage | 03:05:57
 clang-ppc64be-linux  | 03:00:10
 clang-x86_64-debian-new-pass-manager-fast| 03:00:03
 clang-x86_64-debian-fast | 02:59:59
 llvm-clang-x86_64-expensive-checks-debian| 02:59:58
 clang-ppc64le-linux  | 02:54:31
 clang-s390x-linux| 02:52:49
 ppc64le-lld-multistage-test  | 02:50:35
 sanitizer-x86_64-linux-bootstrap-msan| 02:47:56
 lld-x86_64-darwin13  | 02:45:24
 clang-ppc64le-linux-lnt  | 02:40:30
 clang-ppc64le-rhel   | 02:39:46
 clang-s390x-linux-lnt| 02:38:02
 clang-ppc64be-linux-lnt  | 02:36:40
 clang-ppc64be-linux-multistage   | 02:30:27
 sanitizer-x86_64-linux-android   | 01:37:15
 clang-cmake-x86_64-sde-avx512-linux  | 01:33:06
 clang-cmake-x86_64-avx2-linux| 01:25:53
 sanitizer-x86_64-linux-fuzzer| 01:13:39
 lld-x86_64-ubuntu-fast   | 00:53:47
 llvm-clang-x86_64-expensive-checks-ubuntu| 00:46:45
 clang-x86_64-linux-abi-test  | 00:45:17
 openmp-gcc-x86_64-linux-debian   | 00:44:03
 sanitizer-x86_64-linux-autoconf  | 00:43:40
 clang-atom-d525-fedora-rel   | 00:41:15
 clang-aarch64-linux-build-cache  | 00:40:32
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast   | 00:40:04
 llvm-clang-x86_64-win-fast   | 00:36:25
 sanitizer-windows| 00:33:31
 lldb-x86_64-debian   | 00:32:37
 llvm-sphinx-docs | 00:31:09
 lldb-sphinx-docs | 00:30:08
 lld-sphinx-docs  | 00:29:10
 libcxx-sphinx-docs   | 00:28:34
 libunwind-sphinx-docs| 00:27:56
 clang-tools-sphinx-docs  | 00:27:11
 clang-armv7-linux-build-cache| 00:19:14
(60 rows)


"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green):
   buildername| builds | changes |
status_change_ratio
--++-+
 sanitizer-x86_64-linux   | 71 |  22 |
   31.0
 clang-with-thin-lto-ubuntu   | 59 |  14 |
   23.7
 ppc64le-lld-multistage-test  | 56 |  10 |
   

Buildbot numbers for the week of 12/15/2019 - 12/21/2019

2020-01-10 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 12/15/2019 - 12/21/2019.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
   buildername| was_red
--+-
 clang-cmake-armv7-full   | 56:01:18
 clang-cmake-thumbv7-full-sh  | 34:52:37
 clang-cmake-armv7-global-isel| 31:55:44
 llvm-clang-win-x-armv7l  | 30:08:24
 clang-cmake-armv7-quick  | 30:01:13
 clang-cmake-armv8-lld| 29:58:16
 clang-cmake-aarch64-global-isel  | 22:10:32
 clang-cmake-aarch64-quick| 21:22:47
 clang-with-lto-ubuntu| 17:24:57
 sanitizer-x86_64-linux-bootstrap-msan| 17:11:28
 sanitizer-x86_64-linux-bootstrap-ubsan   | 16:43:30
 clang-with-thin-lto-ubuntu   | 16:09:51
 sanitizer-x86_64-linux-fast  | 16:01:34
 clang-s390x-linux-multistage | 15:47:17
 clang-s390x-linux| 15:27:33
 llvm-clang-x86_64-expensive-checks-win   | 15:10:11
 llvm-clang-x86_64-expensive-checks-ubuntu| 14:36:07
 clang-ppc64be-linux-lnt  | 14:33:05
 clang-s390x-linux-lnt| 14:30:33
 llvm-clang-x86_64-expensive-checks-debian| 14:18:49
 clang-ppc64be-linux  | 14:05:49
 clang-ppc64be-linux-multistage   | 13:54:53
 lld-x86_64-win7  | 13:54:00
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast | 13:48:01
 llvm-clang-win-x-aarch64 | 12:36:25
 clang-x64-windows-msvc   | 11:49:35
 clang-ppc64le-linux-multistage   | 11:35:19
 clang-ppc64le-linux-lnt  | 11:10:51
 clang-atom-d525-fedora-rel   | 11:01:34
 clang-x86_64-debian-new-pass-manager-fast| 10:56:18
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast   | 10:56:14
 clang-x86_64-debian-fast | 10:56:13
 clang-cmake-x86_64-sde-avx512-linux  | 10:56:13
 lld-x86_64-darwin13  | 10:56:13
 clang-ppc64le-linux  | 10:52:49
 lld-x86_64-ubuntu-fast   | 10:44:59
 ppc64le-lld-multistage-test  | 10:11:37
 lldb-x86_64-debian   | 10:10:16
 clang-cmake-x86_64-avx2-linux| 09:55:55
 sanitizer-x86_64-linux-bootstrap | 09:52:02
 lldb-x64-windows-ninja   | 09:50:13
 polly-arm-linux  | 05:55:53
 aosp-O3-polly-before-vectorizer-unprofitable | 05:53:38
 sanitizer-windows| 05:06:18
 sanitizer-ppc64le-linux  | 05:05:09
 llvm-clang-x86_64-win-fast   | 04:53:57
 clang-cmake-armv7-selfhost   | 04:24:07
 sanitizer-ppc64be-linux  | 04:04:12
 sanitizer-x86_64-linux   | 03:32:54
 clang-ppc64le-rhel   | 03:25:09
 clang-cmake-armv7-selfhost-neon  | 03:03:42
 clang-cmake-armv7-lnt| 02:39:01
 clang-x86_64-linux-abi-test  | 02:30:59
 sanitizer-x86_64-linux-android   | 01:49:57
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03   | 01:22:40
 sanitizer-x86_64-linux-fuzzer| 01:05:53
 openmp-clang-x86_64-linux-debian | 01:04:14
 openmp-gcc-x86_64-linux-debian   | 00:45:42
 sanitizer-x86_64-linux-autoconf  | 00:40:55
 clang-armv7-linux-build-cache| 00:24:41
 clang-aarch64-linux-build-cache  | 00:24:39
 lldb-sphinx-docs | 00:10:33
 lld-sphinx-docs  | 00:10:20
 clang-tools-sphinx-docs  | 00:10:15
 libunwind-sphinx-docs| 00:10:06
 libcxx-sphinx-docs   | 00:10:00
(66 rows)


"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green):
   buildername   | builds | changes
| 

Buildbot numbers for the week of 12/22/2019 - 12/28/2019

2020-01-10 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 12/22/2019 - 12/28/2019.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
   buildername|  was_red
--+--
 clang-x64-windows-msvc   | 131:21:42
 sanitizer-x86_64-linux-bootstrap | 74:14:46
 sanitizer-x86_64-linux-bootstrap-msan| 73:05:39
 llvm-sphinx-docs | 30:50:51
 clang-cmake-armv7-full   | 17:08:41
 clang-ppc64le-rhel   | 09:48:58
 ppc64le-lld-multistage-test  | 09:44:07
 sanitizer-ppc64le-linux  | 09:39:49
 sanitizer-ppc64be-linux  | 08:19:12
 sanitizer-x86_64-linux   | 07:55:06
 clang-with-lto-ubuntu| 06:52:53
 sanitizer-x86_64-linux-android   | 06:39:10
 clang-with-thin-lto-ubuntu   | 05:56:28
 clang-s390x-linux-multistage | 05:44:20
 clang-cmake-thumbv7-full-sh  | 04:35:32
 clang-ppc64le-linux-lnt  | 04:21:11
 clang-ppc64le-linux-multistage   | 04:05:28
 clang-s390x-linux-lnt| 03:57:09
 sanitizer-x86_64-linux-bootstrap-ubsan   | 03:52:59
 sanitizer-x86_64-linux-fast  | 03:51:40
 clang-ppc64le-linux  | 03:49:05
 clang-ppc64be-linux-multistage   | 03:38:29
 clang-ppc64be-linux-lnt  | 03:34:06
 lldb-aarch64-ubuntu  | 03:33:42
 clang-s390x-linux| 03:30:32
 clang-ppc64be-linux  | 03:26:29
 clang-x86_64-debian-fast | 03:23:59
 clang-x86_64-debian-new-pass-manager-fast| 03:23:42
 clang-atom-d525-fedora-rel   | 03:23:20
 sanitizer-x86_64-linux-fuzzer| 02:45:21
 clang-cmake-armv8-lld| 01:50:15
 clang-cmake-armv7-lnt| 01:37:31
 llvm-clang-x86_64-expensive-checks-win   | 01:14:37
 openmp-clang-x86_64-linux-debian | 01:08:45
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast | 01:01:17
 lldb-x86_64-debian   | 00:43:44
 openmp-gcc-x86_64-linux-debian   | 00:37:12
 llvm-clang-x86_64-expensive-checks-debian| 00:36:04
 clang-cmake-armv7-quick  | 00:32:05
 lld-x86_64-darwin13  | 00:31:08
 lld-x86_64-ubuntu-fast   | 00:30:59
 llvm-clang-x86_64-expensive-checks-ubuntu| 00:28:44
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast   | 00:13:54
(43 rows)


"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green):
   buildername   | builds | changes
| status_change_ratio
-++-+
 sanitizer-x86_64-linux  | 73 |  23
|31.5
 clang-cmake-armv7-full  | 51 |  12
|23.5
 lldb-aarch64-ubuntu |121 |  20
|16.5
 clang-ppc64be-linux-multistage  |118 |  16
|13.6
 ppc64le-lld-multistage-test | 60 |   8
|13.3
 clang-with-lto-ubuntu   | 47 |   6
|12.8
 clang-ppc64le-linux-multistage  | 33 |   4
|12.1
 sanitizer-ppc64le-linux | 34 |   4
|11.8
 clang-ppc64be-linux-lnt |139 |  16
|11.5
 sanitizer-ppc64be-linux | 66 |   6
| 9.1
 clang-with-thin-lto-ubuntu  | 55 |   5
| 9.1
 clang-s390x-linux-multistage| 45 |   4
| 8.9
 clang-ppc64le-rhel  |116 |  10
| 8.6
 

Buildbot numbers for the week of 12/8/2019 - 12/14/2019

2020-01-10 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 12/8/2019 - 12/14/2019.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
  buildername  | was_red
---+-
 clang-cmake-aarch64-global-isel   | 79:16:33
 clang-cmake-aarch64-quick | 77:55:45
 llvm-clang-win-x-armv7l   | 53:10:53
 clang-cmake-armv7-full| 51:28:32
 clang-cmake-armv7-selfhost-neon   | 50:20:05
 clang-native-arm-lnt-perf | 49:26:54
 clang-hexagon-elf | 49:24:12
 clang-cmake-armv7-quick   | 49:21:11
 clang-cmake-thumbv7-full-sh   | 49:10:50
 clang-cmake-armv8-lld | 49:09:15
 clang-cmake-armv7-global-isel | 48:56:41
 clang-cmake-armv7-selfhost| 45:51:27
 clang-ppc64le-linux-multistage| 32:12:36
 aosp-O3-polly-before-vectorizer-unprofitable  | 31:01:43
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03| 29:40:32
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast| 25:59:36
 polly-arm-linux   | 23:43:14
 clang-x86_64-debian-new-pass-manager-fast | 19:03:20
 clang-cmake-aarch64-lld   | 16:43:30
 lldb-x86_64-debian| 16:10:02
 clang-cmake-aarch64-full  | 13:59:33
 clang-with-lto-ubuntu | 10:36:17
 clang-with-thin-lto-ubuntu| 10:31:56
 llvm-clang-win-x-aarch64  | 09:23:12
 clang-x64-windows-msvc| 09:11:40
 sanitizer-ppc64be-linux   | 08:54:20
 clang-ppc64be-linux-lnt   | 08:41:53
 sanitizer-x86_64-linux-autoconf   | 06:57:04
 sanitizer-x86_64-linux-bootstrap-msan | 06:42:47
 clang-ppc64le-linux   | 06:11:16
 ppc64le-lld-multistage-test   | 06:00:21
 clang-ppc64le-linux-lnt   | 06:00:02
 lld-x86_64-win7   | 05:57:47
 clang-ppc64be-linux   | 05:57:43
 llvm-clang-x86_64-expensive-checks-win| 05:55:12
 clang-s390x-linux-lnt | 05:40:54
 clang-ppc64be-linux-multistage| 05:35:34
 clang-s390x-linux | 05:35:18
 sanitizer-x86_64-linux| 05:17:00
 sanitizer-ppc64le-linux   | 04:57:23
 sanitizer-x86_64-linux-bootstrap-ubsan| 04:53:55
 sanitizer-x86_64-linux-android| 04:31:34
 openmp-gcc-x86_64-linux-debian| 04:20:06
 clang-s390x-linux-multistage  | 04:16:56
 sanitizer-x86_64-linux-fast   | 03:58:00
 lldb-x64-windows-ninja| 03:53:57
 sanitizer-x86_64-linux-bootstrap  | 03:08:55
 llvm-clang-x86_64-expensive-checks-ubuntu | 02:54:52
 llvm-clang-x86_64-expensive-checks-debian | 02:39:02
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast  | 02:30:29
 lld-x86_64-darwin13   | 02:29:56
 libcxx-libcxxabi-libunwind-aarch64-linux-noexceptions | 01:53:40
 libcxx-libcxxabi-libunwind-armv8-linux-noexceptions   | 01:53:07
 clang-cmake-x86_64-avx2-linux | 01:46:37
 clang-cmake-armv7-lnt | 01:44:18
 clang-atom-d525-fedora-rel| 01:43:02
 clang-x86_64-debian-fast  | 01:30:40
 clang-cmake-x86_64-sde-avx512-linux   | 01:30:23
 sanitizer-x86_64-linux-fuzzer | 01:27:20
 lld-x86_64-ubuntu-fast| 00:58:14
 llvm-clang-x86_64-win-fast| 00:55:08
 libcxx-libcxxabi-x86_64-linux-ubuntu-gcc5-cxx11   | 00:52:14
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx11| 00:50:26
 sanitizer-windows | 00:49:06
 

[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 2 inline comments as done.
tejohnson added a comment.

In D72538#1815074 , @wmi wrote:

> The additional pipeline testing will catch any future pass change to the 
> pipeline. A related but separate question is do we have a way to check 
> whether there is any other missing pass in thinlto newpm similar as that in 
> D72386 ?


Unfortunately not. That will take some painstaking comparisons between the pass 
debug output between the old and new PMs, which is going to be manual given the 
different format and structuring of the dependences. I am going to try to do 
that at least for a few important cases. As you noted, this is to help flag any 
future changes (although the last one did actually result in a test being 
changed, but it looks like no one realized the implications). Hopefully by 
having additional testing it will be more likely to trigger concerns if it 
happens again.




Comment at: clang/test/CodeGen/thinlto-distributed-newpm.ll:11
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -O2 -fexperimental-new-pass-manager -fdebug-pass-manager \

wmi wrote:
> Can we test %clang intead of %clang_cc1? so we don't have to add flags like 
> -vectorize-slp and -vectorize-loops. clang `O2/O3` pipeline is something we 
> care about. Those flags added by clang to cc1 options may be subject to 
> change.  
> 
Good idea, done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72538



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


[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-10 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin added a comment.

Another example where there is a discrepancy with the old pass manager: in the 
old pass manager (PassManagerBuilder::addFunctionSimplificationPasses):

  if (OptLevel > 1) {
  if (EnableGVNHoist)
MPM.add(createGVNHoistPass());

(before this change, new pass manager):

  if (Level > O1) {
 if (EnableGVNHoist)
   FPM.addPass(GVNHoistPass());

Which really means "O2 -3, and Os 
and Oz". I currently left it backwards compatible - since I'm not sure the 
added support for gvn hoisting for Os/z was intentional.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72547



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 237462.
tejohnson marked an inline comment as done.
tejohnson added a comment.

Implement suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SimplifyCFGPass
+; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
+; CHECK-O-NEXT: Running analysis: AssumptionAnalysis
+; CHECK-O-NEXT: Running pass: SROA
+; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
+; CHECK-O-NEXT: Running pass: EarlyCSEPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
+; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
+; CHECK-O-NEXT: Running pass: InstCombinePass on foo
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo
+; CHECK-O-NEXT: Running analysis: AAManager on foo
+; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy on foo
+; CHECK-O-NEXT: Finished llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SampleProfileLoaderPass
+; CHECK-O-NEXT: Running analysis: ProfileSummaryAnalysis
+; CHECK-O-NEXT: Running analysis: CallGraphAnalysis

[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-10 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin created this revision.
Herald added subscribers: llvm-commits, cfe-commits, dang, dexonsmith, 
steven_wu, hiraditya, mehdi_amini.
Herald added projects: clang, LLVM.
mtrofin added reviewers: tejohnson, davidxl.
mtrofin added a comment.

Another example where there is a discrepancy with the old pass manager: in the 
old pass manager (PassManagerBuilder::addFunctionSimplificationPasses):

  if (OptLevel > 1) {
  if (EnableGVNHoist)
MPM.add(createGVNHoistPass());

(before this change, new pass manager):

  if (Level > O1) {
 if (EnableGVNHoist)
   FPM.addPass(GVNHoistPass());

Which really means "O2 -3, and Os 
and Oz". I currently left it backwards compatible - since I'm not sure the 
added support for gvn hoisting for Os/z was intentional.


The old pass manager separated speed optimization and size optimization
levels into two unsigned values. Coallescing both in an enum in the new
pass manager may lead to unintentional casts and comparisons. For example,
(enum) "Level > 1" captures not only O2 
 and O3 
, but also  Os, and Oz.

In particular, taking a look at how the loop unroll passes were constructed
previously, the Os/Oz are now (==new pass manager) treated just like O3 
,
likely unintentionally.

This change disallows raw comparisons between optimization levels, to
avoid such unintended effects.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72547

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -192,10 +192,9 @@
cl::Hidden, cl::ZeroOrMore,
cl::desc("Run Partial inlinining pass"));
 
-static cl::opt
-RunNewGVN("enable-npm-newgvn", cl::init(false),
-  cl::Hidden, cl::ZeroOrMore,
-  cl::desc("Run NewGVN instead of GVN"));
+static cl::opt RunNewGVN("enable-npm-newgvn", cl::init(false), cl::Hidden,
+   cl::ZeroOrMore,
+   cl::desc("Run NewGVN instead of GVN"));
 
 static cl::opt EnableGVNHoist(
 "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
@@ -238,20 +237,12 @@
 
 extern cl::opt FlattenedProfileUsed;
 
-static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
-  switch (Level) {
-  case PassBuilder::O0:
-  case PassBuilder::O1:
-  case PassBuilder::O2:
-  case PassBuilder::O3:
-return false;
-
-  case PassBuilder::Os:
-  case PassBuilder::Oz:
-return true;
-  }
-  llvm_unreachable("Invalid optimization level!");
-}
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O0 = {0};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O1 = {1};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O2 = {2};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O3 = {3};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Os = {4};
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Oz = {5};
 
 namespace {
 
@@ -386,11 +377,9 @@
 C(LAM);
 }
 
-FunctionPassManager
-PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
- ThinLTOPhase Phase,
- bool DebugLogging) {
-  assert(Level != O0 && "Must request optimizations!");
+FunctionPassManager PassBuilder::buildFunctionSimplificationPipeline(
+OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging) {
+  assert(Level != OptimizationLevel::O0 && "Must request optimizations!");
   FunctionPassManager FPM(DebugLogging);
 
   // Form SSA out of local memory accesses after breaking apart aggregates into
@@ -401,7 +390,7 @@
   FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
 
   // Hoisting of scalars and load expressions.
-  if (Level > O1) {
+  if (Level.isO2Or3() || Level.isOptimizingForSize()) {
 if (EnableGVNHoist)
   FPM.addPass(GVNHoistPass());
 
@@ -413,31 +402,31 @@
   }
 
   // Speculative execution if the target has divergent branches; otherwise nop.
-  if (Level > O1) {
+  if (Level.isO2Or3() || Level.isOptimizingForSize()) {
 FPM.addPass(SpeculativeExecutionPass());
 
-// Optimize based on known information about branches, and cleanup afterward.
+// Optimize based on known information about branches, and cleanup
+// afterward.
 FPM.addPass(JumpThreadingPass());
 FPM.addPass(CorrelatedValuePropagationPass());
   }
   FPM.addPass(SimplifyCFGPass());
-  if (Level == O3)
+  if (Level == OptimizationLevel::O3)
 

[clang] 44e0daf - driver: Allow -fdebug-compilation-dir=foo in joined form.

2020-01-10 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2020-01-10T19:20:51-05:00
New Revision: 44e0daf16e6985eb44ea9a629402852dbff9cb0b

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

LOG: driver: Allow -fdebug-compilation-dir=foo in joined form.

All 130+ f_Group flags that take an argument allow it after a '=',
except for fdebug-complation-dir. Add a Joined<> alias so that
it behaves consistently with all the other f_Group flags.
(Keep the old Separate flag for backwards compat.)

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/debug-info-compilation-dir.c
clang/test/Driver/cl-options.c
clang/test/Driver/clang_f_opts.c
clang/test/Driver/fembed-bitcode.c
clang/test/Driver/integrated-as.s

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index dd673737b97b..caeed3d7b8ed 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -737,6 +737,9 @@ def fno_auto_profile_accurate : Flag<["-"], 
"fno-auto-profile-accurate">,
 def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
 Group, Flags<[CC1Option, CC1AsOption, CoreOption]>,
 HelpText<"The compilation directory to embed in the debug info.">;
+def fdebug_compilation_dir_EQ : Joined<["-"], "fdebug-compilation-dir=">,
+Group, Flags<[CC1Option, CC1AsOption, CoreOption]>,
+Alias;
 def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">,
 Group, Flags<[CC1Option]>,
 HelpText<"Emit extra debug info to make sample profile more accurate.">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8fdf1f23e28d..4ef40e974cd6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2397,6 +2397,12 @@ static void 
CollectArgsForIntegratedAssembler(Compilation ,
   } else if (Value == "-fdebug-compilation-dir") {
 CmdArgs.push_back("-fdebug-compilation-dir");
 TakeNextArg = true;
+  } else if (Value.consume_front("-fdebug-compilation-dir=")) {
+// The flag is a -Wa / -Xassembler argument and Options doesn't
+// parse the argument, so this isn't automatically aliased to
+// -fdebug-compilation-dir (without '=') here.
+CmdArgs.push_back("-fdebug-compilation-dir");
+CmdArgs.push_back(Value.data());
   } else {
 D.Diag(diag::err_drv_unsupported_option_argument)
 << A->getOption().getName() << Value;

diff  --git a/clang/test/CodeGen/debug-info-compilation-dir.c 
b/clang/test/CodeGen/debug-info-compilation-dir.c
index 786d23556de9..b49a0f5751f8 100644
--- a/clang/test/CodeGen/debug-info-compilation-dir.c
+++ b/clang/test/CodeGen/debug-info-compilation-dir.c
@@ -1,6 +1,7 @@
 // RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: cp %s rel.c
 // RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm 
-debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
+// RUN: %clang_cc1 -fdebug-compilation-dir=/nonsense -emit-llvm 
-debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
 // CHECK-NONSENSE: nonsense
 
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck 
-check-prefix=CHECK-DIR %s

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 2a5453b10d26..49f5166b95e4 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -627,6 +627,7 @@
 // RUN: -fdiagnostics-color \
 // RUN: -fno-diagnostics-color \
 // RUN: -fdebug-compilation-dir . \
+// RUN: -fdebug-compilation-dir=. \
 // RUN: -fdiagnostics-parseable-fixits \
 // RUN: -fdiagnostics-absolute-paths \
 // RUN: -ferror-limit=10 \

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index ea6d10af5317..0a7cfdf11281 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -543,7 +543,9 @@
 // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch
 
 // RUN: %clang -### -S -fdebug-compilation-dir . %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir" "."
 
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
@@ -590,4 

[clang] fbf915f - Add a FIXME and corresponding test coverage for some suspicious behavior

2020-01-10 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-01-10T16:12:00-08:00
New Revision: fbf915f01d46e005146f01553a5d7c6619d19597

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

LOG: Add a FIXME and corresponding test coverage for some suspicious behavior
forming composite ObjC pointer types in comparisons.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaObjC/arc.m
clang/test/SemaObjCXX/arc-ptr-comparison.mm

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 51b1ebe0b17f..5f4071924d3f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11055,6 +11055,9 @@ QualType Sema::CheckCompareOperands(ExprResult , 
ExprResult ,
 diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS,
   /*isError*/false);
   }
+  // FIXME: If LPtrToVoid, we should presumably convert the LHS rather than
+  // the RHS, but we have test coverage for this behavior.
+  // FIXME: Consider using convertPointersToCompositeType in C++.
   if (LHSIsNull && !RHSIsNull) {
 Expr *E = LHS.get();
 if (getLangOpts().ObjCAutoRefCount)

diff  --git a/clang/test/SemaObjC/arc.m b/clang/test/SemaObjC/arc.m
index b87f294eef53..dea3ba5e9b79 100644
--- a/clang/test/SemaObjC/arc.m
+++ b/clang/test/SemaObjC/arc.m
@@ -295,6 +295,7 @@ void test11(id op, void *vp) {
   b = (vp == nil);
   b = (nil == vp);
 
+  // FIXME: Shouldn't these be consistent?
   b = (vp == op); // expected-error {{implicit conversion of Objective-C 
pointer type 'id' to C pointer type 'void *' requires a bridged cast}} 
expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}}
   b = (op == vp);
 }

diff  --git a/clang/test/SemaObjCXX/arc-ptr-comparison.mm 
b/clang/test/SemaObjCXX/arc-ptr-comparison.mm
index 8571a8179598..b3af26c1f847 100644
--- a/clang/test/SemaObjCXX/arc-ptr-comparison.mm
+++ b/clang/test/SemaObjCXX/arc-ptr-comparison.mm
@@ -22,3 +22,32 @@ int testObjCComparisonRules(void *v, id x, id y) {
   return v == (void *)0;
   return x == y;
 }
+
+@class A;
+
+int testMixedQualComparisonRules(void *v, const void *cv, A *a, const A *ca) {
+  return cv == ca;
+#ifndef NOARC
+// expected-error@-2 {{implicit conversion of Objective-C pointer type 'const 
A *' to C pointer type 'const void *' requires a bridged cast}}
+// expected-note@-3 {{use __bridge to convert directly (no change in 
ownership)}}
+// expected-note@-4 {{use __bridge_retained to make an ARC object available as 
a +1 'const void *'}}
+#endif
+  // FIXME: The "to" type in this diagnostic is wrong; we should convert to 
"const void *".
+  return v == ca;
+#ifndef NOARC
+// expected-error@-2 {{implicit conversion of Objective-C pointer type 'const 
A *' to C pointer type 'void *' requires a bridged cast}}
+// expected-note@-3 {{use __bridge to convert directly (no change in 
ownership)}}
+// expected-note@-4 {{use __bridge_retained to make an ARC object available as 
a +1 'void *'}}
+#endif
+  return cv == a;
+#ifndef NOARC
+// expected-error@-2 {{implicit conversion of Objective-C pointer type 'A *' 
to C pointer type 'const void *' requires a bridged cast}}
+// expected-note@-3 {{use __bridge to convert directly (no change in 
ownership)}}
+// expected-note@-4 {{use __bridge_retained to make an ARC object available as 
a +1 'const void *'}}
+#endif
+
+  // FIXME: Shouldn't these be rejected in ARC mode too?
+  return ca == cv;
+  return a == cv;
+  return ca == v;
+}



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


[clang] f4df7f4 - Remove redundant implicit cast creation.

2020-01-10 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-01-10T16:12:00-08:00
New Revision: f4df7f4701d80ce6a2f5674db50f87fbd2dad82f

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

LOG: Remove redundant implicit cast creation.

FindCompositePointerType has already cast the operands to the composite
type for us in the case where it succeeds.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6c1d3deab2a3..51b1ebe0b17f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10180,8 +10180,6 @@ static bool convertPointersToCompositeType(Sema , 
SourceLocation Loc,
 return true;
   }
 
-  LHS = S.ImpCastExprToType(LHS.get(), T, CK_BitCast);
-  RHS = S.ImpCastExprToType(RHS.get(), T, CK_BitCast);
   return false;
 }
 



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


[PATCH] D72467: [WIP] Remove "mask" operand from shufflevector.

2020-01-10 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4413
 unsigned MaxRecurse) {
-  if (isa(Mask))
+  if (all_of(Mask, [](int Elem) { return Elem == -1; }))
 return UndefValue::get(RetTy);

maybe introduce new helper function to check if mask is "undef"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72467



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


[PATCH] D72467: [WIP] Remove "mask" operand from shufflevector.

2020-01-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma updated this revision to Diff 237453.
efriedma added a comment.
Herald added subscribers: cfe-commits, Petar.Avramovic, dexonsmith, nhaehnle, 
jvesely, arsenm.
Herald added a project: clang.

Add more comments, fixed the GlobalISel representation of shuffles, misc other 
cleanups.  Still haven't addressed the bitcode reader/writer issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72467

Files:
  clang/lib/CodeGen/CGExpr.cpp
  llvm/include/llvm/ADT/ArrayRef.h
  llvm/include/llvm/Analysis/ConstantFolding.h
  llvm/include/llvm/Analysis/InstructionSimplify.h
  llvm/include/llvm/Analysis/TargetFolder.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/CodeGen/MachineInstrBuilder.h
  llvm/include/llvm/CodeGen/MachineOperand.h
  llvm/include/llvm/IR/ConstantFolder.h
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Instructions.h
  llvm/include/llvm/IR/NoFolder.h
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
  llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
  llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
  llvm/lib/CodeGen/MIRParser/MIParser.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/MachineVerifier.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/ConstantFold.cpp
  llvm/lib/IR/ConstantFold.h
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/ConstantsContext.h
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
  llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
  llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/MVETailPredication.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/lib/Transforms/Scalar/GVNSink.cpp
  llvm/lib/Transforms/Scalar/NewGVN.cpp
  llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-shuffle-vector.mir
  llvm/unittests/IR/PatternMatch.cpp

Index: llvm/unittests/IR/PatternMatch.cpp
===
--- llvm/unittests/IR/PatternMatch.cpp
+++ llvm/unittests/IR/PatternMatch.cpp
@@ -991,31 +991,31 @@
   EXPECT_TRUE(match(EX3, m_ExtractElement(m_Constant(), m_ConstantInt(;
 
   // Test matching shufflevector
-  EXPECT_TRUE(match(SI1, m_ShuffleVector(m_Value(), m_Undef(), m_Zero(;
-  EXPECT_TRUE(match(SI2, m_ShuffleVector(m_Value(A), m_Value(B), m_Value(C;
+  ArrayRef Mask;
+  EXPECT_TRUE(match(SI1, m_ShuffleVector(m_Value(), m_Undef(), m_ZeroMask(;
+  EXPECT_TRUE(match(SI2, m_ShuffleVector(m_Value(A), m_Value(B), m_Mask(Mask;
   EXPECT_TRUE(A == VI3);
   EXPECT_TRUE(B == VI4);
-  EXPECT_TRUE(C == IdxVec);
   A = B = C = nullptr; // reset
 
   // Test matching the vector splat pattern
   EXPECT_TRUE(match(
   SI1,
   m_ShuffleVector(m_InsertElement(m_Undef(), m_SpecificInt(1), m_Zero()),
-  m_Undef(), m_Zero(;
+  m_Undef(), m_ZeroMask(;
   EXPECT_FALSE(match(
   SI3, m_ShuffleVector(m_InsertElement(m_Undef(), m_Value(), m_Zero()),
-   m_Undef(), m_Zero(;
+   m_Undef(), m_ZeroMask(;
   EXPECT_FALSE(match(
   SI4, m_ShuffleVector(m_InsertElement(m_Undef(), m_Value(), m_Zero()),
-   m_Undef(), m_Zero(;
+   m_Undef(), m_ZeroMask(;
   EXPECT_TRUE(match(
   SP1,
   m_ShuffleVector(m_InsertElement(m_Undef(), m_SpecificInt(2), m_Zero()),
-  m_Undef(), m_Zero(;
+  m_Undef(), m_ZeroMask(;
   EXPECT_TRUE(match(
   SP2, m_ShuffleVector(m_InsertElement(m_Undef(), m_Value(A), m_Zero()),
-   m_Undef(), m_Zero(;
+   m_Undef(), m_ZeroMask(;
   EXPECT_TRUE(A == Val);
 }
 
Index: llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-shuffle-vector.mir

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

2020-01-10 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

In D54943#1815121 , @JonasToth wrote:

> In D54943#1815073 , @0x8000- 
> wrote:
>
> > Applied the fix-it on one of our smaller (but C++ code bases) and it builds 
> > and passes the tests. Comments:
> >
> > 1. I'm still seeing some false positives, where some locals that are const 
> > are flagged as could be made const - I'm working to create a minimal 
> > reproduction recipe.
> > 2. We're a west const shop :) so adding a bunch of east-consts will not fly 
> > well. Is there a way to configure where 'const' is placed by the fixit? 
> > (Specifically 'auto const', we prefer it 'const auto').
>
>
> Does it build now? I couldn't find a way to reproduce that and gave up, tbh.
>
> 1. Template context? Auto involved? I saw some double-analysis for `auto&`, 
> because clang-tidy didn't ignore those properly. And are you using 
> `run-clang-tidy`? It deduplicates fixits, maybe that is involved?
> 2. YesNo, The utility for adding const is able to do both, west const has 
> problems with `typedef int * MyType;` scenarios, where the `const` will apply 
> to the wrong thing. Doing that right requires special care. BUT: 
> `clang-format` has a east-const/west-const feature now (i think new with this 
> release). So I am now somewhat considering to let clang-format do that for me.
>
>   Thanks again for taking a look at it. But if the issues you found are new, 
> i think we should maybe not commit this weekend.


I haven't tried Debug build, Release only.

I'm good with having clang-format do the west-const transformation.

It's not a template, but something like "const Foo foo{x, y, z};" where x and y 
were references and z was a pointer. I'll try to reduce a test case.

I have also noticed a check failure, but not sure if in this tool or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[clang] 1b8c84b - Improve precision of documentation comment.

2020-01-10 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-01-10T15:49:17-08:00
New Revision: 1b8c84b8dd5a4a294943a6a6f0631d2d3a1f9f27

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

LOG: Improve precision of documentation comment.

Added: 


Modified: 
clang/include/clang/AST/Decl.h

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index aa5cfb6e2c8b..623f47b31bb4 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1519,8 +1519,8 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// need not have a usable destructor at all.
   bool isNoDestroy(const ASTContext &) const;
 
-  /// Do we need to emit an exit-time destructor for this variable, and if so,
-  /// what kind?
+  /// Would the destruction of this variable have any effect, and if so, what
+  /// kind?
   QualType::DestructionKind needsDestruction(const ASTContext ) const;
 
   // Implement isa/cast/dyncast/etc.



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


[PATCH] D62686: [RISCV] Add support for save/restore of callee-saved registers via libcalls

2020-01-10 Thread Pengxuan Zheng via Phabricator via cfe-commits
pzheng added a comment.

I see the following .cfi_offset directives generated using @shiva0217's test 
case. Any idea why the offset for ra is 536870908?

  callt0, __riscv_save_0
  .cfi_def_cfa_offset 16
  .cfi_offset ra, 536870908




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62686



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


[PATCH] D69868: Allow "callbr" to return non-void values

2020-01-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: llvm/lib/CodeGen/MachineVerifier.cpp:701
+  } else if (MBB->succ_size() == LandingPadSuccs.size() ||
+ MBB->succ_size() == IndirectPadSuccs.size()) {
 // It's possible that the block legitimately ends with a noreturn

void wrote:
> jyknight wrote:
> > This isn't correct.
> > 
> > This line here, is looking at a block which doesn't end in a jump to a 
> > successor. So, it's trying to verify that the successor list makes sense in 
> > that context.
> > 
> > The unstated assumption in the code is that the only successors will be 
> > landing pads. Instead of actually checking each one, instead it just checks 
> > that the count is the number of landing pads, with the assumption that all 
> > the successors should be landing pads, and that all the landing pads should 
> > be successors.
> > 
> > The next clause is then checking for the case where there's a fallthrough 
> > to the next block. In that case, the successors should've been all the 
> > landing pads, and the single fallthrough block.
> > 
> > Adding similar code to check for the number of callbr targets doesn't 
> > really make sense. It's certainly not the case that all callbr targets are 
> > targets of all 
> > callbr instructions. And even if it was, this still wouldn't be counting 
> > things correctly.
> > 
> > 
> > However -- I think i'd expect analyzeBranch to error out (returning true) 
> > when confronted by a callbr instruction, because it cannot actually tell 
> > what's going on there. If that were the case, nothing in this block should 
> > even be invoked. But I guess that's probably not happening, due to the 
> > terminator being followed by non-terminators.
> > 
> > That seems likely to be a problem that needs to be fixed. (And if that is 
> > fixed, I think the changes here aren't needed anymore)
> > 
> > 
> Your comment is very confusing. Could you please give an example of where 
> this fails?
Sorry about that, I should've delimited the parts of that message better...
Basically:
- Paragraphs 2-4 are describing why the code before this patch appears to be 
correct for landing pad, even though it's taking some shortcuts and making some 
non-obvious assumptions.
- Paragraph 5 ("Adding similar code"...) is why it's not correct for callbr.
- Paragraph 6-7 are how I'd suggest to resolve it.


I believe the code as of your patch will fail validation if you have a callbr 
instruction which has a normal-successor block which is an indirect target of a 
*different* callbr in the function.

I believe it'll also fail if you have any landing-pad successors, since those 
aren't being added to the count of expected successors, but rather checked 
separately.

But more seriously than these potential verifier failures, I expect that 
analyzeBranch returning wrong answers (in that it may report that a block 
unconditionally-jumps to a successor, while it really has both a callbr and 
jump, separated by the non-terminator copies) will cause miscompilation. I'm 
not sure exactly how that will exhibit, but I'm pretty sure it's not going to 
be good.

And, if analyzeBranch properly said "no idea" when confronted by callbr control 
flow, then this code in the verifier wouldn't be reached.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69868



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


[PATCH] D72411: [CodeGen] partially revert 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 to fix Objective-C static variable initialization

2020-01-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:377
 
-  if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
+  if (hasNontrivialDestruction(D.getType()) && HaveInsertPoint()) {
 // We have a constant initializer, but a nontrivial destructor. We still

rjmccall wrote:
> rsmith wrote:
> > arphaman wrote:
> > > rjmccall wrote:
> > > > The long-term fix here is probably for `needsDestruction` to say that 
> > > > variables of static storage duration of non-trivial ARC type and/or 
> > > > non-trivial C struct type don't need destruction.
> > > I don't have time to fix it properly right now, but I filed 
> > > https://github.com/llvm/llvm-project/issues/93 to keep track of the 
> > > issue. Can this be committed now before the branch next week to avoid 
> > > shipping this bug in the release?
> > A correct fix looks to be pretty trivial and this patch appears to break 
> > C++20 semantics, so let's fix it properly.
> I agree.
Done in llvmorg-10-init-17084-g7a38468e34e.  Thanks for the report and the 
testcase :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72411



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


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

2020-01-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54943#1815073 , @0x8000- wrote:

> Applied the fix-it on one of our smaller (but C++ code bases) and it builds 
> and passes the tests. Comments:
>
> 1. I'm still seeing some false positives, where some locals that are const 
> are flagged as could be made const - I'm working to create a minimal 
> reproduction recipe.
> 2. We're a west const shop :) so adding a bunch of east-consts will not fly 
> well. Is there a way to configure where 'const' is placed by the fixit? 
> (Specifically 'auto const', we prefer it 'const auto').


Does it build now? I couldn't find a way to reproduce that and gave up, tbh.

1. Template context? Auto involved? I saw some double-analysis for `auto&`, 
because clang-tidy didn't ignore those properly. And are you using 
`run-clang-tidy`? It deduplicates fixits, maybe that is involved?
2. YesNo, The utility for adding const is able to do both, west const has 
problems with `typedef int * MyType;` scenarios, where the `const` will apply 
to the wrong thing. Doing that right requires special care. BUT: `clang-format` 
has a east-const/west-const feature now (i think new with this release).

So I am now somewhat considering to let clang-format do that for me.

Thanks again for taking a look at it. But if the issues you found are new, i 
think we should maybe not commit this weekend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[clang] 7a38468 - Only destroy static locals if they have non-trivial destructors.

2020-01-10 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-01-10T15:18:36-08:00
New Revision: 7a38468e34eeeb59e80b176b97213d205d8d9b41

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

LOG: Only destroy static locals if they have non-trivial destructors.

This fixes a regression introduced in
2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 that caused us to emit
shutdown-time destruction for variables with ARC ownership, using
C++-specific functions that don't exist in C implementations.

Added: 
clang/test/CodeGenObjC/initialize-function-static.m

Modified: 
clang/lib/CodeGen/CGDecl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 61fb8fa384cf..86e02d2d7e4a 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -366,7 +366,8 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const 
VarDecl ,
 
   emitter.finalize(GV);
 
-  if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
+  if (D.needsDestruction(getContext()) == QualType::DK_cxx_destructor &&
+  HaveInsertPoint()) {
 // We have a constant initializer, but a nontrivial destructor. We still
 // need to perform a guarded "initialization" in order to register the
 // destructor.

diff  --git a/clang/test/CodeGenObjC/initialize-function-static.m 
b/clang/test/CodeGenObjC/initialize-function-static.m
new file mode 100644
index ..21ad320f7820
--- /dev/null
+++ b/clang/test/CodeGenObjC/initialize-function-static.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.15 -emit-llvm -fobjc-arc -o - 
%s | FileCheck %s
+
+@interface I
+@end
+
+I *i() {
+  static I *i = ((void *)0);
+  return i;
+}
+
+// CHECK-NOT: __cxa_guard_acquire
+// CHECK-NOT: __cxa_guard_release



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


[PATCH] D72411: [CodeGen] partially revert 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 to fix Objective-C static variable initialization

2020-01-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:377
 
-  if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
+  if (hasNontrivialDestruction(D.getType()) && HaveInsertPoint()) {
 // We have a constant initializer, but a nontrivial destructor. We still

rsmith wrote:
> arphaman wrote:
> > rjmccall wrote:
> > > The long-term fix here is probably for `needsDestruction` to say that 
> > > variables of static storage duration of non-trivial ARC type and/or 
> > > non-trivial C struct type don't need destruction.
> > I don't have time to fix it properly right now, but I filed 
> > https://github.com/llvm/llvm-project/issues/93 to keep track of the issue. 
> > Can this be committed now before the branch next week to avoid shipping 
> > this bug in the release?
> A correct fix looks to be pretty trivial and this patch appears to break 
> C++20 semantics, so let's fix it properly.
I agree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72411



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Jeffrey Sorensen via Phabricator via cfe-commits
sorenj added a comment.

First time so trying to follow similar recent submits. PTAL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607



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


[PATCH] D72411: [CodeGen] partially revert 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 to fix Objective-C static variable initialization

2020-01-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:377
 
-  if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
+  if (hasNontrivialDestruction(D.getType()) && HaveInsertPoint()) {
 // We have a constant initializer, but a nontrivial destructor. We still

arphaman wrote:
> rjmccall wrote:
> > The long-term fix here is probably for `needsDestruction` to say that 
> > variables of static storage duration of non-trivial ARC type and/or 
> > non-trivial C struct type don't need destruction.
> I don't have time to fix it properly right now, but I filed 
> https://github.com/llvm/llvm-project/issues/93 to keep track of the issue. 
> Can this be committed now before the branch next week to avoid shipping this 
> bug in the release?
A correct fix looks to be pretty trivial and this patch appears to break C++20 
semantics, so let's fix it properly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72411



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:106
+
+  Finds cases where a signed value is subtracted from an unsigned value,
+  a likely cause of unexpected underflow.

Please synchronize with first statement in documentation.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst:5-6
+==
+
+This check finds expressions where a signed value is subtracted from
+an unsigned value.

This check should be removed.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst:15
+
+This warning suggest a fixit change that will append a ``u`` to
+constants, thus making the implict cast explicit and signals that

fix-it. Check, not warning.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst:17
+constants, thus making the implict cast explicit and signals that
+the developer intends the subtraction with unsigned arguments.
+In cases where the second argument is not a constant, a

code was intended?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Jeffrey Sorensen via Phabricator via cfe-commits
sorenj updated this revision to Diff 237440.
sorenj added a comment.

- Merge branch 'master' of https://github.com/llvm/llvm-project
- Add documentation and release notes, fix spelling error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsignedSubtractionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnsignedSubtractionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unsigned-subtraction.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s bugprone-unsigned-subtraction %t
+
+template 
+class vector {
+ public:
+  unsigned size();
+  bool empty();
+};
+
+#define MACRO_MINUS(x) x - 5
+#define MACRO_INT 20
+
+void signedSubtracted() {
+  unsigned x = 5;
+  int  = 2;
+  if (x -  == 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+// CHECK-FIXES: if (x - static_cast() == 0) {
+return;
+  }
+  if (0 >= x - ) {
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: signed value subtracted from
+// CHECK-FIXES: if (0 >= x - static_cast()) {
+return;
+  }
+  unsigned z = MACRO_MINUS(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: signed value subtracted from
+  z = x - MACRO_INT;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+  // CHECK-FIXES: z = x - static_cast(MACRO_INT);
+}
+
+void signedConstantSubtracted() {
+  unsigned x = 5;
+  if (x - 2 > 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: signed value subtracted from
+// CHECK-FIXES: if (x - 2u > 0) {
+return;
+  }
+}
+
+void casesThatShouldBeIgnored() {
+  unsigned x = 5;
+  // If the constant used in subtraction is already explicitly unsigned, do not
+  // warn. This is not safe, but the user presumably knows what they are doing.
+  if (x - 2u > 0u) {
+return;
+  }
+  if (x - 2u > 0) {
+return;
+  }
+  // sizeof operators are strictly positive for all types, and a constexpr, so
+  // any underflow would happen at compile time, so do not warn.
+  x = sizeof(long double) - 1;
+  // If both sides of the subtraction are compile time constants, don't warn.
+  if (5u - 2 > 0) {
+return;
+  }
+  constexpr long y = 4;  // NOLINT(runtime/int)
+  if (y - 4 > 0) {
+return;
+  }
+}
+
+// If the first argument of the subtraction is an expression that was previously
+// used in a comparison, the user is presumed to have done something smart.
+// This isn't perfect, but it greatly reduces false alarms.
+void contextMatters() {
+  unsigned x = 5;
+  if (x < 5) return;
+  if (x - 2 > 0u) {
+return;
+  }
+}
+
+// For loops with a compartor meet the previously described case, and therefore
+// do not warn if the variable is used in a subtraction. Again not perfect, but
+// this code is complex to reason about and it's best not to generate false
+// alarms.
+unsigned forLoops() {
+  unsigned x;
+  for (unsigned i = 1; i < 5; ++i) {
+x += i - 1;
+  }
+  return x;
+}
+
+// Testing for an empty container before subtracting from size() is considered
+// to be the same as comparing against the size - it's still possible to fail
+// but reduces the number of false positives.
+void containersEmpty() {
+  vector x;
+  if (!x.empty()) {
+if (x.size() - 1 > 0) {
+  return;
+}
+  }
+  vector y;
+  if (y.size() - 1 > 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: signed value subtracted from
+// CHECK-FIXES: if (y.size() - 1u > 0) {
+return;
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unsigned-subtraction.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - bugprone-unsigned-subtraction
+
+bugprone-sizeof-expression
+==
+
+This check finds expressions where a signed value is subtracted from
+an unsigned value.
+
+Many programmers are unaware that an expression of unsigned - signed
+will promote the signed argument to unsigned, and if an underflow
+occurs it results in a large positive value. Hence the frequent
+errors related to to tests of ``container.size() - 1 <= 0`` when a
+container is empty.
+
+This warning suggest a fixit change that will append a ``u`` to
+constants, thus making the implict cast explicit and signals that
+the developer intends the subtraction with unsigned arguments.
+In cases where the second argument is not a constant, a

[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Wei Mi via Phabricator via cfe-commits
wmi added a comment.

The additional pipeline testing will catch any future pass change to the 
pipeline. A related but separate question is do we have a way to check whether 
there is any other missing pass in thinlto newpm similar as that in D72386 
?




Comment at: clang/test/CodeGen/thinlto-distributed-newpm.ll:11
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -O2 -fexperimental-new-pass-manager -fdebug-pass-manager \

Can we test %clang intead of %clang_cc1? so we don't have to add flags like 
-vectorize-slp and -vectorize-loops. clang `O2/O3` pipeline is something we 
care about. Those flags added by clang to cc1 options may be subject to change. 
 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72538



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


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

2020-01-10 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

Applied the fix-it on one of our smaller (but C++ code bases) and it builds and 
passes the tests. Comments:

1. I'm still seeing some false positives, where some locals that are const are 
flagged as could be made const - I'm working to create a minimal reproduction 
recipe.
2. We're a west const shop :) so adding a bunch of east-consts will not fly 
well. Is there a way to configure where 'const' is placed by the fixit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D72411: [CodeGen] partially revert 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 to fix Objective-C static variable initialization

2020-01-10 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked an inline comment as done.
arphaman added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:377
 
-  if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
+  if (hasNontrivialDestruction(D.getType()) && HaveInsertPoint()) {
 // We have a constant initializer, but a nontrivial destructor. We still

rjmccall wrote:
> The long-term fix here is probably for `needsDestruction` to say that 
> variables of static storage duration of non-trivial ARC type and/or 
> non-trivial C struct type don't need destruction.
I don't have time to fix it properly right now, but I filed 
https://github.com/llvm/llvm-project/issues/93 to keep track of the issue. Can 
this be committed now before the branch next week to avoid shipping this bug in 
the release?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72411



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


[PATCH] D72378: [clang-tidy] Add `bugprone-reserved-identifier`

2020-01-10 Thread Logan Smith via Phabricator via cfe-commits
logan-5 updated this revision to Diff 237433.
logan-5 marked 4 inline comments as done.
logan-5 added a comment.

Added a TODO comment for catching more reserved names. Added links in 
documentation to CERT guidelines covered by the check. Pulled strings into 
named constants and made that logic easier to read.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72378

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-reserved-identifier.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-dcl37-c.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-dcl51-cpp.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-reserved-identifier/system/system-header.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-reserved-identifier/user-header.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-c.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
@@ -0,0 +1,206 @@
+// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- -- \
+// RUN:   -I%S/Inputs/bugprone-reserved-identifier \
+// RUN:   -isystem %S/Inputs/bugprone-reserved-identifier/system
+
+// no warnings expected without -header-filter=
+#include "user-header.h"
+#include 
+
+#define _MACRO(m) int m = 0
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses reserved identifier '_MACRO', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}#define MACRO(m) int m = 0{{$}}
+
+namespace _Ns {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses reserved identifier '_Ns', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}namespace Ns {{{$}}
+
+class _Object {
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '_Object', which causes undefined behavior [bugprone-reserved-identifier]
+  // CHECK-FIXES: {{^}}class Object {{{$}}
+  int _Member;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '_Member', which causes undefined behavior [bugprone-reserved-identifier]
+  // CHECK-FIXES: {{^}}  int Member;{{$}}
+};
+
+float _Global;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '_Global', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}float Global;{{$}}
+
+void _Function() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses reserved identifier '_Function', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}void Function() {}{{$}}
+
+using _Alias = int;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '_Alias', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}using Alias = int;{{$}}
+
+template 
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses reserved identifier '_TemplateParam', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}template {{$}}
+struct S {};
+
+} // namespace _Ns
+
+//
+
+#define __macro(m) int m = 0
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses reserved identifier '__macro', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}#define macro(m) int m = 0{{$}}
+
+namespace __ns {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses reserved identifier '__ns', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}namespace ns {{{$}}
+class __object {
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '__object', which causes undefined behavior [bugprone-reserved-identifier]
+  // CHECK-FIXES: {{^}}class _object {{{$}}
+  int __member;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '__member', which causes undefined behavior [bugprone-reserved-identifier]
+  // CHECK-FIXES: {{^}}  int _member;{{$}}
+};
+
+float __global;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses reserved identifier '__global', which causes undefined behavior [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}float _global;{{$}}
+
+void __function() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: 

[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Documentation and Release Notes entry are still missing..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607



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


[PATCH] D71607: [clang-tidy] Add unsigned subtraction warning, with suggestion to convert to unsigned literals.

2020-01-10 Thread Jeffrey Sorensen via Phabricator via cfe-commits
sorenj added a comment.

Friendly ping - anything further I need to do here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71607



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 237427.
tejohnson added a comment.

Remove some cruft


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SimplifyCFGPass
+; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
+; CHECK-O-NEXT: Running analysis: AssumptionAnalysis
+; CHECK-O-NEXT: Running pass: SROA
+; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
+; CHECK-O-NEXT: Running pass: EarlyCSEPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
+; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
+; CHECK-O-NEXT: Running pass: InstCombinePass on foo
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo
+; CHECK-O-NEXT: Running analysis: AAManager on foo
+; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy on foo
+; CHECK-O-NEXT: Finished llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SampleProfileLoaderPass
+; CHECK-O-NEXT: Running analysis: ProfileSummaryAnalysis
+; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
+; CHECK-O-NEXT: Running pass: 

[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: wmi.
Herald added subscribers: jfb, dexonsmith, steven_wu, hiraditya, inglorion, 
mehdi_amini.
Herald added projects: clang, LLVM.

I've added some more extensive ThinLTO pipeline testing with the new PM,
motivated by the bug fixed in D72386 .

I beefed up llvm/test/Other/new-pm-pgo.ll a little so that it tests
ThinLTO pre and post link with PGO, similar to the testing for the
default pipelines with PGO.

Added new pre and post link PGO tests for both instrumentation and
sample PGO that exhaustively test the pipelines at different
optimization levels via opt.

Added a clang test to exhaustively test the post link pipeline invoked for
distributed builds. I am currently only testing O2 
 and O3 
 since these
are the most important for performance.

It would be nice to add similar exhaustive testing for full LTO, and for
the old PM, but I don't have the bandwidth now and this is a start to
cover some of the situations that are not currently default and were
under tested.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting 

[PATCH] D65761: Add Windows Control Flow Guard checks (/guard:cf).

2020-01-10 Thread Andrew Paverd via Phabricator via cfe-commits
ajpaverd added a comment.

In D65761#1811097 , 
@hubert.reinterpretcast wrote:

> In D65761#1804302 , 
> @hubert.reinterpretcast wrote:
>
> > I have confirmed that the case I mentioned fails with rGd157a9b 
> > .
>
>
> @ajpaverd, is a fix forthcoming for the issue I mentioned with this patch?


The CFGuard library shouldn't be needed for targets other than ARM, AArch64, 
and X86, and it's only being built for these targets. However, it looks like 
`llvm-build` is also including it in the `LibraryDependencies.inc` file for 
other targets, such as PowerPC, which I think is causing this error. I'm not 
sure how to indicate that the library is only needed for a specified subset of 
targets. @rnk or @hans  any suggestions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65761



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


[clang-tools-extra] 68cd283 - clang-tidy doc: unbreak the CI

2020-01-10 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2020-01-10T22:25:01+01:00
New Revision: 68cd283f3b074e3b64b9f65e93ceb2de6807c72d

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

LOG: clang-tidy doc: unbreak the CI

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 3cdf2c9a7d14..c89ec0c10917 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -7,6 +7,8 @@ Clang-Tidy Checks
:glob:
:hidden:
 
+   *
+
 .. csv-table::
:header: "Name", "Offers fixes"
 



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst:14
+
+   Specify extra functions to flag that act similarily to memset.
+   Default is an empty string.

Somehow memset is still not in double back-ticks. Same for other options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488



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


[clang-tools-extra] faeeb71 - clang-tidy doc: Refresh the list of checkers and polish the script

2020-01-10 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2020-01-10T22:07:47+01:00
New Revision: faeeb71a17344171f814144213ac4fbc93be28fd

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

LOG: clang-tidy doc: Refresh the list of checkers and polish the script

Added: 


Modified: 
clang-tools-extra/clang-tidy/add_new_check.py
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index 68a723900751..4406efc1b0f5 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -368,14 +368,12 @@ def format_link_alias(doc_file):
   f.write(line)
   if line.strip() == ".. csv-table::":
 # We dump the checkers
-f.write('   :header: "Name", "Offers fixes"\n')
-f.write('   :widths: 50, 20\n\n')
+f.write('   :header: "Name", "Offers fixes"\n\n')
 f.writelines(checks)
 # and the aliases
 f.write('\n\n')
 f.write('.. csv-table:: Aliases..\n')
-f.write('   :header: "Name", "Redirect", "Offers fixes"\n')
-f.write('   :widths: 50, 50, 10\n\n')
+f.write('   :header: "Name", "Redirect", "Offers fixes"\n\n')
 f.writelines(checks_alias)
 break
 

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index e5cac0312081..3cdf2c9a7d14 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -3,6 +3,10 @@
 Clang-Tidy Checks
 =
 
+.. toctree::
+   :glob:
+   :hidden:
+
 .. csv-table::
:header: "Name", "Offers fixes"
 
@@ -25,8 +29,8 @@ Clang-Tidy Checks
`abseil-upgrade-duration-conversions 
`_, "Yes"
`android-cloexec-accept `_, "Yes"
`android-cloexec-accept4 `_,
-   `android-cloexec-creat `_,
-   `android-cloexec-dup `_,
+   `android-cloexec-creat `_, "Yes"
+   `android-cloexec-dup `_, "Yes"
`android-cloexec-epoll-create `_,
`android-cloexec-epoll-create1 `_,
`android-cloexec-fopen `_,
@@ -34,10 +38,10 @@ Clang-Tidy Checks
`android-cloexec-inotify-init1 `_,
`android-cloexec-memfd-create `_,
`android-cloexec-open `_,
-   `android-cloexec-pipe `_,
+   `android-cloexec-pipe `_, "Yes"
`android-cloexec-pipe2 `_,
`android-cloexec-socket `_,
-   `android-comparison-in-temp-failure-retry 
`_, "Yes"
+   `android-comparison-in-temp-failure-retry 
`_,
`boost-use-to-string `_, "Yes"
`bugprone-argument-comment `_, "Yes"
`bugprone-assert-side-effect `_,
@@ -58,8 +62,8 @@ Clang-Tidy Checks
`bugprone-lambda-function-name `_,
`bugprone-macro-parentheses `_, "Yes"
`bugprone-macro-repeated-side-effects 
`_,
-   `bugprone-misplaced-operator-in-strlen-in-alloc 
`_,
-   `bugprone-misplaced-widening-cast 
`_, "Yes"
+   `bugprone-misplaced-operator-in-strlen-in-alloc 
`_, "Yes"
+   `bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference 
`_, "Yes"
`bugprone-multiple-statement-macro 
`_,
`bugprone-not-null-terminated-result 
`_, "Yes"
@@ -149,19 +153,19 @@ Clang-Tidy Checks
`fuchsia-statically-constructed-objects 
`_,
`fuchsia-trailing-return `_,
`fuchsia-virtual-inheritance `_,
-   `google-build-explicit-make-pair `_, 
"Yes"
+   `google-build-explicit-make-pair `_,
`google-build-namespaces `_,
`google-build-using-namespace `_,
`google-default-arguments `_,
`google-explicit-constructor `_, "Yes"
-   `google-global-names-in-headers `_, 
"Yes"
-   `google-objc-avoid-nsobject-new `_, 
"Yes"
+   `google-global-names-in-headers `_,
+   `google-objc-avoid-nsobject-new `_,
`google-objc-avoid-throwing-exception 
`_,
-   `google-objc-function-naming `_, "Yes"
+   `google-objc-function-naming `_,
`google-objc-global-variable-declaration 
`_,
`google-readability-avoid-underscore-in-googletest-name 
`_,
-   `google-readability-casting `_, "Yes"
-   `google-readability-todo `_, "Yes"
+   `google-readability-casting `_,
+   `google-readability-todo `_,
`google-runtime-int `_,
`google-runtime-operator `_,
`google-runtime-references `_,
@@ -197,7 +201,7 @@ Clang-Tidy Checks
`modernize-deprecated-headers `_, "Yes"
`modernize-deprecated-ios-base-aliases 
`_, "Yes"
`modernize-loop-convert `_, "Yes"
-   `modernize-make-shared `_, "Yes"
+   `modernize-make-shared `_,
`modernize-make-unique `_, "Yes"
`modernize-pass-by-value `_, "Yes"
`modernize-raw-string-literal `_, "Yes"
@@ -237,19 +241,19 @@ Clang-Tidy Checks
`performance-inefficient-string-concatenation 
`_,
`performance-inefficient-vector-operation 
`_, "Yes"
`performance-move-const-arg `_, "Yes"
-   

[clang-tools-extra] f3db1aa - MakeUniqueCheck.cpp: explicit the fact that there is an autofix for this checker

2020-01-10 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2020-01-10T22:06:03+01:00
New Revision: f3db1aad2796c62f0d188a74f2901c18e51843c2

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

LOG: MakeUniqueCheck.cpp: explicit the fact that there is an autofix for this 
checker

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp
index 1ee4fd701d8c..e2f812b35aea 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -41,6 +41,8 @@ bool MakeUniqueCheck::isLanguageVersionSupported(
   return RequireCPlusPlus14 ? LangOpts.CPlusPlus14 : LangOpts.CPlusPlus11;
 }
 
+// FixItHint is done by MakeSmartPtrCheck
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 237422.
njames93 added a comment.

- Reworked options documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.cpp
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cert-oop57-cpp %t -- \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cert-oop57-cpp.MemSetNames, value: mymemset}, \
+// RUN:  {key: cert-oop57-cpp.MemCpyNames, value: mymemcpy}, \
+// RUN:  {key: cert-oop57-cpp.MemCmpNames, value: mymemcmp}]}' \
+// RUN: --
+
+void mymemset(void *, unsigned char, decltype(sizeof(int)));
+void mymemcpy(void *, const void *, decltype(sizeof(int)));
+int mymemcmp(const void *, const void *, decltype(sizeof(int)));
+
+namespace std {
+void memset(void *, unsigned char, decltype(sizeof(int)));
+void memcpy(void *, const void *, decltype(sizeof(int)));
+void memmove(void *, const void *, decltype(sizeof(int)));
+void strcpy(void *, const void *, decltype(sizeof(int)));
+int memcmp(const void *, const void *, decltype(sizeof(int)));
+int strcmp(const void *, const void *, decltype(sizeof(int)));
+} // namespace std
+
+struct Trivial {
+  int I;
+  int J;
+};
+
+struct NonTrivial {
+  int I;
+  int J;
+
+  NonTrivial() : I(0), J(0) {}
+  NonTrivial =(const NonTrivial ) {
+I = Other.I;
+J = Other.J;
+return *this;
+  }
+
+  bool operator==(const Trivial ) const {
+return I == Other.I && J == Other.J;
+  }
+  bool operator!=(const Trivial ) const {
+return !(*this == Other);
+  }
+};
+
+void foo(const Trivial ) {
+  Trivial Data;
+  std::memset(, 0, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memset(, 0, sizeof(Trivial));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void bar(const NonTrivial ) {
+  NonTrivial Data;
+  std::memset(, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  // Check it detects sizeof(Type) as well as sizeof(Instantiation)
+  std::memset(, 0, sizeof(NonTrivial));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void baz(const NonTrivial ) {
+  NonTrivial Data;
+  mymemset(, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'mymemset' on a non trivially default constructible class is undefined
+  mymemcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'mymemcpy' on a non trivially copyable class is undefined
+  mymemcmp(, , 

[PATCH] D72414: Add new AST matcher `hasAnyCapture`

2020-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thank you! I have commit on your behalf in 
4ffcec40acebae7161ac7426edc68290bbaca2b8 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72414



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


[clang] 4ffcec4 - Implement new AST matcher hasAnyCapture to match on LambdaExpr captures.

2020-01-10 Thread Aaron Ballman via cfe-commits

Author: Reid
Date: 2020-01-10T15:49:43-05:00
New Revision: 4ffcec40acebae7161ac7426edc68290bbaca2b8

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

LOG: Implement new AST matcher hasAnyCapture to match on LambdaExpr captures.

Accepts child matchers cxxThisExpr to match on capture of this and also on 
varDecl.

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 05562c543c47..5bb181b04d3a 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -6390,6 +6390,33 @@ AST Traversal Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html;>LambdaExprhasAnyCaptureMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html;>CXXThisExpr
 InnerMatcher
+Matches any capture 
of 'this' in a lambda expression.
+
+Given
+  struct foo {
+void bar() {
+  auto f = [this](){};
+}
+  }
+lambdaExpr(hasAnyCapture(cxxThisExpr()))
+  matches [this](){};
+
+
+
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html;>LambdaExprhasAnyCaptureMatcherhttps://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl
 InnerMatcher
+Matches any capture 
of a lambda expression.
+
+Given
+  void foo() {
+int x;
+auto f = [x](){};
+  }
+lambdaExpr(hasAnyCapture(anything()))
+  matches [x](){};
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html;>MemberExprhasDeclarationconst Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl  
InnerMatcher
 Matches a node if 
the declaration associated with that node
 matches the given matcher.
@@ -7277,6 +7304,10 @@ AST Traversal Matchers
 
 
 
+MatcherTtraverseast_type_traits::TraversalKind TK, 
const BindableMatcherT  InnerMatcher
+
+
+
 MatcherTtraverseast_type_traits::TraversalKind TK, 
const MatcherT  InnerMatcher
 Causes all nested matchers 
to be matched with the specified traversal kind.
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 71cb85264bc2..9a5888b7572b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -55,6 +55,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenMPClause.h"
 #include "clang/AST/OperationKinds.h"
@@ -4044,6 +4045,50 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
   return false;
 }
 
+/// Matches any capture of a lambda expression.
+///
+/// Given
+/// \code
+///   void foo() {
+/// int x;
+/// auto f = [x](){};
+///   }
+/// \endcode
+/// lambdaExpr(hasAnyCapture(anything()))
+///   matches [x](){};
+AST_MATCHER_P_OVERLOAD(LambdaExpr, hasAnyCapture, internal::Matcher,
+   InnerMatcher, 0) {
+  for (const LambdaCapture  : Node.captures()) {
+if (Capture.capturesVariable()) {
+  BoundNodesTreeBuilder Result(*Builder);
+  if (InnerMatcher.matches(*Capture.getCapturedVar(), Finder, )) {
+*Builder = std::move(Result);
+return true;
+  }
+}
+  }
+  return false;
+}
+
+/// Matches any capture of 'this' in a lambda expression.
+///
+/// Given
+/// \code
+///   struct foo {
+/// void bar() {
+///   auto f = [this](){};
+/// }
+///   }
+/// \endcode
+/// lambdaExpr(hasAnyCapture(cxxThisExpr()))
+///   matches [this](){};
+AST_MATCHER_P_OVERLOAD(LambdaExpr, hasAnyCapture,
+   internal::Matcher, InnerMatcher, 1) {
+  return llvm::any_of(Node.captures(), [](const LambdaCapture ) {
+return LC.capturesThis();
+  });
+}
+
 /// Matches a constructor call expression which uses list initialization.
 AST_MATCHER(CXXConstructExpr, isListInitialization) {
   return Node.isListInitialization();

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 475818bc3ae5..1c0930c5983a 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -105,6 +105,7 @@ RegistryMaps::RegistryMaps() {
   // equalsNode
 
   REGISTER_OVERLOADED_2(callee);
+  REGISTER_OVERLOADED_2(hasAnyCapture);
   REGISTER_OVERLOADED_2(hasPrefix);
   REGISTER_OVERLOADED_2(hasType);
   REGISTER_OVERLOADED_2(ignoringParens);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ee7b3bfd5b1b..23447baf912b 100644

[PATCH] D72531: Set traversal explicitly where needed in tests

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 237418.
steveire added a comment.

Fix case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,7 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -331,8 +331,8 @@
 };
   )cc";
   auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  matchStmt(Snippet, traverse(ast_type_traits::TK_AsIs, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+ hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope RAII(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
@@ -101,8 +102,8 @@
   decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
  .bind("init")))
   .bind("decl")))
-  .bind("expr")))
-  .bind("stmt");
+  .bind("expr"))
+).bind("stmt");
 
   return Selector(matchCode(Code, Matcher).Result);
 }
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,8 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(),
+ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
@@ -1129,6 +1131,7 @@
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
+  // return;
 
   AST = buildASTFromCode("void f() { int x, y; __typeof(x = 10) z = y; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
@@ -1158,7 +1161,7 @@
 
   AST = buildASTFromCode(
   "void f() { int x; _Generic(x = 10, int: 0, default: 1); }");
-  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  Results = match(traverse(ast_type_traits::TK_AsIs, withEnclosingCompound(declRefTo("x"))), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
 }
 
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ 

[PATCH] D72530: Set traversal explicitly where needed in clang-tidy

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 237417.
steveire added a comment.

Fix case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72530

Files:
  clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp
  clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
  clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StrCatAppendCheck.cpp
  clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
  clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp
  clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
  clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ShrinkToFitCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
  clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
  clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
  clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.cpp
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  
clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
  clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
  clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
  

[PATCH] D72233: Add a new AST matcher 'optionally'.

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

LGTM too. I described a more ad-hoc implementation previously: 
https://steveire.wordpress.com/2018/11/20/composing-ast-matchers-in-clang-tidy/ 
but I prefer this implementation.


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

https://reviews.llvm.org/D72233



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


[PATCH] D72414: Add new AST matcher `hasAnyCapture`

2020-01-10 Thread Reid via Phabricator via cfe-commits
rhiro added a comment.

In D72414#1814831 , @aaron.ballman 
wrote:

> LGTM! Do you need someone to commit on your behalf?


Yes, please.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72414



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


[PATCH] D69868: Allow "callbr" to return non-void values

2020-01-10 Thread Bill Wendling via Phabricator via cfe-commits
void marked an inline comment as done.
void added inline comments.



Comment at: llvm/lib/CodeGen/MachineVerifier.cpp:701
+  } else if (MBB->succ_size() == LandingPadSuccs.size() ||
+ MBB->succ_size() == IndirectPadSuccs.size()) {
 // It's possible that the block legitimately ends with a noreturn

jyknight wrote:
> This isn't correct.
> 
> This line here, is looking at a block which doesn't end in a jump to a 
> successor. So, it's trying to verify that the successor list makes sense in 
> that context.
> 
> The unstated assumption in the code is that the only successors will be 
> landing pads. Instead of actually checking each one, instead it just checks 
> that the count is the number of landing pads, with the assumption that all 
> the successors should be landing pads, and that all the landing pads should 
> be successors.
> 
> The next clause is then checking for the case where there's a fallthrough to 
> the next block. In that case, the successors should've been all the landing 
> pads, and the single fallthrough block.
> 
> Adding similar code to check for the number of callbr targets doesn't really 
> make sense. It's certainly not the case that all callbr targets are targets 
> of all 
> callbr instructions. And even if it was, this still wouldn't be counting 
> things correctly.
> 
> 
> However -- I think i'd expect analyzeBranch to error out (returning true) 
> when confronted by a callbr instruction, because it cannot actually tell 
> what's going on there. If that were the case, nothing in this block should 
> even be invoked. But I guess that's probably not happening, due to the 
> terminator being followed by non-terminators.
> 
> That seems likely to be a problem that needs to be fixed. (And if that is 
> fixed, I think the changes here aren't needed anymore)
> 
> 
Your comment is very confusing. Could you please give an example of where this 
fails?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69868



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


[PATCH] D69868: Allow "callbr" to return non-void values

2020-01-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: llvm/lib/CodeGen/MachineVerifier.cpp:701
+  } else if (MBB->succ_size() == LandingPadSuccs.size() ||
+ MBB->succ_size() == IndirectPadSuccs.size()) {
 // It's possible that the block legitimately ends with a noreturn

This isn't correct.

This line here, is looking at a block which doesn't end in a jump to a 
successor. So, it's trying to verify that the successor list makes sense in 
that context.

The unstated assumption in the code is that the only successors will be landing 
pads. Instead of actually checking each one, instead it just checks that the 
count is the number of landing pads, with the assumption that all the 
successors should be landing pads, and that all the landing pads should be 
successors.

The next clause is then checking for the case where there's a fallthrough to 
the next block. In that case, the successors should've been all the landing 
pads, and the single fallthrough block.

Adding similar code to check for the number of callbr targets doesn't really 
make sense. It's certainly not the case that all callbr targets are targets of 
all 
callbr instructions. And even if it was, this still wouldn't be counting things 
correctly.


However -- I think i'd expect analyzeBranch to error out (returning true) when 
confronted by a callbr instruction, because it cannot actually tell what's 
going on there. If that were the case, nothing in this block should even be 
invoked. But I guess that's probably not happening, due to the terminator being 
followed by non-terminators.

That seems likely to be a problem that needs to be fixed. (And if that is 
fixed, I think the changes here aren't needed anymore)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69868



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


[PATCH] D72427: [DebugInfo] Add option to clang to limit debug info that is emitted for classes.

2020-01-10 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 237411.
akhuang added a comment.

Address comments

- Removed driver option
- Simplified test cases
- Changed name of limited debug info from isFullDebug to hasReducedDebugInfo, 
which is maybe

slightly less misleading


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72427

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DebugInfoOptions.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/debug-info-limited-ctor.cpp

Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -cc1 -debug-info-kind=constructor -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
+// CHECK-NOT:  DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
+struct A {};
+void TestA() { A a; }
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "B"
+// CHECK-SAME: flags: DIFlagFwdDecl
+struct B {};
+int bar(B *b);
+int TestB(B *b) {
+  return bar(b);
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "C"
+// CHECK-SAME: flags: DIFlagFwdDecl
+struct C {
+  C();
+};
+void TestC() { C c; }
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D"
+// CHECK-NOT:  flags: DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
+struct D {
+  D() {}
+};
+void TestD() { D d; }
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "E"
+// CHECK-NOT:  flags: DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
+struct E {
+  E();
+};
+E::E() {}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -731,6 +731,7 @@
 llvm::StringSwitch(A->getValue())
 .Case("line-tables-only", codegenoptions::DebugLineTablesOnly)
 .Case("line-directives-only", codegenoptions::DebugDirectivesOnly)
+.Case("constructor", codegenoptions::DebugInfoConstructor)
 .Case("limited", codegenoptions::LimitedDebugInfo)
 .Case("standalone", codegenoptions::FullDebugInfo)
 .Default(~0U);
@@ -787,8 +788,7 @@
   llvm::Triple::arm, llvm::Triple::armeb};
 
   llvm::Triple T(TargetOpts.Triple);
-  if (Opts.OptimizationLevel > 0 &&
-  Opts.getDebugInfo() >= codegenoptions::LimitedDebugInfo &&
+  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EnableDebugEntryValues = Args.hasArg(OPT_femit_debug_entry_values);
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -999,6 +999,9 @@
   case codegenoptions::DebugLineTablesOnly:
 CmdArgs.push_back("-debug-info-kind=line-tables-only");
 break;
+  case codegenoptions::DebugInfoConstructor:
+CmdArgs.push_back("-debug-info-kind=constructor");
+break;
   case codegenoptions::LimitedDebugInfo:
 CmdArgs.push_back("-debug-info-kind=limited");
 break;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4113,13 +4113,13 @@
 
   // Emit global variable debug information.
   if (CGDebugInfo *DI = getModuleDebugInfo())
-if (getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo)
+if (getCodeGenOpts().hasReducedDebugInfo())
   DI->EmitGlobalVariable(GV, D);
 }
 
 void CodeGenModule::EmitExternalVarDeclaration(const VarDecl *D) {
   if (CGDebugInfo *DI = getModuleDebugInfo())
-if (getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo) {
+if (getCodeGenOpts().hasReducedDebugInfo()) {
   QualType ASTTy = D->getType();
   llvm::Type *Ty = getTypes().ConvertTypeForMem(D->getType());
   llvm::PointerType *PTy =
@@ -5366,7 +5366,7 @@
 ObjCRuntime->GenerateClass(OMD);
 // Emit global variable debug information.
 if (CGDebugInfo *DI = getModuleDebugInfo())
-  if (getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo)
+  if (getCodeGenOpts().hasReducedDebugInfo())
 DI->getOrCreateInterfaceType(getContext().getObjCInterfaceType(
 OMD->getClassInterface()), 

[PATCH] D72414: Add new AST matcher `hasAnyCapture`

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

LGTM! Do you need someone to commit on your behalf?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72414



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


[PATCH] D72532: Make the ExprMutationAnalyzer explicit about how it traverses the AST

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72532

Files:
  clang/lib/Analysis/ExprMutationAnalyzer.cpp


Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -284,11 +284,12 @@
 
maybeEvalCommaExpr(equalsNode(Exp;
 
   const auto Matches =
-  match(findAll(stmt(anyOf(AsAssignmentLhs, AsIncDecOperand, 
AsNonConstThis,
+  match(traverse(ast_type_traits::TK_AsIs,
+findAll(stmt(anyOf(AsAssignmentLhs, AsIncDecOperand, AsNonConstThis,
AsAmpersandOperand, AsPointerFromArrayDecay,
AsOperatorArrowThis, AsNonConstRefArg,
AsLambdaRefCaptureInit, AsNonConstRefReturn))
-.bind("stmt")),
+.bind("stmt"))),
 Stm, Context);
   return selectFirst("stmt", Matches);
 }
@@ -387,13 +388,13 @@
   parmVarDecl(hasType(nonConstReferenceType())).bind("parm"));
   const auto IsInstantiated = hasDeclaration(isInstantiated());
   const auto FuncDecl = hasDeclaration(functionDecl().bind("func"));
-  const auto Matches = match(
+  const auto Matches = match(traverse(ast_type_traits::TK_AsIs,
   findAll(expr(anyOf(callExpr(NonConstRefParam, IsInstantiated, FuncDecl,
   unless(callee(namedDecl(hasAnyName(
   "::std::move", "::std::forward"),
  cxxConstructExpr(NonConstRefParam, IsInstantiated,
   FuncDecl)))
-  .bind(NodeID::value)),
+  .bind(NodeID::value))),
   Stm, Context);
   for (const auto  : Matches) {
 const auto *Exp = Nodes.getNodeAs(NodeID::value);


Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -284,11 +284,12 @@
 maybeEvalCommaExpr(equalsNode(Exp;
 
   const auto Matches =
-  match(findAll(stmt(anyOf(AsAssignmentLhs, AsIncDecOperand, AsNonConstThis,
+  match(traverse(ast_type_traits::TK_AsIs,
+findAll(stmt(anyOf(AsAssignmentLhs, AsIncDecOperand, AsNonConstThis,
AsAmpersandOperand, AsPointerFromArrayDecay,
AsOperatorArrowThis, AsNonConstRefArg,
AsLambdaRefCaptureInit, AsNonConstRefReturn))
-.bind("stmt")),
+.bind("stmt"))),
 Stm, Context);
   return selectFirst("stmt", Matches);
 }
@@ -387,13 +388,13 @@
   parmVarDecl(hasType(nonConstReferenceType())).bind("parm"));
   const auto IsInstantiated = hasDeclaration(isInstantiated());
   const auto FuncDecl = hasDeclaration(functionDecl().bind("func"));
-  const auto Matches = match(
+  const auto Matches = match(traverse(ast_type_traits::TK_AsIs,
   findAll(expr(anyOf(callExpr(NonConstRefParam, IsInstantiated, FuncDecl,
   unless(callee(namedDecl(hasAnyName(
   "::std::move", "::std::forward"),
  cxxConstructExpr(NonConstRefParam, IsInstantiated,
   FuncDecl)))
-  .bind(NodeID::value)),
+  .bind(NodeID::value))),
   Stm, Context);
   for (const auto  : Matches) {
 const auto *Exp = Nodes.getNodeAs(NodeID::value);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72530: Set traversal explicitly where needed in clang-tidy

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added subscribers: cfe-commits, arphaman, kbarton, nemanjai.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72530

Files:
  clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp
  clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
  clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StrCatAppendCheck.cpp
  clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
  clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp
  clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
  clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ShrinkToFitCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
  clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
  clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
  clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.cpp
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  
clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
  clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
  clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
  

[PATCH] D72534: Change default traversal in AST Matchers to ignore invisible nodes

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72534

Files:
  clang/include/clang/AST/ASTContext.h


Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -561,7 +561,8 @@
   clang::PrintingPolicy PrintingPolicy;
   std::unique_ptr InterpContext;
 
-  ast_type_traits::TraversalKind Traversal = ast_type_traits::TK_AsIs;
+  ast_type_traits::TraversalKind Traversal =
+  ast_type_traits::TK_IgnoreUnlessSpelledInSource;
 
 public:
   ast_type_traits::TraversalKind getTraversalKind() const { return Traversal; }


Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -561,7 +561,8 @@
   clang::PrintingPolicy PrintingPolicy;
   std::unique_ptr InterpContext;
 
-  ast_type_traits::TraversalKind Traversal = ast_type_traits::TK_AsIs;
+  ast_type_traits::TraversalKind Traversal =
+  ast_type_traits::TK_IgnoreUnlessSpelledInSource;
 
 public:
   ast_type_traits::TraversalKind getTraversalKind() const { return Traversal; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a reviewer: shafik.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,7 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -331,8 +331,8 @@
 };
   )cc";
   auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  matchStmt(Snippet, traverse(ast_type_traits::TK_AsIs, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+ hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope raii(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
@@ -101,8 +102,8 @@
   decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
  .bind("init")))
   .bind("decl")))
-  .bind("expr")))
-  .bind("stmt");
+  .bind("expr"))
+).bind("stmt");
 
   return Selector(matchCode(Code, Matcher).Result);
 }
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,8 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(),
+ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
@@ -1129,6 +1131,7 @@
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
+  // return;
 
   AST = buildASTFromCode("void f() { int x, y; __typeof(x = 10) z = y; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
@@ -1158,7 +1161,7 @@
 
   AST = buildASTFromCode(
   "void f() { int x; _Generic(x = 10, int: 0, default: 1); }");
-  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  Results = match(traverse(ast_type_traits::TK_AsIs, withEnclosingCompound(declRefTo("x"))), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
 }
 
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- 

[PATCH] D69878: Consoldiate internal denormal flushing controls

2020-01-10 Thread Cameron McInally via Phabricator via cfe-commits
cameron.mcinally added inline comments.



Comment at: llvm/docs/LangRef.rst:1837
+   are present, this overrides ``"denormal-fp-math"``. Not all targets
+   support separately setting the denormal mode per type.
+

arsenm wrote:
> andrew.w.kaylor wrote:
> > cameron.mcinally wrote:
> > > andrew.w.kaylor wrote:
> > > > arsenm wrote:
> > > > > andrew.w.kaylor wrote:
> > > > > > arsenm wrote:
> > > > > > > andrew.w.kaylor wrote:
> > > > > > > > Can you document which targets do support the option? What 
> > > > > > > > happens if I try to use the option on a target where it is not 
> > > > > > > > supported?
> > > > > > > I'm not sure where to document this, or if/how/where to diagnose 
> > > > > > > it. I don't think the high level LangRef description is the right 
> > > > > > > place to discuss specific target handling.
> > > > > > > 
> > > > > > > Currently it won't error or anything. Code checking the denorm 
> > > > > > > mode will see the f32 specific mode, even if the target in the 
> > > > > > > end isn't really going to respect this.
> > > > > > > 
> > > > > > > One problem is this potentially does require coordination with 
> > > > > > > other toolchain components. For AMDGPU, the compiler can directly 
> > > > > > > tell the driver what FP mode to set on each entry point, but for 
> > > > > > > x86 it requires linking in crtfastmath to set the default mode 
> > > > > > > bits. If another target had a similar runtime environment 
> > > > > > > requirement, I don't think we can be sure the attribute is 
> > > > > > > correct or not.
> > > > > > There is precedent for describing target-specific behavior in 
> > > > > > LangRef. It just doesn't seem useful to say that not all targets 
> > > > > > support the attribute without saying which ones do. We should also 
> > > > > > say what is expected if a target doesn't support the attribute. It 
> > > > > > seems reasonable for the function attribute to be silently ignored.
> > > > > > 
> > > > > > > One problem is this potentially does require coordination with 
> > > > > > > other toolchain components. For AMDGPU, the compiler can directly 
> > > > > > > tell the driver what FP mode to set on each entry point, but for 
> > > > > > > x86 it requires linking in crtfastmath to set the default mode 
> > > > > > > bits.
> > > > > > 
> > > > > > This is a point I'm interested in. I don't like the current 
> > > > > > crtfastmath.o handling. It feels almost accidental when FTZ works 
> > > > > > as expected. My understanding is we link crtfastmath.o if we find 
> > > > > > it but if not everything just goes about its business. The Intel 
> > > > > > compiler injects code into main() to explicitly set the FTZ/DAZ 
> > > > > > control modes. That obviously has problems too, but it's at least 
> > > > > > consistent and predictable. As I understand it, crtfastmath.o sets 
> > > > > > these modes from a static initializer, but I'm not sure anything is 
> > > > > > done to determine the order of that initializer relative to others.
> > > > > > 
> > > > > > How does the compiler identify entry points for AMDGPU? And does it 
> > > > > > emit code to set FTZ based on the function attribute here?
> > > > > The entry points are a specific calling convention. There's no real 
> > > > > concept of main. Each kernel has an associated blob of metadata the 
> > > > > driver uses to set up various config registers on dispatch.
> > > > > 
> > > > > I don't think specially recognizing main in the compiler is 
> > > > > fundamentally different than having it done in a static constructor. 
> > > > > It's still a construct not associated with any particular function or 
> > > > > anything.
> > > > The problem with having it done in a static constructor is that you 
> > > > have no certainty of when it will be done relative to other static 
> > > > constructors. If it's in main you can at least say that it's after all 
> > > > the static constructors (assuming main is your entry point).
> > > Yes and no. The linker should honor static constructor priorities. But, 
> > > yeah, there's no guarantee that this constructor will run before other 
> > > priority 101 constructors.
> > > 
> > > The performance penalty for setting denormal flushing in main could be 
> > > significant (think C++). Also, there's precedent for using static 
> > > constructors, like GCC's crtfastmath.o.
> > Fair enough. I don't necessarily like how icc handles this. I don't have a 
> > problem with how gcc handles it. I just really don't like how LLVM does it. 
> > If we want to take the static constructor approach we should define our 
> > own, not depend on whether or not the GNU object file happens to be around.
> > 
> > Static initialization doesn't help for AMDGPU, and I suppose that's likely 
> > to be the case for any offload execution model. Since this patch is moving 
> > us toward a more consistent implementation I'm wondering if we can define 
> > some general rules 

[clang] 55d7b22 - [ASTMatchers] Make test more clear about what it is verifying

2020-01-10 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-01-10T19:47:12Z
New Revision: 55d7b22277e1c5e710bac7d4d4dc09db3a22dad8

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

LOG: [ASTMatchers] Make test more clear about what it is verifying

Added: 


Modified: 
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 6ca54df06571..ee7b3bfd5b1b 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1639,9 +1639,12 @@ void foo()
   EXPECT_TRUE(matches(VarDeclCode, varDecl(traverse(ast_type_traits::TK_AsIs,
 
has(implicitCastExpr());
 
-  EXPECT_TRUE(notMatches(
+  EXPECT_TRUE(matches(
   VarDeclCode,
-  varDecl(has(traverse(ast_type_traits::TK_AsIs, floatLiteral());
+  traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
+// The has() below strips away the ImplicitCastExpr before the
+// traverse(AsIs) gets to process it.
+varDecl(has(traverse(ast_type_traits::TK_AsIs, floatLiteral()));
 
   EXPECT_TRUE(matches(
   VarDeclCode,



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


[PATCH] D72433: [Driver][PowerPC] Move powerpcspe logic from cc1 to Driver

2020-01-10 Thread Justin Hibbits via Phabricator via cfe-commits
jhibbits accepted this revision.
jhibbits added a comment.
This revision is now accepted and ready to land.

Fine with me.  I just wanted -target powerpcspe-... to work with D72014 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72433



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


[PATCH] D72433: [Driver][PowerPC] Move powerpcspe logic from cc1 to Driver

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba91dffafe4d: [Driver][PowerPC] Move powerpcspe logic from 
cc1 to Driver (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72433

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Driver/ppc-features.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -6551,7 +6551,6 @@
 // PPC32-LINUX-NOT: _CALL_LINUX
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu 
-target-feature +spe < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC32-SPE %s
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpcspe-unknown-linux-gnu 
< /dev/null | FileCheck -match-full-lines -check-prefix PPC32-SPE %s
 //
 // PPC32-SPE:#define __NO_FPRS__ 1
 // PPC32-SPE:#define __SPE__ 1
Index: clang/test/Driver/ppc-features.cpp
===
--- clang/test/Driver/ppc-features.cpp
+++ clang/test/Driver/ppc-features.cpp
@@ -168,8 +168,11 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s 
-mno-invariant-function-descriptors -minvariant-function-descriptors -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CHECK-INVFUNCDESC %s
 // CHECK-INVFUNCDESC: "-target-feature" "+invariant-function-descriptors"
 
-// RUN: %clang -target powerpc-unknown-linux-gnu %s -mno-spe -mspe -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpc %s -mno-spe -mspe -c -### 2>&1 | FileCheck 
-check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpcspe %s -c -### 2>&1 | FileCheck 
-check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpcspe %s -mno-spe -c -### 2>&1 | FileCheck 
-check-prefix=CHECK-NOSPE %s
 // CHECK-SPE: "-target-feature" "+spe"
+// CHECK-NOSPE: "-target-feature" "-spe"
 
 // Assembler features
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
-no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_BE_AS_ARGS %s
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -104,6 +104,9 @@
 void ppc::getPPCTargetFeatures(const Driver , const llvm::Triple ,
const ArgList ,
std::vector ) {
+  if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
+Features.push_back("+spe");
+
   handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
 
   ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -316,8 +316,7 @@
 .Case("pwr8", true)
 .Default(false);
 
-  Features["spe"] = getTriple().getSubArch() == llvm::Triple::PPCSubArch_spe ||
-llvm::StringSwitch(CPU)
+  Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
 .Case("e500", true)
 .Default(false);


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -6551,7 +6551,6 @@
 // PPC32-LINUX-NOT: _CALL_LINUX
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu -target-feature +spe < /dev/null | FileCheck -match-full-lines -check-prefix PPC32-SPE %s
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpcspe-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC32-SPE %s
 //
 // PPC32-SPE:#define __NO_FPRS__ 1
 // PPC32-SPE:#define __SPE__ 1
Index: clang/test/Driver/ppc-features.cpp
===
--- clang/test/Driver/ppc-features.cpp
+++ clang/test/Driver/ppc-features.cpp
@@ -168,8 +168,11 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-invariant-function-descriptors -minvariant-function-descriptors -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-INVFUNCDESC %s
 // CHECK-INVFUNCDESC: "-target-feature" "+invariant-function-descriptors"
 
-// RUN: %clang -target powerpc-unknown-linux-gnu %s -mno-spe -mspe -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpc %s -mno-spe -mspe -c -### 2>&1 | FileCheck -check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpcspe %s -c -### 2>&1 | FileCheck -check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpcspe %s -mno-spe -c -### 2>&1 | FileCheck -check-prefix=CHECK-NOSPE %s
 // 

[clang] ba91dff - [Driver][PowerPC] Move powerpcspe logic from cc1 to Driver

2020-01-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-01-10T11:43:17-08:00
New Revision: ba91dffafe4d348b469d8ae2b7b1cd00754f72f1

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

LOG: [Driver][PowerPC] Move powerpcspe logic from cc1 to Driver

Follow-up of D72014. It is more appropriate to use a target
feature instead of a SubTypeArch to express the difference.

Reviewed By: #powerpc, jhibbits

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

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.cpp
clang/lib/Driver/ToolChains/Arch/PPC.cpp
clang/test/Driver/ppc-features.cpp
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index bc0ffb7fa440..1877d4a5ef70 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -316,8 +316,7 @@ bool PPCTargetInfo::initFeatureMap(
 .Case("pwr8", true)
 .Default(false);
 
-  Features["spe"] = getTriple().getSubArch() == llvm::Triple::PPCSubArch_spe ||
-llvm::StringSwitch(CPU)
+  Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
 .Case("e500", true)
 .Default(false);

diff  --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 625f7cb2f1f3..f1baadaebf41 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -104,6 +104,9 @@ const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
 void ppc::getPPCTargetFeatures(const Driver , const llvm::Triple ,
const ArgList ,
std::vector ) {
+  if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
+Features.push_back("+spe");
+
   handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
 
   ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);

diff  --git a/clang/test/Driver/ppc-features.cpp 
b/clang/test/Driver/ppc-features.cpp
index f6f2c78903d0..d21774cc6175 100644
--- a/clang/test/Driver/ppc-features.cpp
+++ b/clang/test/Driver/ppc-features.cpp
@@ -168,8 +168,11 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s 
-mno-invariant-function-descriptors -minvariant-function-descriptors -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CHECK-INVFUNCDESC %s
 // CHECK-INVFUNCDESC: "-target-feature" "+invariant-function-descriptors"
 
-// RUN: %clang -target powerpc-unknown-linux-gnu %s -mno-spe -mspe -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpc %s -mno-spe -mspe -c -### 2>&1 | FileCheck 
-check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpcspe %s -c -### 2>&1 | FileCheck 
-check-prefix=CHECK-SPE %s
+// RUN: %clang -target powerpcspe %s -mno-spe -c -### 2>&1 | FileCheck 
-check-prefix=CHECK-NOSPE %s
 // CHECK-SPE: "-target-feature" "+spe"
+// CHECK-NOSPE: "-target-feature" "-spe"
 
 // Assembler features
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
-no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_BE_AS_ARGS %s

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index a03725889360..e25946304d0f 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -6551,7 +6551,6 @@
 // PPC32-LINUX-NOT: _CALL_LINUX
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu 
-target-feature +spe < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC32-SPE %s
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpcspe-unknown-linux-gnu 
< /dev/null | FileCheck -match-full-lines -check-prefix PPC32-SPE %s
 //
 // PPC32-SPE:#define __NO_FPRS__ 1
 // PPC32-SPE:#define __SPE__ 1



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


[PATCH] D69878: Consoldiate internal denormal flushing controls

2020-01-10 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm marked an inline comment as done.
arsenm added inline comments.



Comment at: llvm/docs/LangRef.rst:1837
+   are present, this overrides ``"denormal-fp-math"``. Not all targets
+   support separately setting the denormal mode per type.
+

andrew.w.kaylor wrote:
> cameron.mcinally wrote:
> > andrew.w.kaylor wrote:
> > > arsenm wrote:
> > > > andrew.w.kaylor wrote:
> > > > > arsenm wrote:
> > > > > > andrew.w.kaylor wrote:
> > > > > > > Can you document which targets do support the option? What 
> > > > > > > happens if I try to use the option on a target where it is not 
> > > > > > > supported?
> > > > > > I'm not sure where to document this, or if/how/where to diagnose 
> > > > > > it. I don't think the high level LangRef description is the right 
> > > > > > place to discuss specific target handling.
> > > > > > 
> > > > > > Currently it won't error or anything. Code checking the denorm mode 
> > > > > > will see the f32 specific mode, even if the target in the end isn't 
> > > > > > really going to respect this.
> > > > > > 
> > > > > > One problem is this potentially does require coordination with 
> > > > > > other toolchain components. For AMDGPU, the compiler can directly 
> > > > > > tell the driver what FP mode to set on each entry point, but for 
> > > > > > x86 it requires linking in crtfastmath to set the default mode 
> > > > > > bits. If another target had a similar runtime environment 
> > > > > > requirement, I don't think we can be sure the attribute is correct 
> > > > > > or not.
> > > > > There is precedent for describing target-specific behavior in 
> > > > > LangRef. It just doesn't seem useful to say that not all targets 
> > > > > support the attribute without saying which ones do. We should also 
> > > > > say what is expected if a target doesn't support the attribute. It 
> > > > > seems reasonable for the function attribute to be silently ignored.
> > > > > 
> > > > > > One problem is this potentially does require coordination with 
> > > > > > other toolchain components. For AMDGPU, the compiler can directly 
> > > > > > tell the driver what FP mode to set on each entry point, but for 
> > > > > > x86 it requires linking in crtfastmath to set the default mode bits.
> > > > > 
> > > > > This is a point I'm interested in. I don't like the current 
> > > > > crtfastmath.o handling. It feels almost accidental when FTZ works as 
> > > > > expected. My understanding is we link crtfastmath.o if we find it but 
> > > > > if not everything just goes about its business. The Intel compiler 
> > > > > injects code into main() to explicitly set the FTZ/DAZ control modes. 
> > > > > That obviously has problems too, but it's at least consistent and 
> > > > > predictable. As I understand it, crtfastmath.o sets these modes from 
> > > > > a static initializer, but I'm not sure anything is done to determine 
> > > > > the order of that initializer relative to others.
> > > > > 
> > > > > How does the compiler identify entry points for AMDGPU? And does it 
> > > > > emit code to set FTZ based on the function attribute here?
> > > > The entry points are a specific calling convention. There's no real 
> > > > concept of main. Each kernel has an associated blob of metadata the 
> > > > driver uses to set up various config registers on dispatch.
> > > > 
> > > > I don't think specially recognizing main in the compiler is 
> > > > fundamentally different than having it done in a static constructor. 
> > > > It's still a construct not associated with any particular function or 
> > > > anything.
> > > The problem with having it done in a static constructor is that you have 
> > > no certainty of when it will be done relative to other static 
> > > constructors. If it's in main you can at least say that it's after all 
> > > the static constructors (assuming main is your entry point).
> > Yes and no. The linker should honor static constructor priorities. But, 
> > yeah, there's no guarantee that this constructor will run before other 
> > priority 101 constructors.
> > 
> > The performance penalty for setting denormal flushing in main could be 
> > significant (think C++). Also, there's precedent for using static 
> > constructors, like GCC's crtfastmath.o.
> Fair enough. I don't necessarily like how icc handles this. I don't have a 
> problem with how gcc handles it. I just really don't like how LLVM does it. 
> If we want to take the static constructor approach we should define our own, 
> not depend on whether or not the GNU object file happens to be around.
> 
> Static initialization doesn't help for AMDGPU, and I suppose that's likely to 
> be the case for any offload execution model. Since this patch is moving us 
> toward a more consistent implementation I'm wondering if we can define some 
> general rules for how this is supposed to work. Like when the function 
> attribute will result in injected instructions setting the control flags and 
> when it 

[PATCH] D72427: [DebugInfo] Add option to clang to limit debug info that is emitted for classes.

2020-01-10 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked 5 inline comments as done.
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:4516
 void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue ) 
{
-  assert(DebugKind >= codegenoptions::LimitedDebugInfo);
+  assert(CGM.getCodeGenOpts().isFullDebug());
   if (VD->hasAttr())

aprantl wrote:
> akhuang wrote:
> > aprantl wrote:
> > > This change appears to be unnecessary?
> > Do you mean changing the DebugKind comparison?
> Yes, since the new kind is < Limited.
The new kind is supposed to do most of the same things as Limited, except 
slightly more limited, so I think the comparison needs to be changed? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72427



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


[PATCH] D72527: [clang-tidy] adjust scripts to subsubsections in Release Notes

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: aaron.ballman, alexfh, hokein.
Eugene.Zelenko added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

I added subsubsections for typical Clang-tidy entries in Release Notes, so now 
scripts are aware of this changes.

I don't have GitHub commit access, so please commit changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72527

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/rename_check.py


Index: clang-tools-extra/clang-tidy/rename_check.py
===
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -176,11 +176,11 @@
 
 for line in lines:
   if not note_added:
-match = re.search('Improvements to clang-tidy', line)
+match = re.search('Renamed checks', line)
 if match:
   header_found = True
 elif header_found:
-  if not line.startswith(''):
+  if not line.startswith(''):
 f.write("""
 - The '%s' check was renamed to :doc:`%s
   `
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -219,8 +219,8 @@
   with open(filename, 'r') as f:
 lines = f.readlines()
 
-  lineMatcher = re.compile('Improvements to clang-tidy')
-  nextSectionMatcher = re.compile('Improvements to clang-include-fixer')
+  lineMatcher = re.compile('New checks')
+  nextSectionMatcher = re.compile('New aliases')
   checkerMatcher = re.compile('- New :doc:`(.*)')
 
   print('Updating %s...' % filename)
@@ -249,12 +249,12 @@
   f.write(line)
   continue
 
-if line.startswith(''):
+if line.startswith(''):
   f.write(line)
   continue
 
 if header_found and add_note_here:
-  if not line.startswith(''):
+  if not line.startswith(''):
 f.write("""- New :doc:`%s
   ` check.
 


Index: clang-tools-extra/clang-tidy/rename_check.py
===
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -176,11 +176,11 @@
 
 for line in lines:
   if not note_added:
-match = re.search('Improvements to clang-tidy', line)
+match = re.search('Renamed checks', line)
 if match:
   header_found = True
 elif header_found:
-  if not line.startswith(''):
+  if not line.startswith(''):
 f.write("""
 - The '%s' check was renamed to :doc:`%s
   `
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -219,8 +219,8 @@
   with open(filename, 'r') as f:
 lines = f.readlines()
 
-  lineMatcher = re.compile('Improvements to clang-tidy')
-  nextSectionMatcher = re.compile('Improvements to clang-include-fixer')
+  lineMatcher = re.compile('New checks')
+  nextSectionMatcher = re.compile('New aliases')
   checkerMatcher = re.compile('- New :doc:`(.*)')
 
   print('Updating %s...' % filename)
@@ -249,12 +249,12 @@
   f.write(line)
   continue
 
-if line.startswith(''):
+if line.startswith(''):
   f.write(line)
   continue
 
 if header_found and add_note_here:
-  if not line.startswith(''):
+  if not line.startswith(''):
 f.write("""- New :doc:`%s
   ` check.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72409: [clang] Fix out-of-bounds memory access in ComputeLineNumbers

2020-01-10 Thread Jan Korous via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf28972facc1f: [clang] Fix out-of-bounds memory access in 
ComputeLineNumbers (authored by jkorous).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D72409?vs=237219=237399#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72409

Files:
  clang/lib/Basic/SourceManager.cpp
  clang/unittests/Basic/SourceManagerTest.cpp


Index: clang/unittests/Basic/SourceManagerTest.cpp
===
--- clang/unittests/Basic/SourceManagerTest.cpp
+++ clang/unittests/Basic/SourceManagerTest.cpp
@@ -20,7 +20,9 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Process.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -241,6 +243,28 @@
 "UTF-32 (LE)");
 }
 
+// Regression test - there was an out of bound access for buffers not 
terminated by zero.
+TEST_F(SourceManagerTest, getLineNumber) {
+  const unsigned pageSize = llvm::sys::Process::getPageSizeEstimate();
+  std::unique_ptr source(new char[pageSize]);
+  for(unsigned i = 0; i < pageSize; ++i) {
+source[i] = 'a';
+  }
+
+  std::unique_ptr Buf =
+  llvm::MemoryBuffer::getMemBuffer(
+llvm::MemoryBufferRef(
+  llvm::StringRef(source.get(), 3), "whatever"
+),
+false
+  );
+
+  FileID mainFileID = SourceMgr.createFileID(std::move(Buf));
+  SourceMgr.setMainFileID(mainFileID);
+
+  ASSERT_NO_FATAL_FAILURE(SourceMgr.getLineNumber(mainFileID, 1, nullptr));
+}
+
 #if defined(LLVM_ON_UNIX)
 
 TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1250,23 +1250,18 @@
 
   const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart();
   const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd();
+  const std::size_t BufLen = End - Buf;
   unsigned I = 0;
-  while (true) {
-// Skip over the contents of the line.
-while (Buf[I] != '\n' && Buf[I] != '\r' && Buf[I] != '\0')
-  ++I;
-
-if (Buf[I] == '\n' || Buf[I] == '\r') {
+  while (I < BufLen) {
+if (Buf[I] == '\n') {
+  LineOffsets.push_back(I + 1);
+} else if (Buf[I] == '\r') {
   // If this is \r\n, skip both characters.
-  if (Buf[I] == '\r' && Buf[I+1] == '\n')
+  if (I + 1 < BufLen && Buf[I + 1] == '\n')
 ++I;
-  ++I;
-  LineOffsets.push_back(I);
-} else {
-  // Otherwise, this is a NUL. If end of file, exit.
-  if (Buf+I == End) break;
-  ++I;
+  LineOffsets.push_back(I + 1);
 }
+++I;
   }
 
   // Copy the offsets into the FileInfo structure.


Index: clang/unittests/Basic/SourceManagerTest.cpp
===
--- clang/unittests/Basic/SourceManagerTest.cpp
+++ clang/unittests/Basic/SourceManagerTest.cpp
@@ -20,7 +20,9 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Process.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -241,6 +243,28 @@
 "UTF-32 (LE)");
 }
 
+// Regression test - there was an out of bound access for buffers not terminated by zero.
+TEST_F(SourceManagerTest, getLineNumber) {
+  const unsigned pageSize = llvm::sys::Process::getPageSizeEstimate();
+  std::unique_ptr source(new char[pageSize]);
+  for(unsigned i = 0; i < pageSize; ++i) {
+source[i] = 'a';
+  }
+
+  std::unique_ptr Buf =
+  llvm::MemoryBuffer::getMemBuffer(
+llvm::MemoryBufferRef(
+  llvm::StringRef(source.get(), 3), "whatever"
+),
+false
+  );
+
+  FileID mainFileID = SourceMgr.createFileID(std::move(Buf));
+  SourceMgr.setMainFileID(mainFileID);
+
+  ASSERT_NO_FATAL_FAILURE(SourceMgr.getLineNumber(mainFileID, 1, nullptr));
+}
+
 #if defined(LLVM_ON_UNIX)
 
 TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1250,23 +1250,18 @@
 
   const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart();
   const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd();
+  const std::size_t BufLen = End - Buf;
   unsigned I = 0;
-  while (true) {
-// Skip over the contents of the line.
-while (Buf[I] != '\n' && Buf[I] != '\r' && Buf[I] != '\0')
-  ++I;
-
-if (Buf[I] == '\n' || Buf[I] == '\r') {
+  while (I < BufLen) {
+if (Buf[I] == 

[clang] f28972f - [clang] Fix out-of-bounds memory access in ComputeLineNumbers

2020-01-10 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2020-01-10T11:22:41-08:00
New Revision: f28972facc1fce9589feab9803e3e8cfad01891c

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

LOG: [clang] Fix out-of-bounds memory access in ComputeLineNumbers

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

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp
clang/unittests/Basic/SourceManagerTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 5f457d6f9e3d..73f2ae96d4a3 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1250,23 +1250,18 @@ static void ComputeLineNumbers(DiagnosticsEngine , 
ContentCache *FI,
 
   const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart();
   const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd();
+  const std::size_t BufLen = End - Buf;
   unsigned I = 0;
-  while (true) {
-// Skip over the contents of the line.
-while (Buf[I] != '\n' && Buf[I] != '\r' && Buf[I] != '\0')
-  ++I;
-
-if (Buf[I] == '\n' || Buf[I] == '\r') {
+  while (I < BufLen) {
+if (Buf[I] == '\n') {
+  LineOffsets.push_back(I + 1);
+} else if (Buf[I] == '\r') {
   // If this is \r\n, skip both characters.
-  if (Buf[I] == '\r' && Buf[I+1] == '\n')
+  if (I + 1 < BufLen && Buf[I + 1] == '\n')
 ++I;
-  ++I;
-  LineOffsets.push_back(I);
-} else {
-  // Otherwise, this is a NUL. If end of file, exit.
-  if (Buf+I == End) break;
-  ++I;
+  LineOffsets.push_back(I + 1);
 }
+++I;
   }
 
   // Copy the offsets into the FileInfo structure.

diff  --git a/clang/unittests/Basic/SourceManagerTest.cpp 
b/clang/unittests/Basic/SourceManagerTest.cpp
index 465f7a06f71a..07c72e27f9fe 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -20,7 +20,9 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Process.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -241,6 +243,28 @@ TEST_F(SourceManagerTest, getInvalidBOM) {
 "UTF-32 (LE)");
 }
 
+// Regression test - there was an out of bound access for buffers not 
terminated by zero.
+TEST_F(SourceManagerTest, getLineNumber) {
+  const unsigned pageSize = llvm::sys::Process::getPageSizeEstimate();
+  std::unique_ptr source(new char[pageSize]);
+  for(unsigned i = 0; i < pageSize; ++i) {
+source[i] = 'a';
+  }
+
+  std::unique_ptr Buf =
+  llvm::MemoryBuffer::getMemBuffer(
+llvm::MemoryBufferRef(
+  llvm::StringRef(source.get(), 3), "whatever"
+),
+false
+  );
+
+  FileID mainFileID = SourceMgr.createFileID(std::move(Buf));
+  SourceMgr.setMainFileID(mainFileID);
+
+  ASSERT_NO_FATAL_FAILURE(SourceMgr.getLineNumber(mainFileID, 1, nullptr));
+}
+
 #if defined(LLVM_ON_UNIX)
 
 TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {



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


[PATCH] D71124: [RISCV] support clang driver to select cpu

2020-01-10 Thread Evandro Menezes via Phabricator via cfe-commits
evandro added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:164
+
+static constexpr llvm::StringLiteral ValidRV32CPUNames[] = {{"generic-rv32"},
+{"rocket-rv32"}};

Strange formatting...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71124



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


[PATCH] D69878: Consoldiate internal denormal flushing controls

2020-01-10 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added inline comments.



Comment at: llvm/docs/LangRef.rst:1837
+   are present, this overrides ``"denormal-fp-math"``. Not all targets
+   support separately setting the denormal mode per type.
+

cameron.mcinally wrote:
> andrew.w.kaylor wrote:
> > arsenm wrote:
> > > andrew.w.kaylor wrote:
> > > > arsenm wrote:
> > > > > andrew.w.kaylor wrote:
> > > > > > Can you document which targets do support the option? What happens 
> > > > > > if I try to use the option on a target where it is not supported?
> > > > > I'm not sure where to document this, or if/how/where to diagnose it. 
> > > > > I don't think the high level LangRef description is the right place 
> > > > > to discuss specific target handling.
> > > > > 
> > > > > Currently it won't error or anything. Code checking the denorm mode 
> > > > > will see the f32 specific mode, even if the target in the end isn't 
> > > > > really going to respect this.
> > > > > 
> > > > > One problem is this potentially does require coordination with other 
> > > > > toolchain components. For AMDGPU, the compiler can directly tell the 
> > > > > driver what FP mode to set on each entry point, but for x86 it 
> > > > > requires linking in crtfastmath to set the default mode bits. If 
> > > > > another target had a similar runtime environment requirement, I don't 
> > > > > think we can be sure the attribute is correct or not.
> > > > There is precedent for describing target-specific behavior in LangRef. 
> > > > It just doesn't seem useful to say that not all targets support the 
> > > > attribute without saying which ones do. We should also say what is 
> > > > expected if a target doesn't support the attribute. It seems reasonable 
> > > > for the function attribute to be silently ignored.
> > > > 
> > > > > One problem is this potentially does require coordination with other 
> > > > > toolchain components. For AMDGPU, the compiler can directly tell the 
> > > > > driver what FP mode to set on each entry point, but for x86 it 
> > > > > requires linking in crtfastmath to set the default mode bits.
> > > > 
> > > > This is a point I'm interested in. I don't like the current 
> > > > crtfastmath.o handling. It feels almost accidental when FTZ works as 
> > > > expected. My understanding is we link crtfastmath.o if we find it but 
> > > > if not everything just goes about its business. The Intel compiler 
> > > > injects code into main() to explicitly set the FTZ/DAZ control modes. 
> > > > That obviously has problems too, but it's at least consistent and 
> > > > predictable. As I understand it, crtfastmath.o sets these modes from a 
> > > > static initializer, but I'm not sure anything is done to determine the 
> > > > order of that initializer relative to others.
> > > > 
> > > > How does the compiler identify entry points for AMDGPU? And does it 
> > > > emit code to set FTZ based on the function attribute here?
> > > The entry points are a specific calling convention. There's no real 
> > > concept of main. Each kernel has an associated blob of metadata the 
> > > driver uses to set up various config registers on dispatch.
> > > 
> > > I don't think specially recognizing main in the compiler is fundamentally 
> > > different than having it done in a static constructor. It's still a 
> > > construct not associated with any particular function or anything.
> > The problem with having it done in a static constructor is that you have no 
> > certainty of when it will be done relative to other static constructors. If 
> > it's in main you can at least say that it's after all the static 
> > constructors (assuming main is your entry point).
> Yes and no. The linker should honor static constructor priorities. But, yeah, 
> there's no guarantee that this constructor will run before other priority 101 
> constructors.
> 
> The performance penalty for setting denormal flushing in main could be 
> significant (think C++). Also, there's precedent for using static 
> constructors, like GCC's crtfastmath.o.
Fair enough. I don't necessarily like how icc handles this. I don't have a 
problem with how gcc handles it. I just really don't like how LLVM does it. If 
we want to take the static constructor approach we should define our own, not 
depend on whether or not the GNU object file happens to be around.

Static initialization doesn't help for AMDGPU, and I suppose that's likely to 
be the case for any offload execution model. Since this patch is moving us 
toward a more consistent implementation I'm wondering if we can define some 
general rules for how this is supposed to work. Like when the function 
attribute will result in injected instructions setting the control flags and 
when it won't.


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

https://reviews.llvm.org/D69878



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst:16
+   Default is an empty string.
+   The check will detect the following memory setting function: 
+   ``memset``

This repeats first sentence in documentation, so it should be removed. Same in 
other places.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 237393.
njames93 marked 3 inline comments as done.
njames93 added a comment.

- Fixed more documentation nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.cpp
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cert-oop57-cpp %t -- \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cert-oop57-cpp.MemSetNames, value: mymemset}, \
+// RUN:  {key: cert-oop57-cpp.MemCpyNames, value: mymemcpy}, \
+// RUN:  {key: cert-oop57-cpp.MemCmpNames, value: mymemcmp}]}' \
+// RUN: --
+
+void mymemset(void *, unsigned char, decltype(sizeof(int)));
+void mymemcpy(void *, const void *, decltype(sizeof(int)));
+int mymemcmp(const void *, const void *, decltype(sizeof(int)));
+
+namespace std {
+void memset(void *, unsigned char, decltype(sizeof(int)));
+void memcpy(void *, const void *, decltype(sizeof(int)));
+void memmove(void *, const void *, decltype(sizeof(int)));
+void strcpy(void *, const void *, decltype(sizeof(int)));
+int memcmp(const void *, const void *, decltype(sizeof(int)));
+int strcmp(const void *, const void *, decltype(sizeof(int)));
+} // namespace std
+
+struct Trivial {
+  int I;
+  int J;
+};
+
+struct NonTrivial {
+  int I;
+  int J;
+
+  NonTrivial() : I(0), J(0) {}
+  NonTrivial =(const NonTrivial ) {
+I = Other.I;
+J = Other.J;
+return *this;
+  }
+
+  bool operator==(const Trivial ) const {
+return I == Other.I && J == Other.J;
+  }
+  bool operator!=(const Trivial ) const {
+return !(*this == Other);
+  }
+};
+
+void foo(const Trivial ) {
+  Trivial Data;
+  std::memset(, 0, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memset(, 0, sizeof(Trivial));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void bar(const NonTrivial ) {
+  NonTrivial Data;
+  std::memset(, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  // Check it detects sizeof(Type) as well as sizeof(Instantiation)
+  std::memset(, 0, sizeof(NonTrivial));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void baz(const NonTrivial ) {
+  NonTrivial Data;
+  mymemset(, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'mymemset' on a non trivially default constructible class is undefined
+  mymemcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'mymemcpy' on a non trivially copyable 

[PATCH] D69878: Consoldiate internal denormal flushing controls

2020-01-10 Thread Cameron McInally via Phabricator via cfe-commits
cameron.mcinally added inline comments.



Comment at: llvm/docs/LangRef.rst:1837
+   are present, this overrides ``"denormal-fp-math"``. Not all targets
+   support separately setting the denormal mode per type.
+

andrew.w.kaylor wrote:
> arsenm wrote:
> > andrew.w.kaylor wrote:
> > > arsenm wrote:
> > > > andrew.w.kaylor wrote:
> > > > > Can you document which targets do support the option? What happens if 
> > > > > I try to use the option on a target where it is not supported?
> > > > I'm not sure where to document this, or if/how/where to diagnose it. I 
> > > > don't think the high level LangRef description is the right place to 
> > > > discuss specific target handling.
> > > > 
> > > > Currently it won't error or anything. Code checking the denorm mode 
> > > > will see the f32 specific mode, even if the target in the end isn't 
> > > > really going to respect this.
> > > > 
> > > > One problem is this potentially does require coordination with other 
> > > > toolchain components. For AMDGPU, the compiler can directly tell the 
> > > > driver what FP mode to set on each entry point, but for x86 it requires 
> > > > linking in crtfastmath to set the default mode bits. If another target 
> > > > had a similar runtime environment requirement, I don't think we can be 
> > > > sure the attribute is correct or not.
> > > There is precedent for describing target-specific behavior in LangRef. It 
> > > just doesn't seem useful to say that not all targets support the 
> > > attribute without saying which ones do. We should also say what is 
> > > expected if a target doesn't support the attribute. It seems reasonable 
> > > for the function attribute to be silently ignored.
> > > 
> > > > One problem is this potentially does require coordination with other 
> > > > toolchain components. For AMDGPU, the compiler can directly tell the 
> > > > driver what FP mode to set on each entry point, but for x86 it requires 
> > > > linking in crtfastmath to set the default mode bits.
> > > 
> > > This is a point I'm interested in. I don't like the current crtfastmath.o 
> > > handling. It feels almost accidental when FTZ works as expected. My 
> > > understanding is we link crtfastmath.o if we find it but if not 
> > > everything just goes about its business. The Intel compiler injects code 
> > > into main() to explicitly set the FTZ/DAZ control modes. That obviously 
> > > has problems too, but it's at least consistent and predictable. As I 
> > > understand it, crtfastmath.o sets these modes from a static initializer, 
> > > but I'm not sure anything is done to determine the order of that 
> > > initializer relative to others.
> > > 
> > > How does the compiler identify entry points for AMDGPU? And does it emit 
> > > code to set FTZ based on the function attribute here?
> > The entry points are a specific calling convention. There's no real concept 
> > of main. Each kernel has an associated blob of metadata the driver uses to 
> > set up various config registers on dispatch.
> > 
> > I don't think specially recognizing main in the compiler is fundamentally 
> > different than having it done in a static constructor. It's still a 
> > construct not associated with any particular function or anything.
> The problem with having it done in a static constructor is that you have no 
> certainty of when it will be done relative to other static constructors. If 
> it's in main you can at least say that it's after all the static constructors 
> (assuming main is your entry point).
Yes and no. The linker should honor static constructor priorities. But, yeah, 
there's no guarantee that this constructor will run before other priority 101 
constructors.

The performance penalty for setting denormal flushing in main could be 
significant (think C++). Also, there's precedent for using static constructors, 
like GCC's crtfastmath.o.


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

https://reviews.llvm.org/D69878



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst:14
+
+   Specify extra functions to flag on that act similarily to memset.
+   Default is an empty string

Please enclose memset in double back-ticks. Same for other options.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst:15
+   Specify extra functions to flag on that act similarily to memset.
+   Default is an empty string
+   The check will always detect the function: ``memset``

Please append dot. Same for other options.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst:16
+   Default is an empty string
+   The check will always detect the function: ``memset``
+

This is tautological because extra functions assume additions to functions 
handled by default. Same for other options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488



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


[PATCH] D71612: [analyzer] Add PlacementNewChecker

2020-01-10 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Related commit that moves to alpha:
https://github.com/llvm/llvm-project/commit/13ec473b9d4bd4f7a558272932b7c0806171c666


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71612



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


[PATCH] D72414: Add new AST matcher `hasAnyCapture`

2020-01-10 Thread Reid via Phabricator via cfe-commits
rhiro marked 2 inline comments as done.
rhiro added a comment.

I addressed the inline comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72414



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 237390.
njames93 marked 3 inline comments as done.
njames93 added a comment.

- Fix format of options docs and remove unnecessary empty line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.cpp
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cert-oop57-cpp %t -- \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cert-oop57-cpp.MemSetNames, value: mymemset}, \
+// RUN:  {key: cert-oop57-cpp.MemCpyNames, value: mymemcpy}, \
+// RUN:  {key: cert-oop57-cpp.MemCmpNames, value: mymemcmp}]}' \
+// RUN: --
+
+void mymemset(void *, unsigned char, decltype(sizeof(int)));
+void mymemcpy(void *, const void *, decltype(sizeof(int)));
+int mymemcmp(const void *, const void *, decltype(sizeof(int)));
+
+namespace std {
+void memset(void *, unsigned char, decltype(sizeof(int)));
+void memcpy(void *, const void *, decltype(sizeof(int)));
+void memmove(void *, const void *, decltype(sizeof(int)));
+void strcpy(void *, const void *, decltype(sizeof(int)));
+int memcmp(const void *, const void *, decltype(sizeof(int)));
+int strcmp(const void *, const void *, decltype(sizeof(int)));
+} // namespace std
+
+struct Trivial {
+  int I;
+  int J;
+};
+
+struct NonTrivial {
+  int I;
+  int J;
+
+  NonTrivial() : I(0), J(0) {}
+  NonTrivial =(const NonTrivial ) {
+I = Other.I;
+J = Other.J;
+return *this;
+  }
+
+  bool operator==(const Trivial ) const {
+return I == Other.I && J == Other.J;
+  }
+  bool operator!=(const Trivial ) const {
+return !(*this == Other);
+  }
+};
+
+void foo(const Trivial ) {
+  Trivial Data;
+  std::memset(, 0, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memset(, 0, sizeof(Trivial));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(, , sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void bar(const NonTrivial ) {
+  NonTrivial Data;
+  std::memset(, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  // Check it detects sizeof(Type) as well as sizeof(Instantiation)
+  std::memset(, 0, sizeof(NonTrivial));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void baz(const NonTrivial ) {
+  NonTrivial Data;
+  mymemset(, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'mymemset' on a non trivially default constructible class is undefined
+  mymemcpy(, , sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 

[clang] 13ec473 - [analyzer] Move PlacementNewChecker to alpha

2020-01-10 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-01-10T19:35:25+01:00
New Revision: 13ec473b9d4bd4f7a558272932b7c0806171c666

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

LOG: [analyzer] Move PlacementNewChecker to alpha

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/test/Analysis/placement-new-user-defined.cpp
clang/test/Analysis/placement-new.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index fc1529f2ea1c..d235273cda41 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -470,12 +470,6 @@ def NewDeleteLeaksChecker : Checker<"NewDeleteLeaks">,
   Dependencies<[NewDeleteChecker]>,
   Documentation;
 
-def PlacementNewChecker : Checker<"PlacementNew">,
-  HelpText<"Check if default placement new is provided with pointers to "
-   "sufficient storage capacity">,
-  Dependencies<[NewDeleteChecker]>,
-  Documentation;
-
 def CXXSelfAssignmentChecker : Checker<"SelfAssignment">,
   HelpText<"Checks C++ copy and move assignment operators for self 
assignment">,
   Documentation,
@@ -621,6 +615,12 @@ def MismatchedIteratorChecker : 
Checker<"MismatchedIterator">,
   Dependencies<[IteratorModeling]>,
   Documentation;
 
+def PlacementNewChecker : Checker<"PlacementNew">,
+  HelpText<"Check if default placement new is provided with pointers to "
+   "sufficient storage capacity">,
+  Dependencies<[NewDeleteChecker]>,
+  Documentation;
+
 } // end: "alpha.cplusplus"
 
 

diff  --git a/clang/test/Analysis/placement-new-user-defined.cpp 
b/clang/test/Analysis/placement-new-user-defined.cpp
index b3fe47057f8a..47f0b459ea00 100644
--- a/clang/test/Analysis/placement-new-user-defined.cpp
+++ b/clang/test/Analysis/placement-new-user-defined.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -std=c++11 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-checker=cplusplus.PlacementNew \
+// RUN:   -analyzer-checker=alpha.cplusplus.PlacementNew \
 // RUN:   -analyzer-output=text -verify \
 // RUN:   -triple x86_64-unknown-linux-gnu
 

diff  --git a/clang/test/Analysis/placement-new.cpp 
b/clang/test/Analysis/placement-new.cpp
index dfd057b2fa20..0f5248410a41 100644
--- a/clang/test/Analysis/placement-new.cpp
+++ b/clang/test/Analysis/placement-new.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -std=c++11 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=cplusplus.NewDelete \
-// RUN:   -analyzer-checker=cplusplus.PlacementNew \
+// RUN:   -analyzer-checker=alpha.cplusplus.PlacementNew \
 // RUN:   -analyzer-output=text -verify \
 // RUN:   -triple x86_64-unknown-linux-gnu
 



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


[PATCH] D72414: Add new AST matcher `hasAnyCapture`

2020-01-10 Thread Reid via Phabricator via cfe-commits
rhiro updated this revision to Diff 237389.
rhiro added a comment.

Fixed the condition for the varDecl case and made the cxxThisExpr more concise.

- Condition on `capturesVariable` instead of `capturesThis` and switch the loop 
in the cxxThisExpr overload to use llvm::any_of instead of an explicit loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72414

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

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -454,6 +454,26 @@
   objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x";
 }
 
+TEST(Matcher, HasAnyCapture) {
+  auto HasCaptureX = lambdaExpr(hasAnyCapture(varDecl(hasName("x";
+  EXPECT_TRUE(matches("void f() { int x = 3; [x](){}; }", HasCaptureX));
+  EXPECT_TRUE(matches("void f() { int x = 3; [](){}; }", HasCaptureX));
+  EXPECT_TRUE(notMatches("void f() { [](){}; }", HasCaptureX));
+  EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureX));
+  EXPECT_TRUE(
+  notMatches("struct a { void f() { [this](){}; }; };", HasCaptureX));
+}
+
+TEST(Matcher, CapturesThis) {
+  auto HasCaptureThis = lambdaExpr(hasAnyCapture(cxxThisExpr()));
+  EXPECT_TRUE(
+  matches("struct a { void f() { [this](){}; }; };", HasCaptureThis));
+  EXPECT_TRUE(notMatches("void f() { [](){}; }", HasCaptureThis));
+  EXPECT_TRUE(notMatches("void f() { int x = 3; [x](){}; }", HasCaptureThis));
+  EXPECT_TRUE(notMatches("void f() { int x = 3; [](){}; }", HasCaptureThis));
+  EXPECT_TRUE(notMatches("void f() { int z = 3; [](){}; }", HasCaptureThis));
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -105,6 +105,7 @@
   // equalsNode
 
   REGISTER_OVERLOADED_2(callee);
+  REGISTER_OVERLOADED_2(hasAnyCapture);
   REGISTER_OVERLOADED_2(hasPrefix);
   REGISTER_OVERLOADED_2(hasType);
   REGISTER_OVERLOADED_2(ignoringParens);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -55,6 +55,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenMPClause.h"
 #include "clang/AST/OperationKinds.h"
@@ -4014,6 +4015,50 @@
   return false;
 }
 
+/// Matches any capture of a lambda expression.
+///
+/// Given
+/// \code
+///   void foo() {
+/// int x;
+/// auto f = [x](){};
+///   }
+/// \endcode
+/// lambdaExpr(hasAnyCapture(anything()))
+///   matches [x](){};
+AST_MATCHER_P_OVERLOAD(LambdaExpr, hasAnyCapture, internal::Matcher,
+   InnerMatcher, 0) {
+  for (const LambdaCapture  : Node.captures()) {
+if (Capture.capturesVariable()) {
+  BoundNodesTreeBuilder Result(*Builder);
+  if (InnerMatcher.matches(*Capture.getCapturedVar(), Finder, )) {
+*Builder = std::move(Result);
+return true;
+  }
+}
+  }
+  return false;
+}
+
+/// Matches any capture of 'this' in a lambda expression.
+///
+/// Given
+/// \code
+///   struct foo {
+/// void bar() {
+///   auto f = [this](){};
+/// }
+///   }
+/// \endcode
+/// lambdaExpr(hasAnyCapture(cxxThisExpr()))
+///   matches [this](){};
+AST_MATCHER_P_OVERLOAD(LambdaExpr, hasAnyCapture,
+   internal::Matcher, InnerMatcher, 1) {
+  return llvm::any_of(Node.captures(), [](const LambdaCapture ) {
+return LC.capturesThis();
+  });
+}
+
 /// Matches a constructor call expression which uses list initialization.
 AST_MATCHER(CXXConstructExpr, isListInitialization) {
   return Node.isListInitialization();
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -5098,15 +5098,15 @@
 Matches selection statements with initializer.
 
 Given:
- void foo() { 
+ void foo() {
if (int i = foobar(); i  0) {}
switch (int i = foobar(); i) {}
-   for (auto a = get_range(); auto x : a) {} 
+   for (auto a = get_range(); auto x : a) {}
  }
- void bar() { 
+ void bar() {
if (foobar()  0) {}
switch (foobar()) {}
-   for (auto x : 

  1   2   3   >