[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-07-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D106577#2905027 , @aaron.ballman 
wrote:

> In D106577#2904960 , @rsmith wrote:
>
>> I'd expect we will break at least things like libc++ tests that build with 
>> `-Wsystem-headers` in the case where libc defines the macro. But if the 
>> problem is limited to old libc and a rare use case, and can easily be worked 
>> around with a `-Wno` flag, that's probably fine.
>
> Doesn't look to be in an old libc: 
> https://sourceware.org/git/?p=glibc.git;a=blob;f=include/stdc-predef.h;h=e130c462a7b71f87956a6d4b2bd69a38c9d9cb32;hb=refs/heads/master#l58

The "old libc" case is for old versions of glibc that put the macro in 
`features.h` instead of in `stdc-predef.h`. The macros in `stdc-predef.h` 
aren't a problem until / unless we start auto-including that header.

In D106577#2905755 , @jyknight wrote:

> In D106577#2904960 , @rsmith wrote:
>
>> One benefit we don't get with this approach is providing the right value for 
>> the macro (without paying the cost of always including `stdc-predefs.h`).
>
> What do you mean by "right value", though? As Aaron pointed out, the value 
> seems only dependent upon what characters can fit into a wchar_t, which is 
> independent of what unicode version the libc supports.

I don't see how that follows from the definition in the C standard; it says 
"every character in the Unicode required set, when stored in an object of type 
`wchar_t`, has the same value as the short identifier of that character". This 
doesn't say anything about character or string literals, and for example 
`mbstowcs` stores characters in objects of type `wchar_t` too (it "stores not 
more than `n` wide characters into the array pointed to by `pwcs`"), so unless 
`mbstowcs` does the right thing I don't see how we can claim support for a new 
Unicode standard version. As far as I can tell, this macro is documenting a 
property of the complete implementation (compiler plus standard library), and 
should be set to the minimum of the version supported by the compiler and the 
version supported by the stdlib. I think it's OK for the compiler to say it 
supports *any* version, though, because we don't expect future Unicode versions 
to require any changes on our part. But they may require standard library 
changes.

If Aaron's checked with WG14 and the intent is for this to only constrain how 
literals are represented, and not the complete implementation, then I'm 
entirely fine with us defining the macro ourselves. But that's not the 
interpretation that several other vendors have taken. If we're confident that 
the intent is just that this macro lists (effectively) the latest version of 
the Unicode standard that we've heard of, we should let the various libc 
vendors that currently define the macro know that they're doing it wrong and 
the definition belongs in the compiler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D105695#2905028 , @dexonsmith 
wrote:

> Seeing the `-fembed-bitcode` case made me think of `-save-temps`. I think 
> this will work since `-x cpp-output` should return false for `isSrcFile()`... 
> but probably worth adding a test. LGTM assuming the test passes.

Thanks for pointing that out. Things work as expected, committing with the 
added test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105695

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


[PATCH] D106849: [NFC][X86] add missing tests in clang/test/CodeGen/attr-target-mv.c

2021-07-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 361919.
FreddyYe added a comment.

lowering pre-merge issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106849

Files:
  clang/test/CodeGen/attr-target-mv.c


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,8 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,8 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 60426f3 - [clang][driver] NFC: Move InputInfo.h from lib to include

2021-07-27 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-07-27T09:17:39+02:00
New Revision: 60426f33b1d417763ca1954fba5293c959c9623d

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

LOG: [clang][driver] NFC: Move InputInfo.h from lib to include

Moving `InputInfo.h` from `lib/Driver/` into `include/Driver` to be able to 
expose it in an API consumed from outside of `clangDriver`.

Reviewed By: dexonsmith

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

Added: 
clang/include/clang/Driver/InputInfo.h

Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Job.cpp
clang/lib/Driver/Tool.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/AVR.h
clang/lib/Driver/ToolChains/Ananas.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CloudABI.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/HIP.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/MSP430.cpp
clang/lib/Driver/ToolChains/MSP430.h
clang/lib/Driver/ToolChains/MinGW.cpp
clang/lib/Driver/ToolChains/Minix.cpp
clang/lib/Driver/ToolChains/NaCl.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp

Removed: 
clang/lib/Driver/InputInfo.h



diff  --git a/clang/lib/Driver/InputInfo.h 
b/clang/include/clang/Driver/InputInfo.h
similarity index 97%
rename from clang/lib/Driver/InputInfo.h
rename to clang/include/clang/Driver/InputInfo.h
index a6b6f7f344bc5..a1ecdb623331b 100644
--- a/clang/lib/Driver/InputInfo.h
+++ b/clang/include/clang/Driver/InputInfo.h
@@ -6,8 +6,8 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
-#define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H
+#ifndef LLVM_CLANG_DRIVER_INPUTINFO_H
+#define LLVM_CLANG_DRIVER_INPUTINFO_H
 
 #include "clang/Driver/Action.h"
 #include "clang/Driver/Types.h"

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9714c3c42e840..a06eb6ccc1b3c 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 
 #include "clang/Driver/Driver.h"
-#include "InputInfo.h"
 #include "ToolChains/AIX.h"
 #include "ToolChains/AMDGPU.h"
 #include "ToolChains/AMDGPUOpenMP.h"
@@ -54,6 +53,7 @@
 #include "clang/Driver/Action.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Job.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"

diff  --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index 68d5db281c7d6..e1b62d771578c 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -7,10 +7,10 @@
 
//===--===//
 
 #include "clang/Driver/Job.h"
-#include "InputInfo.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/ArrayRef.h"

diff  --git a/clang/lib/Driver/Tool.cpp b/clang/lib/Driver/Tool.cpp
index 449f69cfcb357..a198f4f3b6753 100644
--- a/clang/lib/Driver/Tool.cpp
+++ b/clang/lib/Driver/Tool.cpp
@@ -7,7 +7,7 @@
 
//===--===//
 
 #include "clang/Driver/Tool.h"
-#include "InputInfo.h"
+#include "clang/Driver/InputInfo.h"
 
 using namespace clang::driver;
 

diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 63ddd2acbec15..6c1b88141c452 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 
 #include "clang/Driver/ToolChain.h"
-#include "InputInfo.h"
 #include "ToolChains/Arch/ARM.h"
 #include "ToolChains/Clang.h"
 #include "ToolChains/InterfaceStubs.h"
@@ -18,6 +17,7 @@
 #include "clang/Driver/Action.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Job.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 0a1da2879ee18..d63c5e12c4af4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
++

[PATCH] D106787: [clang][driver] NFC: Move InputInfo.h from lib to include

2021-07-27 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 rG60426f33b1d4: [clang][driver] NFC: Move InputInfo.h from lib 
to include (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106787

Files:
  clang/include/clang/Driver/InputInfo.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/InputInfo.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/Tool.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/lib/Driver/ToolChains/Ananas.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CloudABI.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/Minix.cpp
  clang/lib/Driver/ToolChains/NaCl.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp

Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -8,8 +8,8 @@
 
 #include "RISCVToolchain.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
Index: clang/lib/Driver/ToolChains/NaCl.cpp
===
--- clang/lib/Driver/ToolChains/NaCl.cpp
+++ clang/lib/Driver/ToolChains/NaCl.cpp
@@ -7,11 +7,11 @@
 //===--===//
 
 #include "NaCl.h"
-#include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -8,9 +8,9 @@
 
 #include "Minix.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/VirtualFileSystem.h"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -7,12 +7,12 @@
 //===--===//
 
 #include "MinGW.h"
-#include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
Index: clang/lib/Driver/ToolChains/MSP430.h
===
--- clang/lib/Driver/ToolChains/MSP430.h
+++ clang/lib/Driver/ToolChains/MSP430.h
@@ -10,9 +10,9 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSP430_H
 
 #include "Gnu.h"
-#include "InputInfo.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringRef.h"
Index: clang/lib/Driver/ToolChains/MSP430.cpp
===
--- clang/lib/Driver/ToolChains/MSP430.cpp
+++ clang/lib/Driver/ToolChains/MSP430.cpp
@@ -9,8 +9,8 @@
 #include "MSP430.h"
 #include "CommonArgs.h"
 #include "Gnu.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Multilib.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -8,10 +8,10 @@
 
 #include "Hexagon.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Co

[clang] b76c7c6 - [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

2021-07-27 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-07-27T09:18:58+02:00
New Revision: b76c7c6faf06bb02b7b7b6bba3f6eb8a33edcdca

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

LOG: [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

This patch exposes `InputInfo` in `Job` instead of plain filenames. This is 
useful in a follow-up patch that uses this to recognize `-cc1` commands 
interesting for Clang tooling.

Depends on D106787.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/include/clang/Driver/Job.h
clang/lib/Driver/Job.cpp
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Job.h 
b/clang/include/clang/Driver/Job.h
index 138ffc331a2f4..8b287638a271d 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_DRIVER_JOB_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Driver/InputInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
@@ -119,8 +120,8 @@ class Command {
   /// argument, which will be the executable).
   llvm::opt::ArgStringList Arguments;
 
-  /// The list of program arguments which are inputs.
-  llvm::opt::ArgStringList InputFilenames;
+  /// The list of program inputs.
+  std::vector InputInfoList;
 
   /// The list of program arguments which are outputs. May be empty.
   std::vector OutputFilenames;
@@ -207,9 +208,7 @@ class Command {
 
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
 
-  const llvm::opt::ArgStringList &getInputFilenames() const {
-return InputFilenames;
-  }
+  const std::vector &getInputInfos() const { return InputInfoList; }
 
   const std::vector &getOutputFilenames() const {
 return OutputFilenames;

diff  --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index e1b62d771578c..5b87106b6565d 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -43,7 +43,7 @@ Command::Command(const Action &Source, const Tool &Creator,
   Executable(Executable), Arguments(Arguments) {
   for (const auto &II : Inputs)
 if (II.isFilename())
-  InputFilenames.push_back(II.getFilename());
+  InputInfoList.push_back(II);
   for (const auto &II : Outputs)
 if (II.isFilename())
   OutputFilenames.push_back(II.getFilename());
@@ -237,9 +237,10 @@ void Command::Print(raw_ostream &OS, const char 
*Terminator, bool Quote,
 }
   }
 
-  auto Found = llvm::find_if(InputFilenames,
- [&Arg](StringRef IF) { return IF == Arg; });
-  if (Found != InputFilenames.end() &&
+  auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
+return II.getFilename() == Arg;
+  });
+  if (Found != InputInfoList.end() &&
   (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
 // Replace the input file name with the crashinfo's file name.
 OS << ' ';
@@ -302,8 +303,8 @@ void Command::setEnvironment(llvm::ArrayRef 
NewEnvironment) {
 
 void Command::PrintFileNames() const {
   if (PrintInputFilenames) {
-for (const char *Arg : InputFilenames)
-  llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
+for (const auto &Arg : InputInfoList)
+  llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
 llvm::outs().flush();
   }
 }

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 87f476c98dc94..253c65d0e29fe 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@ TEST(ToolChainTest, CommandOutput) {
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);



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


[PATCH] D106788: [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

2021-07-27 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 rGb76c7c6faf06: [clang][driver] NFC: Expose InputInfo in Job 
instead of plain filenames (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106788

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);
Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -43,7 +43,7 @@
   Executable(Executable), Arguments(Arguments) {
   for (const auto &II : Inputs)
 if (II.isFilename())
-  InputFilenames.push_back(II.getFilename());
+  InputInfoList.push_back(II);
   for (const auto &II : Outputs)
 if (II.isFilename())
   OutputFilenames.push_back(II.getFilename());
@@ -237,9 +237,10 @@
 }
   }
 
-  auto Found = llvm::find_if(InputFilenames,
- [&Arg](StringRef IF) { return IF == Arg; });
-  if (Found != InputFilenames.end() &&
+  auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
+return II.getFilename() == Arg;
+  });
+  if (Found != InputInfoList.end() &&
   (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
 // Replace the input file name with the crashinfo's file name.
 OS << ' ';
@@ -302,8 +303,8 @@
 
 void Command::PrintFileNames() const {
   if (PrintInputFilenames) {
-for (const char *Arg : InputFilenames)
-  llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
+for (const auto &Arg : InputInfoList)
+  llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
 llvm::outs().flush();
   }
 }
Index: clang/include/clang/Driver/Job.h
===
--- clang/include/clang/Driver/Job.h
+++ clang/include/clang/Driver/Job.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_DRIVER_JOB_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Driver/InputInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
@@ -119,8 +120,8 @@
   /// argument, which will be the executable).
   llvm::opt::ArgStringList Arguments;
 
-  /// The list of program arguments which are inputs.
-  llvm::opt::ArgStringList InputFilenames;
+  /// The list of program inputs.
+  std::vector InputInfoList;
 
   /// The list of program arguments which are outputs. May be empty.
   std::vector OutputFilenames;
@@ -207,9 +208,7 @@
 
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
 
-  const llvm::opt::ArgStringList &getInputFilenames() const {
-return InputFilenames;
-  }
+  const std::vector &getInputInfos() const { return InputInfoList; }
 
   const std::vector &getOutputFilenames() const {
 return OutputFilenames;


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);
Index: clang/lib/Driver/Job.cpp
===
--- clang

[PATCH] D104601: [Preprocessor] Implement -fminimize-whitespace.

2021-07-27 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

This broke some cases for me, where the output is missing some newlines, 
breaking the output badly. I’ll try to provide a repro…


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D106849: [NFC][X86] add missing tests in clang/test/CodeGen/attr-target-mv.c

2021-07-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 361935.
FreddyYe added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106849

Files:
  clang/test/CodeGen/attr-target-mv.c


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna updated this revision to Diff 361937.
Topotuna added a comment.

Reference to C++ for OpenCL 1.0 specification removed. More elaborate code 
example added.


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

https://reviews.llvm.org/D106785

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Headers/opencl-c-base.h
  clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp


Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space<__generic int>::type, 
int>::value,
+"__generic address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, 
char>::value,
+"__global address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, 
ulong>::value,
+"__private address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, 
short>::value,
+"__local address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__constant int3>::type, 
int3>::value,
+"__constant address space not removed by 
__remove_address_space");
+  static_assert(is_same<__remove_address_space::type, const volatile int>::value,
+"non-address-space qualifiers inappropriately removed by 
__remove_address_space");
+}
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -565,6 +565,26 @@
 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
 
+// C++ for OpenCL - __remove_address_space
+#if defined(__OPENCL_CPP_VERSION__)
+template  struct __remove_address_space { using type = _Tp; };
+template  struct __remove_address_space<__generic _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__global _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__private _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__local _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__constant _Tp> {
+  using type = _Tp;
+};
+#endif
+
 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
 
 #define __kernel_exec(X, typen) __kernel \
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1961,6 +1961,30 @@
 global OnlySL *d,
   );
 
+Address space removal
+-
+
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. The tool only throws away
+address space qualifiers, therefore, other type qualifiers such as
+``const`` or ``volatile`` remain unchanged.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  template
+  void foo(T *par){
+T var1; // error - local function variable with global address space
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // compiled - var3 is __private 
int
+  }
+
+  void bar(){
+__global int* ptr;
+foo(ptr);
+  }
+
 Legacy 1.x atomics with generic address space
 -
 


Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space<__generic int>::type, int>::value,
+"__generic address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, char>::value,
+"__global address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value,
+"__private address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, short>::

[PATCH] D104601: [Preprocessor] Implement -fminimize-whitespace.

2021-07-27 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D104601#2906588 , @mstorsjo wrote:

> This broke some cases for me, where the output is missing some newlines, 
> breaking the output badly. I’ll try to provide a repro…

https://martin.st/temp/repro.tar.xz

clang -target x86_64-windows-gnu -E -P _mkerrcodes.h -Iinclude

The output (at the end) has missing newlines (e.g. around GPG_ERR_ETXTBSY).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[clang] 11ee699 - [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-27 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-07-27T10:47:55+02:00
New Revision: 11ee699b3c812ebe56ce5d3b14ab7ef16c1e8495

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

LOG: [clang][tooling] Accept Clang invocations with multiple jobs

When `-fno-integrated-as` is passed to the Clang driver (or set by default by a 
specific toolchain), it will construct an assembler job in addition to the cc1 
job. Similarly, the `-fembed-bitcode` driver  flag will create additional cc1 
job that reads LLVM IR file.

The Clang tooling library only cares about the job that reads a source file. 
Instead of relying on the fact that the client injected `-fsyntax-only` to the 
driver invocation to get a single `-cc1` invocation that reads the source file, 
this patch filters out such jobs from `Compilation` automatically and ignores 
the rest.

This fixes a test failure in `ClangScanDeps/headerwithname.cpp` and 
`ClangScanDeps/headerwithnamefollowedbyinclude.cpp` on AIX reported here: 
https://reviews.llvm.org/D103461#2841918 and `clang-scan-deps` failures with 
`-fembed-bitcode`.

Depends on D106788.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/ToolingTest.cpp

Removed: 
clang/test/Tooling/clang-check-offload.cpp



diff  --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 8b3b2e5ad0026..73d09662562b2 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -66,6 +66,14 @@ namespace tooling {
 
 class CompilationDatabase;
 
+/// Retrieves the flags of the `-cc1` job in `Compilation` that has only source
+/// files as its inputs.
+/// Returns nullptr if there are no such jobs or multiple of them. Note that
+/// offloading jobs are ignored.
+const llvm::opt::ArgStringList *
+getCC1Arguments(DiagnosticsEngine *Diagnostics,
+driver::Compilation *Compilation);
+
 /// Interface to process a clang::CompilerInvocation.
 ///
 /// If your tool is based on FrontendAction, you should be deriving from

diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 463f466d9b763..5242134097dac 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -83,16 +83,20 @@ newDriver(DiagnosticsEngine *Diagnostics, const char 
*BinaryName,
   return CompilerDriver;
 }
 
-/// Retrieves the clang CC1 specific flags out of the compilation's jobs.
-///
-/// Returns nullptr on error.
-static const llvm::opt::ArgStringList *getCC1Arguments(
-DiagnosticsEngine *Diagnostics, driver::Compilation *Compilation) {
-  // We expect to get back exactly one Command job, if we didn't something
-  // failed. Extract that job from the Compilation.
+/// Decide whether extra compiler frontend commands can be ignored.
+static bool ignoreExtraCC1Commands(const driver::Compilation *Compilation) {
   const driver::JobList &Jobs = Compilation->getJobs();
   const driver::ActionList &Actions = Compilation->getActions();
+
   bool OffloadCompilation = false;
+
+  // Jobs and Actions look very 
diff erent depending on whether the Clang tool
+  // injected -fsyntax-only or not. Try to handle both cases here.
+
+  for (const auto &Job : Jobs)
+if (StringRef(Job.getExecutable()) == "clang-offload-bundler")
+  OffloadCompilation = true;
+
   if (Jobs.size() > 1) {
 for (auto A : Actions){
   // On MacOSX real actions may end up being wrapped in BindArchAction
@@ -117,8 +121,33 @@ static const llvm::opt::ArgStringList *getCC1Arguments(
   }
 }
   }
-  if (Jobs.size() == 0 || !isa(*Jobs.begin()) ||
-  (Jobs.size() > 1 && !OffloadCompilation)) {
+
+  return OffloadCompilation;
+}
+
+namespace clang {
+namespace tooling {
+
+const llvm::opt::ArgStringList *
+getCC1Arguments(DiagnosticsEngine *Diagnostics,
+driver::Compilation *Compilation) {
+  const driver::JobList &Jobs = Compilation->getJobs();
+
+  auto IsCC1Command = [](const driver::Command &Cmd) {
+return StringRef(Cmd.getCreator().getName()) == "clang";
+  };
+
+  auto IsSrcFile = [](const driver::InputInfo &II) {
+return isSrcFile(II.getType());
+  };
+
+  llvm::SmallVector CC1Jobs;
+  for (const driver::Command &Job : Jobs)
+if (IsCC1Command(Job) && llvm::all_of(Job.getInputInfos(), IsSrcFile))
+  CC1Jobs.push_back(&Job);
+
+  if (CC1Jobs.empty() ||
+  (CC1Jobs.size() > 1 && !ignoreExtraCC1Commands(Compilation))) {
 SmallString<256> error_msg;
 llvm::raw_svector_ostream error_stream(error_msg);
 Jobs.Print(error_stream, "; ", true);
@@ -127,19 +156,9 @@ static const llvm::opt::ArgStringList *getCC1Arguments(
 return nullptr;
   }

[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-27 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 rG11ee699b3c81: [clang][tooling] Accept Clang invocations with 
multiple jobs (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D105695?vs=361630&id=361942#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105695

Files:
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/test/Tooling/clang-check-offload.cpp
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -18,6 +20,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -258,6 +261,105 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+namespace {
+/// Overlays the real filesystem with the given VFS and returns the result.
+llvm::IntrusiveRefCntPtr
+overlayRealFS(llvm::IntrusiveRefCntPtr VFS) {
+  auto RFS = llvm::vfs::getRealFileSystem();
+  auto OverlayFS = llvm::makeIntrusiveRefCnt(RFS);
+  OverlayFS->pushOverlay(VFS);
+  return OverlayFS;
+}
+
+struct CommandLineExtractorTest : public ::testing::Test {
+  llvm::IntrusiveRefCntPtr InMemoryFS;
+  llvm::IntrusiveRefCntPtr Diags;
+  driver::Driver Driver;
+
+public:
+  CommandLineExtractorTest()
+  : InMemoryFS(new llvm::vfs::InMemoryFileSystem),
+Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)),
+Driver("clang", llvm::sys::getDefaultTargetTriple(), *Diags,
+   "clang LLVM compiler", overlayRealFS(InMemoryFS)) {}
+
+  void addFile(StringRef Name, StringRef Content) {
+InMemoryFS->addFile(Name, 0, llvm::MemoryBuffer::getMemBuffer(Content));
+  }
+
+  const llvm::opt::ArgStringList *
+  extractCC1Arguments(llvm::ArrayRef Argv) {
+const std::unique_ptr Compilation(
+Driver.BuildCompilation(llvm::makeArrayRef(Argv)));
+
+return getCC1Arguments(Diags.get(), Compilation.get());
+  }
+};
+} // namespace
+
+TEST_F(CommandLineExtractorTest, AcceptOffloading) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target",  "arm64-apple-macosx11.0.0",
+"-x","hip",  "test.c",
+"-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-target",   "arm64-apple-macosx11.0.0",
+"-c", "-x","hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target",   "arm64-apple-macosx11.0.0",
+  "-fsyntax-only", "-x","hip",
+  "test.c","-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptExternalAssembler) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target", "arm64-apple-macosx11.0.0", "-fno-integrated-as",
+  "-c","test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptEmbedBitcode) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","-fembed-bitcode", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptSaveTemps) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","-save-temps", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-arch", "x86_64",  "-arch",
+"arm64", "-c",  "test.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectM

[clang] 5bcbb5e - [clang][tooling] Link clangDriver to ToolingTests

2021-07-27 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-07-27T11:09:45+02:00
New Revision: 5bcbb5ec5f07e4ab0ec8f8941bb4a98cab44d169

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

LOG: [clang][tooling] Link clangDriver to ToolingTests

This fixes a build failure introduced in 
11ee699b3c812ebe56ce5d3b14ab7ef16c1e8495.

Added: 


Modified: 
clang/unittests/Tooling/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Tooling/CMakeLists.txt 
b/clang/unittests/Tooling/CMakeLists.txt
index 01eb8d67dada..001d02636fa1 100644
--- a/clang/unittests/Tooling/CMakeLists.txt
+++ b/clang/unittests/Tooling/CMakeLists.txt
@@ -69,6 +69,7 @@ clang_target_link_libraries(ToolingTests
   clangASTMatchers
   clangBasic
   clangDependencyScanning
+  clangDriver
   clangFormat
   clangFrontend
   clangLex



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


[PATCH] D106854: Pass `--start-group` and `--end-group` to the linker when using the AVR toolchain

2021-07-27 Thread Matt Jacobson via Phabricator via cfe-commits
mhjacobson created this revision.
mhjacobson added a reviewer: dylanmckay.
mhjacobson added a project: clang.
Herald added a subscriber: Jim.
mhjacobson requested review of this revision.
Herald added a subscriber: cfe-commits.

The way the GNU linker deals with static archives is that it only loads objects
from the archive that are needed by *previously seen objects*.  That is, in this
case, if libm or libc depend on symbols from libgcc, they might be out of luck.

As it happens, it's common for avr-libc to depend on symbols (specifically, the
deduplicated function prologue/epilogue) from libgcc.  The linker, as invoked by
clang currently, fails to link the program in this case because of the argument
ordering.

In general, libraries should be supplied to the linker in a dependents-then-
dependencies order.

However, to more perfectly match GCC's behavior here--and since we don't control
the libraries in question--simply use `--start-group` and `--end-group`.  These
flags tell the linker to repeatedly search all the intervening libraries until
no new undefined symbol references are created.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106854

Files:
  clang/lib/Driver/ToolChains/AVR.cpp


Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -414,6 +414,8 @@
   if (LinkStdlib) {
 assert(!CPU.empty() && "CPU name must be known in order to link stdlibs");
 
+CmdArgs.push_back("--start-group");
+
 // Add the object file for the CRT.
 std::string CrtFileName = std::string("-l:crt") + CPU + std::string(".o");
 CmdArgs.push_back(Args.MakeArgString(CrtFileName));
@@ -425,6 +427,8 @@
 // Add the link library specific to the MCU.
 CmdArgs.push_back(Args.MakeArgString(std::string("-l") + CPU));
 
+CmdArgs.push_back("--end-group");
+
 // Specify the family name as the emulation mode to use.
 // This is almost always required because otherwise avr-ld
 // will assume 'avr2' and warn about the program being larger


Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -414,6 +414,8 @@
   if (LinkStdlib) {
 assert(!CPU.empty() && "CPU name must be known in order to link stdlibs");
 
+CmdArgs.push_back("--start-group");
+
 // Add the object file for the CRT.
 std::string CrtFileName = std::string("-l:crt") + CPU + std::string(".o");
 CmdArgs.push_back(Args.MakeArgString(CrtFileName));
@@ -425,6 +427,8 @@
 // Add the link library specific to the MCU.
 CmdArgs.push_back(Args.MakeArgString(std::string("-l") + CPU));
 
+CmdArgs.push_back("--end-group");
+
 // Specify the family name as the emulation mode to use.
 // This is almost always required because otherwise avr-ld
 // will assume 'avr2' and warn about the program being larger
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D106785#2904619 , @Anastasia wrote:

> I would like @svenvh to take a look from the clang header's design point.

Looks okay to me.




Comment at: clang/docs/LanguageExtensions.rst:1980
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // compiled - var3 is __private 
int
+  }





Comment at: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp:14
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space<__generic int>::type, 
int>::value,
+"__generic address space not removed by 
__remove_address_space");

It's maybe worth testing `is_same` with `static_assert(!is_same::value);` too, or at least testing some negative case.

A case without any address space qualifiers is currently missing (i.e., for the 
first trait).


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

https://reviews.llvm.org/D106785

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


[PATCH] D106790: prfchwintrin.h: Make _m_prefetchw take a pointer to volatile (PR49124)

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

In D106790#2905110 , @rnk wrote:

> Does this match GCC? They also provide this Intel intrinsic.

No, they define it without volatile (and also without const): 
https://github.com/gcc-mirror/gcc/blob/releases/gcc-11.1.0/gcc/config/i386/prfchwintrin.h#L32

But maybe their header doesn't get included together with Microsoft's header?




Comment at: clang/lib/Headers/prfchwintrin.h:54
+#pragma clang diagnostic ignored "-Wcast-qual"
+  __builtin_prefetch ((const void*)__P, 1, 3 /* _MM_HINT_T0 */);
+#pragma clang diagnostic pop

pengfei wrote:
> Can we declare `__builtin_prefetch` to volatile one in Builtins.def:
> ```
> BUILTIN(__builtin_prefetch, "vvCD*.", "nc")
> ```
We could, and that would remove the need for the cast, but I'm not sure it 
would make sense in itself. Since _m_prefetchw is the odd one here, I think it 
makes sense to do the fix in its implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106790

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


[PATCH] D105555: [RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-27 Thread Alex Bradbury via Phabricator via cfe-commits
asb accepted this revision.
asb added a comment.
This revision is now accepted and ready to land.

This looks good to me, and as Jessica says this patch improves robustness and 
correctness so it would be great to land it for 13.x.

@jrtc27 - I think @khchen has reflected all of your comments, but please 
double-check if you get a chance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

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


[clang] a648f34 - [clang-cl] Expose -fmodules and related flags in the driver (PR43391)

2021-07-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2021-07-27T11:27:16+02:00
New Revision: a648f34342740e3fe2ddf040d61909d53b09e323

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

LOG: [clang-cl] Expose -fmodules and related flags in the driver (PR43391)

I don't know how well this works with clang-cl, but people want to try
it out, and I think we want to make it work, so exposing the flags seems
reasonable.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0e0aa16797cad..5a9fd078390e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2139,7 +2139,7 @@ defm pch_debuginfo: OptInFFlag<"pch-debuginfo", "Generate 
", "Do not generate ",
   "debug info for types in an object file built from this PCH and do not 
generate them elsewhere">;
 
 def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, 
Group,
-  Flags<[NoXarchOption, CC1Option]>,
+  Flags<[NoXarchOption, CC1Option, CoreOption]>,
   HelpText<"Implicitly search the file system for module map files.">,
   MarshallingInfoFlag>;
 def fmodules_ts : Flag <["-"], "fmodules-ts">, Group,
@@ -2148,42 +2148,43 @@ def fmodules_ts : Flag <["-"], "fmodules-ts">, 
Group,
 defm modules : BoolFOption<"modules",
   LangOpts<"Modules">, Default,
   PosFlag,
-  NegFlag, BothFlags<[NoXarchOption]>>;
-def fmodule_maps : Flag <["-"], "fmodule-maps">, Alias;
+  NegFlag, BothFlags<[NoXarchOption, CoreOption]>>;
+def fmodule_maps : Flag <["-"], "fmodule-maps">, Flags<[CoreOption]>, 
Alias;
 def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, Group,
-  Flags<[NoXarchOption,CC1Option]>, MetaVarName<"">,
+  Flags<[NoXarchOption,CC1Option,CoreOption]>, MetaVarName<"">,
   HelpText<"Specify the name of the module to build">,
   MarshallingInfoString>;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
-  Flags<[CC1Option]>, Alias;
-def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  Flags<[CC1Option,CoreOption]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, 
Flags<[CC1Option,CoreOption]>,
   HelpText<"Build this module as a system module. Only used with 
-emit-module">,
   MarshallingInfoFlag>;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
-  Group, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"">,
+  Group, Flags<[NoXarchOption,CC1Option,CoreOption]>, 
MetaVarName<"">,
   HelpText<"Load this module map file">,
   MarshallingInfoStringVector>;
 def fmodule_file : Joined<["-"], "fmodule-file=">,
-  Group, Flags<[NoXarchOption,CC1Option]>, 
MetaVarName<"[=]">,
+  Group, Flags<[NoXarchOption,CC1Option,CoreOption]>, 
MetaVarName<"[=]">,
   HelpText<"Specify the mapping of module name to precompiled module file, or 
load a module file if name is omitted.">;
-def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, 
Group, Flags<[CC1Option]>,
+def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, 
Group,
+  Flags<[CC1Option,CoreOption]>,
   HelpText<"Ignore the definition of the given macro when building and loading 
modules">;
 def fmodules_strict_decluse : Flag <["-"], "fmodules-strict-decluse">, 
Group,
-  Flags<[NoXarchOption,CC1Option]>,
+  Flags<[NoXarchOption,CC1Option,CoreOption]>,
   HelpText<"Like -fmodules-decluse but requires all headers to be in modules">,
   MarshallingInfoFlag>;
 defm modules_decluse : BoolFOption<"modules-decluse",
   LangOpts<"ModulesDeclUse">, Default,
   PosFlag,
-  NegFlag, BothFlags<[NoXarchOption]>>;
+  NegFlag, BothFlags<[NoXarchOption,CoreOption]>>;
 defm modules_search_all : BoolFOption<"modules-search-all",
   LangOpts<"ModulesSearchAll">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[NoXarchOption, CC1Option]>>,
+  NegFlag, BothFlags<[NoXarchOption, CC1Option,CoreOption]>>,
   ShouldParseIf;
 defm implicit_modules : BoolFOption<"implicit-modules",
   LangOpts<"ImplicitModules">, DefaultTrue,
-  NegFlag, PosFlag, 
BothFlags<[NoXarchOption]>>;
+  NegFlag, PosFlag, 
BothFlags<[NoXarchOption,CoreOption]>>;
 def fretain_comments_from_system_headers : Flag<["-"], 
"fretain-comments-from-system-headers">, Group, Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 7f553079e4cc9..038badd847ce8 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -710,6 +710,23 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -fmodules \
+// RUN: -fno-modules \
+// RUN: -fimplicit-module-maps 

[PATCH] D106791: [clang-cl] Expose -fmodules and related flags in the driver (PR43391)

2021-07-27 Thread Hans Wennborg 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 rGa648f3434274: [clang-cl] Expose -fmodules and related flags 
in the driver (PR43391) (authored by hans).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106791

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -710,6 +710,23 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -fmodules \
+// RUN: -fno-modules \
+// RUN: -fimplicit-module-maps \
+// RUN: -fmodule-maps \
+// RUN: -fmodule-name=foo \
+// RUN: -fmodule-implementation-of \
+// RUN: -fsystem-module \
+// RUN: -fmodule-map-file=foo \
+// RUN: -fmodule-file=foo \
+// RUN: -fmodules-ignore-macro=foo \
+// RUN: -fmodules-strict-decluse \
+// RUN: -fmodules-decluse \
+// RUN: -fno-modules-decluse \
+// RUN: -fmodules-search-all \
+// RUN: -fno-modules-search-all \
+// RUN: -fimplicit-modules \
+// RUN: -fno-implicit-modules \
 // RUN: -ftrivial-auto-var-init=zero \
 // RUN: 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2139,7 +2139,7 @@
   "debug info for types in an object file built from this PCH and do not 
generate them elsewhere">;
 
 def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, 
Group,
-  Flags<[NoXarchOption, CC1Option]>,
+  Flags<[NoXarchOption, CC1Option, CoreOption]>,
   HelpText<"Implicitly search the file system for module map files.">,
   MarshallingInfoFlag>;
 def fmodules_ts : Flag <["-"], "fmodules-ts">, Group,
@@ -2148,42 +2148,43 @@
 defm modules : BoolFOption<"modules",
   LangOpts<"Modules">, Default,
   PosFlag,
-  NegFlag, BothFlags<[NoXarchOption]>>;
-def fmodule_maps : Flag <["-"], "fmodule-maps">, Alias;
+  NegFlag, BothFlags<[NoXarchOption, CoreOption]>>;
+def fmodule_maps : Flag <["-"], "fmodule-maps">, Flags<[CoreOption]>, 
Alias;
 def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, Group,
-  Flags<[NoXarchOption,CC1Option]>, MetaVarName<"">,
+  Flags<[NoXarchOption,CC1Option,CoreOption]>, MetaVarName<"">,
   HelpText<"Specify the name of the module to build">,
   MarshallingInfoString>;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
-  Flags<[CC1Option]>, Alias;
-def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  Flags<[CC1Option,CoreOption]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, 
Flags<[CC1Option,CoreOption]>,
   HelpText<"Build this module as a system module. Only used with 
-emit-module">,
   MarshallingInfoFlag>;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
-  Group, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"">,
+  Group, Flags<[NoXarchOption,CC1Option,CoreOption]>, 
MetaVarName<"">,
   HelpText<"Load this module map file">,
   MarshallingInfoStringVector>;
 def fmodule_file : Joined<["-"], "fmodule-file=">,
-  Group, Flags<[NoXarchOption,CC1Option]>, 
MetaVarName<"[=]">,
+  Group, Flags<[NoXarchOption,CC1Option,CoreOption]>, 
MetaVarName<"[=]">,
   HelpText<"Specify the mapping of module name to precompiled module file, or 
load a module file if name is omitted.">;
-def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, 
Group, Flags<[CC1Option]>,
+def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, 
Group,
+  Flags<[CC1Option,CoreOption]>,
   HelpText<"Ignore the definition of the given macro when building and loading 
modules">;
 def fmodules_strict_decluse : Flag <["-"], "fmodules-strict-decluse">, 
Group,
-  Flags<[NoXarchOption,CC1Option]>,
+  Flags<[NoXarchOption,CC1Option,CoreOption]>,
   HelpText<"Like -fmodules-decluse but requires all headers to be in modules">,
   MarshallingInfoFlag>;
 defm modules_decluse : BoolFOption<"modules-decluse",
   LangOpts<"ModulesDeclUse">, Default,
   PosFlag,
-  NegFlag, BothFlags<[NoXarchOption]>>;
+  NegFlag, BothFlags<[NoXarchOption,CoreOption]>>;
 defm modules_search_all : BoolFOption<"modules-search-all",
   LangOpts<"ModulesSearchAll">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[NoXarchOption, CC1Option]>>,
+  NegFlag, BothFlags<[NoXarchOption, CC1Option,CoreOption]>>,
   ShouldParseIf;
 defm implicit_modules : BoolFOption<"implicit-modules",
   LangOpts<"ImplicitModules">, DefaultTrue,
-  NegFlag, PosFlag, 
BothFlags<[NoXarchOption]>>;
+  NegFlag, PosFlag, 
BothFlags<[NoXarchOption,C

[PATCH] D106858: [hwasan] Fix stack safety test for old PM.

2021-07-27 Thread Florian Mayer via Phabricator via cfe-commits
fmayer created this revision.
fmayer requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With the old PM, the stub for __hwasan_generate_tag is still generated
in the IR, but never called.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106858

Files:
  clang/test/CodeGen/hwasan-stack-safety-analysis.c


Index: clang/test/CodeGen/hwasan-stack-safety-analysis.c
===
--- clang/test/CodeGen/hwasan-stack-safety-analysis.c
+++ clang/test/CodeGen/hwasan-stack-safety-analysis.c
@@ -1,5 +1,8 @@
-// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm 
-mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls 
-O2 %s -o - | FileCheck %s --check-prefix=SAFETY
-// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm 
-mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls 
-O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY
+// RUN: %clang -fno-legacy-pass-manager -fsanitize=hwaddress -target 
aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm 
-hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s 
--check-prefix=SAFETY
+// RUN: %clang -fno-legacy-pass-manager -fsanitize=hwaddress -target 
aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm 
-hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s 
--check-prefix=NOSAFETY
+
+// RUN: %clang -flegacy-pass-manager -fsanitize=hwaddress -target 
aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm 
-hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s 
--check-prefix=SAFETY
+// RUN: %clang -flegacy-pass-manager -fsanitize=hwaddress -target 
aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm 
-hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s 
--check-prefix=NOSAFETY
 
 // Default when optimizing, but not with O0.
 // RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm 
-mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s 
--check-prefix=SAFETY
@@ -10,6 +13,6 @@
   volatile char *x = buf;
   *x = 0;
   return buf[0];
-  // NOSAFETY: __hwasan_generate_tag
-  // SAFETY-NOT: __hwasan_generate_tag
+  // NOSAFETY: call i8 @__hwasan_generate_tag
+  // SAFETY-NOT: call i8 @__hwasan_generate_tag
 }


Index: clang/test/CodeGen/hwasan-stack-safety-analysis.c
===
--- clang/test/CodeGen/hwasan-stack-safety-analysis.c
+++ clang/test/CodeGen/hwasan-stack-safety-analysis.c
@@ -1,5 +1,8 @@
-// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY
-// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY
+// RUN: %clang -fno-legacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY
+// RUN: %clang -fno-legacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY
+
+// RUN: %clang -flegacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY
+// RUN: %clang -flegacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY
 
 // Default when optimizing, but not with O0.
 // RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY
@@ -10,6 +13,6 @@
   volatile char *x = buf;
   *x = 0;
   return buf[0];
-  // NOSAFETY: __hwasan_generate_tag
-  // SAFETY-NOT: __hwasan_generate_tag
+  // NOSAFETY: call i8 @__hwasan_generate_tag
+  // SAFETY-NOT: call i8 @__hwasan_generate_tag
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna updated this revision to Diff 361954.
Topotuna added a comment.

Additional tests added for `is_same`


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

https://reviews.llvm.org/D106785

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Headers/opencl-c-base.h
  clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp

Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_is_same() {
+  static_assert(is_same::value);
+  static_assert(!is_same::value);
+  static_assert(!is_same<__private int, int>::value);
+}
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space<__generic int>::type, int>::value,
+"__generic address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, char>::value,
+"__global address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value,
+"__private address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, short>::value,
+"__local address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__constant int3>::type, int3>::value,
+"__constant address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space::type, const volatile int>::value,
+"non-address-space qualifiers inappropriately removed by __remove_address_space");
+}
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -565,6 +565,26 @@
 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
 
+// C++ for OpenCL - __remove_address_space
+#if defined(__OPENCL_CPP_VERSION__)
+template  struct __remove_address_space { using type = _Tp; };
+template  struct __remove_address_space<__generic _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__global _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__private _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__local _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__constant _Tp> {
+  using type = _Tp;
+};
+#endif
+
 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
 
 #define __kernel_exec(X, typen) __kernel \
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1961,6 +1961,30 @@
 global OnlySL *d,
   );
 
+Address space removal
+-
+
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. The tool only throws away
+address space qualifiers, therefore, other type qualifiers such as
+``const`` or ``volatile`` remain unchanged.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  template
+  void foo(T *par){
+T var1; // error - local function variable with global address space
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // var3 is __private int
+  }
+
+  void bar(){
+__global int* ptr;
+foo(ptr);
+  }
+
 Legacy 1.x atomics with generic address space
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0f98e6e - [clang][tooling] Link LLVMOption to ToolingTests

2021-07-27 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-07-27T11:48:44+02:00
New Revision: 0f98e6e87558b34cb00e2a043d471cb71466783a

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

LOG: [clang][tooling] Link LLVMOption to ToolingTests

This fixes a build failure introduced in 
11ee699b3c812ebe56ce5d3b14ab7ef16c1e8495.

Added: 


Modified: 
clang/unittests/Tooling/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Tooling/CMakeLists.txt 
b/clang/unittests/Tooling/CMakeLists.txt
index 001d02636fa1..27b5e30f76ba 100644
--- a/clang/unittests/Tooling/CMakeLists.txt
+++ b/clang/unittests/Tooling/CMakeLists.txt
@@ -1,5 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
+  Option
   FrontendOpenMP
   Support
   )



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


[PATCH] D105495: [clang] Make negative getLocWithOffset widening-safe.

2021-07-27 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 361957.
simon_tatham edited the summary of this revision.
simon_tatham added a comment.

In D105495#2882628 , @tmatheson wrote:

> I also think it's the caller's responsibility to make sure what they pass in 
> is correctly signed.

I don't disagree with that in principle, but in a case like this, where the 
error is extremely easy to make, not warned about at compile time (so you have 
to exercise the failing code path to spot it), and won't even show up at 
//runtime// in the default build configuration (even once 64-bit 
SourceLocations are actually implemented, the current plan is for them to be 
off by default), I think it's worth at least //trying// to think of ways to 
help the caller get it right.

Perhaps an alternative API might be to replace 
`SourceLocation::getLocWithOffset` with an `operator+`, and add an `operator-` 
to go with it? Then you could write `NewLoc = OldLoc + ThisInteger - 
ThatInteger` and each integer would be implicitly widened if it was the wrong 
size.

But in this version of the patch, I haven't done that; I've just reverted the 
introduction of dyadic `getLocWithOffset` and added cumbersome casts or 
intermediate variables at the call sites where I'd previously used it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105495

Files:
  clang/lib/AST/SelectorLocationsKind.cpp
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/Parse/ParseStmtAsm.cpp
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Index: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -1081,8 +1081,8 @@
   // Highlight the range.  Make the span tag the outermost tag for the
   // selected range.
 
-  SourceLocation E =
-InstantiationEnd.getLocWithOffset(EndColNo - OldEndColNo);
+  SourceLocation E = InstantiationEnd.getLocWithOffset(
+  static_cast(EndColNo) - OldEndColNo);
 
   html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd);
 }
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -185,7 +185,8 @@
   if (TokIndex < AsmToks.size()) {
 const Token &Tok = AsmToks[TokIndex];
 Loc = Tok.getLocation();
-Loc = Loc.getLocWithOffset(Offset - TokOffset);
+Loc = Loc.getLocWithOffset(static_cast(Offset) -
+   TokOffset);
   }
   return Loc;
 }
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -510,24 +510,29 @@
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   assert(Loc.isFileID());
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-  if (LocInfo.first.isInvalid())
+  FileID LocFileID;
+  SourceLocation::UIntTy LocOffset;
+  std::tie(LocFileID, LocOffset) = SM.getDecomposedLoc(Loc);
+  if (LocFileID.isInvalid())
 return Loc;
 
   bool Invalid = false;
-  StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
+  StringRef Buffer = SM.getBufferData(LocFileID, &Invalid);
   if (Invalid)
 return Loc;
 
+  if (LocOffset > Buffer.size())
+return Loc;
+
   // Back up from the current location until we hit the beginning of a line
   // (or the buffer). We'll relex from that point.
-  const char *StrData = Buffer.data() + LocInfo.second;
-  const char *LexStart = findBeginningOfLine(Buffer, LocInfo.second);
+  const char *StrData = Buffer.data() + LocOffset;
+  const char *LexStart = findBeginningOfLine(Buffer, LocOffset);
   if (!LexStart || LexStart == StrData)
 return Loc;
 
   // Create a lexer starting at the beginning of this token.
-  SourceLocation LexerStartLoc = Loc.getLocWithOffset(-LocInfo.second);
+  SourceLocation LexerStartLoc = Loc.getLocWithOffset(-LocOffset);
   Lexer TheLexer(LexerStartLoc, LangOpts, Buffer.data(), LexStart,
  Buffer.end());
   TheLexer.SetCommentRetentionState(true);
@@ -565,12 +570,12 @@
 
   SourceLocation FileLoc = SM.getSpellingLoc(Loc);
   SourceLocation BeginFileLoc = getBeginningOfFileToken(FileLoc, SM, LangOpts);
-  std::pair FileLocInfo = SM.getDecomposedLoc(FileLoc);
-  std::pair BeginFileLocInfo =
-  SM.getDecomposedLoc(BeginFileLoc);
-  assert(FileLocInfo.first == BeginFileLocInfo.first &&
- FileLocInfo.second >= BeginFileLocInfo.second);
-  return Loc.getLocWithOffset(BeginFileLocInfo.second - FileLocInfo.second);
+  FileID FID, BeginFID;
+  SourceLocation::UIntTy FileOffset, BeginFileOffset;
+  s

[PATCH] D105495: [clang] Make negative getLocWithOffset widening-safe.

2021-07-27 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added inline comments.



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:236
 if (Loc.isMacroID())
-  return Loc.getLocWithOffset(-SM.getFileOffset(Loc));
+  return Loc.getLocWithOffset(0, SM.getFileOffset(Loc));
 return SM.getLocForStartOfFile(SM.getFileID(Loc));

tmatheson wrote:
> Seems like getFileOffset should now return ui64.
That seems sensible from first principles, but I tried tugging on that thread 
and it turned out to have a //lot// of extra work behind it, because file 
offsets are absolutely all over the place (perhaps even more so that 
SourceLocations proper), and in particular, they're often used as indexes into 
in-memory buffers, which gets awkward if you want 64-bit SourceLocations and 
64-bit builds of clang to be independent choices.

Perhaps you're right that expanding file offsets to 64-bit would also be a 
useful piece of work. But doing it as part of //this// work would double the 
size of the job, so I think it would make more sense to keep it separate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105495

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


[PATCH] D105981: [AMDGPU][OpenMP] Support linking of math libraries

2021-07-27 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 361967.
pdhaliwal added a comment.

Extract the options from HIP/OpenMP to a common method in base class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105981

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c

Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -74,3 +74,6 @@
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
 // CHECK-EMIT-LLVM-IR: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"
+
+// RUN: env LIBRARY_PATH=%S/Inputs/hip_dev_lib %clang -### -target x86_64-pc-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE
+// CHECK-LIB-DEVICE: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-mlink-builtin-bitcode"{{.*}}libomptarget-amdgcn-gfx803.bc"{{.*}}"-mlink-builtin-bitcode"{{.*}}ocml.bc" "-mlink-builtin-bitcode"{{.*}}ockl.bc" "-mlink-builtin-bitcode"{{.*}}oclc_daz_opt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_finite_only_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_isa_version_803.bc"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -395,35 +395,8 @@
 }
 StringRef GpuArch = getGPUArch(DriverArgs);
 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
-(void)GpuArch;
-auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
-const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-
-std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
-if (LibDeviceFile.empty()) {
-  getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 1 << GpuArch;
-  return {};
-}
 
 // If --hip-device-lib is not set, add the default bitcode libraries.
-// TODO: There are way too many flags that change this. Do we need to check
-// them all?
-bool DAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
-  options::OPT_fno_gpu_flush_denormals_to_zero,
-  getDefaultDenormsAreZeroForTarget(Kind));
-bool FiniteOnly =
-DriverArgs.hasFlag(options::OPT_ffinite_math_only,
-   options::OPT_fno_finite_math_only, false);
-bool UnsafeMathOpt =
-DriverArgs.hasFlag(options::OPT_funsafe_math_optimizations,
-   options::OPT_fno_unsafe_math_optimizations, false);
-bool FastRelaxedMath = DriverArgs.hasFlag(
-options::OPT_ffast_math, options::OPT_fno_fast_math, false);
-bool CorrectSqrt = DriverArgs.hasFlag(
-options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
-options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
-bool Wave64 = isWave64(DriverArgs, Kind);
-
 if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
options::OPT_fno_gpu_sanitize, false)) {
   auto AsanRTL = RocmInstallation.getAsanRTLPath();
@@ -442,10 +415,8 @@
 // Add the HIP specific bitcode library.
 BCLibs.push_back(RocmInstallation.getHIPPath().str());
 
-// Add the generic set of libraries.
-BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
-DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
-FastRelaxedMath, CorrectSqrt));
+// Add common device libraries like ocml etc.
+BCLibs.append(getCommonDeviceLibOptions(DriverArgs, GpuArch.str()));
 
 // Add instrument lib.
 auto InstLib =
Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -10,11 +10,13 @@
 #include "AMDGPU.h"
 #include "CommonArgs.h"
 #include "InputInfo.h"
+#include "ToolChains/ROCm.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/F

[PATCH] D105981: [AMDGPU][OpenMP] Support linking of math libraries

2021-07-27 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added inline comments.



Comment at: clang/lib/Driver/ToolChains/AMDGPU.cpp:923-924
+  bool CorrectSqrt = DriverArgs.hasFlag(
+  options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
+  options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
+  bool Wave64 = isWave64(DriverArgs, Kind);

I wanted to rename these to something generic like -fgpu-fp32 but due to 
some weird reason aliasing wasn't working. Anyhow, my suggestion is to make 
that change in separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105981

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


[PATCH] D106860: [clang][AArch64][SVE] Avoid going through memory for fixed/scalable predicate casts

2021-07-27 Thread Bradley Smith via Phabricator via cfe-commits
bsmith created this revision.
bsmith added reviewers: paulwalker-arm, peterwaller-arm, eli.friedman, 
junparser.
Herald added subscribers: psnobl, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
bsmith requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For fixed SVE types, predicates are represented using vectors of i8,
where as for scalable types they are represented using vectors of i1. We
can avoid going through memory for casts between these by bitcasting the
i1 scalable vectors to/from a scalable i8 vector of matching size, which
can then use the existing vector insert/extract logic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106860

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-call.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c

Index: clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
@@ -49,20 +49,16 @@
 
 // CHECK-128-LABEL: @write_global_bool(
 // CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca , align 16
-// CHECK-128-NEXT:store  [[V:%.*]], * [[SAVED_VALUE]], align 16, !tbaa [[TBAA9:![0-9]+]]
-// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast * [[SAVED_VALUE]] to <2 x i8>*
-// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i8>, <2 x i8>* [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
-// CHECK-128-NEXT:store <2 x i8> [[TMP0]], <2 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = bitcast  [[V:%.*]] to 
+// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = call <2 x i8> @llvm.experimental.vector.extract.v2i8.nxv2i8( [[TMP0]], i64 0)
+// CHECK-128-NEXT:store <2 x i8> [[CASTFIXEDSVE]], <2 x i8>* @global_bool, align 2, !tbaa [[TBAA6:![0-9]+]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_bool(
 // CHECK-512-NEXT:  entry:
-// CHECK-512-NEXT:[[SAVED_VALUE:%.*]] = alloca , align 16
-// CHECK-512-NEXT:store  [[V:%.*]], * [[SAVED_VALUE]], align 16, !tbaa [[TBAA9:![0-9]+]]
-// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast * [[SAVED_VALUE]] to <8 x i8>*
-// CHECK-512-NEXT:[[TMP0:%.*]] = load <8 x i8>, <8 x i8>* [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
-// CHECK-512-NEXT:store <8 x i8> [[TMP0]], <8 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
+// CHECK-512-NEXT:[[TMP0:%.*]] = bitcast  [[V:%.*]] to 
+// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = call <8 x i8> @llvm.experimental.vector.extract.v8i8.nxv2i8( [[TMP0]], i64 0)
+// CHECK-512-NEXT:store <8 x i8> [[CASTFIXEDSVE]], <8 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_bool(svbool_t v) { global_bool = v; }
@@ -101,20 +97,16 @@
 
 // CHECK-128-LABEL: @read_global_bool(
 // CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca <2 x i8>, align 16
 // CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i8>, <2 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
-// CHECK-128-NEXT:store <2 x i8> [[TMP0]], <2 x i8>* [[SAVED_VALUE]], align 16, !tbaa [[TBAA6]]
-// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast <2 x i8>* [[SAVED_VALUE]] to *
-// CHECK-128-NEXT:[[TMP1:%.*]] = load , * [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = call  @llvm.experimental.vector.insert.nxv2i8.v2i8( undef, <2 x i8> [[TMP0]], i64 0)
+// CHECK-128-NEXT:[[TMP1:%.*]] = bitcast  [[CASTFIXEDSVE]] to 
 // CHECK-128-NEXT:ret  [[TMP1]]
 //
 // CHECK-512-LABEL: @read_global_bool(
 // CHECK-512-NEXT:  entry:
-// CHECK-512-NEXT:[[SAVED_VALUE:%.*]] = alloca <8 x i8>, align 16
 // CHECK-512-NEXT:[[TMP0:%.*]] = load <8 x i8>, <8 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
-// CHECK-512-NEXT:store <8 x i8> [[TMP0]], <8 x i8>* [[SAVED_VALUE]], align 16, !tbaa [[TBAA6]]
-// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast <8 x i8>* [[SAVED_VALUE]] to *
-// CHECK-512-NEXT:[[TMP1:%.*]] = load , * [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
+// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = call  @llvm.experimental.vector.insert.nxv2i8.v8i8( undef, <8 x i8> [[TMP0]], i64 0)
+// CHECK-512-NEXT:[[TMP1:%.*]] = bitcast  [[CASTFIXEDSVE]] to 
 // CHECK-512-NEXT:ret  [[TMP1]]
 //
 svbool_t read_global_bool() { return global_bool; }
Index: clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
@@ -18,19 +18,15 @@
 // CHECK-NEXT:[[PRED_ADDR:%.*]] = 

[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:1964
 
+Address space removal
+-

Maybe we could title it something like:

`Address space removal utility`
or
`Address space removal trait`
?



Comment at: clang/docs/LanguageExtensions.rst:1968
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. The tool only throws away
+address space qualifiers, therefore, other type qualifiers such as




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

https://reviews.llvm.org/D106785

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


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:1964
 
+Address space removal
+-

Anastasia wrote:
> Maybe we could title it something like:
> 
> `Address space removal utility`
> or
> `Address space removal trait`
> ?
Although we could also be more specific and name it
`Remove address space builtin function`?


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

https://reviews.llvm.org/D106785

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


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna updated this revision to Diff 361975.
Topotuna added a comment.

Documentation rewording


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

https://reviews.llvm.org/D106785

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Headers/opencl-c-base.h
  clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp

Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_is_same() {
+  static_assert(is_same::value);
+  static_assert(!is_same::value);
+  static_assert(!is_same<__private int, int>::value);
+}
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space<__generic int>::type, int>::value,
+"__generic address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, char>::value,
+"__global address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value,
+"__private address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, short>::value,
+"__local address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__constant int3>::type, int3>::value,
+"__constant address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space::type, const volatile int>::value,
+"non-address-space qualifiers inappropriately removed by __remove_address_space");
+}
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -565,6 +565,26 @@
 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
 
+// C++ for OpenCL - __remove_address_space
+#if defined(__OPENCL_CPP_VERSION__)
+template  struct __remove_address_space { using type = _Tp; };
+template  struct __remove_address_space<__generic _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__global _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__private _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__local _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__constant _Tp> {
+  using type = _Tp;
+};
+#endif
+
 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
 
 #define __kernel_exec(X, typen) __kernel \
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1961,6 +1961,30 @@
 global OnlySL *d,
   );
 
+Builtin address space removal utility
+-
+
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. This utility only affects
+address space qualifiers, therefore, other type qualifiers such as
+``const`` or ``volatile`` remain unchanged.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  template
+  void foo(T *par){
+T var1; // error - local function variable with global address space
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // var3 is __private int
+  }
+
+  void bar(){
+__global int* ptr;
+foo(ptr);
+  }
+
 Legacy 1.x atomics with generic address space
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:1964
 
+Address space removal
+-

Anastasia wrote:
> Anastasia wrote:
> > Maybe we could title it something like:
> > 
> > `Address space removal utility`
> > or
> > `Address space removal trait`
> > ?
> Although we could also be more specific and name it
> `Remove address space builtin function`?
`Builtin address space removal utility`?

I would prefer not to leave wording "Remove address space" in description 
because it is already what utility name says and so it adds no extra 
information.



Comment at: clang/docs/LanguageExtensions.rst:1968
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. The tool only throws away
+address space qualifiers, therefore, other type qualifiers such as

Anastasia wrote:
> 
I would rather use word "affects" instead of "removes" here. There is already 
excessive amount of "remove" in this paragraph


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

https://reviews.llvm.org/D106785

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


[PATCH] D106733: [clang/darwin] Pass libclang_rt.profile last on linker command

2021-07-27 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

@vsk, I'll go ahead and land this. If this does cause problems for you after 
all (on the bug you said it should be fine), please revert :)


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

https://reviews.llvm.org/D106733

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


[PATCH] D105881: [flang][driver] Switch to `BoolFOption` for boolean options

2021-07-27 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thank you for your detailed reply!

In D105881#2904699 , @jansvoboda11 
wrote:

> Sorry, I'm not sure I follow.

OK, let me try to clarify. I've tried to split this into threads.

(flag == OptionFlag 

 )

**SEMANTICS**

> In D105881#2890134 , @awarzynski 
> wrote:
>
>> @jansvoboda11 , now I'm realising the key disadvantage of using 
>> `OptInFFlag/OptOutFFlag` - it's impossible to express the `opt-in`/`opt-out` 
>> semantics in TableGen.
>
> What do you mean exactly?

BoolOption 

 (from which BoolFOption 

 derives) has e.g. the `default` value and a bunch of `assert`s to define the 
relation between `-ffoo` and `-fno-foo`. So effectively, the opt-in/opt-out 
semantics are enforced here. `OptInFFlag`/`OptOutFFlag` have none of this. It's 
just a syntactic sugar to automate the generation of `-ffoo` and `-fno-foo`. 
That's fine, we can add such checks inside the driver.

**CC1Option**

> I think the semantics are expressed pretty well from Clang's point of view:

OK, that's fair enough. But what about the output from `clang --help` and 
`clang -cc1 --help`? Let's look at -feliminate-unused-debug-types 

 (the only instance of `OptOutFFLag`):

  # Only -fno-eliminate-unusued-debug-types is printed
  clang -cc1 --help | grep eliminate-unused
-fno-eliminate-unused-debug-types
  # Both -fno-eliminate-unusued-debug-types and -feliminate-unusued-debug-types 
printed?
  clang --help | grep eliminate-unused
-feliminate-unused-debug-types
-fno-eliminate-unused-debug-types

To me this behavior is counter-intuitive. So are these `clang` options? `clang 
-cc1` options? Both? What's the point of adding `CC1Option` if both `clang` and 
`clang -cc1` accept them. The definition of `CC1Option` from Options.td:

  // CC1Option - This option should be accepted by clang -cc1.
  def CC1Option : OptionFlag;

OK, so currently `-fno-eliminate-unused-debug-types` is a `CC1Option` and 
_should_ be accepted by `clang -cc1`. How about 
`-feliminate-unused-debug-types`?

  clang -cc1 -feliminate-unused-debug-types file.c
  error: unknown argument: '-feliminate-unused-debug-types'

Makes sense, but:

  clang -c -feliminate-unused-debug-types file.c
  clang-13: warning: argument unused during compilation: 
'-feliminate-unused-debug-types' [-Wunused-command-line-argument]

Shouldn't it be rejected by `clang` with an error as well? Shouldn't 
`CC1Option` be used consistently for `-feliminate-unused-debug-types`  and 
`-fno-eliminate-unused-debug-types`?

>> In fact, only the contents of `clang -cc1 --help` are being tweaked by using 
>> `OptInFFlag/OptOutFFlag`.
>
> That's incorrect, `OptInFFlag` and `OptOutFFlag` both set `HelpText` for the 
> positive and negative driver flags.

Yes, but in `clang --cc1 --help`, only the variant with `CC1Option` is being 
printed and the other one is ignored. So why bother adding the other one?

Btw, now I see that `-cc1` does reject `-feliminate-unused-debug-types`, so 
it's not only about the contents of `clang -cc1 --help`. I was wrong, sorry 
about that and thanks for pointing this out!

**Content of `--help`**

>> In Flang, we rely on the fact that "no help text? don't include it in 
>> `flang-new -fc1 --help`" instead. This behavior is implemented in 
>> `clangDriver` and applies to all drivers that use it (so this is nothing 
>> specific to Flang).
>
> I see. Is this intentional?
>
>> This way, we can always mark Flang options with the relevant flags (e.g. 
>> `FC1Option`). In other words, we can claim them and make it clear that other 
>> drivers can ignore them.
>
> I don't understand this. Can you elaborate? Are you relying on the 
> absence/presence of a help text to mark flags with `FC1Option`? When does 
> this happen? (In `Options.td`? The TableGen backend? The consumer of 
> `Options.inc`?)

See the implementation of printHelp 

 from OptTable.cpp. Basically: "No help text? Not printing". We rely on this 
**not to print** options supported by Flang, but for which we have no help 
text. We only used that for boolean options (so we have a help text for e.g. 
`-ffoo`, but not for `-fno-foo`). This is a minor thing and I am not concerned 
about loosing it.

As for `FC1Option` (and `FlangOption`), we always add these explicitly in 
Opt

[clang] 452095f - [clang/darwin] Pass libclang_rt.profile last on linker command

2021-07-27 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-07-27T07:51:06-04:00
New Revision: 452095fe2f58528c174ca780265f227439e3e07e

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

LOG: [clang/darwin] Pass libclang_rt.profile last on linker command

This reverts the functional change of https://reviews.llvm.org/D35385 because
it sounds like this is no longer necessary
(https://bugs.llvm.org/show_bug.cgi?id=51135#c11) and makes clang's behavior
more uniform across platforms.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Darwin.h
clang/test/Driver/darwin-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 4de5e81d2c0c0..261f522f6c493 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1113,10 +1113,7 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, 
ArgStringList &CmdArgs,
   // we explicitly force linking with this library).
   if ((Opts & RLO_AlwaysLink) || getVFS().exists(P)) {
 const char *LibArg = Args.MakeArgString(P);
-if (Opts & RLO_FirstLink)
-  CmdArgs.insert(CmdArgs.begin(), LibArg);
-else
-  CmdArgs.push_back(LibArg);
+CmdArgs.push_back(LibArg);
   }
 
   // Adding the rpaths might negatively interact when other rpaths are 
involved,
@@ -1225,7 +1222,7 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
 return;
 
   AddLinkRuntimeLib(Args, CmdArgs, "profile",
-RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink));
+RuntimeLinkOptions(RLO_AlwaysLink));
 
   bool ForGCOV = needsGCovInstrumentation(Args);
 

diff  --git a/clang/lib/Driver/ToolChains/Darwin.h 
b/clang/lib/Driver/ToolChains/Darwin.h
index 812e51344f470..4de122c8d513e 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -184,9 +184,6 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
 
 /// Emit rpaths for @executable_path as well as the resource directory.
 RLO_AddRPath = 1 << 2,
-
-/// Link the library in before any others.
-RLO_FirstLink = 1 << 3,
   };
 
   /// Add a runtime library to the list of items to link.

diff  --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index 7441cc186df92..f6472f49c92e9 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -316,16 +316,6 @@
 // LINK_VERSION_DIGITS: invalid version number in 
'-mlinker-version=133.3.0.1.a'
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1a'
 
-// RUN: %clang -target x86_64-apple-ios6.0 -miphoneos-version-min=6.0 
-fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### 
%t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target i386-apple-darwin9 -fprofile-instr-generate -### %t.o 
2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target arm64-apple-ios5.0 -miphoneos-version-min=5.0 
-fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// LINK_PROFILE_FIRST: {{ld(.exe)?"}} 
"{{[^"]+}}libclang_rt.profile_{{[a-z]+}}.a"
-
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### 
%t.o 2> %t.log
 // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log
 // RUN: %clang -target arm64-apple-ios12 -fprofile-instr-generate -### %t.o 2> 
%t.log



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


[PATCH] D106733: [clang/darwin] Pass libclang_rt.profile last on linker command

2021-07-27 Thread Nico Weber via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG452095fe2f58: [clang/darwin] Pass libclang_rt.profile last 
on linker command (authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106733

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/test/Driver/darwin-ld.c


Index: clang/test/Driver/darwin-ld.c
===
--- clang/test/Driver/darwin-ld.c
+++ clang/test/Driver/darwin-ld.c
@@ -316,16 +316,6 @@
 // LINK_VERSION_DIGITS: invalid version number in 
'-mlinker-version=133.3.0.1.a'
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1a'
 
-// RUN: %clang -target x86_64-apple-ios6.0 -miphoneos-version-min=6.0 
-fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### 
%t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target i386-apple-darwin9 -fprofile-instr-generate -### %t.o 
2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target arm64-apple-ios5.0 -miphoneos-version-min=5.0 
-fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// LINK_PROFILE_FIRST: {{ld(.exe)?"}} 
"{{[^"]+}}libclang_rt.profile_{{[a-z]+}}.a"
-
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### 
%t.o 2> %t.log
 // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log
 // RUN: %clang -target arm64-apple-ios12 -fprofile-instr-generate -### %t.o 2> 
%t.log
Index: clang/lib/Driver/ToolChains/Darwin.h
===
--- clang/lib/Driver/ToolChains/Darwin.h
+++ clang/lib/Driver/ToolChains/Darwin.h
@@ -184,9 +184,6 @@
 
 /// Emit rpaths for @executable_path as well as the resource directory.
 RLO_AddRPath = 1 << 2,
-
-/// Link the library in before any others.
-RLO_FirstLink = 1 << 3,
   };
 
   /// Add a runtime library to the list of items to link.
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1113,10 +1113,7 @@
   // we explicitly force linking with this library).
   if ((Opts & RLO_AlwaysLink) || getVFS().exists(P)) {
 const char *LibArg = Args.MakeArgString(P);
-if (Opts & RLO_FirstLink)
-  CmdArgs.insert(CmdArgs.begin(), LibArg);
-else
-  CmdArgs.push_back(LibArg);
+CmdArgs.push_back(LibArg);
   }
 
   // Adding the rpaths might negatively interact when other rpaths are 
involved,
@@ -1225,7 +1222,7 @@
 return;
 
   AddLinkRuntimeLib(Args, CmdArgs, "profile",
-RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink));
+RuntimeLinkOptions(RLO_AlwaysLink));
 
   bool ForGCOV = needsGCovInstrumentation(Args);
 


Index: clang/test/Driver/darwin-ld.c
===
--- clang/test/Driver/darwin-ld.c
+++ clang/test/Driver/darwin-ld.c
@@ -316,16 +316,6 @@
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1.a'
 // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1a'
 
-// RUN: %clang -target x86_64-apple-ios6.0 -miphoneos-version-min=6.0 -fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target i386-apple-darwin9 -fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// RUN: %clang -target arm64-apple-ios5.0 -miphoneos-version-min=5.0 -fprofile-instr-generate -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
-// LINK_PROFILE_FIRST: {{ld(.exe)?"}} "{{[^"]+}}libclang_rt.profile_{{[a-z]+}}.a"
-
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log
 // RUN: %clang -target arm64-apple-ios12 -fprofile-instr-generate -### %t.o 2> %t.log
Index: clang/lib/Driver/ToolChains/Darwin.h
===
--- clang/lib/Driver/ToolChains/Darwin.h
+++ clang/lib/Driver/ToolChains/Darwin.h
@@ -184,9 +184,6 @@
 
 /// Emit rpaths for @executable_path as well as the resource directory.
 

[PATCH] D106862: [clang][modules] Avoid creating partial FullSourceLoc for explicit modules imports

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman, christof.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Some parts of the codebase use `FullSourceLoc` -- a wrapper around regular 
`SourceLocation` and `SourceManager`.

>From the existing code, it looks like the wrapper can be in two states:

- valid `SourceLocation`, present `SourceManager`,
- invalid `SourceLocation`, missing `SourceManager`.

When importing an explicitly-built module, the `SourceLocation` of the `import` 
directive is invalid, since the module is "imported" by the command-line 
argument. This causes an assertion failure in `hasManager` when serializing 
diagnostics containing this `SourceLocation` to file.

This patch makes sure the `FullSourceLoc` for invalid import `SourceLocations` 
omits the `SourceManager`, upholding the class invariant.

I also tried more defensive approach: making sure the wrapped `SourceLocation` 
is always valid in the `FullSourceLoc` constructor. However, some clients 
apparently rely on the fact they can construct invalid source locations and 
later modify their `ID` to make them valid.

Another approach (that works) is checking `Loc.isValid() && Loc.hasManager()` 
in `SDiagsRenderer::emitNote` before working with the `FullSourceLoc`. I think 
this is what all users of the wrapper should do, but I think that's something 
people more closely familiar with this code to consider. (@christof)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106862

Files:
  clang/lib/Basic/SourceLocation.cpp
  clang/test/Modules/Inputs/explicit-build-diags/a.h
  clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
  clang/test/Modules/explicit-build-diags.cpp


Index: clang/test/Modules/explicit-build-diags.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ 
%S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o 
%t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations 
-fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm 
-fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }
Index: clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }
Index: clang/test/Modules/Inputs/explicit-build-diags/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -199,6 +199,10 @@
 
   std::pair ImportLoc =
   SrcMgr->getModuleImportLoc(*this);
+
+  if (!ImportLoc.first.isValid())
+return std::make_pair(FullSourceLoc(), ImportLoc.second);
+
   return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr),
 ImportLoc.second);
 }


Index: clang/test/Modules/explicit-build-diags.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ %S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o %t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations -fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm -fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }
Index: clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }
Index: clang/test/Modules/Inputs/explicit-build-diags/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -199,6 +199,10 @@
 
   std::pair ImportLoc =
   SrcMgr->getModuleImportLoc(*this);
+
+  if (!ImportLoc.first.isValid())
+return std::make_pair(FullSourceLoc(), ImportLoc.second);
+
   return std::make_pair(FullSourceLoc(ImportLoc.first,

[PATCH] D106701: [clang] Add -falign-loops=N where N is a power of 2

2021-07-27 Thread Alex Bradbury via Phabricator via cfe-commits
asb added inline comments.



Comment at: llvm/test/CodeGen/RISCV/loop-alignment.ll:3-4
+; RUN: llc < %s -mtriple=riscv64 | FileCheck %s
+; RUN: llc < %s -mtriple=riscv64 -align-loops=16 | FileCheck %s 
-check-prefix=ALIGN_16
+; RUN: llc < %s -mtriple=riscv64 -align-loops=32 | FileCheck %s 
-check-prefix=ALIGN_32
+

MaskRay wrote:
> luismarques wrote:
> > MaskRay wrote:
> > > jrtc27 wrote:
> > > > MaskRay wrote:
> > > > > jrtc27 wrote:
> > > > > > MaskRay wrote:
> > > > > > > luismarques wrote:
> > > > > > > > Nit: it's a convention of the RISC-V backend codegen tests to 
> > > > > > > > wrap the RUN lines.
> > > > > > > only 86 columns. compiler-rt is even transiting to 100 column.
> > > > > > compiler-rt is not the RISC-V backend :)
> > > > > Wrapping lines here just makes the code less readable.
> > > > That's your personal opinion, which I disagree with, and it's not true 
> > > > if your terminal isn't wide enough. Going against existing convention 
> > > > in the backend tests should only be done with very good reason, and 
> > > > personal opinion is not that.
> > > Lines longer than 80-column (in this case just 86) are pretty common 
> > > among tests. I really hope test/CodeGen/RISCV/ can be more tolerant on 
> > > this matter.
> > > 
> > > Even the Linux scripts/checkpatch.pl has increased the limit to 100 
> > > because in many cases wrapping lines for strict 80-conformance just harms 
> > > readability.
> > > 
> > > Of course I don't want to waste time arguing on this matter. So if this 
> > > turns out to be an issue for RISC-V folks, I'll update it to save my time.
> > > Of course I don't want to waste time arguing on this matter. So if this 
> > > turns out to be an issue for RISC-V folks, I'll update it to save my time.
> > 
> > Personally, I don't particularly care. I don't know if @asb has strong 
> > feelings about this. If you think it would be beneficial to relax this 
> > convention please raise the issue on llvm-dev. Let's not keep discussing 
> > this in every patch touching RISC-V :-)
> Personally I don't even think the generic case needs to be raised on 
> llvm-dev:) There are just so many column>80 cases in llvm/test and 
> clang/test. Actually, If someone wants to enforce the 80-column rule more 
> rigidly, that probably needs a discussion.
> 
> That said, the argument here is about a subdirectory: 
> llvm/test/CodeGen/RISCV/ ...
> 
> 
I don't have a strong view on this one to be honest. I think I've typically 
wrapped at 80 columns for these RUN lines after being asked to, but ultimately 
I think choosing a logical point to split has a greater impact on readability 
than keeping it strictly to 80 columns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106701

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


[clang-tools-extra] ec1fb95 - [clangd] Use function pointer instead of function_ref to avoid GCC 5 bug

2021-07-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-07-27T14:01:35+02:00
New Revision: ec1fb9533305e9bd69294ede7e5e7d9befbb2225

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

LOG: [clangd] Use function pointer instead of function_ref to avoid GCC 5 bug

With GCC <6 constructing a function_ref from a free function reference
leads to it referencing a temporary function pointer. If the lifetime of
that temporary is insufficient it can crash.

Fixes https://github.com/clangd/clangd/issues/800

Added: 


Modified: 
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d830190bfdfdb..cfc46131496d1 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -279,11 +279,10 @@ bool 
DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
   struct CDBFile {
 CachedFile *File;
 // Wrapper for {Fixed,JSON}CompilationDatabase::loadFromBuffer.
-llvm::function_ref(
+std::unique_ptr (*Parser)(
 PathRef,
 /*Data*/ llvm::StringRef,
-/*ErrorMsg*/ std::string &)>
-Parser;
+/*ErrorMsg*/ std::string &);
   };
   for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
 CDBFile{&BuildCompileCommandsJson, parseJSON},



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


[PATCH] D106863: Allow #pragma float_control(push|pop) within a language linkage specification

2021-07-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: mibintc, rjmccall, erichkeane, kbsmith1.
aaron.ballman requested review of this revision.
Herald added a project: clang.

Currently, we prohibit this pragma from appearing within a language linkage 
specification, but this is useful functionality that is supported by MSVC 
(which is where we inherited this feature from). This patch allows you to use 
the pragma within an extern "C" {} (etc) block.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106863

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Parser/fp-floatcontrol-syntax.cpp


Index: clang/test/Parser/fp-floatcontrol-syntax.cpp
===
--- clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -5,15 +5,35 @@
   return a;
 }
 
+// Ok, at namespace scope.
+namespace foo {
+#pragma float_control(push)
+#pragma float_control(pop)
+}
+
+// Ok, within a language linkage specification.
+extern "C" {
+#pragma float_control(push)
+#pragma float_control(pop)
+}
+
+// Same.
+extern "C++" {
+#pragma float_control(push)
+#pragma float_control(pop)
+}
+
 #ifdef CHECK_ERROR
+// Ok at file scope.
 #pragma float_control(push)
 #pragma float_control(pop)
 #pragma float_control(precise, on, push)
 void check_stack() {
-#pragma float_control(push)   // expected-error {{can only 
appear at file scope or namespace scope}}
-#pragma float_control(pop)// expected-error {{can only 
appear at file scope or namespace scope}}
-#pragma float_control(precise, on, push)  // expected-error {{can only 
appear at file scope or namespace scope}}
-#pragma float_control(except, on, push)   // expected-error {{can only 
appear at file scope or namespace scope}}
+  // Not okay within a function declaration.
+#pragma float_control(push)   // expected-error {{can only 
appear at file or namespace scope or within a language linkage specification}}
+#pragma float_control(pop)// expected-error {{can only 
appear at file or namespace scope or within a language linkage specification}}
+#pragma float_control(precise, on, push)  // expected-error {{can only 
appear at file or namespace scope or within a language linkage specification}}
+#pragma float_control(except, on, push)   // expected-error {{can only 
appear at file or namespace scope or within a language linkage specification}}
 #pragma float_control(except, on, push, junk) // expected-error 
{{float_control is malformed}}
   return;
 }
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -475,8 +475,10 @@
PragmaFloatControlKind Value) {
   FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
   if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
-  !(CurContext->isTranslationUnit()) && !CurContext->isNamespace()) {
-// Push and pop can only occur at file or namespace scope.
+  !(CurContext->isTranslationUnit()) && !CurContext->isNamespace() &&
+  !isa(CurContext)) {
+// Push and pop can only occur at file or namespace scope, or within a
+// language linkage declaration.
 Diag(Loc, diag::err_pragma_fc_pp_scope);
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -933,7 +933,8 @@
 def warn_pragma_pop_failed : Warning<"#pragma %0(pop, ...) failed: %1">,
   InGroup;
 def err_pragma_fc_pp_scope : Error<
-  "'#pragma float_control push/pop' can only appear at file scope or namespace 
scope">;
+  "'#pragma float_control push/pop' can only appear at file or namespace scope 
"
+  "or within a language linkage specification">;
 def err_pragma_fc_noprecise_requires_nofenv : Error<
   "'#pragma float_control(precise, off)' is illegal when fenv_access is 
enabled">;
 def err_pragma_fc_except_requires_precise : Error<
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -3544,12 +3544,14 @@
 
 The ``#pragma float_control`` pragma allows precise floating-point
 semantics and floating-point exception behavior to be specified
-for a section of the source code. This pragma can only appear at file scope or
-at the start of a compound statement (excluding comments). When using within a
-compound statement, the pragma is active within the scope of the compound
-statement.  This pragma is modeled after a Microsoft pragma with the
-same spelling and syntax.  For pragm

[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables with enum judgement

2021-07-27 Thread gehry via Phabricator via cfe-commits
Sockke added a comment.

Any thoughts?  : )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106431

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


[PATCH] D106789: [clang][Driver] Expose driver mode detection logic

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



Comment at: clang/include/clang/Driver/Driver.h:643
 
+/// Returns the driver mode option's value, i.e. `X` in `--driver-mode=X`. If 
\p
+/// Args doesn't mention one explicitly, tries to deduce from `ProgName`.

List the "good" values, and explicitly mention that it need not be one?



Comment at: clang/lib/Driver/Driver.cpp:1018
   // how other options are parsed.
-  ParseDriverMode(ClangExecutable, ArgList.slice(1));
+  setDriverMode(getDriverMode(ClangExecutable, ArgList.slice(1)));
 

can we do this only if we have a value to set to, and remove the "" special 
case?



Comment at: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp:149
 TmpArgv.push_back(S.c_str());
+  ClangCLMode = !TmpArgv.empty() &&
+driver::getDriverMode(TmpArgv.front(),

could consider adding isClangCL(StringRef)... up to you


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106789

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


[PATCH] D106864: [clang][cli] Expose -fno-cxx-modules in cc1

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
Herald added a subscriber: dang.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For some use-cases, it might be useful to be able to turn off modules for C++ 
in `-cc1`. (The feature is implied by `-std=C++20`.)

This patch exposes the `-fno-cxx-modules` option in `-cc1`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106864

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/cxx20-disable.cpp


Index: clang/test/Modules/cxx20-disable.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-disable.cpp
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+
+export module Foo;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3150,8 +3150,6 @@
   Opts.HexFloats = Std.hasHexFloats();
   Opts.ImplicitInt = Std.hasImplicitInt();
 
-  Opts.CPlusPlusModules = Opts.CPlusPlus20;
-
   // Set OpenCL Version.
   Opts.OpenCL = Std.isOpenCL();
   if (LangStd == LangStandard::lang_opencl10)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -467,7 +467,6 @@
 defvar hip = LangOpts<"HIP">;
 defvar gnu_mode = LangOpts<"GNUMode">;
 defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
-defvar cpp_modules = LangOpts<"CPlusPlusModules">;
 
 defvar std = !strconcat("LangStandard::getLangStandardForKind(", 
lang_std.KeyPath, ")");
 
@@ -1329,8 +1328,11 @@
 defm async_exceptions: BoolFOption<"async-exceptions",
   LangOpts<"EHAsynch">, DefaultFalse,
   PosFlag, 
NegFlag>;
-def fcxx_modules : Flag <["-"], "fcxx-modules">, Group,
-  Flags<[NoXarchOption]>;
+defm cxx_modules : BoolFOption<"cxx-modules",
+  LangOpts<"CPlusPlusModules">, Default,
+  NegFlag, PosFlag,
+  BothFlags<[NoXarchOption], " modules for C++">>,
+  ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;
 def fdebug_pass_structure : Flag<["-"], "fdebug-pass-structure">, 
Group;
 def fdepfile_entry : Joined<["-"], "fdepfile-entry=">,
@@ -2146,7 +2148,7 @@
   Flags<[CC1Option]>, HelpText<"Enable support for the C++ Modules TS">,
   MarshallingInfoFlag>;
 defm modules : BoolFOption<"modules",
-  LangOpts<"Modules">, Default,
+  LangOpts<"Modules">, Default,
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CoreOption]>>;
 def fmodule_maps : Flag <["-"], "fmodule-maps">, Flags<[CoreOption]>, 
Alias;
@@ -2205,8 +2207,6 @@
   Flags<[CoreOption, NoXarchOption]>;
 def fno_common : Flag<["-"], "fno-common">, Group, Flags<[CC1Option]>,
 HelpText<"Compile common globals like normal definitions">;
-def fno_cxx_modules : Flag <["-"], "fno-cxx-modules">, Group,
-  Flags<[NoXarchOption]>;
 defm digraphs : BoolFOption<"digraphs",
   LangOpts<"Digraphs">, Default,
   PosFlag', 
'<%', '%>', '%:', '%:%:' (default)">,
@@ -5283,7 +5283,7 @@
   HelpText<"Enforce name visibility rules across submodules of the same "
"top-level module.">,
   MarshallingInfoFlag>,
-  ImpliedByAnyOf<[fmodules_ts.KeyPath, cpp_modules.KeyPath]>;
+  ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>;
 def fmodules_codegen :
   Flag<["-"], "fmodules-codegen">,
   HelpText<"Generate code for uses of this module that assumes an explicit "


Index: clang/test/Modules/cxx20-disable.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-disable.cpp
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+
+export module Foo;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3150,8 +3150,6 @@
   Opts.HexFloats = Std.hasHexFloats();
   Opts.ImplicitInt = Std.hasImplicitInt();
 
-  Opts.CPlusPlusModules = Opts.CPlusPlus20;
-
   // Set OpenCL Version.
   Opts.OpenCL = Std.isOpenCL();
   if (LangStd == LangStandard::lang_opencl10)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -467,7 +467,6 @@
 defvar hip = LangOpts<"HIP">;
 defvar gnu_mode = LangOpts<"GNUMode">;
 defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
-defvar cpp_modules = LangOpts<"CPlusPlusModules">;
 
 defvar std = !strconcat("LangStandard::getLangStandardForKind(", lang_

[PATCH] D106864: [clang][cli] Expose -fno-cxx-modules in cc1

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/Modules/cxx20-disable.cpp:2
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+

I'm not sure how to best test this. Checking the error messages is not that 
useful, since they don't make the intent here any clearer:

```
/llvm-project/clang/test/Modules/cxx20-disable.cpp:4:8: error: expected 
template
export module Foo;
   ^
/llvm-project/clang/test/Modules/cxx20-disable.cpp:4:8: error: unknown 
type name 'module'
2 errors generated.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106864

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


[PATCH] D106794: Revert "Revert "[clangd] Canonicalize compile flags before applying edits""

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



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:208
+  !OriginalArgs.empty() &&
+  driver::getDriverMode(OriginalArgs[0], OriginalArgs).equals("cl");
+  // ParseArgs propagates missig arg/opt counts on error, but preserves

makeArrayRef(OriginalArgs).slice(1)?



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:213
+  auto ArgList = OptTable.ParseArgs(
+  OriginalArgs, IgnoredCount, IgnoredCount, /*FlagsToInclude=*/0,
+  /*FlagsToExclude=*/IsCLMode ? 0 : driver::options::CLOption);

include should be IsCLMode ? (CLOption | CoreOption) : /*everything*/0?



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:214
+  OriginalArgs, IgnoredCount, IgnoredCount, /*FlagsToInclude=*/0,
+  /*FlagsToExclude=*/IsCLMode ? 0 : driver::options::CLOption);
+

exclude NoDriverOption | ( IsCLMode ? 0 : CLOption)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106794

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


[clang-tools-extra] e2559e5 - [clangd] Add platform triple (host & target) to version info

2021-07-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-07-27T14:25:17+02:00
New Revision: e2559e5dc62445a92a9a5344db79f78f735e1e61

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

LOG: [clangd] Add platform triple (host & target) to version info

Useful in logs to understand issues around some platforms we don't have much
experience with (e.g. m1, mingw)

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/Features.cpp
clang-tools-extra/clangd/Features.h
clang-tools-extra/clangd/index/remote/Client.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 9214bcbe66bca..90d6e1159750a 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -619,9 +619,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
 
   llvm::json::Object Result{
   {{"serverInfo",
-llvm::json::Object{{"name", "clangd"},
-   {"version", llvm::formatv("{0} {1}", 
versionString(),
- featureString())}}},
+llvm::json::Object{
+{"name", "clangd"},
+{"version", llvm::formatv("{0} {1} {2}", versionString(),
+  featureString(), platformString())}}},
{"capabilities", std::move(ServerCaps)}}};
   if (Opts.Encoding)
 Result["offsetEncoding"] = *Opts.Encoding;

diff  --git a/clang-tools-extra/clangd/Features.cpp 
b/clang-tools-extra/clangd/Features.cpp
index 4ec03ea84bfb4..d7fba42a3408c 100644
--- a/clang-tools-extra/clangd/Features.cpp
+++ b/clang-tools-extra/clangd/Features.cpp
@@ -9,12 +9,26 @@
 #include "Features.h"
 #include "clang/Basic/Version.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/Host.h"
 
 namespace clang {
 namespace clangd {
 
 std::string versionString() { return clang::getClangToolFullVersion("clangd"); 
}
 
+std::string platformString() {
+  static std::string PlatformString = []() {
+std::string Host = llvm::sys::getProcessTriple();
+std::string Target = llvm::sys::getDefaultTargetTriple();
+if (Host != Target) {
+  Host += "; target=";
+  Host += Target;
+}
+return Host;
+  }();
+  return PlatformString;
+}
+
 std::string featureString() {
   return
 #if defined(_WIN32)

diff  --git a/clang-tools-extra/clangd/Features.h 
b/clang-tools-extra/clangd/Features.h
index 6fa3618578632..1723eb37b3bc1 100644
--- a/clang-tools-extra/clangd/Features.h
+++ b/clang-tools-extra/clangd/Features.h
@@ -19,6 +19,10 @@ namespace clangd {
 // Returns a version string for clangd, e.g. "clangd 10.0.0"
 std::string versionString();
 
+// Returns the platform triple for clangd, e.g. "x86_64-pc-linux-gnu"
+// May include both the host and target triple if they 
diff er.
+std::string platformString();
+
 // Returns a string describing the compile-time configuration.
 // e.g. mac+debug+asan+grpc
 std::string featureString();

diff  --git a/clang-tools-extra/clangd/index/remote/Client.cpp 
b/clang-tools-extra/clangd/index/remote/Client.cpp
index ac6b7c0c829ff..8db2287654600 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -74,6 +74,7 @@ class IndexClient : public clangd::SymbolIndex {
 grpc::ClientContext Context;
 Context.AddMetadata("version", versionString());
 Context.AddMetadata("features", featureString());
+Context.AddMetadata("platform", platformString());
 std::chrono::system_clock::time_point StartTime =
 std::chrono::system_clock::now();
 auto Deadline = StartTime + DeadlineWaitingTime;

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 8db52c65061c8..c40f98f5a4eeb 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -679,7 +679,8 @@ int main(int argc, char *argv[]) {
   llvm::sys::SetInterruptFunction(&requestShutdown);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
 OS << versionString() << "\n"
-   << "Features: " << featureString() << "\n";
+   << "Features: " << featureString() << "\n"
+   << "Platform: " << platformString() << "\n";
   });
   const char *FlagsEnvVar = "CLANGD_FLAGS";
   const char *Overview =



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


[PATCH] D105681: [clangd] Add platform triple (host & target) to version info

2021-07-27 Thread Sam McCall 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 rGe2559e5dc624: [clangd] Add platform triple (host & 
target) to version info (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105681

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/Features.cpp
  clang-tools-extra/clangd/Features.h
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -679,7 +679,8 @@
   llvm::sys::SetInterruptFunction(&requestShutdown);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
 OS << versionString() << "\n"
-   << "Features: " << featureString() << "\n";
+   << "Features: " << featureString() << "\n"
+   << "Platform: " << platformString() << "\n";
   });
   const char *FlagsEnvVar = "CLANGD_FLAGS";
   const char *Overview =
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -74,6 +74,7 @@
 grpc::ClientContext Context;
 Context.AddMetadata("version", versionString());
 Context.AddMetadata("features", featureString());
+Context.AddMetadata("platform", platformString());
 std::chrono::system_clock::time_point StartTime =
 std::chrono::system_clock::now();
 auto Deadline = StartTime + DeadlineWaitingTime;
Index: clang-tools-extra/clangd/Features.h
===
--- clang-tools-extra/clangd/Features.h
+++ clang-tools-extra/clangd/Features.h
@@ -19,6 +19,10 @@
 // Returns a version string for clangd, e.g. "clangd 10.0.0"
 std::string versionString();
 
+// Returns the platform triple for clangd, e.g. "x86_64-pc-linux-gnu"
+// May include both the host and target triple if they differ.
+std::string platformString();
+
 // Returns a string describing the compile-time configuration.
 // e.g. mac+debug+asan+grpc
 std::string featureString();
Index: clang-tools-extra/clangd/Features.cpp
===
--- clang-tools-extra/clangd/Features.cpp
+++ clang-tools-extra/clangd/Features.cpp
@@ -9,12 +9,26 @@
 #include "Features.h"
 #include "clang/Basic/Version.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/Host.h"
 
 namespace clang {
 namespace clangd {
 
 std::string versionString() { return clang::getClangToolFullVersion("clangd"); 
}
 
+std::string platformString() {
+  static std::string PlatformString = []() {
+std::string Host = llvm::sys::getProcessTriple();
+std::string Target = llvm::sys::getDefaultTargetTriple();
+if (Host != Target) {
+  Host += "; target=";
+  Host += Target;
+}
+return Host;
+  }();
+  return PlatformString;
+}
+
 std::string featureString() {
   return
 #if defined(_WIN32)
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -619,9 +619,10 @@
 
   llvm::json::Object Result{
   {{"serverInfo",
-llvm::json::Object{{"name", "clangd"},
-   {"version", llvm::formatv("{0} {1}", 
versionString(),
- featureString())}}},
+llvm::json::Object{
+{"name", "clangd"},
+{"version", llvm::formatv("{0} {1} {2}", versionString(),
+  featureString(), platformString())}}},
{"capabilities", std::move(ServerCaps)}}};
   if (Opts.Encoding)
 Result["offsetEncoding"] = *Opts.Encoding;


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -679,7 +679,8 @@
   llvm::sys::SetInterruptFunction(&requestShutdown);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
 OS << versionString() << "\n"
-   << "Features: " << featureString() << "\n";
+   << "Features: " << featureString() << "\n"
+   << "Platform: " << platformString() << "\n";
   });
   const char *FlagsEnvVar = "CLANGD_FLAGS";
   const char *Overview =
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -74,6 +

[PATCH] D106867: [scan-build] Fix a typo in the manual page: s/contraint/constraint.

2021-07-27 Thread Frederic Cambus via Phabricator via cfe-commits
fcambus created this revision.
fcambus added a reviewer: mgorny.
fcambus requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix a typo in the scan-build manual page: s/contraint/constraint.

  

While there, update hardcoded Clang version from 3.5 to 13.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106867

Files:
  clang/tools/scan-build/man/scan-build.1


Index: clang/tools/scan-build/man/scan-build.1
===
--- clang/tools/scan-build/man/scan-build.1
+++ clang/tools/scan-build/man/scan-build.1
@@ -2,9 +2,9 @@
 .\" See https://llvm.org/LICENSE.txt for license information.
 .\" SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 .\" $Id$
-.Dd May 25, 2012
+.Dd Jul 27, 2021
 .Dt SCAN-BUILD 1
-.Os "clang" "3.5"
+.Os "clang" "13"
 .Sh NAME
 .Nm scan-build
 .Nd Clang static analyzer
@@ -110,7 +110,7 @@
 .It Fl V , Fl Fl view
 View analysis results in a web browser when the build completes.
 .It Fl constraints Op Ar model
-Specify the contraint engine used by the analyzer.  By default the
+Specify the constraint engine used by the analyzer.  By default the
 .Ql range
 model is used.  Specifying
 .Ql basic


Index: clang/tools/scan-build/man/scan-build.1
===
--- clang/tools/scan-build/man/scan-build.1
+++ clang/tools/scan-build/man/scan-build.1
@@ -2,9 +2,9 @@
 .\" See https://llvm.org/LICENSE.txt for license information.
 .\" SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 .\" $Id$
-.Dd May 25, 2012
+.Dd Jul 27, 2021
 .Dt SCAN-BUILD 1
-.Os "clang" "3.5"
+.Os "clang" "13"
 .Sh NAME
 .Nm scan-build
 .Nd Clang static analyzer
@@ -110,7 +110,7 @@
 .It Fl V , Fl Fl view
 View analysis results in a web browser when the build completes.
 .It Fl constraints Op Ar model
-Specify the contraint engine used by the analyzer.  By default the
+Specify the constraint engine used by the analyzer.  By default the
 .Ql range
 model is used.  Specifying
 .Ql basic
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ce90b60 - [clang][Driver] Expose driver mode detection logic

2021-07-27 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-27T14:49:53+02:00
New Revision: ce90b60bd09da41c52006374a4715425122572ab

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

LOG: [clang][Driver] Expose driver mode detection logic

Also use it in other places that performed it on their own.

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

Added: 


Modified: 
clang/include/clang/Driver/Driver.h
clang/lib/Driver/Driver.cpp
clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
clang/tools/driver/driver.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 85810f0b568b6..da7e8386a151c 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -380,12 +380,6 @@ class Driver {
   /// to determine if an error occurred.
   Compilation *BuildCompilation(ArrayRef Args);
 
-  /// @name Driver Steps
-  /// @{
-
-  /// ParseDriverMode - Look for and handle the driver mode option in Args.
-  void ParseDriverMode(StringRef ProgramName, ArrayRef Args);
-
   /// ParseArgStrings - Parse the given list of strings into an
   /// ArgList.
   llvm::opt::InputArgList ParseArgStrings(ArrayRef Args,
@@ -584,9 +578,9 @@ class Driver {
   /// \returns true, if error occurred while reading.
   bool readConfigFile(StringRef FileName);
 
-  /// Set the driver mode (cl, gcc, etc) from an option string of the form
-  /// --driver-mode=.
-  void setDriverModeFromOption(StringRef Opt);
+  /// Set the driver mode (cl, gcc, etc) from the value of the `--driver-mode`
+  /// option.
+  void setDriverMode(StringRef DriverModeValue);
 
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
@@ -646,6 +640,16 @@ bool isOptimizationLevelFast(const llvm::opt::ArgList 
&Args);
 /// \return True if the argument combination will end up generating remarks.
 bool willEmitRemarks(const llvm::opt::ArgList &Args);
 
+/// Returns the driver mode option's value, i.e. `X` in `--driver-mode=X`. If 
\p
+/// Args doesn't mention one explicitly, tries to deduce from `ProgName`.
+/// Returns empty on failure.
+/// Common values are "gcc", "g++", "cpp", "cl" and "flang". Returned value 
need
+/// not be one of these.
+llvm::StringRef getDriverMode(StringRef ProgName, ArrayRef Args);
+
+/// Checks whether the value produced by getDriverMode is for CL mode.
+bool IsClangCL(StringRef DriverMode);
+
 } // end namespace driver
 } // end namespace clang
 

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a06eb6ccc1b3c..5c323cb6ea23e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -63,6 +63,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
@@ -168,28 +169,9 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
   ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
-void Driver::ParseDriverMode(StringRef ProgramName,
- ArrayRef Args) {
-  if (ClangNameParts.isEmpty())
-ClangNameParts = ToolChain::getTargetAndModeFromProgramName(ProgramName);
-  setDriverModeFromOption(ClangNameParts.DriverMode);
-
-  for (const char *ArgPtr : Args) {
-// Ignore nullptrs, they are the response file's EOL markers.
-if (ArgPtr == nullptr)
-  continue;
-const StringRef Arg = ArgPtr;
-setDriverModeFromOption(Arg);
-  }
-}
-
-void Driver::setDriverModeFromOption(StringRef Opt) {
-  const std::string OptName =
+void Driver::setDriverMode(StringRef Value) {
+  static const std::string OptName =
   getOpts().getOption(options::OPT_driver_mode).getPrefixedName();
-  if (!Opt.startswith(OptName))
-return;
-  StringRef Value = Opt.drop_front(OptName.size());
-
   if (auto M = llvm::StringSwitch>(Value)
.Case("gcc", GCCMode)
.Case("g++", GXXMode)
@@ -1031,7 +1013,10 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   // We look for the driver mode option early, because the mode can affect
   // how other options are parsed.
-  ParseDriverMode(ClangExecutable, ArgList.slice(1));
+
+  auto DriverMode = getDriverMode(ClangExecutable, ArgList.slice(1));
+  if (!DriverMode.empty())
+setDriverMode(DriverMode);
 
   // FIXME: What are we going to do with -V and -b?
 
@@ -5573,3 +5558,21 @@ bool clang::driver::willEmitRemarks(const ArgList &Args) 
{
 return true;
   return false;
 }
+
+llvm::StringRef clang::driver::getDriverMode(StringRef ProgName,
+   

[clang-tools-extra] ab714ba - Revert "Revert "[clangd] Canonicalize compile flags before applying edits""

2021-07-27 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-27T14:49:53+02:00
New Revision: ab714ba056c14bce00ab67cc10e34678f9d77b5a

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

LOG: Revert "Revert "[clangd] Canonicalize compile flags before applying edits""

Set driver mode before parsing arglist.

Depends on D106789.

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index ffc66303c9fc4..ec0e2160abbad 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,11 +9,17 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/ToolChain.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -188,11 +194,43 @@ CommandMangler CommandMangler::detect() {
   return Result;
 }
 
-CommandMangler CommandMangler::forTests() {
-  return CommandMangler();
-}
+CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
 void CommandMangler::adjust(std::vector &Cmd) const {
+  trace::Span S("AdjustCompileFlags");
+  auto &OptTable = clang::driver::getDriverOptTable();
+  // OriginalArgs needs to outlive ArgList.
+  llvm::SmallVector OriginalArgs;
+  OriginalArgs.reserve(Cmd.size());
+  for (const auto &S : Cmd)
+OriginalArgs.push_back(S.c_str());
+  bool IsCLMode =
+  !OriginalArgs.empty() &&
+  driver::IsClangCL(driver::getDriverMode(
+  OriginalArgs[0], llvm::makeArrayRef(OriginalArgs).slice(1)));
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // everything it could parse in ArgList. So we just ignore those counts.
+  unsigned IgnoredCount;
+  auto ArgList = OptTable.ParseArgs(
+  OriginalArgs, IgnoredCount, IgnoredCount,
+  /*FlagsToInclude=*/
+  IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
+   : /*everything*/ 0,
+  /*FlagsToExclude=*/driver::options::NoDriverOption |
+  (IsCLMode ? 0 : driver::options::CLOption));
+
+  // Move the inputs to the end, separated via `--` from flags. This ensures
+  // modifications done in the following steps apply in more cases (like 
setting
+  // -x, which only affects inputs that come after it).
+  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
+// In theory there might be more than one input, but clangd can't deal with
+// them anyway.
+if (auto *Input = ArgList.getLastArg(driver::options::OPT_INPUT)) {
+  Cmd.insert(Cmd.end(), {"--", Input->getAsString(ArgList)});
+  Cmd.erase(Cmd.begin() + Input->getIndex());
+}
+  }
+
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);
 

diff  --git 
a/clang-tools-extra/clangd/test/did-change-configuration-params.test 
b/clang-tools-extra/clangd/test/did-change-configuration-params.test
index 19d41d0812e23..e90e26c0d3a7a 100644
--- a/clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ b/clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c foo.c -Wall -Werror
+# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index de8ff2b4a14e1..79da2f059a8c2 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,8 +133,9 @@ TEST_F(BackgroundIndexTest, Config) {
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back(
-  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
+  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
+Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
+  });
 if (P.endswith("baz.cpp"))

[clang-tools-extra] 259e365 - Revert "Revert "[clangd] Adjust compile flags to contain only the requested file as input""

2021-07-27 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-27T14:49:53+02:00
New Revision: 259e365deaa3a6920b30f49e3d03d3508f1d4900

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

LOG: Revert "Revert "[clangd] Adjust compile flags to contain only the 
requested file as input""

This reverts commit 04e21fbc44c145d5599ef8db9aaf66b159107f33.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index ec0e2160abbad..032bf7354d770 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -196,7 +196,8 @@ CommandMangler CommandMangler::detect() {
 
 CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
-void CommandMangler::adjust(std::vector &Cmd) const {
+void CommandMangler::adjust(std::vector &Cmd,
+llvm::StringRef File) const {
   trace::Span S("AdjustCompileFlags");
   auto &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
@@ -211,8 +212,10 @@ void CommandMangler::adjust(std::vector &Cmd) 
const {
   // ParseArgs propagates missig arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
+  // Drop the executable name, as ParseArgs doesn't expect it. This means
+  // indices are actually of by one between ArgList and OriginalArgs.
   auto ArgList = OptTable.ParseArgs(
-  OriginalArgs, IgnoredCount, IgnoredCount,
+  llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, 
IgnoredCount,
   /*FlagsToInclude=*/
   IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
: /*everything*/ 0,
@@ -223,12 +226,17 @@ void CommandMangler::adjust(std::vector 
&Cmd) const {
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// In theory there might be more than one input, but clangd can't deal with
-// them anyway.
-if (auto *Input = ArgList.getLastArg(driver::options::OPT_INPUT)) {
-  Cmd.insert(Cmd.end(), {"--", Input->getAsString(ArgList)});
-  Cmd.erase(Cmd.begin() + Input->getIndex());
-}
+// Drop all the inputs and only add one for the current file.
+llvm::SmallVector IndicesToDrop;
+for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
+  IndicesToDrop.push_back(Input->getIndex());
+llvm::sort(IndicesToDrop);
+llvm::for_each(llvm::reverse(IndicesToDrop),
+   // +1 to account for the executable name in Cmd[0] that
+   // doesn't exist in ArgList.
+   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
+Cmd.push_back("--");
+Cmd.push_back(File.str());
   }
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
@@ -278,7 +286,7 @@ CommandMangler::operator 
clang::tooling::ArgumentsAdjuster() && {
   return [Mangler = std::make_shared(std::move(*this))](
  const std::vector &Args, llvm::StringRef File) {
 auto Result = Args;
-Mangler->adjust(Result);
+Mangler->adjust(Result, File);
 return Result;
   };
 }

diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 759472413fdaf..50c1a3571ec42 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -12,6 +12,7 @@
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include 
 #include 
 #include 
@@ -46,7 +47,7 @@ struct CommandMangler {
   //  - on mac, find clang and isysroot by querying the `xcrun` launcher
   static CommandMangler detect();
 
-  void adjust(std::vector &Cmd) const;
+  void adjust(std::vector &Cmd, llvm::StringRef File) const;
   explicit operator clang::tooling::ArgumentsAdjuster() &&;
 
 private:

diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index cfc46131496d1..85b0826e6d8b0 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -763,7 +763,7 @@ OverlayCDB::getCompileCommand

[PATCH] D106789: [clang][Driver] Expose driver mode detection logic

2021-07-27 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.
kadircet marked 3 inline comments as done.
Closed by commit rGce90b60bd09d: [clang][Driver] Expose driver mode detection 
logic (authored by kadircet).
Herald added a reviewer: sscalpone.

Changed prior to commit:
  https://reviews.llvm.org/D106789?vs=361656&id=362000#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106789

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -360,7 +360,6 @@
 return 1;
 
   llvm::InitializeAllTargets();
-  auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(Args[0]);
 
   llvm::BumpPtrAllocator A;
   llvm::StringSaver Saver(A);
@@ -372,13 +371,8 @@
   // have to manually search for a --driver-mode=cl argument the hard way.
   // Finally, our -cc1 tools don't care which tokenization mode we use because
   // response files written by clang will tokenize the same way in either mode.
-  bool ClangCLMode = false;
-  if (StringRef(TargetAndMode.DriverMode).equals("--driver-mode=cl") ||
-  llvm::find_if(Args, [](const char *F) {
-return F && strcmp(F, "--driver-mode=cl") == 0;
-  }) != Args.end()) {
-ClangCLMode = true;
-  }
+  bool ClangCLMode =
+  IsClangCL(getDriverMode(Args[0], llvm::makeArrayRef(Args).slice(1)));
   enum { Default, POSIX, Windows } RSPQuoting = Default;
   for (const char *F : Args) {
 if (strcmp(F, "--rsp-quoting=posix") == 0)
@@ -490,6 +484,7 @@
 
   Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
   SetInstallDir(Args, TheDriver, CanonicalPrefixes);
+  auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(Args[0]);
   TheDriver.setTargetAndMode(TargetAndMode);
 
   insertTargetAndModeArgs(TargetAndMode, Args, SavedStrings);
Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -43,9 +43,11 @@
 //===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Types.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringExtras.h"
@@ -134,8 +136,7 @@
   bool ClangCLMode;
 
   TransferableCommand(CompileCommand C)
-  : Cmd(std::move(C)), Type(guessType(Cmd.Filename)),
-ClangCLMode(checkIsCLMode(Cmd.CommandLine)) {
+  : Cmd(std::move(C)), Type(guessType(Cmd.Filename)) {
 std::vector OldArgs = std::move(Cmd.CommandLine);
 Cmd.CommandLine.clear();
 
@@ -145,6 +146,9 @@
   SmallVector TmpArgv;
   for (const std::string &S : OldArgs)
 TmpArgv.push_back(S.c_str());
+  ClangCLMode = !TmpArgv.empty() &&
+driver::IsClangCL(driver::getDriverMode(
+TmpArgv.front(), llvm::makeArrayRef(TmpArgv).slice(1)));
   ArgList = {TmpArgv.begin(), TmpArgv.end()};
 }
 
@@ -246,19 +250,6 @@
   }
 
 private:
-  // Determine whether the given command line is intended for the CL driver.
-  static bool checkIsCLMode(ArrayRef CmdLine) {
-// First look for --driver-mode.
-for (StringRef S : llvm::reverse(CmdLine)) {
-  if (S.consume_front("--driver-mode="))
-return S == "cl";
-}
-
-// Otherwise just check the clang executable file name.
-return !CmdLine.empty() &&
-   llvm::sys::path::stem(CmdLine.front()).endswith_insensitive("cl");
-  }
-
   // Map the language from the --std flag to that of the -x flag.
   static types::ID toType(Language Lang) {
 switch (Lang) {
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -63,6 +63,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
@@ -168,28 +169,9 @@
   ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
-void Driver::ParseDriverMode(StringRef ProgramName,
- ArrayRef Args) {
-  if (ClangNameParts.isEmpty())
-ClangNameParts = ToolChain::getTargetAndModeFromProgramName(ProgramName);
-  setDriverModeFromOption(ClangNamePart

[PATCH] D106794: Revert "Revert "[clangd] Canonicalize compile flags before applying edits""

2021-07-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kadircet marked 3 inline comments as done.
Closed by commit rGab714ba056c1: Revert "Revert "[clangd] 
Canonicalize compile flags before applying edits"" (authored by 
kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D106794?vs=361657&id=362001#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106794

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -11,6 +11,8 @@
 #include "TestFS.h"
 #include "support/Context.h"
 
+#include "clang/Tooling/ArgumentsAdjusters.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FileSystem.h"
@@ -165,13 +167,15 @@
 for (char &C : Arg)
   C = llvm::toUpper(C);
 });
-Cfg.CompileFlags.Edits.push_back(
-[](std::vector &Argv) { Argv.push_back("--hello"); });
+Cfg.CompileFlags.Edits.push_back([](std::vector &Argv) {
+  Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
+});
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
 Mangler.adjust(Cmd);
   }
-  // Edits are applied in given order and before other mangling.
-  EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello"));
+  // Edits are applied in given order and before other mangling and they always
+  // go before filename.
+  EXPECT_THAT(Cmd, ElementsAre(_, "--hello", "--", "FOO.CC"));
 }
 
 static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
@@ -342,6 +346,27 @@
   EXPECT_EQ(Expected, printArgv(Args));
 }
 
+TEST(CommandMangler, InputsAfterDashDash) {
+  const auto Mangler = CommandMangler::forTests();
+  {
+std::vector Args = {"clang", "/Users/foo.cc"};
+Mangler.adjust(Args);
+EXPECT_THAT(llvm::makeArrayRef(Args).take_back(2),
+ElementsAre("--", "/Users/foo.cc"));
+EXPECT_THAT(llvm::makeArrayRef(Args).drop_back(2),
+Not(Contains("/Users/foo.cc")));
+  }
+  // In CL mode /U triggers an undef operation, hence `/Users/foo.cc` shouldn't
+  // be interpreted as a file.
+  {
+std::vector Args = {"clang", "--driver-mode=cl", "bar.cc",
+ "/Users/foo.cc"};
+Mangler.adjust(Args);
+EXPECT_THAT(llvm::makeArrayRef(Args).take_back(2),
+ElementsAre("--", "bar.cc"));
+EXPECT_THAT(llvm::makeArrayRef(Args).drop_back(2), Not(Contains("bar.cc")));
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,8 +133,9 @@
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back(
-  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
+  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
+Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
+  });
 if (P.endswith("baz.cpp"))
   C.Index.Background = Config::BackgroundPolicy::Skip;
 return Context::current().derive(Config::Key, std::move(C));
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c foo.c -Wall -Werror
+# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,11 +9,17 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/ToolChain.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallV

[PATCH] D106870: [OpenMP] Multi architecture compilation support

2021-07-27 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: jdoerfert, yaxunl, JonChesterfield, RaviNarayanaswamy.
Herald added subscribers: kerbowa, pengfei, guansong, nhaehnle, jvesely.
saiislam requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

Multiple offloading targets can now be specified in the command
line. An instance of toolchain is created for each unique
combination of Target Triple and Target GPU. Device runtime has
been modified to support binaries containing multiple images,
each for a different target.
Data structure "__tgt_image_info" defined in
"llvm-project/openmp/libomptarget/include/omptarget.h" is used
to pass requirements of each image. E.g. GPU name like gfx906,
sm35, etc are the requirements of the image, which is produced
by clang-offload-wrapper and read by device RTL.

Example:

  clang  -O2  -target x86_64-pc-linux-gnu -fopenmp \
-fopenmp-targets=amdgcn-amd-amdhsa,amdgcn-amd-amdhsa \
-Xopenmp-target=amdgcn-amd-amdhsa -march=gfx906 \
-Xopenmp-target=amdgcn-amd-amdhsa -march=gfx908 \
   helloworld.c -o helloworld


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106870

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Action.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/amdgpu-openmp-system-arch-fail.c
  clang/test/Driver/amdgpu-openmp-toolchain.c
  clang/test/Driver/hip-rdc-device-only.hip
  clang/test/Driver/hip-toolchain-rdc-separate.hip
  clang/test/Driver/openmp-offload-multi.c
  clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interface.cpp
  openmp/libomptarget/src/rtl.cpp

Index: openmp/libomptarget/src/rtl.cpp
===
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 // List of all plugins that can support offloading.
 static const char *RTLNames[] = {
@@ -288,18 +289,131 @@
  flags, RequiresFlags);
 }
 
+/// Query runtime capabilities of this system by calling offload-arch -c
+/// offload_arch_output_buffer is persistant storage returned by this
+/// __tgt_get_active_offload_env.
+static void
+__tgt_get_active_offload_env(__tgt_active_offload_env *active_env,
+ char *offload_arch_output_buffer,
+ size_t offload_arch_output_buffer_size) {
+  void *handle = dlopen("libomptarget.so", RTLD_NOW);
+  if (!handle)
+DP("dlopen() failed: %s\n", dlerror());
+  char *libomptarget_dir_name = new char[PATH_MAX];
+  if (dlinfo(handle, RTLD_DI_ORIGIN, libomptarget_dir_name) == -1)
+DP("RTLD_DI_ORIGIN failed: %s\n", dlerror());
+  std::string cmd_bin;
+  cmd_bin.assign(libomptarget_dir_name).append("/../bin/amdgpu-arch");
+  struct stat stat_buffer;
+  if (stat(cmd_bin.c_str(), &stat_buffer)) {
+DP("Missing offload-arch command at %s \n", cmd_bin.c_str());
+  } else {
+// Add option to print capabilities of current system
+// cmd_bin.append(" -c");
+FILE *stream = popen(cmd_bin.c_str(), "r");
+while (fgets(offload_arch_output_buffer, offload_arch_output_buffer_size,
+ stream) != NULL)
+  ;
+pclose(stream);
+active_env->capabilities = offload_arch_output_buffer;
+size_t slen = strlen(active_env->capabilities);
+offload_arch_output_buffer[slen - 1] =
+'\0'; // terminate string before line feed
+offload_arch_output_buffer +=
+slen; // To store next value in offload_arch_output_buffer, not likely
+  }
+  delete[] libomptarget_dir_name;
+}
+
+std::vector _splitstrings(char *input, const char *sep) {
+  std::vector split_strings;
+  std::string s(input);
+  std::string delimiter(sep);
+  size_t pos = 0;
+  while ((pos = s.find(delimiter)) != std::string::npos) {
+if (pos != 0)
+  split_strings.push_back(s.substr(0, pos));
+s.erase(0, pos + delimiter.length());
+  }
+  if (s.length() > 1)
+split_strings.push_back(s.substr(0, s.length()));
+  return split_strings;
+}
+
+static bool _ImageIsCompatibleWithEnv(__tgt_image_info *img_info,
+  __tgt_active_offload_env *active_env) {
+  // get_image_info will return null if no image information was registered.
+  // If no image information, assume application built with old compiler and
+  // check each image.
+  if (!img_info)
+return true;
+
+  // Each runtime requirement for the compiled image is stored in
+  // the img_info->requirements string and is separated by __ .
+  // Each runtime capability obt

[PATCH] D106863: Allow #pragma float_control(push|pop) within a language linkage specification

2021-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Just one documentation change suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106863

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


[PATCH] D106863: Allow #pragma float_control(push|pop) within a language linkage specification

2021-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Weird, phab didn't let me save the comment on the last one... done the right 
way this time :)




Comment at: clang/docs/LanguageExtensions.rst:3549
+namespace scope, within a language linkage specification or at the start of a
+compound statement (excluding comments). When using within a compound 
statement,
+the pragma is active within the scope of the compound statement.  This pragma




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106863

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


[PATCH] D106863: Allow #pragma float_control(push|pop) within a language linkage specification

2021-07-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Doc change can be done as a part of the commit btw, otherwise this is fine to 
me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106863

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


[PATCH] D106701: [clang] Add -falign-loops=N where N is a power of 2

2021-07-27 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/test/CodeGen/RISCV/loop-alignment.ll:3-4
+; RUN: llc < %s -mtriple=riscv64 | FileCheck %s
+; RUN: llc < %s -mtriple=riscv64 -align-loops=16 | FileCheck %s 
-check-prefix=ALIGN_16
+; RUN: llc < %s -mtriple=riscv64 -align-loops=32 | FileCheck %s 
-check-prefix=ALIGN_32
+

asb wrote:
> MaskRay wrote:
> > luismarques wrote:
> > > MaskRay wrote:
> > > > jrtc27 wrote:
> > > > > MaskRay wrote:
> > > > > > jrtc27 wrote:
> > > > > > > MaskRay wrote:
> > > > > > > > luismarques wrote:
> > > > > > > > > Nit: it's a convention of the RISC-V backend codegen tests to 
> > > > > > > > > wrap the RUN lines.
> > > > > > > > only 86 columns. compiler-rt is even transiting to 100 column.
> > > > > > > compiler-rt is not the RISC-V backend :)
> > > > > > Wrapping lines here just makes the code less readable.
> > > > > That's your personal opinion, which I disagree with, and it's not 
> > > > > true if your terminal isn't wide enough. Going against existing 
> > > > > convention in the backend tests should only be done with very good 
> > > > > reason, and personal opinion is not that.
> > > > Lines longer than 80-column (in this case just 86) are pretty common 
> > > > among tests. I really hope test/CodeGen/RISCV/ can be more tolerant on 
> > > > this matter.
> > > > 
> > > > Even the Linux scripts/checkpatch.pl has increased the limit to 100 
> > > > because in many cases wrapping lines for strict 80-conformance just 
> > > > harms readability.
> > > > 
> > > > Of course I don't want to waste time arguing on this matter. So if this 
> > > > turns out to be an issue for RISC-V folks, I'll update it to save my 
> > > > time.
> > > > Of course I don't want to waste time arguing on this matter. So if this 
> > > > turns out to be an issue for RISC-V folks, I'll update it to save my 
> > > > time.
> > > 
> > > Personally, I don't particularly care. I don't know if @asb has strong 
> > > feelings about this. If you think it would be beneficial to relax this 
> > > convention please raise the issue on llvm-dev. Let's not keep discussing 
> > > this in every patch touching RISC-V :-)
> > Personally I don't even think the generic case needs to be raised on 
> > llvm-dev:) There are just so many column>80 cases in llvm/test and 
> > clang/test. Actually, If someone wants to enforce the 80-column rule more 
> > rigidly, that probably needs a discussion.
> > 
> > That said, the argument here is about a subdirectory: 
> > llvm/test/CodeGen/RISCV/ ...
> > 
> > 
> I don't have a strong view on this one to be honest. I think I've typically 
> wrapped at 80 columns for these RUN lines after being asked to, but 
> ultimately I think choosing a logical point to split has a greater impact on 
> readability than keeping it strictly to 80 columns.
FWIW I care less about argument lists extending beyond 80 columns, but I do 
think the | is a logical point at which to wrap it if you have a long line and 
keeps things more readable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106701

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


[PATCH] D105555: [RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-27 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

Commit message needs rewriting still, but the patch looks good to me


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

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


[PATCH] D106664: [clang][docs] Fix typos in Options.td and regen ClangCommandLineReference.rst.

2021-07-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

I suppose it's simple enough for me to count as second pair of eyes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106664

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


[PATCH] D106867: [scan-build] Fix a typo in the manual page: s/contraint/constraint.

2021-07-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

I suppose it's simple enough for me to count as second pair of eyes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106867

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


[PATCH] D106860: [clang][AArch64][SVE] Avoid going through memory for fixed/scalable predicate casts

2021-07-27 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2065
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
+// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate

should const be dropped now the type might change?



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2110-2129
 // Perform VLAT <-> VLST bitcast through memory.
 // TODO: since the llvm.experimental.vector.{insert,extract} intrinsics
 //   require the element types of the vectors to be the same, we
 //   need to keep this around for casting between predicates, or more
 //   generally for bitcasts between VLAT <-> VLST where the element
 //   types of the vectors are not the same, until we figure out a 
better
 //   way of doing these casts.

With the predicate casting now using the intrinsics I don't think this is 
needed any longer. Perhaps we should add an unreachable above if the element 
type doesn't match?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106860

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


[PATCH] D106870: [OpenMP] Multi architecture compilation support

2021-07-27 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

`-fopenmp-targets=amdgcn-amd-amdhsa,amdgcn-amd-amdhsa` seems burdensome. Could 
you just count how many `-Xopenmp-target=amdgcn-amd-amdhsa` there are on the 
comand line and then count the unique ones?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106870

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


[PATCH] D106870: [OpenMP] Multi architecture compilation support

2021-07-27 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

In D106870#2907252 , @ye-luo wrote:

> `-fopenmp-targets=amdgcn-amd-amdhsa,amdgcn-amd-amdhsa` seems burdensome. 
> Could you just count how many `-Xopenmp-target=amdgcn-amd-amdhsa` there are 
> on the comand line and then count the unique ones?

I have a patch in pipeline which will eliminate need of (-fopenmp-targets, 
-Xopenmp-target, and -march) altogether. User will be able to compile with just 
"--offload-arch=gfx906" instead of using the other three flags.
It is working in our downstream AOMP Compiler but I haven't posted a phab 
review yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106870

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


[PATCH] D106870: [OpenMP] Multi architecture compilation support

2021-07-27 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added inline comments.



Comment at: openmp/libomptarget/src/rtl.cpp:306
+  std::string cmd_bin;
+  cmd_bin.assign(libomptarget_dir_name).append("/../bin/amdgpu-arch");
+  struct stat stat_buffer;

Call to amdgpu-arch binary is going to be replaced with call to a new library 
named OffloadArch. It will return current GPU name along with enabled GPU 
features (i.e. requirements) in a platform-independent way. As the library and 
its various functionalities are self-contained I decided to post it is a 
separate review and use amdgpu-arch here for demonstration.
I will be posting the phab review for the library soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106870

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


[PATCH] D106870: [OpenMP] Multi architecture compilation support

2021-07-27 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

In D106870#2907257 , @saiislam wrote:

> In D106870#2907252 , @ye-luo wrote:
>
>> `-fopenmp-targets=amdgcn-amd-amdhsa,amdgcn-amd-amdhsa` seems burdensome. 
>> Could you just count how many `-Xopenmp-target=amdgcn-amd-amdhsa` there are 
>> on the comand line and then count the unique ones?
>
> I have a patch in pipeline which will eliminate need of (-fopenmp-targets, 
> -Xopenmp-target, and -march) altogether. User will be able to compile with 
> just "--offload-arch=gfx906" instead of using the other three flags.
> It is working in our downstream AOMP Compiler but I haven't posted a phab 
> review yet.

That is just a convenient option and separate topic. I'm commenting on the 
current generic option you are fiddle with.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106870

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


[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-27 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 362018.
azabaznov added a comment.
Herald added a subscriber: dexonsmith.

Preserve existing diagnostic with `err_opencl_unknown_type_specifier`, fix 
comments for language option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106748

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/pipe_builtin.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl

Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
Index: clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++
 
 global pipe int gp;// expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
Index: clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
@@ -1,9 +1,23 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_pipes,-__opencl_c_generic_address_space
 
 void foo(read_only pipe int p);
-// expected-warning@-1 {{type specifier missing, defaults to 'int'}}
-// expected-error@-2 {{access qualifier can only be used for pipe and image type}}
-// expected-error@-3 {{expected ')'}} expected-note@-3 {{to match this '('}}
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-error@-3 {{access qualifier can only be used for pipe and image type}}
+#else
+// expected-warning@-5 {{type specifier missing, defaults to 'int'}}
+// expected-error@-6 {{access qualifier can only be used for pipe and image type}}
+// expected-error@-7 {{expected ')'}} expected-note@-7 {{to match this '('}}
+#endif
 
 // 'pipe' should be accepted as an identifier.
 typedef int pipe;
+#if __OPENCL_C_VERSION__ > 120
+// expected-error@-2 {{OpenCL C version 3.0 does not support the 'pipe' type qualifier}}
+// expected-warning@-3 {{typedef requires a name}}
+#endif
+
+void bar() {
+ reserve_id_t r; // expected-error {{use of undeclared identifier 'reserve_id_t'}}
+}
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,8 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-27 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:31
+public:
+  RISCVISAInfo() : XLen(0), FLen(0) {}
+

Does Exts need initialising to be empty here? I can never remember



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:47-52
+  /// Parse RISCV ISA info from arch string.
+  Error parseArchString(StringRef Arch, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck = true);
+
+  /// Parse RISCV ISA info from feature vector.
+  void parseFeatures(unsigned XLen, const std::vector &Features);

I wonder, should these be constructors instead? `RISCVISAInfo ISAInfo; 
ISAInfo.parse` doesn't feel very idiomatic C++



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:178
+// order, but after all known standard extensions.
+Rank = AllStdExts.size() + (Ext - 'a');
+  else

Why not just return these directly? Don't need a variable.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:194
+  switch (ExtClass) {
+  case 's':
+HighOrder = 0;

I imagine this needs to change to the new Sm-/Ss- scheme, but I don't know 
which way round those are intended to go



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:197
+break;
+  case 'h':
+HighOrder = 1;

Do we know if this is still the case? Ss- is being used for S-mode extensions 
and Sm- for M-mode extensions, so I'd expect Sh- (or maybe just Ss-) for 
HS-mode extensions, not H-.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:207
+  default:
+assert(false && "Unknown prefix for multi-char extension");
+return -1;

llvm_unreachable



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:214
+  if (ExtClass == 'z')
+LowOrder = singleLetterExtensionRank(ExtName[1]);
+

Why not put this in its switch case?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:225-229
+  if (LHSLen == 1 && RHSLen != 1)
+return true;
+
+  if (LHSLen != 1 && RHSLen == 1)
+return false;

Don't know if this is better or not, but this is the more compact way to write 
it



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:231
+  size_t RHSLen = RHS.length();
+  int LHSRank, RHSRank;
+  if (LHSLen == 1 && RHSLen != 1)

frasercrmck wrote:
> Not sure why these need to be declared up here.
Yeah, declare the variables at their assignments. Besides, you don't even need 
variables for the single-letter case, just compare the return values of the 
functions directly.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:40
+
+static const StringRef AllStdExts = "mafdqlcbjtpvn";
+

kito-cheng wrote:
> jrtc27 wrote:
> > craig.topper wrote:
> > > Make this `static constexpr StringLiteral AllStdExts = "mafdqlcbjtpvn";`
> > I can't help but feel this is really an array of chars, not a string. We 
> > don't even need the trailing NUL, though double quote syntax is simpler 
> > than curly braces and a bunch of single-quote chars just to save a byte.
> Yeah, it's actually just an array of chars, but we have use find function 
> from StringRef :p
Still not a StringLiteral



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:43
+static const RISCVSupportedExtensionInfo SupportedExtensionInfos[] = {
+{"i", RISCVExtensionVersion{2, 0}, /* Experimental */ false},
+{"e", RISCVExtensionVersion{1, 9}, /* Experimental */ false},

jrtc27 wrote:
> but that's the default so I'd omit it for anything other than the cases where 
> it's true
I do think it would be better to not list Experimental for the non-experimental 
ones


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D106739: [analyzer] Add option to SATest.py for extra checkers

2021-07-27 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Looks good!  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106739

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


[PATCH] D106277: [SVE] Remove the interface for getMaxVScale in favour of the IR attributes

2021-07-27 Thread Dylan Fleming via Phabricator via cfe-commits
DylanFleming-arm updated this revision to Diff 362020.
DylanFleming-arm added a comment.

Rebased onto main, updated newly added AArch64 getMaxVScale usages to use IR 
attribute instead


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106277

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Analysis/CostModel/AArch64/sve-gather.ll
  llvm/test/Analysis/CostModel/AArch64/sve-scatter.ll
  llvm/test/Transforms/LoopVectorize/AArch64/first-order-recurrence.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll

Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
@@ -12,7 +12,7 @@
 ; that we can use gather instructions with the correct offsets, taking
 ; vscale into account.
 
-define void @widen_ptr_phi_unrolled(i32* noalias nocapture %a, i32* noalias nocapture %b, i32* nocapture readonly %c, i64 %n) {
+define void @widen_ptr_phi_unrolled(i32* noalias nocapture %a, i32* noalias nocapture %b, i32* nocapture readonly %c, i64 %n) #0 {
 ; CHECK-LABEL: @widen_ptr_phi_unrolled(
 ; CHECK:   vector.body:
 ; CHECK-NEXT:[[POINTER_PHI:%.*]] = phi i32* [ %c, %vector.ph ], [ %[[PTR_IND:.*]], %vector.body ]
@@ -122,7 +122,7 @@
 ; because it is stored to memory.
 ;
 
-define i32 @pointer_iv_mixed(i32* noalias %a, i32** noalias %b, i64 %n) {
+define i32 @pointer_iv_mixed(i32* noalias %a, i32** noalias %b, i64 %n) #0 {
 ; CHECK-LABEL: @pointer_iv_mixed(
 ; CHECK: vector.body
 ; CHECK:   %[[IDX:.*]] = phi i64 [ 0, %vector.ph ], [ %{{.*}}, %vector.body ]
@@ -170,7 +170,7 @@
   ret i32 %tmp5
 }
 
-
+attributes #0 = { vscale_range(0, 16) }
 !0 = distinct !{!0, !1, !2, !3, !4, !5}
 !1 = !{!"llvm.loop.mustprogress"}
 !2 = !{!"llvm.loop.vectorize.width", i32 4}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
@@ -49,7 +49,7 @@
   ret double %add
 }
 
-attributes #0 = { "target-features"="+sve" }
+attributes #0 = { "target-features"="+sve" vscale_range(0, 16) }
 
 !0 = distinct !{!0, !1}
 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
@@ -1,6 +1,6 @@
 ; RUN: opt -mtriple aarch64-linux-gnu -mattr=+sve -loop-vectorize -scalable-vectorization=on -dce -instcombine -S <%s | FileCheck %s
 
-define void @stride7_i32(i32* noalias nocapture %dst, i64 %n) {
+define void @stride7_i32(i32* noalias nocapture %dst, i64 %n) #0 {
 ; CHECK-LABEL: @stride7_i32(
 ; CHECK:  vector.body
 ; CHECK:%[[VEC_IND:.*]] = phi  [ %{{.*}}, %vector.ph ], [ %{{.*}}, %vector.body ]
@@ -27,7 +27,7 @@
   ret void
 }
 
-define void @stride7_f64(double* noalias nocapture %dst, i64 %n) {
+define void @stride7_f64(double* noalias nocapture %dst, i64 %n) #0 {
 ; CHECK-LABEL: @stride7_f64(
 ; CHECK:  vector.body
 ; CHECK:%[[VEC_IND:.*]] = phi  [ %{{.*}}, %vector.ph ], [ %{{.*}}, %vector.body ]
@@ -55,7 +55,7 @@
 }
 
 
-define void @cond_stride7_f64(double* noalias nocapture %dst, i64* noalias nocapture readonly %cond, i64 %n) {
+define void @cond_stride7_f64(double* noalias nocapture %dst, i64* noalias nocapture readonly %cond, i64 %n) #0 {
 ; CHECK-LABEL: @cond_stride7_f64(
 ; CHECK:  vector.body
 ; CHECK:%[[MASK:.*]] = icmp ne 
@@ -90,7 +90,7 @@
   ret void
 }
 
-
+attributes #0 = { vscale_range(0, 16) }
 !0 = distinct !{!0, !1, !2, !3, !4, !5}
 !1 = !{!"llvm.loop.mustprogress"}
 !2 = !{!"llvm.loop.vectorize.width", i32 4}
Index: llvm/test/Transforms/Loop

[clang] da58ca5 - [clang-repl] Build and install clang-repl by default.

2021-07-27 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-07-27T14:09:44Z
New Revision: da58ca51f0cf4b415bbfc299ac7cef0666243c6c

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

LOG: [clang-repl] Build and install clang-repl by default.

We have the basic infrastructure in place. We can recover from simple errors
(recovering from errors in template instantiations is not yet supported). It
looks like we are in a reasonably functional state for llvm13.

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

Added: 


Modified: 
clang/tools/clang-repl/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-repl/CMakeLists.txt 
b/clang/tools/clang-repl/CMakeLists.txt
index 106af3f1939b1..a9dcd1f6a66bb 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -7,7 +7,6 @@ set( LLVM_LINK_COMPONENTS
   )
 
 add_clang_executable(clang-repl
-  EXCLUDE_FROM_ALL
   ClangRepl.cpp
   )
 



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


[PATCH] D106813: [clang-repl] Build and install clang-repl by default

2021-07-27 Thread Vassil Vassilev 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 rGda58ca51f0cf: [clang-repl] Build and install clang-repl by 
default. (authored by v.g.vassilev).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106813

Files:
  clang/tools/clang-repl/CMakeLists.txt


Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -7,7 +7,6 @@
   )
 
 add_clang_executable(clang-repl
-  EXCLUDE_FROM_ALL
   ClangRepl.cpp
   )
 


Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -7,7 +7,6 @@
   )
 
 add_clang_executable(clang-repl
-  EXCLUDE_FROM_ALL
   ClangRepl.cpp
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105555: [RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-27 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

This patch depends on D105168 , 
Please help to review it if you have time.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

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


[PATCH] D106863: Allow #pragma float_control(push|pop) within a language linkage specification

2021-07-27 Thread Melanie Blower via Phabricator via cfe-commits
mibintc accepted this revision.
mibintc added a comment.

Thanks for fixing this Aaron, just curious was there a bug report?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106863

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


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-07-27 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev created this revision.
ilyakuteev added reviewers: aprantl, dblaikie, rsmith, dexonsmith.
ilyakuteev requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Problem:
PCM file includes references to all module maps used in compilation which 
created PCM. This problem leads to PCM-rebuilds in distributed compilations as 
some module maps could be missing in isolated compilation. (For example in our 
distributed build system we create a temp folder for every compilation with 
only modules and headers that are needed for that particular command).

Solution:
Add only affecting module map files to a PCM-file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,48 @@

 namespace {

+std::string ModuleMapFilePathForModule(ModuleMap &Map, Module* GivenModule) {
+  if (GivenModule->PresumedModuleMapFile.empty()) {
+auto *ModuleMapFile = Map.getModuleMapFileForUniquing(GivenModule);
+if (ModuleMapFile) {
+  return std::string(ModuleMapFile->getName());
+} else {
+  return std::string();
+}
+  } else {
+return GivenModule->PresumedModuleMapFile;
+  }
+}
+
+std::set GetAllModulemaps(ModuleMap &Map, Module *RootModule) {
+  std::set ModuleMaps {};
+  std::set ProcessedModules;
+  std::set ModulesToProcess {RootModule};
+  while (!ModulesToProcess.empty()) {
+auto CurrentModule = ModulesToProcess.begin();
+ProcessedModules.insert(*CurrentModule);
+
+const std::string CurrentModuleMapFile =
+ModuleMapFilePathForModule(Map, *CurrentModule);
+if (CurrentModuleMapFile.empty()) {
+  ModulesToProcess.erase(CurrentModule);
+  continue;
+}
+
+ModuleMaps.insert(CurrentModuleMapFile);
+
+for (auto *ImportedModule : (*CurrentModule)->Imports) {
+  if (!ImportedModule ||
+  ProcessedModules.find(ImportedModule) != ProcessedModules.end()) {
+continue;
+  }
+  ModulesToProcess.insert(ImportedModule);
+}
+ModulesToProcess.erase(CurrentModule);
+  }
+  return ModuleMaps;
+}
+
 class ASTTypeWriter {
   ASTWriter &Writer;
   ASTWriter::RecordData Record;
@@ -1396,9 +1438,15 @@
 Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
   }

+  std::set AffectingModulemaps;
+  if (WritingModule) {
+AffectingModulemaps = GetAllModulemaps(
+PP.getHeaderSearchInfo().getModuleMap(), WritingModule);
+  }
+
   WriteInputFiles(Context.SourceMgr,
   PP.getHeaderSearchInfo().getHeaderSearchOpts(),
-  PP.getLangOpts().Modules);
+  AffectingModulemaps);
   Stream.ExitBlock();
 }

@@ -1418,7 +1466,7 @@

 void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
 HeaderSearchOptions &HSOpts,
-bool Modules) {
+std::set& AffectingModuleMaps) {
   using namespace llvm;

   Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
@@ -1458,6 +1506,15 @@
 if (!Cache->OrigEntry)
   continue;

+if (isModuleMap(File.getFileCharacteristic()) &&
+!isSystem(File.getFileCharacteristic()) &&
+!AffectingModuleMaps.empty() &&
+AffectingModuleMaps.find(std::string(Cache->OrigEntry->getName())) ==
+   AffectingModuleMaps.end()) {
+  // Do not emit modulemaps that do not affect current module.
+  continue;
+}
+
 InputFileEntry Entry;
 Entry.File = Cache->OrigEntry;
 Entry.IsSystemFile = isSystem(File.getFileCharacteristic());
@@ -1971,11 +2028,15 @@
 Record.push_back(SLoc->getOffset() - 2);
 if (SLoc->isFile()) {
   const SrcMgr::FileInfo &File = SLoc->getFile();
+  const SrcMgr::ContentCache *Content = &File.getContentCache();
+  if (Content->OrigEntry && InputFileIDs[Content->OrigEntry] == 0) {
+// Do not emit files that were not listed as inputs.
+continue;
+  }
   AddSourceLocation(File.getIncludeLoc(), Record);
   Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
   Record.push_back(File.hasLineDirectives());

-  const SrcMgr::ContentCache *Content = &File.getContentCache();
   bool EmitBlob = false;
   if (Content->OrigEntry) {
 assert(Content->OrigEntry == Content->ContentsEntry &&
Index: clang/include/clang/Serialization/ASTWriter.h
===
--- clang/include/clang/Serialization/ASTWriter.h
+++ clang/include/clang/Serialization/ASTWriter.h
@@ -475,7 +475,7 @@
   createSignature(StringRef AllBytes, StringRef ASTBlockBytes);

   void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
- 

[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna updated this revision to Diff 362027.
Topotuna added a comment.

Test case added that checks if __remove_address_space modifies types without 
address space


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

https://reviews.llvm.org/D106785

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Headers/opencl-c-base.h
  clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp

Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header
+
+template
+struct is_same {
+  static const bool value = false;
+};
+
+template
+struct is_same {
+  static const bool value = true;
+};
+
+void test_is_same() {
+  static_assert(is_same::value);
+  static_assert(!is_same::value);
+  static_assert(!is_same<__private int, int>::value);
+}
+
+void test_remove_address_space() {
+  static_assert(is_same<__remove_address_space::type, int>::value,
+"type without an address space unexpectedly modified by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__generic int>::type, int>::value,
+"__generic address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__global char>::type, char>::value,
+"__global address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value,
+"__private address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__local short>::type, short>::value,
+"__local address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space<__constant int3>::type, int3>::value,
+"__constant address space not removed by __remove_address_space");
+  static_assert(is_same<__remove_address_space::type, const volatile int>::value,
+"non-address-space qualifiers inappropriately removed by __remove_address_space");
+}
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -565,6 +565,26 @@
 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
 
+// C++ for OpenCL - __remove_address_space
+#if defined(__OPENCL_CPP_VERSION__)
+template  struct __remove_address_space { using type = _Tp; };
+template  struct __remove_address_space<__generic _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__global _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__private _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__local _Tp> {
+  using type = _Tp;
+};
+template  struct __remove_address_space<__constant _Tp> {
+  using type = _Tp;
+};
+#endif
+
 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
 
 #define __kernel_exec(X, typen) __kernel \
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1961,6 +1961,30 @@
 global OnlySL *d,
   );
 
+Builtin address space removal utility
+-
+
+``__remove_address_space`` allows to derive types in C++ for OpenCL
+that have address space qualifiers removed. This utility only affects
+address space qualifiers, therefore, other type qualifiers such as
+``const`` or ``volatile`` remain unchanged.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  template
+  void foo(T *par){
+T var1; // error - local function variable with global address space
+__private T var2; // error - conflicting address space qualifiers
+__private __remove_address_space var3; // var3 is __private int
+  }
+
+  void bar(){
+__global int* ptr;
+foo(ptr);
+  }
+
 Legacy 1.x atomics with generic address space
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-27 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362028.
beanz marked 13 inline comments as done.
beanz added a comment.

Minor comment fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,56 @@
   }
 };
 
+/// "\#pragma clang deprecate(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
+Token &Tok) override {
+std::string Macro, MessageString;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Tok, diag::err_expected) << "(";
+  return;
+}
+
+PP.LexUnexpandedToken(Tok);
+if (!Tok.is(tok::identifier)) {
+  PP.Diag(Tok, diag::err_expected) << tok::identifier;
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+
+if (!II->hasMacroDefinition()) {
+  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II->getName();
+  return;
+}
+
+PP.Lex(Tok);
+if (Tok.is(tok::comma)) {
+  PP.Lex(Tok);
+  if (!PP.FinishLexStringLiteral(Tok, MessageString,
+ "#pragma clang deprecated",
+ /*AllowMacroExpansion=*/true))
+return;
+}
+
+if (Tok.isNot(tok::r_paren)) {
+  PP.Diag(Tok, diag::err_expected) << ")";
+  return;
+}
+
+II->setIsDeprecatedMacro(true);
+PP.addMacroDeprecationMsg(II, std::move(MessageString));
+  }
+};
+
 } // namespace
 
 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
@@ -1939,6 +1989,7 @@
   AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
   AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
   AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
+  AddPragmaHandler("clang", new PragmaDeprecatedHandler());
 
   // #pragma clang module ...
   auto *ModuleHandler = new PragmaNamespace("module");
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -471,6 +471,16 @@
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
  const MacroDefinition &M) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()) {
+auto DepMsg = getMac

[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-27 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

All feedback should be addressed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

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


[PATCH] D106870: [OpenMP] Multi architecture compilation support

2021-07-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

There seems to be a bunch of different things in this patch.

There's some driver plumbing to compile for more than one arch (presumably by 
calling the target compiler N times). That's a great feature, I want to build 
an application bthat can run on nvptx or amdgpu. Probably need a test case 
showing that combination.

Then there's a bunch of stuff to do with 'requirements', but it's not clear 
what that is.

Finally there's some stuff where libomptarget dlopens itself then spawns 
amdgpu-arch. I can't tell why we would want to do that.

My guess was that each arch would get its own section in the host executable 
containing a code object and each host plugin would be responsible for 
indicating whether it could do anything with a given code object. That should 
work out of the box for machines with only one offloading arch available, and 
need some work around device_id to handle multiple ones.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106870

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


[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-07-27 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

BTW, looks like the standard wording came from:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_273.htm

which indeed seems to suggest that the intent was to:

1. ensure that WCHAR_MAX is at least the maximum character actually defined so 
far by the standard (which in past versions was 0x, and in current versions 
is 0x10).
2. ensure that for each of those characters defined by the standard, that it 
has the same numeric value stored in a wchar_t as the value the standard 
specifies.

In D106577#2906542 , @rsmith wrote:

> The "old libc" case is for old versions of glibc that put the macro in 
> `features.h` instead of in `stdc-predef.h`. The macros in `stdc-predef.h` 
> aren't a problem until / unless we start auto-including that header.

The `features.h` header in every version of glibc since `stdc-predef.h` was 
split off has had `#include ` in it. If the redefinition is a 
problem, it's still a problem in current versions.

> In D106577#2905755 , @jyknight 
> wrote:
>
>> In D106577#2904960 , @rsmith wrote:
>>
>>> One benefit we don't get with this approach is providing the right value 
>>> for the macro (without paying the cost of always including 
>>> `stdc-predefs.h`).
>>
>> What do you mean by "right value", though? As Aaron pointed out, the value 
>> seems only dependent upon what characters can fit into a wchar_t, which is 
>> independent of what unicode version the libc supports.
>
> I don't see how that follows from the definition in the C standard; it says 
> "every character in the Unicode required set, when stored in an object of 
> type `wchar_t`, has the same value as the short identifier of that 
> character". This doesn't say anything about character or string literals, and 
> for example `mbstowcs` stores characters in objects of type `wchar_t` too (it 
> "stores not more than `n` wide characters into the array pointed to by 
> `pwcs`"), so unless `mbstowcs` does the right thing I don't see how we can 
> claim support for a new Unicode standard version. 
> As far as I can tell, this macro is documenting a property of the complete 
> implementation (compiler plus standard library), and should be set to the 
> minimum of the version supported by the compiler and the version supported by 
> the stdlib. I think it's OK for the compiler to say it supports *any* 
> version, though, because we don't expect future Unicode versions to require 
> any changes on our part. But they may require standard library changes.

But that's exactly it -- there are no library OR compiler changes changes 
required to remain conformant with this property when a new standard version is 
released. The range of values wchar_t needs to represent won't change. Even 
considering mbstowcs, there's no problem because it will already do the right 
thing, with zero changes, no matter how many new characters are defined within 
that valid range of 0x0-0x10 -- assuming that it does store unicode ordinal 
values into wchar_t in the first place. UTF-8/16/32 encoding and decoding are 
agnostic to which characters have been defined.

Of course, the library does need to make certain other changes corresponding to 
a new version, e.g. updating the tables for iswalpha to return true for newly 
defined alphabetical characters, but that functionality seems irrelevant to 
this define.

> If Aaron's checked with WG14 and the intent is for this to only constrain how 
> literals are represented, and not the complete implementation, then I'm 
> entirely fine with us defining the macro ourselves. But that's not the 
> interpretation that several other vendors have taken. If we're confident that 
> the intent is just that this macro lists (effectively) the latest version of 
> the Unicode standard that we've heard of, we should let the various libc 
> vendors that currently define the macro know that they're doing it wrong and 
> the definition belongs in the compiler.

It's surely intended to cover the complete system, since the standard doesn't 
consider "compiler" vs "libc" as separate things, they're both just components 
of the "implementation". But as per above comments, I don't think that changes 
the conclusion here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


[PATCH] D106863: Allow #pragma float_control(push|pop) within a language linkage specification

2021-07-27 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a reviewer: zahiraam.
mibintc added a subscriber: zahiraam.
mibintc added a comment.

Adding @zahiraam FYI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106863

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


[PATCH] D106748: [OpenCL] Add support of __opencl_c_pipes feature macro.

2021-07-27 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106748

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


[clang] 973de71 - Revert "[clang][pp] adds '#pragma include_instead'"

2021-07-27 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2021-07-27T17:29:48+02:00
New Revision: 973de7185606a21fd5e9d5e8c014fbf898c0e72f

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

LOG: Revert "[clang][pp] adds '#pragma include_instead'"

> `#pragma clang include_instead()` is a pragma that can be used
> by system headers (and only system headers) to indicate to a tool that
> the file containing said pragma is an implementation-detail header and
> should not be directly included by user code.
>
> The library alternative is very messy code that can be seen in the first
> diff of D106124, and we'd rather avoid that with something more
> universal.
>
> This patch takes the first step by warning a user when they include a
> detail header in their code, and suggests alternative headers that the
> user should include instead. Future work will involve adding a fixit to
> automate the process, as well as cleaning up modules diagnostics to not
> suggest said detail headers. Other tools, such as clangd can also take
> advantage of this pragma to add the correct user headers.
>
> Differential Revision: https://reviews.llvm.org/D106394

This caused compiler crashes in Chromium builds involving PCH and an include
directive with macro expansion, when Token::getLiteralData() returned null. See
the code review for details.

This reverts commit e8a64e5491260714c79dab65d1aa73245931d314.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Lex/PreprocessorLexer.h
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/Pragma.cpp

Removed: 
clang/test/Preprocessor/Inputs/include_instead/bad-syntax.h
clang/test/Preprocessor/Inputs/include_instead/file-not-found.h
clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
clang/test/Preprocessor/Inputs/include_instead/private-x.h
clang/test/Preprocessor/Inputs/include_instead/private1.h
clang/test/Preprocessor/Inputs/include_instead/private2.h
clang/test/Preprocessor/Inputs/include_instead/private3.h
clang/test/Preprocessor/Inputs/include_instead/public-after.h
clang/test/Preprocessor/Inputs/include_instead/public-before.h
clang/test/Preprocessor/Inputs/include_instead/public-empty.h
clang/test/Preprocessor/include_instead.cpp
clang/test/Preprocessor/include_instead_file_not_found.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 690ea693bd366..ce6d0d0394b48 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -300,12 +300,6 @@ def pp_pragma_once_in_main_file : Warning<"#pragma once in 
main file">,
 def pp_pragma_sysheader_in_main_file : Warning<
   "#pragma system_header ignored in main file">,
   InGroup>;
-
-def err_pragma_include_instead_not_sysheader : Error<
-  "'#pragma clang include_instead' cannot be used outside of system headers">;
-def err_pragma_include_instead_system_reserved : Error<
-  "header '%0' is an implementation detail; #include %select{'%2'|either '%2' 
or '%3'|one of %2}1 instead">;
-
 def pp_poisoning_existing_macro : Warning<"poisoning existing macro">;
 def pp_out_of_date_dependency : Warning<
   "current file is older than dependency %0">;

diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index a35a394f719b0..93d6ea72270aa 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -20,12 +20,9 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/SmallSet.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
 #include 
 #include 
@@ -113,14 +110,6 @@ struct HeaderFileInfo {
   /// of the framework.
   StringRef Framework;
 
-  /// List of aliases that this header is known as.
-  /// Most headers should only have at most one alias, but a handful
-  /// have two.
-  llvm::SetVector,
-  llvm::SmallVector, 2>,
-  llvm::SmallSet, 2>>
-  Aliases;
-
   HeaderFileInfo()
   : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
 External(false), isModuleHeader(false), isCompilingModuleHeader(false),
@@ -464,10 +453,6 @@ class HeaderSearch {
 getFileInfo(File).DirInfo = SrcMgr::C_System;
   }
 
-  void AddFileAlias(const FileEntry *File, StringRef Alias) {
-getFileInfo(File).Alia

[PATCH] D106394: [clang][pp] adds '#pragma include_instead'

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

This is causing the compiler to crash in Chromium builds, see 
https://bugs.chromium.org/p/chromium/issues/detail?id=1195353

I verified that replacing the use of getLiteralData() with OriginalFileName in 
HandleHeaderIncludeOrImport() fixes the crash, but the the other 
getLiteralData() probably needs a fix too, and I don't have a test case, so 
reverted for now in 973de7185606a21fd5e9d5e8c014fbf898c0e72f 





Comment at: clang/lib/Lex/PPDirectives.cpp:2028
+CurLexer->addInclude(
+{FilenameTok.getLiteralData(), FilenameTok.getLength()},
+File->getFileEntry(), FilenameLoc);

getLiteralData() can return null, which causes a crash here in Chromium.

I think getSpelling() should be used instead, and since it was already called 
above, perhaps you could just pass in OriginalFilename here.



Comment at: clang/lib/Lex/Pragma.cpp:571
+  TheLexer->getFileEntry(),
+  {FilenameTok->getLiteralData(), FilenameTok->getLength()});
+}

actually, get getSpelling() is probably necessary in case getLiteralData() 
returns null?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106394

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


[clang] e5f47ee - [OpenCL] NULL redefined as nullptr in C++ mode.

2021-07-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-27T16:33:50+01:00
New Revision: e5f47eedeb02595247e433ad756607e6c1397ae3

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

LOG: [OpenCL] NULL redefined as nullptr in C++ mode.

Redefines NULL as nullptr instead of ((void*)0)
in C++ for OpenCL.

Such internal representation of NULL provides
compatibility with C++11 and later language
standards.

Patch by Topotuna (Justas Janickas)!

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/test/SemaOpenCL/null_literal.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index b5029a254b7a8..3c5e2c9739368 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -169,7 +169,11 @@ typedef double double8 __attribute__((ext_vector_type(8)));
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
+#if defined(__OPENCL_CPP_VERSION__)
+#define NULL nullptr
+#elif defined(__OPENCL_C_VERSION__)
 #define NULL ((void*)0)
+#endif
 
 /**
  * Value of maximum non-infinite single-precision floating-point

diff  --git a/clang/test/SemaOpenCL/null_literal.cl 
b/clang/test/SemaOpenCL/null_literal.cl
index f4d55d70aaf89..b641c6bd7c6dd 100644
--- a/clang/test/SemaOpenCL/null_literal.cl
+++ b/clang/test/SemaOpenCL/null_literal.cl
@@ -2,27 +2,46 @@
 // RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 // RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 
 void foo(){
 
 global int* ptr1 = NULL;
 
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+2{{cannot initialize a variable of type '__global int 
*__private' with an rvalue of type '__global void *'}}
+#endif
 global int* ptr2 = (global void*)0;
 
 constant int* ptr3 = NULL;
 
-constant int* ptr4 = (global void*)0; // expected-error{{initializing 
'__constant int *__private' with an expression of type '__global void *' 
changes address space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__constant int 
*__private' with an rvalue of type '__global void *'}}
+#else
+// expected-error@+2{{initializing '__constant int *__private' with an 
expression of type '__global void *' changes address space of pointer}}
+#endif
+constant int* ptr4 = (global void*)0;
 
 #if __OPENCL_C_VERSION__ == CL_VERSION_2_0
 // Accept explicitly pointer to generic address space in OpenCL v2.0.
 global int* ptr5 = (generic void*)0;
 #endif
 
-global int* ptr6 = (local void*)0; // expected-error{{initializing '__global 
int *__private' with an expression of type '__local void *' changes address 
space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__global int 
*__private' with an rvalue of type '__local void *'}}
+#else
+// expected-error@+2{{initializing '__global int *__private' with an 
expression of type '__local void *' changes address space of pointer}}
+#endif
+global int* ptr6 = (local void*)0;
 
 bool cmp = ptr1 == NULL;
 
-cmp = ptr1 == (local void*)0; // expected-error{{comparison between  
('__global int *' and '__local void *') which are pointers to non-overlapping 
address spaces}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{comparison of distinct pointer types ('__global int *' 
and '__local void *')}}
+#else
+// expected-error@+2{{comparison between  ('__global int *' and '__local void 
*') which are pointers to non-overlapping address spaces}}
+#endif
+cmp = ptr1 == (local void*)0;
 
 cmp = ptr3 == NULL;
 



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


[PATCH] D105987: [C++4OpenCL] NULL redefined as nullptr

2021-07-27 Thread Anastasia Stulova 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 rGe5f47eedeb02: [OpenCL] NULL redefined as nullptr in C++ 
mode. (authored by Anastasia).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105987

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/test/SemaOpenCL/null_literal.cl


Index: clang/test/SemaOpenCL/null_literal.cl
===
--- clang/test/SemaOpenCL/null_literal.cl
+++ clang/test/SemaOpenCL/null_literal.cl
@@ -2,27 +2,46 @@
 // RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 // RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 
 void foo(){
 
 global int* ptr1 = NULL;
 
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+2{{cannot initialize a variable of type '__global int 
*__private' with an rvalue of type '__global void *'}}
+#endif
 global int* ptr2 = (global void*)0;
 
 constant int* ptr3 = NULL;
 
-constant int* ptr4 = (global void*)0; // expected-error{{initializing 
'__constant int *__private' with an expression of type '__global void *' 
changes address space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__constant int 
*__private' with an rvalue of type '__global void *'}}
+#else
+// expected-error@+2{{initializing '__constant int *__private' with an 
expression of type '__global void *' changes address space of pointer}}
+#endif
+constant int* ptr4 = (global void*)0;
 
 #if __OPENCL_C_VERSION__ == CL_VERSION_2_0
 // Accept explicitly pointer to generic address space in OpenCL v2.0.
 global int* ptr5 = (generic void*)0;
 #endif
 
-global int* ptr6 = (local void*)0; // expected-error{{initializing '__global 
int *__private' with an expression of type '__local void *' changes address 
space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__global int 
*__private' with an rvalue of type '__local void *'}}
+#else
+// expected-error@+2{{initializing '__global int *__private' with an 
expression of type '__local void *' changes address space of pointer}}
+#endif
+global int* ptr6 = (local void*)0;
 
 bool cmp = ptr1 == NULL;
 
-cmp = ptr1 == (local void*)0; // expected-error{{comparison between  
('__global int *' and '__local void *') which are pointers to non-overlapping 
address spaces}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{comparison of distinct pointer types ('__global int *' 
and '__local void *')}}
+#else
+// expected-error@+2{{comparison between  ('__global int *' and '__local void 
*') which are pointers to non-overlapping address spaces}}
+#endif
+cmp = ptr1 == (local void*)0;
 
 cmp = ptr3 == NULL;
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -169,7 +169,11 @@
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
+#if defined(__OPENCL_CPP_VERSION__)
+#define NULL nullptr
+#elif defined(__OPENCL_C_VERSION__)
 #define NULL ((void*)0)
+#endif
 
 /**
  * Value of maximum non-infinite single-precision floating-point


Index: clang/test/SemaOpenCL/null_literal.cl
===
--- clang/test/SemaOpenCL/null_literal.cl
+++ clang/test/SemaOpenCL/null_literal.cl
@@ -2,27 +2,46 @@
 // RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins -finclude-default-header -verify %s
 // RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header -verify %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header -verify %s
 
 void foo(){
 
 global int* ptr1 = NULL;
 
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+2{{cannot initialize a variable of type '__global int *__private' with an rvalue of type '__global void *'}}
+#endif
 global int* ptr2 = (global void*)0;
 
 constant int* ptr3 = NULL;
 
-constant int* ptr4 = (global void*)0; // expected-error{{initializing '__constant int *__private' with an expression of type '__global void *' changes address space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__constant int *__private' with an rvalue of type '__global void *'}}
+#else
+// expected-error@+2{{initializing '__constant int *__private' with an expression of type '__global void *' changes address 

[clang] 3378657 - [WebAssembly] Codegen for extmul SIMD instructions

2021-07-27 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-07-27T08:41:30-07:00
New Revision: 33786576fd3a7f79a6627a51386b173940bab0e9

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

LOG: [WebAssembly] Codegen for extmul SIMD instructions

Replace the clang builtins and LLVM intrinsics for the SIMD extmul instructions
with normal codegen patterns.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/wasm_simd128.h
clang/test/CodeGen/builtins-wasm.c
clang/test/Headers/wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-arith.ll
llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index aff14b7dbf4d8..04ec45aa3b747 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -103,21 +103,6 @@ TARGET_BUILTIN(__builtin_wasm_popcnt_i8x16, "V16ScV16Sc", 
"nc", "simd128")
 
 TARGET_BUILTIN(__builtin_wasm_q15mulr_sat_s_i16x8, "V8sV8sV8s", "nc", 
"simd128")
 
-TARGET_BUILTIN(__builtin_wasm_extmul_low_i8x16_s_i16x8, "V8sV16ScV16Sc", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_high_i8x16_s_i16x8, "V8sV16ScV16Sc", 
"nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_low_i8x16_u_i16x8, "V8UsV16UcV16Uc", 
"nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_high_i8x16_u_i16x8, "V8UsV16UcV16Uc", 
"nc", "simd128")
-
-TARGET_BUILTIN(__builtin_wasm_extmul_low_i16x8_s_i32x4, "V4iV8sV8s", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_high_i16x8_s_i32x4, "V4iV8sV8s", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_low_i16x8_u_i32x4, "V4UiV8UsV8Us", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_high_i16x8_u_i32x4, "V4UiV8UsV8Us", "nc", 
"simd128")
-
-TARGET_BUILTIN(__builtin_wasm_extmul_low_i32x4_s_i64x2, "V2LLiV4iV4i", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_high_i32x4_s_i64x2, "V2LLiV4iV4i", "nc", 
"simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_low_i32x4_u_i64x2, "V2ULLiV4UiV4Ui", 
"nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_extmul_high_i32x4_u_i64x2, "V2ULLiV4UiV4Ui", 
"nc", "simd128")
-
 TARGET_BUILTIN(__builtin_wasm_extadd_pairwise_i8x16_s_i16x8, "V8sV16Sc", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_extadd_pairwise_i8x16_u_i16x8, "V8UsV16Uc", 
"nc", "simd128")
 

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f6a9a10c3f7fd..d9b2a5fe16bec 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17864,49 +17864,6 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_q15mulr_sat_signed);
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
-  case WebAssembly::BI__builtin_wasm_extmul_low_i8x16_s_i16x8:
-  case WebAssembly::BI__builtin_wasm_extmul_high_i8x16_s_i16x8:
-  case WebAssembly::BI__builtin_wasm_extmul_low_i8x16_u_i16x8:
-  case WebAssembly::BI__builtin_wasm_extmul_high_i8x16_u_i16x8:
-  case WebAssembly::BI__builtin_wasm_extmul_low_i16x8_s_i32x4:
-  case WebAssembly::BI__builtin_wasm_extmul_high_i16x8_s_i32x4:
-  case WebAssembly::BI__builtin_wasm_extmul_low_i16x8_u_i32x4:
-  case WebAssembly::BI__builtin_wasm_extmul_high_i16x8_u_i32x4:
-  case WebAssembly::BI__builtin_wasm_extmul_low_i32x4_s_i64x2:
-  case WebAssembly::BI__builtin_wasm_extmul_high_i32x4_s_i64x2:
-  case WebAssembly::BI__builtin_wasm_extmul_low_i32x4_u_i64x2:
-  case WebAssembly::BI__builtin_wasm_extmul_high_i32x4_u_i64x2: {
-Value *LHS = EmitScalarExpr(E->getArg(0));
-Value *RHS = EmitScalarExpr(E->getArg(1));
-unsigned IntNo;
-switch (BuiltinID) {
-case WebAssembly::BI__builtin_wasm_extmul_low_i8x16_s_i16x8:
-case WebAssembly::BI__builtin_wasm_extmul_low_i16x8_s_i32x4:
-case WebAssembly::BI__builtin_wasm_extmul_low_i32x4_s_i64x2:
-  IntNo = Intrinsic::wasm_extmul_low_signed;
-  break;
-case WebAssembly::BI__builtin_wasm_extmul_low_i8x16_u_i16x8:
-case WebAssembly::BI__builtin_wasm_extmul_low_i16x8_u_i32x4:
-case WebAssembly::BI__builtin_wasm_extmul_low_i32x4_u_i64x2:
-  IntNo = Intrinsic::wasm_extmul_low_unsigned;
-  break;
-case WebAssembly::BI__builtin_wasm_extmul_high_i8x16_s_i16x8:
-case WebAssembly::BI__builtin_wasm_extmul_high_i16x8_s_i32x4:
-case WebAssembly::BI__builtin_wasm_extmul_high_i32x4_s_i64x2:
-  IntNo = Intrinsic::wasm_extmul_high_signed;
-  break;
-case WebAssembly::BI__builtin_wasm_extmul_high_i8x16

[PATCH] D106724: [WebAssembly] Codegen for extmul SIMD instructions

2021-07-27 Thread Thomas Lively 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 rG33786576fd3a: [WebAssembly] Codegen for extmul SIMD 
instructions (authored by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106724

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-arith.ll
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -248,54 +248,6 @@
   ret <8 x i16> %a
 }
 
-; CHECK-LABEL: extmul_low_s_v8i16:
-; CHECK-NEXT: .functype extmul_low_s_v8i16 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i16x8.extmul_low_i8x16_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.extmul.low.signed.v8i16(<16 x i8>, <16 x i8>)
-define <8 x i16> @extmul_low_s_v8i16(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <8 x i16> @llvm.wasm.extmul.low.signed.v8i16(
-<16 x i8> %x, <16 x i8> %y
-  )
-  ret <8 x i16> %a
-}
-
-; CHECK-LABEL: extmul_high_s_v8i16:
-; CHECK-NEXT: .functype extmul_high_s_v8i16 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i16x8.extmul_high_i8x16_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.extmul.high.signed.v8i16(<16 x i8>, <16 x i8>)
-define <8 x i16> @extmul_high_s_v8i16(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <8 x i16> @llvm.wasm.extmul.high.signed.v8i16(
-<16 x i8> %x, <16 x i8> %y
-  )
-  ret <8 x i16> %a
-}
-
-; CHECK-LABEL: extmul_low_u_v8i16:
-; CHECK-NEXT: .functype extmul_low_u_v8i16 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i16x8.extmul_low_i8x16_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.extmul.low.unsigned.v8i16(<16 x i8>, <16 x i8>)
-define <8 x i16> @extmul_low_u_v8i16(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <8 x i16> @llvm.wasm.extmul.low.unsigned.v8i16(
-<16 x i8> %x, <16 x i8> %y
-  )
-  ret <8 x i16> %a
-}
-
-; CHECK-LABEL: extmul_high_u_v8i16:
-; CHECK-NEXT: .functype extmul_high_u_v8i16 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i16x8.extmul_high_i8x16_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.extmul.high.unsigned.v8i16(<16 x i8>, <16 x i8>)
-define <8 x i16> @extmul_high_u_v8i16(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <8 x i16> @llvm.wasm.extmul.high.unsigned.v8i16(
-<16 x i8> %x, <16 x i8> %y
-  )
-  ret <8 x i16> %a
-}
-
 ; CHECK-LABEL: extadd_pairwise_s_v8i16:
 ; CHECK-NEXT: .functype extadd_pairwise_s_v8i16 (v128) -> (v128){{$}}
 ; CHECK-NEXT: i16x8.extadd_pairwise_i8x16_s $push[[R:[0-9]+]]=, $0{{$}}
@@ -395,55 +347,6 @@
   ret <4 x i32> %a
 }
 
-
-; CHECK-LABEL: extmul_low_s_v4i32:
-; CHECK-NEXT: .functype extmul_low_s_v4i32 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i32x4.extmul_low_i16x8_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <4 x i32> @llvm.wasm.extmul.low.signed.v4i32(<8 x i16>, <8 x i16>)
-define <4 x i32> @extmul_low_s_v4i32(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <4 x i32> @llvm.wasm.extmul.low.signed.v4i32(
-<8 x i16> %x, <8 x i16> %y
-  )
-  ret <4 x i32> %a
-}
-
-; CHECK-LABEL: extmul_high_s_v4i32:
-; CHECK-NEXT: .functype extmul_high_s_v4i32 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i32x4.extmul_high_i16x8_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <4 x i32> @llvm.wasm.extmul.high.signed.v4i32(<8 x i16>, <8 x i16>)
-define <4 x i32> @extmul_high_s_v4i32(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <4 x i32> @llvm.wasm.extmul.high.signed.v4i32(
-<8 x i16> %x, <8 x i16> %y
-  )
-  ret <4 x i32> %a
-}
-
-; CHECK-LABEL: extmul_low_u_v4i32:
-; CHECK-NEXT: .functype extmul_low_u_v4i32 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i32x4.extmul_low_i16x8_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <4 x i32> @llvm.wasm.extmul.low.unsigned.v4i32(<8 x i16>, <8 x i16>)
-define <4 x i32> @extmul_low_u_v4i32(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <4 x i32> @llvm.wasm.extmul.low.unsigned.v4i32(
-<8 x i16> %x, <8 x i16> %y
-  )
-  ret <4 x i32> %a
-}
-
-; CHECK-LABEL: extmul_high_u_v4i32:
-; CHECK-NEXT: .functype extmul_high_u_v4i32 (v128, v128) -> (v128){{$}}
-; CHECK-NEXT: i32x4.extmul_high_i16x8_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <4 x i32> @llvm.wasm.extmul.high.unsigned.v4i32(<8 x i16>, <8 x i16>)
-define <4 x i3

[PATCH] D106394: [clang][pp] adds '#pragma include_instead'

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

In D106394#2907520 , @hans wrote:

> This is causing the compiler to crash in Chromium builds, see 
> https://bugs.chromium.org/p/chromium/issues/detail?id=1195353

Durr, that should be 
https://bugs.chromium.org/p/chromium/issues/detail?id=1233495


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106394

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


[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-27 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362049.
beanz added a comment.

Fix warning printing always having a `:` on the end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,57 @@
   }
 };
 
+/// "\#pragma clang deprecate(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
+Token &Tok) override {
+std::string Macro, MessageString;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Tok, diag::err_expected) << "(";
+  return;
+}
+
+PP.LexUnexpandedToken(Tok);
+if (!Tok.is(tok::identifier)) {
+  PP.Diag(Tok, diag::err_expected) << tok::identifier;
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+
+if (!II->hasMacroDefinition()) {
+  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II->getName();
+  return;
+}
+
+PP.Lex(Tok);
+if (Tok.is(tok::comma)) {
+  PP.Lex(Tok);
+  if (!PP.FinishLexStringLiteral(Tok, MessageString,
+ "#pragma clang deprecated",
+ /*AllowMacroExpansion=*/true))
+return;
+}
+
+if (Tok.isNot(tok::r_paren)) {
+  PP.Diag(Tok, diag::err_expected) << ")";
+  return;
+}
+
+II->setIsDeprecatedMacro(true);
+if (!MessageString.empty())
+  PP.addMacroDeprecationMsg(II, std::move(MessageString));
+  }
+};
+
 } // namespace
 
 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
@@ -1939,6 +1990,7 @@
   AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
   AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
   AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
+  AddPragmaHandler("clang", new PragmaDeprecatedHandler());
 
   // #pragma clang module ...
   auto *ModuleHandler = new PragmaNamespace("module");
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -471,6 +471,16 @@
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
  const MacroDefinition &M) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()

[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-27 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362052.
beanz added a comment.

Minor comment fixes... I swear, eventually I'll be done...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,57 @@
   }
 };
 
+/// "\#pragma clang deprecate(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
+Token &Tok) override {
+std::string Macro, MessageString;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Tok, diag::err_expected) << "(";
+  return;
+}
+
+PP.LexUnexpandedToken(Tok);
+if (!Tok.is(tok::identifier)) {
+  PP.Diag(Tok, diag::err_expected) << tok::identifier;
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+
+if (!II->hasMacroDefinition()) {
+  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II->getName();
+  return;
+}
+
+PP.Lex(Tok);
+if (Tok.is(tok::comma)) {
+  PP.Lex(Tok);
+  if (!PP.FinishLexStringLiteral(Tok, MessageString,
+ "#pragma clang deprecated",
+ /*AllowMacroExpansion=*/true))
+return;
+}
+
+if (Tok.isNot(tok::r_paren)) {
+  PP.Diag(Tok, diag::err_expected) << ")";
+  return;
+}
+
+II->setIsDeprecatedMacro(true);
+if (!MessageString.empty())
+  PP.addMacroDeprecationMsg(II, std::move(MessageString));
+  }
+};
+
 } // namespace
 
 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
@@ -1939,6 +1990,7 @@
   AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
   AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
   AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
+  AddPragmaHandler("clang", new PragmaDeprecatedHandler());
 
   // #pragma clang module ...
   auto *ModuleHandler = new PragmaNamespace("module");
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -471,6 +471,16 @@
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
  const MacroDefinition &M) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedM

[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-27 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362053.
beanz added a comment.

Missed one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,57 @@
   }
 };
 
+/// "\#pragma clang deprecated(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
+Token &Tok) override {
+std::string Macro, MessageString;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Tok, diag::err_expected) << "(";
+  return;
+}
+
+PP.LexUnexpandedToken(Tok);
+if (!Tok.is(tok::identifier)) {
+  PP.Diag(Tok, diag::err_expected) << tok::identifier;
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+
+if (!II->hasMacroDefinition()) {
+  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II->getName();
+  return;
+}
+
+PP.Lex(Tok);
+if (Tok.is(tok::comma)) {
+  PP.Lex(Tok);
+  if (!PP.FinishLexStringLiteral(Tok, MessageString,
+ "#pragma clang deprecated",
+ /*AllowMacroExpansion=*/true))
+return;
+}
+
+if (Tok.isNot(tok::r_paren)) {
+  PP.Diag(Tok, diag::err_expected) << ")";
+  return;
+}
+
+II->setIsDeprecatedMacro(true);
+if (!MessageString.empty())
+  PP.addMacroDeprecationMsg(II, std::move(MessageString));
+  }
+};
+
 } // namespace
 
 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
@@ -1939,6 +1990,7 @@
   AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
   AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
   AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
+  AddPragmaHandler("clang", new PragmaDeprecatedHandler());
 
   // #pragma clang module ...
   auto *ModuleHandler = new PragmaNamespace("module");
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -471,6 +471,16 @@
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
  const MacroDefinition &M) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()) {
+auto DepMsg = getMacroDeprecatio

[PATCH] D106739: [analyzer] Add option to SATest.py for extra checkers

2021-07-27 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@RedDocMD Could you, please, explain the motivation and add at least one test 
to verify it works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106739

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


[PATCH] D106137: [flang][driver] Add support for Frontend Plugins

2021-07-27 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

I think that this is almost ready to be merged. Just a couple more comments.




Comment at: flang/examples/CMakeLists.txt:1
 # This test is not run by default as it requires input.
 add_executable(external-hello-world

Could you add the following at the top of this file:
```
if(NOT FLANG_BUILD_EXAMPLES)
  set(EXCLUDE_FROM_ALL ON)
endif()
```
This will make sure that the examples are not build with e.g. `ninja` when 
`FLANG_BUILD_EXAMPLES` is `Off`.

In [[ 
https://github.com/llvm/llvm-project/blob/43e45f0ec920b45d6073c0aff47597c44948f52c/clang/examples/CMakeLists.txt#L1-L4
 | Clang ]], CMake also contains 
```  set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
```
I think that `set(EXCLUDE_FROM_ALL ON)` should be sufficient though (see [[ 
https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_ALL.html#prop_tgt:EXCLUDE_FROM_ALL
 | CMake ]]  docs for `EXCLUDE_FROM_ALL`). 

Note  that in LLVM, there is [[ 
https://github.com/llvm/llvm-project/blob/43e45f0ec920b45d6073c0aff47597c44948f52c/llvm/cmake/modules/AddLLVM.cmake#L1264-L1273
 | add_llvm_example_library ]]. It would be nice to use that, be we'd need to 
make sure that `LLVM_BUILD_EXAMPLES` is set correctly. But that's not required 
just now and could be added later.



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:147
+  // If there were errors in processing arguments, don't do anything else.
+  if (flang->diagnostics().hasErrorOccurred())
+return false;

This will silence this warning:
```
if (flang->diagnostics().hasErrorOccurred()) {
return false;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106137

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


[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables with enum judgement

2021-07-27 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D106431#2907002 , @Sockke wrote:

> Any thoughts?  : )

First, let's first fix that we should still warn for the uninitialised `enum` 
case, without a FixIt. That's the issue at hand, right now, Clang-Tidy 
generates, as you identified, broken output. We can discuss the later steps 
after this is fixed. Please implement this logic, and update the patch, so we 
have a snapshot of how that would look like and the thing working.

Afterwards, as Aaron suggested:

In D106431#2896441 , @aaron.ballman 
wrote:

> for enumerations, we could issue up to two fix-its on a note, one for the 
> first and one for the last enumerator in an enumeration (and if the enum only 
> contains one enumerator, there's only one fix-it to generate which suggests 
> it could be on the warning rather than a note, but that seems like a lot of 
> trouble for an unlikely scenario). However, I don't recall how clang-tidy 
> interacts with fix-its on notes off the top of my head, so I'm making an 
> assumption that clang-tidy's automatic fixit applying mode handles notes the 
> same way as clang and we should double-check that assumption.

This might require nontrivial changes to the check's code, and investigating 
the potential problem with automated fix-it application when multiple 
conflicting fix-its are given on a **note** (not a //warning// line).

I think we all would be fine with only doing the first step (reintroduce the 
warning, without a fixit) in this patch, so it can be merged and hit the the 
mainline code quickly. The next step can be its own patch. 🙂



In addition, I wager that adding a line about this fix to the release notes at 
`clang-tools-extra/docs/ReleaseNotes.rst` is a good option, I can imagine 
people having turned this check off due to it being broken on enums.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106431

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


[PATCH] D106888: [RISC-V] Implement jump tables for CFI-icall

2021-07-27 Thread Wende Tan via Phabricator via cfe-commits
twd2 created this revision.
twd2 added reviewers: MaskRay, asb, eugenis, pcc.
twd2 created this object with edit policy "Administrators".
twd2 added projects: LLVM, Sanitizers, clang.
Herald added subscribers: ormris, vkmr, luismarques, sameer.abuasal, s.egerton, 
Jim, PkmX, rogfer01, shiva0217, kito-cheng, simoncook, hiraditya.
twd2 requested review of this revision.
Herald added a subscriber: cfe-commits.

This patch implements jump tables for RISC-V so that CFI-icall can be enabled 
for it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106888

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/fsanitize.c
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp


Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1211,6 +1211,7 @@
 static const unsigned kX86JumpTableEntrySize = 8;
 static const unsigned kARMJumpTableEntrySize = 4;
 static const unsigned kARMBTIJumpTableEntrySize = 8;
+static const unsigned kRISCVJumpTableEntrySize = 8;
 
 unsigned LowerTypeTestsModule::getJumpTableEntrySize() {
   switch (Arch) {
@@ -1226,6 +1227,9 @@
 if (BTE->getZExtValue())
   return kARMBTIJumpTableEntrySize;
   return kARMJumpTableEntrySize;
+case Triple::riscv32:
+case Triple::riscv64:
+  return kRISCVJumpTableEntrySize;
 default:
   report_fatal_error("Unsupported architecture for jump tables");
   }
@@ -1253,6 +1257,10 @@
 AsmOS << "b $" << ArgIndex << "\n";
   } else if (JumpTableArch == Triple::thumb) {
 AsmOS << "b.w $" << ArgIndex << "\n";
+  } else if (JumpTableArch == Triple::riscv32 ||
+ JumpTableArch == Triple::riscv64) {
+AsmOS << "1: auipc t0, %pcrel_hi($" << ArgIndex << ")\n"
+  << "jr %pcrel_lo(1b)(t0)\n";
   } else {
 report_fatal_error("Unsupported architecture for jump tables");
   }
@@ -1270,7 +1278,8 @@
 void LowerTypeTestsModule::buildBitSetsFromFunctions(
 ArrayRef TypeIds, ArrayRef Functions) {
   if (Arch == Triple::x86 || Arch == Triple::x86_64 || Arch == Triple::arm ||
-  Arch == Triple::thumb || Arch == Triple::aarch64)
+  Arch == Triple::thumb || Arch == Triple::aarch64 ||
+  Arch == Triple::riscv32 || Arch == Triple::riscv64)
 buildBitSetsFromFunctionsNative(TypeIds, Functions);
   else if (Arch == Triple::wasm32 || Arch == Triple::wasm64)
 buildBitSetsFromFunctionsWASM(TypeIds, Functions);
@@ -1415,6 +1424,11 @@
 F->addFnAttr("branch-target-enforcement", "false");
 F->addFnAttr("sign-return-address", "none");
   }
+  if (JumpTableArch == Triple::riscv32 || JumpTableArch == Triple::riscv64) {
+// Make sure the jump table assembly is not modified by the assembler or
+// the linker.
+F->addFnAttr("target-features", "-c,-relax");
+  }
   // Make sure we don't emit .eh_frame for this function.
   F->addFnAttr(Attribute::NoUnwind);
 
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -603,6 +603,8 @@
 // RUN: %clang -target arm-linux-android -fvisibility=hidden -fsanitize=cfi 
-flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
 // RUN: %clang -target aarch64-linux-android -fvisibility=hidden 
-fsanitize=cfi -flto -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
 // RUN: %clang -target aarch64_be -fvisibility=hidden -fsanitize=cfi -flto -c 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target riscv32 -fvisibility=hidden -fsanitize=cfi -flto -c %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
+// RUN: %clang -target riscv64 -fvisibility=hidden -fsanitize=cfi -flto -c %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
 // CHECK-CFI: 
-emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-NOMFCALL: 
-emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-DCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -1008,7 +1008,7 @@
   if (getTriple().getArch() == llvm::Triple::x86 ||
   getTriple().getArch() == llvm::Triple::x86_64 ||
   getTriple().getArch() == llvm::Triple::arm || getTriple().isWasm() ||
-  getTriple().isAArch64())
+  getTriple().isAArch64() || getTriple().isRISCV())
 Res |= SanitizerKind::CFIICall;
   if (getTriple().getArch() == llvm::Triple::x86_64 ||
   getTriple().isAArch64(64) || getTriple().isRISCV())


Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms

[PATCH] D106889: [examples] Fix the clang-interpreter example for changes in 2487db1f2862

2021-07-27 Thread Ryan Mansfield via Phabricator via cfe-commits
rmansfield created this revision.
rmansfield added a reviewer: lhames.
rmansfield 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/D106889

Files:
  clang/examples/clang-interpreter/main.cpp

Index: clang/examples/clang-interpreter/main.cpp
===
--- clang/examples/clang-interpreter/main.cpp
+++ clang/examples/clang-interpreter/main.cpp
@@ -50,31 +50,37 @@
 
 class SimpleJIT {
 private:
-  ExecutionSession ES;
+  std::unique_ptr ES;
   std::unique_ptr TM;
   const DataLayout DL;
-  MangleAndInterner Mangle{ES, DL};
-  JITDylib &MainJD{ES.createBareJITDylib("")};
-  RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr};
-  IRCompileLayer CompileLayer{ES, ObjectLayer,
-  std::make_unique(*TM)};
+  MangleAndInterner Mangle;
+  JITDylib &MainJD;
+  RTDyldObjectLinkingLayer ObjectLayer;
+  IRCompileLayer CompileLayer;
 
   static std::unique_ptr createMemMgr() {
 return std::make_unique();
   }
 
   SimpleJIT(
-  std::unique_ptr TM, DataLayout DL,
+  std::unique_ptr ES, std::unique_ptr TM,
+  DataLayout DL,
   std::unique_ptr ProcessSymbolsGenerator)
-  : TM(std::move(TM)), DL(std::move(DL)) {
+  : ES(std::move(ES)), TM(std::move(TM)), DL(std::move(DL)),
+Mangle(*this->ES, this->DL),
+MainJD(this->ES->createBareJITDylib("")),
+ObjectLayer(*this->ES, createMemMgr),
+CompileLayer(*this->ES, ObjectLayer,
+ std::make_unique(*this->TM)) {
+
 llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
 MainJD.addGenerator(std::move(ProcessSymbolsGenerator));
   }
 
 public:
   ~SimpleJIT() {
-if (auto Err = ES.endSession())
-  ES.reportError(std::move(Err));
+if (auto Err = ES->endSession())
+  ES->reportError(std::move(Err));
   }
 
   static Expected> Create() {
@@ -86,6 +92,12 @@
 if (!TM)
   return TM.takeError();
 
+auto EPC = SelfExecutorProcessControl::Create();
+if (!EPC)
+  return EPC.takeError();
+
+auto ES = std::make_unique(std::move(*EPC));
+
 auto DL = (*TM)->createDataLayout();
 
 auto ProcessSymbolsGenerator =
@@ -95,8 +107,9 @@
 if (!ProcessSymbolsGenerator)
   return ProcessSymbolsGenerator.takeError();
 
-return std::unique_ptr(new SimpleJIT(
-std::move(*TM), std::move(DL), std::move(*ProcessSymbolsGenerator)));
+return std::unique_ptr(
+new SimpleJIT(std::move(ES), std::move(*TM), std::move(DL),
+  std::move(*ProcessSymbolsGenerator)));
   }
 
   const TargetMachine &getTargetMachine() const { return *TM; }
@@ -106,7 +119,7 @@
   }
 
   Expected findSymbol(const StringRef &Name) {
-return ES.lookup({&MainJD}, Mangle(Name));
+return ES->lookup({&MainJD}, Mangle(Name));
   }
 
   Expected getSymbolAddress(const StringRef &Name) {
@@ -125,11 +138,11 @@
 int main(int argc, const char **argv) {
   // This just needs to be some symbol in the binary; C++ doesn't
   // allow taking the address of ::main however.
-  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
   std::string Path = GetExecutablePath(argv[0], MainAddr);
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   TextDiagnosticPrinter *DiagClient =
-new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
 
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
@@ -204,7 +217,7 @@
   if (Clang.getHeaderSearchOpts().UseBuiltinIncludes &&
   Clang.getHeaderSearchOpts().ResourceDir.empty())
 Clang.getHeaderSearchOpts().ResourceDir =
-  CompilerInvocation::GetResourcesPath(argv[0], MainAddr);
+CompilerInvocation::GetResourcesPath(argv[0], MainAddr);
 
   // Create and execute the frontend to generate an LLVM bitcode module.
   std::unique_ptr Act(new EmitLLVMOnlyAction());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362070.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,90 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(
+const LocationDescription &Loc, Value *InteropVar,
+omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
+Value *DependenceAddress, bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  Constant *InteropTypeVal = ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription &Loc, Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription &Loc,
+   Value *InteropVar, Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst *OpenMPIRBuilder::createCachedThreadPrivate(
 const LocationDescription &Loc, llvm::Value *Pointer,
 llvm::ConstantInt *Size, const llvm::Twine &Name) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@

[PATCH] D106298: [OpenMP] Creating the `omp_target_num_teams` and `omp_target_thread_limit` attributes to outlined functions

2021-07-27 Thread Jose Manuel Monsalve Diaz via Phabricator via cfe-commits
josemonsalve2 updated this revision to Diff 362074.
josemonsalve2 added a comment.

Fixing tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106298

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_map_codegen_03.cpp
  clang/test/OpenMP/target_num_teams_num_threads_attributes.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_private_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/target_teams_num_teams_codegen.cpp
  clang/test/OpenMP/target_teams_thread_limit_codegen.cpp
  clang/test/OpenMP/teams_codegen.cpp

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


[PATCH] D106890: [z/OS] Make MinGlobalAlign consistent with SystemZ

2021-07-27 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng created this revision.
fanbo-meng requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Remove overriding MinGlobalAlign to 0 for z/OS target to be consistent with 
SystemZ.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106890

Files:
  clang/lib/Basic/Targets/OSTargets.h


Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -796,7 +796,6 @@
 this->UseZeroLengthBitfieldAlignment = true;
 this->UseLeadingZeroLengthBitfield = false;
 this->ZeroLengthBitfieldBoundary = 32;
-this->MinGlobalAlign = 0;
 this->DefaultAlignForAttributeAligned = 128;
   }
 };


Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -796,7 +796,6 @@
 this->UseZeroLengthBitfieldAlignment = true;
 this->UseLeadingZeroLengthBitfield = false;
 this->ZeroLengthBitfieldBoundary = 32;
-this->MinGlobalAlign = 0;
 this->DefaultAlignForAttributeAligned = 128;
   }
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >