[PATCH] D80237: [hip] Ensure pointer in struct argument has proper `addrspacecast`.

2020-05-19 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1339
+  }
+  for (uint64_t i = 0, e = SrcATy->getNumElements(); i < e; ++i) {
+Address EltPtr = CGF.Builder.CreateConstArrayGEP(Dest, i);

Is there a limit on array size? We may end up here with potentially unbounded 
number of spacecasts. Perhaps we need a loop which may later be unrolled, if 
feasible.



Comment at: clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu:17
 // HOST: define void @_Z22__device_stub__kernel1Pi(i32* %x)
+// COMMON-LABEL: define amdgpu_kernel void @_Z7kernel1Pi(i32 
addrspace(1)*{{.*}} %x.coerce)
+// CHECK: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*

Nit: relying on parameter name `%x.coerce` may be rather fragile. Considering 
that we don't care about the name itself, it may be better to just trim the 
match after `%x` or even after`%`.



Comment at: clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu:62-63
+// COMMON-LABEL: define amdgpu_kernel void @_Z7kernel41S(%struct.S.coerce 
%s.coerce)
+// CHECK: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// CHECK: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*

Nit: You could use `CHECK-COUNT-2` : 
https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-count-directive


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80237



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


[PATCH] D64128: [CodeGen] Generate llvm.ptrmask instead of inttoptr(and(ptrtoint, C)) if possible.

2020-05-19 Thread Florian Hahn via Phabricator via cfe-commits
fhahn abandoned this revision.
fhahn added a comment.

In D64128#1578916 , @fhahn wrote:

> In D64128#1576391 , @rjmccall wrote:
>
> > I wouldn't favor adding something really obscure that was only useful for 
> > clang, but I think builtins to set and clear mask bits while promising to 
> > preserve object-reference identity would be more generally useful for 
> > libraries.  For example, there might be somewhere in libc++ that could take 
> > advantage of this.
>
>
> Yep, I think for this to be generally useful we would also need an intrinsic 
> to set bits as well. I'll commit the LLVM patches and improvements to 
> ValueTracking in the next few days for ptrmask and will put up a patch for 
> builtins once I know more about how libcxx could use them.


Thanks for all the comments! I checked with a few contributors to libcxx and 
there seem to be no very obvious places where this would help a lot. IUUC for 
now the patch is not really worth pursuing further.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64128



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


[PATCH] D60620: [HIP] Support target id by --offload-arch

2020-05-19 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 265025.
yaxunl retitled this revision from "[HIP] Support -offloading-target-id" to 
"[HIP] Support target id by --offload-arch".
yaxunl edited the summary of this revision.
yaxunl added a comment.

rebased the patch and revised by passing target id by `--offload-arch`.


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

https://reviews.llvm.org/D60620

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/HIP.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/HIP.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-invalid-target-id.hip
  clang/test/Driver/hip-target-id.hip

Index: clang/test/Driver/hip-target-id.hip
===
--- /dev/null
+++ clang/test/Driver/hip-target-id.hip
@@ -0,0 +1,56 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   -x hip --offload-arch=gfx908 \
+// RUN:   --offload-arch=gfx908+xnack+sramecc \
+// RUN:   --offload-arch=gfx908+xnack-sramecc \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %s 2>&1 | FileCheck %s
+
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: {{.*}} "-target-cpu" "gfx908"
+
+// CHECK: [[OPT:".*opt"]] {{".*-gfx908-linked.*bc"}} "-mtriple=amdgcn-amd-amdhsa"
+// CHECK-SAME: "-mcpu=gfx908"
+// CHECK-SAME: "-o" [[OPT_906_BC:".*-gfx908-optimized.*bc"]]
+
+// CHECK: [[LLC: ".*llc"]] [[OPT_906_BC]]
+// CHECK-SAME: "-mtriple=amdgcn-amd-amdhsa"
+// CHECK-SAME: {{.*}} "-mcpu=gfx908"
+// CHECK-SAME: "-o" {{".*-gfx908-.*o"}}
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: {{.*}} "-target-cpu" "gfx908" "-mxnack" "-msram-ecc"
+
+// CHECK: [[OPT]] {{".*-gfx908\+xnack\+sramecc.*bc"}} "-mtriple=amdgcn-amd-amdhsa"
+// CHECK-SAME: "-mcpu=gfx908"
+// CHECK-SAME: "-o" [[OPT_906XE_BC:".*-gfx908\+xnack\+sramecc.*bc"]]
+
+// CHECK: [[LLC]] [[OPT_906XE_BC]]
+// CHECK-SAME: "-mtriple=amdgcn-amd-amdhsa"
+// CHECK-SAME: {{.*}} "-mcpu=gfx908"
+// CHECK-SAME: "-o" {{".*-gfx908\+xnack\+sramecc.*o"}}
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-emit-llvm-bc"
+// CHECK-SAME: {{.*}} "-target-cpu" "gfx908" "-mxnack" "-mno-sram-ecc"
+
+// CHECK: [[OPT]] {{".*-gfx908\+xnack.*bc"}} "-mtriple=amdgcn-amd-amdhsa"
+// CHECK-SAME: "-mcpu=gfx908"
+// CHECK-SAME: "-o" [[OPT_906XN_BC:".*-gfx908\+xnack.*bc"]]
+
+// CHECK: [[LLC]] [[OPT_906XN_BC]]
+// CHECK-SAME: "-mtriple=amdgcn-amd-amdhsa"
+// CHECK-SAME: {{.*}} "-mcpu=gfx908"
+// CHECK-SAME: "-o" {{".*-gfx908\+xnack.*o"}}
+
+
+// CHECK: {{".*clang-offload-bundler"}}
+// CHECK-SAME: "-targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa-gfx908,hip-amdgcn-amd-amdhsa-gfx908+xnack+sramecc,hip-amdgcn-amd-amdhsa-gfx908+xnack-sramecc"
Index: clang/test/Driver/hip-invalid-target-id.hip
===
--- /dev/null
+++ clang/test/Driver/hip-invalid-target-id.hip
@@ -0,0 +1,48 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   -x hip --offload-arch=gfx908 \
+// RUN:   --offload-arch=gfx908xnack \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=NOPLUS %s
+
+// NOPLUS: error: Unsupported CUDA gpu architecture
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   -x hip --offload-arch=gfx908 \
+// RUN:   --offload-arch=gfx908+sramecc+xnack \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=ORDER %s
+
+// ORDER: error: Invalid HIP offloading target id: gfx908+sramecc+xnack
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   -x hip --offload-arch=gfx908 \
+// RUN:   --offload-arch=gfx908+unknown \
+// RUN:   --offload-arch=gfx908+sramecc+unknown \
+// RUN:   --offload-arch=gfx900+xnack \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=UNK %s
+
+// UNK: error: Invalid HIP offloading target id: gfx908+unknown
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   -x hip --offload-arch=gfx908 \
+// RUN:   --offload-arch=gfx908+sramecc+unknown \
+// RUN:   --offload-arch=gfx900+xnack \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=MIXED %s
+
+// MIXED: error: Invalid HIP offloading target id: gfx908+sramecc+unknown
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   -x hip --offload-arch=gfx908 \
+// RUN:   --offloa

[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: echristo, dblaikie.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes pr/11710.
Signed-off-by: Nick Desaulniers 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80242

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/debug-info-unused-types.c

Index: clang/test/CodeGen/debug-info-unused-types.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-unused-types.c
@@ -0,0 +1,11 @@
+// RUN: %clang -fno-eliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang -feliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+typedef int my_int;
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "my_int", file: !5, line: 5, baseType: !6)
+// CHECK-NEXT: !5 = !DIFile(filename: "clang/test/CodeGen/debug-info-unused-types.c", directory: "/android0/llvm-project")
+// CHECK-NEXT: !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// NODBG-NOT: !DIDerivedType(tag: DW_TAG_typedef, name: "my_int", file: !5, line: 5, baseType: !6)
+// NODBG-NOT: !5 = !DIFile(filename: "clang/test/CodeGen/debug-info-unused-types.c", directory: "/android0/llvm-project")
+// NODBG-NOT: !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -765,6 +765,7 @@
   Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
   Opts.DebugExplicitImport = Args.hasArg(OPT_dwarf_explicit_import);
   Opts.DebugFwdTemplateParams = Args.hasArg(OPT_debug_forward_template_params);
+  Opts.DebugUnusedTypes = Args.hasArg(OPT_eliminate_unused_debug_types_fno);
   Opts.EmbedSource = Args.hasArg(OPT_gembed_source);
   Opts.ForceDwarfFrameSection = Args.hasArg(OPT_fforce_dwarf_frame);
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5190,6 +5190,8 @@
 
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
+  Args.AddLastArg(CmdArgs, options::OPT_eliminate_unused_debug_types_f);
+  Args.AddLastArg(CmdArgs, options::OPT_eliminate_unused_debug_types_fno);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -,6 +,12 @@
 EmitOMPRequiresDecl(cast(D));
 break;
 
+  case Decl::Typedef:
+if (getCodeGenOpts().DebugUnusedTypes)
+  if (CGDebugInfo *DI = getModuleDebugInfo())
+DI->EmitTypedef(*cast(D));
+break;
+
   default:
 // Make sure we handled everything we should, every other kind is a
 // non-top-level decl.  FIXME: Would be nice to have an isTopLevelDeclKind
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -496,6 +496,9 @@
   /// Emit an @import declaration.
   void EmitImportDecl(const ImportDecl &ID);
 
+  /// Eagerly emit Typedef.
+  void EmitTypedef(const TypedefDecl &TD);
+
   /// Emit C++ namespace alias.
   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4956,3 +4956,10 @@
 
   return llvm::DINode::FlagAllCallsDescribed;
 }
+
+void CGDebugInfo::EmitTypedef(const TypedefDecl &TD) {
+  QualType QT = CGM.getContext().getTypedefType(&TD);
+  llvm::DIFile *Unit = getOrCreateFile(TD.getLocation());
+  llvm::DIType *Ty = getOrCreateType(QT, Unit);
+  DBuilder.retainType(Ty);
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3343,7 +3343,10 @@
 defm fcheck_new : BooleanFFlag<"check-new">, Group;
 defm ca

[clang] 47650dc - Revert "[clang-misexpect] Fixed typo which causes that --pgo-warn-misexpect option is not passed in the compiler invocation"

2020-05-19 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-05-19T23:20:54+02:00
New Revision: 47650dcbeee215f48277ed8bea5f0e43cbf125fc

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

LOG: Revert "[clang-misexpect] Fixed typo which causes that 
--pgo-warn-misexpect option is not passed in the compiler invocation"

This reverts commit 6d2b75e0887ee87e247756c4d51733616bb2f356.

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5496df79dbfb..94ba0dd8e598 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3680,7 +3680,7 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
 }
   }
 
-  if (!Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
+  if (Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
 Res.FrontendOpts.LLVMArgs.push_back("-pgo-warn-misexpect");
 
   LangOpts.FunctionAlignment =



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


[PATCH] D80020: [PowerPC] Add support for -mcpu=pwr10 in both clang and llvm

2020-05-19 Thread Victor Huang via Phabricator via cfe-commits
NeHuang added inline comments.



Comment at: clang/lib/Basic/Targets/PPC.cpp:339
 
   if (!(ArchDefs & ArchDefinePwr9) && (ArchDefs & ArchDefinePpcgr) &&
   llvm::find(FeaturesVec, "+float128") != FeaturesVec.end()) {

I think we also need to check for `ArchDefinePwr10` and `ArchDefineFuture` 
based on the comment  "// We have __float128 on PPC but not power 9 and above."

`!(ArchDefs & ArchDefinePwr9)` -> `!(ArchDefs & (ArchDefinePwr9 | 
ArchDefinePwr10 | ArchDefineFuture))`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80020



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


[PATCH] D80153: [AST] Mangle LambdaContextDecl for top level decl

2020-05-19 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 265046.
zequanwu added a comment.

Update test cases.


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

https://reviews.llvm.org/D80153

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
  clang/test/CodeGenCXX/mangle-ms-cxx17.cpp


Index: clang/test/CodeGenCXX/mangle-ms-cxx17.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-cxx17.cpp
+++ clang/test/CodeGenCXX/mangle-ms-cxx17.cpp
@@ -19,3 +19,11 @@
 
 // CHECK-DAG: "?$S4@@3US@@B"
 const auto [x2, y2] = f();
+
+// CHECK-DAG: "?i1@@3V@0@B"
+inline const auto i1 = [](auto x) { return 0; };
+// CHECK-DAG: "?i2@@3V@0@B"
+inline const auto i2 = [](auto x) { return 1; };
+// CHECK-DAG: "??$?RH@@i1@@QBE?A?@@H@Z"
+// CHECK-DAG: "??$?RH@@i2@@QBE?A?@@H@Z"
+int g() {return i1(1) + i2(1); }
Index: clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -337,10 +337,10 @@
   }();
   using FPtrTy = void(void);
   static void default_args(FPtrTy x = [] {}, FPtrTy y = [] {}, int z = [] { 
return 1; }() + [] { return 2; }()) {}
-  // CHECK-DAG: 
@"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
-  // CHECK-DAG: 
@"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
-  // CHECK-DAG: 
@"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
-  // CHECK-DAG: 
@"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: 
@"??R@z@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: 
@"??R@z@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: 
@"??R@y@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: 
@"??R@x@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
 };
 A a;
 
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -947,12 +947,11 @@
 
   mangleSourceName(Name);
 
-  // If the context of a closure type is an initializer for a class
-  // member (static or nonstatic), it is encoded in a qualified name.
+  // If the context is a variable or a class member, it is encoded
+  // in a qualified name.
   if (LambdaManglingNumber && LambdaContextDecl) {
 if ((isa(LambdaContextDecl) ||
- isa(LambdaContextDecl)) &&
-LambdaContextDecl->getDeclContext()->isRecord()) {
+ isa(LambdaContextDecl))) {
   mangleUnqualifiedName(cast(LambdaContextDecl));
 }
   }


Index: clang/test/CodeGenCXX/mangle-ms-cxx17.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-cxx17.cpp
+++ clang/test/CodeGenCXX/mangle-ms-cxx17.cpp
@@ -19,3 +19,11 @@
 
 // CHECK-DAG: "?$S4@@3US@@B"
 const auto [x2, y2] = f();
+
+// CHECK-DAG: "?i1@@3V@0@B"
+inline const auto i1 = [](auto x) { return 0; };
+// CHECK-DAG: "?i2@@3V@0@B"
+inline const auto i2 = [](auto x) { return 1; };
+// CHECK-DAG: "??$?RH@@i1@@QBE?A?@@H@Z"
+// CHECK-DAG: "??$?RH@@i2@@QBE?A?@@H@Z"
+int g() {return i1(1) + i2(1); }
Index: clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -337,10 +337,10 @@
   }();
   using FPtrTy = void(void);
   static void default_args(FPtrTy x = [] {}, FPtrTy y = [] {}, int z = [] { return 1; }() + [] { return 2; }()) {}
-  // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
-  // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
-  // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
-  // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"??R@z@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"??R@z@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"??R@y@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
+  // CHECK-DAG: @"??R@x@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"(
 };
 A a;
 
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -947,12 +947,11 @@
 
   mangleSourceName(Name);
 
-  // If the context of a closure type is an initializer for a class
-  // member (static or nonstatic), it is encoded in a qualified name.
+  // If the context is a variable or a class member, it is encoded
+  // in a qualified name.
   if (LambdaManglingNumber && LambdaContextDecl) {
 if ((isa(LambdaContextDecl) ||
- isa(LambdaContextDecl)) &&
-  

[PATCH] D80153: [AST] Mangle LambdaContextDecl for top level decl

2020-05-19 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 265031.
zequanwu added a comment.

Remove check for context of `LambdaContextDecl`.
Update test cases.


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

https://reviews.llvm.org/D80153

Files:
  clang/lib/AST/MicrosoftMangle.cpp


Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -947,12 +947,11 @@
 
   mangleSourceName(Name);
 
-  // If the context of a closure type is an initializer for a class
-  // member (static or nonstatic), it is encoded in a qualified name.
+  // If the context is a variable or a class member, it is encoded
+  // in a qualified name.
   if (LambdaManglingNumber && LambdaContextDecl) {
 if ((isa(LambdaContextDecl) ||
- isa(LambdaContextDecl)) &&
-LambdaContextDecl->getDeclContext()->isRecord()) {
+ isa(LambdaContextDecl))) {
   mangleUnqualifiedName(cast(LambdaContextDecl));
 }
   }


Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -947,12 +947,11 @@
 
   mangleSourceName(Name);
 
-  // If the context of a closure type is an initializer for a class
-  // member (static or nonstatic), it is encoded in a qualified name.
+  // If the context is a variable or a class member, it is encoded
+  // in a qualified name.
   if (LambdaManglingNumber && LambdaContextDecl) {
 if ((isa(LambdaContextDecl) ||
- isa(LambdaContextDecl)) &&
-LambdaContextDecl->getDeclContext()->isRecord()) {
+ isa(LambdaContextDecl))) {
   mangleUnqualifiedName(cast(LambdaContextDecl));
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80176: [clang-format][PR45816] Add AlignConsecutiveBitFields

2020-05-19 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD updated this revision to Diff 265048.
JakeMerdichAMD added a comment.

Reformat with a newer clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80176

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11955,6 +11955,48 @@
Alignment);
 }
 
+TEST_F(FormatTest, AlignConsecutiveBitFields) {
+  FormatStyle Alignment = getLLVMStyle();
+  Alignment.AlignConsecutiveBitFields = true;
+  verifyFormat("int const a : 5;\n"
+   "int oneTwoThree : 23;",
+   Alignment);
+
+  // Initializers are allowed starting with c++2a
+  verifyFormat("int const a : 5 = 1;\n"
+   "int oneTwoThree : 23 = 0;",
+   Alignment);
+
+  Alignment.AlignConsecutiveDeclarations = true;
+  verifyFormat("int const a   : 5;\n"
+   "int   oneTwoThree : 23;",
+   Alignment);
+
+  verifyFormat("int const a   : 5;  // comment\n"
+   "int   oneTwoThree : 23; // comment",
+   Alignment);
+
+  verifyFormat("int const a   : 5 = 1;\n"
+   "int   oneTwoThree : 23 = 0;",
+   Alignment);
+
+  Alignment.AlignConsecutiveAssignments = true;
+  verifyFormat("int const a   : 5  = 1;\n"
+   "int   oneTwoThree : 23 = 0;",
+   Alignment);
+  verifyFormat("int const a   : 5  = {1};\n"
+   "int   oneTwoThree : 23 = 0;",
+   Alignment);
+
+  // Known limitations: ':' is only recognized as a bitfield colon when
+  // followed by a number.
+  /*
+  verifyFormat("int oneTwoThree : SOME_CONSTANT;\n"
+   "int a   : 5;",
+   Alignment);
+  */
+}
+
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
   FormatStyle Alignment = getLLVMStyle();
   Alignment.AlignConsecutiveMacros = true;
@@ -13369,6 +13411,7 @@
   Style.Language = FormatStyle::LK_Cpp;
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AlignConsecutiveAssignments);
+  CHECK_PARSE_BOOL(AlignConsecutiveBitFields);
   CHECK_PARSE_BOOL(AlignConsecutiveDeclarations);
   CHECK_PARSE_BOOL(AlignConsecutiveMacros);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
Index: clang/lib/Format/WhitespaceManager.h
===
--- clang/lib/Format/WhitespaceManager.h
+++ clang/lib/Format/WhitespaceManager.h
@@ -184,6 +184,9 @@
   /// Align consecutive assignments over all \c Changes.
   void alignConsecutiveAssignments();
 
+  /// Align consecutive bitfields over all \c Changes.
+  void alignConsecutiveBitFields();
+
   /// Align consecutive declarations over all \c Changes.
   void alignConsecutiveDeclarations();
 
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -95,6 +95,7 @@
   calculateLineBreakInformation();
   alignConsecutiveMacros();
   alignConsecutiveDeclarations();
+  alignConsecutiveBitFields();
   alignConsecutiveAssignments();
   alignChainedConditionals();
   alignTrailingComments();
@@ -609,6 +610,26 @@
   Changes, /*StartAt=*/0);
 }
 
+void WhitespaceManager::alignConsecutiveBitFields() {
+  if (!Style.AlignConsecutiveBitFields)
+return;
+
+  AlignTokens(
+  Style,
+  [&](Change const &C) {
+// Do not align on ':' that is first on a line.
+if (C.NewlinesBefore > 0)
+  return false;
+
+// Do not align on ':' that is last on a line.
+if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
+  return false;
+
+return C.Tok->is(TT_BitFieldColon);
+  },
+  Changes, /*StartAt=*/0);
+}
+
 void WhitespaceManager::alignConsecutiveDeclarations() {
   if (!Style.AlignConsecutiveDeclarations)
 return;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -403,6 +403,8 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignConsecutiveAssignments",
Style.AlignConsecutiveAssignments);
+IO.mapOptional("AlignConsecutiveBitFields",
+   Style.AlignConsecutiveBitFields);
 IO.mapOptional("AlignConsecutiveDeclarations",
Style.AlignConsecutiveDeclarations);
 IO.mapOptional("AlignEscapedNewlines", Style.Alig

[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-19 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:72
+   binaryOperator(hasOperatorName("=="),
+  hasEitherOperand(ignoringParenImpCasts(StringNpos)),
+  hasEitherOperand(ignoringParenImpCasts(StringFind))),

ymandel wrote:
> Would `hasOperands` replace these two separate calls to `hasEitherOperand`? 
> Same below lines 79-80 (I think it's a new matcher, fwiw).
Just added, I added it to remove calls of multiple hasEitherOperand calls for 
the reason of preventing the matchers matching the same operand. I just got a 
little lost in my previous comment



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:98
+const LangOptions &LangOpts) const {
+  return LangOpts.CPlusPlus;
+}

nit: as abseil requires c++11, should this check also require c++11 support


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D80251: [X86] Update some av512 shift intrinsics to use "unsigned int" parameter instead of int to match Intel documentaiton

2020-05-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel.

There are 65 that take a scalar shift amount. Intel documentation shows 60 of 
them taking unsigned int. There are 5 versions of srli_epi16 that use int, the 
512-bit maskz and 128/256 mask/maskz.

Fixes PR45931


https://reviews.llvm.org/D80251

Files:
  clang/lib/Headers/avx512bwintrin.h
  clang/lib/Headers/avx512fintrin.h
  clang/lib/Headers/avx512vlbwintrin.h
  clang/lib/Headers/avx512vlintrin.h
  clang/test/CodeGen/avx512bw-builtins.c
  clang/test/CodeGen/avx512f-builtins.c
  clang/test/CodeGen/avx512vl-builtins.c
  clang/test/CodeGen/avx512vlbw-builtins.c

Index: clang/test/CodeGen/avx512vlbw-builtins.c
===
--- clang/test/CodeGen/avx512vlbw-builtins.c
+++ clang/test/CodeGen/avx512vlbw-builtins.c
@@ -2199,7 +2199,7 @@
   return _mm_mask_slli_epi16(__W, __U, __A, 5); 
 }
 
-__m128i test_mm_mask_slli_epi16_2(__m128i __W, __mmask8 __U, __m128i __A, int __B) {
+__m128i test_mm_mask_slli_epi16_2(__m128i __W, __mmask8 __U, __m128i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm_mask_slli_epi16_2
   // CHECK: @llvm.x86.sse2.pslli.w
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
@@ -2213,7 +2213,7 @@
   return _mm_maskz_slli_epi16(__U, __A, 5); 
 }
 
-__m128i test_mm_maskz_slli_epi16_2(__mmask8 __U, __m128i __A, int __B) {
+__m128i test_mm_maskz_slli_epi16_2(__mmask8 __U, __m128i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm_maskz_slli_epi16_2
   // CHECK: @llvm.x86.sse2.pslli.w
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
@@ -2227,7 +2227,7 @@
   return _mm256_mask_slli_epi16(__W, __U, __A, 5); 
 }
 
-__m256i test_mm256_mask_slli_epi16_2(__m256i __W, __mmask16 __U, __m256i __A, int __B) {
+__m256i test_mm256_mask_slli_epi16_2(__m256i __W, __mmask16 __U, __m256i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm256_mask_slli_epi16_2
   // CHECK: @llvm.x86.avx2.pslli.w
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
@@ -2241,7 +2241,7 @@
   return _mm256_maskz_slli_epi16(__U, __A, 5); 
 }
 
-__m256i test_mm256_maskz_slli_epi16_2(__mmask16 __U, __m256i __A, int __B) {
+__m256i test_mm256_maskz_slli_epi16_2(__mmask16 __U, __m256i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm256_maskz_slli_epi16_2
   // CHECK: @llvm.x86.avx2.pslli.w
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
@@ -2447,7 +2447,7 @@
   return _mm_mask_srai_epi16(__W, __U, __A, 5); 
 }
 
-__m128i test_mm_mask_srai_epi16_2(__m128i __W, __mmask8 __U, __m128i __A, int __B) {
+__m128i test_mm_mask_srai_epi16_2(__m128i __W, __mmask8 __U, __m128i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm_mask_srai_epi16_2
   // CHECK: @llvm.x86.sse2.psrai.w
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
@@ -2461,7 +2461,7 @@
   return _mm_maskz_srai_epi16(__U, __A, 5); 
 }
 
-__m128i test_mm_maskz_srai_epi16_2(__mmask8 __U, __m128i __A, int __B) {
+__m128i test_mm_maskz_srai_epi16_2(__mmask8 __U, __m128i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm_maskz_srai_epi16_2
   // CHECK: @llvm.x86.sse2.psrai.w
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
@@ -2475,7 +2475,7 @@
   return _mm256_mask_srai_epi16(__W, __U, __A, 5); 
 }
 
-__m256i test_mm256_mask_srai_epi16_2(__m256i __W, __mmask16 __U, __m256i __A, int __B) {
+__m256i test_mm256_mask_srai_epi16_2(__m256i __W, __mmask16 __U, __m256i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm256_mask_srai_epi16_2
   // CHECK: @llvm.x86.avx2.psrai.w
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
@@ -2489,7 +2489,7 @@
   return _mm256_maskz_srai_epi16(__U, __A, 5); 
 }
 
-__m256i test_mm256_maskz_srai_epi16_2(__mmask16 __U, __m256i __A, int __B) {
+__m256i test_mm256_maskz_srai_epi16_2(__mmask16 __U, __m256i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm256_maskz_srai_epi16_2
   // CHECK: @llvm.x86.avx2.psrai.w
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
Index: clang/test/CodeGen/avx512vl-builtins.c
===
--- clang/test/CodeGen/avx512vl-builtins.c
+++ clang/test/CodeGen/avx512vl-builtins.c
@@ -6236,7 +6236,7 @@
   return _mm_mask_srli_epi32(__W, __U, __A, 5); 
 }
 
-__m128i test_mm_mask_srli_epi32_2(__m128i __W, __mmask8 __U, __m128i __A, int __B) {
+__m128i test_mm_mask_srli_epi32_2(__m128i __W, __mmask8 __U, __m128i __A, unsigned int __B) {
   // CHECK-LABEL: @test_mm_mask_srli_epi32_2
   // CHECK: @llvm.x86.sse2.psrli.d
   // CHECK: select <4 x i1> %{{.*}}, <4 x i32> %{{.*}}, <4 x i32> %{{.*}}
@@ -6250,7 +6250,7 @@
   return _mm_maskz_srli_epi32(__U, __A, 5); 
 }
 
-__m128i test_mm_maskz_srli_epi32_2(__mmask8 __U, __m128i __A, int __B) {
+__m128i test_mm_maskz_srli_epi32_2(__mmask8 __U, __m128i __A, unsigned int __B) {
   // CHECK-LAB

[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

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

Looks like this only implements support for typedefs, but the flag in GCC does 
more than that (as the flag name indicates - it's about unused types in 
general) - could you test this across some non-trivial code and see if it 
matches GCC's behavior (or, where it doesn't, that there's a good reason for 
that divergence)

Here's a few cases I tested by hand:

  typedef int t1; // yes
  struct t2 { }; // yes
  template
  struct t3 { T t; };
  void f1(
  decltype(t3::t), // yes (t3)
  t3); // no (t3)
  struct t4; // no
  struct t5; // yes because \/
  typedef t5* t6; // yes
  struct t7; // no
  void f2(t7*);

https://godbolt.org/z/SgHxJv




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5559
+  case Decl::Typedef:
+if (getCodeGenOpts().DebugUnusedTypes)
+  if (CGDebugInfo *DI = getModuleDebugInfo())

Probably test this within the implementation of CGDebugInfo? & rename the 
EmitTypedef function to something that clarifies that it's for an otherwise 
unused type?

But that function might need to be generalized further, rather than only having 
it for typedefs. (see general comment above)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242



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


[clang] b47d1ba - [analyzer][NSOrCFError] Don't emit diagnostics under the name osx.NSOrCFErrorDerefChecker

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-20T00:05:49+02:00
New Revision: b47d1baa535abe061e6a89341e91c8b885b5b80e

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

LOG: [analyzer][NSOrCFError] Don't emit diagnostics under the name 
osx.NSOrCFErrorDerefChecker

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
clang/test/Analysis/incorrect-checker-names.mm

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
index 5f68788fafcd..90c5583d8969 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -144,14 +144,14 @@ namespace {
 
 class NSErrorDerefBug : public BugType {
 public:
-  NSErrorDerefBug(const CheckerBase *Checker)
+  NSErrorDerefBug(const CheckerNameRef Checker)
   : BugType(Checker, "NSError** null dereference",
 "Coding conventions (Apple)") {}
 };
 
 class CFErrorDerefBug : public BugType {
 public:
-  CFErrorDerefBug(const CheckerBase *Checker)
+  CFErrorDerefBug(const CheckerNameRef Checker)
   : BugType(Checker, "CFErrorRef* null dereference",
 "Coding conventions (Apple)") {}
 };
@@ -166,9 +166,9 @@ class NSOrCFErrorDerefChecker
   mutable std::unique_ptr NSBT;
   mutable std::unique_ptr CFBT;
 public:
-  bool ShouldCheckNSError, ShouldCheckCFError;
-  NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr),
-  ShouldCheckNSError(0), ShouldCheckCFError(0) { }
+  DefaultBool ShouldCheckNSError, ShouldCheckCFError;
+  CheckerNameRef NSErrorName, CFErrorName;
+  NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr) {}
 
   void checkLocation(SVal loc, bool isLoad, const Stmt *S,
  CheckerContext &C) const;
@@ -276,12 +276,12 @@ void 
NSOrCFErrorDerefChecker::checkEvent(ImplicitNullDerefEvent event) const {
   BugType *bug = nullptr;
   if (isNSError) {
 if (!NSBT)
-  NSBT.reset(new NSErrorDerefBug(this));
+  NSBT.reset(new NSErrorDerefBug(NSErrorName));
 bug = NSBT.get();
   }
   else {
 if (!CFBT)
-  CFBT.reset(new CFErrorDerefBug(this));
+  CFBT.reset(new CFErrorDerefBug(CFErrorName));
 bug = CFBT.get();
   }
   BR.emitReport(
@@ -331,6 +331,7 @@ void ento::registerNSErrorChecker(CheckerManager &mgr) {
   mgr.registerChecker();
   NSOrCFErrorDerefChecker *checker = mgr.getChecker();
   checker->ShouldCheckNSError = true;
+  checker->NSErrorName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterNSErrorChecker(const CheckerManager &mgr) {
@@ -341,6 +342,7 @@ void ento::registerCFErrorChecker(CheckerManager &mgr) {
   mgr.registerChecker();
   NSOrCFErrorDerefChecker *checker = mgr.getChecker();
   checker->ShouldCheckCFError = true;
+  checker->CFErrorName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterCFErrorChecker(const CheckerManager &mgr) {

diff  --git a/clang/test/Analysis/incorrect-checker-names.mm 
b/clang/test/Analysis/incorrect-checker-names.mm
index f14eea9d9c63..11b6a21a14a9 100644
--- a/clang/test/Analysis/incorrect-checker-names.mm
+++ b/clang/test/Analysis/incorrect-checker-names.mm
@@ -106,9 +106,19 @@ + (id)errorWithDomain:(NSString *)domain 
code:(NSInteger)code userInfo:(NSDictio
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0;  // expected-warning {{Potential null dereference.  According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.NSOrCFErrorDerefChecker]}}
+  *error = 0; // expected-warning {{Potential null dereference.  According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
 }
 
+@interface A
+- (void)myMethodWhichMayFail:(NSError **)error;
+@end
+
+@implementation A
+- (void)myMethodWhichMayFail:(NSError **)error {  // 
expected-warning {{Method accepting NSError** should have a non-void return 
value to indicate whether or not an error occurred [osx.cocoa.NSError]}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference.  According to coding standards 
in 'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
+}
+@end
+
 bool write_into_out_param_on_success(OS_RETURNS_RETAINED OSObject **obj);
 
 void use_out_param_leak() {



___
cfe-commit

[clang] 66224d3 - [analyzer][ObjCGenerics] Don't emit diagnostics under the name core.DynamicTypePropagation

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-20T00:19:20+02:00
New Revision: 66224d309d08c048b3bea257ceafe4873ce166c6

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

LOG: [analyzer][ObjCGenerics] Don't emit diagnostics under the name 
core.DynamicTypePropagation

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
clang/test/Analysis/Inputs/expected-plists/generics.m.plist

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
index 1502c0f9d656..14ba5d769969 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -55,6 +55,7 @@ class DynamicTypePropagation:
 check::PostStmt,
 check::PreObjCMessage,
 check::PostObjCMessage > {
+
   const ObjCObjectType *getObjectTypeForAllocAndNew(const ObjCMessageExpr 
*MsgE,
 CheckerContext &C) const;
 
@@ -69,8 +70,8 @@ class DynamicTypePropagation:
   mutable std::unique_ptr ObjCGenericsBugType;
   void initBugType() const {
 if (!ObjCGenericsBugType)
-  ObjCGenericsBugType.reset(
-  new BugType(this, "Generics", categories::CoreFoundationObjectiveC));
+  ObjCGenericsBugType.reset(new BugType(
+  GenericCheckName, "Generics", categories::CoreFoundationObjectiveC));
   }
 
   class GenericsBugVisitor : public BugReporterVisitor {
@@ -108,6 +109,7 @@ class DynamicTypePropagation:
 
   /// This value is set to true, when the Generics checker is turned on.
   DefaultBool CheckGenerics;
+  CheckerNameRef GenericCheckName;
 };
 
 bool isObjCClassType(QualType Type) {
@@ -1101,6 +1103,7 @@ PathDiagnosticPieceRef 
DynamicTypePropagation::GenericsBugVisitor::VisitNode(
 void ento::registerObjCGenericsChecker(CheckerManager &mgr) {
   DynamicTypePropagation *checker = mgr.getChecker();
   checker->CheckGenerics = true;
+  checker->GenericCheckName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterObjCGenericsChecker(const CheckerManager &mgr) {

diff  --git a/clang/test/Analysis/Inputs/expected-plists/generics.m.plist 
b/clang/test/Analysis/Inputs/expected-plists/generics.m.plist
index ad01828a350e..bbe77595818d 100644
--- a/clang/test/Analysis/Inputs/expected-plists/generics.m.plist
+++ b/clang/test/Analysis/Inputs/expected-plists/generics.m.plist
@@ -138,9 +138,9 @@
descriptionConversion from value of type 
'NSMutableArray *' to incompatible type 
'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   
issue_hash_content_of_line_in_context33d4584e2bf66b029ab9d152cc9cd8f7
+   
issue_hash_content_of_line_in_context9be4ccbeebeb5f814eb9ff5cef4907d3
   issue_context_kindfunction
   issue_contextincompatibleTypesErased
   issue_hash_function_offset2
@@ -295,9 +295,9 @@
descriptionConversion from value of type 
'NSMutableArray *' to incompatible type 
'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   
issue_hash_content_of_line_in_context6edc910aaa9dc1f2d823abc8cb75360f
+   
issue_hash_content_of_line_in_context567cd90c936f23ea70aca98b9d3af2b7
   issue_context_kindfunction
   issue_contextincompatibleTypesErased
   issue_hash_function_offset5
@@ -421,9 +421,9 @@
descriptionConversion from value of type 'NSNumber 
*' to incompatible type 'NSString *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   
issue_hash_content_of_line_in_context73c71c858082f5d7a2258f707927da3c
+   
issue_hash_content_of_line_in_contexta6e6f9c2db7532f45c07d2c13bcf496b
   issue_context_kindfunction
   issue_contextincompatibleTypesErased
   issue_hash_function_offset8
@@ -689,9 +689,9 @@
descriptionConversion from value of type 
'NSArray *' to incompatible type 
'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   
issue_hash_content_of_line_in_context82c378fdcfcc5c0318d2f3ca46420ec1
+   
issue_hash_content_of_line_in_context73523166e7c9e436da86a96fbd7b3d90
   issue_context_kindfunction
   issue_contextcrossProceduralErasedTypes
   issue_hash_function_offset1
@@ -846,9 +846,9 @@
descriptionConversion from value of type 
'NSMutableArray *' to incompatible type 
'NSArr

[PATCH] D79967: Fix debug info for NoDebug attr

2020-05-19 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

@yaxunl thanks, this patch lgtm.

@dblaikie I've kicked off a thread on cfe-dev about the topics you brought up 
("Design discussion re: DW_TAG_call_site support in clang") and cc'd you.


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

https://reviews.llvm.org/D79967



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


[PATCH] D60620: [HIP] Support target id by --offload-arch

2020-05-19 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D60620#1464633 , @tra wrote:

> It looks like you are solving two problems here.
>  a) you want to create multiple device passes for the same GPU, but with 
> different options.
>  b) you may want to pass different compiler options to different device 
> compilations.
>  The patch effectively hard-codes {gpu, options} tuple into 
> --offloading-target-id variant.
>  Is that correct?
>
> This looks essentially the same as your previous patch D59863 
> .
>
> We have a limited way to deal with (b), but there's currently no way to deal 
> with (a).
>
> For (a), I think, the real problem is that until now we've assumed that 
> there's only one device-side compilation per target GPU arch. If we need 
> multiple device-side compilations, we need a way to name them.  Using 
> `offloading-target-id` as  a super-set of `--cuda-gpu-arch` is OK with me. 
> However, I'm on the fence about the option serving a double-duty of setting 
> magic compiler flags. On one hand, that's what driver does, so it may be OK. 
> On the other hand, it's unnecessarily strict. I.e. if we provide ability to 
> create multiple compilation passes for the same GPU arch, why limit that to 
> only changing those hard-coded options? A general approach would allow a way 
> to create more than one device-side compilation and provide arbitrary 
> compiler options only to *that* compilation. Thiw will also help solving 
> number of issues we have right now when some host-side compilation options 
> break device-side compilation and we have to work around that by filtering 
> out some of them in the driver.


This patch is trying to solve the issue about GPU arch explosion due to 
combination of GPU configurations. A GPU may have several configurations which 
require different ISA's. From the compiler point of view, the GPU plus 
configuration behaves like different GPU archs. Previously we have been using 
different gfx names for the same GPU with different configurations. However, 
that does not scale. Therefore in this patch we extend GPU arch to `target id`, 
which is something like gpu+feature1-feature2.

The features allowed in target id are not arbitrary target features. They 
corresponding a limited number of GPU configurations that HIP runtime 
understands. Basically HIP runtime looks at the target id of the device objects 
in a fat binary and knows which one is best for the current GPU configuration. 
On the other hand, this is not some feature that can be easily implemented by 
users, since it needs knowledge about GPU configurations and corresponding 
compiler options for such configurations. Therefore, this is some feature 
better implemented within HIP compiler/runtime.

For embedding multiple device binaries for the same GPU but compiled with 
different options in one fat binary, since HIP runtime does not know which one 
to load, I don't think it is useful. On the other hand, users can always 
implement their own mechanisms for using device binaries compiled with 
different options with their own logic about how to choose them, therefore this 
is better left to the users.


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

https://reviews.llvm.org/D60620



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


[PATCH] D80166: [CGCall] Annotate reference parameters with "align" attribute.

2020-05-19 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/lib/CodeGen/CGCall.cpp:2258
 Attrs.addDereferenceableAttr(info.first.getQuantity());
-Attrs.addAttribute(llvm::Attribute::getWithAlignment(
-getLLVMContext(), info.second.getAsAlign()));
+Attrs.addAlignmentAttr(info.second.getAsAlign());
   }

efriedma wrote:
> rjmccall wrote:
> > Both of these are wrong for classes with virtual bases.
> I'm pretty sure classes with virtual bases aren't used with 
> SwiftIndirectResult, so not really relevant.
Ah... true, and even if they were, it would presumably be a complete object 
that was returned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80166



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


[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

ah, right. I need to additionally handle structs, unions, enums.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242



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


[PATCH] D80176: [clang-format][PR45816] Add AlignConsecutiveBitFields

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80176



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


[PATCH] D78124: [analyzer][ObjCGenerics] Don't emit diagnostics under the name core.DynamicTypePropagation

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG66224d309d08: [analyzer][ObjCGenerics] Don't emit 
diagnostics under the name core. (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D78124?vs=257375&id=265067#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78124

Files:
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/test/Analysis/Inputs/expected-plists/generics.m.plist

Index: clang/test/Analysis/Inputs/expected-plists/generics.m.plist
===
--- clang/test/Analysis/Inputs/expected-plists/generics.m.plist
+++ clang/test/Analysis/Inputs/expected-plists/generics.m.plist
@@ -138,9 +138,9 @@
descriptionConversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_context33d4584e2bf66b029ab9d152cc9cd8f7
+   issue_hash_content_of_line_in_context9be4ccbeebeb5f814eb9ff5cef4907d3
   issue_context_kindfunction
   issue_contextincompatibleTypesErased
   issue_hash_function_offset2
@@ -295,9 +295,9 @@
descriptionConversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_context6edc910aaa9dc1f2d823abc8cb75360f
+   issue_hash_content_of_line_in_context567cd90c936f23ea70aca98b9d3af2b7
   issue_context_kindfunction
   issue_contextincompatibleTypesErased
   issue_hash_function_offset5
@@ -421,9 +421,9 @@
descriptionConversion from value of type 'NSNumber *' to incompatible type 'NSString *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_context73c71c858082f5d7a2258f707927da3c
+   issue_hash_content_of_line_in_contexta6e6f9c2db7532f45c07d2c13bcf496b
   issue_context_kindfunction
   issue_contextincompatibleTypesErased
   issue_hash_function_offset8
@@ -689,9 +689,9 @@
descriptionConversion from value of type 'NSArray *' to incompatible type 'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_context82c378fdcfcc5c0318d2f3ca46420ec1
+   issue_hash_content_of_line_in_context73523166e7c9e436da86a96fbd7b3d90
   issue_context_kindfunction
   issue_contextcrossProceduralErasedTypes
   issue_hash_function_offset1
@@ -846,9 +846,9 @@
descriptionConversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_context234e3c299ee75a4dd4563e0ea88b9ed9
+   issue_hash_content_of_line_in_context649d50ef4cf1287ed225396d39995361
   issue_context_kindfunction
   issue_contextincompatibleTypesErasedReverseConversion
   issue_hash_function_offset4
@@ -970,9 +970,9 @@
descriptionConversion from value of type 'NSNumber *' to incompatible type 'NSString *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_contexte875afc5479fec33a693ce2b550a9573
+   issue_hash_content_of_line_in_contextd5cc413c71cae912d5ba469f8fa05ac3
   issue_context_kindfunction
   issue_contextincompatibleTypesErasedReverseConversion
   issue_hash_function_offset6
@@ -1129,9 +1129,9 @@
descriptionConversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_contextd7fa9fa89fe860ed8f5d22631233a5fa
+   issue_hash_content_of_line_in_context36d360e268b9ebc2d70e160a15b9a186
   issue_context_kindfunction
   issue_contextidErasedIncompatibleTypesReverseConversion
   issue_hash_function_offset4
@@ -1252,9 +1252,9 @@
descriptionConversion from value of type 'NSNumber *' to incompatible type 'NSString *'
categoryCore Foundation/Objective-C
typeGenerics
-   check_namecore.DynamicTypePropagation
+   check_nameosx.cocoa.ObjCGenerics

-   issue_hash_content_of_line_in_context7de91182a5d6e40a85fa3b91cf3fd089
+   issue_hash_content_of_line_in_contexta7326f4dedbc94e8fa1ee02d851e7810
   issue_context_kindfunction
   issue_contextidErasedIncompatibl

[PATCH] D78123: [analyzer][NSOrCFError] Don't emit diagnostics under the name osx.NSOrCFErrorDerefChecker

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb47d1baa535a: [analyzer][NSOrCFError] Don't emit 
diagnostics under the name osx. (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D78123?vs=257373&id=265066#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78123

Files:
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/test/Analysis/incorrect-checker-names.mm


Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -106,9 +106,19 @@
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0;  // expected-warning {{Potential null dereference.  According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.NSOrCFErrorDerefChecker]}}
+  *error = 0; // expected-warning {{Potential null dereference.  According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
 }
 
+@interface A
+- (void)myMethodWhichMayFail:(NSError **)error;
+@end
+
+@implementation A
+- (void)myMethodWhichMayFail:(NSError **)error {  // 
expected-warning {{Method accepting NSError** should have a non-void return 
value to indicate whether or not an error occurred [osx.cocoa.NSError]}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference.  According to coding standards 
in 'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
+}
+@end
+
 bool write_into_out_param_on_success(OS_RETURNS_RETAINED OSObject **obj);
 
 void use_out_param_leak() {
Index: clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -144,14 +144,14 @@
 
 class NSErrorDerefBug : public BugType {
 public:
-  NSErrorDerefBug(const CheckerBase *Checker)
+  NSErrorDerefBug(const CheckerNameRef Checker)
   : BugType(Checker, "NSError** null dereference",
 "Coding conventions (Apple)") {}
 };
 
 class CFErrorDerefBug : public BugType {
 public:
-  CFErrorDerefBug(const CheckerBase *Checker)
+  CFErrorDerefBug(const CheckerNameRef Checker)
   : BugType(Checker, "CFErrorRef* null dereference",
 "Coding conventions (Apple)") {}
 };
@@ -166,9 +166,9 @@
   mutable std::unique_ptr NSBT;
   mutable std::unique_ptr CFBT;
 public:
-  bool ShouldCheckNSError, ShouldCheckCFError;
-  NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr),
-  ShouldCheckNSError(0), ShouldCheckCFError(0) { }
+  DefaultBool ShouldCheckNSError, ShouldCheckCFError;
+  CheckerNameRef NSErrorName, CFErrorName;
+  NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr) {}
 
   void checkLocation(SVal loc, bool isLoad, const Stmt *S,
  CheckerContext &C) const;
@@ -276,12 +276,12 @@
   BugType *bug = nullptr;
   if (isNSError) {
 if (!NSBT)
-  NSBT.reset(new NSErrorDerefBug(this));
+  NSBT.reset(new NSErrorDerefBug(NSErrorName));
 bug = NSBT.get();
   }
   else {
 if (!CFBT)
-  CFBT.reset(new CFErrorDerefBug(this));
+  CFBT.reset(new CFErrorDerefBug(CFErrorName));
 bug = CFBT.get();
   }
   BR.emitReport(
@@ -331,6 +331,7 @@
   mgr.registerChecker();
   NSOrCFErrorDerefChecker *checker = mgr.getChecker();
   checker->ShouldCheckNSError = true;
+  checker->NSErrorName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterNSErrorChecker(const CheckerManager &mgr) {
@@ -341,6 +342,7 @@
   mgr.registerChecker();
   NSOrCFErrorDerefChecker *checker = mgr.getChecker();
   checker->ShouldCheckCFError = true;
+  checker->CFErrorName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterCFErrorChecker(const CheckerManager &mgr) {


Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -106,9 +106,19 @@
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0;  // expected-warning {{Potential null dereference.  According to coding standards documente

[PATCH] D80176: [clang-format][PR45816] Add AlignConsecutiveBitFields

2020-05-19 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD added a comment.

Can I get your assistance committing this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80176



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


[clang] 3d0d2fe - analyzer][CallAndMessage][NFC] Change old callbacks to rely on CallEvent

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-20T00:37:59+02:00
New Revision: 3d0d2fefc0a18f13e45a17be04a3da8d2b1299f8

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

LOG: analyzer][CallAndMessage][NFC] Change old callbacks to rely on CallEvent

The following series of patches has something similar in mind with D77474, with
the same goal to finally end incorrect checker names for good. Despite
CallAndMessage not suffering from this particular issue, it is a dependency for
many other checkers, which is problematic, because we don't really want
dependencies to also emit diagnostics (reasoning for this is also more detailed
in D77474).

CallAndMessage also has another problem, namely that it is responsible for a lot
of reports. You'll soon learn that this isn't really easy to solve for
compatibility reasons, but that is the topic of followup patches.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index 82bc200ba4ce..00fbe2c8dcb7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -11,9 +11,10 @@
 //
 
//===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -21,6 +22,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -29,11 +31,8 @@ using namespace ento;
 namespace {
 
 class CallAndMessageChecker
-  : public Checker< check::PreStmt,
-check::PreStmt,
-check::PreObjCMessage,
-check::ObjCMessageNil,
-check::PreCall > {
+: public Checker {
   mutable std::unique_ptr BT_call_null;
   mutable std::unique_ptr BT_call_undef;
   mutable std::unique_ptr BT_cxx_call_null;
@@ -48,11 +47,10 @@ class CallAndMessageChecker
   mutable std::unique_ptr BT_call_few_args;
 
 public:
-  DefaultBool Check_CallAndMessageUnInitRefArg;
-  CheckerNameRef CheckName_CallAndMessageUnInitRefArg;
+  enum CheckKind { CK_CallAndMessageUnInitRefArg, CK_NumCheckKinds };
+
+  DefaultBool ChecksEnabled[CK_NumCheckKinds];
 
-  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
-  void checkPreStmt(const CXXDeleteExpr *DE, CheckerContext &C) const;
   void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
 
   /// Fill in the return value that results from messaging nil based on the
@@ -144,7 +142,7 @@ bool CallAndMessageChecker::uninitRefOrPointer(
 CheckerContext &C, const SVal &V, SourceRange ArgRange, const Expr *ArgEx,
 std::unique_ptr &BT, const ParmVarDecl *ParamDecl, const char *BD,
 int ArgumentNumber) const {
-  if (!Check_CallAndMessageUnInitRefArg)
+  if (!ChecksEnabled[CK_CallAndMessageUnInitRefArg])
 return false;
 
   // No parameter declaration available, i.e. variadic function argument.
@@ -311,63 +309,36 @@ bool 
CallAndMessageChecker::PreVisitProcessArg(CheckerContext &C,
   return false;
 }
 
-void CallAndMessageChecker::checkPreStmt(const CallExpr *CE,
- CheckerContext &C) const{
-
-  const Expr *Callee = CE->getCallee()->IgnoreParens();
+void CallAndMessageChecker::checkPreCall(const CallEvent &Call,
+ CheckerContext &C) const {
   ProgramStateRef State = C.getState();
-  const LocationContext *LCtx = C.getLocationContext();
-  SVal L = State->getSVal(Callee, LCtx);
-
-  if (L.isUndef()) {
-if (!BT_call_undef)
-  BT_call_undef.reset(new BuiltinBug(
-  this, "Called function pointer is an uninitialized pointer value"));
-emitBadCall(BT_call_undef.get(), C, Callee);
-return;
-  }
-
-  ProgramStateRef StNonNull, StNull;
-  std::tie(StNonNull, StNull) = 
State->assume(L.castAs());
-
-  if (StNull && !StNonNull) {
-if (!BT_call_null)
-  BT_call_null.reset(new BuiltinBug(
-  this, "Called function pointer is null (null dereference)"));
-emitBadCall(BT_call_null.get(), C, Callee);
-return;
-  }
-
-  C.ad

[clang] f2be30d - [analyzer][NFC] Merge checkNewAllocator's paramaters into CXXAllocatorCall

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-20T00:56:10+02:00
New Revision: f2be30def37d248a7666cfac3c922ca9db308c2a

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

LOG: [analyzer][NFC] Merge checkNewAllocator's paramaters into CXXAllocatorCall

Party based on this thread:
http://lists.llvm.org/pipermail/cfe-dev/2020-February/064754.html.

This patch merges two of CXXAllocatorCall's parameters, so that we are able to
supply a CallEvent object to check::NewAllocatorCall (see the description of
D75430 to see why this would be great).

One of the things mentioned by @NoQ was the following:

  I think at this point we might actually do a good job sorting out this
  check::NewAllocator issue because we have a "separate" "Environment" to hold
  the other SVal, which is "objects under construction"! - so we should probably
  simply teach CXXAllocatorCall to extract the value from the
  objects-under-construction trait of the program state and we're good.

I had MallocChecker in my crosshair for now, so I admittedly threw together
something as a proof of concept. Now that I know that this effort is worth
pursuing though, I'll happily look for a solution better then demonstrated in
this patch.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/Checker.h
clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index 0c7acdbc3a97..fdba49664615 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -285,9 +285,9 @@ class BranchCondition {
 
 class NewAllocator {
   template 
-  static void _checkNewAllocator(void *checker, const CXXNewExpr *NE,
- SVal Target, CheckerContext &C) {
-((const CHECKER *)checker)->checkNewAllocator(NE, Target, C);
+  static void _checkNewAllocator(void *checker, const CXXAllocatorCall &Call,
+ CheckerContext &C) {
+((const CHECKER *)checker)->checkNewAllocator(Call, C);
   }
 
 public:

diff  --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index f34f5c239290..820ccfceecf6 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -37,6 +37,7 @@ class TranslationUnitDecl;
 namespace ento {
 
 class AnalysisManager;
+class CXXAllocatorCall;
 class BugReporter;
 class CallEvent;
 class CheckerBase;
@@ -361,11 +362,9 @@ class CheckerManager {
  ExprEngine &Eng);
 
   /// Run checkers between C++ operator new and constructor calls.
-  void runCheckersForNewAllocator(const CXXNewExpr *NE, SVal Target,
-  ExplodedNodeSet &Dst,
-  ExplodedNode *Pred,
-  ExprEngine &Eng,
-  bool wasInlined = false);
+  void runCheckersForNewAllocator(const CXXAllocatorCall &Call,
+  ExplodedNodeSet &Dst, ExplodedNode *Pred,
+  ExprEngine &Eng, bool wasInlined = false);
 
   /// Run checkers for live symbols.
   ///
@@ -506,7 +505,7 @@ class CheckerManager {
   CheckerFn;
 
   using CheckNewAllocatorFunc =
-  CheckerFn;
+  CheckerFn;
 
   using CheckDeadSymbolsFunc =
   CheckerFn;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index 871875b45b1b..8b84b79651bd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -39,6 +39,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -1010,6 +1011,12 @@ class CXXAllocatorCall : public AnyFunctionCall {
 return getOriginExpr()->getOperatorNew();
   }
 
+  SVal getObjectUnderConstruction() const {
+return ExprEngine::getObjectUnderConstruction(getState(), getOriginExpr(),

[PATCH] D80214: [clang-format] Set of unit test to begin to validate that we don't change defaults

2020-05-19 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD added a comment.

+1 for this idea. It'd eventually be neat to also take all samples from the 
style guide of each project and test them, if there aren't licensing concerns.

LGTM with an appropriate merge fix/CI passing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80214



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


[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align

2020-05-19 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD added a comment.

Hey @MyDeveloperDay, can I get your assistance committing this when you have 
the chance?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79465



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


[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:4965
+  DBuilder.retainType(Ty);
+}

Looks like I can just reuse CGDebugInfo::EmitExplicitCastType


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242



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


[PATCH] D55892: [OpenMP] 'close' map-type-modifier code generation

2020-05-19 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir closed this revision.
saghir added a comment.
Herald added subscribers: sstefan1, yaxunl.

Support for  'close' map-type-modifier code generation in clang has been added 
by patch D65341 . This revision can be closed.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55892



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


[PATCH] D79675: [OpenMP][OMPBuilder] Adding Privatization Requirements to OMPIRBuilder

2020-05-19 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim marked 21 inline comments as done.
fghanim added a comment.

In D79675#2044809 , @jdoerfert wrote:

> What's the status? Can we split the target specific types stuff if this may 
> take a while, other patches depend on that :)


Could you please list the other patches that are being held back by this one? 
I'd be interested to have a look at them. :)




Comment at: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def:234
 __OMP_RTL(__kmpc_critical, false, Void, IdentPtr, Int32, KmpCriticalNamePtrTy)
-__OMP_RTL(__kmpc_critical_with_hint, false, Void, IdentPtr, Int32, 
KmpCriticalNamePtrTy, Int32)
+__OMP_RTL(__kmpc_critical_with_hint, false, Void, IdentPtr, Int32, 
KmpCriticalNamePtrTy, IntPtrTy)
 __OMP_RTL(__kmpc_end_critical, false, Void, IdentPtr, Int32, 
KmpCriticalNamePtrTy)

jdoerfert wrote:
> fghanim wrote:
> > jdoerfert wrote:
> > > fghanim wrote:
> > > > jdoerfert wrote:
> > > > > fghanim wrote:
> > > > > > jdoerfert wrote:
> > > > > > > I think this was correct before:
> > > > > > > ```
> > > > > > >   KMP_EXPORT void __kmpc_critical_with_hint(ident_t *, kmp_int32 
> > > > > > > global_tid, kmp_critical_name *, uint32_t hint);
> > > > > > > ```
> > > > > > Nop, it's supposed to be whatever `IntPtrTy` is in the frontend 
> > > > > > (i.e. 32 for 32bit, 64 for 64bit).
> > > > > > 
> > > > > > `IntPtrTy` is actually a union with `sizety` in `CodeGenModule`
> > > > > I'm confused. I copied the declaration above from the runtime. It 
> > > > > doesn't contain an `IntPtrTy` or similar. I agree that `IntPtrTy` is 
> > > > > machine dependent and we need your initializers. What I tried to say 
> > > > > is that at least one declaration in the runtime has 
> > > > > `__kmpc_critical_with_hint` with an int32 as last argument. That 
> > > > > said, the runtime is not shy of incompatible declarations for 
> > > > > functions.
> > > > I cannot speak for what's in the runtime. However, in clang, this 
> > > > currently is defined to use `IntPtrTy`. If you go check, I have a todo 
> > > > in the current implementation for critical to come back and fix it.
> > > That is just an existing bug in Clang. The runtime is consistent with the 
> > > type and arguably it is the runtime we must match, not the other way 
> > > around ;)
> > Apparently, this used to be `uintptr_t` in the runtime and was changed by 
> > D51235 . It doesn't say why the change was made.
> > 
> > Clang uses this in multiple places, which makes me think it may have been 
> > intentional. So I suggest we go by the standard. Where can I find what does 
> > the OMP standard say about how the signature of the runtime calls should 
> > look like? This way I'll fix this one accordingly, and later we may go and 
> > make sure that all the rest match up with the standard - where possible.
> This is not a standard function. It is a runtime function. I suspect it is a 
> int32_t because enums default to `int` which is 32 bit on all interesting 
> platforms. Should probably be a `int` but I would need to read up to confirm. 
> Long story short, and as I said before, it is a bug in clang. The code here 
> was correct.
> 
> FWIW, we will soon replace clang's runtime function generation with these 
> macros. That will happen in the next days I hope.
Oh, my bad. I thought OMP runtime functions are designed a specific way based 
on the OMP standard. If that's not the case, then it doesn't matter. I'll drop 
this change as well. There is a handful of hints anyway.



Comment at: llvm/lib/Frontend/OpenMP/OMPConstants.cpp:122
+  }
+}
+

jdoerfert wrote:
> fghanim wrote:
> > jdoerfert wrote:
> > > fghanim wrote:
> > > > jdoerfert wrote:
> > > > > (I doubt we need the `initVoidPtr` function but if we do, the 
> > > > > condition looks wrong)
> > > > Forgot to refractor when I changed names.
> > > > 
> > > > Regarding `void*` , I am not sure how it is defined in fortran. That's 
> > > > why I made it possible to initialize it separately.
> > > I see. Let's cross that bridge once we get to it.
> > Modified it a bit and removed usage from initialization. If fortran people 
> > don't end using it, then we can remove it.
> Let's not add stuff that might be used.
I just looked this up. Apparently, Fortran doesn't seem to have the concept of 
void pointer natively. However, They have something called `Assumed types` , 
which was added for interoperability with C, which *probably* means it will 
follow whatever C does to handle void pointers.

I'll remove it now, and if they choose, people can add it later.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:106
+  initializeVoidPtrTy(VoidPtrTy);
+}
+

jdoerfert wrote:
> fghanim wrote:
> > jdoerfert wrote:
> > > I guess we can directly call the initialize functions, right?
> > > With an assert that SizeTy is set we can make sure users do it ;)
> > Sure, then again, I am just followin

[PATCH] D77845: [analyzer][CallAndMessage][NFC] Change old callbacks to rely on CallEvent

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d0d2fefc0a1: analyzer][CallAndMessage][NFC] Change old 
callbacks to rely on CallEvent (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D77845?vs=256461&id=265074#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77845

Files:
  clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -11,9 +11,10 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -21,6 +22,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -29,11 +31,8 @@
 namespace {
 
 class CallAndMessageChecker
-  : public Checker< check::PreStmt,
-check::PreStmt,
-check::PreObjCMessage,
-check::ObjCMessageNil,
-check::PreCall > {
+: public Checker {
   mutable std::unique_ptr BT_call_null;
   mutable std::unique_ptr BT_call_undef;
   mutable std::unique_ptr BT_cxx_call_null;
@@ -48,11 +47,10 @@
   mutable std::unique_ptr BT_call_few_args;
 
 public:
-  DefaultBool Check_CallAndMessageUnInitRefArg;
-  CheckerNameRef CheckName_CallAndMessageUnInitRefArg;
+  enum CheckKind { CK_CallAndMessageUnInitRefArg, CK_NumCheckKinds };
+
+  DefaultBool ChecksEnabled[CK_NumCheckKinds];
 
-  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
-  void checkPreStmt(const CXXDeleteExpr *DE, CheckerContext &C) const;
   void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
 
   /// Fill in the return value that results from messaging nil based on the
@@ -144,7 +142,7 @@
 CheckerContext &C, const SVal &V, SourceRange ArgRange, const Expr *ArgEx,
 std::unique_ptr &BT, const ParmVarDecl *ParamDecl, const char *BD,
 int ArgumentNumber) const {
-  if (!Check_CallAndMessageUnInitRefArg)
+  if (!ChecksEnabled[CK_CallAndMessageUnInitRefArg])
 return false;
 
   // No parameter declaration available, i.e. variadic function argument.
@@ -311,63 +309,36 @@
   return false;
 }
 
-void CallAndMessageChecker::checkPreStmt(const CallExpr *CE,
- CheckerContext &C) const{
-
-  const Expr *Callee = CE->getCallee()->IgnoreParens();
+void CallAndMessageChecker::checkPreCall(const CallEvent &Call,
+ CheckerContext &C) const {
   ProgramStateRef State = C.getState();
-  const LocationContext *LCtx = C.getLocationContext();
-  SVal L = State->getSVal(Callee, LCtx);
-
-  if (L.isUndef()) {
-if (!BT_call_undef)
-  BT_call_undef.reset(new BuiltinBug(
-  this, "Called function pointer is an uninitialized pointer value"));
-emitBadCall(BT_call_undef.get(), C, Callee);
-return;
-  }
-
-  ProgramStateRef StNonNull, StNull;
-  std::tie(StNonNull, StNull) = State->assume(L.castAs());
-
-  if (StNull && !StNonNull) {
-if (!BT_call_null)
-  BT_call_null.reset(new BuiltinBug(
-  this, "Called function pointer is null (null dereference)"));
-emitBadCall(BT_call_null.get(), C, Callee);
-return;
-  }
-
-  C.addTransition(StNonNull);
-}
+  if (const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr())) {
+const Expr *Callee = CE->getCallee()->IgnoreParens();
+const LocationContext *LCtx = C.getLocationContext();
+SVal L = State->getSVal(Callee, LCtx);
+
+if (L.isUndef()) {
+  if (!BT_call_undef)
+BT_call_undef.reset(new BuiltinBug(
+this, "Called function pointer is an uninitialized pointer value"));
+  emitBadCall(BT_call_undef.get(), C, Callee);
+  return;
+}
 
-void CallAndMessageChecker::checkPreStmt(const CXXDeleteExpr *DE,
- CheckerContext &C) const {
+ProgramStateRef StNonNull, StNull;
+std::tie(StNonNull, StNull) =
+State->assume(L.castAs());
 
-  SVal Arg = C.getSVal(DE->getArgument());
-  if (Arg.isUndef()) {
-StringRef Desc;
-ExplodedNode *N = C.generateErrorNode();
-if (!N)
+if (StNull && !StNonNull) {
+  

[PATCH] D75431: [analyzer][NFC] Merge checkNewAllocator's paramaters into CXXAllocatorCall

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2be30def37d: [analyzer][NFC] Merge checkNewAllocator's 
paramaters into CXXAllocatorCall (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D75431?vs=254816&id=265075#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75431

Files:
  clang/include/clang/StaticAnalyzer/Core/Checker.h
  clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -21,6 +21,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/SaveAndRestore.h"
 
@@ -325,17 +326,14 @@
 CallEventRef<> UpdatedCall = Call.cloneWithState(CEEState);
 
 ExplodedNodeSet DstPostCall;
-if (const CXXNewExpr *CNE = dyn_cast_or_null(CE)) {
+if (llvm::isa_and_nonnull(CE)) {
   ExplodedNodeSet DstPostPostCallCallback;
   getCheckerManager().runCheckersForPostCall(DstPostPostCallCallback,
  CEENode, *UpdatedCall, *this,
  /*wasInlined=*/true);
-  for (auto I : DstPostPostCallCallback) {
+  for (ExplodedNode *I : DstPostPostCallCallback) {
 getCheckerManager().runCheckersForNewAllocator(
-CNE,
-*getObjectUnderConstruction(I->getState(), CNE,
-calleeCtx->getParent()),
-DstPostCall, I, *this,
+cast(*UpdatedCall), DstPostCall, I, *this,
 /*wasInlined=*/true);
   }
 } else {
@@ -591,7 +589,7 @@
   // If there were other constructors called for object-type arguments
   // of this call, clean them up.
   ExplodedNodeSet dstArgumentCleanup;
-  for (auto I : dstCallEvaluated)
+  for (ExplodedNode *I : dstCallEvaluated)
 finishArgumentConstruction(dstArgumentCleanup, I, Call);
 
   ExplodedNodeSet dstPostCall;
@@ -605,7 +603,7 @@
 
   // Run pointerEscape callback with the newly conjured symbols.
   SmallVector, 8> Escaped;
-  for (auto I : dstPostCall) {
+  for (ExplodedNode *I : dstPostCall) {
 NodeBuilder B(I, Dst, *currBldrCtx);
 ProgramStateRef State = I->getState();
 Escaped.clear();
@@ -743,7 +741,7 @@
 const ConstructionContext *CC = CCE ? CCE->getConstructionContext()
 : nullptr;
 
-if (CC && isa(CC) &&
+if (llvm::isa_and_nonnull(CC) &&
 !Opts.MayInlineCXXAllocator)
   return CIP_DisallowedOnce;
 
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -577,9 +577,10 @@
   // paths when no-return temporary destructors are used for assertions.
   const AnalysisDeclContext *ADC = LCtx->getAnalysisDeclContext();
   if (!ADC->getCFGBuildOptions().AddTemporaryDtors) {
-if (TargetRegion && isa(TargetRegion) &&
+if (llvm::isa_and_nonnull(TargetRegion) &&
 cast(Call->getDecl())
-->getParent()->isAnyDestructorNoReturn()) {
+->getParent()
+->isAnyDestructorNoReturn()) {
 
   // If we've inlined the constructor, then DstEvaluated would be empty.
   // In this case we still want a sink, which could be implemented
@@ -603,7 +604,7 @@
   }
 
   ExplodedNodeSet DstPostArgumentCleanup;
-  for (auto I : DstEvaluated)
+  for (ExplodedNode *I : DstEvaluated)
 finishArgumentConstruction(DstPostArgumentCleanup, I, *Call);
 
   // If there were other constructors called for object-type arguments
@@ -712,7 +713,7 @@
 
   ExplodedNodeSet DstPostCall;
   StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
-  for (auto I : DstPreCall) {
+  for (ExplodedNode *I : DstPreCall) {
 // FIXME: Provide evalCall for checkers?
 defaultEvalCall(CallBldr, I, *Call);
   }
@@ -722,7 +723,7 @@
   // CXXNewExpr gets processed.
   ExplodedNodeSet DstPostValue;
   StmtNodeBuilder ValueBldr(DstPostCall, DstPostValue, *currBldrCtx);
-  for (auto I : DstPostCall) {
+  for (ExplodedNode *I : DstPostCall) {
 // FIXME: Because CNE serves as the "call site" for the all

[PATCH] D79675: [OpenMP][OMPBuilder] Adding Privatization Requirements to OMPIRBuilder

2020-05-19 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim updated this revision to Diff 265071.
fghanim marked 2 inline comments as done.
fghanim added a comment.

Addressing reviewer Comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79675

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPConstants.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -62,7 +62,7 @@
 
 TEST_F(OpenMPIRBuilderTest, CreateBarrier) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
 
   IRBuilder<> Builder(BB);
 
@@ -102,7 +102,7 @@
 TEST_F(OpenMPIRBuilderTest, CreateCancel) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
 
   BasicBlock *CBB = BasicBlock::Create(Ctx, "", F);
   new UnreachableInst(Ctx, CBB);
@@ -157,7 +157,7 @@
 TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
 
   BasicBlock *CBB = BasicBlock::Create(Ctx, "", F);
   new UnreachableInst(Ctx, CBB);
@@ -218,7 +218,7 @@
 TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
 
   BasicBlock *CBB = BasicBlock::Create(Ctx, "", F);
   new UnreachableInst(Ctx, CBB);
@@ -272,7 +272,7 @@
 
 TEST_F(OpenMPIRBuilderTest, DbgLoc) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
   F->setName("func");
 
   IRBuilder<> Builder(BB);
@@ -308,7 +308,7 @@
 TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
   F->setName("func");
   IRBuilder<> Builder(BB);
 
@@ -405,7 +405,7 @@
 TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
   F->setName("func");
   IRBuilder<> Builder(BB);
 
@@ -516,7 +516,7 @@
 TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
   F->setName("func");
   IRBuilder<> Builder(BB);
 
@@ -625,7 +625,7 @@
 TEST_F(OpenMPIRBuilderTest, MasterDirective) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
   F->setName("func");
   IRBuilder<> Builder(BB);
 
@@ -704,7 +704,7 @@
 TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
   F->setName("func");
   IRBuilder<> Builder(BB);
 
@@ -779,4 +779,41 @@
   EXPECT_EQ(CriticalEndCI->getArgOperand(2)->getType(), CriticalNamePtrTy);
 }
 
+TEST_F(OpenMPIRBuilderTest, CopyinBlocks) {
+  using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
+  F->setName("func");
+  IRBuilder<> Builder(BB);
+
+  OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+  AllocaInst *PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+  IntegerType* Int32 = Type::getInt32Ty(M->getContext());
+  AllocaInst* MasterAddress = Builder.CreateAlloca(Int32->getPointerTo());
+	AllocaInst* PrivAddress = Builder.CreateAlloca(Int32->getPointerTo());
+
+  BasicBlock *EntryBB = BB;
+
+  OMPBuilder.CreateCopyinClauseBlocks(Builder.saveIP(), MasterAddress, PrivAddress, Int32, /*BranchtoEnd*/true);
+
+  BranchInst* EntryBr = dyn_cast_or_null(EntryBB->getTerminator());
+
+  EXPECT_NE(EntryBr, nullptr);
+  EXPECT_TRUE(EntryBr->isConditional());
+
+  BasicBlock* NotMasterBB = EntryBr->getSuccessor(0);
+  BasicBlock* CopyinEnd = EntryBr->getSuccessor(1);
+  CmpInst* CMP = dyn_cast_or_null(EntryBr->getCondition())

[PATCH] D79967: Fix debug info for NoDebug attr

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

In D79967#2045196 , @vsk wrote:

> @yaxunl thanks, this patch lgtm.
>
> @dblaikie I've kicked off a thread on cfe-dev about the topics you brought up 
> ("Design discussion re: DW_TAG_call_site support in clang") and cc'd you.


Thanks on both counts!


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

https://reviews.llvm.org/D79967



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


[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

For C++, I'd imagine:

  class foo {};
  using my_foo = foo;
  template 
  struct baz {
bar my_bar;
  };

but it seems that `g++` doesn't emit debug info the for the templated struct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242



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


[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 265077.
nickdesaulniers added a comment.

- add support for structs, unions, and enums


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/debug-info-unused-types.c

Index: clang/test/CodeGen/debug-info-unused-types.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-unused-types.c
@@ -0,0 +1,30 @@
+// RUN: %clang -fno-eliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang -feliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+typedef int my_int;
+struct foo {};
+enum bar { BAR };
+union baz {};
+
+// Check that debug info is emitted for the typedef, struct, enum, and union
+// when -fno-eliminate-unused-debug-types and -g are set.
+
+// CHECK: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "bar", file: !4, line: 7, baseType: !5, size: 32, elements: !6)
+// CHECK: !5 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+// CHECK: !7 = !DIEnumerator(name: "BAR", value: 0, isUnsigned: true)
+// CHECK: !9 = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int", file: !4, line: 5, baseType: !10)
+// CHECK: !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// CHECK: !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !4, line: 6, elements: !12)
+// CHECK: !13 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "baz", file: !4, line: 8, elements: !12)
+
+// Check that debug info is not emitted for the typedef, struct, enum, and
+// union when -fno-eliminate-unused-debug-types and -g are not set.
+
+// NODBG-NOT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "bar", file: !4, line: 7, baseType: !5, size: 32, elements: !6)
+// NODBG-NOT: !5 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+// NODBG-NOT: !7 = !DIEnumerator(name: "BAR", value: 0, isUnsigned: true)
+// NODBG-NOT: !9 = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int", file: !4, line: 5, baseType: !10)
+// NODBG-NOT: !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// NODBG-NOT: !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !4, line: 6, elements: !12)
+// NODBG-NOT: !13 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "baz", file: !4, line: 8, elements: !12)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -765,6 +765,7 @@
   Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
   Opts.DebugExplicitImport = Args.hasArg(OPT_dwarf_explicit_import);
   Opts.DebugFwdTemplateParams = Args.hasArg(OPT_debug_forward_template_params);
+  Opts.DebugUnusedTypes = Args.hasArg(OPT_eliminate_unused_debug_types_fno);
   Opts.EmbedSource = Args.hasArg(OPT_gembed_source);
   Opts.ForceDwarfFrameSection = Args.hasArg(OPT_fforce_dwarf_frame);
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5190,6 +5190,8 @@
 
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
+  Args.AddLastArg(CmdArgs, options::OPT_eliminate_unused_debug_types_f);
+  Args.AddLastArg(CmdArgs, options::OPT_eliminate_unused_debug_types_fno);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -,6 +,30 @@
 EmitOMPRequiresDecl(cast(D));
 break;
 
+  case Decl::Typedef:
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  if (getCodeGenOpts().DebugUnusedTypes) {
+QualType QT = getContext().getTypedefType(cast(D));
+DI->EmitExplicitCastType(QT);
+  }
+break;
+
+  case Decl::Record:
+if (CGDebugInfo *DI = getModuleDebugInfo())
+  if (getCodeGenOpts().DebugUnusedTypes) {
+QualType QT = getContext().getRecordType(cast(D));
+DI->EmitExplicitCastType(QT);
+  }
+break;
+
+  case Decl::Enum:
+i

[PATCH] D79998: Add AST_SIGNATURE record to unhashed control block of pcm files (Patch series 2/3)

2020-05-19 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added a comment.

In D79998#2038430 , @dang wrote:

> Should I add the test here or in the clang-scan-deps patch?


It's best to have a test in every non-nfc patch. You should be able to test 
this with llvm-bcanalyzer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79998



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


[PATCH] D79743: [clang][asm goto][slh] Warn if asm goto + SLH

2020-05-19 Thread Zola Bridges via Phabricator via cfe-commits
zbrid updated this revision to Diff 265081.
zbrid added a comment.

Add test; Update command for existing test

Also rename file to match warning flag


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79743

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Parse/ParseStmtAsm.cpp
  clang/test/Parser/slh-asm-goto-no-warn.cpp
  clang/test/Parser/slh-asm-goto.cpp


Index: clang/test/Parser/slh-asm-goto.cpp
===
--- /dev/null
+++ clang/test/Parser/slh-asm-goto.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -mspeculative-load-hardening -fsyntax-only -verify %s
+
+void f() {
+  __asm goto("movl %ecx, %edx"); // expected-warning {{Speculative load 
hardening does not protect functions with asm goto}}
+}
Index: clang/test/Parser/slh-asm-goto-no-warn.cpp
===
--- /dev/null
+++ clang/test/Parser/slh-asm-goto-no-warn.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wno-slh-asm-goto -mspeculative-load-hardening 
-fsyntax-only -verify %s
+
+void f() {
+  __asm goto("movl %ecx, %edx"); // expected-no-diagnostics
+}
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -729,6 +729,9 @@
   if (parseGNUAsmQualifierListOpt(GAQ))
 return StmtError();
 
+  if (GAQ.isGoto() && getLangOpts().SpeculativeLoadHardening)
+Diag(Loc, diag::warn_slh_does_not_support_asm_goto);
+
   BalancedDelimiterTracker T(*this, tok::l_paren);
   T.consumeOpen();
 
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -243,6 +243,9 @@
   def warn_stack_clash_protection_inline_asm : Warning<
 "Unable to protect inline asm that clobbers stack pointer against stack 
clash">,
 InGroup>;
+
+  def warn_slh_does_not_support_asm_goto : Warning<
+"Speculative load hardening does not protect functions with asm goto">, 
InGroup>;
 }
 
 // Sema && Serialization


Index: clang/test/Parser/slh-asm-goto.cpp
===
--- /dev/null
+++ clang/test/Parser/slh-asm-goto.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -mspeculative-load-hardening -fsyntax-only -verify %s
+
+void f() {
+  __asm goto("movl %ecx, %edx"); // expected-warning {{Speculative load hardening does not protect functions with asm goto}}
+}
Index: clang/test/Parser/slh-asm-goto-no-warn.cpp
===
--- /dev/null
+++ clang/test/Parser/slh-asm-goto-no-warn.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wno-slh-asm-goto -mspeculative-load-hardening -fsyntax-only -verify %s
+
+void f() {
+  __asm goto("movl %ecx, %edx"); // expected-no-diagnostics
+}
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -729,6 +729,9 @@
   if (parseGNUAsmQualifierListOpt(GAQ))
 return StmtError();
 
+  if (GAQ.isGoto() && getLangOpts().SpeculativeLoadHardening)
+Diag(Loc, diag::warn_slh_does_not_support_asm_goto);
+
   BalancedDelimiterTracker T(*this, tok::l_paren);
   T.consumeOpen();
 
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -243,6 +243,9 @@
   def warn_stack_clash_protection_inline_asm : Warning<
 "Unable to protect inline asm that clobbers stack pointer against stack clash">,
 InGroup>;
+
+  def warn_slh_does_not_support_asm_goto : Warning<
+"Speculative load hardening does not protect functions with asm goto">, InGroup>;
 }
 
 // Sema && Serialization
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79743: [clang][asm goto][slh] Warn if asm goto + SLH

2020-05-19 Thread Zola Bridges via Phabricator via cfe-commits
zbrid added a comment.

In D79743#2044676 , @jyu2 wrote:

> This looks good to me.  Could you also add a test to use this new DiagGroup 
> (-Wno-slh-asm-goto)?
>
> Thanks.
>
> Jennifer


Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79743



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


[PATCH] D79675: [OpenMP][OMPBuilder] Adding Privatization Requirements to OMPIRBuilder

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

> Could you please list the other patches that are being held back by this one? 
> I'd be interested to have a look at them. :)

We need the target type support for D80222 , 
D79739  can go in but we need to modify it 
afterwards.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79675



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


[PATCH] D60620: [HIP] Support target id by --offload-arch

2020-05-19 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Basic/HIP.cpp:16
+const llvm::SmallVector
+getAllPossibleTargetIdFeatures(llvm::StringRef Device) {
+  llvm::SmallVector Ret;

Nit: there's an unfortunate clash with already [[ 
https://github.com/llvm/llvm-project/blob/6a3469f58d0c230e86043f6975f048968334dfa4/clang/include/clang/Driver/CC1Options.td#L23
 | target-feature ]] in clang & LLVM.

Would something like `GPUProperties` be a reasonable name?



Comment at: clang/lib/Driver/ToolChains/HIP.cpp:121-123
+  auto Pos = SubArchName.find_first_of("+-");
+  if (Pos != SubArchName.npos)
+SubArchName = SubArchName.substr(0, Pos);

Parsing should probably be extracted into a separate function to avoid 
replicating it all over the place.

I'd also propose use a different syntax for the properties.
* use explicit character to separate individual elements. This way splitting 
the properties becomes independent of what those properties are. If you decide 
to make properties with values or change their meaning some other way, it would 
not affect how you compose them.
* use `name=value` or `name[+-]` for individual properties. This makes it easy 
to parse individual properties and normalize their names. This makes property 
map creation independent of the property values.

Right now `[+-]` serves as both a separator and as the value, which would 
present problems if you ever need more flexible parametrization of properties. 
What if a property must be a number or a string. Granted, you can always encode 
them as a set of bools, but that's rather unpractical. 

E.g. something like this would work a bit better: 
`gfx111:foo+:bar=33:buz=string`.



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

https://reviews.llvm.org/D60620



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


[PATCH] D76510: [analyzer] Change the default output type to PD_TEXT_MINIMAL in the frontend, error if an output loc is missing for PathDiagConsumers that need it

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I'm committing this now as-is, if something breaks, I'll revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76510



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


[PATCH] D76510: [analyzer] Change the default output type to PD_TEXT_MINIMAL in the frontend, error if an output loc is missing for PathDiagConsumers that need it

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfe1a3a7e8c8b: [analyzer] Change the default output type to 
PD_TEXT_MINIMAL in the frontend… (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D76510?vs=251673&id=265087#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76510

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/test/Analysis/output_types.cpp

Index: clang/test/Analysis/output_types.cpp
===
--- /dev/null
+++ clang/test/Analysis/output_types.cpp
@@ -0,0 +1,49 @@
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=plist \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-PLIST
+
+// CHECK-PLIST: error: analyzer output type 'plist' requires an output file to
+// CHECK-PLIST-SAME: be specified with -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=plist-multi-file \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-PLIST-MULTI
+
+// CHECK-PLIST-MULTI: error: analyzer output type 'plist-multi-file' requires
+// CHECK-PLIST-MULTI-SAME: an output file to be specified with
+// CHECK-PLIST-MULTI-SAME: -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=plist-html \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-PLIST-HTML
+
+// CHECK-PLIST-HTML: error: analyzer output type 'plist-html' requires an output
+// CHECK-PLIST-HTML-SAME: directory to be specified with
+// CHECK-PLIST-HTML-SAME: -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=sarif \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-SARIF
+
+// CHECK-SARIF: error: analyzer output type 'sarif' requires an output file to
+// CHECK-SARIF-SAME: be specified with -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=html \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-HTML
+
+// CHECK-HTML: error: analyzer output type 'html' requires an output directory
+// CHECK-HTML-SAME: to be specified with -o 
+
+
+// RUN: not %clang_analyze_cc1 %s \
+// RUN:   -analyzer-output=html-single-file \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-HTML-SINGLE
+
+// CHECK-HTML-SINGLE: error: analyzer output type 'html-single-file' requires
+// CHECK-HTML-SINGLE-SAME: an output directory to be specified with
+// CHECK-HTML-SINGLE-SAME: -o 
Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -23,6 +23,7 @@
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Rewrite/Core/Rewriter.h"
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/Version.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -52,9 +53,11 @@
 const std::string &Output, const Preprocessor &PP,
 const cross_tu::CrossTranslationUnitContext &CTU) {
 
-  // TODO: Emit an error here.
-  if (Output.empty())
+  if (Output.empty()) {
+PP.getDiagnostics().Report(diag::err_analyzer_missing_output_loc)
+  << "sarif" << "file";
 return;
+  }
 
   C.push_back(new SarifDiagnostics(AnalyzerOpts, Output, PP.getLangOpts()));
   createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, Output, PP, CTU);
Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/TokenConcatenation.h"
@@ -571,10 +572,10 @@
 //===--===

[clang] fe1a3a7 - [analyzer] Change the default output type to PD_TEXT_MINIMAL in the frontend, error if an output loc is missing for PathDiagConsumers that need it

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-20T01:36:06+02:00
New Revision: fe1a3a7e8c8be33968b9a768666489823dabab10

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

LOG: [analyzer] Change the default output type to PD_TEXT_MINIMAL in the 
frontend, error if an output loc is missing for PathDiagConsumers that need it

The title and the included test file sums everything up -- the only thing I'm
mildly afraid of is whether anyone actually depends on the weird behavior of
HTMLDiagnostics pretending to be TextDiagnostics if an output directory is not
supplied. If it is, I guess we would need to resort to tiptoeing around the
compatibility flag.

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

Added: 
clang/test/Analysis/output_types.cpp

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index d010a7dfb2de..fdca8532ab53 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -358,6 +358,9 @@ def err_analyzer_checker_option_invalid_input : Error<
   "invalid input for checker option '%0', that expects %1">;
 def err_analyzer_checker_incompatible_analyzer_option : Error<
   "checker cannot be enabled with analyzer option '%0' == %1">;
+def err_analyzer_missing_output_loc : Error<
+  "analyzer output type '%0' requires an output %1 to be specified with "
+  "-o ">;
 
 def err_drv_invalid_hvx_length : Error<
   "-mhvx-length is not supported without a -mhvx/-mhvx= flag">;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index d2df24a6e21b..373caa30bbc9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -206,7 +206,7 @@ class AnalyzerOptions : public 
RefCountedBase {
   ConfigTable Config;
   AnalysisStores AnalysisStoreOpt = RegionStoreModel;
   AnalysisConstraints AnalysisConstraintsOpt = RangeConstraintsModel;
-  AnalysisDiagClients AnalysisDiagOpt = PD_HTML;
+  AnalysisDiagClients AnalysisDiagOpt = PD_TEXT_MINIMAL;
   AnalysisPurgeMode AnalysisPurgeOpt = PurgeStmt;
 
   std::string AnalyzeSpecificFunction;

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 184fdcfb3d4b..8ce3aa2e081e 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -21,6 +21,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Rewrite/Core/HTMLRewrite.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
@@ -137,18 +138,14 @@ void ento::createHTMLDiagnosticConsumer(
 const std::string &OutputDir, const Preprocessor &PP,
 const cross_tu::CrossTranslationUnitContext &CTU) {
 
-  // FIXME: HTML is currently our default output type, but if the output
-  // directory isn't specified, it acts like if it was in the minimal text
-  // output mode. This doesn't make much sense, we should have the minimal text
-  // as our default. In the case of backward compatibility concerns, this could
-  // be preserved with -analyzer-config-compatibility-mode=true.
-  createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, OutputDir, PP, CTU);
-
-  // TODO: Emit an error here.
-  if (OutputDir.empty())
+  if (OutputDir.empty()) {
+PP.getDiagnostics().Report(diag::err_analyzer_missing_output_loc)
+  << "html" << "directory";
 return;
+  }
 
   C.push_back(new HTMLDiagnostics(AnalyzerOpts, OutputDir, PP, true));
+  createTextMinimalPathDiagnosticConsumer(AnalyzerOpts, C, OutputDir, PP, CTU);
 }
 
 void ento::createHTMLSingleFileDiagnosticConsumer(
@@ -156,9 +153,11 @@ void ento::createHTMLSingleFileDiagnosticConsumer(
 const std::string &OutputDir, const Preprocessor &PP,
 const cross_tu::CrossTranslationUnitContext &CTU) {
 
-  // TODO: Emit an error here.
-  if (OutputDir.empty())
+  if (OutputDir.empty()) {
+PP.getDiagnostics().Report(diag::err_analyzer_missing_output_loc)
+  << "html-single-file" << "directory";
 return;
+  }
 
   C.push_back(new HTMLDiagnostics(AnalyzerOpts, OutputDir, PP, false));
   createTextMinimalPathDiagnosticConsu

[clang] 392222d - [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2020-05-20T02:03:31+02:00
New Revision: 39dd72657244f13d7f99cc6a497cc78eba2e

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

LOG: [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

Exactly what it says on the tin! This is clearly not the end of the road in this
direction, the parameters could be merged far more with the use of CallEvent or
a better value type in the CallDescriptionMap, but this was shockingly difficult
enough on its own. I expect that simplifying the file further will be far easier
moving forward.

The end goal is to research how we could create a more mature checker
interaction infrastructure for more complicated C++ modeling, and I'm pretty
sure that being able successfully split up our giants is the first step in this
direction.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index edcee6e2d052..f5f4dd0eaea5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -47,7 +47,10 @@
 #include "AllocationState.h"
 #include "InterCheckerAPI.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/ParentMap.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
@@ -63,10 +66,12 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
@@ -268,7 +273,7 @@ REGISTER_MAP_WITH_PROGRAMSTATE(ReallocPairs, SymbolRef, 
ReallocPair)
 /// placement operators and other standard overloads.
 static bool isStandardNewDelete(const FunctionDecl *FD);
 static bool isStandardNewDelete(const CallEvent &Call) {
-  if (!Call.getDecl())
+  if (!Call.getDecl() || !isa(Call.getDecl()))
 return false;
   return isStandardNewDelete(cast(Call.getDecl()));
 }
@@ -283,9 +288,8 @@ class MallocChecker
 : public Checker,
  check::EndFunction, check::PreCall, check::PostCall,
- check::PostStmt, check::NewAllocator,
- check::PostStmt, check::PostObjCMessage,
- check::Location, eval::Assume> {
+ check::NewAllocator, check::PostStmt,
+ check::PostObjCMessage, check::Location, eval::Assume> {
 public:
   /// In pessimistic mode, the checker assumes that it does not know which
   /// functions might free the memory.
@@ -314,8 +318,6 @@ class MallocChecker
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
-  void checkPostStmt(const CXXNewExpr *NE, CheckerContext &C) const;
-  void checkPreStmt(const CXXDeleteExpr *DE, CheckerContext &C) const;
   void checkNewAllocator(const CXXAllocatorCall &Call, CheckerContext &C) 
const;
   void checkPostObjCMessage(const ObjCMethodCall &Call, CheckerContext &C) 
const;
   void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const;
@@ -351,7 +353,7 @@ class MallocChecker
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
 
 #define CHECK_FN(NAME) 
\
-  void NAME(CheckerContext &C, const CallExpr *CE, ProgramStateRef State) 
const;
+  void NAME(const CallEvent &Call, CheckerContext &C) const;
 
   CHECK_FN(checkFree)
   CHECK_FN(checkIfNameIndex)
@@ -369,12 +371,11 @@ class MallocChecker
   CHECK_FN(checkReallocN)
   CHECK_FN(checkOwnershipAttr)
 
-  void checkRealloc(CheckerContext &C, const CallExpr *CE,
-ProgramStateRef State, bool ShouldFreeOnFail) const;
+  void checkRealloc(const CallEvent &Call, CheckerContext &C,
+bool ShouldFreeOnFail) const;
 
-  using CheckFn =
-  std::function;
+  using CheckFn = std::function;
 
   const CallDescriptionMap FreeingMemFnMap{
   {{"free", 1}, &MallocChecker::checkFree},
@@ -412,13 +413,13 @@ class MallocChecker
 
   CallDescriptionMap ReallocatingMemFnMap{
   {{"realloc", 2},
-   std::bind(&MallocChecker::checkRealloc, _1, 

[PATCH] D80171: [analyzer] LoopUnrolling: fix crash when a parameter is a loop counter

2020-05-19 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra updated this revision to Diff 265090.
AbbasSabra added a comment.

Fix code review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80171

Files:
  clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  clang/test/Analysis/loop-unrolling.cpp


Index: clang/test/Analysis/loop-unrolling.cpp
===
--- clang/test/Analysis/loop-unrolling.cpp
+++ clang/test/Analysis/loop-unrolling.cpp
@@ -500,8 +500,14 @@
   }
 }
 
-void arg_as_loop_counter(int i) {
+void parm_by_value_as_loop_counter(int i) {
   for (i = 0; i < 10; ++i) {
-(void)i;
+clang_analyzer_numTimesReached(); // expected-warning {{10}}
+  }
+}
+
+void parm_by_ref_as_loop_counter(int &i) {
+  for (i = 0; i < 10; ++i) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
   }
 }
Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -160,8 +160,13 @@
 }
 
 static bool isPossiblyEscaped(const VarDecl *VD, ExplodedNode *N) {
-  // Global variables and parameters assumed as escaped variables.
-  if (VD->hasGlobalStorage() || VD->getKind() == Decl::ParmVar)
+  // Global variables assumed as escaped variables.
+  if (VD->hasGlobalStorage())
+return true;
+
+  const bool isParm = VD->getKind() == Decl::ParmVar;
+  // Reference parameters are assumed as escaped variables.
+  if (isParm && VD->getType()->isReferenceType())
 return true;
 
   while (!N->pred_empty()) {
@@ -193,6 +198,11 @@
 
 N = N->getFirstPred();
   }
+
+  // Parameter declaration will not be found.
+  if (isParm)
+return false;
+
   llvm_unreachable("Reached root without finding the declaration of VD");
 }
 


Index: clang/test/Analysis/loop-unrolling.cpp
===
--- clang/test/Analysis/loop-unrolling.cpp
+++ clang/test/Analysis/loop-unrolling.cpp
@@ -500,8 +500,14 @@
   }
 }
 
-void arg_as_loop_counter(int i) {
+void parm_by_value_as_loop_counter(int i) {
   for (i = 0; i < 10; ++i) {
-(void)i;
+clang_analyzer_numTimesReached(); // expected-warning {{10}}
+  }
+}
+
+void parm_by_ref_as_loop_counter(int &i) {
+  for (i = 0; i < 10; ++i) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
   }
 }
Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -160,8 +160,13 @@
 }
 
 static bool isPossiblyEscaped(const VarDecl *VD, ExplodedNode *N) {
-  // Global variables and parameters assumed as escaped variables.
-  if (VD->hasGlobalStorage() || VD->getKind() == Decl::ParmVar)
+  // Global variables assumed as escaped variables.
+  if (VD->hasGlobalStorage())
+return true;
+
+  const bool isParm = VD->getKind() == Decl::ParmVar;
+  // Reference parameters are assumed as escaped variables.
+  if (isParm && VD->getType()->isReferenceType())
 return true;
 
   while (!N->pred_empty()) {
@@ -193,6 +198,11 @@
 
 N = N->getFirstPred();
   }
+
+  // Parameter declaration will not be found.
+  if (isParm)
+return false;
+
   llvm_unreachable("Reached root without finding the declaration of VD");
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-05-19 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added inline comments.



Comment at: clang/include/clang/Frontend/CompilerInvocation.h:156
   /// \param [out] Res - The resulting invocation.
+  /// \param [in] CommandLineArgs - Array of argument strings, this should not
+  /// contain "-cc1".

Is this really a should not, or is it must not?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3604-3610
+#define OPTION_WITH_MARSHALLING(PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, 
\
+ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR,
\
+VALUES, KEYPATH, IS_POSITIVE, DEFAULT_VALUE)   
\
+  if (Option::KIND##Class == Option::FlagClass)
\
+Res.KEYPATH = Args.hasArg(OPT_##ID) && IS_POSITIVE;
+#include "clang/Driver/Options.inc"
+#undef OPTION_WITH_MARSHALLING

This should probably go in a separate function as it will grow. I would 
recommend something like `ParseSimpleArgs` and call it right before 
`ParseAnalyzerArgs `.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3607
+VALUES, KEYPATH, IS_POSITIVE, DEFAULT_VALUE)   
\
+  if (Option::KIND##Class == Option::FlagClass)
\
+Res.KEYPATH = Args.hasArg(OPT_##ID) && IS_POSITIVE;

How would this handle other option classes? I think it would be good to include 
a few different types of options in the first patch.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3845
+  IS_POSITIVE != DEFAULT_VALUE && this->KEYPATH != DEFAULT_VALUE)  
\
+Args.push_back(StringAllocator(Twine(PREFIX_TYPE[0]) + NAME));
+#include "clang/Driver/Options.inc"

It's a little sad that we need to allocation every string just because of the 
`-`. We definitely need to be able to allocate strings for options with data, 
but it would be good if we could just have the strings with `-` prefixed in the 
option table if that's reasonable to do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796



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


[PATCH] D75432: [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39dd7265: [analyzer][NFC][MallocChecker] Convert many 
parameters into CallEvent (authored by Szelethus).
Herald added a subscriber: ASDenysPetrov.

Changed prior to commit:
  https://reviews.llvm.org/D75432?vs=247534&id=265091#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75432

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -47,7 +47,10 @@
 #include "AllocationState.h"
 #include "InterCheckerAPI.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/ParentMap.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
@@ -63,10 +66,12 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
@@ -268,7 +273,7 @@
 /// placement operators and other standard overloads.
 static bool isStandardNewDelete(const FunctionDecl *FD);
 static bool isStandardNewDelete(const CallEvent &Call) {
-  if (!Call.getDecl())
+  if (!Call.getDecl() || !isa(Call.getDecl()))
 return false;
   return isStandardNewDelete(cast(Call.getDecl()));
 }
@@ -283,9 +288,8 @@
 : public Checker,
  check::EndFunction, check::PreCall, check::PostCall,
- check::PostStmt, check::NewAllocator,
- check::PostStmt, check::PostObjCMessage,
- check::Location, eval::Assume> {
+ check::NewAllocator, check::PostStmt,
+ check::PostObjCMessage, check::Location, eval::Assume> {
 public:
   /// In pessimistic mode, the checker assumes that it does not know which
   /// functions might free the memory.
@@ -314,8 +318,6 @@
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
-  void checkPostStmt(const CXXNewExpr *NE, CheckerContext &C) const;
-  void checkPreStmt(const CXXDeleteExpr *DE, CheckerContext &C) const;
   void checkNewAllocator(const CXXAllocatorCall &Call, CheckerContext &C) const;
   void checkPostObjCMessage(const ObjCMethodCall &Call, CheckerContext &C) const;
   void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const;
@@ -351,7 +353,7 @@
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
 
 #define CHECK_FN(NAME) \
-  void NAME(CheckerContext &C, const CallExpr *CE, ProgramStateRef State) const;
+  void NAME(const CallEvent &Call, CheckerContext &C) const;
 
   CHECK_FN(checkFree)
   CHECK_FN(checkIfNameIndex)
@@ -369,12 +371,11 @@
   CHECK_FN(checkReallocN)
   CHECK_FN(checkOwnershipAttr)
 
-  void checkRealloc(CheckerContext &C, const CallExpr *CE,
-ProgramStateRef State, bool ShouldFreeOnFail) const;
+  void checkRealloc(const CallEvent &Call, CheckerContext &C,
+bool ShouldFreeOnFail) const;
 
-  using CheckFn =
-  std::function;
+  using CheckFn = std::function;
 
   const CallDescriptionMap FreeingMemFnMap{
   {{"free", 1}, &MallocChecker::checkFree},
@@ -412,13 +413,13 @@
 
   CallDescriptionMap ReallocatingMemFnMap{
   {{"realloc", 2},
-   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, _4, false)},
+   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, false)},
   {{"reallocf", 2},
-   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, _4, true)},
+   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, true)},
   {{"g_realloc", 2},
-   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, _4, false)},
+   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, false)},
   {{"g_try_realloc", 2},
-   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, _4, false)},
+   std::bind(&MallocChecker::checkRealloc, _1, _2, _3, false)},
   {{"g_realloc_n", 3}, &MallocChecker::checkReallocN},
   {{"g_try_realloc_n", 3}, &MallocChecker::checkReallocN},
   };
@@ -437,8 +438,10 @@
 
   /// Process C++ operator new()'s allocation, which is the part of C++
   /// new-expression that goes before the construct

[clang] 3a6ee4f - [analyzer][StackAddressEscape] Tie warnings to the diagnostic checkers rather then core.StackAddrEscapeBase

2020-05-19 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-05-20T02:26:40+02:00
New Revision: 3a6ee4fefec0bc97a0340ddc33e7a8ffd4590ad5

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

LOG: [analyzer][StackAddressEscape] Tie warnings to the diagnostic checkers 
rather then core.StackAddrEscapeBase

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
clang/test/Analysis/incorrect-checker-names.cpp
clang/test/Analysis/incorrect-checker-names.mm

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
index 237053df7e44..49ab25eca2dd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
@@ -78,13 +78,16 @@ class BuiltinBug : public BugType {
  const char *description)
   : BugType(checker, name, categories::LogicError), desc(description) {}
 
+  BuiltinBug(class CheckerNameRef checker, const char *name)
+  : BugType(checker, name, categories::LogicError), desc(name) {}
+
   BuiltinBug(const CheckerBase *checker, const char *name)
   : BugType(checker, name, categories::LogicError), desc(name) {}
 
   StringRef getDescription() const { return desc; }
 };
 
-} // end ento namespace
+} // namespace ento
 
 } // end clang namespace
 #endif

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 21fc65a8e4f1..b5c9356322fc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -43,6 +43,7 @@ class StackAddrEscapeChecker
   };
 
   DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPreStmt(const ReturnStmt *RS, CheckerContext &C) const;
@@ -156,7 +157,8 @@ void StackAddrEscapeChecker::EmitStackError(CheckerContext 
&C,
 return;
   if (!BT_returnstack)
 BT_returnstack = std::make_unique(
-this, "Return of address to stack-allocated memory");
+CheckNames[CK_StackAddrEscapeChecker],
+"Return of address to stack-allocated memory");
   // Generate a report for this bug.
   SmallString<128> buf;
   llvm::raw_svector_ostream os(buf);
@@ -195,7 +197,8 @@ void 
StackAddrEscapeChecker::checkAsyncExecutedBlockCaptures(
   continue;
 if (!BT_capturedstackasync)
   BT_capturedstackasync = std::make_unique(
-  this, "Address of stack-allocated memory is captured");
+  CheckNames[CK_StackAddrAsyncEscapeChecker],
+  "Address of stack-allocated memory is captured");
 SmallString<128> Buf;
 llvm::raw_svector_ostream Out(Buf);
 SourceRange Range = genName(Out, Region, C.getASTContext());
@@ -218,7 +221,8 @@ void StackAddrEscapeChecker::checkReturnedBlockCaptures(
   continue;
 if (!BT_capturedstackret)
   BT_capturedstackret = std::make_unique(
-  this, "Address of stack-allocated memory is captured");
+  CheckNames[CK_StackAddrEscapeChecker],
+  "Address of stack-allocated memory is captured");
 SmallString<128> Buf;
 llvm::raw_svector_ostream Out(Buf);
 SourceRange Range = genName(Out, Region, C.getASTContext());
@@ -277,7 +281,7 @@ void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt 
*RS,
 
   // The CK_CopyAndAutoreleaseBlockObject cast causes the block to be copied
   // so the stack address is not escaping here.
-  if (auto *ICE = dyn_cast(RetE)) {
+  if (const auto *ICE = dyn_cast(RetE)) {
 if (isa(R) &&
 ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject) {
   return;
@@ -333,7 +337,8 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
 
   if (!BT_stackleak)
 BT_stackleak = std::make_unique(
-this, "Stack address stored into global variable",
+CheckNames[CK_StackAddrEscapeChecker],
+"Stack address stored into global variable",
 "Stack address was saved into a global variable. "
 "This is dangerous because the address will become "
 "invalid after returning from the function");
@@ -371,14 +376,13 @@ bool ento::shouldRegisterStackAddrEscapeBase(const 
CheckerManager &mgr) {
 
 #define REGISTER_CHECKER(name) 
\
   void ento::register##name(CheckerManager &Mgr) { 
\
-StackAddrEscapeChecker *Chk =  
\
-Mgr.getC

[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

`CXXRecordDecl` is a funny case, the AST looks like:

  |-CXXRecordDecl 0x5c661a8  col:7 class foo 
definition
  | |-DefinitionData pass_in_registers empty aggregate standard_layout 
trivially_copyable pod trivial literal has_constexpr_non_copy_
  | `-CXXRecordDecl 0x5c662d0  col:7 implicit class foo
  ...

There's probably a bunch more C++ cases I'm not thinking of.  Reading through 
gcc's test suite for `-fno-eliminate-unused-debug-types`, this feature doesn't 
have tests for anything with templates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242



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


[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 265093.
nickdesaulniers added a comment.

- add C++ `using` and `class` support


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/debug-info-unused-types.c
  clang/test/CodeGen/debug-info-unused-types.cpp

Index: clang/test/CodeGen/debug-info-unused-types.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-unused-types.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang++ -fno-eliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang++ -feliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang++ -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang++ -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+using foo = int;
+class bar {};
+
+// CHECK: !4 = !DIDerivedType(tag: DW_TAG_typedef, name: "foo", file: !5, line: 5, baseType: !6)
+// CHECK: !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// CHECK: !7 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "bar", file: !5, line: 6, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS3bar")
+
+// NODBG-NOT: !4 = !DIDerivedType(tag: DW_TAG_typedef, name: "foo", file: !5, line: 5, baseType: !6)
+// NODBG-NOT: !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// NODBG-NOT: !7 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "bar", file: !5, line: 6, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS3bar")
Index: clang/test/CodeGen/debug-info-unused-types.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-unused-types.c
@@ -0,0 +1,30 @@
+// RUN: %clang -fno-eliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang -feliminate-unused-debug-types -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang -g -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+// RUN: %clang -emit-llvm -S -o - %s | FileCheck --check-prefix=NODBG %s
+typedef int my_int;
+struct foo {};
+enum bar { BAR };
+union baz {};
+
+// Check that debug info is emitted for the typedef, struct, enum, and union
+// when -fno-eliminate-unused-debug-types and -g are set.
+
+// CHECK: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "bar", file: !4, line: 7, baseType: !5, size: 32, elements: !6)
+// CHECK: !5 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+// CHECK: !7 = !DIEnumerator(name: "BAR", value: 0, isUnsigned: true)
+// CHECK: !9 = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int", file: !4, line: 5, baseType: !10)
+// CHECK: !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// CHECK: !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !4, line: 6, elements: !12)
+// CHECK: !13 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "baz", file: !4, line: 8, elements: !12)
+
+// Check that debug info is not emitted for the typedef, struct, enum, and
+// union when -fno-eliminate-unused-debug-types and -g are not set.
+
+// NODBG-NOT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "bar", file: !4, line: 7, baseType: !5, size: 32, elements: !6)
+// NODBG-NOT: !5 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+// NODBG-NOT: !7 = !DIEnumerator(name: "BAR", value: 0, isUnsigned: true)
+// NODBG-NOT: !9 = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int", file: !4, line: 5, baseType: !10)
+// NODBG-NOT: !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// NODBG-NOT: !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !4, line: 6, elements: !12)
+// NODBG-NOT: !13 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "baz", file: !4, line: 8, elements: !12)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -765,6 +765,7 @@
   Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
   Opts.DebugExplicitImport = Args.hasArg(OPT_dwarf_explicit_import);
   Opts.DebugFwdTemplateParams = Args.hasArg(OPT_debug_forward_template_params);
+  Opts.DebugUnusedTypes = Args.hasArg(OPT_eliminate_unused_debug_types_fno);
   Opts.EmbedSource = Args.hasArg(OPT_gembed_source);
   Opts.ForceDwarfFrameSection = Args.hasArg(OPT_fforce_dwarf_frame);
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- cla

[PATCH] D80242: [Clang] implement -fno-eliminate-unused-debug-types

2020-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5369
 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
-  DebugInfo->completeUnusedClass(cast(*D));
+  DebugInfo->completeUnusedClass(*CRD);
 }

The difference between using `DebugInfo` vs `getModuleDebugInfo` in this method 
is *killing* me.  Same with `return` vs `break`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80242



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


[PATCH] D80171: [analyzer] LoopUnrolling: fix crash when a parameter is a loop counter

2020-05-19 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra updated this revision to Diff 265095.
AbbasSabra added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80171

Files:
  clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  clang/test/Analysis/loop-unrolling.cpp


Index: clang/test/Analysis/loop-unrolling.cpp
===
--- clang/test/Analysis/loop-unrolling.cpp
+++ clang/test/Analysis/loop-unrolling.cpp
@@ -499,3 +499,15 @@
 clang_analyzer_numTimesReached(); // expected-warning {{6}}
   }
 }
+
+void parm_by_value_as_loop_counter(int i) {
+  for (i = 0; i < 10; ++i) {
+clang_analyzer_numTimesReached(); // expected-warning {{10}}
+  }
+}
+
+void parm_by_ref_as_loop_counter(int &i) {
+  for (i = 0; i < 10; ++i) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -164,6 +164,11 @@
   if (VD->hasGlobalStorage())
 return true;
 
+  const bool isParm = VD->getKind() == Decl::ParmVar;
+  // Reference parameters are assumed as escaped variables.
+  if (isParm && VD->getType()->isReferenceType())
+return true;
+
   while (!N->pred_empty()) {
 // FIXME: getStmtForDiagnostics() does nasty things in order to provide
 // a valid statement for body farms, do we need this behavior here?
@@ -193,6 +198,11 @@
 
 N = N->getFirstPred();
   }
+
+  // Parameter declaration will not be found.
+  if (isParm)
+return false;
+
   llvm_unreachable("Reached root without finding the declaration of VD");
 }
 


Index: clang/test/Analysis/loop-unrolling.cpp
===
--- clang/test/Analysis/loop-unrolling.cpp
+++ clang/test/Analysis/loop-unrolling.cpp
@@ -499,3 +499,15 @@
 clang_analyzer_numTimesReached(); // expected-warning {{6}}
   }
 }
+
+void parm_by_value_as_loop_counter(int i) {
+  for (i = 0; i < 10; ++i) {
+clang_analyzer_numTimesReached(); // expected-warning {{10}}
+  }
+}
+
+void parm_by_ref_as_loop_counter(int &i) {
+  for (i = 0; i < 10; ++i) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -164,6 +164,11 @@
   if (VD->hasGlobalStorage())
 return true;
 
+  const bool isParm = VD->getKind() == Decl::ParmVar;
+  // Reference parameters are assumed as escaped variables.
+  if (isParm && VD->getType()->isReferenceType())
+return true;
+
   while (!N->pred_empty()) {
 // FIXME: getStmtForDiagnostics() does nasty things in order to provide
 // a valid statement for body farms, do we need this behavior here?
@@ -193,6 +198,11 @@
 
 N = N->getFirstPred();
   }
+
+  // Parameter declaration will not be found.
+  if (isParm)
+return false;
+
   llvm_unreachable("Reached root without finding the declaration of VD");
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79743: [clang][asm goto][slh] Warn if asm goto + SLH

2020-05-19 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 accepted this revision.
jyu2 added a comment.
This revision is now accepted and ready to land.

LGTM.  Please changed format for td file.




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:247
+
+  def warn_slh_does_not_support_asm_goto : Warning<
+"Speculative load hardening does not protect functions with asm goto">, 
InGroup>;

Just need run clang-format:
def warn_slh_does_not_support_asm_goto
  : Warning<"Speculative load hardening does not protect functions with "
"asm goto">,
InGroup>;



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79743



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


[PATCH] D78101: [analyzer][StackAddressEscape] Tie warnings to the diagnostic checkers rather then core.StackAddrEscapeBase

2020-05-19 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a6ee4fefec0: [analyzer][StackAddressEscape] Tie warnings to 
the diagnostic checkers rather… (authored by Szelethus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78101

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/test/Analysis/incorrect-checker-names.cpp
  clang/test/Analysis/incorrect-checker-names.mm

Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -1,5 +1,6 @@
-// RUN: %clang_analyze_cc1 -fblocks -verify %s -Wno-objc-root-class \
+// RUN: %clang_analyze_cc1 -fblocks -fobjc-arc -verify %s -Wno-objc-root-class \
 // RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.core.StackAddressAsyncEscape \
 // RUN:   -analyzer-checker=nullability \
 // RUN:   -analyzer-checker=osx
 
@@ -126,3 +127,32 @@
   // FIXME: This shouldn't be tied to a modeling checker.
   write_into_out_param_on_success(&obj); // expected-warning{{Potential leak of an object stored into 'obj' [osx.cocoa.RetainCountBase]}}
 }
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+typedef long dispatch_once_t;
+void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
+typedef long dispatch_time_t;
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+extern dispatch_once_t *predicate;
+extern dispatch_time_t when;
+
+dispatch_block_t get_leaking_block() {
+  int leaked_x = 791;
+  int *p = &leaked_x;
+  return ^void(void) {
+*p = 1;
+  };
+  // expected-warning@-3 {{Address of stack memory associated with local variable 'leaked_x' \
+is captured by a returned block [core.StackAddressEscape]}}
+}
+
+void test_returned_from_func_block_async() {
+  dispatch_async(queue, get_leaking_block());
+  // expected-warning@-1 {{Address of stack memory associated with local variable 'leaked_x' \
+is captured by an asynchronously-executed block [alpha.core.StackAddressAsyncEscape]}}
+}
Index: clang/test/Analysis/incorrect-checker-names.cpp
===
--- clang/test/Analysis/incorrect-checker-names.cpp
+++ clang/test/Analysis/incorrect-checker-names.cpp
@@ -5,9 +5,16 @@
 int* stack_addr_escape_base() {
   int x = 0;
   // FIXME: This shouldn't be tied to a modeling checker.
-  return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned to caller [core.StackAddrEscapeBase]}}
+  return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned to caller [core.StackAddressEscape]}}
   // expected-note-re@-1^Address of stack memory associated with local variable 'x' returned to caller$
   // Just a regular compiler warning.
   // expected-warning@-3{{address of stack memory associated with local variable 'x' returned}}
 }
 
+char const *p;
+
+void f0() {
+  char const str[] = "This will change";
+  p = str;
+} // expected-warning{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller.  This will be a dangling reference [core.StackAddressEscape]}}
+// expected-note@-1{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller.  This will be a dangling reference}}
Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -43,6 +43,7 @@
   };
 
   DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPreStmt(const ReturnStmt *RS, CheckerContext &C) const;
@@ -156,7 +157,8 @@
 return;
   if (!BT_returnstack)
 BT_returnstack = std::make_unique(
-this, "Return of address to stack-allocated memory");
+CheckNames[CK_StackAddrEscapeChecker],
+"Return of address to stack-allocated memory");
   // Generate a report for this bug.
   SmallString<128> buf;
   llvm::raw_svector_ostream os(buf);
@@ -195,7 +197,8 @@
   continue;
 if (!BT_capturedstackasync)
   BT_capturedstackasync = std::make_unique(
-  this, "Address of stack-allocated memory is captured");

[PATCH] D80171: [analyzer] LoopUnrolling: fix crash when a parameter is a loop counter

2020-05-19 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra requested review of this revision.
AbbasSabra added a comment.

What you both said makes sense.  Now, reference parameters are escaped and 
value parameters are treated as the local variables.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80171



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


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I would like a specification for this header to be added somewhere. We 
shouldn't be implementing random things with no specification. (Suppose someone 
claims that our `` is wrong in some way. How would we know whether 
they're right?)

Ideally, I'd also like this header to be installed somewhere where we look for 
assembler-with-cpp preprocessing but not for regular compilation; it doesn't 
make sense to me to pollute the header namespace for all C and C++ compilations 
with a header that is not meaningful in C and C++. But knowing whether that 
change is correct depends on having, you know, a specification.

I don't think we should be porting this to Clang 10. It seems clear that this 
is a new feature, not a bug fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79617



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


[PATCH] D79675: [OpenMP][OMPBuilder] Adding Privatization Requirements to OMPIRBuilder

2020-05-19 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim added a comment.

In D79675#2045405 , @jdoerfert wrote:

> > Could you please list the other patches that are being held back by this 
> > one? I'd be interested to have a look at them. :)
>
> We need the target type support for D80222 , 
> D79739  can go in but we need to modify it 
> afterwards.


So this whole thing was about moving Def.s out of `CGOMPRuntime`? Given how low 
priority making the-soon-to-be-deprecated `CGOMPRuntime` use the new Def.s is, 
and that I actually use these stuff as part of the-soon-to-be-the-way-to-CG-OMP 
`OMPBuilder`, wouldn't it have been better to postpone both patches until we 
are done with this one then add anything I didn't have already as part of 
D79739  ? It would have certainly saved 
everyone a lot of time, and made more sense given that the earlier patch came 
out 2 days after mine, and the other patch today? :)

In any case, I addressed everything based on your earlier comments. Thanks for 
reviewing my patches. Let me know if you think other changes are needed here, 
otherwise could you please commit this for me, I still don't have commit access.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79675



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


[PATCH] D80263: [HeaderSearch] Fix processing #import-ed headers multiple times with modules enabled.

2020-05-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: rsmith, bruno, Bigcheese.
Herald added subscribers: ributzka, dexonsmith, jkorous.
Herald added a project: clang.

HeaderSearch was marking requested HeaderFileInfo as Resolved only based on
the presence of ExternalSource. As the result, using any module was enough
to set ExternalSource and headers unknown to this module would have
HeaderFileInfo with empty fields, including `isImport = 0`, `NumIncludes = 0`.
Such HeaderFileInfo was preserved without changes regardless of how the
header was used in other modules and caused incorrect result in
`HeaderSearch::ShouldEnterIncludeFile`.

Fix by marking HeaderFileInfo as Resolved only if ExternalSource knows
about this header.

rdar://problem/62126911


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80263

Files:
  clang/lib/Lex/HeaderSearch.cpp
  
clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
  
clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
  
clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
  clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h
  
clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
  clang/test/Modules/import-once.m

Index: clang/test/Modules/import-once.m
===
--- /dev/null
+++ clang/test/Modules/import-once.m
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodule-name=ImportOnce -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-once %s
+
+// Test #import-ed headers are processed only once, even without header guards.
+// Dependency graph is
+//
+// Unrelated   ImportOnce
+//   ^  ^^
+//\/ |
+//   IndirectImporter|
+// ^ |
+//  \|
+//   import-once.m
+#import 
+#import 
Index: clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/Unrelated.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module Unrelated {
+umbrella header "Unrelated.h"
+export *
+}
Index: clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/Unrelated.framework/Headers/Unrelated.h
@@ -0,0 +1 @@
+void foo(void);
Index: clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module IndirectImporter {
+umbrella header "IndirectImporter.h"
+export *
+}
Index: clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/IndirectImporter.framework/Headers/IndirectImporter.h
@@ -0,0 +1,2 @@
+#import 
+#import 
Index: clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/ImportOnce.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module ImportOnce {
+  umbrella header "ImportOnce.h"
+  export *
+}
Index: clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-once/ImportOnce.framework/Headers/ImportOnce.h
@@ -0,0 +1,5 @@
+// No header guards on purpose.
+
+enum SomeSimpleEnum {
+SomeSimpleEnumCase,
+};
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1167,12 +1167,12 @@
   HeaderFileInfo *HFI = &FileInfo[FE->getUID()];
   // FIXME: Use a generation count to check whether this is really up to date.
   if (ExternalSource && !HFI->Resolved) {
-HFI->Resolved = true;
 auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE);
-
-HFI = &FileInfo[FE->getUID()];
-if (ExternalHFI.External)
-  mergeHeaderFileInfo(*HFI, ExternalHFI);
+if (ExternalHFI.IsValid) {
+  HFI->Resolved = true;
+  if (ExternalHFI.External)
+mergeHeaderFileInfo(*HFI, ExternalHFI);
+}
   }
 
   HFI->IsValid = true;
@@ -1199,12 +1199,12 @@
 if (!WantExternal && (!HFI->IsValid || H

[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread Xiang Zhang via Phabricator via cfe-commits
xiangzhangllvm added a comment.

Hello rsmith, 
first, very sorry for have committed this patch before your reply, I waited 10 
days, I thought you have agreed it. 
I think the  linux-ABI can be the specification of this head file. The context 
of this cet.h is according to the linux ABI about CET.
We explained in which case we should use this cet.h file. (line 2-4)
tks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79617



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


[PATCH] D79617: Add cet.h for writing CET-enabled assembly code

2020-05-19 Thread H.J Lu via Phabricator via cfe-commits
hjl.tools added a comment.

In D79617#2045552 , @rsmith wrote:

> I would like a specification for this header to be added somewhere. We 
> shouldn't be implementing random things with no specification. (Suppose 
> someone claims that our `` is wrong in some way. How would we know 
> whether they're right?)
>
> Ideally, I'd also like this header to be installed somewhere where we look 
> for assembler-with-cpp preprocessing but not for regular compilation; it 
> doesn't make sense to me to pollute the header namespace for all C and C++ 
> compilations with a header that is not meaningful in C and C++. But knowing 
> whether that change is correct depends on having, you know, a specification.


 from GCC is as close as you can get for a reference 
implementation/specification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79617



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


[PATCH] D79903: FastMathFlags.allowContract should be init from FPFeatures.allowFPContractAcrossStatement

2020-05-19 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

No, go ahead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79903



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


[PATCH] D79675: [OpenMP][OMPBuilder] Adding Privatization Requirements to OMPIRBuilder

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

In D79675#2045563 , @fghanim wrote:

> In D79675#2045405 , @jdoerfert wrote:
>
> > > Could you please list the other patches that are being held back by this 
> > > one? I'd be interested to have a look at them. :)
> >
> > We need the target type support for D80222 
> > , D79739  
> > can go in but we need to modify it afterwards.
>
>
> So this whole thing was about moving Def.s out of `CGOMPRuntime`? Given how 
> low priority making the-soon-to-be-deprecated `CGOMPRuntime` use the new 
> Def.s is, and that I actually use these stuff as part of 
> the-soon-to-be-the-way-to-CG-OMP `OMPBuilder`, wouldn't it have been better 
> to postpone both patches until we are done with this one then add anything I 
> didn't have already as part of D79739  ? It 
> would have certainly saved everyone a lot of time, and made more sense given 
> that the earlier patch came out 2 days after mine, and the other patch today? 
> :)




1. Soon is relative.
2. In the meantime people work on clang and add runtime functions into the 
CGOMPRuntime but not into OMPKinds.def. We are playing catch up all the time, 
thus wasting time.
3. I said it before, please split them up in small pieces. It does really not 
help if we combine unrelated things in a single patch. It doesn't make it 
faster and it is not less work at the end of the day.

> In any case, I addressed everything based on your earlier comments. Thanks 
> for reviewing my patches. Let me know if you think other changes are needed 
> here, otherwise could you please commit this for me, I still don't have 
> commit access.

Thanks. Comments added.




Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:62
+
+  /// Set Insert point to Instruction /p IPII
+  void setInsertPoint(Instruction *IPII) { Builder.SetInsertPoint(IPII); }

Nit: \p not /p (Or does both work?)



Comment at: llvm/lib/Frontend/OpenMP/OMPConstants.cpp:86
+  llvm::omp::types::Int8PtrPtr = Int8Ptr->getPointerTo();
+  llvm::omp::types::Int8PtrPtrPtr = Int8PtrPtr->getPointerTo();
+

I think the macro way to specify pointer is easier to use.



Comment at: llvm/lib/Frontend/OpenMP/OMPConstants.cpp:109
+  llvm::omp::types::SizeTy = (SizeTy) ? SizeTy : Int32;
+}
+

I guess we don't need anymore.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:104
+  initializeSizeTy(SizeTy);
+}
 

Probably won't need these either.



Comment at: llvm/lib/Transforms/IPO/OpenMPOpt.cpp:61
 initializeRuntimeFunctions();
-OMPBuilder.initialize();
+OMPBuilder.initialize(Type::getInt32Ty(M.getContext()));
   }

Is size_t always 32 bit? I think you can use the datalayout from the module via 
`getIntPtrType`.



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:65
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.initialize();
+  OMPBuilder.initialize(Type::getInt32Ty(M->getContext()));
 

Same as above, also below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79675



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


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

2020-05-19 Thread Michael Schellenberger Costa via Phabricator via cfe-commits
miscco added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2314
+  nextToken();
+  if (FormatTok->Tok.is(tok::less)) {
+while (!FormatTok->Tok.is(tok::greater)) {

miscco wrote:
> I guess you could use `parseBracedList(/*ContinueOnSemicolons=*/false, 
> /*IsEnum=*/false,/*ClosingBraceKind=*/tok::greater);` here?
To be more specific, I am concerned what happens if you have multiple template 
arguments where a linebreak should occur. Is this still happening here?


```
template 
concept someVeryLongConceptName = someVeryLongConstraintName1;
```



Comment at: clang/unittests/Format/FormatTest.cpp:16319
+  verifyFormat("template \n"
+   "concept bool EqualityComparable = requires(T a, T b) {\n"
+   "  { a == b } -> bool;\n"

I think `concept bool` should just be `concept` occurs below 


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

https://reviews.llvm.org/D79773



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


[PATCH] D69987: [RISCV] Assemble/Disassemble v-ext instructions.

2020-05-19 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

Is this patch ready to land? Are there any comments or suggestions I missed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69987



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


[clang] e71c537 - [clang-format] Fix line lengths w/ comments in align

2020-05-19 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-05-20T07:22:01+01:00
New Revision: e71c537a487cacaa00265e1acb765235943d5172

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

LOG: [clang-format] Fix line lengths w/ comments in align

Summary:
https://bugs.llvm.org/show_bug.cgi?id=43845

When a '//comment' trails a consecutive alignment, it adds a whitespace
replacement within the comment token. This wasn't handled correctly in
the alignment code, which treats it as a whole token and thus double
counts it.

This can wrongly trigger the "line too long, it'll wrap" alignment-break
condition with specific lengths, causing the alignment to break for
seemingly no reason.

Patch By:  JakeMerdichAMD

Reviewed By: MyDeveloperDay

Subscribers: kostyakozko, cfe-commits

Tags: #clang, #clang-format

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

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 000141a7a1b0..fd1d74933925 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -445,8 +445,16 @@ static unsigned AlignTokens(const FormatStyle &Style, F 
&&Matches,
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = Changes[i].TokenLength;
-for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a0b1dc7331e1..5eefe99214b2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12010,6 +12010,16 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {



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


[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe71c537a487c: [clang-format] Fix line lengths w/ comments in 
align (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79465

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12010,6 +12010,16 @@
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -445,8 +445,16 @@
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = Changes[i].TokenLength;
-for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12010,6 +12010,16 @@
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -445,8 +445,16 @@
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = Changes[i].TokenLength;
-for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b99bf0e - [clang-format][PR45816] Add AlignConsecutiveBitFields

2020-05-19 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-05-20T07:42:58+01:00
New Revision: b99bf0e08be4faa4527709541dfdc29240e0c75c

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

LOG: [clang-format][PR45816] Add AlignConsecutiveBitFields

Summary:
The following revision follows D80115 since @MyDeveloperDay and I apparently 
both had the same idea at the same time, for 
https://bugs.llvm.org/show_bug.cgi?id=45816 and my efforts on tooling support 
for AMDVLK, respectively.

This option aligns adjacent bitfield separators across lines, in a manner 
similar to AlignConsecutiveAssignments and friends.

Example:
```
struct RawFloat {
  uint32_t sign : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};
```
would become
```
struct RawFloat {
  uint32_t sign : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};
```

This also handles c++2a style bitfield-initializers with 
AlignConsecutiveAssignments.
```
struct RawFloat {
  uint32_t sign : 1  = 0;
  uint32_t exponent : 8  = 127;
  uint32_t mantissa : 23 = 0;
}; // defaults to 1.0f
```

Things this change does not do:
 - Align multiple comma-chained bitfield variables. None of the other
   AlignConsecutive* options seem to implement that either.
 - Detect bitfields that have a width specified with something other
   than a numeric literal (ie, `int a : SOME_MACRO;`). That'd be fairly
   difficult to parse and is rare.

Patch By:  JakeMerdichAMD

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang, #clang-format

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

Added: 


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

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index e367c3620e16..c4d6c1d50d13 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -204,6 +204,18 @@ the configuration (without a prefix: ``Auto``).
 int b= 23;
 int ccc  = 23;
 
+**AlignConsecutiveBitFields** (``bool``)
+  If ``true``, aligns consecutive bitfield members.
+
+  This will align the bitfield separators of consecutive lines. This
+  will result in formattings like
+
+  .. code-block:: c++
+
+int  : 1;
+int b: 12;
+int ccc  : 8;
+
 **AlignConsecutiveDeclarations** (``bool``)
   If ``true``, aligns consecutive declarations.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8dd22887a195..06b01420ca4e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -297,6 +297,21 @@ clang-format
   bar();
 });
 
+- Option ``AlignConsecutiveBitFields`` has been added to align bit field
+  declarations across multiple adjacent lines
+
+  .. code-block:: c++
+
+  true:
+bool aaa  : 1;
+bool a: 1;
+bool bb   : 1;
+
+  false:
+bool aaa : 1;
+bool a : 1;
+bool bb : 1;
+
 libclang
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
old mode 100644
new mode 100755
index 9bc08a775647..7083a46b5b14
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -108,6 +108,17 @@ struct FormatStyle {
   /// \endcode
   bool AlignConsecutiveAssignments;
 
+  /// If ``true``, aligns consecutive bitfield members.
+  ///
+  /// This will align the bitfield separators of consecutive lines. This
+  /// will result in formattings like
+  /// \code
+  ///   int  : 1;
+  ///   int b: 12;
+  ///   int ccc  : 8;
+  /// \endcode
+  bool AlignConsecutiveBitFields;
+
   /// If ``true``, aligns consecutive declarations.
   ///
   /// This will align the declaration names of consecutive lines. This
@@ -2011,8 +2022,8 @@ struct FormatStyle {
 /// \endcode
 SBPO_ControlStatements,
 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
-/// ForEach macros. This is useful in projects where ForEach macros are 
-/// treated as function calls instead of control statements. 
+/// ForEach macros. This is useful in projects where ForEach macros are
+/// treated as function calls instead of control statements.
 /// \code
 ///void f() {
 ///  Q_FOREACH(...) {
@@ -2218,6 +2229,7 @@ struct FormatStyle {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
+   AlignConsecutiveBitFi

[clang] cc918e9 - [clang-format] [PR33890] Add support for Microsoft C++/CLI non standard for each looping extension

2020-05-19 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-05-20T07:44:36+01:00
New Revision: cc918e90c048c6c9a59ed08e7b2a2f92b4ac8140

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

LOG: [clang-format] [PR33890] Add support for Microsoft C++/CLI non standard 
for each looping extension

Summary:
https://bugs.llvm.org/show_bug.cgi?id=33890

This revision allow the microsoft `for each( in ...` nonstandard C++ 
extension which can be used in C++/CLI to be handled as a ForEach macro.

This prevents the breaking between the for and each onto a new line

Reviewed By: JakeMerdichAMD

Subscribers: cfe-commits

Tags: #clang, #clang-format

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 249d3ac39c3e..b6cbebdcbe7f 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -74,6 +74,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
 return;
   if (tryMergeLessLess())
 return;
+  if (tryMergeForEach())
+return;
 
   if (Style.isCSharp()) {
 if (tryMergeCSharpKeywordVariables())
@@ -359,6 +361,28 @@ bool FormatTokenLexer::tryTransformCSharpForEach() {
   return true;
 }
 
+bool FormatTokenLexer::tryMergeForEach() {
+  if (Tokens.size() < 2)
+return false;
+  auto &For = *(Tokens.end() - 2);
+  auto &Each = *(Tokens.end() - 1);
+  if (!For->is(tok::kw_for))
+return false;
+  if (!Each->is(tok::identifier))
+return false;
+  if (Each->TokenText != "each")
+return false;
+
+  For->setType(TT_ForEachMacro);
+  For->Tok.setKind(tok::kw_for);
+
+  For->TokenText = StringRef(For->TokenText.begin(),
+ Each->TokenText.end() - For->TokenText.begin());
+  For->ColumnWidth += Each->ColumnWidth;
+  Tokens.erase(Tokens.end() - 1);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeLessLess() {
   // Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
   if (Tokens.size() < 3)

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 192e26a10d4a..be11020270a3 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -55,6 +55,7 @@ class FormatTokenLexer {
   bool tryMergeCSharpDoubleQuestion();
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
+  bool tryMergeForEach();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 9f1b88bf6a6f..dada02e5841c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -994,6 +994,9 @@ TEST_F(FormatTest, ForEachLoops) {
"#define Q_FOREACH (x, y)\n"
"#define BOOST_FOREACH (x, y)\n"
"#define UNKNOWN_FOREACH (x, y)\n");
+
+  // handle microsoft non standard extension
+  verifyFormat("for each (char c in x->MyStringProperty)");
 }
 
 TEST_F(FormatTest, FormatsWhileLoop) {



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


[clang] 807ab2c - [clang-format] [PR42164] Add Option to Break before While

2020-05-19 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-05-20T07:48:45+01:00
New Revision: 807ab2cd0db398c420ca5b8a7fc260aaea5051a1

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

LOG: [clang-format] [PR42164] Add Option to Break before While

Summary:
Its currently not possible to recreate the GNU style using the 
`BreakBeforeBraces: Custom` style due to a lack of missing `BeforeWhile` in the 
`BraceWrappingFlags`

The following request was raised to add `BeforeWhile` in a `do..while` context 
like `BeforeElse` and `BeforeCatch` to give greater control over the 
positioning of the `while`

https://bugs.llvm.org/show_bug.cgi?id=42164

Reviewers: krasimir, mitchell-stellar, sammccall

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

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

Added: 


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

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index c4d6c1d50d13..e5a5fd154849 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1025,6 +1025,21 @@ the configuration (without a prefix: ``Auto``).
 bar();
   });
 
+  * ``bool BeforeWhile`` Wrap before ``while``.
+
+.. code-block:: c++
+
+  true:
+  do {
+foo();
+  }
+  while (1);
+
+  false:
+  do {
+foo();
+  } while (1);
+
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
   * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06b01420ca4e..48c1c9ea019d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -312,6 +312,27 @@ clang-format
 bool a : 1;
 bool bb : 1;
 
+- Option ``BraceWrapping.BeforeWhile`` has been added to allow wrapping
+  before the ```while`` in a do..while loop. By default the value is 
(``false``)
+
+  In previous releases ``IndentBraces`` implied ``BraceWrapping.BeforeWhile``.
+  If using a Custom BraceWrapping style you may need to now set 
+  ``BraceWrapping.BeforeWhile`` to (``true``) to be explicit.
+
+  .. code-block:: c++
+
+  true:
+  do {
+foo();
+  }
+  while(1);
+
+  false:
+  do {
+foo();
+  } while(1);
+
+
 libclang
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7083a46b5b14..05a9cd2d418d 100755
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1076,6 +1076,20 @@ struct FormatStyle {
 ///   });
 /// \endcode
 bool BeforeLambdaBody;
+/// Wrap before ``while``.
+/// \code
+///   true:
+///   do {
+/// foo();
+///   }
+///   while (1);
+///
+///   false:
+///   do {
+/// foo();
+///   } while (1);
+/// \endcode
+bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
 /// If ``false``, empty function body can be put on a single line.

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 418ace7376ff..79e9f35de707 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -604,6 +604,7 @@ template <> struct 
MappingTraits {
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("BeforeLambdaBody", Wrapping.BeforeLambdaBody);
+IO.mapOptional("BeforeWhile", Wrapping.BeforeWhile);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
 IO.mapOptional("SplitEmptyFunction", Wrapping.SplitEmptyFunction);
 IO.mapOptional("SplitEmptyRecord", Wrapping.SplitEmptyRecord);
@@ -687,12 +688,24 @@ static FormatStyle expandPresets(const FormatStyle 
&Style) {
   if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
 return Style;
   FormatStyle Expanded = Style;
-  Expanded.BraceWrapping = {false, false, FormatStyle::BWACS_Never,
-false, false, false,
-false, false, false,
-false, false, false,
-false, false, true,
-true,  true};
+  Expanded.BraceWrapping = {/*AfterCaseLabel=*/false,
+/*AfterClass=*/false,
+/*AfterControlStatement=*/FormatStyle::BWACS_Never,
+/*AfterEnum=*/false,
+/*AfterFu

[PATCH] D80237: [hip] Ensure pointer in struct argument has proper `addrspacecast`.

2020-05-19 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 265148.
hliao added a comment.

Revise following comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80237

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu

Index: clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
===
--- clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
+++ clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
@@ -1,37 +1,52 @@
-// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm -x hip %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm -x hip %s -o - | FileCheck --check-prefixes=COMMON,CHECK %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm -x hip %s -disable-O0-optnone -o - | opt -S -O2 | FileCheck %s --check-prefixes=COMMON,OPT
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -x hip %s -o - | FileCheck -check-prefix=HOST %s
 
 #include "Inputs/cuda.h"
 
 // Coerced struct from `struct S` without all generic pointers lowered into
 // global ones.
-// CHECK: %struct.S.coerce = type { i32 addrspace(1)*, float addrspace(1)* }
-// CHECK: %struct.T.coerce = type { [2 x float addrspace(1)*] }
+// COMMON: %struct.S.coerce = type { i32 addrspace(1)*, float addrspace(1)* }
+// COMMON: %struct.T.coerce = type { [2 x float addrspace(1)*] }
 
 // On the host-side compilation, generic pointer won't be coerced.
 // HOST-NOT: %struct.S.coerce
 // HOST-NOT: %struct.T.coerce
 
-// CHECK: define amdgpu_kernel void  @_Z7kernel1Pi(i32 addrspace(1)* %x.coerce)
 // HOST: define void @_Z22__device_stub__kernel1Pi(i32* %x)
+// COMMON-LABEL: define amdgpu_kernel void @_Z7kernel1Pi(i32 addrspace(1)*{{.*}} %x.coerce)
+// CHECK: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// OPT-NOT: alloca
+// OPT-NOT: inttoptr
 __global__ void kernel1(int *x) {
   x[0]++;
 }
 
-// CHECK: define amdgpu_kernel void  @_Z7kernel2Ri(i32 addrspace(1)* nonnull align 4 dereferenceable(4) %x.coerce)
 // HOST: define void @_Z22__device_stub__kernel2Ri(i32* nonnull align 4 dereferenceable(4) %x)
+// COMMON-LABEL: define amdgpu_kernel void @_Z7kernel2Ri(i32 addrspace(1)*{{.*}} nonnull align 4 dereferenceable(4) %x.coerce)
+// CHECK: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// OPT-NOT: alloca
+// OPT-NOT: ptrtoint
+// OPT-NOT: inttoptr
 __global__ void kernel2(int &x) {
   x++;
 }
 
-// CHECK: define amdgpu_kernel void  @_Z7kernel3PU3AS2iPU3AS1i(i32 addrspace(2)* %x, i32 addrspace(1)* %y)
 // HOST: define void @_Z22__device_stub__kernel3PU3AS2iPU3AS1i(i32 addrspace(2)* %x, i32 addrspace(1)* %y)
+// CHECK-LABEL: define amdgpu_kernel void  @_Z7kernel3PU3AS2iPU3AS1i(i32 addrspace(2)*{{.*}} %x, i32 addrspace(1)*{{.*}} %y)
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
 __global__ void kernel3(__attribute__((address_space(2))) int *x,
 __attribute__((address_space(1))) int *y) {
   y[0] = x[0];
 }
 
-// CHECK: define void @_Z4funcPi(i32* %x)
+// COMMON-LABEL: define void @_Z4funcPi(i32*{{.*}} %x)
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// OPT-NOT: alloca
+// OPT-NOT: ptrtoint
+// OPT-NOT: inttoptr
 __device__ void func(int *x) {
   x[0]++;
 }
@@ -42,16 +57,26 @@
 };
 // `by-val` struct will be coerced into a similar struct with all generic
 // pointers lowerd into global ones.
-// CHECK: define amdgpu_kernel void @_Z7kernel41S(%struct.S.coerce %s.coerce)
 // HOST: define void @_Z22__device_stub__kernel41S(i32* %s.coerce0, float* %s.coerce1)
+// COMMON-LABEL: define amdgpu_kernel void @_Z7kernel41S(%struct.S.coerce %s.coerce)
+// CHECK-COUNT-2: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// OPT-NOT: alloca
+// OPT-NOT: ptrtoint
+// OPT-NOT: inttoptr
 __global__ void kernel4(struct S s) {
   s.x[0]++;
   s.y[0] += 1.f;
 }
 
 // If a pointer to struct is passed, only the pointer itself is coerced into the global one.
-// CHECK: define amdgpu_kernel void @_Z7kernel5P1S(%struct.S addrspace(1)* %s.coerce)
 // HOST: define void @_Z22__device_stub__kernel5P1S(%struct.S* %s)
+// COMMON-LABEL: define amdgpu_kernel void @_Z7kernel5P1S(%struct.S addrspace(1)*{{.*}} %s.coerce)
+// CHECK: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// CHECK-NOT: = addrspacecast [[TYPE:.*]] addrspace(1)* %{{.*}} to [[TYPE]]*
+// OPT-NOT: alloca
+// OPT-NOT: ptrtoint
+// OPT-NOT: inttoptr
 __global__ void kernel5(struct S *s) {
   s->x[0]++;
   s->y[0] += 1.f;
@@ -61,16 +86,26 @@
   float *x[2];
 };
 // `

[PATCH] D79325: [clang-format] [PR42164] Add Option to Break before While

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG807ab2cd0db3: [clang-format] [PR42164] Add Option to Break 
before While (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D79325?vs=264235&id=265153#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79325

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1706,6 +1706,22 @@
 format("try{foo();}catch(...){baz();}", Style));
 }
 
+TEST_F(FormatTest, BeforeWhile) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Custom;
+
+  verifyFormat("do {\n"
+   "  foo();\n"
+   "} while (1);",
+   Style);
+  Style.BraceWrapping.BeforeWhile = true;
+  verifyFormat("do {\n"
+   "  foo();\n"
+   "}\n"
+   "while (1);",
+   Style);
+}
+
 //===--===//
 // Tests for classes, namespaces, etc.
 //===--===//
@@ -13543,6 +13559,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeWhile);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2175,7 +2175,7 @@
   if (FormatTok->Tok.is(tok::l_brace)) {
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false);
-if (Style.BraceWrapping.IndentBraces)
+if (Style.BraceWrapping.BeforeWhile)
   addUnwrappedLine();
   } else {
 addUnwrappedLine();
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -604,6 +604,7 @@
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("BeforeLambdaBody", Wrapping.BeforeLambdaBody);
+IO.mapOptional("BeforeWhile", Wrapping.BeforeWhile);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
 IO.mapOptional("SplitEmptyFunction", Wrapping.SplitEmptyFunction);
 IO.mapOptional("SplitEmptyRecord", Wrapping.SplitEmptyRecord);
@@ -687,12 +688,24 @@
   if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
 return Style;
   FormatStyle Expanded = Style;
-  Expanded.BraceWrapping = {false, false, FormatStyle::BWACS_Never,
-false, false, false,
-false, false, false,
-false, false, false,
-false, false, true,
-true,  true};
+  Expanded.BraceWrapping = {/*AfterCaseLabel=*/false,
+/*AfterClass=*/false,
+/*AfterControlStatement=*/FormatStyle::BWACS_Never,
+/*AfterEnum=*/false,
+/*AfterFunction=*/false,
+/*AfterNamespace=*/false,
+/*AfterObjCDeclaration=*/false,
+/*AfterStruct=*/false,
+/*AfterUnion=*/false,
+/*AfterExternBlock=*/false,
+/*BeforeCatch=*/false,
+/*BeforeElse=*/false,
+/*BeforeLambdaBody=*/false,
+/*BeforeWhile=*/false,
+/*IndentBraces=*/false,
+/*SplitEmptyFunction=*/true,
+/*SplitEmptyRecord=*/true,
+/*SplitEmptyNamespace=*/true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -743,12 +756,25 @@
 Expanded.BraceWrapping.BeforeLambdaBody = true;
 break;
   case FormatStyle::BS_GNU:
-Expanded.BraceWrapping = {true,  true, FormatStyle::BWACS_Always,
-  true,  true, true,
-   

[PATCH] D80176: [clang-format][PR45816] Add AlignConsecutiveBitFields

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb99bf0e08be4: [clang-format][PR45816] Add 
AlignConsecutiveBitFields (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D80176?vs=265048&id=265152#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80176

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12022,6 +12022,48 @@
Alignment));
 }
 
+TEST_F(FormatTest, AlignConsecutiveBitFields) {
+  FormatStyle Alignment = getLLVMStyle();
+  Alignment.AlignConsecutiveBitFields = true;
+  verifyFormat("int const a : 5;\n"
+   "int oneTwoThree : 23;",
+   Alignment);
+
+  // Initializers are allowed starting with c++2a
+  verifyFormat("int const a : 5 = 1;\n"
+   "int oneTwoThree : 23 = 0;",
+   Alignment);
+
+  Alignment.AlignConsecutiveDeclarations = true;
+  verifyFormat("int const a   : 5;\n"
+   "int   oneTwoThree : 23;",
+   Alignment);
+
+  verifyFormat("int const a   : 5;  // comment\n"
+   "int   oneTwoThree : 23; // comment",
+   Alignment);
+
+  verifyFormat("int const a   : 5 = 1;\n"
+   "int   oneTwoThree : 23 = 0;",
+   Alignment);
+
+  Alignment.AlignConsecutiveAssignments = true;
+  verifyFormat("int const a   : 5  = 1;\n"
+   "int   oneTwoThree : 23 = 0;",
+   Alignment);
+  verifyFormat("int const a   : 5  = {1};\n"
+   "int   oneTwoThree : 23 = 0;",
+   Alignment);
+
+  // Known limitations: ':' is only recognized as a bitfield colon when
+  // followed by a number.
+  /*
+  verifyFormat("int oneTwoThree : SOME_CONSTANT;\n"
+   "int a   : 5;",
+   Alignment);
+  */
+}
+
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
   FormatStyle Alignment = getLLVMStyle();
   Alignment.AlignConsecutiveMacros = true;
@@ -13436,6 +13478,7 @@
   Style.Language = FormatStyle::LK_Cpp;
   CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AlignConsecutiveAssignments);
+  CHECK_PARSE_BOOL(AlignConsecutiveBitFields);
   CHECK_PARSE_BOOL(AlignConsecutiveDeclarations);
   CHECK_PARSE_BOOL(AlignConsecutiveMacros);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
Index: clang/lib/Format/WhitespaceManager.h
===
--- clang/lib/Format/WhitespaceManager.h
+++ clang/lib/Format/WhitespaceManager.h
@@ -184,6 +184,9 @@
   /// Align consecutive assignments over all \c Changes.
   void alignConsecutiveAssignments();
 
+  /// Align consecutive bitfields over all \c Changes.
+  void alignConsecutiveBitFields();
+
   /// Align consecutive declarations over all \c Changes.
   void alignConsecutiveDeclarations();
 
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -95,6 +95,7 @@
   calculateLineBreakInformation();
   alignConsecutiveMacros();
   alignConsecutiveDeclarations();
+  alignConsecutiveBitFields();
   alignConsecutiveAssignments();
   alignChainedConditionals();
   alignTrailingComments();
@@ -617,6 +618,26 @@
   Changes, /*StartAt=*/0);
 }
 
+void WhitespaceManager::alignConsecutiveBitFields() {
+  if (!Style.AlignConsecutiveBitFields)
+return;
+
+  AlignTokens(
+  Style,
+  [&](Change const &C) {
+// Do not align on ':' that is first on a line.
+if (C.NewlinesBefore > 0)
+  return false;
+
+// Do not align on ':' that is last on a line.
+if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
+  return false;
+
+return C.Tok->is(TT_BitFieldColon);
+  },
+  Changes, /*StartAt=*/0);
+}
+
 void WhitespaceManager::alignConsecutiveDeclarations() {
   if (!Style.AlignConsecutiveDeclarations)
 return;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -403,6 +403,8 @@
 IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
 IO.mapOptional("AlignConsecutiveAssignments",
Style.AlignConsecutiveAssignments);
+IO.mapOptional("AlignConsecutiveBitFields",
+   Style.AlignConsecutiveBitFields);

[PATCH] D80228: [clang-format] [PR33890] Add support for Microsoft C++/CLI non standard for each looping extension

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc918e90c048: [clang-format] [PR33890] Add support for 
Microsoft C++/CLI non standard for… (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80228

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -994,6 +994,9 @@
"#define Q_FOREACH (x, y)\n"
"#define BOOST_FOREACH (x, y)\n"
"#define UNKNOWN_FOREACH (x, y)\n");
+
+  // handle microsoft non standard extension
+  verifyFormat("for each (char c in x->MyStringProperty)");
 }
 
 TEST_F(FormatTest, FormatsWhileLoop) {
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -55,6 +55,7 @@
   bool tryMergeCSharpDoubleQuestion();
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
+  bool tryMergeForEach();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -74,6 +74,8 @@
 return;
   if (tryMergeLessLess())
 return;
+  if (tryMergeForEach())
+return;
 
   if (Style.isCSharp()) {
 if (tryMergeCSharpKeywordVariables())
@@ -359,6 +361,28 @@
   return true;
 }
 
+bool FormatTokenLexer::tryMergeForEach() {
+  if (Tokens.size() < 2)
+return false;
+  auto &For = *(Tokens.end() - 2);
+  auto &Each = *(Tokens.end() - 1);
+  if (!For->is(tok::kw_for))
+return false;
+  if (!Each->is(tok::identifier))
+return false;
+  if (Each->TokenText != "each")
+return false;
+
+  For->setType(TT_ForEachMacro);
+  For->Tok.setKind(tok::kw_for);
+
+  For->TokenText = StringRef(For->TokenText.begin(),
+ Each->TokenText.end() - For->TokenText.begin());
+  For->ColumnWidth += Each->ColumnWidth;
+  Tokens.erase(Tokens.end() - 1);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeLessLess() {
   // Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
   if (Tokens.size() < 3)


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -994,6 +994,9 @@
"#define Q_FOREACH (x, y)\n"
"#define BOOST_FOREACH (x, y)\n"
"#define UNKNOWN_FOREACH (x, y)\n");
+
+  // handle microsoft non standard extension
+  verifyFormat("for each (char c in x->MyStringProperty)");
 }
 
 TEST_F(FormatTest, FormatsWhileLoop) {
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -55,6 +55,7 @@
   bool tryMergeCSharpDoubleQuestion();
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
+  bool tryMergeForEach();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -74,6 +74,8 @@
 return;
   if (tryMergeLessLess())
 return;
+  if (tryMergeForEach())
+return;
 
   if (Style.isCSharp()) {
 if (tryMergeCSharpKeywordVariables())
@@ -359,6 +361,28 @@
   return true;
 }
 
+bool FormatTokenLexer::tryMergeForEach() {
+  if (Tokens.size() < 2)
+return false;
+  auto &For = *(Tokens.end() - 2);
+  auto &Each = *(Tokens.end() - 1);
+  if (!For->is(tok::kw_for))
+return false;
+  if (!Each->is(tok::identifier))
+return false;
+  if (Each->TokenText != "each")
+return false;
+
+  For->setType(TT_ForEachMacro);
+  For->Tok.setKind(tok::kw_for);
+
+  For->TokenText = StringRef(For->TokenText.begin(),
+ Each->TokenText.end() - For->TokenText.begin());
+  For->ColumnWidth += Each->ColumnWidth;
+  Tokens.erase(Tokens.end() - 1);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeLessLess() {
   // Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
   if (Tokens.size() < 3)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4c09289 - [clang] Add an API to retrieve implicit constructor arguments.

2020-05-19 Thread Dmitri Gribenko via cfe-commits

Author: Martin Böhme
Date: 2020-05-19T09:21:26+02:00
New Revision: 4c09289f635c4291c41fe4396afba4ba839d265b

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

LOG: [clang] Add an API to retrieve implicit constructor arguments.

Summary:
This is needed in Swift for C++ interop -- see here for the corresponding Swift 
change:

https://github.com/apple/swift/pull/30630

As part of this change, I've had to make some changes to the interface of 
CGCXXABI to return the additional parameters separately rather than adding them 
directly to a `CallArgList`.

Reviewers: rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/CodeGen/CodeGenABITypes.h
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CodeGenABITypes.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/CodeGenABITypes.h 
b/clang/include/clang/CodeGen/CodeGenABITypes.h
index 255e1603509e..0201f92074ec 100644
--- a/clang/include/clang/CodeGen/CodeGenABITypes.h
+++ b/clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -39,6 +39,7 @@ class Type;
 
 namespace clang {
 class ASTContext;
+class CXXConstructorDecl;
 class CXXRecordDecl;
 class CXXMethodDecl;
 class CodeGenOptions;
@@ -53,6 +54,16 @@ namespace CodeGen {
 class CGFunctionInfo;
 class CodeGenModule;
 
+/// Additional implicit arguments to add to a constructor argument list.
+struct ImplicitCXXConstructorArgs {
+  /// Implicit arguments to add before the explicit arguments, but after the
+  /// `*this` argument (which always comes first).
+  SmallVector Prefix;
+
+  /// Implicit arguments to add after the explicit arguments.
+  SmallVector Suffix;
+};
+
 const CGFunctionInfo &arrangeObjCMessageSendSignature(CodeGenModule &CGM,
   const ObjCMethodDecl *MD,
   QualType receiverType);
@@ -74,6 +85,11 @@ const CGFunctionInfo &arrangeFreeFunctionCall(CodeGenModule 
&CGM,
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+/// Returns the implicit arguments to add to a complete, non-delegating C++
+/// constructor call.
+ImplicitCXXConstructorArgs
+getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D);
+
 /// Returns null if the function type is incomplete and can't be lowered.
 llvm::FunctionType *convertFreeFunctionType(CodeGenModule &CGM,
 const FunctionDecl *FD);

diff  --git a/clang/lib/CodeGen/CGCXXABI.cpp b/clang/lib/CodeGen/CGCXXABI.cpp
index 7ada4032b3ee..928fbaea8278 100644
--- a/clang/lib/CodeGen/CGCXXABI.cpp
+++ b/clang/lib/CodeGen/CGCXXABI.cpp
@@ -313,3 +313,20 @@ CatchTypeInfo CGCXXABI::getCatchAllTypeInfo() {
 std::vector CGCXXABI::getVBPtrOffsets(const CXXRecordDecl *RD) {
   return std::vector();
 }
+
+CGCXXABI::AddedStructorArgCounts CGCXXABI::addImplicitConstructorArgs(
+CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type,
+bool ForVirtualBase, bool Delegating, CallArgList &Args) {
+  AddedStructorArgs AddedArgs =
+  getImplicitConstructorArgs(CGF, D, Type, ForVirtualBase, Delegating);
+  for (size_t i = 0; i < AddedArgs.Prefix.size(); ++i) {
+Args.insert(Args.begin() + 1 + i,
+CallArg(RValue::get(AddedArgs.Prefix[i].Value),
+AddedArgs.Prefix[i].Type));
+  }
+  for (const auto &arg : AddedArgs.Suffix) {
+Args.add(RValue::get(arg.Value), arg.Type);
+  }
+  return AddedStructorArgCounts(AddedArgs.Prefix.size(),
+AddedArgs.Suffix.size());
+}

diff  --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index bff49be7a3c4..f5f378510950 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ -16,6 +16,7 @@
 
 #include "CodeGenFunction.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 
 namespace llvm {
 class Constant;
@@ -287,24 +288,44 @@ class CGCXXABI {
   /// Emit constructor variants required by this ABI.
   virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
 
-  /// Notes how many arguments were added to the beginning (Prefix) and ending
-  /// (Suffix) of an arg list.
+  /// Additional implicit arguments to add to the beginning (Prefix) and end
+  /// (Suffix) of a constructor / destructor arg list.
   ///
-  /// Note that Prefix actually refers to the number of args *after* the first
-  /// one: `this` 

[clang] 51bb212 - [Analyzer][VLASizeChecker] Check for VLA size overflow.

2020-05-19 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-05-19T09:44:46+02:00
New Revision: 51bb2128ef03985fddf2a84f17d3276f4ae2c6ad

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

LOG: [Analyzer][VLASizeChecker] Check for VLA size overflow.

Summary:
Variable-length array (VLA) should have a size that fits into
a size_t value. According to the standard: "std::size_t can
store the maximum size of a theoretically possible object of
any type (including array)" (this is applied to C too).

The size expression is evaluated at the definition of the
VLA type even if this is a typedef.
The evaluation of the size expression in itself might cause
problems if it overflows.

Reviewers: Szelethus, baloghadamsoftware, martong, gamesh411

Reviewed By: Szelethus, martong, gamesh411

Subscribers: whisperity, rnkovacs, xazax.hun, baloghadamsoftware, szepet, 
a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, 
martong, ASDenysPetrov, cfe-commits

Tags: #clang

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

Added: 
clang/test/Analysis/vla-overflow.c

Modified: 
clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
index 3bd2520f013a..de487042fb8a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -34,24 +34,24 @@ class VLASizeChecker
 : public Checker,
  check::PreStmt> {
   mutable std::unique_ptr BT;
-  enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative };
+  enum VLASize_Kind {
+VLA_Garbage,
+VLA_Zero,
+VLA_Tainted,
+VLA_Negative,
+VLA_Overflow
+  };
 
   /// Check a VLA for validity.
-  /// Every dimension of the array is checked for validity, and
-  /// dimension sizes are collected into 'VLASizes'. 'VLALast' is set to the
-  /// innermost VLA that was encountered.
-  /// In "int vla[x][2][y][3]" this will be the array for index "y" (with type
-  /// int[3]). 'VLASizes' contains 'x', '2', and 'y'. Returns null or a new
-  /// state where the size is validated for every dimension.
-  ProgramStateRef checkVLA(CheckerContext &C, ProgramStateRef State,
-   const VariableArrayType *VLA,
-   const VariableArrayType *&VLALast,
-   llvm::SmallVector &VLASizes) const;
-
-  /// Check one VLA dimension for validity.
+  /// Every dimension of the array and the total size is checked for validity.
   /// Returns null or a new state where the size is validated.
-  ProgramStateRef checkVLASize(CheckerContext &C, ProgramStateRef State,
-   const Expr *SizeE) const;
+  /// 'ArraySize' will contain SVal that refers to the total size (in char)
+  /// of the array.
+  ProgramStateRef checkVLA(CheckerContext &C, ProgramStateRef State,
+   const VariableArrayType *VLA, SVal &ArraySize) 
const;
+  /// Check a single VLA index size expression for validity.
+  ProgramStateRef checkVLAIndexSize(CheckerContext &C, ProgramStateRef State,
+const Expr *SizeE) const;
 
   void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
  CheckerContext &C,
@@ -64,20 +64,25 @@ class VLASizeChecker
 };
 } // end anonymous namespace
 
-ProgramStateRef
-VLASizeChecker::checkVLA(CheckerContext &C, ProgramStateRef State,
- const VariableArrayType *VLA,
- const VariableArrayType *&VLALast,
- llvm::SmallVector &VLASizes) const {
+ProgramStateRef VLASizeChecker::checkVLA(CheckerContext &C,
+ ProgramStateRef State,
+ const VariableArrayType *VLA,
+ SVal &ArraySize) const {
   assert(VLA && "Function should be called with non-null VLA argument.");
 
-  VLALast = nullptr;
+  const VariableArrayType *VLALast = nullptr;
+  llvm::SmallVector VLASizes;
+
   // Walk over the VLAs for every dimension until a non-VLA is found.
   // There is a VariableArrayType for every dimension (fixed or variable) until
   // the most inner array that is variably modified.
+  // Dimension sizes are collected into 'VLASizes'. 'VLALast' is set to the
+  // innermost VLA that was encountered.
+  // In "int vla[x][2][y][3]" this will be the array for index "y" (with type
+  // int[3]). 'VLASizes' contains 'x', '2', and 'y'.
   while (VLA) {
 const Expr *SizeE = VLA->getSizeExpr();
-State = checkVLASize(C, State, SizeE);
+State = checkVLAIndexSize(C, State, SizeE);
 if (!State)
   ret

[PATCH] D79477: [clang-tidy] Add --use-color command line option and UseColor option to control colors in diagnostics

2020-05-19 Thread hyd-dev via Phabricator via cfe-commits
hyd-dev marked 2 inline comments as done.
hyd-dev added a comment.

Any reply?


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

https://reviews.llvm.org/D79477



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


[PATCH] D79967: Fix debug info for NoDebug attr

2020-05-19 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

This seems reasonable, so this change looks good to me!

@dblaikie Thanks for pointing out to the potential problems of the usage of the 
func decl !dbg in the purpose of call sites debug info. It is currently being 
stored into CU's retainedTypes field.

> That's why DISubprogram moved to be attached to an llvm::Function (previously 
> all DISubprograms were listed on the CU and DISubprograms pointed to 
> llvm::Functions) to aid in LTO

Is it only one patch or a set of patches? I'll try to find these changes in the 
log history.

I am open for the discussion about redesigning it (please wait for a comment 
from @vsk as well). :)


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

https://reviews.llvm.org/D79967



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


[PATCH] D80176: [clang-format][PR45816] Add AlignConsecutiveBitFields

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

The LGTM (nit: clang-format)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80176



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


[PATCH] D80025: [ASTMatcher] Correct memoization bug ignoring direction (descendants or ancestors)

2020-05-19 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:46-49
+enum class MatchDirection {
+  Ancestors,
+  Descendants
+};

loic-joly-sonarsource wrote:
> klimek wrote:
> > Nice find! Why don't we need more states though?
> > 1. wouldn't hasParent() followed by a hasAncestor() also trigger the 
> > memoization? (if so, we'd need transitive / non-transitive)
> > 2. can we trigger a directional match and a non-directional (non-traversal, 
> > for example, explicit) match in the same memoization scope?
> 1. Yes, I'm going to add it
> 2. Sorry, I did not understand what you mean...
> 
Re 2: nevermind, we don't memoize non-transitive matches (other than hasParent 
/ hasChild), right?
In that case, I'm wondering whether the simpler solution is to just not memoize 
hasParent / hasChild - wouldn't that be more in line with the rest of the 
memoization?


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

https://reviews.llvm.org/D80025



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


[PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added subscribers: Abpostelnicu, sylvestre.ledru.
MyDeveloperDay added a comment.

This is totally fine, now I'm just concerned by the choice of defaults, I 
really don't know if we want to change the defaults for all the styles, I don't 
want to break all those people using it

One way might be if we canvas opinion from those developers who work on some of 
those proejcts for example @sylvestre.ledru, @Abpostelnicu   what impact might 
this have on the Mozilla sources (if any?)




Comment at: clang/lib/Format/Format.cpp:714
   case FormatStyle::BS_Mozilla:
+Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping.AfterClass = true;

I'm sorry but I feel these are changing the previous default which as I 
understood would indent ONLY if Style.BraceWrapping.AfterExternBlock == true

I think in all cases other than GNU this was false, isn't that correct?



Comment at: clang/lib/Format/Format.cpp:725
   case FormatStyle::BS_Stroustrup:
+Expanded.IndentExternBlock = FormatStyle::IEBS_NoIndent;
 Expanded.BraceWrapping.AfterFunction = true;

I think you can remove this to avoid confusion that you are changing from the 
default LLVM style



Comment at: clang/lib/Format/Format.cpp:731
   case FormatStyle::BS_Allman:
+Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping.AfterCaseLabel = true;

Isn't this changing the default?



Comment at: clang/lib/Format/Format.cpp:746
   case FormatStyle::BS_Whitesmiths:
+Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping.AfterCaseLabel = true;

Isn't this changing the default?



Comment at: clang/lib/Format/Format.cpp:761
   case FormatStyle::BS_GNU:
+Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock;
 Expanded.BraceWrapping = {true,  true, FormatStyle::BWACS_Always,

Ok this one feel correct.



Comment at: clang/lib/Format/Format.cpp:931
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.IndentExternBlock = FormatStyle::IEBS_NoIndent;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;

everyone inherits from LLVM so no need for this it only makes people think its 
different from the base style



Comment at: clang/lib/Format/Format.cpp:1067
 ChromiumStyle.IndentWidth = 4;
+ChromiumStyle.IndentExternBlock = FormatStyle::IEBS_NoIndent;
 // See styleguide for import groups:

everyone inherits from LLVM so no need for this it only makes people think its 
different from the base style



Comment at: clang/lib/Format/Format.cpp:1117
   MozillaStyle.IndentCaseLabels = true;
+  MozillaStyle.IndentExternBlock = FormatStyle::IEBS_NoIndent;
   MozillaStyle.ObjCSpaceAfterProperty = true;

everyone inherits from LLVM so no need for this it only makes people think its 
different from the base style



Comment at: clang/lib/Format/Format.cpp:1140
   Style.IndentWidth = 4;
+  Style.IndentExternBlock = FormatStyle::IEBS_NoIndent;
   Style.NamespaceIndentation = FormatStyle::NI_Inner;

everyone inherits from LLVM so no need for this it only makes people think its 
different from the base style



Comment at: clang/lib/Format/Format.cpp:1159
   Style.ColumnLimit = 79;
+  Style.IndentExternBlock = FormatStyle::IEBS_NoIndent;
   Style.FixNamespaceComments = false;

everyone inherits from LLVM so no need for this it only makes people think its 
different from the base style



Comment at: clang/lib/Format/Format.cpp:1200
   NoStyle.SortUsingDeclarations = false;
+  NoStyle.IndentExternBlock = FormatStyle::IEBS_NoIndent;
   return NoStyle;

everyone inherits from LLVM so no need for this it only makes people think its 
different from the base style


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

https://reviews.llvm.org/D75791



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


[PATCH] D80160: [Tooling] Drop leading/trailing whitespace from compile_flags.txt lines

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

thanks for remembering this :D




Comment at: clang/test/Tooling/fixed-database.cpp:6
 // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/"
+// RUN: echo '# this is a comment' >> %t/compile_flags.txt
 // -I flag is relative to %t (where compile_flags is), not Src/.

Not sure what this line is about, default comment marker is `\0` for 
`line_itearator` and we don't seem to be changing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80160



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


[PATCH] D79942: [clang] Add an API to retrieve implicit constructor arguments.

2020-05-19 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c09289f635c: [clang] Add an API to retrieve implicit 
constructor arguments. (authored by mboehme, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79942

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGCXXABI.cpp
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CodeGenABITypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp

Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -206,7 +206,7 @@
   // lacks a definition for the destructor, non-base destructors must always
   // delegate to or alias the base destructor.
 
-  AddedStructorArgs
+  AddedStructorArgCounts
   buildStructorSignature(GlobalDecl GD,
  SmallVectorImpl &ArgTys) override;
 
@@ -253,10 +253,11 @@
 
   void EmitInstanceFunctionProlog(CodeGenFunction &CGF) override;
 
-  AddedStructorArgs
-  addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
- CXXCtorType Type, bool ForVirtualBase,
- bool Delegating, CallArgList &Args) override;
+  AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF,
+   const CXXConstructorDecl *D,
+   CXXCtorType Type,
+   bool ForVirtualBase,
+   bool Delegating) override;
 
   void EmitDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *DD,
   CXXDtorType Type, bool ForVirtualBase,
@@ -1261,10 +1262,10 @@
   }
 }
 
-CGCXXABI::AddedStructorArgs
+CGCXXABI::AddedStructorArgCounts
 MicrosoftCXXABI::buildStructorSignature(GlobalDecl GD,
 SmallVectorImpl &ArgTys) {
-  AddedStructorArgs Added;
+  AddedStructorArgCounts Added;
   // TODO: 'for base' flag
   if (isa(GD.getDecl()) &&
   GD.getDtorType() == Dtor_Deleting) {
@@ -1553,9 +1554,9 @@
   }
 }
 
-CGCXXABI::AddedStructorArgs MicrosoftCXXABI::addImplicitConstructorArgs(
+CGCXXABI::AddedStructorArgs MicrosoftCXXABI::getImplicitConstructorArgs(
 CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type,
-bool ForVirtualBase, bool Delegating, CallArgList &Args) {
+bool ForVirtualBase, bool Delegating) {
   assert(Type == Ctor_Complete || Type == Ctor_Base);
 
   // Check if we need a 'most_derived' parameter.
@@ -1570,13 +1571,10 @@
   } else {
 MostDerivedArg = llvm::ConstantInt::get(CGM.Int32Ty, Type == Ctor_Complete);
   }
-  RValue RV = RValue::get(MostDerivedArg);
   if (FPT->isVariadic()) {
-Args.insert(Args.begin() + 1, CallArg(RV, getContext().IntTy));
-return AddedStructorArgs::prefix(1);
+return AddedStructorArgs::prefix({{MostDerivedArg, getContext().IntTy}});
   }
-  Args.add(RV, getContext().IntTy);
-  return AddedStructorArgs::suffix(1);
+  return AddedStructorArgs::suffix({{MostDerivedArg, getContext().IntTy}});
 }
 
 void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
@@ -4009,7 +4007,7 @@
   CGF.EmitCallArgs(Args, FPT, llvm::makeArrayRef(ArgVec), CD, IsCopy ? 1 : 0);
 
   // Insert any ABI-specific implicit constructor arguments.
-  AddedStructorArgs ExtraArgs =
+  AddedStructorArgCounts ExtraArgs =
   addImplicitConstructorArgs(CGF, CD, Ctor_Complete,
  /*ForVirtualBase=*/false,
  /*Delegating=*/false, Args);
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -203,7 +203,7 @@
 
   void EmitCXXConstructors(const CXXConstructorDecl *D) override;
 
-  AddedStructorArgs
+  AddedStructorArgCounts
   buildStructorSignature(GlobalDecl GD,
  SmallVectorImpl &ArgTys) override;
 
@@ -222,10 +222,11 @@
 
   void EmitInstanceFunctionProlog(CodeGenFunction &CGF) override;
 
-  AddedStructorArgs
-  addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
- CXXCtorType Type, bool ForVirtualBase,
- bool Delegating, CallArgList &Args) override;
+  AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF,
+   const CXXConstructorDecl *D,
+   CXXCtorType Type,
+   bool ForVirtualBase,
+   bool Delegating

[PATCH] D79330: [Analyzer][VLASizeChecker] Check for VLA size overflow.

2020-05-19 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51bb2128ef03: [Analyzer][VLASizeChecker] Check for VLA size 
overflow. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79330

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla-overflow.c

Index: clang/test/Analysis/vla-overflow.c
===
--- /dev/null
+++ clang/test/Analysis/vla-overflow.c
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core -verify %s
+
+typedef unsigned long size_t;
+#define BIGINDEX 65536U
+
+size_t check_VLA_overflow_sizeof(unsigned int x) {
+  if (x == BIGINDEX) {
+// We expect here that size_t is a 64 bit value.
+// Size of this array should be the first to overflow.
+size_t s = sizeof(char[x][x][x][x]); // expected-warning{{Declared variable-length array (VLA) has too large size [core.VLASize]}}
+return s;
+  }
+  return 0;
+}
+
+void check_VLA_overflow_typedef() {
+  unsigned int x = BIGINDEX;
+  typedef char VLA[x][x][x][x]; // expected-warning{{Declared variable-length array (VLA) has too large size [core.VLASize]}}
+}
+
+void check_VLA_no_overflow() {
+  unsigned int x = BIGINDEX;
+  typedef char VLA[x][x][x][x - 1];
+  typedef char VLA1[0xu];
+}
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -34,24 +34,24 @@
 : public Checker,
  check::PreStmt> {
   mutable std::unique_ptr BT;
-  enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative };
+  enum VLASize_Kind {
+VLA_Garbage,
+VLA_Zero,
+VLA_Tainted,
+VLA_Negative,
+VLA_Overflow
+  };
 
   /// Check a VLA for validity.
-  /// Every dimension of the array is checked for validity, and
-  /// dimension sizes are collected into 'VLASizes'. 'VLALast' is set to the
-  /// innermost VLA that was encountered.
-  /// In "int vla[x][2][y][3]" this will be the array for index "y" (with type
-  /// int[3]). 'VLASizes' contains 'x', '2', and 'y'. Returns null or a new
-  /// state where the size is validated for every dimension.
-  ProgramStateRef checkVLA(CheckerContext &C, ProgramStateRef State,
-   const VariableArrayType *VLA,
-   const VariableArrayType *&VLALast,
-   llvm::SmallVector &VLASizes) const;
-
-  /// Check one VLA dimension for validity.
+  /// Every dimension of the array and the total size is checked for validity.
   /// Returns null or a new state where the size is validated.
-  ProgramStateRef checkVLASize(CheckerContext &C, ProgramStateRef State,
-   const Expr *SizeE) const;
+  /// 'ArraySize' will contain SVal that refers to the total size (in char)
+  /// of the array.
+  ProgramStateRef checkVLA(CheckerContext &C, ProgramStateRef State,
+   const VariableArrayType *VLA, SVal &ArraySize) const;
+  /// Check a single VLA index size expression for validity.
+  ProgramStateRef checkVLAIndexSize(CheckerContext &C, ProgramStateRef State,
+const Expr *SizeE) const;
 
   void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
  CheckerContext &C,
@@ -64,20 +64,25 @@
 };
 } // end anonymous namespace
 
-ProgramStateRef
-VLASizeChecker::checkVLA(CheckerContext &C, ProgramStateRef State,
- const VariableArrayType *VLA,
- const VariableArrayType *&VLALast,
- llvm::SmallVector &VLASizes) const {
+ProgramStateRef VLASizeChecker::checkVLA(CheckerContext &C,
+ ProgramStateRef State,
+ const VariableArrayType *VLA,
+ SVal &ArraySize) const {
   assert(VLA && "Function should be called with non-null VLA argument.");
 
-  VLALast = nullptr;
+  const VariableArrayType *VLALast = nullptr;
+  llvm::SmallVector VLASizes;
+
   // Walk over the VLAs for every dimension until a non-VLA is found.
   // There is a VariableArrayType for every dimension (fixed or variable) until
   // the most inner array that is variably modified.
+  // Dimension sizes are collected into 'VLASizes'. 'VLALast' is set to the
+  // innermost VLA that was encountered.
+  // In "int vla[x][2][y][3]" this will be the array for index "y" (with type
+  // int[3]). 'VLASizes' contains 'x', '2', and 'y'.
   while (VLA) {
 const Expr *SizeE = VLA->getSizeExpr();
-State = checkVLASize(C, State, SizeE);
+State = checkVLAIndexSize(C, State, SizeE);
 if (!State)
   re

[PATCH] D80144: [clang-format] @lefticus just taught the world how to use [[unlikely]] but we forgot to teach clang-format

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

In D80144#2042926 , @JakeMerdichAMD 
wrote:

> This is a great improvement in readability. I think this will get in here 
> before it does for clang proper :D
>
> Likely/unlikely also seem to be supported on while, do-while, and for loops 
> (case statements too, but that's not relevant). Should we also apply 
> identical logic there? Far less useful/common than plain if's so it's not a 
> blocker, but it's best to be consistent and I can imagine some decent use 
> cases.


I struggled to find decent examples, cppreference.org and the standard is very 
think on the ground. We should handle those cases but I feel maybe small 
increments are better as its not common code.


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

https://reviews.llvm.org/D80144



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


[clang] d94bacb - [WebAssembly] Handle exception specifications

2020-05-19 Thread Heejin Ahn via cfe-commits

Author: Heejin Ahn
Date: 2020-05-19T01:16:09-07:00
New Revision: d94bacbcf87a06abc0c1fc3405406399460debc3

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

LOG: [WebAssembly] Handle exception specifications

Summary:
Wasm currently does not fully handle exception specifications. Rather
than crashing,
- This treats `throw()` in the same way as `noexcept`.
- This ignores and prints a warning for `throw(type, ..)`, for a
  temporary measure. This warning is controlled by
  `-Wwasm-exception-spec`, which is on by default. You can suppress the
  warning by using `-Wno-wasm-exception-spec`.

Reviewers: dschuff

Subscribers: sbc100, jgravelle-google, sunfish, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/docs/DiagnosticsReference.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGenCXX/wasm-eh.cpp

Removed: 




diff  --git a/clang/docs/DiagnosticsReference.rst 
b/clang/docs/DiagnosticsReference.rst
index 402ec9d4eba6..2fab8b5f3026 100644
--- a/clang/docs/DiagnosticsReference.rst
+++ b/clang/docs/DiagnosticsReference.rst
@@ -14010,3 +14010,10 @@ This diagnostic is enabled by default.
 ++
 
 
+-Wwasm-exception-spec
+-
+**Diagnostic text:**
+
+++
+|:warning:`warning:` |nbsp| :diagtext:`dynamic exception specifications with 
types are currently ignored in wasm`|
+++

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index c9104da66f1f..3f0521615a5e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1207,3 +1207,5 @@ Note that the warning is disabled by default, so 
-Wmax-tokens must be used
 in addition with the pragmas or -fmax-tokens flag to get any warnings.
 }];
 }
+
+def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 55d35be8f939..d415802916b6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1590,6 +1590,9 @@ def err_exception_spec_cycle : Error<
   "exception specification of %0 uses itself">;
 def err_exception_spec_incomplete_type : Error<
   "exception specification needed for member of incomplete class %0">;
+def warn_wasm_dynamic_exception_spec_ignored : ExtWarn<
+  "dynamic exception specifications with types are currently ignored in wasm">,
+  InGroup;
 
 // C++ access checking
 def err_class_redeclared_with_
diff erent_access : Error<

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index a5dae1b32e69..d821eb2d5595 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Cor

[PATCH] D80061: [WebAssembly] Handle exception specifications

2020-05-19 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd94bacbcf87a: [WebAssembly] Handle exception specifications 
(authored by aheejin).

Changed prior to commit:
  https://reviews.llvm.org/D80061?vs=264466&id=264821#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80061

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp

Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -7,7 +7,6 @@
 // RUN: rm -f %S/wasm-eh.ll
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -391,9 +390,34 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
+
+// Wasm ignores dynamic exception specifications with types at the moment. This
+// is controlled by -Wwasm-exception-spec, which is on by default. This warning
+// can be suppressed with -Wno-wasm-exception-spec.
+// Checks if a warning message is correctly printed or not printed depending on
+// the options.
+void test9() throw(int) {
+}
+// WARNING-DEFAULT: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-ON: warning: dynamic exception specifications with types are currently ignored in wasm
+// WARNING-OFF-NOT: warning: dynamic exception specifications with types are currently ignored in wasm
+
+// Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
+// same warning message is printed as if when a 'noexcept' function throws.
+void test10() throw() {
+  throw 3;
+}
+// WARNING-DEFAULT: warning: 'test10' has a non-throwing exception specification but can still throw
+// WARNING-DEFAULT: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
+// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHS

[clang] 1d579f5 - [AST] Fix recovery-AST crash: dependent overloaded call exprs are now possible.

2020-05-19 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-05-19T11:11:09+02:00
New Revision: 1d579f54d720dcc53e11386fdec59e07614599a5

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

LOG: [AST] Fix recovery-AST crash: dependent overloaded call exprs are now 
possible.

Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/AST/StmtProfile.cpp
clang/test/AST/ast-dump-recovery.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 2d8e30aac4c8..501c07b9b667 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1446,7 +1446,6 @@ static Stmt::StmtClass DecodeOperatorCall(const 
CXXOperatorCallExpr *S,
   case OO_Array_New:
   case OO_Array_Delete:
   case OO_Arrow:
-  case OO_Call:
   case OO_Conditional:
   case NUM_OVERLOADED_OPERATORS:
 llvm_unreachable("Invalid operator call kind");
@@ -1620,6 +1619,9 @@ static Stmt::StmtClass DecodeOperatorCall(const 
CXXOperatorCallExpr *S,
   case OO_Subscript:
 return Stmt::ArraySubscriptExprClass;
 
+  case OO_Call:
+return Stmt::CallExprClass;
+
   case OO_Coawait:
 UnaryOp = UO_Coawait;
 return Stmt::UnaryOperatorClass;
@@ -1660,7 +1662,7 @@ void StmtProfiler::VisitCXXOperatorCallExpr(const 
CXXOperatorCallExpr *S) {
  SC == Stmt::CompoundAssignOperatorClass)
   ID.AddInteger(BinaryOp);
 else
-  assert(SC == Stmt::ArraySubscriptExprClass);
+  assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
 
 return;
   }

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index 3fce48a7a34e..b63483fba416 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -177,3 +177,11 @@ void InitializerForAuto() {
   // CHECK: `-VarDecl {{.*}} invalid unresolved_typo 'auto'
   auto unresolved_typo = gned.*[] {};
 }
+
+// CHECK:  `-TypeAliasDecl {{.*}} Escape 'decltype([] {
+// CHECK-NEXT:   return (undef);
+// CHECK-NEXT: }())'
+// CHECK-NEXT:   `-DecltypeType {{.*}} 'decltype([] {
+// CHECK-NEXT: return (undef);
+// CHECK-NEXT:   }())' dependent
+using Escape = decltype([] { return undef(); }());



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


[clang] 48aa781 - [Tooling] Drop leading/trailing whitespace from compile_flags.txt lines

2020-05-19 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-05-19T11:20:02+02:00
New Revision: 48aa781ae44a611967084ca031fdbb3a0712c40c

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

LOG: [Tooling] Drop leading/trailing whitespace from compile_flags.txt lines

Summary:
These files tend to be hand-authored, and people get very confused.
I can't think of any reason that such whitespace would be intended.

Reviewers: kadircet

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/CompilationDatabase.cpp
clang/test/Tooling/fixed-database.cpp

Removed: 




diff  --git a/clang/lib/Tooling/CompilationDatabase.cpp 
b/clang/lib/Tooling/CompilationDatabase.cpp
index 3590f19675c7..254314b1967f 100644
--- a/clang/lib/Tooling/CompilationDatabase.cpp
+++ b/clang/lib/Tooling/CompilationDatabase.cpp
@@ -368,8 +368,14 @@ FixedCompilationDatabase::loadFromFile(StringRef Path, 
std::string &ErrorMsg) {
 ErrorMsg = "Error while opening fixed database: " + Result.message();
 return nullptr;
   }
-  std::vector Args{llvm::line_iterator(**File),
-llvm::line_iterator()};
+  std::vector Args;
+  for (llvm::StringRef Line :
+   llvm::make_range(llvm::line_iterator(**File), llvm::line_iterator())) {
+// Stray whitespace is almost certainly unintended.
+Line = Line.trim();
+if (!Line.empty())
+  Args.push_back(Line.str());
+  }
   return std::make_unique(
   llvm::sys::path::parent_path(Path), std::move(Args));
 }

diff  --git a/clang/test/Tooling/fixed-database.cpp 
b/clang/test/Tooling/fixed-database.cpp
index 73d0779258b2..038ef5c470e2 100644
--- a/clang/test/Tooling/fixed-database.cpp
+++ b/clang/test/Tooling/fixed-database.cpp
@@ -5,7 +5,7 @@
 // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/"
 // -I flag is relative to %t (where compile_flags is), not Src/.
 // RUN: echo '-IInclude/' >> %t/compile_flags.txt
-// RUN: echo "-Dklazz=class" >> %t/compile_flags.txt
+// RUN: echo "  -Dklazz=class   " >> %t/compile_flags.txt
 // RUN: echo '-std=c++11' >> %t/compile_flags.txt
 // RUN: clang-check "%t/Src/test.cpp" 2>&1
 // RUN: echo > %t/compile_flags.txt



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


[PATCH] D80160: [Tooling] Drop leading/trailing whitespace from compile_flags.txt lines

2020-05-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 2 inline comments as done.
sammccall added inline comments.



Comment at: clang/test/Tooling/fixed-database.cpp:6
 // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/"
+// RUN: echo '# this is a comment' >> %t/compile_flags.txt
 // -I flag is relative to %t (where compile_flags is), not Src/.

kadircet wrote:
> Not sure what this line is about, default comment marker is `\0` for 
> `line_itearator` and we don't seem to be changing it.
Uh, this is a bad test, clang-check doesn't fail on driver errors and the 
compilation didn't depend on it.

And `#comments` would probably break something one day anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80160



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


[PATCH] D80198: [clangd] locateMacroAt handles patched macros

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

Depends on D79992 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80198

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -514,7 +514,7 @@
   ASSERT_TRUE(bool(CurLoc));
   const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
   ASSERT_TRUE(Id);
-  auto Result = locateMacroAt(*Id, AST.getPreprocessor());
+  auto Result = locateMacroAt(*Id, AST.getPreprocessor(), AST.getTokens());
   ASSERT_TRUE(Result);
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
@@ -528,7 +528,7 @@
   ASSERT_TRUE(bool(CurLoc));
   const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
   ASSERT_TRUE(Id);
-  auto Result = locateMacroAt(*Id, AST.getPreprocessor());
+  auto Result = locateMacroAt(*Id, AST.getPreprocessor(), AST.getTokens());
   ASSERT_TRUE(Result);
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -198,7 +198,7 @@
 ADD_FAILURE() << "Failed to build compiler invocation";
 return llvm::None;
   }
-  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  return ParsedAST::build(testPath(TU.Filename), TU.inputs(), std::move(CI), {},
   BaselinePreamble);
 }
 
@@ -243,6 +243,101 @@
   EXPECT_THAT(AST->getDiagnostics(),
   Not(Contains(Field(&Diag::Range, Modified.range();
 }
+
+TEST(PreamblePatchTest, LocateMacroAtWorks) {
+  struct {
+llvm::StringLiteral Baseline;
+llvm::StringLiteral Modified;
+  } Cases[] = {
+  // Addition of new directive
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  // Available inside preamble section
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef $use^FOO)cpp",
+  },
+  // Available after undef, as we don't patch those
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef FOO
+$use^FOO)cpp",
+  },
+  // Identifier on a different line
+  {
+  "",
+  R"cpp(
+#define \
+  $def^FOO
+$use^FOO)cpp",
+  },
+  // In presence of comment tokens
+  {
+  "",
+  R"cpp(
+#\
+  define /* FOO */\
+  /* FOO */ $def^FOO
+$use^FOO)cpp",
+  },
+  // Moved around
+  {
+  "#define FOO",
+  R"cpp(
+#define BAR
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  };
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Modified);
+llvm::Annotations Modified(Case.Modified);
+auto AST = createPatchedAST(Case.Baseline, Modified.code());
+ASSERT_TRUE(AST);
+
+const auto &SM = AST->getSourceManager();
+auto *MacroTok = AST->getTokens().spelledTokenAt(
+SM.getComposedLoc(SM.getMainFileID(), Modified.point("use")));
+ASSERT_TRUE(MacroTok);
+
+auto FoundMacro =
+locateMacroAt(*MacroTok, AST->getPreprocessor(), AST->getTokens());
+ASSERT_TRUE(FoundMacro);
+EXPECT_THAT(FoundMacro->Name, "FOO");
+
+auto MacroLoc = FoundMacro->DefRange.getBegin();
+EXPECT_EQ(SM.getFileID(MacroLoc), SM.getMainFileID());
+EXPECT_EQ(SM.getFileOffset(MacroLoc), Modified.point("def"));
+  }
+}
+
+TEST(PreamblePatchTest, LocateMacroAtDeletion) {
+  // We don't patch deleted define directives, make sure we don't crash.
+  llvm::StringLiteral Baseline = "#define FOO";
+  llvm::Annotations Modified("^FOO");
+
+  auto AST = createPatchedAST(Baseline, Modified.code());
+  ASSERT_TRUE(AST);
+
+  const auto &SM = AST->getSourceManager();
+  auto *MacroTok = AST->getTokens().spelledTokenAt(
+  SM.getComposedLoc(SM.getMainFileID(), Modified.point()));
+  ASSERT_TRUE(MacroTok);
+
+  auto FoundMacro =
+  locateMacroAt(*MacroTok, AST->getPreprocessor(), AST->getTokens());
+  ASSERT_TRUE(FoundMacro);
+  

[PATCH] D77068: [XCore] fix crash on unused inline in EmitTargetMetadata

2020-05-19 Thread Nigel Perks via Phabricator via cfe-commits
nigelp-xmos updated this revision to Diff 264827.
nigelp-xmos added a comment.

As suggested by FIXME comment in code, and review comment, moved the 
EmitTargetMetadata loop into XCore target.


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

https://reviews.llvm.org/D77068

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGen/xcore-unused-inline.c

Index: clang/test/CodeGen/xcore-unused-inline.c
===
--- /dev/null
+++ clang/test/CodeGen/xcore-unused-inline.c
@@ -0,0 +1,4 @@
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore-unknown-unknown -emit-llvm -o - %s
+
+inline void dead_function(void) {}
Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -57,10 +57,11 @@
   virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const {}
 
-  /// emitTargetMD - Provides a convenient hook to handle extra
-  /// target-specific metadata for the given global.
-  virtual void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
-CodeGen::CodeGenModule &M) const {}
+  /// emitTargetMetadata - Provides a convenient hook to handle extra
+  /// target-specific metadata for the given globals.
+  virtual void emitTargetMetadata(
+  CodeGen::CodeGenModule &CGM,
+  const llvm::MapVector &MangledDeclNames) const {}
 
   /// Determines the size of struct _Unwind_Exception on this platform,
   /// in 8-bit units.  The Itanium ABI defines this as:
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9394,11 +9394,15 @@
 
 class XCoreTargetCodeGenInfo : public TargetCodeGenInfo {
   mutable TypeStringCache TSC;
+  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+const CodeGen::CodeGenModule &M) const;
+
 public:
   XCoreTargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
-  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
-CodeGen::CodeGenModule &M) const override;
+  void emitTargetMetadata(CodeGen::CodeGenModule &CGM,
+  const llvm::MapVector
+  &MangledDeclNames) const override;
 };
 
 } // End anonymous namespace.
@@ -9559,11 +9563,13 @@
 /// The output is tested by test/CodeGen/xcore-stringtype.c.
 ///
 static bool getTypeString(SmallStringEnc &Enc, const Decl *D,
-  CodeGen::CodeGenModule &CGM, TypeStringCache &TSC);
+  const CodeGen::CodeGenModule &CGM,
+  TypeStringCache &TSC);
 
 /// XCore uses emitTargetMD to emit TypeString metadata for global symbols.
-void XCoreTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
-  CodeGen::CodeGenModule &CGM) const {
+void XCoreTargetCodeGenInfo::emitTargetMD(
+const Decl *D, llvm::GlobalValue *GV,
+const CodeGen::CodeGenModule &CGM) const {
   SmallStringEnc Enc;
   if (getTypeString(Enc, D, CGM, TSC)) {
 llvm::LLVMContext &Ctx = CGM.getModule().getContext();
@@ -9575,6 +9581,21 @@
   }
 }
 
+void XCoreTargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule &CGM,
+const llvm::MapVector &MangledDeclNames) const {
+  // Warning, new MangledDeclNames may be appended within this loop.
+  // We rely on MapVector insertions adding new elements to the end
+  // of the container.
+  for (unsigned I = 0; I != MangledDeclNames.size(); ++I) {
+auto Val = *(MangledDeclNames.begin() + I);
+llvm::GlobalValue *GV = CGM.GetGlobalValue(Val.second);
+if (GV) {
+  const Decl *D = Val.first.getDecl()->getMostRecentDecl();
+  emitTargetMD(D, GV, CGM);
+}
+  }
+}
 //===--===//
 // SPIR ABI Implementation
 //===--===//
@@ -9908,7 +9929,8 @@
 }
 
 static bool getTypeString(SmallStringEnc &Enc, const Decl *D,
-  CodeGen::CodeGenModule &CGM, TypeStringCache &TSC) {
+  const CodeGen::CodeGenModule &CGM,
+  TypeStringCache &TSC) {
   if (!D)
 return false;
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1508,9 +1508,6 @@
   /// Emit the Clang commandline as llvm.commandline metadata.
   void EmitCommandLineMetadata();
 
-  /// Emits target specific Metadata for 

[PATCH] D80160: [Tooling] Drop leading/trailing whitespace from compile_flags.txt lines

2020-05-19 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG48aa781ae44a: [Tooling] Drop leading/trailing whitespace 
from compile_flags.txt lines (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D80160?vs=264716&id=264828#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80160

Files:
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/test/Tooling/fixed-database.cpp


Index: clang/test/Tooling/fixed-database.cpp
===
--- clang/test/Tooling/fixed-database.cpp
+++ clang/test/Tooling/fixed-database.cpp
@@ -5,7 +5,7 @@
 // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/"
 // -I flag is relative to %t (where compile_flags is), not Src/.
 // RUN: echo '-IInclude/' >> %t/compile_flags.txt
-// RUN: echo "-Dklazz=class" >> %t/compile_flags.txt
+// RUN: echo "  -Dklazz=class   " >> %t/compile_flags.txt
 // RUN: echo '-std=c++11' >> %t/compile_flags.txt
 // RUN: clang-check "%t/Src/test.cpp" 2>&1
 // RUN: echo > %t/compile_flags.txt
Index: clang/lib/Tooling/CompilationDatabase.cpp
===
--- clang/lib/Tooling/CompilationDatabase.cpp
+++ clang/lib/Tooling/CompilationDatabase.cpp
@@ -368,8 +368,14 @@
 ErrorMsg = "Error while opening fixed database: " + Result.message();
 return nullptr;
   }
-  std::vector Args{llvm::line_iterator(**File),
-llvm::line_iterator()};
+  std::vector Args;
+  for (llvm::StringRef Line :
+   llvm::make_range(llvm::line_iterator(**File), llvm::line_iterator())) {
+// Stray whitespace is almost certainly unintended.
+Line = Line.trim();
+if (!Line.empty())
+  Args.push_back(Line.str());
+  }
   return std::make_unique(
   llvm::sys::path::parent_path(Path), std::move(Args));
 }


Index: clang/test/Tooling/fixed-database.cpp
===
--- clang/test/Tooling/fixed-database.cpp
+++ clang/test/Tooling/fixed-database.cpp
@@ -5,7 +5,7 @@
 // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/"
 // -I flag is relative to %t (where compile_flags is), not Src/.
 // RUN: echo '-IInclude/' >> %t/compile_flags.txt
-// RUN: echo "-Dklazz=class" >> %t/compile_flags.txt
+// RUN: echo "  -Dklazz=class   " >> %t/compile_flags.txt
 // RUN: echo '-std=c++11' >> %t/compile_flags.txt
 // RUN: clang-check "%t/Src/test.cpp" 2>&1
 // RUN: echo > %t/compile_flags.txt
Index: clang/lib/Tooling/CompilationDatabase.cpp
===
--- clang/lib/Tooling/CompilationDatabase.cpp
+++ clang/lib/Tooling/CompilationDatabase.cpp
@@ -368,8 +368,14 @@
 ErrorMsg = "Error while opening fixed database: " + Result.message();
 return nullptr;
   }
-  std::vector Args{llvm::line_iterator(**File),
-llvm::line_iterator()};
+  std::vector Args;
+  for (llvm::StringRef Line :
+   llvm::make_range(llvm::line_iterator(**File), llvm::line_iterator())) {
+// Stray whitespace is almost certainly unintended.
+Line = Line.trim();
+if (!Line.empty())
+  Args.push_back(Line.str());
+  }
   return std::make_unique(
   llvm::sys::path::parent_path(Path), std::move(Args));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-05-19 Thread Michael Schellenberger Costa via Phabricator via cfe-commits
miscco added a comment.

Awesome, Thank you very much, I dragged my feet on starting to implement 
something for real.

As a high level comment I think we need to handle requires expressions to get 
this correct, as `requires requires` would otherwise to bad things.

From my early brainstorming i got the following options I thought useful. This 
is in no ways a request for you to implement them, but I would want to get them 
out here in case they are usefull

  /// Different styles for merging short requires-clauses with the template
/// decalaration
enum ShortRequiresClauseStyle {
  /// Never merge requires clauses into a single line.
  /// \code
  ///   template 
  ///   requires someConstraint
  ///   T foo();
  /// \endcode
  SRCS_Never,
  /// Only merge requires clauses with a single constraint.
  /// \code
  ///   template  requires someConstraint
  ///   T foo();
  ///
  ///   template 
  ///   requires someConstraint && otherConstraint
  ///   T bar();
  /// \endcode
  SRCS_Single,
  /// Merge requires clauses if they are short
  /// \code
  ///   template  requires short && shorter
  ///   T foo();
  ///
  ///   template 
  ///   requires someReallyLongElaborateConstraintThatIsReallyLong
  ///   T bar();
  ///
  ///   template 
  ///   requires someLongConstraint && otherLongConstraint
  ///   T baz();
  /// \endcode
  SRCS_Short,
  /// Always try to merge the requires clause with the template declaration
  /// \code
  ///   template  requires someLongConstraint &&
  ///   otherLongConstraint
  ///   T foo();
  /// \endcode
  SRCS_Always,
};
  
/// Dependent on the value, requires-clauses can be put on the same line
/// as the template declaration.
ShortRequiresClauseStyle AllowShortRequiresClause;
  
/// Dependent on the value, requires-expressions can be a single line
/// Always try to merge the requires clause with the template declaration
/// \code
///   template  requires someLongConstraint &&
///   requires { T{}; }
///   T foo();
/// \endcode
bool AllowShortRequiresExpression;
  
 /// Dependent on the value break before or after constraint expressions.
enum ConstraintExpressionBreakingStyle {
  /// Break after constraint expressions but multiple may be on single line
  /// \code
  ///   template  requires someLongConstraint &&
  ///   otherLongConstraint
  ///   T foo();
  ///
  ///   template  requires short && shorter &&
  ///   otherLongConstraint
  ///   T bar();
  /// \endcode
  CEBS_After,
  /// Break after constraint expressions.
  /// \code
  ///   template  requires short &&
  ///   shorter &&
  ///   otherLongConstraint
  ///   T bar();
  /// \endcode
  CEBS_AfterSingleExpression,
  /// Break before constraint expressions but multiple may be on single line
  /// \code
  ///   template  requires someLongConstraint &&
  ///   otherLongConstraint
  ///   T foo();
  ///
  ///   template  requires short && shorter
  ///&& otherLongConstraint
  ///   T bar();
  /// \endcode
  CEBS_Before,
  /// Break before constraint expressions.
  /// \code
  ///   template  requires short
  ///&& shorter
  ///&& otherLongConstraint
  ///   T foo();
  /// \endcode
  CEBS_BeforeSingleExpression,
};
  
/// The constraint expressions style to use.
ConstraintExpressionBreakingStyle BreakBeforeConstraintExpression;
  
/// Dependent on the value wrap before or after requires expressions.
enum BraceWrappingRequiresExpressionStyle {
  /// Do not wrap braces of requires expressions
  /// \code
  ///   template  requires requires {  T{};
  ///   T(int); }
  ///   T foo();
  /// \endcode
  BWARES_NoWrap,
  /// Wrap after requires expressions.
  /// \code
  ///   template  requires requires { T{};
  ///  T(int);
  ///}
  ///   T foo();
  /// \endcode
  BWARES_WrapAfter,
  /// Wrap after requires expressions.
  /// \code
  ///   template  requires requires
  ///   { T{};
  /// T(int); }
  ///   T foo();
  /// \endcode
  BWARES_WrapBefore,
  /// Wrap after requires expressions with a new line.
  /// \code
  ///   template  requires requires
  ///   {

[PATCH] D80154: [AST] Fix recovery-AST crash: dependent overloaded call exprs are now possible.

2020-05-19 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d579f54d720: [AST] Fix recovery-AST crash: dependent 
overloaded call exprs are now possible. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80154

Files:
  clang/lib/AST/StmtProfile.cpp
  clang/test/AST/ast-dump-recovery.cpp


Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -177,3 +177,11 @@
   // CHECK: `-VarDecl {{.*}} invalid unresolved_typo 'auto'
   auto unresolved_typo = gned.*[] {};
 }
+
+// CHECK:  `-TypeAliasDecl {{.*}} Escape 'decltype([] {
+// CHECK-NEXT:   return (undef);
+// CHECK-NEXT: }())'
+// CHECK-NEXT:   `-DecltypeType {{.*}} 'decltype([] {
+// CHECK-NEXT: return (undef);
+// CHECK-NEXT:   }())' dependent
+using Escape = decltype([] { return undef(); }());
Index: clang/lib/AST/StmtProfile.cpp
===
--- clang/lib/AST/StmtProfile.cpp
+++ clang/lib/AST/StmtProfile.cpp
@@ -1446,7 +1446,6 @@
   case OO_Array_New:
   case OO_Array_Delete:
   case OO_Arrow:
-  case OO_Call:
   case OO_Conditional:
   case NUM_OVERLOADED_OPERATORS:
 llvm_unreachable("Invalid operator call kind");
@@ -1620,6 +1619,9 @@
   case OO_Subscript:
 return Stmt::ArraySubscriptExprClass;
 
+  case OO_Call:
+return Stmt::CallExprClass;
+
   case OO_Coawait:
 UnaryOp = UO_Coawait;
 return Stmt::UnaryOperatorClass;
@@ -1660,7 +1662,7 @@
  SC == Stmt::CompoundAssignOperatorClass)
   ID.AddInteger(BinaryOp);
 else
-  assert(SC == Stmt::ArraySubscriptExprClass);
+  assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
 
 return;
   }


Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -177,3 +177,11 @@
   // CHECK: `-VarDecl {{.*}} invalid unresolved_typo 'auto'
   auto unresolved_typo = gned.*[] {};
 }
+
+// CHECK:  `-TypeAliasDecl {{.*}} Escape 'decltype([] {
+// CHECK-NEXT:   return (undef);
+// CHECK-NEXT: }())'
+// CHECK-NEXT:   `-DecltypeType {{.*}} 'decltype([] {
+// CHECK-NEXT: return (undef);
+// CHECK-NEXT:   }())' dependent
+using Escape = decltype([] { return undef(); }());
Index: clang/lib/AST/StmtProfile.cpp
===
--- clang/lib/AST/StmtProfile.cpp
+++ clang/lib/AST/StmtProfile.cpp
@@ -1446,7 +1446,6 @@
   case OO_Array_New:
   case OO_Array_Delete:
   case OO_Arrow:
-  case OO_Call:
   case OO_Conditional:
   case NUM_OVERLOADED_OPERATORS:
 llvm_unreachable("Invalid operator call kind");
@@ -1620,6 +1619,9 @@
   case OO_Subscript:
 return Stmt::ArraySubscriptExprClass;
 
+  case OO_Call:
+return Stmt::CallExprClass;
+
   case OO_Coawait:
 UnaryOp = UO_Coawait;
 return Stmt::UnaryOperatorClass;
@@ -1660,7 +1662,7 @@
  SC == Stmt::CompoundAssignOperatorClass)
   ID.AddInteger(BinaryOp);
 else
-  assert(SC == Stmt::ArraySubscriptExprClass);
+  assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
 
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] e408b54 - [clangd] Fix gcc compiler warning by removing extra ";" [NFC]

2020-05-19 Thread Mikael Holmen via cfe-commits

Author: Mikael Holmen
Date: 2020-05-19T11:57:15+02:00
New Revision: e408b54290bd5dc35b02ef4270292d52c89d9751

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

LOG: [clangd] Fix gcc compiler warning by removing extra ";" [NFC]

gcc complained with:

/data/repo/master/clang-tools-extra/clangd/index/Ref.h:189:2: warning: extra 
';' [-Wpedantic]
 }; // namespace llvm
  ^

Added: 


Modified: 
clang-tools-extra/clangd/index/Ref.h

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Ref.h 
b/clang-tools-extra/clangd/index/Ref.h
index cba8adaee7c2..577db7525442 100644
--- a/clang-tools-extra/clangd/index/Ref.h
+++ b/clang-tools-extra/clangd/index/Ref.h
@@ -186,6 +186,6 @@ template <> struct 
DenseMapInfo {
LHS.Reference.Location.End == RHS.Reference.Location.End;
   }
 };
-}; // namespace llvm
+} // namespace llvm
 
 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_REF_H



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


[clang] 56079e1 - [Analyzer][VLASizeChecker] Try to fix vla.c test problems.

2020-05-19 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-05-19T12:12:28+02:00
New Revision: 56079e1de1129837aa7569d8b3bb5e50afc0f1ea

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

LOG: [Analyzer][VLASizeChecker] Try to fix vla.c test problems.

Added: 


Modified: 
clang/test/Analysis/vla.c

Removed: 




diff  --git a/clang/test/Analysis/vla.c b/clang/test/Analysis/vla.c
index 062bb0828e23..a269ef334c32 100644
--- a/clang/test/Analysis/vla.c
+++ b/clang/test/Analysis/vla.c
@@ -18,11 +18,11 @@ void check_uninit_sized_VLA() {
 }
 
 // Negative VLAs.
-static void vla_allocate_signed(int x) {
+static void vla_allocate_signed(short x) {
   int vla[x]; // expected-warning{{Declared variable-length array (VLA) has 
negative size}}
 }
 
-static void vla_allocate_unsigned(unsigned int x) {
+static void vla_allocate_unsigned(unsigned short x) {
   int vla[x]; // no-warning
 }
 
@@ -35,12 +35,12 @@ void check_negative_sized_VLA_2() {
 }
 
 void check_negative_sized_VLA_3() {
-  int x = -1;
+  short x = -1;
   int vla[x]; // expected-warning{{Declared variable-length array (VLA) has 
negative size}}
 }
 
 void check_negative_sized_VLA_4() {
-  unsigned int x = -1;
+  unsigned short x = -1;
   int vla[x]; // no-warning
 }
 
@@ -79,12 +79,12 @@ void check_negative_sized_VLA_10(int x) {
 check_negative_sized_VLA_10_sub(x);
 }
 
-static void check_negative_sized_VLA_11_sub(int x)
+static void check_negative_sized_VLA_11_sub(short x)
 {
   int vla[x]; // no-warning
 }
 
-void check_negative_sized_VLA_11(int x) {
+void check_negative_sized_VLA_11(short x) {
   if (x > 0)
 check_negative_sized_VLA_11_sub(x);
 }



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


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

2020-05-19 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked 6 inline comments as done.
MyDeveloperDay added a subscriber: STL_MSFT.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1566
   Current.Type = TT_TrailingReturnArrow;
-
+} else if (Current.is(tok::arrow) && Current.Previous &&
+   Current.Previous->is(tok::r_brace)) {

miscco wrote:
> Should that really be `tok::arrow` and not `tok::kw_requires`?
This is to prevent the breaking between } and -> in the following (which could 
be some way from the requires

`{ t.foo(u) } -> typename T::foo_type;`



Comment at: clang/lib/Format/TokenAnnotator.cpp:3484
+  // concept ...
+  if (Left.is(TT_TemplateCloser) && Right.is(tok::kw_concept))
+return true;

miscco wrote:
> I think we should have an option to allow short requires clauses on the same 
> line similar to allow short functions
Actually at present it will pull short requires onto a new line, this 
particular line is about keeping `concept` on a new line (most examplesI've 
seen are like this..i.e.

```template
concept...```

rather than 

`template concept...`

For me the natural thing here is to enforce a newline and then relax that later 
if we think it needs it, but I'm wary of adding too many options upfront. 

This is virgin territory as most style guides out there don't specify anything 
for concepts yet, to be honest i'd prefer to establish an LLVM style and wait 
for the other style guides to catch up. (I know we will revisit this later), 
just want to keep the initial commit small. (incremental development is 
encouraged in LLVM) and multiple options will be a huge commit that never gets 
passed.





Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2284
+
+void UnwrappedLineParser::parseRequires() {
+  assert(FormatTok->Tok.is(tok::kw_requires) && "'requires' expected");

miscco wrote:
> I believe we should separate between constraint expressions aka: `tempalte<  
> > requires Concept1 && Concept2` and requires expressions aka `requires { ... 
> }`
> 
> The two are quite different. That said the handling of requires expressions 
> should be "simple" as we only need to find the matching "}". 
> 
> As an upside this would also handle the famous `requires requires`
This is effectively the `if` at line 2305 seeing "requires {" or requires(Foo 
t) {" sets off down the parseBlock path which can itself include requires.

If you do have an example you think would break this please feel free to add 
that in a comment and I'll add it to the unit tests and rework accordingly.

My exposure to concepts is still pretty new, I'm not even sure I've covered all 
the places it can be used, but I wanted to start because at present I see alot 
of the MS STL(@STL_MSFT ) covered with // clang-format off around the concepts.


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

https://reviews.llvm.org/D79773



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


[PATCH] D78990: [analyzer] Allow bindings of the CompoundLiteralRegion

2020-05-19 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 264831.
vsavchenko added a comment.

Fix code review remarks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78990

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/compound-literals.c
  clang/test/Analysis/retain-release-compound-literal.m
  clang/unittests/StaticAnalyzer/StoreTest.cpp

Index: clang/unittests/StaticAnalyzer/StoreTest.cpp
===
--- clang/unittests/StaticAnalyzer/StoreTest.cpp
+++ clang/unittests/StaticAnalyzer/StoreTest.cpp
@@ -15,89 +15,139 @@
 namespace ento {
 namespace {
 
+class StoreTestConsumer : public ExprEngineConsumer {
+public:
+  StoreTestConsumer(CompilerInstance &C) : ExprEngineConsumer(C) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+for (const auto *D : DG)
+  performTest(D);
+return true;
+  }
+
+private:
+  virtual void performTest(const Decl *D) = 0;
+};
+
+template  class TestAction : public ASTFrontendAction {
+public:
+  std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler,
+ StringRef File) override {
+return std::make_unique(Compiler);
+  }
+};
+
 // Test that we can put a value into an int-type variable and load it
 // back from that variable. Test what happens if default bindings are used.
-class VariableBindConsumer : public ExprEngineConsumer {
-  void performTest(const Decl *D) {
-StoreManager &StMgr = Eng.getStoreManager();
-SValBuilder &SVB = Eng.getSValBuilder();
-MemRegionManager &MRMgr = StMgr.getRegionManager();
-const ASTContext &ACtx = Eng.getContext();
+class VariableBindConsumer : public StoreTestConsumer {
+  void performTest(const Decl *D) override {
+StoreManager &SManager = Eng.getStoreManager();
+SValBuilder &Builder = Eng.getSValBuilder();
+MemRegionManager &MRManager = SManager.getRegionManager();
+const ASTContext &ASTCtxt = Eng.getContext();
 
 const auto *VDX0 = findDeclByName(D, "x0");
 const auto *VDY0 = findDeclByName(D, "y0");
 const auto *VDZ0 = findDeclByName(D, "z0");
 const auto *VDX1 = findDeclByName(D, "x1");
 const auto *VDY1 = findDeclByName(D, "y1");
-assert(VDX0 && VDY0 && VDZ0 && VDX1 && VDY1);
+
+ASSERT_TRUE(VDX0 && VDY0 && VDZ0 && VDX1 && VDY1);
 
 const StackFrameContext *SFC =
 Eng.getAnalysisDeclContextManager().getStackFrame(D);
 
-Loc LX0 = loc::MemRegionVal(MRMgr.getVarRegion(VDX0, SFC));
-Loc LY0 = loc::MemRegionVal(MRMgr.getVarRegion(VDY0, SFC));
-Loc LZ0 = loc::MemRegionVal(MRMgr.getVarRegion(VDZ0, SFC));
-Loc LX1 = loc::MemRegionVal(MRMgr.getVarRegion(VDX1, SFC));
-Loc LY1 = loc::MemRegionVal(MRMgr.getVarRegion(VDY1, SFC));
+Loc LX0 = loc::MemRegionVal(MRManager.getVarRegion(VDX0, SFC));
+Loc LY0 = loc::MemRegionVal(MRManager.getVarRegion(VDY0, SFC));
+Loc LZ0 = loc::MemRegionVal(MRManager.getVarRegion(VDZ0, SFC));
+Loc LX1 = loc::MemRegionVal(MRManager.getVarRegion(VDX1, SFC));
+Loc LY1 = loc::MemRegionVal(MRManager.getVarRegion(VDY1, SFC));
 
-Store StInit = StMgr.getInitialStore(SFC).getStore();
-SVal Zero = SVB.makeZeroVal(ACtx.IntTy);
-SVal One = SVB.makeIntVal(1, ACtx.IntTy);
-SVal NarrowZero = SVB.makeZeroVal(ACtx.CharTy);
+Store StInit = SManager.getInitialStore(SFC).getStore();
+SVal Zero = Builder.makeZeroVal(ASTCtxt.IntTy);
+SVal One = Builder.makeIntVal(1, ASTCtxt.IntTy);
+SVal NarrowZero = Builder.makeZeroVal(ASTCtxt.CharTy);
 
 // Bind(Zero)
-Store StX0 =
-StMgr.Bind(StInit, LX0, Zero).getStore();
-ASSERT_EQ(Zero, StMgr.getBinding(StX0, LX0, ACtx.IntTy));
+Store StX0 = SManager.Bind(StInit, LX0, Zero).getStore();
+EXPECT_EQ(Zero, SManager.getBinding(StX0, LX0, ASTCtxt.IntTy));
 
 // BindDefaultInitial(Zero)
 Store StY0 =
-StMgr.BindDefaultInitial(StInit, LY0.getAsRegion(), Zero).getStore();
-ASSERT_EQ(Zero, StMgr.getBinding(StY0, LY0, ACtx.IntTy));
-ASSERT_EQ(Zero, *StMgr.getDefaultBinding(StY0, LY0.getAsRegion()));
+SManager.BindDefaultInitial(StInit, LY0.getAsRegion(), Zero).getStore();
+EXPECT_EQ(Zero, SManager.getBinding(StY0, LY0, ASTCtxt.IntTy));
+EXPECT_EQ(Zero, *SManager.getDefaultBinding(StY0, LY0.getAsRegion()));
 
 // BindDefaultZero()
-Store StZ0 =
-StMgr.BindDefaultZero(StInit, LZ0.getAsRegion()).getStore();
+Store StZ0 = SManager.BindDefaultZero(StInit, LZ0.getAsRegion()).getStore();
 // BindDefaultZero wipes the region with '0 S8b', not with out Zero.
 // Direct load, however, does give us back the object of the type
 // that we specify for loading.
-ASSERT_EQ(Zero, StMgr.getBinding(StZ0, LZ0, ACtx.IntTy));
-ASSERT_EQ(NarrowZero, *StMgr.getDefaultBinding(StZ0, LZ0.getAsRegion()));
+EXPECT_EQ(Zero, SManager.getBinding(StZ0, LZ0, ASTCtxt.

[PATCH] D80200: [AST][RecoveryExpr] Fix an assertion crash on openMP.

2020-05-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: guansong, yaxunl.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

With recovery expr, it is possible that we have a value-dependent expr
within non-dependent context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80200

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/recovery-crash.cpp


Index: clang/test/OpenMP/recovery-crash.cpp
===
--- /dev/null
+++ clang/test/OpenMP/recovery-crash.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -frecovery-ast %s
+
+void foo(int i) {
+#pragma omp target update from(i) device(undef()) // expected-error {{use of 
undeclared identifier 'undef'}}
+}
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -6894,8 +6894,8 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
-  if (SemaRef.CurContext->isDependentContext())
-return ExprResult(Capture);
+  if (SemaRef.CurContext->isDependentContext() || Capture->containsErrors())
+return Capture;
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,


Index: clang/test/OpenMP/recovery-crash.cpp
===
--- /dev/null
+++ clang/test/OpenMP/recovery-crash.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -frecovery-ast %s
+
+void foo(int i) {
+#pragma omp target update from(i) device(undef()) // expected-error {{use of undeclared identifier 'undef'}}
+}
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -6894,8 +6894,8 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
-  if (SemaRef.CurContext->isDependentContext())
-return ExprResult(Capture);
+  if (SemaRef.CurContext->isDependentContext() || Capture->containsErrors())
+return Capture;
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-05-19 Thread Michael Schellenberger Costa via Phabricator via cfe-commits
miscco added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3499
 return true;
   if (Right.Previous->ClosesTemplateDeclaration &&
   Right.Previous->MatchingParen &&

I think that your change should actually come in here where we determine what 
to do after a `ClosesTemplateDeclaration` 

With an potential new option `AlwaysBreakConceptDeclarations ` that should 
probably default to `AlwaysBreakTemplateDeclarations ` this would read
```
  if (Right.Previous->ClosesTemplateDeclaration &&
  Right.Previous->MatchingParen &&
  Right.Previous->MatchingParen->NestingLevel == 0) { 
  if (Right.is(tok::kw_requires)) {
switch(Style.AllowShortRequiresClause) {
  case FormatStyle::SRCS_Never: 
return true;
  case FormatStyle::SRCS_Always: 
return false;
  case FormatStyle::SRCS_Single:
// TODO: Determine whether there is a single constraint 
return true;
  case FormatStyle::SRCS_Short: 
// TODO: Determine whether the constraint clause is short enough
return true;
} 
  } else if (Right.is(tok::kw_concept)) {
return Style.AlwaysBreakConceptDeclarations == FormatStyle::BTCS_Yes);
  } else {
return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes);
  }
  }
```


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

https://reviews.llvm.org/D79773



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


  1   2   3   >