[PATCH] D112398: [RISCV] Add ABI testing for Float16.

2021-10-27 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

I'm curious about how we handle `_Float16` here.

My understanding from the psabi 

 and the Zfh draft 
, don't 
we want under `Zfh` + `ilp32f` to pass the float16 directly in a FP register?

So for a case like this

  typedef _Float16 FP;
  typedef struct A { FP a; FP b; } A;
  
  void foo(A);
  
  void bar()
  {
  A a = {1.0, 2.0};
  foo(a);
  }

I'd expect  `Zfh` +  ilp32` to pass an `i32` (which we already do)

  define dso_local void @bar() local_unnamed_addr #0 {
tail call void @foo(i32 1073757184) #2
ret void
  }

and `Zfh` + `ilp32f` (and I understand `ilp32d` too) do

  define dso_local void @bar() local_unnamed_addr #0 {
tail call void @foo(half 1.0e+0.0, half 2.0e+0.0)
ret void
  }

Perhaps it was already decided against using FP regs for `_Float16`?

I think a similar consideration can be done for `rv64` + `Zfh` and `lp64` / 
`lp64f` / `lp64d`, the last two using FP registers.

If this is the case, then I understand a parameter like

  typedef struct A { _Float16 a; float b; } A;

would also be passed as two FP registers in `ilp32f`, `ilp32d`, `lp64f` and 
`lp64d`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112398

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-27 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 382932.
linjamaki added a comment.

Update for changes in D112404 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,100 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain &TC) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation &C, const JobAction &JA,
+const InputInfoList &Inputs,
+const InputInfo &Output,
+const llvm::opt::ArgList &Args) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
+  const ToolChain &HostTC, const llvm::opt::ArgList &Args);
+
+  const llvm::Triple *getAuxTriple() const override {
+return &HostTC.getTriple();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList &Args,
+  llvm::opt::ArgStringList &CC1Args) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+   llvm::opt::ArgStringList &CC1Args) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList &Args) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList &Args) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain &HostTC;
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,288 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Projec

[PATCH] D112404: [SPIR-V] Add translator tool

2021-10-27 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 382931.
linjamaki marked an inline comment as done.
linjamaki added a comment.

Remove `--spirv-ext` and `--spirv-max-version`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112404

Files:
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/SPIRV.cpp
  clang/lib/Driver/ToolChains/SPIRV.h

Index: clang/lib/Driver/ToolChains/SPIRV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/SPIRV.h
@@ -0,0 +1,46 @@
+//===--- SPIRV.h - SPIR-V Tool Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace SPIRV {
+
+void addTranslatorArgs(const llvm::opt::ArgList &InArgs,
+   llvm::opt::ArgStringList &OutArgs);
+
+void constructTranslateCommand(Compilation &C, const Tool &T,
+   const JobAction &JA, const InputInfo &Output,
+   const InputInfo &Input,
+   const llvm::opt::ArgStringList &Args);
+
+class LLVM_LIBRARY_VISIBILITY Translator : public Tool {
+public:
+  Translator(const ToolChain &TC)
+  : Tool("SPIRV::Translator", "translator", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+  bool hasIntegratedAssembler() const override { return true; }
+
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+const char *LinkingOutput) const override;
+};
+
+} // namespace SPIRV
+} // namespace tools
+} // namespace driver
+} // namespace clang
+#endif
Index: clang/lib/Driver/ToolChains/SPIRV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -0,0 +1,48 @@
+//===--- SPIRV.cpp - SPIR-V Tool Implementations *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SPIRV.h"
+#include "CommonArgs.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/InputInfo.h"
+#include "clang/Driver/Options.h"
+
+using namespace clang::driver::tools;
+using namespace llvm::opt;
+
+void SPIRV::constructTranslateCommand(Compilation &C, const Tool &T,
+  const JobAction &JA,
+  const InputInfo &Output,
+  const InputInfo &Input,
+  const llvm::opt::ArgStringList &Args) {
+  llvm::opt::ArgStringList CmdArgs(Args);
+  CmdArgs.push_back(Input.getFilename());
+
+  if (Input.getType() == types::TY_PP_Asm)
+CmdArgs.push_back("-to-binary");
+  if (Output.getType() == types::TY_PP_Asm)
+CmdArgs.push_back("-spirv-text");
+
+  CmdArgs.append({"-o", Output.getFilename()});
+
+  const char *Exec =
+  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
+ Exec, CmdArgs, Input, Output));
+}
+
+void SPIRV::Translator::ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output,
+ const InputInfoList &Inputs,
+ const ArgList &Args,
+ const char *LinkingOutput) const {
+  claimNoWarnArgs(Args);
+  if (Inputs.size() != 1)
+llvm_unreachable("Invalid number of input files.");
+  constructTranslateCommand(C, *this, JA, Output, Inputs[0], {});
+}
Index: clang/lib/Driver/CMakeLists.txt
===
--- clang/lib/Driver/CMakeLists.txt
+++ clang/lib/Driver/CMakeLists.txt
@@ -69,6 +69,7 @@
   ToolChains/PS4CPU.cpp
   ToolChains/RISCVToolchain.cpp
   ToolChains/Solaris.cpp
+  ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http

[PATCH] D112410: [SPIR-V] Add a tool chain for SPIR-V (incomplete)

2021-10-27 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

> Do I read it correctly that you would have no objections for others to rework 
> this patch if needed? :)

Yes, anyone can work on this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112410

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


[PATCH] D112404: [SPIR-V] Add translator tool

2021-10-27 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki marked an inline comment as done.
linjamaki added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1534
+HelpText<"Specify maximum SPIR-V version which can be emitted">;
+def spirv_ext_EQ : CommaJoined<["--"], "spirv-ext">,
+HelpText<"Specify comma separated list of allowed/disallowed SPIR-V "

Anastasia wrote:
> Is this flag expected to be similar to `-cl-ext`?
> 
> https://clang.llvm.org/docs/OpenCLSupport.html#cmdoption-cl-ext
> 
> It might be good to see how those can align? I imagine for HIP you haven't 
> used such flags yet?
> Is this flag expected to be similar to `-cl-ext`?
> 
> https://clang.llvm.org/docs/OpenCLSupport.html#cmdoption-cl-ext
> 
> It might be good to see how those can align? 

It is similar to -cl-ext. I thought it would make sense to have --spirv-ext for 
defining allowed SPIR-V extensions via the clang driver. I did not think that 
having both the -cl-ext and the --spirv-ext at the same time may conflict 
and/or contradict so I’ll remove the options here (--spirv-max-version too). 
Let’s introduce them in D112410 if needed.

> I imagine for HIP you haven't used such flags yet?

HIPSPV tool chain passes --spirv-max-version and --spirv-ext options to the 
LLVM-SPIR-V translator for overriding its defaults.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112404

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


[PATCH] D112652: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG73453e7adecb: [clangd] Avoid expensive checks of buffer 
names in IncludeCleaner (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112652

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -16,6 +16,7 @@
 namespace clangd {
 namespace {
 
+using ::testing::ElementsAre;
 using ::testing::UnorderedElementsAre;
 
 TEST(IncludeCleaner, ReferencedLocations) {
@@ -236,9 +237,8 @@
 
 TEST(IncludeCleaner, VirtualBuffers) {
   TestTU TU;
-  TU.Filename = "foo.cpp";
   TU.Code = R"cpp(
-#include "macro_spelling_in_scratch_buffer.h"
+#include "macros.h"
 
 using flags::FLAGS_FOO;
 
@@ -251,7 +251,7 @@
   // The pasting operator in combination with DEFINE_FLAG will create
   // ScratchBuffer with `flags::FLAGS_FOO` that will have FileID but not
   // FileEntry.
-  TU.AdditionalFiles["macro_spelling_in_scratch_buffer.h"] = R"cpp(
+  TU.AdditionalFiles["macros.h"] = R"cpp(
 #define DEFINE_FLAG(X) \
 namespace flags { \
 int FLAGS_##X; \
@@ -266,18 +266,27 @@
   ParsedAST AST = TU.build();
   auto &SM = AST.getSourceManager();
   auto &Includes = AST.getIncludeStructure();
+
   auto ReferencedFiles = findReferencedFiles(findReferencedLocations(AST), SM);
-  auto Entry = SM.getFileManager().getFile(
-  testPath("macro_spelling_in_scratch_buffer.h"));
-  ASSERT_TRUE(Entry);
-  auto FID = SM.translateFile(*Entry);
-  // No "" FID.
-  EXPECT_THAT(ReferencedFiles, UnorderedElementsAre(FID));
-  // Should not crash due to  "files" missing from include
-  // structure.
-  EXPECT_THAT(
-  getUnused(Includes, translateToHeaderIDs(ReferencedFiles, Includes, SM)),
-  ::testing::IsEmpty());
+  llvm::StringSet<> ReferencedFileNames;
+  for (FileID FID : ReferencedFiles)
+ReferencedFileNames.insert(
+SM.getPresumedLoc(SM.getLocForStartOfFile(FID)).getFilename());
+  // Note we deduped the names as _number_ of s is uninteresting.
+  EXPECT_THAT(ReferencedFileNames.keys(),
+  UnorderedElementsAre("", "",
+   testPath("macros.h")));
+
+  // Should not crash due to FileIDs that are not headers.
+  auto ReferencedHeaders = translateToHeaderIDs(ReferencedFiles, Includes, SM);
+  std::vector ReferencedHeaderNames;
+  for (IncludeStructure::HeaderID HID : ReferencedHeaders)
+ReferencedHeaderNames.push_back(Includes.getRealPath(HID));
+  // Non-header files are gone at this point.
+  EXPECT_THAT(ReferencedHeaderNames, ElementsAre(testPath("macros.h")));
+
+  // Sanity check.
+  EXPECT_THAT(getUnused(Includes, ReferencedHeaders), ::testing::IsEmpty());
 }
 
 } // namespace
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -49,10 +49,13 @@
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
 /// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// The output only includes things SourceManager sees as files (not macro IDs).
+/// This can include ,  etc that are not true files.
 llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
const SourceManager &SM);
 
 /// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+/// FileIDs that are not true files ( etc) are dropped.
 llvm::DenseSet
 translateToHeaderIDs(const llvm::DenseSet &Files,
  const IncludeStructure &Includes, const SourceManager &SM);
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -129,9 +129,7 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-// Check if Loc is not written in a physical file.
-if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc) ||
-SM.isWrittenInCommandLineFile(Loc))
+if (FID.isInvalid())
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {
@@ -142,15 +140,9 @@
 if (!Macros.insert(FID).second)
   return;
 const auto &Exp = SM.getSLocEntry(FID).getExpansion();
-// For token pasting operator in macros, spelling and expansion locations
-// can be within a temporary buffer that Clang creates (scratch space or
-// ScratchB

[clang-tools-extra] 73453e7 - [clangd] Avoid expensive checks of buffer names in IncludeCleaner

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

Author: Sam McCall
Date: 2021-10-28T08:00:57+02:00
New Revision: 73453e7adecbcc7208ceb70d5e55086ffbd1de3a

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

LOG: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

This changes the handling of special buffers ( etc) that
SourceManager treats as files but FileManager does not.

We now include them in findReferencedFiles() and drop them as part of
translateToHeaderIDs(). This pairs more naturally with the data representations
we're using, and so avoids a bunch of converting between representations for
filtering.

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/IncludeCleaner.h
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 156129be22fee..b813c3f2c0417 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -129,9 +129,7 @@ struct ReferencedFiles {
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-// Check if Loc is not written in a physical file.
-if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc) ||
-SM.isWrittenInCommandLineFile(Loc))
+if (FID.isInvalid())
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {
@@ -142,15 +140,9 @@ struct ReferencedFiles {
 if (!Macros.insert(FID).second)
   return;
 const auto &Exp = SM.getSLocEntry(FID).getExpansion();
-// For token pasting operator in macros, spelling and expansion locations
-// can be within a temporary buffer that Clang creates (scratch space or
-// ScratchBuffer). That is not a real file we can include.
-if (!SM.isWrittenInScratchSpace(Exp.getSpellingLoc()))
-  add(Exp.getSpellingLoc());
-if (!SM.isWrittenInScratchSpace(Exp.getExpansionLocStart()))
-  add(Exp.getExpansionLocStart());
-if (!SM.isWrittenInScratchSpace(Exp.getExpansionLocEnd()))
-  add(Exp.getExpansionLocEnd());
+add(Exp.getSpellingLoc());
+add(Exp.getExpansionLocStart());
+add(Exp.getExpansionLocEnd());
   }
 };
 
@@ -249,6 +241,14 @@ getUnused(const IncludeStructure &Structure,
   return Unused;
 }
 
+#ifndef NDEBUG
+// Is FID a ,  etc?
+static bool isSpecialBuffer(FileID FID, const SourceManager &SM) {
+  const SrcMgr::FileInfo &FI = SM.getSLocEntry(FID).getFile();
+  return FI.getName().startswith("<");
+}
+#endif
+
 llvm::DenseSet
 translateToHeaderIDs(const llvm::DenseSet &Files,
  const IncludeStructure &Includes,
@@ -257,7 +257,10 @@ translateToHeaderIDs(const llvm::DenseSet &Files,
   TranslatedHeaderIDs.reserve(Files.size());
   for (FileID FID : Files) {
 const FileEntry *FE = SM.getFileEntryForID(FID);
-assert(FE);
+if (!FE) {
+  assert(isSpecialBuffer(FID, SM));
+  continue;
+}
 const auto File = Includes.getID(FE);
 assert(File);
 TranslatedHeaderIDs.insert(*File);

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.h 
b/clang-tools-extra/clangd/IncludeCleaner.h
index c7dd7efd4ed6f..b797e3c8d6f40 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.h
+++ b/clang-tools-extra/clangd/IncludeCleaner.h
@@ -49,10 +49,13 @@ using ReferencedLocations = llvm::DenseSet;
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
 /// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// The output only includes things SourceManager sees as files (not macro 
IDs).
+/// This can include ,  etc that are not true files.
 llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
const SourceManager &SM);
 
 /// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+/// FileIDs that are not true files ( etc) are dropped.
 llvm::DenseSet
 translateToHeaderIDs(const llvm::DenseSet &Files,
  const IncludeStructure &Includes, const SourceManager 
&SM);

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 99749692c541c..895a2074ad2e7 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -16,6 +16,7 @@ namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::ElementsAre;
 using ::testing::UnorderedElementsAre;
 
 TEST(IncludeCleaner, ReferencedLocations) {
@@ -236,9 +237,8 @@ TEST(IncludeCleaner, GetUnusedHeaders) {
 
 TEST(IncludeCleaner, VirtualBuffers) {
   TestTU TU;
-  TU.Filenam

[PATCH] D111400: [Clang] Implement P2242R3

2021-10-27 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

Lambda capture semantics mean that extensions or inconsistencies in constexpr 
evaluation result in binary-compatibility issues.

  struct NonLit {
NonLit();
  };
  template 
  constexpr int foo() {
return 42;
T t;
  }
  extern int g(void *);
  inline int f(void *p) {
const int x = foo();
auto ff = [=] { return x; };
using ty = decltype(ff);
if (p) {
  return (*(ty *)p)();
}
return g(&ff);
  }
  int g(void *p) { if (!p) return 0; return f(p); }

Notice that GCC reads from the closure object in C++20: 
https://godbolt.org/z/vYs63h8vb.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111400

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


[PATCH] D112481: [Sema] fix nondeterminism in ASTContext::getDeducedTemplateSpecializationType

2021-10-27 Thread Wei Wang via Phabricator via cfe-commits
weiwang added a comment.

This issue has been blocking our internal module re-enablement for some time 
now, and we really appreciate any feedback. We also wonder if only 
`DeducedTemplateSpecializationType` is affected or it could also happen to 
other types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112481

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


[PATCH] D112652: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev 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/D112652/new/

https://reviews.llvm.org/D112652

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


[PATCH] D111833: [clang] Fortify warning for scanf calls with field width too big.

2021-10-27 Thread Michael Benfield via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG15e3d39110fa: [clang] Fortify warning for scanf calls with 
field width too big. (authored by mbenfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111833

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-scanf.c

Index: clang/test/Sema/warn-fortify-scanf.c
===
--- /dev/null
+++ clang/test/Sema/warn-fortify-scanf.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
+
+typedef struct _FILE FILE;
+extern int scanf(const char *format, ...);
+extern int fscanf(FILE *f, const char *format, ...);
+extern int sscanf(const char *input, const char *format, ...);
+
+void call_scanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  scanf("%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 11}}
+  scanf("%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 12}}
+  scanf("%4s %5s %9s", buf20, buf30, buf10);
+  scanf("%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 21}}
+  scanf("%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 22}}
+  scanf("%19s %5s %9s", buf20, buf30, buf10);
+  scanf("%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_sscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  sscanf("a b c", "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  sscanf("a b c", "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  sscanf("a b c", "%4s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  sscanf("a b c", "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  sscanf("a b c", "%19s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_fscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  fscanf(0, "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  fscanf(0, "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  fscanf(0, "%4s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  fscanf(0, "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  fscanf(0, "%19s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%19s %29s %9s", buf20, buf30, buf10);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -408,6 +408,50 @@
 
 namespace {
 
+class ScanfDiagnosticFormatHandler
+: public analyze_format_string::FormatStringHandler {
+  // Accepts the argument index (relative to the first destination index) of the
+  // argument whose size we want.
+  using ComputeSizeFunction =
+  llvm::function_ref(unsigned)>;
+
+  // Accepts the argument index (relative to the first destination index), the
+  // destination size, and the source size).
+  using DiagnoseFunction =
+  llvm::function_ref;
+
+  ComputeSizeFunction ComputeSizeArgument;
+  DiagnoseFunction Diagnose;
+
+public:
+  ScanfDiagnosticFormatHandler(ComputeSizeFunction ComputeSizeArgument,
+   DiagnoseFunction Diagnose)
+  : ComputeSizeArgument(ComputeSizeArgument), Diagnose(Diagnose) {}
+
+  bool Handle

[clang] 15e3d39 - [clang] Fortify warning for scanf calls with field width too big.

2021-10-27 Thread Michael Benfield via cfe-commits

Author: Michael Benfield
Date: 2021-10-28T02:52:03Z
New Revision: 15e3d39110fa4449be4f56196af3bc81b623f3ab

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

LOG: [clang] Fortify warning for scanf calls with field width too big.

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

Added: 
clang/test/Sema/warn-fortify-scanf.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 09482d238ff3..920146f71bd8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -833,6 +833,10 @@ def warn_fortify_source_format_overflow : Warning<
   " but format string expands to at least %2">,
   InGroup;
 
+def warn_fortify_scanf_overflow : Warning<
+  "'%0' may overflow; destination buffer in argument %1 has size "
+  "%2, but the corresponding field width plus NUL byte is %3">,
+  InGroup;
 
 /// main()
 // static main() is not an error in C, just in C++.

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 147f50aeed97..e11966020ae9 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -408,6 +408,50 @@ static bool SemaBuiltinCallWithStaticChain(Sema &S, 
CallExpr *BuiltinCall) {
 
 namespace {
 
+class ScanfDiagnosticFormatHandler
+: public analyze_format_string::FormatStringHandler {
+  // Accepts the argument index (relative to the first destination index) of 
the
+  // argument whose size we want.
+  using ComputeSizeFunction =
+  llvm::function_ref(unsigned)>;
+
+  // Accepts the argument index (relative to the first destination index), the
+  // destination size, and the source size).
+  using DiagnoseFunction =
+  llvm::function_ref;
+
+  ComputeSizeFunction ComputeSizeArgument;
+  DiagnoseFunction Diagnose;
+
+public:
+  ScanfDiagnosticFormatHandler(ComputeSizeFunction ComputeSizeArgument,
+   DiagnoseFunction Diagnose)
+  : ComputeSizeArgument(ComputeSizeArgument), Diagnose(Diagnose) {}
+
+  bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
+const char *StartSpecifier,
+unsigned specifierLen) override {
+auto OptionalFW = FS.getFieldWidth();
+if (OptionalFW.getHowSpecified() !=
+analyze_format_string::OptionalAmount::HowSpecified::Constant)
+  return true;
+
+// We have to write the data plus a NUL byte.
+unsigned SourceSize = OptionalFW.getConstantAmount() + 1;
+
+auto DestSizeAPS = ComputeSizeArgument(FS.getArgIndex());
+if (!DestSizeAPS)
+  return true;
+
+unsigned DestSize = DestSizeAPS->getZExtValue();
+
+if (DestSize < SourceSize)
+  Diagnose(FS.getArgIndex(), DestSize, SourceSize);
+
+return true;
+  }
+};
+
 class EstimateSizeFormatHandler
 : public analyze_format_string::FormatStringHandler {
   size_t Size;
@@ -615,9 +659,12 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
 // (potentially) more strict checking mode. Otherwise, conservatively 
assume
 // type 0.
 int BOSType = 0;
-if (const auto *POS =
-FD->getParamDecl(Index)->getAttr())
-  BOSType = POS->getType();
+// This check can fail for variadic functions.
+if (Index < FD->getNumParams()) {
+  if (const auto *POS =
+  FD->getParamDecl(Index)->getAttr())
+BOSType = POS->getType();
+}
 
 const Expr *ObjArg = TheCall->getArg(Index);
 uint64_t Result;
@@ -642,6 +689,20 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
   unsigned DiagID = 0;
   bool IsChkVariant = false;
 
+  auto GetFunctionName = [&]() {
+StringRef FunctionName = getASTContext().BuiltinInfo.getName(BuiltinID);
+// Skim off the details of whichever builtin was called to produce a better
+// diagnostic, as it's unlikely that the user wrote the __builtin
+// explicitly.
+if (IsChkVariant) {
+  FunctionName = FunctionName.drop_front(std::strlen("__builtin___"));
+  FunctionName = FunctionName.drop_back(std::strlen("_chk"));
+} else if (FunctionName.startswith("__builtin_")) {
+  FunctionName = FunctionName.drop_front(std::strlen("__builtin_"));
+}
+return FunctionName;
+  };
+
   switch (BuiltinID) {
   default:
 return;
@@ -661,6 +722,61 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
 break;
   }
 
+  case Builtin::BIscanf:
+  case Builtin::BIfscanf:
+  case Builtin::BIsscanf: {
+unsigned FormatIndex = 1;
+unsigned DataIndex = 2;
+if (BuiltinID == Builtin::BIscanf) {
+  Fo

[PATCH] D112400: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread Kai Luo via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ea2431d3f10: [clang][compiler-rt][atomics] Add 
`__c11_atomic_fetch_nand` builtin and support… (authored by lkail).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112400

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/atomic-implicit-seq_cst.c
  clang/test/Sema/atomic-ops.c
  compiler-rt/lib/builtins/atomic.c
  compiler-rt/test/builtins/Unit/atomic_test.c

Index: compiler-rt/test/builtins/Unit/atomic_test.c
===
--- compiler-rt/test/builtins/Unit/atomic_test.c
+++ compiler-rt/test/builtins/Unit/atomic_test.c
@@ -96,6 +96,11 @@
 uint32_t __atomic_fetch_xor_4(uint32_t *ptr, uint32_t val, int model);
 uint64_t __atomic_fetch_xor_8(uint64_t *ptr, uint64_t val, int model);
 
+uint8_t __atomic_fetch_nand_1(uint8_t *ptr, uint8_t val, int model);
+uint16_t __atomic_fetch_nand_2(uint16_t *ptr, uint16_t val, int model);
+uint32_t __atomic_fetch_nand_4(uint32_t *ptr, uint32_t val, int model);
+uint64_t __atomic_fetch_nand_8(uint64_t *ptr, uint64_t val, int model);
+
 // We conditionally test the *_16 atomic function variants based on the same
 // condition that compiler_rt (atomic.c) uses to conditionally generate them.
 // Currently atomic.c tests if __SIZEOF_INT128__ is defined (which can be the
@@ -119,6 +124,7 @@
 uint128_t __atomic_fetch_and_16(uint128_t *ptr, uint128_t val, int model);
 uint128_t __atomic_fetch_or_16(uint128_t *ptr, uint128_t val, int model);
 uint128_t __atomic_fetch_xor_16(uint128_t *ptr, uint128_t val, int model);
+uint128_t __atomic_fetch_nand_16(uint128_t *ptr, uint128_t val, int model);
 #else
 typedef uint64_t maxuint_t;
 #endif
@@ -540,6 +546,28 @@
   abort();
 #endif
 
+// Fetch nand.
+
+set_a_values(V + m);
+set_b_values(0);
+b8 = __atomic_fetch_nand_1(&a8, U8(ONES), model);
+if (b8 != U8(V + m) || a8 != U8(~((V + m) & ONES)))
+  abort();
+b16 = __atomic_fetch_nand_2(&a16, U16(ONES), model);
+if (b16 != U16(V + m) || a16 != U16(~((V + m) & ONES)))
+  abort();
+b32 = __atomic_fetch_nand_4(&a32, U32(ONES), model);
+if (b32 != U32(V + m) || a32 != U32(~((V + m) & ONES)))
+  abort();
+b64 = __atomic_fetch_nand_8(&a64, U64(ONES), model);
+if (b64 != U64(V + m) || a64 != U64(~((V + m) & ONES)))
+  abort();
+#ifdef TEST_16
+b128 = __atomic_fetch_nand_16(&a128, ONES, model);
+if (b128 != (V + m) || a128 != ~((V + m) & ONES))
+  abort();
+#endif
+
 // Check signed integer overflow behavior
 
 set_a_values(V + m);
Index: compiler-rt/lib/builtins/atomic.c
===
--- compiler-rt/lib/builtins/atomic.c
+++ compiler-rt/lib/builtins/atomic.c
@@ -336,6 +336,18 @@
 return tmp;\
   }
 
+#define ATOMIC_RMW_NAND(n, lockfree, type) \
+  type __atomic_fetch_nand_##n(type *ptr, type val, int model) {   \
+if (lockfree(ptr)) \
+  return __c11_atomic_fetch_nand((_Atomic(type) *)ptr, val, model);\
+Lock *l = lock_for_pointer(ptr);   \
+lock(l);   \
+type tmp = *ptr;   \
+*ptr = ~(tmp & val);   \
+unlock(l); \
+return tmp;\
+  }
+
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, add, +)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
@@ -351,3 +363,6 @@
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, xor, ^)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
+#define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW_NAND(n, lockfree, type)
+OPTIMISED_CASES
+#undef OPTIMISED_CASE
Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -362,6 +362,13 @@
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_acq_rel);
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_seq_cst);
 
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_relaxed);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_acquire);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_consume);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_release);
+  (void)__c11_atomic_fetch_nand(Ap, val, memory_order_acq_rel);
+  (void)

[clang] 6ea2431 - [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall

2021-10-27 Thread Kai Luo via cfe-commits

Author: Kai Luo
Date: 2021-10-28T02:18:43Z
New Revision: 6ea2431d3f109aefa31cd4d520cc234a5aa5484a

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

LOG: [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and 
support `__atomic_fetch_nand` libcall

Add `__c11_atomic_fetch_nand` builtin to language extensions and support 
`__atomic_fetch_nand` libcall in compiler-rt.

Reviewed By: theraven

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/lib/AST/Expr.cpp
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/atomic-implicit-seq_cst.c
clang/test/Sema/atomic-ops.c
compiler-rt/lib/builtins/atomic.c
compiler-rt/test/builtins/Unit/atomic_test.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 143b2359b58d7..da2c90778ef46 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2866,6 +2866,7 @@ the corresponding C11 operations, are:
 * ``__c11_atomic_fetch_and``
 * ``__c11_atomic_fetch_or``
 * ``__c11_atomic_fetch_xor``
+* ``__c11_atomic_fetch_nand`` (Nand is not presented in )
 * ``__c11_atomic_fetch_max``
 * ``__c11_atomic_fetch_min``
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 874bc655a00b7..7d331a86126f1 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -796,6 +796,7 @@ ATOMIC_BUILTIN(__c11_atomic_fetch_sub, "v.", "t")
 ATOMIC_BUILTIN(__c11_atomic_fetch_and, "v.", "t")
 ATOMIC_BUILTIN(__c11_atomic_fetch_or, "v.", "t")
 ATOMIC_BUILTIN(__c11_atomic_fetch_xor, "v.", "t")
+ATOMIC_BUILTIN(__c11_atomic_fetch_nand, "v.", "t")
 ATOMIC_BUILTIN(__c11_atomic_fetch_max, "v.", "t")
 ATOMIC_BUILTIN(__c11_atomic_fetch_min, "v.", "t")
 BUILTIN(__c11_atomic_thread_fence, "vi", "n")

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index e9ee624e499da..415b6e52b564b 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4695,6 +4695,7 @@ unsigned AtomicExpr::getNumSubExprs(AtomicOp Op) {
   case AO__c11_atomic_fetch_and:
   case AO__c11_atomic_fetch_or:
   case AO__c11_atomic_fetch_xor:
+  case AO__c11_atomic_fetch_nand:
   case AO__c11_atomic_fetch_max:
   case AO__c11_atomic_fetch_min:
   case AO__atomic_fetch_add:

diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index b6722ad4e4f18..326ca8d50533e 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -664,6 +664,7 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
   case AtomicExpr::AO__atomic_nand_fetch:
 PostOp = llvm::Instruction::And; // the NOT is special cased below
 LLVM_FALLTHROUGH;
+  case AtomicExpr::AO__c11_atomic_fetch_nand:
   case AtomicExpr::AO__atomic_fetch_nand:
 Op = llvm::AtomicRMWInst::Nand;
 break;
@@ -906,6 +907,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   case AtomicExpr::AO__c11_atomic_fetch_and:
   case AtomicExpr::AO__c11_atomic_fetch_or:
   case AtomicExpr::AO__c11_atomic_fetch_xor:
+  case AtomicExpr::AO__c11_atomic_fetch_nand:
   case AtomicExpr::AO__c11_atomic_fetch_max:
   case AtomicExpr::AO__c11_atomic_fetch_min:
   case AtomicExpr::AO__opencl_atomic_fetch_and:
@@ -972,6 +974,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
 case AtomicExpr::AO__c11_atomic_fetch_or:
 case AtomicExpr::AO__opencl_atomic_fetch_or:
 case AtomicExpr::AO__atomic_fetch_or:
+case AtomicExpr::AO__c11_atomic_fetch_nand:
 case AtomicExpr::AO__atomic_fetch_nand:
 case AtomicExpr::AO__c11_atomic_fetch_sub:
 case AtomicExpr::AO__opencl_atomic_fetch_sub:
@@ -1211,6 +1214,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
 case AtomicExpr::AO__atomic_nand_fetch:
   PostOp = llvm::Instruction::And; // the NOT is special cased below
   LLVM_FALLTHROUGH;
+case AtomicExpr::AO__c11_atomic_fetch_nand:
 case AtomicExpr::AO__atomic_fetch_nand:
   LibCallName = "__atomic_fetch_nand";
   AddDirectArgument(*this, Args, UseOptimizedLibcall, Val1.getPointer(),

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3eaeae197648a..147f50aeed97f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5287,6 +5287,7 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
   case AtomicExpr::AO__c11_atomic_fetch_and:
   case AtomicExpr::AO__c11_atomic_fetch_or:
   case AtomicExpr::AO__c11_atomic_fetch_xor:
+  case AtomicExpr::AO__c11_atomic_fetch_nand:
   case AtomicExpr

[PATCH] D111863: [libunwind] Add an interface for dynamic .eh_frame registration

2021-10-27 Thread Peter S. Housel via Phabricator via cfe-commits
housel updated this revision to Diff 382884.
housel added a comment.

Added additional comments to `CFI_Parser::decodeFDE`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111863

Files:
  libunwind/src/DwarfParser.hpp
  libunwind/src/libunwind.cpp
  libunwind/src/libunwind_ext.h

Index: libunwind/src/libunwind_ext.h
===
--- libunwind/src/libunwind_ext.h
+++ libunwind/src/libunwind_ext.h
@@ -51,6 +51,9 @@
 extern void __unw_add_dynamic_fde(unw_word_t fde);
 extern void __unw_remove_dynamic_fde(unw_word_t fde);
 
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+
 #if defined(_LIBUNWIND_ARM_EHABI)
 extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*);
 extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context,
Index: libunwind/src/libunwind.cpp
===
--- libunwind/src/libunwind.cpp
+++ libunwind/src/libunwind.cpp
@@ -292,6 +292,35 @@
   // fde is own mh_group
   DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
+
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+  // The eh_frame section start serves as the mh_group
+  unw_word_t mh_group = eh_frame_start;
+  CFI_Parser::CIE_Info cieInfo;
+  CFI_Parser::FDE_Info fdeInfo;
+  auto p = (LocalAddressSpace::pint_t)eh_frame_start;
+  while (true) {
+if (CFI_Parser::decodeFDE(
+LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
+true) == NULL) {
+  DwarfFDECache::add((LocalAddressSpace::pint_t)mh_group,
+fdeInfo.pcStart, fdeInfo.pcEnd,
+fdeInfo.fdeStart);
+  p += fdeInfo.fdeLength;
+} else if (CFI_Parser::parseCIE(
+   LocalAddressSpace::sThisAddressSpace, p, &cieInfo) == NULL) {
+  p += cieInfo.cieLength;
+} else
+  return;
+  }
+}
+
+void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+  // The eh_frame section start serves as the mh_group
+  DwarfFDECache::removeAllIn(
+  (LocalAddressSpace::pint_t)eh_frame_start);
+}
+
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 #endif // !defined(__USING_SJLJ_EXCEPTIONS__)
 
Index: libunwind/src/DwarfParser.hpp
===
--- libunwind/src/DwarfParser.hpp
+++ libunwind/src/DwarfParser.hpp
@@ -154,7 +154,8 @@
   uintptr_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo,
   CIE_Info *cieInfo);
   static const char *decodeFDE(A &addressSpace, pint_t fdeStart,
-   FDE_Info *fdeInfo, CIE_Info *cieInfo);
+   FDE_Info *fdeInfo, CIE_Info *cieInfo,
+   bool useCIEInfo = false);
   static bool parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo,
const CIE_Info &cieInfo, pint_t upToPC,
int arch, PrologInfo *results);
@@ -162,10 +163,14 @@
   static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo);
 };
 
-/// Parse a FDE into a CIE_Info and an FDE_Info
+/// Parse a FDE into a CIE_Info and an FDE_Info. If useCIEInfo is
+/// true, treat cieInfo as already-parsed CIE_Info (whose start offset
+/// must match the one specified by the FDE) rather than parsing the
+/// one indicated within the FDE.
 template 
 const char *CFI_Parser::decodeFDE(A &addressSpace, pint_t fdeStart,
- FDE_Info *fdeInfo, CIE_Info *cieInfo) {
+ FDE_Info *fdeInfo, CIE_Info *cieInfo,
+ bool useCIEInfo) {
   pint_t p = fdeStart;
   pint_t cfiLength = (pint_t)addressSpace.get32(p);
   p += 4;
@@ -181,9 +186,14 @@
 return "FDE is really a CIE"; // this is a CIE not an FDE
   pint_t nextCFI = p + cfiLength;
   pint_t cieStart = p - ciePointer;
-  const char *err = parseCIE(addressSpace, cieStart, cieInfo);
-  if (err != NULL)
-return err;
+  if (useCIEInfo) {
+if (cieInfo->cieStart != cieStart)
+  return "CIE start does not match";
+  } else {
+const char *err = parseCIE(addressSpace, cieStart, cieInfo);
+if (err != NULL)
+  return err;
+  }
   p += 4;
   // Parse pc begin and range.
   pint_t pcStart =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109770: [OpenMP] Declare variants for templates need to match # template args

2021-10-27 Thread Johannes Doerfert 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 rG6cf6fa6ef1c2: [OpenMP] Declare variants for templates need 
to match # template args (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109770

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp

Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+template 
+int template_number_mismatch_1() {
+  return 0;
+}
+
+template 
+int template_number_mismatch_2() {
+  return 1;
+}
+
+#pragma omp begin declare variant match(implementation = {extension(allow_templates)})
+template 
+int template_number_mismatch_1() {
+  return 2;
+}
+template 
+int template_number_mismatch_2() {
+  return 0;
+}
+#pragma omp end declare variant
+
+int test() {
+  // Should return 0.
+  return template_number_mismatch_1() + template_number_mismatch_2();
+}
+
+// CHECK:  |-FunctionTemplateDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:8:1> line:6:5 template_number_mismatch_1
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_1:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 A
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_2:0x[a-z0-9]*]]  col:32 typename depth 0 index 1 B
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_3:0x[a-z0-9]*]]  line:6:5 template_number_mismatch_1 'int ({{.*}})'
+// CHECK-NEXT: | | `-CompoundStmt [[ADDR_4:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-ReturnStmt [[ADDR_5:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_6:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_7:0x[a-z0-9]*]]  line:6:5 used template_number_mismatch_1 'int ({{.*}})'
+// CHECK-NEXT: |   |-TemplateArgument type 'int'
+// CHECK-NEXT: |   | `-BuiltinType [[ADDR_8:0x[a-z0-9]*]] 'int'
+// CHECK-NEXT: |   |-TemplateArgument type 'float'
+// CHECK-NEXT: |   | `-BuiltinType [[ADDR_9:0x[a-z0-9]*]] 'float'
+// CHECK-NEXT: |   `-CompoundStmt [[ADDR_10:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-ReturnStmt [[ADDR_11:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-IntegerLiteral [[ADDR_6]]  'int' 0
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_12:0x[a-z0-9]*]]  line:11:5 template_number_mismatch_2
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_13:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 A
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_14:0x[a-z0-9]*]]  col:32 typename depth 0 index 1 B
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_15:0x[a-z0-9]*]]  line:11:5 template_number_mismatch_2 'int ({{.*}})'
+// CHECK-NEXT: |   `-CompoundStmt [[ADDR_16:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-ReturnStmt [[ADDR_17:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-IntegerLiteral [[ADDR_18:0x[a-z0-9]*]]  'int' 1
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_19:0x[a-z0-9]*]]  col:5 implicit template_number_mismatch_1
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_20:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 Q
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_21:0x[a-z0-9]*]]  col:5 template_number_mismatch_1 'int ({{.*}})'
+// CHECK-NEXT: |   `-OMPDeclareVariantAttr [[ADDR_22:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)}
+// CHECK-NEXT: | `-DeclRefExpr [[ADDR_23:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_24:0x[a-z0-9]*]] 'template_number_mismatch_1[implementation={extension(allow_templates)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_25:0x[a-z0-9]*]]  line:17:1 template_number_mismatch_1[implementation={extension(allow_templates)}]
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_20]]  col:20 typename depth 0 index 0 Q
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_24]]  line:17:1 template_number_mismatch_1[implementation={extension(allow_templates)}] 'int ({{.*}})'
+// CHECK-NEXT: |   `-CompoundStmt [[ADDR_26:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-ReturnStmt [[ADDR_27:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-IntegerLiteral [[ADDR_28:0x[a-z0-9]*]]  'int' 2
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_29:0x[a-z0-9]*]]  col:5 implicit template_number_mismatch_2
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_30:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 Q
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_31:0x[a-z0-9]*]]  col:5 template_number_mismatch_2 'int ({{.*}})'
+// CHECK-NEXT: | | `-OMPDeclareVariantAttr [[ADDR_32:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)}
+// CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_33:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_34:0x[a-z0-9]*]] 'templat

[clang] 6cf6fa6 - [OpenMP] Declare variants for templates need to match # template args

2021-10-27 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2021-10-27T21:04:32-05:00
New Revision: 6cf6fa6ef1c28de0d553a38defa719342774f104

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

LOG: [OpenMP] Declare variants for templates need to match # template args

A declare variant template is only compatible with a base when the
number of template arguments is equal, otherwise our instantiations will
produce nonsensical results.

Exposes as part of D109344.

Reviewed By: JonChesterfield

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

Added: 
clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp

Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3ee913206457d..f5937df17d828 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6731,9 +6731,11 @@ void 
Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
   for (auto *Candidate : Lookup) {
 auto *CandidateDecl = Candidate->getUnderlyingDecl();
 FunctionDecl *UDecl = nullptr;
-if (IsTemplated && isa(CandidateDecl))
-  UDecl = cast(CandidateDecl)->getTemplatedDecl();
-else if (!IsTemplated)
+if (IsTemplated && isa(CandidateDecl)) {
+  auto *FTD = cast(CandidateDecl);
+  if (FTD->getTemplateParameters()->size() == TemplateParamLists.size())
+UDecl = FTD->getTemplatedDecl();
+} else if (!IsTemplated)
   UDecl = dyn_cast(CandidateDecl);
 if (!UDecl)
   continue;

diff  --git 
a/clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp 
b/clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp
new file mode 100644
index 0..831b353e3ae7e
--- /dev/null
+++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_template_4.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump 
%s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump 
%s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+template 
+int template_number_mismatch_1() {
+  return 0;
+}
+
+template 
+int template_number_mismatch_2() {
+  return 1;
+}
+
+#pragma omp begin declare variant match(implementation = 
{extension(allow_templates)})
+template 
+int template_number_mismatch_1() {
+  return 2;
+}
+template 
+int template_number_mismatch_2() {
+  return 0;
+}
+#pragma omp end declare variant
+
+int test() {
+  // Should return 0.
+  return template_number_mismatch_1() + 
template_number_mismatch_2();
+}
+
+// CHECK:  |-FunctionTemplateDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, 
line:8:1> line:6:5 template_number_mismatch_1
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_1:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 A
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_2:0x[a-z0-9]*]]  col:32 typename depth 0 index 1 B
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_3:0x[a-z0-9]*]]  
line:6:5 template_number_mismatch_1 'int ({{.*}})'
+// CHECK-NEXT: | | `-CompoundStmt [[ADDR_4:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-ReturnStmt [[ADDR_5:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_6:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_7:0x[a-z0-9]*]]  
line:6:5 used template_number_mismatch_1 'int ({{.*}})'
+// CHECK-NEXT: |   |-TemplateArgument type 'int'
+// CHECK-NEXT: |   | `-BuiltinType [[ADDR_8:0x[a-z0-9]*]] 'int'
+// CHECK-NEXT: |   |-TemplateArgument type 'float'
+// CHECK-NEXT: |   | `-BuiltinType [[ADDR_9:0x[a-z0-9]*]] 'float'
+// CHECK-NEXT: |   `-CompoundStmt [[ADDR_10:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-ReturnStmt [[ADDR_11:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-IntegerLiteral [[ADDR_6]]  'int' 0
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_12:0x[a-z0-9]*]]  line:11:5 template_number_mismatch_2
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_13:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 A
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_14:0x[a-z0-9]*]]  col:32 typename depth 0 index 1 B
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_15:0x[a-z0-9]*]]  
line:11:5 template_number_mismatch_2 'int ({{.*}})'
+// CHECK-NEXT: |   `-CompoundStmt [[ADDR_16:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-ReturnStmt [[ADDR_17:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-IntegerLiteral [[ADDR_18:0x[a-z0-9]*]]  'int' 
1
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_19:0x[a-z0-9]*]]  col:5 implicit template_number_mismatch_1
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_20:0x[a-z0-9]*]]  col:20 typename depth 0 index 0 Q
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_21:0x[a-z0-9]*]]  
col:5 template_number_mismatch_1 'int ({{.*}})'
+// CHECK-NEXT: |   `-OMPDeclareVariantAttr [[ADDR_22:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)}
+// CHECK-NEXT: |   

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.cpp:112
 return 0;
-  assert(RVVVectorBitsMax >= 128 && RVVVectorBitsMax <= 65536 &&
+  assert(RVVVectorBitsMax >= 32 && RVVVectorBitsMax <= 65536 &&
  isPowerOf2_32(RVVVectorBitsMax) &&

HsiangKai wrote:
> craig.topper wrote:
> > The max should be greater than ZvlLen right?
> Should it be less than or equal to ZvlLen? I would suggest to return 0 when 
> `RVVVectorBitsMax > ZvlLen`.
> The value also needs to `>= 64`.
@HsiangKai I think you mis-typed the equation? It should be `RVVVectorBitsMax < 
ZvlLen` ;)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

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


[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382880.
eopXD added a comment.

Update code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s
@@ -35,14 +35,14 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbr %s -o - | FileCheck --check-pref

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-27 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 382879.
eopXD added a comment.

Update code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s
@@ -35,14 +35,14 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbr %s -o - | FileCheck --check-pref

[PATCH] D112682: [openmp][nfc] Subset of D112680

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

Change takes the bulk of EmitNVPTXDevicePrintfCallExpr into a helper function, 
and adjusts it to also return the size of the alloca for use in D112680 
. NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112682

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


[PATCH] D112682: [openmp][nfc] Subset of D112680, landing would clean up diff

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield created this revision.
JonChesterfield added reviewers: jdoerfert, tianshilei1992, jhuber6, ye-luo, 
ronlieb, pdhaliwal.
Herald added subscribers: guansong, yaxunl.
JonChesterfield requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

A refactor to share code in CGGPUBuiltin renders poorly
on phabricator, splitting that part out as this diff to help review.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112682

Files:
  clang/lib/CodeGen/CGGPUBuiltin.cpp

Index: clang/lib/CodeGen/CGGPUBuiltin.cpp
===
--- clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -21,13 +21,14 @@
 using namespace clang;
 using namespace CodeGen;
 
-static llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
+namespace {
+llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
   llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
 llvm::Type::getInt8PtrTy(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
-  if (auto* F = M.getFunction("vprintf")) {
+  if (auto *F = M.getFunction("vprintf")) {
 // Our CUDA system header declares vprintf with the right signature, so
 // nobody else should have been able to declare vprintf with a bogus
 // signature.
@@ -66,39 +67,24 @@
 //
 // Note that by the time this function runs, E's args have already undergone the
 // standard C vararg promotion (short -> int, float -> double, etc.).
-RValue
-CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const CallExpr *E,
-   ReturnValueSlot ReturnValue) {
-  assert(getTarget().getTriple().isNVPTX());
-  assert(E->getBuiltinCallee() == Builtin::BIprintf);
-  assert(E->getNumArgs() >= 1); // printf always has at least one arg.
 
-  const llvm::DataLayout &DL = CGM.getDataLayout();
-  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+std::pair
+packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const CallArgList &Args) {
 
-  CallArgList Args;
-  EmitCallArgs(Args,
-   E->getDirectCallee()->getType()->getAs(),
-   E->arguments(), E->getDirectCallee(),
-   /* ParamsToSkip = */ 0);
-
-  // We don't know how to emit non-scalar varargs.
-  if (llvm::any_of(llvm::drop_begin(Args), [&](const CallArg &A) {
-return !A.getRValue(*this).isScalar();
-  })) {
-CGM.ErrorUnsupported(E, "non-scalar arg to printf");
-return RValue::get(llvm::ConstantInt::get(IntTy, 0));
-  }
+  const llvm::DataLayout &DL = CGF->CGM.getDataLayout();
+  llvm::LLVMContext &Ctx = CGF->CGM.getLLVMContext();
+  CGBuilderTy &Builder = CGF->Builder;
 
   // Construct and fill the args buffer that we'll pass to vprintf.
   llvm::Value *BufferPtr;
   if (Args.size() <= 1) {
-// If there are no args, pass a null pointer to vprintf.
+// If there are no args, pass a null pointer and size 0
 BufferPtr = llvm::ConstantPointerNull::get(llvm::Type::getInt8PtrTy(Ctx));
+return {BufferPtr, llvm::TypeSize::Fixed(0)};
   } else {
 llvm::SmallVector ArgTypes;
 for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I)
-  ArgTypes.push_back(Args[I].getRValue(*this).getScalarVal()->getType());
+  ArgTypes.push_back(Args[I].getRValue(*CGF).getScalarVal()->getType());
 
 // Using llvm::StructType is correct only because printf doesn't accept
 // aggregates.  If we had to handle aggregates here, we'd have to manually
@@ -106,18 +92,43 @@
 // that the alignment of the llvm type was the same as the alignment of the
 // clang type.
 llvm::Type *AllocaTy = llvm::StructType::create(ArgTypes, "printf_args");
-llvm::Value *Alloca = CreateTempAlloca(AllocaTy);
+llvm::Value *Alloca = CGF->CreateTempAlloca(AllocaTy);
 
 for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I) {
   llvm::Value *P = Builder.CreateStructGEP(AllocaTy, Alloca, I - 1);
-  llvm::Value *Arg = Args[I].getRValue(*this).getScalarVal();
+  llvm::Value *Arg = Args[I].getRValue(*CGF).getScalarVal();
   Builder.CreateAlignedStore(Arg, P, DL.getPrefTypeAlign(Arg->getType()));
 }
 BufferPtr = Builder.CreatePointerCast(Alloca, llvm::Type::getInt8PtrTy(Ctx));
+return {BufferPtr, DL.getTypeAllocSize(AllocaTy)};
+  }
+}
+} // namespace
+
+RValue
+CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const CallExpr *E,
+   ReturnValueSlot ReturnValue) {
+  assert(getTarget().getTriple().isNVPTX());
+  assert(E->getBuiltinCallee() == Builtin::BIprintf);
+  assert(E->getNumArgs() >= 1); // printf always has at least one arg.
+
+  CallArgList Args;
+  EmitCallArgs(Args,
+   E->getDirectCallee()->getType()->getAs(),
+   E->arguments(), E->getDirectCallee(),
+   

[PATCH] D112680: [OpenMP] Lower printf to __llvm_omp_vprintf

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

New runtime failing CI suggests it may take some iteration to land, so reworked 
this to make sense with or without it.

Doesn't make much difference to nvptx - printf still ultimately resolves to the 
same vprintf function as before - but a lot of tests that were previously 
disabled for amdgpu because references to printf were a linker error will now 
build and run, some of them successfully.




Comment at: openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip:189
+int32_t __llvm_omp_vprintf(const char *Format, void *Arguments, uint32_t) {
+  return 1;
+}

this should be -1, for 'error'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

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


[PATCH] D112680: [OpenMP] Lower printf to __llvm_omp_vprintf

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 382873.
JonChesterfield added a comment.

- rebase to not require new runtime, stubs now return error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -2,8 +2,8 @@
 
 // REQUIRES: unified_shared_memory
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -3,8 +3,8 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -3,7 +3,7 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -2,7 +2,7 @@
 // XFAIL: nvptx64-nvidia-cuda
 // XFAIL: nvptx64-nvidia-cuda-newRTL
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 
 #include 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -7,7 +7,7 @@
 
 // RUN: %libomptarget-compile-run-and-check-generic
 
-// amdgcn does not have printf definition
+// amdgpu does not have a working printf definition
 // XFAIL: amdgcn-amd-amdhsa
 
 #include 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openmp/libomptarget/test/offloading/bug50022.cpp
@@ -1,7 +1,5 @@
 // RUN: %libomptarget-compilexx-and-run-generic
 
-// UNSUPPORTED: amdgcn-amd-amdhsa
-
 #include 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- openmp/libomptarget/test/offloading/bug49021.cpp
+++ openmp/libomptarget/test/offloading/bug49021.cpp
@@ -1,7 +1,7 @@
 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
 
-// Wrong results on amdgcn
-// UNSUPPORTED: amdgcn-amd-amdhsa
+// Wrong results on amdgpu
+// XFAIL: amdgcn-amd-amdhsa
 
 #include 
 
Index: openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
===
--- openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
+++ openmp/libomptarget/test/mapping/reduction_i

[PATCH] D112227: [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a reviewer: ronlieb.
JonChesterfield added a comment.

Tagging Ron as this is current stuck on the mystery of passing locally and 
failing CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112227

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


[PATCH] D112680: [OpenMP] Lower printf to __llvm_omp_vprintf

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

Makes more sense with D112227  landed, but 
probably worthwhile just for the old runtime as it removes the link failure 
from all the tests that use printf.




Comment at: clang/lib/CodeGen/CGGPUBuiltin.cpp:94
+std::pair
+packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const CallArgList &Args) {
 

This packArgsIntoNVPTXFormatBuffer helper could/should be factored out as a 
first patch to make the minimal change to EmitNVPTXDevicePrintfCallExpr clearer 
in the diff



Comment at: openmp/libomptarget/DeviceRTL/include/Debug.h:36
 
-#define PRINTF(fmt, ...) (void)printf(fmt, __VA_ARGS__);
+#define PRINTF(fmt, ...) (void)printf(fmt, ##__VA_ARGS__);
 #define PRINT(str) PRINTF("%s", str)

the ## could be rolled into some other change, it makes PRINTF("no args") work, 
at which point we probably don't need/want #define PRINT()



Comment at: openmp/libomptarget/DeviceRTL/include/Interface.h:351
+/// Printf
+int32_t __llvm_omp_vprintf(const char *Format, void *Arguments, uint32_t Size);
 }

Possibly not a good thing to have in the interface


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

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


[PATCH] D112680: [OpenMP] Lower printf to __llvm_omp_vprintf

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield created this revision.
JonChesterfield added reviewers: jdoerfert, tianshilei1992, jhuber6, ye-luo, 
ronlieb, pdhaliwal.
Herald added subscribers: asavonic, kerbowa, guansong, tpr, yaxunl, mgorny, 
nhaehnle, jvesely.
JonChesterfield requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

Extension of D112504 . Lower amdgpu printf to 
`__llvm_omp_vprintf`
which takes the same const char*, void* arguments as cuda vprintf and also
passes the size of the void* alloca which will be needed by a non-stub
implementation of `__llvm_omp_vprintf` for amdgpu.

This removes the amdgpu link error on any printf in a target region in favour
of silently compiling code that doesn't print anything to stdout.

The exact set of changes to check-openmp probably needs revision before commit


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112680

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -2,8 +2,9 @@
 
 // REQUIRES: unified_shared_memory
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -3,8 +3,9 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -3,7 +3,7 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -2,7 +2,7 @@
 // XFAIL: nvptx64-nvidia-cuda
 // XFAIL: nvptx64-nvidia-cuda-newRTL
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 
 #include 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -7,7 +7,7 @@
 
 // RUN: %libomptarget-compile-run-and-check-generic
 
-// amdgcn does not have printf definition
+// amdgpu does not have a working printf definition
 // XFAIL: amdgcn-amd-amdhsa
 
 #include 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openm

Maintenance works at llvm lab today

2021-10-27 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM lab and build bot will be unavailable for about 3 hours starting from
6:00 PM PST today for lab maintenance work.

Thank you for understanding.

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


[PATCH] D112227: [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 382866.
JonChesterfield added a comment.

- fix new+old test enabling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112227

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/delete_inf_refcount.c
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug49334.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/global_constructor.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -4,6 +4,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -5,6 +5,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -5,6 +5,7 @@
 
 // Fails on amdgcn with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -4,6 +4,7 @@
 
 // Fails on amdgcn with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -9,6 +9,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/global_constructor.cpp
===
--- openmp/libomptarget/test/offloading/global_constructor.cpp
+++ openmp/libomptarget/test/offloading/global_constructor.cpp
@@ -2,6 +2,7 @@
 
 // Fails in DAGToDAG on an address space problem
 // UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openmp/libomptarget/test/offloading/bug50022.cpp
@@ -1,6 +1,7 @@
 // RUN: %libomptarget-compilexx-and-run-generic
 
 // UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug49334.cpp
===
--- openmp/libomptarget/test/offloading/bug49334.cpp
+++ openmp/libomptarget/test/offloading/bug49334.cpp
@@ -2,7 +2,7 @@
 
 // Currently hangs on amdgpu
 // UNSUPPORTED: amdgcn-amd-amdhsa
-
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 // UNSUPPORTED: x86_64-pc-linux-gnu
 
 #include 
Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- openmp/libomptarget/test/offloadi

[PATCH] D112227: [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 382864.
JonChesterfield added a comment.

- Reintroduce syncThreadsAligned, dropped in git merge conflict


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112227

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/delete_inf_refcount.c
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug49334.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/global_constructor.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -4,6 +4,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -5,6 +5,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -5,6 +5,7 @@
 
 // Fails on amdgcn with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -4,6 +4,7 @@
 
 // Fails on amdgcn with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -9,6 +9,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/global_constructor.cpp
===
--- openmp/libomptarget/test/offloading/global_constructor.cpp
+++ openmp/libomptarget/test/offloading/global_constructor.cpp
@@ -2,6 +2,7 @@
 
 // Fails in DAGToDAG on an address space problem
 // UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openmp/libomptarget/test/offloading/bug50022.cpp
@@ -1,6 +1,7 @@
 // RUN: %libomptarget-compilexx-and-run-generic
 
 // UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug49334.cpp
===
--- openmp/libomptarget/test/offloading/bug49334.cpp
+++ openmp/libomptarget/test/offloading/bug49334.cpp
@@ -2,7 +2,7 @@
 
 // Currently hangs on amdgpu
 // UNSUPPORTED: amdgcn-amd-amdhsa
-
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 // UNSUPPORTED: x86_64-pc-linux-gnu
 
 #include 
Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
-

[PATCH] D112227: [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added inline comments.



Comment at: openmp/libomptarget/DeviceRTL/src/Synchronization.cpp:196
 
-void syncThreadsAligned() { syncThreads(); }
-
-void fenceTeam(int Ordering) { __builtin_amdgcn_fence(Ordering, "workgroup"); }
-
-void fenceKernel(int Ordering) { __builtin_amdgcn_fence(Ordering, "agent"); }
-
-void fenceSystem(int Ordering) { __builtin_amdgcn_fence(Ordering, ""); }
+// TODO: Don't have wavefront lane locks. Possibly can't have them.
+void unsetLock(omp_lock_t *) { __builtin_trap(); }

Error here - syncThreadsAligned is deleted but should not be


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112227

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


[PATCH] D112098: [ASan] Added stack safety support in address sanitizer.

2021-10-27 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added inline comments.



Comment at: llvm/include/llvm/Analysis/StackSafetyAnalysis.h:93
+  bool invalidate(Module &, const PreservedAnalyses &,
+  ModuleAnalysisManager::Invalidator &) {
+return false;

vitalybuka wrote:
> vitalybuka wrote:
> > we still can't do that, some passes can make results irrelevant
> Looks like only immutable analysis can be used through proxy, and this 
> analysis cannot be immutable.
> Maybe we have to convert Asan into ModulePass, like HWAsan.
> Any other ideas? @eugenis @pcc @morehouse 
Is the problem here that an invalidated analysis needs to be rerun, and the 
module-to-function proxy does not know how to do that?

TBH, I'm not sure how big the performance benefits of a function pass are. With 
the amount of time we've sunk in working around function pass requirements and 
I'd say just go for it.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112098

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


[PATCH] D108479: [Clang] Add __builtin_addressof_nocfi

2021-10-27 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/AST/APValue.cpp:133
+void APValue::LValueBase::setNoCFIValue(bool NoCFI) {
+  if (is()) {
+Local.NoCFIValue = NoCFI;

Remove braces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108479

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


[PATCH] D112227: [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield reopened this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

Didn't fare very well under CI, investigating.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112227

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


[clang] 6c7b203 - Revert "[libomptarget] Build DeviceRTL for amdgpu"

2021-10-27 Thread Jon Chesterfield via cfe-commits

Author: Jon Chesterfield
Date: 2021-10-28T01:01:53+01:00
New Revision: 6c7b203d1d7000269215ab5b3d329ab03dc85e42

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

LOG: Revert "[libomptarget] Build DeviceRTL for amdgpu"
 - more tests failing on CI than failed locally when writing this patch

This reverts commit 33427fdb7b52b79ce5e25b7e14e0f1a44d876bd2.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
openmp/libomptarget/DeviceRTL/CMakeLists.txt
openmp/libomptarget/DeviceRTL/src/Configuration.cpp
openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
openmp/libomptarget/test/mapping/data_member_ref.cpp
openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
openmp/libomptarget/test/mapping/delete_inf_refcount.c
openmp/libomptarget/test/mapping/lambda_by_value.cpp
openmp/libomptarget/test/mapping/ompx_hold/struct.c
openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
openmp/libomptarget/test/offloading/bug49021.cpp
openmp/libomptarget/test/offloading/bug49334.cpp
openmp/libomptarget/test/offloading/bug50022.cpp
openmp/libomptarget/test/offloading/global_constructor.cpp
openmp/libomptarget/test/offloading/host_as_target.c
openmp/libomptarget/test/unified_shared_memory/api.c
openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
openmp/libomptarget/test/unified_shared_memory/close_modifier.c
openmp/libomptarget/test/unified_shared_memory/shared_update.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b138000f8cf2..5400e2617729 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -252,7 +252,7 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   std::string BitcodeSuffix;
   if (DriverArgs.hasFlag(options::OPT_fopenmp_target_new_runtime,
  options::OPT_fno_openmp_target_new_runtime, false))
-BitcodeSuffix = "new-amdgpu-" + GPUArch;
+BitcodeSuffix = "new-amdgcn-" + GPUArch;
   else
 BitcodeSuffix = "amdgcn-" + GPUArch;
 

diff  --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt 
b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index 419c64d38116..a4f9862fb09b 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -226,5 +226,6 @@ foreach(sm ${nvptx_sm_list})
 endforeach()
 
 foreach(mcpu ${amdgpu_mcpus})
-  compileDeviceRTLLibrary(${mcpu} amdgpu -target amdgcn-amd-amdhsa 
-D__AMDGCN__ -fvisibility=default -nogpulib)
+  # require D112227 or similar to enable the compilation for amdgpu
+  # compileDeviceRTLLibrary(${mcpu} amdgpu -target amdgcn-amd-amdhsa 
-D__AMDGCN__ -fvisibility=default -nogpulib)
 endforeach()

diff  --git a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp 
b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
index f7c61dc013cf..2b6f20fb1732 100644
--- a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
@@ -20,9 +20,9 @@ using namespace _OMP;
 
 #pragma omp declare target
 
-extern uint32_t __omp_rtl_debug_kind; // defined by CGOpenMPRuntimeGPU
+extern uint32_t __omp_rtl_debug_kind;
 
-// TODO: We want to change the name as soon as the old runtime is gone.
+// TOOD: We want to change the name as soon as the old runtime is gone.
 DeviceEnvironmentTy CONSTANT(omptarget_device_environment)
 __attribute__((used));
 

diff  --git a/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp 
b/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
index 931dffcaa131..46e7701a4872 100644
--- a/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
@@ -68,23 +68,8 @@ uint64_t atomicAdd(uint64_t *Address, uint64_t Val, int 
Ordering) {
 ///{
 #pragma omp begin declare variant match(device = {arch(amdgcn)})
 
-uint32_t atomicInc(uint32_t *A, uint32_t V, int Ordering) {
-  // builtin_amdgcn_atomic_inc32 should expand to this switch when
-  // passed a runtime value, but does not do so yet. Workaround here.
-  switch (Ordering) {
-  default:
-__builtin_unreachable();
-  case __ATOMIC_RELAXED:
-return __builtin_amdgcn_atomic_inc32(A, V, __ATOMIC_RELAXED, "");
-  case __ATOMIC_ACQUIRE:
-return __builtin_amdgcn_atomic_inc32(A, V, __ATOMIC_ACQUIRE, "");
-  case __ATOMIC_RELEASE:
-return __builtin_amdgcn_atomic_inc32(A, V, __ATOMIC_RELEASE, "");
-  case __ATOMIC_ACQ_REL:
-return __builtin_amdgcn_atomic_inc32(A, 

[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Nick Desaulniers 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 rGd7e089f2d6a5: [ARM] Use hardware TLS register in Thumb2 mode 
when -mtp=cp15 is passed (authored by ardb, committed by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112600

Files:
  llvm/lib/Target/ARM/ARMInstrThumb.td
  llvm/lib/Target/ARM/ARMInstrThumb2.td
  llvm/test/CodeGen/ARM/readtp.ll
  llvm/test/CodeGen/ARM/thread_pointer.ll


Index: llvm/test/CodeGen/ARM/thread_pointer.ll
===
--- llvm/test/CodeGen/ARM/thread_pointer.ll
+++ llvm/test/CodeGen/ARM/thread_pointer.ll
@@ -1,4 +1,7 @@
-; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
+; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck 
%s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | 
FileCheck %s -check-prefix=CHECK-HARD
 
 declare i8* @llvm.thread.pointer()
 
@@ -8,5 +11,6 @@
   ret i8* %tmp1
 }
 
-; CHECK: bl __aeabi_read_tp
+; CHECK-SOFT: bl __aeabi_read_tp
+; CHECK-HARD: mrc p15, #0, {{r[0-9]+}}, c13, c0, #3
 
Index: llvm/test/CodeGen/ARM/readtp.ll
===
--- llvm/test/CodeGen/ARM/readtp.ll
+++ llvm/test/CodeGen/ARM/readtp.ll
@@ -1,5 +1,7 @@
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | 
FileCheck %s -check-prefix=CHECK-HARD
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | 
FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s 
-check-prefix=CHECK-SOFT
 
 
 ; __thread int counter;
Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4671,6 +4671,9 @@
 }
 
 
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 
//===--===//
 // ARMv8.1 Privilege Access Never extension
Index: llvm/lib/Target/ARM/ARMInstrThumb.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb.td
+++ llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1520,6 +1520,7 @@
 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
   [(set R0, ARMthread_pointer)]>,
+  Requires<[IsThumb, IsReadTPSoft]>,
   Sched<[WriteBr]>;
 
 
//===--===//


Index: llvm/test/CodeGen/ARM/thread_pointer.ll
===
--- llvm/test/CodeGen/ARM/thread_pointer.ll
+++ llvm/test/CodeGen/ARM/thread_pointer.ll
@@ -1,4 +1,7 @@
-; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
+; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
 
 declare i8* @llvm.thread.pointer()
 
@@ -8,5 +11,6 @@
   ret i8* %tmp1
 }
 
-; CHECK: bl __aeabi_read_tp
+; CHECK-SOFT: bl __aeabi_read_tp
+; CHECK-HARD: mrc p15, #0, {{r[0-9]+}}, c13, c0, #3
 
Index: llvm/test/CodeGen/ARM/readtp.ll
===
--- llvm/test/CodeGen/ARM/readtp.ll
+++ llvm/test/CodeGen/ARM/readtp.ll
@@ -1,5 +1,7 @@
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
 
 
 ; __thread int counter;
Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4671,6 +4671,9 @@
 }
 
 

[PATCH] D112227: [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33427fdb7b52: [libomptarget] Build DeviceRTL for amdgpu 
(authored by JonChesterfield).

Changed prior to commit:
  https://reviews.llvm.org/D112227?vs=382446&id=382853#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112227

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/delete_inf_refcount.c
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug49334.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/global_constructor.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -4,6 +4,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -5,6 +5,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -5,6 +5,7 @@
 
 // Fails on amdgcn with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -4,6 +4,7 @@
 
 // Fails on amdgcn with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -9,6 +9,7 @@
 
 // amdgcn does not have printf definition
 // XFAIL: amdgcn-amd-amdhsa
+// XFAIL: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/global_constructor.cpp
===
--- openmp/libomptarget/test/offloading/global_constructor.cpp
+++ openmp/libomptarget/test/offloading/global_constructor.cpp
@@ -2,6 +2,7 @@
 
 // Fails in DAGToDAG on an address space problem
 // UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openmp/libomptarget/test/offloading/bug50022.cpp
@@ -1,6 +1,7 @@
 // RUN: %libomptarget-compilexx-and-run-generic
 
 // UNSUPPORTED: amdgcn-amd-amdhsa
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug49334.cpp
===
--- openmp/libomptarget/test/offloading/bug49334.cpp
+++ openmp/libomptarget/test/offloading/bug49334.cpp
@@ -2,7 +2,7 @@
 
 // Currently hangs on amdgpu
 // UNSUPPORTED: amdgcn-amd-amdhsa
-
+// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
 // UNSUPPORTED: x86_64-pc-linux-gnu
 
 #include 
Index: openm

[clang] 33427fd - [libomptarget] Build DeviceRTL for amdgpu

2021-10-27 Thread Jon Chesterfield via cfe-commits

Author: Jon Chesterfield
Date: 2021-10-28T00:41:45+01:00
New Revision: 33427fdb7b52b79ce5e25b7e14e0f1a44d876bd2

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

LOG: [libomptarget] Build DeviceRTL for amdgpu

Passes same tests as the current deviceRTL. Includes cmake change from D111987.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
openmp/libomptarget/DeviceRTL/CMakeLists.txt
openmp/libomptarget/DeviceRTL/src/Configuration.cpp
openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
openmp/libomptarget/test/mapping/data_member_ref.cpp
openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
openmp/libomptarget/test/mapping/delete_inf_refcount.c
openmp/libomptarget/test/mapping/lambda_by_value.cpp
openmp/libomptarget/test/mapping/ompx_hold/struct.c
openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
openmp/libomptarget/test/offloading/bug49021.cpp
openmp/libomptarget/test/offloading/bug49334.cpp
openmp/libomptarget/test/offloading/bug50022.cpp
openmp/libomptarget/test/offloading/global_constructor.cpp
openmp/libomptarget/test/offloading/host_as_target.c
openmp/libomptarget/test/unified_shared_memory/api.c
openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
openmp/libomptarget/test/unified_shared_memory/close_modifier.c
openmp/libomptarget/test/unified_shared_memory/shared_update.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 5400e2617729..b138000f8cf2 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -252,7 +252,7 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   std::string BitcodeSuffix;
   if (DriverArgs.hasFlag(options::OPT_fopenmp_target_new_runtime,
  options::OPT_fno_openmp_target_new_runtime, false))
-BitcodeSuffix = "new-amdgcn-" + GPUArch;
+BitcodeSuffix = "new-amdgpu-" + GPUArch;
   else
 BitcodeSuffix = "amdgcn-" + GPUArch;
 

diff  --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt 
b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index a4f9862fb09b..419c64d38116 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -226,6 +226,5 @@ foreach(sm ${nvptx_sm_list})
 endforeach()
 
 foreach(mcpu ${amdgpu_mcpus})
-  # require D112227 or similar to enable the compilation for amdgpu
-  # compileDeviceRTLLibrary(${mcpu} amdgpu -target amdgcn-amd-amdhsa 
-D__AMDGCN__ -fvisibility=default -nogpulib)
+  compileDeviceRTLLibrary(${mcpu} amdgpu -target amdgcn-amd-amdhsa 
-D__AMDGCN__ -fvisibility=default -nogpulib)
 endforeach()

diff  --git a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp 
b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
index 2b6f20fb1732..f7c61dc013cf 100644
--- a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp
@@ -20,9 +20,9 @@ using namespace _OMP;
 
 #pragma omp declare target
 
-extern uint32_t __omp_rtl_debug_kind;
+extern uint32_t __omp_rtl_debug_kind; // defined by CGOpenMPRuntimeGPU
 
-// TOOD: We want to change the name as soon as the old runtime is gone.
+// TODO: We want to change the name as soon as the old runtime is gone.
 DeviceEnvironmentTy CONSTANT(omptarget_device_environment)
 __attribute__((used));
 

diff  --git a/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp 
b/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
index c77e766ae6ca..33e2194b25f3 100644
--- a/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
@@ -68,8 +68,23 @@ uint64_t atomicAdd(uint64_t *Address, uint64_t Val, int 
Ordering) {
 ///{
 #pragma omp begin declare variant match(device = {arch(amdgcn)})
 
-uint32_t atomicInc(uint32_t *Address, uint32_t Val, int Ordering) {
-  return __builtin_amdgcn_atomic_inc32(Address, Val, Ordering, "");
+uint32_t atomicInc(uint32_t *A, uint32_t V, int Ordering) {
+  // builtin_amdgcn_atomic_inc32 should expand to this switch when
+  // passed a runtime value, but does not do so yet. Workaround here.
+  switch (Ordering) {
+  default:
+__builtin_unreachable();
+  case __ATOMIC_RELAXED:
+return __builtin_amdgcn_atomic_inc32(A, V, __ATOMIC_RELAXED, "");
+  case __ATOMIC_ACQUIRE:
+return __builtin_amdgcn_atomic_inc32(A, V, __ATOMIC_ACQUIRE, "");
+  case __AT

[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D112600#3091959 , @ardb wrote:

> Thanks all. Could someone with commit access please merge this? Thanks.

Sure thing; I'll pick it up. Thanks again for the patch!


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

https://reviews.llvm.org/D112600

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


[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Ard Biesheuvel via Phabricator via cfe-commits
ardb added a comment.

Thanks all. Could someone with commit access please merge this? Thanks.


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

https://reviews.llvm.org/D112600

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


[PATCH] D111400: [Clang] Implement P2242R3

2021-10-27 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

A different "ouch" (and, yes, this is a regression from this patch):

  auto f = [](bool b) {
if (b) return 42;
static int x = 0;
return x;
  };
  constexpr int x = f(true);
  const int *p = &x;

Generates no diagnostics with this patch even with `-std=c++17 -Wall -Wextra 
-pedantic-errors`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111400

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


[PATCH] D111833: [clang] Fortify warning for scanf calls with field width too big.

2021-10-27 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield updated this revision to Diff 382845.
mbenfield added a comment.

const


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111833

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-scanf.c

Index: clang/test/Sema/warn-fortify-scanf.c
===
--- /dev/null
+++ clang/test/Sema/warn-fortify-scanf.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
+
+typedef struct _FILE FILE;
+extern int scanf(const char *format, ...);
+extern int fscanf(FILE *f, const char *format, ...);
+extern int sscanf(const char *input, const char *format, ...);
+
+void call_scanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  scanf("%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 11}}
+  scanf("%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 12}}
+  scanf("%4s %5s %9s", buf20, buf30, buf10);
+  scanf("%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 21}}
+  scanf("%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 22}}
+  scanf("%19s %5s %9s", buf20, buf30, buf10);
+  scanf("%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_sscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  sscanf("a b c", "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  sscanf("a b c", "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  sscanf("a b c", "%4s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  sscanf("a b c", "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  sscanf("a b c", "%19s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_fscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  fscanf(0, "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  fscanf(0, "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  fscanf(0, "%4s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  fscanf(0, "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  fscanf(0, "%19s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%19s %29s %9s", buf20, buf30, buf10);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -408,6 +408,50 @@
 
 namespace {
 
+class ScanfDiagnosticFormatHandler
+: public analyze_format_string::FormatStringHandler {
+  // Accepts the argument index (relative to the first destination index) of the
+  // argument whose size we want.
+  using ComputeSizeFunction =
+  llvm::function_ref(unsigned)>;
+
+  // Accepts the argument index (relative to the first destination index), the
+  // destination size, and the source size).
+  using DiagnoseFunction =
+  llvm::function_ref;
+
+  ComputeSizeFunction ComputeSizeArgument;
+  DiagnoseFunction Diagnose;
+
+public:
+  ScanfDiagnosticFormatHandler(ComputeSizeFunction ComputeSizeArgument,
+   DiagnoseFunction Diagnose)
+  : ComputeSizeArgument(ComputeSizeArgument), Diagnose(Diagnose) {}
+
+  bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
+const char *StartSpecifier,
+  

[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-27 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 382823.
ASDenysPetrov added a comment.

Added doc comment to `getSValFromStringLiteral` function.
Fixed minor code defects.


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

https://reviews.llvm.org/D107339

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -146,3 +146,110 @@
 void struct_arr_index1() {
   clang_analyzer_eval(S2::arr_no_init[2]); // expected-warning{{UNKNOWN}}
 }
+
+char const glob_arr6[5] = "123";
+void glob_array_index5() {
+  clang_analyzer_eval(glob_arr6[0] == '1');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[1] == '2');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[2] == '3');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[3] == '\0'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[4] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_ptr_index3() {
+  char const *ptr = glob_arr6;
+  clang_analyzer_eval(ptr[-42] == '\0'); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[0] == '1');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == '2');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == '3');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == '\0');   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == '\0');   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[5] == '\0');   // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[6] == '\0');   // expected-warning{{UNDEFINED}}
+}
+
+void glob_invalid_index7() {
+  int idx = -42;
+  auto x = glob_arr6[idx]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_invalid_index8() {
+  const char *ptr = glob_arr6;
+  int idx = 42;
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
+}
+
+char const glob_arr7[5] = {"123"};
+void glob_array_index6() {
+  clang_analyzer_eval(glob_arr7[0] == '1');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr7[1] == '2');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr7[2] == '3');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr7[3] == '\0'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr7[4] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_invalid_index9() {
+  int idx = -42;
+  auto x = glob_arr7[idx]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_invalid_index10() {
+  const char *ptr = glob_arr7;
+  int idx = 42;
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
+}
+
+char const *const glob_ptr8 = "123";
+void glob_ptr_index4() {
+  clang_analyzer_eval(glob_ptr8[0] == '1');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr8[1] == '2');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr8[2] == '3');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr8[3] == '\0'); // expected-warning{{TRUE}}
+  // FIXME: Should be UNDEFINED.
+  // We should take into account a declaration in which the literal is used.
+  clang_analyzer_eval(glob_ptr8[4] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_invalid_index11() {
+  int idx = -42;
+  auto x = glob_ptr8[idx]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_invalid_index12() {
+  int idx = 42;
+  // FIXME: Should warn {{garbage or undefined}}
+  // We should take into account a declaration in which the literal is used.
+  auto x = glob_ptr8[idx]; // no-warning
+}
+
+const char16_t *const glob_ptr9 = u"абв";
+void glob_ptr_index5() {
+  clang_analyzer_eval(glob_ptr9[0] == u'а'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr9[1] == u'б'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr9[2] == u'в'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr9[3] == '\0'); // expected-warning{{TRUE}}
+}
+
+const char32_t *const glob_ptr10 = U"\U0001F607\U0001F608\U0001F609";
+void glob_ptr_index6() {
+  clang_analyzer_eval(glob_ptr10[0] == U'\U0001F607'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr10[1] == U'\U0001F608'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr10[2] == U'\U0001F609'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr10[3] == '\0');  // expected-warning{{TRUE}}
+}
+
+const wchar_t *const glob_ptr11 = L"\123\u0041\xFF";
+void glob_ptr_index7() {
+  clang_analyzer_eval(glob_ptr11[0] == L'\123');   // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr11[1] == L'\u0041'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr11[2] == L'\xFF');   // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_ptr11[3] == L'\0'); // expected-warning{{TRUE}}
+}
+
+const char *const glob_ptr12 = u8"abc";
+void glob_ptr_index8() {
+  clang_analyzer_eval(glob_ptr12[0] == 'a');  // 

[PATCH] D111833: [clang] Fortify warning for scanf calls with field width too big.

2021-10-27 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield updated this revision to Diff 382840.
mbenfield added a comment.

fix function_ref use-after-free


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111833

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-scanf.c

Index: clang/test/Sema/warn-fortify-scanf.c
===
--- /dev/null
+++ clang/test/Sema/warn-fortify-scanf.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
+
+typedef struct _FILE FILE;
+extern int scanf(const char *format, ...);
+extern int fscanf(FILE *f, const char *format, ...);
+extern int sscanf(const char *input, const char *format, ...);
+
+void call_scanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  scanf("%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 11}}
+  scanf("%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 12}}
+  scanf("%4s %5s %9s", buf20, buf30, buf10);
+  scanf("%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 21}}
+  scanf("%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 22}}
+  scanf("%19s %5s %9s", buf20, buf30, buf10);
+  scanf("%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_sscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  sscanf("a b c", "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  sscanf("a b c", "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  sscanf("a b c", "%4s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  sscanf("a b c", "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  sscanf("a b c", "%19s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_fscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  fscanf(0, "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  fscanf(0, "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  fscanf(0, "%4s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  fscanf(0, "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  fscanf(0, "%19s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%19s %29s %9s", buf20, buf30, buf10);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -408,6 +408,50 @@
 
 namespace {
 
+class ScanfDiagnosticFormatHandler
+: public analyze_format_string::FormatStringHandler {
+  // Accepts the argument index (relative to the first destination index) of the
+  // argument whose size we want.
+  using ComputeSizeFunction =
+  llvm::function_ref(unsigned)>;
+
+  // Accepts the argument index (relative to the first destination index), the
+  // destination size, and the source size).
+  using DiagnoseFunction =
+  llvm::function_ref;
+
+  ComputeSizeFunction ComputeSizeArgument;
+  DiagnoseFunction Diagnose;
+
+public:
+  ScanfDiagnosticFormatHandler(ComputeSizeFunction ComputeSizeArgument,
+   DiagnoseFunction Diagnose)
+  : ComputeSizeArgument(ComputeSizeArgument), Diagnose(Diagnose) {}
+
+  bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
+const

[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Ard Biesheuvel via Phabricator via cfe-commits
ardb updated this revision to Diff 382839.
ardb added a comment.

Add another test suggested by Nick.


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

https://reviews.llvm.org/D112600

Files:
  llvm/lib/Target/ARM/ARMInstrThumb.td
  llvm/lib/Target/ARM/ARMInstrThumb2.td
  llvm/test/CodeGen/ARM/readtp.ll
  llvm/test/CodeGen/ARM/thread_pointer.ll


Index: llvm/test/CodeGen/ARM/thread_pointer.ll
===
--- llvm/test/CodeGen/ARM/thread_pointer.ll
+++ llvm/test/CodeGen/ARM/thread_pointer.ll
@@ -1,4 +1,7 @@
-; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
+; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck 
%s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | 
FileCheck %s -check-prefix=CHECK-HARD
 
 declare i8* @llvm.thread.pointer()
 
@@ -8,5 +11,6 @@
   ret i8* %tmp1
 }
 
-; CHECK: bl __aeabi_read_tp
+; CHECK-SOFT: bl __aeabi_read_tp
+; CHECK-HARD: mrc p15, #0, {{r[0-9]+}}, c13, c0, #3
 
Index: llvm/test/CodeGen/ARM/readtp.ll
===
--- llvm/test/CodeGen/ARM/readtp.ll
+++ llvm/test/CodeGen/ARM/readtp.ll
@@ -1,5 +1,7 @@
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | 
FileCheck %s -check-prefix=CHECK-HARD
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | 
FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s 
-check-prefix=CHECK-SOFT
 
 
 ; __thread int counter;
Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4671,6 +4671,9 @@
 }
 
 
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 
//===--===//
 // ARMv8.1 Privilege Access Never extension
Index: llvm/lib/Target/ARM/ARMInstrThumb.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb.td
+++ llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1520,6 +1520,7 @@
 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
   [(set R0, ARMthread_pointer)]>,
+  Requires<[IsThumb, IsReadTPSoft]>,
   Sched<[WriteBr]>;
 
 
//===--===//


Index: llvm/test/CodeGen/ARM/thread_pointer.ll
===
--- llvm/test/CodeGen/ARM/thread_pointer.ll
+++ llvm/test/CodeGen/ARM/thread_pointer.ll
@@ -1,4 +1,7 @@
-; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
+; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
 
 declare i8* @llvm.thread.pointer()
 
@@ -8,5 +11,6 @@
   ret i8* %tmp1
 }
 
-; CHECK: bl __aeabi_read_tp
+; CHECK-SOFT: bl __aeabi_read_tp
+; CHECK-HARD: mrc p15, #0, {{r[0-9]+}}, c13, c0, #3
 
Index: llvm/test/CodeGen/ARM/readtp.ll
===
--- llvm/test/CodeGen/ARM/readtp.ll
+++ llvm/test/CodeGen/ARM/readtp.ll
@@ -1,5 +1,7 @@
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
 
 
 ; __thread int counter;
Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4671,6 +4671,9 @@
 }
 
 
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 //===--

[PATCH] D111952: [clang] [MinGW] Guess the right ix86 arch name spelling as sysroot

2021-10-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/MinGW.h:63
 
+  static void FixTripleArch(const Driver &D, llvm::Triple &Triple,
+const llvm::opt::ArgList &Args);

Use `functionName` for newer functions. (It's unfortunate that Clang has much 
inconsistency but we should do the right thing for new methods.)



Comment at: clang/test/Driver/mingw-sysroot.cpp:49
+
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 -m32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG_I686 %s
+// CHECK_TESTROOT_CLANG_I686: 
"{{[^"]+}}/testroot-clang{{/|}}i686-w64-mingw32{{/|}}include"

Changing `PATH` seems unreliable for some test environments.

Any alternative way to test this?

`--target=` is preferred over `-target ` for driver options. `-target ` is 
legacy but we probably need to keep indefinitely for its wide usage.

`linux-cross.cpp` has some nice tests which may inspire this file ? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111952

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


[PATCH] D112413: [X86] Add -mskip-rax-setup support to align with GCC

2021-10-27 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:96
 
+static cl::opt SkipRaxSetup(
+"x86-skip-rax-setup", cl::init(false),

MaskRay wrote:
> nickdesaulniers wrote:
> > If it's a command line option rather than encoded in the IR, then this 
> > won't be handled correctly under LTO (we support building the x86 linux 
> > kernel under LTO), unless the linker re-passes the flag.  I've been trying 
> > to avoid that by encoding this information properly in IR rather than rely 
> > on codegen command line options which I find brittle.  Please see 
> > https://reviews.llvm.org/D103928 as an example.
> This depends on how frequent the feature is used.
> 
> I see that `arch/x86/Makefile` may add `-mskip-rax-setup` which is presumably 
> used by all C files, so a module flag metadata suffices. If there are 
> mix-and-match cases for different modules (e.g. ssp/nossp) a function 
> attribute may be used. If a feature is really obscure than I might not 
> consider wasting an IR attribute on it. Arguably if a feature is sufficient 
> obscure we may not want to port it from GCC at all.
> 
> So "This fixes pr23258." in the description should state the use case to give 
> archaeologists a hint why the feature is added.
That's fine, though then we should add a test for new module level IR using 
llvm-link, IMO, since this (and many `-m` flags) imply an ABI breakage across 
modules with mismatched use of this flag.

> Arguably if a feature is sufficient obscure we may not want to port it from 
> GCC at all.

In this case, I think@hjl.tools has some nice numbers to justify this feature 
in [[ 
https://patchwork.ozlabs.org/project/gcc/patch/20141218131150.ga32...@intel.com/
 | their patch ]]. I can run similar numbers on clang built kernels, but it 
seems nice to have.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112413

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


[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

Cool, if you wouldn't mind additional extending this patch to cover the 
intrinsic that the front end also generates, this LGTM:

  diff --git a/llvm/test/CodeGen/ARM/thread_pointer.ll 
b/llvm/test/CodeGen/ARM/thread_pointer.ll
  index c6318a58277c..f1ef2ddac2d0 100644
  --- a/llvm/test/CodeGen/ARM/thread_pointer.ll
  +++ b/llvm/test/CodeGen/ARM/thread_pointer.ll
  @@ -1,4 +1,7 @@
  -; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
  +; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s 
-check-prefix=CHECK-SOFT
  +; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | 
FileCheck %s -check-prefix=CHECK-HARD
  +; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s 
-check-prefix=CHECK-SOFT
  +; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | 
FileCheck %s -check-prefix=CHECK-HARD
   
   declare i8* @llvm.thread.pointer()
   
  @@ -8,5 +11,6 @@ entry:
 ret i8* %tmp1
   }
   
  -; CHECK: bl __aeabi_read_tp
  +; CHECK-SOFT: bl __aeabi_read_tp
  +; CHECK-HARD: mrc p15, #0, {{r[0-9]+}}, c13, c0, #3

Thanks for the patch!


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

https://reviews.llvm.org/D112600

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


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-27 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

Agreed. If after semantic analysis for a declaration we can check declaration's 
typeloc chain again, we might be able to give proper warnings. I am happy to 
implement this as a followup as you suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

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


[PATCH] D112569: -Wformat-nonliteral should not trigger for format strings passed to blocks with __attribute__((format))

2021-10-27 Thread Félix Cloutier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd378a0febc7e: [Sema] Recognize format argument indicated by 
format attribute inside blocks (authored by fcloutier).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112569

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/format-strings.c


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs -fno-signed-char %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs -fno-signed-char %s
 
 #include 
 #include 
@@ -714,3 +714,30 @@
 void test_printf_opaque_ptr(void *op) {
   printf("%s", op); // expected-warning{{format specifies type 'char *' but 
the argument has type 'void *'}}
 }
+
+void test_block() {
+  void __attribute__((__format__(__printf__, 1, 2))) (^printf_arg1)(
+  const char *, ...) =
+  ^(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(fmt, ap);
+va_end(ap);
+  };
+
+  printf_arg1("%s string %i\n", "aaa", 123);
+  printf_arg1("%s string\n", 123); // expected-warning{{format specifies type 
'char *' but the argument has type 'int'}}
+
+  void __attribute__((__format__(__printf__, 2, 3))) (^printf_arg2)(
+  const char *, const char *, ...) =
+  ^(const char *not_fmt, const char *fmt, ...)
+  __attribute__((__format__(__printf__, 2, 3))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(not_fmt, ap); // expected-warning{{format string is not a string 
literal}}
+va_end(ap);
+  };
+
+  printf_arg2("foo", "%s string %i\n", "aaa", 123);
+  printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument 
not used by format string}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7784,11 +7784,11 @@
   // }
   if (HasVAListArg) {
 if (const ParmVarDecl *PV = dyn_cast(VD)) {
-  if (const NamedDecl *ND = dyn_cast(PV->getDeclContext())) 
{
+  if (const Decl *D = dyn_cast(PV->getDeclContext())) {
 int PVIndex = PV->getFunctionScopeIndex() + 1;
-for (const auto *PVFormat : ND->specific_attrs()) {
+for (const auto *PVFormat : D->specific_attrs()) {
   // adjust for implicit parameter
-  if (const CXXMethodDecl *MD = dyn_cast(ND))
+  if (const CXXMethodDecl *MD = dyn_cast(D))
 if (MD->isInstance())
   ++PVIndex;
   // We also check if the formats are compatible.


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s
 
 #include 
 #include 
@@ -714,3 +714,30 @@
 void test_printf_opaque_ptr(void *op) {
   printf("%s", op); // expected-warning{{format specifies type 'char *' but the argument has type 'void *'}}
 }
+
+void test_block() {
+  void __attribute__((__format__(__printf__, 1, 2))) (^printf_arg1)(
+  const char *, ...) =
+  ^(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(fmt, ap);
+va_end(ap);
+  };
+
+  printf_arg1("%s string %i\n", "aaa", 123);
+  printf_arg1("%s string\n", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+
+  void __attribute__((__format__(__printf__, 2, 3))) (^printf_arg2)(
+  const char *, const char *, ...) =
+  ^(const char *not_fmt, const char *fmt, ...)
+  __attribute__((__format__(__printf__, 2, 3))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(not_fmt, ap); // expected-warning{{format string is not a string literal}}
+va_end(ap);
+  };
+
+  printf_arg2("foo", "%s string %i\n", "aaa", 123);
+  printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
=

[clang] d378a0f - [Sema] Recognize format argument indicated by format attribute inside blocks

2021-10-27 Thread Félix Cloutier via cfe-commits

Author: Félix Cloutier
Date: 2021-10-27T15:48:35-07:00
New Revision: d378a0febc7e13aae7853b2e8733626f61140e55

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

LOG: [Sema] Recognize format argument indicated by format attribute inside 
blocks

- `[[format(archetype, fmt-idx, ellipsis)]]` specifies that a function accepts a
  format string and arguments according to `archetype`. This is how Clang
  type-checks `printf` arguments based on the format string.
- Clang has a `-Wformat-nonliteral` warning that is triggered when a function
  with the `format` attribute is called with a format string that is not
  inspectable because it isn't constant. This warning is suppressed if the
  caller has the `format` attribute itself and the format argument to the callee
  is the caller's own format parameter.
- When using the `format` attribute on a block, Clang wouldn't recognize its
  format parameter when calling another function with the format attribute. This
  would cause unsuppressed -Wformat-nonliteral warnings for no supported reason.

Reviewed By: ahatanak

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

Radar-Id: rdar://84603673

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/format-strings.c

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 83fb824cb14a6..3eaeae197648a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7784,11 +7784,11 @@ checkFormatStringExpr(Sema &S, const Expr *E, 
ArrayRef Args,
   // }
   if (HasVAListArg) {
 if (const ParmVarDecl *PV = dyn_cast(VD)) {
-  if (const NamedDecl *ND = dyn_cast(PV->getDeclContext())) 
{
+  if (const Decl *D = dyn_cast(PV->getDeclContext())) {
 int PVIndex = PV->getFunctionScopeIndex() + 1;
-for (const auto *PVFormat : ND->specific_attrs()) {
+for (const auto *PVFormat : D->specific_attrs()) {
   // adjust for implicit parameter
-  if (const CXXMethodDecl *MD = dyn_cast(ND))
+  if (const CXXMethodDecl *MD = dyn_cast(D))
 if (MD->isInstance())
   ++PVIndex;
   // We also check if the formats are compatible.

diff  --git a/clang/test/Sema/format-strings.c 
b/clang/test/Sema/format-strings.c
index e8cd478d25126..bbe47636ebb7d 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs -fno-signed-char %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs -fno-signed-char %s
 
 #include 
 #include 
@@ -714,3 +714,30 @@ void PR30481() {
 void test_printf_opaque_ptr(void *op) {
   printf("%s", op); // expected-warning{{format specifies type 'char *' but 
the argument has type 'void *'}}
 }
+
+void test_block() {
+  void __attribute__((__format__(__printf__, 1, 2))) (^printf_arg1)(
+  const char *, ...) =
+  ^(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(fmt, ap);
+va_end(ap);
+  };
+
+  printf_arg1("%s string %i\n", "aaa", 123);
+  printf_arg1("%s string\n", 123); // expected-warning{{format specifies type 
'char *' but the argument has type 'int'}}
+
+  void __attribute__((__format__(__printf__, 2, 3))) (^printf_arg2)(
+  const char *, const char *, ...) =
+  ^(const char *not_fmt, const char *fmt, ...)
+  __attribute__((__format__(__printf__, 2, 3))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(not_fmt, ap); // expected-warning{{format string is not a string 
literal}}
+va_end(ap);
+  };
+
+  printf_arg2("foo", "%s string %i\n", "aaa", 123);
+  printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument 
not used by format string}}
+}



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


[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Ard Biesheuvel via Phabricator via cfe-commits
ardb updated this revision to Diff 382826.
ardb added a comment.

Drop new Clang CodeGen test, and add the Thumb2 check to an existing backend 
test instead.


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

https://reviews.llvm.org/D112600

Files:
  llvm/lib/Target/ARM/ARMInstrThumb.td
  llvm/lib/Target/ARM/ARMInstrThumb2.td
  llvm/test/CodeGen/ARM/readtp.ll


Index: llvm/test/CodeGen/ARM/readtp.ll
===
--- llvm/test/CodeGen/ARM/readtp.ll
+++ llvm/test/CodeGen/ARM/readtp.ll
@@ -1,5 +1,7 @@
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | 
FileCheck %s -check-prefix=CHECK-HARD
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s 
-check-prefix=CHECK-SOFT
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | 
FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s 
-check-prefix=CHECK-SOFT
 
 
 ; __thread int counter;
Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4671,6 +4671,9 @@
 }
 
 
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 
//===--===//
 // ARMv8.1 Privilege Access Never extension
Index: llvm/lib/Target/ARM/ARMInstrThumb.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb.td
+++ llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1520,6 +1520,7 @@
 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
   [(set R0, ARMthread_pointer)]>,
+  Requires<[IsThumb, IsReadTPSoft]>,
   Sched<[WriteBr]>;
 
 
//===--===//


Index: llvm/test/CodeGen/ARM/readtp.ll
===
--- llvm/test/CodeGen/ARM/readtp.ll
+++ llvm/test/CodeGen/ARM/readtp.ll
@@ -1,5 +1,7 @@
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
 ; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
+; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
 
 
 ; __thread int counter;
Index: llvm/lib/Target/ARM/ARMInstrThumb2.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -4671,6 +4671,9 @@
 }
 
 
+// Reading thread pointer from coprocessor register
+def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
+  Requires<[IsThumb2, IsReadTPHard]>;
 
 //===--===//
 // ARMv8.1 Privilege Access Never extension
Index: llvm/lib/Target/ARM/ARMInstrThumb.td
===
--- llvm/lib/Target/ARM/ARMInstrThumb.td
+++ llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1520,6 +1520,7 @@
 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
   [(set R0, ARMthread_pointer)]>,
+  Requires<[IsThumb, IsReadTPSoft]>,
   Sched<[WriteBr]>;
 
 //===--===//
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112670: __attribute__((format_arg(__NSString__, N))) does not support instancetype in NSString interface

2021-10-27 Thread Félix Cloutier via Phabricator via cfe-commits
fcloutier created this revision.
fcloutier added reviewers: doug.gregor, dcoughlin, rsmith, NoQ, ahatanak.
fcloutier added a project: clang.
Herald added a reviewer: aaron.ballman.
fcloutier requested review of this revision.
Herald added a subscriber: cfe-commits.

It has come to my attention that _inside the interface of `NSString_`, using 
`__attribute__((format_arg(__NSString__, N)))` does not work for a method that 
returns `instancetype`. This is a pretty specific problem because not a lot of 
people define `NSString`. Thankfully, the fix isn't very difficult: if checking 
an Objective-C method definition, and it returns `instancetype`, we also check 
if the class being defined is `NSString`.

rdar://84729746


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112670

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/format-arg-attribute.m


Index: clang/test/SemaObjC/format-arg-attribute.m
===
--- clang/test/SemaObjC/format-arg-attribute.m
+++ clang/test/SemaObjC/format-arg-attribute.m
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 
-@class NSString;
+@interface NSString
++(instancetype)stringWithCString:(const char *)cstr 
__attribute__((format_arg(1)));
+@end
+
 @class NSAttributedString;
 
 extern NSString *fa2 (const NSString *) __attribute__((format_arg(1)));
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -156,26 +156,39 @@
   return false;
 }
 
-static inline bool isNSStringType(QualType T, ASTContext &Ctx,
-  bool AllowNSAttributedString = false) {
-  const auto *PT = T->getAs();
-  if (!PT)
-return false;
-
-  ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
+static inline bool isNSStringInterface(ASTContext &Ctx, ObjCInterfaceDecl 
*Cls, bool AllowNSAttributedString = false) {
   if (!Cls)
 return false;
 
-  IdentifierInfo* ClsName = Cls->getIdentifier();
+  IdentifierInfo *ClsName = Cls->getIdentifier();
 
-  if (AllowNSAttributedString &&
-  ClsName == &Ctx.Idents.get("NSAttributedString"))
-return true;
+  if (ClsName == &Ctx.Idents.get("NSAttributedString"))
+return AllowNSAttributedString;
   // FIXME: Should we walk the chain of classes?
   return ClsName == &Ctx.Idents.get("NSString") ||
  ClsName == &Ctx.Idents.get("NSMutableString");
 }
 
+static inline bool isNSStringType(QualType T, ASTContext &Ctx,
+  bool AllowNSAttributedString = false) {
+  const auto *PT = T->getAs();
+  if (!PT)
+return false;
+  
+  return isNSStringInterface(Ctx, PT->getObjectType()->getInterface(), 
AllowNSAttributedString);
+}
+
+static inline bool isInstancetypeNSStringType(ASTContext &Ctx, QualType T, 
Decl *D, bool AllowNSAttributedString = false) {
+  if (T.getTypePtr() != Ctx.getObjCInstanceTypeDecl()->getTypeForDecl())
+return false;
+  
+  auto *OMD = dyn_cast(D);
+  if (!OMD)
+return false;
+  
+  return isNSStringInterface(Ctx, OMD->getClassInterface(), 
AllowNSAttributedString);
+}
+
 static inline bool isCFStringType(QualType T, ASTContext &Ctx) {
   const auto *PT = T->getAs();
   if (!PT)
@@ -3390,6 +3403,7 @@
   Ty = getFunctionOrMethodResultType(D);
   if (!isNSStringType(Ty, S.Context, /*AllowNSAttributedString=*/true) &&
   !isCFStringType(Ty, S.Context) &&
+  !isInstancetypeNSStringType(S.Context, Ty, D) &&
   (!Ty->isPointerType() ||
!Ty->castAs()->getPointeeType()->isCharType())) {
 S.Diag(AL.getLoc(), diag::err_format_attribute_result_not)


Index: clang/test/SemaObjC/format-arg-attribute.m
===
--- clang/test/SemaObjC/format-arg-attribute.m
+++ clang/test/SemaObjC/format-arg-attribute.m
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 
-@class NSString;
+@interface NSString
++(instancetype)stringWithCString:(const char *)cstr __attribute__((format_arg(1)));
+@end
+
 @class NSAttributedString;
 
 extern NSString *fa2 (const NSString *) __attribute__((format_arg(1)));
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -156,26 +156,39 @@
   return false;
 }
 
-static inline bool isNSStringType(QualType T, ASTContext &Ctx,
-  bool AllowNSAttributedString = false) {
-  const auto *PT = T->getAs();
-  if (!PT)
-return false;
-
-  ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
+static inline bool isNSStringInterface(ASTContext &Ctx, ObjCInterfaceDecl *Cls, bool AllowNSAttributedString = false) {
   if (!Cls)
 return false;
 
-  IdentifierInfo* ClsName = Cls->getIdentifier();
+  IdentifierInfo *ClsName = Cls->getIdentifier();
 
-  if (AllowNSAttributedStri

[PATCH] D112110: [OpenCL] queue_t and ndrange_t can't be defined in program scope.

2021-10-27 Thread Chuang-Yu Cheng via Phabricator via cfe-commits
cycheng updated this revision to Diff 382816.
cycheng added a comment.

previous update was using wrong file, sorry!!


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

https://reviews.llvm.org/D112110

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaOpenCL/invalid-types.cl


Index: clang/test/SemaOpenCL/invalid-types.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/invalid-types.cl
@@ -0,0 +1,11 @@
+// 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_device_enqueue
+
+// Test declare "Other Data Type" variables in program scope.
+global queue_t qt; // expected-error {{the '__global queue_t' type cannot be 
used to declare a program scope variable}}
+
+typedef struct {int a;} ndrange_t;
+global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot 
be used to declare a program scope variable}}
+
+typedef image2d_t test;
+global test qtt; // expected-error {{the '__global ndrange_t' type cannot be 
used to declare a program scope variable}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6841,8 +6841,12 @@
   // OpenCL v2.0 s6.9.q:
   // The clk_event_t and reserve_id_t types cannot be declared in program
   // scope.
+  // OpenCL v3.0 s6.11.w:
+  // Program scope variables can be defined with any valid OpenCL C data type
+  // except for those in Other Built-in Data Types.
   if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) {
-if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() ||
+R->isQueueT() || R.getUnqualifiedType().getAsString() == "ndrange_t") {
   Se.Diag(NewVD->getLocation(),
   diag::err_invalid_type_for_program_scope_var)
   << R;


Index: clang/test/SemaOpenCL/invalid-types.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/invalid-types.cl
@@ -0,0 +1,11 @@
+// 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_device_enqueue
+
+// Test declare "Other Data Type" variables in program scope.
+global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}}
+
+typedef struct {int a;} ndrange_t;
+global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}}
+
+typedef image2d_t test;
+global test qtt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6841,8 +6841,12 @@
   // OpenCL v2.0 s6.9.q:
   // The clk_event_t and reserve_id_t types cannot be declared in program
   // scope.
+  // OpenCL v3.0 s6.11.w:
+  // Program scope variables can be defined with any valid OpenCL C data type
+  // except for those in Other Built-in Data Types.
   if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) {
-if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() ||
+R->isQueueT() || R.getUnqualifiedType().getAsString() == "ndrange_t") {
   Se.Diag(NewVD->getLocation(),
   diag::err_invalid_type_for_program_scope_var)
   << R;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112110: [OpenCL] queue_t and ndrange_t can't be defined in program scope.

2021-10-27 Thread Chuang-Yu Cheng via Phabricator via cfe-commits
cycheng updated this revision to Diff 382813.
cycheng marked 2 inline comments as done.
cycheng added a comment.

- Remove OpenCL 2.0 description
- Merge test files into single test file


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

https://reviews.llvm.org/D112110

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaOpenCL/invalid-ndrange.cl
  clang/test/SemaOpenCL/invalid-queue.cl


Index: clang/test/SemaOpenCL/invalid-queue.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/invalid-queue.cl
@@ -0,0 +1,4 @@
+// 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_device_enqueue
+
+global queue_t qt; // expected-error {{the '__global queue_t' type cannot be 
used to declare a program scope variable}}
Index: clang/test/SemaOpenCL/invalid-ndrange.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/invalid-ndrange.cl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
+
+typedef struct {int a;} ndrange_t;
+
+global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot 
be used to declare a program scope variable}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6841,8 +6841,16 @@
   // OpenCL v2.0 s6.9.q:
   // The clk_event_t and reserve_id_t types cannot be declared in program
   // scope.
+  // OpenCL v2.0 s6.5.1:
+  // Variables defined at program scope and static variables inside a function
+  // can also be declared in the global address space. They can be defined with
+  // any valid OpenCL C data type except for those in Other Built-in Data 
Types.
+  // OpenCL v3.0 s6.11.w:
+  // Program scope variables can be defined with any valid OpenCL C data type
+  // except for those in Other Built-in Data Types. 
   if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) {
-if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() ||
+R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) {
   Se.Diag(NewVD->getLocation(),
   diag::err_invalid_type_for_program_scope_var)
   << R;


Index: clang/test/SemaOpenCL/invalid-queue.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/invalid-queue.cl
@@ -0,0 +1,4 @@
+// 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_device_enqueue
+
+global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}}
Index: clang/test/SemaOpenCL/invalid-ndrange.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/invalid-ndrange.cl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
+
+typedef struct {int a;} ndrange_t;
+
+global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6841,8 +6841,16 @@
   // OpenCL v2.0 s6.9.q:
   // The clk_event_t and reserve_id_t types cannot be declared in program
   // scope.
+  // OpenCL v2.0 s6.5.1:
+  // Variables defined at program scope and static variables inside a function
+  // can also be declared in the global address space. They can be defined with
+  // any valid OpenCL C data type except for those in Other Built-in Data Types.
+  // OpenCL v3.0 s6.11.w:
+  // Program scope variables can be defined with any valid OpenCL C data type
+  // except for those in Other Built-in Data Types. 
   if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) {
-if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() ||
+R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) {
   Se.Diag(NewVD->getLocation(),
   diag::err_invalid_type_for_program_scope_var)
   << R;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112534: [PoC][RISCV] Use an attribute to declare C intrinsics with different policy.

2021-10-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I think the concept seems good to me. I'd like @aaron.ballman to review the 
attribute code.




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:18610
   unsigned NF = 1;
   constexpr unsigned TAIL_UNDISTURBED = 0;
+  constexpr unsigned TAIL_AGNOSTIC = 0b01;

Is constant still used?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:883
+
+  const char *policySuffix[] = {"tumu", "tamu", "tuma", "tama"};
+

Capitalize `policySuffix` and make it

`static const char *const PolicySuffix[]`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112534

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


[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/CodeGen/arm-tphard.c:10
+}
+

ardb wrote:
> nickdesaulniers wrote:
> > Let's make this a test under llvm/test/CodeGen/, using IR:
> > ```
> > ; RUN: llc --mtriple=armv7-linux-gnueabihf -o - %s | FileCheck %s
> > ; RUN: llc --mtriple=thumbv7-linux-gnu -o - %s | FileCheck %s
> > define dso_local i8* @tphard() "target-features"="+read-tp-hard" {
> > // CHECK-NOT: __aeabi_read_tp
> >   %1 = tail call i8* @llvm.thread.pointer()
> >   ret i8* %1
> > }
> > 
> > declare i8* @llvm.thread.pointer()
> > ```
> > 
> > Let's make this a test under llvm/test/CodeGen/, using IR:
> 
> Why is that better?
> 
> > ```
> > ; RUN: llc --mtriple=armv7-linux-gnueabihf -o - %s | FileCheck %s
> > ; RUN: llc --mtriple=thumbv7-linux-gnu -o - %s | FileCheck %s
> 
> Are you sure using this triple forces generation of Thumb2 code? It didn't 
> seem to when I tried.
> 
> > define dso_local i8* @tphard() "target-features"="+read-tp-hard" {
> > // CHECK-NOT: __aeabi_read_tp
> 
> Are you sure __aeabi_read_tp will appear in the IR for soft TP?
> 
> >   %1 = tail call i8* @llvm.thread.pointer()
> >   ret i8* %1
> > }
> > 
> > declare i8* @llvm.thread.pointer()
> > ```
> > 
> 
> 
> Why is that better?

Because the front-end isn't really involved in this back end code gen bug, so 
we should just be testing the back end.

> Are you sure using this triple forces generation of Thumb2 code? It didn't 
> seem to when I tried.

Good question; I guess for thumb2 there's no command line flag passed to the 
compiler that says "I would like thumb[1] as opposed to thumb2?"  Maybe 
@peter.smith can provide some color on that? Is it simply armv7 for thumb2 vs 
v6 for thumb[1], or something else?

> Are you sure __aeabi_read_tp will appear in the IR for soft TP?

`__aeabi_read_tp` will never appear in the IR (unless someone explicitly called 
it`. Instead, we're testing that the intrinsic (`@llvm.thread.pointer`) is 
lowered to either that libcall or `mrc`.  `__aeabi_read_tp` may appear in the 
object file or assembler code generated from that intrinsic call.

But also, it looks like there's already coverage for `__aeabi_read_tp` being 
generated for soft TP. See also llvm/test/CodeGen/ARM/readtp.ll. There's also 
thread_pointer.ll in that same dir (and a few more tests mentioning 
`__aeabi_read_tp` that all look like candidates to add these tests to rather 
than creating a new test file, perhaps.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112600

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


[PATCH] D112413: [X86] Add -mskip-rax-setup support to align with GCC

2021-10-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3193
+def mskip_rax_setup : Flag<["-"], "mskip-rax-setup">, Group, 
Flags<[NoXarchOption]>,
+  HelpText<"Skip setting up RAX register when passing variable arguments (x86 
only)">;
 def mstackrealign : Flag<["-"], "mstackrealign">, Group, 
Flags<[CC1Option]>,

nickdesaulniers wrote:
> I think GCC support `-mno-skip-rax-setup` as well. Can you please add that 
> (and tests for it) as well?  We don't need to actually handle it, I think, 
> but we shouldn't warn about the flag being unsupported, for example.
Consider `SimpleMFlag`



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:96
 
+static cl::opt SkipRaxSetup(
+"x86-skip-rax-setup", cl::init(false),

nickdesaulniers wrote:
> If it's a command line option rather than encoded in the IR, then this won't 
> be handled correctly under LTO (we support building the x86 linux kernel 
> under LTO), unless the linker re-passes the flag.  I've been trying to avoid 
> that by encoding this information properly in IR rather than rely on codegen 
> command line options which I find brittle.  Please see 
> https://reviews.llvm.org/D103928 as an example.
This depends on how frequent the feature is used.

I see that `arch/x86/Makefile` may add `-mskip-rax-setup` which is presumably 
used by all C files, so a module flag metadata suffices. If there are 
mix-and-match cases for different modules (e.g. ssp/nossp) a function attribute 
may be used. If a feature is really obscure than I might not consider wasting 
an IR attribute on it. Arguably if a feature is sufficient obscure we may not 
want to port it from GCC at all.

So "This fixes pr23258." in the description should state the use case to give 
archaeologists a hint why the feature is added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112413

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


[PATCH] D112663: [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-10-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:70
   llvm::Expected
-  getSymbolAddress(llvm::StringRef UnmangledName) const;
+  getSymbolAddress(llvm::StringRef Name, bool IsMangled = false) const;
 };

I find this flag name to be very confusing, given what "mangling" usually means 
within Clang. I think `IsMangled = false` means "this is a symbol name of the 
same kind that Clang would emit in IR", and `IsMangled = true` means "this is a 
symbol name of the same kind that would appear in an object file's symbol 
table" -- and the former is a mangled name in the sense in which the term is 
used in Clang.

Perhaps `enum { IRName, LinkerName }` instead of a bool flag would be clearer? 
But I'm not sure whether this flag is motivated given that your test case below 
wants / is testing the `IsMangled = false` behavior.

I wonder if a better interface here generally would be:

```
llvm::Expected getSymbolAddress(GlobalDecl GD) const;
```

... which could internally form the proper symbol name for the given 
`GlobalDecl` (or perhaps reuse `CodeGen`'s decl -> mangling map rather than 
redoing the name mangling step).



Comment at: clang/unittests/Interpreter/InterpreterTest.cpp:131-138
+static std::string MangleName(NamedDecl *ND) {
+  ASTContext &C = ND->getASTContext();
+  std::unique_ptr MangleC(C.createMangleContext());
+  std::string mangledName;
+  llvm::raw_string_ostream RawStr(mangledName);
+  MangleC->mangleName(ND, RawStr);
+  return RawStr.str();

This function produces names that are not mangled in the sense that 
`getSymbolAddress`'s `IsMangled = true` means. I would expect this test to fail 
on MacOS for that reason.


Repository:
  rC Clang

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

https://reviews.llvm.org/D112663

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


[PATCH] D112349: [Verifier] Add verification logic for GlobalIFuncs

2021-10-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112349

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


[libunwind] 3e39bbf - [libunwind] Simplify the executor used in the tests

2021-10-27 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2021-10-27T17:30:07-04:00
New Revision: 3e39bbf5f9614327bb09d6527db8b40fc472fedf

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

LOG: [libunwind] Simplify the executor used in the tests

Instead of going through libc++'s run.py, we can simply run the executable
directly since we don't need to setup a working directory or control the
environment.

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

Added: 


Modified: 
libunwind/test/configs/llvm-libunwind-shared.cfg.in
libunwind/test/configs/llvm-libunwind-static.cfg.in

Removed: 




diff  --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in 
b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index b60c9ffbf42d6..206c2b9c3e4f5 100644
--- a/libunwind/test/configs/llvm-libunwind-shared.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
@@ -49,9 +49,7 @@ config.substitutions.append(('%{compile_flags}',
 config.substitutions.append(('%{link_flags}',
 '-nodefaultlibs -L {0} -Wl,-rpath,{0} -lunwind -ldl -lc 
{1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
 ))
-config.substitutions.append(('%{exec}',
-'{} {}/utils/run.py --execdir %T -- '.format(sys.executable, 
'@LIBUNWIND_LIBCXX_PATH@')
-))
+config.substitutions.append(('%{exec}', ''))
 
 import os, site
 site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))

diff  --git a/libunwind/test/configs/llvm-libunwind-static.cfg.in 
b/libunwind/test/configs/llvm-libunwind-static.cfg.in
index 327f048b1e0f4..dd292e7c88df9 100644
--- a/libunwind/test/configs/llvm-libunwind-static.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-static.cfg.in
@@ -51,9 +51,7 @@ config.substitutions.append(('%{compile_flags}',
 config.substitutions.append(('%{link_flags}',
 '-nodefaultlibs {}/libunwind.a -ldl -lc 
{}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
 ))
-config.substitutions.append(('%{exec}',
-'{} {}/utils/run.py --execdir %T -- '.format(sys.executable, 
'@LIBUNWIND_LIBCXX_PATH@')
-))
+config.substitutions.append(('%{exec}', ''))
 
 import os, site
 site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))



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


[PATCH] D112600: [ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed

2021-10-27 Thread Ard Biesheuvel via Phabricator via cfe-commits
ardb added inline comments.



Comment at: clang/test/CodeGen/arm-tphard.c:10
+}
+

nickdesaulniers wrote:
> Let's make this a test under llvm/test/CodeGen/, using IR:
> ```
> ; RUN: llc --mtriple=armv7-linux-gnueabihf -o - %s | FileCheck %s
> ; RUN: llc --mtriple=thumbv7-linux-gnu -o - %s | FileCheck %s
> define dso_local i8* @tphard() "target-features"="+read-tp-hard" {
> // CHECK-NOT: __aeabi_read_tp
>   %1 = tail call i8* @llvm.thread.pointer()
>   ret i8* %1
> }
> 
> declare i8* @llvm.thread.pointer()
> ```
> 
> Let's make this a test under llvm/test/CodeGen/, using IR:

Why is that better?

> ```
> ; RUN: llc --mtriple=armv7-linux-gnueabihf -o - %s | FileCheck %s
> ; RUN: llc --mtriple=thumbv7-linux-gnu -o - %s | FileCheck %s

Are you sure using this triple forces generation of Thumb2 code? It didn't seem 
to when I tried.

> define dso_local i8* @tphard() "target-features"="+read-tp-hard" {
> // CHECK-NOT: __aeabi_read_tp

Are you sure __aeabi_read_tp will appear in the IR for soft TP?

>   %1 = tail call i8* @llvm.thread.pointer()
>   ret i8* %1
> }
> 
> declare i8* @llvm.thread.pointer()
> ```
> 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112600

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


[PATCH] D112664: [clang-format][docs] fix indentation of rst code block

2021-10-27 Thread Mike via Phabricator via cfe-commits
Wirena created this revision.
Wirena added a reviewer: HazardyKnusperkeks.
Wirena 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/D112664

Files:
  clang/docs/ClangFormatStyleOptions.rst


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3821,16 +3821,16 @@
 
   .. code-block:: c++
 
-  before:   after:
-  Minimum: 1
-  //if (b) {// if (b) {
-  //  return true;  //   return true;
-  //}   // }
-
-  Maximum: 0
-  /// List: ///List:
-  ///  - Foo/// - Foo
-  ///- Bar  ///   - Bar
+ before:   after:
+ Minimum: 1
+ //if (b) {// if (b) {
+ //  return true;  //   return true;
+ //}   // }
+
+ Maximum: 0
+ /// List: ///List:
+ ///  - Foo/// - Foo
+ ///- Bar  ///   - Bar
 
   Nested configuration flags:
 


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3821,16 +3821,16 @@
 
   .. code-block:: c++
 
-  before:   after:
-  Minimum: 1
-  //if (b) {// if (b) {
-  //  return true;  //   return true;
-  //}   // }
-
-  Maximum: 0
-  /// List: ///List:
-  ///  - Foo/// - Foo
-  ///- Bar  ///   - Bar
+ before:   after:
+ Minimum: 1
+ //if (b) {// if (b) {
+ //  return true;  //   return true;
+ //}   // }
+
+ Maximum: 0
+ /// List: ///List:
+ ///  - Foo/// - Foo
+ ///- Bar  ///   - Bar
 
   Nested configuration flags:
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112569: -Wformat-nonliteral should not trigger for format strings passed to blocks with __attribute__((format))

2021-10-27 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak accepted this revision.
ahatanak added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112569

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


[PATCH] D111833: [clang] Fortify warning for scanf calls with field width too big.

2021-10-27 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield updated this revision to Diff 382802.
mbenfield added a comment.

rebase and rerun tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111833

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-scanf.c

Index: clang/test/Sema/warn-fortify-scanf.c
===
--- /dev/null
+++ clang/test/Sema/warn-fortify-scanf.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
+
+typedef struct _FILE FILE;
+extern int scanf(const char *format, ...);
+extern int fscanf(FILE *f, const char *format, ...);
+extern int sscanf(const char *input, const char *format, ...);
+
+void call_scanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  scanf("%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 11}}
+  scanf("%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus NUL byte is 12}}
+  scanf("%4s %5s %9s", buf20, buf30, buf10);
+  scanf("%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 21}}
+  scanf("%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus NUL byte is 22}}
+  scanf("%19s %5s %9s", buf20, buf30, buf10);
+  scanf("%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_sscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  sscanf("a b c", "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  sscanf("a b c", "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  sscanf("a b c", "%4s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  sscanf("a b c", "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  sscanf("a b c", "%19s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_fscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  fscanf(0, "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 11}}
+  fscanf(0, "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus NUL byte is 12}}
+  fscanf(0, "%4s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 21}}
+  fscanf(0, "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus NUL byte is 22}}
+  fscanf(0, "%19s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%19s %29s %9s", buf20, buf30, buf10);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -408,6 +408,50 @@
 
 namespace {
 
+class ScanfDiagnosticFormatHandler
+: public analyze_format_string::FormatStringHandler {
+  // Accepts the argument index (relative to the first destination index) of the
+  // argument whose size we want.
+  using ComputeSizeFunction =
+  llvm::function_ref(unsigned)>;
+
+  // Accepts the argument index (relative to the first destination index), the
+  // destination size, and the source size).
+  using DiagnoseFunction =
+  llvm::function_ref;
+
+  ComputeSizeFunction ComputeSizeArgument;
+  DiagnoseFunction Diagnose;
+
+public:
+  ScanfDiagnosticFormatHandler(ComputeSizeFunction ComputeSizeArgument,
+   DiagnoseFunction Diagnose)
+  : ComputeSizeArgument(ComputeSizeArgument), Diagnose(Diagnose) {}
+
+  bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
+const char *St

[PATCH] D111952: [clang] [MinGW] Guess the right ix86 arch name spelling as sysroot

2021-10-27 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 382801.
mstorsjo added a comment.

Rebased after renaming `SysrootName` to `SubdirName`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111952

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h
  clang/test/Driver/mingw-sysroot.cpp

Index: clang/test/Driver/mingw-sysroot.cpp
===
--- clang/test/Driver/mingw-sysroot.cpp
+++ clang/test/Driver/mingw-sysroot.cpp
@@ -12,6 +12,7 @@
 // RUN: mkdir -p %T/testroot-clang/bin
 // RUN: ln -s %clang %T/testroot-clang/bin/x86_64-w64-mingw32-clang
 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %T/testroot-clang/x86_64-w64-mingw32
+// RUN: ln -s %S/Inputs/mingw_arch_tree/usr/i686-w64-mingw32 %T/testroot-clang/i686-w64-mingw32
 
 
 // If we find a gcc in the path with the right triplet prefix, pick that as
@@ -36,3 +37,14 @@
 // the libgcc directory:
 
 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-gcc/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
+
+
+// If the user requests a different arch via the -m32 option, which changes
+// x86_64 into i386, check that the driver notices that it can't find a
+// sysroot for i386 but there is one for i686, and uses that one.
+// (In practice, this usecase is when using an unprefixed native clang
+// that defaults to x86_64 mingw, but it's easier to test in cross setups
+// with symlinks, like the other tests here.)
+
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 -m32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG_I686 %s
+// CHECK_TESTROOT_CLANG_I686: "{{[^"]+}}/testroot-clang{{/|}}i686-w64-mingw32{{/|}}include"
Index: clang/lib/Driver/ToolChains/MinGW.h
===
--- clang/lib/Driver/ToolChains/MinGW.h
+++ clang/lib/Driver/ToolChains/MinGW.h
@@ -60,6 +60,9 @@
   MinGW(const Driver &D, const llvm::Triple &Triple,
 const llvm::opt::ArgList &Args);
 
+  static void FixTripleArch(const Driver &D, llvm::Triple &Triple,
+const llvm::opt::ArgList &Args);
+
   bool HasNativeLLVMSupport() const override;
 
   bool IsIntegratedAssemblerDefault() const override;
@@ -103,8 +106,6 @@
   mutable std::unique_ptr Preprocessor;
   mutable std::unique_ptr Compiler;
   void findGccLibDir();
-  llvm::ErrorOr findGcc();
-  llvm::ErrorOr findClangRelativeSysroot();
 
   bool NativeLLVMSupport;
 };
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -369,9 +369,9 @@
   }
 }
 
-llvm::ErrorOr toolchains::MinGW::findGcc() {
+static llvm::ErrorOr findGcc(const llvm::Triple &T) {
   llvm::SmallVector, 2> Gccs;
-  Gccs.emplace_back(getTriple().getArchName());
+  Gccs.emplace_back(T.getArchName());
   Gccs[0] += "-w64-mingw32-gcc";
   Gccs.emplace_back("mingw32-gcc");
   // Please do not add "gcc" here
@@ -381,13 +381,14 @@
   return make_error_code(std::errc::no_such_file_or_directory);
 }
 
-llvm::ErrorOr toolchains::MinGW::findClangRelativeSysroot() {
+static llvm::ErrorOr
+findClangRelativeSysroot(const Driver &D, const llvm::Triple &T,
+ std::string &SubdirName) {
   llvm::SmallVector, 2> Subdirs;
-  Subdirs.emplace_back(getTriple().str());
-  Subdirs.emplace_back(getTriple().getArchName());
+  Subdirs.emplace_back(T.str());
+  Subdirs.emplace_back(T.getArchName());
   Subdirs[1] += "-w64-mingw32";
-  StringRef ClangRoot =
-  llvm::sys::path::parent_path(getDriver().getInstalledDir());
+  StringRef ClangRoot = llvm::sys::path::parent_path(D.getInstalledDir());
   StringRef Sep = llvm::sys::path::get_separator();
   for (StringRef CandidateSubdir : Subdirs) {
 if (llvm::sys::fs::is_directory(ClangRoot + Sep + CandidateSubdir)) {
@@ -404,13 +405,16 @@
   RocmInstallation(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
+  // The sequence for detecting a sysroot here should be kept in sync with
+  // the testTriple function below.
   if (getDriver().SysRoot.size())
 Base = getDriver().SysRoot;
   // Look for /../; if found, use /.. as the
   // base as it could still be a base for a gcc setup with libgcc.
-  else if (llvm::ErrorOr TargetSubdir = findClangRelativeSysroot())
+  else if (llvm::ErrorOr TargetSubdir =
+   findClangRelativeSysroot(getDriver(), getTriple(), SubdirName))
 Base = std::string(llvm::sys::path::parent_path(TargetSubdir.get()));
-  else if (llvm::ErrorOr GPPName 

[PATCH] D112387: [clang] [MinGW] Rename the 'Arch' member to 'SysrootName'. NFC.

2021-10-27 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 382798.
mstorsjo added a comment.

Renamed the variable to `SubdirName`. Will push tomorrow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112387

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h

Index: clang/lib/Driver/ToolChains/MinGW.h
===
--- clang/lib/Driver/ToolChains/MinGW.h
+++ clang/lib/Driver/ToolChains/MinGW.h
@@ -99,7 +99,7 @@
   std::string Base;
   std::string GccLibDir;
   std::string Ver;
-  std::string Arch;
+  std::string SubdirName;
   mutable std::unique_ptr Preprocessor;
   mutable std::unique_ptr Compiler;
   void findGccLibDir();
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -349,20 +349,20 @@
 }
 
 void toolchains::MinGW::findGccLibDir() {
-  llvm::SmallVector, 2> Archs;
-  Archs.emplace_back(getTriple().getArchName());
-  Archs[0] += "-w64-mingw32";
-  Archs.emplace_back("mingw32");
-  if (Arch.empty())
-Arch = std::string(Archs[0].str());
+  llvm::SmallVector, 2> SubdirNames;
+  SubdirNames.emplace_back(getTriple().getArchName());
+  SubdirNames[0] += "-w64-mingw32";
+  SubdirNames.emplace_back("mingw32");
+  if (SubdirName.empty())
+SubdirName = std::string(SubdirNames[0].str());
   // lib: Arch Linux, Ubuntu, Windows
   // lib64: openSUSE Linux
   for (StringRef CandidateLib : {"lib", "lib64"}) {
-for (StringRef CandidateArch : Archs) {
+for (StringRef CandidateSysroot : SubdirNames) {
   llvm::SmallString<1024> LibDir(Base);
-  llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch);
+  llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateSysroot);
   if (findGccVersion(LibDir, GccLibDir, Ver)) {
-Arch = std::string(CandidateArch);
+SubdirName = std::string(CandidateSysroot);
 return;
   }
 }
@@ -391,7 +391,7 @@
   StringRef Sep = llvm::sys::path::get_separator();
   for (StringRef CandidateSubdir : Subdirs) {
 if (llvm::sys::fs::is_directory(ClangRoot + Sep + CandidateSubdir)) {
-  Arch = std::string(CandidateSubdir);
+  SubdirName = std::string(CandidateSubdir);
   return (ClangRoot + Sep + CandidateSubdir).str();
 }
   }
@@ -423,10 +423,10 @@
   // correct crtbegin.o ,cetend.o would be found.
   getFilePaths().push_back(GccLibDir);
   getFilePaths().push_back(
-  (Base + Arch + llvm::sys::path::get_separator() + "lib").str());
+  (Base + SubdirName + llvm::sys::path::get_separator() + "lib").str());
   getFilePaths().push_back(Base + "lib");
   // openSUSE
-  getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
+  getFilePaths().push_back(Base + SubdirName + "/sys-root/mingw/lib");
 
   NativeLLVMSupport =
   Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER)
@@ -573,11 +573,12 @@
   if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
 // openSUSE
 addSystemInclude(DriverArgs, CC1Args,
- Base + Arch + "/sys-root/mingw/include");
+ Base + SubdirName + "/sys-root/mingw/include");
   }
 
   addSystemInclude(DriverArgs, CC1Args,
-   Base + Arch + llvm::sys::path::get_separator() + "include");
+   Base + SubdirName + llvm::sys::path::get_separator() +
+   "include");
   addSystemInclude(DriverArgs, CC1Args, Base + "include");
 }
 
@@ -596,8 +597,9 @@
 .str();
 if (getDriver().getVFS().exists(TargetDir))
   addSystemInclude(DriverArgs, CC1Args, TargetDir);
-addSystemInclude(DriverArgs, CC1Args, Base + Arch + Slash + "include" +
-  Slash + "c++" + Slash + "v1");
+addSystemInclude(DriverArgs, CC1Args,
+ Base + SubdirName + Slash + "include" + Slash + "c++" +
+ Slash + "v1");
 addSystemInclude(DriverArgs, CC1Args,
  Base + "include" + Slash + "c++" + Slash + "v1");
 break;
@@ -606,9 +608,10 @@
   case ToolChain::CST_Libstdcxx:
 llvm::SmallVector, 4> CppIncludeBases;
 CppIncludeBases.emplace_back(Base);
-llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++");
+llvm::sys::path::append(CppIncludeBases[0], SubdirName, "include", "c++");
 CppIncludeBases.emplace_back(Base);
-llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver);
+llvm::sys::path::append(CppIncludeBases[1], SubdirName, "include", "c++",
+Ver);
 CppIncludeBases.emplace_back(Base);
 llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver);
 CppIncludeBases.emplace_back(GccLibDir);
@@ -616,7 +619,7 @@
 for (auto &CppIncludeBase :

[PATCH] D112569: -Wformat-nonliteral should not trigger for format strings passed to blocks with __attribute__((format))

2021-10-27 Thread Félix Cloutier via Phabricator via cfe-commits
fcloutier updated this revision to Diff 382788.
fcloutier added a reviewer: ahatanak.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112569

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/format-strings.c


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs -fno-signed-char %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem 
%S/Inputs -fno-signed-char %s
 
 #include 
 #include 
@@ -714,3 +714,30 @@
 void test_printf_opaque_ptr(void *op) {
   printf("%s", op); // expected-warning{{format specifies type 'char *' but 
the argument has type 'void *'}}
 }
+
+void test_block() {
+  void __attribute__((__format__(__printf__, 1, 2))) (^printf_arg1)(
+  const char *, ...) =
+  ^(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(fmt, ap);
+va_end(ap);
+  };
+
+  printf_arg1("%s string %i\n", "aaa", 123);
+  printf_arg1("%s string\n", 123); // expected-warning{{format specifies type 
'char *' but the argument has type 'int'}}
+
+  void __attribute__((__format__(__printf__, 2, 3))) (^printf_arg2)(
+  const char *, const char *, ...) =
+  ^(const char *not_fmt, const char *fmt, ...)
+  __attribute__((__format__(__printf__, 2, 3))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(not_fmt, ap); // expected-warning{{format string is not a string 
literal}}
+va_end(ap);
+  };
+
+  printf_arg2("foo", "%s string %i\n", "aaa", 123);
+  printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument 
not used by format string}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7780,11 +7780,11 @@
   // }
   if (HasVAListArg) {
 if (const ParmVarDecl *PV = dyn_cast(VD)) {
-  if (const NamedDecl *ND = dyn_cast(PV->getDeclContext())) 
{
+  if (const Decl *D = dyn_cast(PV->getDeclContext())) {
 int PVIndex = PV->getFunctionScopeIndex() + 1;
-for (const auto *PVFormat : ND->specific_attrs()) {
+for (const auto *PVFormat : D->specific_attrs()) {
   // adjust for implicit parameter
-  if (const CXXMethodDecl *MD = dyn_cast(ND))
+  if (const CXXMethodDecl *MD = dyn_cast(D))
 if (MD->isInstance())
   ++PVIndex;
   // We also check if the formats are compatible.


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s
 
 #include 
 #include 
@@ -714,3 +714,30 @@
 void test_printf_opaque_ptr(void *op) {
   printf("%s", op); // expected-warning{{format specifies type 'char *' but the argument has type 'void *'}}
 }
+
+void test_block() {
+  void __attribute__((__format__(__printf__, 1, 2))) (^printf_arg1)(
+  const char *, ...) =
+  ^(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(fmt, ap);
+va_end(ap);
+  };
+
+  printf_arg1("%s string %i\n", "aaa", 123);
+  printf_arg1("%s string\n", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
+
+  void __attribute__((__format__(__printf__, 2, 3))) (^printf_arg2)(
+  const char *, const char *, ...) =
+  ^(const char *not_fmt, const char *fmt, ...)
+  __attribute__((__format__(__printf__, 2, 3))) {
+va_list ap;
+va_start(ap, fmt);
+vprintf(not_fmt, ap); // expected-warning{{format string is not a string literal}}
+va_end(ap);
+  };
+
+  printf_arg2("foo", "%s string %i\n", "aaa", 123);
+  printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7780,11 +7780

[PATCH] D112659: Add a limit to __make_integer_seq builtin.

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

I wonder if more generally we should have a limit on either the size of a pack 
or the number of template arguments in a template specialization, rather than 
limiting only `__make_integer_seq`? I think a hand-rolled 
`make_integer_sequence` implementation should also be limited in the same way.

I'd also be inclined to pick a smaller default limit. Maybe 64K? I think we 
should be aiming to pick a limit that causes template argument list explosions 
to be caught before the compiler runs out of memory and dies and before the 
user gets bored and interrupts the compilation, and 16M seems a bit high for 
both.


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

https://reviews.llvm.org/D112659

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


[PATCH] D110210: [clang] NFC: include non friendly types and missing sugar in test expectations

2021-10-27 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG086e111216bc: [clang] NFC: include non friendly types and 
missing sugar in test expectations (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110210

Files:
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
  clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
  clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
  clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
  clang/test/SemaCXX/cxx1z-decomposition.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp
  clang/test/SemaCXX/redeclared-alias-template.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -43,7 +43,7 @@
   typedef A d;
   typedef A d;
   typedef A> d;
-  typedef A> e; // expected-error {{is not implicitly convertible}}
+  typedef A> e; // expected-error {{value of type '' is not implicitly convertible to 'void (*)()'}}
 
   typedef A x; // expected-error {{not allowed in a converted constant}}
   typedef A y;
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template class X> struct A {
 template N> struct B; // expected-note 2{{here}}
-template struct B {}; // expected-error {{specializes a template parameter with dependent type 'Y'}}
+template struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'type-parameter-0-0 *')}}
   };
   A::B ax;
   A::B ay; // expected-error {{undefined}} expected-note {{instantiation of}}
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,7 +31,7 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static_assert failed}}
+static_assert(a == 0, ""); // expected-error {{static_assert failed due to requirement 'a == 0'}}
   }
 }
 
Index: clang/test/SemaCXX/redeclared-alias-template.cpp
===
--- clang/test/SemaCXX/redeclared-alias-template.cpp
+++ clang/test/SemaCXX/redeclared-alias-template.cpp
@@ -5,7 +5,7 @@
 template using A = T1; // expected-error {{too many template parameters in template redeclaration}}
 
 template using B = T1; // expected-note {{previous}}
-template using B = T1; // expected-error {{type alias template redefinition with different types}}
+template using B = T1; // expected-error {{type alias template redefinition with different types ('T1' (aka 'type-parameter-0-1') vs 'T1' (aka 'type-parameter-0-0'))}}
 
 
 template struct S;
Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -133,7 +133,7 @@
 template  S(T t) -> S;
 
 void baz() {
-  bar(S(123)); // expected-error {{no matching conversion}}
+  bar(S(123)); // expected-error {{no matching conversion for functional-style cast from 'int' to 'test11::S<>'}}
 }
 } // namespace test11
 
Index: clang/test/SemaCXX/deduced-return-type-cxx14.cpp
===
--- clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -146,7 +146,7 @@
   auto fwd_decl(); // expected-note {{candidate template ignored: could not match 'auto ()' against 'int ()'}}
   int g = fwd_decl();
 
-  auto (*p)() = f1; // expected-error {{incompatible initializer}}
+  auto (*p)() = f1; // expected-error {{variable 'p' with type 'auto (*)()' has incompatible initializer of type ''}}
   auto (*q)() = f1; // ok
 
   typedef decltype(f2(1.2)) dbl; // cxx14_20-note {{previous}}
Index: clang/test/SemaCXX/cxx1z-decomposition.cpp
=

[clang] 086e111 - [clang] NFC: include non friendly types and missing sugar in test expectations

2021-10-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-10-27T23:03:29+02:00
New Revision: 086e111216bc4fb8065aa7ef4bc226380d1c237e

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

LOG: [clang] NFC: include non friendly types and missing sugar in test 
expectations

The dump of all diagnostics of all tests under 
`clang/test/{CXX,SemaCXX,SemaTemplate}` was analyzed , and all the cases where 
there were obviously bad canonical types being printed, like 
`type-parameter-*-*` and `` were identified. Also a 
small amount of cases of missing sugar were analyzed.

This patch then spells those explicitly in the test expectations, as 
preparatory work for future fixes for these problems.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp

clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaCXX/recovery-expr-type.cpp
clang/test/SemaCXX/redeclared-alias-template.cpp
clang/test/SemaTemplate/instantiate-var-template.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
index f780bf796ee43..2933532627d4c 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
@@ -7,7 +7,7 @@ int &b = [] (int &r) -> decltype(auto) { return r; } (a);
 int &c = [] (int &r) -> decltype(auto) { return (r); } (a);
 int &d = [] (int &r) -> auto & { return r; } (a);
 int &e = [] (int &r) -> auto { return r; } (a); // expected-error {{cannot 
bind to a temporary}}
-int &f = [] (int r) -> decltype(auto) { return r; } (a); // expected-error 
{{cannot bind to a temporary}}
+int &f = [] (int r) -> decltype(auto) { return r; } (a); // expected-error 
{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 
'int'}}
 int &g = [] (int r) -> decltype(auto) { return (r); } (a); // expected-warning 
{{reference to stack}}
 // cxx2b-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a 
temporary of type 'int'}}
 

diff  --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
index cb9541caaddd4..cb9407b1db88b 100644
--- 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
+++ 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
@@ -36,7 +36,7 @@ namespace std {
 
 namespace p0702r1 {
   template struct X { // expected-note {{candidate}}
-X(std::initializer_list); // expected-note {{candidate}}
+X(std::initializer_list); // expected-note {{candidate template 
ignored: could not match 'initializer_list' against 
'p0702r1::Z'}}
   };
 
   X xi = {0};
@@ -84,4 +84,4 @@ int main() {
 }
 
 
-}
\ No newline at end of file
+}

diff  --git a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp 
b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
index d6d171470c21d..0963dd23724a8 100644
--- a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
@@ -336,9 +336,9 @@ namespace p0962r1 {
   void use(NA::A a, NB::B b, NC::C c, ND::D d, NE::E e, NF::F f) {
 for (auto x : a) {}
 for (auto x : b) {}
-for (auto x : c) {} // expected-error {{no viable 'end' function}}
-for (auto x : d) {} // expected-error {{no viable 'begin' function}}
-for (auto x : e) {} // expected-error {{no viable 'begin' function}}
-for (auto x : f) {} // expected-error {{no viable 'end' function}}
+for (auto x : c) {} // expected-error {{invalid range expression of type 
'p0962r1::NC::C'; no viable 'end' function available}}
+for (auto x : d) {} // expected-error {{invalid range expression of type 
'p0962r1::ND::D'; no viable 'begin' function available}}
+for (auto x : e) {} // expected-error {{invalid range expression of type 
'p0962r1::NE::E'; no viable 'begin' function available}}
+for (auto x : f) {

[PATCH] D112663: [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-10-27 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, sgraenitz, lhames, thakis.
Herald added a subscriber: mgorny.
v.g.vassilev requested review of this revision.

Repository:
  rC Clang

https://reviews.llvm.org/D112663

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/IncrementalProcessingTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -14,8 +14,13 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+
+#include "llvm/Support/TargetSelect.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -123,4 +128,109 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+static std::string MangleName(NamedDecl *ND) {
+  ASTContext &C = ND->getASTContext();
+  std::unique_ptr MangleC(C.createMangleContext());
+  std::string mangledName;
+  llvm::raw_string_ostream RawStr(mangledName);
+  MangleC->mangleName(ND, RawStr);
+  return RawStr.str();
+}
+struct LLVMInitRAII {
+  LLVMInitRAII() {
+llvm::InitializeNativeTarget();
+llvm::InitializeNativeTargetAsmPrinter();
+  }
+  ~LLVMInitRAII() { llvm::llvm_shutdown(); }
+} LLVMInit;
+
+TEST(IncrementalProcessing, FindMangledNameSymbol) {
+
+  std::unique_ptr Interp = createInterpreter();
+
+  auto &PTU(cantFail(Interp->Parse("int f(const char*) {return 0;}")));
+  EXPECT_EQ(1U, DeclsSize(PTU.TUPart));
+  auto R1DeclRange = PTU.TUPart->decls();
+
+  NamedDecl *ND = cast(*R1DeclRange.begin());
+  // Lower the PTU
+  if (llvm::Error Err = Interp->Execute(PTU)) {
+// We cannot execute on the platform.
+consumeError(std::move(Err));
+return;
+  }
+
+  std::string MangledName = MangleName(ND);
+  auto Addr =
+  cantFail(Interp->getSymbolAddress(MangledName, /*IsMangled=*/true));
+  EXPECT_TRUE(Addr != 0);
+}
+
+static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) {
+  std::string Name = TD->getQualifiedNameAsString();
+  const clang::Type *RDTy = TD->getTypeForDecl();
+  clang::ASTContext &C = Interp.getCompilerInstance()->getASTContext();
+  size_t size = C.getTypeSize(RDTy);
+  void *loc = malloc(size);
+
+  // Tell the interpreter to call the default ctor with this memory. Synthesize:
+  // new (loc) ClassName;
+  static unsigned counter = 0;
+  std::stringstream ss;
+  ss << "auto _v" << counter++ << " = "
+ << "new ((void*)" << loc << ")" << Name << "();";
+
+  auto R = Interp.ParseAndExecute(ss.str());
+  if (!R)
+return nullptr;
+
+  return loc;
+}
+
+static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
+  Sema &SemaRef = Interp.getCompilerInstance()->getSema();
+  ASTContext &C = SemaRef.getASTContext();
+  DeclarationName DeclName = &C.Idents.get(Name);
+  LookupResult R(SemaRef, DeclName, SourceLocation(), Sema::LookupOrdinaryName);
+  SemaRef.LookupName(R, SemaRef.TUScope);
+  assert(!R.empty());
+  return R.getFoundDecl();
+}
+
+TEST(IncrementalProcessing, InstantiateTemplate) {
+  std::unique_ptr Interp = createInterpreter();
+
+  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
+   "extern \"C\" int printf(const char*,...);"
+   "class A {};"
+   "struct B {"
+   "  template"
+   "  int callme(T) { return 42; }"
+   "};"));
+  auto &PTU = llvm::cantFail(Interp->Parse("auto _t = &B::callme;"));
+  auto PTUDeclRange = PTU.TUPart->decls();
+  EXPECT_TRUE(std::distance(PTUDeclRange.begin(), PTUDeclRange.end()));
+
+  // Lower the PTU
+  if (llvm::Error Err = Interp->Execute(PTU)) {
+// We cannot execute on the platform.
+consumeError(std::move(Err));
+return;
+  }
+
+  TypeDecl *TD = cast(LookupSingleName(*Interp, "A"));
+  void *NewA = AllocateObject(TD, *Interp);
+
+  // Find back the template specialization
+  VarDecl *VD = static_cast(*PTUDeclRange.begin());
+  UnaryOperator *UO = llvm::cast(VD->getInit());
+  NamedDecl *TmpltSpec = llvm::cast(UO->getSubExpr())->getDecl();
+
+  std::string MangledName = MangleName(TmpltSpec);
+  typedef int (*TemplateSpecFn)(void *);
+  auto fn = (TemplateSpecFn)cantFail(
+  Interp->getSymbolAddress(MangledName, /*IsMangled=*/true));
+  EXPECT_TRUE(42 == fn(NewA));
+}
+
 } // end anonymous namespace
Index: clang/unittests/Interpreter/IncrementalProcessingTest.cpp
=

[PATCH] D112652: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 382779.
sammccall added a comment.

Add more docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112652

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -16,6 +16,7 @@
 namespace clangd {
 namespace {
 
+using ::testing::ElementsAre;
 using ::testing::UnorderedElementsAre;
 
 TEST(IncludeCleaner, ReferencedLocations) {
@@ -236,9 +237,8 @@
 
 TEST(IncludeCleaner, VirtualBuffers) {
   TestTU TU;
-  TU.Filename = "foo.cpp";
   TU.Code = R"cpp(
-#include "macro_spelling_in_scratch_buffer.h"
+#include "macros.h"
 
 using flags::FLAGS_FOO;
 
@@ -251,7 +251,7 @@
   // The pasting operator in combination with DEFINE_FLAG will create
   // ScratchBuffer with `flags::FLAGS_FOO` that will have FileID but not
   // FileEntry.
-  TU.AdditionalFiles["macro_spelling_in_scratch_buffer.h"] = R"cpp(
+  TU.AdditionalFiles["macros.h"] = R"cpp(
 #define DEFINE_FLAG(X) \
 namespace flags { \
 int FLAGS_##X; \
@@ -266,18 +266,27 @@
   ParsedAST AST = TU.build();
   auto &SM = AST.getSourceManager();
   auto &Includes = AST.getIncludeStructure();
+
   auto ReferencedFiles = findReferencedFiles(findReferencedLocations(AST), SM);
-  auto Entry = SM.getFileManager().getFile(
-  testPath("macro_spelling_in_scratch_buffer.h"));
-  ASSERT_TRUE(Entry);
-  auto FID = SM.translateFile(*Entry);
-  // No "" FID.
-  EXPECT_THAT(ReferencedFiles, UnorderedElementsAre(FID));
-  // Should not crash due to  "files" missing from include
-  // structure.
-  EXPECT_THAT(
-  getUnused(Includes, translateToHeaderIDs(ReferencedFiles, Includes, SM)),
-  ::testing::IsEmpty());
+  llvm::StringSet<> ReferencedFileNames;
+  for (FileID FID : ReferencedFiles)
+ReferencedFileNames.insert(
+SM.getPresumedLoc(SM.getLocForStartOfFile(FID)).getFilename());
+  // Note we deduped the names as _number_ of s is uninteresting.
+  EXPECT_THAT(ReferencedFileNames.keys(),
+  UnorderedElementsAre("", "",
+   testPath("macros.h")));
+
+  // Should not crash due to FileIDs that are not headers.
+  auto ReferencedHeaders = translateToHeaderIDs(ReferencedFiles, Includes, SM);
+  std::vector ReferencedHeaderNames;
+  for (IncludeStructure::HeaderID HID : ReferencedHeaders)
+ReferencedHeaderNames.push_back(Includes.getRealPath(HID));
+  // Non-header files are gone at this point.
+  EXPECT_THAT(ReferencedHeaderNames, ElementsAre(testPath("macros.h")));
+
+  // Sanity check.
+  EXPECT_THAT(getUnused(Includes, ReferencedHeaders), ::testing::IsEmpty());
 }
 
 } // namespace
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -49,10 +49,13 @@
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
 /// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// The output only includes things SourceManager sees as files (not macro IDs).
+/// This can include ,  etc that are not true files.
 llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
const SourceManager &SM);
 
 /// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+/// FileIDs that are not true files ( etc) are dropped.
 llvm::DenseSet
 translateToHeaderIDs(const llvm::DenseSet &Files,
  const IncludeStructure &Includes, const SourceManager &SM);
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -129,9 +129,7 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-// Check if Loc is not written in a physical file.
-if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc) ||
-SM.isWrittenInCommandLineFile(Loc))
+if (FID.isInvalid())
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {
@@ -142,15 +140,9 @@
 if (!Macros.insert(FID).second)
   return;
 const auto &Exp = SM.getSLocEntry(FID).getExpansion();
-// For token pasting operator in macros, spelling and expansion locations
-// can be within a temporary buffer that Clang creates (scratch space or
-// ScratchBuffer). That is not a real file we can include.
-if (!SM.isWrittenInScratchSpace(Exp.getSpellingLoc()))

[PATCH] D109496: [clang] deprecate frelaxed-template-template-args, make it on by default

2021-10-27 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d7fba5f95f0: [clang] deprecate 
frelaxed-template-template-args, make it on by default (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109496

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/Driver/frelaxed-template-template-args.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaTemplate/deduction.cpp
  clang/test/SemaTemplate/default-arguments.cpp
  clang/test/SemaTemplate/instantiate-template-template-parm.cpp
  clang/test/SemaTemplate/nested-template.cpp
  clang/test/SemaTemplate/temp_arg_template.cpp
  clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -596,7 +596,7 @@
 You can use Clang in C++17 mode with the -std=c++17 option
 (use -std=c++1z in Clang 4 and earlier).
 
-
+
 List of features and minimum Clang version with support
 
 
@@ -813,8 +813,8 @@
 
 
   Matching template template parameters to compatible arguments
-  https://wg21.link/p0522r0";>P0522R0
-  Partial (10)
+  https://wg21.link/p0522r0";>P0522R0 (DR)
+  Clang 4 (10)
 
 
   Removing deprecated dynamic exception specifications
@@ -842,13 +842,10 @@
 reverse construction order in that ABI.
 This is not fully supported during constant expression evaluation until Clang 12.
 
-(10): Despite being the resolution to a Defect Report, this
-feature is disabled by default in all language versions, and can be enabled
-explicitly with the flag -frelaxed-template-template-args in Clang 4
-onwards.
-The change to the standard lacks a corresponding change for template partial
-ordering, resulting in ambiguity errors for reasonable and previously-valid
-code. This issue is expected to be rectified soon.
+(10): Prior to Clang 14, this feature is not enabled by
+default, but can be enabled with -frelaxed-template-template-args.
+Starting from Clang 14, the flag is deprecated and will be removed in a future
+version.
 
 
 
Index: clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -frelaxed-template-template-args %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
 
 // expected-note@temp_arg_template_cxx1z.cpp:* 1+{{}}
 
Index: clang/test/SemaTemplate/temp_arg_template.cpp
===
--- clang/test/SemaTemplate/temp_arg_template.cpp
+++ clang/test/SemaTemplate/temp_arg_template.cpp
@@ -6,11 +6,11 @@
 
 template class X> struct B; // expected-note{{previous template template parameter is here}}
 
-template class X> struct C;  // expected-note 2{{previous non-type template parameter with type 'int' is here}}
+template class X> struct C;  // expected-note {{previous non-type template parameter with type 'int' is here}}
 
 template struct X; // expected-note{{too few template parameters in template template argument}}
 template struct Y; // expected-note{{template parameter has a different kind in template argument}}
-template struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
+template struct Ylong;
 template struct Yref; // expected-note{{template non-type parameter has a different type 'const int &' in template argument}}
 
 namespace N {
@@ -27,7 +27,7 @@
 A *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
 B *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
 C *a7;
-C *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
+C *a8;
 C *a9; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
 
 template void f(int);
Index: clang/test/SemaTemplate/nested-template.cpp
===
--- clang/test/SemaTemplate/nested-template.cpp
+++ clang/test/SemaTemplate/nested-template.cpp
@@ -112,18 +112,16 @@
 // Template template parameters
 template
 struct X2

[clang] 2d7fba5 - [clang] deprecate frelaxed-template-template-args, make it on by default

2021-10-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-10-27T22:48:27+02:00
New Revision: 2d7fba5f95f0614f6f2c4a4ed966b307d617898b

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

LOG: [clang] deprecate frelaxed-template-template-args, make it on by default

A resolution to the ambiguity issues created by P0522, which is a DR solving
CWG 150, did not come as expected, so we are just going to accept the change,
and watch how users digest it.

For now we deprecate the flag with a warning, and make it on by default.
We don't remove the flag completely in order to give users a chance to
work around any problems by disabling it.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 
clang/test/Driver/frelaxed-template-template-args.cpp

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaTemplate/deduction.cpp
clang/test/SemaTemplate/default-arguments.cpp
clang/test/SemaTemplate/instantiate-template-template-parm.cpp
clang/test/SemaTemplate/nested-template.cpp
clang/test/SemaTemplate/temp_arg_template.cpp
clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 0cf49ed397f60..e013cf25db809 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -355,7 +355,7 @@ def warn_drv_diagnostics_hotness_requires_pgo : Warning<
 def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
-  "argument '%0' is deprecated, use '%1' instead">, InGroup;
+  "argument '%0' is deprecated%select{|, use '%2' instead}1">, 
InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
   "unknown platform, assuming -mfloat-abi=%0">;
 def warn_ignoring_ftabstop_value : Warning<

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 4651f4fff6aa0..565ecd94f977c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -149,7 +149,7 @@ LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin 
functions")
 LANGOPT(GNUAsm, 1, 1, "GNU-style inline assembly")
 LANGOPT(Coroutines, 1, 0, "C++20 coroutines")
 LANGOPT(DllExportInlines  , 1, 1, "dllexported classes dllexport inline 
methods")
-LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template 
template arguments")
+LANGOPT(RelaxedTemplateTemplateArgs, 1, 1, "C++17 relaxed matching of template 
template arguments")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b4a2411fa5c5c..0d3c053e89ae4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2335,9 +2335,9 @@ defm application_extension : 
BoolFOption<"application-extension",
   PosFlag,
   NegFlag>;
 defm relaxed_template_template_args : 
BoolFOption<"relaxed-template-template-args",
-  LangOpts<"RelaxedTemplateTemplateArgs">, DefaultFalse,
-  PosFlag,
-  NegFlag>;
+  LangOpts<"RelaxedTemplateTemplateArgs">, DefaultTrue,
+  PosFlag,
+  NegFlag>;
 defm sized_deallocation : BoolFOption<"sized-deallocation",
   LangOpts<"SizedDeallocation">, DefaultFalse,
   PosFlag,

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index bef0dec64d4e1..44692e131d3e1 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -683,7 +683,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 Arg->claim();
 if (LegacySanitizeCoverage != 0) {
   D.Diag(diag::warn_drv_deprecated_arg)
-  << Arg->getAsString(Args) << 
"-fsanitize-coverage=trace-pc-guard";
+  << Arg->getAsString(Args) << true
+  << "-fsanitize-coverage=trace-pc-guard";
 }
 continue;
   }
@@ -718,11 +719,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   // enabled.
   if (CoverageFeatures & CoverageTraceBB)
 D.Diag(clang::diag::warn_drv_deprecated_arg)
-<< "-fsanitize-coverage=trace-bb"
+<< "-fsanitize-coverage=trace

[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

2021-10-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.
Herald added a subscriber: carlosgalvezp.



Comment at: clang/include/clang/AST/Type.h:4968
   QualType getDeducedType() const {
-return !isCanonicalUnqualified() ? getCanonicalTypeInternal() : QualType();
+return DeducedAsType.isNull() ? QualType() : DeducedAsType;
   }





Comment at: clang/lib/AST/ASTImporter.cpp:3275
+!DeducedT.isNull()
+? dyn_cast(DeducedT->getCanonicalTypeInternal())
+: nullptr) {





Comment at: clang/lib/AST/ASTImporter.cpp:3285
   }
-  if (const TypedefType *TypedefT =
-  dyn_cast(FromFPT->getReturnType())) {
-TypedefNameDecl *TD = TypedefT->getDecl();
+  if (const auto *TypedefT = dyn_cast(FromFPT->getReturnType())) {
+const TypedefNameDecl *TD = TypedefT->getDecl();

(Preparing for D112374)



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1154
   if (!ParamFunction || !ArgFunction)
 return Param == Arg;
 

The `==` comparisons here and below should presumably be `hasSameType` 
comparisons now that we're preserving sugar.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1234-1250
   llvm::SmallPtrSet Visited;
   SmallVector ToVisit;
   // We iterate over this later, so we have to use MapVector to ensure
   // determinism.
   llvm::MapVector>
   Matches;
 

I think we should:

* track `ToVisit` as a vector of `QualType`, so we preserve the type sugar as 
written in base specifier lists
* track `Visited` as a set of (canonical) `const CXXRecordDecl*`s rather than 
relying on `RecordType`s always being canonical (they currently are, but I 
don't think that's intended to be guaranteed)



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1385-1388
+P = P.getUnqualifiedType();
 // - If A is a cv-qualified type, A is replaced by the cv-unqualified
 //   version of A.
+A = A.getUnqualifiedType();

Do we need to use `Context.getUnqualifiedArrayType` here, for cases like:
```
typedef const int CInt;
// Partial ordering should deduce `T = int` from both parameters here,
// even though `T = const int` might make more sense for the first one.
template void f(CInt (&)[N], int*);
template void f(T (&)[N], T*);
CInt arr[5];
void g() { f(arr, arr); }
```
? I think `getUnqualifiedType()` on `CInt[N]` will not remove the indirect 
`const` qualifier.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1437
 // top level, so they can be matched with the qualifiers on the parameter.
-if (isa(Arg)) {
+if (isa(A)) {
   Qualifiers Quals;

`A` could be sugar for an array type here.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1546-1568
+  QualType CanP = P.getCanonicalType();
+  // If the parameter type is not dependent, there is nothing to deduce.
+  if (!P->isDependentType()) {
+if (TDF & TDF_SkipNonDependent)
   return Sema::TDK_Success;
+
+QualType CanA = A.getCanonicalType();

I think we can excise `CanA` and `CanP` entirely here so people aren't tempted 
to use them and lose sugar.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1643
 
-  return Param == Arg? Sema::TDK_Success : Sema::TDK_NonDeducedMismatch;
+  return ParDesug == ArgDesug ? Sema::TDK_Success
+  : Sema::TDK_NonDeducedMismatch;

mizvekov wrote:
> mizvekov wrote:
> > rsmith wrote:
> > > This looks wrong to me: we should be comparing the types, not how they're 
> > > written. `Context.hasSameType(Param, Arg)` (or 
> > > `Context.hasSameUnqualifiedType(Param, Arg)` in the 
> > > `TDF_IgnoreQualifiers` case) would be appropriate here.
> > You are right, but the reason we don't get into any troubles here is 
> > because this is dead code anyway, the non-dependent case will always be 
> > handled above :)
> > 
> > Although perhaps, I wonder if we should dig down into non-dependent types 
> > anyway, in case the types are too complex and it's not immediately obvious 
> > what does not match, we could perhaps improve the diagnostic?
> > 
> > I will experiment a little bit with this idea.
> Here are the results of this experiment:
> ```
> error: 'note' diagnostics expected but not seen:
>   File SemaCXX\cxx1z-noexcept-function-type.cpp Line 21: could not match 
> 'void (I) noexcept(false)' (aka 'void (int) noexcept(false)') against 'void 
> (int) noexcept'
> error: 'note' diagnostics seen but not expected:
>   File SemaCXX\cxx1z-noexcept-function-type.cpp Line 21: candidate template 
> ignored: failed template argument deduction
> 
> error: 'note' diagnostics expected but not seen:
>   File SemaCXX\deduced-return-type-cxx14.cpp Line 146: candidate template 
> ignored: could not match 'auto ()' against 'int ()'
>   File Sema

[PATCH] D112633: [AST] fail rather than crash when const evaluating invalid c++ foreach

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGde7494a33a5c: [AST] fail rather than crash when const 
evaluating invalid c++ foreach (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D112633?vs=382705&id=382776#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112633

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -69,3 +69,8 @@
 
 constexpr int test10() { return undef(); } // expected-error {{use of 
undeclared identifier 'undef'}}
 static_assert(test10() <= 1, "should not crash"); // expected-error 
{{static_assert expression is not an integral constant expression}}
+
+struct X {} array[] = {undef()}; // expected-error {{use of undeclared 
identifier 'undef'}}
+constexpr void test11() {
+  for (X& e : array) {}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5319,6 +5319,11 @@
   return ESR;
 }
 
+// In error-recovery cases it's possible to get here even if we failed to
+// synthesize the __begin and __end variables.
+if (!FS->getBeginStmt() || !FS->getEndStmt() || !FS->getCond())
+  return ESR_Failed;
+
 // Create the __begin and __end iterators.
 ESR = EvaluateStmt(Result, Info, FS->getBeginStmt());
 if (ESR != ESR_Succeeded) {


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -69,3 +69,8 @@
 
 constexpr int test10() { return undef(); } // expected-error {{use of undeclared identifier 'undef'}}
 static_assert(test10() <= 1, "should not crash"); // expected-error {{static_assert expression is not an integral constant expression}}
+
+struct X {} array[] = {undef()}; // expected-error {{use of undeclared identifier 'undef'}}
+constexpr void test11() {
+  for (X& e : array) {}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5319,6 +5319,11 @@
   return ESR;
 }
 
+// In error-recovery cases it's possible to get here even if we failed to
+// synthesize the __begin and __end variables.
+if (!FS->getBeginStmt() || !FS->getEndStmt() || !FS->getCond())
+  return ESR_Failed;
+
 // Create the __begin and __end iterators.
 ESR = EvaluateStmt(Result, Info, FS->getBeginStmt());
 if (ESR != ESR_Succeeded) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] de7494a - [AST] fail rather than crash when const evaluating invalid c++ foreach

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

Author: Sam McCall
Date: 2021-10-27T22:45:32+02:00
New Revision: de7494a33a5c3152dd0ed24ea1c8b2760255f2f7

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

LOG: [AST] fail rather than crash when const evaluating invalid c++ foreach

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constexpr-function-recovery-crash.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c74e4c96f7b0..fa0d22064f0e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5319,6 +5319,11 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
   return ESR;
 }
 
+// In error-recovery cases it's possible to get here even if we failed to
+// synthesize the __begin and __end variables.
+if (!FS->getBeginStmt() || !FS->getEndStmt() || !FS->getCond())
+  return ESR_Failed;
+
 // Create the __begin and __end iterators.
 ESR = EvaluateStmt(Result, Info, FS->getBeginStmt());
 if (ESR != ESR_Succeeded) {

diff  --git a/clang/test/SemaCXX/constexpr-function-recovery-crash.cpp 
b/clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
index 94be9a12bc66..4b73cff13838 100644
--- a/clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ b/clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -69,3 +69,8 @@ constexpr int test9(int x) {
 
 constexpr int test10() { return undef(); } // expected-error {{use of 
undeclared identifier 'undef'}}
 static_assert(test10() <= 1, "should not crash"); // expected-error 
{{static_assert expression is not an integral constant expression}}
+
+struct X {} array[] = {undef()}; // expected-error {{use of undeclared 
identifier 'undef'}}
+constexpr void test11() {
+  for (X& e : array) {}
+}



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


[PATCH] D112652: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:261
+if (!FE) {
+  assert(isSpecialBuffer(FID, SM));
+  continue;

kbobyrev wrote:
> kbobyrev wrote:
> > Implementation-wise, this seems like the right place to drop nonexistent 
> > "headers". However, this is a very surprising behavior from something like 
> > "translateToHeaderIDs" for two reasons:
> > 
> > - As the name states, it used to be a simple "translation" process, now 
> > it's also filtering.
> > - `TranslatedHeaderIDs.size() == Files.size()` can be rather unexpected
> > 
> > We never had 1:1 order etc translation assumptions but this is certainly 
> > the new behavior we want to document.
> Thinking out loud: now I'm also thinking about the "handle non self-contained 
> files" + "drop warnings for files without include warnings"
This function is mapping from a domain (FileIDs excluding macros) where special 
buffers exist to a codomain (HeaderIDs) where they don't. Some sort of 
filtering/handling is implied by the signature!
So I think it's not surprising at least if you think about it that way :-) But 
this definitely needs to be documented, I'll do that.

> Thinking out loud: now I'm also thinking about the "handle non self-contained 
> files" + "drop warnings for files without include warnings"

There may some small efficiency from mashing those into this loop as well, but 
I don't think it's worth the confusion.
The reason I put this one inline instead of as a separate filtering step is 
that the check we'd be doing is a natural part of the conversion. It's 
basically a form of [parse, don't 
validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112652

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


[PATCH] D112659: Add a limit to __make_integer_seq builtin.

2021-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: ldionne.
erichkeane added a comment.

Some additional data on a release build (on my quite recent Xeon 8260M):
2^24: 27 sec, ~3.3GB 
2^25: 49 sec, ~6.4GB

It follows a pretty linear pattern from there.  I'm open to choosing a 
different limit if we find one more reasonable for some reason or another 
(@ldionne opinion?).


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

https://reviews.llvm.org/D112659

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


[PATCH] D112661: [clangd] reuse preambles from other files when possible

2021-10-27 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

This is a revisit of D97417  which is a bit 
out of date and fell into oblivion.
I've been using a forked version of clangd including this change for months on 
my day-to-day work and it does significantly improve my experience.
Some numbers showing the kind of improvement you can expect from this change 
can be found in D97417 , they are still 
relevant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112661

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


[PATCH] D112661: [clangd] reuse preambles from other files when possible

2021-10-27 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau created this revision.
qchateau added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, javed.absar.
qchateau requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Keep a store of the preambles of all opened filed, plus 
a configurable number of previously used preambles (default 1). 
When building the AST for a TU, if the preamble for this 
TU is not yet built, look through the stored premables 
to find the best compatible preamble and use this 
preamble to speed-up the AST build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112661

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  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
@@ -329,6 +329,13 @@
 init(getDefaultAsyncThreadsCount()),
 };
 
+opt ClosedPreambleCacheSize{
+"closed-preamble-cache-size",
+cat(Misc),
+desc("Number of preambles of closed files to keep in the cache."),
+init(1),
+};
+
 opt IndexFile{
 "index-file",
 cat(Misc),
@@ -868,6 +875,7 @@
 Opts.StaticIndex = PAI.get();
   }
   Opts.AsyncThreadsCount = WorkerThreadsCount;
+  Opts.ClosedPreambleCacheSize = ClosedPreambleCacheSize;
   Opts.FoldingRanges = FoldingRanges;
   Opts.InlayHints = InlayHints;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -192,6 +192,9 @@
 /// If 0, executes actions synchronously on the calling thread.
 unsigned AsyncThreadsCount = getDefaultAsyncThreadsCount();
 
+// Number of preambles of closed files to keep in the cache.
+unsigned ClosedPreambleCacheSize = 1;
+
 /// Cache (large) preamble data in RAM rather than temporary files on disk.
 bool StorePreamblesInMemory = false;
 
@@ -315,6 +318,8 @@
   class ASTCache;
   /// Tracks headers included by open files, to get known-good compile commands.
   class HeaderIncluderCache;
+  /// Store all known preambles
+  class PreambleStore;
 
   // The file being built/processed in the current thread. This is a hack in
   // order to get the file name into the index implementations. Do not depend on
@@ -338,6 +343,7 @@
   llvm::StringMap> Files;
   std::unique_ptr IdleASTs;
   std::unique_ptr HeaderIncluders;
+  std::unique_ptr Preambles;
   // None when running tasks synchronously and non-None when running tasks
   // asynchronously.
   llvm::Optional PreambleTasks;
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -307,6 +307,65 @@
   }
 };
 
+class TUScheduler::PreambleStore {
+public:
+  struct Entry {
+std::shared_ptr Preamble;
+size_t Score;
+Path FileName;
+
+bool operator>(const Entry &Other) const { return Score > Other.Score; }
+  };
+
+  explicit PreambleStore(size_t ClosedPreamblesToKeep): ClosedPreamblesToKeep(ClosedPreamblesToKeep) {}
+
+  auto getAll() {
+std::unique_lock Lock(Mut);
+return Store;
+  }
+
+  void push(PathRef FileName, std::shared_ptr Preamble) {
+std::unique_lock Lock(Mut);
+auto It = llvm::find_if(
+Store, [&](const auto &Item) { return Item.FileName == FileName; });
+if (It == Store.end()) {
+  Store.push_back(Entry{std::move(Preamble), 0, FileName.str()});
+  popWorstPreambles();
+}
+else {
+  It->Preamble = std::move(Preamble);
+}
+vlog("Store contains {0} preambles", Store.size());
+  }
+
+  void hit(PathRef FileName) {
+std::unique_lock Lock(Mut);
+auto It = llvm::find_if(
+Store, [&](const auto &Item) { return Item.FileName == FileName; });
+if (It == Store.end()) {
+  return;
+}
+It->Score++;
+  }
+
+private:
+  void popWorstPreambles() {
+auto Begin = llvm::partition(
+Store, [](const auto &Item) { return Item.Preamble.use_count() > 1; });
+if (static_cast(std::distance(Begin, Store.end())) <=
+ClosedPreamblesToKeep) {
+  return;
+}
+auto Nth = Begin + ClosedPreamblesToKeep;
+std::nth_element(Begin, Nth, Store.end(), std::greater());
+Store.erase(Nth, Store.end());
+  }
+
+  std::mutex Mut;
+  std::vector Store;
+  size_t ClosedPreamblesToKeep;
+};
+
 namespace {
 
 bool isReliable(const tooling::CompileCommand &Cmd) {
@@ -506,7 +565,8 @@
   ASTWorker(PathRef FileName, const GlobalCompilationDa

[PATCH] D111863: [libunwind] Add an interface for dynamic .eh_frame registration

2021-10-27 Thread Lang Hames via Phabricator via cfe-commits
lhames added a comment.

@joerg Any further thoughts on this?

I'm happy for it to go in as-is -- we can always make the implementation of 
`__unw_add_dynamic_eh_frame_section` / `__unw_remove_dynamic_eh_frame_section` 
later, but the API looks good to me, and I think this is a strict improvement 
in functionality for JIT clients.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111863

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


[PATCH] D112659: Add a limit to __make_integer_seq builtin.

2021-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: aaron.ballman, majnemer, EricWF.
Herald added subscribers: dexonsmith, dang.
erichkeane requested review of this revision.

As brought up in PR48246, passing a large value to `__make_integer_seq`
results in the compiler getting stuck in a large loop and potentially
crashing if it runs out of memory as a result.

This patch puts a command-line configurable limit in place to limit the
size to something reasonable.

I chose 2^24 as default after a brief experimentation with the debug compiler,
which made it take a few minutes.  On a release build, a program with a 2^24
value takes roughly 30 seconds, and uses about 3.3GB of ram.


https://reviews.llvm.org/D112659

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/make_integer_seq.cpp

Index: clang/test/SemaCXX/make_integer_seq.cpp
===
--- clang/test/SemaCXX/make_integer_seq.cpp
+++ clang/test/SemaCXX/make_integer_seq.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,smalllimit -fint-seq-limit 500 -std=c++11 %s
 
 static_assert(__has_builtin(__make_integer_seq), "");
 
@@ -51,3 +52,18 @@
 __make_integer_seq<__make_integer_seq, int, 10> PR28494; // expected-error{{different template parameters}}
 // expected-note@make_integer_seq.cpp:* {{template parameter has a different kind}}
 // expected-note@make_integer_seq.cpp:* {{previous template template parameter is here}}
+
+__make_integer_seq PR48246;
+// smalllimit-error@-1{{'__make_integer_seq' exceeded maximum limit of 500}}
+// smalllimit-note@-2 {{use -fint-seq-limit=N to increase '__make_integer_seq' limit}}
+
+// Default value is ~16.7 million, so without the command line option, fail.
+__make_integer_seq PR48246_b;
+// expected-error@-1{{'__make_integer_seq' exceeded maximum limit of}}
+// expected-note@-2 {{use -fint-seq-limit=N to increase '__make_integer_seq' limit}}
+
+using size_t = unsigned long long;
+
+__make_integer_seq PR48246_c;
+// expected-error@-1{{'__make_integer_seq' exceeded maximum limit of}}
+// expected-note@-2 {{use -fint-seq-limit=N to increase '__make_integer_seq' limit}}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3452,6 +3452,18 @@
   return QualType();
 }
 
+// The below loop ends up taking a very long time and causing an OOM crash
+// if 'N' is too large.  Limit to a command-line specified value.
+if (NumArgs > SemaRef.getLangOpts().MakeIntSeqSize) {
+  SemaRef.Diag(TemplateArgs[2].getLocation(),
+   diag::err_integer_sequence_length_exceeded)
+  << SemaRef.getLangOpts().MakeIntSeqSize;
+  SemaRef.Diag(TemplateArgs[2].getLocation(),
+   diag::note_integer_sequence_length_exceeded)
+  << SemaRef.getLangOpts().MakeIntSeqSize;
+  return QualType();
+}
+
 QualType ArgTy = NumArgsArg.getIntegralType();
 TemplateArgumentListInfo SyntheticTemplateArgs;
 // The type argument gets reused as the first template argument in the
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5617,6 +5617,11 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fint_seq_limit_EQ)) {
+CmdArgs.push_back("-fint-seq-limit");
+CmdArgs.push_back(A->getValue());
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_depth_EQ)) {
 CmdArgs.push_back("-fconstexpr-depth");
 CmdArgs.push_back(A->getValue());
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2626,6 +2626,7 @@
Group;
 def foperator_arrow_depth_EQ : Joined<["-"], "foperator-arrow-depth=">,
Group;
+def fint_seq_limit_EQ : Joined<["-"], "fint-seq-limit=">, Group;
 
 def fsave_optimization_record : Flag<["-"], "fsave-optimization-record">,
   Group, HelpText<"Generate a YAML optimization record file">;
@@ -5679,6 +5680,9 @@
 def foperator_arrow_depth : Separate<["-"], "foperator-arrow-depth">,
   HelpText<"Maximum number of 'operator->'s to call for a member access">,
   MarshallingInfoInt, "256">;
+def fint_seq_limit : Separate<["-"], "fint-seq-limit">,
+  HelpText<"Maximum value of the __make_integer_seq builtin">,
+  MarshallingInfoInt, "16777216">;
 def fconstexpr_depth : Separate<["-"], "fconstexpr-depth">,
   HelpT

[PATCH] D112652: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

2021-10-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Thank you for taking care of this!




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:261
+if (!FE) {
+  assert(isSpecialBuffer(FID, SM));
+  continue;

Implementation-wise, this seems like the right place to drop nonexistent 
"headers". However, this is a very surprising behavior from something like 
"translateToHeaderIDs" for two reasons:

- As the name states, it used to be a simple "translation" process, now it's 
also filtering.
- `TranslatedHeaderIDs.size() == Files.size()` can be rather unexpected

We never had 1:1 order etc translation assumptions but this is certainly the 
new behavior we want to document.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:261
+if (!FE) {
+  assert(isSpecialBuffer(FID, SM));
+  continue;

kbobyrev wrote:
> Implementation-wise, this seems like the right place to drop nonexistent 
> "headers". However, this is a very surprising behavior from something like 
> "translateToHeaderIDs" for two reasons:
> 
> - As the name states, it used to be a simple "translation" process, now it's 
> also filtering.
> - `TranslatedHeaderIDs.size() == Files.size()` can be rather unexpected
> 
> We never had 1:1 order etc translation assumptions but this is certainly the 
> new behavior we want to document.
Thinking out loud: now I'm also thinking about the "handle non self-contained 
files" + "drop warnings for files without include warnings"



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:275
+SM.getPresumedLoc(SM.getLocForStartOfFile(FID)).getFilename());
+  // (Note we deduped the names as _number_ of s is uninteresting).
+  EXPECT_THAT(ReferencedFileNames.keys(),

nit: Drop the parenthesis?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112652

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


[PATCH] D109496: [clang] deprecate frelaxed-template-template-args, make it on by default

2021-10-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 382762.
mizvekov added a comment.

rebase, one last CI run.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109496

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/Driver/frelaxed-template-template-args.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaTemplate/deduction.cpp
  clang/test/SemaTemplate/default-arguments.cpp
  clang/test/SemaTemplate/instantiate-template-template-parm.cpp
  clang/test/SemaTemplate/nested-template.cpp
  clang/test/SemaTemplate/temp_arg_template.cpp
  clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -596,7 +596,7 @@
 You can use Clang in C++17 mode with the -std=c++17 option
 (use -std=c++1z in Clang 4 and earlier).
 
-
+
 List of features and minimum Clang version with support
 
 
@@ -813,8 +813,8 @@
 
 
   Matching template template parameters to compatible arguments
-  https://wg21.link/p0522r0";>P0522R0
-  Partial (10)
+  https://wg21.link/p0522r0";>P0522R0 (DR)
+  Clang 4 (10)
 
 
   Removing deprecated dynamic exception specifications
@@ -842,13 +842,10 @@
 reverse construction order in that ABI.
 This is not fully supported during constant expression evaluation until Clang 12.
 
-(10): Despite being the resolution to a Defect Report, this
-feature is disabled by default in all language versions, and can be enabled
-explicitly with the flag -frelaxed-template-template-args in Clang 4
-onwards.
-The change to the standard lacks a corresponding change for template partial
-ordering, resulting in ambiguity errors for reasonable and previously-valid
-code. This issue is expected to be rectified soon.
+(10): Prior to Clang 14, this feature is not enabled by
+default, but can be enabled with -frelaxed-template-template-args.
+Starting from Clang 14, the flag is deprecated and will be removed in a future
+version.
 
 
 
Index: clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -frelaxed-template-template-args %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
 
 // expected-note@temp_arg_template_cxx1z.cpp:* 1+{{}}
 
Index: clang/test/SemaTemplate/temp_arg_template.cpp
===
--- clang/test/SemaTemplate/temp_arg_template.cpp
+++ clang/test/SemaTemplate/temp_arg_template.cpp
@@ -6,11 +6,11 @@
 
 template class X> struct B; // expected-note{{previous template template parameter is here}}
 
-template class X> struct C;  // expected-note 2{{previous non-type template parameter with type 'int' is here}}
+template class X> struct C;  // expected-note {{previous non-type template parameter with type 'int' is here}}
 
 template struct X; // expected-note{{too few template parameters in template template argument}}
 template struct Y; // expected-note{{template parameter has a different kind in template argument}}
-template struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
+template struct Ylong;
 template struct Yref; // expected-note{{template non-type parameter has a different type 'const int &' in template argument}}
 
 namespace N {
@@ -27,7 +27,7 @@
 A *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
 B *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
 C *a7;
-C *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
+C *a8;
 C *a9; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
 
 template void f(int);
Index: clang/test/SemaTemplate/nested-template.cpp
===
--- clang/test/SemaTemplate/nested-template.cpp
+++ clang/test/SemaTemplate/nested-template.cpp
@@ -112,18 +112,16 @@
 // Template template parameters
 template
 struct X2 {
-  template class>  // expected-error{{cannot have type 'float'}} \
- 

[PATCH] D111986: [Clang] Add elementwise abs builtin.

2021-10-27 Thread Florian Hahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01870d51b848: [Clang] Add elementwise abs builtin. (authored 
by fhahn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111986

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -14,6 +14,13 @@
 
 // expected-no-diagnostics
 
+void test_builtin_elementwise_abs() {
+  const int a = 2;
+  int b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
 void test_builtin_elementwise_max() {
   const int a = 2;
   int b = 1;
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -2,6 +2,7 @@
 
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef int int3 __attribute__((ext_vector_type(3)));
+typedef unsigned unsigned4 __attribute__((ext_vector_type(4)));
 
 struct Foo {
   char *p;
@@ -11,6 +12,26 @@
 typedef int bar;
 bar b;
 
+void test_builtin_elementwise_abs(int i, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+  struct Foo s = __builtin_elementwise_abs(i);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+  i = __builtin_elementwise_abs();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_abs(i, i);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  i = __builtin_elementwise_abs(v);
+  // expected-error@-1 {{assigning to 'int' from incompatible type 'float4' (vector of 4 'float' values)}}
+
+  u = __builtin_elementwise_abs(u);
+  // expected-error@-1 {{1st argument must be a signed integer or floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_abs(uv);
+  // expected-error@-1 {{1st argument must be a signed integer or floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_max(int i, short s, double d, float4 v, int3 iv, int *p) {
   i = __builtin_elementwise_max(p, d);
   // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -8,12 +8,54 @@
 typedef int bar;
 bar b;
 
+void test_builtin_elementwise_abs(float f1, float f2, double d1, double d2,
+  float4 vf1, float4 vf2, si8 vi1, si8 vi2,
+  long long int i1, long long int i2, short si) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_abs(
+  // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.fabs.f32(float [[F1]])
+  f2 = __builtin_elementwise_abs(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, double* %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.fabs.f64(double [[D1]])
+  d2 = __builtin_elementwise_abs(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.fabs.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_abs(vf1);
+
+  // CHECK:  [[I1:%.+]] = load i64, i64* %i1.addr, align 8
+  // CHECK-NEXT: call i64 @llvm.abs.i64(i64 [[I1]], i1 false)
+  i2 = __builtin_elementwise_abs(i1);
+
+  // CHECK:  [[VI1:%.+]] = load <8 x i16>, <8 x i16>* %vi1.addr, align 16
+  // CHECK-NEXT: call <8 x i16> @llvm.abs.v8i16(<8 x i16> [[VI1]], i1 false)
+  vi2 = __builtin_elementwise_abs(vi1);
+
+  // CHECK:  [[CVI2:%.+]] = load <8 x i16>, <8 x i16>* %cvi2, align 16
+  // CHECK-NEXT: call <8 x i16> @llvm.abs.v8i16(<8 x i16> [[CVI2]], i1 false)
+  const si8 cvi2 = vi2;
+  vi2 = __builtin_elementwise_abs(cvi2);
+
+  // CHECK:  [[IA1:%.+]] = load i32, i32 addrspace(1)* @int_as_one, align 4
+  // CHECK-NEXT: call i32 @llvm.abs.i32(i32 [[IA1]], i1 false)
+  b = __builtin_elementwise_abs(int_as_one);
+
+  // CHECK:   call i32 @llvm.abs.i32(i32 -10, i1 false)
+  b = __builtin_elementwise_abs(-10);
+
+  // CHECK:  [[SI:%.+]] = load i16, i16* %si.addr, align 2
+  // CHECK-NEXT: [[SI_EXT:%.+]] = sext i16 [[SI]] to i32
+  // CHECK-NEXT: [[RES:%.+]] = call i32 @llvm.ab

[clang] 01870d5 - [Clang] Add elementwise abs builtin.

2021-10-27 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2021-10-27T21:01:44+01:00
New Revision: 01870d51b848166eee59ed2e77be0199a561cf59

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

LOG: [Clang] Add elementwise abs builtin.

This patch implements __builtin_elementwise_abs as specified in
D111529.

Reviewed By: aaron.ballman, scanon

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

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index b6967cc26af06..874bc655a00b7 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -643,6 +643,7 @@ BUILTIN(__builtin_alloca, "v*z"   , "Fn")
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
 BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
 
+BUILTIN(__builtin_elementwise_abs, "v.", "nct")
 BUILTIN(__builtin_elementwise_max, "v.", "nct")
 BUILTIN(__builtin_elementwise_min, "v.", "nct")
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ea030aad5d8df..09482d238ff3d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11306,7 +11306,8 @@ def err_builtin_launder_invalid_arg : Error<
 def err_builtin_invalid_arg_type: Error <
   "%ordinal0 argument must be a "
   "%select{vector, integer or floating point type|matrix|"
-   "pointer to a valid matrix element type}1 (was %2)">;
+   "pointer to a valid matrix element type|"
+   "signed integer or floating point type}1 (was %2)">;
 
 def err_builtin_matrix_disabled: Error<
   "matrix types extension is disabled. Pass -fenable-matrix to enable it">;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6bd5f4a35750d..b87532c51f630 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12725,6 +12725,7 @@ class Sema final {
   bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc);
 
   bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
+  bool SemaBuiltinElementwiseMathOneArg(CallExpr *TheCall);
 
   // Matrix builtin handling.
   ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall,

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index af6b496c604f1..02cba577a5420 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3101,6 +3101,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 return RValue::get(V);
   }
 
+  case Builtin::BI__builtin_elementwise_abs: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Result;
+if (Op0->getType()->isIntOrIntVectorTy())
+  Result = Builder.CreateBinaryIntrinsic(
+  llvm::Intrinsic::abs, Op0, Builder.getFalse(), nullptr, "elt.abs");
+else
+  Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, 
nullptr,
+"elt.abs");
+return RValue::get(Result);
+  }
   case Builtin::BI__builtin_elementwise_max: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9d19a81ab23e7..83fb824cb14a6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1976,6 +1976,10 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
   }
 
+  case Builtin::BI__builtin_elementwise_abs:
+if (SemaBuiltinElementwiseMathOneArg(TheCall))
+  return ExprError();
+break;
   case Builtin::BI__builtin_elementwise_min:
   case Builtin::BI__builtin_elementwise_max:
 if (SemaBuiltinElementwiseMath(TheCall))
@@ -16536,6 +16540,31 @@ static bool checkMathBuiltinElementType(Sema &S, 
SourceLocation Loc,
   return false;
 }
 
+bool Sema::SemaBuiltinElementwiseMathOneArg(CallExpr *TheCall) {
+  if (checkArgCount(*this, TheCall, 1))
+return true;
+
+  ExprResult A = UsualUnaryConversions(TheCall->getArg(0));
+  SourceLocation ArgLoc = TheCall->getArg(0)->getBeginLoc();
+  if (A.isInvalid())
+return true;
+
+  TheCall->setArg(0, A.get());
+  QualType TyA = A.get()->getType();
+  if (checkMathBuiltinElementType(*this, ArgLoc, TyA))
+return true;
+
+  QualType EltTy = TyA;
+  if (auto *VecTy = EltTy->getAs())
+EltTy = VecTy->get

[PATCH] D112647: [clang-apply-replacements] Correctly handle relative paths

2021-10-27 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

I'm not really familiar w/ this code. But, if njames93 doesn't respond, then 
I'll give it a go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112647

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


[PATCH] D112648: [clang-tidy] Improve fix-its for `modernize-pass-by-value` check

2021-10-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added a reviewer: alexfh.
avogelsgesang added a subscriber: alexfh.
avogelsgesang added a comment.

not sure whom to add as a reviewer.  According to `git log` this check wasn't 
changed for a while...
Adding @alexfh based on `CODE_OWNERS.TXT`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112648

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


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

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

I'm gonna add docs to `getSValFromStringLiteral` and update the patch. And of 
course will fix your nits.




Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1757-1760
+  // FIXME: Nevertheless, we can't do the same for cases, like:
+  //   const char *str = "123"; // literal length is 4
+  //   char c = str[41];// offset is 41
+  // It should be properly handled before reaching this point.

steakhal wrote:
> martong wrote:
> > ASDenysPetrov wrote:
> > > ASDenysPetrov wrote:
> > > > martong wrote:
> > > > > Thanks for updating the patch! However, this `FIXME` makes me 
> > > > > worried. Do you think you could pass the `Decl` itself to 
> > > > > `getSValFromInitListExpr` in order to be able to check whether the 
> > > > > type is a pointer or an array? 
> > > > This worried me as well. Currently I can't find a way to get the `Decl` 
> > > > for `SL`.
> > > > 
> > > We can load this as is for now with mentioning the known issue.
> > This might cause some itchy false positives. Perhaps, we could address this 
> > in a follow-up patch and then commit them together?
> > Currently I can't find a way to get the Decl for SL.
> Why do you need a Decl? The SVal's gotta be an `Element{"123",41 S64b,char}` 
> for the example in the comment (*).
> 
> (*) With a minor modification: https://godbolt.org/z/7zhGMnf7P
> ```lang=C++
> template  void clang_analyzer_dump(T);
> const char * const str = "123";
> const char * str2 = "123";
> void top() {
>   clang_analyzer_dump(&str[41]);  // &Element{"123",41 S64b,char}
>   clang_analyzer_dump(&str2[41]); // &Element{SymRegion{reg_$0 str2>},41 S64b,char}
> }
> ```
Because only `Decl` can tell us whether it is a `const char str[42]` or `const 
char * const str`. We can't say anything just looking at `SVal`.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1757-1760
+  // FIXME: Nevertheless, we can't do the same for cases, like:
+  //   const char *str = "123"; // literal length is 4
+  //   char c = str[41];// offset is 41
+  // It should be properly handled before reaching this point.

ASDenysPetrov wrote:
> steakhal wrote:
> > martong wrote:
> > > ASDenysPetrov wrote:
> > > > ASDenysPetrov wrote:
> > > > > martong wrote:
> > > > > > Thanks for updating the patch! However, this `FIXME` makes me 
> > > > > > worried. Do you think you could pass the `Decl` itself to 
> > > > > > `getSValFromInitListExpr` in order to be able to check whether the 
> > > > > > type is a pointer or an array? 
> > > > > This worried me as well. Currently I can't find a way to get the 
> > > > > `Decl` for `SL`.
> > > > > 
> > > > We can load this as is for now with mentioning the known issue.
> > > This might cause some itchy false positives. Perhaps, we could address 
> > > this in a follow-up patch and then commit them together?
> > > Currently I can't find a way to get the Decl for SL.
> > Why do you need a Decl? The SVal's gotta be an `Element{"123",41 
> > S64b,char}` for the example in the comment (*).
> > 
> > (*) With a minor modification: https://godbolt.org/z/7zhGMnf7P
> > ```lang=C++
> > template  void clang_analyzer_dump(T);
> > const char * const str = "123";
> > const char * str2 = "123";
> > void top() {
> >   clang_analyzer_dump(&str[41]);  // &Element{"123",41 S64b,char}
> >   clang_analyzer_dump(&str2[41]); // &Element{SymRegion{reg_$0 > str2>},41 S64b,char}
> > }
> > ```
> Because only `Decl` can tell us whether it is a `const char str[42]` or 
> `const char * const str`. We can't say anything just looking at `SVal`.
> This might cause some itchy false positives. Perhaps, we could address this 
> in a follow-up patch and then commit them together?
This will produce not more FP as before, even less. I didn't change the 
behavior specifically here. I just found the issue point to it.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1784-1786
+  const auto Offset = static_cast(Idx.getExtValue());
+  if (Idx < 0)
 return UndefinedVal();

steakhal wrote:
> I think it would be better to have the check before we calculate the 
> `Offset`. At least that way I find it easier to follow.
Yes, it's just my omission.


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

https://reviews.llvm.org/D107339

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


[clang] 101aaf6 - Revert "[NFC] `IRBuilderBase::CreateAdd()`: place constant onto RHS"

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T22:21:37+03:00
New Revision: 101aaf62efef1ee55e0bc9fa78a83d8a4c6fcee6

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

LOG: Revert "[NFC] `IRBuilderBase::CreateAdd()`: place constant onto RHS"

Clang OpenMP codegen tests are failing,
will recommit afterwards.

This reverts commit 4723c9b3c6c46632a5d66e65d198899894b1e2c5.

Added: 


Modified: 
clang/test/CodeGen/builtins-overflow.c
clang/test/CodeGen/builtins-ppc-p10vector.c
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
clang/test/CodeGen/complex-convert.c
clang/test/CodeGen/extern-inline.c
clang/test/CodeGen/matrix-type-operators.c
clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
clang/test/CodeGenCXX/virtual-base-cast.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll
llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll
llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll
llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll
llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll
llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll
llvm/test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll
llvm/test/Transforms/LoopDistribute/scev-inserted-runtime-check.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
llvm/test/Transforms/LoopVectorize/ARM/mve-gather-scatter-tailpred.ll
llvm/test/Transforms/LoopVectorize/X86/conversion-cost.ll
llvm/test/Transforms/LoopVectorize/X86/load-deref-pred.ll
llvm/test/Transforms/LoopVectorize/X86/pr36524.ll
llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll
llvm/test/Transforms/LoopVectorize/float-minmax-instruction-flag.ll
llvm/test/Transforms/LoopVectorize/if-pred-stores.ll
llvm/test/Transforms/LoopVectorize/induction-step.ll
llvm/test/Transforms/LoopVectorize/induction.ll
llvm/test/Transforms/LoopVectorize/pr30654-phiscev-sext-trunc.ll
llvm/test/Transforms/LoopVectorize/pr44488-predication.ll
llvm/test/Transforms/LoopVectorize/pr45259.ll
llvm/test/Transforms/LoopVectorize/runtime-check-small-clamped-bounds.ll
llvm/test/Transforms/LoopVectorize/scalar_after_vectorization.ll
llvm/test/Transforms/LoopVersioning/wrapping-pointer-versioning.ll

Removed: 




diff  --git a/clang/test/CodeGen/builtins-overflow.c 
b/clang/test/CodeGen/builtins-overflow.c
index f7f5a577e1dc3..636a571d13640 100644
--- a/clang/test/CodeGen/builtins-overflow.c
+++ b/clang/test/CodeGen/builtins-overflow.c
@@ -484,7 +484,7 @@ int test_mixed_sign_mull_overflow(int x, unsigned y) {
 // CHECK-NEXT:  [[UnsignedOFlow:%.*]] = extractvalue { i32, i1 } %{{.*}}, 1
 // CHECK-NEXT:  [[UnsignedResult:%.*]] = extractvalue { i32, i1 } %{{.*}}, 0
 // CHECK-NEXT:  [[IsNegZext:%.*]] = zext i1 [[IsNeg]] to i32
-// CHECK-NEXT:  [[MaxResult:%.*]] = add i32 [[IsNegZext]], 2147483647
+// CHECK-NEXT:  [[MaxResult:%.*]] = add i32 2147483647, [[IsNegZext]]
 // CHECK-NEXT:  [[SignedOFlow:%.*]] = icmp ugt i32 [[UnsignedResult]], 
[[MaxResult]]
 // CHECK-NEXT:  [[OFlow:%.*]] = or i1 [[UnsignedOFlow]], [[SignedOFlow]]
 // CHECK-NEXT:  [[NegativeResult:%.*]] = sub i32 0, [[UnsignedResult]]
@@ -523,7 +523,7 @@ int test_mixed_sign_mull_overflow_unsigned(int x, unsigned 
y) {
 int test_mixed_sign_mull_overflow_swapped(int x, unsigned y) {
 // CHECK: @test_mixed_sign_mull_overflow_swapped
 // CHECK:  call { i32, i1 } @llvm.umul.with.overflow.i32
-// CHECK:  add i32 [[Op0:%.*]], 2147483647
+// CHECK:  add i32 2147483647
   int result;
   if (__builtin_mul_overflow(y, x, &result))
 return LongErrorCode;
@@ -533,7 +533,7 @@ int test_mixed_sign_mull_overflow_swapped(int x, unsigned 
y) {
 long long test_mixed_sign_mulll_overflow(long long x, unsigned long long y) {
 // CHECK: @test_mixed_sign_mulll_overflow
 // CHECK:  call { i64, i1 } @llvm.umul.with.overflow.i64
-// CHECK:  add i64 [[Op0:%.*]], 92233720368547
+// CHECK:  add i64 92233720368547
   long long result;
   if (__builtin_mul_overflow(x, y, &result))
 return LongLongErrorCode;
@@ -543,7 +543,7 @@ long long test_mixed_sign_mulll_overflow(long long x, 
unsigned long long y) {
 long long test_mixed_sign_mulll_overflow_swapped(long long x, unsigned long 
long y) {
 // CHECK: @test_mixed_sign_mulll_overflow_swapped
 // CHECK:  call { i64, i1 } @llvm.umul.with.overflow.i64
-// CHECK:  add i64 [[Op0:%.*]], 92233720368547
+// CHECK:  add i64 92233720368547
   long long result;
   if (__builtin_mul_overflow(y, x, &result))
 return LongLongErr

[PATCH] D112652: [clangd] Avoid expensive checks of buffer names in IncludeCleaner

2021-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kbobyrev.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This changes the handling of special buffers ( etc) that
SourceManager treats as files but FileManager does not.

We now include them in findReferencedFiles() and drop them as part of
translateToHeaderIDs(). This pairs more naturally with the data representations
we're using, and so avoids a bunch of converting between representations for
filtering.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112652

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -16,6 +16,7 @@
 namespace clangd {
 namespace {
 
+using ::testing::ElementsAre;
 using ::testing::UnorderedElementsAre;
 
 TEST(IncludeCleaner, ReferencedLocations) {
@@ -236,9 +237,8 @@
 
 TEST(IncludeCleaner, VirtualBuffers) {
   TestTU TU;
-  TU.Filename = "foo.cpp";
   TU.Code = R"cpp(
-#include "macro_spelling_in_scratch_buffer.h"
+#include "macros.h"
 
 using flags::FLAGS_FOO;
 
@@ -251,7 +251,7 @@
   // The pasting operator in combination with DEFINE_FLAG will create
   // ScratchBuffer with `flags::FLAGS_FOO` that will have FileID but not
   // FileEntry.
-  TU.AdditionalFiles["macro_spelling_in_scratch_buffer.h"] = R"cpp(
+  TU.AdditionalFiles["macros.h"] = R"cpp(
 #define DEFINE_FLAG(X) \
 namespace flags { \
 int FLAGS_##X; \
@@ -266,18 +266,27 @@
   ParsedAST AST = TU.build();
   auto &SM = AST.getSourceManager();
   auto &Includes = AST.getIncludeStructure();
+
   auto ReferencedFiles = findReferencedFiles(findReferencedLocations(AST), SM);
-  auto Entry = SM.getFileManager().getFile(
-  testPath("macro_spelling_in_scratch_buffer.h"));
-  ASSERT_TRUE(Entry);
-  auto FID = SM.translateFile(*Entry);
-  // No "" FID.
-  EXPECT_THAT(ReferencedFiles, UnorderedElementsAre(FID));
-  // Should not crash due to  "files" missing from include
-  // structure.
-  EXPECT_THAT(
-  getUnused(Includes, translateToHeaderIDs(ReferencedFiles, Includes, SM)),
-  ::testing::IsEmpty());
+  llvm::StringSet<> ReferencedFileNames;
+  for (FileID FID : ReferencedFiles)
+ReferencedFileNames.insert(
+SM.getPresumedLoc(SM.getLocForStartOfFile(FID)).getFilename());
+  // (Note we deduped the names as _number_ of s is uninteresting).
+  EXPECT_THAT(ReferencedFileNames.keys(),
+  UnorderedElementsAre("", "",
+   testPath("macros.h")));
+
+  // Should not crash due to FileIDs that are not headers.
+  auto ReferencedHeaders = translateToHeaderIDs(ReferencedFiles, Includes, SM);
+  std::vector ReferencedHeaderNames;
+  for (IncludeStructure::HeaderID HID : ReferencedHeaders)
+ReferencedHeaderNames.push_back(Includes.getRealPath(HID));
+  // Non-header files are gone at this point.
+  EXPECT_THAT(ReferencedHeaderNames, ElementsAre(testPath("macros.h")));
+
+  // Sanity check.
+  EXPECT_THAT(getUnused(Includes, ReferencedHeaders), ::testing::IsEmpty());
 }
 
 } // namespace
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -129,9 +129,7 @@
   void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
 
   void add(FileID FID, SourceLocation Loc) {
-// Check if Loc is not written in a physical file.
-if (FID.isInvalid() || SM.isWrittenInBuiltinFile(Loc) ||
-SM.isWrittenInCommandLineFile(Loc))
+if (FID.isInvalid())
   return;
 assert(SM.isInFileID(Loc, FID));
 if (Loc.isFileID()) {
@@ -142,15 +140,9 @@
 if (!Macros.insert(FID).second)
   return;
 const auto &Exp = SM.getSLocEntry(FID).getExpansion();
-// For token pasting operator in macros, spelling and expansion locations
-// can be within a temporary buffer that Clang creates (scratch space or
-// ScratchBuffer). That is not a real file we can include.
-if (!SM.isWrittenInScratchSpace(Exp.getSpellingLoc()))
-  add(Exp.getSpellingLoc());
-if (!SM.isWrittenInScratchSpace(Exp.getExpansionLocStart()))
-  add(Exp.getExpansionLocStart());
-if (!SM.isWrittenInScratchSpace(Exp.getExpansionLocEnd()))
-  add(Exp.getExpansionLocEnd());
+add(Exp.getSpellingLoc());
+add(Exp.getExpansionLocStart());
+add(Exp.getExpansionLocEnd());
   }
 };
 
@@ -249,6 +241,14 @@
   return Unused;
 }
 
+#ifndef NDEBUG
+// Is FID a ,  etc?
+static bool isSpecialBuffer(FileID FID, const SourceMa

[PATCH] D112647: [clang-apply-replacements] Correctly handle relative paths

2021-10-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added reviewers: ymandel, njames93.
avogelsgesang added a comment.

Adding reviewers based on `git log`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112647

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


[PATCH] D112504: [OpenMP] Wrap (v)printf in the new RT and use same handling for AMD

2021-10-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 382747.
JonChesterfield added a comment.

-rebase on main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112504

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp

Index: openmp/libomptarget/DeviceRTL/src/Debug.cpp
===
--- openmp/libomptarget/DeviceRTL/src/Debug.cpp
+++ openmp/libomptarget/DeviceRTL/src/Debug.cpp
@@ -35,6 +35,15 @@
  assertion);
   __builtin_trap();
 }
+
+// We do not have a vprintf implementation for AMD GPU yet so we use a stub.
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+int32_t vprintf(const char *, void *) { return 0; }
+#pragma omp end declare variant
+
+int32_t __llvm_omp_vprintf(const char *Format, void *Arguments) {
+  return vprintf(Format, Arguments);
+}
 }
 
 /// Current indentation level for the function trace. Only accessed by thread 0.
Index: openmp/libomptarget/DeviceRTL/include/Interface.h
===
--- openmp/libomptarget/DeviceRTL/include/Interface.h
+++ openmp/libomptarget/DeviceRTL/include/Interface.h
@@ -352,6 +352,9 @@
 int32_t __kmpc_shuffle_int32(int32_t val, int16_t delta, int16_t size);
 int64_t __kmpc_shuffle_int64(int64_t val, int16_t delta, int16_t size);
 ///}
+
+/// Printf
+int32_t __llvm_omp_vprintf(const char *Format, void *Arguments);
 }
 
 #endif
Index: openmp/libomptarget/DeviceRTL/include/Debug.h
===
--- openmp/libomptarget/DeviceRTL/include/Debug.h
+++ openmp/libomptarget/DeviceRTL/include/Debug.h
@@ -32,17 +32,12 @@
 /// macro.
 /// {
 
-#ifndef __AMDGCN__
 extern "C" {
 int printf(const char *format, ...);
 }
 
 #define PRINTF(fmt, ...) (void)printf(fmt, __VA_ARGS__);
 #define PRINT(str) PRINTF("%s", str)
-#else
-#define PRINTF(fmt, ...)
-#define PRINT(str)
-#endif
 
 ///}
 
Index: clang/lib/CodeGen/CGGPUBuiltin.cpp
===
--- clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -21,24 +21,30 @@
 using namespace clang;
 using namespace CodeGen;
 
-static llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
+static llvm::Function *GetVprintfDeclaration(CodeGenModule &CGM) {
+  bool UsesNewOpenMPDeviceRuntime = CGM.getLangOpts().OpenMPIsDevice &&
+CGM.getLangOpts().OpenMPTargetNewRuntime;
+  const char *Name =
+  UsesNewOpenMPDeviceRuntime ? "__llvm_omp_vprintf" : "vprintf";
+  llvm::Module &M = CGM.getModule();
   llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
 llvm::Type::getInt8PtrTy(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
-  if (auto* F = M.getFunction("vprintf")) {
+  if (auto *F = M.getFunction(Name)) {
 // Our CUDA system header declares vprintf with the right signature, so
 // nobody else should have been able to declare vprintf with a bogus
-// signature.
+// signature. The OpenMP device runtime provides a wrapper around vprintf
+// which we use here. The signature should match though.
 assert(F->getFunctionType() == VprintfFuncType);
 return F;
   }
 
-  // vprintf doesn't already exist; create a declaration and insert it into the
-  // module.
+  // vprintf, or for OpenMP device offloading the vprintf wrapper, doesn't
+  // already exist; create a declaration and insert it into the module.
   return llvm::Function::Create(
-  VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, "vprintf", &M);
+  VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, Name, &M);
 }
 
 // Transforms a call to printf into a call to the NVPTX vprintf syscall (which
@@ -117,7 +123,7 @@
   }
 
   // Invoke vprintf and return.
-  llvm::Function* VprintfFunc = GetVprintfDeclaration(CGM.getModule());
+  llvm::Function *VprintfFunc = GetVprintfDeclaration(CGM);
   return RValue::get(Builder.CreateCall(
   VprintfFunc, {Args[0].getRValue(*this).getScalarVal(), BufferPtr}));
 }
@@ -130,6 +136,12 @@
  E->getBuiltinCallee() == Builtin::BI__builtin_printf);
   assert(E->getNumArgs() >= 1); // printf always has at least one arg.
 
+  // For OpenMP target offloading we go with a modified nvptx printf method.
+  // Basically creating calls to __llvm_omp_vprintf with the arguments and
+  // dealing with the details in the device runtime itself.
+  if (getLangOpts().OpenMPIsDevice && getLangOpts().OpenMPTargetNewRuntime)
+return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);
+
   CallArgList CallArgs;
   EmitCallArgs(CallArg

[PATCH] D112648: [clang-tidy] Improve fix-its for `modernize-pass-by-value` check

2021-10-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
avogelsgesang requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This commit improves the fix-its of `modernize-pass-by-value` in two ways:

1. No longer propose partial fixes. In the presence of `using`/`typedef`, we 
failed to rewrite the function signature but still adjusted the function body. 
This led to incorrect, partial fix-its. Instead, the check now simply doesn't 
offer any fixes at all in such a situation
2. The check unconditionally added a whitespace after the new type name. This 
is necessary, e.g., for LLVM's code style where the `&` is directly attached to 
the variable name. For other code styles, we don't want this whitespace, 
though. The check now checks if a whitespace is already present and if so 
doesn't introduce a 2nd duplicated whitespace


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112648

Files:
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value.cpp
@@ -231,5 +231,33 @@
 
 struct U {
   U(const POD &M) : M(M) {}
+  // CHECK-FIXES: U(const POD &M) : M(M) {}
   POD M;
 };
+
+// The rewrite can't look through `typedefs` and `using`.
+// Test that we don't partially rewrite one decl without rewriting the other.
+using MovableConstRef = const Movable &;
+struct V {
+  V(MovableConstRef M);
+  // CHECK-FIXES: V(MovableConstRef M);
+  Movable M;
+};
+V::V(const Movable &M) : M(M) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: pass by value and use std::move
+// CHECK-FIXES: V::V(const Movable &M) : M(M) {}
+
+// Check that we don't insert an unnecessary whitespace if not required
+struct W {
+  // Here we need a whitespace so we don't write `MovableM`
+  W(const Movable &M);
+  // CHECK-FIXES: W(Movable M);
+  Movable M;
+};
+// Here we don't need an additional whitepace, as there already is a whitespace
+// between `&` and the variable name
+// clang-format off
+W::W(const Movable& M) : M(M) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: pass by value and use std::move
+// CHECK-FIXES: W::W(Movable M) : M(std::move(M)) {}
+// clang-format on
Index: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -190,24 +190,46 @@
 
   auto Diag = diag(ParamDecl->getBeginLoc(), "pass by value and use std::move");
 
-  // Iterate over all declarations of the constructor.
-  for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
-auto ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
-auto RefTL = ParamTL.getAs();
+  // If we received a `const&` type, we need to rewrite the function
+  // declarations
+  if (ParamDecl->getType()->isLValueReferenceType()) {
+// Check if we can succesfully rewrite all declarations of the constructor.
+for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
+  auto ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
+  auto RefTL = ParamTL.getAs();
+  if (RefTL.isNull()) {
+// We cannot rewrite this instance. The type is probably hidden behind
+// some `typedef`. Do not offer a fix-it in this case.
+return;
+  }
+}
+// Rewrite all declarations.
+for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
+  auto ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
+  auto RefTL = ParamTL.getAs();
 
-// Do not replace if it is already a value, skip.
-if (RefTL.isNull())
-  continue;
+  TypeLoc ValueTL = RefTL.getPointeeLoc();
+  auto TypeRange = CharSourceRange::getTokenRange(ParmDecl->getBeginLoc(),
+  ParamTL.getEndLoc());
+  std::string ValueStr =
+  Lexer::getSourceText(
+  CharSourceRange::getTokenRange(ValueTL.getSourceRange()), SM,
+  getLangOpts())
+  .str();
 
-TypeLoc ValueTL = RefTL.getPointeeLoc();
-auto TypeRange = CharSourceRange::getTokenRange(ParmDecl->getBeginLoc(),
-ParamTL.getEndLoc());
-std::string ValueStr = Lexer::getSourceText(CharSourceRange::getTokenRange(
-ValueTL.getSourceRange()),
-SM, getLangOpts())
-   .str();
-ValueStr += ' ';
-Diag << FixItHi

[PATCH] D112645: [OpenMP] Fix: opposite attributes could be set by -fno-inline

2021-10-27 Thread Igor Kirillov via Phabricator via cfe-commits
igor.kirillov added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5370
   if (CGM.getCodeGenOpts().OptimizationLevel != 0)
 Fn->addFnAttr(llvm::Attribute::AlwaysInline);
   return Fn;

I noticed that here we set this attribute on the same function that is created 
by `emitOutlinedFunctionPrologue` but there AlwaysInline attribute is 
guaranteed to be set under same condition. So I suppose we could remove this 
piece of code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112645

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


[PATCH] D112633: [AST] fail rather than crash when const evaluating invalid c++ foreach

2021-10-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp:73
+
+struct X { int a; } array[] = {{undef()}}; // expected-error {{use of 
undeclared identifier 'undef'}}
+constexpr void test11() {

this can be simplified further.

struct X {} array[] = {undef()};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112633

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


[PATCH] D112647: [clang-apply-replacements] Correctly handle relative paths

2021-10-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang updated this revision to Diff 382741.
avogelsgesang added a comment.

Remove unrelated changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112647

Files:
  clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/basic.h
  
clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file1.yaml
  
clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file2.yaml
  clang-tools-extra/test/clang-apply-replacements/relative-paths.cpp

Index: clang-tools-extra/test/clang-apply-replacements/relative-paths.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/relative-paths.cpp
@@ -0,0 +1,7 @@
+// RUN: mkdir -p %T/Inputs/relative-paths
+// RUN: mkdir -p %T/Inputs/relative-paths/subdir
+// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/relative-paths/basic.h > %T/Inputs/relative-paths/basic.h
+// RUN: sed "s#\$(path)#%/T/Inputs/relative-paths#" %S/Inputs/relative-paths/file1.yaml > %T/Inputs/relative-paths/file1.yaml
+// RUN: sed "s#\$(path)#%/T/Inputs/relative-paths#" %S/Inputs/relative-paths/file2.yaml > %T/Inputs/relative-paths/file2.yaml
+// RUN: clang-apply-replacements %T/Inputs/relative-paths
+// RUN: FileCheck -input-file=%T/Inputs/relative-paths/basic.h %S/Inputs/relative-paths/basic.h
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file2.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file2.yaml
@@ -0,0 +1,15 @@
+---
+MainSourceFile: source2.cpp
+Diagnostics:
+  - BuildDirectory: $(path)
+DiagnosticName: test-relative-path
+DiagnosticMessage:
+  Message: Fix
+  FilePath: ./basic.h
+  FileOffset: 148
+  Replacements:
+- FilePath:./basic.h
+  Offset:  298
+  Length:  1
+  ReplacementText: elem
+...
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file1.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file1.yaml
@@ -0,0 +1,27 @@
+---
+MainSourceFile: source1.cpp
+Diagnostics:
+  - BuildDirectory: $(path)/subdir/
+DiagnosticName: test-relative-path
+DiagnosticMessage:
+  Message: Fix
+  FilePath: ../relative-path.h
+  FileOffset: 242
+  Replacements:
+- FilePath:../basic.h
+  Offset:  242
+  Length:  26
+  ReplacementText: 'auto & elem : ints'
+- FilePath:$(path)/basic.h
+  Offset:  276
+  Length:  22
+  ReplacementText: ''
+- FilePath:../basic.h
+  Offset:  298
+  Length:  1
+  ReplacementText: elem
+- FilePath:../../relative-paths/basic.h
+  Offset:  148
+  Length:  0
+  ReplacementText: 'override '
+...
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/basic.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/basic.h
@@ -0,0 +1,32 @@
+#ifndef BASIC_H
+#define BASIC_H
+
+
+class Parent {
+public:
+  virtual void func() {}
+};
+
+class Derived : public Parent {
+public:
+  virtual void func() {}
+  // CHECK: virtual void func() override {}
+};
+
+extern void ext(int (&)[5], const Parent &);
+
+void func(int t) {
+  int ints[5];
+  for (unsigned i = 0; i < 5; ++i) {
+int &e = ints[i];
+e = t;
+// CHECK: for (auto & elem : ints) {
+// CHECK-NEXT: elem = t;
+  }
+
+  Derived d;
+
+  ext(ints, d);
+}
+
+#endif // BASIC_H
Index: clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
===
--- clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -152,9 +152,15 @@
   DiagReplacements;
 
   auto AddToGroup = [&](const tooling::Replacement &R,
-const tooling::TranslationUnitDiagnostics *SourceTU) {
+const tooling::TranslationUnitDiagnostics *SourceTU,
+const std::string *buildDir) {
 // Use the file manager to deduplicate paths. FileEntries are
 // automatically canonicalized.
+auto &WorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
+auto PrevWorkingDir = WorkingDir;
+if (buildDir) {
+  WorkingDir = *buildDir;
+}
 if (auto Entry = SM.getFileManager().getFile(R.getF

[PATCH] D112647: [clang-apply-replacements] Correctly handle relative paths

2021-10-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang created this revision.
Herald added a subscriber: carlosgalvezp.
avogelsgesang requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The fixes from the YAML file can refer to relative paths.
Those relative paths are meant to be resolved relative to the
corresponding `build directory`.
However, `clang-apply-replacements` currently interprets all
paths relative to its own working directory. This causes issues,
e.g., when `clang-apply-replacements` is run from outside of
the original build directory.

This commit adjusts `clang-apply-replacements` to take the build
directory into account when resolving relative file paths.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112647

Files:
  clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/basic.h
  
clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file1.yaml
  
clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file2.yaml
  clang-tools-extra/test/clang-apply-replacements/relative-paths.cpp

Index: clang-tools-extra/test/clang-apply-replacements/relative-paths.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/relative-paths.cpp
@@ -0,0 +1,7 @@
+// RUN: mkdir -p %T/Inputs/relative-paths
+// RUN: mkdir -p %T/Inputs/relative-paths/subdir
+// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/relative-paths/basic.h > %T/Inputs/relative-paths/basic.h
+// RUN: sed "s#\$(path)#%/T/Inputs/relative-paths#" %S/Inputs/relative-paths/file1.yaml > %T/Inputs/relative-paths/file1.yaml
+// RUN: sed "s#\$(path)#%/T/Inputs/relative-paths#" %S/Inputs/relative-paths/file2.yaml > %T/Inputs/relative-paths/file2.yaml
+// RUN: clang-apply-replacements %T/Inputs/relative-paths
+// RUN: FileCheck -input-file=%T/Inputs/relative-paths/basic.h %S/Inputs/relative-paths/basic.h
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file2.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file2.yaml
@@ -0,0 +1,15 @@
+---
+MainSourceFile: source2.cpp
+Diagnostics:
+  - BuildDirectory: $(path)
+DiagnosticName: test-relative-path
+DiagnosticMessage:
+  Message: Fix
+  FilePath: ./basic.h
+  FileOffset: 148
+  Replacements:
+- FilePath:./basic.h
+  Offset:  298
+  Length:  1
+  ReplacementText: elem
+...
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file1.yaml
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/file1.yaml
@@ -0,0 +1,27 @@
+---
+MainSourceFile: source1.cpp
+Diagnostics:
+  - BuildDirectory: $(path)/subdir/
+DiagnosticName: test-relative-path
+DiagnosticMessage:
+  Message: Fix
+  FilePath: ../relative-path.h
+  FileOffset: 242
+  Replacements:
+- FilePath:../basic.h
+  Offset:  242
+  Length:  26
+  ReplacementText: 'auto & elem : ints'
+- FilePath:$(path)/basic.h
+  Offset:  276
+  Length:  22
+  ReplacementText: ''
+- FilePath:../basic.h
+  Offset:  298
+  Length:  1
+  ReplacementText: elem
+- FilePath:../../relative-paths/basic.h
+  Offset:  148
+  Length:  0
+  ReplacementText: 'override '
+...
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/basic.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/relative-paths/basic.h
@@ -0,0 +1,32 @@
+#ifndef BASIC_H
+#define BASIC_H
+
+
+class Parent {
+public:
+  virtual void func() {}
+};
+
+class Derived : public Parent {
+public:
+  virtual void func() {}
+  // CHECK: virtual void func() override {}
+};
+
+extern void ext(int (&)[5], const Parent &);
+
+void func(int t) {
+  int ints[5];
+  for (unsigned i = 0; i < 5; ++i) {
+int &e = ints[i];
+e = t;
+// CHECK: for (auto & elem : ints) {
+// CHECK-NEXT: elem = t;
+  }
+
+  Derived d;
+
+  ext(ints, d);
+}
+
+#endif // BASIC_H
Index: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -196,8 +196,9 @@
 auto RefTL = ParamTL.getAs();
 
 // Do not replace if it is already a value, skip

  1   2   3   >