[PATCH] D113359: [Libomptarget][WIP] Introduce VGPU Plugin

2021-11-10 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 386426.
atmnpatel added a comment.

small nit fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113359

Files:
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Frontend/OpenMP/OMPGridValues.h
  llvm/lib/Support/Triple.cpp
  openmp/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/Mapping.cpp
  openmp/libomptarget/DeviceRTL/src/Misc.cpp
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
  openmp/libomptarget/DeviceRTL/src/Utils.cpp
  openmp/libomptarget/plugins/CMakeLists.txt
  openmp/libomptarget/plugins/vgpu/CMakeLists.txt
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironment.cpp
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironment.h
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironmentImpl.h
  openmp/libomptarget/plugins/vgpu/src/rtl.cpp
  openmp/libomptarget/src/rtl.cpp

Index: openmp/libomptarget/src/rtl.cpp
===
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -30,6 +30,7 @@
 /* SX-Aurora VE target  */ "libomptarget.rtl.ve.so",
 /* AMDGPU target*/ "libomptarget.rtl.amdgpu.so",
 /* Remote target*/ "libomptarget.rtl.rpc.so",
+/* Virtual GPU target   */ "libomptarget.rtl.vgpu.so",
 };
 
 PluginManager *PM;
@@ -79,7 +80,13 @@
   // is correct and if they are supporting any devices.
   for (auto *Name : RTLNames) {
 DP("Loading library '%s'...\n", Name);
-void *dynlib_handle = dlopen(Name, RTLD_NOW);
+
+int Flags = RTLD_NOW;
+
+if (strcmp(Name, "libomptarget.rtl.vgpu.so") == 0)
+  Flags |= RTLD_GLOBAL;
+
+void *dynlib_handle = dlopen(Name, Flags);
 
 if (!dynlib_handle) {
   // Library does not exist or cannot be found.
Index: openmp/libomptarget/plugins/vgpu/src/rtl.cpp
===
--- /dev/null
+++ openmp/libomptarget/plugins/vgpu/src/rtl.cpp
@@ -0,0 +1,623 @@
+//===--RTLs/vgpu/src/rtl.cpp - Target RTLs Implementation - C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// RTL for virtual (x86) GPU
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "Debug.h"
+#include "ThreadEnvironment.h"
+#include "ThreadEnvironmentImpl.h"
+#include "omptarget.h"
+#include "omptargetplugin.h"
+
+#ifndef TARGET_NAME
+#define TARGET_NAME Generic ELF - 64bit
+#endif
+#define DEBUG_PREFIX "TARGET " GETNAME(TARGET_NAME) " RTL"
+
+#ifndef TARGET_ELF_ID
+#define TARGET_ELF_ID 0
+#endif
+
+#include "elf_common.h"
+
+#define NUMBER_OF_DEVICES 1
+#define OFFLOADSECTIONNAME "omp_offloading_entries"
+
+#define DEBUG false
+
+/// Array of Dynamic libraries loaded for this target.
+struct DynLibTy {
+  char *FileName;
+  void *Handle;
+};
+
+/// Keep entries table per device.
+struct FuncOrGblEntryTy {
+  __tgt_target_table Table;
+};
+
+thread_local ThreadEnvironmentTy *ThreadEnvironment;
+
+/// Class containing all the device information.
+class RTLDeviceInfoTy {
+  std::vector> FuncGblEntries;
+
+public:
+  std::list DynLibs;
+
+  // Record entry point associated with device.
+  void createOffloadTable(int32_t device_id, __tgt_offload_entry *begin,
+  __tgt_offload_entry *end) {
+assert(device_id < (int32_t)FuncGblEntries.size() &&
+   "Unexpected device id!");
+FuncGblEntries[device_id].emplace_back();
+FuncOrGblEntryTy  = FuncGblEntries[device_id].back();
+
+E.Table.EntriesBegin = begin;
+E.Table.EntriesEnd = end;
+  }
+
+  // Return true if the entry is associated with device.
+  bool findOffloadEntry(int32_t device_id, void *addr) {
+assert(device_id < (int32_t)FuncGblEntries.size() &&
+   "Unexpected device id!");
+FuncOrGblEntryTy  = FuncGblEntries[device_id].back();
+
+for (__tgt_offload_entry *i = E.Table.EntriesBegin, *e = E.Table.EntriesEnd;
+ i < e; ++i) {
+  if (i->addr == addr)
+return true;
+}
+
+return false;
+  }
+
+  // Return the pointer to the target entries table.
+  __tgt_target_table *getOffloadEntriesTable(int32_t 

[PATCH] D113359: [Libomptarget][WIP] Introduce VGPU Plugin

2021-11-10 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 386425.
atmnpatel added a comment.

I removed the shared var opt - might be best to keep this in a separate patch 
@tianshilei1992. Also addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113359

Files:
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Frontend/OpenMP/OMPGridValues.h
  llvm/lib/Support/Triple.cpp
  openmp/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/Mapping.cpp
  openmp/libomptarget/DeviceRTL/src/Misc.cpp
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
  openmp/libomptarget/DeviceRTL/src/Utils.cpp
  openmp/libomptarget/plugins/CMakeLists.txt
  openmp/libomptarget/plugins/vgpu/CMakeLists.txt
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironment.cpp
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironment.h
  openmp/libomptarget/plugins/vgpu/src/ThreadEnvironmentImpl.h
  openmp/libomptarget/plugins/vgpu/src/rtl.cpp
  openmp/libomptarget/src/rtl.cpp

Index: openmp/libomptarget/src/rtl.cpp
===
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -30,6 +30,7 @@
 /* SX-Aurora VE target  */ "libomptarget.rtl.ve.so",
 /* AMDGPU target*/ "libomptarget.rtl.amdgpu.so",
 /* Remote target*/ "libomptarget.rtl.rpc.so",
+/* Virtual GPU target   */ "libomptarget.rtl.vgpu.so",
 };
 
 PluginManager *PM;
@@ -79,7 +80,7 @@
   // is correct and if they are supporting any devices.
   for (auto *Name : RTLNames) {
 DP("Loading library '%s'...\n", Name);
-void *dynlib_handle = dlopen(Name, RTLD_NOW);
+void *dynlib_handle = dlopen(Name, RTLD_NOW | RTLD_GLOBAL);
 
 if (!dynlib_handle) {
   // Library does not exist or cannot be found.
Index: openmp/libomptarget/plugins/vgpu/src/rtl.cpp
===
--- /dev/null
+++ openmp/libomptarget/plugins/vgpu/src/rtl.cpp
@@ -0,0 +1,623 @@
+//===--RTLs/vgpu/src/rtl.cpp - Target RTLs Implementation - C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// RTL for virtual (x86) GPU
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "Debug.h"
+#include "ThreadEnvironment.h"
+#include "ThreadEnvironmentImpl.h"
+#include "omptarget.h"
+#include "omptargetplugin.h"
+
+#ifndef TARGET_NAME
+#define TARGET_NAME Generic ELF - 64bit
+#endif
+#define DEBUG_PREFIX "TARGET " GETNAME(TARGET_NAME) " RTL"
+
+#ifndef TARGET_ELF_ID
+#define TARGET_ELF_ID 0
+#endif
+
+#include "elf_common.h"
+
+#define NUMBER_OF_DEVICES 1
+#define OFFLOADSECTIONNAME "omp_offloading_entries"
+
+#define DEBUG false
+
+/// Array of Dynamic libraries loaded for this target.
+struct DynLibTy {
+  char *FileName;
+  void *Handle;
+};
+
+/// Keep entries table per device.
+struct FuncOrGblEntryTy {
+  __tgt_target_table Table;
+};
+
+thread_local ThreadEnvironmentTy *ThreadEnvironment;
+
+/// Class containing all the device information.
+class RTLDeviceInfoTy {
+  std::vector> FuncGblEntries;
+
+public:
+  std::list DynLibs;
+
+  // Record entry point associated with device.
+  void createOffloadTable(int32_t device_id, __tgt_offload_entry *begin,
+  __tgt_offload_entry *end) {
+assert(device_id < (int32_t)FuncGblEntries.size() &&
+   "Unexpected device id!");
+FuncGblEntries[device_id].emplace_back();
+FuncOrGblEntryTy  = FuncGblEntries[device_id].back();
+
+E.Table.EntriesBegin = begin;
+E.Table.EntriesEnd = end;
+  }
+
+  // Return true if the entry is associated with device.
+  bool findOffloadEntry(int32_t device_id, void *addr) {
+assert(device_id < (int32_t)FuncGblEntries.size() &&
+   "Unexpected device id!");
+FuncOrGblEntryTy  = FuncGblEntries[device_id].back();
+
+for (__tgt_offload_entry *i = E.Table.EntriesBegin, *e = E.Table.EntriesEnd;
+ i < e; ++i) {
+  if (i->addr == addr)
+return true;
+}
+
+return false;
+  }
+
+  // Return the pointer to the target entries table.
+  __tgt_target_table *getOffloadEntriesTable(int32_t 

[PATCH] D113647: [X86] Honor command line features along with cpu_specific attribute

2021-11-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: andrew.w.kaylor, erichkeane, pengfei.
craig.topper requested review of this revision.
Herald added a project: clang.

If the feature is on the command line we should honor it for all
functions. I don't think we could reliably target a single function
for a less capable processor than what the rest of the program is
compiled for.

Fixes PR52407.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113647

Files:
  clang/lib/AST/ASTContext.cpp


Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11759,6 +11759,9 @@
 Target->getCPUSpecificCPUDispatchFeatures(
 SD->getCPUName(GD.getMultiVersionIndex())->getName(), FeaturesTmp);
 std::vector Features(FeaturesTmp.begin(), FeaturesTmp.end());
+Features.insert(Features.begin(),
+Target->getTargetOpts().FeaturesAsWritten.begin(),
+Target->getTargetOpts().FeaturesAsWritten.end());
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else {
 FeatureMap = Target->getTargetOpts().FeatureMap;


Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11759,6 +11759,9 @@
 Target->getCPUSpecificCPUDispatchFeatures(
 SD->getCPUName(GD.getMultiVersionIndex())->getName(), FeaturesTmp);
 std::vector Features(FeaturesTmp.begin(), FeaturesTmp.end());
+Features.insert(Features.begin(),
+Target->getTargetOpts().FeaturesAsWritten.begin(),
+Target->getTargetOpts().FeaturesAsWritten.end());
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else {
 FeatureMap = Target->getTargetOpts().FeatureMap;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113645: [clangd] Allow Unix config paths on Darwin

2021-11-10 Thread Keith Smiley via Phabricator via cfe-commits
keith created this revision.
Herald added subscribers: dexonsmith, usaxena95, kadircet, arphaman, hiraditya.
keith requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits, MaskRay, ilya-biryukov.
Herald added projects: LLVM, clang-tools-extra.

It's common for CLIs on macOS to read configuration files from more
unix-standard directories with either dotfiles directly in ~ or files in
~/.config. Previously macOS clangd configuration only read from
~/Library/Preferences on macOS, now it respects the other Unix
directories with XDG_CONFIG_HOME or just ~/.config as a fallback. This
is implemented by changing user_config_directory to
user_config_directories which sets a vector of paths to search,
maintaining the previous order of operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113645

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -509,9 +509,10 @@
 TEST(Support, ConfigDirectoryWithEnv) {
   WithEnv Env("XDG_CONFIG_HOME", "/xdg/config");
 
-  SmallString<128> ConfigDir;
-  EXPECT_TRUE(path::user_config_directory(ConfigDir));
-  EXPECT_EQ("/xdg/config", ConfigDir);
+  std::vector ConfigDirs;
+  EXPECT_TRUE(path::user_config_directories(ConfigDirs));
+  std::vector Expected = {"/xdg/config"};
+  EXPECT_EQ(Expected, ConfigDirs);
 }
 
 TEST(Support, ConfigDirectoryNoEnv) {
@@ -521,9 +522,10 @@
   ASSERT_TRUE(path::home_directory(Fallback));
   path::append(Fallback, ".config");
 
-  SmallString<128> CacheDir;
-  EXPECT_TRUE(path::user_config_directory(CacheDir));
-  EXPECT_EQ(Fallback, CacheDir);
+  std::vector ConfigDirs;
+  EXPECT_TRUE(path::user_config_directories(ConfigDirs));
+  std::vector Expected = {std::string(Fallback)};
+  EXPECT_EQ(Expected, ConfigDirs);
 }
 
 TEST(Support, CacheDirectoryWithEnv) {
@@ -549,13 +551,41 @@
 
 #ifdef __APPLE__
 TEST(Support, ConfigDirectory) {
-  SmallString<128> Fallback;
-  ASSERT_TRUE(path::home_directory(Fallback));
-  path::append(Fallback, "Library/Preferences");
+  WithEnv Env("XDG_CONFIG_HOME", nullptr);
 
-  SmallString<128> ConfigDir;
-  EXPECT_TRUE(path::user_config_directory(ConfigDir));
-  EXPECT_EQ(Fallback, ConfigDir);
+  SmallString<128> HomerDir;
+  ASSERT_TRUE(path::home_directory(HomerDir));
+
+  SmallString<128> Preferences = HomerDir;
+  path::append(Preferences, "Library/Preferences");
+
+  SmallString<128> ConfigDir = HomerDir;
+  path::append(ConfigDir, ".config");
+
+  std::vector ConfigDirs;
+  EXPECT_TRUE(path::user_config_directories(ConfigDirs));
+  std::vector Expected = {std::string(Preferences),
+   std::string(ConfigDir)};
+  EXPECT_TRUE(Expected == ConfigDirs);
+}
+
+TEST(Support, XDGConfigDirectory) {
+  WithEnv Env("XDG_CONFIG_HOME", "/xdg/config");
+
+  SmallString<128> HomerDir;
+  ASSERT_TRUE(path::home_directory(HomerDir));
+
+  SmallString<128> Preferences = HomerDir;
+  path::append(Preferences, "Library/Preferences");
+
+  SmallString<128> ConfigDir = HomerDir;
+  path::append(ConfigDir, ".config");
+
+  std::vector ConfigDirs;
+  EXPECT_TRUE(path::user_config_directories(ConfigDirs));
+  std::vector Expected = {std::string(Preferences), "/xdg/config",
+   std::string(ConfigDir)};
+  EXPECT_TRUE(Expected == ConfigDirs);
 }
 #endif
 
Index: llvm/lib/Support/Windows/Path.inc
===
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -1434,10 +1434,13 @@
   return getKnownFolderPath(FOLDERID_Profile, result);
 }
 
-bool user_config_directory(SmallVectorImpl ) {
+bool user_config_directories(std::vector ) {
   // Either local or roaming appdata may be suitable in some cases, depending
   // on the data. Local is more conservative, Roaming may not always be correct.
-  return getKnownFolderPath(FOLDERID_LocalAppData, result);
+  SmallString result;
+  bool found = getKnownFolderPath(FOLDERID_LocalAppData, );
+  results.push_back(result.c_str());
+  return found;
 }
 
 bool cache_directory(SmallVectorImpl ) {
Index: llvm/lib/Support/Unix/Path.inc
===
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -1363,27 +1363,34 @@
   return false;
 }
 
-bool user_config_directory(SmallVectorImpl ) {
+bool user_config_directories(std::vector ) {
+  bool found = false;
+  SmallString<128> result;
 #ifdef __APPLE__
   // Mac: ~/Library/Preferences/
   if (home_directory(result)) {
 append(result, "Library", "Preferences");
-return true;
+results.push_back(result.c_str());
+found = true;
   }
-#else
+#endif
+
   

[PATCH] D109051: Use Component in OpenBSD::getCompilerRT to find libraries

2021-11-10 Thread Greg Steuck via Phabricator via cfe-commits
blackgnezdo added a comment.

I reformatted with clang-format to address the lint complaint.


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

https://reviews.llvm.org/D109051

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


[PATCH] D109051: Use Component in OpenBSD::getCompilerRT to find libraries

2021-11-10 Thread Greg Steuck via Phabricator via cfe-commits
blackgnezdo updated this revision to Diff 386414.

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

https://reviews.llvm.org/D109051

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


Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -324,12 +325,21 @@
   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 }
 
-std::string OpenBSD::getCompilerRT(const ArgList ,
-   StringRef Component,
+std::string OpenBSD::getCompilerRT(const ArgList , StringRef Component,
FileType Type) const {
-  SmallString<128> Path(getDriver().SysRoot);
-  llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
-  return std::string(Path.str());
+  if (Component == "builtins") {
+SmallString<128> Path(getDriver().SysRoot);
+llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
+return std::string(Path.str());
+  }
+  SmallString<128> P(getDriver().ResourceDir);
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  llvm::sys::path::append(P, "lib", CRTBasename);
+  // Checks if this is the base system case which uses a different location.
+  if (getVFS().exists(P))
+return std::string(P.str());
+  return ToolChain::getCompilerRT(Args, Component, Type);
 }
 
 Tool *OpenBSD::buildAssembler() const {


Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -324,12 +325,21 @@
   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 }
 
-std::string OpenBSD::getCompilerRT(const ArgList ,
-   StringRef Component,
+std::string OpenBSD::getCompilerRT(const ArgList , StringRef Component,
FileType Type) const {
-  SmallString<128> Path(getDriver().SysRoot);
-  llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
-  return std::string(Path.str());
+  if (Component == "builtins") {
+SmallString<128> Path(getDriver().SysRoot);
+llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a");
+return std::string(Path.str());
+  }
+  SmallString<128> P(getDriver().ResourceDir);
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  llvm::sys::path::append(P, "lib", CRTBasename);
+  // Checks if this is the base system case which uses a different location.
+  if (getVFS().exists(P))
+return std::string(P.str());
+  return ToolChain::getCompilerRT(Args, Component, Type);
 }
 
 Tool *OpenBSD::buildAssembler() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113642: [PowerPC] Provide XL-compatible vec_round implementation

2021-11-10 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai created this revision.
nemanjai added reviewers: PowerPC, rzurob, qiongsiwu.
Herald added subscribers: shchenz, kbarton, hiraditya.
nemanjai requested review of this revision.
Herald added projects: clang, LLVM.

The XL implementation of `vec_round` for `vector double` uses 
"round-to-nearest, ties to even" just as the `vector float` version does. 
However clang and gcc use "round-to-nearest-away" for `vector double` and 
"round-to-nearest, ties to even" for `vector float`.

The XL behaviour is implemented under the `__XL_COMPAT_ALTIVEC__` macro 
similarly to other instances of incompatibility.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113642

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-vsx.c
  clang/test/CodeGen/builtins-ppc-xlcompat.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/read-set-flm.ll

Index: llvm/test/CodeGen/PowerPC/read-set-flm.ll
===
--- llvm/test/CodeGen/PowerPC/read-set-flm.ll
+++ llvm/test/CodeGen/PowerPC/read-set-flm.ll
@@ -11,7 +11,6 @@
 ; CHECK-NEXT:xsdivdp 1, 1, 2
 ; CHECK-NEXT:xsadddp 1, 1, 3
 ; CHECK-NEXT:xsadddp 0, 1, 0
-; CHECK-NEXT:mffs 1
 ; CHECK-NEXT:mtfsf 255, 4
 ; CHECK-NEXT:xsdivdp 1, 3, 4
 ; CHECK-NEXT:xsadddp 1, 1, 2
@@ -47,7 +46,6 @@
 ; CHECK-NEXT:xsdivdp 1, 1, 2
 ; CHECK-NEXT:xsadddp 1, 1, 3
 ; CHECK-NEXT:xsadddp 0, 1, 0
-; CHECK-NEXT:mffs 1
 ; CHECK-NEXT:mtfsf 255, 4
 ; CHECK-NEXT:xsdivdp 1, 3, 4
 ; CHECK-NEXT:xsadddp 1, 1, 2
@@ -96,7 +94,6 @@
 ; CHECK-NEXT:nop
 ; CHECK-NEXT:mffs 0
 ; CHECK-NEXT:stfd 0, 0(30)
-; CHECK-NEXT:mffs 0
 ; CHECK-NEXT:mtfsf 255, 31
 ; CHECK-NEXT:addi 1, 1, 64
 ; CHECK-NEXT:ld 0, 16(1)
@@ -134,7 +131,6 @@
 ; CHECK-NEXT:nop
 ; CHECK-NEXT:mffs 0
 ; CHECK-NEXT:stfd 0, 0(30)
-; CHECK-NEXT:mffs 0
 ; CHECK-NEXT:mtfsf 255, 31
 ; CHECK-NEXT:addi 1, 1, 64
 ; CHECK-NEXT:ld 0, 16(1)
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -12122,6 +12122,7 @@
   MachineFunction::iterator It = ++BB->getIterator();
 
   MachineFunction *F = BB->getParent();
+  MachineRegisterInfo  = F->getRegInfo();
 
   if (MI.getOpcode() == PPC::SELECT_CC_I4 ||
   MI.getOpcode() == PPC::SELECT_CC_I8 || MI.getOpcode() == PPC::SELECT_I4 ||
@@ -12727,7 +12728,10 @@
 Register OldFPSCRReg = MI.getOperand(0).getReg();
 
 // Save FPSCR value.
-BuildMI(*BB, MI, dl, TII->get(PPC::MFFS), OldFPSCRReg);
+if (MRI.use_empty(OldFPSCRReg))
+  BuildMI(*BB, MI, dl, TII->get(TargetOpcode::IMPLICIT_DEF), OldFPSCRReg);
+else
+  BuildMI(*BB, MI, dl, TII->get(PPC::MFFS), OldFPSCRReg);
 
 // The floating point rounding mode is in the bits 62:63 of FPCSR, and has
 // the following settings:
@@ -12860,7 +12864,10 @@
 
 // Result of setflm is previous FPSCR content, so we need to save it first.
 Register OldFPSCRReg = MI.getOperand(0).getReg();
-BuildMI(*BB, MI, Dl, TII->get(PPC::MFFS), OldFPSCRReg);
+if (MRI.use_empty(OldFPSCRReg))
+  BuildMI(*BB, MI, Dl, TII->get(TargetOpcode::IMPLICIT_DEF), OldFPSCRReg);
+else
+  BuildMI(*BB, MI, Dl, TII->get(PPC::MFFS), OldFPSCRReg);
 
 // Put bits in 32:63 to FPSCR.
 Register NewFPSCRReg = MI.getOperand(1).getReg();
Index: clang/test/CodeGen/builtins-ppc-xlcompat.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat.c
@@ -5,11 +5,16 @@
 // RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
 // RUN:   -triple powerpc64le-unknown-linux-gnu -emit-llvm %s -o - \
 // RUN:   -D__XL_COMPAT_ALTIVEC__ -target-cpu pwr8 | FileCheck %s
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -triple powerpc64le-unknown-linux-gnu -emit-llvm %s -o - \
+// RUN:   -U__XL_COMPAT_ALTIVEC__ -target-cpu pwr8 | FileCheck \
+// RUN:   --check-prefix=NOCOMPAT %s
 #include 
 vector double vd = { 3.4e22, 1.8e-3 };
 vector signed long long vsll = { -12345678999ll, 12345678999 };
 vector unsigned long long vull = { 11547229456923630743llu, 18014402265226391llu };
 vector float res_vf;
+vector double res_vd;
 vector signed int res_vsi;
 vector unsigned int res_vui;
 
@@ -38,4 +43,11 @@
 // CHECK: [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP8]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+
+  res_vd = vec_round(vd);
+// CHECK: call double @llvm.ppc.readflm()
+// CHECK: call double @llvm.ppc.setrnd(i32 0)
+// CHECK: call <2 x double> @llvm.rint.v2f64(<2 x double>
+// CHECK: call double @llvm.ppc.setflm(double
+// NOCOMPAT:  

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

2021-11-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Awesome!




Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:559
+  // Get the resolved template arguments from the canonical type.
+  // FIXME: Handle the as-written arguments so the sugar is not lost.
+  ArrayRef PResolved =

Does this matter on the `P` side? (Can we remove this FIXME?)



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:561
+  ArrayRef PResolved =
+  TP->getCanonicalTypeInternal()
+  ->castAs()

Can we avoid using the `Internal` version here? (The only difference is whether 
we preserve top-level qualifiers that are outside any type sugar.)

Might also be worth a comment here explaining that we're going to the canonical 
type first here to step over any alias templates.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:571-573
+  // FIXME: Should not lose sugar here.
+  if (const auto *SA = dyn_cast(
+  UA->getCanonicalTypeInternal())) {

I think we can retain type sugar here without too much effort.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:573
+  if (const auto *SA = dyn_cast(
+  UA->getCanonicalTypeInternal())) {
 // Perform template argument deduction for the template name.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110216

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


[PATCH] D111477: DO NOT SUBMIT: workaround for context-sensitive use of non-type-template-parameter integer suffixes

2021-11-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a subscriber: rsmith.
dblaikie added a comment.

Some offline post-commit feedback from @rsmith - Rename printing policy to 
match closer to the function it's tested in. Will think about that, check the 
function name, etc, and commit a patch in the next few days, hopefully.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111477

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


[PATCH] D113638: [xray] Add support for hexagon architecture

2021-11-10 Thread Brian Cain via Phabricator via cfe-commits
androm3da added a comment.

This patch spans several areas, so I would be happy to decompose it into 
smaller parts if it made it easier for reviewers.




Comment at: compiler-rt/lib/xray/xray_hexagon.cpp:76-84
+static void WriteInstFlushCache(void *Addr, uint32_t NewInstruction) {
+  asm volatile("icinva(%[inst_addr])\n\t"
+   "isync\n\t"
+   "memw(%[inst_addr]) = %[new_inst]\n\t"
+   "dccleaninva(%[inst_addr])\n\t"
+   "syncht\n\t"
+   :

If we need to support cases where the entire sled spans cache lines, then we 
must iterate over the icinva() instead.




Comment at: compiler-rt/lib/xray/xray_hexagon.cpp:76-84
+static void WriteInstFlushCache(void *Addr, uint32_t NewInstruction) {
+  asm volatile("icinva(%[inst_addr])\n\t"
+   "isync\n\t"
+   "memw(%[inst_addr]) = %[new_inst]\n\t"
+   "dccleaninva(%[inst_addr])\n\t"
+   "syncht\n\t"
+   :

androm3da wrote:
> If we need to support cases where the entire sled spans cache lines, then we 
> must iterate over the icinva() instead.
> 
Other arches do atomic stores.  I think we will need to change this to: LL 
first, then icinva/isync, then SC.  

If the SC fails then either we re-run all those steps because we want to 
clobber it or we do nothing because we assume some other thread applied the 
same patch first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113638

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


[PATCH] D110898: Pass template parameters when printing template argument lists for function templates

2021-11-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie abandoned this revision.
dblaikie added a comment.

Talked to Richard offline - this is undesirable because it would mean that 
certain template overloads would not be disambiguated in their naming. I'll 
post a patch with a test case that demonstrates that desired behavior and 
abandon this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110898

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


[PATCH] D113638: [xray] Add support for hexagon architecture

2021-11-10 Thread Brian Cain via Phabricator via cfe-commits
androm3da created this revision.
androm3da added reviewers: dberris, kparzysz.
Herald added subscribers: hiraditya, mgorny.
androm3da requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Adds x-ray support for hexagon to llvm codegen, clang driver, compiler-rt libs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113638

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_hexagon.cpp
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_trampoline_hexagon.S
  compiler-rt/lib/xray/xray_tsc.h
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
  llvm/lib/Target/Hexagon/HexagonAsmPrinter.h
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/lib/Target/Hexagon/HexagonInstrInfo.h
  llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
  llvm/lib/Target/Hexagon/HexagonSubtarget.h
  llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
  llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
  llvm/test/CodeGen/Hexagon/xray.ll

Index: llvm/test/CodeGen/Hexagon/xray.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Hexagon/xray.ll
@@ -0,0 +1,29 @@
+; RUN: llc -filetype=asm -o - -mtriple=hexagon-unknown-elf < %s | FileCheck %s
+; RUN: llc -filetype=asm -o - -mtriple=hexagon-unknown-linux-musl  < %s | FileCheck %s
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: .Lxray_sled_0:
+; CHECK:   jump .Ltmp0
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK-LABEL: .Ltmp0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_1:
+; CHECK:   jump .Ltmp1
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK: nop
+; CHECK-LABEL: .Ltmp1:
+; CHECK:   jumpr r31
+}
+; CHECK-LABEL: xray_instr_map
+; CHECK-LABEL: .Lxray_sleds_start0:
+; CHECK:   .word {{.*}}Lxray_sled_0
+; CHECK:   .word {{.*}}Lxray_sled_1
+; CHECK-LABEL: .Lxray_sleds_end0:
+; CHECK-LABEL: xray_fn_idx
+; CHECK:   .word {{.*}}Lxray_sleds_start0
+; CHECK-NEXT:  .word {{.*}}Lxray_sleds_end0
Index: llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Hexagon/xray-pred-ret.ll
@@ -0,0 +1,27 @@
+; RUN: llc -filetype=asm -o - -mtriple=hexagon-unknown-linux-musl < %s | FileCheck %s
+
+define void @Foo(i32 signext %a, i32 signext %b) #0 {
+; CHECK-LABEL: @Foo
+; CHECK-LABEL: .Lxray_sled_0:
+; CHECK:jump .Ltmp0
+; CHECK-COUNT-4: nop
+entry:
+  %cmp = icmp sgt i32 %a, %b
+  br i1 %cmp, label %return, label %if.end
+
+; CHECK-LABEL: .Lxray_sled_1:
+; CHECK:jump .Ltmp1
+; CHECK-COUNT-4: nop
+; CHECK-LABEL: .Ltmp1:
+; CHECK:   if (p0) jumpr:nt r31
+if.end:
+  tail call void @Bar()
+  br label %return
+
+return:
+  ret void
+}
+
+declare void @Bar()
+
+attributes #0 = { "function-instrument"="xray-always" }
Index: llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
===
--- llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
+++ llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
@@ -1082,6 +1082,11 @@
   if (HII->isSolo(MI))
 return true;
 
+  if (MI.getOpcode() == Hexagon::PATCHABLE_FUNCTION_ENTER ||
+  MI.getOpcode() == Hexagon::PATCHABLE_FUNCTION_EXIT ||
+  MI.getOpcode() == Hexagon::PATCHABLE_TAIL_CALL)
+return true;
+
   if (MI.getOpcode() == Hexagon::A2_nop)
 return true;
 
Index: llvm/lib/Target/Hexagon/HexagonSubtarget.h
===
--- llvm/lib/Target/Hexagon/HexagonSubtarget.h
+++ llvm/lib/Target/Hexagon/HexagonSubtarget.h
@@ -138,6 +138,8 @@
   /// subtarget options.  Definition of function is auto generated by tblgen.
   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
 
+  bool isXRaySupported() const override { return true; }
+
   bool hasV5Ops() const {
 return getHexagonArchVersion() >= Hexagon::ArchEnum::V5;
   }
Index: llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
===
--- llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
+++ llvm/lib/Target/Hexagon/HexagonMCInstLower.cpp
@@ -104,6 +104,19 @@
 HexagonMCInstrInfo::setOuterLoop(MCB);
 return;
   }
+  if (MI->getOpcode() == Hexagon::PATCHABLE_FUNCTION_ENTER) {
+AP.EmitSled(*MI, HexagonAsmPrinter::SledKind::FUNCTION_ENTER);
+return;
+  }
+  if (MI->getOpcode() == Hexagon::PATCHABLE_FUNCTION_EXIT) {
+AP.EmitSled(*MI, HexagonAsmPrinter::SledKind::FUNCTION_EXIT);
+return;
+  }
+  if (MI->getOpcode() == Hexagon::PATCHABLE_TAIL_CALL) {
+AP.EmitSled(*MI, 

[PATCH] D112915: [clang][modules] Track number of includes per submodule

2021-11-10 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

As we've discussed earlier, tracking `isImport` shouldn't be done per .pcm and 
here is the test case 
https://gist.github.com/vsapsai/a2d2bd19c54c24540495fd9b262106aa I'm not sure 
it is worth adding the second `#include` as the test fails just with one.

Overall, the change seems more complicated than it has to be. I need to check 
it carefully to see what can be simplified. And I need to check in debugger how 
and when AST reading is triggered. Looks like not all of that is lazy but I 
need to check the compiled code, not my guesses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112915

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


[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-11-10 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

In D106585#3122726 , @glandium wrote:

> It seems to have been fixed in rG3c47c5ca13b8a502de3272e8105548715947b7a8 
> .

Actually, there are some remaining cases not covered by that. I'm trying to 
produce a small reproducer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D113636: format_arg attribute does not support nullable instancetype return type

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

Following up with D112670 , it appears that 
the original fix was insufficient: it's not possible to use 
`__attribute__((format_arg))` on methods that return `instancetype` in 
`NSString` when `instancetype` is sugared, as this breaks pointer equality. 
Although this is only possible in limited scenarios because `instancetype` is a 
contextual keyword, it can (crucially) be combined with nullability qualifiers.

rdar://85278860


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113636

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


Index: clang/test/SemaObjC/format-arg-attribute.m
===
--- clang/test/SemaObjC/format-arg-attribute.m
+++ clang/test/SemaObjC/format-arg-attribute.m
@@ -2,7 +2,10 @@
 
 @interface NSString
 +(instancetype)stringWithCString:(const char *)cstr 
__attribute__((format_arg(1)));
-+(instancetype)stringWithString:(NSString *)cstr 
__attribute__((format_arg(1)));
+-(instancetype)initWithString:(NSString *)str __attribute__((format_arg(1)));
+
++(instancetype _Nonnull)nonNullableString:(NSString *)str 
__attribute__((format_arg(1)));
++(instancetype _Nullable)nullableString:(NSString *)str 
__attribute__((format_arg(1)));
 @end
 
 @protocol MaybeString
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3389,7 +3389,8 @@
   }
   Ty = getFunctionOrMethodResultType(D);
   // replace instancetype with the class type
-  if (Ty.getTypePtr() == S.Context.getObjCInstanceTypeDecl()->getTypeForDecl())
+  auto Instancetype = S.Context.getObjCInstanceTypeDecl()->getTypeForDecl();
+  if (Ty->getAs() == Instancetype)
 if (auto *OMD = dyn_cast(D))
   if (auto *Interface = OMD->getClassInterface())
 Ty = S.Context.getObjCObjectPointerType(


Index: clang/test/SemaObjC/format-arg-attribute.m
===
--- clang/test/SemaObjC/format-arg-attribute.m
+++ clang/test/SemaObjC/format-arg-attribute.m
@@ -2,7 +2,10 @@
 
 @interface NSString
 +(instancetype)stringWithCString:(const char *)cstr __attribute__((format_arg(1)));
-+(instancetype)stringWithString:(NSString *)cstr __attribute__((format_arg(1)));
+-(instancetype)initWithString:(NSString *)str __attribute__((format_arg(1)));
+
++(instancetype _Nonnull)nonNullableString:(NSString *)str __attribute__((format_arg(1)));
++(instancetype _Nullable)nullableString:(NSString *)str __attribute__((format_arg(1)));
 @end
 
 @protocol MaybeString
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3389,7 +3389,8 @@
   }
   Ty = getFunctionOrMethodResultType(D);
   // replace instancetype with the class type
-  if (Ty.getTypePtr() == S.Context.getObjCInstanceTypeDecl()->getTypeForDecl())
+  auto Instancetype = S.Context.getObjCInstanceTypeDecl()->getTypeForDecl();
+  if (Ty->getAs() == Instancetype)
 if (auto *OMD = dyn_cast(D))
   if (auto *Interface = OMD->getClassInterface())
 Ty = S.Context.getObjCObjectPointerType(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113428: [AIX] Define WCHAR_T_TYPE as unsigned int on 64-bit AIX for wchar.c test

2021-11-10 Thread Jake Egan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9303c7da3967: [AIX] Define WCHAR_T_TYPE as unsigned int on 
64-bit AIX for wchar.c test (authored by Jake-Egan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113428

Files:
  clang/test/Sema/wchar.c


Index: clang/test/Sema/wchar.c
===
--- clang/test/Sema/wchar.c
+++ clang/test/Sema/wchar.c
@@ -14,7 +14,7 @@
   #else
 #define WCHAR_T_TYPE unsigned int
   #endif
-#elif defined(__arm) || defined(__MVS__)
+#elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && 
defined(__64BIT__))
   #define WCHAR_T_TYPE unsigned int
 #elif defined(__sun)
   #if defined(__LP64__)


Index: clang/test/Sema/wchar.c
===
--- clang/test/Sema/wchar.c
+++ clang/test/Sema/wchar.c
@@ -14,7 +14,7 @@
   #else
 #define WCHAR_T_TYPE unsigned int
   #endif
-#elif defined(__arm) || defined(__MVS__)
+#elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && defined(__64BIT__))
   #define WCHAR_T_TYPE unsigned int
 #elif defined(__sun)
   #if defined(__LP64__)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9303c7d - [AIX] Define WCHAR_T_TYPE as unsigned int on 64-bit AIX for wchar.c test

2021-11-10 Thread Jake Egan via cfe-commits

Author: Jake Egan
Date: 2021-11-10T20:46:57-05:00
New Revision: 9303c7da39678dbcf3397da4944bb9b4c6e1ac65

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

LOG: [AIX] Define WCHAR_T_TYPE as unsigned int on 64-bit AIX for wchar.c test

The default wchar type on 64-bit AIX is `unsigned int`, so this patch sets 
`WCHAR_T_TYPE` to `unsigned int` rather than `int`.

This patch follows similar reasoning to D110428 except for 64-bit.

Reviewed By: daltenty

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

Added: 


Modified: 
clang/test/Sema/wchar.c

Removed: 




diff  --git a/clang/test/Sema/wchar.c b/clang/test/Sema/wchar.c
index fff12442ed543..2c88f8db52487 100644
--- a/clang/test/Sema/wchar.c
+++ b/clang/test/Sema/wchar.c
@@ -14,7 +14,7 @@ typedef __WCHAR_TYPE__ wchar_t;
   #else
 #define WCHAR_T_TYPE unsigned int
   #endif
-#elif defined(__arm) || defined(__MVS__)
+#elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && 
defined(__64BIT__))
   #define WCHAR_T_TYPE unsigned int
 #elif defined(__sun)
   #if defined(__LP64__)



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


[PATCH] D113614: Disable clang-repl tests failing due to lack of 64-bit XCOFF support.

2021-11-10 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan accepted this revision.
Jake-Egan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113614

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


[PATCH] D113623: [OpenMP][FIX] Pass the num_threads value directly to parallel_51

2021-11-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: jhuber6, ggeorgakoudis, tianshilei1992, grokos, 
jdenny.
Herald added subscribers: asavonic, guansong, bollu, yaxunl.
jdoerfert requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

The problem with the old scheme is that we would need to keep track of
the "next region" and reset the num_threads value after it. The new RT
doesn't do it and an assertion is triggered. The old RT doesn't do it
either, I haven't tested it but I assume a num_threads clause might
impact multiple parallel regions "accidentally". Further, in SPMD mode
num_threads was simply ignored, for some reason beyond me.

In any case, parallel_51 is designed to take the clause value directly,
so let's do that instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113623

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/omptargeti.h
  openmp/libomptarget/deviceRTLs/common/src/parallel.cu
  openmp/libomptarget/deviceRTLs/interface.h

Index: openmp/libomptarget/deviceRTLs/interface.h
===
--- openmp/libomptarget/deviceRTLs/interface.h
+++ openmp/libomptarget/deviceRTLs/interface.h
@@ -220,8 +220,6 @@
 
 // parallel
 EXTERN int32_t __kmpc_global_thread_num(kmp_Ident *loc);
-EXTERN void __kmpc_push_num_threads(kmp_Ident *loc, int32_t global_tid,
-int32_t num_threads);
 NOINLINE EXTERN uint8_t __kmpc_parallel_level();
 
 // proc bind
@@ -445,7 +443,8 @@
   bool RequiresFullRuntime);
 EXTERN void __kmpc_target_deinit(ident_t *Ident, int8_t Mode,
  bool RequiresFullRuntime);
-EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn);
+EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn,
+   int32_t NumThreadsClause);
 EXTERN bool __kmpc_kernel_parallel(void **WorkFn);
 EXTERN void __kmpc_kernel_end_parallel();
 
Index: openmp/libomptarget/deviceRTLs/common/src/parallel.cu
===
--- openmp/libomptarget/deviceRTLs/common/src/parallel.cu
+++ openmp/libomptarget/deviceRTLs/common/src/parallel.cu
@@ -73,7 +73,8 @@
 }
 
 // This routine is always called by the team master..
-EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn) {
+EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn,
+   kmp_int32 NumThreadsClause) {
   PRINT0(LD_IO, "call to __kmpc_kernel_prepare_parallel\n");
 
   omptarget_nvptx_workFn = WorkFn;
@@ -92,9 +93,6 @@
 return;
   }
 
-  uint16_t  =
-  omptarget_nvptx_threadPrivateContext->NumThreadsForNextParallel(threadId);
-
   uint16_t NumThreads =
   determineNumberOfThreads(NumThreadsClause, nThreads, threadLimit);
 
@@ -255,16 +253,6 @@
 // push params
 
 
-EXTERN void __kmpc_push_num_threads(kmp_Ident *loc, int32_t tid,
-int32_t num_threads) {
-  PRINT(LD_IO, "call kmpc_push_num_threads %d\n", num_threads);
-  ASSERT0(LT_FUSSY, isRuntimeInitialized(),
-  "Runtime must be initialized.");
-  tid = GetLogicalThreadIdInBlock();
-  omptarget_nvptx_threadPrivateContext->NumThreadsForNextParallel(tid) =
-  num_threads;
-}
-
 // Do nothing. The host guarantees we started the requested number of
 // teams and we only need inspection of gridDim.
 
@@ -304,11 +292,7 @@
 return;
   }
 
-  // Handle the num_threads clause.
-  if (num_threads != -1)
-__kmpc_push_num_threads(ident, global_tid, num_threads);
-
-  __kmpc_kernel_prepare_parallel((void *)wrapper_fn);
+  __kmpc_kernel_prepare_parallel((void *)wrapper_fn, num_threads);
 
   if (nargs) {
 void **GlobalArgs;
Index: openmp/libomptarget/deviceRTLs/common/omptargeti.h
===
--- openmp/libomptarget/deviceRTLs/common/omptargeti.h
+++ openmp/libomptarget/deviceRTLs/common/omptargeti.h
@@ -158,8 +158,6 @@
   // levelOneTaskDescr is init when starting the parallel region
   // top task descr is NULL (team master version will be fixed separately)
   topTaskDescr[tid] = NULL;
-  // no num threads value has been pushed
-  nextRegion.tnum[tid] = 0;
   // the following don't need to be init here; they are init when using dyn
   

[PATCH] D113126: [OpenMP][NFCI] Embed the source location string size in the ident_t

2021-11-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D113126#3122659 , @tianshilei1992 
wrote:

> I'm not convinced. `std::strlen` can do the job. Can you explain more why 
> need it?

Because the ident_t is on the device and you want to grab it from the host.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113126

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


[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfddc4e41164e: Correct handling of the throw() 
exception specifier in C++17. (authored by jyknight).

Changed prior to commit:
  https://reviews.llvm.org/D113517?vs=385971=386326#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CXX/except/except.spec/p9-dynamic.cpp


Index: clang/test/CXX/except/except.spec/p9-dynamic.cpp
===
--- clang/test/CXX/except/except.spec/p9-dynamic.cpp
+++ clang/test/CXX/except/except.spec/p9-dynamic.cpp
@@ -1,12 +1,26 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s --check-prefixes=CHECK,CHECK-PRE17
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -std=c++17 
-Wno-dynamic-exception-spec -emit-llvm -o - -fcxx-exceptions -fexceptions | 
FileCheck %s --check-prefixes=CHECK,CHECK-17
 
 void external();
 
+// CHECK-LABEL: _Z6targetv(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:  landingpad { i8*, i32 }
+// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
+// CHECK:  call void @__cxa_call_unexpected
 void target() throw(int)
 {
-  // CHECK: invoke void @_Z8externalv()
   external();
 }
-// CHECK:  landingpad { i8*, i32 }
-// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
-// CHECK:  call void @__cxa_call_unexpected
+
+// CHECK-LABEL: _Z7target2v(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:landingpad { i8*, i32 }
+// CHECK-PRE17-NEXT:   filter [0 x i8*] zeroinitializer
+// CHECK-17-NEXT:  catch i8* null
+// CHECK-PRE17:  call void @__cxa_call_unexpected
+// CHECK-17: call void @__clang_call_terminate
+void target2() throw()
+{
+  external();
+}
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -477,11 +477,11 @@
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
-// noexcept functions are simple terminate scopes.
-if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
-  EHStack.pushTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled in this block, along with
+  // 'throw(X...)'.
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -521,6 +521,10 @@
 /*ForEH=*/true);
   Filter->setFilter(I, EHType);
 }
+  } else if (Proto->canThrow() == CT_Cannot) {
+// noexcept functions are simple terminate scopes.
+if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
+  EHStack.pushTerminate();
   }
 }
 
@@ -580,10 +584,8 @@
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot &&
-  !EHStack.empty() /* possible empty when under async exceptions */) {
-EHStack.popTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -599,6 +601,10 @@
 EHFilterScope  = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();
+  } else if (Proto->canThrow() == CT_Cannot &&
+  /* possible empty when under async exceptions */
+ !EHStack.empty()) {
+EHStack.popTerminate();
   }
 }
 


Index: clang/test/CXX/except/except.spec/p9-dynamic.cpp
===
--- clang/test/CXX/except/except.spec/p9-dynamic.cpp
+++ clang/test/CXX/except/except.spec/p9-dynamic.cpp
@@ -1,12 +1,26 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s --check-prefixes=CHECK,CHECK-PRE17
+// RUN: 

[clang] fddc4e4 - Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2021-11-10T17:40:16-05:00
New Revision: fddc4e41164e2fd152605362639eb3255cc75212

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

LOG: Correct handling of the 'throw()' exception specifier in C++17.

Per C++17 [except.spec], 'throw()' has become equivalent to
'noexcept', and should therefore call std::terminate, not
std::unexpected.

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

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp
clang/test/CXX/except/except.spec/p9-dynamic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 9f65e9eb120cf..aff9c77d53c78 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -477,11 +477,11 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
-// noexcept functions are simple terminate scopes.
-if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
-  EHStack.pushTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled in this block, along with
+  // 'throw(X...)'.
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -521,6 +521,10 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 /*ForEH=*/true);
   Filter->setFilter(I, EHType);
 }
+  } else if (Proto->canThrow() == CT_Cannot) {
+// noexcept functions are simple terminate scopes.
+if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
+  EHStack.pushTerminate();
   }
 }
 
@@ -580,10 +584,8 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot &&
-  !EHStack.empty() /* possible empty when under async exceptions */) {
-EHStack.popTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -599,6 +601,10 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 EHFilterScope  = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();
+  } else if (Proto->canThrow() == CT_Cannot &&
+  /* possible empty when under async exceptions */
+ !EHStack.empty()) {
+EHStack.popTerminate();
   }
 }
 

diff  --git a/clang/test/CXX/except/except.spec/p9-dynamic.cpp 
b/clang/test/CXX/except/except.spec/p9-dynamic.cpp
index 1e7b29479fbdb..ccba71767729e 100644
--- a/clang/test/CXX/except/except.spec/p9-dynamic.cpp
+++ b/clang/test/CXX/except/except.spec/p9-dynamic.cpp
@@ -1,12 +1,26 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s --check-prefixes=CHECK,CHECK-PRE17
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -std=c++17 
-Wno-dynamic-exception-spec -emit-llvm -o - -fcxx-exceptions -fexceptions | 
FileCheck %s --check-prefixes=CHECK,CHECK-17
 
 void external();
 
+// CHECK-LABEL: _Z6targetv(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:  landingpad { i8*, i32 }
+// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
+// CHECK:  call void @__cxa_call_unexpected
 void target() throw(int)
 {
-  // CHECK: invoke void @_Z8externalv()
   external();
 }
-// CHECK:  landingpad { i8*, i32 }
-// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
-// CHECK:  call void @__cxa_call_unexpected
+
+// CHECK-LABEL: _Z7target2v(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:landingpad { i8*, i32 }
+// CHECK-PRE17-NEXT:   filter [0 x i8*] zeroinitializer
+// CHECK-17-NEXT:  catch i8* null
+// CHECK-PRE17:  call void @__cxa_call_unexpected
+// CHECK-17: call void @__clang_call_terminate
+void target2() throw()

[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D113517#3122217 , @rsmith wrote:

> In D113517#3121455 , @jyknight 
> wrote:
>
>> This change allows those future optimizations to apply to throw() as well, 
>> in C++17 mode, which is the desirable outcome.
>
> I see. It seems inconsistent that `throw(X)` would still call `unexpected` 
> but that `throw()` would call `terminate`, but I suppose in the `throw()` 
> case there is really not much interesting that an `unexpected_handler` can do 
> other than (take some logging action and) terminate the program -- in 
> particular, it can't do exception translation. So maybe the inconsistency is 
> not a big deal, and it's more important to get the better code generation, 
> especially given how rare `throw(X)` is compared to `throw()`. OK, I think 
> I'm convinced that this is the best direction.

Well, "throw(X)" is not even permitted by C++17. In Clang, we allow that it 
only if you turn off the default-error warning option. Given that, I'm not too 
worried about it keeping the legacy behavior, while "throw()" gets the new 
behavior.




Comment at: clang/lib/CodeGen/CGException.cpp:480-487
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled separately, below.
+  if ((getLangOpts().CPlusPlus17 || EST != EST_DynamicNone) &&
+  Proto->canThrow() == CT_Cannot) {
 // noexcept functions are simple terminate scopes.
 if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
   EHStack.pushTerminate();

rsmith wrote:
> Maybe the logic would be clearer if we swap the terminate and unexpected 
> cases:
> ```
> if  (EST == EST_Dynamic || (!getLangOpts().CPlusPlus17 && EST == 
> EST_DynamicNone)) {
>   // Prepare to call unexpected
> } else if (Proto->canThrow() == CT_Cannot) {
>   // Prepare to call terminate
> }
> ```
> This would keep the syntactic checks of `EST` separated from the semantic 
> checks of `canThrow`.
Agreed, that's better. I'll make that change and submit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[PATCH] D113614: Disable clang-repl tests failing due to lack of 64-bit XCOFF support.

2021-11-10 Thread Steven Wan via Phabricator via cfe-commits
stevewan created this revision.
stevewan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The following interpreter tests failed on AIX because 64-bit XCOFF object files 
are currently not supported on AIX. This patch disables the tests on AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113614

Files:
  clang/unittests/Interpreter/InterpreterTest.cpp


Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -145,7 +145,11 @@
   ~LLVMInitRAII() { llvm::llvm_shutdown(); }
 } LLVMInit;
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_FindMangledNameSymbol) {
+#else
 TEST(IncrementalProcessing, FindMangledNameSymbol) {
+#endif
 
   std::unique_ptr Interp = createInterpreter();
 
@@ -201,7 +205,11 @@
   return R.getFoundDecl();
 }
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_InstantiateTemplate) {
+#else
 TEST(IncrementalProcessing, InstantiateTemplate) {
+#endif
   // FIXME: We cannot yet handle delayed template parsing. If we run with
   // -fdelayed-template-parsing we try adding the newly created decl to the
   // active PTU which causes an assert.


Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -145,7 +145,11 @@
   ~LLVMInitRAII() { llvm::llvm_shutdown(); }
 } LLVMInit;
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_FindMangledNameSymbol) {
+#else
 TEST(IncrementalProcessing, FindMangledNameSymbol) {
+#endif
 
   std::unique_ptr Interp = createInterpreter();
 
@@ -201,7 +205,11 @@
   return R.getFoundDecl();
 }
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_InstantiateTemplate) {
+#else
 TEST(IncrementalProcessing, InstantiateTemplate) {
+#endif
   // FIXME: We cannot yet handle delayed template parsing. If we run with
   // -fdelayed-template-parsing we try adding the newly created decl to the
   // active PTU which causes an assert.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112820: Emit hidden hostcall argument for sanitized kernels.

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b3881e9f319: Emit hidden hostcall argument for sanitized 
kernels (authored by yaxunl).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112820

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/amdgpu-asan.cu
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll


Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
@@ -0,0 +1,54 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 
--amdhsa-code-object-version=3 -amdgpu-dump-hsa-metadata 
-amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck  %s
+
+; CHECK:  ---
+; CHECK:  amdhsa.kernels:
+; CHECK:- .args:
+; CHECK-NEXT:   - .name:   a
+; CHECK-NEXT: .offset: 0
+; CHECK-NEXT: .size:   1
+; CHECK-NEXT: .type_name:  char
+; CHECK-NEXT: .value_kind: by_value
+; CHECK-NEXT:   - .offset: 8
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_x
+; CHECK-NEXT:   - .offset: 16
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_y
+; CHECK-NEXT:   - .offset: 24
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_z
+; CHECK-NEXT:   - .address_space:  global
+; CHECK-NEXT: .offset: 32
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_hostcall_buffer
+; CHECK:  .language:   OpenCL C
+; CHECK-NEXT: .language_version:
+; CHECK-NEXT:   - 2
+; CHECK-NEXT:   - 0
+; CHECK:  .name:   test_kernel
+; CHECK:  .symbol: test_kernel.kd
+
+define amdgpu_kernel void @test_kernel(i8 %a) #0
+!kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3
+!kernel_arg_base_type !3 !kernel_arg_type_qual !4 {
+  ret void
+}
+
+; CHECK:  amdhsa.version:
+; CHECK-NEXT: - 1
+; CHECK-NEXT: - 0
+
+attributes #0 = { sanitize_address "amdgpu-implicitarg-num-bytes"="48" }
+
+!1 = !{i32 0}
+!2 = !{!"none"}
+!3 = !{!"char"}
+!4 = !{!""}
+
+!opencl.ocl.version = !{!90}
+!90 = !{i32 2, i32 0}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 4, !"amdgpu_hostcall", i32 1}
+
+; CHECK: AMDGPU HSA Metadata Parser Test: PASS
Index: clang/test/CodeGenCUDA/amdgpu-asan.cu
===
--- clang/test/CodeGenCUDA/amdgpu-asan.cu
+++ clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -9,12 +9,12 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -O3 -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
@@ -27,5 +27,8 @@
 // ASAN-DAG: @llvm.compiler.used = 
{{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
 // ASAN-DAG: define weak void @__asan_report_load1(i64 %{{.*}})
 
+// MFCHECK: !llvm.module.flags = !{![[FLAG1:[0-9]+]], ![[FLAG2:[0-9]+]]}
+// MFCHECK: ![[FLAG1]] = !{i32 4, !"amdgpu_hostcall", i32 1}
+
 // CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions
 // CHECK-NOT: @__asan_report_load1
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -565,6 +565,7 @@
 "__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
 llvm::GlobalVariable::NotThreadLocal);
 addCompilerUsedGlobal(Var);
+getModule().addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
   }
 
   emitLLVMUsed();


Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
@@ -0,0 +1,54 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 --amdhsa-code-object-version=3 -amdgpu-dump-hsa-metadata -amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck  %s
+
+; CHECK: 

[clang] 4b3881e - Emit hidden hostcall argument for sanitized kernels

2021-11-10 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-11-10T17:05:57-05:00
New Revision: 4b3881e9f319b6c4ec69160f16a49c128ffbd7dd

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

LOG: Emit hidden hostcall argument for sanitized kernels

this patch - https://reviews.llvm.org/D110337 changes the way how hostcall
hidden argument is emitted for printf, but the sanitized kernels also use
hostcall buffer to report a error for invalid memory access, which is not
handled by the above patch and it leads to vdi runtime error:

Device::callbackQueue aborting with error : HSA_STATUS_ERROR_MEMORY_FAULT:
Agent attempted to access an inaccessible address. code: 0x2b

Patch by: Praveen Velliengiri

Reviewed by: Yaxun Liu, Matt Arsenault

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

Added: 
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/amdgpu-asan.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index a4c60f0c50c2d..c28c2e2e85d89 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -565,6 +565,7 @@ void CodeGenModule::Release() {
 "__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
 llvm::GlobalVariable::NotThreadLocal);
 addCompilerUsedGlobal(Var);
+getModule().addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
   }
 
   emitLLVMUsed();

diff  --git a/clang/test/CodeGenCUDA/amdgpu-asan.cu 
b/clang/test/CodeGenCUDA/amdgpu-asan.cu
index e392b9617cdd9..d63e3cf12a74c 100644
--- a/clang/test/CodeGenCUDA/amdgpu-asan.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -9,12 +9,12 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -O3 -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
@@ -27,5 +27,8 @@
 // ASAN-DAG: @llvm.compiler.used = 
{{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
 // ASAN-DAG: define weak void @__asan_report_load1(i64 %{{.*}})
 
+// MFCHECK: !llvm.module.flags = !{![[FLAG1:[0-9]+]], ![[FLAG2:[0-9]+]]}
+// MFCHECK: ![[FLAG1]] = !{i32 4, !"amdgpu_hostcall", i32 1}
+
 // CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions
 // CHECK-NOT: @__asan_report_load1

diff  --git a/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll 
b/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
new file mode 100644
index 0..5b63af45bbe92
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
@@ -0,0 +1,54 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 
--amdhsa-code-object-version=3 -amdgpu-dump-hsa-metadata 
-amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck  %s
+
+; CHECK:  ---
+; CHECK:  amdhsa.kernels:
+; CHECK:- .args:
+; CHECK-NEXT:   - .name:   a
+; CHECK-NEXT: .offset: 0
+; CHECK-NEXT: .size:   1
+; CHECK-NEXT: .type_name:  char
+; CHECK-NEXT: .value_kind: by_value
+; CHECK-NEXT:   - .offset: 8
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_x
+; CHECK-NEXT:   - .offset: 16
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_y
+; CHECK-NEXT:   - .offset: 24
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_z
+; CHECK-NEXT:   - .address_space:  global
+; CHECK-NEXT: .offset: 32
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_hostcall_buffer
+; CHECK:  .language:   OpenCL C
+; CHECK-NEXT: .language_version:
+; CHECK-NEXT:   - 2
+; CHECK-NEXT:   - 0
+; CHECK:  .name:   test_kernel
+; CHECK:  .symbol: test_kernel.kd
+
+define amdgpu_kernel void @test_kernel(i8 %a) #0
+!kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3
+!kernel_arg_base_type !3 !kernel_arg_type_qual !4 {
+  ret void
+}
+
+; CHECK:  amdhsa.version:
+; CHECK-NEXT: - 1

[PATCH] D111443: [Driver] Fix ToolChain::getSanitizerArgs

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



Comment at: clang/lib/Driver/ToolChain.cpp:124
+  }
+  return SanitizerArgs(*this, JobArgs, /*DiagnoseErrors=*/false);
 }

SanitizerArgs SanArgs(*this, JobArgs, !SanitizerArgsChecked);
SanitizerArgsChecked = true;
return SanArgs;




Comment at: clang/lib/Driver/ToolChains/FreeBSD.cpp:471
+bool FreeBSD::isPIEDefault(const llvm::opt::ArgList ) const {
+  return getSanitizerArgs(Args).requiresPIE();
+}

it looks like we do a lot of sanitizerargs recomputing. Is it worth it to try 
and cache it?


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

https://reviews.llvm.org/D111443

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


[clang] 80072fd - [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-11-10T16:42:23-05:00
New Revision: 80072fde61d40a4e8a9da673476730d34a483fa2

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

LOG: [CUDA][HIP] Allow comdat for kernels

Two identical instantiations of a template function can be emitted by two TU's
with linkonce_odr linkage without causing duplicate symbols in linker. MSVC
also requires these symbols be in comdat sections. Linux does not require
the symbols in comdat sections to be merged by linker but by default
clang puts them in comdat sections.

If a template kernel is instantiated identically in two TU's. MSVC requires
that them to be in comdat sections, otherwise MSVC linker will diagnose them as
duplicate symbols. However, currently clang does not put instantiated template
kernels in comdat sections, which causes link error for MSVC.

This patch allows putting instantiated template kernels into comdat sections.

Reviewed by: Artem Belevich, Reid Kleckner

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

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/kernel-stub-name.cu
clang/test/CodeGenCUDA/usual-deallocators.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 69499672bd861..a1b4431ca8c43 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1147,6 +1147,7 @@ llvm::GlobalValue 
*CGNVCUDARuntime::getKernelHandle(llvm::Function *F,
   Var->setAlignment(CGM.getPointerAlign().getAsAlign());
   Var->setDSOLocal(F->isDSOLocal());
   Var->setVisibility(F->getVisibility());
+  CGM.maybeSetTrivialComdat(*GD.getDecl(), *Var);
   KernelHandles[F] = Var;
   KernelStubs[Var] = F;
   return Var;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d36cff82f9dde..a4c60f0c50c2d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4308,11 +4308,6 @@ static bool shouldBeInCOMDAT(CodeGenModule , const 
Decl ) {
   if (!CGM.supportsCOMDAT())
 return false;
 
-  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
-  // them being "merged" by the COMDAT Folding linker optimization.
-  if (D.hasAttr())
-return false;
-
   if (D.hasAttr())
 return true;
 

diff  --git a/clang/test/CodeGenCUDA/kernel-stub-name.cu 
b/clang/test/CodeGenCUDA/kernel-stub-name.cu
index 460dd6010e835..8e82c3612e323 100644
--- a/clang/test/CodeGenCUDA/kernel-stub-name.cu
+++ b/clang/test/CodeGenCUDA/kernel-stub-name.cu
@@ -2,16 +2,35 @@
 
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -fcuda-include-gpubinary %t -o - -x hip\
-// RUN:   | FileCheck %s
+// RUN:   | FileCheck -check-prefixes=CHECK,GNU %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
+// RUN: -fcuda-include-gpubinary %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefixes=CHECK,MSVC %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
 
 #include "Inputs/cuda.h"
 
-// Kernel handles
+// Check kernel handles are emitted for non-MSVC target but not for MSVC 
target.
 
-// CHECK: @[[HCKERN:ckernel]] = constant void ()* @__device_stub__ckernel, 
align 8
-// CHECK: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* 
@_ZN2ns23__device_stub__nskernelEv, align 8
-// CHECK: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* 
@_Z25__device_stub__kernelfuncIiEvv, align 8
-// CHECK: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+// GNU: @[[HCKERN:ckernel]] = constant void ()* 
@[[CSTUB:__device_stub__ckernel]], align 8
+// GNU: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* 
@[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]], align 8
+// GNU: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* 
@[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]], comdat, align 8
+// GNU: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+
+// MSVC: @[[HCKERN:ckernel]] = dso_local constant void ()* 
@[[CSTUB:__device_stub__ckernel]], align 8
+// MSVC: @[[HNSKERN:"\?nskernel@ns@@YAXXZ.*"]] = dso_local constant void ()* 
@[[NSSTUB:"\?nskernel@ns@@YAXXZ"]], align 8
+// MSVC: @[[HTKERN:"\?\?\$kernelfunc@H@@YAXXZ.*"]] = linkonce_odr dso_local 
constant void ()* @[[TSTUB:"\?\?\$kernelfunc@H@@YAXXZ.*"]], comdat, align 8
+// MSVC: 

[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu 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 rG80072fde61d4: [CUDA][HIP] Allow comdat for kernels (authored 
by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112492

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/kernel-stub-name.cu
  clang/test/CodeGenCUDA/usual-deallocators.cu

Index: clang/test/CodeGenCUDA/usual-deallocators.cu
===
--- clang/test/CodeGenCUDA/usual-deallocators.cu
+++ clang/test/CodeGenCUDA/usual-deallocators.cu
@@ -109,7 +109,7 @@
 }
 
 // Make sure that we've generated the kernel used by A::~A.
-// DEVICE-LABEL: define dso_local void @_Z1fIiEvT_
+// DEVICE-LABEL: define void @_Z1fIiEvT_
 
 // Make sure we've picked deallocator for the correct side of compilation.
 
Index: clang/test/CodeGenCUDA/kernel-stub-name.cu
===
--- clang/test/CodeGenCUDA/kernel-stub-name.cu
+++ clang/test/CodeGenCUDA/kernel-stub-name.cu
@@ -2,16 +2,35 @@
 
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -fcuda-include-gpubinary %t -o - -x hip\
-// RUN:   | FileCheck %s
+// RUN:   | FileCheck -check-prefixes=CHECK,GNU %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
+// RUN: -fcuda-include-gpubinary %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefixes=CHECK,MSVC %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
 
 #include "Inputs/cuda.h"
 
-// Kernel handles
+// Check kernel handles are emitted for non-MSVC target but not for MSVC target.
 
-// CHECK: @[[HCKERN:ckernel]] = constant void ()* @__device_stub__ckernel, align 8
-// CHECK: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* @_ZN2ns23__device_stub__nskernelEv, align 8
-// CHECK: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* @_Z25__device_stub__kernelfuncIiEvv, align 8
-// CHECK: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+// GNU: @[[HCKERN:ckernel]] = constant void ()* @[[CSTUB:__device_stub__ckernel]], align 8
+// GNU: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* @[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]], align 8
+// GNU: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* @[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]], comdat, align 8
+// GNU: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+
+// MSVC: @[[HCKERN:ckernel]] = dso_local constant void ()* @[[CSTUB:__device_stub__ckernel]], align 8
+// MSVC: @[[HNSKERN:"\?nskernel@ns@@YAXXZ.*"]] = dso_local constant void ()* @[[NSSTUB:"\?nskernel@ns@@YAXXZ"]], align 8
+// MSVC: @[[HTKERN:"\?\?\$kernelfunc@H@@YAXXZ.*"]] = linkonce_odr dso_local constant void ()* @[[TSTUB:"\?\?\$kernelfunc@H@@YAXXZ.*"]], comdat, align 8
+// MSVC: @[[HDKERN:"\?kernel_decl@@YAXXZ.*"]] = external dso_local constant void ()*, align 8
 
 extern "C" __global__ void ckernel() {}
 
@@ -24,10 +43,10 @@
 
 __global__ void kernel_decl();
 
-void (*kernel_ptr)();
-void *void_ptr;
+extern "C" void (*kernel_ptr)();
+extern "C" void *void_ptr;
 
-void launch(void *kern);
+extern "C" void launch(void *kern);
 
 // Device side kernel names
 
@@ -37,21 +56,22 @@
 
 // Non-template kernel stub functions
 
-// CHECK: define{{.*}}@[[CSTUB:__device_stub__ckernel]]
+// CHECK: define{{.*}}@[[CSTUB]]
 // CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[HCKERN]]
-// CHECK: define{{.*}}@[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]]
-// CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[HNSKERN]]
 
+// CHECK: define{{.*}}@[[NSSTUB]]
+// CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[HNSKERN]]
 
-// Check kernel stub is used for triple chevron
+// Check kernel stub is called for triple chevron.
 
-// CHECK-LABEL: define{{.*}}@_Z4fun1v()
+// CHECK-LABEL: define{{.*}}@fun1()
 // CHECK: call void @[[CSTUB]]()
 // CHECK: call void @[[NSSTUB]]()
-// CHECK: call void @[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]]()
-// CHECK: call void @[[DSTUB:_Z26__device_stub__kernel_declv]]()
+// CHECK: call void @[[TSTUB]]()
+// GNU: call void @[[DSTUB:_Z26__device_stub__kernel_declv]]()
+// MSVC: call void @[[DSTUB:"\?kernel_decl@@YAXXZ"]]()
 
-void fun1(void) {
+extern "C" void fun1(void) {
   ckernel<<<1, 1>>>();
   ns::nskernel<<<1, 1>>>();
   kernelfunc<<<1, 1>>>();
@@ -67,28 +87,28 @@
 
 // CHECK: declare{{.*}}@[[DSTUB]]
 
-// Check kernel handle is used for passing the kernel as a 

[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-11-10 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

It seems to have been fixed in rG3c47c5ca13b8a502de3272e8105548715947b7a8 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


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

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

Overall, looks good to me. But, I'd like to get a more experienced reviewer to 
confirm they're comfortable with the new behavior.




Comment at: 
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:159
 // automatically canonicalized.
+auto  = SM.getFileManager().getFileSystemOpts().WorkingDir;
+auto PrevWorkingDir = WorkingDir;

avogelsgesang wrote:
> ymandel wrote:
> > Why are you capturing this as a reference? This is a subtle and IMO error 
> > prone pattern, since it's not obvious in the code below that you're 
> > mutating a deeply nested element of the filesystem.  Can  you instead use a 
> > local variable and just set this right before you need it?
> > Why are you capturing this as a reference?
> 
> Mostly to keep the code shorter. Otherwise, I would have to write
> 
> ```
> auto PrevWorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
> if (buildDir)
>   SM.getFileManager().getFileSystemOpts().WorkingDir = *buildDir;
> // [...]
> WorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
> ```
> 
> which isn't really DRY.
> 
> > Can you instead use a local variable and just set this right before you 
> > need it?
> 
> I think I don't understand the alternative you are proposing here. Can you 
> provide an example?
What you wrote is what I had in mind, though the last line, i think, would be:
`SM.getFileManager().getFileSystemOpts().WorkingDir = PrevWorkingDir;`
?

That said, I see your point.  The problem is not in your code so much as in the 
underlying (lack of) API for setting and restoring the working directory. 
Honestly, the need to manually restore bothers me more than the reference, now 
that I consider it in more detail. Perhaps another reviewer will have a better 
suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112647

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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath 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 rGff11f0aa5de1: [Clang] Pass -z rel to linker for Fuchsia 
(authored by mcgrathr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ff11f0a - [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via cfe-commits

Author: Roland McGrath
Date: 2021-11-10T13:31:22-08:00
New Revision: ff11f0aa5de1fffaec5f0dde53fad2ba333116b1

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

LOG: [Clang] Pass -z rel to linker for Fuchsia

Fuchsia already supports the more compact relocation format.
Make it the default.

Reviewed By: phosek

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index ee79007fe9a61..b8570fce9eb7d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@ void fuchsia::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index 926594da95c3a..ecf811d9401ba 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"



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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff marked 2 inline comments as done.
fwolff added a comment.

Thanks for your review @carlosgalvezp! I have addressed your inline comments. 
I'm not sure about the failing test, but it looks like a regression test 
internal to libFuzzer? Maybe it goes away with the rebuild.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:374
 {
   PositiveSelfInitialization() : PositiveSelfInitialization() {}
 };

carlosgalvezp wrote:
> Not really sure what this test is meant to do. Why would it call the 
> destructor of the own class in it's own constructor? Looks very strange to me.
> 
> If anything, the constructor should call the constructor of the base:
> 
> PositiveSelfInitialization() : NegativeAggregateType()
> 
> What do you think?
The comment above talks about a "pathological template", so my guess is that 
this checks that clang-tidy doesn't crash for this input. The only reason why I 
had to touch this test at all is that the constructor is now treated as a 
delegating constructor, which suppresses the warning.


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

https://reviews.llvm.org/D113518

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


[PATCH] D106674: Runtime for Interop directive

2021-11-10 Thread Ravi Narayanaswamy via Phabricator via cfe-commits
RaviNarayanaswamy accepted this revision.
RaviNarayanaswamy added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106674

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


[PATCH] D113126: [OpenMP][NFCI] Embed the source location string size in the ident_t

2021-11-10 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

I'm not convinced. `std::strlen` can do the job. Can you explain more why need 
it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113126

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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff updated this revision to Diff 386297.

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

https://reviews.llvm.org/D113518

Files:
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
  clang/lib/Sema/SemaDeclCXX.cpp


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -4496,6 +4496,8 @@
   // (broken) code in a non-template! SetCtorInitializers does not expect this.
   bool Dependent = CurContext->isDependentContext() &&
(BaseType->isDependentType() || Init->isTypeDependent());
+  bool Delegating = Context.hasSameUnqualifiedType(
+  QualType(ClassDecl->getTypeForDecl(), 0), BaseType);
 
   SourceRange InitRange = Init->getSourceRange();
   if (EllipsisLoc.isValid()) {
@@ -4519,8 +4521,7 @@
   const CXXBaseSpecifier *DirectBaseSpec = nullptr;
   const CXXBaseSpecifier *VirtualBaseSpec = nullptr;
   if (!Dependent) {
-if (Context.hasSameUnqualifiedType(QualType(ClassDecl->getTypeForDecl(),0),
-   BaseType))
+if (Delegating)
   return BuildDelegatingInitializer(BaseTInfo, Init, ClassDecl);
 
 FindBaseInitializer(*this, ClassDecl, BaseType, DirectBaseSpec,
@@ -4548,10 +4549,14 @@
   if (Dependent) {
 DiscardCleanupsInEvaluationContext();
 
-return new (Context) CXXCtorInitializer(Context, BaseTInfo,
-/*IsVirtual=*/false,
-InitRange.getBegin(), Init,
-InitRange.getEnd(), EllipsisLoc);
+if (!Delegating)
+  return new (Context)
+  CXXCtorInitializer(Context, BaseTInfo,
+ /*IsVirtual=*/false, InitRange.getBegin(), Init,
+ InitRange.getEnd(), EllipsisLoc);
+else
+  return new (Context) CXXCtorInitializer(
+  Context, BaseTInfo, InitRange.getBegin(), Init, InitRange.getEnd());
   }
 
   // C++ [base.class.init]p2:
@@ -5063,14 +5068,16 @@
   memcpy(initializer, , sizeof (CXXCtorInitializer*));
   Constructor->setCtorInitializers(initializer);
 
-  if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
-MarkFunctionReferenced(Initializer->getSourceLocation(), Dtor);
-DiagnoseUseOfDecl(Dtor, Initializer->getSourceLocation());
-  }
+  if (!Constructor->isDependentContext()) {
+if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
+  MarkFunctionReferenced(Initializer->getSourceLocation(), Dtor);
+  DiagnoseUseOfDecl(Dtor, Initializer->getSourceLocation());
+}
 
-  DelegatingCtorDecls.push_back(Constructor);
+DelegatingCtorDecls.push_back(Constructor);
 
-  DiagnoseUninitializedFields(*this, Constructor);
+DiagnoseUninitializedFields(*this, Constructor);
+  }
 
   return false;
 }
Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -372,8 +372,6 @@
 class PositiveSelfInitialization : NegativeAggregateType
 {
   PositiveSelfInitialization() : PositiveSelfInitialization() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these bases: NegativeAggregateType
-  // CHECK-FIXES: PositiveSelfInitialization() : NegativeAggregateType(), 
PositiveSelfInitialization() {}
 };
 
 class PositiveIndirectMember {
@@ -552,3 +550,18 @@
   int A;
   // CHECK-FIXES-NOT: int A{};
 };
+
+// Check that a delegating constructor in a template does not trigger false 
positives (PR#37902).
+template 
+struct TemplateWithDelegatingCtor {
+  int X;
+  TemplateWithDelegatingCtor() : X{} {};
+  TemplateWithDelegatingCtor(int) : TemplateWithDelegatingCtor(){};
+};
+
+template 
+struct TemplateWithDelegatingCtorNSDMI {
+  int X{};
+  TemplateWithDelegatingCtorNSDMI() = default;
+  TemplateWithDelegatingCtorNSDMI(int) : TemplateWithDelegatingCtorNSDMI() {}
+};


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -4496,6 +4496,8 @@
   // (broken) code in a non-template! SetCtorInitializers does not expect this.
   bool Dependent = CurContext->isDependentContext() &&
(BaseType->isDependentType() || Init->isTypeDependent());
+  bool Delegating = Context.hasSameUnqualifiedType(
+  QualType(ClassDecl->getTypeForDecl(), 0), BaseType);
 
   SourceRange InitRange = Init->getSourceRange();
   if (EllipsisLoc.isValid()) {
@@ -4519,8 +4521,7 @@
   const CXXBaseSpecifier *DirectBaseSpec = nullptr;
   const CXXBaseSpecifier *VirtualBaseSpec 

[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

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

@steakhal Thank you!

> Please clang-format the patch to reflow the touched comment. Given that's 
> done, you are good to go.

The comment is OK. `clang-format` doesn't complain on it.

> Also, wait a couple days before committing to give chance to the rest of the 
> reviewers to have a look.

Sure.


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

https://reviews.llvm.org/D113480

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


[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor accepted this revision.
andrew.w.kaylor added a comment.

lgtm


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

https://reviews.llvm.org/D107994

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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added a comment.

Reordered the switches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 386293.
mcgrathr marked an inline comment as done.
mcgrathr added a comment.

reordered switches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-11-10 Thread Keith Smiley via Phabricator via cfe-commits
keith added a comment.

@JDevlieghere can you take another pass?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

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


[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D107994#3115589 , @thakis wrote:

> This fixes tests on macOS, but I don't know if the space is there 
> intentionally to check for presence of any attributes:
>
>   % git diff
>   diff --git a/clang/test/CodeGen/ffp-contract-option.c 
> b/clang/test/CodeGen/ffp-contract-option.c
>   index 04d23d5f90b7..327722f56f4e 100644
>   --- a/clang/test/CodeGen/ffp-contract-option.c
>   +++ b/clang/test/CodeGen/ffp-contract-option.c
>   @@ -63,7 +63,7 @@
>// RUN: --check-prefixes=CHECK,CHECK-FPC-ON
>   
>float mymuladd(float x, float y, float z) {
>   -  // CHECK: define {{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>   +  // CHECK: define{{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>  return x * y + z;
>  // expected-warning{{overriding '-ffp-contract=fast' option with 
> '-ffp-contract=on'}}
>   
>   diff --git a/clang/test/CodeGen/ffp-model.c b/clang/test/CodeGen/ffp-model.c
>   index ee0eedb2718f..98d31106a119 100644
>   --- a/clang/test/CodeGen/ffp-model.c
>   +++ b/clang/test/CodeGen/ffp-model.c
>   @@ -19,7 +19,7 @@
>// RUN: --check-prefixes CHECK,CHECK-FAST1
>   
>float mymuladd(float x, float y, float z) {
>   -  // CHECK: define {{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>   +  // CHECK: define{{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>  return x * y + z;
>  // CHECK-FAST: fmul fast float
>
> If this is the right fix, please land it. Else I'll revert again in 30 min or 
> so; bots have been broken for hours by now.






Comment at: clang/test/CodeGen/ffp-model.c:4
+// RUN: | FileCheck %s \
+// RUN: --check-prefixes=CHECK,CHECK-FAST --strict-whitespace
+

zahiraam wrote:
> andrew.w.kaylor wrote:
> > Why did you add the strict-whitespace option?
> Because on some targets, the IR generated for the define is "define 
> {{.*}}float @mymuladd" and on and some others it is 
> "define {{.*}} float @mymuladd" (space between {{.*}} and float.
I was trying to fix the issue with the define function check. 
With this run command:

// RUN: %clang -S -emit-llvm -fno-fast-math -emit-llvm -target 
x86_64-apple-macosx10.11 %s -o -
I get this IR:

define float @mymuladd(float noundef %x, float noundef %y, float noundef %z)

This wouldn't be represented by

// CHECK: define {{.*}} float @mymuladd

but by

// CHECK: define{{.*}} float @mymuladd

or

// CHECK: define {{.*}}float @mymuladd 
But I get replacing with // CHECK: define{{.*}} float @mymuladd
Should solve the issue. Right?


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

https://reviews.llvm.org/D107994

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


[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 386279.
zahiraam marked 2 inline comments as done.

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

https://reviews.llvm.org/D107994

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/ffp-contract-option.c
  clang/test/CodeGen/ffp-model.c
  clang/test/CodeGen/ppc-emmintrin.c
  clang/test/CodeGen/ppc-xmmintrin.c
  clang/test/Driver/fp-model.c
  clang/test/Misc/ffp-contract.c

Index: clang/test/Misc/ffp-contract.c
===
--- /dev/null
+++ clang/test/Misc/ffp-contract.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -O3 -ffp-contract=fast -triple=aarch64-apple-darwin \
+// RUN: -S -o - %s | FileCheck --check-prefix=CHECK-FMADD %s
+// REQUIRES: aarch64-registered-target
+
+float fma_test1(float a, float b, float c) {
+  // CHECK-FMADD: fmadd
+  float x = a * b;
+  float y = x + c;
+  return y;
+}
Index: clang/test/Driver/fp-model.c
===
--- clang/test/Driver/fp-model.c
+++ clang/test/Driver/fp-model.c
@@ -99,7 +99,7 @@
 // RUN: %clang -### -nostdinc -ffp-model=precise -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPM-PRECISE %s
 // CHECK-FPM-PRECISE: "-cc1"
-// CHECK-FPM-PRECISE: "-ffp-contract=fast"
+// CHECK-FPM-PRECISE: "-ffp-contract=on"
 // CHECK-FPM-PRECISE: "-fno-rounding-math"
 
 // RUN: %clang -### -nostdinc -ffp-model=strict -c %s 2>&1 \
Index: clang/test/CodeGen/ppc-xmmintrin.c
===
--- clang/test/CodeGen/ppc-xmmintrin.c
+++ clang/test/CodeGen/ppc-xmmintrin.c
@@ -2,11 +2,11 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 // RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
Index: clang/test/CodeGen/ppc-emmintrin.c
===
--- clang/test/CodeGen/ppc-emmintrin.c
+++ clang/test/CodeGen/ppc-emmintrin.c
@@ -2,9 +2,9 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:  -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN:  -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 
 // CHECK-BE-DAG: @_mm_movemask_pd.perm_mask = internal constant <4 x i32> , align 16
 // CHECK-BE-DAG: @_mm_shuffle_epi32.permute_selectors = internal constant [4 x i32] [i32 66051, i32 67438087, i32 134810123, i32 202182159], align 4
Index: clang/test/CodeGen/ffp-model.c
===
--- /dev/null
+++ clang/test/CodeGen/ffp-model.c
@@ -0,0 +1,48 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -S -emit-llvm -ffp-model=fast -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-FAST
+
+// RUN: %clang -S -emit-llvm -ffp-model=precise %s -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-PRECISE
+
+// RUN: %clang -S -emit-llvm -ffp-model=strict %s -o - \
+// RUN: -target x86_64 | FileCheck %s --check-prefixes=CHECK,CHECK-STRICT
+
+// RUN: %clang -S -emit-llvm -ffp-model=strict -ffast-math \
+// RUN: -target x86_64 %s -o - | FileCheck %s \
+// RUN: 

[PATCH] D113599: Revert "[clang] Add early exit when checking for const init of arrays."

2021-11-10 Thread Adam Czachorowski 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 rG6d09aaecdfe5: Revert [clang] Add early exit when 
checking for const init of arrays. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113599

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();
+unsigned N = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), 0, FinalSize);
-if (FinalSize == 0)
-  return true;
+*Value = APValue(APValue::UninitArray(), N, N);
+
+if (HadZeroInit)
+  for (unsigned I = 0; I != N; ++I)
+Value->getArrayInitializedElt(I) = Filler;
 
+// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-// We do the whole initialization in two passes, first for just one 
element,
-// then for the whole array. It's possible we may find out we can't do 
const
-// init in the first pass, in which case we avoid allocating a potentially
-// large array. We don't do more passes because expanding array requires
-// copying the data, which is wasteful.
-for (const unsigned N : {1u, FinalSize}) {
-  unsigned OldElts = Value->getArrayInitializedElts();
-  if (OldElts == N)
-break;
-
-  // Expand the array to appropriate size.
-  APValue NewValue(APValue::UninitArray(), N, FinalSize);
-  for (unsigned I = 0; I < OldElts; ++I)
-NewValue.getArrayInitializedElt(I).swap(
-Value->getArrayInitializedElt(I));
-  Value->swap(NewValue);
-
-  if (HadZeroInit)
-for (unsigned I = OldElts; I < N; ++I)
-  Value->getArrayInitializedElt(I) = Filler;
-
-  // Initialize the elements.
-  for (unsigned I = OldElts; I < N; ++I) {
-if (!VisitCXXConstructExpr(E, ArrayElt,
-   >getArrayInitializedElt(I),
-   CAT->getElementType()) ||
-!HandleLValueArrayAdjustment(Info, E, ArrayElt,
- CAT->getElementType(), 1))
-  return false;
-// When checking for const initilization any diagnostic is considered
-// an error.
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-!Info.keepEvaluatingAfterFailure())
-  return false;
-  }
-}
+for (unsigned I = 0; I != N; ++I)
+  if (!VisitCXXConstructExpr(E, ArrayElt, 
>getArrayInitializedElt(I),
+ CAT->getElementType()) ||
+  !HandleLValueArrayAdjustment(Info, E, ArrayElt, 
CAT->getElementType(),
+   1))
+return false;
 
 return true;
   }


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();

[clang] 6d09aae - Revert "[clang] Add early exit when checking for const init of arrays."

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T20:59:35+01:00
New Revision: 6d09aaecdfe51e13fc64d539aa7c9a790de341d7

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

LOG: Revert "[clang] Add early exit when checking for const init of arrays."

This reverts commit 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3.

Several breakages, including ARM (fixed later, but not sufficient) and
MSan (to be diagnosed later).

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 
clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp



diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index a6da3d3fbea2d..fe96db9ca918e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@ bool ArrayExprEvaluator::VisitCXXConstructExpr(const 
CXXConstructExpr *E,
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();
+unsigned N = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), 0, FinalSize);
-if (FinalSize == 0)
-  return true;
+*Value = APValue(APValue::UninitArray(), N, N);
+
+if (HadZeroInit)
+  for (unsigned I = 0; I != N; ++I)
+Value->getArrayInitializedElt(I) = Filler;
 
+// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-// We do the whole initialization in two passes, first for just one 
element,
-// then for the whole array. It's possible we may find out we can't do 
const
-// init in the first pass, in which case we avoid allocating a potentially
-// large array. We don't do more passes because expanding array requires
-// copying the data, which is wasteful.
-for (const unsigned N : {1u, FinalSize}) {
-  unsigned OldElts = Value->getArrayInitializedElts();
-  if (OldElts == N)
-break;
-
-  // Expand the array to appropriate size.
-  APValue NewValue(APValue::UninitArray(), N, FinalSize);
-  for (unsigned I = 0; I < OldElts; ++I)
-NewValue.getArrayInitializedElt(I).swap(
-Value->getArrayInitializedElt(I));
-  Value->swap(NewValue);
-
-  if (HadZeroInit)
-for (unsigned I = OldElts; I < N; ++I)
-  Value->getArrayInitializedElt(I) = Filler;
-
-  // Initialize the elements.
-  for (unsigned I = OldElts; I < N; ++I) {
-if (!VisitCXXConstructExpr(E, ArrayElt,
-   >getArrayInitializedElt(I),
-   CAT->getElementType()) ||
-!HandleLValueArrayAdjustment(Info, E, ArrayElt,
- CAT->getElementType(), 1))
-  return false;
-// When checking for const initilization any diagnostic is considered
-// an error.
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-!Info.keepEvaluatingAfterFailure())
-  return false;
-  }
-}
+for (unsigned I = 0; I != N; ++I)
+  if (!VisitCXXConstructExpr(E, ArrayElt, 
>getArrayInitializedElt(I),
+ CAT->getElementType()) ||
+  !HandleLValueArrayAdjustment(Info, E, ArrayElt, 
CAT->getElementType(),
+   1))
+return false;
 
 return true;
   }

diff  --git a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp 
b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
deleted file mode 100644
index 1bbc1b5c863c0..0
--- a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-



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


[PATCH] D113599: Revert "[clang] Add early exit when checking for const init of arrays."

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: kadircet.
Herald added a subscriber: kristof.beyls.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3 
.

Several breakages, including ARM (fixed later, but not sufficient) and
MSan (to be diagnosed later).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113599

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();
+unsigned N = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), 0, FinalSize);
-if (FinalSize == 0)
-  return true;
+*Value = APValue(APValue::UninitArray(), N, N);
+
+if (HadZeroInit)
+  for (unsigned I = 0; I != N; ++I)
+Value->getArrayInitializedElt(I) = Filler;
 
+// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-// We do the whole initialization in two passes, first for just one 
element,
-// then for the whole array. It's possible we may find out we can't do 
const
-// init in the first pass, in which case we avoid allocating a potentially
-// large array. We don't do more passes because expanding array requires
-// copying the data, which is wasteful.
-for (const unsigned N : {1u, FinalSize}) {
-  unsigned OldElts = Value->getArrayInitializedElts();
-  if (OldElts == N)
-break;
-
-  // Expand the array to appropriate size.
-  APValue NewValue(APValue::UninitArray(), N, FinalSize);
-  for (unsigned I = 0; I < OldElts; ++I)
-NewValue.getArrayInitializedElt(I).swap(
-Value->getArrayInitializedElt(I));
-  Value->swap(NewValue);
-
-  if (HadZeroInit)
-for (unsigned I = OldElts; I < N; ++I)
-  Value->getArrayInitializedElt(I) = Filler;
-
-  // Initialize the elements.
-  for (unsigned I = OldElts; I < N; ++I) {
-if (!VisitCXXConstructExpr(E, ArrayElt,
-   >getArrayInitializedElt(I),
-   CAT->getElementType()) ||
-!HandleLValueArrayAdjustment(Info, E, ArrayElt,
- CAT->getElementType(), 1))
-  return false;
-// When checking for const initilization any diagnostic is considered
-// an error.
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-!Info.keepEvaluatingAfterFailure())
-  return false;
-  }
-}
+for (unsigned I = 0; I != N; ++I)
+  if (!VisitCXXConstructExpr(E, ArrayElt, 
>getArrayInitializedElt(I),
+ CAT->getElementType()) ||
+  !HandleLValueArrayAdjustment(Info, E, ArrayElt, 
CAT->getElementType(),
+   1))
+return false;
 
 return true;
   }


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-

[PATCH] D113120: [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added a comment.

Sorry for trouble, I will revert this for now.

It's only the test that's causing the problem, the fix is fine, as far as I can 
tell. Still, better revert the whole thing for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113120

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


[PATCH] D113120: [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

The test is failing on non-arm macs: http://45.33.8.238/mac/38601/step_7.txt

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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113120

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


[clang-tools-extra] 26d195d - Replace include by forward declaration in test case

2021-11-10 Thread via cfe-commits

Author: serge-sans-paille
Date: 2021-11-10T20:34:05+01:00
New Revision: 26d195d8b332d8615b7bd0ab9657bcf244f6b112

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

LOG: Replace include by forward declaration in test case

This should fix the remaining buildbot issue for the misleading identifier
detection pass.

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp
index cb036f96dfee1..fdd0886eb3851 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s misc-misleading-identifier %t
 
-#include 
+int printf(const char *format, ...);
 
 // CHECK-MESSAGES: :[[#@LINE+1]]:1: warning: identifier has right-to-left 
codepoints [misc-misleading-identifier]
 short int א = (short int)0;



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


[PATCH] D112915: [clang][modules] Track number of includes per submodule

2021-11-10 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Implementation looks a lot cleaner!

I'd still like to drop NumIncludes first if possible because I think it'll be 
easier to reason about without this extra layer of complexity. Also, that'd 
mitigate the potential regression in `.pcm` size.

(Note: I'd be more comfortable with @vsapsai and/or @rsmith reviewing the 
overall direction; I just jumped in for the implementation details.)




Comment at: clang/include/clang/Lex/HeaderSearch.h:133-139
-
-  /// Determine whether this is a non-default header file info, e.g.,
-  /// it corresponds to an actual header we've included or tried to include.
-  bool isNonDefault() const {
-return isImport || isPragmaOnce || NumIncludes || ControllingMacro ||
-  ControllingMacroID;
-  }

Looks like this is already dead code? If so, please separate out and commit 
ahead of time (e.g., now).



Comment at: clang/include/clang/Serialization/ModuleFile.h:399
+  /// include information.
+  llvm::StringMap> SubmoduleIncludedFiles;
+

Each StringMapEntry is going to have a pretty big allocation here, for a 512B 
vector. Given that it doesn't need to be after creation, it'd be more efficient 
to use this pattern:
```
lang=c++
llvm::StringMap> SubmoduleIncludedFiles;
SpecificBumpPtrAlloc SubmoduleIncludedFilesAlloc;

// later
MutableArrayRef Files(SubmoduleIncludedFiles.Allocate(Record.size()), 
Record.size());
llvm::copy(Record, Files.begin());
SubmoduleIncludedFiles[Key] = Files;
```

That said, I feel like this should just be:
```
lang=c++
DenseMap SubmoduleIncludedFiles;
```
The key can point at the name of the submodule, which must already exist 
somewhere without needing a StringMap to create a new copy of it. The value is 
a lazily deserialized blob.



Comment at: clang/lib/Lex/Preprocessor.cpp:1323
+auto  = SubmoduleIncludeStates[M].NumIncludes;
+for (unsigned UID = 0; UID <= ModNumIncludes.maxUID(); ++UID) {
+  CurSubmoduleIncludeState->NumIncludes[UID] += ModNumIncludes[UID];

jansvoboda11 wrote:
> dexonsmith wrote:
> > jansvoboda11 wrote:
> > > Iterating over all FileEntries is probably not very efficient, as 
> > > Volodymyr mentioned. Thinking about how to make this more efficient...
> > My suggestion above to drop FileEntryMap in favour of a simple DenseMap 
> > would help a bit, just iterating through the files actually included by the 
> > submodules.
> > 
> > Further, I wonder if "num-includes"/file/submodule (`unsigned`) is actually 
> > useful, vs. "was-included"/file/submodule (`bool`). The only observer I see 
> > is `HeaderSearch::PrintStats()` but maybe I missed something?
> > 
> > If I'm right and we can switch to `bool`, then NumIncludes becomes a 
> > `DenseSet IncludedFiles` (or `DenseSet` for UIDs). 
> > (BTW, I also wondered if you could rotate the map, using File as the outer 
> > key, and then use bitsets for the sbumodules, but I doubt this is better, 
> > since most files are only included by a few submodules, right?)
> > 
> > Then you can just do a set union here. Also simplifies bitcode 
> > serialization.
> > 
> > (If a `bool`/set is sufficient, then I'd suggest landing that 
> > first/separately, before adding the per-submodule granularity in this 
> > patch.)
> For each file, we need to have three distinct states: not included at all, 
> included exactly once (`firstTimeLexingFile`), included more than once. This 
> means we can't use a single `DenseSet`.
> 
> But we could use a `DenseMap`, where "not included at all" can be 
> expressed as being absent from the map, exactly once as having `true` in the 
> map and more than once as having `false` in the map. Alternatively, we could 
> use two `DenseSet` instances to encode the same, but I don't think having two 
> lookups per file to determine stuff is efficient.
> 
> I can look into this in a follow-up patch.
Seems like a DenseSet could still be used by having HeaderInfo pass back the 
WasInserted bit from the insertion to the preprocessor, and threading it 
through to Preprocessor::HandleEndOfFile (the only caller of 
FirstTimeLexingFile):
```
lang=c++
bool IsFirst = Set.insert(Key).second;
```
The threading doesn't seem too hard. Looking at main:
- Preprocessor::HandleHeaderIncludeOrImport calls 
HeaderInfo::ShouldEnterIncludeFile. This does the `++FI.NumIncludes` (going 
from 0 to 1). Instead, it could be `IsFirst = !FI.WasIncluded; FI.WasIncluded = 
true;`, then return `IsFirst` somehow. (Then your patch can pull `IsFirst` from 
the `insert().second`).
- Preprocessor::HandleHeaderIncludeOrImport calls 
Preprocessor::EnterSourceFile. This creates a new Lexer for that file. 
`IsFirst` can be stored on that Lexer.
- Preprocessor::HandleEndOfFile calls FirstTimeLexingFile. Instead, it can 
check the new accessor `CurLexer->isFirstTimeLexing()`.

> I can look into this in a follow-up patch.

Follow-up might be okay, but it'd be nice to 

[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Driver/ToolChains/Fuchsia.cpp:64-65
 CmdArgs.push_back("--pack-dyn-relocs=relr");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
   }

Super minor nit, but I'd prefer moving this two lines up to keep all the `-z` 
options together.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 386262.
mcgrathr added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr" "-z" 
"rel"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -61,6 +61,8 @@
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
   }
 
   if (!D.SysRoot.empty())


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr" "-z" "rel"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -61,6 +61,8 @@
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
   }
 
   if (!D.SysRoot.empty())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2021-11-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added subscribers: njames93, whisperity, steakhal.
steakhal added a comment.
Herald added subscribers: carlosgalvezp, manas, ASDenysPetrov.
Herald added a project: clang-tools-extra.

It seems like the list got pretty outdated by the time.
Do you think we should really refer to the clang-analyzer checks in this list? 
What about simply referring to the clangsa docs instead?
I fear, this will be a constant problem in the future.

That being said, a specific grep-like test would suffice to ensure it's always 
updated, but I would be surprised as a clang static analyzer developer that I 
need to run the clang-tools-extra tests besides the clang-analysis ones.
It would cause build bot breakages all the time - and just as many revert 
commits by choosing that direction.

WDYT? @aaron.ballman @njames93 @whisperity


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64454

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


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 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.

Please clang-format the patch to reflow the touched comment. Given that's done, 
you are good to go.
Also, wait a couple days before committing to give chance to the rest of the 
reviewers to have a look.


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

https://reviews.llvm.org/D113480

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


[PATCH] D113126: [OpenMP][NFCI] Embed the source location string size in the ident_t

2021-11-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 386255.
jdoerfert added a comment.
Herald added a subscriber: asavonic.

update tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113126

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/barrier_codegen.cpp
  clang/test/OpenMP/for_codegen.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/parallel_num_threads_codegen.cpp
  clang/test/OpenMP/parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/parallel_proc_bind_primary_codegen.cpp
  clang/test/OpenMP/sections_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1589,8 +1589,10 @@
 (), F.getEntryBlock().begin()));
   // Create a fallback location if non was found.
   // TODO: Use the debug locations of the calls instead.
-  Constant *Loc = OMPInfoCache.OMPBuilder.getOrCreateDefaultSrcLocStr();
-  Ident = OMPInfoCache.OMPBuilder.getOrCreateIdent(Loc);
+  uint32_t SrcLocStrSize;
+  Constant *Loc =
+  OMPInfoCache.OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize);
+  Ident = OMPInfoCache.OMPBuilder.getOrCreateIdent(Loc, SrcLocStrSize);
 }
 return Ident;
   }
@@ -3216,8 +3218,11 @@
   OpenMPIRBuilder::LocationDescription Loc(
   InsertPointTy(ParentBB, ParentBB->end()), DL);
   OMPInfoCache.OMPBuilder.updateToLocation(Loc);
-  auto *SrcLocStr = OMPInfoCache.OMPBuilder.getOrCreateSrcLocStr(Loc);
-  Value *Ident = OMPInfoCache.OMPBuilder.getOrCreateIdent(SrcLocStr);
+  uint32_t SrcLocStrSize;
+  auto *SrcLocStr =
+  OMPInfoCache.OMPBuilder.getOrCreateSrcLocStr(Loc, SrcLocStrSize);
+  Value *Ident =
+  OMPInfoCache.OMPBuilder.getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   BranchInst::Create(RegionCheckTidBB, ParentBB)->setDebugLoc(DL);
 
   // Add check for Tid in RegionCheckTidBB
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,7 +21,9 @@
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/IR/CFG.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/PassManager.h"
@@ -37,6 +39,7 @@
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Transforms/Utils/UnrollLoop.h"
 
+#include 
 #include 
 
 #define DEBUG_TYPE "openmp-ir-builder"
@@ -255,19 +258,21 @@
   return GV;
 }
 
-Value *OpenMPIRBuilder::getOrCreateIdent(Constant *SrcLocStr,
- IdentFlag LocFlags,
- unsigned Reserve2Flags) {
+Constant *OpenMPIRBuilder::getOrCreateIdent(Constant *SrcLocStr,
+uint32_t SrcLocStrSize,
+IdentFlag LocFlags,
+unsigned Reserve2Flags) {
   // Enable "C-mode".
   LocFlags |= OMP_IDENT_FLAG_KMPC;
 
-  Value * =
+  Constant * =
   IdentMap[{SrcLocStr, uint64_t(LocFlags) << 31 | Reserve2Flags}];
   if (!Ident) {
 Constant *I32Null = ConstantInt::getNullValue(Int32);
-Constant *IdentData[] = {
-I32Null, ConstantInt::get(Int32, uint32_t(LocFlags)),
-ConstantInt::get(Int32, Reserve2Flags), I32Null, SrcLocStr};
+Constant *IdentData[] = {I32Null,
+ ConstantInt::get(Int32, uint32_t(LocFlags)),
+ ConstantInt::get(Int32, Reserve2Flags),
+ ConstantInt::get(Int32, SrcLocStrSize), SrcLocStr};
 Constant *Initializer =
 ConstantStruct::get(OpenMPIRBuilder::Ident, IdentData);
 
@@ -290,10 +295,12 @@
 }
   }
 
-  return Builder.CreatePointerCast(Ident, IdentPtr);
+  return ConstantExpr::getPointerBitCastOrAddrSpaceCast(Ident, IdentPtr);
 }
 
-Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef LocStr) {
+Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef LocStr,
+uint32_t ) {
+  SrcLocStrSize = LocStr.size();
   Constant * = SrcLocStrMap[LocStr];
   if (!SrcLocStr) {
 Constant *Initializer =
@@ -314,8 +321,8 @@
 
 Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef FunctionName,
 StringRef FileName,
-unsigned Line,
-unsigned 

[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

In D113517#3121455 , @jyknight wrote:

> This change allows those future optimizations to apply to throw() as well, in 
> C++17 mode, which is the desirable outcome.

I see. It seems inconsistent that `throw(X)` would still call `unexpected` but 
that `throw()` would call `terminate`, but I suppose in the `throw()` case 
there is really not much interesting that an `unexpected_handler` can do other 
than (take some logging action and) terminate the program -- in particular, it 
can't do exception translation. So maybe the inconsistency is not a big deal, 
and it's more important to get the better code generation, especially given how 
rare `throw(X)` is compared to `throw()`. OK, I think I'm convinced that this 
is the best direction.




Comment at: clang/lib/CodeGen/CGException.cpp:480-487
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled separately, below.
+  if ((getLangOpts().CPlusPlus17 || EST != EST_DynamicNone) &&
+  Proto->canThrow() == CT_Cannot) {
 // noexcept functions are simple terminate scopes.
 if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
   EHStack.pushTerminate();

Maybe the logic would be clearer if we swap the terminate and unexpected cases:
```
if  (EST == EST_Dynamic || (!getLangOpts().CPlusPlus17 && EST == 
EST_DynamicNone)) {
  // Prepare to call unexpected
} else if (Proto->canThrow() == CT_Cannot) {
  // Prepare to call terminate
}
```
This would keep the syntactic checks of `EST` separated from the semantic 
checks of `canThrow`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Also, what's with the pre-merge test, is it related?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113518

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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp requested changes to this revision.
carlosgalvezp added a comment.
This revision now requires changes to proceed.

Amazing, thanks a lot for fixing this long-standing issue! I have a couple 
comments. I'm not familiar at all with the Sema part so someone that knows 
should look at it :)




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:374
 {
   PositiveSelfInitialization() : PositiveSelfInitialization() {}
 };

Not really sure what this test is meant to do. Why would it call the destructor 
of the own class in it's own constructor? Looks very strange to me.

If anything, the constructor should call the constructor of the base:

PositiveSelfInitialization() : NegativeAggregateType()

What do you think?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:555
+// Check that a delegating constructor in a template does not trigger false 
positives (PR#37902).
+template 
+struct TemplateWithDelegatingCtor {

typename T?

Not sure if it makes a difference



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:559
+  TemplateWithDelegatingCtor() : X{} {};
+  TemplateWithDelegatingCtor(int) : TemplateWithDelegatingCtor(){};
+};

Could you add another test where X is initialized via NSDMI instead of in the 
constructor initializer list?

int X{};
TemplateWithDelegatingCtor() = default;
TemplateWithDelegatingCtor(int) : TemplateWithDelegatingCtor() {}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113518

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


[PATCH] D113499: [clang-tidy] Reduce false positives for `bugprone-infinite-loop` with dependent expressions

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff updated this revision to Diff 386244.
fwolff added a comment.

The test failed on Windows. I don't have a machine to reproduce this, but maybe 
adding `-fno-delayed-template-parsing` helps.


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

https://reviews.llvm.org/D113499

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
-// RUN:   -- -- -fexceptions -fblocks
+// RUN:   -- -- -fexceptions -fblocks 
-fno-delayed-template-parsing
 
 void simple_infinite_loop1() {
   int i = 0;
@@ -622,3 +622,31 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (size) are updated in the loop body 
[bugprone-infinite-loop]
   }
 }
+
+template 
+int some_template_fn() { return 1; }
+
+template 
+void test_dependent_condition() {
+  const int error = some_template_fn();
+  do {
+  } while (false && error == 0);
+
+  const int val = some_template_fn();
+  for (; !(val == 0 || true);) {
+  }
+
+  const int val2 = some_template_fn();
+  for (; !(val2 == 0 || false);) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (val2) are updated in the loop body 
[bugprone-infinite-loop]
+  }
+
+  const int val3 = some_template_fn();
+  do {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (val3) are updated in the loop body 
[bugprone-infinite-loop]
+  } while (1, (true) && val3 == 1);
+
+  const int val4 = some_template_fn();
+  do {
+  } while (1, (false) && val4 == 1);
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -117,12 +117,31 @@
   return Result;
 }
 
-static bool isKnownFalse(const Expr , const ASTContext ) {
-  if (Cond.isValueDependent())
+static bool isKnown(const Expr , const ASTContext , const bool Value) 
{
+  if (Cond.isValueDependent()) {
+if (const auto *BinOp = dyn_cast()) {
+  // Conjunctions (disjunctions) can still be handled if at least one
+  // conjunct (disjunct) is known to be false (true).
+  if (!Value && BinOp->getOpcode() == BO_LAnd)
+return isKnown(*BinOp->getLHS(), Ctx, false) ||
+   isKnown(*BinOp->getRHS(), Ctx, false);
+  if (Value && BinOp->getOpcode() == BO_LOr)
+return isKnown(*BinOp->getLHS(), Ctx, true) ||
+   isKnown(*BinOp->getRHS(), Ctx, true);
+  if (BinOp->getOpcode() == BO_Comma)
+return isKnown(*BinOp->getRHS(), Ctx, Value);
+} else if (const auto *UnOp = dyn_cast()) {
+  if (UnOp->getOpcode() == UO_LNot)
+return isKnown(*UnOp->getSubExpr(), Ctx, !Value);
+} else if (const auto *Paren = dyn_cast())
+  return isKnown(*Paren->getSubExpr(), Ctx, Value);
+else if (const auto *ImplCast = dyn_cast())
+  return isKnown(*ImplCast->getSubExpr(), Ctx, Value);
 return false;
+  }
   bool Result = false;
   if (Cond.EvaluateAsBooleanCondition(Result, Ctx))
-return !Result;
+return Result == Value;
   return false;
 }
 
@@ -144,7 +163,7 @@
   const auto *LoopStmt = Result.Nodes.getNodeAs("loop-stmt");
   const auto *Func = Result.Nodes.getNodeAs("func");
 
-  if (isKnownFalse(*Cond, *Result.Context))
+  if (isKnown(*Cond, *Result.Context, false))
 return;
 
   bool ShouldHaveConditionVariables = true;


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
-// RUN:   -- -- -fexceptions -fblocks
+// RUN:   -- -- -fexceptions -fblocks -fno-delayed-template-parsing
 
 void simple_infinite_loop1() {
   int i = 0;
@@ -622,3 +622,31 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (size) are updated in the loop body [bugprone-infinite-loop]
   }
 }
+
+template 
+int some_template_fn() { return 1; }
+
+template 
+void test_dependent_condition() {
+  const int error = some_template_fn();
+  do {
+  } while (false && error == 0);
+
+  const int val = some_template_fn();
+  for (; !(val == 0 || true);) {
+  }

[PATCH] D113585: [clang-tidy] Fix false positive in `bugprone-throw-keyword-missing` check

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff created this revision.
fwolff added reviewers: steveire, alexfh, Eugene.Zelenko.
fwolff added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
fwolff requested review of this revision.
Herald added a subscriber: cfe-commits.

Fixes PR#52400. The tests for `bugprone-throw-keyword-missing` actually already 
contain exceptions as class members, but not as members with initializers, 
which was probably just an oversight.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113585

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -118,6 +118,7 @@
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}
 
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -26,7 +26,7 @@
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
   unless(anyOf(hasAncestor(stmt(
anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(varDecl()),
+   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
allOf(hasAncestor(CtorInitializerList),
  unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -118,6 +118,7 @@
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}
 
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -26,7 +26,7 @@
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
   unless(anyOf(hasAncestor(stmt(
anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(varDecl()),
+   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
allOf(hasAncestor(CtorInitializerList),
  unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113575: Add `isInitCapture` and `forEachLambdaCapture` matchers.

2021-11-10 Thread Matt Kulukundis via Phabricator via cfe-commits
fowles added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4224
+/// float z;
+/// auto f = [=]() { return x + y + z; };
+///   }

it would be nice to be able to do something like

```
int main() {
  int x, y;
  float z;
  auto f = [=, z]() { return x+ y + z; };
}
```

`lambdaExpr(forEachLambdaCapture(isImplicit())` matches `x` and `y` but not `z`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113575

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


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

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

Updated according to comments.


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

https://reviews.llvm.org/D113480

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

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -68,8 +68,7 @@
 void glob_invalid_index4() {
   const int *ptr = glob_arr4[1];
   int idx = -42;
-  // FIXME: Should warn {{garbage or undefined}}.
-  auto x = ptr[idx]; // no-warning
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
 }
 
 int const glob_arr5[4][2] = {{1}, 3, 4, 5};
@@ -86,16 +85,11 @@
 
 void glob_ptr_index2() {
   int const *ptr = glob_arr5[1];
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(ptr[1] == 4); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be UNDEFINED.
-  clang_analyzer_eval(ptr[2] == 5); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be UNDEFINED.
-  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be UNDEFINED.
-  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 4); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 5); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNDEFINED}}
 }
 
 void glob_invalid_index5() {
@@ -106,8 +100,7 @@
 void glob_invalid_index6() {
   int const *ptr = _arr5[1][0];
   int idx = 42;
-  // FIXME: Should warn {{garbage or undefined}}.
-  auto x = ptr[idx]; // no-warning
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
 }
 
 extern const int glob_arr_no_init[10];
Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -96,18 +96,24 @@
   // already be handled.
   QualType PointeeTy = CastToTy->getPointeeType();
   QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
+  CanonPointeeTy = CanonPointeeTy.getLocalUnqualifiedType();
 
   // Handle casts to void*.  We just pass the region through.
-  if (CanonPointeeTy.getLocalUnqualifiedType() == Ctx.VoidTy)
+  if (CanonPointeeTy == Ctx.VoidTy)
 return R;
 
-  // Handle casts from compatible types.
-  if (R->isBoundable())
+  const auto IsSameRegionType = [](const MemRegion *R, QualType OtherTy) {
 if (const auto *TR = dyn_cast(R)) {
   QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
-  if (CanonPointeeTy == ObjTy)
-return R;
+  if (OtherTy == ObjTy.getLocalUnqualifiedType())
+return true;
 }
+return false;
+  };
+
+  // Handle casts from compatible types.
+  if (R->isBoundable() && IsSameRegionType(R, CanonPointeeTy))
+return R;
 
   // Process region cast according to the kind of the region being cast.
   switch (R->getKind()) {
@@ -174,16 +180,11 @@
   CharUnits off = rawOff.getOffset();
 
   if (off.isZero()) {
-// Edge case: we are at 0 bytes off the beginning of baseR.  We
-// check to see if type we are casting to is the same as the base
-// region.  If so, just return the base region.
-if (const auto *TR = dyn_cast(baseR)) {
-  QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
-  QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
-  if (CanonPointeeTy == ObjTy)
-return baseR;
-}
-
+// Edge case: we are at 0 bytes off the beginning of baseR. We check to
+// see if the type we are casting to is the same as the type of the base
+// region. If so, just return the base region.
+if (IsSameRegionType(baseR, CanonPointeeTy))
+  return baseR;
 // Otherwise, create a new ElementRegion at offset 0.
 return MakeElementRegion(cast(baseR), PointeeTy);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113583: [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

2021-11-10 Thread Adam Czachorowski 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 rG581a6a8118f5: [clang] Fix armv7-quick build by hardcoding 
-triple=x86_64 in OOM test. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113583

Files:
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 581a6a8 - [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T19:24:06+01:00
New Revision: 581a6a8118f55d2662e180880558db95f808b0dc

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

LOG: [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

The test was added in 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3 and it
creates a very large array, which is too large for ARM. Making the array
smaller is not a good option, since we would need a very low ulimit and
could then hit it for other reasons.

Should fix the https://lab.llvm.org/buildbot/#/builders/171/builds/5851
failure.

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

Added: 


Modified: 
clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp 
b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
index 4504c0caed55..1bbc1b5c863c 100644
--- a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.



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


[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I think the key is the self-reference in the LEA instruction:

>   ; foo
>   .seh_proc "??$foo@H@@YAXH@Z"
>   ...
>   leaq"??$foo@H@@YAXH@Z"(%rip), %rcx
>   ...
>   ; foo
>   .seh_proc "??$foo@M@@YAXM@Z"
>   ...
>   leaq"??$foo@M@@YAXM@Z"(%rip), %rcx
>
> I think they are not folded because link.exe is smart enough to treat them as 
> not identical comdat functions. I think we may stop worrying about the ICF 
> foading kernel stubs.

It sounds like the behavior may have changed since D63277 
 was landed, and maybe we don't need it 
anymore.


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

https://reviews.llvm.org/D112492

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


[PATCH] D113583: [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: kadircet.
Herald added a subscriber: kristof.beyls.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The test was added in 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3 
 and it
creates a very large array, which is too large for ARM. Making the array
smaller is not a good option, since we would need a very low ulimit and
could then hit it for other reasons.

Should fix the https://lab.llvm.org/buildbot/#/builders/171/builds/5851
failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113583

Files:
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112914: Misleading identifier detection

2021-11-10 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp:3
+
+#include 
+

RKSimon wrote:
> @serge-sans-paille Any chance you can remove the include and just forward 
> declare printf()?
Sure, I'll prepare a patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112914

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


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:98
   QualType PointeeTy = CastToTy->getPointeeType();
   QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
 

steakhal wrote:
> You only use `CanonPointeeTy.getLocalUnqualifiedType()` all the places. Spell 
> it once and reuse it everywhere.
Make sense!



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:104
 
-  // Handle casts from compatible types.
-  if (R->isBoundable())
+  const auto IsSameRegionType = [, CanonPointeeTy](const MemRegion *R) {
 if (const auto *TR = dyn_cast(R)) {

steakhal wrote:
> For me at least, a name like `IsSameRegionType()` would imply a function with 
> two parameters.
I'll carry `CanonPointeeTy` out.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:115
+  // Handle casts from compatible types.
+  if (R->isBoundable() && IsSameRegionType(R))
+return R;

steakhal wrote:
> BTW do you know what `isBoundable()` is? I'm just curious.
I've looked for information about it. It's poor, I'd say there is nothing of 
it. I'm curious as well.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:184
+// Edge case: we are at 0 bytes off the beginning of baseR. We
 // check to see if type we are casting to is the same as the base
+// region. If so, just return the base region.

steakhal wrote:
> 
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113480

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


[PATCH] D113555: [clangd] Mark macros from preamble for code completion

2021-11-10 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 accepted this revision.
usaxena95 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:567
 S.CanonicalDeclaration = R.Location;
+if (!HeaderFileURIs->getIncludeHeader(SM.getMainFileID()).empty()) {
+  S.Flags |= Symbol::IndexedForCodeCompletion;

Please add a comment about this (maybe similar to the parch description)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113555

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


[PATCH] D51650: Implement target_clones multiversioning

2021-11-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 386205.
erichkeane marked an inline comment as done.
erichkeane added a comment.

For the rest of multiversioning we count on the optimizer to remove variants 
made irrelevant, but I'm not sure opt can do anything like that yet :)  But nit 
made.


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

https://reviews.llvm.org/D51650

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-target-clones.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-cpuspecific.c
  clang/test/Sema/attr-target-clones.c

Index: clang/test/Sema/attr-target-clones.c
===
--- /dev/null
+++ clang/test/Sema/attr-target-clones.c
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify %s
+
+// expected-error@+1 {{'target_clones' multiversioning requires a default target}}
+void __attribute__((target_clones("sse4.2", "arch=sandybridge")))
+no_default(void);
+
+// expected-error@+2 {{'target_clones' and 'target' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target("sse4.2"), target_clones("arch=sandybridge")))
+ignored_attr(void);
+// expected-error@+2 {{'target' and 'target_clones' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target_clones("arch=sandybridge,default"), target("sse4.2")))
+ignored_attr2(void);
+
+int redecl(void);
+int __attribute__((target_clones("sse4.2", "default"))) redecl(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2", "default"))) redecl2(void);
+int __attribute__((target_clones("sse4.2", "default"))) redecl2(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2", "default"))) redecl3(void);
+int redecl3(void);
+
+int __attribute__((target_clones("sse4.2", "arch=atom", "default"))) redecl4(void);
+// expected-error@+3 {{'target_clones' attribute does not match previous declaration}}
+// expected-note@-2 {{previous declaration is here}}
+int __attribute__((target_clones("sse4.2", "arch=sandybridge", "default")))
+redecl4(void) { return 1; }
+
+int __attribute__((target("sse4.2"))) redef2(void) { return 1; }
+// expected-error@+2 {{multiversioning attributes cannot be combined}}
+// expected-note@-2 {{previous declaration is here}}
+int __attribute__((target_clones("sse4.2", "default"))) redef2(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2,default"))) redef3(void) { return 1; }
+// expected-error@+2 {{redefinition of 'redef3'}}
+// expected-note@-2 {{previous definition is here}}
+int __attribute__((target_clones("sse4.2,default"))) redef3(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2,default"))) redef4(void) { return 1; }
+// expected-error@+2 {{redefinition of 'redef4'}}
+// expected-note@-2 {{previous definition is here}}
+int __attribute__((target_clones("sse4.2,default"))) redef4(void) { return 1; }
+
+// Duplicates are allowed, however they alter name mangling.
+// expected-warning@+2 {{mixing 'target_clones' specifier mechanisms is permitted for GCC compatibility}}
+// expected-warning@+1 2 {{version list contains duplicate entries}}
+int __attribute__((target_clones("arch=atom,arch=atom", "arch=atom,default")))
+dupes(void) { return 1; }
+
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("")))
+empty_target_1(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones(",default")))
+empty_target_2(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default,")))
+empty_target_3(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default, ,avx2")))
+empty_target_4(void);
+
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default,avx2", "")))
+empty_target_5(void);
+
+// expected-warning@+1 {{version list contains duplicate entries}}
+void __attribute__((target_clones("default", "default")))
+dupe_default(void);
+
+// expected-warning@+1 {{version list contains duplicate entries}}
+void __attribute__((target_clones("avx2,avx2,default")))
+dupe_normal(void);
+
+// expected-error@+2 {{'target_clones' and 'target_clones' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void 

[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

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

Very solid patch!




Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:98
   QualType PointeeTy = CastToTy->getPointeeType();
   QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
 

You only use `CanonPointeeTy.getLocalUnqualifiedType()` all the places. Spell 
it once and reuse it everywhere.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:104
 
-  // Handle casts from compatible types.
-  if (R->isBoundable())
+  const auto IsSameRegionType = [, CanonPointeeTy](const MemRegion *R) {
 if (const auto *TR = dyn_cast(R)) {

For me at least, a name like `IsSameRegionType()` would imply a function with 
two parameters.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:115
+  // Handle casts from compatible types.
+  if (R->isBoundable() && IsSameRegionType(R))
+return R;

BTW do you know what `isBoundable()` is? I'm just curious.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:184
+// Edge case: we are at 0 bytes off the beginning of baseR. We
 // check to see if type we are casting to is the same as the base
+// region. If so, just return the base region.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113480

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


[PATCH] D51650: Implement target_clones multiversioning

2021-11-10 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss added a comment.

Thanks for the rebase!

Looks got to me,

`-march` may make the default same as one of the clone, in this case maybe we 
don't need to create two versions of the function. This could be solved later 
IMHO.




Comment at: clang/lib/Sema/SemaDecl.cpp:10662
+  return false;
+  break;
+}




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

https://reviews.llvm.org/D51650

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


[PATCH] D113575: Add `isInitCapture` and `forEachLambdaCapture` matchers.

2021-11-10 Thread James King via Phabricator via cfe-commits
jcking1034 created this revision.
jcking1034 added reviewers: ymandel, tdl-g, aaron.ballman, fowles.
jcking1034 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This contributes follow-up work from https://reviews.llvm.org/D112491, which
allows for increased control over the matching of lambda captures. This also
updates the documentation for the `lambdaCapture` matcher.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113575

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -4769,6 +4769,36 @@
 cxxConstructorDecl(forEachConstructorInitializer(cxxCtorInitializer();
 }
 
+TEST(ForEachLambdaCapture, MatchesCaptures) {
+  EXPECT_TRUE(matches(
+  "int main() { int x, y; auto f = [x, y]() { return x + y; }; }",
+  lambdaExpr(forEachLambdaCapture(lambdaCapture())), langCxx11OrLater()));
+  auto matcher = lambdaExpr(forEachLambdaCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(isInteger().bind("LC")));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "int main() { int x, y; float z; auto f = [=]() { return x + y + z; }; }",
+  matcher, std::make_unique>("LC", 2)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "int main() { int x, y; float z; auto f = [x, y, z]() { return x + y + "
+  "z; }; }",
+  matcher, std::make_unique>("LC", 2)));
+}
+
+TEST(ForEachLambdaCapture, IgnoreUnlessSpelledInSource) {
+  auto matcher =
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   lambdaExpr(forEachLambdaCapture(
+   lambdaCapture(capturesVar(varDecl(hasType(isInteger()
+   .bind("LC";
+  EXPECT_TRUE(
+  notMatches("int main() { int x, y; auto f = [=]() { return x + y; }; }",
+ matcher, langCxx11OrLater()));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "int main() { int x, y; float z; auto f = [=, ]() { return x + y + z; "
+  "}; }",
+  matcher, std::make_unique>("LC", 1)));
+}
+
 TEST(HasConditionVariableStatement, DoesNotMatchCondition) {
   EXPECT_TRUE(notMatches(
 "void x() { if(true) {} }",
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1439,6 +1439,22 @@
   EXPECT_TRUE(notMatches("int X;", M));
 }
 
+TEST_P(ASTMatchersTest, IsInitCapture) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  auto M = varDecl(hasName("vd"), isInitCapture());
+  EXPECT_TRUE(notMatches(
+  "int main() { int vd = 3; auto f = [vd]() { return vd; }; }", M));
+
+  if (!GetParam().isCXX14OrLater()) {
+return;
+  }
+  EXPECT_TRUE(matches("int main() { auto f = [vd=3]() { return vd; }; }", M));
+  EXPECT_TRUE(matches(
+  "int main() { int x = 3; auto f = [vd=x]() { return vd; }; }", M));
+}
+
 TEST_P(ASTMatchersTest, StorageDuration) {
   StringRef T =
   "void f() { int x; static int y; } int a;static int b;extern int c;";
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -246,6 +246,7 @@
   REGISTER_MATCHER(forEachArgumentWithParamType);
   REGISTER_MATCHER(forEachConstructorInitializer);
   REGISTER_MATCHER(forEachDescendant);
+  REGISTER_MATCHER(forEachLambdaCapture);
   REGISTER_MATCHER(forEachOverridden);
   REGISTER_MATCHER(forEachSwitchCase);
   REGISTER_MATCHER(forField);
@@ -424,6 +425,7 @@
   REGISTER_MATCHER(isImplicit);
   REGISTER_MATCHER(isInStdNamespace);
   REGISTER_MATCHER(isInTemplateInstantiation);
+  REGISTER_MATCHER(isInitCapture);
   REGISTER_MATCHER(isInline);
   REGISTER_MATCHER(isInstanceMessage);
   REGISTER_MATCHER(isInstanceMethod);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4205,6 +4205,45 @@
   InnerMatcher.matches(*Initializer, Finder, Builder));
 }
 
+/// Matches a variable serving as the implicit variable for a lambda init-
+/// capture.
+///
+/// Example matches x (matcher = varDecl(isInitCapture()))
+/// \code
+/// auto f = [x=3]() { return x; };
+/// \endcode
+AST_MATCHER(VarDecl, isInitCapture) { return Node.isInitCapture(); }
+
+/// Matches each lambda capture in 

[PATCH] D113120: [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG48bb5f4cbe8d: [clang] Add early exit when checking for const 
init of arrays. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113120

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// UNSUPPORTED: win32
+// RUN: ulimit -v 1048576
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// This used to require too much memory and crash with OOM.
+struct {
+  int a, b, c, d;
+} arr[1<<30];
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,28 +10596,55 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned N = CAT->getSize().getZExtValue();
+unsigned FinalSize = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), N, N);
-
-if (HadZeroInit)
-  for (unsigned I = 0; I != N; ++I)
-Value->getArrayInitializedElt(I) = Filler;
+*Value = APValue(APValue::UninitArray(), 0, FinalSize);
+if (FinalSize == 0)
+  return true;
 
-// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-for (unsigned I = 0; I != N; ++I)
-  if (!VisitCXXConstructExpr(E, ArrayElt, 
>getArrayInitializedElt(I),
- CAT->getElementType()) ||
-  !HandleLValueArrayAdjustment(Info, E, ArrayElt,
-   CAT->getElementType(), 1))
-return false;
+// We do the whole initialization in two passes, first for just one 
element,
+// then for the whole array. It's possible we may find out we can't do 
const
+// init in the first pass, in which case we avoid allocating a potentially
+// large array. We don't do more passes because expanding array requires
+// copying the data, which is wasteful.
+for (const unsigned N : {1u, FinalSize}) {
+  unsigned OldElts = Value->getArrayInitializedElts();
+  if (OldElts == N)
+break;
+
+  // Expand the array to appropriate size.
+  APValue NewValue(APValue::UninitArray(), N, FinalSize);
+  for (unsigned I = 0; I < OldElts; ++I)
+NewValue.getArrayInitializedElt(I).swap(
+Value->getArrayInitializedElt(I));
+  Value->swap(NewValue);
+
+  if (HadZeroInit)
+for (unsigned I = OldElts; I < N; ++I)
+  Value->getArrayInitializedElt(I) = Filler;
+
+  // Initialize the elements.
+  for (unsigned I = OldElts; I < N; ++I) {
+if (!VisitCXXConstructExpr(E, ArrayElt,
+   >getArrayInitializedElt(I),
+   CAT->getElementType()) ||
+!HandleLValueArrayAdjustment(Info, E, ArrayElt,
+ CAT->getElementType(), 1))
+  return false;
+// When checking for const initilization any diagnostic is considered
+// an error.
+if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
+!Info.keepEvaluatingAfterFailure())
+  return false;
+  }
+}
 
 return true;
   }


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// UNSUPPORTED: win32
+// RUN: ulimit -v 1048576
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// This used to require too much memory and crash with OOM.
+struct {
+  int a, b, c, d;
+} arr[1<<30];
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,28 +10596,55 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned N = CAT->getSize().getZExtValue();
+unsigned FinalSize = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && 

[clang] 48bb5f4 - [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T18:11:21+01:00
New Revision: 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3

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

LOG: [clang] Add early exit when checking for const init of arrays.

Before this commit, on code like:

  struct S { ... };
  S arr[1000];

while checking if arr is constexpr, clang would reserve memory for
arr before running constructor for S. If S turned out to not have a
valid constexpr c-tor, clang would still try to initialize each element
(and, in case the c-tor was trivial, even skipping the constexpr step
limit), only to discard that whole APValue later, since the first
element generated a diagnostic.

With this change, we start by allocating just 1 element in the array to
try out the c-tor and take an early exit if any diagnostics are
generated, avoiding possibly large memory allocation and a lot of work
initializing to-be-discarded APValues.

Fixes 51712 and 51843.

In the future we may want to be smarter about large possibly-constexrp
arrays and maybe make the allocation lazy.

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

Added: 
clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp

Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fa0d22064f0eb..a6da3d3fbea2d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10596,28 +10596,55 @@ bool ArrayExprEvaluator::VisitCXXConstructExpr(const 
CXXConstructExpr *E,
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned N = CAT->getSize().getZExtValue();
+unsigned FinalSize = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), N, N);
-
-if (HadZeroInit)
-  for (unsigned I = 0; I != N; ++I)
-Value->getArrayInitializedElt(I) = Filler;
+*Value = APValue(APValue::UninitArray(), 0, FinalSize);
+if (FinalSize == 0)
+  return true;
 
-// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-for (unsigned I = 0; I != N; ++I)
-  if (!VisitCXXConstructExpr(E, ArrayElt, 
>getArrayInitializedElt(I),
- CAT->getElementType()) ||
-  !HandleLValueArrayAdjustment(Info, E, ArrayElt,
-   CAT->getElementType(), 1))
-return false;
+// We do the whole initialization in two passes, first for just one 
element,
+// then for the whole array. It's possible we may find out we can't do 
const
+// init in the first pass, in which case we avoid allocating a potentially
+// large array. We don't do more passes because expanding array requires
+// copying the data, which is wasteful.
+for (const unsigned N : {1u, FinalSize}) {
+  unsigned OldElts = Value->getArrayInitializedElts();
+  if (OldElts == N)
+break;
+
+  // Expand the array to appropriate size.
+  APValue NewValue(APValue::UninitArray(), N, FinalSize);
+  for (unsigned I = 0; I < OldElts; ++I)
+NewValue.getArrayInitializedElt(I).swap(
+Value->getArrayInitializedElt(I));
+  Value->swap(NewValue);
+
+  if (HadZeroInit)
+for (unsigned I = OldElts; I < N; ++I)
+  Value->getArrayInitializedElt(I) = Filler;
+
+  // Initialize the elements.
+  for (unsigned I = OldElts; I < N; ++I) {
+if (!VisitCXXConstructExpr(E, ArrayElt,
+   >getArrayInitializedElt(I),
+   CAT->getElementType()) ||
+!HandleLValueArrayAdjustment(Info, E, ArrayElt,
+ CAT->getElementType(), 1))
+  return false;
+// When checking for const initilization any diagnostic is considered
+// an error.
+if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
+!Info.keepEvaluatingAfterFailure())
+  return false;
+  }
+}
 
 return true;
   }

diff  --git a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp 
b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
new file mode 100644
index 0..4504c0caed55f
--- /dev/null
+++ b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// UNSUPPORTED: win32
+// RUN: ulimit -v 1048576
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only 

[PATCH] D110927: [analyzer] Access stored value of a constant array through a pointer to another type

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

In D110927#3118936 , @ASDenysPetrov 
wrote:

>> You could have a parameter, and take its address to accomplish your 
>> reinterpret casts and type puns.
>
> Do you mean: ...
> If so, IMO it doesn't matter.

I see. Sorry about the confusion I caused.

In D110927#3115795 , @ASDenysPetrov 
wrote:

> Does anyone know how to check the status of`-fno-strict-aliasing` flag from 
> CSA side?

I think I know.
Within the `AnalysisConsumer::AnalysisConsumer()` you have access to the 
`CompilerInstance` object. Using that you can acquire the 
`CI.getCodeGenOpts().RelaxedAliasing` bool member, which represents exactly 
what we need, according to the 
`clang/include/clang/Basic/CodeGenOptions.def:211`:

  CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.

I think you should simply save a `const` reference to the `CodeGenOptions` 
object from the `AnalysisConsumer`.




Comment at: clang/test/Analysis/initialization.cpp:295-299
+void glob_cast_opposite_sign1() {
+  auto *ptr = (unsigned int *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // expected-warning{{garbage or undefined}}
+}

ASDenysPetrov wrote:
> steakhal wrote:
> > I think it's not correct.
> > 
> > `glob_arr2` refers to an object of dynamic type `int[2]`.
> > And the pointer decayed from it is `int *`, which has //similar type// to 
> > `unsigned *` what you are using to access the memory.
> > Since they are //similar//, this operation should work for all the valid 
> > indices, thus `ptr[0]`, `ptr[1]`, `ptr[2]`, `ptr[3]` should all be valid.
> > 
> > 
> > glob_arr2 refers to an object of dynamic type int[2].
> `glob_arr2` has an extent of 4.
> > And the pointer decayed from it is int *, which has similar type to 
> > unsigned * what you are using to access the memory.
> Yes, they are the same and it perfectly suits to 
> http://eel.is/c++draft/basic.lval#11 . But still you can't access other 
> element then the first one according to 
> http://eel.is/c++draft/basic.compound#3 : //For purposes of pointer 
> arithmetic ([expr.add]) and comparison ([expr.rel], [expr.eq]), [...] an 
> object of type T that is not an array element is considered to belong to an 
> array with one element of type T. //
> `unsigned int` and `int` are different types according to 
> http://eel.is/c++draft/basic.fundamental#2 . The object of type `unsigned 
> int` is NOT an array, beacuse there is no array of type `unsigned int`. Hence 
> you can only only access the first and a single element of type `unsigned 
> int`.
> 
Yes, `glob_arr` has 4 elements, sorry for this typo.

---
I disagree with the second part though. It seems like gcc disagrees as well: 
https://godbolt.org/z/5o7ozvPar
```lang=C++
auto foo(unsigned ()[4], int ()[4]) {
p[0] = 2;
q[0] = 1;
return p[0]; // memory read! thus, p and q can alias according to g++.
}
```
`gcc` still thinks that `p` and `q` can refer to the same memory region even if 
the `-fstrict-aliasing` flag is present.
In other circumstances, it would produce a `mov eax, 2` instead of a memory 
load if `p` and `q` cannot alias.


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

https://reviews.llvm.org/D110927

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


[PATCH] D112431: [ARM][clang] Define feature test macro for the PACBTI-M extension

2021-11-10 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 386195.
stuij added a comment.

addressing review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112431

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s 
-o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+Builder.defineMacro("__ARM_FEATURE_BTI", "1");
+
   if (HasBFloat16) {
 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+

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

2021-11-10 Thread Igor Kirillov 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 rG4860f6cb25bd: [OpenMP] Fix: opposite attributes could be set 
by -fno-inline (authored by igor.kirillov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112645

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

Index: clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
===
--- clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
+++ clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
@@ -1,5 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-attributes --include-generated-funcs
 // RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify -fopenmp -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify -fopenmp -triple x86_64-unknown-linux -emit-llvm -fno-inline %s -o - | FileCheck %s --check-prefix=CHECK-NOINLINE
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -8,6 +9,8 @@
 void foo() {
 #pragma omp parallel if(0)
   ;
+#pragma omp parallel
+  ;
 }
 
 #endif
@@ -23,6 +26,7 @@
 // CHECK-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4
 // CHECK-NEXT:call void @.omp_outlined.(i32* [[DOTTHREADID_TEMP_]], i32* [[DOTBOUND_ZERO_ADDR]]) #[[ATTR2:[0-9]+]]
 // CHECK-NEXT:call void @__kmpc_end_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
 // CHECK-NEXT:ret void
 //
 //
@@ -36,3 +40,52 @@
 // CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8, !tbaa [[TBAA7]]
 // CHECK-NEXT:ret void
 //
+//
+// CHECK: Function Attrs: alwaysinline norecurse nounwind
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]]) #[[ATTR3:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: mustprogress noinline nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-NOINLINE-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NOINLINE-NEXT:  entry:
+// CHECK-NOINLINE-NEXT:[[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
+// CHECK-NOINLINE-NEXT:call void @__kmpc_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NOINLINE-NEXT:store i32 [[TMP0]], i32* [[DOTTHREADID_TEMP_]], align 4, !tbaa [[TBAA3:![0-9]+]]
+// CHECK-NOINLINE-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4
+// CHECK-NOINLINE-NEXT:call void @.omp_outlined.(i32* [[DOTTHREADID_TEMP_]], i32* [[DOTBOUND_ZERO_ADDR]]) #[[ATTR2:[0-9]+]]
+// CHECK-NOINLINE-NEXT:call void @__kmpc_end_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NOINLINE-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
+// CHECK-NOINLINE-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: noinline norecurse nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@.omp_outlined.
+// CHECK-NOINLINE-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-NOINLINE-NEXT:  entry:
+// CHECK-NOINLINE-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NOINLINE-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NOINLINE-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8, !tbaa [[TBAA7:![0-9]+]]
+// CHECK-NOINLINE-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NOINLINE-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: alwaysinline norecurse nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-NOINLINE-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias 

[clang] 4860f6c - [OpenMP] Fix: opposite attributes could be set by -fno-inline

2021-11-10 Thread Igor Kirillov via cfe-commits

Author: Igor Kirillov
Date: 2021-11-10T16:48:09Z
New Revision: 4860f6cb25bd20b0fc2f20403602526df650d7ed

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

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

After the changes introduced by D106799 it is possible to tag
outlined function with both AlwaysInline and NoInline attributes using
-fno-inline command line options.
This issue is similiar to D107649.

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/parallel_if_codegen_PR51349.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 3dbebc5d3296..2cf01939d9b6 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -518,8 +518,10 @@ static llvm::Function *emitOutlinedFunctionPrologue(
   F->setDoesNotRecurse();
 
   // Always inline the outlined function if optimizations are enabled.
-  if (CGM.getCodeGenOpts().OptimizationLevel != 0)
+  if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
+F->removeFnAttr(llvm::Attribute::NoInline);
 F->addFnAttr(llvm::Attribute::AlwaysInline);
+  }
 
   // Generate the function.
   CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, TargetArgs,
@@ -5364,8 +5366,6 @@ static llvm::Function 
*emitOutlinedOrderedFunction(CodeGenModule ,
   CGF.CapturedStmtInfo = 
   llvm::Function *Fn = CGF.GenerateOpenMPCapturedStmtFunction(*S, Loc);
   Fn->setDoesNotRecurse();
-  if (CGM.getCodeGenOpts().OptimizationLevel != 0)
-Fn->addFnAttr(llvm::Attribute::AlwaysInline);
   return Fn;
 }
 

diff  --git a/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp 
b/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
index a00b5ec95ca0..982156054e45 100644
--- a/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
+++ b/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
@@ -1,5 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --include-generated-funcs
 // RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify 
-fopenmp -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
+// RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify 
-fopenmp -triple x86_64-unknown-linux -emit-llvm -fno-inline %s -o - | 
FileCheck %s --check-prefix=CHECK-NOINLINE
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -8,6 +9,8 @@
 void foo() {
 #pragma omp parallel if(0)
   ;
+#pragma omp parallel
+  ;
 }
 
 #endif
@@ -23,6 +26,7 @@ void foo() {
 // CHECK-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4
 // CHECK-NEXT:call void @.omp_outlined.(i32* [[DOTTHREADID_TEMP_]], i32* 
[[DOTBOUND_ZERO_ADDR]]) #[[ATTR2:[0-9]+]]
 // CHECK-NEXT:call void @__kmpc_end_serialized_parallel(%struct.ident_t* 
@[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
 // CHECK-NEXT:ret void
 //
 //
@@ -36,3 +40,52 @@ void foo() {
 // CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], 
align 8, !tbaa [[TBAA7]]
 // CHECK-NEXT:ret void
 //
+//
+// CHECK: Function Attrs: alwaysinline norecurse nounwind
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias 
[[DOTBOUND_TID_:%.*]]) #[[ATTR3:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** 
[[DOTGLOBAL_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], 
align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: mustprogress noinline nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-NOINLINE-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NOINLINE-NEXT:  entry:
+// CHECK-NOINLINE-NEXT:[[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[TMP0:%.*]] = call i32 
@__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
+// CHECK-NOINLINE-NEXT:call void 
@__kmpc_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NOINLINE-NEXT:store i32 [[TMP0]], i32* [[DOTTHREADID_TEMP_]], 
align 4, !tbaa [[TBAA3:![0-9]+]]
+// CHECK-NOINLINE-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4

[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

I did an experiment regarding the ICF issue and it seems not to affect kernel 
stub.

  #include "hip/hip_runtime.h"
  
  template
  void bar(T x) { }
  
  template
  __global__ void foo(T x) {}
  
  int main() {
foo<<<1,1>>>(1);
printf("%p\n", foo);
printf("%p\n", foo);
printf("%p\n", bar);
printf("%p\n", bar);
  }

If I pass `-Wl,/opt:noicf`, I got

  7FF622A01100
  7FF622A01170
  7FF622A01360
  7FF622A01370

By default, I got

  7FF693521100
  7FF693521170
  7FF693521360
  7FF693521360

This indicates bar and bar are folded but kernel stubs are not 
folded.

I also tried `-Wl,/opt:icf=10`, and kernel stubs are still not folded.

For HIP, since the kernel stub passes a unique kernel symbol to the internal 
kernel launching API, you may think the kernel stubs are not folded because 
they are not identical.

To imitate the CUDA case, where the address of kernel stub function itself is 
passed to the internal kernel launching API, I used the original patch of this 
review, where the kernel stub function passes the address of itself to the 
internal kernel launching API, therefore in a sense, the kernel stubs are all 
the same. Still, the kernel stubs are not folded.

Looking at the assembly of the kernel stub function:

  ; foo
  .seh_proc "??$foo@H@@YAXH@Z"
  # %bb.0:
  pushq   %rsi
  .seh_pushreg %rsi
  pushq   %rdi
  .seh_pushreg %rdi
  subq$120, %rsp
  .seh_stackalloc 120
  .seh_endprologue
  movl%ecx, 60(%rsp)
  leaq60(%rsp), %rax
  movq%rax, 64(%rsp)
  leaq104(%rsp), %rsi
  leaq88(%rsp), %rdi
  leaq80(%rsp), %r8
  leaq72(%rsp), %r9
  movq%rsi, %rcx
  movq%rdi, %rdx
  callq   __hipPopCallConfiguration
  movq80(%rsp), %rax
  movq72(%rsp), %rcx
  movq%rcx, 40(%rsp)
  movq%rax, 32(%rsp)
  leaq"??$foo@H@@YAXH@Z"(%rip), %rcx
  leaq64(%rsp), %r9
  movq%rsi, %rdx
  movq%rdi, %r8
  callq   hipLaunchKernel
  nop
  addq$120, %rsp
  popq%rdi
  popq%rsi
  retq
  .seh_endproc
  
  ; foo
  .seh_proc "??$foo@M@@YAXM@Z"
  # %bb.0:
  pushq   %rsi
  .seh_pushreg %rsi
  pushq   %rdi
  .seh_pushreg %rdi
  subq$120, %rsp
  .seh_stackalloc 120
  .seh_endprologue
  movss   %xmm0, 60(%rsp)
  leaq60(%rsp), %rax
  movq%rax, 64(%rsp)
  leaq104(%rsp), %rsi
  leaq88(%rsp), %rdi
  leaq80(%rsp), %r8
  leaq72(%rsp), %r9
  movq%rsi, %rcx
  movq%rdi, %rdx
  callq   __hipPopCallConfiguration
  movq80(%rsp), %rax
  movq72(%rsp), %rcx
  movq%rcx, 40(%rsp)
  movq%rax, 32(%rsp)
  leaq"??$foo@M@@YAXM@Z"(%rip), %rcx
  leaq64(%rsp), %r9
  movq%rsi, %rdx
  movq%rdi, %r8
  callq   hipLaunchKernel
  nop
  addq$120, %rsp
  popq%rdi
  popq%rsi
  retq
  .seh_endproc

I think they are not folded because link.exe is smart enough to treat them as 
not identical comdat functions. I think we may stop worrying about the ICF 
foading kernel stubs.


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

https://reviews.llvm.org/D112492

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


[PATCH] D112914: Misleading identifier detection

2021-11-10 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp:3
+
+#include 
+

@serge-sans-paille Any chance you can remove the include and just forward 
declare printf()?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112914

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


[PATCH] D112914: Misleading identifier detection

2021-11-10 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@serge-sans-paille Still failing on 
https://lab.llvm.org/buildbot/#/builders/139/builds/12974


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112914

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


[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

Peanut gallery says: It seems like `Proto->canThrow()` is already returning the 
correct answer for C++17-and-later: a function declared `throw()` cannot throw. 
So from the POV of C++17-and-later, this could be a simple patch:

  - if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
  + if (Proto->canThrow() == CT_Cannot) {

and the only reason we can't do this is because C++14-and-earlier needs a 
different behavior.

Meanwhile, it looks as if every other use of `isNoexceptExceptionSpec` (or its 
inverse `isDynamicExceptionSpec`) is related to pretty-printing the exception 
specification, and isn't used for semantics at all.
Perhaps a cleaner way to preserve the current special case for 
C++14-and-earlier is to add a "language version" parameter to `canThrow`, 
and/or introduce an `isEssentiallyNoexcept()` helper:

  - if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
  + if (Proto->isEssentiallyNoexcept(getLangOpts())) {


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[PATCH] D113570: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a2b1bdb4c8a: [clang] Do not crash in APValue::prettyPrint() 
on forward-decl structs. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113570

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/APValue.cpp


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7a2b1bd - [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T17:17:00+01:00
New Revision: 7a2b1bdb4c8a099ebc38b7f802988244ad21fcc0

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

LOG: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

The call to getTypeSizeInChars() is replaced with
getTypeSizeInCharsIfKnown(), which does not crash on forward declared
structs. This only affects printing.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/AST/APValue.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 2e33ce4c5d101..53df965fef2fa 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@ TEST(Hover, SpaceshipTemplateNoCrash) {
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 9a9233bc1ea74..ef333c7711663 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@ void APValue::printPretty(raw_ostream , const 
PrintingPolicy ,
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";



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


[PATCH] D111443: [Driver] Fix ToolChain::getSanitizerArgs

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

@eugenis Any further changes needed? Thanks.


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

https://reviews.llvm.org/D111443

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


[PATCH] D113299: [NFC] Inclusive Language: change master to main for .chm files

2021-11-10 Thread Quinn Pham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc3b15b71ce00: [NFC] Inclusive Language: change master to 
main for .chm files (authored by quinnp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113299

Files:
  clang-tools-extra/docs/doxygen.cfg.in
  clang/docs/doxygen.cfg.in
  flang/docs/doxygen.cfg.in
  lldb/docs/doxygen.cfg.in
  llvm/docs/doxygen.cfg.in
  mlir/docs/doxygen.cfg.in
  openmp/docs/doxygen.cfg.in
  openmp/runtime/doc/doxygen/config
  polly/docs/doxygen.cfg.in

Index: polly/docs/doxygen.cfg.in
===
--- polly/docs/doxygen.cfg.in
+++ polly/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: openmp/runtime/doc/doxygen/config
===
--- openmp/runtime/doc/doxygen/config
+++ openmp/runtime/doc/doxygen/config
@@ -1048,7 +1048,7 @@
 
 # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
 # controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
+# it should be included in the main .chm file (NO).
 
 GENERATE_CHI   = NO
 
Index: openmp/docs/doxygen.cfg.in
===
--- openmp/docs/doxygen.cfg.in
+++ openmp/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: mlir/docs/doxygen.cfg.in
===
--- mlir/docs/doxygen.cfg.in
+++ mlir/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: llvm/docs/doxygen.cfg.in
===
--- llvm/docs/doxygen.cfg.in
+++ llvm/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: lldb/docs/doxygen.cfg.in
===
--- lldb/docs/doxygen.cfg.in
+++ lldb/docs/doxygen.cfg.in
@@ -916,7 +916,7 @@
 
 # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
 # controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
+# it should be included in the main .chm file (NO).
 
 GENERATE_CHI   = NO
 
Index: flang/docs/doxygen.cfg.in
===
--- flang/docs/doxygen.cfg.in
+++ flang/docs/doxygen.cfg.in
@@ -1222,7 +1222,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: clang/docs/doxygen.cfg.in
===
--- clang/docs/doxygen.cfg.in
+++ clang/docs/doxygen.cfg.in
@@ -1219,7 +1219,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: clang-tools-extra/docs/doxygen.cfg.in
===
--- clang-tools-extra/docs/doxygen.cfg.in
+++ clang-tools-extra/docs/doxygen.cfg.in
@@ -1230,7 +1230,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate 

[PATCH] D113256: [AArch64][ARM] Enablement of Cortex-A710 Support

2021-11-10 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ updated this revision to Diff 386165.
mubashar_ marked 5 inline comments as done.
mubashar_ added a comment.

Placement of Cortex-A710 items changed to order specified by previous comments.


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

https://reviews.llvm.org/D113256

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -309,6 +309,13 @@
  ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS |
  ARM::AEK_FP16 | ARM::AEK_DOTPROD,
  "8.2-A"),
+ARMCPUTestParams("cortex-a710", "armv9-a", "neon-fp-armv8",
+ ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
+ ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
+ ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS |
+ ARM::AEK_DOTPROD | ARM::AEK_FP16FML |
+ ARM::AEK_BF16 | ARM::AEK_I8MM | ARM::AEK_SB,
+ "9-A"),
 ARMCPUTestParams("cortex-a77", "armv8.2-a", "crypto-neon-fp-armv8",
  ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
  ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
@@ -386,7 +393,7 @@
  ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
  "7-S")));
 
-static constexpr unsigned NumARMCPUArchs = 86;
+static constexpr unsigned NumARMCPUArchs = 87;
 
 TEST(TargetParserTest, testARMCPUArchList) {
   SmallVector List;
@@ -984,6 +991,17 @@
  AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
  AArch64::AEK_RCPC | AArch64::AEK_SSBS,
  "8.2-A"),
+ARMCPUTestParams("cortex-a710", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_SVE2 |
+ AArch64::AEK_DOTPROD | AArch64::AEK_MTE |
+ AArch64::AEK_FP16FML | AArch64::AEK_SVE2BITPERM |
+ AArch64::AEK_PAUTH | AArch64::AEK_FLAGM |
+ AArch64::AEK_SB | AArch64::AEK_I8MM |
+ AArch64::AEK_BF16,
+ "9-A"),
 ARMCPUTestParams(
 "neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
 AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
@@ -1208,7 +1226,7 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 51;
+static constexpr unsigned NumAArch64CPUArchs = 52;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/ARM/ARMSubtarget.h
===
--- llvm/lib/Target/ARM/ARMSubtarget.h
+++ llvm/lib/Target/ARM/ARMSubtarget.h
@@ -65,6 +65,7 @@
 CortexA77,
 CortexA78,
 CortexA78C,
+CortexA710,
 CortexA8,
 CortexA9,
 CortexM3,
Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -295,6 +295,7 @@
   case CortexA77:
   case CortexA78:
   case CortexA78C:
+  case CortexA710:
   case CortexR4:
   case CortexR4F:
   case CortexR5:
Index: llvm/lib/Target/ARM/ARM.td
===
--- llvm/lib/Target/ARM/ARM.td
+++ llvm/lib/Target/ARM/ARM.td
@@ -636,6 +636,8 @@
"Cortex-A78 ARM processors", []>;
 def ProcA78C: SubtargetFeature<"a78c", "ARMProcFamily", "CortexA78C",
"Cortex-A78C ARM processors", []>;
+def ProcA710: SubtargetFeature<"cortex-a710", "ARMProcFamily",
+   "CortexA710", "Cortex-A710 ARM processors", []>;
 def ProcX1  : SubtargetFeature<"cortex-x1", "ARMProcFamily", "CortexX1",
"Cortex-X1 ARM processors", []>;
 
@@ -1380,6 +1382,14 

[PATCH] D113570: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113570

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


[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D113517#3120030 , @rsmith wrote:

> What's the motivation for this change? I believe the current behavior is 
> still conforming: `set_unexpected` is no longer (officially) part of the 
> standard library (though it still exists as a zombie name), and the default 
> `unexpected` handler calls `terminate`, so calling `unexpected` rather than 
> `terminate` should have the same effect, except in non-conforming programs 
> that call `std::set_unexpected` anyway (and for such programs, calling 
> `unexpected` seems like the behavior the programmer would expect). Do we 
> generate better code if we call `terminate` rather than `unexpected`?

Today: no, we don't.

But, I'm planning to propose further changes to improve noexcept codegen in 
Clang -- which is currently quite bad, compared to what it should be, because 
it's effectively following the same rules as legacy throw(). This change allows 
those future optimizations to apply to throw() as well, in C++17 mode, which is 
the desirable outcome.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


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

2021-11-10 Thread Jon Chesterfield 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 rG27177b82d4ca: [OpenMP] Lower printf to __llvm_omp_vprintf 
(authored by JonChesterfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

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

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

[clang] 27177b8 - [OpenMP] Lower printf to __llvm_omp_vprintf

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

Author: Jon Chesterfield
Date: 2021-11-10T15:30:56Z
New Revision: 27177b82d4ca4451f288168fc1e06c0736afbdaf

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

LOG: [OpenMP] Lower printf to __llvm_omp_vprintf

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

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

Reviewed By: jdoerfert

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fab21e5b588a5..18e429cf3efd2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5106,11 +5106,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getFloatTy()));
   }
   case Builtin::BIprintf:
-if (getTarget().getTriple().isNVPTX())
-  return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);
-if (getTarget().getTriple().getArch() == Triple::amdgcn &&
-getLangOpts().HIP)
-  return EmitAMDGPUDevicePrintfCallExpr(E, ReturnValue);
+if (getTarget().getTriple().isNVPTX() ||
+getTarget().getTriple().isAMDGCN()) {
+  if (getLangOpts().OpenMPIsDevice)
+return EmitOpenMPDevicePrintfCallExpr(E);
+  if (getTarget().getTriple().isNVPTX())
+return EmitNVPTXDevicePrintfCallExpr(E);
+  if (getTarget().getTriple().isAMDGCN() && getLangOpts().HIP)
+return EmitAMDGPUDevicePrintfCallExpr(E);
+}
+
 break;
   case Builtin::BI__builtin_canonicalize:
   case Builtin::BI__builtin_canonicalizef:

diff  --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 43192c587e262..fdd2fa18bb4a0 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -21,13 +21,14 @@
 using namespace clang;
 using namespace CodeGen;
 
-static llvm::Function *GetVprintfDeclaration(llvm::Module ) {
+namespace {
+llvm::Function *GetVprintfDeclaration(llvm::Module ) {
   llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
 llvm::Type::getInt8PtrTy(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
-  if (auto* F = M.getFunction("vprintf")) {
+  if (auto *F = M.getFunction("vprintf")) {
 // Our CUDA system header declares vprintf with the right signature, so
 // nobody else should have been able to declare vprintf with a bogus
 // signature.
@@ -41,6 +42,28 @@ static llvm::Function *GetVprintfDeclaration(llvm::Module 
) {
   VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, "vprintf", );
 }
 
+llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule ) {
+  const char *Name = "__llvm_omp_vprintf";
+  llvm::Module  = CGM.getModule();
+  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
+llvm::Type::getInt8PtrTy(M.getContext()),
+llvm::Type::getInt32Ty(M.getContext())};
+  llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
+  llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);

[PATCH] D113570: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
adamcz requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

The call to getTypeSizeInChars() is replaced with
getTypeSizeInCharsIfKnown(), which does not crash on forward declared
structs. This only affects printing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113570

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/APValue.cpp


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

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

- regen test file using the better './llvm/utils/update_cc_test_checks.py 
--llvm-bin=/home/amd/llvm-install/bin 
clang/test/OpenMP/nvptx_target_printf_codegen.c', now passing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

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

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

[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4290-4293
-  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
-  // them being "merged" by the COMDAT Folding linker optimization.
-  if (D.hasAttr())
-return false;

rnk wrote:
> rnk wrote:
> > tra wrote:
> > > This was added in D63277 specifically to deal with comdat-related issue 
> > > on windows. 
> > > 
> > > We do need to have unique addresses for each kernel stub. Placing stubs 
> > > into comdat may allow them to be merged into one and that would be a 
> > > problem.
> > > https://docs.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=vs-2019
> > >  
> > > 
> > > @rnk,@kpyzhov -- how do we make sure that identical functions are placed 
> > > in comdat (needed for templates) but do not get comdat-folded with 
> > > `/OPT:ICF`? 
> > > 
> > These are readonly global variables. I believe MSVC's ICF implementation 
> > changed behavior here a few times over the years. I think the current state 
> > is that they don't merge such globals. If you are using LLD, you can use 
> > safe ICF to avoid merging such globals.
> > 
> > @zequanwu reviewed the state of ICF in LLD in the last year, so he may know 
> > more about the current status, and he may be more helpful if you have more 
> > questions.
> > 
> > Finally, you could mark these globals as mutable if you really want to 
> > block ICF. That will work reliably with any linker.
> Broadly, I think this change is correct. If I had reviewed D63277, I probably 
> would have objected to it and not approved it.
These symbols are for kernel stub functions. How do I mark them as mutable? 


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

https://reviews.llvm.org/D112492

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


[PATCH] D112915: [clang][modules] Track number of includes per submodule

2021-11-10 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 386139.
jansvoboda11 added a comment.

Store only direct includes in the PCM (compared to transitive stored 
previously), use InputFile ID (instead of full filesystem path).

Also: add test of transitive includes, fix bug in 
`VisibleModuleSet::setVisible`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112915

Files:
  clang/include/clang/Lex/ExternalPreprocessorSource.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/import-submodule-visibility.c

Index: clang/test/Modules/import-submodule-visibility.c
===
--- /dev/null
+++ clang/test/Modules/import-submodule-visibility.c
@@ -0,0 +1,99 @@
+// This test checks that imports of headers that appeared in a different submodule than
+// what is imported by the current TU don't affect the compilation.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- A.framework/Headers/A.h
+#include "Textual.h"
+//--- A.framework/Modules/module.modulemap
+framework module A { header "A.h" }
+
+//--- B.framework/Headers/B1.h
+#include "Textual.h"
+//--- B.framework/Headers/B2.h
+//--- B.framework/Modules/module.modulemap
+framework module B {
+  module B1 { header "B1.h" }
+  module B2 { header "B2.h" }
+}
+
+//--- C/C.h
+#include "Textual.h"
+//--- C/module.modulemap
+module C { header "C.h" }
+
+//--- D/D1.h
+#include "Textual.h"
+//--- D/D2.h
+//--- D/module.modulemap
+module D {
+  module D1 { header "D1.h" }
+  module D2 { header "D2.h" }
+}
+
+//--- E/E1.h
+#include "E2.h"
+//--- E/E2.h
+#include "Textual.h"
+//--- E/module.modulemap
+module E {
+  module E1 { header "E1.h" }
+  module E2 { header "E2.h" }
+}
+
+//--- Textual.h
+#define MACRO_TEXTUAL 1
+
+//--- test.c
+
+#ifdef A
+//
+#endif
+
+#ifdef B
+#import 
+#endif
+
+#ifdef C
+//
+#endif
+
+#ifdef D
+#import "D/D2.h"
+#endif
+
+#ifdef E
+#import "E/E1.h"
+#endif
+
+#import "Textual.h"
+
+static int x = MACRO_TEXTUAL;
+
+// Specifying the PCM file on the command line (without actually importing "A") should not
+// prevent "Textual.h" to be included in the TU.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/A.framework/Modules/module.modulemap -fmodule-name=A -o %t/A.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DA -fmodule-file=%t/A.pcm
+
+// Specifying the PCM file on the command line and importing "B2" in the source does not
+// prevent "Textual.h" to be included in the TU.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/B.framework/Modules/module.modulemap -fmodule-name=B -o %t/B.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DB -iframework %t -fmodule-file=%t/B.pcm
+
+// Module-only version of the test with framework A.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/C/module.modulemap -fmodule-name=C -o %t/C.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DC -fmodule-file=%t/C.pcm
+
+// Module-only version of the test with framework B.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/D/module.modulemap -fmodule-name=D -o %t/D.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DD -fmodule-file=%t/D.pcm
+
+// Transitively imported, but not exported.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/E/module.modulemap -fmodule-name=E -o %t/E.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DE -fmodule-file=%t/E.pcm
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1696,7 +1696,7 @@
 std::pair
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1728,7 +1728,6 @@
   | (Data.HFI.DirInfo << 1)
   | Data.HFI.IndexHeaderMapHeader;
   LE.write(Flags);
-  LE.write(Data.HFI.NumIncludes);
 
   if (!Data.HFI.ControllingMacro)
 LE.write(Data.HFI.ControllingMacroID);
@@ -2171,6 +2170,42 @@
   return false;
 }
 
+void ASTWriter::addIncludedFiles(
+const llvm::DenseMap ,
+RecordDataImpl ) {
+  // 

[PATCH] D113538: OpenMP: Start calling setTargetAttributes for generated kernels

2021-11-10 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 386137.
arsenm added a comment.

Also test non-kernel


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

https://reviews.llvm.org/D113538

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/OpenMP/amdgcn-attributes.cpp

Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -0,0 +1,43 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=DEFAULT,ALL %s
+// RUN: %clang_cc1 -target-cpu gfx900 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=CPU,ALL %s
+
+// RUN: %clang_cc1 -menable-no-nans -mno-amdgpu-ieee -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=NOIEEE,ALL %s
+// RUN: %clang_cc1 -munsafe-fp-atomics -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=UNSAFEATOMIC,ALL %s
+
+// expected-no-diagnostics
+
+#define N 100
+
+int callable(int);
+
+// Check that the target attributes are set on the generated kernel
+int func() {
+  // ALL-LABEL: amdgpu_kernel void @__omp_offloading{{.*}} #0
+
+  int arr[N];
+
+#pragma omp target
+  for (int i = 0; i < N; i++) {
+arr[i] = callable(arr[i]);
+  }
+
+  return arr[0];
+}
+
+int callable(int x) {
+  // ALL-LABEL: @_Z8callablei(i32 %x) #1
+  return x + 1;
+}
+
+  // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-implicitarg-num-bytes"="56" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+  // CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-implicitarg-num-bytes"="56" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" }
+  // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-ieee"="false" "amdgpu-implicitarg-num-bytes"="56" "frame-pointer"="none" "min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+  // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-implicitarg-num-bytes"="56" "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+// DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" }
+// NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// UNSAFEATOMIC: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9143,6 +9143,10 @@
 public:
   AMDGPUTargetCodeGenInfo(CodeGenTypes )
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  void setFunctionDeclAttributes(const FunctionDecl *FD, llvm::Function *F,
+ CodeGenModule ) const;
+
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override;
   unsigned getOpenCLKernelCallingConv() const override;
@@ -9182,36 +9186,13 @@

[PATCH] D113538: OpenMP: Start calling setTargetAttributes for generated kernels

2021-11-10 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D113538#3121062 , @JonChesterfield 
wrote:

> That seems important. What was the symptom of failing to set these? We may 
> now be redundantly setting some, e.g. 
> I think convergent is set somewhere else before this patch.

A bunch of missing attributes on the kernel. The one I noticed was not setting 
amdgpu-implicitarg-num-bytes (although D112488 
 avoids needing to do that), but we have a 
few other attributes that simply wouldn't be set. I'm fighting with some 
divergence between upstream and the internal branches with these attributes. In 
particular, the internal branch is hacking on the generic attributes for 
openmp, and also redundantly (and incorrectly) setting 
amdgpu-flat-work-group-size to the invalid range 257,257.

convergent isn't a target attribute and isn't the target's responsibility to 
add.


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

https://reviews.llvm.org/D113538

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


[clang] 4fb0805 - [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-11-10 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-11-10T12:52:05Z
New Revision: 4fb0805c6525b13e50067b9ddfe8677a0b7b2d7c

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

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

Added: 


Modified: 
clang/include/clang/CodeGen/ModuleBuilder.h
clang/include/clang/Interpreter/Interpreter.h
clang/lib/CodeGen/ModuleBuilder.cpp
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Interpreter/Interpreter.cpp
clang/unittests/Interpreter/CMakeLists.txt
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/ModuleBuilder.h 
b/clang/include/clang/CodeGen/ModuleBuilder.h
index f9d056ed8b1ea..26587e73bf6c7 100644
--- a/clang/include/clang/CodeGen/ModuleBuilder.h
+++ b/clang/include/clang/CodeGen/ModuleBuilder.h
@@ -74,6 +74,10 @@ class CodeGenerator : public ASTConsumer {
   /// This may return null if there was no matching declaration.
   const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
 
+  /// Given a global declaration, return a mangled name for this declaration
+  /// which has been added to this code generator via a Handle method.
+  llvm::StringRef GetMangledName(GlobalDecl GD);
+
   /// Return the LLVM address of the given global entity.
   ///
   /// \param isForDefinition If true, the caller intends to define the

diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 9f5b64ce21243..2dc0fd5963a2f 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -16,6 +16,8 @@
 
 #include "clang/Interpreter/PartialTranslationUnit.h"
 
+#include "clang/AST/GlobalDecl.h"
+
 #include "llvm/ExecutionEngine/JITSymbol.h"
 #include "llvm/Support/Error.h"
 
@@ -66,8 +68,20 @@ class Interpreter {
   return Execute(*PTU);
 return llvm::Error::success();
   }
+
+  /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses
+  /// the CodeGenModule's internal mangling cache to avoid recomputing the
+  /// mangled name.
+  llvm::Expected getSymbolAddress(GlobalDecl GD) const;
+
+  /// \returns the \c JITTargetAddress of a given name as written in the IR.
+  llvm::Expected
+  getSymbolAddress(llvm::StringRef IRName) const;
+
+  /// \returns the \c JITTargetAddress of a given name as written in the object
+  /// file.
   llvm::Expected
-  getSymbolAddress(llvm::StringRef UnmangledName) const;
+  getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
 };
 } // namespace clang
 

diff  --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index b63f756ca2884..f6642a79e1e48 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -122,6 +122,10 @@ namespace {
   return D;
 }
 
+llvm::StringRef GetMangledName(GlobalDecl GD) {
+  return Builder->getMangledName(GD);
+}
+
 llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) {
   return Builder->GetAddrOfGlobal(global, 
ForDefinition_t(isForDefinition));
 }
@@ -325,6 +329,10 @@ const Decl 
*CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
 
+llvm::StringRef CodeGenerator::GetMangledName(GlobalDecl GD) {
+  return static_cast(this)->GetMangledName(GD);
+}
+
 llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global,
bool isForDefinition) {
   return static_cast(this)

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 230b49167f347..705235aafa070 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -61,8 +61,11 @@ llvm::Error IncrementalExecutor::runCtors() const {
 }
 
 llvm::Expected
-IncrementalExecutor::getSymbolAddress(llvm::StringRef UnmangledName) const {
-  auto Sym = Jit->lookup(UnmangledName);
+IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
+  SymbolNameKind NameKind) const {
+  auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
+  : Jit->lookup(Name);
+
   if (!Sym)
 return Sym.takeError();
   return Sym->getAddress();

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index b626ebedcdc30..24447994d5f1d 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ 

  1   2   >