[PATCH] D96838: Add GNU attribute 'retain'

2021-02-22 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

> I have documented the behaviors in clang/include/clang/Basic/AttrDocs.td. Do 
> you have suggestions on the wording?

Included; please let me know what you think.




Comment at: clang/include/clang/Basic/AttrDocs.td:63-76
+The attribute, when attached to a function definition, causes the function to
+be emitted even if it appears that the function is not referenced and can
+otherwise be omitted.
+
+The attribute, when attached to a variable definition with static storage,
+causes the variable to be emitted even if it appears that the variable is not
+referenced.





Comment at: clang/include/clang/Basic/AttrDocs.td:83-91
+This attribute only has effects on ELF targets that support SHF_GNU_RETAIN.
+The attribute, when attached to a function or variable definition, if the
+function or variable is emitted, causes the function or variable to be emitted
+in a unique section with SHF_GNU_RETAIN flag.  This ELF section flag prevents
+garbage collection of the section by supported linkers (GNU ld and gold from
+binutils 2.36 onwards, LLD 13 or newer).
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96838

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


[PATCH] D94376: [MemCpyOpt] Enable MemorySSA by default

2021-02-22 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

I ran into a crash in memcpyopt with this patch.
Running

  opt -S -o - bbi-53212.ll -memcpyopt

yields

  opt: ../include/llvm/Support/Casting.h:104: static bool 
llvm::isa_impl_cl::doit(const 
From *) [To = llvm::MemoryUse, From = const llvm::MemoryUseOrDef *]: Assertion 
`Val && "isa<> used on a null pointer"' failed.
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
  Stack dump:
  0.Program arguments: /data/repo/master/llvm/build-all/bin/opt -S -o - 
bbi-53212.ll -memcpyopt
   #0 0x029461e3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/data/repo/master/llvm/build-all/bin/opt+0x29461e3)
   #1 0x02943e9e llvm::sys::RunSignalHandlers() 
(/data/repo/master/llvm/build-all/bin/opt+0x2943e9e)
   #2 0x029466a6 SignalHandler(int) Signals.cpp:0:0
   #3 0x7ff087446980 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
   #4 0x7ff084517fb7 raise 
/build/glibc-S9d2JN/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
   #5 0x7ff084519921 abort 
/build/glibc-S9d2JN/glibc-2.27/stdlib/abort.c:81:0
   #6 0x7ff08450948a __assert_fail_base 
/build/glibc-S9d2JN/glibc-2.27/assert/assert.c:89:0
   #7 0x7ff084509502 (/lib/x86_64-linux-gnu/libc.so.6+0x30502)
   #8 0x019f8722 llvm::MemoryUseOrDef::getDefiningAccess() const 
(/data/repo/master/llvm/build-all/bin/opt+0x19f8722)
   #9 0x02766c6d 
llvm::MemCpyOptPass::processByValArgument(llvm::CallBase&, unsigned int) 
(/data/repo/master/llvm/build-all/bin/opt+0x2766c6d)
  #10 0x02767810 
llvm::MemCpyOptPass::iterateOnFunction(llvm::Function&) 
(/data/repo/master/llvm/build-all/bin/opt+0x2767810)
  #11 0x02768280 llvm::MemCpyOptPass::runImpl(llvm::Function&, 
llvm::MemoryDependenceResults*, llvm::TargetLibraryInfo*, llvm::AAResults*, 
llvm::AssumptionCache*, llvm::DominatorTree*, llvm::MemorySSA*) 
(/data/repo/master/llvm/build-all/bin/opt+0x2768280)
  #12 0x02767c69 llvm::MemCpyOptPass::run(llvm::Function&, 
llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0x2767c69)
  #13 0x02bf031d llvm::detail::PassModel >::run(llvm::Function&, 
llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0x2bf031d)
  #14 0x021720c9 llvm::PassManager >::run(llvm::Function&, 
llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0x21720c9)
  #15 0x00a7cbfd llvm::detail::PassModel >, 
llvm::PreservedAnalyses, llvm::AnalysisManager 
>::run(llvm::Function&, llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0xa7cbfd)
  #16 0x021768b6 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, 
llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0x21768b6)
  #17 0x0076c61d llvm::detail::PassModel >::run(llvm::Module&, 
llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0x76c61d)
  #18 0x02170f2b llvm::PassManager >::run(llvm::Module&, 
llvm::AnalysisManager&) 
(/data/repo/master/llvm/build-all/bin/opt+0x2170f2b)
  #19 0x00764fe1 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, 
llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, 
llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, 
llvm::ArrayRef, llvm::opt_tool::OutputKind, 
llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) 
(/data/repo/master/llvm/build-all/bin/opt+0x764fe1)
  #20 0x00776b32 main 
(/data/repo/master/llvm/build-all/bin/opt+0x776b32)
  #21 0x7ff0844fabf7 __libc_start_main 
/build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:344:0
  #22 0x0075e76a _start 
(/data/repo/master/llvm/build-all/bin/opt+0x75e76a)

F15612676: bbi-53212.ll 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94376

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-02-22 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD created this revision.
RedDocMD added reviewers: NoQ, vsavchenko, dcoughlin.
Herald added subscribers: steakhal, ASDenysPetrov, martong, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
RedDocMD requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Removed a TODO by adding a note-tag to explain where the
raw pointer came from.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp


Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,7 +306,7 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -457,8 +457,15 @@
 
   State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
   InnerPointerVal);
-  // TODO: Add NoteTag, for how the raw pointer got using 'get' method.
-  C.addTransition(State);
+
+  C.addTransition(State, C.getNoteTag([ThisRegion](PathSensitiveBugReport &BR,
+   llvm::raw_ostream &OS) {
+if (&BR.getBugType() != smartptr::getNullDereferenceBugType() ||
+!BR.isInteresting(ThisRegion))
+  return;
+OS << "Obtained null inner pointer from";
+checkAndPrettyPrintRegion(OS, ThisRegion);
+  }));
 }
 
 bool SmartPtrModeling::handleAssignOp(const CallEvent &Call,


Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,7 +306,7 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -457,8 +457,15 @@
 
   State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
   InnerPointerVal);
-  // TODO: Add NoteTag, for how the raw pointer got using 'get' method.
-  C.addTransition(State);
+
+  C.addTransition(State, C.getNoteTag([ThisRegion](PathSensitiveBugReport &BR,
+   llvm::raw_ostream &OS) {
+if (&BR.getBugType() != smartptr::getNullDereferenceBugType() ||
+!BR.isInteresting(ThisRegion))
+  return;
+OS << "Obtained null inner pointer from";
+checkAndPrettyPrintRegion(OS, ThisRegion);
+  }));
 }
 
 bool SmartPtrModeling::handleAssignOp(const CallEvent &Call,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-02-22 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

@NoQ, @vsavchenko could you please review this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[clang] bf15697 - [clang][cli] Stop creating '-Wno-stdlibcxx-not-found' in cc1

2021-02-22 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-02-22T09:53:25+01:00
New Revision: bf15697e9b66b8f7e6f3f7c510a259651810bd29

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

LOG: [clang][cli] Stop creating '-Wno-stdlibcxx-not-found' in cc1

This patch stops creating the '-Wno-stdlibcxx-not-found' argument in 
`CompilerInvocation::CreateFromArgs`.

The code was added in 2e7ab55e657f (a follow-up to D48297). However, D61963 
removes relevant tests and starts explicitly passing '-Wno-stdlibcxx-not-found' 
to the driver. I think it's fair to assume this is a dead code.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index a49c97860324..45fb4f60a396 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4588,12 +4588,6 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
  Res.getPreprocessorOpts().Includes, Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   LangOpts.ObjCExceptions = 1;
-if (T.isOSDarwin() && DashX.isPreprocessed()) {
-  // Supress the darwin-specific 'stdlibcxx-not-found' diagnostic for
-  // preprocessed input as we don't expect it to be used with -std=libc++
-  // anyway.
-  Res.getDiagnosticOpts().Warnings.push_back("no-stdlibcxx-not-found");
-}
   }
 
   if (LangOpts.CUDA) {



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


[PATCH] D97042: [clang][cli] Stop creating '-Wno-stdlibcxx-not-found' in cc1

2021-02-22 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf15697e9b66: [clang][cli] Stop creating 
'-Wno-stdlibcxx-not-found' in cc1 (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97042

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4588,12 +4588,6 @@
  Res.getPreprocessorOpts().Includes, Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   LangOpts.ObjCExceptions = 1;
-if (T.isOSDarwin() && DashX.isPreprocessed()) {
-  // Supress the darwin-specific 'stdlibcxx-not-found' diagnostic for
-  // preprocessed input as we don't expect it to be used with -std=libc++
-  // anyway.
-  Res.getDiagnosticOpts().Warnings.push_back("no-stdlibcxx-not-found");
-}
   }
 
   if (LangOpts.CUDA) {


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4588,12 +4588,6 @@
  Res.getPreprocessorOpts().Includes, Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   LangOpts.ObjCExceptions = 1;
-if (T.isOSDarwin() && DashX.isPreprocessed()) {
-  // Supress the darwin-specific 'stdlibcxx-not-found' diagnostic for
-  // preprocessed input as we don't expect it to be used with -std=libc++
-  // anyway.
-  Res.getDiagnosticOpts().Warnings.push_back("no-stdlibcxx-not-found");
-}
   }
 
   if (LangOpts.CUDA) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 820e0c4 - [clang][cli] Pass '-Wspir-compat' to cc1 from driver

2021-02-22 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-02-22T09:54:44+01:00
New Revision: 820e0c49fc48024d8b426f4b10b50b5b5659a705

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

LOG: [clang][cli] Pass '-Wspir-compat' to cc1 from driver

This patch moves the creation of the '-Wspir-compat' argument from cc1 to the 
driver.

Without this change, generating command line arguments from 
`CompilerInvocation` cannot be done reliably: there's no way to distinguish 
whether '-Wspir-compat' was passed to cc1 on the command line (should be 
generated), or if it was created within `CompilerInvocation::CreateFromArgs` 
(should not be generated).

This is also in line with how other '-W' flags are handled.

(This was introduced in D21567.)

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/opencl.cl
clang/test/SemaOpenCL/sampler_t.cl

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 180d9cfec225..386bec831175 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4264,6 +4264,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // are provided.
   TC.addClangWarningOptions(CmdArgs);
 
+  // FIXME: Subclass ToolChain for SPIR and move this to 
addClangWarningOptions.
+  if (Triple.isSPIR())
+CmdArgs.push_back("-Wspir-compat");
+
   // Select the appropriate action.
   RewriteKind rewriteKind = RK_None;
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 45fb4f60a396..a870940ac110 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4628,10 +4628,6 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
 Success = false;
   }
 
-  // Turn on -Wspir-compat for SPIR target.
-  if (T.isSPIR())
-Res.getDiagnosticOpts().Warnings.push_back("spir-compat");
-
   // If sanitizer is enabled, disable OPT_ffine_grained_bitfield_accesses.
   if (Res.getCodeGenOpts().FineGrainedBitfieldAccesses &&
   !Res.getLangOpts()->Sanitize.empty()) {

diff  --git a/clang/test/Driver/opencl.cl b/clang/test/Driver/opencl.cl
index 44ae12330662..b6a9b8a32448 100644
--- a/clang/test/Driver/opencl.cl
+++ b/clang/test/Driver/opencl.cl
@@ -19,6 +19,8 @@
 // RUN: %clang -S -### -cl-uniform-work-group-size %s 2>&1 | FileCheck 
--check-prefix=CHECK-UNIFORM-WG %s
 // RUN: not %clang -cl-std=c99 -DOPENCL %s 2>&1 | FileCheck 
--check-prefix=CHECK-C99 %s
 // RUN: not %clang -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck 
--check-prefix=CHECK-INVALID %s
+// RUN: %clang -S -### -target spir-unknown-unknown %s 2>&1 | FileCheck 
--check-prefix=CHECK-W-SPIR-COMPAT %s
+// RUN: %clang -S -### -target amdgcn-amd-amdhsa-opencl %s 2>&1 | FileCheck 
--check-prefix=CHECK-NO-W-SPIR-COMPAT %s
 
 // CHECK-CL: "-cc1" {{.*}} "-cl-std=CL"
 // CHECK-CL10: "-cc1" {{.*}} "-cl-std=CL1.0"
@@ -45,4 +47,7 @@
 // CHECK-C99: error: invalid value 'c99' in '-cl-std=c99'
 // CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid'
 
+// CHECK-W-SPIR-COMPAT: "-Wspir-compat"
+// CHECK-NO-W-SPIR-COMPAT-NOT: "-Wspir-compat"
+
 kernel void func(void);

diff  --git a/clang/test/SemaOpenCL/sampler_t.cl 
b/clang/test/SemaOpenCL/sampler_t.cl
index 888e973cc31d..a9fcab7faf06 100644
--- a/clang/test/SemaOpenCL/sampler_t.cl
+++ b/clang/test/SemaOpenCL/sampler_t.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE 
-Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE 
-triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE 
-Wspir-compat -triple spir-unknown-unknown
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only 
-DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only 
-DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only 
-DCHECK_SAMPLER_VALUE -Wspir-compat -triple spir-unknown-unknown
 
 #define CLK_ADDRESS_CLAMP_TO_EDGE   2
 #define CLK_NORMALIZED_COORDS_TRUE  1



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


[PATCH] D97041: [clang][cli] Pass '-Wspir-compat' to cc1 from driver

2021-02-22 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG820e0c49fc48: [clang][cli] Pass '-Wspir-compat' to 
cc1 from driver (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97041

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/opencl.cl
  clang/test/SemaOpenCL/sampler_t.cl


Index: clang/test/SemaOpenCL/sampler_t.cl
===
--- clang/test/SemaOpenCL/sampler_t.cl
+++ clang/test/SemaOpenCL/sampler_t.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE 
-Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE 
-triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE 
-Wspir-compat -triple spir-unknown-unknown
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only 
-DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only 
-DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only 
-DCHECK_SAMPLER_VALUE -Wspir-compat -triple spir-unknown-unknown
 
 #define CLK_ADDRESS_CLAMP_TO_EDGE   2
 #define CLK_NORMALIZED_COORDS_TRUE  1
Index: clang/test/Driver/opencl.cl
===
--- clang/test/Driver/opencl.cl
+++ clang/test/Driver/opencl.cl
@@ -19,6 +19,8 @@
 // RUN: %clang -S -### -cl-uniform-work-group-size %s 2>&1 | FileCheck 
--check-prefix=CHECK-UNIFORM-WG %s
 // RUN: not %clang -cl-std=c99 -DOPENCL %s 2>&1 | FileCheck 
--check-prefix=CHECK-C99 %s
 // RUN: not %clang -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck 
--check-prefix=CHECK-INVALID %s
+// RUN: %clang -S -### -target spir-unknown-unknown %s 2>&1 | FileCheck 
--check-prefix=CHECK-W-SPIR-COMPAT %s
+// RUN: %clang -S -### -target amdgcn-amd-amdhsa-opencl %s 2>&1 | FileCheck 
--check-prefix=CHECK-NO-W-SPIR-COMPAT %s
 
 // CHECK-CL: "-cc1" {{.*}} "-cl-std=CL"
 // CHECK-CL10: "-cc1" {{.*}} "-cl-std=CL1.0"
@@ -45,4 +47,7 @@
 // CHECK-C99: error: invalid value 'c99' in '-cl-std=c99'
 // CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid'
 
+// CHECK-W-SPIR-COMPAT: "-Wspir-compat"
+// CHECK-NO-W-SPIR-COMPAT-NOT: "-Wspir-compat"
+
 kernel void func(void);
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4628,10 +4628,6 @@
 Success = false;
   }
 
-  // Turn on -Wspir-compat for SPIR target.
-  if (T.isSPIR())
-Res.getDiagnosticOpts().Warnings.push_back("spir-compat");
-
   // If sanitizer is enabled, disable OPT_ffine_grained_bitfield_accesses.
   if (Res.getCodeGenOpts().FineGrainedBitfieldAccesses &&
   !Res.getLangOpts()->Sanitize.empty()) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4264,6 +4264,10 @@
   // are provided.
   TC.addClangWarningOptions(CmdArgs);
 
+  // FIXME: Subclass ToolChain for SPIR and move this to 
addClangWarningOptions.
+  if (Triple.isSPIR())
+CmdArgs.push_back("-Wspir-compat");
+
   // Select the appropriate action.
   RewriteKind rewriteKind = RK_None;
 


Index: clang/test/SemaOpenCL/sampler_t.cl
===
--- clang/test/SemaOpenCL/sampler_t.cl
+++ clang/test/SemaOpenCL/sampler_t.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple spir-unknown-unknown
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple spir-unknown-unknown
 
 #define CLK_ADDRESS_CLAMP_TO_EDGE   2
 #define CLK_NORMALIZED_COORDS_TRUE  1
Index: clang/test/Drive

[clang] f101373 - [clang][CodeComplete] Ensure there are no crashes when completing with ParenListExprs as LHS

2021-02-22 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-02-22T10:01:22+01:00
New Revision: f10137399a3c9239a6acd1d3df12a40766b64759

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

LOG: [clang][CodeComplete] Ensure there are no crashes when completing with 
ParenListExprs as LHS

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

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 1e4d5dd62aa0..2feb02bbe4ed 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5245,6 +5245,19 @@ QualType getApproximateType(const Expr *E) {
   return Unresolved;
 }
 
+// If \p Base is ParenListExpr, assume a chain of comma operators and pick the
+// last expr. We expect other ParenListExprs to be resolved to e.g. constructor
+// calls before here. (So the ParenListExpr should be nonempty, but check just
+// in case)
+Expr *unwrapParenList(Expr *Base) {
+  if (auto *PLE = llvm::dyn_cast_or_null(Base)) {
+if (PLE->getNumExprs() == 0)
+  return nullptr;
+Base = PLE->getExpr(PLE->getNumExprs() - 1);
+  }
+  return Base;
+}
+
 } // namespace
 
 void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
@@ -5252,18 +5265,11 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, 
Expr *Base,
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement,
QualType PreferredType) {
+  Base = unwrapParenList(Base);
+  OtherOpBase = unwrapParenList(OtherOpBase);
   if (!Base || !CodeCompleter)
 return;
 
-  // Peel off the ParenListExpr by chosing the last one, as they don't have a
-  // predefined type.
-  if (auto *PLE = llvm::dyn_cast(Base))
-Base = PLE->getExpr(PLE->getNumExprs() - 1);
-  if (OtherOpBase) {
-if (auto *PLE = llvm::dyn_cast(OtherOpBase))
-  OtherOpBase = PLE->getExpr(PLE->getNumExprs() - 1);
-  }
-
   ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
   if (ConvertedBase.isInvalid())
 return;
@@ -5693,14 +5699,10 @@ ProduceSignatureHelp(Sema &SemaRef, Scope *S,
 QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
 ArrayRef Args,
 SourceLocation OpenParLoc) {
+  Fn = unwrapParenList(Fn);
   if (!CodeCompleter || !Fn)
 return QualType();
 
-  // If we have a ParenListExpr for LHS, peel it off by chosing the last expr.
-  // As ParenListExprs don't have a predefined type.
-  if (auto *PLE = llvm::dyn_cast(Fn))
-Fn = PLE->getExpr(PLE->getNumExprs() - 1);
-
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.
   if (Fn->isTypeDependent() || anyNullArguments(Args))



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


[PATCH] D96950: [clang][CodeComplete] Ensure there are no crashes when completing with ParenListExprs as LHS

2021-02-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf10137399a3c: [clang][CodeComplete] Ensure there are no 
crashes when completing with… (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96950

Files:
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5245,6 +5245,19 @@
   return Unresolved;
 }
 
+// If \p Base is ParenListExpr, assume a chain of comma operators and pick the
+// last expr. We expect other ParenListExprs to be resolved to e.g. constructor
+// calls before here. (So the ParenListExpr should be nonempty, but check just
+// in case)
+Expr *unwrapParenList(Expr *Base) {
+  if (auto *PLE = llvm::dyn_cast_or_null(Base)) {
+if (PLE->getNumExprs() == 0)
+  return nullptr;
+Base = PLE->getExpr(PLE->getNumExprs() - 1);
+  }
+  return Base;
+}
+
 } // namespace
 
 void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
@@ -5252,18 +5265,11 @@
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement,
QualType PreferredType) {
+  Base = unwrapParenList(Base);
+  OtherOpBase = unwrapParenList(OtherOpBase);
   if (!Base || !CodeCompleter)
 return;
 
-  // Peel off the ParenListExpr by chosing the last one, as they don't have a
-  // predefined type.
-  if (auto *PLE = llvm::dyn_cast(Base))
-Base = PLE->getExpr(PLE->getNumExprs() - 1);
-  if (OtherOpBase) {
-if (auto *PLE = llvm::dyn_cast(OtherOpBase))
-  OtherOpBase = PLE->getExpr(PLE->getNumExprs() - 1);
-  }
-
   ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
   if (ConvertedBase.isInvalid())
 return;
@@ -5693,14 +5699,10 @@
 QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
 ArrayRef Args,
 SourceLocation OpenParLoc) {
+  Fn = unwrapParenList(Fn);
   if (!CodeCompleter || !Fn)
 return QualType();
 
-  // If we have a ParenListExpr for LHS, peel it off by chosing the last expr.
-  // As ParenListExprs don't have a predefined type.
-  if (auto *PLE = llvm::dyn_cast(Fn))
-Fn = PLE->getExpr(PLE->getNumExprs() - 1);
-
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.
   if (Fn->isTypeDependent() || anyNullArguments(Args))


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5245,6 +5245,19 @@
   return Unresolved;
 }
 
+// If \p Base is ParenListExpr, assume a chain of comma operators and pick the
+// last expr. We expect other ParenListExprs to be resolved to e.g. constructor
+// calls before here. (So the ParenListExpr should be nonempty, but check just
+// in case)
+Expr *unwrapParenList(Expr *Base) {
+  if (auto *PLE = llvm::dyn_cast_or_null(Base)) {
+if (PLE->getNumExprs() == 0)
+  return nullptr;
+Base = PLE->getExpr(PLE->getNumExprs() - 1);
+  }
+  return Base;
+}
+
 } // namespace
 
 void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
@@ -5252,18 +5265,11 @@
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement,
QualType PreferredType) {
+  Base = unwrapParenList(Base);
+  OtherOpBase = unwrapParenList(OtherOpBase);
   if (!Base || !CodeCompleter)
 return;
 
-  // Peel off the ParenListExpr by chosing the last one, as they don't have a
-  // predefined type.
-  if (auto *PLE = llvm::dyn_cast(Base))
-Base = PLE->getExpr(PLE->getNumExprs() - 1);
-  if (OtherOpBase) {
-if (auto *PLE = llvm::dyn_cast(OtherOpBase))
-  OtherOpBase = PLE->getExpr(PLE->getNumExprs() - 1);
-  }
-
   ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
   if (ConvertedBase.isInvalid())
 return;
@@ -5693,14 +5699,10 @@
 QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
 ArrayRef Args,
 SourceLocation OpenParLoc) {
+  Fn = unwrapParenList(Fn);
   if (!CodeCompleter || !Fn)
 return QualType();
 
-  // If we have a ParenListExpr for LHS, peel it off by chosing the last expr.
-  // As ParenListExprs don't have a predefined type.
-  if (auto *PLE = llvm::dyn_cast(Fn))
-Fn = PLE->getExpr(PLE->getNumExprs() - 1);
-
   // FIXME: Provide support for variadic template functions.
   // Ignore type-depend

[PATCH] D96777: [clang][driver] Set the input type to Fortran when reading from stdin

2021-02-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a subscriber: hans.
awarzynski added a comment.

In D96777#2578153 , @SouraVX wrote:

> Thanks! for the patch.
> This code touches some of the `clang` part, Anyway changes are pretty 
> self-explanatory. I'll leave this one to you, if you want land it or wait 
> from someone from `clang` community to take a look :)

Thank you for reviewing!

Git history tells me that @hans touched this bit most recently - in 2014 :) 
Added as a reviewer - I will wait another day or two before merging.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96777

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


[PATCH] D97138: [Driver] replace argc_ with argc

2021-02-22 Thread James Henderson via Phabricator via cfe-commits
jhenderson resigned from this revision.
jhenderson added a comment.

In general, I don't work on the clang side. As such, I don't know the norms 
surrounding this sort of change in this area, and don't feel comfortable 
reviewing. You should look at getting reviewers who do work in that part of the 
repository.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97138

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


[PATCH] D97158: [ASTMatchers] Make nullPointerConstant usable at top-level

2021-02-22 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 325398.
steveire added a comment.

Update docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97158

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


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3660,10 +3660,10 @@
 TEST_P(ASTMatchersTest, NullPointerConstant) {
   EXPECT_TRUE(matches("#define NULL ((void *)0)\n"
   "void *v1 = NULL;",
-  expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
+  nullPointerConstant()));
+  EXPECT_TRUE(matches("char *cp = (char *)0;", nullPointerConstant()));
+  EXPECT_TRUE(matches("int *ip = 0;", nullPointerConstant()));
+  EXPECT_FALSE(matches("int i = 0;", nullPointerConstant()));
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7381,13 +7381,13 @@
 ///   int *ip = 0;
 ///   int i = 0;
 /// \endcode
-/// expr(nullPointerConstant())
+/// nullPointerConstant()
 ///   matches the initializer for v1, v2, v3, cp, and ip. Does not match the
 ///   initializer for i.
-AST_MATCHER_FUNCTION(internal::Matcher, nullPointerConstant) {
-  return anyOf(
+AST_MATCHER_FUNCTION(internal::BindableMatcher, nullPointerConstant) {
+  return stmt(anyOf(
   gnuNullExpr(), cxxNullPtrLiteralExpr(),
-  integerLiteral(equals(0), hasParent(expr(hasType(pointerType());
+  integerLiteral(equals(0), hasParent(expr(hasType(pointerType()));
 }
 
 /// Matches the DecompositionDecl the binding belongs to.
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -3917,23 +3917,6 @@
 
 
 
-MatcherExpr>nullPointerConstant
-Matches 
expressions that resolve to a null pointer constant, such as
-GNU's __null, C++11's nullptr, or C's NULL macro.
-
-Given:
-  void *v1 = NULL;
-  void *v2 = nullptr;
-  void *v3 = __null; // GNU extension
-  char *cp = (char *)0;
-  int *ip = 0;
-  int i = 0;
-expr(nullPointerConstant())
-  matches the initializer for v1, v2, v3, cp, and ip. Does not match the
-  initializer for i.
-
-
-
 MatcherFieldDecl>hasBitWidthunsigned Width
 Matches non-static data 
members that are bit-fields of the specified
 bit width.
@@ -5038,6 +5021,23 @@
 
 
 
+MatcherStmt>nullPointerConstant
+Matches 
expressions that resolve to a null pointer constant, such as
+GNU's __null, C++11's nullptr, or C's NULL macro.
+
+Given:
+  void *v1 = NULL;
+  void *v2 = nullptr;
+  void *v3 = __null; // GNU extension
+  char *cp = (char *)0;
+  int *ip = 0;
+  int i = 0;
+nullPointerConstant()
+  matches the initializer for v1, v2, v3, cp, and ip. Does not match the
+  initializer for i.
+
+
+
 MatcherStringLiteral>hasSizeunsigned N
 Matches nodes that have the 
specified size.
 


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3660,10 +3660,10 @@
 TEST_P(ASTMatchersTest, NullPointerConstant) {
   EXPECT_TRUE(matches("#define NULL ((void *)0)\n"
   "void *v1 = NULL;",
-  expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
+  nullPointerConstant()));
+  EXPECT_TRUE(matches("char *cp = (char *)0;", nullPointerConstant()));
+  EXPECT_TRUE(matches("int *ip = 0;", nullPointerConstant()));
+  EXPECT_FALSE(matches("int i = 0;", nullPointerConstant()));
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- cl

[clang] 6e30710 - [analyzer] Introduce MacroExpansionContext to libAnalysis

2021-02-22 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-02-22T11:11:57+01:00
New Revision: 6e3071007b4c9438d2ae49476de87db30d6d24e9

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

LOG: [analyzer] Introduce MacroExpansionContext to libAnalysis

Introduce `MacroExpansionContext` to track what and how macros in a translation
unit expand. This is the first element of the patch-stack in this direction.

The main goal is to substitute the current macro expansion generator in the
`PlistsDiagnostics`, but all the other `DiagnosticsConsumer` could benefit from
this.

`getExpandedText` and `getOriginalText` are the primary functions of this class.
The former can provide you the text that was the result of the macro expansion
chain starting from a `SourceLocation`.
While the latter will tell you **what text** was in the original source code
replaced by the macro expansion chain from that location.

Here is an example:

  void bar();
  #define retArg(x) x
  #define retArgUnclosed retArg(bar()
  #define BB CC
  #define applyInt BB(int)
  #define CC(x) retArgUnclosed

  void unbalancedMacros() {
applyInt  );
  //^~^ is the substituted range
  // Original text is "applyInt  )"
  // Expanded text is "bar()"
  }

  #define expandArgUnclosedCommaExpr(x) (x, bar(), 1
  #define f expandArgUnclosedCommaExpr

  void unbalancedMacros2() {
int x =  f(f(1))  ));  // Look at the parenthesis!
  // ^~^ is the substituted range
  // Original text is "f(f(1))"
  // Expanded text is "((1,bar(),1,bar(),1"
  }

Might worth investigating how to provide a reusable component, which could be
used for example by a standalone tool eg. expanding all macros to their
definitions.

I borrowed the main idea from the `PrintPreprocessedOutput.cpp` Frontend
component, providing a `PPCallbacks` instance hooking the preprocessor events.
I'm using that for calculating the source range where tokens will be expanded
to. I'm also using the `Preprocessor`'s `OnToken` callback, via the
`Preprocessor::setTokenWatcher` to reconstruct the expanded text.

Unfortunately, I concatenate the token's string representation without any
whitespaces except if the token is an identifier when I emit an extra space
to produce valid code for `int var` token sequences.
This could be improved later if needed.

Patch-stack:
  1) D93222 (this one) Introduces the MacroExpansionContext class and unittests

  2) D93223 Create MacroExpansionContext member in AnalysisConsumer and pass
 down to the diagnostics consumers

  3) D93224 Use the MacroExpansionContext for macro expansions in plists
 It replaces the 'old' macro expansion mechanism.

  4) D94673 API for CTU macro expansions
 You should be able to get a `MacroExpansionContext` for each imported TU.
 Right now it will just return `llvm::None` as this is not implemented yet.

  5) FIXME: Implement macro expansion tracking for imported TUs as well.

It would also relieve us from bugs like:
  - [fixed] D86135
  - [confirmed] The `__VA_ARGS__` and other macro nitty-gritty, such as how to
stringify macro parameters, where to put or swallow commas, etc. are not
handled correctly.
  - [confirmed] Unbalanced parenthesis are not well handled - resulting in
incorrect expansions or even crashes.
  - [confirmed][crashing] https://bugs.llvm.org/show_bug.cgi?id=48358

Reviewed By: martong, Szelethus

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

Added: 
clang/include/clang/Analysis/MacroExpansionContext.h
clang/lib/Analysis/MacroExpansionContext.cpp
clang/unittests/Analysis/MacroExpansionContextTest.cpp

Modified: 
clang/lib/Analysis/CMakeLists.txt
clang/unittests/Analysis/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Analysis/MacroExpansionContext.h 
b/clang/include/clang/Analysis/MacroExpansionContext.h
new file mode 100644
index ..57934bfc09d9
--- /dev/null
+++ b/clang/include/clang/Analysis/MacroExpansionContext.h
@@ -0,0 +1,127 @@
+//===- MacroExpansionContext.h - Macro expansion information *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_MACROEXPANSIONCONTEXT_H
+#define LLVM_CLANG_ANALYSIS_MACROEXPANSIONCONTEXT_H
+
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+
+namespace detail {
+class MacroExpansionRangeRe

[clang] 7c58fb6 - [analyzer] Create MacroExpansionContext member in AnalysisConsumer

2021-02-22 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-02-22T11:12:14+01:00
New Revision: 7c58fb6ba04e28e594587bb27f13849cc1f2d305

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

LOG: [analyzer] Create MacroExpansionContext member in AnalysisConsumer

Adds a `MacroExpansionContext` member to the `AnalysisConsumer` class.
Tracks macro expansions only if the `ShouldDisplayMacroExpansions` is set.
Passes a reference down the pipeline letting AnalysisConsumers query macro
expansions during bugreport construction.

Reviewed By: martong, Szelethus

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h 
b/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
index f40f88eb32ff..71a590d9e9a2 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
@@ -21,7 +21,9 @@
 namespace clang {
 
 class AnalyzerOptions;
+class MacroExpansionContext;
 class Preprocessor;
+
 namespace cross_tu {
 class CrossTranslationUnitContext;
 }
@@ -35,7 +37,8 @@ typedef std::vector 
PathDiagnosticConsumers;
   void CREATEFN(PathDiagnosticConsumerOptions Diagopts,
\
 PathDiagnosticConsumers &C, const std::string &Prefix, 
\
 const Preprocessor &PP,
\
-const cross_tu::CrossTranslationUnitContext &CTU);
+const cross_tu::CrossTranslationUnitContext &CTU,  
\
+const MacroExpansionContext &MacroExpansions);
 #include "clang/StaticAnalyzer/Core/Analyses.def"
 
 } // end 'ento' namespace

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 46e533d9680e..fe530bce4a3e 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -10,11 +10,12 @@
 //
 
//===--===//
 
-#include "clang/Analysis/IssueHash.h"
-#include "clang/Analysis/PathDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Analysis/IssueHash.h"
+#include "clang/Analysis/MacroExpansionContext.h"
+#include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
@@ -135,14 +136,16 @@ class HTMLDiagnostics : public PathDiagnosticConsumer {
 void ento::createHTMLDiagnosticConsumer(
 PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
 const std::string &OutputDir, const Preprocessor &PP,
-const cross_tu::CrossTranslationUnitContext &CTU) {
+const cross_tu::CrossTranslationUnitContext &CTU,
+const MacroExpansionContext &MacroExpansions) {
 
   // 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(DiagOpts, C, OutputDir, PP, CTU);
+  createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU,
+  MacroExpansions);
 
   // TODO: Emit an error here.
   if (OutputDir.empty())
@@ -154,8 +157,10 @@ void ento::createHTMLDiagnosticConsumer(
 void ento::createHTMLSingleFileDiagnosticConsumer(
 PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
 const std::string &OutputDir, const Preprocessor &PP,
-const cross_tu::CrossTranslationUnitContext &CTU) {
-  createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU);
+const cross_tu::CrossTranslationUnitContext &CTU,
+const clang::MacroExpansionContext &MacroExpansions) {
+  createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU,
+  MacroExpansions);
 
   // TODO: Emit an error here.
   if (OutputDir.empty())
@@ -167,23 +172,29 @@ void ento::createHTMLSingleFileDiagnosticConsumer(
 void ento::createPlistHTMLDiagnosticConsumer(

[PATCH] D93222: [analyzer] Introduce MacroExpansionContext to libAnalysis

2021-02-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6e3071007b4c: [analyzer] Introduce MacroExpansionContext to 
libAnalysis (authored by steakhal, committed by Balazs Benics 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93222

Files:
  clang/include/clang/Analysis/MacroExpansionContext.h
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/MacroExpansionContext.cpp
  clang/unittests/Analysis/CMakeLists.txt
  clang/unittests/Analysis/MacroExpansionContextTest.cpp

Index: clang/unittests/Analysis/MacroExpansionContextTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -0,0 +1,424 @@
+//===- unittests/Analysis/MacroExpansionContextTest.cpp - -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/MacroExpansionContext.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Parse/Parser.h"
+#include "llvm/ADT/SmallString.h"
+#include "gtest/gtest.h"
+
+// static bool HACK_EnableDebugInUnitTest = (::llvm::DebugFlag = true);
+
+namespace clang {
+namespace analysis {
+namespace {
+
+class MacroExpansionContextTest : public ::testing::Test {
+protected:
+  MacroExpansionContextTest()
+  : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
+FileMgr(FileSystemOptions(), InMemoryFileSystem),
+DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
+Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) {
+TargetOpts->Triple = "x86_64-pc-linux-unknown";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+LangOpts.CPlusPlus20 = 1; // For __VA_OPT__
+  }
+
+  IntrusiveRefCntPtr InMemoryFileSystem;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  IntrusiveRefCntPtr DiagOpts;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+
+  std::unique_ptr
+  getMacroExpansionContextFor(StringRef SourceText) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+TrivialModuleLoader ModLoader;
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+Preprocessor PP(std::make_shared(), Diags, LangOpts,
+SourceMgr, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+
+PP.Initialize(*Target);
+auto Ctx = std::make_unique(LangOpts);
+Ctx->registerForPreprocessor(PP);
+
+// Lex source text.
+PP.EnterMainSourceFile();
+
+while (true) {
+  Token Tok;
+  PP.Lex(Tok);
+  if (Tok.is(tok::eof))
+break;
+}
+
+// Callbacks have been executed at this point.
+return Ctx;
+  }
+
+  /// Returns the expansion location to main file at the given row and column.
+  SourceLocation at(unsigned row, unsigned col) const {
+SourceLocation Loc =
+SourceMgr.translateLineCol(SourceMgr.getMainFileID(), row, col);
+return SourceMgr.getExpansionLoc(Loc);
+  }
+
+  static std::string dumpExpandedTexts(const MacroExpansionContext &Ctx) {
+std::string Buf;
+llvm::raw_string_ostream OS{Buf};
+Ctx.dumpExpandedTextsToStream(OS);
+return OS.str();
+  }
+
+  static std::string dumpExpansionRanges(const MacroExpansionContext &Ctx) {
+std::string Buf;
+llvm::raw_string_ostream OS{Buf};
+Ctx.dumpExpansionRangesToStream(OS);
+return OS.str();
+  }
+};
+
+TEST_F(MacroExpansionContextTest, IgnoresPragmas) {
+  // No-crash during lexing.
+  const auto Ctx = getMacroExpansionContextFor(R"code(
+  _Pragma("pack(push, 1)")
+  _Pragma("pack(pop, 1)")
+  )code");
+  // After preprocessing:
+  // #pragma pack(push, 1)
+  // #pragma pack(pop, 1)
+
+  EXPECT_EQ("\n=== ExpandedTokens ===\n",
+dumpExpandedTexts(*Ctx));
+  EXPECT_EQ("\n=== Expa

[PATCH] D93223: [analyzer] Create MacroExpansionContext member in AnalysisConsumer

2021-02-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c58fb6ba04e: [analyzer] Create MacroExpansionContext member 
in AnalysisConsumer (authored by steakhal, committed by Balazs Benics 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93223

Files:
  clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -20,6 +20,7 @@
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CallGraph.h"
 #include "clang/Analysis/CodeInjector.h"
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
@@ -98,6 +99,8 @@
   /// working with a PCH file.
   SetOfDecls LocalTUDecls;
 
+  MacroExpansionContext MacroExpansions;
+
   // Set of PathDiagnosticConsumers.  Owned by AnalysisManager.
   PathDiagnosticConsumers PathConsumers;
 
@@ -122,7 +125,8 @@
CodeInjector *injector)
   : RecVisitorMode(0), RecVisitorBR(nullptr), Ctx(nullptr),
 PP(CI.getPreprocessor()), OutDir(outdir), Opts(std::move(opts)),
-Plugins(plugins), Injector(injector), CTU(CI) {
+Plugins(plugins), Injector(injector), CTU(CI),
+MacroExpansions(CI.getLangOpts()) {
 DigestAnalyzerOptions();
 if (Opts->PrintStats || Opts->ShouldSerializeStats) {
   AnalyzerTimers = std::make_unique(
@@ -136,6 +140,9 @@
   *AnalyzerTimers);
   llvm::EnableStatistics(/* PrintOnExit= */ false);
 }
+
+if (Opts->ShouldDisplayMacroExpansions)
+  MacroExpansions.registerForPreprocessor(PP);
   }
 
   ~AnalysisConsumer() override {
@@ -150,7 +157,8 @@
   break;
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)\
   case PD_##NAME:  \
-CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU); \
+CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU,  \
+ MacroExpansions); \
 break;
 #include "clang/StaticAnalyzer/Core/Analyses.def"
 default:
Index: clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
@@ -138,8 +139,9 @@
 
 void ento::createTextPathDiagnosticConsumer(
 PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
-const std::string &Prefix, const clang::Preprocessor &PP,
-const cross_tu::CrossTranslationUnitContext &CTU) {
+const std::string &Prefix, const Preprocessor &PP,
+const cross_tu::CrossTranslationUnitContext &CTU,
+const MacroExpansionContext &MacroExpansions) {
   C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
  PP.getLangOpts(),
  /*ShouldDisplayPathNotes=*/true));
@@ -147,8 +149,9 @@
 
 void ento::createTextMinimalPathDiagnosticConsumer(
 PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
-const std::string &Prefix, const clang::Preprocessor &PP,
-const cross_tu::CrossTranslationUnitContext &CTU) {
+const std::string &Prefix, const Preprocessor &PP,
+const cross_tu::CrossTranslationUnitContext &CTU,
+const MacroExpansionContext &MacroExpansions) {
   C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
  PP.getLangOpts(),
  /*ShouldDisplayPathNotes=*/false));
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clan

[clang] 38b1858 - [analyzer][CTU] API for CTU macro expansions

2021-02-22 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-02-22T11:12:22+01:00
New Revision: 38b185832e04ed0588c43161f5c3a8c0ce267497

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

LOG: [analyzer][CTU] API for CTU macro expansions

Removes `CrossTranslationUnitContext::getImportedFromSourceLocation`
Removes the corresponding unit-test segment.

Introduces the 
`CrossTranslationUnitContext::getMacroExpansionContextForSourceLocation`
which will return the macro expansion context for an imported TU. Also adds a
few implementation FIXME notes where applicable, since this feature is
not implemented yet. This fact is also noted as Doxygen comments.

Uplifts a few CTU LIT test to match the current **incomplete** behavior.

It is a regression to some extent since now we don't expand any
macros in imported TUs. At least we don't crash anymore.

Note that the introduced function is already covered by LIT tests.
Eg.: Analysis/plist-macros-with-expansion-ctu.c

Reviewed By: balazske, Szelethus

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

Added: 


Modified: 
clang/include/clang/AST/ASTImporter.h
clang/include/clang/CrossTU/CrossTranslationUnit.h
clang/lib/AST/ASTImporter.cpp
clang/lib/CrossTU/CrossTranslationUnit.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
clang/test/Analysis/plist-macros-with-expansion-ctu.c
clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTImporter.h 
b/clang/include/clang/AST/ASTImporter.h
index a6d822ba2ea6..630d220deff7 100644
--- a/clang/include/clang/AST/ASTImporter.h
+++ b/clang/include/clang/AST/ASTImporter.h
@@ -93,8 +93,6 @@ class TypeSourceInfo;
 using NonEquivalentDeclSet = llvm::DenseSet>;
 using ImportedCXXBaseSpecifierMap =
 llvm::DenseMap;
-using FileIDImportHandlerType =
-std::function;
 
 enum class ODRHandlingType { Conservative, Liberal };
 
@@ -220,8 +218,6 @@ class TypeSourceInfo;
 };
 
   private:
-FileIDImportHandlerType FileIDImportHandler;
-
 std::shared_ptr SharedState = nullptr;
 
 /// The path which we go through during the import of a given AST node.
@@ -324,14 +320,6 @@ class TypeSourceInfo;
 
 virtual ~ASTImporter();
 
-/// Set a callback function for FileID import handling.
-/// The function is invoked when a FileID is imported from the From 
context.
-/// The imported FileID in the To context and the original FileID in the
-/// From context is passed to it.
-void setFileIDImportHandler(FileIDImportHandlerType H) {
-  FileIDImportHandler = H;
-}
-
 /// Whether the importer will perform a minimal import, creating
 /// to-be-completed forward declarations when possible.
 bool isMinimalImport() const { return Minimal; }

diff  --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h 
b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index 027c6f16430b..b419b9be67cb 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
 
 #include "clang/AST/ASTImporterSharedState.h"
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
@@ -182,21 +183,18 @@ class CrossTranslationUnitContext {
   /// Emit diagnostics for the user for potential configuration errors.
   void emitCrossTUDiagnostics(const IndexError &IE);
 
-  /// Determine the original source location in the original TU for an
-  /// imported source location.
+  /// Returns the MacroExpansionContext for the imported TU to which the given
+  /// source-location corresponds.
   /// \p ToLoc Source location in the imported-to AST.
-  /// \return Source location in the imported-from AST and the corresponding
-  /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
-  /// object that is returned here).
-  /// If any error happens (ToLoc is a non-imported source location) empty is
-  /// returned.
-  llvm::Optional>
-  getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const;
+  /// \note If any error happens such as \p ToLoc is a non-imported
+  ///   source-location, empty is returned.
+  /// \note Macro expansion tracking for imported TUs is not implemented yet.
+  ///   It returns empty unconditionally.
+  llvm::Optional
+  getMacroExpansionContextForSourceLocation(
+  const clang::SourceLocation &ToLoc) const;
 
 private:
-  using ImportedFileIDMap =
-  llvm::DenseMap>;
-
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTUnit *Unit);
   template 
@@ -217,14 +215,6 @@ class CrossTranslationUn

[PATCH] D94673: [analyzer][CTU] API for CTU macro expansions

2021-02-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38b185832e04: [analyzer][CTU] API for CTU macro expansions 
(authored by steakhal, committed by Balazs Benics 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94673

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/test/Analysis/plist-macros-with-expansion-ctu.c
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -91,26 +91,6 @@
   *Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
 
   if (NewFD) {
-// Check GetImportedFromSourceLocation.
-llvm::Optional> SLocResult =
-CTU.getImportedFromSourceLocation(NewFD->getLocation());
-EXPECT_TRUE(SLocResult);
-if (SLocResult) {
-  SourceLocation OrigSLoc = (*SLocResult).first;
-  ASTUnit *OrigUnit = (*SLocResult).second;
-  // OrigUnit is created internally by CTU (is not the
-  // ASTWithDefinition).
-  TranslationUnitDecl *OrigTU =
-  OrigUnit->getASTContext().getTranslationUnitDecl();
-  const FunctionDecl *FDWithDefinition = FindFInTU(OrigTU);
-  EXPECT_TRUE(FDWithDefinition);
-  if (FDWithDefinition) {
-EXPECT_EQ(FDWithDefinition->getName(), "f");
-EXPECT_TRUE(FDWithDefinition->isThisDeclarationADefinition());
-EXPECT_EQ(OrigSLoc, FDWithDefinition->getLocation());
-  }
-}
-
 // Check parent map.
 const DynTypedNodeList ParentsAfterImport =
 Ctx.getParentMapContext().getParents(*FD);
Index: clang/test/Analysis/plist-macros-with-expansion-ctu.c
===
--- clang/test/Analysis/plist-macros-with-expansion-ctu.c
+++ clang/test/Analysis/plist-macros-with-expansion-ctu.c
@@ -2,13 +2,13 @@
 // RUN: mkdir -p %t/ctudir
 // RUN: %clang_cc1 -emit-pch -o %t/ctudir/plist-macros-ctu.c.ast %S/Inputs/plist-macros-ctu.c
 // RUN: cp %S/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt %t/ctudir/externalDefMap.txt
-
+//
 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
 // RUN:   -analyzer-config ctu-dir=%t/ctudir \
 // RUN:   -analyzer-config expand-macros=true \
 // RUN:   -analyzer-output=plist-multi-file -o %t.plist -verify %s
-// XFAIL: *
+//
 // Check the macro expansions from the plist output here, to make the test more
 // understandable.
 //   RUN: FileCheck --input-file=%t.plist %s
@@ -23,25 +23,30 @@
   F3(&X);
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM1
-// CHECK-NEXT: expansion*Z = (int *)0
-
+// FIXME: Macro expansion for other TUs should also work.
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 
 void test1() {
   int *X;
   F1(&X);
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM
-// CHECK-NEXT: expansion*X = (int *)0
+
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 
 void test2() {
   int *X;
   F2(&X);
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM
-// CHECK-NEXT: expansion*Y = (int *)0
+
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 
 #define M F1(&X)
 
@@ -50,10 +55,20 @@
   M;
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM
-// CHECK-NEXT: expansionF1(&X)
-// CHECK: nameM
-// CHECK-NEXT: expansion*X = (int *)0
+// Macro expansions for the main TU still works, even in CTU mode.
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT:  
+// CHECK-NEXT:   location
+// CHECK-NEXT:   
+// CHECK-NEXT:line55
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   nameM
+// CHECK-NEXT:   expansionF1 (&X )
+// CHECK-NEXT:  
+// CHECK-NEXT: 
 
 #undef M
 #define M F2(&X)
@@ -64,10 +79,19 @@
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
 
-// CHECK: nameM
-// CHECK-NEXT: expansionF2(&X)
-// CHECK: nameM
-// CHECK-NEXT: expansion*Y = (int *)0
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT:  
+// CHECK-NEXT:   location
+// CHECK-NEXT:   
+// CHECK-NEXT:line78
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   nameM
+// CHECK-NEXT:   expansionF2 (&X )
+// CHECK-NEXT:  
+// CHECK-NEXT: 
 
 void test_h() {
   int *X;
@@ -75,5 +99,6 @@
   *X = 1; // expected-warning

[clang] d81f633 - [flang][driver] Add -Xflang and make -test-io a frontend-only flang

2021-02-22 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-02-22T10:11:43Z
New Revision: d81f633fe28fd23108b4dc8c25548f1653ba0cd2

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

LOG: [flang][driver] Add -Xflang and make -test-io a frontend-only flang

This patch adds support for `-Xflang` in `flang-new`. The semantics are
identical to `-Xclang`.

With the addition of `-Xflang`, we can modify `-test-io` to be a
compiler-frontend only flag. This makes more sense, this flag is:
  * very frontend specific
  * to be used for development and testing only
  * not to be exposed to the end user
Originally we added it to the compiler driver, `flang-new`, in order to
facilitate testing. With `-Xflang` this is no longer needed. Tests are
updated accordingly.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/Types.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/test/Frontend/input-output-file.f90
flang/test/Frontend/multiple-input-files.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ade330bd7ba4..bbaa16658639 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4236,11 +4236,17 @@ def sycl_std_EQ : Joined<["-"], "sycl-std=">, 
Group, Flags<[CC1Optio
   MarshallingInfoString, "SYCL_None">, 
ShouldParseIf, AutoNormalizeEnum;
 
 
//===--===//
-// FlangOption and FC1 Options
+// FLangOption + CoreOption + NoXarchOption
 
//===--===//
-def test_io : Flag<["-"], "test-io">, Flags<[HelpHidden, FlangOption, 
FC1Option, FlangOnlyOption]>, Group,
-  HelpText<"Run the InputOuputTest action. Use for development and testing 
only.">;
+let Flags = [FlangOption, FlangOnlyOption, NoXarchOption, CoreOption] in {
+def Xflang : Separate<["-"], "Xflang">,
+  HelpText<"Pass  to the flang compiler">, MetaVarName<"">,
+  Flags<[NoXarchOption, CoreOption]>, Group;
+}
 
+//===--===//
+// FlangOption and FC1 Options
+//===--===//
 let Flags = [FC1Option, FlangOption, FlangOnlyOption] in {
 
 def ffixed_form : Flag<["-"], "ffixed-form">, Group,
@@ -4270,7 +4276,6 @@ def fimplicit_none : Flag<["-"], "fimplicit-none">, 
Group,
 def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group;
 def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-statement">, Group,
   HelpText<"Enable the old style PARAMETER statement">;
-
 }
 
 
//===--===//
@@ -4278,6 +4283,8 @@ def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-state
 
//===--===//
 let Flags = [FC1Option, FlangOnlyOption] in {
 
+def test_io : Flag<["-"], "test-io">, Group,
+  HelpText<"Run the InputOuputTest action. Use for development and testing 
only.">;
 def fdebug_unparse : Flag<["-"], "fdebug-unparse">, Group,
   HelpText<"Unparse and stop.">;
 def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, 
Group,

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98d37eb7e692..b79b94a11956 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -63,9 +63,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa(JA)) {
-if (C.getArgs().hasArg(options::OPT_test_io))
-  CmdArgs.push_back("-test-io");
-else
   CmdArgs.push_back("-E");
   } else if (isa(JA) || isa(JA)) {
 if (JA.getType() == types::TY_Nothing) {
@@ -102,6 +99,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // Add other compile options
   AddOtherOptions(Args, CmdArgs);
 
+  // Forward -Xflang arguments to -fc1
+  Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index e898334c3227..2050dffa6fa0 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -325,12 +325,10 @@ types::getCompilationPhases(const clang::driver::Driver 
&Driver,
   // Filter to compiler mode. When the compiler is run as a preprocessor then
   // compilation is not an option.

[PATCH] D96864: [flang][driver] Add -Xflang and make -test-io a frontend-only flag

2021-02-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd81f633fe28f: [flang][driver] Add -Xflang and make -test-io 
a frontend-only flang (authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D96864?vs=324287&id=325405#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96864

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/Types.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Frontend/input-output-file.f90
  flang/test/Frontend/multiple-input-files.f90

Index: flang/test/Frontend/multiple-input-files.f90
===
--- flang/test/Frontend/multiple-input-files.f90
+++ flang/test/Frontend/multiple-input-files.f90
@@ -1,16 +1,16 @@
-! RUN: rm -rf %S/multiple-input-files.txt  %S/Inputs/hello-world.txt
-
 ! REQUIRES: new-flang-driver
 
 !--
 ! FLANG DRIVER (flang-new)
 !--
+! NOTE: Use `-E` so that the compiler driver stops after the 1st compilation phase, preprocessing. That's all we need.
+
 ! TEST 1: Both input files are processed (output is printed to stdout)
-! RUN: %flang-new -test-io %s %S/Inputs/hello-world.f90 | FileCheck %s --match-full-lines -check-prefix=FLANG
+! RUN: %flang-new -E -Xflang -test-io %s %S/Inputs/hello-world.f90 | FileCheck %s --match-full-lines -check-prefix=FLANG
 
 ! TEST 2: None of the files is processed (not possible to specify the output file when multiple input files are present)
-! RUN: not %flang-new -test-io -o - %S/Inputs/hello-world.f90 %s  2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
-! RUN: not %flang-new -test-io -o %t %S/Inputs/hello-world.f90 %s 2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
+! RUN: not %flang-new -E -Xflang -test-io -o - %S/Inputs/hello-world.f90 %s  2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
+! RUN: not %flang-new -E -Xflang -test-io -o %t %S/Inputs/hello-world.f90 %s 2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
 
 !
 ! FLANG FRONTEND DRIVER (flang-new -fc1)
Index: flang/test/Frontend/input-output-file.f90
===
--- flang/test/Frontend/input-output-file.f90
+++ flang/test/Frontend/input-output-file.f90
@@ -1,16 +1,18 @@
-! RUN: rm -rf %S/input-output-file.txt
-
 ! REQUIRES: new-flang-driver
 
 !--
 ! FLANG DRIVER (flang-new)
 !--
+! NOTE: Use `-E` so that the compiler driver stops after the 1st compilation phase, preprocessing. That's all we need.
+
 ! TEST 1: Print to stdout (implicit)
-! RUN: %flang-new -test-io %s  2>&1 | FileCheck %s --match-full-lines
+! RUN: %flang-new -E -Xflang -test-io %s  2>&1 | FileCheck %s --match-full-lines
+
 ! TEST 2: Print to stdout (explicit)
-! RUN: %flang-new -test-io -o - %s  2>&1 | FileCheck %s --match-full-lines
+! RUN: %flang-new -E -Xflang -test-io -o - %s  2>&1 | FileCheck %s --match-full-lines
+
 ! TEST 3: Print to a file
-! RUN: %flang-new -test-io -o %t %s 2>&1 && FileCheck %s --match-full-lines --input-file=%t
+! RUN: %flang-new -E -Xflang -test-io -o %t %s 2>&1 && FileCheck %s --match-full-lines --input-file=%t
 
 !
 ! FLANG FRONTEND DRIVER (flang-new -fc1)
@@ -21,6 +23,7 @@
 ! RUN: rm -rf %t-dir && mkdir -p %t-dir && cd %t-dir
 ! RUN: cp %s .
 ! RUN: %flang-new -fc1 -test-io input-output-file.f90  2>&1 && FileCheck %s --match-full-lines --input-file=input-output-file.txt
+
 ! TEST 5: Write to a file (explicit)
 ! RUN: %flang-new -fc1 -test-io  -o %t %s 2>&1 && FileCheck %s --match-full-lines --input-file=%t
 
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -43,6 +43,7 @@
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
+! HELP-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
 ! EXPECTED OUTPUT FOR FLANG FRONTEND DRIVER (flang-new -fc1)
@@ -79,6 +80,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 
Index: flang/test/Flang-Driver/driver-help-hidden.f90

[PATCH] D96864: [flang][driver] Add -Xflang and make -test-io a frontend-only flag

2021-02-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thanks for reviewing @SouraVX ! I did update that comment before merging. 
Hopefully it _will_ make sense when we come back to it at later time :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96864

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


[PATCH] D96847: [clang][cli] Store additional optimization remarks info

2021-02-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 325407.
jansvoboda11 added a comment.

Rename `RemarkPattern` to `OptRemark`, simplify the API usage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96847

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1162,20 +1162,69 @@
<< "a filename";
 }
 
-/// Create a new Regex instance out of the string value in \p RpassArg.
-/// It returns the string and a pointer to the newly generated Regex instance.
-static CodeGenOptions::RemarkPattern
-GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args,
-Arg *RpassArg) {
-  StringRef Val = RpassArg->getValue();
-  std::string RegexError;
-  std::shared_ptr Pattern = std::make_shared(Val);
-  if (!Pattern->isValid(RegexError)) {
-Diags.Report(diag::err_drv_optimization_remark_pattern)
-<< RegexError << RpassArg->getAsString(Args);
-Pattern.reset();
-  }
-  return {std::string(Val), Pattern};
+/// Generate a remark argument. This is an inverse of `ParseOptimizationRemark`.
+static void
+GenerateOptimizationRemark(SmallVectorImpl &Args,
+   CompilerInvocation::StringAllocator SA,
+   OptSpecifier OptEQ, StringRef Name,
+   const CodeGenOptions::OptRemark &Remark) {
+  if (Remark.hasValidPattern()) {
+GenerateArg(Args, OptEQ, Remark.Pattern, SA);
+  } else if (Remark.Kind == CodeGenOptions::RK_Enabled) {
+GenerateArg(Args, OPT_R_Joined, Name, SA);
+  } else if (Remark.Kind == CodeGenOptions::RK_Disabled) {
+GenerateArg(Args, OPT_R_Joined, StringRef("no-") + Name, SA);
+  }
+};
+
+/// Parse a remark command line argument. It may be missing, disabled/enabled by
+/// '-R[no-]group' or specified with a regular expression by '-Rgroup=regexp'.
+/// On top of that, it can be disabled/enabled globally by '-R[no-]everything'.
+static CodeGenOptions::OptRemark
+ParseOptimizationRemark(DiagnosticsEngine &Diags, ArgList &Args,
+OptSpecifier OptEQ, StringRef Name) {
+  CodeGenOptions::OptRemark Result;
+
+  auto InitializeResultPattern = [&Diags, &Args, &Result](const Arg *A) {
+Result.Pattern = A->getValue();
+
+std::string RegexError;
+Result.Regex = std::make_shared(Result.Pattern);
+if (!Result.Regex->isValid(RegexError)) {
+  Diags.Report(diag::err_drv_optimization_remark_pattern)
+  << RegexError << A->getAsString(Args);
+  return false;
+}
+
+return true;
+  };
+
+  for (Arg *A : Args) {
+if (A->getOption().matches(OPT_R_Joined)) {
+  StringRef Value = A->getValue();
+
+  if (Value == Name)
+Result.Kind = CodeGenOptions::RK_Enabled;
+  else if (Value == "everything")
+Result.Kind = CodeGenOptions::RK_EnabledEverything;
+  else if (Value.split('-') == std::make_pair(StringRef("no"), Name))
+Result.Kind = CodeGenOptions::RK_Disabled;
+  else if (Value == "no-everything")
+Result.Kind = CodeGenOptions::RK_DisabledEverything;
+} else if (A->getOption().matches(OptEQ)) {
+  Result.Kind = CodeGenOptions::RK_WithPattern;
+  if (!InitializeResultPattern(A))
+return CodeGenOptions::OptRemark();
+}
+  }
+
+  if (Result.Kind == CodeGenOptions::RK_Disabled ||
+  Result.Kind == CodeGenOptions::RK_DisabledEverything) {
+Result.Pattern = "";
+Result.Regex = nullptr;
+  }
+
+  return Result;
 }
 
 static bool parseDiagnosticLevelMask(StringRef FlagName,
@@ -1483,16 +1532,14 @@
   if (!Opts.OptRecordFormat.empty())
 GenerateArg(Args, OPT_opt_record_format, Opts.OptRecordFormat, SA);
 
-  if (Opts.OptimizationRemarkPattern)
-GenerateArg(Args, OPT_Rpass_EQ, Opts.OptimizationRemarkPattern.Pattern, SA);
+  GenerateOptimizationRemark(Args, SA, OPT_Rpass_EQ, "pass",
+ Opts.OptimizationRemark);
 
-  if (Opts.OptimizationRemarkMissedPattern)
-GenerateArg(Args, OPT_Rpass_missed_EQ,
-Opts.OptimizationRemarkMissedPattern.Pattern, SA);
+  GenerateOptimizationRemark(Args, SA, OPT_Rpass_missed_EQ, "pass-missed",
+ Opts.OptimizationRemarkMissed);
 
-  if (Opts.OptimizationRemarkAnalysisPattern)
-GenerateArg(Args, OPT_Rpass_analysis_EQ,
-Opts.OptimizationRemarkAnalysisPattern.Pattern, SA);
+  GenerateOptimizationRemark(Args, SA, OPT_Rpass_analysis_EQ, "pass-analysis",
+ Opts.OptimizationRemarkAnalysis);
 
   GenerateArg(Args, OPT_fdiagnostics_hotness_threshold_EQ,
   Opts.DiagnosticsHotnessThr

[PATCH] D96847: [clang][cli] Store additional optimization remarks info

2021-02-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 325408.
jansvoboda11 added a comment.

Comment wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96847

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1162,20 +1162,69 @@
<< "a filename";
 }
 
-/// Create a new Regex instance out of the string value in \p RpassArg.
-/// It returns the string and a pointer to the newly generated Regex instance.
-static CodeGenOptions::RemarkPattern
-GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args,
-Arg *RpassArg) {
-  StringRef Val = RpassArg->getValue();
-  std::string RegexError;
-  std::shared_ptr Pattern = std::make_shared(Val);
-  if (!Pattern->isValid(RegexError)) {
-Diags.Report(diag::err_drv_optimization_remark_pattern)
-<< RegexError << RpassArg->getAsString(Args);
-Pattern.reset();
-  }
-  return {std::string(Val), Pattern};
+/// Generate a remark argument. This is an inverse of `ParseOptimizationRemark`.
+static void
+GenerateOptimizationRemark(SmallVectorImpl &Args,
+   CompilerInvocation::StringAllocator SA,
+   OptSpecifier OptEQ, StringRef Name,
+   const CodeGenOptions::OptRemark &Remark) {
+  if (Remark.hasValidPattern()) {
+GenerateArg(Args, OptEQ, Remark.Pattern, SA);
+  } else if (Remark.Kind == CodeGenOptions::RK_Enabled) {
+GenerateArg(Args, OPT_R_Joined, Name, SA);
+  } else if (Remark.Kind == CodeGenOptions::RK_Disabled) {
+GenerateArg(Args, OPT_R_Joined, StringRef("no-") + Name, SA);
+  }
+};
+
+/// Parse a remark command line argument. It may be missing, disabled/enabled by
+/// '-R[no-]group' or specified with a regular expression by '-Rgroup=regexp'.
+/// On top of that, it can be disabled/enabled globally by '-R[no-]everything'.
+static CodeGenOptions::OptRemark
+ParseOptimizationRemark(DiagnosticsEngine &Diags, ArgList &Args,
+OptSpecifier OptEQ, StringRef Name) {
+  CodeGenOptions::OptRemark Result;
+
+  auto InitializeResultPattern = [&Diags, &Args, &Result](const Arg *A) {
+Result.Pattern = A->getValue();
+
+std::string RegexError;
+Result.Regex = std::make_shared(Result.Pattern);
+if (!Result.Regex->isValid(RegexError)) {
+  Diags.Report(diag::err_drv_optimization_remark_pattern)
+  << RegexError << A->getAsString(Args);
+  return false;
+}
+
+return true;
+  };
+
+  for (Arg *A : Args) {
+if (A->getOption().matches(OPT_R_Joined)) {
+  StringRef Value = A->getValue();
+
+  if (Value == Name)
+Result.Kind = CodeGenOptions::RK_Enabled;
+  else if (Value == "everything")
+Result.Kind = CodeGenOptions::RK_EnabledEverything;
+  else if (Value.split('-') == std::make_pair(StringRef("no"), Name))
+Result.Kind = CodeGenOptions::RK_Disabled;
+  else if (Value == "no-everything")
+Result.Kind = CodeGenOptions::RK_DisabledEverything;
+} else if (A->getOption().matches(OptEQ)) {
+  Result.Kind = CodeGenOptions::RK_WithPattern;
+  if (!InitializeResultPattern(A))
+return CodeGenOptions::OptRemark();
+}
+  }
+
+  if (Result.Kind == CodeGenOptions::RK_Disabled ||
+  Result.Kind == CodeGenOptions::RK_DisabledEverything) {
+Result.Pattern = "";
+Result.Regex = nullptr;
+  }
+
+  return Result;
 }
 
 static bool parseDiagnosticLevelMask(StringRef FlagName,
@@ -1483,16 +1532,14 @@
   if (!Opts.OptRecordFormat.empty())
 GenerateArg(Args, OPT_opt_record_format, Opts.OptRecordFormat, SA);
 
-  if (Opts.OptimizationRemarkPattern)
-GenerateArg(Args, OPT_Rpass_EQ, Opts.OptimizationRemarkPattern.Pattern, SA);
+  GenerateOptimizationRemark(Args, SA, OPT_Rpass_EQ, "pass",
+ Opts.OptimizationRemark);
 
-  if (Opts.OptimizationRemarkMissedPattern)
-GenerateArg(Args, OPT_Rpass_missed_EQ,
-Opts.OptimizationRemarkMissedPattern.Pattern, SA);
+  GenerateOptimizationRemark(Args, SA, OPT_Rpass_missed_EQ, "pass-missed",
+ Opts.OptimizationRemarkMissed);
 
-  if (Opts.OptimizationRemarkAnalysisPattern)
-GenerateArg(Args, OPT_Rpass_analysis_EQ,
-Opts.OptimizationRemarkAnalysisPattern.Pattern, SA);
+  GenerateOptimizationRemark(Args, SA, OPT_Rpass_analysis_EQ, "pass-analysis",
+ Opts.OptimizationRemarkAnalysis);
 
   GenerateArg(Args, OPT_fdiagnostics_hotness_threshold_EQ,
   Opts.DiagnosticsHotnessThreshold
@@ -1859,23 +1906,18 @@
 NeedLocTra

[PATCH] D96847: [clang][cli] Store additional optimization remarks info

2021-02-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D96847#2576369 , @dexonsmith wrote:

> In D96847#2574408 , @jansvoboda11 
> wrote:
>
>> That's a bit nicer.
>>
>> Not sure if `RemarkPattern` is a good name now, as it may represent an 
>> optimization remark that doesn't have any pattern associated with it.
>> How about calling it `OptimizationRemark` and merging `operator bool` and 
>> `operator ->` into `bool patternMatch(...) { return Pattern && 
>> Pattern.match(...); }`?
>
> Seems reasonable. Or `matchesPattern(...)`?

I chose `patternMatches`, which (IMO) suggests the pattern is contained within 
the object and the string to be matched is passed as an argument. To me, 
`matchesPattern` sounds like it's the other way around, which would contradict 
the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96847

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-02-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Looks fine to me.




Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:466-467
+  return;
+OS << "Obtained null inner pointer from";
+checkAndPrettyPrintRegion(OS, ThisRegion);
+  }));

You should emit a //sort of grammatically correct// diagnostic message even if 
the region can not be pretty-printed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D97156: [ASTMatchers] Make Param functors variadic

2021-02-22 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 325409.
steveire added a comment.

Update dump script


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97156

Files:
  clang/docs/tools/dump_ast_matchers.py
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/include/clang/ASTMatchers/ASTMatchersMacros.h

Index: clang/include/clang/ASTMatchers/ASTMatchersMacros.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersMacros.h
+++ clang/include/clang/ASTMatchers/ASTMatchersMacros.h
@@ -239,10 +239,10 @@
  *Builder) const override; \
   };   \
   }\
-  inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam0<\
+  inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParamN<\
   internal::matcher_##DefineMatcher##Matcher, ReturnTypesF>\
   DefineMatcher() {\
-return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam0<  \
+return ::clang::ast_matchers::internal::PolymorphicMatcherWithParamN<  \
 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF>();   \
   }\
   template  \
@@ -284,18 +284,17 @@
 ParamType const Param; \
   };   \
   }\
-  inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1<\
-  internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType,   \
-  ReturnTypesF>\
+  inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParamN<\
+  internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF,\
+  ParamType>   \
   DefineMatcher(ParamType const &Param) {  \
-return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1<  \
-internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType, \
-ReturnTypesF>(Param);  \
+return ::clang::ast_matchers::internal::PolymorphicMatcherWithParamN<  \
+internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF,  \
+ParamType>(Param); \
   }\
-  typedef ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1<   \
-  internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType,   \
-  ReturnTypesF>(&DefineMatcher##_Type##OverloadId)(\
-  ParamType const &Param); \
+  typedef ::clang::ast_matchers::internal::PolymorphicMatcherWithParamN<   \
+  internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF,\
+  ParamType> (&DefineMatcher##_Type##OverloadId)(ParamType const &Param);  \
   template \
   bool internal::  \
   matcher_##DefineMatcher##OverloadId##Matcher::matches( \
@@ -338,17 +337,17 @@
 ParamType2 const Param2;   \
   };   \
   }\
-  inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2<\
-  internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1,  \
-  ParamType2, ReturnTypesF>\
+  inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParamN<\
+  internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF,\
+  ParamType1, ParamType2>  \
   DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) {  \
-return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2<  \
-internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1,\
-ParamType2, ReturnTypesF>(Param1, Param2); \
+return ::clang::ast_matchers::internal::PolymorphicMatcherW

[clang] b5b3243 - Regenerate documentation

2021-02-22 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-22T11:07:45Z
New Revision: b5b3243bf783f07415c5e2838fa1a948e126f643

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

LOG: Regenerate documentation

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index a956091318a1..0becf5ebfb8c 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -7152,7 +7152,8 @@ AST Traversal Matchers
 f = 42;
 }
 The matcher:
-  decompositionDecl(hasBinding(0, bindingDecl(hasName("f").bind("fBinding"
+  decompositionDecl(hasBinding(0,
+  bindingDecl(hasName("f").bind("fBinding"
 matches the decomposition decl with 'f' bound to "fBinding".
 
 



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


[PATCH] D97156: [ASTMatchers] Make Param functors variadic

2021-02-22 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

Good catch! Updated the docs generating script.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97156

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


[PATCH] D96114: [ASTMatchers] Fix parent-child traversal between functions and parms

2021-02-22 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D96114#2548029 , @klimek wrote:

> Can you explain the change and the before/after a bit more? Thanks!

I'm not sure. Can you ask a more-specific question? Did you read the link that 
Nathan posted? Is the unit test unclear?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96114

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


[PATCH] D97138: [Driver] replace argc_ with argc

2021-02-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski requested changes to this revision.
awarzynski added a comment.
This revision now requires changes to proceed.

Thank you for submitting this @achieveartificialintelligence !

The aim of these changes is to improve the consistency of the code-base with 
respect to the coding standards documented separately for Clang 
 and Flang 
. I 
think that this is a very positive suggestion, but would like to request a few 
refinements before this is ready:

- Please note that in LLVM/Clang, variables names start with upper case (so it 
should be int `main(int Argc, const char **Argv)` instead of `main(int argc, 
const char **argv)` ). link 

- In Flang the rules are slightly different, and the variable names start with 
a lower case (so it should be int `main(int Argc, const char **Argv)` instead 
of `main(int argc, const char **argv)` ). link 

- Your commit message refers to _a driver_, but in fact you are updating 2 
specific drivers: Clang compiler driver and Flang compiler driver - could you 
clarify?
- Your commit message refers to `argc_` specifically, but you are updating 
`argc_`, `argv_` and `Argv/argv` too.

Personally I'd prefer `ArgC/argC` and `ArgV/argV` for input parameters and 
`ArgValues/argValues` for the local variable. This way it would be more 
self-explanatory. But that's a matter of style. As long as this is consistent 
with the coding standards, I think that this should be accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97138

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


[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

2021-02-22 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Is this obsolete with the change to devicertl cmake? Would prefer abandon to 
land if so


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96877

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


[PATCH] D97053: [clang][SVE] Don't warn on vector to sizeless builtin implicit conversion

2021-02-22 Thread Joe Ellis via Phabricator via cfe-commits
joechrisellis updated this revision to Diff 325410.
joechrisellis added a comment.

Address comments.

- @c-rhodes: remove test; it is probably not necessary.
- @craig.topper: add better constraints for when we do/don't bail out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97053

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp


Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 
-msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 
-msve-vector-bits=512 -fallow-half-arguments-and-returns -Wconversion %s
 // expected-no-diagnostics
 
 #include 
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12051,7 +12051,16 @@
 checkObjCDictionaryLiteral(S, QualType(Target, 0), DictionaryLiteral);
 
   // Strip vector types.
-  if (isa(Source)) {
+  if (auto *SourceVT = dyn_cast(Source)) {
+if (Target->isSizelessBuiltinType()) {
+  auto SourceVectorKind = SourceVT->getVectorKind();
+  if (SourceVectorKind == VectorType::SveFixedLengthDataVector ||
+  SourceVectorKind == VectorType::SveFixedLengthPredicateVector ||
+  (SourceVectorKind == VectorType::GenericVector &&
+   S.Context.getTypeSize(Source) == S.getLangOpts().ArmSveVectorBits))
+return;
+}
+
 if (!isa(Target)) {
   if (S.SourceMgr.isInSystemMacro(CC))
 return;


Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns -Wconversion %s
 // expected-no-diagnostics
 
 #include 
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12051,7 +12051,16 @@
 checkObjCDictionaryLiteral(S, QualType(Target, 0), DictionaryLiteral);
 
   // Strip vector types.
-  if (isa(Source)) {
+  if (auto *SourceVT = dyn_cast(Source)) {
+if (Target->isSizelessBuiltinType()) {
+  auto SourceVectorKind = SourceVT->getVectorKind();
+  if (SourceVectorKind == VectorType::SveFixedLengthDataVector ||
+  SourceVectorKind == VectorType::SveFixedLengthPredicateVector ||
+  (SourceVectorKind == VectorType::GenericVector &&
+   S.Context.getTypeSize(Source) == S.getLangOpts().ArmSveVectorBits))
+return;
+}
+
 if (!isa(Target)) {
   if (S.SourceMgr.isInSystemMacro(CC))
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 7dc7f0c - [clang-tidy] Add new check 'concurrency-thread-canceltype-asynchronous' and alias 'cert-pos47-c'.

2021-02-22 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2021-02-22T12:42:20+01:00
New Revision: 7dc7f0c2ecc05b9a9c73e89facec24ad6d325cae

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

LOG: [clang-tidy] Add new check 'concurrency-thread-canceltype-asynchronous' 
and alias 'cert-pos47-c'.

Reviewed By: aaron.ballman

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

Added: 

clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.cpp
clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.h
clang-tools-extra/docs/clang-tidy/checks/cert-pos47-c.rst

clang-tools-extra/docs/clang-tidy/checks/concurrency-thread-canceltype-asynchronous.rst

clang-tools-extra/test/clang-tidy/checkers/concurrency-thread-canceltype-asynchronous.cpp

Modified: 
clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
clang-tools-extra/clang-tidy/cert/CMakeLists.txt
clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp 
b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index 3e0e3502f5e1..616cd3d7069f 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -15,6 +15,7 @@
 #include "../bugprone/SignedCharMisuseCheck.h"
 #include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
 #include "../bugprone/UnhandledSelfAssignmentCheck.h"
+#include "../concurrency/ThreadCanceltypeAsynchronousCheck.h"
 #include "../google/UnnamedNamespaceInHeaderCheck.h"
 #include "../misc/NewDeleteOverloadsCheck.h"
 #include "../misc/NonCopyableObjects.h"
@@ -110,6 +111,9 @@ class CERTModule : public ClangTidyModule {
 // POS
 CheckFactories.registerCheck(
 "cert-pos44-c");
+CheckFactories
+.registerCheck(
+"cert-pos47-c");
 // SIG
 CheckFactories.registerCheck("cert-sig30-c");
 // STR

diff  --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index e56de01b4780..6d40e9418fc6 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyCERTModule
   LINK_LIBS
   clangTidy
   clangTidyBugproneModule
+  clangTidyConcurrencyModule
   clangTidyGoogleModule
   clangTidyMiscModule
   clangTidyPerformanceModule

diff  --git a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
index b757d6a60b78..65d2ace6645e 100644
--- a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangTidyConcurrencyModule
   ConcurrencyTidyModule.cpp
   MtUnsafeCheck.cpp
+  ThreadCanceltypeAsynchronousCheck.cpp
 
   LINK_LIBS
   clangTidy

diff  --git 
a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp 
b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
index ea4131e0ca51..7ae891d463f7 100644
--- a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "MtUnsafeCheck.h"
+#include "ThreadCanceltypeAsynchronousCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,6 +21,8 @@ class ConcurrencyModule : public ClangTidyModule {
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "concurrency-mt-unsafe");
+CheckFactories.registerCheck(
+"concurrency-thread-canceltype-asynchronous");
   }
 };
 

diff  --git 
a/clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.cpp
 
b/clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.cpp
new file mode 100644
index ..736fff4c1ed6
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.cpp
@@ -0,0 +1,39 @@
+//===--- ThreadCanceltypeAsynchronousCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ThreadCanceltypeAsynchronousCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/

[PATCH] D96719: [clang-tidy] Add new check 'concurrency-thread-canceltype-asynchronous' and alias 'cert-pos47-c'.

2021-02-22 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7dc7f0c2ecc0: [clang-tidy] Add new check 
'concurrency-thread-canceltype-asynchronous' and… (authored by 
balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96719

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
  clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
  clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.cpp
  clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-pos47-c.rst
  
clang-tools-extra/docs/clang-tidy/checks/concurrency-thread-canceltype-asynchronous.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/concurrency-thread-canceltype-asynchronous.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/concurrency-thread-canceltype-asynchronous.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/concurrency-thread-canceltype-asynchronous.cpp
@@ -0,0 +1,52 @@
+// RUN: %check_clang_tidy %s concurrency-thread-canceltype-asynchronous %t
+
+#define ONE (1 << 0)
+
+#define PTHREAD_CANCEL_DEFERRED 0
+// define the macro intentionally complex
+#define PTHREAD_CANCEL_ASYNCHRONOUS ONE
+
+#define ASYNCHR PTHREAD_CANCEL_ASYNCHRONOUS
+
+int pthread_setcanceltype(int type, int *oldtype);
+
+int main() {
+  int result, oldtype;
+
+  if ((result = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype)) != 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: the cancel type for a pthread should not be 'PTHREAD_CANCEL_ASYNCHRONOUS' [concurrency-thread-canceltype-asynchronous]
+return 1;
+  }
+
+  if ((result = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype)) != 0) {
+return 1;
+  }
+
+  return 0;
+}
+
+int f1() {
+  int result, oldtype;
+
+  if ((result = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype)) != 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: the cancel type for a pthread should not be 'PTHREAD_CANCEL_ASYNCHRONOUS' [concurrency-thread-canceltype-asynchronous]
+return 1;
+  }
+
+  if ((result = pthread_setcanceltype(ASYNCHR, &oldtype)) != 0) {
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: the cancel type for a pthread should not be 'PTHREAD_CANCEL_ASYNCHRONOUS' [concurrency-thread-canceltype-asynchronous]
+return 1;
+  }
+
+  return 0;
+}
+
+int f2(int type) {
+  int result, oldtype;
+
+  if ((result = pthread_setcanceltype(type, &oldtype)) != 0) {
+return 1;
+  }
+
+  return 0;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -140,6 +140,7 @@
`clang-analyzer-valist.Uninitialized `_,
`clang-analyzer-valist.Unterminated `_,
`concurrency-mt-unsafe `_,
+   `concurrency-thread-canceltype-asynchronous `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
`cppcoreguidelines-init-variables `_, "Yes"
@@ -334,6 +335,7 @@
`cert-oop11-cpp `_, `performance-move-constructor-init `_, "Yes"
`cert-oop54-cpp `_, `bugprone-unhandled-self-assignment `_,
`cert-pos44-c `_, `bugprone-bad-signal-to-kill-thread `_,
+   `cert-pos47-c `_, `concurrency-thread-canceltype-asynchronous `_,
`cert-str34-c `_, `bugprone-signed-char-misuse `_,
`clang-analyzer-core.CallAndMessage `_, `Clang Static Analyzer `_,
`clang-analyzer-core.DivideZero `_, `Clang Static Analyzer `_,
Index: clang-tools-extra/docs/clang-tidy/checks/concurrency-thread-canceltype-asynchronous.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/concurrency-thread-canceltype-asynchronous.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - concurrency-thread-canceltype-asynchronous
+
+concurrency-thread-canceltype-asynchronous
+==
+
+Finds ``pthread_setcanceltype`` function calls where a thread's cancellation
+type is set to asynchronous. Asynchronous cancellation type
+(``PTHREAD_CANCEL_ASYNCHRONOUS``) is generally unsafe, use type
+``PTHREAD_CANCEL_DEFERRED`` instead which is the default. Even with deferred
+cancellation, a cancellation point in an asynchronous signal handler may still
+be acted upon and the effect is as if it was an asynchronous cancellation.
+
+.. code-block: c++
+
+  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &

[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Hi @arnamoy10 , thank for working on this!

I suggest making it more explicit that the new option is about _enabling 
standard conformance checks_. So e.g. `enableConformanceChecks` rather than 
`setStandard` (or `set_EnableConformanceChecks` if the member variable is 
called `EnableConformanceChecks`).

I am also mindful that adding `-std=f2018` might be a bit confusing to users if 
we don't support other versions of the language. @tskeith raised this point 
earlier .

Perhaps we should use e..g `-fstd-conf-checks/-fno-std-conf-checks` instead? 
This could be an alias for `-Mstandard` in `f18`. We would replace it with 
`-std=` once that makes more sense.




Comment at: flang/include/flang/Frontend/CompilerInvocation.h:74
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
+  bool standard_ = false;
 

Wouldn`t e.g. `standardConformanceChecks_` be a bit more self-explanatory? 
Currently this is quite vague.



Comment at: flang/include/flang/Frontend/CompilerInvocation.h:113
+standard_ = true;
+  }
   /// Set the Fortran options to predifined defaults. These defaults are

Missing empty line.



Comment at: flang/test/Flang-Driver/std2018.f90:12-13
+!-
+!  RUN: %flang-new -fc1 -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s 
--check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -fsyntax-only -std=90 %s  2>&1 | FileCheck %s 
--check-prefix=WRONG
+

[nit] `-fstynax-only` is effectively the default in the frontend driver, see [[ 
https://github.com/llvm/llvm-project/blob/b5b3243bf783f07415c5e2838fa1a948e126f643/flang/lib/Frontend/CompilerInvocation.cpp#L92
 | here ]]. Basically, in the absence of any _action_ options, the driver will 
run the `ParseSyntaxOnly` action (which corresponds to `-fsyntax-only`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97119

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


[clang] 2c25efc - [AArch64] Adding SHA3 Intrinsics support

2021-02-22 Thread David Spickett via cfe-commits

Author: Ryan Santhiraraja
Date: 2021-02-22T12:09:20Z
New Revision: 2c25efcbd322c58b62e592a8265ef83803f0e7b9

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

LOG: [AArch64] Adding SHA3 Intrinsics support

This patch adds the following SHA3 Intrinsics:
vsha512hq_u64,
vsha512h2q_u64,
vsha512su0q_u64,
vsha512su1q_u64
veor3q_u8
veor3q_u16
veor3q_u32
veor3q_u64
veor3q_s8
veor3q_s16
veor3q_s32
veor3q_s64
vrax1q_u64
vxarq_u64
vbcaxq_u8
vbcaxq_u16
vbcaxq_u32
vbcaxq_u64
vbcaxq_s8
vbcaxq_s16
vbcaxq_s32
vbcaxq_s64

Note need to include +sha3 and +crypto when building from the front-end

Reviewed By: DavidSpickett

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

Added: 
clang/test/CodeGen/aarch64-neon-sha3.c
llvm/test/CodeGen/AArch64/neon-sha3.ll

Modified: 
clang/include/clang/Basic/arm_neon.td
clang/include/clang/Basic/arm_neon_incl.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-range-checks.c
clang/utils/TableGen/NeonEmitter.cpp
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64InstrFormats.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index cb8e30445a76..0b0105c665f5 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1135,6 +1135,19 @@ def SHA256H : SInst<"vsha256h", "", "QUi">;
 def SHA256H2 : SInst<"vsha256h2", "", "QUi">;
 def SHA256SU1 : SInst<"vsha256su1", "", "QUi">;
 
+def BCAX : SInst<"vbcax", "", "QUcQUsQUiQUlQcQsQiQl">;
+def EOR3 : SInst<"veor3", "", "QUcQUsQUiQUlQcQsQiQl">;
+def RAX1 : SInst<"vrax1", "...", "QUl">;
+
+let isVXAR = 1 in {
+def XAR :  SInst<"vxar", "...I", "QUl">;
+}
+
+def SHA512SU0 : SInst<"vsha512su0", "...", "QUl">;
+def SHA512su1 : SInst<"vsha512su1", "", "QUl">;
+def SHA512H : SInst<"vsha512h", "", "QUl">;
+def SHA512H2 : SInst<"vsha512h2", "", "QUl">;
+
 def SM3SS1 : SInst<"vsm3ss1", "", "QUi">;
 def SM3TT1A : SInst<"vsm3tt1a", "I", "QUi">;
 def SM3TT1B : SInst<"vsm3tt1b", "I", "QUi">;

diff  --git a/clang/include/clang/Basic/arm_neon_incl.td 
b/clang/include/clang/Basic/arm_neon_incl.td
index dd20b70433ef..60dbea627d58 100644
--- a/clang/include/clang/Basic/arm_neon_incl.td
+++ b/clang/include/clang/Basic/arm_neon_incl.td
@@ -272,6 +272,7 @@ class Inst  {
   bit isScalarShift = 0;
   bit isScalarNarrowShift = 0;
   bit isVCVT_N = 0;
+  bit isVXAR = 0;
   // For immediate checks: the immediate will be assumed to specify the lane of
   // a Q register. Only used for intrinsics which end up calling polymorphic
   // builtins.

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c1eaba49ce91..04289bf885b7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5676,6 +5676,7 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP1(vaeseq_v, aarch64_crypto_aese, 0),
   NEONMAP1(vaesimcq_v, aarch64_crypto_aesimc, 0),
   NEONMAP1(vaesmcq_v, aarch64_crypto_aesmc, 0),
+  NEONMAP2(vbcaxq_v, aarch64_crypto_bcaxu, aarch64_crypto_bcaxs, Add1ArgType | 
UnsignedAlts),
   NEONMAP1(vbfdot_v, aarch64_neon_bfdot, 0),
   NEONMAP1(vbfdotq_v, aarch64_neon_bfdot, 0),
   NEONMAP1(vbfmlalbq_v, aarch64_neon_bfmlalb, 0),
@@ -5745,6 +5746,7 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP1(vcvtx_f32_v, aarch64_neon_fcvtxn, AddRetType | Add1ArgType),
   NEONMAP2(vdot_v, aarch64_neon_udot, aarch64_neon_sdot, 0),
   NEONMAP2(vdotq_v, aarch64_neon_udot, aarch64_neon_sdot, 0),
+  NEONMAP2(veor3q_v, aarch64_crypto_eor3u, aarch64_crypto_eor3s, Add1ArgType | 
UnsignedAlts),
   NEONMAP0(vext_v),
   NEONMAP0(vextq_v),
   NEONMAP0(vfma_v),
@@ -5810,6 +5812,7 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP2(vqsub_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | 
UnsignedAlts),
   NEONMAP2(vqsubq_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | 
UnsignedAlts),
   NEONMAP1(vraddhn_v, aarch64_neon_raddhn, Add1ArgType),
+  NEONMAP1(vrax1q_v, aarch64_crypto_rax1, 0),
   NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0),
   NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0),
   NEONMAP1(vrecps_v, aarch64_neon_frecps, Add1ArgType),
@@ -5833,6 +5836,10 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP1(vsha256hq_v, aarch64_crypto_sha256h, 0),
   NEONMAP1(vsha256su0q_v, aarch64_crypto_sha256su0, 0),
   NEONMAP1(vsha

[PATCH] D96381: [AArch64] Adding SHA3 Intrinsics support

2021-02-22 Thread David Spickett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2c25efcbd322: [AArch64] Adding SHA3 Intrinsics support 
(authored by rsanthir.quic, committed by DavidSpickett).

Changed prior to commit:
  https://reviews.llvm.org/D96381?vs=324711&id=325416#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96381

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/include/clang/Basic/arm_neon_incl.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-range-checks.c
  clang/test/CodeGen/aarch64-neon-sha3.c
  clang/utils/TableGen/NeonEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/neon-sha3.ll

Index: llvm/test/CodeGen/AArch64/neon-sha3.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/neon-sha3.ll
@@ -0,0 +1,246 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc %s -mtriple=aarch64 -mattr=+v8.3a,+sha3 -o - | FileCheck %s
+
+define <2 x i64> @test_vsha512h(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c) {
+; CHECK-LABEL: test_vsha512h:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sha512h q0, q1, v2.2d
+; CHECK-NEXT:ret
+entry:
+  %vsha512h.i = tail call <2 x i64> @llvm.aarch64.crypto.sha512h(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c)
+  ret <2 x i64> %vsha512h.i
+}
+
+define <2 x i64> @test_vsha512h2(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c) {
+; CHECK-LABEL: test_vsha512h2:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sha512h2 q0, q1, v2.2d
+; CHECK-NEXT:ret
+entry:
+  %vsha512h2.i = tail call <2 x i64> @llvm.aarch64.crypto.sha512h2(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c)
+  ret <2 x i64> %vsha512h2.i
+}
+
+define <2 x i64> @test_vsha512su0(<2 x i64> %a, <2 x i64> %b) {
+; CHECK-LABEL: test_vsha512su0:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sha512su0 v0.2d, v1.2d
+; CHECK-NEXT:ret
+entry:
+  %vsha512su0.i = tail call <2 x i64> @llvm.aarch64.crypto.sha512su0(<2 x i64> %a, <2 x i64> %b)
+  ret <2 x i64> %vsha512su0.i
+}
+
+define <2 x i64> @test_vsha512su1(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c) {
+; CHECK-LABEL: test_vsha512su1:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sha512su1 v0.2d, v1.2d, v2.2d
+; CHECK-NEXT:ret
+entry:
+  %vsha512su1.i = tail call <2 x i64> @llvm.aarch64.crypto.sha512su1(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c)
+  ret <2 x i64> %vsha512su1.i
+}
+
+define <2 x i64> @test_vrax1(<2 x i64> %a, <2 x i64> %b) {
+; CHECK-LABEL: test_vrax1:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:rax1 v0.2d, v0.2d, v1.2d
+; CHECK-NEXT:ret
+entry:
+  %vrax1.i = tail call <2 x i64> @llvm.aarch64.crypto.rax1(<2 x i64> %a, <2 x i64> %b)
+  ret <2 x i64> %vrax1.i
+}
+
+define <2 x i64> @test_vxar(<2 x i64> %a,  <2 x i64> %b) {
+; CHECK-LABEL: test_vxar:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:xar v0.2d, v0.2d, v1.2d, #1
+; CHECK-NEXT:ret
+entry:
+  %vxar.i = tail call  <2 x i64> @llvm.aarch64.crypto.xar(<2 x i64> %a, <2 x i64> %b, i64 1)
+  ret <2 x i64> %vxar.i
+}
+
+define <16 x i8> @test_bcax_8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c) {
+; CHECK-LABEL: test_bcax_8:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bcax v0.16b, v0.16b, v1.16b, v2.16b
+; CHECK-NEXT:ret
+entry:
+  %vbcax_8.i = tail call <16 x i8> @llvm.aarch64.crypto.bcaxu.v16i8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c)
+  ret <16 x i8> %vbcax_8.i
+}
+
+define <16 x i8> @test_eor3_8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c) {
+; CHECK-LABEL: test_eor3_8:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:eor3 v0.16b, v0.16b, v1.16b, v2.16b
+; CHECK-NEXT:ret
+entry:
+  %veor3_8.i = tail call <16 x i8> @llvm.aarch64.crypto.eor3u.v16i8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c)
+  ret <16 x i8> %veor3_8.i
+}
+
+define <16 x i8> @test_bcax_s8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c) {
+; CHECK-LABEL: test_bcax_s8:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bcax v0.16b, v0.16b, v1.16b, v2.16b
+; CHECK-NEXT:ret
+entry:
+  %vbcax_8.i = tail call <16 x i8> @llvm.aarch64.crypto.bcaxs.v16i8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c)
+  ret <16 x i8> %vbcax_8.i
+}
+
+define <16 x i8> @test_eor3_s8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c) {
+; CHECK-LABEL: test_eor3_s8:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:eor3 v0.16b, v0.16b, v1.16b, v2.16b
+; CHECK-NEXT:ret
+entry:
+  %veor3_8.i = tail call <16 x i8> @llvm.aarch64.crypto.eor3s.v16i8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c)
+  ret <16 x i8> %veor3_8.i
+}
+
+define <8 x i16> @test_bcax_16(<8 x i16> %a, <8 x i16> %b, <8 x i16> %c) {
+; CHECK-LABEL: test_bcax_16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bcax v0.16b, v0.16b, v1.16b, v2.16b
+; CHECK-NEXT:ret
+entry:
+  %vbcax_16.i = tai

[PATCH] D96381: [AArch64] Adding SHA3 Intrinsics support

2021-02-22 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added inline comments.



Comment at: clang/test/CodeGen/aarch64-neon-range-checks.c:31
   vsm3tt2bq_u32(a, b, c, 0);
+
+void test_range_check_xar(uint64x2_t a, uint64x2_t b) {

I added a "}" here. Please run ninja check-clang and/or check-llvm before you 
update patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96381

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


[clang] cf3ef15 - [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-22T12:24:16Z
New Revision: cf3ef15a6ec5e5b45c6c54e8fbe3769255e815ce

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

LOG: [OpenCL] Add builtin declarations by default.

This change enables the builtin function declarations
in clang driver by default using the Tablegen solution
along with the implicit include of 'opencl-c-base.h'
header.

A new flag '-cl-no-stdinc' disabling all default
declarations and header includes is added. If any other
mechanisms were used to include the declarations (e.g.
with -Xclang -finclude-default-header) and the new default
approach is not sufficient the, `-cl-no-stdinc` flag has
to be used with clang to activate the old behavior.

Tags: #clang

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

Added: 
clang/test/Driver/default-includes.cl

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/Types.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/Types.cpp
clang/unittests/AST/MatchVerifier.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bbaa16658639..e4a6ef9cb2f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -818,6 +818,8 @@ def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-round
 def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Defines that the global work-size be a multiple of 
the work-group size specified to clEnqueueNDRangeKernel">,
   MarshallingInfoFlag>;
+def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group,
+  HelpText<"OpenCL only. Disables all standard includes containing non-native 
compiler types and functions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, 
Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;

diff  --git a/clang/include/clang/Driver/Types.h 
b/clang/include/clang/Driver/Types.h
index 97bf5fd672ab..6a1f57416ae5 100644
--- a/clang/include/clang/Driver/Types.h
+++ b/clang/include/clang/Driver/Types.h
@@ -81,6 +81,9 @@ namespace types {
   /// isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
   bool isObjC(ID Id);
 
+  /// isOpenCL - Is this an "OpenCL" input.
+  bool isOpenCL(ID Id);
+
   /// isFortran - Is this a Fortran input.
   bool isFortran(ID Id);
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 386bec831175..17bb48cd595d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3193,7 +3193,8 @@ static void RenderTrivialAutoVarInitOptions(const Driver 
&D,
   }
 }
 
-static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs) {
+static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs,
+types::ID InputType) {
   // cl-denorms-are-zero is not forwarded. It is translated into a generic flag
   // for denormal flushing handling based on the target.
   const unsigned ForwardedArguments[] = {
@@ -3218,6 +3219,13 @@ static void RenderOpenCLOptions(const ArgList &Args, 
ArgStringList &CmdArgs) {
   for (const auto &Arg : ForwardedArguments)
 if (const auto *A = Args.getLastArg(Arg))
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
+
+  // Only add the default headers if we are compiling OpenCL sources.
+  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  !Args.hasArg(options::OPT_cl_no_stdinc)) {
+CmdArgs.push_back("-finclude-default-header");
+CmdArgs.push_back("-fdeclare-opencl-builtins");
+  }
 }
 
 static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args,
@@ -5726,7 +5734,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   }
 
   // Forward -cl options to -cc1
-  RenderOpenCLOptions(Args, CmdArgs);
+  RenderOpenCLOptions(Args, CmdArgs, InputType);
 
   if (IsHIP) {
 if (Args.hasFlag(options::OPT_fhip_new_launch_api,

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 2050dffa6fa0..9bdebe2dd761 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -160,6 +160,8 @@ bool types::isObjC(ID Id) {
   }
 }
 
+bool types::isOpenCL(ID Id) { return Id == TY_CL; }
+
 bool types::isCXX(ID Id) {
   switch (Id) {
   default:

diff  --git a/clang/test/Driver/default-includes.cl 
b/clang/test/Driver/default-includes.cl
new file mode 100644
index ..2596ccca9638
--- /dev/null
+++ b/clang/test/Driver/default-includes.cl
@@ -0,0 +1,13 @@
+//

[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf3ef15a6ec5: [OpenCL] Add builtin declarations by default. 
(authored by Anastasia).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96515

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/Types.cpp
  clang/test/Driver/default-includes.cl
  clang/unittests/AST/MatchVerifier.h

Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -117,6 +117,7 @@
 FileName = "input.cc";
 break;
   case Lang_OpenCL:
+Args.push_back("-cl-no-stdinc");
 FileName = "input.cl";
 break;
   case Lang_OBJCXX:
Index: clang/test/Driver/default-includes.cl
===
--- /dev/null
+++ clang/test/Driver/default-includes.cl
@@ -0,0 +1,13 @@
+// RUN: %clang %s -Xclang -verify -fsyntax-only
+// RUN: %clang %s -cl-no-stdinc -Xclang -verify -DNOINC -fsyntax-only
+
+#ifndef NOINC
+//expected-no-diagnostics
+#endif
+
+void test() {
+int i = get_global_id(0);
+#ifdef NOINC
+//expected-error@-2{{implicit declaration of function 'get_global_id' is invalid in OpenCL}}
+#endif
+}
Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -160,6 +160,8 @@
   }
 }
 
+bool types::isOpenCL(ID Id) { return Id == TY_CL; }
+
 bool types::isCXX(ID Id) {
   switch (Id) {
   default:
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3193,7 +3193,8 @@
   }
 }
 
-static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs) {
+static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs,
+types::ID InputType) {
   // cl-denorms-are-zero is not forwarded. It is translated into a generic flag
   // for denormal flushing handling based on the target.
   const unsigned ForwardedArguments[] = {
@@ -3218,6 +3219,13 @@
   for (const auto &Arg : ForwardedArguments)
 if (const auto *A = Args.getLastArg(Arg))
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
+
+  // Only add the default headers if we are compiling OpenCL sources.
+  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  !Args.hasArg(options::OPT_cl_no_stdinc)) {
+CmdArgs.push_back("-finclude-default-header");
+CmdArgs.push_back("-fdeclare-opencl-builtins");
+  }
 }
 
 static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args,
@@ -5726,7 +5734,7 @@
   }
 
   // Forward -cl options to -cc1
-  RenderOpenCLOptions(Args, CmdArgs);
+  RenderOpenCLOptions(Args, CmdArgs, InputType);
 
   if (IsHIP) {
 if (Args.hasFlag(options::OPT_fhip_new_launch_api,
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -81,6 +81,9 @@
   /// isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
   bool isObjC(ID Id);
 
+  /// isOpenCL - Is this an "OpenCL" input.
+  bool isOpenCL(ID Id);
+
   /// isFortran - Is this a Fortran input.
   bool isFortran(ID Id);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -818,6 +818,8 @@
 def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Defines that the global work-size be a multiple of the work-group size specified to clEnqueueNDRangeKernel">,
   MarshallingInfoFlag>;
+def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group,
+  HelpText<"OpenCL only. Disables all standard includes containing non-native compiler types and functions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97161: Improve diagnostic for ignored GNU 'used' attribute

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

LGTM, thank you, that's a much better diagnostic than the original!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97161

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


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests: http://45.33.8.238/linux/39988/step_8.txt

Please take a look, and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96515

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


[clang] ba1d954 - Revert "Revert "Implement nullPointerConstant() using a better API.""

2021-02-22 Thread Mikhail Goncharov via cfe-commits

Author: Mikhail Goncharov
Date: 2021-02-22T13:43:42+01:00
New Revision: ba1d9546ee389ce1d2e8f353ae777a65f647d508

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

LOG: Revert "Revert "Implement nullPointerConstant() using a better API.""

This reverts commit 6984e0d4398592a20055cb12842fc72462ce01a5.

While change by itself seems to be consistent with nullPointerConstant
docs of not matching "int i = 0;" but it's not clear why it's wrong and
9148302a2ae5ac6e5d69ae84042361889247ce64 author just forgot to update
the doc.

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index b82929019f6c..6cd4d26768b5 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7384,10 +7384,9 @@ extern const internal::VariadicDynCastAllOfMatcher
 /// expr(nullPointerConstant())
 ///   matches the initializer for v1, v2, v3, cp, and ip. Does not match the
 ///   initializer for i.
-AST_MATCHER_FUNCTION(internal::Matcher, nullPointerConstant) {
-  return anyOf(
-  gnuNullExpr(), cxxNullPtrLiteralExpr(),
-  integerLiteral(equals(0), hasParent(expr(hasType(pointerType());
+AST_MATCHER(Expr, nullPointerConstant) {
+  return Node.isNullPointerConstant(Finder->getASTContext(),
+Expr::NPC_ValueDependentIsNull);
 }
 
 /// Matches the DecompositionDecl the binding belongs to.

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index c26e8f8d4d22..1c6947acf0ab 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3663,7 +3663,7 @@ TEST_P(ASTMatchersTest, NullPointerConstant) {
   expr(nullPointerConstant(;
   EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
   EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
+  EXPECT_TRUE(matches("int i = 0;", expr(nullPointerConstant(;
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {



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


[PATCH] D96777: [clang][driver] Set the input type to Fortran when reading from stdin

2021-02-22 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D96777#2578473 , @awarzynski wrote:

> In D96777#2578153 , @SouraVX wrote:
>
>> Thanks! for the patch.
>> This code touches some of the `clang` part, Anyway changes are pretty 
>> self-explanatory. I'll leave this one to you, if you want land it or wait 
>> from someone from `clang` community to take a look :)
>
> Thank you for reviewing!
>
> Git history tells me that @hans touched this bit most recently - in 2014 :) 
> Added as a reviewer - I will wait another day or two before merging.

I don't remember what I did here in 2014, but this looks reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96777

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


[PATCH] D96665: Revert "Implement nullPointerConstant() using a better API."

2021-02-22 Thread Mikhail Goncharov via Phabricator via cfe-commits
goncharov added a comment.

Hi @steveire! Sorry but I reverted this revert. Could you please give some 
context of "discussed elsewhere" and "pre-existing unit test for the matcher"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96665

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


[PATCH] D96838: Add GNU attribute 'retain'

2021-02-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2655
+
+def Retain : InheritableAttr {
+  let Spellings = [GCC<"retain">];

MaskRay wrote:
> aaron.ballman wrote:
> > Should this be a target-specific attribute as it only has effects on ELF 
> > targets?
> As I understand it, GCC `retain` is not warned on unsupported targets.
> 
> Regardless of GCC's choice, I think not having a `warning: unknown attribute 
> 'retain' ignored [-Wunknown-attributes]` diagnostic makes sense. `retain` 
> will be usually used together with `used`. In Clang, `used` already has 
> "retain" semantics on macOS and Windows (I don't know what they do on GCC; 
> GCC folks want orthogonality for ELF and I agree). If `retain` is silently 
> ignored on macOS and Windows, then users don't need to condition compile for 
> different targets.
The other side of that is a user who writes only `retain` and expects it to do 
something when it's actually being silently ignored. While they may usually use 
it in conjunction with `used`, I'm more worried about the situation where the 
user is possibly confused.



Comment at: clang/lib/Sema/SemaDecl.cpp:2834
   }
+  if (RetainAttr *OldAttr = Old->getMostRecentDecl()->getAttr()) {
+RetainAttr *NewAttr = OldAttr->clone(Context);

MaskRay wrote:
> aaron.ballman wrote:
> > I realize you're following the same pattern as the used attribute, but.. 
> > why is this code even necessary? The attributes are already marked as being 
> > inherited in Attr.td, so I'd not expect to need either of these. (If you 
> > don't know the answer off the top of your head, that's fine -- I can 
> > investigate on my own.)
> Without `setInherited`, `attr-decl-after-definition.c` will fail. (I don't 
> know why..) So I will keep the code but add a test case using the variable 
> `tentative`.
Thanks, if I get the chance, I'll try to look into why this code is necessary 
(and make adjustments if needed).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96838

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


[PATCH] D97053: [clang][SVE] Don't warn on vector to sizeless builtin implicit conversion

2021-02-22 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added a comment.

In D97053#2575791 , @craig.topper 
wrote:

> Is this change specific to fixed vectors declared with arm_sve_vector_bits or 
> any of the subclasses of VectorType? If it allows the others, how do we know 
> for sure that there are enough bits in the scalable type for the fixed 
> vector. I ask because RISCV is also using sizeless builtin types for our 
> vectors as of D92715 .

Thanks for pointing out that out Craig, I wasn't aware RISCV is also using 
sizeless builtins now, I hadn't considered that.




Comment at: clang/lib/Sema/SemaChecking.cpp:12055
+  if (auto *SourceVT = dyn_cast(Source)) {
+if (Target->isSizelessBuiltinType()) {
+  auto SourceVectorKind = SourceVT->getVectorKind();

I suppose we could tighten this further by replacing `isSizelessBuiltinType` 
with `isVLSTBuiltinType`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97053

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


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D96515#2578629 , @thakis wrote:

> Looks like this breaks tests: http://45.33.8.238/linux/39988/step_8.txt
>
> Please take a look, and revert for now if it takes a while to fix.

Thanks for pointing this out. I think the following change should fix the 
issue, but I am still trying to reproduce it locally as it is taking time to 
build.

  diff --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp 
b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
  index 8ba26c3b7396..31f61027994f 100644
  --- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
  +++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
  @@ -1,4 +1,4 @@
  -// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl | 
FileCheck --strict-whitespace %s
  +// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl 
-cl-no-stdinc | FileCheck --strict-whitespace %s
   
   #pragma OPENCL EXTENSION all : disable
   #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable

FYI, @thakis would you be able to approve the fix? Otherwise, I am also ok to 
revert it until I figure out how to commit the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96515

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


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a subscriber: klimek.
Anastasia added a comment.

In D96515#2578666 , @Anastasia wrote:

> In D96515#2578629 , @thakis wrote:
>
>> Looks like this breaks tests: http://45.33.8.238/linux/39988/step_8.txt
>>
>> Please take a look, and revert for now if it takes a while to fix.
>
> Thanks for pointing this out. I think the following change should fix the 
> issue, but I am still trying to reproduce it locally as it is taking time to 
> build.
>
>   diff --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp 
> b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>   index 8ba26c3b7396..31f61027994f 100644
>   --- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>   +++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>   @@ -1,4 +1,4 @@
>   -// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl | 
> FileCheck --strict-whitespace %s
>   +// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl 
> -cl-no-stdinc | FileCheck --strict-whitespace %s
>
>#pragma OPENCL EXTENSION all : disable
>#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable
>
> FYI, @thakis would you be able to approve the fix? Otherwise, I am also ok to 
> revert it until I figure out how to commit the fix.

@klimek, I am not very familiar with clang-tools-extra, would it be possible to 
look at the fix for the broken test? I can create a review if needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96515

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


[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2021-02-22 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

@shixiao do you have plans to keep working on this diff? If not, do you have 
any objections if I send for review a similar diff that will eliminate the 
check `Sources.isInMainFile` and will rely on generic header filtration 
mechanism in clang-tidy?

We have faced the same issue on our codebase and would like to make this check 
works on headers too.

In D61989#2367012 , @njames93 wrote:

> Tbh clang-tidy already handles disabling warnings for header files, so some 
> of the code here isn't needed

+1 to use generic header filtration mechanism and avoid adding new option for 
this particular check. I tried to find the reason why `Sources.isInMainFile` 
was added but it looks like it was not even discussed during initial codereview 
D52136 

Everyone please speak up if there is a good reason to limit this check to the 
main file only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989

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


[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D61989#2578687 , @DmitryPolukhin 
wrote:

> Everyone please speak up if there is a good reason to limit this check to the 
> main file only.

The only possible reason I can see to limit to main file only is if the header 
is included in pre-c++17 and post c++17 translation units. Though that is a 
very niche use case IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989

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


[clang] 3b148d6 - Revert "Revert "Revert "Implement nullPointerConstant() using a better API."""

2021-02-22 Thread Mikhail Goncharov via cfe-commits

Author: Mikhail Goncharov
Date: 2021-02-22T14:37:03+01:00
New Revision: 3b148d6f991181a1b8f089c4bc2126e1a6c1212d

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

LOG: Revert "Revert "Revert "Implement nullPointerConstant() using a better 
API."""

This reverts commit ba1d9546ee389ce1d2e8f353ae777a65f647d508.

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 6cd4d26768b5..b82929019f6c 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7384,9 +7384,10 @@ extern const internal::VariadicDynCastAllOfMatcher
 /// expr(nullPointerConstant())
 ///   matches the initializer for v1, v2, v3, cp, and ip. Does not match the
 ///   initializer for i.
-AST_MATCHER(Expr, nullPointerConstant) {
-  return Node.isNullPointerConstant(Finder->getASTContext(),
-Expr::NPC_ValueDependentIsNull);
+AST_MATCHER_FUNCTION(internal::Matcher, nullPointerConstant) {
+  return anyOf(
+  gnuNullExpr(), cxxNullPtrLiteralExpr(),
+  integerLiteral(equals(0), hasParent(expr(hasType(pointerType());
 }
 
 /// Matches the DecompositionDecl the binding belongs to.

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 1c6947acf0ab..c26e8f8d4d22 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3663,7 +3663,7 @@ TEST_P(ASTMatchersTest, NullPointerConstant) {
   expr(nullPointerConstant(;
   EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant(;
   EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant(;
-  EXPECT_TRUE(matches("int i = 0;", expr(nullPointerConstant(;
+  EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant(;
 }
 
 TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {



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


[PATCH] D92195: [OPENMP50]Mapping of the subcomponents with the 'default' mappers.

2021-02-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 325425.
ABataev added a comment.

Temp update, not finished yet. Still WIP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92195

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_codegen_34.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp

Index: openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
@@ -0,0 +1,62 @@
+// RUN: %libomptarget-compilexx-run-and-check-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compilexx-run-and-check-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-run-and-check-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-run-and-check-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda
+
+#include 
+#include 
+
+typedef struct {
+  int a;
+  double *b;
+} C1;
+#pragma omp declare mapper(C1 s) map(to : s.a) map(from : s.b [0:2])
+
+typedef struct {
+  int a;
+  double *b;
+  C1 c;
+} C;
+#pragma omp declare mapper(C s) map(to : s.a, s.c) map(from : s.b [0:2])
+
+typedef struct {
+  int e;
+  C f;
+  int h;
+} D;
+
+int main() {
+  constexpr int N = 10;
+  D s;
+  s.e = 111;
+  s.f.a = 222;
+  double x[2];
+  double x1[2];
+  x[1] = 20;
+  s.f.b = &x[0];
+  s.f.c.b = &x1[0];
+  s.h = N;
+
+  D *sp = &s;
+  D **spp = &sp;
+
+  printf("%d %d %4.5f %d %p %p %p %p %p\n", spp[0][0].e, spp[0][0].f.a,
+ spp[0][0].f.b[1], spp[0][0].f.b == &x[0] ? 1 : 0, &sp, sp, &s.e, &s.f,
+ &s.h);
+  // CHECK: 111 222 20.0 1
+
+  __intptr_t p = reinterpret_cast<__intptr_t>(&x[0]);
+#pragma omp target map(tofrom : spp[0][0]) firstprivate(p)
+  {
+printf("%d %d\n", spp[0][0].f.a,
+   spp[0][0].f.b == reinterpret_cast(p) ? 1 : 0);
+// CHECK: 222 0
+spp[0][0].e = 333;
+spp[0][0].f.a = 444;
+spp[0][0].f.b[1] = 40;
+  }
+  printf("%d %d %4.5f %d\n", spp[0][0].e, spp[0][0].f.a, spp[0][0].f.b[1],
+ spp[0][0].f.b == &x[0] ? 1 : 0);
+  // CHECK: 333 222 40.0 1
+}
Index: clang/test/OpenMP/target_map_codegen_34.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_map_codegen_34.cpp
@@ -0,0 +1,258 @@
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+///==///
+// RUN: %clang_cc1 -DCK34 -verify -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefix CK34 --check-prefix CK34-64
+// RUN: %clang_cc1 -DCK34 -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  --check-prefix CK34 --check-prefix CK34-64
+// RUN: %clang_cc1 -DCK34 -verify -fopenmp -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s  --check-prefix CK34 --check-prefix CK34-32
+// RUN: %clang_cc1 -DCK34 -fopenmp -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  --check-prefix CK34 --check-prefix CK34-32
+
+// RUN: %clang_cc1 -DCK34 -verify -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY32 %s
+// RUN: %clang_cc1 -DCK34 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY32 %s
+// RUN: %clang_cc1 -DCK34 -verify -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY32 %s
+// RUN: %clang_cc1 -DCK34 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=i386-p

[PATCH] D96665: Revert "Implement nullPointerConstant() using a better API."

2021-02-22 Thread Mikhail Goncharov via Phabricator via cfe-commits
goncharov added a comment.

I have relanded this in 
https://github.com/llvm/llvm-project/commit/3b148d6f991181a1b8f089c4bc2126e1a6c1212d
 . My apologies


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96665

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


[PATCH] D95753: [Coverage] Store compilation dir separately in coverage mapping

2021-02-22 Thread greg miller via Phabricator via cfe-commits
gregmiller added a comment.

Hello, we are seeing failures like below:

Note: Google Test filter = 
ParameterizedCovMapTest/CoverageMappingTest.skip_duplicate_function_record/0
[==] Running 1 test from 1 test case.
[--] Global test environment set-up.
[--] 1 test from ParameterizedCovMapTest/CoverageMappingTest
[ RUN ] 
ParameterizedCovMapTest/CoverageMappingTest.skip_duplicate_function_record/0
/scratch/build_jenkins/workspace/Downstream_Changes/llvm_cgt/llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp:889:
 Failure
Expected: 3U
Which is: 3
To be equal to: NumFuncs
Which is: 5
[ FAILED ] 
ParameterizedCovMapTest/CoverageMappingTest.skip_duplicate_function_record/0, 
where GetParam() = (false, false) (0 ms)

Do you have any suggestions on why we would start seeing above failures after 
your commit? Was passing before.

Thanks
Greg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95753

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


[PATCH] D97132: [clang-tidy] Harden PreferMemberInitializerCheck

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 325428.
njames93 added a comment.

Fix potential crash if macros are used, Now we just don't try to emit a fix.
Fix issue where FixIt for member initializers would be inserted at the start of 
the constructor decl due to implicit member initializers confusing it.
Streamlined method for finding where to create member initializers when there's 
no member initializer list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97132

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -488,3 +488,48 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
 // CHECK-FIXES: {{^\ *$}}
 }
+
+struct SafeDependancy {
+  int m;
+  int n;
+  SafeDependancy(int M) : m(M) {
+// CHECK-FIXES: SafeDependancy(int M) : m(M), n(m) {
+n = m;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor
+  }
+  // We match against direct field dependancy as well as descendant field
+  // dependancy, ensure both are accounted for.
+  SafeDependancy(short M) : m(M) {
+// CHECK-FIXES: SafeDependancy(short M) : m(M), n(m + 1) {
+n = m + 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor
+  }
+};
+
+struct BadDependancy {
+  int m;
+  int n;
+  BadDependancy(int N) : n(N) {
+m = n;
+  }
+  BadDependancy(short N) : n(N) {
+m = n + 1;
+  }
+};
+
+struct InitFromVarDecl {
+  int m;
+  InitFromVarDecl() {
+// Can't apply this fix as n is declared in the body of the constructor.
+int n = 3;
+m = n;
+  }
+};
+
+struct AlreadyHasInit {
+  int m = 4;
+  AlreadyHasInit() {
+m = 3;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm' should be initialized in a member initializer of the constructor
+  }
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -8,7 +8,9 @@
 
 #include "PreferMemberInitializerCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
@@ -55,8 +57,37 @@
   return false;
 }
 
+namespace {
+AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
+  return Node.getFieldIndex() >= Index;
+}
+} // namespace
+
+// Checks if Field is initialised using a field that will be initialised after
+// it.
+// TODO: Probably should guard against function calls that could have side
+// effects or if they do reference another field that's initialized before this
+// field, but is modified before the assignment.
+static bool isSafeAssignment(const FieldDecl *Field, const Expr *Init,
+ const CXXConstructorDecl *Context) {
+
+  auto MemberMatcher =
+  memberExpr(hasObjectExpression(cxxThisExpr()),
+ member(fieldDecl(indexNotLessThan(Field->getFieldIndex();
+
+  auto DeclMatcher = declRefExpr(
+  to(varDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Context);
+
+  return match(expr(anyOf(MemberMatcher, DeclMatcher,
+  hasDescendant(MemberMatcher),
+  hasDescendant(DeclMatcher))),
+   *Init, Field->getASTContext())
+  .empty();
+}
+
 static const std::pair
-isAssignmentToMemberOf(const RecordDecl *Rec, const Stmt *S) {
+isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
+   const CXXConstructorDecl *Ctor) {
   if (const auto *BO = dyn_cast(S)) {
 if (BO->getOpcode() != BO_Assign)
   return std::make_pair(nullptr, nullptr);
@@ -69,8 +100,11 @@
 if (!Field)
   return std::make_pair(nullptr, nullptr);
 
-if (isa(ME->getBase()))
-  return std::make_pair(Field, BO->getRHS()->IgnoreParenImpCasts());
+if (!isa(ME->getBase()))
+  return std::make_pair(nullptr, nullptr);
+const auto *Init = BO->getRHS()->IgnoreParenImpCasts();
+if (isSafeAssignment(Field, Init, Ctor))
+  return std::make_pair(Field, Init);
   } else if (

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

If there is no objection, I’ll merge it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

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


[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

2021-02-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

I think we might not this patch. We’re gonna not support old version of CUDA 
anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96877

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


[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

2021-02-22 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

to me this is still desired + cmake creating libomptarget-nvptx-unknown.bc as a 
solution for forward compatibility until a clean solution lands.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96877

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


[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

2021-02-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D96877#2578748 , @ye-luo wrote:

> to me this is still desired + cmake creating libomptarget-nvptx-unknown.bc as 
> a solution for forward compatibility until a clean solution lands.

We’ll have newer version LLVM like 12.1 or 12.01 w/ a *right* solution. I don’t 
think we need to think that further.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96877

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


[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

2021-02-22 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

In D96877#2578752 , @tianshilei1992 
wrote:

> In D96877#2578748 , @ye-luo wrote:
>
>> to me this is still desired + cmake creating libomptarget-nvptx-unknown.bc 
>> as a solution for forward compatibility until a clean solution lands.
>
> We’ll have newer version LLVM like 12.1 or 12.01 w/ a *right* solution. I 
> don’t think we need to think that further.

This doesn't help people who needs to run exactly 12.0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96877

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


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D96515#2578666 , @Anastasia wrote:

> In D96515#2578629 , @thakis wrote:
>
>> Looks like this breaks tests: http://45.33.8.238/linux/39988/step_8.txt
>>
>> Please take a look, and revert for now if it takes a while to fix.
>
> Thanks for pointing this out. I think the following change should fix the 
> issue, but I am still trying to reproduce it locally as it is taking time to 
> build.
>
>   diff --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp 
> b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>   index 8ba26c3b7396..31f61027994f 100644
>   --- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>   +++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>   @@ -1,4 +1,4 @@
>   -// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl | 
> FileCheck --strict-whitespace %s
>   +// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl 
> -cl-no-stdinc | FileCheck --strict-whitespace %s
>
>#pragma OPENCL EXTENSION all : disable
>#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable
>
> FYI, @thakis would you be able to approve the fix? Otherwise, I am also ok to 
> revert it until I figure out how to commit the fix.

The test is already broken, so speculatively landing that and seeing if it 
helps sounds fine. But let's try to not keep the build broken for hours. (Was 
afk for a bit, and it looks like it's still broken now that I look again.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96515

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


[clang-tools-extra] b71add9 - [pp-trace] Fix test for OpenCL pragmas.

2021-02-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-22T14:28:45Z
New Revision: b71add9777bed67e05206fa1fdb665f3e21a13ab

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

LOG: [pp-trace] Fix test for OpenCL pragmas.

After updating clang driver to include standard
OpenCL headers implicitly, the output being checked
in the test does not match because the implicit
header contains other pragmas. The test does not
aim to use the header and therefore it has to be
updated passing '-cl-no-stdinc' command-line flag.

This fixes failing bots.

Added: 


Modified: 
clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp

Removed: 




diff  --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp 
b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
index 8ba26c3b7396..31f61027994f 100644
--- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
+++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl | 
FileCheck --strict-whitespace %s
+// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl 
-cl-no-stdinc | FileCheck --strict-whitespace %s
 
 #pragma OPENCL EXTENSION all : disable
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable



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


[PATCH] D96877: [libomptarget] Try a fallback devicertl if the preferred one is missing

2021-02-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D96877#2578756 , @ye-luo wrote:

> In D96877#2578752 , @tianshilei1992 
> wrote:
>
>> In D96877#2578748 , @ye-luo wrote:
>>
>>> to me this is still desired + cmake creating libomptarget-nvptx-unknown.bc 
>>> as a solution for forward compatibility until a clean solution lands.
>>
>> We’ll have newer version LLVM like 12.1 or 12.01 w/ a *right* solution. I 
>> don’t think we need to think that further.
>
> This doesn't help people who needs to run exactly 12.0. Also cannot wait for 
> a minor release, need things to work right away when a new cuda toolkit is 
> installed intentionally.

First, we don’t know whether a new version of CUDA will be released during this 
time, especially considering the release history of CUDA, 11.3 is not that 
possible, and 12 will not come out so soon. Second, even if NVIDIA’s people are 
so brilliant and release CUDA 12 in a short time,  we have a mechanism for user 
to work around the issue using the option `libomptarget-nvptx-bc-path`. This 
patch is just a work around, and it contains so many uncertainties, which 
cannot be called “forward compatibility” at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96877

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


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D96515#2578765 , @thakis wrote:

> In D96515#2578666 , @Anastasia wrote:
>
>> In D96515#2578629 , @thakis wrote:
>>
>>> Looks like this breaks tests: http://45.33.8.238/linux/39988/step_8.txt
>>>
>>> Please take a look, and revert for now if it takes a while to fix.
>>
>> Thanks for pointing this out. I think the following change should fix the 
>> issue, but I am still trying to reproduce it locally as it is taking time to 
>> build.
>>
>>   diff --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp 
>> b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>>   index 8ba26c3b7396..31f61027994f 100644
>>   --- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>>   +++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
>>   @@ -1,4 +1,4 @@
>>   -// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl | 
>> FileCheck --strict-whitespace %s
>>   +// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl 
>> -cl-no-stdinc | FileCheck --strict-whitespace %s
>>
>>#pragma OPENCL EXTENSION all : disable
>>#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable
>>
>> FYI, @thakis would you be able to approve the fix? Otherwise, I am also ok 
>> to revert it until I figure out how to commit the fix.
>
> The test is already broken, so speculatively landing that and seeing if it 
> helps sounds fine. But let's try to not keep the build broken for hours. (Was 
> afk for a bit, and it looks like it's still broken now that I look again.)

I have just committed the fix after verifying that it indeed makes the test 
pass: 
https://github.com/llvm/llvm-project/commit/b71add9777bed67e05206fa1fdb665f3e21a13ab


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96515

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


[PATCH] D97191: [clang][NFC] Reorder CXXCtorInitializer members

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: rsmith, aaron.ballman.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Swapping the order of Init and MemberOrEllipsisLocation removes 8 bytes (20%) 
of padding on 64bit builds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97191

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/DeclCXX.cpp


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2506,16 +2506,15 @@
SourceLocation L, Expr *Init,
SourceLocation R,
SourceLocation EllipsisLoc)
-: Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
+: Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
   IsWritten(false), SourceOrder(0) {}
 
-CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
-   FieldDecl *Member,
+CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
@@ -2524,7 +2523,7 @@
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -2166,6 +2166,10 @@
   llvm::PointerUnion
   Initializee;
 
+  /// The argument used to initialize the base or member, which may
+  /// end up constructing an object (when multiple arguments are involved).
+  Stmt *Init;
+
   /// The source location for the field name or, for a base initializer
   /// pack expansion, the location of the ellipsis.
   ///
@@ -2174,10 +2178,6 @@
   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
   SourceLocation MemberOrEllipsisLocation;
 
-  /// The argument used to initialize the base or member, which may
-  /// end up constructing an object (when multiple arguments are involved).
-  Stmt *Init;
-
   /// Location of the left paren of the ctor-initializer.
   SourceLocation LParenLoc;
 


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2506,16 +2506,15 @@
SourceLocation L, Expr *Init,
SourceLocation R,
SourceLocation EllipsisLoc)
-: Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
+: Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
   IsWritten(false), SourceOrder(0) {}
 
-CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
-   FieldDecl *Member,
+CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
@@ -2524,7 +2523,7 @@
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsW

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-22 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.

LGTM too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

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


[PATCH] D97191: [clang][NFC] Reorder CXXCtorInitializer members

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

LGTM, good catch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97191

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-02-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D96090#2574526 , @ASDenysPetrov 
wrote:

> @steakhal wrote:
>
>> This patch preserves all previous reports as expected.

Even with or without Z3 refutation.

> If this patch is technically full-baked and does not bring any harm, can we 
> approve it as well to move forward?

I would like @NoQ or someone else to also review this.


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

https://reviews.llvm.org/D96090

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


[clang] daeb70b - [clang][NFC] Reorder CXXCtorInitializer members

2021-02-22 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-02-22T15:25:33Z
New Revision: daeb70be0bd42fbed66c03b4c5f9940ffba88ce9

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

LOG: [clang][NFC] Reorder CXXCtorInitializer members

Swapping the order of Init and MemberOrEllipsisLocation removes 8 bytes (20%) 
of padding on 64bit builds.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/DeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 89006b1cfa7f..bb99ab1373ba 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2166,6 +2166,10 @@ class CXXCtorInitializer final {
   llvm::PointerUnion
   Initializee;
 
+  /// The argument used to initialize the base or member, which may
+  /// end up constructing an object (when multiple arguments are involved).
+  Stmt *Init;
+
   /// The source location for the field name or, for a base initializer
   /// pack expansion, the location of the ellipsis.
   ///
@@ -2174,10 +2178,6 @@ class CXXCtorInitializer final {
   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
   SourceLocation MemberOrEllipsisLocation;
 
-  /// The argument used to initialize the base or member, which may
-  /// end up constructing an object (when multiple arguments are involved).
-  Stmt *Init;
-
   /// Location of the left paren of the ctor-initializer.
   SourceLocation LParenLoc;
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 0375f9b4432e..f22e599225b6 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2506,16 +2506,15 @@ CXXCtorInitializer::CXXCtorInitializer(ASTContext 
&Context,
SourceLocation L, Expr *Init,
SourceLocation R,
SourceLocation EllipsisLoc)
-: Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
+: Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
   IsWritten(false), SourceOrder(0) {}
 
-CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
-   FieldDecl *Member,
+CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
@@ -2524,7 +2523,7 @@ CXXCtorInitializer::CXXCtorInitializer(ASTContext 
&Context,
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 



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


[PATCH] D97191: [clang][NFC] Reorder CXXCtorInitializer members

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdaeb70be0bd4: [clang][NFC] Reorder CXXCtorInitializer 
members (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97191

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/DeclCXX.cpp


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2506,16 +2506,15 @@
SourceLocation L, Expr *Init,
SourceLocation R,
SourceLocation EllipsisLoc)
-: Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
+: Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
   IsWritten(false), SourceOrder(0) {}
 
-CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
-   FieldDecl *Member,
+CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
@@ -2524,7 +2523,7 @@
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -2166,6 +2166,10 @@
   llvm::PointerUnion
   Initializee;
 
+  /// The argument used to initialize the base or member, which may
+  /// end up constructing an object (when multiple arguments are involved).
+  Stmt *Init;
+
   /// The source location for the field name or, for a base initializer
   /// pack expansion, the location of the ellipsis.
   ///
@@ -2174,10 +2178,6 @@
   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
   SourceLocation MemberOrEllipsisLocation;
 
-  /// The argument used to initialize the base or member, which may
-  /// end up constructing an object (when multiple arguments are involved).
-  Stmt *Init;
-
   /// Location of the left paren of the ctor-initializer.
   SourceLocation LParenLoc;
 


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2506,16 +2506,15 @@
SourceLocation L, Expr *Init,
SourceLocation R,
SourceLocation EllipsisLoc)
-: Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
+: Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
   IsWritten(false), SourceOrder(0) {}
 
-CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
-   FieldDecl *Member,
+CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
@@ -2524,7 +2523,7 @@
SourceLocation MemberLoc,
SourceLocation L, Expr *Init,
SourceLocation R)
-: Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+: Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
   LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   IsWritten(false), SourceOrder(0) {}
 
Index: clang/include/cla

[PATCH] D97125: Stop traping on sNaN in __builtin_isinf

2021-02-22 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

System/Z's TEST DATA CLASS instruction covers most (all?) of the possible FP 
value states. You might want to subscribe, or add as a reviewer, jonpa just to 
make sure everyone stays in sync.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97125

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


[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

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

LGTM aside from some nits.




Comment at: clang/lib/Parse/ParseDeclCXX.cpp:861
+   SourceLocation EndExprLoc) {
+  if (const auto *BO = llvm::dyn_cast_or_null(AssertExpr)) {
+if (BO->getOpcode() == BO_LAnd &&





Comment at: clang/lib/Parse/ParseDeclCXX.cpp:863
+if (BO->getOpcode() == BO_LAnd &&
+llvm::isa(BO->getRHS()->IgnoreImpCasts()))
+  return FixItHint::CreateReplacement(BO->getOperatorLoc(), ",");





Comment at: clang/test/FixIt/fixit-static-assert.cpp:2-3
+// RUN: %clang_cc1 -std=c++14 %s -fdiagnostics-parseable-fixits %s 2>&1 | 
FileCheck %s
+// Ensure no warnings are emitted in c++17.
+// RUN: %clang_cc1 -std=c++17 %s -Werror -fsyntax-only
+// RUN: %clang_cc1 -std=c++14 %s -fixit-recompile -fixit-to-temporary -Werror

Any reason not to pass `-verify=cxx17` and `// cxx17-no-diagnostics`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

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


[PATCH] D50106: [libc++] Fix tuple assignment from types derived from a tuple-like

2021-02-22 Thread Louis Dionne via Phabricator via cfe-commits
ldionne updated this revision to Diff 325445.
ldionne marked 6 inline comments as done.
ldionne added a comment.

Address Arthur's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D50106

Files:
  libcxx/include/tuple
  
libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.assign/array.extension.pass.cpp
  
libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp
  
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/derived_from_tuple_like.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/laziness.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp
  
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp
  libcxx/test/support/propagate_value_category.hpp

Index: libcxx/test/support/propagate_value_category.hpp
===
--- /dev/null
+++ libcxx/test/support/propagate_value_category.hpp
@@ -0,0 +1,153 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
+#define TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
+
+#include "test_macros.h"
+#include 
+
+#if TEST_STD_VER < 11
+#error this header may only be used in C++11
+#endif
+
+using UnderlyingVCType = unsigned;
+enum ValueCategory : UnderlyingVCType {
+  VC_None = 0,
+  VC_LVal = 1 << 0,
+  VC_RVal = 1 << 1,
+  VC_Const = 1 << 2,
+  VC_Volatile = 1 << 3,
+  VC_ConstVolatile = VC_Const | VC_Volatile
+};
+
+inline constexpr ValueCategory operator&(ValueCategory LHS, ValueCategory RHS) {
+  return ValueCategory(LHS & (UnderlyingVCType)RHS);
+}
+
+inline constexpr ValueCategory operator|(ValueCategory LHS, ValueCategory RHS) {
+  return ValueCategory(LHS | (UnderlyingVCType)RHS);
+}
+
+inline constexpr ValueCategory operator^(ValueCategory LHS, ValueCategory RHS) {
+  return ValueCategory(LHS ^ (UnderlyingVCType)RHS);
+}
+
+inline constexpr bool isValidValueCategory(ValueCategory VC) {
+  return (VC & (VC_LVal | VC_RVal)) != (VC_LVal | VC_RVal);
+}
+
+inline constexpr bool hasValueCategory(ValueCategory Arg, ValueCategory Key) {
+  return Arg == Key || ((Arg & Key) == Key);
+}
+
+template 
+using UnCVRef =
+typename std::remove_cv::type>::type;
+
+template 
+constexpr ValueCategory getReferenceQuals() {
+  return std::is_lvalue_reference::value
+ ? VC_LVal
+ : (std::is_rvalue_reference::value ? VC_RVal : VC_None);
+}
+static_assert(getReferenceQuals() == VC_None, "");
+static_assert(getReferenceQuals() == VC_LVal, "");
+static_assert(getReferenceQuals() == VC_RVal, "");
+
+template 
+constexpr ValueCategory getCVQuals() {
+  using Vp = typename std::remove_reference::type;
+  return std::is_const::value && std::is_volatile::value
+ ? VC_ConstVolatile
+ : (std::is_const::value
+? VC_Const
+: (std::is_volatile::value ? VC_Volatile : VC_None));
+}
+static_assert(getCVQuals() == VC_None, "");
+static_assert(getCVQuals() == VC_Const, "");
+static_assert(getCVQuals() == VC_Volatile, "");
+static_assert(getCVQuals() == VC_ConstVolatile, "");
+static_assert(getCVQuals() == VC_None, "");
+static_assert(getCVQuals() == VC_Const, "");
+
+template 
+inline constexpr ValueCategory getValueCategory() {
+  return getReferenceQuals() | getCVQuals();
+}
+static_assert(getValueCategory() == VC_None, "");
+static_assert(getValueCategory() == (VC_LVal | VC_Const), "");
+static_assert(getValueCategory() ==
+  (VC_RVal | VC_ConstVolatile),
+  "");
+
+template 
+struct ApplyValueCategory {
+private:
+  static_assert(isValidValueCategory(VC), "");
+
+  template 
+  using CondT = typename std::conditional::type;
+
+public:
+  template >
+  using ApplyCVQuals = CondT<
+  hasValueCategory(VC, VC_ConstVolatile), typename std::add_cv::type,
+  CondT::type,
+CondT::type, Tp>>>;
+
+  template ::type>
+  using ApplyReferenceQuals =
+  CondT::type,
+CondT::type, Vp>>;
+
+  template 
+  using Apply = ApplyReferenceQuals>>;
+
+  template ::type = true>
+  static Apply> cast(Tp &&t) {
+using ToType = Apply>;
+retur

[PATCH] D50106: [libc++] Fix tuple assignment from types derived from a tuple-like

2021-02-22 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

I think we should be pretty much good to go now. Will let CI run just in case.




Comment at: libcxx/include/tuple:971
+_VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
+_VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
+return *this;

Quuxplusone wrote:
> Oh, late-breaking nit: I would prefer to see `... = 
> static_cast<_Up1&&>(__pair.first);` here, because `_Up1` is not being deduced 
> according to forwarding-reference rules, and thus shouldn't be "forwarded."  
> Pragmatically I think `forward<_Up1>` ends up doing the right thing in all 
> cases... but I don't think it's appropriate here. (Plus, we save one function 
> template instantiation by omitting it!)
It actually occurs to me that we should really be using 
`_VSTD::move(__pair.first)` since we're taking a rvalue reference to the pair 
as an argument. I'll change it to that, please LMK if you disagree.



Comment at: libcxx/include/tuple:975
+
+// EXTENSION
+template Perhaps in a followup patch: could we delineate exactly what code is part of 
> this extension and put it all under an `#if _LIBCPP_TUPLE_ARRAY_ASSIGNMENT` 
> or something, such that we could say "this is the exact extent of the 
> extension code" and maybe even get customers to try compiling with 
> `-D_LIBCPP_TUPLE_ARRAY_ASSIGNMENT=0` to see what breaks?
> 
> I'm assuming that our goal here is to deprecate and remove this extension 
> over time. But even if we support it forever, I think `#if` would be nicer 
> than the `//EXTENSION` comments.
The goal is to remove the extension shortly after.



Comment at: libcxx/include/tuple:992
+// EXTENSION
+template Nitpick: Sent you a Slack suggesting how to eliminate this `class = void`.
Replied there. The short story is that I used `class = void` to workaround the 
GCC segfaults I was seeing on the bots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D50106

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


[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-02-22 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp, xazax.hun, 
whisperity, mgorny.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97196

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
@@ -0,0 +1,133 @@
+// RUN: %check_clang_tidy -std=c++14 %s bugprone-unhandled-exception-at-new %t
+
+namespace std {
+typedef __typeof__(sizeof(0)) size_t;
+enum class align_val_t : std::size_t {};
+class exception {};
+class bad_alloc : public exception {};
+struct nothrow_t {};
+extern const nothrow_t nothrow;
+} // namespace std
+
+void *operator new(std::size_t, const std::nothrow_t &);
+void *operator new(std::size_t, std::align_val_t, const std::nothrow_t &);
+
+class A {};
+typedef std::bad_alloc badalloc1;
+using badalloc2 = std::bad_alloc;
+using badalloc3 = std::bad_alloc &;
+
+void f1() noexcept {
+  int *I1 = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: missing exception handler for allocation failure at 'new'
+  try {
+int *I2 = new int;
+try {
+  int *I3 = new int;
+} catch (A) {
+}
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc2) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc3) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (std::bad_alloc *) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (A) {
+  }
+}
+
+void f2() noexcept {
+  try {
+int *I = new int;
+  } catch (A) {
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (...) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::exception &) {
+  }
+}
+
+void f3() noexcept {
+  int *I1 = new (std::nothrow) int;
+  int *I2 = new (static_cast(1), std::nothrow) int;
+}
+
+void f_est_none() {
+  int *I = new int;
+}
+
+void f_est_noexcept_false() noexcept(false) {
+  int *I = new int;
+}
+
+void f_est_noexcept_true() noexcept(true) {
+  int *I = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_est_dynamic_none() throw() {
+  int *I = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_est_dynamic_1() throw(std::bad_alloc) {
+  int *I = new int;
+}
+
+void f_est_dynamic_2() throw(A) {
+  // the exception specification list is not checked
+  int *I = new int;
+}
+
+template 
+void f_est_noexcept_dependent() noexcept(P) {
+  int *I = new int;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -99,6 +99,7 @@
`bugprone-too-small-loop-variable `_,
`bugprone-undefined-memory-manipulation `_,
`bugprone-undelegated-constructor `_,
+   `bugprone-unhandled-exception-at-new `_,
`bugprone-unhandled-self-assignment `_,
`bugprone-unused-raii `_, "Yes"
`bugprone-unused-return-value `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - bugprone-unhandled-exception-at-new
+
+bugprone-unhandled-exception-at-new
+===
+
+Finds calls to ``new`` that may throw exception that is not handled.
+
+.. code-block:: c++
+
+  int *f() noexcept {
+int *p =

[PATCH] D50106: [libc++] Fix tuple assignment from types derived from a tuple-like

2021-02-22 Thread Louis Dionne via Phabricator via cfe-commits
ldionne updated this revision to Diff 325449.
ldionne added a comment.

Rebase onto main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D50106

Files:
  libcxx/include/tuple
  
libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.assign/array.extension.pass.cpp
  
libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp
  
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/derived_from_tuple_like.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/laziness.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp
  
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp
  libcxx/test/support/propagate_value_category.hpp

Index: libcxx/test/support/propagate_value_category.hpp
===
--- /dev/null
+++ libcxx/test/support/propagate_value_category.hpp
@@ -0,0 +1,153 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
+#define TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
+
+#include "test_macros.h"
+#include 
+
+#if TEST_STD_VER < 11
+#error this header may only be used in C++11
+#endif
+
+using UnderlyingVCType = unsigned;
+enum ValueCategory : UnderlyingVCType {
+  VC_None = 0,
+  VC_LVal = 1 << 0,
+  VC_RVal = 1 << 1,
+  VC_Const = 1 << 2,
+  VC_Volatile = 1 << 3,
+  VC_ConstVolatile = VC_Const | VC_Volatile
+};
+
+inline constexpr ValueCategory operator&(ValueCategory LHS, ValueCategory RHS) {
+  return ValueCategory(LHS & (UnderlyingVCType)RHS);
+}
+
+inline constexpr ValueCategory operator|(ValueCategory LHS, ValueCategory RHS) {
+  return ValueCategory(LHS | (UnderlyingVCType)RHS);
+}
+
+inline constexpr ValueCategory operator^(ValueCategory LHS, ValueCategory RHS) {
+  return ValueCategory(LHS ^ (UnderlyingVCType)RHS);
+}
+
+inline constexpr bool isValidValueCategory(ValueCategory VC) {
+  return (VC & (VC_LVal | VC_RVal)) != (VC_LVal | VC_RVal);
+}
+
+inline constexpr bool hasValueCategory(ValueCategory Arg, ValueCategory Key) {
+  return Arg == Key || ((Arg & Key) == Key);
+}
+
+template 
+using UnCVRef =
+typename std::remove_cv::type>::type;
+
+template 
+constexpr ValueCategory getReferenceQuals() {
+  return std::is_lvalue_reference::value
+ ? VC_LVal
+ : (std::is_rvalue_reference::value ? VC_RVal : VC_None);
+}
+static_assert(getReferenceQuals() == VC_None, "");
+static_assert(getReferenceQuals() == VC_LVal, "");
+static_assert(getReferenceQuals() == VC_RVal, "");
+
+template 
+constexpr ValueCategory getCVQuals() {
+  using Vp = typename std::remove_reference::type;
+  return std::is_const::value && std::is_volatile::value
+ ? VC_ConstVolatile
+ : (std::is_const::value
+? VC_Const
+: (std::is_volatile::value ? VC_Volatile : VC_None));
+}
+static_assert(getCVQuals() == VC_None, "");
+static_assert(getCVQuals() == VC_Const, "");
+static_assert(getCVQuals() == VC_Volatile, "");
+static_assert(getCVQuals() == VC_ConstVolatile, "");
+static_assert(getCVQuals() == VC_None, "");
+static_assert(getCVQuals() == VC_Const, "");
+
+template 
+inline constexpr ValueCategory getValueCategory() {
+  return getReferenceQuals() | getCVQuals();
+}
+static_assert(getValueCategory() == VC_None, "");
+static_assert(getValueCategory() == (VC_LVal | VC_Const), "");
+static_assert(getValueCategory() ==
+  (VC_RVal | VC_ConstVolatile),
+  "");
+
+template 
+struct ApplyValueCategory {
+private:
+  static_assert(isValidValueCategory(VC), "");
+
+  template 
+  using CondT = typename std::conditional::type;
+
+public:
+  template >
+  using ApplyCVQuals = CondT<
+  hasValueCategory(VC, VC_ConstVolatile), typename std::add_cv::type,
+  CondT::type,
+CondT::type, Tp>>>;
+
+  template ::type>
+  using ApplyReferenceQuals =
+  CondT::type,
+CondT::type, Vp>>;
+
+  template 
+  using Apply = ApplyReferenceQuals>>;
+
+  template ::type = true>
+  static Apply> cast(Tp &&t) {
+using ToType = Apply>;
+return static_cast(t);
+  }
+
+  template ::type = true>

[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.

2021-02-22 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95244

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


[clang] 76151ac - [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-22 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-02-22T11:00:33-05:00
New Revision: 76151acf893ac7bdaf460fdfe8a8494cf477157a

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

LOG: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

In current implementation of `deviceRTLs`, we're using some functions
that are CUDA version dependent (if CUDA_VERSION < 9, it is one; otheriwse, it
is another one). As a result, we have to compile one bitcode library for each
CUDA version supported. A worse problem is forward compatibility. If a new CUDA
version is released, we have to update CMake file as well.

CUDA 9.2 has been released for three years. Instead of using various weird 
tricks
to make `deviceRTLs` work with different CUDA versions and still have forward
compatibility, we can simply drop support for CUDA 9.1 or lower version. It has 
at
least two benifits:
- We don't need to generate bitcode libraries for each CUDA version;
- Clang driver doesn't need to search for the bitcode lib based on CUDA version.

We can claim that starting from LLVM 12, OpenMP offloading on NVPTX target 
requires
CUDA 9.2+.

Reviewed By: jdoerfert, JonChesterfield

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

Added: 
clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_35.bc

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Cuda.cpp
clang/test/Driver/openmp-offload-gpu.c

Removed: 
clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc



diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 6a37a15c6564..2440240608fd 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -263,6 +263,7 @@ def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
 def err_drv_omp_offload_target_missingbcruntime : Error<
   "No library '%0' found in the default clang lib directory or in 
LIBRARY_PATH. Please use --libomptarget-%1-bc-path to specify %1 bitcode 
library.">;
 def err_drv_omp_offload_target_bcruntime_not_found : Error<"Bitcode library 
'%0' does not exist.">;
+def err_drv_omp_offload_target_cuda_version_not_support : Error<"NVPTX target 
requires CUDA 9.2 or above. CUDA %0 is detected.">;
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">,
   InGroup;

diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index dc2a85cdd696..ce7a46921be5 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -710,13 +710,14 @@ void CudaToolChain::addClangTargetOptions(
   CC1Args.push_back("-mlink-builtin-bitcode");
   CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
 
+  clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
   std::string CudaVersionStr;
 
   // New CUDA versions often introduce new instructions that are only supported
   // by new PTX version, so we need to raise PTX level to enable them in NVPTX
   // back-end.
   const char *PtxFeature = nullptr;
-  switch (CudaInstallation.version()) {
+  switch (CudaInstallationVersion) {
 #define CASE_CUDA_VERSION(CUDA_VER, PTX_VER)   
\
   case CudaVersion::CUDA_##CUDA_VER:   
\
 CudaVersionStr = #CUDA_VER;
\
@@ -743,12 +744,19 @@ void CudaToolChain::addClangTargetOptions(
  options::OPT_fno_cuda_short_ptr, false))
 CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
 
-  if (CudaInstallation.version() >= CudaVersion::UNKNOWN)
-CC1Args.push_back(DriverArgs.MakeArgString(
-Twine("-target-sdk-version=") +
-CudaVersionToString(CudaInstallation.version(;
+  if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
+CC1Args.push_back(
+DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
+ 
CudaVersionToString(CudaInstallationVersion)));
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+if (CudaInstallationVersion < CudaVersion::CUDA_92) {
+  getDriver().Diag(
+  diag::err_drv_omp_offload_target_cuda_version_not_support)
+  << CudaVersionToString(CudaInstallationVersion);
+  return;
+}
+
 std::string BitcodeSuffix =
 "nvptx-cuda_" + CudaVersionStr + "-" + GpuArch.str();
 addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, BitcodeSuffix,

diff  --git 
a/clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc 
b/clang/test/Driver/Inputs/libomptarget/

[PATCH] D97003: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP offloading on NVPTX target

2021-02-22 Thread Shilei Tian via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76151acf893a: [Clang][OpenMP] Require CUDA 9.2+ for OpenMP 
offloading on NVPTX target (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97003

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_35.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_80-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -154,17 +154,17 @@
 /// Check that the runtime bitcode library is part of the compile line. Create a bogus
 /// bitcode library and add it to the LIBRARY_PATH.
 // RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 /// The user can override default detection using --libomptarget-nvptx-bc-path=.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-USER %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_80-sm_35.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-cuda_102-sm_35.bc
 // CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
@@ -173,23 +173,33 @@
 /// Check that the warning is thrown when the libomptarget bitcode library is not found.
 /// Libomptarget requires sm_35 or newer so an sm_35 bitcode library should never exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_80-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-cuda_102-sm_35.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
 
 /// ###
 
 /// Check that the error is thrown when the libomptarget bitcode library does not exist.
 // RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
-// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
 // RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
 
 // CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
+/// ###
+
+/// Check that the error is thrown when CUDA 9.1 or lower version is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-CUDA-VERSION-ERROR %s
+
+// CHK-CUDA-VERSION-ERROR: NVPTX target requires CUDA 9.2 or above. CUDA 9.0 is detected.
+
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
 // RUN:   | FileCheck -check-prefix=DEBUG_DIRECTIVES %s
Index: clang/lib/Driver/ToolCh

[PATCH] D97058: [OpenCL] Refactor diagnostic for OpenCL extension/feature

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

FYI, I would even be ok if we remove the need for enabling non-core features 
too but it is also fine to start from just core features. Thanks!




Comment at: clang/lib/Sema/Sema.cpp:360
 
 setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
 

I think the same should apply to `double` not only `atomic_double`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97058

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


[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added inline comments.



Comment at: clang/test/FixIt/fixit-static-assert.cpp:2-3
+// RUN: %clang_cc1 -std=c++14 %s -fdiagnostics-parseable-fixits %s 2>&1 | 
FileCheck %s
+// Ensure no warnings are emitted in c++17.
+// RUN: %clang_cc1 -std=c++17 %s -Werror -fsyntax-only
+// RUN: %clang_cc1 -std=c++14 %s -fixit-recompile -fixit-to-temporary -Werror

aaron.ballman wrote:
> Any reason not to pass `-verify=cxx17` and `// cxx17-no-diagnostics`?
I don't know my way around clang testing framework that well.
For the recompile test I think Werror has to be used as verify resulted in an 
assertion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

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


[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 325452.
njames93 marked an inline comment as done.
njames93 added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/FixIt/fixit-static-assert.cpp


Index: clang/test/FixIt/fixit-static-assert.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-static-assert.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -std=c++14 %s -fdiagnostics-parseable-fixits %s 2>&1 | 
FileCheck %s
+// Ensure no warnings are emitted in c++17.
+// RUN: %clang_cc1 -std=c++17 %s -verify=cxx17
+// RUN: %clang_cc1 -std=c++14 %s -fixit-recompile -fixit-to-temporary -Werror
+
+// cxx17-no-diagnostics
+
+static_assert(true && "String");
+// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
+
+// String literal prefixes are good.
+static_assert(true && R"(RawString)");
+// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
+static_assert(true && L"RawString");
+// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
+
+
+static_assert(true);
+// CHECK-DAG: {[[@LINE-1]]:19-[[@LINE-1]]:19}:", \"\""
+
+// While its technically possible to transform this to
+// static_assert(true, "String") we don't attempt this fix.
+static_assert("String" && true);
+// CHECK-DAG: {[[@LINE-1]]:31-[[@LINE-1]]:31}:", \"\""
+
+// Don't be smart and look in parentheses.
+static_assert((true && "String"));
+// CHECK-DAG: {[[@LINE-1]]:33-[[@LINE-1]]:33}:", \"\""
+
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -856,6 +856,16 @@
DeclFromDeclSpec);
 }
 
+static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr,
+   SourceLocation EndExprLoc) {
+  if (const auto *BO = dyn_cast_or_null(AssertExpr)) {
+if (BO->getOpcode() == BO_LAnd &&
+isa(BO->getRHS()->IgnoreImpCasts()))
+  return FixItHint::CreateReplacement(BO->getOperatorLoc(), ",");
+  }
+  return FixItHint::CreateInsertion(EndExprLoc, ", \"\"");
+}
+
 /// ParseStaticAssertDeclaration - Parse C++0x or C11 
static_assert-declaration.
 ///
 /// [C++0x] static_assert-declaration:
@@ -892,12 +902,11 @@
 
   ExprResult AssertMessage;
   if (Tok.is(tok::r_paren)) {
-Diag(Tok, getLangOpts().CPlusPlus17
-  ? diag::warn_cxx14_compat_static_assert_no_message
-  : diag::ext_static_assert_no_message)
-  << (getLangOpts().CPlusPlus17
-  ? FixItHint()
-  : FixItHint::CreateInsertion(Tok.getLocation(), ", \"\""));
+if (getLangOpts().CPlusPlus17)
+  Diag(Tok, diag::warn_cxx14_compat_static_assert_no_message);
+else
+  Diag(Tok, diag::ext_static_assert_no_message)
+  << getStaticAssertNoMessageFixIt(AssertExpr.get(), 
Tok.getLocation());
   } else {
 if (ExpectAndConsume(tok::comma)) {
   SkipUntil(tok::semi);


Index: clang/test/FixIt/fixit-static-assert.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-static-assert.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -std=c++14 %s -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// Ensure no warnings are emitted in c++17.
+// RUN: %clang_cc1 -std=c++17 %s -verify=cxx17
+// RUN: %clang_cc1 -std=c++14 %s -fixit-recompile -fixit-to-temporary -Werror
+
+// cxx17-no-diagnostics
+
+static_assert(true && "String");
+// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
+
+// String literal prefixes are good.
+static_assert(true && R"(RawString)");
+// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
+static_assert(true && L"RawString");
+// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
+
+
+static_assert(true);
+// CHECK-DAG: {[[@LINE-1]]:19-[[@LINE-1]]:19}:", \"\""
+
+// While its technically possible to transform this to
+// static_assert(true, "String") we don't attempt this fix.
+static_assert("String" && true);
+// CHECK-DAG: {[[@LINE-1]]:31-[[@LINE-1]]:31}:", \"\""
+
+// Don't be smart and look in parentheses.
+static_assert((true && "String"));
+// CHECK-DAG: {[[@LINE-1]]:33-[[@LINE-1]]:33}:", \"\""
+
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -856,6 +856,16 @@
DeclFromDeclSpec);
 }
 
+static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr,
+   SourceLocation EndExprLoc) {
+  if (const auto *BO = dyn_cast_or_null(AssertExpr)) {
+if (BO->getOpcode() == BO_LAnd &&
+isa(BO->getRHS()->IgnoreImpCasts()))
+  return FixItHint::CreateReplacement(BO->getOperatorLoc(), ",");
+  }
+  return FixItHi

[PATCH] D97052: [OpenCL] Prevent adding extension pragma by default

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/OpenCLExtensions.def:71
+OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
+OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
 

azabaznov wrote:
> Anastasia wrote:
> > azabaznov wrote:
> > > I think core and optional core features do not require pragma too. So for 
> > > example 3d image writes or fp64 do not require pragma in OpenCL C 2.0. 
> > > Isn't that so?
> > Well to be honest nothing seems to need pragma but we have to accept it for 
> > the backward compatibility. :)
> > 
> > In case of the core features if pragma would have been useful we would have 
> > to still accept it for the backward compatibility even if the feature 
> > became core.
> I'm just wondering if this new field needed in the file to maintain backward 
> compatibility. Maybe we can highlight OpenCL C 3.0 features with some other 
> way? Is it seems that check for name starting with "__opencl_c" is a bad idea?
Not sure I understand you here but I don't think that we should add extension 
pragmas any longer at all even for the new extensions. FYI I am planning to add 
guidelines for that in https://reviews.llvm.org/D97072. Maybe it helps to 
clarify the idea?



Comment at: clang/lib/Parse/ParsePragma.cpp:785
+  // Therefore, it should never be added by default.
+  Opt.acceptsPragma(Name);
 }

azabaznov wrote:
> Anastasia wrote:
> > svenvh wrote:
> > > I fail to understand why this is needed, so perhaps this needs a bit more 
> > > explanation.  Extensions that should continue to support pragmas already 
> > > have their `WithPragma` field set to `true` via `OpenCLExtensions.def`.  
> > > Why do we need to dynamically modify the field?
> > It is a bit twisty here to be honest. Because we have also introduced the 
> > pragma `begin` and `end` that would add pragma `enable`/`disable` by 
> > default. So any extension added dynamically using `begin`/`end` would have 
> > to accept the pragma `enable`/`disable`. 
> > 
> > https://clang.llvm.org/docs/UsersManual.html#opencl-extensions
> > 
> > But in the subsequent patches, I hope to remove this because I just don't 
> > see where it is useful but it is very confusing.
> Is it ok not to track this situation here:
> 
> ```
> #pragma OPENCL EXTENSION __opencl_c_feature : begin
> #pragma OPENCL EXTENSION __opencl_c_feature: end
> ```
> 
> This is some of a corner case, but still...
I see. I am not sure what should happen here - I guess we should give an error? 
Although for earlier versions than OpenCL 3.0 this should probably be accepted?

Perhaps we can create a PR for this for now...


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

https://reviews.llvm.org/D97052

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


[PATCH] D89065: [clang] Tweaked fixit for static assert with no message

2021-02-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/FixIt/fixit-static-assert.cpp:2-3
+// RUN: %clang_cc1 -std=c++14 %s -fdiagnostics-parseable-fixits %s 2>&1 | 
FileCheck %s
+// Ensure no warnings are emitted in c++17.
+// RUN: %clang_cc1 -std=c++17 %s -Werror -fsyntax-only
+// RUN: %clang_cc1 -std=c++14 %s -fixit-recompile -fixit-to-temporary -Werror

njames93 wrote:
> aaron.ballman wrote:
> > Any reason not to pass `-verify=cxx17` and `// cxx17-no-diagnostics`?
> I don't know my way around clang testing framework that well.
> For the recompile test I think Werror has to be used as verify resulted in an 
> assertion.
Ah, okay, thanks for the explanation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89065

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


[PATCH] D96860: [OpenCL] Add declarations with enum/typedef args

2021-02-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:932
+let MinVersion = CL20 in {
+  def : Builtin<"get_fence", [MemFenceFlags, PointerType]>;
+  def : Builtin<"get_fence", [MemFenceFlags, PointerType, 
GenericAS>]>;

svenvh wrote:
> Anastasia wrote:
> > Btw, I am guessing you are matching the behavior of `opencl-c.h`, but 
> > however it doesn't seem entirely conformant.
> > 
> > `cl_mem_fence_flags get_fence(gentype *ptr)`
> > 
> > So I guess we should have implemented these as other functions from `Table 
> > 22. Built-in Address Space Qualifier Functions` in clang? But since the 
> > void pointer is only used as a parameter and not return value I doubt this 
> > is customer visible. Should we add a comment or something?
> > 
> > 
> > 
> Yes, I'm matching  `opencl-c.h` here, as the "gentype argument to indicate 
> any of the built-in data types supported by OpenCL C or a user defined type.  
> Since this cannot be captured" can't be expressed literally.  I can add the 
> following comment if that makes sense?
> ```// The OpenCL 3.0 specification defines these with a "gentype" argument 
> indicating any builtin
> // type or user-defined type, which cannot be represented currently.  Hence 
> we slightly diverge
> // from this by providing only the following two overloads with a void 
> pointer.
> ```
Yes, I think a comment is good enough. We could even create a spec bug because 
it is literally not possible to implement without a **magic** and just using 
`void*` is so easy and straight forward.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:1103
   }
   foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
   [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],

I think this should be renamed now, but we can do as a separate change.

I would suggest using something like `OverloadTypes` instead...



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:185
+#if !defined(NO_HEADER) && (defined(__OPENCL_CPP_VERSION__) || 
__OPENCL_C_VERSION__ >= 200)
+  sub_group_barrier(CLK_GLOBAL_MEM_FENCE, memory_scope_device);
+#endif

svenvh wrote:
> Anastasia wrote:
> > Should `work_group_barrier` and fences also be added to the testing?
> MemFenceFlags are already tested using `barrier()` on line 23, so not 
> strictly needed.  I added this test to verify the combination of 
> MemFenceFlags and extensions.  Do you think we're missing any tablegen 
> functionality coverage that would require adding more builtins to the test 
> (also taking into account the comment on lines 10-13)?
Taking into account the definition it's not easy to tell. I was trying to apply 
the strategy of any new group of declarations is to be tested but it might not 
be the original intention. I still think we do need to come up with some sort 
of unambiguous strategy but perhaps it is not in the scope of this patch. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96860

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


[PATCH] D90851: [clang-tidy] Extending bugprone-signal-handler with POSIX functions.

2021-02-22 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 325453.
balazske added a comment.

Rebase, improved documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90851

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-signal-handler.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/unistd.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -1,8 +1,9 @@
-// RUN: %check_clang_tidy %s cert-sig30-c %t -- -- -isystem %S/Inputs/Headers
+// RUN: %check_clang_tidy %s bugprone-signal-handler %t -- -- -isystem %S/Inputs/Headers
 
 #include "signal.h"
-#include "stdio.h"
 #include "stdlib.h"
+#include "stdio.h"
+#include "system-other.h"
 
 // The function should be classified as system call even if there is
 // declaration the in source file.
@@ -16,17 +17,9 @@
   abort();
 }
 
-void handler__Exit(int) {
-  _Exit(0);
-}
-
-void handler_quick_exit(int) {
-  quick_exit(0);
-}
-
 void handler_other(int) {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void handler_signal(int) {
@@ -40,7 +33,7 @@
 
 void f_bad() {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void f_extern();
@@ -55,13 +48,11 @@
 
 void handler_extern(int) {
   f_extern();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void test() {
   signal(SIGINT, handler_abort);
-  signal(SIGINT, handler__Exit);
-  signal(SIGINT, handler_quick_exit);
   signal(SIGINT, handler_signal);
   signal(SIGINT, handler_other);
 
@@ -69,9 +60,9 @@
   signal(SIGINT, handler_bad);
   signal(SIGINT, handler_extern);
 
-  signal(SIGINT, quick_exit);
+  signal(SIGINT, _Exit);
   signal(SIGINT, other_call);
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 
   signal(SIGINT, SIG_IGN);
   signal(SIGINT, SIG_DFL);
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy %s bugprone-signal-handler %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: bugprone-signal-handler.AsyncSafeFunctionSet, value: "POSIX"}]}' \
+// RUN: -- -isystem %S/Inputs/Headers
+
+#include "signal.h"
+#include "stdlib.h"
+#include "stdio.h"
+#include "string.h"
+#include "unistd.h"
+
+void handler_bad(int) {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void handler_good(int) {
+  abort();
+  _Exit(0);
+  _exit(0);
+  quick_exit(0);
+  signal(0, SIG_DFL);
+  memcpy((void*)10, (const void*)20, 1);
+}
+
+void test() {
+  signal(SIGINT, handler_good);
+  signal(SIGINT, handler_bad);
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
==

[PATCH] D97132: [clang-tidy] Harden PreferMemberInitializerCheck

2021-02-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> Fix potential crash if macros are used, Now we just don't try to emit a fix.

Can you add a test case that covers this change?




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:105
+  return std::make_pair(nullptr, nullptr);
+const auto *Init = BO->getRHS()->IgnoreParenImpCasts();
+if (isSafeAssignment(Field, Init, Ctor))





Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:123
+  return std::make_pair(nullptr, nullptr);
+const auto *Init = COCE->getArg(1)->IgnoreParenImpCasts();
+if (isSafeAssignment(Field, Init, Ctor))




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97132

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


[PATCH] D97137: Bug fix of clang-format, the AlignConsecutiveDeclarations option doesn't handle pointer properly

2021-02-22 Thread Darwin Xu via Phabricator via cfe-commits
darwin updated this revision to Diff 325455.
darwin added a comment.

Add more test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97137

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
@@ -13945,6 +13945,20 @@
   verifyFormat("int  oneTwoThree{0}; // comment\n"
"unsigned oneTwo; // comment",
Alignment);
+  verifyFormat("unsigned int *  a;\n"
+   "int *   b;\n"
+   "unsigned int Const *c;\n"
+   "unsigned int const *d;\n"
+   "unsigned int Const &e;\n"
+   "unsigned int const &f;",
+   Alignment);
+  verifyFormat("Const unsigned int *c;\n"
+   "const unsigned int *d;\n"
+   "Const unsigned int &e;\n"
+   "const unsigned int &f;\n"
+   "const unsigned  g;\n"
+   "Const unsigned  h;",
+Alignment);
   EXPECT_EQ("float const a = 5;\n"
 "\n"
 "int oneTwoThree = 123;",
@@ -14249,6 +14263,38 @@
   EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
 "foo(int a);",
 format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
+
+  Alignment.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("unsigned int*   a;\n"
+   "int*b;\n"
+   "unsigned int Const* c;\n"
+   "unsigned int const* d;\n"
+   "unsigned int Const& e;\n"
+   "unsigned int const& f;",
+   Alignment);
+  verifyFormat("Const unsigned int* c;\n"
+   "const unsigned int* d;\n"
+   "Const unsigned int& e;\n"
+   "const unsigned int& f;\n"
+   "const unsigned  g;\n"
+   "Const unsigned  h;",
+Alignment);
+
+  Alignment.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat("unsigned int *   a;\n"
+   "int *b;\n"
+   "unsigned int Const * c;\n"
+   "unsigned int const * d;\n"
+   "unsigned int Const & e;\n"
+   "unsigned int const & f;",
+   Alignment);
+  verifyFormat("Const unsigned int * c;\n"
+   "const unsigned int * d;\n"
+   "Const unsigned int & e;\n"
+   "const unsigned int & f;\n"
+   "const unsigned   g;\n"
+   "Const unsigned   h;",
+Alignment);
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -709,6 +709,8 @@
 for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
   if (Next->is(tok::comment))
 continue;
+  if (Next->is(TT_PointerOrReference))
+return false;
   if (!Next->Tok.getIdentifierInfo())
 break;
   if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13945,6 +13945,20 @@
   verifyFormat("int  oneTwoThree{0}; // comment\n"
"unsigned oneTwo; // comment",
Alignment);
+  verifyFormat("unsigned int *  a;\n"
+   "int *   b;\n"
+   "unsigned int Const *c;\n"
+   "unsigned int const *d;\n"
+   "unsigned int Const &e;\n"
+   "unsigned int const &f;",
+   Alignment);
+  verifyFormat("Const unsigned int *c;\n"
+   "const unsigned int *d;\n"
+   "Const unsigned int &e;\n"
+   "const unsigned int &f;\n"
+   "const unsigned  g;\n"
+   "Const unsigned  h;",
+Alignment);
   EXPECT_EQ("float const a = 5;\n"
 "\n"
 "int oneTwoThree = 123;",
@@ -14249,6 +14263,38 @@
   EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
 "foo(int a);",
 format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
+
+  Alignment.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("unsigned int*   a;\n"
+   "int*b;\n"
+   "unsigned int Const* c;\n"
+   "unsigned int const* d;\n"
+   "unsigned int Const& e;\n"
+   "unsigned int const& f;",
+   Alignment);
+  verifyFormat("Const

[PATCH] D97198: [OpenMP][Clang][NVPTX] Only build one bitcode library for each SM

2021-02-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, JonChesterfield, ABataev, grokos, 
ye-luo.
Herald added subscribers: guansong, yaxunl, mgorny.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

In D97003 , CUDA 9.2 is the minimum 
requirement for OpenMP offloading on
NVPTX target. We don't need to have macros in source code to select right 
functions
based on CUDA version. we don't need to compile multiple bitcode libraries of
different CUDA versions for each SM. We don't need to worry about future
compatibility with newer CUDA version.

`-target-feature +ptx60` is used in this patch, which corresponds to the highest
PTX version that CUDA 9.2 can support.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97198

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-cuda_102-sm_35.bc
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-sm_35.bc
  clang/test/Driver/openmp-offload-gpu.c
  openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu

Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
@@ -53,46 +53,28 @@
   return (double)nsecs * __kmpc_impl_get_wtick();
 }
 
-// In Cuda 9.0, __ballot(1) from Cuda 8.0 is replaced with __activemask().
 DEVICE __kmpc_impl_lanemask_t __kmpc_impl_activemask() {
-#if CUDA_VERSION < 9020
-  return __nvvm_vote_ballot(1);
-#else
   unsigned int Mask;
   asm volatile("activemask.b32 %0;" : "=r"(Mask));
   return Mask;
-#endif
 }
 
-// In Cuda 9.0, the *_sync() version takes an extra argument 'mask'.
 DEVICE int32_t __kmpc_impl_shfl_sync(__kmpc_impl_lanemask_t Mask, int32_t Var,
  int32_t SrcLane) {
-#if CUDA_VERSION >= 9000
   return __nvvm_shfl_sync_idx_i32(Mask, Var, SrcLane, 0x1f);
-#else
-  return __nvvm_shfl_idx_i32(Var, SrcLane, 0x1f);
-#endif // CUDA_VERSION
 }
 
 DEVICE int32_t __kmpc_impl_shfl_down_sync(__kmpc_impl_lanemask_t Mask,
   int32_t Var, uint32_t Delta,
   int32_t Width) {
   int32_t T = ((WARPSIZE - Width) << 8) | 0x1f;
-#if CUDA_VERSION >= 9000
   return __nvvm_shfl_sync_down_i32(Mask, Var, Delta, T);
-#else
-  return __nvvm_shfl_down_i32(Var, Delta, T);
-#endif // CUDA_VERSION
 }
 
 DEVICE void __kmpc_impl_syncthreads() { __syncthreads(); }
 
 DEVICE void __kmpc_impl_syncwarp(__kmpc_impl_lanemask_t Mask) {
-#if CUDA_VERSION >= 9000
   __nvvm_bar_warp_sync(Mask);
-#else
-  // In Cuda < 9.0 no need to sync threads in warps.
-#endif // CUDA_VERSION
 }
 
 // NVPTX specific kernel initialization
Index: openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
===
--- openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
+++ openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
@@ -137,6 +137,7 @@
  -Xclang -emit-llvm-bc
  -Xclang -aux-triple -Xclang ${aux_triple}
  -fopenmp -fopenmp-cuda-mode -Xclang -fopenmp-is-device
+ -Xclang -target-feature -Xclang +ptx60
  -D__CUDACC__
  -I${devicertl_base_directory}
  -I${devicertl_nvptx_directory}/src)
@@ -150,81 +151,51 @@
 # Create target to build all Bitcode libraries.
 add_custom_target(omptarget-nvptx-bc)
 
-# This map is from clang/lib/Driver/ToolChains/Cuda.cpp.
-# The last element is the default case.
-set(cuda_version_list 112 111 110 102 101 100 92 91 90 80)
-set(ptx_feature_list 71 71 70 65 64 63 61 61 60 42)
-# The following two lines of ugly code is not needed when the minimal CMake
-# version requirement is 3.17+.
-list(LENGTH cuda_version_list num_version_supported)
-math(EXPR loop_range "${num_version_supported} - 1")
-
-# Generate a Bitcode library for all the compute capabilities the user
-# requested and all PTX version we know for now.
+# Generate a Bitcode library for all the compute capabilities the user requested
 foreach(sm ${nvptx_sm_list})
-  set(sm_flags -Xclang -target-cpu -Xclang sm_${sm} "-D__CUDA_ARCH__=${sm}0")
-
-  # Uncomment the following code and remove those ugly part if the feature
-  # is available.
-  # foreach(cuda_version ptx_num IN ZIP_LISTS cuda_version_list ptx_feature_list)
-  foreach(itr RANGE ${loop_range})
-list(GET cuda_version_list ${itr} cuda_version)
-list(GET ptx_feature_list ${itr} ptx_num)
-set(cuda_flags ${sm_flags})
-list(APPEND cuda_flags -Xclang -target-feature -Xclang +ptx${ptx_num})
-if("${cuda_version}" MATCHES "^([0-9]+)([0-9])$")
-  set(cuda_version_major ${CMAKE_MATCH_1})
-  set(cuda_versio

[PATCH] D97132: [clang-tidy] Harden PreferMemberInitializerCheck

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D97132#2578992 , @aaron.ballman 
wrote:

>> Fix potential crash if macros are used, Now we just don't try to emit a fix.
>
> Can you add a test case that covers this change?

I can try, but I'm not sure of the exact cause of it. It happened when running 
the check over clang codebase.
The assert was caused by not checking the Optional returned from 
`findNextToken` which can fail if the location passed is at the end of a macro 
expansion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97132

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-02-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@steakhal

> I would like @NoQ or someone else to also review this.

Oh, I would be very pleased if our colleagues pay attention to my recent 
patches. But seems you are the only who helps me with this stuff 🙂


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

https://reviews.llvm.org/D96090

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


[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text

2021-02-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

mostly LG, can you also add some tests?




Comment at: clang-tools-extra/clangd/Diagnostics.cpp:695
+  if (Insert.empty() && FixIt.InsertFromRange.isValid()) {
+bool InvalidInsert = false;
+Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts,

nit: I would rather make `!Invalid` a condition and just make use of it in here 
as well.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:555
+auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, &Invalid);
+if (!Invalid)
+  Result.newText = Insert.str();

it feels like correct semantics would be to make this function fail now. as the 
resulting value will likely be used for editing the source code and we don't 
want to propagate some garbage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97123

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


[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text

2021-02-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:552
   Result.newText = FixIt.CodeToInsert;
+  if (Result.newText.empty() && FixIt.InsertFromRange.isValid()) {
+bool Invalid = false;

oh btw, i think the condition should only check for validness of the 
`InsertFromRange`, and then we should assert for the emptyness of 
`CodeToInsert`. (same for the piece in Diagnostics.cpp)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97123

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


[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text

2021-02-22 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:695
+  if (Insert.empty() && FixIt.InsertFromRange.isValid()) {
+bool InvalidInsert = false;
+Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts,

kadircet wrote:
> nit: I would rather make `!Invalid` a condition and just make use of it in 
> here as well.
Good point, that's much nicer.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:555
+auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, &Invalid);
+if (!Invalid)
+  Result.newText = Insert.str();

kadircet wrote:
> it feels like correct semantics would be to make this function fail now. as 
> the resulting value will likely be used for editing the source code and we 
> don't want to propagate some garbage.
While I agree with this in principal. We currently don't handle the case where 
RemoveRange doesn't correspond to a FileCharRange which would likely need 
propagating. Though likely in a separate patch. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97123

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


[PATCH] D97053: [clang][SVE] Don't warn on vector to sizeless builtin implicit conversion

2021-02-22 Thread Joe Ellis via Phabricator via cfe-commits
joechrisellis updated this revision to Diff 325461.
joechrisellis marked an inline comment as done.
joechrisellis added a comment.

Address @c-rhodes's comment.

- use `isVLSTBuiltinType` instead of `isSizelessBuiltinType`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97053

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp


Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 
-msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 
-msve-vector-bits=512 -fallow-half-arguments-and-returns -Wconversion %s
 // expected-no-diagnostics
 
 #include 
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12051,7 +12051,16 @@
 checkObjCDictionaryLiteral(S, QualType(Target, 0), DictionaryLiteral);
 
   // Strip vector types.
-  if (isa(Source)) {
+  if (auto *SourceVT = dyn_cast(Source)) {
+if (Target->isVLSTBuiltinType()) {
+  auto SourceVectorKind = SourceVT->getVectorKind();
+  if (SourceVectorKind == VectorType::SveFixedLengthDataVector ||
+  SourceVectorKind == VectorType::SveFixedLengthPredicateVector ||
+  (SourceVectorKind == VectorType::GenericVector &&
+   S.Context.getTypeSize(Source) == S.getLangOpts().ArmSveVectorBits))
+return;
+}
+
 if (!isa(Target)) {
   if (S.SourceMgr.isInSystemMacro(CC))
 return;


Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns -Wconversion %s
 // expected-no-diagnostics
 
 #include 
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12051,7 +12051,16 @@
 checkObjCDictionaryLiteral(S, QualType(Target, 0), DictionaryLiteral);
 
   // Strip vector types.
-  if (isa(Source)) {
+  if (auto *SourceVT = dyn_cast(Source)) {
+if (Target->isVLSTBuiltinType()) {
+  auto SourceVectorKind = SourceVT->getVectorKind();
+  if (SourceVectorKind == VectorType::SveFixedLengthDataVector ||
+  SourceVectorKind == VectorType::SveFixedLengthPredicateVector ||
+  (SourceVectorKind == VectorType::GenericVector &&
+   S.Context.getTypeSize(Source) == S.getLangOpts().ArmSveVectorBits))
+return;
+}
+
 if (!isa(Target)) {
   if (S.SourceMgr.isInSystemMacro(CC))
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97053: [clang][SVE] Don't warn on vector to sizeless builtin implicit conversion

2021-02-22 Thread Joe Ellis via Phabricator via cfe-commits
joechrisellis added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:12055
+  if (auto *SourceVT = dyn_cast(Source)) {
+if (Target->isSizelessBuiltinType()) {
+  auto SourceVectorKind = SourceVT->getVectorKind();

c-rhodes wrote:
> I suppose we could tighten this further by replacing `isSizelessBuiltinType` 
> with `isVLSTBuiltinType`
Good shout -- thanks. :smile:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97053

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


[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-02-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:73
+
+New checks
+^^

Please rebase from trunk.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:79
+
+Finds calls to ``new`` that may throw exception that is not handled.
 

Please indent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97196

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


[PATCH] D96803: EntryExitInstrumenter: Enable at all optimization levels (PR49143)

2021-02-22 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

code looks good, just some test nits




Comment at: llvm/test/Transforms/EntryExitInstrumenter/mcount.ll:1
-; RUN: opt 
-passes="function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument)"
 -S < %s | FileCheck %s
+; RUN: opt --O0 --ee-instrument --inline --post-inline-ee-instrument -S < %s | 
FileCheck %s
+

I don't think it makes sense to add tests to `llvm/test`, there should be a 
clang test for this since the pass is added in clang. These tests aren't really 
testing the changed code.
Are there any existing tests for `CodeGenOpts.InstrumentFunctions`? We just 
need to make sure that the calls to the instrument functions exist for `clang 
-O0`.


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

https://reviews.llvm.org/D96803

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


  1   2   3   >