[PATCH] D70973: [OPENMP50]Treat context selectors as expressions, not just strings.

2019-12-23 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D70973#1793061 , @jdoerfert wrote:

> I haven't forgotten about this! With the other two changes to the declare 
> variant going to happen now,as well, I figured we should look at this again 
> from a high-level.
>
> My plan now is:
>
> 1. Move all of the declare variant context stuff out of clang into the 
> libFrontendOpenMP. This has various benefits, including reuse capabilities 
> and the problem of where to put it (which was discussed briefly in my other 
> declare variant patches), is gone.
> 2. Set it up to accept *constant* strings and non-string alike from the 
> beginning. I'll also make it completely OMPKinds.def based with all the trait 
> sets and selectors at least parsed properly. Rules what can be nested 
> together, what can have a score, etc. are all reusable and mostly generated.
> 3. Introduce the declare variant begin/end stuff to get math support before 
> the 10 fork.
> 4. Make all declare variant decisions in SemaOverload.


Part 1) and 2) are ready for review (D71830 ). 
I took some code from here to handle string literals the same as identifiers 
and I sprinkled a few '"' into the match clauses to test it.

(In contrast to this patch, with D71830  we 
will actually remove the quotes when we pretty print the AST instead of adding 
them.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70973



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


[PATCH] D71830: [OpenMP] Reusable OpenMP context/traits handling

2019-12-23 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{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 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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


[PATCH] D71716: [ItaniumCXXABI] Don't mark an extern_weak init function as dso_local on windows

2019-12-23 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG86c9831bb40d: [ItaniumCXXABI] Don't mark an extern_weak 
init function as dso_local on windows (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71716

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/mingw-thread-local.cpp


Index: clang/test/CodeGenCXX/mingw-thread-local.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/mingw-thread-local.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-w64-mingw32 | 
FileCheck %s
+
+extern thread_local int var;
+
+int get() {
+  return var;
+}
+
+// CHECK: declare extern_weak void @_ZTH3var()
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2684,7 +2684,9 @@
 
 if (Init) {
   Init->setVisibility(Var->getVisibility());
-  Init->setDSOLocal(Var->isDSOLocal());
+  // Don't mark an extern_weak function DSO local on windows.
+  if (!CGM.getTriple().isOSWindows() || !Init->hasExternalWeakLinkage())
+Init->setDSOLocal(Var->isDSOLocal());
 }
 
 llvm::LLVMContext &Context = CGM.getModule().getContext();


Index: clang/test/CodeGenCXX/mingw-thread-local.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/mingw-thread-local.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-w64-mingw32 | FileCheck %s
+
+extern thread_local int var;
+
+int get() {
+  return var;
+}
+
+// CHECK: declare extern_weak void @_ZTH3var()
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2684,7 +2684,9 @@
 
 if (Init) {
   Init->setVisibility(Var->getVisibility());
-  Init->setDSOLocal(Var->isDSOLocal());
+  // Don't mark an extern_weak function DSO local on windows.
+  if (!CGM.getTriple().isOSWindows() || !Init->hasExternalWeakLinkage())
+Init->setDSOLocal(Var->isDSOLocal());
 }
 
 llvm::LLVMContext &Context = CGM.getModule().getContext();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b714583 - [OpenCL] Add atomic builtin functions

2019-12-23 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2019-12-23T12:29:01Z
New Revision: b714583fd09683458be9eb03a9faef656a8ccf49

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

LOG: [OpenCL] Add atomic builtin functions

Add atomic builtin functions from the OpenCL C specification.

Patch by Pierre Gondois and Sven van Haastregt.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 37f317823933..38e07b21cb85 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -55,6 +55,10 @@ def FuncExtNone  : 
FunctionExtension<"">;
 def FuncExtKhrSubgroups  : 
FunctionExtension<"cl_khr_subgroups">;
 def FuncExtKhrGlobalInt32BaseAtomics : 
FunctionExtension<"cl_khr_global_int32_base_atomics">;
 def FuncExtKhrGlobalInt32ExtendedAtomics : 
FunctionExtension<"cl_khr_global_int32_extended_atomics">;
+def FuncExtKhrLocalInt32BaseAtomics  : 
FunctionExtension<"cl_khr_local_int32_base_atomics">;
+def FuncExtKhrLocalInt32ExtendedAtomics  : 
FunctionExtension<"cl_khr_local_int32_extended_atomics">;
+def FuncExtKhrInt64BaseAtomics   : 
FunctionExtension<"cl_khr_int64_base_atomics">;
+def FuncExtKhrInt64ExtendedAtomics   : 
FunctionExtension<"cl_khr_int64_extended_atomics">;
 
 // Qualified Type.  These map to ASTContext::QualType.
 class QualType {
@@ -892,6 +896,81 @@ let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
 }
   }
 }
+// --- Table 9.3 ---
+let Extension = FuncExtKhrLocalInt32BaseAtomics in {
+  foreach Type = [Int, UInt] in {
+foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
+  def : Builtin, LocalAS>, 
Type]>;
+}
+foreach name = ["atom_inc", "atom_dec"] in {
+  def : Builtin, LocalAS>]>;
+}
+foreach name = ["atom_cmpxchg"] in {
+  def : Builtin, LocalAS>, 
Type, Type]>;
+}
+  }
+}
+// --- Table 9.5 ---
+let Extension = FuncExtKhrInt64BaseAtomics in {
+  foreach AS = [GlobalAS, LocalAS] in {
+foreach Type = [Long, ULong] in {
+  foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
+def : Builtin, AS>, Type]>;
+  }
+  foreach name = ["atom_inc", "atom_dec"] in {
+def : Builtin, AS>]>;
+  }
+  foreach name = ["atom_cmpxchg"] in {
+def : Builtin, AS>, Type, 
Type]>;
+  }
+}
+  }
+}
+// --- Table 9.2 ---
+let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
+  foreach Type = [Int, UInt] in {
+foreach name = ["atom_min", "atom_max", "atom_and",
+"atom_or", "atom_xor"] in {
+  def : Builtin, GlobalAS>, 
Type]>;
+}
+  }
+}
+// --- Table 9.4 ---
+let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
+  foreach Type = [Int, UInt] in {
+foreach name = ["atom_min", "atom_max", "atom_and",
+"atom_or", "atom_xor"] in {
+  def : Builtin, LocalAS>, 
Type]>;
+}
+  }
+}
+// --- Table 9.6 ---
+let Extension = FuncExtKhrInt64ExtendedAtomics in {
+  foreach AS = [GlobalAS, LocalAS] in {
+foreach Type = [Long, ULong] in {
+  foreach name = ["atom_min", "atom_max", "atom_and",
+  "atom_or", "atom_xor"] in {
+def : Builtin, AS>, Type]>;
+  }
+}
+  }
+}
+// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
+foreach AS = [GlobalAS, LocalAS] in {
+  foreach Type = [Int, UInt] in {
+foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
+"atomic_min", "atomic_max", "atomic_and",
+"atomic_or", "atomic_xor"] in {
+  def : Builtin, AS>, Type]>;
+}
+foreach name = ["atomic_inc", "atomic_dec"] in {
+  def : Builtin, AS>]>;
+}
+foreach name = ["atomic_cmpxchg"] in {
+  def : Builtin, AS>, Type, 
Type]>;
+}
+  }
+}
 
 //
 // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector 
Functions

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 000f96278faa..dd89f40761c0 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -44,8 +44,14 @@ kernel void test_pointers(volatile global void *global_p, 
global const int4 *a)
 
 // There are two potential definitions of the function "atom_add", both are
 // currently disabled because the associated extension is disabled.
-// expected-note@-6{{candidate unavailable as it requires OpenCL extension 
'cl_khr_global_int32_base_atomics' to be enabled}}
-// expected-note@-7{{candidate unavailable as it requires OpenCL extension 

[clang] eca4006 - [NFC] Move OptionUtils from Basic to Driver

2019-12-23 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2019-12-23T08:11:23-05:00
New Revision: eca40066ebb5759aa44d21833c7a1fd7dd2361af

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

LOG: [NFC] Move OptionUtils from Basic to Driver

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

Added: 
clang/include/clang/Driver/OptionUtils.h
clang/lib/Driver/OptionUtils.cpp

Modified: 
clang/include/clang/Frontend/Utils.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Driver/CMakeLists.txt

Removed: 
clang/include/clang/Basic/OptionUtils.h
clang/lib/Basic/OptionUtils.cpp



diff  --git a/clang/include/clang/Basic/OptionUtils.h 
b/clang/include/clang/Driver/OptionUtils.h
similarity index 94%
rename from clang/include/clang/Basic/OptionUtils.h
rename to clang/include/clang/Driver/OptionUtils.h
index 6254f758c2f0..922f536bf33e 100644
--- a/clang/include/clang/Basic/OptionUtils.h
+++ b/clang/include/clang/Driver/OptionUtils.h
@@ -10,8 +10,8 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_BASIC_OPTIONUTILS_H
-#define LLVM_CLANG_BASIC_OPTIONUTILS_H
+#ifndef LLVM_CLANG_DRIVER_OPTIONUTILS_H
+#define LLVM_CLANG_DRIVER_OPTIONUTILS_H
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
@@ -55,4 +55,4 @@ inline uint64_t getLastArgUInt64Value(const 
llvm::opt::ArgList &Args,
 
 } // namespace clang
 
-#endif // LLVM_CLANG_BASIC_OPTIONUTILS_H
+#endif // LLVM_CLANG_DRIVER_OPTIONUTILS_H

diff  --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index d5990d56ba28..b5834921b9ed 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -15,7 +15,7 @@
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/OptionUtils.h"
+#include "clang/Driver/OptionUtils.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"

diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index b54d261b9d1d..be739c70468e 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -1,7 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   Core
   MC
-  Option
   Support
   )
 
@@ -56,7 +55,6 @@ add_clang_library(clangBasic
   ObjCRuntime.cpp
   OpenMPKinds.cpp
   OperatorPrecedence.cpp
-  OptionUtils.cpp
   SanitizerBlacklist.cpp
   SanitizerSpecialCaseList.cpp
   Sanitizers.cpp

diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index eb76cd3dcade..6f25d3588ebb 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -19,6 +19,7 @@ add_clang_library(clangDriver
   DriverOptions.cpp
   Job.cpp
   Multilib.cpp
+  OptionUtils.cpp
   Phases.cpp
   SanitizerArgs.cpp
   Tool.cpp

diff  --git a/clang/lib/Basic/OptionUtils.cpp b/clang/lib/Driver/OptionUtils.cpp
similarity index 97%
rename from clang/lib/Basic/OptionUtils.cpp
rename to clang/lib/Driver/OptionUtils.cpp
index e33c233b58b7..1f36ffc03cab 100644
--- a/clang/lib/Basic/OptionUtils.cpp
+++ b/clang/lib/Driver/OptionUtils.cpp
@@ -6,9 +6,9 @@
 //
 
//===--===//
 
-#include "clang/Basic/OptionUtils.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/OptionUtils.h"
 #include "llvm/Option/ArgList.h"
 
 using namespace clang;



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


[PATCH] D71802: [NFC] Move OptionUtils from Basic to Driver

2019-12-23 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeca40066ebb5: [NFC] Move OptionUtils from Basic to Driver 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D71802?vs=235036&id=235134#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71802

Files:
  clang/include/clang/Basic/OptionUtils.h
  clang/include/clang/Driver/OptionUtils.h
  clang/include/clang/Frontend/Utils.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/OptionUtils.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OptionUtils.cpp


Index: clang/lib/Driver/OptionUtils.cpp
===
--- clang/lib/Driver/OptionUtils.cpp
+++ clang/lib/Driver/OptionUtils.cpp
@@ -6,9 +6,9 @@
 //
 
//===--===//
 
-#include "clang/Basic/OptionUtils.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/OptionUtils.h"
 #include "llvm/Option/ArgList.h"
 
 using namespace clang;
Index: clang/lib/Driver/CMakeLists.txt
===
--- clang/lib/Driver/CMakeLists.txt
+++ clang/lib/Driver/CMakeLists.txt
@@ -19,6 +19,7 @@
   DriverOptions.cpp
   Job.cpp
   Multilib.cpp
+  OptionUtils.cpp
   Phases.cpp
   SanitizerArgs.cpp
   Tool.cpp
Index: clang/lib/Basic/CMakeLists.txt
===
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -1,7 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   Core
   MC
-  Option
   Support
   )
 
@@ -56,7 +55,6 @@
   ObjCRuntime.cpp
   OpenMPKinds.cpp
   OperatorPrecedence.cpp
-  OptionUtils.cpp
   SanitizerBlacklist.cpp
   SanitizerSpecialCaseList.cpp
   Sanitizers.cpp
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -15,7 +15,7 @@
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/OptionUtils.h"
+#include "clang/Driver/OptionUtils.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
Index: clang/include/clang/Driver/OptionUtils.h
===
--- clang/include/clang/Driver/OptionUtils.h
+++ clang/include/clang/Driver/OptionUtils.h
@@ -10,8 +10,8 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_BASIC_OPTIONUTILS_H
-#define LLVM_CLANG_BASIC_OPTIONUTILS_H
+#ifndef LLVM_CLANG_DRIVER_OPTIONUTILS_H
+#define LLVM_CLANG_DRIVER_OPTIONUTILS_H
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
@@ -55,4 +55,4 @@
 
 } // namespace clang
 
-#endif // LLVM_CLANG_BASIC_OPTIONUTILS_H
+#endif // LLVM_CLANG_DRIVER_OPTIONUTILS_H


Index: clang/lib/Driver/OptionUtils.cpp
===
--- clang/lib/Driver/OptionUtils.cpp
+++ clang/lib/Driver/OptionUtils.cpp
@@ -6,9 +6,9 @@
 //
 //===--===//
 
-#include "clang/Basic/OptionUtils.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/OptionUtils.h"
 #include "llvm/Option/ArgList.h"
 
 using namespace clang;
Index: clang/lib/Driver/CMakeLists.txt
===
--- clang/lib/Driver/CMakeLists.txt
+++ clang/lib/Driver/CMakeLists.txt
@@ -19,6 +19,7 @@
   DriverOptions.cpp
   Job.cpp
   Multilib.cpp
+  OptionUtils.cpp
   Phases.cpp
   SanitizerArgs.cpp
   Tool.cpp
Index: clang/lib/Basic/CMakeLists.txt
===
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -1,7 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   Core
   MC
-  Option
   Support
   )
 
@@ -56,7 +55,6 @@
   ObjCRuntime.cpp
   OpenMPKinds.cpp
   OperatorPrecedence.cpp
-  OptionUtils.cpp
   SanitizerBlacklist.cpp
   SanitizerSpecialCaseList.cpp
   Sanitizers.cpp
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -15,7 +15,7 @@
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/OptionUtils.h"
+#include "clang/Driver/OptionUtils.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
Index: clang/include/clang/Driver/OptionUtils.h
===
--- clang/include/clang/Driver/Opti

[PATCH] D70111: [DWARF5]Addition of alignment field in the typedef for dwarf5

2019-12-23 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added inline comments.



Comment at: llvm/docs/ReleaseNotes.rst:169
 
+* C DebugInfo API ``LLVMDIBuilderCreateTypedef`` is updated to include an extra
+argument ``AlignInBits``, to facilitate / propagate specified Alignment 
information

It looks like this breaks the llvm-sphinx-docs build.


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

https://reviews.llvm.org/D70111



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


[PATCH] D71830: [OpenMP] Reusable OpenMP context/traits handling

2019-12-23 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Big patch but looks like a net decrease in complexity. Please could you clang 
format the areas phabricator is complaining about?

Reading through on a browser looks great. I'll take a closer look in a real 
editor once Christmas is out of the way. Thanks for posting this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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


[clang] 0860db9 - [OPENMP50]Codegen for nontemporal clause.

2019-12-23 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2019-12-23T10:04:46-05:00
New Revision: 0860db966a7d2ab61b26e41426a55189986924b4

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

LOG: [OPENMP50]Codegen for nontemporal clause.

Summary:
Basic codegen for the declarations marked as nontemporal. Also, if the
base declaration in the member expression is marked as nontemporal,
lvalue for member decl access inherits nonteporal flag from the base
lvalue.

Reviewers: rjmccall, hfinkel, jdoerfert

Subscribers: guansong, arphaman, caomhin, kkwli0, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/distribute_simd_codegen.cpp
clang/test/OpenMP/for_simd_codegen.cpp
clang/test/OpenMP/simd_codegen.cpp
clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
clang/test/OpenMP/target_simd_codegen.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
clang/test/OpenMP/teams_distribute_simd_codegen.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index c708b011849a..7cef0bc9092a 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6275,6 +6275,15 @@ class OMPNontemporalClause final
 OMPC_nontemporal, SourceLocation(), SourceLocation(),
 SourceLocation(), N) {}
 
+  /// Get the list of privatied copies if the member expression was captured by
+  /// one of the privatization clauses.
+  MutableArrayRef getPrivateRefs() {
+return MutableArrayRef(varlist_end(), varlist_size());
+  }
+  ArrayRef getPrivateRefs() const {
+return llvm::makeArrayRef(varlist_end(), varlist_size());
+  }
+
 public:
   /// Creates clause with a list of variables \a VL.
   ///
@@ -6293,6 +6302,10 @@ class OMPNontemporalClause final
   /// \param N The number of variables.
   static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
 
+  /// Sets the list of references to private copies created in private clauses.
+  /// \param VL List of references.
+  void setPrivateRefs(ArrayRef VL);
+
   child_range children() {
 return child_range(reinterpret_cast(varlist_begin()),
reinterpret_cast(varlist_end()));
@@ -6303,6 +6316,16 @@ class OMPNontemporalClause final
 return const_child_range(Children.begin(), Children.end());
   }
 
+  child_range private_refs() {
+return child_range(reinterpret_cast(getPrivateRefs().begin()),
+   reinterpret_cast(getPrivateRefs().end()));
+  }
+
+  const_child_range private_refs() const {
+auto Children = const_cast(this)->private_refs();
+return const_child_range(Children.begin(), Children.end());
+  }
+
   child_range used_children() {
 return child_range(child_iterator(), child_iterator());
   }

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index a93a01da34c1..19dd62b0fe0f 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3378,6 +3378,9 @@ template 
 bool RecursiveASTVisitor::VisitOMPNontemporalClause(
 OMPNontemporalClause *C) {
   TRY_TO(VisitOMPClauseList(C));
+  for (auto *E : C->private_refs()) {
+TRY_TO(TraverseStmt(E));
+  }
   return true;
 }
 

diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index f062c3e463a8..790b44012298 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -1162,8 +1162,8 @@ OMPNontemporalClause *OMPNontemporalClause::Create(const 
ASTContext &C,
SourceLocation LParenLoc,
SourceLocation EndLoc,
ArrayRef VL) {
-  // Allocate space for nontemporal variables.
-  void *Mem = C.Allocate(totalSizeToAlloc(VL.size()));
+  // Allocate space for nontemporal variables + private references.
+  void *Mem = C.Allocate(totalSizeToAlloc(2 * VL.size()));
   auto *Clause =
   new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
   Clause->setVarRefs(VL);
@@ -1172,10 +117

[PATCH] D71708: [OPENMP50]Codegen for nontemporal clause.

2019-12-23 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0860db966a7d: [OPENMP50]Codegen for nontemporal clause. 
(authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71708

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/for_simd_codegen.cpp
  clang/test/OpenMP/simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_codegen.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2458,6 +2458,8 @@
 void OMPClauseEnqueue::VisitOMPNontemporalClause(
 const OMPNontemporalClause *C) {
   VisitOMPClauseList(C);
+  for (const auto *E : C->private_refs())
+Visitor->AddStmt(E);
 }
 }
 
Index: clang/test/OpenMP/teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_simd_codegen.cpp
@@ -177,16 +177,16 @@
   // CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
   int foo(void) {
 
-  // CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* %{{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 1)
+  // CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* %{{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 1)
   // CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
 #pragma omp target
 #ifdef OMP5
-#pragma omp teams distribute simd if(b)
+#pragma omp teams distribute simd if(b) nontemporal(a, b)
 #else
 #pragma omp teams distribute simd
 #endif // OMP5
 for(int i = 0; i < X; i++) {
-  a[i] = (T)0;
+  a[i] = (T)b;
 }
 
   // outlined target region
@@ -197,6 +197,8 @@
 
   // CK3: define internal void @[[OUTL1]]({{.+}})
   // CK3: call void @__kmpc_for_static_init_4(
+  // OMP3_45-NOT: !nontemporal
+  // OMP3_50: load float,{{.*}}!nontemporal
   // CK3: call void @__kmpc_for_static_fini(
   // CK3: ret void
 
Index: clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
@@ -165,7 +165,7 @@
 
   // CHECK:   call void [[HVT1:@.+]](i[[SZ]] {{[^,]+}})
 #ifdef OMP5
-  #pragma omp target teams distribute simd if(target: 0) safelen(32) linear(a) if(simd: 1)
+  #pragma omp target teams distribute simd if(target: 0) safelen(32) linear(a) if(simd: 1) nontemporal(a)
 #else
   #pragma omp target teams distribute simd if(target: 0) safelen(32) linear(a)
 #endif // OMP5
@@ -395,6 +395,8 @@
 // CHECK:   [[AA_ADDR:%.+]] = alloca i[[SZ]], align
 // CHECK:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[AA_ADDR]], align
 // CHECK-64:[[AA_CADDR:%.+]] = bitcast i[[SZ]]* [[AA_ADDR]] to i32*
+// OMP45-NOT:   !nontemporal
+// OMP50:   load i32,{{.*}}!nontemporal
 // CHECK-64:store i32 10, i32* [[AA_CADDR]], align
 // CHECK-32:store i32 10, i32* [[AA_ADDR]], align
 // CHECK:   ret void
Index: clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
===
--- clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
+++ clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
@@ -35,20 +35,25 @@
 // CHECK: call i{{[0-9]+}} @__tgt_target_teams(
 // CHECK: call void [[OFFLOADING_FUN_1:@.+]](
 #ifdef OMP5
-#pragma omp target teams distribute parallel for simd if(simd: true)
+#pragma omp target teams distribute parallel for simd if(simd: true) nontemporal(Arg)
 #else
 #pragma omp target teams distribute parallel for simd
 #endif // OMP5
-  for(int i = 0 ; i < 100; i++) {}
+  for (int i = 0; i < 100; i++) {
+Arg = 0;
+  }
   // CHECK: define internal void [[OFFLOADING_FUN_0]](
-  // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_teams({{.+}}, i32 0, {{.+}}* [[OMP_TEAMS_OUTLINED_0:@.+]] to {{.+}})
+  // CHECK: call {{.*}}void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {

[PATCH] D71842: Allow newlines in AST Matchers in clang-query files

2019-12-23 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/D71842

Files:
  clang-tools-extra/clang-query/Query.cpp
  clang-tools-extra/clang-query/Query.h
  clang-tools-extra/clang-query/QueryParser.cpp
  clang-tools-extra/clang-query/tool/ClangQuery.cpp
  clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
  clang/include/clang/ASTMatchers/Dynamic/Parser.h
  clang/lib/ASTMatchers/Dynamic/Parser.cpp
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -207,10 +207,12 @@
 
 TEST(ParserTest, FullParserTest) {
   Diagnostics Error;
-  llvm::Optional VarDecl(Parser::parseMatcherExpression(
+
+  StringRef Code =
   "varDecl(hasInitializer(binaryOperator(hasLHS(integerLiteral()),"
-  "  hasOperatorName(\"+\"",
-  &Error));
+  "  hasOperatorName(\"+\"";
+  llvm::Optional VarDecl(
+  Parser::parseMatcherExpression(Code, &Error));
   EXPECT_EQ("", Error.toStringFull());
   Matcher M = VarDecl->unconditionalConvertTo();
   EXPECT_TRUE(matches("int x = 1 + false;", M));
@@ -218,8 +220,9 @@
   EXPECT_FALSE(matches("int x = 1 - false;", M));
   EXPECT_FALSE(matches("int x = true - 1;", M));
 
-  llvm::Optional HasParameter(Parser::parseMatcherExpression(
-  "functionDecl(hasParameter(1, hasName(\"x\")))", &Error));
+  Code = "functionDecl(hasParameter(1, hasName(\"x\")))";
+  llvm::Optional HasParameter(
+  Parser::parseMatcherExpression(Code, &Error));
   EXPECT_EQ("", Error.toStringFull());
   M = HasParameter->unconditionalConvertTo();
 
@@ -228,20 +231,18 @@
 
   // Test named values.
   auto NamedValues = getTestNamedValues();
+
+  Code = "functionDecl(hasParamA, hasParameter(1, hasName(nameX)))";
   llvm::Optional HasParameterWithNamedValues(
-  Parser::parseMatcherExpression(
-  "functionDecl(hasParamA, hasParameter(1, hasName(nameX)))",
-  nullptr, &NamedValues, &Error));
+  Parser::parseMatcherExpression(Code, nullptr, &NamedValues, &Error));
   EXPECT_EQ("", Error.toStringFull());
   M = HasParameterWithNamedValues->unconditionalConvertTo();
 
   EXPECT_TRUE(matches("void f(int a, int x);", M));
   EXPECT_FALSE(matches("void f(int x, int a);", M));
 
-
-  EXPECT_TRUE(!Parser::parseMatcherExpression(
-   "hasInitializer(\nbinaryOperator(hasLHS(\"A\")))",
-   &Error).hasValue());
+  Code = "hasInitializer(\nbinaryOperator(hasLHS(\"A\")))";
+  EXPECT_TRUE(!Parser::parseMatcherExpression(Code, &Error).hasValue());
   EXPECT_EQ("1:1: Error parsing argument 1 for matcher hasInitializer.\n"
 "2:5: Error parsing argument 1 for matcher binaryOperator.\n"
 "2:20: Error building matcher hasLHS.\n"
@@ -252,9 +253,11 @@
 
 TEST(ParserTest, VariadicMatchTest) {
   Diagnostics Error;
-  llvm::Optional OM(Parser::parseMatcherExpression(
-  "stmt(objcMessageExpr(hasAnySelector(\"methodA\", \"methodB:\")))",
-  &Error));
+
+  StringRef Code =
+  "stmt(objcMessageExpr(hasAnySelector(\"methodA\", \"methodB:\")))";
+  llvm::Optional OM(
+  Parser::parseMatcherExpression(Code, &Error));
   EXPECT_EQ("", Error.toStringFull());
   auto M = OM->unconditionalConvertTo();
   EXPECT_TRUE(matchesObjC("@interface I @end "
@@ -324,15 +327,132 @@
 ParseWithError("callee(\"A\")"));
 }
 
+TEST(ParserTest, ParseMultiline) {
+  StringRef Code;
+
+  llvm::Optional M;
+  {
+Code = R"matcher(varDecl(
+  hasName("foo")
+  )
+)matcher";
+Diagnostics Error;
+EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+  }
+
+  {
+Code = R"matcher(varDecl(
+  # Internal comment
+  hasName("foo") # Internal comment
+# Internal comment
+  )
+)matcher";
+Diagnostics Error;
+EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+  }
+
+  {
+Code = R"matcher(decl().bind(
+  "paramName")
+)matcher";
+Diagnostics Error;
+EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+  }
+
+  {
+Code = R"matcher(decl().bind(
+  "paramName"
+  )
+)matcher";
+Diagnostics Error;
+EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+  }
+
+  {
+Code = R"matcher(decl(decl()
+, decl()))matcher";
+Diagnostics Error;
+EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+  }
+
+  {
+Code = R"matcher(decl(decl(),
+decl()))matcher";
+Diagnostics Error;
+EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+  }
+
+  {
+Code = "namedDecl(hasName(\"n\"\n))";
+Diagnostics Error;
+EXPECT_TRUE(Pa

[PATCH] D71830: [OpenMP] Reusable OpenMP context/traits handling

2019-12-23 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D71830#1794920 , @JonChesterfield 
wrote:

> Big patch but looks like a net decrease in complexity. Please could you clang 
> format the areas phabricator is complaining about?


I'll go over it. (FWIW, I do clang format my patch automatically on each save 
but sometimes I want to minimize the change and only commit affected lines 
instead of reformatting the surrounding, e.g., a switch. Also, some of the lint 
warnings are not good, e.g., the `set_is_strict_subset` one.) I'll also add 
tests for the new capabilities and maybe Gunit tests for the lib/Frontend parts.

> Reading through on a browser looks great. I'll take a closer look in a real 
> editor once Christmas is out of the way. Thanks for posting this.

It is a reusable, very generic approach with almost all context selector sets, 
selectors, and properties. So while there is a net increase in lines, a lot of 
them are in OMPContext.{h,cpp} with little complexity or able to handle more 
than we could (e.g., the scoring).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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


[PATCH] D71666: [clang-tidy] Fix readability-const-return-type identifying the wrong `const` token

2019-12-23 Thread Ilya Mirsky via Phabricator via cfe-commits
ilya updated this revision to Diff 235156.
ilya added a comment.

Update LexerUtils.h documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71666

Files:
  clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
@@ -37,6 +37,9 @@
 template 
 typename std::add_const::type n15(T v) { return v; }
 
+template 
+struct MyStruct {};
+
 template 
 class Klazz {
 public:
@@ -128,10 +131,46 @@
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz'
 // CHECK-FIXES: Klazz p12() {}
 
+const Klazz> p33() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<
+// CHECK-FIXES: Klazz> p33() {}
+
 const Klazz* const p13() {}
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz *
 // CHECK-FIXES: const Klazz* p13() {}
 
+const Klazz* const volatile p14() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz *
+// CHECK-FIXES: const Klazz* volatile p14() {}
+
+const MyStruct<0 < 1> p34() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const MyStruct<0 < 1>'
+// CHECK-FIXES: MyStruct<0 < 1> p34() {}
+
+MyStruct<0 < 1> const p35() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const MyStruct<0 < 1>'
+// CHECK-FIXES: MyStruct<0 < 1> p35() {}
+
+Klazz const> const p36() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz const> p36() {}
+
+const Klazz const> *const p37() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz const> *p37() {}
+
+Klazz> const p38() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz> p38() {}
+
+const Klazz> p39() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<
+// CHECK-FIXES: Klazz> p39() {}
+
+const Klazz 1)>> p40() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz 1)>> p40() {}
+
 // re-declaration of p15.
 const int p15();
 // CHECK-FIXES: int p15();
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -92,13 +92,15 @@
  const SourceManager &SM,
  const LangOptions &LangOpts);
 
-/// Assuming that ``Range`` spans a const-qualified type, returns the ``const``
-/// token in ``Range`` that is responsible for const qualification. ``Range``
-/// must be valid with respect to ``SM``.  Returns ``None`` if no ``const``
+/// Assuming that ``Range`` spans a CVR-qualified type, returns the
+/// token in ``Range`` that is responsible for the qualification. ``Range``
+/// must be valid with respect to ``SM``.  Returns ``None`` if no qualifying
 /// tokens are found.
-llvm::Optional getConstQualifyingToken(CharSourceRange Range,
-  const ASTContext &Context,
-  const SourceManager &SM);
+/// Note: doesn't support member function qualifiers.
+llvm::Optional getQualifyingToken(tok::TokenKind TK,
+ CharSourceRange Range,
+ const ASTContext &Context,
+ const SourceManager &SM);
 
 } // namespace lexer
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -102,15 +102,20 @@
   return false;
 }
 
-llvm::Optional getConstQualifyingToken(CharSourceRange Range,
-  const ASTContext &Context,
-  const SourceManager &SM) {
+llvm::Optional getQualifyingToken(tok::TokenKind TK,
+ CharSourceRange Range,
+ const ASTContext &Context,
+ const SourceManager &SM) {
+  assert((TK == tok::kw_const || TK == tok::kw_volatile ||
+  TK == tok::kw_restrict) &&
+ "TK is not a qualifier keyword");
   std::pair LocInfo = SM.getDecomposedLoc(Range.getBegin());
   StringRef File = SM.getBufferData(LocInfo.first);
   Lexer RawLexer(SM.getLocForStartOfFile(LocInfo.first), Context.get

[PATCH] D71830: [OpenMP] Reusable OpenMP context/traits handling

2019-12-23 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 60967 tests passed, 0 failed 
and 726 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/D71830/new/

https://reviews.llvm.org/D71830



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


[PATCH] D71666: [clang-tidy] Fix readability-const-return-type identifying the wrong `const` token

2019-12-23 Thread Ilya Mirsky via Phabricator via cfe-commits
ilya marked 2 inline comments as done.
ilya added a comment.

@aaron.ballman, thanks for reviewing. Do you mind submitting this, as I don't 
have commit access?




Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.h:95-97
+/// Assuming that ``Range`` spans a CVR-qualified type, returns the
+/// token in ``Range`` that is responsible for the qualification. ``Range``
+/// must be valid with respect to ``SM``.  Returns ``None`` if no qualifying

aaron.ballman wrote:
> Should we add a comment that this is not for getting a member function 
> qualifier? (I am assuming that case was never intended to work, but if it 
> does work, should we also support ref qualifiers in that case?)
That's a good point. For the purposes that this function is currently being 
used, I don't see a reason to support member function qualifiers - updated the 
documentation accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71666



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


[PATCH] D71666: [clang-tidy] Fix readability-const-return-type identifying the wrong `const` token

2019-12-23 Thread Ilya Mirsky via Phabricator via cfe-commits
ilya updated this revision to Diff 235157.
ilya marked an inline comment as done.
ilya added a comment.

Doxygen format the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71666

Files:
  clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
@@ -37,6 +37,9 @@
 template 
 typename std::add_const::type n15(T v) { return v; }
 
+template 
+struct MyStruct {};
+
 template 
 class Klazz {
 public:
@@ -128,10 +131,46 @@
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz'
 // CHECK-FIXES: Klazz p12() {}
 
+const Klazz> p33() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<
+// CHECK-FIXES: Klazz> p33() {}
+
 const Klazz* const p13() {}
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz *
 // CHECK-FIXES: const Klazz* p13() {}
 
+const Klazz* const volatile p14() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz *
+// CHECK-FIXES: const Klazz* volatile p14() {}
+
+const MyStruct<0 < 1> p34() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const MyStruct<0 < 1>'
+// CHECK-FIXES: MyStruct<0 < 1> p34() {}
+
+MyStruct<0 < 1> const p35() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const MyStruct<0 < 1>'
+// CHECK-FIXES: MyStruct<0 < 1> p35() {}
+
+Klazz const> const p36() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz const> p36() {}
+
+const Klazz const> *const p37() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz const> *p37() {}
+
+Klazz> const p38() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz> p38() {}
+
+const Klazz> p39() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<
+// CHECK-FIXES: Klazz> p39() {}
+
+const Klazz 1)>> p40() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz 1)>> p40() {}
+
 // re-declaration of p15.
 const int p15();
 // CHECK-FIXES: int p15();
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -92,13 +92,15 @@
  const SourceManager &SM,
  const LangOptions &LangOpts);
 
-/// Assuming that ``Range`` spans a const-qualified type, returns the ``const``
-/// token in ``Range`` that is responsible for const qualification. ``Range``
-/// must be valid with respect to ``SM``.  Returns ``None`` if no ``const``
+/// Assuming that ``Range`` spans a CVR-qualified type, returns the
+/// token in ``Range`` that is responsible for the qualification. ``Range``
+/// must be valid with respect to ``SM``.  Returns ``None`` if no qualifying
 /// tokens are found.
-llvm::Optional getConstQualifyingToken(CharSourceRange Range,
-  const ASTContext &Context,
-  const SourceManager &SM);
+/// \note: doesn't support member function qualifiers.
+llvm::Optional getQualifyingToken(tok::TokenKind TK,
+ CharSourceRange Range,
+ const ASTContext &Context,
+ const SourceManager &SM);
 
 } // namespace lexer
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -102,15 +102,20 @@
   return false;
 }
 
-llvm::Optional getConstQualifyingToken(CharSourceRange Range,
-  const ASTContext &Context,
-  const SourceManager &SM) {
+llvm::Optional getQualifyingToken(tok::TokenKind TK,
+ CharSourceRange Range,
+ const ASTContext &Context,
+ const SourceManager &SM) {
+  assert((TK == tok::kw_const || TK == tok::kw_volatile ||
+  TK == tok::kw_restrict) &&
+ "TK is not a qualifier keyword");
   std::pair LocInfo = SM.getDecomposedLoc(Range.getBegin());
   StringRef File = SM.getBufferData(LocInfo.first);
   Lexer RawLexer(SM.getLocFor

[clang-tools-extra] d2c9c91 - Move from a long list of checkers to tables

2019-12-23 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2019-12-23T18:44:31+01:00
New Revision: d2c9c9157b0528436d3b9f5e22c872f0ee6509a2

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

LOG: Move from a long list of checkers to tables

Summary:
Currently, the list isn't very useful.
This change adds two tables.

* The checkers
* The aliases

For each checkers, we provide extract info:

* the severity. Taken from codechecker - 
https://github.com/Ericsson/codechecker/blob/master/config/checker_severity_map.json
* if the checker has an autofix or not

I used the cvs format for the table because:
* it is easy
* the data could be reused by other tools (we could move
that into a separated / generated file at some point)

Reviewers: alexfh, jdoerfert, jfb, lebedev.ri, Eugene.Zelenko

Subscribers: dexonsmith, wuzish, nemanjai, kbarton, arphaman, lebedev.ri, 
whisperity, Eugene.Zelenko, JonasToth, JDevlieghere, xazax.hun, cfe-commits, 
#clang-tools-extra

Tags: #clang

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

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 565fe7a03c09..08805ea248eb 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -3,388 +3,408 @@
 Clang-Tidy Checks
 =
 
+.. Severities are coming from Codechecker:
+   
https://github.com/Ericsson/codechecker/blob/master/config/checker_severity_map.json
+   If you change it here, please submit a PR on codechecker too
+
+.. csv-table::
+   :header: "Name", "Offers fixes", "Severity"
+   :widths: 50, 20, 10
+
+   `abseil-duration-addition `_, "Yes", ""
+   `abseil-duration-comparison `_, "Yes", ""
+   `abseil-duration-conversion-cast `_, 
"Yes", ""
+   `abseil-duration-division `_, "Yes", ""
+   `abseil-duration-factory-float `_, 
"Yes", ""
+   `abseil-duration-factory-scale `_, 
"Yes", ""
+   `abseil-duration-subtraction `_, "Yes", ""
+   `abseil-duration-unnecessary-conversion 
`_, "Yes", ""
+   `abseil-faster-strsplit-delimiter 
`_, "Yes", ""
+   `abseil-no-internal-dependencies `_, 
, ""
+   `abseil-no-namespace `_, , ""
+   `abseil-redundant-strcat-calls `_, 
"Yes", ""
+   `abseil-str-cat-append `_, "Yes", ""
+   `abseil-string-find-startswith `_, 
"Yes", "style"
+   `abseil-time-comparison `_, "Yes", ""
+   `abseil-time-subtraction `_, "Yes", ""
+   `abseil-upgrade-duration-conversions 
`_, "Yes", ""
+   `android-cloexec-accept `_, "Yes", ""
+   `android-cloexec-accept4 `_, , ""
+   `android-cloexec-creat `_, , "medium"
+   `android-cloexec-dup `_, , ""
+   `android-cloexec-epoll-create `_, , ""
+   `android-cloexec-epoll-create1 `_, , ""
+   `android-cloexec-fopen `_, , "medium"
+   `android-cloexec-inotify-init `_, , ""
+   `android-cloexec-inotify-init1 `_, , ""
+   `android-cloexec-memfd-create `_, , ""
+   `android-cloexec-open `_, , "medium"
+   `android-cloexec-pipe `_, , ""
+   `android-cloexec-pipe2 `_, , ""
+   `android-cloexec-socket `_, , "medium"
+   `android-comparison-in-temp-failure-retry 
`_, "Yes", ""
+   `boost-use-to-string `_, "Yes", "low"
+   `bugprone-argument-comment `_, "Yes", "low"
+   `bugprone-assert-side-effect `_, , 
"medium"
+   `bugprone-bad-signal-to-kill-thread 
`_, , ""
+   `bugprone-bool-pointer-implicit-conversion 
`_, "Yes", "low"
+   `bugprone-branch-clone `_, , "low"
+   `bugprone-copy-constructor-init `_, 
"Yes", "medium"
+   `bugprone-dangling-handle `_, , "high"
+   `bugprone-dynamic-static-initializers 
`_, , ""
+   `bugprone-exception-escape `_, , "medium"
+   `bugprone-fold-init-type `_, , "high"
+   `bugprone-forward-declaration-namespace 
`_, , "low"
+   `bugprone-forwarding-reference-overload 
`_, , "low"
+   `bugprone-inaccurate-erase `_, "Yes", "high"
+   `bugprone-incorrect-roundings `_, , 
"high"
+   `bugprone-infinite-loop `_, , "medium"
+   `bugprone-integer-division `_, , "medium"
+   `bugprone-lambda-function-name `_, , 
"low"
+   `bugprone-macro-parentheses `_, "Yes", 
"medium"
+   `bugprone-macro-repeated-side-effects 
`_, , "medium"
+   `bugprone-misplaced-operator-in-strlen-in-alloc 
`_, , "medium"
+   `bugprone-misplaced-widening-cast 
`_, "Yes", "high"
+   `bugprone-move-forwarding-reference 
`_, "Yes", "medium"
+   `bugprone-multiple-statement-macro 
`_, , "medium"
+   `bugprone-not-null-terminated-result 
`_, "Yes", "medium"
+   `bugprone-parent-virtual-call `_, "Yes", 
"medium"
+   `bugprone-posix-return `_, "Yes", ""
+   `bugprone-sizeof-container `_, , "high"
+   `bugprone-sizeof-expression `_, , "high"
+   `bugprone-string-constructor `_, "Yes", 
"high"
+   `bugprone-string-integer-assignment 
`_, "Yes", "low"
+   `bugprone-strin

[PATCH] D36051: Move from a long list of checkers to tables

2019-12-23 Thread Sylvestre Ledru 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 rGd2c9c9157b05: Move from a long list of checkers to tables 
(authored by sylvestre.ledru).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36051

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

Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -3,388 +3,408 @@
 Clang-Tidy Checks
 =
 
+.. Severities are coming from Codechecker:
+   https://github.com/Ericsson/codechecker/blob/master/config/checker_severity_map.json
+   If you change it here, please submit a PR on codechecker too
+
+.. csv-table::
+   :header: "Name", "Offers fixes", "Severity"
+   :widths: 50, 20, 10
+
+   `abseil-duration-addition `_, "Yes", ""
+   `abseil-duration-comparison `_, "Yes", ""
+   `abseil-duration-conversion-cast `_, "Yes", ""
+   `abseil-duration-division `_, "Yes", ""
+   `abseil-duration-factory-float `_, "Yes", ""
+   `abseil-duration-factory-scale `_, "Yes", ""
+   `abseil-duration-subtraction `_, "Yes", ""
+   `abseil-duration-unnecessary-conversion `_, "Yes", ""
+   `abseil-faster-strsplit-delimiter `_, "Yes", ""
+   `abseil-no-internal-dependencies `_, , ""
+   `abseil-no-namespace `_, , ""
+   `abseil-redundant-strcat-calls `_, "Yes", ""
+   `abseil-str-cat-append `_, "Yes", ""
+   `abseil-string-find-startswith `_, "Yes", "style"
+   `abseil-time-comparison `_, "Yes", ""
+   `abseil-time-subtraction `_, "Yes", ""
+   `abseil-upgrade-duration-conversions `_, "Yes", ""
+   `android-cloexec-accept `_, "Yes", ""
+   `android-cloexec-accept4 `_, , ""
+   `android-cloexec-creat `_, , "medium"
+   `android-cloexec-dup `_, , ""
+   `android-cloexec-epoll-create `_, , ""
+   `android-cloexec-epoll-create1 `_, , ""
+   `android-cloexec-fopen `_, , "medium"
+   `android-cloexec-inotify-init `_, , ""
+   `android-cloexec-inotify-init1 `_, , ""
+   `android-cloexec-memfd-create `_, , ""
+   `android-cloexec-open `_, , "medium"
+   `android-cloexec-pipe `_, , ""
+   `android-cloexec-pipe2 `_, , ""
+   `android-cloexec-socket `_, , "medium"
+   `android-comparison-in-temp-failure-retry `_, "Yes", ""
+   `boost-use-to-string `_, "Yes", "low"
+   `bugprone-argument-comment `_, "Yes", "low"
+   `bugprone-assert-side-effect `_, , "medium"
+   `bugprone-bad-signal-to-kill-thread `_, , ""
+   `bugprone-bool-pointer-implicit-conversion `_, "Yes", "low"
+   `bugprone-branch-clone `_, , "low"
+   `bugprone-copy-constructor-init `_, "Yes", "medium"
+   `bugprone-dangling-handle `_, , "high"
+   `bugprone-dynamic-static-initializers `_, , ""
+   `bugprone-exception-escape `_, , "medium"
+   `bugprone-fold-init-type `_, , "high"
+   `bugprone-forward-declaration-namespace `_, , "low"
+   `bugprone-forwarding-reference-overload `_, , "low"
+   `bugprone-inaccurate-erase `_, "Yes", "high"
+   `bugprone-incorrect-roundings `_, , "high"
+   `bugprone-infinite-loop `_, , "medium"
+   `bugprone-integer-division `_, , "medium"
+   `bugprone-lambda-function-name `_, , "low"
+   `bugprone-macro-parentheses `_, "Yes", "medium"
+   `bugprone-macro-repeated-side-effects `_, , "medium"
+   `bugprone-misplaced-operator-in-strlen-in-alloc `_, , "medium"
+   `bugprone-misplaced-widening-cast `_, "Yes", "high"
+   `bugprone-move-forwarding-reference `_, "Yes", "medium"
+   `bugprone-multiple-statement-macro `_, , "medium"
+   `bugprone-not-null-terminated-result `_, "Yes", "medium"
+   `bugprone-parent-virtual-call `_, "Yes", "medium"
+   `bugprone-posix-return `_, "Yes", ""
+   `bugprone-sizeof-container `_, , "high"
+   `bugprone-sizeof-expression `_, , "high"
+   `bugprone-string-constructor `_, "Yes", "high"
+   `bugprone-string-integer-assignment `_, "Yes", "low"
+   `bugprone-string-literal-with-embedded-nul `_, , "medium"
+   `bugprone-suspicious-enum-usage `_, , "high"
+   `bugprone-suspicious-memset-usage `_, "Yes", "high"
+   `bugprone-suspicious-missing-comma `_, , "high"
+   `bugprone-suspicious-semicolon `_, "Yes", "high"
+   `bugprone-suspicious-string-compare `_, "Yes", "medium"
+   `bugprone-swapped-arguments `_, "Yes", "high"
+   `bugprone-terminating-continue `_, "Yes", "medium"
+   `bugprone-throw-keyword-missing `_, , "medium"
+   `bugprone-too-small-loop-variable `_, , "medium"
+   `bugprone-undefined-memory-manipulation `_, , "medium"
+   `bugprone-undelegated-constructor `_, , "medium"
+   `bugprone-unhandled-self-assignment `_, , "medium"
+   `bugprone-unused-raii `_, "Yes", "high"
+   `bugprone-unused-return-value `_, , "medium"
+   `bugprone-use-after-move `_, , "high"
+   `bugprone-virtual-near-miss `_, "Yes", "medium"
+   `cert-dcl21-cpp `_, , "low"
+   `cert-dcl50-cpp

[PATCH] D71791: [CFG] Fix an assertion failure with static initializers

2019-12-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 235161.
xazax.hun added a comment.

I decided to fix the unittests. Having CFGs full of dangling pointers to the 
AST does not look fun at all, so I think this change was long overdue.


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

https://reviews.llvm.org/D71791

Files:
  clang/lib/Analysis/CFG.cpp
  clang/unittests/Analysis/CFGBuildResult.h
  clang/unittests/Analysis/CFGTest.cpp


Index: clang/unittests/Analysis/CFGTest.cpp
===
--- clang/unittests/Analysis/CFGTest.cpp
+++ clang/unittests/Analysis/CFGTest.cpp
@@ -30,6 +30,22 @@
   EXPECT_EQ(BuildResult::SawFunctionBody, BuildCFG(Code).getStatus());
 }
 
+TEST(CFG, StaticInitializerLastCondition) {
+  const char *Code = "void f() {\n"
+ "  int i = 5 ;\n"
+ "  static int j = 3 ;\n"
+ "}\n";
+  CFG::BuildOptions Options;
+  Options.AddStaticInitBranches = true;
+  Options.setAllAlwaysAdd();
+  BuildResult B = BuildCFG(Code, Options);
+  EXPECT_EQ(BuildResult::BuiltCFG, B.getStatus());
+  EXPECT_EQ(1, B.getCFG()->getEntry().succ_size());
+  CFGBlock *Block = *B.getCFG()->getEntry().succ_begin();
+  EXPECT_TRUE(isa(Block->getTerminatorStmt()));
+  EXPECT_EQ(nullptr, Block->getLastCondition());
+}
+
 // Constructing a CFG containing a delete expression on a dependent type should
 // not crash.
 TEST(CFG, DeleteExpressionOnDependentType) {
Index: clang/unittests/Analysis/CFGBuildResult.h
===
--- clang/unittests/Analysis/CFGBuildResult.h
+++ clang/unittests/Analysis/CFGBuildResult.h
@@ -27,15 +27,19 @@
 
   Status getStatus() const { return S; }
   CFG *getCFG() const { return Cfg.get(); }
+  ASTUnit *getAST() const { return AST.get(); }
+  void setAST(std::unique_ptr AST) { this->AST = std::move(AST); }
 
 private:
   Status S;
   std::unique_ptr Cfg;
+  std::unique_ptr AST;
 };
 
 class CFGCallback : public ast_matchers::MatchFinder::MatchCallback {
 public:
   BuildResult TheBuildResult = BuildResult::ToolRan;
+  CFG::BuildOptions Options;
 
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
 const auto *Func = Result.Nodes.getNodeAs("func");
@@ -43,7 +47,6 @@
 if (!Body)
   return;
 TheBuildResult = BuildResult::SawFunctionBody;
-CFG::BuildOptions Options;
 Options.AddImplicitDtors = true;
 if (std::unique_ptr Cfg =
 CFG::buildCFG(nullptr, Body, Result.Context, Options))
@@ -51,17 +54,19 @@
   }
 };
 
-inline BuildResult BuildCFG(const char *Code) {
+inline BuildResult BuildCFG(const char *Code, CFG::BuildOptions Options = {}) {
   CFGCallback Callback;
+  Callback.Options = Options;
 
   ast_matchers::MatchFinder Finder;
   Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
-  std::unique_ptr Factory(
-  tooling::newFrontendActionFactory(&Finder));
   std::vector Args = {"-std=c++11",
"-fno-delayed-template-parsing"};
-  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args))
+  std::unique_ptr AST = tooling::buildASTFromCodeWithArgs(Code, Args);
+  if (!AST)
 return BuildResult::ToolFailed;
+  Finder.matchAST(AST->getASTContext());
+  Callback.TheBuildResult.setAST(std::move(AST));
   return std::move(Callback.TheBuildResult);
 }
 
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -5919,7 +5919,7 @@
 return nullptr;
 
   const Stmt *Cond = StmtElem->getStmt();
-  if (isa(Cond))
+  if (isa(Cond) || isa(Cond))
 return nullptr;
 
   // Only ObjCForCollectionStmt is known not to be a non-Expr terminator, hence


Index: clang/unittests/Analysis/CFGTest.cpp
===
--- clang/unittests/Analysis/CFGTest.cpp
+++ clang/unittests/Analysis/CFGTest.cpp
@@ -30,6 +30,22 @@
   EXPECT_EQ(BuildResult::SawFunctionBody, BuildCFG(Code).getStatus());
 }
 
+TEST(CFG, StaticInitializerLastCondition) {
+  const char *Code = "void f() {\n"
+ "  int i = 5 ;\n"
+ "  static int j = 3 ;\n"
+ "}\n";
+  CFG::BuildOptions Options;
+  Options.AddStaticInitBranches = true;
+  Options.setAllAlwaysAdd();
+  BuildResult B = BuildCFG(Code, Options);
+  EXPECT_EQ(BuildResult::BuiltCFG, B.getStatus());
+  EXPECT_EQ(1, B.getCFG()->getEntry().succ_size());
+  CFGBlock *Block = *B.getCFG()->getEntry().succ_begin();
+  EXPECT_TRUE(isa(Block->getTerminatorStmt()));
+  EXPECT_EQ(nullptr, Block->getLastCondition());
+}
+
 // Constructing a CFG containing a delete expression on a dependent type should
 // not crash.
 TEST(CFG, DeleteExpressionOnDependentType) {
Index: clang/unittests/Analysis/CFGBuildResult.h
===
---

[PATCH] D69272: Restricted variant of '#pragma STDC FENV_ACCESS'

2019-12-23 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

In D69272#1794630 , @sepavloff wrote:

> Putting restriction on use of the pragma is of course, a temporary solution, 
> it is not usable in all cases. But for some cases it is usable in production 
> code. Where small pieces of code may be extracted into separate functions, 
> this solution can provide tolerable performance loss, if most part of the 
> program doesn't use constrained intrinsics. Warning prevents users from false 
> expectations. Use in production code ensures further development of the 
> feature.
>
> Full-fledged solution requires full support of constrained intrinsics in 
> optimizations. It is not clear how large this work is, but odd are that it 
> would require substantial efforts. It this case usable implementation of 
> 'pragma STDC FE_ACCESS' would postponed. The restricted solution can be 
> implemented much faster and it does not impede development of the 
> full-fledged one.


It depends on the definition of "usable" or "tolerable", and the definition 
that matters is the one users have.

If #pragma is restricted to no smaller than whole functions then a function 
that uses it inside the body won't compile. We made the decision instead of the 
user.

If #pragma is not restricted, but triggers worse performance in the rest of the 
function, then users can decide for themselves if that is acceptable.

We should leave the decision up to the end-user. The idea of always using 
constrained intrinsics if any constrained intrinsic is used in a function is 
our best bet at getting something in the hands of users sooner rather than 
later and without them having to do any rewriting of existing code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69272



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


[PATCH] D70689: [analyzer] Fix SARIF column locations

2019-12-23 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech marked an inline comment as not done.
jranieri-grammatech added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp:157
+  const MemoryBuffer *Buf = SM.getBuffer(LocInfo.first);
+  assert(Buf && "got a NULL buffer for the location's file");
+  assert(Buf->getBufferSize() >= (LocInfo.second + TokenLen) &&

aaron.ballman wrote:
> I don't think this API is able to return a null buffer, but it can return an 
> invalid buffer under legitimate circumstances, I believe. For instance, if 
> the source location is in the scratch space used for things like macros 
> defined on the command line with `-D`. I think you should pass the optional 
> `invalid` parameter to the call to `getBuffer()` and then do no adjustments 
> if the buffer is invalid. WDYT?
Good catch that this can't return NULL.

I tested out defining things on the command line, but this code deals with 
expansion locations and wasn't affected by it. Unless you can think of a way to 
reproduce it, I think I'd rather pass in the `invalid` argument and assert that 
it isn't invalid.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70689



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


[clang] d35bcbb - [Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize.

2019-12-23 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2019-12-23T11:23:30-08:00
New Revision: d35bcbbb5dab0e29b21a586505f5b274377cc41b

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

LOG: [Sema][X86] Consider target attribute into the checks in 
validateOutputSize and validateInputSize.

The validateOutputSize and validateInputSize need to check whether
AVX or AVX512 are enabled. But this can be affected by the
target attribute so we need to factor that in.

This patch moves some of the code from CodeGen to create an
appropriate feature map that we can pass to the function.

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/CodeGen/x86_32-inline-asm.c

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 92f81eb55ed7..6d1265ca6474 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -95,6 +95,7 @@ class CXXRecordDecl;
 class DiagnosticsEngine;
 class Expr;
 class FixedPointSemantics;
+class GlobalDecl;
 class MangleContext;
 class MangleNumberingContext;
 class MaterializeTemporaryExpr;
@@ -112,9 +113,11 @@ class ObjCPropertyDecl;
 class ObjCPropertyImplDecl;
 class ObjCProtocolDecl;
 class ObjCTypeParamDecl;
+class ParsedTargetAttr;
 class Preprocessor;
 class Stmt;
 class StoredDeclsMap;
+class TargetAttr;
 class TemplateDecl;
 class TemplateParameterList;
 class TemplateTemplateParmDecl;
@@ -2838,6 +2841,15 @@ class ASTContext : public RefCountedBase {
   /// PredefinedExpr to cache evaluated results.
   StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
 
+  /// Parses the target attributes passed in, and returns only the ones that 
are
+  /// valid feature names.
+  ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
+
+  void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
+ const FunctionDecl *) const;
+  void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
+ GlobalDecl GD) const;
+
   
//======//
   //Statistics
   
//======//

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index bc06f59d41d4..a32b30f5b7e9 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -945,12 +945,14 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   bool validateInputConstraint(MutableArrayRef 
OutputConstraints,
ConstraintInfo &info) const;
 
-  virtual bool validateOutputSize(StringRef /*Constraint*/,
+  virtual bool validateOutputSize(const llvm::StringMap &FeatureMap,
+  StringRef /*Constraint*/,
   unsigned /*Size*/) const {
 return true;
   }
 
-  virtual bool validateInputSize(StringRef /*Constraint*/,
+  virtual bool validateInputSize(const llvm::StringMap &FeatureMap,
+ StringRef /*Constraint*/,
  unsigned /*Size*/) const {
 return true;
   }

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a09b1aca7c20..d26e7f789d0a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -10817,3 +10817,66 @@ QualType 
ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const {
 llvm_unreachable("Unexpected unsigned fixed point type");
   }
 }
+
+ParsedTargetAttr
+ASTContext::filterFunctionTargetAttrs(const TargetAttr *TD) const {
+  assert(TD != nullptr);
+  ParsedTargetAttr ParsedAttr = TD->parse();
+
+  ParsedAttr.Features.erase(
+  llvm::remove_if(ParsedAttr.Features,
+  [&](const std::string &Feat) {
+return !Target->isValidFeatureName(
+StringRef{Feat}.substr(1));
+  }),
+  ParsedAttr.Features.end());
+  return ParsedAttr;
+}
+
+void ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
+   const FunctionDecl *FD) const {
+  if (FD)
+getFunctionFeatureMap(FeatureMap, GlobalDecl().getWithDecl(FD));
+  else
+Target->initFeatureMap(FeatureMap, getDiagnostics(),
+   Target->getTargetO

[PATCH] D68627: [Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize.

2019-12-23 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd35bcbbb5dab: [Sema][X86] Consider target attribute into the 
checks in validateOutputSize and… (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D68627?vs=232666&id=235168#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68627

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/CodeGen/x86_32-inline-asm.c

Index: clang/test/CodeGen/x86_32-inline-asm.c
===
--- clang/test/CodeGen/x86_32-inline-asm.c
+++ clang/test/CodeGen/x86_32-inline-asm.c
@@ -70,3 +70,35 @@
   __asm__ volatile("foo1 %0" : "=x" (val256)); // expected-error {{invalid output size for constraint '=x'}}
 #endif
 }
+
+int __attribute__((__target__("sse"))) _func2() {
+  __asm__ volatile("foo1 %0" : : "x" (val128)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val128));  // No error.
+#ifdef __AVX__
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val256));  // No error.
+#else
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // expected-error {{invalid input size for constraint 'x'}}
+  __asm__ volatile("foo1 %0" : "=x" (val256)); // expected-error {{invalid output size for constraint '=x'}}
+#endif
+  __asm__ volatile("foo1 %0" : : "x" (val512)); // expected-error {{invalid input size for constraint 'x'}}
+  __asm__ volatile("foo1 %0" : "=x" (val512)); // expected-error {{invalid output size for constraint '=x'}}
+}
+
+int __attribute__((__target__("avx"))) _func3() {
+  __asm__ volatile("foo1 %0" : : "x" (val128)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val128));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val256));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val512)); // expected-error {{invalid input size for constraint 'x'}}
+  __asm__ volatile("foo1 %0" : "=x" (val512)); // expected-error {{invalid output size for constraint '=x'}}
+}
+
+int __attribute__((__target__("avx512f"))) _func4() {
+  __asm__ volatile("foo1 %0" : : "x" (val128)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val128));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val256));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val512)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val512)); // No error.
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/GlobalDecl.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/TargetInfo.h"
@@ -255,6 +256,10 @@
   // The parser verifies that there is a string literal here.
   assert(AsmString->isAscii());
 
+  FunctionDecl *FD = dyn_cast(getCurLexicalContext());
+  llvm::StringMap FeatureMap;
+  Context.getFunctionFeatureMap(FeatureMap, FD);
+
   for (unsigned i = 0; i != NumOutputs; i++) {
 StringLiteral *Literal = Constraints[i];
 assert(Literal->isAscii());
@@ -325,8 +330,8 @@
 }
 
 unsigned Size = Context.getTypeSize(OutputExpr->getType());
-if (!Context.getTargetInfo().validateOutputSize(Literal->getString(),
-Size)) {
+if (!Context.getTargetInfo().validateOutputSize(
+FeatureMap, Literal->getString(), Size)) {
   targetDiag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
   << Info.getConstraintStr();
   return new (Context)
@@ -427,8 +432,8 @@
 return StmtError();
 
 unsigned Size = Context.getTypeSize(Ty);
-if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
-   Size))
+if (!Context.getTargetInfo().validateInputSize(FeatureMap,
+   Literal->getString(), Size))
   return StmtResult(
   targetDiag(InputExpr->getBeginLoc(), diag::err_asm_invalid_input_size)
   << Info.getConstraintStr());
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1157,14 +1157,6 @@
   /// It's up to you to ensure that this is safe.
   void AddDe

[PATCH] D71846: Fix for https://bugs.llvm.org/show_bug.cgi?id=44364

2019-12-23 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added a reviewer: clang-tools-extra.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds a new ASTMatcher condition called 'hasInitStorage()' that matches if and 
switch statements with initializer. Then tweaks the clang-tidy 
'readability-else-after-return' check to ignore if statements with an 
initializer as removing the else branch would result in the condition variable 
going out of scope


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71846

Files:
  clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4297,6 +4297,22 @@
   return Node.isConstexpr();
 }
 
+/// Matches selection statements with initializer
+///
+/// Given:
+/// \code
+///  if (int foo = bar(); bar > 0) {}
+///  switch (int baz = bar(); baz - 1) {}
+/// \endcode
+/// IfStmt(hasInitStorage())
+///   matches the declaration of foo.
+/// SwitchStmt(hasInitStorage())
+///   matches the declaration of baz.
+AST_POLYMORPHIC_MATCHER(hasInitStorage,
+AST_POLYMORPHIC_SUPPORTED_TYPES(IfStmt, SwitchStmt)) {
+  return Node.hasInitStorage();
+}
+
 /// Matches the condition expression of an if statement, for loop,
 /// switch statement or conditional operator.
 ///
Index: clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -26,12 +26,14 @@
   compoundStmt(forEach(
   ifStmt(unless(isConstexpr()),
  // FIXME: Explore alternatives for the
- // `if (T x = ...) {... return; } else {  }`
- // pattern:
+ // `if (T x = ...) {... return; } else {  }` and
+ // 'if (T x = ...; cond) {... return; } else { use  }'
+ // patterns:
  //   * warn, but don't fix;
  //   * fix by pulling out the variable declaration out of
  // the condition.
  unless(hasConditionVariableStatement(anything())),
+ unless(hasInitStorage()),
  hasThen(stmt(anyOf(InterruptsControlFlow,
 
compoundStmt(has(InterruptsControlFlow),
  hasElse(stmt().bind("else")))


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4297,6 +4297,22 @@
   return Node.isConstexpr();
 }
 
+/// Matches selection statements with initializer
+///
+/// Given:
+/// \code
+///  if (int foo = bar(); bar > 0) {}
+///  switch (int baz = bar(); baz - 1) {}
+/// \endcode
+/// IfStmt(hasInitStorage())
+///   matches the declaration of foo.
+/// SwitchStmt(hasInitStorage())
+///   matches the declaration of baz.
+AST_POLYMORPHIC_MATCHER(hasInitStorage,
+AST_POLYMORPHIC_SUPPORTED_TYPES(IfStmt, SwitchStmt)) {
+  return Node.hasInitStorage();
+}
+
 /// Matches the condition expression of an if statement, for loop,
 /// switch statement or conditional operator.
 ///
Index: clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -26,12 +26,14 @@
   compoundStmt(forEach(
   ifStmt(unless(isConstexpr()),
  // FIXME: Explore alternatives for the
- // `if (T x = ...) {... return; } else {  }`
- // pattern:
+ // `if (T x = ...) {... return; } else {  }` and
+ // 'if (T x = ...; cond) {... return; } else { use  }'
+ // patterns:
  //   * warn, but don't fix;
  //   * fix by pulling out the variable declaration out of
  // the condition.
  unless(hasConditionVariableStatement(anything())),
+ unless(hasInitStorage()),
  hasThen(stmt(anyOf(InterruptsControlFlow,
 compoundStmt(has(InterruptsControlFlow),
  hasElse(stmt().bind("else")))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70265: [clang-tidy] Add clang tidy check I.2 to cppcoreguidelines

2019-12-23 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal updated this revision to Diff 235176.
vingeldal marked 7 inline comments as done.
vingeldal added a comment.

Updating D70265 : [clang-tidy] Add clang tidy 
check I.2 to cppcoreguidelines

- Added an option to not check member variables.
- Add checking for member variables referencing or pointing to non-const data.
- Added some early returns in check implementation.
- Expanded documentation, with an example and link to C++ Core Guidelines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70265

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-non-const-global-variables.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables-NoMembers.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
@@ -0,0 +1,270 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-non-const-global-variables %t
+
+int nonConstInt = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+
+int &nonConstIntReference = nonConstInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'nonConstIntReference' provides global access to non-const type, consider making the referenced data const [cppcoreguidelines-avoid-non-const-global-variables]
+
+int *pointerToNonConstInt = &nonConstInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'pointerToNonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: variable 'pointerToNonConstInt' provides global access to non-const type, consider making the pointed to data const [cppcoreguidelines-avoid-non-const-global-variables]
+
+int *const constPointerToNonConstInt = &nonConstInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'constPointerToNonConstInt' provides global access to non-const type, consider making the pointed to data const [cppcoreguidelines-avoid-non-const-global-variables]
+
+namespace namespace_name {
+int nonConstNamespaceInt = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+
+const int constNamespaceInt = 0;
+} // namespace namespace_name
+
+const int constInt = 0;
+
+const int *pointerToConstInt = &constInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'pointerToConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+
+const int *const constPointerToConstInt = &constInt;
+
+const int &constReferenceToConstInt = constInt;
+
+constexpr int constexprInt = 0;
+
+int function() {
+  int nonConstReturnValue = 0;
+  return nonConstReturnValue;
+}
+
+namespace {
+int nonConstAnonymousNamespaceInt = 0;
+}
+
+class DummyClass {
+public:
+  int nonConstMemberVariable = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: member variable 'nonConstMemberVariable' is globally accessible and non-const, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+  const int constMemberVariable = 0;
+  int *const constMemberPointerToNonConst = &nonConstInt;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member variable 'constMemberPointerToNonConst' provides global access to non-const type, consider making the pointed to data const [cppcoreguidelines-avoid-non-const-global-variables]
+  int *memberPointerToNonConst = &nonConstInt;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member variable 'memberPointerToNonConst' is globally accessible and non-const, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+  // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: member variable 'memberPointerToNonConst' provides global access to non-const type, consider making the pointed to data const [cppcoreguidelines-avoid-non-const-global-variables]
+  const int *const constMemberPointerToConst = &constInt;
+  int &nonConstMemberReferenceToNonConst = nonCo

[PATCH] D70265: [clang-tidy] Add clang tidy check I.2 to cppcoreguidelines

2019-12-23 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp:64
+
+  if (Variable) {
+diag(Variable->getLocation(), "variable %0 is non-const and globally "

JonasToth wrote:
> each of those `if`s should `return` early, or could multiple match?
> If only one can match the structure could be changed a bit to
> ```
> if (const auto* Variable = 
> Result.Nodes.getNodeAs("non-const_variable")) {
> diag(...);
> return;
> }
> ```
> 
> If you change the order of the `if`s in the order of matches you expect to 
> happen most, this should be a bit faster as well, as retrieving the matches 
> introduces some overhead that is not relevant in the current situation.
> 
> If you keep only one statement within the `if` you should ellide the braces, 
> per coding convention.
There could be multiple matches but there could still be some early returns.
An example of a multi match would be:

namespace {
int i = 0;
}
int * i_ptr = &i;

There would be two warnings for i_ptr, since it is:
 1. A global non-const variable it self and...
 2. because it globally exposes the non-const variable i.

I'll add early returns where possible.

...Now that I think about it I realize I'v missed checking for member variables 
referencing or pointing to non-const data,
I'll add that tigether with some more testing.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:107
+
+  Finds non-const global variables as described in check I.2 of cpp core
+  guidelines.

JonasToth wrote:
> The official name is "C++ Core Guidelines", i think we should stick to that.
> And please ellide the new empty line above.
I'll remove the empty line,  I must ask about this formatting though.
I see multiple examples both with and without the empty line, so I just tried 
to be consistent with what most people seem to do.
What's the rule for knowing when to use one and when not to?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp:46
+  int nonConstMemberVariable = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: member variable 
'nonConstMemberVariable' is globally accessible and non-const, consider making 
it const [cppcoreguidelines-avoid-non-const-global-variables]
+  const int constMemberVariable = 0;

JonasToth wrote:
> diagnosing those might be undesired. maybe having an option to enable/disable 
> this would be nice?
> We should try to allow reducing the noise level of clang-tidy.
I can see your point and I agree that an option would be a good idea.
It isn't obvious that members variable could be considered global variables.
I'll make the current behavior the default though, since I got the impression
that in most  aligned with the intent of the guideline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70265



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


[clang] 4b64e03 - ASTContext: fix declaration of ParsedTargetAttr [-Wmismatched-tags] after D68627

2019-12-23 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2019-12-23T12:38:37-08:00
New Revision: 4b64e034612017fcc97b64d6031319cf18dbbb88

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

LOG: ASTContext: fix declaration of ParsedTargetAttr [-Wmismatched-tags] after 
D68627

Added: 


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

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 6d1265ca6474..d5ade9340c8e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -113,7 +113,7 @@ class ObjCPropertyDecl;
 class ObjCPropertyImplDecl;
 class ObjCProtocolDecl;
 class ObjCTypeParamDecl;
-class ParsedTargetAttr;
+struct ParsedTargetAttr;
 class Preprocessor;
 class Stmt;
 class StoredDeclsMap;



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


[PATCH] D68627: [Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize.

2019-12-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:116
 class ObjCTypeParamDecl;
+class ParsedTargetAttr;
 class Preprocessor;

This should be `struct`. I fixed it it in 
4b64e034612017fcc97b64d6031319cf18dbbb88


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68627



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


[PATCH] D70527: [clang] Fix the canonicalization of paths in -fdiagnostics-absolute-paths

2019-12-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Frontend/absolute-paths-symlinks.c:15
+
+// REQUIRES: shell

rnk wrote:
> I wish we had a more precise feature to indicate symlink support, but this is 
> what we do elsewhere, so there's nothing to do here.
I wrote:

```
## Don't make symlinks on Windows.
# UNSUPPORTED: system-windows
```

in D71302. Yeah, please tell me which precise feature I should use :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70527



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


[PATCH] D70527: [clang] Fix the canonicalization of paths in -fdiagnostics-absolute-paths

2019-12-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Basic/FileManager.cpp:562
 
-  CanonicalDirNames.insert({Dir, CanonicalName});
+  CanonicalNames.insert({Dir, CanonicalName});
+  return CanonicalName;

There is no need to change now, but I think try_emplace may be slightly more 
idiomatic as it saves a copy-list-initialization.



Comment at: clang/lib/Basic/FileManager.cpp:572
+
+  StringRef CanonicalName(File->getName());
+

There is no need to change now. `StringRef ... = ` may be more common.



Comment at: clang/test/Frontend/absolute-paths-symlinks.c:4
+// RUN: cd %t
+// RUN: cp "%s" "test.c"
+// RUN: ln -sf "test.c" "link.c"

No need to change now. Quotes are not needed.



Comment at: clang/test/Frontend/absolute-paths-symlinks.c:6
+// RUN: ln -sf "test.c" "link.c"
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-absolute-paths "link.c" 
2>&1|FileCheck %s
+

No need to change now. Spaces around `|`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70527



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


[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2019-12-23 Thread Ilya Mirsky via Phabricator via cfe-commits
ilya marked an inline comment as done.
ilya added a comment.

In D71714#1791464 , @riccibruno wrote:

> These are not the only AST nodes representing cast expressions (there is also 
> `CXXFunctionalCastExpr`, ...). What about replacing the 
> `IgnoreParenImpCasts()` above by `IgnoreParenCasts()` ? Incidentally doing 
> this uncovers another test (`Parser/cxx-ambig-decl-expr.cpp )` where this 
> diagnostic is triggered.


Thanks, using `IgnoreParenCasts` is even better.




Comment at: clang/lib/Sema/SemaChecking.cpp:13384
   case Stmt::MemberExprClass: {
 expr = cast(expr)->getBase();
 break;

rsmith wrote:
> Hmm, don't we need to do different things for dot and arrow in this case?
There are several test cases for an out of bounds access on an array member 
using dot and arrow operators in array-bounds.cpp. Do you have a specific test 
case for which you think the code is broken?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71714



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


[PATCH] D68627: [Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize.

2019-12-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper marked an inline comment as done.
craig.topper added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:116
 class ObjCTypeParamDecl;
+class ParsedTargetAttr;
 class Preprocessor;

MaskRay wrote:
> This should be `struct`. I fixed it it in 
> 4b64e034612017fcc97b64d6031319cf18dbbb88
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68627



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-12-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70696#1794440 , @rnk wrote:

> Three of these tests have been failing for me locally since this patch landed:
>
>   Failing Tests (3):
>   Clang :: CodeGen/debug-info-extern-basic.c
>   Clang :: CodeGen/debug-info-extern-duplicate.c
>   Clang :: CodeGen/debug-info-extern-multi.c 
>
>
> I suspect bots do not see these failures because the BPF target is 
> experimental. I would recommend that you:
>
> - do not use %clang in CodeGen tests, use %clang_cc1
> - find a way to make the test run without the BPF target
>
>   I'll take a look at fixing forward.


Got any more details on the nature of the failure/repro steps?

In D70696#1794480 , @yonghong-song 
wrote:

> @rnk I just submitted a patch https://reviews.llvm.org/D71818 to use 
> `%clang_cc1` instead of `%clang` in the test. Could you check whether this 
> fixed your issue or not?
>
> I cannot remove BPF target requirement as only BPF target can trigger debug 
> info generation for extern variables. This is by design as discussed in this 
> patch review due to concerns it may blow up debug info binary size for 
> existing applications. This may be relaxed in the future through some flags. 
> BPF is used on linux platform only.


If needed/useful, we could add a (just a cc1 flag, not a full driver flag) to 
support expliictly enabling this feature regardless of target, for testing 
purposes - but I'm not sure that's needed as yet.

> As far as I know, BPF is enabled for a lot of bots, ubuntu, x86, ppc, arm, 
> etc. So the coverage of this feature should be fine.

Could you link to particular bots that have logs showing they ran this test? 
(perhaps the logs have been retired by now, though - since this patch was 
reverted :/ - but then at least seeing which bots run BPF tests would be 
helpful)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[PATCH] D71848: Allow the discovery of Android NDK's triple-prefixed binaries.

2019-12-23 Thread Brian Ledger via Phabricator via cfe-commits
brianpl updated this revision to Diff 235182.
brianpl added a comment.

Fix a typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71848

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/android-triple-version.c

Index: clang/test/Driver/android-triple-version.c
===
--- /dev/null
+++ clang/test/Driver/android-triple-version.c
@@ -0,0 +1,141 @@
+// Android's target triples can contain a version number in the environment
+// field (e.g. arm-linux-androideabi9).
+// Make sure that any version is stripped when finding toolchain binaries.
+
+// Ensure no execute permissions on .../bin/{target-triple}/ld.
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld
+
+// Ensure execute permissions on .../bin/{target-triple}-ld
+// RUN: chmod +x  %S/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld
+// RUN: chmod +x  %S/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld
+// RUN: chmod +x %S/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld
+// RUN: chmod +x %S/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld
+
+// Test target arm-linux-androideabi
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-linux-androideabi %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-unknown-linux-androideabi
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-unknown-linux-androideabi %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-linux-androideabi14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-linux-androideabi14 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-linux-androideabi29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-linux-androideabi29 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-unknown-linux-androideabi14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-unknown-linux-androideabi14 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-unknown-linux-androideabi29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-unknown-linux-androideabi29 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target aarch64-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-linux-android %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-unknown-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-unknown-linux-android %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-linux-android14 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-linux-android29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-linux-android29 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-unknown-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-unknown-linux-android14 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-unknown-linux-android29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-unknown-linux-android29 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target i686-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-linux-android %s |& \
+// RUN: grep i686-linux-android-ld
+
+// Test target i686-unknown-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-unknown-linux-android %s |& \
+// RUN: grep i686-linux-android-ld
+
+// Test target i686-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-linux-android14 %s |& \
+// RUN: grep i686-linux-android-ld
+
+// Test target i686-linux-android29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-linux-android29 %s |& \
+// RUN: grep i686-linux-android-ld
+
+// Test target i686-unknown-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-unknown-linux-android14 %s |& \
+// RUN: grep i686-linux-andr

[PATCH] D70876: [clang-tidy] Add spuriously-wake-up-functions check

2019-12-23 Thread Kocsis Ábel via Phabricator via cfe-commits
abelkocsis updated this revision to Diff 235180.
abelkocsis added a comment.

Checker is moved to bugprone section, tests added. C checker is improved, and 
documentations are synchronised.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D70876

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-spuriously-wake-up-functions.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-con36-c.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-con54-cpp.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/chrono.h
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/condition_variable.h
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/cstdint.h
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/mutex.h
  
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/ratio.h
  clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.cpp

Index: clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s bugprone-spuriously-wake-up-functions %t -- -- -I %S/Inputs/bugprone-spuriously-wake-up-functions/
+#include "condition_variable.h"
+#define NULL 0
+
+struct Node1 {
+  void *Node1;
+  struct Node1 *next;
+};
+
+static Node1 list;
+static std::mutex m;
+static std::condition_variable condition;
+
+void consume_list_element(std::condition_variable &condition) {
+  std::unique_lock lk(m);
+
+  if (list.next == nullptr) {
+condition.wait(lk);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'wait' should be placed inside a while statement or used with a condition parameter [bugprone-spuriously-wake-up-functions]
+  }
+
+  while (list.next == nullptr) {
+condition.wait(lk);
+  }
+
+  if (list.next == nullptr) {
+while (list.next == nullptr) {
+  condition.wait(lk);
+}
+  }
+  using durtype = std::chrono::duration;
+  durtype dur = std::chrono::duration();
+  if (list.next == nullptr) {
+condition.wait_for(lk, dur);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'wait_for' should be placed inside a while statement or used with a condition parameter [bugprone-spuriously-wake-up-functions]
+  }
+  if (list.next == nullptr) {
+condition.wait_for(lk, dur, [] { return 1; });
+  }
+  auto now = std::chrono::system_clock::now();
+  if (list.next == nullptr) {
+condition.wait_until(lk, now);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'wait_until' should be placed inside a while statement or used with a condition parameter [bugprone-spuriously-wake-up-functions]
+  }
+  if (list.next == nullptr) {
+condition.wait_until(lk, now, [] { return 1; });
+  }
+}
+
+typedef struct mtx_t {
+} mtx_t;
+typedef struct cnd_t {
+} cnd_t;
+
+int cnd_wait(cnd_t *cond, mtx_t *mutex){};
+
+struct Node1 list_c;
+static mtx_t lock;
+static cnd_t condition_c;
+
+void consume_list_element(void) {
+
+  if (list_c.next == NULL) {
+if (0 != cnd_wait(&condition_c, &lock)) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions]
+}
+  }
+  while (list_c.next == NULL) {
+if (0 != cnd_wait(&condition_c, &lock)) {
+}
+  }
+  if (list_c.next == NULL) {
+cnd_wait(&condition_c, &lock);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions]
+  }
+  while (list.next == NULL) {
+cnd_wait(&condition_c, &lock);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/ratio.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/ratio.h
@@ -0,0 +1,28 @@
+#include "cstdint.h"
+
+namespace std {
+
+template 
+class ratio {
+public:
+  static constexpr intmax_t num = 0;
+  static constexpr intmax_t den = 0;
+  typedef ratio type;
+};
+
+template 
+struct ratio_equal;
+template 
+struct ratio_not_equal;
+template 
+struct ratio_less;
+template 
+struct ratio_less_equal;
+template 
+struct ratio_greater;
+template 
+struct ratio_greater_equal;
+
+typedef ratio<1, 1000> milli;
+
+} // namespace std
\ No newline at e

[PATCH] D71848: Allow the discovery of Android NDK's triple-prefixed binaries.

2019-12-23 Thread Brian Ledger via Phabricator via cfe-commits
brianpl created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
brianpl added a reviewer: jyknight.
brianpl updated this revision to Diff 235182.
brianpl added a comment.

Fix a typo.


Currently, tool discovery checks for a tool with its target triple as a
prefix. Unfortunately, the triple it uses is canonicalized, and may
contain the Android platform numbers as a suffix. This prevents matching
of the binaries in the LLVM bin directory of the Android NDK.

This CL adds checks during discovery that will match the canonical
Android NDK triples. The matcher will work with vendor "unknown", and at
any level platform.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71848

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/android-triple-version.c

Index: clang/test/Driver/android-triple-version.c
===
--- /dev/null
+++ clang/test/Driver/android-triple-version.c
@@ -0,0 +1,141 @@
+// Android's target triples can contain a version number in the environment
+// field (e.g. arm-linux-androideabi9).
+// Make sure that any version is stripped when finding toolchain binaries.
+
+// Ensure no execute permissions on .../bin/{target-triple}/ld.
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/arm-linux-androideabi/bin/ld
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/aarch64-linux-android/bin/ld
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/i686-linux-android/bin/ld
+// RUN: chmod -x %S/Inputs/basic_android_ndk_tree/mipsel-linux-android/bin/ld
+
+// Ensure execute permissions on .../bin/{target-triple}-ld
+// RUN: chmod +x  %S/Inputs/basic_android_ndk_tree/bin/arm-linux-androideabi-ld
+// RUN: chmod +x  %S/Inputs/basic_android_ndk_tree/bin/aarch64-linux-android-ld
+// RUN: chmod +x %S/Inputs/basic_android_ndk_tree/bin/i686-linux-android-ld
+// RUN: chmod +x %S/Inputs/basic_android_ndk_tree/bin/mipsel-linux-android-ld
+
+// Test target arm-linux-androideabi
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-linux-androideabi %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-unknown-linux-androideabi
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-unknown-linux-androideabi %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-linux-androideabi14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-linux-androideabi14 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-linux-androideabi29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-linux-androideabi29 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-unknown-linux-androideabi14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-unknown-linux-androideabi14 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target arm-unknown-linux-androideabi29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target arm-unknown-linux-androideabi29 %s |& \
+// RUN: grep arm-linux-androideabi-ld
+
+// Test target aarch64-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-linux-android %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-unknown-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-unknown-linux-android %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-linux-android14 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-linux-android29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-linux-android29 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-unknown-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-unknown-linux-android14 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target aarch64-unknown-linux-android29
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target aarch64-unknown-linux-android29 %s |& \
+// RUN: grep aarch64-linux-android-ld
+
+// Test target i686-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-linux-android %s |& \
+// RUN: grep i686-linux-android-ld
+
+// Test target i686-unknown-linux-android
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_tree/bin" \
+// RUN: %clang -### -target i686-unknown-linux-android %s |& \
+// RUN: grep i686-linux-android-ld
+
+// Test target i686-linux-android14
+// RUN: env "PATH=%S/Inputs/basic_android_ndk_t

[PATCH] D70876: [clang-tidy] Add spuriously-wake-up-functions check

2019-12-23 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-spuriously-wake-up-functions.rst:4
+bugprone-spuriously-wake-up-functions
+=
+

Please make length same as in title.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D70876



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


[PATCH] D71791: [CFG] Fix an assertion failure with static initializers

2019-12-23 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

In D71791#1795093 , @xazax.hun wrote:

> I decided to fix the unittests. Having CFGs full of dangling pointers to the 
> AST does not look fun at all, so I think this change was long overdue.


Very much appreciated! LGTM!


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

https://reviews.llvm.org/D71791



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-12-23 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

> Could you link to particular bots that have logs showing they ran this test? 
> (perhaps the logs have been retired by now, though - since this patch was 
> reverted :/ - but then at least seeing which bots run BPF tests would be 
> helpful)

@dblaikie Actually, I do not have direct proof that this test is running on 
buildbot. I only knew BPF is enabled by a lot of bots. I tried to search 
through emails when I got from buildbot failures like:

  clang-cmake-x86_64-avx2-linux
  llvm-clang-win-x-aarch64
  llvm-clang-win-x-armv7l
  clang-hexagon-elf
  clang-with-thin-lto-ubuntu
  clang-ppc64be-linux-lnt
  sanitizer-x86_64-linux-bootstrap-msan
  clang-s390x-linux
  sanitizer-x86_64-linux-fuzzer
  ..

The contents of buildbot failures are all gone and not accessible now. Will 
definitely check buildbot BPF coverage next time when I saw any issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-12-23 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Is this failure expected?
https://bugs.llvm.org/show_bug.cgi?id=44370


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64454



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-12-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70696#1795302 , @yonghong-song 
wrote:

> > Could you link to particular bots that have logs showing they ran this 
> > test? (perhaps the logs have been retired by now, though - since this patch 
> > was reverted :/ - but then at least seeing which bots run BPF tests would 
> > be helpful)
>
> @dblaikie Actually, I do not have direct proof that this test is running on 
> buildbot. I only knew BPF is enabled by a lot of bots. I tried to search 
> through emails when I got from buildbot failures like:
>
>   clang-cmake-x86_64-avx2-linux
>   llvm-clang-win-x-aarch64
>   llvm-clang-win-x-armv7l
>   clang-hexagon-elf
>   clang-with-thin-lto-ubuntu
>   clang-ppc64be-linux-lnt
>   sanitizer-x86_64-linux-bootstrap-msan
>   clang-s390x-linux
>   sanitizer-x86_64-linux-fuzzer
>   ..
>   
>
> The contents of buildbot failures are all gone and not accessible now. Will 
> definitely check buildbot BPF coverage next time when I saw any issues.


Hmm, yeah, I thought some of the buildbots print out verbose test logs, showing 
every test execution (even the passing ones) , but I guess I'm mistaken.

Probably worth waiting a few days (maybe until after the holidays/new year) to 
see if @rnk has some more info that'd help debug the issue before committing 
again.

(or, given it's the holidasy and not many people are around, some "testing on 
the bots" might be acceptable (though I guess we already know the bots aren't 
failing... or you'd have got email, etc... so maybe that doesn't add much 
value?))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[PATCH] D71791: [CFG] Fix an assertion failure with static initializers

2019-12-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Woohoo tests!~~




Comment at: clang/unittests/Analysis/CFGBuildResult.h:69
+  Finder.matchAST(AST->getASTContext());
+  Callback.TheBuildResult.setAST(std::move(AST));
   return std::move(Callback.TheBuildResult);

It should be slightly more visually appealing to construct the AST before the 
callback and pass it into the constructor of the callback.


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

https://reviews.llvm.org/D71791



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


[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2019-12-23 Thread Ilya Mirsky via Phabricator via cfe-commits
ilya updated this revision to Diff 235184.
ilya added a comment.

1. Refactor `CheckArrayAccess()` to take `AllowPastTheEnd` parameter to avoid a 
false positive array out-of-bounds warning for `&(cond ? arr1[N] : arr2[N])`.
2. Use `IgnoreParenCasts()` instead of `IgnoreParenImpCasts()` in 
`CheckArrayAccess()` to avoid false negatives when explicit cast is involved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71714

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Parser/cxx-ambig-decl-expr.cpp
  clang/test/SemaCXX/array-bounds.cpp

Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -27,7 +27,7 @@
 };
 
 void f1(int a[1]) {
-  int val = a[3]; // no warning for function argumnet
+  int val = a[3]; // no warning for function argument
 }
 
 void f2(const int (&a)[2]) { // expected-note {{declared here}}
@@ -133,7 +133,7 @@
 
 int test_sizeof_as_condition(int flag) {
   int arr[2] = { 0, 0 }; // expected-note {{array 'arr' declared here}}
-  if (flag) 
+  if (flag)
 return sizeof(char) != sizeof(char) ? arr[2] : arr[1];
   return sizeof(char) == sizeof(char) ? arr[2] : arr[1]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
 }
@@ -241,7 +241,7 @@
 }
 
 int test_pr11007_aux(const char * restrict, ...);
-  
+
 // Test checking with varargs.
 void test_pr11007() {
   double a[5]; // expected-note {{array 'a' declared here}}
@@ -309,3 +309,25 @@
 foo(); // expected-note 1{{in instantiation of function template specialization}}
   };
 }
+
+namespace PR44343 {
+  const unsigned int array[2] = {0, 1}; // expected-note 5{{array 'array' declared here}}
+
+  const int i1 = (const int)array[2]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const int i2 = static_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const int &i3 = reinterpret_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  unsigned int &i4 = const_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  int i5 = int(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const unsigned int *i6 = &(1 > 0 ? array[2] : array[1]); // no warning for one-past-end element's address retrieval
+
+  struct Base {
+virtual ~Base();
+  };
+
+  struct Derived : Base {
+  };
+
+  Base baseArr[2]; // expected-note {{array 'baseArr' declared here}}
+  Derived *d1 = dynamic_cast(&baseArr[2]); // no warning for one-past-end element's address retrieval
+  Derived &d2 = dynamic_cast(baseArr[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+}
Index: clang/test/Parser/cxx-ambig-decl-expr.cpp
===
--- clang/test/Parser/cxx-ambig-decl-expr.cpp
+++ clang/test/Parser/cxx-ambig-decl-expr.cpp
@@ -24,7 +24,7 @@
 
   // This is array indexing not an array declarator because a comma expression
   // is not syntactically a constant-expression.
-  int(x[1,1]); // expected-warning 2{{unused}}
+  int(x[1,0]); // expected-warning 2{{unused}}
 
   // This is array indexing not an array declaration because a braced-init-list
   // is not syntactically a constant-expression.
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13368,62 +13368,63 @@
 << ND->getDeclName());
 }
 
-void Sema::CheckArrayAccess(const Expr *expr) {
-  int AllowOnePastEnd = 0;
-  while (expr) {
-expr = expr->IgnoreParenImpCasts();
-switch (expr->getStmtClass()) {
-  case Stmt::ArraySubscriptExprClass: {
-const ArraySubscriptExpr *ASE = cast(expr);
-CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE,
- AllowOnePastEnd > 0);
-expr = ASE->getBase();
-break;
-  }
-  case Stmt::MemberExprClass: {
-expr = cast(expr)->getBase();
-break;
-  }
-  case Stmt::OMPArraySectionExprClass: {
-const OMPArraySectionExpr *ASE = cast(expr);
-if (ASE->getLowerBound())
-  CheckArrayAccess(ASE->getBase(), ASE->getLowerBound(),
-   /*ASE=*/nullptr, AllowOnePastEnd > 0);
-return;
-  }
-  case Stmt::UnaryOperatorClass: {
-// Only unwrap the * and & unary operators
-const UnaryOperator *UO = cast(expr);
-expr = UO->getSubExpr();
-switch (UO->getOpcode()) {
-  case UO_Ad

[clang] 379613d - [CFG] Fix an assertion failure with static initializers

2019-12-23 Thread Gabor Horvath via cfe-commits

Author: Gabor Horvath
Date: 2019-12-23T16:35:37-08:00
New Revision: 379613d7c7fa9698a2c300f4067165b5309a5e6e

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

LOG: [CFG] Fix an assertion failure with static initializers

The CFGBlock::getLastCondition was not prepared for static initializer
branches.

This patch also revamps CFG unit tests. Earlier the lifetime of the AST
was smaller than the CFG. So all the AST pointers within the CFG blocks
were dangling. This was OK, since none of the tests dereferenced those
pointers. This was, however, a timed bomb. There were patches in the
past that were reverted partially due to this problem.

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

Added: 


Modified: 
clang/lib/Analysis/CFG.cpp
clang/unittests/Analysis/CFGBuildResult.h
clang/unittests/Analysis/CFGTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 07945a80a311..4c1ea8995f9f 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -5919,7 +5919,7 @@ const Expr *CFGBlock::getLastCondition() const {
 return nullptr;
 
   const Stmt *Cond = StmtElem->getStmt();
-  if (isa(Cond))
+  if (isa(Cond) || isa(Cond))
 return nullptr;
 
   // Only ObjCForCollectionStmt is known not to be a non-Expr terminator, hence

diff  --git a/clang/unittests/Analysis/CFGBuildResult.h 
b/clang/unittests/Analysis/CFGBuildResult.h
index 17511dcd46c8..252e608d28e8 100644
--- a/clang/unittests/Analysis/CFGBuildResult.h
+++ b/clang/unittests/Analysis/CFGBuildResult.h
@@ -6,9 +6,10 @@
 //
 
//===--===//
 
-#include "clang/Analysis/CFG.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Tooling/Tooling.h"
+#include 
 
 namespace clang {
 namespace analysis {
@@ -22,20 +23,27 @@ class BuildResult {
 BuiltCFG,
   };
 
-  BuildResult(Status S, std::unique_ptr Cfg = nullptr)
-  : S(S), Cfg(std::move(Cfg)) {}
+  BuildResult(Status S, std::unique_ptr Cfg = nullptr,
+  std::unique_ptr AST = nullptr)
+  : S(S), Cfg(std::move(Cfg)), AST(std::move(AST)) {}
 
   Status getStatus() const { return S; }
   CFG *getCFG() const { return Cfg.get(); }
+  ASTUnit *getAST() const { return AST.get(); }
 
 private:
   Status S;
   std::unique_ptr Cfg;
+  std::unique_ptr AST;
 };
 
 class CFGCallback : public ast_matchers::MatchFinder::MatchCallback {
 public:
+  CFGCallback(std::unique_ptr AST) : AST(std::move(AST)) {}
+
+  std::unique_ptr AST;
   BuildResult TheBuildResult = BuildResult::ToolRan;
+  CFG::BuildOptions Options;
 
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
 const auto *Func = Result.Nodes.getNodeAs("func");
@@ -43,25 +51,26 @@ class CFGCallback : public 
ast_matchers::MatchFinder::MatchCallback {
 if (!Body)
   return;
 TheBuildResult = BuildResult::SawFunctionBody;
-CFG::BuildOptions Options;
 Options.AddImplicitDtors = true;
 if (std::unique_ptr Cfg =
 CFG::buildCFG(nullptr, Body, Result.Context, Options))
-  TheBuildResult = {BuildResult::BuiltCFG, std::move(Cfg)};
+  TheBuildResult = {BuildResult::BuiltCFG, std::move(Cfg), std::move(AST)};
   }
 };
 
-inline BuildResult BuildCFG(const char *Code) {
-  CFGCallback Callback;
-
-  ast_matchers::MatchFinder Finder;
-  Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
-  std::unique_ptr Factory(
-  tooling::newFrontendActionFactory(&Finder));
+inline BuildResult BuildCFG(const char *Code, CFG::BuildOptions Options = {}) {
   std::vector Args = {"-std=c++11",
"-fno-delayed-template-parsing"};
-  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args))
+  std::unique_ptr AST = tooling::buildASTFromCodeWithArgs(Code, Args);
+  if (!AST)
 return BuildResult::ToolFailed;
+
+  CFGCallback Callback(std::move(AST));
+  Callback.Options = Options;
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
+
+  Finder.matchAST(Callback.AST->getASTContext());
   return std::move(Callback.TheBuildResult);
 }
 

diff  --git a/clang/unittests/Analysis/CFGTest.cpp 
b/clang/unittests/Analysis/CFGTest.cpp
index 27071dc5a5d9..1994658bed56 100644
--- a/clang/unittests/Analysis/CFGTest.cpp
+++ b/clang/unittests/Analysis/CFGTest.cpp
@@ -30,6 +30,22 @@ TEST(CFG, RangeBasedForOverDependentType) {
   EXPECT_EQ(BuildResult::SawFunctionBody, BuildCFG(Code).getStatus());
 }
 
+TEST(CFG, StaticInitializerLastCondition) {
+  const char *Code = "void f() {\n"
+ "  int i = 5 ;\n"
+ "  static int j = 3 ;\n"
+  

[PATCH] D71791: [CFG] Fix an assertion failure with static initializers

2019-12-23 Thread Gábor Horváth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG379613d7c7fa: [CFG] Fix an assertion failure with static 
initializers (authored by xazax.hun).

Changed prior to commit:
  https://reviews.llvm.org/D71791?vs=235161&id=235185#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71791

Files:
  clang/lib/Analysis/CFG.cpp
  clang/unittests/Analysis/CFGBuildResult.h
  clang/unittests/Analysis/CFGTest.cpp

Index: clang/unittests/Analysis/CFGTest.cpp
===
--- clang/unittests/Analysis/CFGTest.cpp
+++ clang/unittests/Analysis/CFGTest.cpp
@@ -30,6 +30,22 @@
   EXPECT_EQ(BuildResult::SawFunctionBody, BuildCFG(Code).getStatus());
 }
 
+TEST(CFG, StaticInitializerLastCondition) {
+  const char *Code = "void f() {\n"
+ "  int i = 5 ;\n"
+ "  static int j = 3 ;\n"
+ "}\n";
+  CFG::BuildOptions Options;
+  Options.AddStaticInitBranches = true;
+  Options.setAllAlwaysAdd();
+  BuildResult B = BuildCFG(Code, Options);
+  EXPECT_EQ(BuildResult::BuiltCFG, B.getStatus());
+  EXPECT_EQ(1u, B.getCFG()->getEntry().succ_size());
+  CFGBlock *Block = *B.getCFG()->getEntry().succ_begin();
+  EXPECT_TRUE(isa(Block->getTerminatorStmt()));
+  EXPECT_EQ(nullptr, Block->getLastCondition());
+}
+
 // Constructing a CFG containing a delete expression on a dependent type should
 // not crash.
 TEST(CFG, DeleteExpressionOnDependentType) {
Index: clang/unittests/Analysis/CFGBuildResult.h
===
--- clang/unittests/Analysis/CFGBuildResult.h
+++ clang/unittests/Analysis/CFGBuildResult.h
@@ -6,9 +6,10 @@
 //
 //===--===//
 
-#include "clang/Analysis/CFG.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Tooling/Tooling.h"
+#include 
 
 namespace clang {
 namespace analysis {
@@ -22,20 +23,27 @@
 BuiltCFG,
   };
 
-  BuildResult(Status S, std::unique_ptr Cfg = nullptr)
-  : S(S), Cfg(std::move(Cfg)) {}
+  BuildResult(Status S, std::unique_ptr Cfg = nullptr,
+  std::unique_ptr AST = nullptr)
+  : S(S), Cfg(std::move(Cfg)), AST(std::move(AST)) {}
 
   Status getStatus() const { return S; }
   CFG *getCFG() const { return Cfg.get(); }
+  ASTUnit *getAST() const { return AST.get(); }
 
 private:
   Status S;
   std::unique_ptr Cfg;
+  std::unique_ptr AST;
 };
 
 class CFGCallback : public ast_matchers::MatchFinder::MatchCallback {
 public:
+  CFGCallback(std::unique_ptr AST) : AST(std::move(AST)) {}
+
+  std::unique_ptr AST;
   BuildResult TheBuildResult = BuildResult::ToolRan;
+  CFG::BuildOptions Options;
 
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
 const auto *Func = Result.Nodes.getNodeAs("func");
@@ -43,25 +51,26 @@
 if (!Body)
   return;
 TheBuildResult = BuildResult::SawFunctionBody;
-CFG::BuildOptions Options;
 Options.AddImplicitDtors = true;
 if (std::unique_ptr Cfg =
 CFG::buildCFG(nullptr, Body, Result.Context, Options))
-  TheBuildResult = {BuildResult::BuiltCFG, std::move(Cfg)};
+  TheBuildResult = {BuildResult::BuiltCFG, std::move(Cfg), std::move(AST)};
   }
 };
 
-inline BuildResult BuildCFG(const char *Code) {
-  CFGCallback Callback;
-
-  ast_matchers::MatchFinder Finder;
-  Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
-  std::unique_ptr Factory(
-  tooling::newFrontendActionFactory(&Finder));
+inline BuildResult BuildCFG(const char *Code, CFG::BuildOptions Options = {}) {
   std::vector Args = {"-std=c++11",
"-fno-delayed-template-parsing"};
-  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args))
+  std::unique_ptr AST = tooling::buildASTFromCodeWithArgs(Code, Args);
+  if (!AST)
 return BuildResult::ToolFailed;
+
+  CFGCallback Callback(std::move(AST));
+  Callback.Options = Options;
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
+
+  Finder.matchAST(Callback.AST->getASTContext());
   return std::move(Callback.TheBuildResult);
 }
 
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -5919,7 +5919,7 @@
 return nullptr;
 
   const Stmt *Cond = StmtElem->getStmt();
-  if (isa(Cond))
+  if (isa(Cond) || isa(Cond))
 return nullptr;
 
   // Only ObjCForCollectionStmt is known not to be a non-Expr terminator, hence
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2019-12-23 Thread Ilya Mirsky via Phabricator via cfe-commits
ilya marked an inline comment as done.
ilya added a comment.

Implemented @riccibruno's and @rsmith's comments.
While I agree with the general notion about the flaws with the current 
implementation, I feel that the more major refactoring proposed in this review 
is out of the scope of this minor fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71714



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


[PATCH] D71709: Give frontend dump flags consistent names (*-dump instead of dump-*)

2019-12-23 Thread David Herzka via Phabricator via cfe-commits
herzka updated this revision to Diff 235188.
herzka added a comment.

rebase, restore changes to CC1Options.td that I left out of last revision


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71709

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CoverageMapping/block-storage-starts-region.m
  clang/test/CoverageMapping/break.c
  clang/test/CoverageMapping/builtinmacro.c
  clang/test/CoverageMapping/casts.c
  clang/test/CoverageMapping/classtemplate.cpp
  clang/test/CoverageMapping/comment-in-macro.c
  clang/test/CoverageMapping/continue.c
  clang/test/CoverageMapping/control-flow-macro.c
  clang/test/CoverageMapping/decl.c
  clang/test/CoverageMapping/default-method.cpp
  clang/test/CoverageMapping/deferred-region.cpp
  clang/test/CoverageMapping/empty-destructor.cpp
  clang/test/CoverageMapping/header.cpp
  clang/test/CoverageMapping/if.cpp
  clang/test/CoverageMapping/implicit-def-in-macro.m
  clang/test/CoverageMapping/include-macros.c
  clang/test/CoverageMapping/includehell.cpp
  clang/test/CoverageMapping/label.cpp
  clang/test/CoverageMapping/lambda.cpp
  clang/test/CoverageMapping/logical.cpp
  clang/test/CoverageMapping/loopmacro.c
  clang/test/CoverageMapping/loops.cpp
  clang/test/CoverageMapping/macro-expansion.c
  clang/test/CoverageMapping/macro-expressions.cpp
  clang/test/CoverageMapping/macro-stringize-twice.cpp
  clang/test/CoverageMapping/macroception.c
  clang/test/CoverageMapping/macroparams.c
  clang/test/CoverageMapping/macroparams2.c
  clang/test/CoverageMapping/macros.c
  clang/test/CoverageMapping/macroscopes.cpp
  clang/test/CoverageMapping/md.cpp
  clang/test/CoverageMapping/moremacros.c
  clang/test/CoverageMapping/nestedclass.cpp
  clang/test/CoverageMapping/objc.m
  clang/test/CoverageMapping/openmp.c
  clang/test/CoverageMapping/pr32679.cpp
  clang/test/CoverageMapping/preprocessor.c
  clang/test/CoverageMapping/return.c
  clang/test/CoverageMapping/switch.cpp
  clang/test/CoverageMapping/switchmacro.c
  clang/test/CoverageMapping/system_macro.cpp
  clang/test/CoverageMapping/templates.cpp
  clang/test/CoverageMapping/test.c
  clang/test/CoverageMapping/trycatch.cpp
  clang/test/CoverageMapping/trymacro.cpp
  clang/test/CoverageMapping/unreachable-macro.c
  clang/test/CoverageMapping/unused_function.cpp
  clang/test/CoverageMapping/while.c
  clang/test/Lexer/dollar-idents.c
  clang/test/Preprocessor/dumptokens_phyloc.c
  clang/utils/token-delta.py

Index: clang/utils/token-delta.py
===
--- clang/utils/token-delta.py
+++ clang/utils/token-delta.py
@@ -108,7 +108,7 @@
   re.DOTALL | re.MULTILINE)
 
 def getTokens(path):
-p = subprocess.Popen(['clang','-dump-raw-tokens',path],
+p = subprocess.Popen(['clang','-raw-tokens-dump',path],
  stdin=subprocess.PIPE,
  stdout=subprocess.PIPE,
  stderr=subprocess.PIPE)
Index: clang/test/Preprocessor/dumptokens_phyloc.c
===
--- clang/test/Preprocessor/dumptokens_phyloc.c
+++ clang/test/Preprocessor/dumptokens_phyloc.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -dump-tokens %s 2>&1 | grep "Spelling=.*dumptokens_phyloc.c:3:20"
+// RUN: %clang_cc1 -tokens-dump %s 2>&1 | grep "Spelling=.*dumptokens_phyloc.c:3:20"
 
 #define TESTPHYLOC 10
 
Index: clang/test/Lexer/dollar-idents.c
===
--- clang/test/Lexer/dollar-idents.c
+++ clang/test/Lexer/dollar-idents.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -dump-tokens %s 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -dump-tokens -x assembler-with-cpp %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM
+// RUN: %clang_cc1 -tokens-dump %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -tokens-dump -x assembler-with-cpp %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM
 // PR3808
 
 // CHECK: identifier '$A'
Index: clang/test/CoverageMapping/while.c
===
--- clang/test/CoverageMapping/while.c
+++ clang/test/CoverageMapping/while.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -coverage-mapping-dump -emit-llvm-only -main-file-name loops.cpp %s | FileCheck %s
 
 // CHECK: main
 int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+8]]:2 = #0
Index: clang/test/CoverageMapping/unused_function.cpp
===
--- clang/test/CoverageMapping/unused_function.cpp
+++ clang/test/CoverageMapping/unused_function.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fprof

[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-12-23 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@dblaikie The root cause has been identified by @rnk . A clang plugin is used 
which requires the following patch:

  
https://github.com/llvm/llvm-project/commit/5128026467cbc17bfc796d94bc8e40e52a9b0752

which has been merged. The original extern variable debug info type has been 
relanded. So we are good. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[PATCH] D71830: [OpenMP] Reusable OpenMP context/traits handling

2019-12-23 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-12-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70696#1795427 , @yonghong-song 
wrote:

> @dblaikie The root cause has been identified by @rnk . A clang plugin is used 
> which requires the following patch:
>
>   
> https://github.com/llvm/llvm-project/commit/5128026467cbc17bfc796d94bc8e40e52a9b0752
>
> which has been merged. The original extern variable debug info type has been 
> relanded. So we are good. Thanks!


Ah, OK - would be good to follow-up here and mention the commit where this was 
relanded for the history/records. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[PATCH] D71830: [OpenMP] Reusable OpenMP context/traits handling

2019-12-23 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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