[PATCH] D102577: TreeTransform.h: make the switch case more beautiful

2021-05-17 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou added a comment.

I do some "grep" in clang/lib directory:
llvm-project/clang/lib#find . -name "*.*"|xargs grep -n -B 2 "break;"|grep -A 2 
"}"

my patch also seems to match the coding style of other parts of clang.

Thanks again


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

https://reviews.llvm.org/D102577

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


[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

2021-05-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 345763.
tbaeder added a comment.

On second thought, rather only handle `=auto` and `=jobserver` and don't warn.


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

https://reviews.llvm.org/D102479

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -72,7 +72,9 @@
 // FFPALL-NEXT: off
 // FFPALL-NEXT: on
 // RUN: %clang --autocomplete=-flto= | FileCheck %s -check-prefix=FLTOALL
+// FLTOALL: auto
 // FLTOALL: full
+// FLTOALL: jobserver
 // FLTOALL-NEXT: thin
 // RUN: %clang --autocomplete=-fveclib= | FileCheck %s -check-prefix=FVECLIBALL
 // FVECLIBALL: Accelerate
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1707,8 +1707,7 @@
 StringRef S = A->getValue();
 if (S == "thin")
   Opts.PrepareForThinLTO = true;
-else if (S != "full")
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+// -flto=full and invalid values are handled elsewhere.
   }
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != Language::LLVM_IR)
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -609,6 +609,8 @@
 
   LTOMode = llvm::StringSwitch(LTOName)
 .Case("full", LTOK_Full)
+.Case("auto", LTOK_Full)  // GCC compatibility
+.Case("jobserver", LTOK_Full) // GCC compatibility
 .Case("thin", LTOK_Thin)
 .Default(LTOK_Unknown);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1938,7 +1938,7 @@
 def fapple_link_rtlib : Flag<["-"], "fapple-link-rtlib">, Group,
   HelpText<"Force linking the clang builtins runtime library">;
 def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, 
Group,
-  HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
+  HelpText<"Set LTO mode to either 'full' or 'thin'">, 
Values<"thin,full,auto,jobserver">;
 def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Enable LTO in 'full' mode">;
 def fno_lto : Flag<["-"], "fno-lto">, Flags<[CoreOption, CC1Option]>, 
Group,
@@ -4226,8 +4226,6 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, 
Group;
 defm default_inline : BooleanFFlag<"default-inline">, 
Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, 
Group;
-def : Flag<["-"], "flto=auto">, Group;
-def : Flag<["-"], "flto=jobserver">, 
Group;
 defm float_store : BooleanFFlag<"float-store">, 
Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, 
Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, 
Group;


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -72,7 +72,9 @@
 // FFPALL-NEXT: off
 // FFPALL-NEXT: on
 // RUN: %clang --autocomplete=-flto= | FileCheck %s -check-prefix=FLTOALL
+// FLTOALL: auto
 // FLTOALL: full
+// FLTOALL: jobserver
 // FLTOALL-NEXT: thin
 // RUN: %clang --autocomplete=-fveclib= | FileCheck %s -check-prefix=FVECLIBALL
 // FVECLIBALL: Accelerate
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1707,8 +1707,7 @@
 StringRef S = A->getValue();
 if (S == "thin")
   Opts.PrepareForThinLTO = true;
-else if (S != "full")
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+// -flto=full and invalid values are handled elsewhere.
   }
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != Language::LLVM_IR)
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -609,6 +609,8 @@
 
   LTOMode = llvm::StringSwitch(LTOName)
 .Case("full", LTOK_Full)
+.Case("auto", LTOK_Full)  // GCC compatibility
+.Case("jobserver", LTOK_Full) // GCC compatibility
 .Case("thin", LTOK_Thin)
 .Default(LTOK_Unknown);
 
Index: clang/include/clang/Driver/Options.td

[clang] b9d5b0c - [clang][deps] NFC: Stop assuming the TU's context hash

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-05-17T09:16:00+02:00
New Revision: b9d5b0c20180e41f24722e622b8c3a3bb510fc1d

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

LOG: [clang][deps] NFC: Stop assuming the TU's context hash

The context hash of modular dependencies can be different from the context hash 
of the original translation unit if we modify their `CompilerInvocation`s.

Stop assuming the TU's context hash everywhere.

No functionality change here, since we're still currently using the unmodified 
TU CompilerInvocation to compute the context hash.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 95876bb665f10..8d191278f22ab 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -147,7 +147,7 @@ class ModuleDepCollectorPP final : public PPCallbacks {
   /// Traverses the previously collected direct modular dependencies to 
discover
   /// transitive modular dependencies and fills the parent \c 
ModuleDepCollector
   /// with both.
-  void handleTopLevelModule(const Module *M);
+  ModuleID handleTopLevelModule(const Module *M);
   void addAllSubmoduleDeps(const Module *M, ModuleDeps &MD,
llvm::DenseSet &AddedModules);
   void addModuleDep(const Module *M, ModuleDeps &MD,
@@ -173,13 +173,13 @@ class ModuleDepCollector final : public 
DependencyCollector {
   DependencyConsumer &Consumer;
   /// Path to the main source file.
   std::string MainFile;
-  /// The module hash identifying the compilation conditions.
+  /// Hash identifying the compilation conditions of the current TU.
   std::string ContextHash;
   /// Non-modular file dependencies. This includes the main source file and
   /// textually included header files.
   std::vector FileDeps;
   /// Direct and transitive modular dependencies of the main source file.
-  std::unordered_map ModularDeps;
+  std::unordered_map ModularDeps;
   /// Options that control the dependency output generation.
   std::unique_ptr Opts;
 };

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index 35817d3f7ae9d..196b05bafea07 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -143,7 +143,7 @@ DependencyScanningTool::getFullDependencies(
   for (auto &&M : ClangModuleDeps) {
 auto &MD = M.second;
 if (MD.ImportedByMainFile)
-  FD.ClangModuleDeps.push_back({MD.ID.ModuleName, ContextHash});
+  FD.ClangModuleDeps.push_back(MD.ID);
   }
 
   FullDependenciesResult FDR;

diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 7c858178cdd53..517312aec8954 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -144,8 +144,6 @@ void ModuleDepCollectorPP::handleImport(const Module 
*Imported) {
 return;
 
   const Module *TopLevelModule = Imported->getTopLevelModule();
-  MDC.ModularDeps[MDC.ContextHash + TopLevelModule->getFullModuleName()]
-  .ImportedByMainFile = true;
   DirectModularDeps.insert(TopLevelModule);
 }
 
@@ -164,28 +162,27 @@ void ModuleDepCollectorPP::EndOfMainFile() {
 MDC.Consumer.handleFileDependency(*MDC.Opts, I);
 }
 
-void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
+ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
   assert(M == M->getTopLevelModule() && "Expected top level module!");
 
-  auto ModI = MDC.ModularDeps.insert(
-  std::make_pair(MDC.ContextHash + M->getFullModuleName(), ModuleDeps{}));
-
-  if (!ModI.first->second.ID.ModuleName.empty())
-return;
+  // If this module has been handled already, just return its ID.
+  auto ModI = MDC.ModularDeps.insert({M, ModuleDeps{}});
+  if (!ModI.second)
+return ModI.first->second.ID;
 
   ModuleDeps &MD = ModI.first->second;
 
+  MD.ID.ModuleName = M->getFullModuleName();
+  MD.ImportedByMainFile = DirectModularDeps.contains(M);
+  MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
+  MD.IsSystem = M->IsSystem;
+
   const FileEntry *ModuleMap = In

[PATCH] D102473: [clang][deps] NFC: Stop assuming the TU's context hash

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb9d5b0c20180: [clang][deps] NFC: Stop assuming the TU's 
context hash (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102473

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -144,8 +144,6 @@
 return;
 
   const Module *TopLevelModule = Imported->getTopLevelModule();
-  MDC.ModularDeps[MDC.ContextHash + TopLevelModule->getFullModuleName()]
-  .ImportedByMainFile = true;
   DirectModularDeps.insert(TopLevelModule);
 }
 
@@ -164,28 +162,27 @@
 MDC.Consumer.handleFileDependency(*MDC.Opts, I);
 }
 
-void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
+ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
   assert(M == M->getTopLevelModule() && "Expected top level module!");
 
-  auto ModI = MDC.ModularDeps.insert(
-  std::make_pair(MDC.ContextHash + M->getFullModuleName(), ModuleDeps{}));
-
-  if (!ModI.first->second.ID.ModuleName.empty())
-return;
+  // If this module has been handled already, just return its ID.
+  auto ModI = MDC.ModularDeps.insert({M, ModuleDeps{}});
+  if (!ModI.second)
+return ModI.first->second.ID;
 
   ModuleDeps &MD = ModI.first->second;
 
+  MD.ID.ModuleName = M->getFullModuleName();
+  MD.ImportedByMainFile = DirectModularDeps.contains(M);
+  MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
+  MD.IsSystem = M->IsSystem;
+
   const FileEntry *ModuleMap = Instance.getPreprocessor()
.getHeaderSearchInfo()
.getModuleMap()
.getContainingModuleMapFile(M);
-
-  MD.Invocation = Instance.getInvocationPtr();
   MD.ClangModuleMapFile = std::string(ModuleMap ? ModuleMap->getName() : "");
-  MD.ID.ModuleName = M->getFullModuleName();
-  MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
-  MD.ID.ContextHash = MDC.ContextHash;
-  MD.IsSystem = M->IsSystem;
+
   serialization::ModuleFile *MF =
   MDC.Instance.getASTReader()->getModuleManager().lookup(M->getASTFile());
   MDC.Instance.getASTReader()->visitInputFiles(
@@ -193,8 +190,16 @@
 MD.FileDeps.insert(IF.getFile()->getName());
   });
 
+  // FIXME: Prepare the CompilerInvocation for building this module **now**, so
+  //that we store the actual context hash for this module (not just the
+  //context hash inherited from the original TU).
+  MD.Invocation = Instance.getInvocationPtr();
+  MD.ID.ContextHash = MD.Invocation->getModuleHash();
+
   llvm::DenseSet AddedModules;
   addAllSubmoduleDeps(M, MD, AddedModules);
+
+  return MD.ID;
 }
 
 void ModuleDepCollectorPP::addAllSubmoduleDeps(
@@ -211,11 +216,9 @@
 llvm::DenseSet &AddedModules) {
   for (const Module *Import : M->Imports) {
 if (Import->getTopLevelModule() != M->getTopLevelModule()) {
+  ModuleID ImportID = handleTopLevelModule(Import->getTopLevelModule());
   if (AddedModules.insert(Import->getTopLevelModule()).second)
-MD.ClangModuleDeps.push_back(
-{std::string(Import->getTopLevelModuleName()),
- Instance.getInvocation().getModuleHash()});
-  handleTopLevelModule(Import->getTopLevelModule());
+MD.ClangModuleDeps.push_back(ImportID);
 }
   }
 }
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -143,7 +143,7 @@
   for (auto &&M : ClangModuleDeps) {
 auto &MD = M.second;
 if (MD.ImportedByMainFile)
-  FD.ClangModuleDeps.push_back({MD.ID.ModuleName, ContextHash});
+  FD.ClangModuleDeps.push_back(MD.ID);
   }
 
   FullDependenciesResult FDR;
Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
===
--- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -147,7 +147,7 @@
   /// Traverses the previously collected direct modular dependencies to discover
   /// transitive modular dependencies and fills the parent \c ModuleDepCollector
   /// with both.
-  void handleTopLevelModule(const

[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy updated this revision to Diff 345767.
condy added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix some tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

Files:
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2372,6 +2372,18 @@
 return false;
   }
 
+  // Create a global zero-sized array precedence before GlobalsToChange[0] so
+  // that the underflow of the it could be observable.
+  ArrayType *ZeroSizedArrayTy = ArrayType::get(IRB.getInt8Ty(), 0);
+  GlobalVariable *UnderflowObserverGV = new GlobalVariable(
+  M, ZeroSizedArrayTy, /*isConstant*/ false, 
GlobalVariable::PrivateLinkage,
+  ConstantArray::get(ZeroSizedArrayTy, {}), kAsanGenPrefix,
+  GlobalsToChange[0]);
+  GlobalsToChange.insert(GlobalsToChange.begin(), UnderflowObserverGV);
+
+  // Update size as we insert a dummy one.
+  n = GlobalsToChange.size();
+
   auto &DL = M.getDataLayout();
 
   // A global is described by a structure
Index: clang/test/CodeGen/asan-globals-odr.cpp
===
--- clang/test/CodeGen/asan-globals-odr.cpp
+++ clang/test/CodeGen/asan-globals-odr.cpp
@@ -24,7 +24,7 @@
 // GLOB_ALIAS_INDICATOR: @0 = internal global {{.*}} @1 to i64), {{.*}}, i64 
ptrtoint (i8* [[ODR]] to i64) }]
 
 // ALIAS0-NOT: private alias
-// ALIAS1: @1 = private alias {{.*}} [[VAR]]
+// ALIAS1: @2 = private alias {{.*}} [[VAR]]
 
-// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
-// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([2 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([2 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
Index: clang/test/CodeGen/asan-globals-alias.cpp
===
--- clang/test/CodeGen/asan-globals-alias.cpp
+++ clang/test/CodeGen/asan-globals-alias.cpp
@@ -36,8 +36,8 @@
 // CHECK: @__mod_joydev_ids_device_table ={{.*}} alias
 
 // CHECK-LABEL: define internal void @asan.module_ctor
-// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 4)
-// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 1)
+// ASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 5)
+// KASAN: call void @__asan_register_globals({{.*}}, i{{32|64}} 2)
 // CHECK-NEXT: ret void
 
 // CHECK-LABEL: define internal void @asan.module_dtor


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2372,6 +2372,18 @@
 return false;
   }
 
+  // Create a global zero-sized array precedence before GlobalsToChange[0] so
+  // that the underflow of the it could be observable.
+  ArrayType *ZeroSizedArrayTy = ArrayType::get(IRB.getInt8Ty(), 0);
+  GlobalVariable *UnderflowObserverGV = new GlobalVariable(
+  M, ZeroSizedArrayTy, /*isConstant*/ false, GlobalVariable::PrivateLinkage,
+  ConstantArray::get(ZeroSizedArrayTy, {}), kAsanGenPrefix,
+  GlobalsToChange[0]);
+  GlobalsToChange.insert(GlobalsToChange.begin(), UnderflowObserverGV);
+
+  // Update size as we insert a dummy one.
+  n = GlobalsToChange.size();
+
   auto &DL = M.getDataLayout();
 
   // A global is described by a structure
Index: clang/test/CodeGen/asan-globals-odr.cpp
===
--- clang/test/CodeGen/asan-globals-odr.cpp
+++ clang/test/CodeGen/asan-globals-odr.cpp
@@ -24,7 +24,7 @@
 // GLOB_ALIAS_INDICATOR: @0 = internal global {{.*}} @1 to i64), {{.*}}, i64 ptrtoint (i8* [[ODR]] to i64) }]
 
 // ALIAS0-NOT: private alias
-// ALIAS1: @1 = private alias {{.*}} [[VAR]]
+// ALIAS1: @2 = private alias {{.*}} [[VAR]]
 
-// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
-// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([2 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([2 x { i64, i6

[PATCH] D102482: [clang][deps] NFC: Report modules' context hash

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd3fb4b9065e9: [clang][deps] NFC: Report modules' 
context hash (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D102482?vs=345402&id=345769#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102482

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -19,9 +19,10 @@
 using namespace dependencies;
 
 static CompilerInvocation
-makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) {
+makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps,
+ const CompilerInvocation &Invocation) 
{
   // Make a deep copy of the invocation.
-  CompilerInvocation CI(*Deps.Invocation);
+  CompilerInvocation CI(Invocation);
 
   // Remove options incompatible with explicit module build.
   CI.getFrontendOpts().Inputs.clear();
@@ -38,7 +39,7 @@
 }
 
 static std::vector
-serializeCompilerInvocation(CompilerInvocation &CI) {
+serializeCompilerInvocation(const CompilerInvocation &CI) {
   // Set up string allocator.
   llvm::BumpPtrAllocator Alloc;
   llvm::StringSaver Strings(Alloc);
@@ -55,7 +56,7 @@
 std::vector ModuleDeps::getCanonicalCommandLine(
 std::function LookupPCMPath,
 std::function LookupModuleDeps) const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
+  CompilerInvocation CI(Invocation);
 
   dependencies::detail::collectPCMAndModuleMapPaths(
   ClangModuleDeps, LookupPCMPath, LookupModuleDeps,
@@ -66,9 +67,7 @@
 
 std::vector
 ModuleDeps::getCanonicalCommandLineWithoutModulePaths() const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
-
-  return serializeCompilerInvocation(CI);
+  return serializeCompilerInvocation(Invocation);
 }
 
 void dependencies::detail::collectPCMAndModuleMapPaths(
@@ -190,11 +189,9 @@
 MD.FileDeps.insert(IF.getFile()->getName());
   });
 
-  // FIXME: Prepare the CompilerInvocation for building this module **now**, so
-  //that we store the actual context hash for this module (not just the
-  //context hash inherited from the original TU).
-  MD.Invocation = Instance.getInvocationPtr();
-  MD.ID.ContextHash = MD.Invocation->getModuleHash();
+  MD.Invocation =
+  makeInvocationForModuleBuildWithoutPaths(MD, Instance.getInvocation());
+  MD.ID.ContextHash = MD.Invocation.getModuleHash();
 
   llvm::DenseSet AddedModules;
   addAllSubmoduleDeps(M, MD, AddedModules);
Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
===
--- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -75,9 +75,8 @@
   // the primary TU.
   bool ImportedByMainFile = false;
 
-  /// The compiler invocation associated with the translation unit that imports
-  /// this module.
-  std::shared_ptr Invocation;
+  /// Compiler invocation that can be used to build this module (without 
paths).
+  CompilerInvocation Invocation;
 
   /// Gets the canonical command line suitable for passing to clang.
   ///


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -19,9 +19,10 @@
 using namespace dependencies;
 
 static CompilerInvocation
-makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) {
+makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps,
+ const CompilerInvocation &Invocation) {
   // Make a deep copy of the invocation.
-  CompilerInvocation CI(*Deps.Invocation);
+  CompilerInvocation CI(Invocation);
 
   // Remove options incompatible with explicit module build.
   CI.getFrontendOpts().Inputs.clear();
@@ -38,7 +39,7 @@
 }
 
 static std::vector
-serializeCompilerInvocation(CompilerInvocation &CI) {
+serializeCompilerInvocation(const CompilerInvocation &CI) {
   // Set up string allocator.
   llvm::BumpPtrAllocator Alloc;
   llvm::StringSaver Strings(Alloc);
@@ -55,7 +56,7 @@
 std::vector ModuleDeps::getCanonicalCommandLine(
 std::function LookupPCMPath,
 std::function LookupModuleDeps) const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
+  CompilerInvocation CI(Invocation

[clang] d3fb4b9 - [clang][deps] NFC: Report modules' context hash

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-05-17T09:24:23+02:00
New Revision: d3fb4b9065e93e2617db44f3ab9c31f341d9cd1f

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

LOG: [clang][deps] NFC: Report modules' context hash

This patch eagerly constructs and modifies CompilerInvocation of modular 
dependencies in order to report the correct context hash instead of the hash of 
the original translation unit.

No functionality change here, since we currently don't modify 
CompilerInvocation in a way that affects the context hash.

Depends on D102473.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 8d191278f22ab..7599a8bf45b9e 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -75,9 +75,8 @@ struct ModuleDeps {
   // the primary TU.
   bool ImportedByMainFile = false;
 
-  /// The compiler invocation associated with the translation unit that imports
-  /// this module.
-  std::shared_ptr Invocation;
+  /// Compiler invocation that can be used to build this module (without 
paths).
+  CompilerInvocation Invocation;
 
   /// Gets the canonical command line suitable for passing to clang.
   ///

diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 517312aec8954..51b7fc48628c1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -19,9 +19,10 @@ using namespace tooling;
 using namespace dependencies;
 
 static CompilerInvocation
-makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) {
+makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps,
+ const CompilerInvocation &Invocation) 
{
   // Make a deep copy of the invocation.
-  CompilerInvocation CI(*Deps.Invocation);
+  CompilerInvocation CI(Invocation);
 
   // Remove options incompatible with explicit module build.
   CI.getFrontendOpts().Inputs.clear();
@@ -38,7 +39,7 @@ makeInvocationForModuleBuildWithoutPaths(const ModuleDeps 
&Deps) {
 }
 
 static std::vector
-serializeCompilerInvocation(CompilerInvocation &CI) {
+serializeCompilerInvocation(const CompilerInvocation &CI) {
   // Set up string allocator.
   llvm::BumpPtrAllocator Alloc;
   llvm::StringSaver Strings(Alloc);
@@ -55,7 +56,7 @@ serializeCompilerInvocation(CompilerInvocation &CI) {
 std::vector ModuleDeps::getCanonicalCommandLine(
 std::function LookupPCMPath,
 std::function LookupModuleDeps) const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
+  CompilerInvocation CI(Invocation);
 
   dependencies::detail::collectPCMAndModuleMapPaths(
   ClangModuleDeps, LookupPCMPath, LookupModuleDeps,
@@ -66,9 +67,7 @@ std::vector ModuleDeps::getCanonicalCommandLine(
 
 std::vector
 ModuleDeps::getCanonicalCommandLineWithoutModulePaths() const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
-
-  return serializeCompilerInvocation(CI);
+  return serializeCompilerInvocation(Invocation);
 }
 
 void dependencies::detail::collectPCMAndModuleMapPaths(
@@ -190,11 +189,9 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const 
Module *M) {
 MD.FileDeps.insert(IF.getFile()->getName());
   });
 
-  // FIXME: Prepare the CompilerInvocation for building this module **now**, so
-  //that we store the actual context hash for this module (not just the
-  //context hash inherited from the original TU).
-  MD.Invocation = Instance.getInvocationPtr();
-  MD.ID.ContextHash = MD.Invocation->getModuleHash();
+  MD.Invocation =
+  makeInvocationForModuleBuildWithoutPaths(MD, Instance.getInvocation());
+  MD.ID.ContextHash = MD.Invocation.getModuleHash();
 
   llvm::DenseSet AddedModules;
   addAllSubmoduleDeps(M, MD, AddedModules);



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


[clang] d9cb70b - [clang] NFC: Remove CompilerInstance::getInvocationPtr

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-05-17T09:33:35+02:00
New Revision: d9cb70ba29dbd74aac294caad0686f1ed52295f9

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

LOG: [clang] NFC: Remove CompilerInstance::getInvocationPtr

This member function was introduced in 0a92e09c ([clang][deps] Generate the 
full command-line for modules) in order to keep the CompilerInvocation object 
alive after CompilerInstance goes out of scope. However, d3fb4b90 
([clang][deps] NFC: Report modules' context hash) removes that use-case, making 
this function dead.

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 7778924fc452f..5e879d672d801 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -225,11 +225,9 @@ class CompilerInstance : public ModuleLoader {
 
   bool hasInvocation() const { return Invocation != nullptr; }
 
-  CompilerInvocation &getInvocation() { return *getInvocationPtr(); }
-
-  std::shared_ptr getInvocationPtr() {
+  CompilerInvocation &getInvocation() {
 assert(Invocation && "Compiler instance has no invocation!");
-return Invocation;
+return *Invocation;
   }
 
   /// setInvocation - Replace the current invocation.



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


[PATCH] D102482: [clang][deps] NFC: Report modules' context hash

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks for the review!




Comment at: clang/include/clang/Frontend/CompilerInstance.h:230-232
-  std::shared_ptr getInvocationPtr() {
+  CompilerInvocation &getInvocation() {
 assert(Invocation && "Compiler instance has no invocation!");
-return Invocation;

dexonsmith wrote:
> It'd be nice to remove this API separately in a follow up patch; the change 
> to CompilerInstance.h is not necessary here so it's easy to split, focusing 
> the patch on the relevant changes, and that pattern is easier for reverting 
> (especially in out-of-tree code).
> 
Committed separately as d9cb70ba29dbd74aac294caad0686f1ed52295f9.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102482

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


[PATCH] D102519: [clangd] Set FileSystem for tweaks in Check tool.

2021-05-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/tool/Check.cpp:215
  nullptr);
-  for (const auto &T :
-   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
+  auto Tweaks =
+  prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);

IIUC, the ordering here is to ensure `FS` is not available during `prepare` but 
exists in `apply`. That sounds sane, as we would like prepare to be fast, and 
IO is likely slow.
But this is very subtle, so deserves a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102519

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


[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy updated this revision to Diff 345777.
condy added a comment.

Fix some tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

Files:
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll


Index: llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
@@ -28,8 +28,8 @@
 ; CHECK: [[LOCDESCR:@___asan_gen_.[0-9]+]] = private unnamed_addr constant { 
[22 x i8]*, i32, i32 } { [22 x i8]* [[FILENAME]], i32 5, i32 5 }
 ; NOALIAS: @__asan_global_global = {{.*}}i64 ptrtoint ({ i32, [60 x i8] }* 
@global to i64){{.*}} section "asan_globals"{{.*}}, !associated
 ; NOALIAS: @__asan_global_.str = {{.*}}i64 ptrtoint ({ [14 x i8], [50 x i8] }* 
@{{.str|1}} to i64){{.*}} section "asan_globals"{{.*}}, !associated
-; ALIAS: @__asan_global_global = {{.*}}i64 ptrtoint ({ i32, [60 x i8] }* @0 to 
i64){{.*}} section "asan_globals"{{.*}}, !associated
-; ALIAS: @__asan_global_.str = {{.*}}i64 ptrtoint ({ [14 x i8], [50 x i8] }* 
@3 to i64){{.*}} section "asan_globals"{{.*}}, !associated
+; ALIAS: @__asan_global_global = {{.*}}i64 ptrtoint ({ i32, [60 x i8] }* @1 to 
i64){{.*}} section "asan_globals"{{.*}}, !associated
+; ALIAS: @__asan_global_.str = {{.*}}i64 ptrtoint ({ [14 x i8], [50 x i8] }* 
@4 to i64){{.*}} section "asan_globals"{{.*}}, !associated
 
 ; The metadata has to be inserted to llvm.compiler.used to avoid being stripped
 ; during LTO.
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2372,6 +2372,18 @@
 return false;
   }
 
+  // Create a global zero-sized array precedence before GlobalsToChange[0] so
+  // that the underflow of the it could be observable.
+  ArrayType *ZeroSizedArrayTy = ArrayType::get(IRB.getInt8Ty(), 0);
+  GlobalVariable *UnderflowObserverGV = new GlobalVariable(
+  M, ZeroSizedArrayTy, /*isConstant*/ false, 
GlobalVariable::PrivateLinkage,
+  ConstantArray::get(ZeroSizedArrayTy, {}), kAsanGenPrefix,
+  GlobalsToChange[0]);
+  GlobalsToChange.insert(GlobalsToChange.begin(), UnderflowObserverGV);
+
+  // Update size as we insert a dummy one.
+  n = GlobalsToChange.size();
+
   auto &DL = M.getDataLayout();
 
   // A global is described by a structure
Index: clang/test/CodeGen/asan-static-odr.cpp
===
--- clang/test/CodeGen/asan-static-odr.cpp
+++ clang/test/CodeGen/asan-static-odr.cpp
@@ -13,5 +13,5 @@
 // CHECK-NOT: private alias
 // CHECK: [[VAR:@.*global.*]] ={{.*}} global { i32, [60 x i8] } 
zeroinitializer, align 32
 // CHECK: @0 = internal global {{.*}} [[VAR]] to i64), {{.*}}, i64 -1 }]
-// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
-// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([2 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([2 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 2)
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -33,8 +33,8 @@
 // ASAN-NEXT: call void @__asan_version_mismatch_check
 // KASAN-NOT: call void @__asan_init
 // KASAN-NOT: call void @__asan_version_mismatch_check
-// ASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 7)
-// KASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 5)
+// ASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 8)
+// KASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 6)
 // CHECK-NEXT: ret void
 
 // CHECK:  define internal void @asan.module_dtor() #[[#ATTR]] {
Index: clang/test/CodeGen/asan-globals-odr.cpp
===
--- clang/test/CodeGen/asan-globals-odr.cpp
+++ clang/test/CodeGen/asan-globals-odr.cpp
@@ -24,7 +24,7 @@
 // GLOB_ALIAS_INDICATOR: @0 = internal global {{.*}} @1 to i64), {{.*}}, i64 
ptrtoint (i8* [[ODR]] to i64) }]
 
 // ALIAS0-NOT: private alias
-// ALIAS1: @1 = private alias {{.*}} [[VAR]]
+// ALIAS1: @2 = private alias {{.*}} [[VAR]]

[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy updated this revision to Diff 345784.
condy added a comment.

Fix all tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

Files:
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
  llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
  llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll

Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -14,9 +14,9 @@
 ; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [59 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 64, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
+; CHECK-SAME:   i64 5, i64 64, i64 ptrtoint ([17 x i8]* @___asan_gen_.2 to i64),
 ; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
+; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.4 to i64), i64 0 },
 ; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
Index: llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
+++ llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
@@ -11,16 +11,16 @@
 @c = internal global [2 x i32] zeroinitializer, align 4
 @d = unnamed_addr global [2 x i32] zeroinitializer, align 4
 
-; NOALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @a to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
-; NOALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @b to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
-; NOALIAS-NEXT: @__asan_global_c = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @c to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.3 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
-; NOALIAS-NEXT: @__asan_global_d = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @d to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.4 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
+; NOALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @a to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
+; NOALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @b to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.3 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
+; NOALIAS-NEXT: @__asan_global_c = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @c to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.4 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
+; NOALIAS-NEXT: @__asan_global_d = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @d to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.5 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
 
-; ALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @0 to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
-; ALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @1 to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 

[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy updated this revision to Diff 345786.
condy added a comment.

Fix typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

Files:
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
  llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
  llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll

Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -14,9 +14,9 @@
 ; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [59 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 64, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
+; CHECK-SAME:   i64 5, i64 64, i64 ptrtoint ([17 x i8]* @___asan_gen_.2 to i64),
 ; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
+; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.4 to i64), i64 0 },
 ; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
Index: llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
+++ llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
@@ -11,16 +11,16 @@
 @c = internal global [2 x i32] zeroinitializer, align 4
 @d = unnamed_addr global [2 x i32] zeroinitializer, align 4
 
-; NOALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @a to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
-; NOALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @b to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
-; NOALIAS-NEXT: @__asan_global_c = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @c to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.3 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
-; NOALIAS-NEXT: @__asan_global_d = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @d to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.4 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
+; NOALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @a to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
+; NOALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @b to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.3 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
+; NOALIAS-NEXT: @__asan_global_c = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @c to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.4 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
+; NOALIAS-NEXT: @__asan_global_d = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @d to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.5 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
 
-; ALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @0 to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
-; ALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @1 to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8

[PATCH] D102577: TreeTransform.h: make the switch case more beautiful

2021-05-17 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

I think you can add a NFC in the title.




Comment at: clang/lib/Sema/TreeTransform.h:3947-3949
 NestedNameSpecifierLoc NNS,
  QualType ObjectType,
  NamedDecl *FirstQualifierInScope) 
{

There're some format issues in this function. It's better if you can fix them 
too. You can use clang-format to help with you.


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

https://reviews.llvm.org/D102577

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


[clang] d3676d4 - [clang][modules] Build inferred modules

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Michael Spencer
Date: 2021-05-17T10:40:51+02:00
New Revision: d3676d4b666ead794fc58bbc7e07aa406dcf487a

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

LOG: [clang][modules] Build inferred modules

This patch enables explicitly building inferred modules.

Effectively a cherry-pick of https://github.com/apple/llvm-project/pull/699 
authored by @Bigcheese with libclang and dependency scanner changes omitted.

Contains the following changes:

1. [Clang] Fix the header paths in clang::Module for inferred modules.
  * The UmbrellaAsWritten and NameAsWritten fields in clang::Module are a lie 
for framework modules. For those they actually are the path to the header or 
umbrella relative to the clang::Module::Directory.
  * The exception to this case is for inferred modules. Here it actually is the 
name as written, because we print out the module and read it back in when 
implicitly building modules. This causes a problem when explicitly building an 
inferred module, as we skip the printing out step.
  * In order to fix this issue this patch adds a new field for the path we want 
to use in getInputBufferForModule. It also makes NameAsWritten actually be the 
name written in the module map file (or that would be, in the case of an 
inferred module).

2. [Clang] Allow explicitly building an inferred module.
  * Building the actual module still fails, but make sure it fails for the 
right reason.

Split from D100934.

Reviewed By: dexonsmith

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

Added: 

clang/test/Modules/Inputs/explicit-build-inferred/frameworks/Inferred.framework/Headers/Inferred.h

clang/test/Modules/Inputs/explicit-build-inferred/frameworks/module.modulemap
clang/test/Modules/explicit-build-inferred.cpp

Modified: 
clang/include/clang/Basic/Module.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Basic/Module.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 16f34d11398af..3476b05d2e929 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -141,6 +141,9 @@ class Module {
   /// The name of the umbrella entry, as written in the module map.
   std::string UmbrellaAsWritten;
 
+  // The path to the umbrella entry relative to the root module's \c Directory.
+  std::string UmbrellaRelativeToRootModuleDirectory;
+
   /// The module through which entities defined in this module will
   /// eventually be exposed, for use in "private" modules.
   std::string ExportAsModule;
@@ -188,6 +191,7 @@ class Module {
   /// file.
   struct Header {
 std::string NameAsWritten;
+std::string PathRelativeToRootModuleDirectory;
 const FileEntry *Entry;
 
 explicit operator bool() { return Entry; }
@@ -197,6 +201,7 @@ class Module {
   /// file.
   struct DirectoryName {
 std::string NameAsWritten;
+std::string PathRelativeToRootModuleDirectory;
 const DirectoryEntry *Entry;
 
 explicit operator bool() { return Entry; }
@@ -545,7 +550,8 @@ class Module {
   /// module.
   Header getUmbrellaHeader() const {
 if (auto *FE = Umbrella.dyn_cast())
-  return Header{UmbrellaAsWritten, FE};
+  return Header{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
+FE};
 return Header{};
   }
 

diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 64562e6760df8..41f85a1f572d7 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -649,12 +649,14 @@ class ModuleMap {
   /// Sets the umbrella header of the given module to the given
   /// header.
   void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
- Twine NameAsWritten);
+ const Twine &NameAsWritten,
+ const Twine &PathRelativeToRootModuleDirectory);
 
   /// Sets the umbrella directory of the given module to the given
   /// directory.
   void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
-  Twine NameAsWritten);
+  const Twine &NameAsWritten,
+  const Twine &PathRelativeToRootModuleDirectory);
 
   /// Adds this header to the given module.
   /// \param Role The role of the header wrt the module.

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 8d26149cd39d9..b6cf1624ef017 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -245,9 +245,10 @@ bool Module::fullModuleNameIs(ArrayRef 
nameParts) const {
 
 M

[PATCH] D102491: [clang][modules] Build inferred modules

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd3676d4b666e: [clang][modules] Build inferred modules 
(authored by Bigcheese, committed by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102491

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/Module.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  
clang/test/Modules/Inputs/explicit-build-inferred/frameworks/Inferred.framework/Headers/Inferred.h
  clang/test/Modules/Inputs/explicit-build-inferred/frameworks/module.modulemap
  clang/test/Modules/explicit-build-inferred.cpp

Index: clang/test/Modules/explicit-build-inferred.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-inferred.cpp
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t && mkdir %t
+//
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fimplicit-module-maps \
+// RUN:   -emit-module -x c++ %S/Inputs/explicit-build-inferred/frameworks/module.modulemap \
+// RUN:   -fmodule-name=Inferred -o %t/Inferred.pcm -F %S/Inputs/explicit-build-inferred/frameworks
+//
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fsyntax-only %s \
+// RUN:   -fmodule-map-file=%S/Inputs/explicit-build-inferred/frameworks/module.modulemap \
+// RUN:   -fmodule-file=%t/Inferred.pcm -F %S/Inputs/explicit-build-inferred/frameworks
+
+#include 
+
+inferred a = 0;
Index: clang/test/Modules/Inputs/explicit-build-inferred/frameworks/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-inferred/frameworks/module.modulemap
@@ -0,0 +1 @@
+framework module * {}
Index: clang/test/Modules/Inputs/explicit-build-inferred/frameworks/Inferred.framework/Headers/Inferred.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-inferred/frameworks/Inferred.framework/Headers/Inferred.h
@@ -0,0 +1 @@
+typedef int inferred;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1921,10 +1921,9 @@
 std::string Filename = std::string(key.Filename);
 if (key.Imported)
   Reader.ResolveImportedPath(M, Filename);
-// FIXME: This is not always the right filename-as-written, but we're not
-// going to use this information to rebuild the module, so it doesn't make
-// a lot of difference.
-Module::Header H = {std::string(key.Filename), *FileMgr.getFile(Filename)};
+// FIXME: NameAsWritten
+Module::Header H = {std::string(key.Filename), "",
+*FileMgr.getFile(Filename)};
 ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
 HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader);
   }
@@ -5618,7 +5617,8 @@
   ResolveImportedPath(F, Filename);
   if (auto Umbrella = PP.getFileManager().getFile(Filename)) {
 if (!CurrentModule->getUmbrellaHeader())
-  ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob);
+  // FIXME: NameAsWritten
+  ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob, "");
 else if (CurrentModule->getUmbrellaHeader().Entry != *Umbrella) {
   if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
 Error("mismatched umbrella headers in submodule");
@@ -5651,7 +5651,8 @@
   ResolveImportedPath(F, Dirname);
   if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) {
 if (!CurrentModule->getUmbrellaDir())
-  ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob);
+  // FIXME: NameAsWritten
+  ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob, "");
 else if (CurrentModule->getUmbrellaDir().Entry != *Umbrella) {
   if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
 Error("mismatched umbrella directories in submodule");
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -260,9 +260,10 @@
   << UmbrellaMod->getFullModuleName();
   else
 // Record this umbrella header.
-setUmbrellaHeader(Mod, *File, RelativePathName.str());
+setUmbrellaHeader(Mod, *File, Header.FileName, RelativePathName.str());
 } else {
-  Module::Header H = {std::string(RelativePathName.str()), *File};
+  Module::Header H = {Header.FileName, std::string(RelativePathName.str()),
+  *File};
   if (Header.Kind == Module::HK_Excluded)

[PATCH] D102280: [analyzer] Engine: fix crash with SEH __leave keyword

2021-05-17 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

I think it's good to go. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102280

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


[PATCH] D102577: NFC: TreeTransform.h: make the switch case more beautiful

2021-05-17 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 345792.
zhouyizhou retitled this revision from "TreeTransform.h: make the switch case 
more beautiful " to "NFC: TreeTransform.h: make the switch case more beautiful 
".
zhouyizhou added a comment.

use clang-format to fix the function TransformNestedNameSpecifierLoc


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

https://reviews.llvm.org/D102577

Files:
  clang/lib/Sema/TreeTransform.h


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3941,12 +3941,10 @@
   return Sema::ConditionResult();
 }
 
-template
-NestedNameSpecifierLoc
-TreeTransform::TransformNestedNameSpecifierLoc(
-NestedNameSpecifierLoc NNS,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope) 
{
+template 
+NestedNameSpecifierLoc TreeTransform::TransformNestedNameSpecifierLoc(
+NestedNameSpecifierLoc NNS, QualType ObjectType,
+NamedDecl *FirstQualifierInScope) {
   SmallVector Qualifiers;
   for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Qualifier = Qualifier.getPrefix())
@@ -3960,28 +3958,26 @@
 switch (QNNS->getKind()) {
 case NestedNameSpecifier::Identifier: {
   Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
-  Q.getLocalBeginLoc(), Q.getLocalEndLoc(), 
ObjectType);
+  Q.getLocalBeginLoc(), Q.getLocalEndLoc(),
+  ObjectType);
   if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
   SS, FirstQualifierInScope, 
false))
 return NestedNameSpecifierLoc();
-}
   break;
+}
 
 case NestedNameSpecifier::Namespace: {
-  NamespaceDecl *NS
-= cast_or_null(
-getDerived().TransformDecl(
-  Q.getLocalBeginLoc(),
-   
QNNS->getAsNamespace()));
+  NamespaceDecl *NS =
+  cast_or_null(getDerived().TransformDecl(
+  Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
   SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
   break;
 }
 
 case NestedNameSpecifier::NamespaceAlias: {
-  NamespaceAliasDecl *Alias
-= cast_or_null(
-  getDerived().TransformDecl(Q.getLocalBeginLoc(),
- QNNS->getAsNamespaceAlias()));
+  NamespaceAliasDecl *Alias =
+  cast_or_null(getDerived().TransformDecl(
+  Q.getLocalBeginLoc(), QNNS->getAsNamespaceAlias()));
   SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
 Q.getLocalEndLoc());
   break;
@@ -4017,7 +4013,7 @@
 if (TL.getType()->isEnumeralType())
   SemaRef.Diag(TL.getBeginLoc(),
diag::warn_cxx98_compat_enum_nested_name_spec);
-SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
+SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL,
   Q.getLocalEndLoc());
 break;
   }
@@ -4026,7 +4022,7 @@
   TypedefTypeLoc TTL = TL.getAs();
   if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
-  << TL.getType() << SS.getRange();
+<< TL.getType() << SS.getRange();
   }
   return NestedNameSpecifierLoc();
 }


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3941,12 +3941,10 @@
   return Sema::ConditionResult();
 }
 
-template
-NestedNameSpecifierLoc
-TreeTransform::TransformNestedNameSpecifierLoc(
-NestedNameSpecifierLoc NNS,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope) {
+template 
+NestedNameSpecifierLoc TreeTransform::TransformNestedNameSpecifierLoc(
+NestedNameSpecifierLoc NNS, QualType ObjectType,
+NamedDecl *FirstQualifierInScope) {
   SmallVector Qualifiers;
   for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Qualifier = Qualifier.getPrefix())
@@ -3960,28 +3958,26 @@
 switch (QNNS->getKind()) {
 case NestedNameSpecifier::Identifier: {
   Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
-  Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
+  Q.getLocalBeginLoc(), Q.getLocalEndLoc(),
+   

[PATCH] D102519: [clangd] Set FileSystem for tweaks in Check tool.

2021-05-17 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 345793.
usaxena95 marked an inline comment as done.
usaxena95 added a comment.

added comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102519

Files:
  clang-tools-extra/clangd/tool/Check.cpp


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -212,8 +212,13 @@
  AST->getTokens(), Start, End);
   Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree),
  nullptr);
-  for (const auto &T :
-   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
+  // FS is only populated when applying a tweak, not during prepare as
+  // prepare should not do any I/O to be fast.
+  auto Tweaks =
+  prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);
+  Selection.FS =
+  &AST->getSourceManager().getFileManager().getVirtualFileSystem();
+  for (const auto &T : Tweaks) {
 auto Result = T->apply(Selection);
 if (!Result) {
   elog("tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -212,8 +212,13 @@
  AST->getTokens(), Start, End);
   Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree),
  nullptr);
-  for (const auto &T :
-   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
+  // FS is only populated when applying a tweak, not during prepare as
+  // prepare should not do any I/O to be fast.
+  auto Tweaks =
+  prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);
+  Selection.FS =
+  &AST->getSourceManager().getFileManager().getVirtualFileSystem();
+  for (const auto &T : Tweaks) {
 auto Result = T->apply(Selection);
 if (!Result) {
   elog("tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 0e7c7d4 - [clangd] Set FileSystem for tweaks in Check tool.

2021-05-17 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2021-05-17T11:10:07+02:00
New Revision: 0e7c7d461df167f141428286afb781636ac92a9e

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

LOG: [clangd] Set FileSystem for tweaks in Check tool.

Tweaks like DefineOutline depend on FS to be set at `apply()` time.
After https://reviews.llvm.org/D93978, tweaks run from Check tool lost
access to FS. This makes the available to apply() once again.

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

Added: 


Modified: 
clang-tools-extra/clangd/tool/Check.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/Check.cpp 
b/clang-tools-extra/clangd/tool/Check.cpp
index 0b1da96771972..89487bd8607f1 100644
--- a/clang-tools-extra/clangd/tool/Check.cpp
+++ b/clang-tools-extra/clangd/tool/Check.cpp
@@ -212,8 +212,13 @@ class Checker {
  AST->getTokens(), Start, End);
   Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree),
  nullptr);
-  for (const auto &T :
-   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
+  // FS is only populated when applying a tweak, not during prepare as
+  // prepare should not do any I/O to be fast.
+  auto Tweaks =
+  prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);
+  Selection.FS =
+  &AST->getSourceManager().getFileManager().getVirtualFileSystem();
+  for (const auto &T : Tweaks) {
 auto Result = T->apply(Selection);
 if (!Result) {
   elog("tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());



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


[PATCH] D102519: [clangd] Set FileSystem for tweaks in Check tool.

2021-05-17 Thread Utkarsh Saxena via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e7c7d461df1: [clangd] Set FileSystem for tweaks in Check 
tool. (authored by usaxena95).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102519

Files:
  clang-tools-extra/clangd/tool/Check.cpp


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -212,8 +212,13 @@
  AST->getTokens(), Start, End);
   Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree),
  nullptr);
-  for (const auto &T :
-   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
+  // FS is only populated when applying a tweak, not during prepare as
+  // prepare should not do any I/O to be fast.
+  auto Tweaks =
+  prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);
+  Selection.FS =
+  &AST->getSourceManager().getFileManager().getVirtualFileSystem();
+  for (const auto &T : Tweaks) {
 auto Result = T->apply(Selection);
 if (!Result) {
   elog("tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -212,8 +212,13 @@
  AST->getTokens(), Start, End);
   Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree),
  nullptr);
-  for (const auto &T :
-   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
+  // FS is only populated when applying a tweak, not during prepare as
+  // prepare should not do any I/O to be fast.
+  auto Tweaks =
+  prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules);
+  Selection.FS =
+  &AST->getSourceManager().getFileManager().getVirtualFileSystem();
+  for (const auto &T : Tweaks) {
 auto Result = T->apply(Selection);
 if (!Result) {
   elog("tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102519: [clangd] Set FileSystem for tweaks in Check tool.

2021-05-17 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 added a comment.

Did you need any other change ? Didn't realised the revision was not "accepted".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102519

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


[PATCH] D102519: [clangd] Set FileSystem for tweaks in Check tool.

2021-05-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

oops, sorry. i thought i've accepted the revision already :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102519

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


[clang] 1d9e8e1 - [clang][deps] Support inferred modules

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Michael Spencer
Date: 2021-05-17T11:41:54+02:00
New Revision: 1d9e8e13dd7b3204fa51ada17d1608bdbd1bed66

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

LOG: [clang][deps] Support inferred modules

This patch adds support for inferred modules to the dependency scanner.

Effectively a cherry-pick of https://github.com/apple/llvm-project/pull/699 
authored by @Bigcheese with libclang and other changes omitted.

Contains following changes:

1. [Clang][ScanDeps] Ignore __inferred_module.map dependency.
  * This shows up with inferred modules, but it doesn't exist on disk, so don't 
report it as a dependency.

2. [Clang][ScanDeps] Use the module map a module was inferred from for inferred 
modules.

Also includes a smoke test that uses clang-scan-deps output to perform an 
explicit build. There's no intention to duplicate whatever `test/Modules` 
contains, just to verify the produced command-line does "work" (with very loose 
definition of work).

Split from D100934.

Reviewed By: dexonsmith

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

Added: 

clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h

clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h

clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
clang/test/ClangScanDeps/Inputs/frameworks/module.modulemap
clang/test/ClangScanDeps/Inputs/modules_inferred_cdb.json
clang/test/ClangScanDeps/modules-inferred-explicit-build.m
clang/test/ClangScanDeps/modules-inferred.m
clang/utils/module-deps-to-rsp.py

Modified: 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/modules-full.cpp

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 51b7fc48628c1..d9e0bead13bc5 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -33,7 +33,6 @@ makeInvocationForModuleBuildWithoutPaths(const ModuleDeps 
&Deps,
   CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
 
   CI.getLangOpts()->ImplicitModules = false;
-  CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
 
   return CI;
 }
@@ -179,13 +178,22 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const 
Module *M) {
   const FileEntry *ModuleMap = Instance.getPreprocessor()
.getHeaderSearchInfo()
.getModuleMap()
-   .getContainingModuleMapFile(M);
+   .getModuleMapFileForUniquing(M);
   MD.ClangModuleMapFile = std::string(ModuleMap ? ModuleMap->getName() : "");
 
   serialization::ModuleFile *MF =
   MDC.Instance.getASTReader()->getModuleManager().lookup(M->getASTFile());
   MDC.Instance.getASTReader()->visitInputFiles(
   *MF, true, true, [&](const serialization::InputFile &IF, bool isSystem) {
+// __inferred_module.map is the result of the way in which an implicit
+// module build handles inferred modules. It adds an overlay VFS with
+// this file in the proper directory and relies on the rest of Clang to
+// handle it like normal. With explicitly built modules we don't need
+// to play VFS tricks, so replace it with the correct module map.
+if (IF.getFile()->getName().endswith("__inferred_module.map")) {
+  MD.FileDeps.insert(ModuleMap->getName());
+  return;
+}
 MD.FileDeps.insert(IF.getFile()->getName());
   });
 

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
new file mode 100644
index 0..1855e4fad5f8d
--- /dev/null
+++ 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
@@ -0,0 +1 @@
+typedef int inferred;

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h 
b/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h
new file mode 100644
index 0..a90c62886749f
--- /dev/null
+++ 
b/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h
@@ -0,0 +1 @@
+enum { 

[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d9e8e13dd7b: [clang][deps] Support inferred modules 
(authored by Bigcheese, committed by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D102495?vs=345428&id=345802#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  
clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
  
clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
  clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h
  
clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
  clang/test/ClangScanDeps/Inputs/frameworks/module.modulemap
  clang/test/ClangScanDeps/Inputs/modules_inferred_cdb.json
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-inferred.m
  clang/utils/module-deps-to-rsp.py

Index: clang/utils/module-deps-to-rsp.py
===
--- /dev/null
+++ clang/utils/module-deps-to-rsp.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+
+# Converts clang-scan-deps output into response files.
+#   * For modules, arguments in the resulting response file are enough to build a PCM.
+#   * For translation units, the response file needs to be added to the original Clang invocation from compilation
+# database.
+#
+# Usage:
+#
+#   clang-scan-deps -compilation-database compile_commands.json ... > deps.json
+#   module-deps-to-rsp.py deps.json --module-name=ModuleName > module_name.cc1.rsp
+#   module-deps-to-rsp.py deps.json --tu-index=0 > tu.rsp
+#   clang @module_name.cc1.rsp
+#   clang ... @tu.rsp
+
+import argparse
+import json
+import sys
+
+class ModuleNotFoundError(Exception):
+  def __init__(self, module_name):
+self.module_name = module_name
+
+class FullDeps:
+  def __init__(self):
+self.modules = dict()
+self.translation_units = str()
+
+def getModulePathArgs(modules, full_deps):
+  cmd = []
+  for md in modules:
+m = full_deps.modules[md['module-name'] + '-' + md['context-hash']]
+cmd += [u'-fmodule-map-file=' + m['clang-modulemap-file']]
+cmd += [u'-fmodule-file=' + md['module-name'] + '-' + md['context-hash'] + '.pcm']
+  return cmd
+
+def getCommandLineForModule(module_name, full_deps):
+  for m in full_deps.modules.values():
+if m['name'] == module_name:
+  module = m
+  break
+  else:
+raise ModuleNotFoundError(module_name)
+
+  cmd = m['command-line']
+  cmd += getModulePathArgs(m['clang-module-deps'], full_deps)
+  cmd += [u'-o', m['name'] + '-' + m['context-hash'] + '.pcm']
+  cmd += [m['clang-modulemap-file']]
+  
+  return cmd
+  
+def getCommandLineForTU(tu, full_deps):
+  cmd = tu['command-line']
+  cmd += getModulePathArgs(tu['clang-module-deps'], full_deps)
+  return cmd
+
+def parseFullDeps(json):
+  ret = FullDeps()
+  for m in json['modules']:
+ret.modules[m['name'] + '-' + m['context-hash']] = m
+  ret.translation_units = json['translation-units']
+  return ret
+
+def main():
+  parser = argparse.ArgumentParser()
+  parser.add_argument("full_deps_file", help="Path to the full dependencies json file",
+  type=str)
+  action = parser.add_mutually_exclusive_group(required=True)
+  action.add_argument("--module-name", help="The name of the module to get arguments for",
+  type=str)
+  action.add_argument("--tu-index", help="The index of the translation unit to get arguments for",
+  type=int)
+  args = parser.parse_args()
+  
+  full_deps = parseFullDeps(json.load(open(args.full_deps_file, 'r')))
+  
+  try:
+if args.module_name:
+  print(" ".join(getCommandLineForModule(args.module_name, full_deps)))
+
+elif args.tu_index != None:
+  print(" ".join(getCommandLineForTU(full_deps.translation_units[args.tu_index], full_deps)))
+  except:
+print("Unexpected error:", sys.exc_info()[0])
+raise
+
+if __name__ == '__main__':
+  main()
Index: clang/test/ClangScanDeps/modules-inferred.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-inferred.m
@@ -0,0 +1,61 @@
+// RUN: rm -rf %t.dir
+// RUN: rm -rf %t.cdb
+// RUN: mkdir -p %t.dir
+// RUN: cp %s %t.dir/modules_cdb_input.cpp
+// RUN: sed -e "s|DIR|%/t.dir|g" -e "s|FRAMEWORKS|%S/Inputs/frameworks|g" \
+// RUN:   %S/Inputs/modules_inferred_cdb.json > %t.cdb
+//
+// RUN: echo -%t.dir > %t.result
+// RUN: echo -%S >> %t.result
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -format experimental-full \
+// RUN:   -generate-modules-path-args -mode preprocess-minimized-sources >

[PATCH] D102577: NFC: TreeTransform.h: make the function TransformNestedNameSpecifierLoc more beautiful

2021-05-17 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks for improving it.


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

https://reviews.llvm.org/D102577

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


[PATCH] D102443: [PowerPC] Added multiple PowerPC builtins

2021-05-17 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Is there any motivation to add these builtins? I don't see them implemented in 
GCC. Besides, in Clang I think a prefix `__builtin` is preferred for them.




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:28
 
+BUILTIN(__popcntb, "ULiULi", "")
+BUILTIN(__eieio, "v", "")

On PPC we have `__builtin_popcount`, but I only saw `popcntw` and `popcntd` 
generated. (I didn't verify it carefully)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102443

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


[PATCH] D100396: [SYCL] Enable `opencl_global_[host,device]` attributes for SYCL

2021-05-17 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 345806.
bader marked an inline comment as done.
bader added a comment.

Added documentation to cover conversion rules and rebased on ToT.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100396

Files:
  clang/docs/SYCLSupport.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGenSYCL/address-space-conversions.cpp
  clang/test/SemaSYCL/address-space-conversions.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFED>();
+  correct<0x7FFFEB>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/SemaSYCL/address-space-conversions.cpp
===
--- clang/test/SemaSYCL/address-space-conversions.cpp
+++ clang/test/SemaSYCL/address-space-conversions.cpp
@@ -61,4 +61,17 @@
   void *v = GLOB;
   (void)i;
   (void)v;
+
+  __attribute__((opencl_global_host)) int *GLOB_HOST;
+  bar(*GLOB_HOST);
+  bar2(*GLOB_HOST);
+  GLOB = GLOB_HOST;
+  GLOB_HOST = GLOB; // expected-error {{assigning '__global int *' to '__global_host int *' changes address space of pointer}}
+  GLOB_HOST = static_cast<__attribute__((opencl_global_host)) int *>(GLOB); // expected-error {{static_cast from '__global int *' to '__global_host int *' is not allowed}}
+  __attribute__((opencl_global_device)) int *GLOB_DEVICE;
+  bar(*GLOB_DEVICE);
+  bar2(*GLOB_DEVICE);
+  GLOB = GLOB_DEVICE;
+  GLOB_DEVICE = GLOB; // expected-error {{assigning '__global int *' to '__global_device int *' changes address space of pointer}}
+  GLOB_DEVICE = static_cast<__attribute__((opencl_global_device)) int *>(GLOB); // expected-error {{static_cast from '__global int *' to '__global_device int *' is not allowed}}
 }
Index: clang/test/CodeGenSYCL/address-space-conversions.cpp
===
--- clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -29,6 +29,10 @@
   // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca i32*
   // CHECK-DAG: [[PRIV]].ascast = addrspacecast i32** [[PRIV]] to i32* addrspace(4)*
   __attribute__((opencl_private)) int *PRIV;
+  // CHECK-DAG: [[GLOB_DEVICE:%[a-zA-Z0-9]+]] = alloca i32 addrspace(5)*
+  __attribute__((opencl_global_device)) int *GLOBDEVICE;
+  // CHECK-DAG: [[GLOB_HOST:%[a-zA-Z0-9]+]] = alloca i32 addrspace(6)*
+  __attribute__((opencl_global_host)) int *GLOBHOST;
 
   // Explicit conversions
   // From names address spaces to default address space
@@ -57,6 +61,15 @@
   // CHECK-DAG: [[NoAS_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(4)* [[NoAS_LOAD]] to i32*
   // CHECK-DAG: store i32* [[NoAS_CAST]], i32* addrspace(4)* [[PRIV]].ascast
   PRIV = (__attribute__((opencl_private)) int *)NoAS;
+  // From opencl_global_[host/device] address spaces to opencl_global
+  // CHECK-DAG: [[GLOBDEVICE_LOAD:%[a-zA-Z0-9]+]] = load i32 addrspace(5)*, i32 addrspace(5)* addrspace(4)* [[GLOB_DEVICE]].ascast
+  // CHECK-DAG: [[GLOBDEVICE_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(5)* [[GLOBDEVICE_LOAD]] to i32 addrspace(1)*
+  // CHECK-DAG: store i32 addrspace(1)* [[GLOBDEVICE_CAST]], i32 addrspace(1)* addrspace(4)* [[GLOB]].ascast
+  GLOB = (__attribute__((opencl_global)) int *)GLOBDEVICE;
+  // CHECK-DAG: [[GLOBHOST_LOAD:%[a-zA-Z0-9]+]] = load i32 addrspace(6)*, i32 addrspace(6)* addrspace(4)* [[GLOB_HOST]].ascast
+  // CHECK-DAG: [[GLOBHOST_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(6)* [[GLOBHOST_LOAD]] to i32 addrspace(1)*
+  // CHECK-DAG: store i32 addrspace(1)* [[GLOBHOST_CAST]], i32 addrsp

[PATCH] D102280: [analyzer] Engine: fix crash with SEH __leave keyword

2021-05-17 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra added a comment.



In D102280#2762760 , @steakhal wrote:

> I think it's good to go. Thank you!

Great! can you take care of merging it? I don't have accesss.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102280

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


[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/utils/module-deps-to-rsp.py:1
+#!/usr/bin/env python
+

@Bigcheese - https://lab.llvm.org/buildbot/#/builders/139/builds/4147 doesn't 
like this - should this be python3 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-17 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.

Thanks. This sounds good to me, if David agrees.




Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp:1912
+if (!SrcReg)
+  report_fatal_error("Unknow SysReg for Stack Protector Guard Register");
+

-> Unknown



Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp:1954
+  // than 23760.
+  // It might be nice to use AArch64::MOVi32imm here, which would get
+  // expanded in PreSched2 after PostRA, but our lone scratch Reg already

It may be possible to do something earlier, where a we add the MOVi32imm 
earlier before registry allocation and use that as the register for the ldr 
offset. That would keep it simpler than trying to find scratch registers, and 
may be optimized better by the pipeline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

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


[PATCH] D102397: [AArch64] Lower bitreverse in ISel

2021-05-17 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks. LGTM




Comment at: llvm/test/CodeGen/AArch64/neon_rbit.ll:9
+
+define <8 x i8> @rbit_8x8(<8 x i8> %A) nounwind {
+; CHECK-LABEL: rbit_8x8:

v8i8 and v8i16 are fine for this patch. They others were not valid 
aarch64.neon.rbit intrinsics anyway.

Also, it may be better to make this an opt test, I'm not sure. It's probably 
fine either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102397

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


[clang-tools-extra] ec2f737 - [clangd][QueryDriver] Dont check for existence of driver

2021-05-17 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-05-17T12:38:17+02:00
New Revision: ec2f7376e39fa5d820d059b6e83e69690fe6315f

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

LOG: [clangd][QueryDriver] Dont check for existence of driver

Execute implementations already checks for permissions and existence
and returns relevant errors as necessary, so instead of printing our own errors,
we just print theirs.

This also fixes a case in windows where the driver might be missing the `.exe`
suffix. Previously, clangd would reject such a driver because sys::fs::exists is
strict, whereas the underlying Execute implementation would check with `.exe`
suffix too.

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

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp 
b/clang-tools-extra/clangd/QueryDriverDatabase.cpp
index 94faec9f3ed9..9704cb8e480f 100644
--- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ b/clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -164,15 +164,6 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> 
Driver,
 return llvm::None;
   }
 
-  if (!llvm::sys::fs::exists(Driver)) {
-elog("System include extraction: {0} does not exist.", Driver);
-return llvm::None;
-  }
-  if (!llvm::sys::fs::can_execute(Driver)) {
-elog("System include extraction: {0} is not executable.", Driver);
-return llvm::None;
-  }
-
   llvm::SmallString<128> StdErrPath;
   if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
StdErrPath)) {
@@ -219,11 +210,13 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> 
Driver,
 }
   }
 
+  std::string ErrMsg;
   if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
- Redirects)) {
+ Redirects, /*SecondsToWait=*/0,
+ /*MemoryLimit=*/0, &ErrMsg)) {
 elog("System include extraction: driver execution failed with return code: 
"
- "{0}. Args: [{1}]",
- llvm::to_string(RC), printArgv(Args));
+ "{0} - '{1}'. Args: [{2}]",
+ llvm::to_string(RC), ErrMsg, printArgv(Args));
 return llvm::None;
   }
 



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


[PATCH] D102431: [clangd][QueryDriver] Dont check for existence of driver

2021-05-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec2f7376e39f: [clangd][QueryDriver] Dont check for existence 
of driver (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102431

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -164,15 +164,6 @@
 return llvm::None;
   }
 
-  if (!llvm::sys::fs::exists(Driver)) {
-elog("System include extraction: {0} does not exist.", Driver);
-return llvm::None;
-  }
-  if (!llvm::sys::fs::can_execute(Driver)) {
-elog("System include extraction: {0} is not executable.", Driver);
-return llvm::None;
-  }
-
   llvm::SmallString<128> StdErrPath;
   if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
StdErrPath)) {
@@ -219,11 +210,13 @@
 }
   }
 
+  std::string ErrMsg;
   if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
- Redirects)) {
+ Redirects, /*SecondsToWait=*/0,
+ /*MemoryLimit=*/0, &ErrMsg)) {
 elog("System include extraction: driver execution failed with return code: 
"
- "{0}. Args: [{1}]",
- llvm::to_string(RC), printArgv(Args));
+ "{0} - '{1}'. Args: [{2}]",
+ llvm::to_string(RC), ErrMsg, printArgv(Args));
 return llvm::None;
   }
 


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -164,15 +164,6 @@
 return llvm::None;
   }
 
-  if (!llvm::sys::fs::exists(Driver)) {
-elog("System include extraction: {0} does not exist.", Driver);
-return llvm::None;
-  }
-  if (!llvm::sys::fs::can_execute(Driver)) {
-elog("System include extraction: {0} is not executable.", Driver);
-return llvm::None;
-  }
-
   llvm::SmallString<128> StdErrPath;
   if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
StdErrPath)) {
@@ -219,11 +210,13 @@
 }
   }
 
+  std::string ErrMsg;
   if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
- Redirects)) {
+ Redirects, /*SecondsToWait=*/0,
+ /*MemoryLimit=*/0, &ErrMsg)) {
 elog("System include extraction: driver execution failed with return code: "
- "{0}. Args: [{1}]",
- llvm::to_string(RC), printArgv(Args));
+ "{0} - '{1}'. Args: [{2}]",
+ llvm::to_string(RC), ErrMsg, printArgv(Args));
 return llvm::None;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-17 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

LGTM with one nit.




Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp:1919
+int Offset = Options.StackProtectorGuardOffset;
+if (Offset >= 0 && Offset <= 32760 && Offset % 8 == 0)
+  // ldr xN, [xN, #offset]

For all the if/else here I'd include the braces. I know that once the 
preprocessor is done it'll be a one line if but visually it's confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

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


[PATCH] D100630: [Debug-Info][DBX] DW_TAG_rvalue_reference_type should not be generated when dwarf version is smaller than 4

2021-05-17 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

In D100630#2760972 , @dblaikie wrote:

> This isn't the sort of thing I'd like to leave to a FIXME later - seems like 
> the sort of thing we shouldn't create now to fix later.
>
> @aprantl mind having a second look at this to consider the situation further?

OK. Let me summary the two solutions here:
1: fixed in the FE. See patch 
https://reviews.llvm.org/D100630?vs=on&id=338035#toc.
Advantage:

- the DWARF info for `DW_TAG_rvalue_reference_type` and `DW_TAG_reference_type` 
is cached, so we will not have redundant info;
- FE also respects strict dwarf option;

Disadvantage:

- No common interface for strict dwarf option.

2: fixed in the BE. See current patch.
Advantage:

- there is a common interface for tags adding, so we can add strict dwarf 
support in one place

Disadvantage:

- Redundant DWARF info since the final DWARF info adding in BE has no cache 
mechanism. And maybe there should be no such mechanism because after we add a 
DIE tag, we may add an attribute anywhere later, so it is hard to tell the DIE 
tag is identical when we create the DIE tag. If we optimize the redundant DWARF 
tag in the place where we add the fix, what about when we need to add another 
attribute to one of the identical DIE tags? Splitting them again into two 
different DIE tags?
- IR Metadata does not respect the strict DWARF option.

Welcome your comments? @dblaikie @aprantl @probinson and other reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100630

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


[clang] e827d74 - [clang][deps] Specify Python 3 in shebang

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-05-17T13:02:25+02:00
New Revision: e827d74a97dcf6623470baf3bda86b1c9544e3df

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

LOG: [clang][deps] Specify Python 3 in shebang

Some build bots don't like plain `python` in the shebang: 
https://lab.llvm.org/buildbot/#/builders/139/builds/4147.

Added: 


Modified: 
clang/utils/module-deps-to-rsp.py

Removed: 




diff  --git a/clang/utils/module-deps-to-rsp.py 
b/clang/utils/module-deps-to-rsp.py
index 56402bf029b67..7b0534deedfbc 100755
--- a/clang/utils/module-deps-to-rsp.py
+++ b/clang/utils/module-deps-to-rsp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Converts clang-scan-deps output into response files.
 #   * For modules, arguments in the resulting response file are enough to 
build a PCM.



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


[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests on windows: http://45.33.8.238/win/38908/step_7.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[clang] 3549466 - [OpenCL] Drop pragma handling for extension types/decls.

2021-05-17 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-17T12:09:43+01:00
New Revision: 3549466ac05eda57c9ce13abd7cb6dd365f6d8d6

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

LOG: [OpenCL] Drop pragma handling for extension types/decls.

Drop non-conformant extension pragma implementation as
it does not properly disable anything and therefore
enabling non-disabled logic has no meaning.

This simplifies clang code and user interface to the extension
functionality. With this patch extension pragma 'begin'/'end'
and 'enable'/'disable' are only accepted for backward
compatibility and no longer have any default behavior.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Overload.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/SemaOpenCL/extension-begin.cl
clang/test/SemaOpenCL/extension-begin.h

Removed: 
clang/test/CodeGenOpenCL/extension-begin.cl



diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 9a3f7adc619ba..97cb7020f3452 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1239,8 +1239,6 @@ def warn_pragma_expected_colon : Warning<
   "missing ':' after %0 - ignoring">, InGroup;
 def warn_pragma_expected_predicate : Warning<
   "expected %select{'enable', 'disable', 'begin' or 'end'|'disable'}0 - 
ignoring">, InGroup;
-def warn_pragma_begin_end_mismatch : Warning<
-  "OpenCL extension end directive mismatches begin directive - ignoring">, 
InGroup;
 def warn_pragma_unknown_extension : Warning<
   "unknown OpenCL extension %0 - ignoring">, InGroup;
 def warn_pragma_unsupported_extension : Warning<

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0683469506e9b..9dd9b1b5118b5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4372,8 +4372,6 @@ def warn_diagnose_if_succeeded : Warning<"%0">, 
InGroup,
 ShowInSystemHeader;
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
-def note_ovl_candidate_disabled_by_extension : Note<
-"candidate unavailable as it requires OpenCL extension '%0' to be 
enabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;

diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 5be6a618711cd..699c3e8088726 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -760,9 +760,6 @@ class Sema;
 /// This candidate was not viable because its address could not be taken.
 ovl_fail_addr_not_available,
 
-/// This candidate was not viable because its OpenCL extension is disabled.
-ovl_fail_ext_disabled,
-
 /// This inherited constructor is not viable because it would slice the
 /// argument.
 ovl_fail_inhctor_slice,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 135da703c4df9..3a8f41196cc4a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10142,73 +10142,6 @@ class Sema final {
   /// potentially-throwing.
   bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend);
 
-  
//======//
-  // OpenCL extensions.
-  //
-private:
-  std::string CurrOpenCLExtension;
-  /// Extensions required by an OpenCL type.
-  llvm::DenseMap> OpenCLTypeExtMap;
-  /// Extensions required by an OpenCL declaration.
-  llvm::DenseMap> OpenCLDeclExtMap;
-public:
-  llvm::StringRef getCurrentOpenCLExtension() const {
-return CurrOpenCLExtension;
-  }
-
-  /// Check if a function declaration \p FD associates with any
-  /// extensions present in OpenCLDeclExtMap and if so return the
-  /// extension(s) name(s).
-  std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
-
-  /// Check if a function type \p FT associates with any
-  /// extensions present in OpenCLTypeExtMap and if so return the
-  /// extension(s) name(s).
-  std::string getOpenCLExtensionsFromTyp

[PATCH] D101043: [OpenCL] Drop extension pragma handling for extension types/declarations

2021-05-17 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3549466ac05e: [OpenCL] Drop pragma handling for extension 
types/decls. (authored by Anastasia).
Herald added a subscriber: ldrumm.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101043

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Overload.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGenOpenCL/extension-begin.cl
  clang/test/SemaOpenCL/extension-begin.cl
  clang/test/SemaOpenCL/extension-begin.h

Index: clang/test/SemaOpenCL/extension-begin.h
===
--- clang/test/SemaOpenCL/extension-begin.h
+++ clang/test/SemaOpenCL/extension-begin.h
@@ -5,10 +5,13 @@
 #pragma OPENCL EXTENSION all : end
 
 #pragma OPENCL EXTENSION my_ext : begin
-
 struct A {
   int a;
 };
+#pragma OPENCL EXTENSION my_ext : end
+#pragma OPENCL EXTENSION my_ext : end
+
+#define my_ext
 
 typedef struct A TypedefOfA;
 typedef const __private TypedefOfA* PointerOfA;
@@ -17,10 +20,8 @@
 
 __attribute__((overloadable)) void g(long x);
 
-#pragma OPENCL EXTENSION my_ext : end
-#pragma OPENCL EXTENSION my_ext : end
+
 
 __attribute__((overloadable)) void g(void);
 
 #endif // INCLUDED
-
Index: clang/test/SemaOpenCL/extension-begin.cl
===
--- clang/test/SemaOpenCL/extension-begin.cl
+++ clang/test/SemaOpenCL/extension-begin.cl
@@ -29,25 +29,23 @@
 #ifndef USE_PCH
 // expected-warning@extension-begin.h:4 {{expected 'disable' - ignoring}}
 // expected-warning@extension-begin.h:5 {{expected 'disable' - ignoring}}
-// expected-warning@extension-begin.h:21 {{OpenCL extension end directive mismatches begin directive - ignoring}}
 #endif // USE_PCH
 
+#if defined(IMPLICIT_INCLUDE) && defined(USE_PCH)
+//expected-no-diagnostics
+#endif
+
+// Tests that the pragmas are accepted for backward compatibility.
 #pragma OPENCL EXTENSION my_ext : enable
-void test_f1(void) {
+#pragma OPENCL EXTENSION my_ext : disable 
+
+#ifndef my_ext
+#error "Missing my_ext macro"
+#endif
+ 
+// When extension is supported its functionality can be used freely.
+void test(void) {
   struct A test_A1;
   f();
   g(0);
 }
-
-#pragma OPENCL EXTENSION my_ext : disable 
-void test_f2(void) {
-  struct A test_A2; // expected-error {{use of type 'struct A' requires my_ext support}}
-  const struct A test_A_local; // expected-error {{use of type 'struct A' requires my_ext support}}
-  TypedefOfA test_typedef_A; // expected-error {{use of type 'TypedefOfA' (aka 'struct A') requires my_ext support}}
-  PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const __private struct A *') requires my_ext support}}
-  f(); // expected-error {{use of declaration 'f' requires my_ext support}}
-  g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@extension-begin.h:18 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be enabled}}
-// expected-note@extension-begin.h:23 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
-}
-
Index: clang/test/CodeGenOpenCL/extension-begin.cl
===
--- clang/test/CodeGenOpenCL/extension-begin.cl
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -o - | FileCheck %s
-
-__attribute__((overloadable)) void f(int x);
-
-#pragma OPENCL EXTENSION my_ext : begin
-
-__attribute__((overloadable)) void f(long x);
-
-#pragma OPENCL EXTENSION my_ext : end
-
-#pragma OPENCL EXTENSION my_ext : enable
-
-//CHECK: define{{.*}} spir_func void @test_f1(i64 %x)
-//CHECK: call spir_func void @_Z1fl(i64 %{{.*}})
-void test_f1(long x) {
-  f(x);
-}
-
-#pragma OPENCL EXTENSION my_ext : disable
-
-//CHECK: define{{.*}} spir_func void @test_f2(i64 %x)
-//CHECK: call spir_func void @_Z1fi(i32 %{{.*}})
-void test_f2(long x) {
-  f(x);
-}
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -3965,72 +3965,6 @@
   }
   Stream.EmitRecord(OPENCL_EXTENSIONS, Record);
 }
-
-void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) {
-  if (!SemaRef.Context.getLangOpts().OpenCL)
-return;
-
-  // Sort the elements of the 

[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/utils/module-deps-to-rsp.py:1
+#!/usr/bin/env python
+

RKSimon wrote:
> @Bigcheese - https://lab.llvm.org/buildbot/#/builders/139/builds/4147 doesn't 
> like this - should this be python3 ?
Thanks, that seems to do the trick: e827d74a97dcf6623470baf3bda86b1c9544e3df, 
https://lab.llvm.org/buildbot/#/builders/139/builds/4154.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D102495#2763080 , @thakis wrote:

> Looks like this breaks tests on windows: 
> http://45.33.8.238/win/38908/step_7.txt

Thanks for the heads-up. This might be hitting behavior introduced here: 
https://reviews.llvm.org/D102491#C2576775NL1045

Reverting this patch for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Did you see my message about the windows breakage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[clang] ccd485e - Revert "[clang][deps] Support inferred modules"

2021-05-17 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-05-17T13:27:14+02:00
New Revision: ccd485e55424b78c07c2f9520faf00b805f78c9b

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

LOG: Revert "[clang][deps] Support inferred modules"

This reverts commit 1d9e8e13

Something is off with handling Windows paths: 
http://45.33.8.238/win/38908/step_7.txt
Most likely introduced in https://reviews.llvm.org/D102491

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/modules-full.cpp

Removed: 

clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h

clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h

clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
clang/test/ClangScanDeps/Inputs/frameworks/module.modulemap
clang/test/ClangScanDeps/Inputs/modules_inferred_cdb.json
clang/test/ClangScanDeps/modules-inferred-explicit-build.m
clang/test/ClangScanDeps/modules-inferred.m
clang/utils/module-deps-to-rsp.py



diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index d9e0bead13bc5..51b7fc48628c1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -33,6 +33,7 @@ makeInvocationForModuleBuildWithoutPaths(const ModuleDeps 
&Deps,
   CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
 
   CI.getLangOpts()->ImplicitModules = false;
+  CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
 
   return CI;
 }
@@ -178,22 +179,13 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const 
Module *M) {
   const FileEntry *ModuleMap = Instance.getPreprocessor()
.getHeaderSearchInfo()
.getModuleMap()
-   .getModuleMapFileForUniquing(M);
+   .getContainingModuleMapFile(M);
   MD.ClangModuleMapFile = std::string(ModuleMap ? ModuleMap->getName() : "");
 
   serialization::ModuleFile *MF =
   MDC.Instance.getASTReader()->getModuleManager().lookup(M->getASTFile());
   MDC.Instance.getASTReader()->visitInputFiles(
   *MF, true, true, [&](const serialization::InputFile &IF, bool isSystem) {
-// __inferred_module.map is the result of the way in which an implicit
-// module build handles inferred modules. It adds an overlay VFS with
-// this file in the proper directory and relies on the rest of Clang to
-// handle it like normal. With explicitly built modules we don't need
-// to play VFS tricks, so replace it with the correct module map.
-if (IF.getFile()->getName().endswith("__inferred_module.map")) {
-  MD.FileDeps.insert(ModuleMap->getName());
-  return;
-}
 MD.FileDeps.insert(IF.getFile()->getName());
   });
 

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Frameworks/Sub.framework/Headers/Sub.h
deleted file mode 100644
index e69de29bb2d1d..0

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
 
b/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
deleted file mode 100644
index 1855e4fad5f8d..0
--- 
a/clang/test/ClangScanDeps/Inputs/frameworks/Inferred.framework/Headers/Inferred.h
+++ /dev/null
@@ -1 +0,0 @@
-typedef int inferred;

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h 
b/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h
deleted file mode 100644
index a90c62886749f..0
--- 
a/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Headers/System.h
+++ /dev/null
@@ -1 +0,0 @@
-enum { bigger_than_int = 0x8000 };

diff  --git 
a/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
 
b/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
deleted file mode 100644
index 51f72f6642351..0
--- 
a/clang/test/ClangScanDeps/Inputs/frameworks/System.framework/Modules/module.modulemap
+++ /dev/null
@@ -1,3 +0,0 @@
-framework module System [system] {
-  umbrella header "System.h"
-}

diff  --git a/clang/test/ClangScanDeps/Inputs/frameworks/module.modulemap 
b/clang/test/ClangScanDeps/Inputs/frameworks/module.modulemap
deleted file mode 100644
index e3bad873c7e7b..000

[PATCH] D102495: [clang][deps] Support inferred modules

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D102495#2763115 , @thakis wrote:

> Did you see my message about the windows breakage?

Yes, reverted in ccd485e55424b78c07c2f9520faf00b805f78c9b 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102495

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


[clang] 66b112d - [OpenCL] Fix reinterpret_cast of vectors

2021-05-17 Thread Ole Strohm via cfe-commits

Author: Ole Strohm
Date: 2021-05-17T12:42:21+01:00
New Revision: 66b112d624a549489fa0af131cf7b632c6181424

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

LOG: [OpenCL] Fix reinterpret_cast of vectors

Fixes issues with vectors in reinterpret_cast in C++ for OpenCL
and adds tests to make sure they both pass without errors and
generate the correct code.

Fixes: PR47977

Reviewed By: Anastasia

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

Added: 
clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp
clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3a8f41196cc4a..b6143d1d31789 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11640,6 +11640,7 @@ class Sema final {
 
   bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy);
 
+  bool areVectorTypesSameSize(QualType srcType, QualType destType);
   bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType);
   bool isLaxVectorConversion(QualType srcType, QualType destType);
 

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 7ed62cc8990eb..439b128e90ea4 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2335,6 +2335,16 @@ static TryCastResult TryReinterpretCast(Sema &Self, 
ExprResult &SrcExpr,
   return TC_Success;
 }
 
+if (Self.LangOpts.OpenCL && !CStyle) {
+  if (DestType->isExtVectorType() || SrcType->isExtVectorType()) {
+// FIXME: Allow for reinterpret cast between 3 and 4 element vectors
+if (Self.areVectorTypesSameSize(SrcType, DestType)) {
+  Kind = CK_BitCast;
+  return TC_Success;
+}
+  }
+}
+
 // Otherwise, pick a reasonable diagnostic.
 if (!destIsVector)
   msg = diag::err_bad_cxx_cast_vector_to_scalar_
diff erent_size;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 948d5eddb43b3..51df757071457 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7341,6 +7341,25 @@ bool Sema::areMatrixTypesOfTheSameDimension(QualType 
srcTy, QualType destTy) {
  matSrcType->getNumColumns() == matDestType->getNumColumns();
 }
 
+bool Sema::areVectorTypesSameSize(QualType SrcTy, QualType DestTy) {
+  assert(DestTy->isVectorType() || SrcTy->isVectorType());
+
+  uint64_t SrcLen, DestLen;
+  QualType SrcEltTy, DestEltTy;
+  if (!breakDownVectorType(SrcTy, SrcLen, SrcEltTy))
+return false;
+  if (!breakDownVectorType(DestTy, DestLen, DestEltTy))
+return false;
+
+  // ASTContext::getTypeSize will return the size rounded up to a
+  // power of 2, so instead of using that, we need to use the raw
+  // element size multiplied by the element count.
+  uint64_t SrcEltSize = Context.getTypeSize(SrcEltTy);
+  uint64_t DestEltSize = Context.getTypeSize(DestEltTy);
+
+  return (SrcLen * SrcEltSize == DestLen * DestEltSize);
+}
+
 /// Are the two types lax-compatible vector types?  That is, given
 /// that one of them is a vector, do they have equal storage sizes,
 /// where the storage size is the number of elements times the element
@@ -7359,18 +7378,7 @@ bool Sema::areLaxCompatibleVectorTypes(QualType srcTy, 
QualType destTy) {
   if (srcTy->isScalarType() && destTy->isExtVectorType()) return false;
   if (destTy->isScalarType() && srcTy->isExtVectorType()) return false;
 
-  uint64_t srcLen, destLen;
-  QualType srcEltTy, destEltTy;
-  if (!breakDownVectorType(srcTy, srcLen, srcEltTy)) return false;
-  if (!breakDownVectorType(destTy, destLen, destEltTy)) return false;
-
-  // ASTContext::getTypeSize will return the size rounded up to a
-  // power of 2, so instead of using that, we need to use the raw
-  // element size multiplied by the element count.
-  uint64_t srcEltSize = Context.getTypeSize(srcEltTy);
-  uint64_t destEltSize = Context.getTypeSize(destEltTy);
-
-  return (srcLen * srcEltSize == destLen * destEltSize);
+  return areVectorTypesSameSize(srcTy, destTy);
 }
 
 /// Is this a legal conversion between two types, one of which is

diff  --git a/clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp 
b/clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp
new file mode 100644
index 0..430223f337b77
--- /dev/null
+++ b/clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp
@@ -0,0 +1,17 @@
+//RUN: %clang_cc1 %s -triple spir -emit-llvm -O0 -o - | FileCheck %s
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+typedef int int4 __attribute__((ext_vector_type(4)));
+typedef long long2 __attribute__((ext_vector_type(2)));
+
+//CHECK-LABEL: define{{

[PATCH] D101519: [C++4OpenCL] Fix reinterpret_cast of vectors

2021-05-17 Thread Ole Strohm via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG66b112d624a5: [OpenCL] Fix reinterpret_cast of vectors 
(authored by olestrohm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101519

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp
  clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp

Index: clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp
===
--- /dev/null
+++ clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+typedef int int3 __attribute__((ext_vector_type(3)));
+typedef int int4 __attribute__((ext_vector_type(4)));
+
+kernel void foo() {
+  // Testing conversions between vectors and vectors/scalars
+  long l1;
+  auto l_to_i2 = reinterpret_cast(l1);
+  int2 i2;
+  auto i2_to_l = reinterpret_cast(i2);
+  auto i2_to_i = reinterpret_cast(i2); // expected-error{{reinterpret_cast from vector 'int2' (vector of 2 'int' values) to scalar 'int' of different size}}
+  auto i2_to_i2 = reinterpret_cast(i2);
+
+  // Only integral types (and pointer/references) can be reinterpret casted to themselves.
+  // Currently this does not include any opencl types.
+  reserve_id_t r_id1;
+  auto r_id2 = reinterpret_cast(r_id1); // expected-error{{reinterpret_cast from 'reserve_id_t' to 'reserve_id_t' is not allowed}}
+}
Index: clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp
@@ -0,0 +1,17 @@
+//RUN: %clang_cc1 %s -triple spir -emit-llvm -O0 -o - | FileCheck %s
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+typedef int int4 __attribute__((ext_vector_type(4)));
+typedef long long2 __attribute__((ext_vector_type(2)));
+
+//CHECK-LABEL: define{{.*}} spir_func void @_Z3barPU3AS1Dv2_i
+void bar(global int2 *in) {
+  //CHECK: bitcast <2 x i32> %{{[0-9]+}} to i64
+  auto l = reinterpret_cast(in[0]);
+  //CHECK: bitcast i64 %{{[0-9]+}} to <2 x i32>
+  auto i2 = reinterpret_cast(l);
+
+  int4 i4;
+  //CHECK: bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+  auto l2 = reinterpret_cast(i4);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7341,6 +7341,25 @@
  matSrcType->getNumColumns() == matDestType->getNumColumns();
 }
 
+bool Sema::areVectorTypesSameSize(QualType SrcTy, QualType DestTy) {
+  assert(DestTy->isVectorType() || SrcTy->isVectorType());
+
+  uint64_t SrcLen, DestLen;
+  QualType SrcEltTy, DestEltTy;
+  if (!breakDownVectorType(SrcTy, SrcLen, SrcEltTy))
+return false;
+  if (!breakDownVectorType(DestTy, DestLen, DestEltTy))
+return false;
+
+  // ASTContext::getTypeSize will return the size rounded up to a
+  // power of 2, so instead of using that, we need to use the raw
+  // element size multiplied by the element count.
+  uint64_t SrcEltSize = Context.getTypeSize(SrcEltTy);
+  uint64_t DestEltSize = Context.getTypeSize(DestEltTy);
+
+  return (SrcLen * SrcEltSize == DestLen * DestEltSize);
+}
+
 /// Are the two types lax-compatible vector types?  That is, given
 /// that one of them is a vector, do they have equal storage sizes,
 /// where the storage size is the number of elements times the element
@@ -7359,18 +7378,7 @@
   if (srcTy->isScalarType() && destTy->isExtVectorType()) return false;
   if (destTy->isScalarType() && srcTy->isExtVectorType()) return false;
 
-  uint64_t srcLen, destLen;
-  QualType srcEltTy, destEltTy;
-  if (!breakDownVectorType(srcTy, srcLen, srcEltTy)) return false;
-  if (!breakDownVectorType(destTy, destLen, destEltTy)) return false;
-
-  // ASTContext::getTypeSize will return the size rounded up to a
-  // power of 2, so instead of using that, we need to use the raw
-  // element size multiplied by the element count.
-  uint64_t srcEltSize = Context.getTypeSize(srcEltTy);
-  uint64_t destEltSize = Context.getTypeSize(destEltTy);
-
-  return (srcLen * srcEltSize == destLen * destEltSize);
+  return areVectorTypesSameSize(srcTy, destTy);
 }
 
 /// Is this a legal conversion between two types, one of which is
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2335,6 +2335,16 @@
   return TC_Success;
 }
 
+if (Self.LangOpts.OpenCL && !CStyle) {
+  if (DestType->isExtVectorType() || SrcType->isExtVectorType()) {
+// FIXME: Allow for reinterpret cast between 3 and 4 element vectors
+if (Self.areVectorTypesSameSize(SrcType, DestType)) {
+  K

[PATCH] D95425: Implementation of global.get/set for reftypes in LLVM IR

2021-05-17 Thread Andy Wingo via Phabricator via cfe-commits
wingo added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td:15
 multiclass TABLE {
+  let mayLoad = 1 in
   defm TABLE_GET_#rt : I<(outs rt:$res), (ins table32_op:$table),

pmatos wrote:
> tlively wrote:
> > wingo wrote:
> > > I think you may need `hasSideEffects = 0` for these annotations to have 
> > > an effect.
> > I would be surprised if this were true!
> Why would this be the case? If I remember correctly, I added `mayLoad` and 
> `mayStore` here so that lowering includes a chain. And this works without the 
> need for `hasSideEffects`. Unless you think this is required for other 
> reaons, but `mayLoad` works with it.
Yeah I misunderstood, I was thinking that `mayLoad` and `mayStore` were a 
subset of the side effect annotations of `hasSideEffects`, which defaults to 1 
effectively (grep for `guessInstructionProperties`).  But no, the side effects 
modelled here are the disjoint bits `mayLoad`, `mayStore`, and 
`hasSideEffects`; `mayRaiseFPException` would appear to be a subset of 
`hasSideEffects`.  Still, may best to explicitly set `hasSideEffects` to 1 for 
`table.get ` and `table.set` just as documentation that they can trap if the 
index is out-of-bounds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95425

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


[PATCH] D102614: [index] Add support for type of pointers to class members

2021-05-17 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie created this revision.
OikawaKirie added a reviewer: akyrtzi.
OikawaKirie added a project: clang.
Herald added a subscriber: arphaman.
OikawaKirie requested review of this revision.
Herald added a subscriber: cfe-commits.

Required in D102159  that we should add 
support for the unhandled items instead of workaround them.
In this patch, support is added for indexing the type of pointers to class 
members. Such usages are found in MySQL.
The format is `::*`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102614

Files:
  clang/lib/Index/USRGeneration.cpp
  clang/test/Index/USR/MemberFunctionPtr.cpp


Index: clang/test/Index/USR/MemberFunctionPtr.cpp
===
--- /dev/null
+++ clang/test/Index/USR/MemberFunctionPtr.cpp
@@ -0,0 +1,33 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+
+struct C {
+  int X;
+  void f(char);
+};
+
+void f(int C::*) {}
+// CHECK: function/C | f | c:@F@f#$@S@C::*I#
+void f(void (C::*)(char)) {}
+// CHECK: function/C | f | c:@F@f#$@S@C::*Fv(#C)#
+
+typedef int C::*Xtd;
+void ftd(Xtd) {}
+// CHECK: function/C | ftd | c:@F@ftd#$@S@C::*I#
+typedef void (C::*Ftd)(char);
+void ftd(Ftd) {}
+// CHECK: function/C | ftd | c:@F@ftd#$@S@C::*Fv(#C)#
+
+using Xus = int C::*;
+void fus(Xus) {}
+// CHECK: function/C | fus | c:@F@fus#$@S@C::*I#
+using Fus = void (C::*)(char);
+void fus(Fus) {}
+// CHECK: function/C | fus | c:@F@fus#$@S@C::*Fv(#C)#
+
+template  struct S;
+template  struct S {
+  static const bool V = true;
+  // CHECK: static-property/C++ | V | c:@SP>2#T#T@S>#t0.1::*t0.0@V
+  void f() {}
+  // CHECK: instance-method/C++ | f | c:@SP>2#T#T@S>#t0.1::*t0.0@F@f#
+};
Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -893,6 +893,12 @@
   T = AT->getElementType();
   continue;
 }
+if (const MemberPointerType *MPT = T->getAs()) {
+  VisitType(QualType(MPT->getClass(), 0));
+  Out << "::*";
+  T = MPT->getPointeeType();
+  continue;
+}
 
 // Unhandled type.
 Out << ' ';


Index: clang/test/Index/USR/MemberFunctionPtr.cpp
===
--- /dev/null
+++ clang/test/Index/USR/MemberFunctionPtr.cpp
@@ -0,0 +1,33 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+
+struct C {
+  int X;
+  void f(char);
+};
+
+void f(int C::*) {}
+// CHECK: function/C | f | c:@F@f#$@S@C::*I#
+void f(void (C::*)(char)) {}
+// CHECK: function/C | f | c:@F@f#$@S@C::*Fv(#C)#
+
+typedef int C::*Xtd;
+void ftd(Xtd) {}
+// CHECK: function/C | ftd | c:@F@ftd#$@S@C::*I#
+typedef void (C::*Ftd)(char);
+void ftd(Ftd) {}
+// CHECK: function/C | ftd | c:@F@ftd#$@S@C::*Fv(#C)#
+
+using Xus = int C::*;
+void fus(Xus) {}
+// CHECK: function/C | fus | c:@F@fus#$@S@C::*I#
+using Fus = void (C::*)(char);
+void fus(Fus) {}
+// CHECK: function/C | fus | c:@F@fus#$@S@C::*Fv(#C)#
+
+template  struct S;
+template  struct S {
+  static const bool V = true;
+  // CHECK: static-property/C++ | V | c:@SP>2#T#T@S>#t0.1::*t0.0@V
+  void f() {}
+  // CHECK: instance-method/C++ | f | c:@SP>2#T#T@S>#t0.1::*t0.0@F@f#
+};
Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -893,6 +893,12 @@
   T = AT->getElementType();
   continue;
 }
+if (const MemberPointerType *MPT = T->getAs()) {
+  VisitType(QualType(MPT->getClass(), 0));
+  Out << "::*";
+  T = MPT->getPointeeType();
+  continue;
+}
 
 // Unhandled type.
 Out << ' ';
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99439: Update @llvm.powi to handle different int sizes for the exponent

2021-05-17 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added inline comments.



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp:581
RTLIB::POWI_F128,
RTLIB::POWI_PPCF128);
   if (!TLI.getLibcallName(LC)) {

efriedma wrote:
> bjope wrote:
> > efriedma wrote:
> > > This is missing a diagnostic for the exponent.  We don't want to silently 
> > > miscompile if someone uses an exponent that isn't supported by the target.
> > Not sure exactly what you suggest. Is that a general comment for all places 
> > in SelectionDAG where we may emit calls to RTLIB::POWI or what makes this 
> > SoftenFloatRes special?
> > 
> > If we end up using mismatching types in the call, wouldn't that being 
> > detected as ICE elsewhere? Only reason I made changes to this function in 
> > the first place was due to the historical assert above regarding the type 
> > of the exponent in FPOWI. Maybe I should just drop that assert instead? 
> > This is the only place where that is checked, but I figure that the 
> > SoftenFloatRes legalization is just one out of many places where FPOWI is 
> > legalized and lowered into libcalls to RTLIB::POWI.
> It's a general issue with emitting calls to RTLIB::POWI; the second parameter 
> to the call has to have type "int", to match the definition in 
> libgcc/compiler-rt.  I guess there are a few other places that also emit 
> calls to these functions.
> 
> > If we end up using mismatching types in the call, wouldn't that being 
> > detected as ICE elsewhere?
> 
> In SelectionDAG, function/pointer types don't exist; the callee of a function 
> call is just a integer.  So we'd never detect mismatched types; we'd just 
> silently emit a call using the wrong calling convention.
One interesting thing when trying to add checks verifying that 
`DAG.getLibInfo().getIntSize() == Node->getOperand(1 + 
Offset).getValueType().getSizeInBits())` in LegalizeDAG some RISCV (64-bit) 
test cases fail. Looks like type legalization is promoting the exponent by 
replacing

```
  t5: i64,ch = CopyFromReg t0, Register:i64 %1
t6: i32 = truncate t5
  t7: f32 = fpowi t3, t6

```
by

```
  t5: i64,ch = CopyFromReg t0, Register:i64 %1
t13: i64 = sign_extend_inreg t5, ValueType:ch:i32
  t7: f32 = fpowi t3, t13
```
I kind of suspect that promoting the exponent for FPOWI always would be 
incorrect, if the idea is that the type always should match with sizeof(int).

In this case RISCV would lower the fpowi to a libcall like this

```
  t5: i64,ch = CopyFromReg t0, Register:i64 %1
t13: i64 = sign_extend_inreg t5, ValueType:ch:i32
  t20: ch,glue = CopyToReg t18, Register:i64 $x11, t13, t18:1
  t23: ch,glue = RISCVISD::CALL t20, TargetExternalSymbol:i64'__powisf2' 
[TF=2], Register:i64 $x10, Register:i64 $x11, RegisterMask:Untyped, t20:1
```
using a 64-bit argument for the call, while the callee expects a 32-bit int. 
Depending on the calling conventions for RISCV64 I suppose this might work by 
coincidence, or it is a bad miscompile.

Not sure exactly how to deal with that when considering this patch. I was kind 
of aiming at fixing problems for 16-bit targets. Maybe we need to deal with 
DAGTypeLegalizer::PromoteIntOp_FPOWI first, turning it into a fault situation. 
And to do that one need to handle FPOWI for RISCV in some sort of way to make 
the 32-bit exponent legal first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99439

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


[clang] 05de4b4 - Put back the trailing commas on TYPED_TEST_SUITE

2021-05-17 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2021-05-17T14:14:13+02:00
New Revision: 05de4b413930418b60c0dd1e72681b476b50e7fb

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

LOG: Put back the trailing commas on TYPED_TEST_SUITE

This avoids a -pedantic warning:
warning: ISO C++11 requires at least one argument for the "..." in a variadic 
macro

See also https://github.com/google/googletest/issues/2271

Added: 


Modified: 
clang/unittests/StaticAnalyzer/RangeSetTest.cpp
flang/unittests/RuntimeGTest/CharacterTest.cpp
llvm/unittests/ADT/BitVectorTest.cpp
llvm/unittests/ADT/DenseMapTest.cpp
llvm/unittests/ADT/DenseSetTest.cpp
llvm/unittests/ADT/IListBaseTest.cpp
llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
llvm/unittests/ADT/MapVectorTest.cpp
llvm/unittests/ADT/PriorityWorklistTest.cpp
llvm/unittests/ADT/RangeAdapterTest.cpp
llvm/unittests/ADT/STLForwardCompatTest.cpp
llvm/unittests/ADT/SmallVectorTest.cpp
llvm/unittests/ADT/TinyPtrVectorTest.cpp
llvm/unittests/IR/PatternMatch.cpp
llvm/unittests/IR/ValueMapTest.cpp
llvm/unittests/Support/MathExtrasTest.cpp
llvm/unittests/XRay/FDRProducerConsumerTest.cpp
llvm/unittests/XRay/FDRRecordPrinterTest.cpp
llvm/unittests/XRay/GraphTest.cpp

Removed: 




diff  --git a/clang/unittests/StaticAnalyzer/RangeSetTest.cpp 
b/clang/unittests/StaticAnalyzer/RangeSetTest.cpp
index c29a5eef00e16..6d9d70277d9d3 100644
--- a/clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ b/clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -188,7 +188,7 @@ llvm::APSInt RangeSetTest::Base{sizeof(BaseType) 
* 8, !isSigned()};
 
 using IntTypes = ::testing::Types;
-TYPED_TEST_SUITE(RangeSetTest, IntTypes);
+TYPED_TEST_SUITE(RangeSetTest, IntTypes, );
 
 TYPED_TEST(RangeSetTest, RangeSetNegateTest) {
   // Use next values of the range {MIN, A, B, MID, C, D, MAX}.

diff  --git a/flang/unittests/RuntimeGTest/CharacterTest.cpp 
b/flang/unittests/RuntimeGTest/CharacterTest.cpp
index ff43e99ae61c5..536855306575e 100644
--- a/flang/unittests/RuntimeGTest/CharacterTest.cpp
+++ b/flang/unittests/RuntimeGTest/CharacterTest.cpp
@@ -111,7 +111,7 @@ struct CharacterComparisonTests : public ::testing::Test {
 };
 
 using CharacterTypes = ::testing::Types;
-TYPED_TEST_SUITE(CharacterComparisonTests, CharacterTypes);
+TYPED_TEST_SUITE(CharacterComparisonTests, CharacterTypes, );
 
 TYPED_TEST(CharacterComparisonTests, CompareCharacters) {
   for (auto &[x, y, xBytes, yBytes, expect] : this->parameters) {
@@ -204,7 +204,7 @@ void RunExtremumTests(const char *which,
 }
 
 template  struct ExtremumTests : public ::testing::Test {};
-TYPED_TEST_SUITE(ExtremumTests, CharacterTypes);
+TYPED_TEST_SUITE(ExtremumTests, CharacterTypes, );
 
 TYPED_TEST(ExtremumTests, MinTests) {
   static std::vector tests{
@@ -284,7 +284,7 @@ void RunSearchTests(const char *which,
 }
 
 template  struct SearchTests : public ::testing::Test {};
-TYPED_TEST_SUITE(SearchTests, CharacterTypes);
+TYPED_TEST_SUITE(SearchTests, CharacterTypes, );
 
 TYPED_TEST(SearchTests, IndexTests) {
   static SearchFunctions functions{

diff  --git a/llvm/unittests/ADT/BitVectorTest.cpp 
b/llvm/unittests/ADT/BitVectorTest.cpp
index 858adb36f22e4..7ab4ab9a9d06e 100644
--- a/llvm/unittests/ADT/BitVectorTest.cpp
+++ b/llvm/unittests/ADT/BitVectorTest.cpp
@@ -21,7 +21,7 @@ class BitVectorTest : public ::testing::Test { };
 
 // Test both BitVector and SmallBitVector with the same suite of tests.
 typedef ::testing::Types BitVectorTestTypes;
-TYPED_TEST_SUITE(BitVectorTest, BitVectorTestTypes);
+TYPED_TEST_SUITE(BitVectorTest, BitVectorTestTypes, );
 
 TYPED_TEST(BitVectorTest, TrivialOperation) {
   TypeParam Vec;

diff  --git a/llvm/unittests/ADT/DenseMapTest.cpp 
b/llvm/unittests/ADT/DenseMapTest.cpp
index e9fe4cb8d5cd2..58eac978157ec 100644
--- a/llvm/unittests/ADT/DenseMapTest.cpp
+++ b/llvm/unittests/ADT/DenseMapTest.cpp
@@ -105,7 +105,7 @@ typedef ::testing::Types,
  SmallDenseMap
  > DenseMapTestTypes;
-TYPED_TEST_SUITE(DenseMapTest, DenseMapTestTypes);
+TYPED_TEST_SUITE(DenseMapTest, DenseMapTestTypes, );
 
 // Empty map tests
 TYPED_TEST(DenseMapTest, EmptyIntMapTest) {

diff  --git a/llvm/unittests/ADT/DenseSetTest.cpp 
b/llvm/unittests/ADT/DenseSetTest.cpp
index 1320e283c59aa..82ac1d8bff0f2 100644
--- a/llvm/unittests/ADT/DenseSetTest.cpp
+++ b/llvm/unittests/ADT/DenseSetTest.cpp
@@ -68,7 +68,7 @@ typedef ::testing::Types,
  const SmallDenseSet,
  SmallDenseSet>
 DenseSetTestTypes;
-TYPED_TEST_SUITE(DenseSetTest, DenseSetTestTypes);
+TYPED_TEST_SUITE(DenseSetTest, DenseSetTestTypes, );
 
 TYPED_TEST(DenseSetTest, Constructor) {
   constexpr unsigned a[] = {1, 2, 

[PATCH] D102569: [clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type

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

LGTM, thank you for the fix!


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

https://reviews.llvm.org/D102569

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


[PATCH] D102443: [PowerPC] Added multiple PowerPC builtins

2021-05-17 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added subscribers: rjmccall, rsmith.
nemanjai added a comment.

In terms of the motivation for this, the description of the patch should 
include something along the lines of:

"This is the first in a series of patches to provide builtins for compatibility 
with the XL compiler."

Since these builtins don't really conform to the typical naming in clang (i.e. 
using the `__builtin` prefix), perhaps @rjmccall or @rsmith have a suggestion 
as to how we should proceed here.
If the names with two underscores are acceptable, great (there won't be any 
name clashes with existing builtins).
However if those names are not acceptable, we might be able to implement some 
sort of compatibility layer in Clang where the names are intercepted if 
compiling for a PPC target and handled in `CGBuiltin.cpp`.




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:28
 
+BUILTIN(__popcntb, "ULiULi", "")
+BUILTIN(__eieio, "v", "")

qiucf wrote:
> On PPC we have `__builtin_popcount`, but I only saw `popcntw` and `popcntd` 
> generated. (I didn't verify it carefully)
There isn't really a good candidate builtin for this since this does a popcount 
in each byte separately. Of course, it could be used for a popcount of `i8`, 
but that is just a subset of what the builtin/instruction do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102443

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


[clang] 888ce70 - [DebugInfo] Fix DWARF expressions for __block vars that are not on the heap

2021-05-17 Thread Raphael Isemann via cfe-commits

Author: Raphael Isemann
Date: 2021-05-17T14:32:07+02:00
New Revision: 888ce70af288168136cf1ca658c3cf6d6759bb3f

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

LOG: [DebugInfo] Fix DWARF expressions for __block vars that are not on the heap

`__block` variables used to be always stored on the head instead of stack.
D51564 allowed `__block` variables to the stored on the stack like normal
variablesif they not captured by any escaping block, but the debug-info
generation code wasn't made aware of it so we still unconditionally emit DWARF
expressions pointing to the heap.

This patch makes CGDebugInfo use the `EscapingByref` introduced in D51564 that
tracks whether the `__block` variable is actually on the heap. If it's stored on
the stack instead we just use the debug info we would generate for normal
variables instead.

Reviewed By: ahatanak, aprantl

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-block-expr.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3d96bf1964e1..fefcf7a4e973 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4303,7 +4303,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
VarDecl *VD,
   auto *Scope = cast(LexicalBlockStack.back());
   StringRef Name = VD->getName();
   if (!Name.empty()) {
-if (VD->hasAttr()) {
+// __block vars are stored on the heap if they are captured by a block that
+// can escape the local scope.
+if (VD->isEscapingByref()) {
   // Here, we need an offset *into* the alloca.
   CharUnits offset = CharUnits::fromQuantity(32);
   Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);

diff  --git a/clang/test/CodeGen/debug-info-block-expr.c 
b/clang/test/CodeGen/debug-info-block-expr.c
index 009e7800b6ee..5626c5c33a4f 100644
--- a/clang/test/CodeGen/debug-info-block-expr.c
+++ b/clang/test/CodeGen/debug-info-block-expr.c
@@ -1,9 +1,55 @@
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -DDEAD_CODE -fblocks -debug-info-kind=limited -emit-llvm -o 
- %s | FileCheck %s
+
+typedef void (^BlockTy)();
+void escapeFunc(BlockTy);
+typedef void (^BlockTy)();
+void noEscapeFunc(__attribute__((noescape)) BlockTy);
+
+// Verify that the desired DIExpression are generated for escaping (i.e, not
+// 'noescape') blocks.
+void test_escape_func() {
+// CHECK-LABEL: void @test_escape_func
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[ESCAPE_VAR:[0-9]+]], 
metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  __block int escape_var;
+// Blocks in dead code branches still capture __block variables.
+#ifdef DEAD_CODE
+  if (0)
+#endif
+  escapeFunc(^{ (void)escape_var; });
+}
+
+// Verify that the desired DIExpression are generated for noescape blocks.
+void test_noescape_func() {
+// CHECK-LABEL: void @test_noescape_func
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[NOESCAPE_VAR:[0-9]+]], 
metadata !DIExpression())
+  __block int noescape_var;
+  noEscapeFunc(^{ (void)noescape_var; });
+}
+
 // Verify that the desired DIExpression are generated for blocks.
+void test_local_block() {
+// CHECK-LABEL: void @test_local_block
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[BLOCK_VAR:[0-9]+]], 
metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  __block int block_var;
 
-void test() {
-// CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_plus_uconst, 
{{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
-  __block int i;
+// CHECK-LABEL: @__test_local_block_block_invoke
 // CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, 
DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
-  ^ { i = 1; }();
+  ^ { block_var = 1; }();
+}
+
+// Verify that the desired DIExpression are generated for __block vars not used
+// in any block.
+void test_unused() {
+// CHECK-LABEL: void @test_unused
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[UNUSED_VAR:[0-9]+]], 
metadata !DIExpression())
+  __block int unused_var;
+// Use i (not inside a block).
+  ++unused_var;
 }
+
+// CHECK: ![[ESCAPE_VAR]] = !DILocalVariable(name: "escape_var"
+// CHECK: ![[NOESCAPE_VAR]] = !DILocalVariable(name: "noescape_var"
+// CHECK: ![[BLOCK_VAR]] = !DILocalVariable(name: "block_var"
+// CHECK: ![[UNUSED_VAR]] = !DILocalVariable(name: "unused_var"
+



___
cfe-commits mailing list
cfe-commits@lists.llvm.or

[PATCH] D99946: [DebugInfo] Fix DWARF expressions for __block vars that are not on the heap

2021-05-17 Thread Raphael Isemann 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 rG888ce70af288: [DebugInfo] Fix DWARF expressions for __block 
vars that are not on the heap (authored by teemperor).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99946

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-block-expr.c


Index: clang/test/CodeGen/debug-info-block-expr.c
===
--- clang/test/CodeGen/debug-info-block-expr.c
+++ clang/test/CodeGen/debug-info-block-expr.c
@@ -1,9 +1,55 @@
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -DDEAD_CODE -fblocks -debug-info-kind=limited -emit-llvm -o 
- %s | FileCheck %s
+
+typedef void (^BlockTy)();
+void escapeFunc(BlockTy);
+typedef void (^BlockTy)();
+void noEscapeFunc(__attribute__((noescape)) BlockTy);
+
+// Verify that the desired DIExpression are generated for escaping (i.e, not
+// 'noescape') blocks.
+void test_escape_func() {
+// CHECK-LABEL: void @test_escape_func
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[ESCAPE_VAR:[0-9]+]], 
metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  __block int escape_var;
+// Blocks in dead code branches still capture __block variables.
+#ifdef DEAD_CODE
+  if (0)
+#endif
+  escapeFunc(^{ (void)escape_var; });
+}
+
+// Verify that the desired DIExpression are generated for noescape blocks.
+void test_noescape_func() {
+// CHECK-LABEL: void @test_noescape_func
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[NOESCAPE_VAR:[0-9]+]], 
metadata !DIExpression())
+  __block int noescape_var;
+  noEscapeFunc(^{ (void)noescape_var; });
+}
+
 // Verify that the desired DIExpression are generated for blocks.
+void test_local_block() {
+// CHECK-LABEL: void @test_local_block
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[BLOCK_VAR:[0-9]+]], 
metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  __block int block_var;
 
-void test() {
-// CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_plus_uconst, 
{{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
-  __block int i;
+// CHECK-LABEL: @__test_local_block_block_invoke
 // CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, 
DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
-  ^ { i = 1; }();
+  ^ { block_var = 1; }();
+}
+
+// Verify that the desired DIExpression are generated for __block vars not used
+// in any block.
+void test_unused() {
+// CHECK-LABEL: void @test_unused
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[UNUSED_VAR:[0-9]+]], 
metadata !DIExpression())
+  __block int unused_var;
+// Use i (not inside a block).
+  ++unused_var;
 }
+
+// CHECK: ![[ESCAPE_VAR]] = !DILocalVariable(name: "escape_var"
+// CHECK: ![[NOESCAPE_VAR]] = !DILocalVariable(name: "noescape_var"
+// CHECK: ![[BLOCK_VAR]] = !DILocalVariable(name: "block_var"
+// CHECK: ![[UNUSED_VAR]] = !DILocalVariable(name: "unused_var"
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4303,7 +4303,9 @@
   auto *Scope = cast(LexicalBlockStack.back());
   StringRef Name = VD->getName();
   if (!Name.empty()) {
-if (VD->hasAttr()) {
+// __block vars are stored on the heap if they are captured by a block that
+// can escape the local scope.
+if (VD->isEscapingByref()) {
   // Here, we need an offset *into* the alloca.
   CharUnits offset = CharUnits::fromQuantity(32);
   Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);


Index: clang/test/CodeGen/debug-info-block-expr.c
===
--- clang/test/CodeGen/debug-info-block-expr.c
+++ clang/test/CodeGen/debug-info-block-expr.c
@@ -1,9 +1,55 @@
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DDEAD_CODE -fblocks -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+
+typedef void (^BlockTy)();
+void escapeFunc(BlockTy);
+typedef void (^BlockTy)();
+void noEscapeFunc(__attribute__((noescape)) BlockTy);
+
+// Verify that the desired DIExpression are generated for escaping (i.e, not
+// 'noescape') blocks.
+void test_escape_func() {
+// CHECK-LABEL: void @test_escape_func
+// CHECK: call void @llvm.dbg.declare({{.*}}metadata ![[ESCAPE_VAR:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  __block int escape_var;
+// Blocks in dead code

[PATCH] D102397: [AArch64] Lower bitreverse in ISel

2021-05-17 Thread Irina Dobrescu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50511df32edf: [AArch64] Lower bitreverse in ISel (authored 
by Rin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102397

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-misc.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/arm64-vbitwise.ll
  llvm/test/CodeGen/AArch64/bitreverse.ll
  llvm/test/CodeGen/AArch64/neon_rbit.ll

Index: llvm/test/CodeGen/AArch64/neon_rbit.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/neon_rbit.ll
@@ -0,0 +1,121 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-eabi -mattr=+fullfp16 %s -o - | FileCheck %s
+
+; The llvm.aarch64_neon_rbit intrinsic should be auto-upgraded to the
+; target-independent bitreverse intrinsic.
+
+declare <8 x i8> @llvm.aarch64.neon.rbit.v8i8(<8 x i8>) nounwind readnone
+
+define <8 x i8> @rbit_8x8(<8 x i8> %A) nounwind {
+; CHECK-LABEL: rbit_8x8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rbit v0.8b, v0.8b
+; CHECK-NEXT:ret
+%tmp3 = call <8 x i8> @llvm.aarch64.neon.rbit.v8i8(<8 x i8> %A)
+	ret <8 x i8> %tmp3
+}
+
+declare <16 x i8> @llvm.aarch64.neon.rbit.v16i8(<16 x i8>) nounwind readnone
+
+define <16 x i8> @rbit_16x8(<16 x i8> %A) nounwind {
+; CHECK-LABEL: rbit_16x8:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rbit v0.16b, v0.16b
+; CHECK-NEXT:ret
+%tmp3 = call <16 x i8> @llvm.aarch64.neon.rbit.v16i8(<16 x i8> %A)
+	ret <16 x i8> %tmp3
+}
+
+declare <4 x i16> @llvm.aarch64.neon.rbit.v4i16(<4 x i16>) nounwind readnone
+
+define <4 x i16> @rbit_4x16(<4 x i16> %A) nounwind {
+; CHECK-LABEL: rbit_4x16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rev16 v0.8b, v0.8b
+; CHECK-NEXT:rbit v0.8b, v0.8b
+; CHECK-NEXT:ret
+%tmp3 = call <4 x i16> @llvm.aarch64.neon.rbit.v4i16(<4 x i16> %A)
+	ret <4 x i16> %tmp3
+}
+
+declare <8 x i16> @llvm.aarch64.neon.rbit.v8i16(<8 x i16>) nounwind readnone
+
+define <8 x i16> @rbit_8x16(<8 x i16> %A) {
+; CHECK-LABEL: rbit_8x16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rev16 v0.16b, v0.16b
+; CHECK-NEXT:rbit v0.16b, v0.16b
+; CHECK-NEXT:ret
+  %tmp3 = call <8 x i16> @llvm.aarch64.neon.rbit.v8i16(<8 x i16> %A)
+  ret <8 x i16> %tmp3
+}
+
+declare <2 x i32> @llvm.aarch64.neon.rbit.v2i32(<2 x i32>) nounwind readnone
+
+define <2 x i32> @rbit_2x32(<2 x i32> %A) {
+; CHECK-LABEL: rbit_2x32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:// kill: def $d0 killed $d0 def $q0
+; CHECK-NEXT:fmov w8, s0
+; CHECK-NEXT:rbit w8, w8
+; CHECK-NEXT:mov w9, v0.s[1]
+; CHECK-NEXT:fmov s0, w8
+; CHECK-NEXT:rbit w8, w9
+; CHECK-NEXT:mov v0.s[1], w8
+; CHECK-NEXT:// kill: def $d0 killed $d0 killed $q0
+; CHECK-NEXT:ret
+  %tmp3 = call <2 x i32> @llvm.aarch64.neon.rbit.v2i32(<2 x i32> %A)
+  ret <2 x i32> %tmp3
+}
+
+declare <4 x i32> @llvm.aarch64.neon.rbit.v4i32(<4 x i32>) nounwind readnone
+
+define <4 x i32> @rbit_4x32(<4 x i32> %A) {
+; CHECK-LABEL: rbit_4x32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmov w10, s0
+; CHECK-NEXT:mov w8, v0.s[1]
+; CHECK-NEXT:rbit w10, w10
+; CHECK-NEXT:mov w9, v0.s[2]
+; CHECK-NEXT:mov w11, v0.s[3]
+; CHECK-NEXT:fmov s0, w10
+; CHECK-NEXT:rbit w8, w8
+; CHECK-NEXT:rbit w9, w9
+; CHECK-NEXT:mov v0.s[1], w8
+; CHECK-NEXT:mov v0.s[2], w9
+; CHECK-NEXT:rbit w8, w11
+; CHECK-NEXT:mov v0.s[3], w8
+; CHECK-NEXT:ret
+  %tmp3 = call <4 x i32> @llvm.aarch64.neon.rbit.v4i32(<4 x i32> %A)
+  ret <4 x i32> %tmp3
+}
+
+declare <1 x i64> @llvm.aarch64.neon.rbit.v1i64(<1 x i64>) readnone
+
+define <1 x i64> @rbit_1x64(<1 x i64> %A) {
+; CHECK-LABEL: rbit_1x64:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:// kill: def $d0 killed $d0 def $q0
+; CHECK-NEXT:fmov x8, d0
+; CHECK-NEXT:rbit x8, x8
+; CHECK-NEXT:fmov d0, x8
+; CHECK-NEXT:ret
+  %tmp3 = call <1 x i64> @llvm.aarch64.neon.rbit.v1i64(<1 x i64> %A)
+  ret <1 x i64> %tmp3
+}
+
+declare <2 x i64> @llvm.aarch64.neon.rbit.v2i64(<2 x i64>) readnone
+
+define <2 x i64> @rbit_2x64(<2 x i64> %A) {
+; CHECK-LABEL: rbit_2x64:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:fmov x8, d0
+; CHECK-NEXT:rbit x8, x8
+; CHECK-NEXT:mov x9, v0.d[1]
+; CHECK-NEXT:fmov d0, x8
+; CHECK-NEXT:rbit x8, x9
+; CHECK-NEXT:mov v0.d[1], x8
+; CHECK-NEXT:ret
+  %tmp3 = call <2 x i64> @llvm.aarch64.neon.rbit.v2i64(<2 x i64> %A)
+  ret <2 x i64> %tmp3
+}
Index: llvm/test/CodeGen/AArch64/bitreverse.ll
===
--- llvm/test/CodeGen/AArch64/bitreverse.ll
+++ llvm/test/CodeGen/AArch64/bitreverse.ll
@@ -1,3 +1,4 @@
+; NOT

[clang] 50511df - [AArch64] Lower bitreverse in ISel

2021-05-17 Thread Irina Dobrescu via cfe-commits

Author: Irina Dobrescu
Date: 2021-05-17T13:35:27+01:00
New Revision: 50511df32edf53238b75b0e9767120dc772dbf14

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

LOG: [AArch64] Lower bitreverse in ISel

Adding lowering support for bitreverse.

Previously, lowering bitreverse would expand it into a series of other 
instructions. This patch makes it so this produces a single rbit instruction 
instead.

Reviewed By: dmgreen

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

Added: 
llvm/test/CodeGen/AArch64/neon_rbit.ll

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-misc.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/test/CodeGen/AArch64/arm64-vbitwise.ll
llvm/test/CodeGen/AArch64/bitreverse.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 147b4c90d8d3..9fdf1df9734e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10879,7 +10879,7 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
   }
   case NEON::BI__builtin_neon_vrbit_v:
   case NEON::BI__builtin_neon_vrbitq_v: {
-Int = Intrinsic::aarch64_neon_rbit;
+Int = Intrinsic::bitreverse;
 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrbit");
   }
   case NEON::BI__builtin_neon_vaddv_u8:

diff  --git a/clang/test/CodeGen/aarch64-neon-misc.c 
b/clang/test/CodeGen/aarch64-neon-misc.c
index ed9af88b56c1..c185eb7af2e2 100644
--- a/clang/test/CodeGen/aarch64-neon-misc.c
+++ b/clang/test/CodeGen/aarch64-neon-misc.c
@@ -1766,42 +1766,42 @@ poly8x16_t test_vmvnq_p8(poly8x16_t a) {
 }
 
 // CHECK-LABEL: @test_vrbit_s8(
-// CHECK:   [[VRBIT_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.rbit.v8i8(<8 x 
i8> %a)
+// CHECK:   [[VRBIT_I:%.*]] = call <8 x i8> @llvm.bitreverse.v8i8(<8 x i8> %a)
 // CHECK:   ret <8 x i8> [[VRBIT_I]]
 int8x8_t test_vrbit_s8(int8x8_t a) {
   return vrbit_s8(a);
 }
 
 // CHECK-LABEL: @test_vrbitq_s8(
-// CHECK:   [[VRBIT_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.rbit.v16i8(<16 
x i8> %a)
+// CHECK:   [[VRBIT_I:%.*]] = call <16 x i8> @llvm.bitreverse.v16i8(<16 x i8> 
%a)
 // CHECK:   ret <16 x i8> [[VRBIT_I]]
 int8x16_t test_vrbitq_s8(int8x16_t a) {
   return vrbitq_s8(a);
 }
 
 // CHECK-LABEL: @test_vrbit_u8(
-// CHECK:   [[VRBIT_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.rbit.v8i8(<8 x 
i8> %a)
+// CHECK:   [[VRBIT_I:%.*]] = call <8 x i8> @llvm.bitreverse.v8i8(<8 x i8> %a)
 // CHECK:   ret <8 x i8> [[VRBIT_I]]
 uint8x8_t test_vrbit_u8(uint8x8_t a) {
   return vrbit_u8(a);
 }
 
 // CHECK-LABEL: @test_vrbitq_u8(
-// CHECK:   [[VRBIT_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.rbit.v16i8(<16 
x i8> %a)
+// CHECK:   [[VRBIT_I:%.*]] = call <16 x i8> @llvm.bitreverse.v16i8(<16 x i8> 
%a)
 // CHECK:   ret <16 x i8> [[VRBIT_I]]
 uint8x16_t test_vrbitq_u8(uint8x16_t a) {
   return vrbitq_u8(a);
 }
 
 // CHECK-LABEL: @test_vrbit_p8(
-// CHECK:   [[VRBIT_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.rbit.v8i8(<8 x 
i8> %a)
+// CHECK:   [[VRBIT_I:%.*]] = call <8 x i8> @llvm.bitreverse.v8i8(<8 x i8> %a)
 // CHECK:   ret <8 x i8> [[VRBIT_I]]
 poly8x8_t test_vrbit_p8(poly8x8_t a) {
   return vrbit_p8(a);
 }
 
 // CHECK-LABEL: @test_vrbitq_p8(
-// CHECK:   [[VRBIT_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.rbit.v16i8(<16 
x i8> %a)
+// CHECK:   [[VRBIT_I:%.*]] = call <16 x i8> @llvm.bitreverse.v16i8(<16 x i8> 
%a)
 // CHECK:   ret <16 x i8> [[VRBIT_I]]
 poly8x16_t test_vrbitq_p8(poly8x16_t a) {
   return vrbitq_p8(a);

diff  --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index 91b3c8fe2114..2815664a562e 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -444,9 +444,6 @@ let TargetPrefix = "aarch64", IntrProperties = [IntrNoMem] 
in {
   def int_aarch64_neon_ursqrte : AdvSIMD_1VectorArg_Intrinsic;
   def int_aarch64_neon_frsqrte : AdvSIMD_1FloatArg_Intrinsic;
 
-  // Vector Bitwise Reverse
-  def int_aarch64_neon_rbit : AdvSIMD_1VectorArg_Intrinsic;
-
   // Vector Conversions Between Half-Precision and Single-Precision.
   def int_aarch64_neon_vcvtfp2hf
 : DefaultAttrsIntrinsic<[llvm_v4i16_ty], [llvm_v4f32_ty], [IntrNoMem]>;

diff  --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 9a33645d017b..9e8683095b52 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -553,6 +553,11 @@ static bool UpgradeIntrinsicFunction1(Function *F, 
Function *&NewFn) {
 F->arg_begin()->getType());
   return true;
 }
+if (Name.startswith("aarch64.neon.

[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-17 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 345846.
azabaznov edited the summary of this revision.
azabaznov added a comment.

Rebase after https://reviews.llvm.org/D100976; addressed review comments and 
updated docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96524

Files:
  clang/docs/OpenCLSupport.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenOpenCL/printf.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/extensions.cl
  clang/test/SemaOpenCL/fp64-fp16-options.cl

Index: clang/test/SemaOpenCL/fp64-fp16-options.cl
===
--- clang/test/SemaOpenCL/fp64-fp16-options.cl
+++ clang/test/SemaOpenCL/fp64-fp16-options.cl
@@ -5,6 +5,7 @@
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
 
 // Test with some extensions enabled or disabled by cmd-line args
 //
@@ -16,12 +17,18 @@
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 //
 // Concatenating
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64
 
 // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h
 // disables all extensions by default, but supported core extensions for a
@@ -85,18 +92,30 @@
 void f2(void) {
   double d;
 #ifdef NOFP64
-// expected-error@-2{{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-3{{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-5{{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   typedef double double4 __attribute__((ext_vector_type(4)));
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
-// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-error@-4 {{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}}
+#else
+// expected-error@-6 {{use of type 'double' requires cl_khr_fp64 support}}
+#endif
 #endif
 
   (void) 1.0;
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300)
+// expected-warning@-3{{double precision constant requires cl_khr_fp64 and __opencl_c_fp64, casting to single precision}}
+#else
+// expected-warning@-5{{double precision constant requires cl_khr_fp64, casting to single precision}}
+#endif
 #endif
 }
 
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl

[PATCH] D102248: [C++4OpenCL] Fix initialization of __constant constructors without arguments

2021-05-17 Thread Ole Strohm via Phabricator via cfe-commits
olestrohm updated this revision to Diff 345845.
olestrohm added a comment.

Relaxed the checks in the codegen test because of failures on platforms with 
slightly different IR being generated.


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

https://reviews.llvm.org/D102248

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===
--- /dev/null
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
+
+__constant int g1; // expected-error {{variable in constant address space must be initialized}}
+__constant int g2 = 0;
+
+struct X {
+  int x;
+  constexpr X() __constant : x(0) {}
+  constexpr X(int x) __constant : x(x) {}
+};
+
+//expected-note@+2{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const __generic Y' for 1st argument}}
+//expected-note@+1{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to '__generic Y' for 1st argument}}
+struct Y {
+  int y;
+  Y() __generic = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
+};
+
+kernel void k() {
+  __constant X cx1;
+  __constant X cx2(1);
+  __local X lx;
+
+  __private Y py;
+  __constant Y cy1; // expected-error{{variable in constant address space must be initialized}}
+  __constant Y cy2(1); // expected-error{{no matching constructor for initialization of '__constant Y'}}
+}
+
+struct Z {
+  int z;
+  // The address space is deduced to be __generic if omitted
+  Z() = default; // expected-note{{previous definition is here}}
+  Z() __generic = default; // expected-error {{constructor cannot be redeclared}}
+
+  Z() __private = default;
+  Z() __local = default;
+  Z() __global = default;
+  // Can't default constexpr constructors
+  constexpr Z() __constant : z(0) {}
+};
+
+struct W {
+  int w;
+  constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor is not constexpr}}
+};
Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s
+
+// CHECK: %struct.X = type { i32 }
+
+// CHECK: @ci = dso_local addrspace(2) constant i32 0
+// CHECK: @gi = dso_local addrspace(1) global i32 0
+__constant int ci = 0;
+__global int gi = 0;
+
+struct X {
+  int x;
+
+  // Local variables are handled in local_addrspace_init.clcpp
+  // FIXME: __private and __generic constructors clash for __private variable
+  // X() /*__generic*/ = default;
+  X() __private : x(0) {}
+  X() __global : x(0) {}
+  constexpr X() __constant : x(0) {}
+  constexpr X(int x) __constant : x(x) {}
+};
+
+// CHECK: @cx1 = dso_local addrspace(2) constant %struct.X zeroinitializer
+// CHECK: @cx2 = dso_local addrspace(2) constant %struct.X { i32 1 }
+// CHECK: @gx = dso_local addrspace(1) global %struct.X zeroinitializer
+__constant X cx1;
+__constant X cx2(1);
+__global X gx;
+
+// CHECK: @_ZZ1kE3cx1 = internal addrspace(2) constant %struct.X zeroinitializer
+// CHECK: @_ZZ1kE3cx2 = internal addrspace(2) constant %struct.X { i32 1 }
+
+kernel void k() {
+  // Check that the constructor for px is executed
+  // CHECK: %px = alloca %struct.X
+  // CHECK-NEXT: call spir_func void @_ZN1XC1Ev(%struct.X* {{.*}}%px)
+  __private X px;
+
+  __constant X cx1;
+  __constant X cx2(1);
+  // CHECK-NEXT: ret void
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12638,9 +12638,21 @@
 if (!Var->isInvalidDecl() &&
 Var->getType().getAddressSpace() == LangAS::opencl_constant &&
 Var->getStorageClass() != SC_Extern && !Var->getInit()) {
-  Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
-  Var->setInvalidDecl();
-  return;
+  bool HasConstExprDefaultConstructor = false;
+  if (CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
+for (auto *Ctor : RD->ctors()) {
+  if (Ctor->isConstexpr() && Ctor->getNumParams() == 0 &&
+  Ctor->getMethodQualifiers().getAddressSpace() ==
+  LangAS::opencl_constant) {
+HasConstExprDefaultConstructor = true;
+  }
+}
+  }
+  if (!HasConstExprDefaultConstructor) {
+Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
+Var->setInvalidDecl();
+return;
+  }
 }
 
 if (!Var->isInvalidDecl() && RealDecl->hasAttr()) {
___

[PATCH] D102241: [clang] p1099 4/5: using enum EnumTag

2021-05-17 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 345848.
urnathan added a comment.

Add serialization test and fix bug so found (thanks Bruno!)


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

https://reviews.llvm.org/D102241

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Index/IndexSymbol.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/AST/ast-dump-using-enum.cpp
  clang/test/SemaCXX/cxx20-using-enum.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -6540,6 +6540,7 @@
   }
 
   case Decl::Using:
+  case Decl::UsingEnum:
 return MakeCursorOverloadedDeclRef(cast(D), D->getLocation(),
TU);
 
Index: clang/test/SemaCXX/cxx20-using-enum.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-using-enum.cpp
@@ -0,0 +1,233 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+// p1099 'using enum ELABORATED-ENUM-SPECIFIER ;'
+
+namespace One {
+namespace Bob {
+enum A { a, // expected-note{{declared here}}
+ b,
+ c };
+class C; // expected-note{{previous use}}
+enum class D : int;
+enum class D { d,
+   e,
+   f };
+enum class D : int;
+} // namespace Bob
+
+using enum Bob::A;
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+using enum Bob::B; // expected-error{{no enum named 'B'}}
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+using enum Bob::C; // expected-error{{tag type that does not match}}
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+auto v = a;
+
+A g; // expected-error{{unknown type name 'A'}}
+
+int A;
+
+using enum Bob::D;
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+} // namespace One
+
+namespace Two {
+namespace Kevin {
+enum class B { d,
+   e,
+   f };
+}
+
+using enum Kevin::B;
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+auto w = e;
+
+} // namespace Two
+
+#if __cplusplus >= 202002
+// Now only check c++20 onwards
+
+namespace Three {
+namespace Stuart {
+enum class C : int; // expected-note{{declared here}}
+}
+
+using enum Stuart::C; // expected-error{{is incomplete}}
+} // namespace Three
+
+namespace Four {
+class Dave {
+public:
+  enum D { a,
+   b,
+   c };
+
+private:
+  enum class E { d, // expected-note{{declared private here}}
+ e,
+ f };
+};
+
+using enum Dave::D;
+using enum Dave::E; // expected-error{{is a private member}}
+
+} // namespace Four
+
+namespace Five {
+enum class A { b,
+   c };
+class Dave {
+public:
+  using enum A;
+  A f = b;
+};
+
+} // namespace Five
+
+namespace Six {
+template  class TPL;
+template <> class TPL {
+public:
+  enum A { a };
+};
+
+template  class USR {
+  using enum TPL::B; // expected-error{{cannot name a dependent type}}
+  using enum TPL::A;
+};
+} // namespace Six
+
+// Now instantiate things
+namespace Seven {
+namespace Stuart {
+enum class A { a,
+   b,
+   c };
+}
+
+static_assert(!int(Stuart::A::a));
+constexpr int Bar() {
+  using enum Stuart::A;
+  return int(b);
+}
+static_assert(Bar() == 1);
+
+template  constexpr int Foo() {
+  using enum Stuart::A;
+  return int(b) + I;
+}
+
+static_assert(Foo<10>() == 11);
+
+template  struct C {
+  using enum Stuart::A;
+  static constexpr int V = int(c) + I;
+
+  enum class D { d,
+ e,
+ f };
+  using enum D;
+

[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Mostly just superficial comments from me at this point.




Comment at: clang/lib/Sema/SemaTemplate.cpp:5094-5095
+bool ForLambdaCallOperator = false;
+if (CXXRecordDecl *Rec =
+dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();





Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:2865
+  CXXRecordDecl *ThisContext = nullptr;
+  if (CXXRecordDecl *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())





Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:2867
+if (Rec->isLambda())
+  if (CXXMethodDecl *Method =
+  dyn_cast(Rec->getDeclContext())) {




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102531

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


[clang] b89e09a - Silence "Undefined or garbage value returned to caller" static analysis warning. NFCI.

2021-05-17 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2021-05-17T14:08:27+01:00
New Revision: b89e09a19f9b60dfa9477b24a404a7ae5522f898

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

LOG: Silence "Undefined or garbage value returned to caller" static analysis 
warning. NFCI.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1086887a8de5..25af909d9bd2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3449,7 +3449,7 @@ class OffloadingActionBuilder final {
   return nullptr;
 
 // Let builders add host linking actions.
-Action* HA;
+Action* HA = nullptr;
 for (DeviceActionBuilder *SB : SpecializedBuilders) {
   if (!SB->isValid())
 continue;



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


[PATCH] D102488: [clang][deps] Prune unused header search paths

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 345861.
jansvoboda11 added a comment.

Use, serialize and deserialize `llvm::BitVector` instead of `std::set`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102488

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/header-search-pruning/a/a.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/b/b.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/cdb.json
  clang/test/ClangScanDeps/Inputs/header-search-pruning/mod.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/module.modulemap
  clang/test/ClangScanDeps/header-search-pruning.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -163,6 +163,11 @@
 "'-fmodule-file=', '-o', '-fmodule-map-file='."),
 llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
 
+static llvm::cl::opt OptimizeArgs(
+"optimize-args",
+llvm::cl::desc("Whether to optimize command-line arguments of modules."),
+llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
+
 llvm::cl::opt
 NumThreads("j", llvm::cl::Optional,
llvm::cl::desc("Number of worker threads to use (default: use "
@@ -357,7 +362,26 @@
 
 private:
   StringRef lookupPCMPath(ModuleID MID) {
-return Modules[IndexedModuleID{MID, 0}].ImplicitModulePCMPath;
+auto PCMPath = PCMPaths.insert({IndexedModuleID{MID, 0}, ""});
+if (PCMPath.second)
+  PCMPath.first->second = constructPCMPath(lookupModuleDeps(MID));
+return PCMPath.first->second;
+  }
+
+  /// Construct a path where to put the explicitly built PCM - essentially the
+  /// path to implicitly built PCM with the context hash replaced by the final
+  /// (potentially modified) context hash.
+  std::string constructPCMPath(const ModuleDeps &MD) const {
+const std::string &ImplicitPCMPath = MD.ImplicitModulePCMPath;
+StringRef Filename = llvm::sys::path::filename(ImplicitPCMPath);
+StringRef ImplicitContextHashPath =
+llvm::sys::path::parent_path(ImplicitPCMPath);
+StringRef ModuleCachePath =
+llvm::sys::path::parent_path(ImplicitContextHashPath);
+
+SmallString<64> ExplicitPCMPath = ModuleCachePath;
+llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
+return std::string(ExplicitPCMPath);
   }
 
   const ModuleDeps &lookupModuleDeps(ModuleID MID) {
@@ -395,6 +419,8 @@
   std::mutex Lock;
   std::unordered_map
   Modules;
+  std::unordered_map
+  PCMPaths;
   std::vector Inputs;
 };
 
@@ -554,7 +580,7 @@
   SharedStream DependencyOS(llvm::outs());
 
   DependencyScanningService Service(ScanMode, Format, ReuseFileManager,
-SkipExcludedPPRanges);
+SkipExcludedPPRanges, OptimizeArgs);
   llvm::ThreadPool Pool(llvm::hardware_concurrency(NumThreads));
   std::vector> WorkerTools;
   for (unsigned I = 0; I < Pool.getThreadCount(); ++I)
Index: clang/test/ClangScanDeps/header-search-pruning.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-pruning.cpp
@@ -0,0 +1,87 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: cp -r %S/Inputs/header-search-pruning/* %t
+// RUN: cp %S/header-search-pruning.cpp %t/header-search-pruning.cpp
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_A|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_a.json
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_B|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_b.json
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_A -DINCLUDE_B|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_ab.json
+//
+// RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -optimize-args >> %t/result_a.json
+// RUN: cat %t/result_a.json | sed 's/\\/\//g' | FileCheck --check-prefixes=CHECK_A %s
+//
+// RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -optimize-args >> %t/result_b.json
+// RUN: cat %t/result_b.json | sed 's/\\/\//g' | FileCheck --

[PATCH] D102488: [clang][deps] Prune unused header search paths

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 planned changes to this revision.
jansvoboda11 added a comment.

In D102488#2760406 , @dexonsmith 
wrote:

> I think it'd be useful to have direct tests for "detecting used search 
> paths". That might be a nice thing to separate out and test independently. 
> E.g., you could add a remark, `-Rused-search-path`, which printed a 
> diagnostic the first time any given search path is used in a TU.

Good idea, I'll look into that.

> It'd also be really nice to be able to dump this info from the `.pcm` file. I 
> guess it'd be outside the scope of this patch, but I really think there 
> should be a clang-pcm-analyzer where we can put functionality like that. 
> Somewhat useful for more fine-grained testing; super useful as a tool for 
> debugging.

Agreed, it's in my todo list.




Comment at: clang/lib/Serialization/ASTReader.cpp:4798-4806
+case USED_HEADER_SEARCH_PATHS:
+  if (F) {
+unsigned Idx = 0;
+unsigned Count = Record[Idx++];
+for (unsigned I = 0; I < Count; ++I)
+  F->UsedHeaderSearchPathIdxs.insert(Record[Idx++]);
+  }

dexonsmith wrote:
> If this were stored as a blob it could be lazily parsed; WDYT?
> 
> Alternatively, it might be more compact if stored as a bit vector, storing 
> 64-bits positions per element of the record.
I'll look into making this lazy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102488

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


[clang-tools-extra] ab92a4c - [clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type

2021-05-17 Thread Georgy Komarov via cfe-commits

Author: Georgy Komarov
Date: 2021-05-17T16:50:47+03:00
New Revision: ab92a4c26f54170bf72706ad29c0fb151a177590

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

LOG: [clang-tidy] Fix altera-struct-pack-align crash for struct fields with 
incomplete type

We can only use ASTContext::getTypeInfo for complete types.

This fixes bugzilla issue 50313.

Reviewed By: aaron.ballman

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp

Modified: 
clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp 
b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
index a2178befa9df..ef5fe41fd8c9 100644
--- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -58,9 +58,11 @@ void StructPackAlignCheck::check(const 
MatchFinder::MatchResult &Result) {
 // For each StructField, record how big it is (in bits).
 // Would be good to use a pair of  to advise a better
 // packing order.
+QualType StructFieldTy = StructField->getType();
+if (StructFieldTy->isIncompleteType())
+  return;
 unsigned int StructFieldWidth =
-(unsigned int)Result.Context
-->getTypeInfo(StructField->getType().getTypePtr())
+(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
 .Width;
 FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
 // FIXME: Recommend a reorganization of the struct (sort by StructField

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
new file mode 100644
index ..660addcbe803
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align 
%t -- -header-filter=.*
+
+struct A;
+struct B {
+  A a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' 
[clang-diagnostic-error]
+};



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


[PATCH] D102569: [clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type

2021-05-17 Thread Georgy Komarov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab92a4c26f54: [clang-tidy] Fix altera-struct-pack-align 
crash for struct fields with… (authored by jubnzv).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102569

Files:
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align 
%t -- -header-filter=.*
+
+struct A;
+struct B {
+  A a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' 
[clang-diagnostic-error]
+};
Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -58,9 +58,11 @@
 // For each StructField, record how big it is (in bits).
 // Would be good to use a pair of  to advise a better
 // packing order.
+QualType StructFieldTy = StructField->getType();
+if (StructFieldTy->isIncompleteType())
+  return;
 unsigned int StructFieldWidth =
-(unsigned int)Result.Context
-->getTypeInfo(StructField->getType().getTypePtr())
+(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
 .Width;
 FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
 // FIXME: Recommend a reorganization of the struct (sort by StructField


Index: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align %t -- -header-filter=.*
+
+struct A;
+struct B {
+  A a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' [clang-diagnostic-error]
+};
Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -58,9 +58,11 @@
 // For each StructField, record how big it is (in bits).
 // Would be good to use a pair of  to advise a better
 // packing order.
+QualType StructFieldTy = StructField->getType();
+if (StructFieldTy->isIncompleteType())
+  return;
 unsigned int StructFieldWidth =
-(unsigned int)Result.Context
-->getTypeInfo(StructField->getType().getTypePtr())
+(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
 .Width;
 FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
 // FIXME: Recommend a reorganization of the struct (sort by StructField
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101192: Add support for #elifdef and #elifndef

2021-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


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

https://reviews.llvm.org/D101192

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


[PATCH] D101192: Add support for #elifdef and #elifndef

2021-05-17 Thread Melanie Blower via Phabricator via cfe-commits
mibintc accepted this revision.
mibintc added a comment.
This revision is now accepted and ready to land.

let 'er rip


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

https://reviews.llvm.org/D101192

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


[clang] 6052a8a - [clang] In DependencyCollector on Windows, ignore case and separators when discarding duplicate dependency file paths.

2021-05-17 Thread Sylvain Audi via cfe-commits

Author: Sylvain Audi
Date: 2021-05-17T10:32:52-04:00
New Revision: 6052a8a53559d667321637f7159353ab724a1141

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

LOG: [clang] In DependencyCollector on Windows, ignore case and separators when 
discarding duplicate dependency file paths.

This patch removes duplicates also encountered in the output of clang-scan-deps 
when one same header file is encountered with different casing and/or different 
separators ('/' vs '\').

The case of separators can appear when the same file is included externally by
 `#include `

whereas a file from the same folder does
 `#include "file.h"`

Under Windows, clang computes the paths using '/' from the include directive, 
the `\` from the -I options, and the concatenations use the native `\`, leading 
to internal paths containing a mix of both separators.

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

Added: 
clang/test/Frontend/dependency-gen-windows-duplicates.c

Modified: 
clang/lib/Frontend/DependencyFile.cpp

Removed: 




diff  --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index ccc7ed9d8d49..288827374106 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -141,7 +141,18 @@ void DependencyCollector::maybeAddDependency(StringRef 
Filename,
 }
 
 bool DependencyCollector::addDependency(StringRef Filename) {
-  if (Seen.insert(Filename).second) {
+  StringRef SearchPath;
+#ifdef _WIN32
+  // Make the search insensitive to case and separators.
+  llvm::SmallString<256> TmpPath = Filename;
+  llvm::sys::path::native(TmpPath);
+  std::transform(TmpPath.begin(), TmpPath.end(), TmpPath.begin(), ::tolower);
+  SearchPath = TmpPath.str();
+#else
+  SearchPath = Filename;
+#endif
+
+  if (Seen.insert(SearchPath).second) {
 Dependencies.push_back(std::string(Filename));
 return true;
   }

diff  --git a/clang/test/Frontend/dependency-gen-windows-duplicates.c 
b/clang/test/Frontend/dependency-gen-windows-duplicates.c
new file mode 100644
index ..abd351377dc3
--- /dev/null
+++ b/clang/test/Frontend/dependency-gen-windows-duplicates.c
@@ -0,0 +1,27 @@
+// REQUIRES: system-windows
+
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/subdir
+// RUN: echo > %t.dir/subdir/x.h
+// RUN: cp %s %t.dir/test.c
+// RUN: cd %t.dir
+
+// RUN: %clang -MD -MF - %t.dir/test.c -fsyntax-only -I %t.dir/subdir | 
FileCheck %s
+// CHECK: test.o:
+// CHECK-NEXT: \test.c
+// CHECK-NEXT: \SubDir\X.h
+// File x.h must appear only once (case insensitive check).
+// CHECK-NOT: {{\\|/}}{{x|X}}.{{h|H}}
+
+// Include x.h several times, with 
diff erent casing and separators.
+// Since all paths are passed to clang as absolute, all dependencies are 
absolute paths.
+// We expect the output dependencies to contain only one line for file x.h
+
+// Test case sensitivity.
+#include "SubDir/X.h"
+#include "subdir/x.h"
+
+// Test separator sensitivity:
+// clang internally concatenates x.h using the Windows native separator.
+#include 
+



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


[PATCH] D102339: [clang] On Windows, ignore case and separators when discarding duplicate dependency file paths.

2021-05-17 Thread Sylvain Audi via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
saudi marked 2 inline comments as done.
Closed by commit rG6052a8a53559: [clang] In DependencyCollector on Windows, 
ignore case and separators when… (authored by saudi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102339

Files:
  clang/lib/Frontend/DependencyFile.cpp
  clang/test/Frontend/dependency-gen-windows-duplicates.c


Index: clang/test/Frontend/dependency-gen-windows-duplicates.c
===
--- /dev/null
+++ clang/test/Frontend/dependency-gen-windows-duplicates.c
@@ -0,0 +1,27 @@
+// REQUIRES: system-windows
+
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/subdir
+// RUN: echo > %t.dir/subdir/x.h
+// RUN: cp %s %t.dir/test.c
+// RUN: cd %t.dir
+
+// RUN: %clang -MD -MF - %t.dir/test.c -fsyntax-only -I %t.dir/subdir | 
FileCheck %s
+// CHECK: test.o:
+// CHECK-NEXT: \test.c
+// CHECK-NEXT: \SubDir\X.h
+// File x.h must appear only once (case insensitive check).
+// CHECK-NOT: {{\\|/}}{{x|X}}.{{h|H}}
+
+// Include x.h several times, with different casing and separators.
+// Since all paths are passed to clang as absolute, all dependencies are 
absolute paths.
+// We expect the output dependencies to contain only one line for file x.h
+
+// Test case sensitivity.
+#include "SubDir/X.h"
+#include "subdir/x.h"
+
+// Test separator sensitivity:
+// clang internally concatenates x.h using the Windows native separator.
+#include 
+
Index: clang/lib/Frontend/DependencyFile.cpp
===
--- clang/lib/Frontend/DependencyFile.cpp
+++ clang/lib/Frontend/DependencyFile.cpp
@@ -141,7 +141,18 @@
 }
 
 bool DependencyCollector::addDependency(StringRef Filename) {
-  if (Seen.insert(Filename).second) {
+  StringRef SearchPath;
+#ifdef _WIN32
+  // Make the search insensitive to case and separators.
+  llvm::SmallString<256> TmpPath = Filename;
+  llvm::sys::path::native(TmpPath);
+  std::transform(TmpPath.begin(), TmpPath.end(), TmpPath.begin(), ::tolower);
+  SearchPath = TmpPath.str();
+#else
+  SearchPath = Filename;
+#endif
+
+  if (Seen.insert(SearchPath).second) {
 Dependencies.push_back(std::string(Filename));
 return true;
   }


Index: clang/test/Frontend/dependency-gen-windows-duplicates.c
===
--- /dev/null
+++ clang/test/Frontend/dependency-gen-windows-duplicates.c
@@ -0,0 +1,27 @@
+// REQUIRES: system-windows
+
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/subdir
+// RUN: echo > %t.dir/subdir/x.h
+// RUN: cp %s %t.dir/test.c
+// RUN: cd %t.dir
+
+// RUN: %clang -MD -MF - %t.dir/test.c -fsyntax-only -I %t.dir/subdir | FileCheck %s
+// CHECK: test.o:
+// CHECK-NEXT: \test.c
+// CHECK-NEXT: \SubDir\X.h
+// File x.h must appear only once (case insensitive check).
+// CHECK-NOT: {{\\|/}}{{x|X}}.{{h|H}}
+
+// Include x.h several times, with different casing and separators.
+// Since all paths are passed to clang as absolute, all dependencies are absolute paths.
+// We expect the output dependencies to contain only one line for file x.h
+
+// Test case sensitivity.
+#include "SubDir/X.h"
+#include "subdir/x.h"
+
+// Test separator sensitivity:
+// clang internally concatenates x.h using the Windows native separator.
+#include 
+
Index: clang/lib/Frontend/DependencyFile.cpp
===
--- clang/lib/Frontend/DependencyFile.cpp
+++ clang/lib/Frontend/DependencyFile.cpp
@@ -141,7 +141,18 @@
 }
 
 bool DependencyCollector::addDependency(StringRef Filename) {
-  if (Seen.insert(Filename).second) {
+  StringRef SearchPath;
+#ifdef _WIN32
+  // Make the search insensitive to case and separators.
+  llvm::SmallString<256> TmpPath = Filename;
+  llvm::sys::path::native(TmpPath);
+  std::transform(TmpPath.begin(), TmpPath.end(), TmpPath.begin(), ::tolower);
+  SearchPath = TmpPath.str();
+#else
+  SearchPath = Filename;
+#endif
+
+  if (Seen.insert(SearchPath).second) {
 Dependencies.push_back(std::string(Filename));
 return true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102633: [clang-scan-deps] Improvements to thread usage

2021-05-17 Thread Sylvain Audi via Phabricator via cfe-commits
saudi created this revision.
saudi added reviewers: arphaman, dexonsmith, Bigcheese.
saudi added projects: clang, LLVM.
saudi requested review of this revision.
Herald added a subscriber: cfe-commits.

Switching back to `std::thread` to simplify the logic, as `ThreadPool` adds a 
layer of task management. However, keeping the `ThreadPoolStrategy` use, to 
benefit the `ThreadPool` improvements from https://reviews.llvm.org/D71775

This patch partly reverts https://reviews.llvm.org/D74569

Added a few optimizations:

  - Prevent from spawning more threads than there are files to process;
  - Perform computations on the main thread too, to save one thread spawn. This 
way, `clang-scan-deps -j1` will be really single-threaded, and the code path is 
the same as when LLVM threads are disabled.
- Call `reserve()` to `std::vector`s which size is known when initializing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102633

Files:
  clang/test/ClangScanDeps/Inputs/num-workers-1cmd.json
  clang/test/ClangScanDeps/Inputs/num-workers-2cmds.json
  clang/test/ClangScanDeps/num-workers.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -20,7 +20,6 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
-#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/Threading.h"
 #include 
 #include 
@@ -555,16 +554,29 @@
 
   DependencyScanningService Service(ScanMode, Format, ReuseFileManager,
 SkipExcludedPPRanges);
-  llvm::ThreadPool Pool(llvm::hardware_concurrency(NumThreads));
-  std::vector> WorkerTools;
-  for (unsigned I = 0; I < Pool.getThreadCount(); ++I)
-WorkerTools.push_back(std::make_unique(Service));
 
   std::vector Inputs;
-  for (tooling::CompileCommand Cmd :
-   AdjustingCompilations->getAllCompileCommands())
-Inputs.emplace_back(Cmd);
+  {
+auto AdjustedCommands = AdjustingCompilations->getAllCompileCommands();
+Inputs.reserve(AdjustedCommands.size());
+for (tooling::CompileCommand Cmd : AdjustedCommands)
+  Inputs.emplace_back(Cmd);
+  }
 
+  unsigned NumWorkers =
+  llvm::hardware_concurrency(NumThreads).compute_thread_count();
+
+  if (NumWorkers > Inputs.size())
+NumWorkers = static_cast(Inputs.size());
+
+  std::vector> WorkerTools;
+  WorkerTools.reserve(NumWorkers);
+  for (unsigned I = 0; I < NumWorkers; ++I)
+WorkerTools.push_back(std::make_unique(Service));
+
+  std::vector WorkerThreads;
+  if (NumWorkers > 1)
+WorkerThreads.reserve(NumWorkers - 1);
   std::atomic HadErrors(false);
   FullDeps FD;
   std::mutex Lock;
@@ -572,11 +584,11 @@
 
   if (Verbose) {
 llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
- << " files using " << Pool.getThreadCount() << " workers\n";
+ << " files using " << NumWorkers << " workers\n";
   }
-  for (unsigned I = 0; I < Pool.getThreadCount(); ++I) {
-Pool.async([I, &Lock, &Index, &Inputs, &HadErrors, &FD, &WorkerTools,
-&DependencyOS, &Errs]() {
+  for (unsigned I = 0; I < NumWorkers; ++I) {
+auto Worker = [I, &Lock, &Index, &Inputs, &HadErrors, &FD, &WorkerTools,
+   &DependencyOS, &Errs]() {
   llvm::StringSet<> AlreadySeenModules;
   while (true) {
 const SingleCommandCompilationDatabase *Input;
@@ -608,9 +620,17 @@
 HadErrors = true;
 }
   }
-});
+};
+// Leave the last worker for the main thread.
+if (I < NumWorkers - 1) {
+  assert(llvm::llvm_is_multithreaded());
+  WorkerThreads.emplace_back(std::move(Worker));
+} else {
+  Worker();
+}
   }
-  Pool.wait();
+  for (auto &W : WorkerThreads)
+W.join();
 
   if (Format == ScanningOutputFormat::Full)
 FD.printFullOutput(llvm::outs());
Index: clang/test/ClangScanDeps/num-workers.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/num-workers.cpp
@@ -0,0 +1,31 @@
+// REQUIRES: thread_support
+// RUN: rm -rf %t.dir
+// RUN: rm -f %t.*.cdb
+// RUN: mkdir -p %t.dir
+// RUN: cp %s %t.dir/file.cpp
+// RUN: cp %s %t.dir/file2.cpp
+// RUN: echo > %t.dir/header.h
+
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/num-workers-1cmd.json > %t.1cmd.cdb
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/num-workers-2cmds.json > %t.2cmds.cdb
+//
+// RUN: clang-scan-deps -compilation-database %t.1cmd.cdb -j 2 -v | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK1F1W %s
+//
+// RUN: clang-scan-deps -compilation-database %t.2cmds.cdb -j 1 -v | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK2F1W %s
+//
+// RUN: clang-scan-deps -compilation-database %t.2cmds.cdb -j 2 -v | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK2F2W %s
+

[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2021-05-17 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.
Herald added subscribers: llvm-commits, kristina.
Herald added a project: LLVM.



Comment at: llvm/trunk/lib/Support/PrettyStackTrace.cpp:93
+extern "C" const char *__crashreporter_info__
+__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");

As far as I can tell, making this a hidden symbol makes the `.desc 
___crashreporter_info__, 0x10` (ie REFERENCED_DYNAMICALLY) not have any effect:

```
% cat crashref.cc
extern "C" const char *__crashreporter_info__  
__attribute__((visibility("hidden"))) = 0;
asm(".desc ___crashreporter_info__, 0x10");
int main() {}
% clang crashref.cc
% nm -m a.out
00014000 (__DATA,__common) non-external (was a private external) 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
00013fb0 (__TEXT,__text) external _main
 (undefined) external dyld_stub_binder (from libSystem)
% strip -r a.out
% nm -m a.out
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
```

It does have an effect without it:
```
% cat crashref.cc
extern "C" const char *__crashreporter_info__ = 0;
asm(".desc ___crashreporter_info__, 0x10");
int main() {}
% clang crashref.cc
% nm -m a.out
00014000 (__DATA,__common) [referenced dynamically] external 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
00013fb0 (__TEXT,__text) external _main
 (undefined) external dyld_stub_binder (from libSystem)
% strip -r a.out
% nm -m a.out
00014000 (__DATA,__common) [referenced dynamically] external 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
```

Is that intentional? Should we just remove the `.desc` line?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D27683

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


[PATCH] D87029: [AIX] Implement AIX special bitfield related alignment rules

2021-05-17 Thread Xiangling Liao 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 rGe0921655b1ff: [AIX] Implement AIX special bitfield related 
alignment rules (authored by Xiangling_L).

Changed prior to commit:
  https://reviews.llvm.org/D87029?vs=345530&id=345898#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87029

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/aix-bitfield-alignment.c
  clang/test/Layout/aix-bitfield-alignment.cpp

Index: clang/test/Layout/aix-bitfield-alignment.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-bitfield-alignment.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK %s
+
+struct A {
+  bool b : 3;
+};
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-2 |   _Bool b
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
+
+enum class Bool : bool { False = 0,
+ True = 1 };
+
+struct B {
+  Bool b : 1;
+};
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0:0-0 |   enum Bool b
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
+
+enum LL : unsigned long long { val = 1 };
Index: clang/test/Layout/aix-bitfield-alignment.c
===
--- /dev/null
+++ clang/test/Layout/aix-bitfield-alignment.c
@@ -0,0 +1,234 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+struct A {
+  unsigned char c : 2;
+} A;
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-1 |   unsigned char c
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
+
+struct B {
+  char c;
+  int : 0;
+} B;
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
+
+struct C {
+  signed int a1 : 6;
+  signed char a2 : 4;
+  short int a3 : 2;
+  int a4 : 2;
+  signed long a5 : 5;
+  long long int a6 : 6;
+  unsigned long a7 : 8;
+} C;
+
+int c = sizeof(C);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct C
+// CHECK-NEXT:  0:0-5 |   int a1
+// CHECK-NEXT:  0:6-9 |   signed char a2
+// CHECK-NEXT:  1:2-3 |   short a3
+// CHECK-NEXT:  1:4-5 |   int a4
+// CHECK-NEXT: 1:6-10 |   long a5
+// CHECK-NEXT:  2:3-8 |   long long a6
+// CHECK32: 4:0-7 |   unsigned long a7
+// CHECK32:  sizeof=8, {{(dsize=8, )?}}align=4, preferredalign=4
+// CHECK64: 3:1-8 |   unsigned long a7
+// CHECK64:  sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
+
+#pragma align(packed)
+struct C1 {
+  signed int a1 : 6;
+  signed char a2 : 4;
+  short int a3 : 2;
+  int a4 : 2;
+  signed long a5 : 5;
+  long long int a6 : 6;
+  unsigned long a7 : 8;
+} C1;
+#pragma align(reset)
+
+int c1 = sizeof(C1);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct C1
+// CHECK-NEXT:  0:0-5 |   int a1
+// CHECK-NEXT:  0:6-9 |   signed char a2
+// CHECK-NEXT:  1:2-3 |   short a3
+// CHECK-NEXT:  1:4-5 |   int a4
+// CHECK-NEXT: 1:6-10 |   long a5
+// CHECK-NEXT:  2:3-8 |   long long a6
+// CHECK-NEXT:  3:1-8 |   unsigned long a7
+// CHECK-NEXT:   sizeof=5, {{(dsize=5, )?}}align=1, preferredalign=1
+
+#pragma pac

[clang] e092165 - [AIX] Implement AIX special bitfield related alignment rules

2021-05-17 Thread Xiangling Liao via cfe-commits

Author: Xiangling Liao
Date: 2021-05-17T11:30:29-04:00
New Revision: e0921655b1ff8d4ba7c14be59252fe05b705920e

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

LOG: [AIX] Implement AIX special bitfield related alignment rules

1.[bool, char, short] bitfields have the same alignment as unsigned int
2.Adjust alignment on typedef field decls/honor align attribute
3.Fix alignment for scoped enum class
4.Long long bitfield has 4bytes alignment and StorageUnitSize under 32 bit
  compile mode

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

Added: 
clang/test/Layout/aix-bitfield-alignment.c
clang/test/Layout/aix-bitfield-alignment.cpp

Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 8a25b5cbd84a..beb111e2e971 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1528,12 +1528,17 @@ void 
ItaniumRecordLayoutBuilder::LayoutWideBitField(uint64_t FieldSize,
   UpdateAlignment(TypeAlign);
 }
 
+static bool isAIXLayout(const ASTContext &Context) {
+  return Context.getTargetInfo().getTriple().getOS() == llvm::Triple::AIX;
+}
+
 void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
   bool FieldPacked = Packed || D->hasAttr();
   uint64_t FieldSize = D->getBitWidthValue(Context);
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
+  bool AlignIsRequired = FieldInfo.AlignIsRequired;
 
   // UnfilledBitsInLastUnit is the 
diff erence between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1611,9 +1616,33 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 }
   }
 
+  if (isAIXLayout(Context)) {
+if (StorageUnitSize < Context.getTypeSize(Context.UnsignedIntTy)) {
+  // On AIX, [bool, char, short] bitfields have the same alignment
+  // as [unsigned].
+  StorageUnitSize = Context.getTypeSize(Context.UnsignedIntTy);
+} else if (StorageUnitSize > Context.getTypeSize(Context.UnsignedIntTy) &&
+   Context.getTargetInfo().getTriple().isArch32Bit() &&
+   FieldSize <= 32) {
+  // Under 32-bit compile mode, the bitcontainer is 32 bits if a single
+  // long long bitfield has length no greater than 32 bits.
+  StorageUnitSize = 32;
+
+  if (!AlignIsRequired)
+FieldAlign = 32;
+}
+
+if (FieldAlign < StorageUnitSize) {
+  // The bitfield alignment should always be greater than or equal to
+  // bitcontainer size.
+  FieldAlign = StorageUnitSize;
+}
+  }
+
   // If the field is wider than its declared type, it follows
-  // 
diff erent rules in all cases.
-  if (FieldSize > StorageUnitSize) {
+  // 
diff erent rules in all cases, except on AIX.
+  // On AIX, wide bitfield follows the same rules as normal bitfield.
+  if (FieldSize > StorageUnitSize && !isAIXLayout(Context)) {
 LayoutWideBitField(FieldSize, StorageUnitSize, FieldPacked, D);
 return;
   }

diff  --git a/clang/test/Layout/aix-bitfield-alignment.c 
b/clang/test/Layout/aix-bitfield-alignment.c
new file mode 100644
index ..a736695cc603
--- /dev/null
+++ b/clang/test/Layout/aix-bitfield-alignment.c
@@ -0,0 +1,234 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+struct A {
+  unsigned char c : 2;
+} A;
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-1 |   unsigned char c
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, 
preferredalign=4
+
+struct B {
+  char c;
+  int : 0;
+} B;
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, 
preferredalign=4
+
+struct C {
+  signed int a1 : 6;
+  signed char a2 : 4;
+ 

[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad added a comment.

I think one of the remaining things to address is the supported architectures:

  set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
  set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})

I am unclear as to whether or not there are consumers for the missing ones, but 
if there are we might break -fsanitize=scudo for them.
We have fallback for non-x86/arm processors in 
https://github.com/llvm/llvm-project/blob/e0921655b1ff8d4ba7c14be59252fe05b705920e/compiler-rt/lib/scudo/standalone/checksum.cpp#L79
 , the rest looks fine so I think adding them should work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D102306: Add gfx1034

2021-05-17 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl added a subscriber: t-tye.
kzhuravl added a comment.

In D102306#2760806 , @tra wrote:

> In D102306#2760775 , @msearles 
> wrote:
>
>> In D102306#2758166 , 
>> @JonChesterfield wrote:
>>
>>> Is there documentation for the mapping from product names to gfx numbers?
>>
>> See the Processors section of https://llvm.org/docs/AMDGPUUsage.html
>
> It appears to be missing some GPUs. None of WX series are listed, for example.

+ @t-tye

@t-tye usually updates product names as they become available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102306

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added a comment.

In D102543#2763749 , @cryptoad wrote:

> I think one of the remaining things to address is the supported architectures:
>
>   set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
> ${MIPS64} ${PPC64})
>   set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
>
> I am unclear as to whether or not there are consumers for the missing ones, 
> but if there are we might break -fsanitize=scudo for them.
> We have fallback for non-x86/arm processors in 
> https://github.com/llvm/llvm-project/blob/e0921655b1ff8d4ba7c14be59252fe05b705920e/compiler-rt/lib/scudo/standalone/checksum.cpp#L79
>  , the rest looks fine so I think adding them should work.

Sure, I've added them but I don't have anything to test with. Well - I'm sure 
they'll let us know if they break.




Comment at: compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp:42
+  if (Allocator.canReturnNull()) { 
\
+errno = EINVAL;
\
+return nullptr;
\

cryptoad wrote:
> I don't think errno carry over to  C++, there seems to be no sign of it in 
> https://en.cppreference.com/w/cpp/memory/new/operator_new
Removed.



Comment at: compiler-rt/test/scudo/standalone/lit.cfg.py:21
 c_flags = ([config.target_cflags] +
-   ["-pthread",
-   "-fPIE",
-   "-pie",
-   "-O0",
-   "-UNDEBUG",
-   "-ldl",
-   "-Wl,--gc-sections"])
+   ["-pthread", "-fPIE", "-pie", "-O0", "-UNDEBUG", "-ldl",
+"-Wl,--gc-sections"])

cryptoad wrote:
> -ldl might not be necessary anymore without the sanitizer dependencies?
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 345906.
hctim marked 2 inline comments as done.
hctim added a comment.

Address Kostya's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,42 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up 
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[k

[PATCH] D102556: [HIP] Fix spack detection

2021-05-17 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM with a test nit.




Comment at: clang/test/Driver/rocm-detect.hip:115
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-4.0.0 not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-4.0.0 not found at

Nit: I'd match the version with a regex. Otherwise this test would continue 
passing even if compiler were to report `hip-some.other.version not found` 


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

https://reviews.llvm.org/D102556

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


[clang] 5f58322 - [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse via cfe-commits

Author: Matt Morehouse
Date: 2021-05-17T09:19:06-07:00
New Revision: 5f58322368b070b63fe2b2559a54f646cb97e2c4

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

LOG: [HWASan] Build separate LAM runtime on x86_64.

Since we have both aliasing mode and Intel LAM on x86_64, we need to
choose the mode at either run time or compile time.  This patch
implements the plumbing to build both and choose between them at
compile time.

Reviewed By: vitalybuka, eugenis

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
compiler-rt/lib/hwasan/CMakeLists.txt
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_allocator.h
compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
compiler-rt/lib/hwasan/hwasan_linux.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index e8fdb08137864..b74a9fe3eb927 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -816,8 +816,12 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
 }
 if (SanArgs.needsTsanRt() && SanArgs.linkRuntimes())
   SharedRuntimes.push_back("tsan");
-if (SanArgs.needsHwasanRt() && SanArgs.linkRuntimes())
-  SharedRuntimes.push_back("hwasan");
+if (SanArgs.needsHwasanRt() && SanArgs.linkRuntimes()) {
+  if (SanArgs.needsHwasanAliasesRt())
+SharedRuntimes.push_back("hwasan_aliases");
+  else
+SharedRuntimes.push_back("hwasan");
+}
   }
 
   // The stats_client library is also statically linked into DSOs.
@@ -847,9 +851,15 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   }
 
   if (!SanArgs.needsSharedRt() && SanArgs.needsHwasanRt() && 
SanArgs.linkRuntimes()) {
-StaticRuntimes.push_back("hwasan");
-if (SanArgs.linkCXXRuntimes())
-  StaticRuntimes.push_back("hwasan_cxx");
+if (SanArgs.needsHwasanAliasesRt()) {
+  StaticRuntimes.push_back("hwasan_aliases");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("hwasan_aliases_cxx");
+} else {
+  StaticRuntimes.push_back("hwasan");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("hwasan_cxx");
+}
   }
   if (SanArgs.needsDfsanRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("dfsan");

diff  --git a/compiler-rt/lib/hwasan/CMakeLists.txt 
b/compiler-rt/lib/hwasan/CMakeLists.txt
index 707cbb44233fe..547b26f0033d6 100644
--- a/compiler-rt/lib/hwasan/CMakeLists.txt
+++ b/compiler-rt/lib/hwasan/CMakeLists.txt
@@ -93,6 +93,24 @@ add_compiler_rt_object_libraries(RTHwasan_dynamic
   CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
   DEFS ${HWASAN_DEFINITIONS})
 
+# Compile a 
diff erent runtime for x86 aliasing mode.
+set(HWASAN_ALIASES_RTL_CFLAGS ${HWASAN_RTL_CFLAGS})
+list(APPEND HWASAN_ALIASES_RTL_CFLAGS -DHWASAN_ALIASING_MODE)
+set(HWASAN_ALIASES_DYNAMIC_CFLAGS ${HWASAN_DYNAMIC_CFLAGS})
+list(APPEND HWASAN_ALIASES_DYNAMIC_CFLAGS -DHWASAN_ALIASING_MODE)
+add_compiler_rt_object_libraries(RTHwasanAliases
+  ARCHS ${HWASAN_SUPPORTED_ARCH}
+  SOURCES ${HWASAN_RTL_SOURCES}
+  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
+  CFLAGS ${HWASAN_ALIASES_RTL_CFLAGS}
+  DEFS ${HWASAN_DEFINITIONS})
+add_compiler_rt_object_libraries(RTHwasanAliases_dynamic
+  ARCHS ${HWASAN_SUPPORTED_ARCH}
+  SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
+  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
+  CFLAGS ${HWASAN_ALIASES_DYNAMIC_CFLAGS}
+  DEFS ${HWASAN_DEFINITIONS})
+
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
 add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
   ARCHS ${HWASAN_SUPPORTED_ARCH}
@@ -100,47 +118,61 @@ 
add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
   CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
   DEFS ${HWASAN_DEFINITIONS})
 
-foreach(arch ${HWASAN_SUPPORTED_ARCH})
-  add_compiler_rt_runtime(clang_rt.hwasan
+# If use_aliases is TRUE, adds the HWASan runtime built with alias support.
+# Otherwise adds the runtime without alias support.
+function(add_hwasan_runtimes arch use_aliases)
+  set(hwasan_object_lib RTHwasan)
+  set(hwasan_object_dyn_lib RTHwasan_dynamic)
+  set(hwasan_runtime clang_rt.hwasan)
+  set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS})
+  set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS})
+  if(use_aliases)
+set(hwasan_object_lib RTHwasanAliases)
+set(hwasan_object_dyn_lib RTHwasanAliases_dynamic)
+set(hwasan_runtime clang_rt.hwasan_aliases)
+set(hwasan_rtl_flags ${HWASAN_ALIASES_RTL_CFLAGS})
+set(hwasan_dyn_flags ${HWASAN_ALIASES_DYNAMIC_CFLAGS})
+  endif()
+  add_compiler_rt_runtime(${hwasan_runtime}
 STATIC
 ARCHS ${arch}
-OBJECT_LIBS RTHwasan

[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse 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 rG5f58322368b0: [HWASan] Build separate LAM runtime on x86_64. 
(authored by morehouse).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
  compiler-rt/lib/hwasan/hwasan_linux.cpp

Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -76,7 +76,7 @@
 uptr kHighMemStart;
 uptr kHighMemEnd;
 
-uptr kAliasRegionStart;  // Always 0 on non-x86.
+uptr kAliasRegionStart;  // Always 0 when aliases aren't used.
 
 static void PrintRange(uptr start, uptr end, const char *name) {
   Printf("|| [%p, %p] || %.*s ||\n", (void *)start, (void *)end, 10, name);
@@ -125,33 +125,50 @@
   if (internal_iserror(internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0),
&local_errno) &&
   local_errno == EINVAL) {
-#if SANITIZER_ANDROID || defined(__x86_64__)
+#  if SANITIZER_ANDROID || defined(HWASAN_ALIASING_MODE)
 // Some older Android kernels have the tagged pointer ABI on
 // unconditionally, and hence don't have the tagged-addr prctl while still
 // allow the ABI.
 // If targeting Android and the prctl is not around we assume this is the
 // case.
 return;
-#else
+#  else
 if (flags()->fail_without_syscall_abi) {
   Printf(
   "FATAL: "
   "HWAddressSanitizer requires a kernel with tagged address ABI.\n");
   Die();
 }
-#endif
+#  endif
   }
 
   // Turn on the tagged address ABI.
   if ((internal_iserror(internal_prctl(PR_SET_TAGGED_ADDR_CTRL,
PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) ||
-   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) &&
-  flags()->fail_without_syscall_abi) {
-Printf(
-"FATAL: HWAddressSanitizer failed to enable tagged address syscall "
-"ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
-"configuration.\n");
-Die();
+   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))) {
+#  if defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+// Try the new prctl API for Intel LAM.  The API is based on a currently
+// unsubmitted patch to the Linux kernel (as of May 2021) and is thus
+// subject to change.  Patch is here:
+// https://lore.kernel.org/linux-mm/20210205151631.43511-12-kirill.shute...@linux.intel.com/
+int tag_bits = kTagBits;
+int tag_shift = kAddressTagShift;
+if (!internal_iserror(
+internal_prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE,
+   reinterpret_cast(&tag_bits),
+   reinterpret_cast(&tag_shift), 0))) {
+  CHECK_EQ(tag_bits, kTagBits);
+  CHECK_EQ(tag_shift, kAddressTagShift);
+  return;
+}
+#  endif  // defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+if (flags()->fail_without_syscall_abi) {
+  Printf(
+  "FATAL: HWAddressSanitizer failed to enable tagged address syscall "
+  "ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
+  "configuration.\n");
+  Die();
+}
   }
 #undef PR_SET_TAGGED_ADDR_CTRL
 #undef PR_GET_TAGGED_ADDR_CTRL
@@ -181,7 +198,7 @@
   // High memory starts where allocated shadow allows.
   kHighMemStart = ShadowToMem(kHighShadowStart);
 
-#if defined(__x86_64__)
+#  if defined(HWASAN_ALIASING_MODE)
   constexpr uptr kAliasRegionOffset = 1ULL << (kTaggableRegionCheckShift - 1);
   kAliasRegionStart =
   __hwasan_shadow_memory_dynamic_address + kAliasRegionOffset;
@@ -191,7 +208,7 @@
   CHECK_EQ(
   (kAliasRegionStart + kAliasRegionOffset - 1) >> kTaggableRegionCheckShift,
   __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
-#endif
+#  endif
 
   // Check the sanity of the defined memory ranges (there might be gaps).
   CHECK_EQ(kHighMemStart % GetMmapGranularity(), 0);
@@ -236,9 +253,11 @@
 }
 
 bool MemIsApp(uptr p) {
-#if !defined(__x86_64__)  // Memory outside the alias range has non-zero tags.
+// Memory outside the alias range has non-zero tags.
+#  if !defined(HWASAN_ALIASING_MODE)
   CHECK(GetTagFromPointer(p) == 0);
-#endif
+#  endif
+
   return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
===
--- compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
+++ compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
@@ -119,12 +119,12 @@
 void InitShadowGOT() {}
 
 uptr FindDynamicS

[PATCH] D102556: [HIP] Fix spack detection

2021-05-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/test/Driver/rocm-detect.hip:115
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-4.0.0 not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-4.0.0 not found at

tra wrote:
> Nit: I'd match the version with a regex. Otherwise this test would continue 
> passing even if compiler were to report `hip-some.other.version not found` 
will do


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

https://reviews.llvm.org/D102556

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


[clang] 02c2468 - [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX cp.async instructions

2021-05-17 Thread Artem Belevich via cfe-commits

Author: Stuart Adams
Date: 2021-05-17T09:46:59-07:00
New Revision: 02c2468864bbb37f7b279aff84961815c1500b6c

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

LOG: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX cp.async 
instructions

Adds NVPTX builtins and intrinsics for the CUDA PTX `cp.async` instructions for
`sm_80` architecture or newer.

PTX ISA description of `cp.async`:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-asynchronous-copy
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-cp-async-mbarrier-arrive

Authored-by: Stuart Adams 
Co-Authored-by: Alexander Johnston 

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

Added: 
llvm/test/CodeGen/NVPTX/async-copy.ll
llvm/test/CodeGen/NVPTX/mbarrier.ll

Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/test/CodeGen/builtins-nvptx.c
llvm/include/llvm/IR/IntrinsicsNVVM.td
llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index b225ddcfa3fa0..3feea854df819 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -462,6 +462,29 @@ BUILTIN(__nvvm_membar_cta, "v", "")
 BUILTIN(__nvvm_membar_gl, "v", "")
 BUILTIN(__nvvm_membar_sys, "v", "")
 
+// mbarrier
+
+TARGET_BUILTIN(__nvvm_mbarrier_init, "vWi*i", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_inval, "vWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_inval_shared, "vWi*3", "", AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_arrive, "WiWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_shared, "WiWi*3", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_noComplete, "WiWi*i", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_noComplete_shared, "WiWi*3i", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop, "WiWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop_shared, "WiWi*3", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop_noComplete, "WiWi*i", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop_noComplete_shared, "WiWi*3i", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_test_wait, "bWi*Wi", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_test_wait_shared, "bWi*3Wi", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_pending_count, "iWi", "", AND(SM_80,PTX70))
+
 // Memcpy, Memset
 
 BUILTIN(__nvvm_memcpy, "vUc*Uc*zi","")
@@ -726,6 +749,21 @@ TARGET_BUILTIN(__imma_m8n8k32_mma_s4, "vi*iC*iC*iC*IiIi", 
"", AND(SM_75,PTX63))
 TARGET_BUILTIN(__imma_m8n8k32_mma_u4, "vi*iC*iC*iC*IiIi", "", AND(SM_75,PTX63))
 TARGET_BUILTIN(__imma_m8n8k32_st_c_i32, "vi*iC*UiIi", "", AND(SM_75,PTX63))
 
+// Async Copy
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive, "vWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive_shared, "vWi*3", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive_noinc, "vWi*", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive_noinc_shared, "vWi*3", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_cp_async_ca_shared_global_4, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_ca_shared_global_8, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_ca_shared_global_16, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_cg_shared_global_16, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_cp_async_commit_group, "v", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_wait_group, "vIi", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_wait_all, "v", "", AND(SM_80,PTX70))
+
 #undef BUILTIN
 #undef TARGET_BUILTIN
 #pragma pop_macro("AND")

diff  --git a/clang/test/CodeGen/builtins-nvptx.c 
b/clang/test/CodeGen/builtins-nvptx.c
index 913da5d7b73b9..ec0f74291ad47 100644
--- a/clang/test/CodeGen/builtins-nvptx.c
+++ b/clang/test/CodeGen/builtins-nvptx.c
@@ -1,4 +1,10 @@
 // REQUIRES: nvptx-registered-target
+// RUN: %clang_cc1 -ffp-contract=off -triple nvptx-unknown-unknown -target-cpu 
sm_80 -target-feature +ptx70 \
+// RUN:-fcuda-is-device -S -emit-llvm -o - -x cuda %s \
+// RUN:   | FileCheck -check-prefix=CHECK -check-prefix=CHECK_PTX70_SM80 
-check-prefix=LP32 %s
+// RUN: %clang_cc1 -ffp-contract=off -triple nvptx64-unknown-unknown 
-target-cpu sm_80 -target-feature +ptx70 \
+// RUN:-fcuda-is-device -S -emit-llvm -o - 

[clang] f226e28 - [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-05-17 Thread Artem Belevich via cfe-commits

Author: Steffen Larsen
Date: 2021-05-17T09:46:59-07:00
New Revision: f226e28a880f8e40b1bfd4c77b9768a667372d22

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

LOG: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync 
instructions

Adds NVPTX builtins and intrinsics for the CUDA PTX `redux.sync` instructions
for `sm_80` architecture or newer.

PTX ISA description of `redux.sync`:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-redux-sync

Authored-by: Steffen Larsen 

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

Added: 
clang/test/CodeGenCUDA/redux-builtins.cu
llvm/test/CodeGen/NVPTX/redux-sync.ll

Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
llvm/include/llvm/IR/IntrinsicsNVVM.td
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 3feea854df819..98f3c659b7cec 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -456,6 +456,16 @@ TARGET_BUILTIN(__nvvm_match_any_sync_i64, "WiUiWi", "", 
PTX60)
 TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", PTX60)
 TARGET_BUILTIN(__nvvm_match_all_sync_i64p, "WiUiWii*", "", PTX60)
 
+// Redux
+TARGET_BUILTIN(__nvvm_redux_sync_add, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_min, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_max, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_umin, "UiUii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_umax, "UiUii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_and, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_xor, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_or, "iii", "", AND(SM_80,PTX70))
+
 // Membar
 
 BUILTIN(__nvvm_membar_cta, "v", "")

diff  --git a/clang/test/CodeGenCUDA/redux-builtins.cu 
b/clang/test/CodeGenCUDA/redux-builtins.cu
new file mode 100644
index 0..bdcd00b567f70
--- /dev/null
+++ b/clang/test/CodeGenCUDA/redux-builtins.cu
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 "-triple" "nvptx-nvidia-cuda" "-target-feature" "+ptx70" 
"-target-cpu" "sm_80" -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+// RUN: %clang_cc1 "-triple" "nvptx64-nvidia-cuda" "-target-feature" "+ptx70" 
"-target-cpu" "sm_80" -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+// CHECK: define{{.*}} void @_Z6kernelPi(i32* %out)
+__attribute__((global)) void kernel(int *out) {
+  int a = 1;
+  unsigned int b = 5;
+  int i = 0;
+
+  out[i++] = __nvvm_redux_sync_add(a, 0xFF);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.add
+
+  out[i++] = __nvvm_redux_sync_add(b, 0x01);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.add
+
+  out[i++] = __nvvm_redux_sync_min(a, 0x0F);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.min
+
+  out[i++] = __nvvm_redux_sync_umin(b, 0xF0);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.umin
+
+  out[i++] = __nvvm_redux_sync_max(a, 0xF0);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.max
+
+  out[i++] = __nvvm_redux_sync_umax(b, 0x0F);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.umax
+
+  out[i++] = __nvvm_redux_sync_and(a, 0xF0);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.and
+
+  out[i++] = __nvvm_redux_sync_and(b, 0x0F);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.and
+
+  out[i++] = __nvvm_redux_sync_xor(a, 0x10);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.xor
+
+  out[i++] = __nvvm_redux_sync_xor(b, 0x01);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.xor
+
+  out[i++] = __nvvm_redux_sync_or(a, 0xFF);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.or
+
+  out[i++] = __nvvm_redux_sync_or(b, 0xFF);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.or
+
+  // CHECK: ret void
+}

diff  --git a/llvm/include/llvm/IR/IntrinsicsNVVM.td 
b/llvm/include/llvm/IR/IntrinsicsNVVM.td
index fa66a4a779e19..71e31b14f4c3b 100644
--- a/llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ b/llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -4204,6 +4204,49 @@ def int_nvvm_match_all_sync_i64p :
   Intrinsic<[llvm_i64_ty, llvm_i1_ty], [llvm_i32_ty, llvm_i64_ty],
 [IntrInaccessibleMemOnly, IntrConvergent], 
"llvm.nvvm.match.all.sync.i64p">;
 
+//
+// REDUX.SYNC
+//
+// redux.sync.min.u32 dst, src, membermask;
+def int_nvvm_redux_sync_umin : GCCBuiltin<"__nvvm_redux_sync_umin">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrInaccessibleMemOnly]>;
+
+// redux.sync.max.u32 dst, src, membermask;
+def int_nvvm_redux_sync_umax : GCCBuiltin<"__nvvm_redux_sync_umax">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrInaccessibleMemOnly]>;
+
+// redux.

[PATCH] D100394: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX cp.async instructions

2021-05-17 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02c2468864bb: [Clang][NVPTX] Add NVPTX intrinsics and 
builtins for CUDA PTX cp.async… (authored by nyalloc, committed by tra).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100394

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGen/builtins-nvptx.c
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/async-copy.ll
  llvm/test/CodeGen/NVPTX/mbarrier.ll

Index: llvm/test/CodeGen/NVPTX/mbarrier.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/mbarrier.ll
@@ -0,0 +1,145 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_80 | FileCheck %s -check-prefix=CHECK_PTX32
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 | FileCheck %s -check-prefix=CHECK_PTX64
+
+declare void @llvm.nvvm.mbarrier.init(i64* %a, i32 %b)
+declare void @llvm.nvvm.mbarrier.init.shared(i64 addrspace(3)* %a, i32 %b)
+
+; CHECK-LABEL: barrierinit
+define void @barrierinit(i64* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.init.b64 [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.init.b64 [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  tail call void @llvm.nvvm.mbarrier.init(i64* %a, i32 %b)
+  ret void
+}
+
+; CHECK-LABEL: barrierinitshared
+define void @barrierinitshared(i64 addrspace(3)* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.init.shared.b64 [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.init.shared.b64 [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  tail call void @llvm.nvvm.mbarrier.init.shared(i64 addrspace(3)* %a, i32 %b)
+  ret void
+}
+
+declare void @llvm.nvvm.mbarrier.inval(i64* %a)
+declare void @llvm.nvvm.mbarrier.inval.shared(i64 addrspace(3)* %a)
+
+; CHECK-LABEL: barrierinval
+define void @barrierinval(i64* %a) {
+; CHECK_PTX32: mbarrier.inval.b64 [%r{{[0-1]+}}];
+; CHECK_PTX64: mbarrier.inval.b64 [%rd{{[0-1]+}}];
+  tail call void @llvm.nvvm.mbarrier.inval(i64* %a)
+  ret void
+}
+
+; CHECK-LABEL: barrierinvalshared
+define void @barrierinvalshared(i64 addrspace(3)* %a) {
+; CHECK_PTX32: mbarrier.inval.shared.b64 [%r{{[0-1]+}}];
+; CHECK_PTX64: mbarrier.inval.shared.b64 [%rd{{[0-1]+}}];
+  tail call void @llvm.nvvm.mbarrier.inval.shared(i64 addrspace(3)* %a)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mbarrier.arrive(i64* %a)
+declare i64 @llvm.nvvm.mbarrier.arrive.shared(i64 addrspace(3)* %a)
+
+; CHECK-LABEL: barrierarrive
+define void @barrierarrive(i64* %a) {
+; CHECK_PTX32: mbarrier.arrive.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive(i64* %a)
+  ret void
+}
+
+; CHECK-LABEL: barrierarriveshared
+define void @barrierarriveshared(i64 addrspace(3)* %a) {
+; CHECK_PTX32: mbarrier.arrive.shared.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive.shared.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.shared(i64 addrspace(3)* %a)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mbarrier.arrive.noComplete(i64* %a, i32 %b)
+declare i64 @llvm.nvvm.mbarrier.arrive.noComplete.shared(i64 addrspace(3)* %a, i32 %b)
+
+; CHECK-LABEL: barrierarrivenoComplete
+define void @barrierarrivenoComplete(i64* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.arrive.noComplete.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.arrive.noComplete.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.noComplete(i64* %a, i32 %b)
+  ret void
+}
+
+; CHECK-LABEL: barrierarrivenoCompleteshared
+define void @barrierarrivenoCompleteshared(i64 addrspace(3)* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.arrive.noComplete.shared.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.arrive.noComplete.shared.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.noComplete.shared(i64 addrspace(3)* %a, i32 %b)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mbarrier.arrive.drop(i64* %a)
+declare i64 @llvm.nvvm.mbarrier.arrive.drop.shared(i64 addrspace(3)* %a)
+
+; CHECK-LABEL: barrierarrivedrop
+define void @barrierarrivedrop(i64* %a) {
+; CHECK_PTX32: mbarrier.arrive_drop.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive_drop.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.drop(i64* %a)
+  ret void
+}
+
+; CHECK-LABEL: barrierarrivedropshared
+define void @barrierarrivedropshared(i64 addrspace(3)* %a) {
+; CHECK_PTX32: mbarrier.arrive_drop.shared.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive_drop.shared.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.drop.shared(i64 addrspace(3)* %a)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mba

[PATCH] D100124: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-05-17 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf226e28a880f: [Clang][NVPTX] Add NVPTX intrinsics and 
builtins for CUDA PTX redux.sync… (authored by steffenlarsen, committed by tra).

Changed prior to commit:
  https://reviews.llvm.org/D100124?vs=339169&id=345915#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100124

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGenCUDA/redux-builtins.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/redux-sync.ll

Index: llvm/test/CodeGen/NVPTX/redux-sync.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/redux-sync.ll
@@ -0,0 +1,65 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck %s
+
+declare i32 @llvm.nvvm.redux.sync.umin(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_min_u32
+define i32 @redux_sync_min_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.min.u32
+  %val = call i32 @llvm.nvvm.redux.sync.umin(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.umax(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_max_u32
+define i32 @redux_sync_max_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.max.u32
+  %val = call i32 @llvm.nvvm.redux.sync.umax(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.add(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_add_s32
+define i32 @redux_sync_add_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.add.s32
+  %val = call i32 @llvm.nvvm.redux.sync.add(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.min(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_min_s32
+define i32 @redux_sync_min_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.min.s32
+  %val = call i32 @llvm.nvvm.redux.sync.min(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.max(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_max_s32
+define i32 @redux_sync_max_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.max.s32
+  %val = call i32 @llvm.nvvm.redux.sync.max(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.and(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_and_b32
+define i32 @redux_sync_and_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.and.b32
+  %val = call i32 @llvm.nvvm.redux.sync.and(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.xor(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_xor_b32
+define i32 @redux_sync_xor_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.xor.b32
+  %val = call i32 @llvm.nvvm.redux.sync.xor(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.or(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_or_b32
+define i32 @redux_sync_or_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.or.b32
+  %val = call i32 @llvm.nvvm.redux.sync.or(i32 %src, i32 %mask)
+  ret i32 %val
+}
Index: llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -274,6 +274,22 @@
 defm MATCH_ALLP_SYNC_64 : MATCH_ALLP_SYNC;
 
+multiclass REDUX_SYNC {
+  def : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$mask),
+  "redux.sync." # BinOp # "." # PTXType # " $dst, $src, $mask;",
+  [(set Int32Regs:$dst, (Intrin Int32Regs:$src, Int32Regs:$mask))]>,
+Requires<[hasPTX70, hasSM80]>;
+}
+
+defm REDUX_SYNC_UMIN : REDUX_SYNC<"min", "u32", int_nvvm_redux_sync_umin>;
+defm REDUX_SYNC_UMAX : REDUX_SYNC<"max", "u32", int_nvvm_redux_sync_umax>;
+defm REDUX_SYNC_ADD : REDUX_SYNC<"add", "s32", int_nvvm_redux_sync_add>;
+defm REDUX_SYNC_MIN : REDUX_SYNC<"min", "s32", int_nvvm_redux_sync_min>;
+defm REDUX_SYNC_MAX : REDUX_SYNC<"max", "s32", int_nvvm_redux_sync_max>;
+defm REDUX_SYNC_AND : REDUX_SYNC<"and", "b32", int_nvvm_redux_sync_and>;
+defm REDUX_SYNC_XOR : REDUX_SYNC<"xor", "b32", int_nvvm_redux_sync_xor>;
+defm REDUX_SYNC_OR : REDUX_SYNC<"or", "b32", int_nvvm_redux_sync_or>;
+
 } // isConvergent = true
 
 //---
Index: llvm/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -4204,6 +4204,49 @@
   Intrinsic<[llvm_i64_ty, llvm_i1_ty], [llvm_i32_ty, llvm_i64_ty],
 [IntrInaccessibleMemOnly, IntrConvergent], "llvm.nvvm.match.all.sync.i64p">;
 
+//
+// REDUX.SYNC
+//
+// redux.sync.min.u32 dst, src, membermask;
+def int_nvvm_redux_sync_umin : GCCBuiltin<"__nvvm_redux_sync_umin">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrInaccessibleMemOnly]>;
+
+// redux.sync.max.u32 dst, src, membermask;
+d

[PATCH] D100768: [Clang][OpenMP] Remove the mandatory flush for capture for OpenMP 5.1

2021-05-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 345917.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100768

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp

Index: clang/test/OpenMP/atomic_capture_codegen.cpp
===
--- clang/test/OpenMP/atomic_capture_codegen.cpp
+++ clang/test/OpenMP/atomic_capture_codegen.cpp
@@ -1,11 +1,19 @@
 
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-50 %s
 
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp-simd -x c -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp-simd -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 #ifndef HEADER
@@ -343,7 +351,7 @@
 // CHECK: [[IM_CAST:%.+]] = fptrunc double [[NEW_IM]] to float
 // CHECK: store float [[RE_CAST]], float* getelementptr inbounds ({ float, float }, { float, float }* @{{.+}}, i32 0, i32 0),
 // CHECK: store float [[IM_CAST]], float* getelementptr inbounds ({ float, float }, { float, float }* @{{.+}}, i32 0, i32 1),
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture seq_cst
   {cdx = cdx - cdv; cfv = cdx;}
 // CHECK: [[BV:%.+]] = load i8, i8* @{{.+}}
@@ -393,7 +401,7 @@
 // CHECK: br i1 [[SUCCESS_FAIL]], label %[[EXIT:.+]], label %[[CONT]]
 // CHECK: [[EXIT]]
 // CHECK: store i8 [[NEW]], i8* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture, seq_cst
   {cx = cx >> ucv; cv = cx;}
 // CHECK: [[SV:%.+]]  = load i16, i16* @{{.+}},
@@ -436,7 +444,7 @@
 // CHECK: [[OLD:%.+]] = atomicrmw or i32* @{{.+}}, i32 [[EXPR]] seq_cst, align 4
 // CHECK: [[DESIRED:%.+]] = or i32 [[EXPR]], [[OLD]]
 // CHECK: store i32 [[DESIRED]], i32* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic seq_cst, capture
   {uix = iv | uix; uiv = uix;}
 // CHECK: [[EXPR:%.+]] = load i32, i32* @{{.+}}
@@ -904,7 +912,7 @@
 // CHECK: [[EXIT]]
 // CHECK: [[NEW_VAL:%.+]] = trunc i64 [[CONV]] to i32
 // CHECK: store i32 [[NEW_VAL]], i32* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture release
   {bfx4.b /= ldv; iv = bfx4.b;}
 // CHECK: [[EXPR:%.+]] = load x86_fp80, x86_fp80* @{{.+}}
@@ -937,7 +945,7 @@
 // CHECK: [[EXIT]]
 // CHECK: [[NEW_VAL_I32:%.+]] = trunc i64 [[NEW_VAL]] to i32
 // CHECK: store i32 [[NEW_VAL_I32]], i32* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture acquire
   iv = bfx4_packed.b += ldv;
 // CHECK: load i64, i64*
@@ -963,7 +971,7 @@
 // CHECK: br i1 [[FAIL_SUCCESS]], label %[[EXIT:.+]], label %[[CONT]]
 // CHECK: [[EXIT]]
 // CHECK: store float [[X]], float* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture acq_rel
   {fv = float2x.x; float2x.x = ulv - float2x.x;}
 // CHECK: [[EXPR:%.+]] = load double, double* @{{.+}},
@@ -973,7 +981,7 @@
 // CHECK: [[NEW_VAL:%.+]] = fptosi double [[DIV]] to i32
 // CHECK: call void @llvm.write_register.i32([[R

[PATCH] D102638: [NFC] Pass GV value type instead of pointer type to GetOrCreateLLVMGlobal

2021-05-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks created this revision.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For opaque pointers, to avoid PointerType::getElementType().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102638

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h

Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,11 +1477,10 @@
   const FunctionDecl *FD);
   void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD);
 
-  llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
-llvm::PointerType *PTy,
-const VarDecl *D,
-ForDefinition_t IsForDefinition
-  = NotForDefinition);
+  llvm::Constant *
+  GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+unsigned AddrSpace, const VarDecl *D,
+ForDefinition_t IsForDefinition = NotForDefinition);
 
   bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
llvm::AttrBuilder &AttrBuilder);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2808,9 +2808,7 @@
   GlobalDecl(cast(VD)),
   /*ForVTable=*/false);
   else
-Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
-llvm::PointerType::getUnqual(DeclTy),
-nullptr);
+Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), DeclTy, 0, nullptr);
 
   auto *F = cast(Aliasee);
   F->setLinkage(llvm::Function::ExternalWeakLinkage);
@@ -3772,9 +3770,9 @@
 }
 
 /// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
-/// create and return an llvm GlobalVariable with the specified type.  If there
-/// is something in the module with the specified name, return it potentially
-/// bitcasted to the right type.
+/// create and return an llvm GlobalVariable with the specified type and address
+/// space. If there is something in the module with the specified name, return
+/// it potentially bitcasted to the right type.
 ///
 /// If D is non-null, it specifies a decl that correspond to this.  This is used
 /// to set the attributes on the global when it is first created.
@@ -3783,9 +3781,8 @@
 /// type Ty will be returned, not conversion of a variable with the same
 /// mangled name but some other type.
 llvm::Constant *
-CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
- llvm::PointerType *Ty,
- const VarDecl *D,
+CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+ unsigned AddrSpace, const VarDecl *D,
  ForDefinition_t IsForDefinition) {
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
@@ -3802,7 +3799,7 @@
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
   getOpenMPRuntime().registerTargetGlobalVariable(D, Entry);
 
-if (Entry->getType() == Ty)
+if (Entry->getValueType() == Ty && Entry->getAddressSpace() == AddrSpace)
   return Entry;
 
 // If there are two attempts to define the same mangled name, issue an
@@ -3826,22 +3823,24 @@
 }
 
 // Make sure the result is of the correct type.
-if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace())
-  return llvm::ConstantExpr::getAddrSpaceCast(Entry, Ty);
+if (Entry->getType()->getAddressSpace() != AddrSpace) {
+  return llvm::ConstantExpr::getAddrSpaceCast(Entry,
+  Ty->getPointerTo(AddrSpace));
+}
 
 // (If global is requested for a definition, we always need to create a new
 // global, not just return a bitcast.)
 if (!IsForDefinition)
-  return llvm::ConstantExpr::getBitCast(Entry, Ty);
+  return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo(AddrSpace));
   }
 
-  auto AddrSpace = GetGlobalVarAddressSpace(D);
-  auto TargetAddrSpace = getContext().getTargetAddressSpace(AddrSpace);
+  auto DAddrSpace = GetGlobalVarAddressSpace(D);
+  auto TargetAddrSpace = getContext().getTargetAddressSpace(DAddrSpace);
 
   auto *GV = new llvm::GlobalVariable(
-  getModule(), Ty->getElementType(), false,
-  llvm::GlobalValue::ExternalLinkage, nullptr, MangledName, nullptr,
-  llvm::GlobalVariable::NotThreadLocal, TargetAdd

[PATCH] D102488: [clang][deps] Prune unused header search paths

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 345922.
jansvoboda11 added a comment.

Make PCM parsing lazier


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102488

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/header-search-pruning/a/a.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/b/b.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/cdb.json
  clang/test/ClangScanDeps/Inputs/header-search-pruning/mod.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/module.modulemap
  clang/test/ClangScanDeps/header-search-pruning.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -163,6 +163,11 @@
 "'-fmodule-file=', '-o', '-fmodule-map-file='."),
 llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
 
+static llvm::cl::opt OptimizeArgs(
+"optimize-args",
+llvm::cl::desc("Whether to optimize command-line arguments of modules."),
+llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
+
 llvm::cl::opt
 NumThreads("j", llvm::cl::Optional,
llvm::cl::desc("Number of worker threads to use (default: use "
@@ -357,7 +362,26 @@
 
 private:
   StringRef lookupPCMPath(ModuleID MID) {
-return Modules[IndexedModuleID{MID, 0}].ImplicitModulePCMPath;
+auto PCMPath = PCMPaths.insert({IndexedModuleID{MID, 0}, ""});
+if (PCMPath.second)
+  PCMPath.first->second = constructPCMPath(lookupModuleDeps(MID));
+return PCMPath.first->second;
+  }
+
+  /// Construct a path where to put the explicitly built PCM - essentially the
+  /// path to implicitly built PCM with the context hash replaced by the final
+  /// (potentially modified) context hash.
+  std::string constructPCMPath(const ModuleDeps &MD) const {
+const std::string &ImplicitPCMPath = MD.ImplicitModulePCMPath;
+StringRef Filename = llvm::sys::path::filename(ImplicitPCMPath);
+StringRef ImplicitContextHashPath =
+llvm::sys::path::parent_path(ImplicitPCMPath);
+StringRef ModuleCachePath =
+llvm::sys::path::parent_path(ImplicitContextHashPath);
+
+SmallString<64> ExplicitPCMPath = ModuleCachePath;
+llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
+return std::string(ExplicitPCMPath);
   }
 
   const ModuleDeps &lookupModuleDeps(ModuleID MID) {
@@ -395,6 +419,8 @@
   std::mutex Lock;
   std::unordered_map
   Modules;
+  std::unordered_map
+  PCMPaths;
   std::vector Inputs;
 };
 
@@ -554,7 +580,7 @@
   SharedStream DependencyOS(llvm::outs());
 
   DependencyScanningService Service(ScanMode, Format, ReuseFileManager,
-SkipExcludedPPRanges);
+SkipExcludedPPRanges, OptimizeArgs);
   llvm::ThreadPool Pool(llvm::hardware_concurrency(NumThreads));
   std::vector> WorkerTools;
   for (unsigned I = 0; I < Pool.getThreadCount(); ++I)
Index: clang/test/ClangScanDeps/header-search-pruning.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-pruning.cpp
@@ -0,0 +1,87 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: cp -r %S/Inputs/header-search-pruning/* %t
+// RUN: cp %S/header-search-pruning.cpp %t/header-search-pruning.cpp
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_A|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_a.json
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_B|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_b.json
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_A -DINCLUDE_B|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_ab.json
+//
+// RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -optimize-args >> %t/result_a.json
+// RUN: cat %t/result_a.json | sed 's/\\/\//g' | FileCheck --check-prefixes=CHECK_A %s
+//
+// RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -optimize-args >> %t/result_b.json
+// RUN: cat %t/result_b.json | sed 's/\\/\//g' | FileCheck --

[PATCH] D101561: [Prototype] Introduce attribute for ignoring C++ ABI

2021-05-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks abandoned this revision.
aeubanks added a comment.

turns out this didn't have a good enough impact to pursue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101561

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


[clang] 18cb17c - [HIP] Fix spack detection

2021-05-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-05-17T13:24:05-04:00
New Revision: 18cb17ce4cd54b9971550840b6f0b872de0d4c8c

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

LOG: [HIP] Fix spack detection

Missing or duplicate spack package should not cause error, since
users may only installed llvm/clang package, or users may installed
duplicate HIP package but will use environment variable or compiler
option to choose HIP path.

The message about missing or duplicate spack package is informational,
therefore should be emitted only when -v is specified.

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/ROCm.h
clang/test/Driver/rocm-detect.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 4da1239dce84..639f3598a1d9 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -58,19 +58,16 @@ RocmInstallationDetector::findSPACKPackage(const Candidate 
&Cand,
 llvm::sys::path::append(PackagePath, SubDirs[0]);
 return PackagePath;
   }
-  if (SubDirs.size() == 0) {
-unsigned DiagID = D.getDiags().getCustomDiagID(
-DiagnosticsEngine::Error,
-"Expecting SPACK package %0 at %1 but not found");
-D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() == 0 && Verbose) {
+llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
+ << '\n';
 return {};
   }
 
-  assert(SubDirs.size() > 1);
-  unsigned DiagID = D.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Expecting one SPACK package %0 at %1 but found more");
-  D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() > 1 && Verbose) {
+llvm::errs() << "Cannot use SPACK package " << Prefix << " at " << 
Cand.Path
+ << " due to multiple installations for the same version\n";
+  }
   return {};
 }
 
@@ -305,6 +302,7 @@ RocmInstallationDetector::RocmInstallationDetector(
 const Driver &D, const llvm::Triple &HostTriple,
 const llvm::opt::ArgList &Args, bool DetectHIPRuntime, bool 
DetectDeviceLib)
 : D(D) {
+  Verbose = Args.hasArg(options::OPT_v);
   RocmPathArg = Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ);
   PrintROCmSearchDirs =
   Args.hasArg(clang::driver::options::OPT_print_rocm_search_dirs);

diff  --git a/clang/lib/Driver/ToolChains/ROCm.h 
b/clang/lib/Driver/ToolChains/ROCm.h
index 35fb24a225e4..bb482be68260 100644
--- a/clang/lib/Driver/ToolChains/ROCm.h
+++ b/clang/lib/Driver/ToolChains/ROCm.h
@@ -110,6 +110,7 @@ class RocmInstallationDetector {
   // Cache ROCm installation search paths.
   SmallVector ROCmSearchDirs;
   bool PrintROCmSearchDirs;
+  bool Verbose;
 
   bool allGenericLibsValid() const {
 return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&

diff  --git a/clang/test/Driver/rocm-detect.hip 
b/clang/test/Driver/rocm-detect.hip
index 68ae1edb4eb2..f1fa1fc636dc 100644
--- a/clang/test/Driver/rocm-detect.hip
+++ b/clang/test/Driver/rocm-detect.hip
@@ -61,12 +61,15 @@
 // RUN:%s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
 
 // Test invalid SPACK ROCm installation missing hip and rocm-device-libs 
packages.
+// The message about SPACK is emitted only if -v is specified.
 
 // RUN: rm -rf %T/rocm-spack/hip-*
 // RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
 // RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### 
-v \
 // RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=SPACK-MISS %s
+// RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang 
--version 2>&1 \
+// RUN:   | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
 
 // GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. 
Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib 
to build without ROCm device library
 
@@ -90,8 +93,8 @@
 // SPACK-SAME: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
 
 // SPACK-MULT: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MULT-DAG: Expecting one SPACK package hip-4.0.0 at [[DIR]] but found 
more
-// SPACK-MULT-DAG: Expecting one SPACK package rocm-device-libs-4.0.0 at 
[[DIR]] but found more
+// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to 
multiple installations for the same version
+// SPACK-MULT-DAG: Cannot use SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
due to multiple installations for the same version
 // SPACK-MULT-NOT: Found HIP installation: 
[

[PATCH] D102556: [HIP] Fix spack detection

2021-05-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG18cb17ce4cd5: [HIP] Fix spack detection (authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D102556?vs=345643&id=345925#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102556

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/ROCm.h
  clang/test/Driver/rocm-detect.hip


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -61,12 +61,15 @@
 // RUN:%s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
 
 // Test invalid SPACK ROCm installation missing hip and rocm-device-libs 
packages.
+// The message about SPACK is emitted only if -v is specified.
 
 // RUN: rm -rf %T/rocm-spack/hip-*
 // RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
 // RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### 
-v \
 // RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=SPACK-MISS %s
+// RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang 
--version 2>&1 \
+// RUN:   | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
 
 // GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. 
Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib 
to build without ROCm device library
 
@@ -90,8 +93,8 @@
 // SPACK-SAME: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
 
 // SPACK-MULT: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MULT-DAG: Expecting one SPACK package hip-4.0.0 at [[DIR]] but found 
more
-// SPACK-MULT-DAG: Expecting one SPACK package rocm-device-libs-4.0.0 at 
[[DIR]] but found more
+// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to 
multiple installations for the same version
+// SPACK-MULT-DAG: Cannot use SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
due to multiple installations for the same version
 // SPACK-MULT-NOT: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK-MULT-NOT: "-mlink-builtin-bitcode" 
"[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
 // SPACK-MULT-NOT: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
@@ -103,8 +106,12 @@
 // SPACK-SET-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-abcd/include"
 
 // SPACK-MISS: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MISS-DAG: Expecting SPACK package hip-4.0.0 at [[DIR]] but not found
-// SPACK-MISS-DAG: Expecting SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
but not found
+// SPACK-MISS-DAG: SPACK package hip-4.0.0 not found at [[DIR]]
+// SPACK-MISS-DAG: SPACK package rocm-device-libs-4.0.0 not found at [[DIR]]
 // SPACK-MISS-NOT: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK-MISS-NOT: "-mlink-builtin-bitcode" 
"[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
 // SPACK-MISS-NOT: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-{{.*}} not found at
+// SPACK-MISS-SILENT-NOT: Found HIP installation
Index: clang/lib/Driver/ToolChains/ROCm.h
===
--- clang/lib/Driver/ToolChains/ROCm.h
+++ clang/lib/Driver/ToolChains/ROCm.h
@@ -110,6 +110,7 @@
   // Cache ROCm installation search paths.
   SmallVector ROCmSearchDirs;
   bool PrintROCmSearchDirs;
+  bool Verbose;
 
   bool allGenericLibsValid() const {
 return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -58,19 +58,16 @@
 llvm::sys::path::append(PackagePath, SubDirs[0]);
 return PackagePath;
   }
-  if (SubDirs.size() == 0) {
-unsigned DiagID = D.getDiags().getCustomDiagID(
-DiagnosticsEngine::Error,
-"Expecting SPACK package %0 at %1 but not found");
-D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() == 0 && Verbose) {
+llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
+ << '\n';
 return {};
   }
 
-  assert(SubDirs.size() > 1);
-  unsigned DiagID = D.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Ex

[PATCH] D102492: [clang][AST] Add support for BindingDecl to ASTImporter.

2021-05-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:873
+  MatchVerifier Verifier;
+  testImport("int a[2] = {1, 2};"
+ "auto [declToImport, x] = a;",

Can we add a larger variety of tests? Given how simple the `BindingDecl` case 
seems to be I don't expect any surprises but it would be good to verify that 
cases like mixed types, references and bit-fields work as expected. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102492

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


[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

LGTM but please review the linter warnings.




Comment at: clang/lib/Basic/Targets/M68k.cpp:145
   case 'd': // data register
-  case 'f': // floating point register
 info.setAllowsRegister();

did you mean to drop support for `'f'`?



Comment at: llvm/test/CodeGen/M68k/inline-asm.ll:36
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void

You probably should add tests for all newly added constraints with valid input.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102585

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


[PATCH] D102640: [ASTimporter] Remove decl from lookup only if it has decl context

2021-05-17 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: teemperor, shafik, balazske, a.sidorin, martong.
Herald added subscribers: whisperity, rnkovacs.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the case of `TypedefDecl`s we set the `DeclContext` after we imported it.
It turns out, it could lead to null pointer dereferences during the cleanup 
part of a failed import.

This patch demonstrates this issue and fixes it by checking if the DeclContext 
is available or not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102640

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5225,6 +5225,40 @@
   EXPECT_TRUE(ImportedOK);
 }
 
+TEST_P(ErrorHandlingTest, ODRViolationWithinTypedefDecls) {
+  // Importing `z` should fail - instead of crashing - due to an ODR violation.
+  // The `bar::e` typedef sets it's DeclContext after the import is done.
+  // However, if the importation fails, it will be left as a nullptr.
+  // During the cleanup of the failed import, we should check whether the
+  // DeclContext is null or not - instead of dereferencing that 
unconditionally.
+  constexpr auto ToTUCode = R"(
+  namespace X {
+struct bar {
+  int odr_violation;
+};
+  })";
+  constexpr auto FromTUCode = R"(
+  namespace X {
+enum b {};
+struct bar {
+  typedef b e;
+  static e d;
+};
+  }
+  int z = X::bar::d;
+  )";
+  Decl *ToTU = getToTuDecl(ToTUCode, Lang_CXX11);
+  static_cast(ToTU);
+  Decl *FromTU = getTuDecl(FromTUCode, Lang_CXX11);
+  auto *FromZ =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("z")));
+  ASSERT_TRUE(FromZ);
+  ASSERT_TRUE(FromZ->hasInit());
+
+  auto *ImportedZ = Import(FromZ, Lang_CXX11);
+  EXPECT_FALSE(ImportedZ);
+}
+
 // An error should be set for a class if it had a previous import with an error
 // from another TU.
 TEST_P(ErrorHandlingTest,
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8383,7 +8383,11 @@
   // traverse of the 'to' context).
   auto PosF = ImportedFromDecls.find(ToD);
   if (PosF != ImportedFromDecls.end()) {
-SharedState->removeDeclFromLookup(ToD);
+// In the case of TypedefNameDecl we create the Decl first and only
+// then we import and set its DeclContext. So, the DC might not be set
+// when we reach here.
+if (ToD->getDeclContext())
+  SharedState->removeDeclFromLookup(ToD);
 ImportedFromDecls.erase(PosF);
   }
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5225,6 +5225,40 @@
   EXPECT_TRUE(ImportedOK);
 }
 
+TEST_P(ErrorHandlingTest, ODRViolationWithinTypedefDecls) {
+  // Importing `z` should fail - instead of crashing - due to an ODR violation.
+  // The `bar::e` typedef sets it's DeclContext after the import is done.
+  // However, if the importation fails, it will be left as a nullptr.
+  // During the cleanup of the failed import, we should check whether the
+  // DeclContext is null or not - instead of dereferencing that unconditionally.
+  constexpr auto ToTUCode = R"(
+  namespace X {
+struct bar {
+  int odr_violation;
+};
+  })";
+  constexpr auto FromTUCode = R"(
+  namespace X {
+enum b {};
+struct bar {
+  typedef b e;
+  static e d;
+};
+  }
+  int z = X::bar::d;
+  )";
+  Decl *ToTU = getToTuDecl(ToTUCode, Lang_CXX11);
+  static_cast(ToTU);
+  Decl *FromTU = getTuDecl(FromTUCode, Lang_CXX11);
+  auto *FromZ =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("z")));
+  ASSERT_TRUE(FromZ);
+  ASSERT_TRUE(FromZ->hasInit());
+
+  auto *ImportedZ = Import(FromZ, Lang_CXX11);
+  EXPECT_FALSE(ImportedZ);
+}
+
 // An error should be set for a class if it had a previous import with an error
 // from another TU.
 TEST_P(ErrorHandlingTest,
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8383,7 +8383,11 @@
   // traverse of the 'to' context).
   auto PosF = ImportedFromDecls.find(ToD);
   if (PosF != ImportedFromDecls.end()) {
-SharedState->removeDeclFromLookup(ToD);
+// In the case of TypedefNameDecl we create the Decl first and only
+// then we import and set its DeclContext. So, the DC might not be set
+// when

[PATCH] D91466: [WIP][clang][Fuchsia] Support HWASan for Fuchsia

2021-05-17 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 345931.
leonardchan added a comment.

Update to some feedback from first round of reviews. Minor refactoring of code 
that can be shared between the linux and fuchsia implementations. Still need to 
discuss refactoring the hwasan threads implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91466

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan.cpp
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
  compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
  compiler-rt/lib/hwasan/hwasan_interceptors.cpp
  compiler-rt/lib/hwasan/hwasan_interface_internal.h
  compiler-rt/lib/hwasan/hwasan_linux.cpp
  compiler-rt/lib/hwasan/hwasan_poisoning.cpp
  compiler-rt/lib/hwasan/hwasan_thread.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_fuchsia.h
  compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp

Index: compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
===
--- compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
@@ -54,6 +54,10 @@
   return false;
 }
 
+// This is mainly used by hwasan for online symbolization. This isn't needed
+// since hwasan can always just dump stack frames for offline symbolization.
+bool Symbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { return false; }
+
 // This is used in some places for suppression checking, which we
 // don't really support for Fuchsia.  It's also used in UBSan to
 // identify a PC location to a function name, so we always fill in
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_fuchsia.h
===
--- /dev/null
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_fuchsia.h
@@ -0,0 +1,25 @@
+//===-- sanitizer_platform_limits_fuchsia.h ---===//
+//
+// 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
+//
+//===--===//
+//
+// This file is a part of Sanitizer common code.
+//
+// Sizes and layouts of platform-specific Fuchsia data structures.
+//===--===//
+
+#ifndef SANITIZER_PLATFORM_LIMITS_FUCHSIA_H
+#define SANITIZER_PLATFORM_LIMITS_FUCHSIA_H
+
+#if SANITIZER_FUCHSIA
+
+namespace __sanitizer {
+struct __sanitizer_struct_mallinfo {};
+}  // namespace __sanitizer
+
+#endif  // SANITIZER_FUCHSIA
+
+#endif
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -51,12 +51,18 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
+#if !SANITIZER_FUCHSIA
   uptr tls_size;
   uptr stack_size;
   GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
&tls_size);
   stack_top_ = stack_bottom_ + stack_size;
   tls_end_ = tls_begin_ + tls_size;
+#else
+  __sanitizer::GetThreadStackTopAndBottom(true, &stack_top_,
+  &stack_bottom_);
+  tls_end_ = tls_begin_ = 0;
+#endif
 
   if (stack_bottom_) {
 int local;
Index: compiler-rt/lib/hwasan/hwasan_poisoning.cpp
===
--- compiler-rt/lib/hwasan/hwasan_poisoning.cpp
+++ compiler-rt/lib/hwasan/hwasan_poisoning.cpp
@@ -22,6 +22,10 @@
 uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
   CHECK(IsAligned(p, kShadowAlignment));
   CHECK(IsAligned(size, kShadowAlignment));
+#if SANITIZER_FUCHSIA
+  __sanitizer_fill_shadow(p, size, tag,
+  common_flags()->clear_shadow_mmap_threshold);
+#else
   uptr shadow_start = MemToShadow(p);
   uptr shadow_size = MemToShadowSize(size);
 
@@ -40,6 +44,7 @@
   } else {
 internal_memset((void *)shadow_start, tag, shadow_size);
   }
+#endif
   return AddTagToPointer(p, tag);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -242,18 +242,6 @@
   return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
 }
 
-static void HwasanAtExit(void) {
-  if (common_flags()->print_module_map)
-DumpProcessMap();
-  if (flags()->print_stats && (flags()->atexit || hwasan_report_count > 0))
-ReportStats();
-  if (hwasan

[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad accepted this revision.
cryptoad added a comment.
This revision is now accepted and ready to land.

I think this is good, with the additional arch




Comment at: compiler-rt/cmake/config-ix.cmake:338
 set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
-set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
+set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
 if(APPLE)

${ARM32} as well please


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 345939.
hctim added a comment.

Add arm32 to supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,42 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up 
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[kNumThreads];
-
-void *thread_func(void *arg

[PATCH] D102547: [clang][AVR] Redefine [u]int16_t to be compatible with avr-gcc

2021-05-17 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


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

https://reviews.llvm.org/D102547

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


[PATCH] D102568: [Driver] Delete -mimplicit-it=

2021-05-17 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.

Seems fine to me; the only reference in all of Android that looks problematic 
might be building libaom for windows: 
https://android.googlesource.com/platform/external/libaom/+/refs/heads/master/libaom/build/cmake/aom_configure.cmake#158,
 which I don't think we do for Android. Should be an easy fix either way 
(replace `-mimplicit-it=always` with `-Wa,-wmimplicit-it=always`). The linux 
kernel already uses `-Wa,-mimplicit-it`. Also, GCC rejects the option: 
https://godbolt.org/z/8rxjY9dPj.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102568

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


  1   2   >