[PATCH] D159167: [clang-repl][Orc] Export executable symbols in ClangReplInterpreterExceptionTests

2023-08-29 Thread Kai Luo via Phabricator via cfe-commits
lkail created this revision.
lkail added reviewers: lhames, v.g.vassilev.
Herald added a project: All.
lkail requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

In Orc runtime, we use `dlopen(nullptr, ...)` to open current executable, this 
requires `-rdynamic` flag.

As `llvm/CMakeLists.txt` suggests

  # Make sure we don't get -rdynamic in every binary. For those that need it,
  # use export_executable_symbols(target).

This patch exports symbols in `ClangReplInterpreterExceptionTests`. This also 
fixes `ClangReplInterpreterExceptionTests` is skipped on ppc64 when jitlink is 
used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159167

Files:
  clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt


Index: clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
===
--- clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -22,3 +22,5 @@
   clangFrontend
   )
 add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)
+
+export_executable_symbols(ClangReplInterpreterExceptionTests)


Index: clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
===
--- clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -22,3 +22,5 @@
   clangFrontend
   )
 add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)
+
+export_executable_symbols(ClangReplInterpreterExceptionTests)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-29 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta accepted this revision.
xgupta added a comment.
This revision is now accepted and ready to land.

LGTM, Thanks!


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

https://reviews.llvm.org/D158540

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-29 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 554571.

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

https://reviews.llvm.org/D158540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/special/class.copy/p13-0x.cpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -54,5 +54,5 @@
 
 struct W {
   int w;
-  constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor is not constexpr}}
+  constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class}}
 };
Index: clang/test/CXX/special/class.copy/p13-0x.cpp
===
--- clang/test/CXX/special/class.copy/p13-0x.cpp
+++ clang/test/CXX/special/class.copy/p13-0x.cpp
@@ -125,7 +125,7 @@
 mutable A a;
   };
   struct C {
-constexpr C(const C &) = default; // expected-error {{not constexpr}}
+constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}}
 A a;
   };
 }
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -129,19 +129,19 @@
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class}}
 #endif
 union C { int n = 0; constexpr C() = default; };
 struct D { union {}; constexpr D() = default; }; // expected-error {{does not declare anything}}
 struct E { union { int n; }; constexpr E() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class}}
 #endif
 struct F { union { int n = 0; }; constexpr F() = default; };
 
 struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class}}
 #endif
 struct H {
   union {
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -328,10 +328,10 @@
 namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
-  union B { constexpr B() = default; int a; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
-  union C { constexpr C() = default; int a, b; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class}} expected-note 2{{candidate}}
+  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class}} expected-note 2{{candidate}}
   struct X { constexpr X() = default; union {}; }; // expected-error {{does not declare anything}}
-  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base classes}} expected-note {{see reference to function 'Y' in 'Y' class}} expected-note 2{{candidate}}
 
   constexpr A a = A();
   constexpr B b = B(); // expected-error {{no matching}}
Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
===
--- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ 

[PATCH] D153907: [AIX] [TOC] Add -mtocdata/-mno-tocdata options on AIX

2023-08-29 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/docs/UsersManual.rst:3161
+static storage duration, including static data members of classes and
+block-scope static variables will be marked with the toc-data attribute.
+Alternatively, the user can specify a comma separated list of external linkage

The "toc-data attribute" is an implementation detail. The user-facing 
documentation should not talk about it.



Comment at: clang/docs/UsersManual.rst:3173
+which variables will be an exception to -mno-tocdata. Alternatively, a user
+may specify -mtocdata to mark all suitable variables with toc-data and specify
+-mno-tocdata= to add which variables will be an exception to -mtocdata.

Please document the conditions for a variable to be "suitable".



Comment at: clang/docs/UsersManual.rst:3178
+
+  Mark all external linkage variables and variables with static storage 
duration
+  that are not explicitly specified with -mno-tocdata= as toc-data.

The use of "all" is incorrect. Please qualify with "suitable" (and address this 
issue elsewhere in the text where applicable).



Comment at: clang/docs/UsersManual.rst:3159
 
+Mark TOC Data / Not TOC Data (AIX-specific)
+---

amyk wrote:
> 
@syzaara, I see the comment has been addressed but it is not marked as "done". 
The author is responsible for marking comments as "done" in Phabricator. Please 
mark all comments that you believe have been addressed as "done" so that other 
parties know if the comment is still pending action.


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

https://reviews.llvm.org/D153907

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


[PATCH] D159163: [analyzer][NFC] Workaround miscompilation on recent MSVC

2023-08-29 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a reviewer: steakhal.
danix800 added a project: clang.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/62130


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159163

Files:
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159054: [Driver] Removal of C_INCLUDE_DIRS feature

2023-08-29 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 554567.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159054

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Haiku.cpp
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/OHOS.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/lib/Lex/InitHeaderSearch.cpp

Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -13,7 +13,6 @@
 #include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
-#include "clang/Config/config.h" // C_INCLUDE_DIRS
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
@@ -257,16 +256,6 @@
   if (!HSOpts.UseStandardSystemIncludes)
 return;
 
-  // Add dirs specified via 'configure --with-c-include-dirs'.
-  StringRef CIncludeDirs(C_INCLUDE_DIRS);
-  if (CIncludeDirs != "") {
-SmallVector dirs;
-CIncludeDirs.split(dirs, ":");
-for (StringRef dir : dirs)
-  AddPath(dir, ExternCSystem, false);
-return;
-  }
-
   switch (os) {
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -10,7 +10,6 @@
 #include "CommonArgs.h"
 #include "Gnu.h"
 #include "clang/Basic/Version.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -413,19 +412,6 @@
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
-  // Check for configure-time C include directories.
-  StringRef CIncludeDirs(C_INCLUDE_DIRS);
-  if (CIncludeDirs != "") {
-SmallVector dirs;
-CIncludeDirs.split(dirs, ":");
-for (StringRef dir : dirs) {
-  StringRef Prefix =
-  llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot);
-  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
-}
-return;
-  }
-
   if (getTriple().getOS() != llvm::Triple::UnknownOS) {
 const std::string MultiarchTriple =
 getMultiarchTriple(D, getTriple(), D.SysRoot);
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -9,7 +9,6 @@
 #include "Solaris.h"
 #include "CommonArgs.h"
 #include "clang/Basic/LangStandard.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -296,19 +295,6 @@
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
-  // Check for configure-time C include directories.
-  StringRef CIncludeDirs(C_INCLUDE_DIRS);
-  if (CIncludeDirs != "") {
-SmallVector dirs;
-CIncludeDirs.split(dirs, ":");
-for (StringRef dir : dirs) {
-  StringRef Prefix =
-  llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot);
-  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
-}
-return;
-  }
-
   // Add include directories specific to the selected multilib set and multilib.
   if (GCCInstallation.isValid()) {
 const MultilibSet::IncludeDirsFunc  =
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -11,7 +11,6 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
@@ -307,19 +306,6 @@
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
-  // Check for configure-time C include directories.
-  StringRef CIncludeDirs(C_INCLUDE_DIRS);
-  if (CIncludeDirs != "") {
-SmallVector dirs;
-CIncludeDirs.split(dirs, ":");
-for (StringRef dir : dirs) {
-  StringRef Prefix =
-  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
-  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
-}
-return;
-  }
-
   addExternCSystemInclude(DriverArgs, CC1Args,
   concat(D.SysRoot, "/usr/include"));
 }
Index: 

[PATCH] D158953: [analyzer] MmapWriteExecChecker: use getAs instead of castAs

2023-08-29 Thread 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 rG2b6160ea3f9a: [analyzer] MmapWriteExecChecker: use getAs 
instead of castAs (authored by dingfei fd...@feysh.com).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158953

Files:
  clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
  clang/test/Analysis/mmap-writeexec.c


Index: clang/test/Analysis/mmap-writeexec.c
===
--- clang/test/Analysis/mmap-writeexec.c
+++ clang/test/Analysis/mmap-writeexec.c
@@ -42,3 +42,9 @@
   int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both 
PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory 
regions, which could be overwritten with malicious code}}
   (void)m;
 }
+
+// gh62285: no crash on non concrete arg 'prot'
+void *gh62285(void *addr, int prot)
+{
+  return mmap(addr, 1, prot, 1, 1, 1);
+}
Index: clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -48,8 +48,10 @@
  CheckerContext ) const {
   if (matchesAny(Call, MmapFn, MprotectFn)) {
 SVal ProtVal = Call.getArgSVal(2);
-auto ProtLoc = ProtVal.castAs();
-int64_t Prot = ProtLoc.getValue().getSExtValue();
+auto ProtLoc = ProtVal.getAs();
+if (!ProtLoc)
+  return;
+int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
   ProtExec = ProtExecOv;
 if (ProtReadOv != ProtRead)


Index: clang/test/Analysis/mmap-writeexec.c
===
--- clang/test/Analysis/mmap-writeexec.c
+++ clang/test/Analysis/mmap-writeexec.c
@@ -42,3 +42,9 @@
   int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory regions, which could be overwritten with malicious code}}
   (void)m;
 }
+
+// gh62285: no crash on non concrete arg 'prot'
+void *gh62285(void *addr, int prot)
+{
+  return mmap(addr, 1, prot, 1, 1, 1);
+}
Index: clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -48,8 +48,10 @@
  CheckerContext ) const {
   if (matchesAny(Call, MmapFn, MprotectFn)) {
 SVal ProtVal = Call.getArgSVal(2);
-auto ProtLoc = ProtVal.castAs();
-int64_t Prot = ProtLoc.getValue().getSExtValue();
+auto ProtLoc = ProtVal.getAs();
+if (!ProtLoc)
+  return;
+int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
   ProtExec = ProtExecOv;
 if (ProtReadOv != ProtRead)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2b6160e - [analyzer] MmapWriteExecChecker: use getAs instead of castAs

2023-08-29 Thread via cfe-commits

Author: dingfei
Date: 2023-08-30T12:34:23+08:00
New Revision: 2b6160ea3f9aa1e859928053ef2893fd511430f2

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

LOG: [analyzer] MmapWriteExecChecker: use getAs instead of castAs

Use 'getAs' instead of 'castAs'

Reviewed By: steakhal

Fixes https://github.com/llvm/llvm-project/issues/62285

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
clang/test/Analysis/mmap-writeexec.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
index 0b3d635a50a3f8..8fc44e78be6f07 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -48,8 +48,10 @@ void MmapWriteExecChecker::checkPreCall(const CallEvent 
,
  CheckerContext ) const {
   if (matchesAny(Call, MmapFn, MprotectFn)) {
 SVal ProtVal = Call.getArgSVal(2);
-auto ProtLoc = ProtVal.castAs();
-int64_t Prot = ProtLoc.getValue().getSExtValue();
+auto ProtLoc = ProtVal.getAs();
+if (!ProtLoc)
+  return;
+int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
   ProtExec = ProtExecOv;
 if (ProtReadOv != ProtRead)

diff  --git a/clang/test/Analysis/mmap-writeexec.c 
b/clang/test/Analysis/mmap-writeexec.c
index c82dfbb4fb2e3d..8fd86ceb9d2a25 100644
--- a/clang/test/Analysis/mmap-writeexec.c
+++ b/clang/test/Analysis/mmap-writeexec.c
@@ -42,3 +42,9 @@ void f3(void)
   int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both 
PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory 
regions, which could be overwritten with malicious code}}
   (void)m;
 }
+
+// gh62285: no crash on non concrete arg 'prot'
+void *gh62285(void *addr, int prot)
+{
+  return mmap(addr, 1, prot, 1, 1, 1);
+}



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


[PATCH] D159016: [clang] Fix assertion failure using -MJ with -fsyntax-only

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great!




Comment at: clang/test/Driver/compilation_database_fsyntax_only.c:1
+// RUN: mkdir -p %t.workdir && cd %t.workdir
+// RUN: %clang -fsyntax-only %s -MJ - 2>&1 | FileCheck %s

The test can be added into `compilation_database.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159016

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


[PATCH] D159145: [RISCV] Don't add -unaligned-scalar-mem to target features by default.

2023-08-29 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 554561.
craig.topper added a comment.

Remove change to sifive-x280.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159145

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-default-features.c
  clang/test/Driver/riscv-features.c


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -39,8 +39,6 @@
 // NO-UNALIGNED-SCALAR-MEM: "-target-feature" "-unaligned-scalar-mem"
 // UNALIGNED-VECTOR-MEM: "-target-feature" "+unaligned-vector-mem"
 // NO-UNALIGNED-VECTOR-MEM: "-target-feature" "-unaligned-vector-mem"
-// DEFAULT: "-target-feature" "-unaligned-scalar-mem"
-// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem"
 
 // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
Index: clang/test/Driver/riscv-default-features.c
===
--- clang/test/Driver/riscv-default-features.c
+++ clang/test/Driver/riscv-default-features.c
@@ -3,10 +3,8 @@
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
 // RV32-SAME: -save-restore
-// RV32-SAME: -unaligned-scalar-mem
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
 // RV64-SAME: -save-restore
-// RV64-SAME: -unaligned-scalar-mem
 
 // Dummy function
 int foo(void){
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -169,15 +169,17 @@
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   bool HasV = llvm::is_contained(Features, "+zve32x");
-  if (Args.hasFlag(options::OPT_munaligned_access,
-   options::OPT_mno_unaligned_access, false)) {
-Features.push_back("+unaligned-scalar-mem");
-if (HasV)
-  Features.push_back("+unaligned-vector-mem");
-  } else {
-Features.push_back("-unaligned-scalar-mem");
-if (HasV)
-  Features.push_back("-unaligned-vector-mem");
+  if (const Arg *A = Args.getLastArg(options::OPT_munaligned_access,
+ options::OPT_mno_unaligned_access)) {
+if (A->getOption().matches(options::OPT_munaligned_access)) {
+  Features.push_back("+unaligned-scalar-mem");
+  if (HasV)
+Features.push_back("+unaligned-vector-mem");
+} else {
+  Features.push_back("-unaligned-scalar-mem");
+  if (HasV)
+Features.push_back("-unaligned-vector-mem");
+}
   }
 
   // Now add any that the user explicitly requested on the command line,


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -39,8 +39,6 @@
 // NO-UNALIGNED-SCALAR-MEM: "-target-feature" "-unaligned-scalar-mem"
 // UNALIGNED-VECTOR-MEM: "-target-feature" "+unaligned-vector-mem"
 // NO-UNALIGNED-VECTOR-MEM: "-target-feature" "-unaligned-vector-mem"
-// DEFAULT: "-target-feature" "-unaligned-scalar-mem"
-// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem"
 
 // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
Index: clang/test/Driver/riscv-default-features.c
===
--- clang/test/Driver/riscv-default-features.c
+++ clang/test/Driver/riscv-default-features.c
@@ -3,10 +3,8 @@
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
 // RV32-SAME: -save-restore
-// RV32-SAME: -unaligned-scalar-mem
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
 // RV64-SAME: -save-restore
-// RV64-SAME: -unaligned-scalar-mem
 
 // Dummy function
 int foo(void){
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -169,15 +169,17 @@
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   bool HasV = llvm::is_contained(Features, "+zve32x");
-  if (Args.hasFlag(options::OPT_munaligned_access,
-   options::OPT_mno_unaligned_access, false)) {
-Features.push_back("+unaligned-scalar-mem");
-if (HasV)
-  Features.push_back("+unaligned-vector-mem");
-  } else {
-Features.push_back("-unaligned-scalar-mem");
-if (HasV)
-  Features.push_back("-unaligned-vector-mem");
+  if (const Arg *A = Args.getLastArg(options::OPT_munaligned_access,
+ options::OPT_mno_unaligned_access)) {
+if (A->getOption().matches(options::OPT_munaligned_access)) {
+  

[PATCH] D117929: [XRay] Add support for RISCV

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: compiler-rt/lib/xray/xray_trampoline_riscv32.S:54
+   // Handler address will be null if it is not set
+   beq a2, x0, FunctionEntry_restore
+

This local symbol doesn't seem useful. We can just use numbers (`1f` and `1:`) 
or `LOCAL_LABEL(...)`, so that the symbol table will not have the unneeded 
symbol entries.



Comment at: compiler-rt/lib/xray/xray_trampoline_riscv32.S:85
+FunctionEntry_end:
+   ASM_SIZE(__xray_FunctionEntry)
+   .cfi_endproc

stray `ASM_SIZE`?



Comment at: compiler-rt/lib/xray/xray_trampoline_riscv64.S:22
+   ASM_TYPE_FUNCTION(__xray_FunctionEntry)
+   ASM_SYMBOL(__xray_FunctionEntry):
+   .cfi_startproc

See the aarch64 implementation to use `ASM_SIZE(__xray_FunctionEntry)` to set 
`.size`



Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:185
+if (F.hasFnAttribute("patchable-function-entry")) {
+  break;
+}

omit braces for single-line single statement body.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.h:164
+  // Add XRay support - needs double precision floats at present and does not
+  // support compressed instructions
+  bool isXRaySupported() const override {

"does not support compressed instructions" makes this feature infeasible for 
many systems, I'll say probably almost all systems that may consider XRay. 


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

https://reviews.llvm.org/D117929

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


[PATCH] D159159: [PowerPC] Disable float128 on AIX in Clang

2023-08-29 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf created this revision.
qiucf added a reviewer: PowerPC.
Herald added subscribers: steven.zhang, shchenz, kbarton, nemanjai.
Herald added a project: All.
qiucf requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

PowerPC AIX backend does not support float128 at all. Diagnose even when 
specifying `-mfloat128` to avoid backend crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159159

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/Sema/128bitfloat.cpp


Index: clang/test/Sema/128bitfloat.cpp
===
--- clang/test/Sema/128bitfloat.cpp
+++ clang/test/Sema/128bitfloat.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -std=gnu++11 %s
 // RUN: %clang_cc1 -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple powerpc64-linux -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +float128 -verify 
-std=c++11 %s
 // RUN: %clang_cc1 -triple i686-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify -std=c++11 %s
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -52,7 +52,7 @@
   HasDirectMove = true;
 } else if (Feature == "+htm") {
   HasHTM = true;
-} else if (Feature == "+float128") {
+} else if (Feature == "+float128" && !getTriple().isOSAIX()) {
   HasFloat128 = true;
 } else if (Feature == "+power9-vector") {
   HasP9Vector = true;


Index: clang/test/Sema/128bitfloat.cpp
===
--- clang/test/Sema/128bitfloat.cpp
+++ clang/test/Sema/128bitfloat.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -std=gnu++11 %s
 // RUN: %clang_cc1 -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple powerpc64-linux -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +float128 -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple i686-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify -std=c++11 %s
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -52,7 +52,7 @@
   HasDirectMove = true;
 } else if (Feature == "+htm") {
   HasHTM = true;
-} else if (Feature == "+float128") {
+} else if (Feature == "+float128" && !getTriple().isOSAIX()) {
   HasFloat128 = true;
 } else if (Feature == "+power9-vector") {
   HasP9Vector = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159068: [clang][X86] Update excessive register save diagnostic to more closely follow the interrupt attribute spec

2023-08-29 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa1dc06a1b39: [clang][X86] Update excessive register save 
diagnostic to more closely follow… (authored by antangelo, committed by 
pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159068

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/attr-x86-interrupt.c
  clang/test/Sema/x86-diag-excessive-regsave.c

Index: clang/test/Sema/x86-diag-excessive-regsave.c
===
--- /dev/null
+++ clang/test/Sema/x86-diag-excessive-regsave.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s -DNO_CALLER_SAVED_REGISTERS=1
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature -x87 -target-feature -mmx -target-feature -sse -fsyntax-only -verify %s -DGPRONLY=1
+
+#if defined(NO_CALLER_SAVED_REGS) || defined(GPRONLY)
+// expected-no-diagnostics
+#else
+#define EXPECT_WARNING
+#endif
+
+#ifdef NO_CALLER_SAVED_REGS
+__attribute__((no_caller_saved_registers))
+#endif
+#ifdef EXPECT_WARNING
+// expected-note@+3 {{'foo' declared here}}
+// expected-note@+2 {{'foo' declared here}}
+#endif
+extern void foo(void *);
+
+__attribute__((no_caller_saved_registers))
+void no_caller_saved_registers(void *arg) {
+#ifdef EXPECT_WARNING
+// expected-warning@+2 {{function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only'}}
+#endif
+foo(arg);
+}
+
+__attribute__((interrupt))
+void interrupt(void *arg) {
+#ifdef EXPECT_WARNING
+// expected-warning@+2 {{interrupt service routine should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only'}}
+#endif
+foo(arg);
+}
Index: clang/test/Sema/attr-x86-interrupt.c
===
--- clang/test/Sema/attr-x86-interrupt.c
+++ clang/test/Sema/attr-x86-interrupt.c
@@ -40,23 +40,6 @@
 __attribute__((interrupt)) void foo7(int *a, unsigned b) {}
 __attribute__((interrupt)) void foo8(int *a) {}
 
-#ifdef _LP64
-typedef unsigned long Arg2Type;
-#elif defined(__x86_64__)
-typedef unsigned long long Arg2Type;
-#else
-typedef unsigned int Arg2Type;
-#endif
-#ifndef NOCALLERSAVE
-__attribute__((no_caller_saved_registers))
-#else
-// expected-note@+3 {{'foo9' declared here}}
-// expected-warning@+4 {{interrupt service routine should only call a function with attribute 'no_caller_saved_registers'}}
-#endif
-void foo9(int *a, Arg2Type b) {}
-__attribute__((interrupt)) void fooA(int *a, Arg2Type b) {
-  foo9(a, b);
-}
 void g(void (*fp)(int *));
 int main(int argc, char **argv) {
   void *ptr = (void *)
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7413,11 +7413,18 @@
   Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
   }
 }
-if (Caller->hasAttr() &&
-((!FDecl || !FDecl->hasAttr( {
-  Diag(Fn->getExprLoc(), diag::warn_anyx86_interrupt_regsave);
-  if (FDecl)
-Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
+if (Caller->hasAttr() ||
+Caller->hasAttr()) {
+  const TargetInfo  = Context.getTargetInfo();
+  bool HasNonGPRRegisters =
+  TI.hasFeature("sse") || TI.hasFeature("x87") || TI.hasFeature("mmx");
+  if (HasNonGPRRegisters &&
+  (!FDecl || !FDecl->hasAttr())) {
+Diag(Fn->getExprLoc(), diag::warn_anyx86_excessive_regsave)
+<< (Caller->hasAttr() ? 0 : 1);
+if (FDecl)
+  Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
+  }
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -310,10 +310,12 @@
   "a pointer as the first parameter|a %2 type as the second parameter}1">;
 def err_anyx86_interrupt_called : Error<
   "interrupt service routine cannot be called directly">;
-def warn_anyx86_interrupt_regsave : Warning<
-  "interrupt service routine should only call a function"
-  " with attribute 'no_caller_saved_registers'">,
-  InGroup>;
+def warn_anyx86_excessive_regsave : Warning<
+  "%select{interrupt service routine|function with attribute"
+  " 'no_caller_saved_registers'}0 should only call a function"
+  " with attribute 'no_caller_saved_registers'"
+  " or be compiled with '-mgeneral-regs-only'">,
+  InGroup>;
 def 

[clang] fa1dc06 - [clang][X86] Update excessive register save diagnostic to more closely follow the interrupt attribute spec

2023-08-29 Thread Phoebe Wang via cfe-commits

Author: Antonio Abbatangelo
Date: 2023-08-30T11:52:04+08:00
New Revision: fa1dc06a1b3997f025b0d81539c31a74e6b6ec79

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

LOG: [clang][X86] Update excessive register save diagnostic to more closely 
follow the interrupt attribute spec

The original diagnostic does not cover all cases according to my reading
of the spec.

For the interrupt attribute, the spec indicates that if the compiler
does not support saving SSE, MMX, or x87 then the function should
be compiled with '-mgeneral-regs-only' (GCC requires this).
Alternatively, calling functions with the `no_caller_saved_registers`
attribute will not clobber state and can be done without disabling
these features.

The warning as implemented in upstream only detects the latter case but
does not consider that disabling the above features also solves the issue
of these register saves being undesirable due to inefficiency.

For the no_caller_saved_registers attribute, the interrupt spec also
indicates that in the absence of saving SSE, MMX and x87 state, these
functions should be compiled with '-mgeneral-regs-only' (also required
by GCC). It does not make any statements about calling other functions
with the attribute, but by extension the result is the same as with the
interrupt attribute (in clang, at least).

This patch handles the remaining cases by adjusting the diagnostic to:

1. Not be shown if the function is compiled without the SSE, MMX or x87
   features enabled (i.e. with '-mgeneral-regs-only')
2. Also be shown for functions with the 'no_caller_saved_registers'
   attribute
3. In addition to advising that the function should only call functions
   with the `no_caller_saved_registers` attribute, the text also suggests
   compiling with `-mgeneral-regs-only` as an alternative.

The interrupt spec is available at 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=5ed3cc7b66af4758f7849ed6f65f4365be8223be
and was taken from the issue that resulted in this diagnostic being
added (#26787)

Reviewed By: pengfei

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

Added: 
clang/test/Sema/x86-diag-excessive-regsave.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/attr-x86-interrupt.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 262bebfc0bde9b..1bd295c68b83b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -122,12 +122,18 @@ Modified Compiler Flags
 ---
 
 * ``-Woverriding-t-option`` is renamed to ``-Woverriding-option``.
+* ``-Winterrupt-service-routine`` is renamed to ``-Wexcessive-regsave`` as a 
generalization
 
 Removed Compiler Flags
 -
 
 Attribute Changes in Clang
 --
+- On X86, a warning is now emitted if a function with 
``__attribute__((no_caller_saved_registers))``
+  calls a function without ``__attribute__((no_caller_saved_registers))``, and 
is not compiled with
+  ``-mgeneral-regs-only``
+- On X86, a function with ``__attribute__((interrupt))`` can now call a 
function without
+  ``__attribute__((no_caller_saved_registers))`` provided that it is compiled 
with ``-mgeneral-regs-only``
 
 - When a non-variadic function is decorated with the ``format`` attribute,
   Clang now checks that the format string would match the function's 
parameters'

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f19fe66bfedc1f..f11ea89d14bad0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4815,6 +4815,10 @@ The user can call functions specified with the 
'no_caller_saved_registers'
 attribute from an interrupt handler without saving and restoring all
 call-clobbered registers.
 
+Functions specified with the 'no_caller_saved_registers' attribute should only
+call other functions with the 'no_caller_saved_registers' attribute, or should 
be
+compiled with the '-mgeneral-regs-only' flag to avoid saving unused non-GPR 
registers.
+
 Note that 'no_caller_saved_registers' attribute is not a calling convention.
 In fact, it only overrides the decision of which registers should be saved by
 the caller, but not how the parameters are passed from the caller to the 
callee.

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a065015cfe02eb..0ac4df8edb242f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -310,10 +310,12 @@ def err_anyx86_interrupt_attribute : Error<
   "a pointer as 

[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-29 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a subscriber: rsmith.
xgupta added a comment.

Just address @rsmith, I think after that we are fine to commit this review.

> +  "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class or 
> struct with virtual base classes">;

Please don't say "class or struct" here. Either just say "class" (a struct is a 
kind of class) or actually figure out which one it is and say that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158540

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


[PATCH] D159145: [RISCV] Don't add -unaligned-scalar-mem to target features by default.

2023-08-29 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVProcessors.td:185
+   FeatureStdExtZbb,
+   FeatureUnalignedScalarMem],
   [TuneSiFive7,

craig.topper wrote:
> wangpc wrote:
> > This can be tested in `clang/test/Driver/riscv-cpus.c`.
> This shouldn’t be in here. That was for testing and I accidentally committed 
> it
Are there any processors in upstream that support unaligned memory access so 
that we can test it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159145

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


[PATCH] D158376: [Driver] move DragonFly header search path management to the driver

2023-08-29 Thread Brad Smith 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 rGf3476332e453: [Driver] move DragonFly header search path 
management to the driver (authored by brad).

Changed prior to commit:
  https://reviews.llvm.org/D158376?vs=554140=554556#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158376

Files:
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/DragonFly.h
  clang/lib/Lex/InitHeaderSearch.cpp


Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -307,9 +307,6 @@
   break;
 }
 break;
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;
   default:
 break;
   }
@@ -319,6 +316,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::DragonFly:
   case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
Index: clang/lib/Driver/ToolChains/DragonFly.h
===
--- clang/lib/Driver/ToolChains/DragonFly.h
+++ clang/lib/Driver/ToolChains/DragonFly.h
@@ -55,6 +55,13 @@
 
   bool IsMathErrnoDefault() const override { return false; }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void addLibStdCxxIncludePaths(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/DragonFly.cpp
===
--- clang/lib/Driver/ToolChains/DragonFly.cpp
+++ clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -12,6 +12,7 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -195,6 +196,33 @@
   getFilePaths().push_back("/usr/lib/gcc80");
 }
 
+void DragonFly::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
+}
+
+void DragonFly::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) 
const {
+  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, 
"/usr/include/c++/8.0"), "", "",
+   DriverArgs, CC1Args);
+}
+
 Tool *DragonFly::buildAssembler() const {
   return new tools::dragonfly::Assembler(*this);
 }


Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -307,9 +307,6 @@
   break;
 }
 break;
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;
   default:
 break;
   }
@@ -319,6 +316,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::DragonFly:
   case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
Index: clang/lib/Driver/ToolChains/DragonFly.h
===
--- clang/lib/Driver/ToolChains/DragonFly.h
+++ clang/lib/Driver/ToolChains/DragonFly.h
@@ -55,6 +55,13 @@
 
   bool IsMathErrnoDefault() const override { return false; }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void addLibStdCxxIncludePaths(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/DragonFly.cpp
===
--- clang/lib/Driver/ToolChains/DragonFly.cpp
+++ clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -12,6 +12,7 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace 

[clang] f347633 - [Driver] move DragonFly header search path management to the driver

2023-08-29 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-08-29T23:18:42-04:00
New Revision: f3476332e4531a667063b8980de1fbc5fb4a6251

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

LOG: [Driver] move DragonFly header search path management to the driver

As has been done for other OS's. Move the header path management to the driver.

Also I noticed with D89690 that the library paths were updated for GCC 8, but
the C++ header path was not. So I also fixed that while here.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/DragonFly.h
clang/lib/Lex/InitHeaderSearch.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index ba901407715f32..6f46864105e9c0 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -12,6 +12,7 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -195,6 +196,33 @@ DragonFly::DragonFly(const Driver , const llvm::Triple 
,
   getFilePaths().push_back("/usr/lib/gcc80");
 }
 
+void DragonFly::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
+}
+
+void DragonFly::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) 
const {
+  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, 
"/usr/include/c++/8.0"), "", "",
+   DriverArgs, CC1Args);
+}
+
 Tool *DragonFly::buildAssembler() const {
   return new tools::dragonfly::Assembler(*this);
 }

diff  --git a/clang/lib/Driver/ToolChains/DragonFly.h 
b/clang/lib/Driver/ToolChains/DragonFly.h
index 3ed5acefaefb51..42ce960c5bdbd9 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.h
+++ b/clang/lib/Driver/ToolChains/DragonFly.h
@@ -55,6 +55,13 @@ class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF 
{
 
   bool IsMathErrnoDefault() const override { return false; }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void addLibStdCxxIncludePaths(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;

diff  --git a/clang/lib/Lex/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
index 1531871411f980..2c2fb767ca1ef9 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -307,9 +307,6 @@ void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
   break;
 }
 break;
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;
   default:
 break;
   }
@@ -319,6 +316,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::DragonFly:
   case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:



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


[PATCH] D158376: [Driver] move DragonFly header search path management to the driver

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great!




Comment at: clang/lib/Lex/InitHeaderSearch.cpp:331
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;

brad wrote:
> MaskRay wrote:
> > 5.0 becomes 8.0 after move?
> > 5.0 becomes 8.0 after move?
> 
> Read what the summary says. The current path is wrong.
Thank you! If this has been broken for so long, it means they don't care about 
libstdc++? I think we can just remove the include path...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158376

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


[PATCH] D158132: [Driver] move ELFIAMCU / RTEMS header search path management to the driver

2023-08-29 Thread Brad Smith 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 rGd267990e8c53: [Driver] move ELFIAMCU / RTEMS header search 
path management to the driver (authored by brad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158132

Files:
  clang/lib/Lex/InitHeaderSearch.cpp


Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -231,8 +231,6 @@
 
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
-case llvm::Triple::ELFIAMCU:
-  break;
 case llvm::Triple::Win32:
   if (triple.getEnvironment() != llvm::Triple::Cygnus)
 break;
@@ -270,8 +268,6 @@
   }
 
   switch (os) {
-  case llvm::Triple::RTEMS:
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -286,14 +282,7 @@
 break;
   }
 
-  switch (os) {
-  case llvm::Triple::RTEMS:
-  case llvm::Triple::ELFIAMCU:
-break;
-  default:
-AddPath("/usr/include", ExternCSystem, false);
-break;
-  }
+  AddPath("/usr/include", ExternCSystem, false);
 }
 
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
@@ -330,6 +319,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::Fuchsia:
@@ -342,6 +332,7 @@
   case llvm::Triple::OpenBSD:
   case llvm::Triple::PS4:
   case llvm::Triple::PS5:
+  case llvm::Triple::RTEMS:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
   case llvm::Triple::ZOS:


Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -231,8 +231,6 @@
 
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
-case llvm::Triple::ELFIAMCU:
-  break;
 case llvm::Triple::Win32:
   if (triple.getEnvironment() != llvm::Triple::Cygnus)
 break;
@@ -270,8 +268,6 @@
   }
 
   switch (os) {
-  case llvm::Triple::RTEMS:
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -286,14 +282,7 @@
 break;
   }
 
-  switch (os) {
-  case llvm::Triple::RTEMS:
-  case llvm::Triple::ELFIAMCU:
-break;
-  default:
-AddPath("/usr/include", ExternCSystem, false);
-break;
-  }
+  AddPath("/usr/include", ExternCSystem, false);
 }
 
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
@@ -330,6 +319,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::Fuchsia:
@@ -342,6 +332,7 @@
   case llvm::Triple::OpenBSD:
   case llvm::Triple::PS4:
   case llvm::Triple::PS5:
+  case llvm::Triple::RTEMS:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
   case llvm::Triple::ZOS:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158920: Delete CloudABI support

2023-08-29 Thread Brad Smith 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 rG5165593a97a0: Delete CloudABI support (authored by brad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158920

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CloudABI.cpp
  clang/lib/Driver/ToolChains/CloudABI.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/test/Analysis/security-syntax-checks.m
  clang/test/Driver/cloudabi.c
  clang/test/Driver/cloudabi.cpp
  clang/test/Driver/frame-pointer-elim.c
  clang/test/Driver/fsanitize.c
  clang/test/Frontend/gnu-mcount.c
  clang/test/Preprocessor/init-arm.c
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/TargetParser/TripleTest.cpp
  llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
@@ -63,7 +63,6 @@
 "ToolChains/BareMetal.cpp",
 "ToolChains/CSKYToolChain.cpp",
 "ToolChains/Clang.cpp",
-"ToolChains/CloudABI.cpp",
 "ToolChains/CommonArgs.cpp",
 "ToolChains/CrossWindows.cpp",
 "ToolChains/Cuda.cpp",
Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -319,12 +319,6 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UnknownOS, T.getOS());
 
-  T = Triple("x86_64-unknown-cloudabi");
-  EXPECT_EQ(Triple::x86_64, T.getArch());
-  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
-  EXPECT_EQ(Triple::CloudABI, T.getOS());
-  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
-
   T = Triple("x86_64-unknown-fuchsia");
   EXPECT_EQ(Triple::x86_64, T.getArch());
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -208,7 +208,6 @@
   case AMDHSA: return "amdhsa";
   case AMDPAL: return "amdpal";
   case CUDA: return "cuda";
-  case CloudABI: return "cloudabi";
   case Darwin: return "darwin";
   case DragonFly: return "dragonfly";
   case DriverKit: return "driverkit";
@@ -570,7 +569,6 @@
 
 static Triple::OSType parseOS(StringRef OSName) {
   return StringSwitch(OSName)
-.StartsWith("cloudabi", Triple::CloudABI)
 .StartsWith("darwin", Triple::Darwin)
 .StartsWith("dragonfly", Triple::DragonFly)
 .StartsWith("freebsd", Triple::FreeBSD)
Index: llvm/include/llvm/TargetParser/Triple.h
===
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -184,7 +184,6 @@
   enum OSType {
 UnknownOS,
 
-CloudABI,
 Darwin,
 DragonFly,
 FreeBSD,
Index: llvm/include/llvm/MC/MCELFObjectWriter.h
===
--- llvm/include/llvm/MC/MCELFObjectWriter.h
+++ llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -71,8 +71,6 @@
 
   static uint8_t getOSABI(Triple::OSType OSType) {
 switch (OSType) {
-  case Triple::CloudABI:
-return ELF::ELFOSABI_CLOUDABI;
   case Triple::HermitCore:
 return ELF::ELFOSABI_STANDALONE;
   case Triple::PS4:
Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -10,7 +10,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
@@ -26,7 +25,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
 // 

[clang] d267990 - [Driver] move ELFIAMCU / RTEMS header search path management to the driver

2023-08-29 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-08-29T23:04:02-04:00
New Revision: d267990e8c5329de76f0bb1673954ebbd666afc0

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

LOG: [Driver] move ELFIAMCU / RTEMS header search path management to the driver

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Lex/InitHeaderSearch.cpp

Removed: 




diff  --git a/clang/lib/Lex/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
index 1b8ec89600a610..1531871411f980 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -231,8 +231,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const 
llvm::Triple ,
 
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
-case llvm::Triple::ELFIAMCU:
-  break;
 case llvm::Triple::Win32:
   if (triple.getEnvironment() != llvm::Triple::Cygnus)
 break;
@@ -270,8 +268,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const 
llvm::Triple ,
   }
 
   switch (os) {
-  case llvm::Triple::RTEMS:
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -286,14 +282,7 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const 
llvm::Triple ,
 break;
   }
 
-  switch (os) {
-  case llvm::Triple::RTEMS:
-  case llvm::Triple::ELFIAMCU:
-break;
-  default:
-AddPath("/usr/include", ExternCSystem, false);
-break;
-  }
+  AddPath("/usr/include", ExternCSystem, false);
 }
 
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
@@ -330,6 +319,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::Fuchsia:
@@ -342,6 +332,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
   case llvm::Triple::OpenBSD:
   case llvm::Triple::PS4:
   case llvm::Triple::PS5:
+  case llvm::Triple::RTEMS:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
   case llvm::Triple::ZOS:



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


[clang] 5165593 - Delete CloudABI support

2023-08-29 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2023-08-29T22:57:30-04:00
New Revision: 5165593a97a04caad553cb0c213d3b3d359b1853

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

LOG: Delete CloudABI support

After this D108637 and with FreeBSD -current and now 14 dropping support for
CloudABI I think it is time to consider deleting the CloudABI support.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Lex/InitHeaderSearch.cpp
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
clang/test/Analysis/security-syntax-checks.m
clang/test/Driver/frame-pointer-elim.c
clang/test/Driver/fsanitize.c
clang/test/Frontend/gnu-mcount.c
clang/test/Preprocessor/init-arm.c
clang/test/Preprocessor/init-x86.c
clang/test/Preprocessor/predefined-macros-no-warnings.c
llvm/include/llvm/MC/MCELFObjectWriter.h
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/TargetParser/Triple.cpp
llvm/unittests/TargetParser/TripleTest.cpp
llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn

Removed: 
clang/lib/Driver/ToolChains/CloudABI.cpp
clang/lib/Driver/ToolChains/CloudABI.h
clang/test/Driver/cloudabi.c
clang/test/Driver/cloudabi.cpp



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 994350c01f8925..648b2401c32d18 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -399,7 +399,6 @@ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
 clang/lib/Driver/ToolChains/AVR.cpp
 clang/lib/Driver/ToolChains/AVR.h
-clang/lib/Driver/ToolChains/CloudABI.cpp
 clang/lib/Driver/ToolChains/CommonArgs.h
 clang/lib/Driver/ToolChains/CrossWindows.h
 clang/lib/Driver/ToolChains/DragonFly.h

diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index d5d523de17ce49..380510e22143d2 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -142,9 +142,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
   return std::make_unique(Triple, Opts);
 
 switch (os) {
-case llvm::Triple::CloudABI:
-  return std::make_unique>(Triple,
-   Opts);
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
   Opts);
@@ -202,9 +199,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
   return std::make_unique(Triple, Opts);
 
 switch (os) {
-case llvm::Triple::CloudABI:
-  return std::make_unique>(Triple,
-   Opts);
 case llvm::Triple::Linux:
   switch (Triple.getEnvironment()) {
   default:
@@ -541,9 +535,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
   return std::make_unique(Triple, Opts);
 
 switch (os) {
-case llvm::Triple::CloudABI:
-  return std::make_unique>(Triple,
-Opts);
 case llvm::Triple::Linux: {
   switch (Triple.getEnvironment()) {
   default:
@@ -603,9 +594,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
   return std::make_unique(Triple, Opts);
 
 switch (os) {
-case llvm::Triple::CloudABI:
-  return std::make_unique>(Triple,
-Opts);
 case llvm::Triple::Linux: {
   switch (Triple.getEnvironment()) {
   default:

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 37e313b248dc13..367defc071417f 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -34,22 +34,6 @@ class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo {
   }
 };
 
-// CloudABI Target
-template 
-class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public OSTargetInfo 
{
-protected:
-  void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const override {
-Builder.defineMacro("__CloudABI__");
-
-// CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
-Builder.defineMacro("__STDC_ISO_10646__", "201206L");
-  }
-
-public:
-  using OSTargetInfo::OSTargetInfo;
-};
-
 void getDarwinDefines(MacroBuilder , const LangOptions ,
   const llvm::Triple , StringRef ,

[PATCH] D158132: [Driver] move ELFIAMCU / RTEMS header search path management to the driver

2023-08-29 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 554553.
brad added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158132

Files:
  clang/lib/Lex/InitHeaderSearch.cpp


Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -231,8 +231,6 @@
 
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
-case llvm::Triple::ELFIAMCU:
-  break;
 case llvm::Triple::Win32:
   if (triple.getEnvironment() != llvm::Triple::Cygnus)
 break;
@@ -270,8 +268,6 @@
   }
 
   switch (os) {
-  case llvm::Triple::RTEMS:
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -286,14 +282,7 @@
 break;
   }
 
-  switch (os) {
-  case llvm::Triple::RTEMS:
-  case llvm::Triple::ELFIAMCU:
-break;
-  default:
-AddPath("/usr/include", ExternCSystem, false);
-break;
-  }
+  AddPath("/usr/include", ExternCSystem, false);
 }
 
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
@@ -330,6 +319,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::Fuchsia:
@@ -342,6 +332,7 @@
   case llvm::Triple::OpenBSD:
   case llvm::Triple::PS4:
   case llvm::Triple::PS5:
+  case llvm::Triple::RTEMS:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
   case llvm::Triple::ZOS:


Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -231,8 +231,6 @@
 
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
-case llvm::Triple::ELFIAMCU:
-  break;
 case llvm::Triple::Win32:
   if (triple.getEnvironment() != llvm::Triple::Cygnus)
 break;
@@ -270,8 +268,6 @@
   }
 
   switch (os) {
-  case llvm::Triple::RTEMS:
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -286,14 +282,7 @@
 break;
   }
 
-  switch (os) {
-  case llvm::Triple::RTEMS:
-  case llvm::Triple::ELFIAMCU:
-break;
-  default:
-AddPath("/usr/include", ExternCSystem, false);
-break;
-  }
+  AddPath("/usr/include", ExternCSystem, false);
 }
 
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
@@ -330,6 +319,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::ELFIAMCU:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::Fuchsia:
@@ -342,6 +332,7 @@
   case llvm::Triple::OpenBSD:
   case llvm::Triple::PS4:
   case llvm::Triple::PS5:
+  case llvm::Triple::RTEMS:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
   case llvm::Triple::ZOS:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151938: [clang][index] NFCI: Make `CXFile` a `FileEntryRef`

2023-08-29 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

Sorry for the late response @jansvoboda11, when `lookupModuleFile` is called, 
the file 
`build/tools/clang/test/Index/Core/Output/index-with-module.m.tmp.mcp/A03A61VI43WA/ModA-21USRMHJNU3PG.pcm`
 doesn't exist. So it seems there's some issue with the creation of the file.

The backtrace is:

  #0  0x095cefe4 in pthread_kill () from 
/usr/lib/libpthreads.a(shr_xpg5_64.o)
  #1  0x095ce808 in _p_raise () from 
/usr/lib/libpthreads.a(shr_xpg5_64.o)
  #2  0x0904130c in raise () from /usr/lib/libc.a(shr_64.o)
  #3  0x0905f49c in abort () from /usr/lib/libc.a(shr_64.o)
  #4  0x090006cb4e30 in llvm::llvm_unreachable_internal (msg=, 
  file=0x8001000a0014bee  
"/llvm-project/llvm/include/llvm/Support/Error.h", line=755) at 
/llvm-project/llvm/lib/Support/ErrorHandling.cpp:212
  #5  0x090006ccc5ec in llvm::cantFail (Err=..., Msg=
  0x0 
)
  at /llvm-project/llvm/include/llvm/Support/Error.h:755
  #6  
llvm::handleAllErrors(llvm::Error, 
llvm::consumeError(llvm::Error)::{lambda(llvm::ErrorInfoBase const&)#1}&&) 
(E=..., Handlers=...)
  at /llvm-project/llvm/include/llvm/Support/Error.h:967
  #7  0x090006d0ef30 in llvm::consumeError (Err=...)
  at /llvm-project/llvm/include/llvm/Support/Error.h:1044
  #8  llvm::expectedToOptional (E=...)
  at /llvm-project/llvm/include/llvm/Support/Error.h:1057
  #9  0x000102dc03a0 in 
clang::serialization::ModuleManager::lookupModuleFile (this=, 
FileName=..., 
  ExpectedSize=576478347173894528, ExpectedModTime=0, File=...)
  at /llvm-project/clang/lib/Serialization/ModuleManager.cpp:451
  #10 0x000102dbf380 in clang::serialization::ModuleManager::addModule 
(this=0x110950d40, FileName=..., 
  Type=clang::serialization::MK_ExplicitModule, ImportLoc=..., 
  ImportedBy=0x0 
,
 
  Generation=67, ExpectedSize=-1, ExpectedModTime=-1, 
ExpectedSignature=..., 
  ReadSignature=@0x11071e1a8: 0x102dbd514 
, 
  Module=@0xfffd678: 0x0 
,
 ErrorStr=...) at /llvm-project/clang/lib/Serialization/ModuleManager.cpp:121
  #11 0x000102dbc2a8 in clang::ASTReader::ReadASTCore (this=0x110950cb0, 
FileName=..., 
  Type=clang::serialization::MK_ImplicitModule, ImportLoc=..., 
  ImportedBy=0x0 
,
 
  Loaded=..., ExpectedSize=-1, ExpectedModTime=0, ExpectedSignature=..., 
ClientLoadCapabilities=19)
  at /llvm-project/clang/lib/Serialization/ASTReader.cpp:4584
  #12 0x000102dbad14 in clang::ASTReader::ReadAST(llvm::StringRef, 
clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, 
llvm::SmallVectorImpl*) ()
  #13 0x000102c826a8 in 
clang::CompilerInstance::findOrCompileModuleAndReadAST(llvm::StringRef, 
clang::SourceLocation, clang::SourceLocation, bool) ()
  #14 0x000102c7e75c in clang::CompilerInstance::loadModule 
(this=0x110950cc8, ImportLoc=..., Path=..., 
  Visibility=(clang::Module::AllVisible | unknown: 0x12), 
IsInclusionDirective=)
  at /llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1995
  #15 0x0001001143ac in clang::Preprocessor::LexAfterModuleImport 
(this=0x1108ee6c8, Result=...)
  at /llvm-project/clang/lib/Lex/Preprocessor.cpp:1323
  #16 0x0001001132e4 in clang::Preprocessor::Lex (
  this=0x110981100, Result=...) at 
/llvm-project/clang/lib/Lex/Preprocessor.cpp:899
  #17 0x00010271eb1c in clang::Parser::ConsumeToken (this=0x1109810f0)
  at /llvm-project/clang/include/clang/Parse/Parser.h:504
  #18 clang::Parser::ParseModuleName (this=0x1109810f0, UseLoc=..., Path=..., 
IsImport=)
  at /llvm-project/clang/lib/Parse/Parser.cpp:2638
  #19 0x00010271de04 in clang::Parser::ParseModuleImport (this=0x1109810f0, 
AtLoc=..., 
  ImportState=@0x1: clang::Sema::FirstDecl) at 
/llvm-project/clang/lib/Parse/Parser.cpp:2526
  #20 0x00010296637c in clang::Parser::ParseObjCAtDirectives 
(this=0x1109810f0, DeclAttrs=..., DeclSpecAttrs=...)
  at /llvm-project/clang/lib/Parse/ParseObjc.cpp:99
  #21 0x000102842e58 in clang::Parser::ParseExternalDeclaration 
(this=0x1109810f0, Attrs=..., DeclSpecAttrs=..., 
  DS=0x0 
)
  at /llvm-project/clang/lib/Parse/Parser.cpp:908
  #22 0x00010271a934 in clang::Parser::ParseTopLevelDecl (this=0x1109810f0, 
Result=..., 
  ImportState=@0xfffeef8: clang::Sema::FirstDecl)
  at /llvm-project/clang/lib/Parse/Parser.cpp:742
  #23 0x000102719524 in clang::Parser::ParseFirstTopLevelDecl 
(this=0xfffef90, Result=..., 
  ImportState=@0x1e8: clang::Sema::FirstDecl)
  at /llvm-project/clang/lib/Parse/Parser.cpp:594
  #24 0x000101693200 in clang::ParseAST (S=..., PrintStats=, 
SkipFunctionBodies=)
  at /llvm-project/clang/lib/Parse/ParseAST.cpp:162
  #25 0x0001015f4d80 in clang::ASTFrontendAction::ExecuteAction() ()
  #26 0x000102f96d18 in clang::FrontendAction::Execute() ()
  at /opt/IBM/openxlC/17.1.1/bin/../include/c++/v1/optional:957
  #27 0x000102c77838 in 

[PATCH] D158376: [Driver] move DragonFly header search path management to the driver

2023-08-29 Thread Brad Smith via Phabricator via cfe-commits
brad added inline comments.



Comment at: clang/lib/Lex/InitHeaderSearch.cpp:331
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;

MaskRay wrote:
> 5.0 becomes 8.0 after move?
> 5.0 becomes 8.0 after move?

Read what the summary says. The current path is wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158376

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


[PATCH] D159145: [RISCV] Don't add -unaligned-scalar-mem to target features by default.

2023-08-29 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVProcessors.td:185
+   FeatureStdExtZbb,
+   FeatureUnalignedScalarMem],
   [TuneSiFive7,

wangpc wrote:
> This can be tested in `clang/test/Driver/riscv-cpus.c`.
This shouldn’t be in here. That was for testing and I accidentally committed it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159145

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


[PATCH] D158376: [Driver] move DragonFly header search path management to the driver

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Lex/InitHeaderSearch.cpp:331
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;

5.0 becomes 8.0 after move?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158376

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


[clang] d1bc6f9 - [Clang][CMake] Remove GCC option override in BOLT.cmake

2023-08-29 Thread Amir Aupov via cfe-commits

Author: Amir Aupov
Date: 2023-08-29T19:41:03-07:00
New Revision: d1bc6f9953ccc351df835a40146569084ba5754d

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

LOG: [Clang][CMake] Remove GCC option override in BOLT.cmake

Added: 


Modified: 
clang/cmake/caches/BOLT.cmake

Removed: 




diff  --git a/clang/cmake/caches/BOLT.cmake b/clang/cmake/caches/BOLT.cmake
index 7c75d60320f7ee..0442f73e5426ac 100644
--- a/clang/cmake/caches/BOLT.cmake
+++ b/clang/cmake/caches/BOLT.cmake
@@ -11,9 +11,3 @@ set(LLVM_DISTRIBUTION_COMPONENTS
   clang
   clang-resource-headers
   CACHE STRING "")
-
-# Disable function splitting enabled by default in GCC8+
-if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-reorder-blocks-and-partition")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-reorder-blocks-and-partition")
-endif()



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


[PATCH] D159145: [RISCV] Don't add -unaligned-scalar-mem to target features by default.

2023-08-29 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVProcessors.td:185
+   FeatureStdExtZbb,
+   FeatureUnalignedScalarMem],
   [TuneSiFive7,

This can be tested in `clang/test/Driver/riscv-cpus.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159145

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


[PATCH] D158948: [clang][ASTImporter] Add import of type-related nodes

2023-08-29 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

Changes planned for https://reviews.llvm.org/D158872 is still under discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158948

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


[PATCH] D158948: [clang][ASTImporter] Add import of type-related nodes

2023-08-29 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 554545.
danix800 added a comment.

1. Simplify error handling
2. Remove unnecessary tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158948

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

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -583,6 +583,88 @@
   functionDecl(hasDescendant(typedefDecl(has(atomicType());
 }
 
+TEST_P(ImportType, ImportBitIntType) {
+  MatchVerifier Verifier;
+  testImport("_BitInt(10) declToImport;", Lang_CXX11, "", Lang_CXX11, Verifier,
+ varDecl(hasType(bitIntType(;
+}
+
+TEST_P(ImportType, ImportDependentBitIntType) {
+  MatchVerifier Verifier;
+  testImport("template using declToImport = _BitInt(Width);",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typeAliasTemplateDecl(
+ has(typeAliasDecl(hasType(dependentBitIntType());
+}
+
+TEST_P(ImportType, ImportDependentAddressSpaceType) {
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((address_space(AddrSpace)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentAddressSpaceType());
+}
+
+TEST_P(ImportType, ImportVectorType) {
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((vector_size(12))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(vectorType(;
+}
+
+TEST_P(ImportType, ImportDependentVectorType) {
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((vector_size(Size)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentVectorType());
+}
+
+struct ImportOpenCLPipe : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"};
+  }
+};
+
+TEST_P(ImportOpenCLPipe, ImportPipeType) {
+  MatchVerifier Verifier;
+  testImport("typedef pipe int declToImport;", Lang_OpenCL, "", Lang_OpenCL,
+ Verifier, typedefDecl(hasType(pipeType(;
+}
+
+struct ImportMatrixType : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-fenable-matrix"};
+  }
+};
+
+TEST_P(ImportMatrixType, ImportConstantMatrixType) {
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((matrix_type(5, 5))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(constantMatrixType(;
+}
+
+TEST_P(ImportMatrixType, ImportDependentSizedMatrixType) {
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((matrix_type(Rows, Cols)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentSizedMatrixType());
+}
+
 TEST_P(ImportType, ImportUsingType) {
   MatchVerifier Verifier;
   testImport("struct C {};"
Index: clang/unittests/AST/ASTImporterObjCTest.cpp
===
--- clang/unittests/AST/ASTImporterObjCTest.cpp
+++ clang/unittests/AST/ASTImporterObjCTest.cpp
@@ -77,6 +77,27 @@
   }
 }
 
+TEST_P(ImportObjCDecl, ImportObjCTypeParamDecl) {
+  Decl *FromTU = getTuDecl(
+  R"(
+@interface X 
+@end
+  )",
+  Lang_OBJCXX, "input.mm");
+  auto Pattern = objcTypeParamDecl(hasTypeForDecl(objcTypeParamType()));
+  auto *FromInterfaceDecl = FirstDeclMatcher().match(
+  FromTU, namedDecl(hasName("X")));
+  auto *FromTypeParamDecl =
+  FirstDeclMatcher().match(FromInterfaceDecl, Pattern);
+
+  auto ToTypeParamDeclImported = Import(FromTypeParamDecl, Lang_OBJCXX);
+
+  auto *ToInterfaceDecl = FirstDeclMatcher().match(
+  ToTypeParamDeclImported->getTranslationUnitDecl(),
+  namedDecl(hasName("X")));
+  ASSERT_TRUE(ToTypeParamDeclImported);
+}
+
 static const auto ObjCTestArrayForRunOptions =
 std::array, 2>{
 {std::vector{"-fno-objc-arc"},
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -368,58 +368,9 @@
 
 // Importing types
 ExpectedType VisitType(const Type *T);
-ExpectedType VisitAtomicType(const AtomicType *T);
-ExpectedType VisitBuiltinType(const BuiltinType *T);
-ExpectedType VisitDecayedType(const DecayedType *T);
-ExpectedType VisitComplexType(const ComplexType *T);
-ExpectedType VisitPointerType(const PointerType 

[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: clang/lib/Basic/Sanitizers.cpp:126
+  // execute-only output (no data access to code sections).
+  if (const llvm::opt::Arg *A =
+  Args.getLastArg(clang::driver::options::OPT_mexecute_only,

MaskRay wrote:
> The idiom is `hasFlag(clang::driver::options::OPT_mexecute_only, 
> clang::driver::options::OPT_mno_execute_only, false)`
`return Args.hasFlag(clang::driver::options::OPT_mexecute_only ...`



Comment at: clang/test/Driver/fsanitize.c:986
+// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not 
allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-UNDEFINED-NOT: error: invalid argument '-fsanitize=function' 
not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-UNDEFINED: 
"-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}

Delete this `-NOT`. `%clang` returning 0 implies that there is no error.


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

https://reviews.llvm.org/D158614

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


[PATCH] D159068: [clang][X86] Update excessive register save diagnostic to more closely follow the interrupt attribute spec

2023-08-29 Thread Antonio Abbatangelo via Phabricator via cfe-commits
antangelo added a comment.

Thank you for the quick reviews! I don't have currently have commit access to 
commit the changes myself, is it possible for someone to commit on my behalf? 
My name and email are:

Name: Antonio Abbatangelo
Email: cont...@antangelo.com


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159068

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


[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

2023-08-29 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D158872#4626272 , @sammccall wrote:

> In D158872#4626095 , @aaron.ballman 
> wrote:
>
>> Out of curiosity, are you testing on Windows with MSVC? My understanding on 
>> build time performance impacts was that it's debug builds with MSVC that get 
>> hit especially hard. (I can test that setup but I could use some help 
>> figuring out how you tested compile times so I can do a similar test instead 
>> of something totally different from what you tried.)
>
> I'm not :-( I don't have a windows machine, and the VM I used to have has 
> bitrotted beyond repair (not sure how useful benchmarks from there would be 
> anyway).
>
> This is with clang on linux, just running `time clang-check-14 
> include/clang/ASTMatchers/ASTMatchers.h` a few times.
> The "deps only" test was `#if 0` ing out all the code in `ASTMatcher.h`, and 
> commenting out the `ASTMatchers/*` includes, and repeating the same.
> For object files I just added a dummy `ASTMatchers.cpp` with only `#include 
> "clang/ASTMatchers/ASTMatchers.h"`.
>
> I guess the equivalent of clang-check would be `/Zs`, not sure the best way 
> to feed it the right flags...

Thanks for the testing. I can do the windows part with MSVC cl.exe.

1. `ASTMatchers.h`: ~3.5s
2. "Deps only": ~3.2s
3. `ASTMatchers.cpp` obj: 8K

  $ uname -a
  MINGW64_NT-10.0-20348 WIN-LH267487PAC 3.3.3-341.x86_64 2022-01-17 11:45 UTC 
x86_64 Msys
  
  $ echo $SHELL
  /usr/bin/bash
  
  $ cat test.ps1
  & "C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\cl.exe" 
/permissive- /MP /we"4238" /GS /Zc:preprocessor /W4 /wd"4141" /wd"4146" 
/wd"4244" /wd"4267" /wd"4291" /wd"4351" /wd"4456" /wd"4457" /wd"4458" /wd"4459" 
/wd"4503" /wd"4624" /wd"4722" /wd"4100" /wd"4127" /wd"4512" /wd"4505" /wd"4610" 
/wd"4510" /wd"4702" /wd"4245" /wd"4706" /wd"4310" /wd"4701" /wd"4703" /wd"4389" 
/wd"4611" /wd"4805" /wd"4204" /wd"4577" /wd"4091" /wd"4592" /wd"4319" /wd"4709" 
/wd"5105" /wd"4324" /Zc:wchar_t 
/I"C:\Users\Administrator\source\repos\llvm-project\build-main-vs2022\tools\clang\lib\ASTMatchers"
 /I"C:\Users\Administrator\source\repos\llvm-project\clang\lib\ASTMatchers" 
/I"C:\Users\Administrator\source\repos\llvm-project\clang\include" 
/I"C:\Users\Administrator\source\repos\llvm-project\build-main-vs2022\tools\clang\include"
 /I"C:\Users\Administrator\source\repos\llvm-project\build-main-vs2022\include" 
/I"C:\Users\Administrator\source\repos\llvm-project\llvm\include" /Gm- /O2 /Ob2 
/Zc:inline /fp:precise /U"NDEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D 
"_WINDOWS" /D "_GLIBCXX_ASSERTIONS" /D "_LIBCPP_ENABLE_ASSERTIONS" /D 
"_CRT_SECURE_NO_DEPRECATE" /D "_CRT_SECURE_NO_WARNINGS" /D 
"_CRT_NONSTDC_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_WARNINGS" /D 
"_SCL_SECURE_NO_DEPRECATE" /D "_SCL_SECURE_NO_WARNINGS" /D 
"__STDC_CONSTANT_MACROS" /D "__STDC_FORMAT_MACROS" /D "__STDC_LIMIT_MACROS" /D 
CMAKE_INTDIR=\"Release\" /errorReport:prompt /WX- /Zc:forScope /GR /Gd /Oi /MD 
/std:c++17 /EHsc /nologo 
/Fp"obj.clangASTMatchers.dir\Release\obj.clangASTMatchers.pch" 
/diagnostics:column /Zc:__cplusplus /bigobj -w14062 /Gw /I"C:\Program 
Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include" 
/I"C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Tools\MSVC\14.37.32822\atlmfc\include" /I"C:\Program 
Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" 
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt" 
/I"C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Auxiliary\VS\UnitTest\include" /I"C:\Program Files 
(x86)\Windows Kits\10\Include\10.0.22621.0\um" /I"C:\Program Files 
(x86)\Windows Kits\10\Include\10.0.22621.0\shared" /I"C:\Program Files 
(x86)\Windows Kits\10\Include\10.0.22621.0\winrt" /I"C:\Program Files 
(x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt" /c 
..\clang\include\clang\ASTMatchers\ASTMatchers.h /TP
  
   $ time powershell ./test.ps1
  ASTMatchers.h
  
  real0m3.143s
  user0m0.015s
  sys 0m0.000s


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158872

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


[PATCH] D158475: [driver] Refactor getRuntimePaths. NFC

2023-08-29 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

In D158475#4626636 , @smeenai wrote:

> I'm halfway through an implementation of this, but I just realized that on 
> Android, Clang never searches for C++ headers installed alongside the driver: 
> https://github.com/llvm/llvm-project/blob/7af0eff5405bb88dc96c0b19892da0fbb44db433/clang/lib/Driver/ToolChains/Gnu.cpp#L3116-L3118.
>  Are you using the C++ headers from the NDK but a library that you built 
> locally, or are you manually specifying the path to your C++ headers?

At the moment, we're only really using libunwind from the clang stdlib 
directory. So we don't really have the problem with headers. It will eventually 
be a problem when we get to use libc++, which we'll want at some point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158475

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


[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-29 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92023b150990: Reland [Clang][SemaCXX] Add unused 
warning for variables declared in condition… (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D152495?vs=550443=554539#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/warn-unused-variables.cpp

Index: clang/test/SemaCXX/warn-unused-variables.cpp
===
--- clang/test/SemaCXX/warn-unused-variables.cpp
+++ clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,3 +294,115 @@
 }
 
 } // namespace gh54489
+
+namespace inside_condition {
+  void ifs() {
+if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
+  return;
+if (const int const_hoge = 0) // expected-warning {{unused variable 'const_hoge'}}
+  return;
+else if (int fuga = 0)
+  (void)fuga;
+else if (int used = 1; int catched = used) // expected-warning {{unused variable 'catched'}}
+  return;
+else if (int refed = 1; int used = refed)
+  (void)used;
+else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused variable 'unused1'}} \
+   // expected-warning {{unused variable 'unused2'}}
+  return;
+else if (int unused = 4; int used = 5) // expected-warning {{unused variable 'unused'}}
+  (void)used;
+else if (int used = 6; int unused = 7) // expected-warning {{unused variable 'unused'}}
+  (void)used;
+else if (int used1 = 8; int used2 = 9)
+  (void)(used1 + used2);
+else if (auto [a, b] = (int[2]){ 1, 2 }; 1) // expected-warning {{unused variable '[a, b]'}}
+  return;
+else if (auto [a, b] = (int[2]){ 1, 2 }; a)
+  return;
+  }
+
+  void fors() {
+for (int i = 0;int unused = 0;); // expected-warning {{unused variable 'i'}} \
+ // expected-warning {{unused variable 'unused'}}
+for (int i = 0;int used = 0;) // expected-warning {{unused variable 'i'}}
+  (void)used;
+  while(int var = 1) // expected-warning {{unused variable 'var'}}
+return;
+  }
+
+  void whiles() {
+while(int unused = 1) // expected-warning {{unused variable 'unused'}}
+  return;
+while(int used = 1)
+  (void)used;
+  }
+
+
+  void switches() {
+switch(int unused = 1) { // expected-warning {{unused variable 'unused'}}
+  case 1: return;
+}
+switch(constexpr int used = 3; int unused = 4) { // expected-warning {{unused variable 'unused'}}
+  case used: return;
+}
+switch(int used = 3; int unused = 4) { // expected-warning {{unused variable 'unused'}}
+  case 3: (void)used;
+}
+switch(constexpr int used1 = 0; constexpr int used2 = 6) {
+  case (used1+used2): return;
+}
+switch(auto [a, b] = (int[2]){ 1, 2 }; 1) { // expected-warning {{unused variable '[a, b]'}}
+  case 1: return;
+}
+switch(auto [a, b] = (int[2]){ 1, 2 }; b) {
+  case 1: return;
+}
+switch(auto [a, b] = (int[2]){ 1, 2 }; 1) {
+  case 1: (void)a;
+}
+  }
+  template 
+  struct Vector {
+void doIt() {
+  for (auto& e : elements){} // expected-warning {{unused variable 'e'}}
+}
+T elements[10];
+  };
+  void ranged_for() {
+Vectorvector;
+vector.doIt(); // expected-note {{here}}
+  }
+
+
+  struct RAII {
+int 
+RAII(int ) : x(ref) {}
+~RAII() { x = 0;}
+operator int() const { return 1; }
+  };
+  void aggregate() {
+int x = 10;
+int y = 10;
+if (RAII var = x) {}
+for(RAII var = x; RAII var2 = y;) {}
+while (RAII var = x) {}
+switch (RAII var = x) {}
+  }
+
+  struct TrivialDtor{
+int 
+TrivialDtor(int ) : x(ref) { ref = 32; }
+operator int() const { return 1; }
+  };
+  void trivial_dtor() {
+int x = 10;
+int y = 10;
+if (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}}
+for(TrivialDtor var = x; TrivialDtor var2 = y;) {} // expected-warning {{unused variable 'var'}} \
+ // expected-warning {{unused variable 'var2'}}
+while (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}}
+switch (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}}
+  }

[PATCH] D158016: [NFC] Remove unused variables declared in conditions

2023-08-29 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01b88dd66d9d: [NFC] Remove unused variables declared in 
conditions (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D158016?vs=550438=554538#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158016

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Yaml.h
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  lld/MachO/Driver.cpp
  llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
  llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
  llvm/lib/IR/PrintPasses.cpp
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/tools/llvm-profgen/ProfiledBinary.cpp

Index: llvm/tools/llvm-profgen/ProfiledBinary.cpp
===
--- llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -812,7 +812,7 @@
   // Handles DWO sections that can either be in .o, .dwo or .dwp files.
   for (const auto  : DebugContext->compile_units()) {
 DWARFUnit *const DwarfUnit = CompilationUnit.get();
-if (std::optional DWOId = DwarfUnit->getDWOId()) {
+if (DwarfUnit->getDWOId()) {
   DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
   if (!DWOCU->isDWOUnit()) {
 std::string DWOName = dwarf::toString(
Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1337,7 +1337,7 @@
   SmallString<256> Path;
   Path_.toVector(Path);
 
-  if (std::error_code EC = makeCanonical(Path))
+  if (makeCanonical(Path))
 return {};
 
   return ExternalFS->isLocal(Path, Result);
Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -501,7 +501,7 @@
   static SmallVector FD{-1};
   SmallVector SR{S};
   static SmallVector FileName{""};
-  if (auto Err = prepareTempFiles(FD, SR, FileName)) {
+  if (prepareTempFiles(FD, SR, FileName)) {
 dbgs() << "Unable to create temporary file.";
 return;
   }
@@ -518,7 +518,7 @@
 return;
   }
 
-  if (auto Err = cleanUpTempFiles(FileName))
+  if (cleanUpTempFiles(FileName))
 dbgs() << "Unable to remove temporary file.";
 }
 
Index: llvm/lib/IR/PrintPasses.cpp
===
--- llvm/lib/IR/PrintPasses.cpp
+++ llvm/lib/IR/PrintPasses.cpp
@@ -212,7 +212,7 @@
   static SmallVector FD{-1, -1, -1};
   SmallVector SR{Before, After};
   static SmallVector FileName{"", "", ""};
-  if (auto Err = prepareTempFiles(FD, SR, FileName))
+  if (prepareTempFiles(FD, SR, FileName))
 return "Unable to create temporary file.";
 
   static ErrorOr DiffExe = sys::findProgramByName(DiffBinary);
@@ -238,7 +238,7 @@
   else
 return "Unable to read result.";
 
-  if (auto Err = cleanUpTempFiles(FileName))
+  if (cleanUpTempFiles(FileName))
 return "Unable to remove temporary file.";
 
   return Diff;
Index: llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
===
--- llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -504,7 +504,7 @@
   size_t NumBefore = Gsym.getNumFunctionInfos();
   auto getDie = [&](DWARFUnit ) -> DWARFDie {
 DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
-if (std::optional DWOId = DwarfUnit.getDWOId()) {
+if (DwarfUnit.getDWOId()) {
   DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
   if (OS && !DWOCU->isDWOUnit()) {
 std::string DWOName = dwarf::toString(
Index: llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
===
--- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -828,7 +828,7 @@
   // no type), then we use a size of one to still allow symbolization of the
   // exact address.
   uint64_t GVSize = 1;
-  if (DWARFDie BaseType = Die.getAttributeValueAsReferencedDie(DW_AT_type))
+  if (Die.getAttributeValueAsReferencedDie(DW_AT_type))
 if (std::optional Size = Die.getTypeSize(getAddressByteSize()))
   GVSize = *Size;
 
Index: llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
===
--- 

[clang] 92023b1 - Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions"

2023-08-29 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-08-30T10:05:10+09:00
New Revision: 92023b15099012a657da07ebf49dd7d94a260f84

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

LOG: Reland "[Clang][SemaCXX] Add unused warning for variables declared in 
condition expressions"

This patch marks the declarations with initializations in condition expressions 
such as
if (int var = init) as unused and unreferenced so that -Wunused can warn on 
them.

Fixes https://github.com/llvm/llvm-project/issues/61681

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D152495

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/warn-unused-variables.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dc7569cf79f43e..262bebfc0bde9b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -156,6 +156,9 @@ Improvements to Clang's diagnostics
   (`#64871: `_).
   Also clang no longer emits false positive warnings about the output length of
   ``%g`` format specifier.
+- Clang now warns on unused variables declared and initialized in condition
+  expressions.
+  (`#61681: `_)
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2ee216fffaa275..9facf2187f76a5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1995,7 +1995,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
,
   return false;
   } else if (!D->getDeclName()) {
 return false;
-  } else if (D->isReferenced() || D->isUsed()) {
+  } else if (D->isReferenced() || (!isa(D) && D->isUsed())) {
 return false;
   }
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index a6e0a8abf81b9a..a9096af70fce4e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4013,6 +4013,10 @@ ExprResult Sema::CheckConditionVariable(VarDecl 
*ConditionVar,
   ConditionVar, ConditionVar->getType().getNonReferenceType(), VK_LValue,
   ConditionVar->getLocation());
 
+  // Ensure that `-Wunused-variable` will be emitted for condition variables
+  // that are not referenced later. e.g.: if (int var = init());
+  ConditionVar->setReferenced(/*R=*/false);
+
   switch (CK) {
   case ConditionKind::Boolean:
 return CheckBooleanCondition(StmtLoc, Condition.get());

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 63f022d5c2ff09..bb8ea187ecf91c 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5353,7 +5353,7 @@ void Sema::BuildVariableInstantiation(
   // will have been deferred.
   if (!NewVar->isInvalidDecl() &&
   NewVar->getDeclContext()->isFunctionOrMethod() &&
-  OldVar->getType()->isDependentType())
+  OldVar->getType()->isDependentType() && !OldVar->isImplicit())
 DiagnoseUnusedDecl(NewVar);
 }
 

diff  --git a/clang/test/SemaCXX/warn-unused-variables.cpp 
b/clang/test/SemaCXX/warn-unused-variables.cpp
index 4db8bdf12e5de0..db33086436d3af 100644
--- a/clang/test/SemaCXX/warn-unused-variables.cpp
+++ b/clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,3 +294,115 @@ void RAIIWrapperTest() {
 }
 
 } // namespace gh54489
+
+namespace inside_condition {
+  void ifs() {
+if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
+  return;
+if (const int const_hoge = 0) // expected-warning {{unused variable 
'const_hoge'}}
+  return;
+else if (int fuga = 0)
+  (void)fuga;
+else if (int used = 1; int catched = used) // expected-warning {{unused 
variable 'catched'}}
+  return;
+else if (int refed = 1; int used = refed)
+  (void)used;
+else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused 
variable 'unused1'}} \
+   // expected-warning {{unused 
variable 'unused2'}}
+  return;
+else if (int unused = 4; int used = 5) // expected-warning {{unused 
variable 'unused'}}
+  (void)used;
+else if (int used = 

[clang] 01b88dd - [NFC] Remove unused variables declared in conditions

2023-08-29 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-08-30T10:05:06+09:00
New Revision: 01b88dd66d9d52d3f531a7d490e18c549f36f445

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

LOG: [NFC] Remove unused variables declared in conditions

D152495 makes clang warn on unused variables that are declared in conditions 
like `if (int var = init) {}`
This patch is an NFC fix to suppress the new warning in llvm,clang,lld builds 
to pass CI in the above patch.

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
clang/lib/StaticAnalyzer/Checkers/Yaml.h
clang/tools/clang-scan-deps/ClangScanDeps.cpp
lld/MachO/Driver.cpp
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
llvm/lib/IR/PrintPasses.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/lib/Support/VirtualFileSystem.cpp
llvm/tools/llvm-profgen/ProfiledBinary.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bdc9a5624ce3af..c1ffe1a2dd3ed5 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3928,7 +3928,7 @@ AST_MATCHER_P(CallExpr, callee, internal::Matcher,
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
 callee, AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCMessageExpr, CallExpr),
 internal::Matcher, InnerMatcher, 1) {
-  if (const auto *CallNode = dyn_cast())
+  if (isa())
 return callExpr(hasDeclaration(InnerMatcher))
 .matches(Node, Finder, Builder);
   else {

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index f048b2c218a4ca..b7553d8963ff0e 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -341,7 +341,7 @@ bool ByteCodeStmtGen::visitIfStmt(const IfStmt 
*IS) {
 return IS->getElse() ? visitStmt(IS->getElse()) : true;
 
   if (auto *CondInit = IS->getInit())
-if (!visitStmt(IS->getInit()))
+if (!visitStmt(CondInit))
   return false;
 
   if (const DeclStmt *CondDecl = IS->getConditionVariableDeclStmt())

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 3e8b2b78a3928b..79b23a85040970 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1353,7 +1353,7 @@ void clang::EmbedObject(llvm::Module *M, const 
CodeGenOptions ,
   for (StringRef OffloadObject : CGOpts.OffloadObjects) {
 llvm::ErrorOr> ObjectOrErr =
 llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
-if (std::error_code EC = ObjectOrErr.getError()) {
+if (ObjectOrErr.getError()) {
   auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
   "could not open '%0' for embedding");
   Diags.Report(DiagID) << OffloadObject;

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ac04b838602345..336cb04b9ad2be 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1557,7 +1557,7 @@ static llvm::TargetRegionEntryInfo 
getEntryInfoFromPresumedLoc(
 PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
 
 llvm::sys::fs::UniqueID ID;
-if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
   PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 4f3cdb00f1cc18..21e1363b613e0e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7423,7 +7423,7 @@ void 
CodeGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream ,
 
 // Get the UniqueID for the file containing the decl.
 llvm::sys::fs::UniqueID ID;
-if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
   PLoc = SM.getPresumedLoc(D->getLocation(), /*UseLineDirectives=*/false);
   assert(PLoc.isValid() && "Source location is expected to be valid.");
   if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))

diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 47187f554db29d..97472a302715bb 100644
--- 

[PATCH] D157813: [Driver][VE] Support VPU flag as a feature for VE

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/VE.cpp:22
+ std::vector ) {
+  // Defaults.
+  bool EnableVPU = true;

kaz7 wrote:
> MaskRay wrote:
> > Delete the comment. The code speaks itself. 
> > 
> > ```
> > if (Args.hasArg(options::OPT_mvevpu, options::OPT_mno_vevpu, true)
> >   Features.push_back("+vpu");
> > ```
> Thanks.  I remove comments and simplify existing code.
Sorry for my typo. We should use the 3-argument `hasFlag` here. It's simpler 
than getLastArg+matches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

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


[PATCH] D157331: [clang] Implement C23

2023-08-29 Thread Zijun Zhao via Phabricator via cfe-commits
ZijunZhao marked an inline comment as not done.
ZijunZhao added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:388
+  }
+
   // First two arguments should be integers.

aaron.ballman wrote:
> 
I keeps my original code because it just checks once but this checks many times 
and in case `BuiltinType::WChar_U` checking is missing(I know isWideCharType() 
can be added but I still think check the type is between Short and Int128, and 
UShort and UInt128 will be quicker and a bit safer?).



Comment at: clang/lib/Sema/SemaChecking.cpp:414-431
 if (!PtrTy ||
 !PtrTy->getPointeeType()->isIntegerType() ||
+(!PtrTy->getPointeeType()->isPureIntegerType() && CkdOperation) ||
 PtrTy->getPointeeType().isConstQualified()) {
   S.Diag(Arg.get()->getBeginLoc(),
  diag::err_overflow_builtin_must_be_ptr_int)
 << Ty << Arg.get()->getSourceRange();

aaron.ballman wrote:
> 
I don't think the `else if` part should be removed. We should make sure the 
result type is not short type. In `ValidCkdIntType()` checking, short type is a 
valid type. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331

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


[PATCH] D157331: [clang] Implement C23

2023-08-29 Thread Zijun Zhao via Phabricator via cfe-commits
ZijunZhao updated this revision to Diff 554534.
ZijunZhao marked 3 inline comments as done.
ZijunZhao added a comment.

1. Remove pure integer check to the right place
2. Update error msg and all related tests
3. Add explanations to header file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/stdckdint.h
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/C/C2x/n2359.c
  clang/test/C/C2x/n2683.c
  clang/test/C/C2x/n2683_2.c
  clang/test/Headers/stdckdint.c
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Sema/builtins-overflow.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -887,6 +887,11 @@
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2672.pdf;>N2672
   Yes
 
+
+  Towards Integer Safety
+  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf;>N2683
+  Clang 18
+
 
   Adding Fundamental Type for N-bit Integers
 
Index: clang/test/Sema/builtins-overflow.c
===
--- clang/test/Sema/builtins-overflow.c
+++ clang/test/Sema/builtins-overflow.c
@@ -14,11 +14,11 @@
   __builtin_add_overflow();  // expected-error {{too few arguments to function call, expected 3, have 0}}
   __builtin_add_overflow(1, 1, 1, 1);  // expected-error {{too many arguments to function call, expected 3, have 4}}
 
-  __builtin_add_overflow(c, 1, );  // expected-error {{operand argument to overflow builtin must be an integer ('const char *' invalid)}}
-  __builtin_add_overflow(1, c, );  // expected-error {{operand argument to overflow builtin must be an integer ('const char *' invalid)}}
-  __builtin_add_overflow(1, 1, 3);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer ('int' invalid)}}
-  __builtin_add_overflow(1, 1, );  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer ('float *' invalid)}}
-  __builtin_add_overflow(1, 1, );  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer ('const unsigned int *' invalid)}}
+  __builtin_add_overflow(c, 1, );  // expected-error {{operand argument to overflow builtin must be an integer type 'const char *' invalid}}
+  __builtin_add_overflow(1, c, );  // expected-error {{operand argument to overflow builtin must be an integer type 'const char *' invalid}}
+  __builtin_add_overflow(1, 1, 3);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('int' invalid)}}
+  __builtin_add_overflow(1, 1, );  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('float *' invalid)}}
+  __builtin_add_overflow(1, 1, );  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('const unsigned int *' invalid)}}
 
   {
 _BitInt(128) x = 1;
Index: clang/test/Modules/Inputs/System/usr/include/module.map
===
--- clang/test/Modules/Inputs/System/usr/include/module.map
+++ clang/test/Modules/Inputs/System/usr/include/module.map
@@ -14,6 +14,11 @@
 header "stdbool.h"
   }
 
+  // In both directories (compiler support version wins, does not forward)
+  module stdckdint {
+header "stdckdint.h"
+  }
+
   // In both directories (compiler support version wins, forwards)
   module stdint {
 header "stdint.h"
Index: clang/test/Headers/stdckdint.c
===
--- /dev/null
+++ clang/test/Headers/stdckdint.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s
+// expected-no-diagnostics
+#include 
+
+_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 -1073741826, i32 -1073741826)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+// CHECK:declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1
+bool test_ckd_add() {
+  int result;
+  return ckd_add(, -1073741826, -1073741826);
+}
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_sub() #0 {
+// CHECK:  entry:
+// 

[PATCH] D148381: [WIP][Clang] Add counted_by attribute

2023-08-29 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 554533.
void added a comment.

Fix some issues Nick pointed out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Misc/warning-flags.c

Index: clang/test/Misc/warning-flags.c
===
--- clang/test/Misc/warning-flags.c
+++ clang/test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (65):
+CHECK: Warnings without flags (66):
 
 CHECK-NEXT:   ext_expected_semi_decl_list
 CHECK-NEXT:   ext_explicit_specialization_storage_class
@@ -52,6 +52,7 @@
 CHECK-NEXT:   warn_fe_cc_log_diagnostics_failure
 CHECK-NEXT:   warn_fe_cc_print_header_failure
 CHECK-NEXT:   warn_fe_macro_contains_embedded_newline
+CHECK-NEXT:   warn_flexible_array_counted_by_attr_field_not_found
 CHECK-NEXT:   warn_ignoring_ftabstop_value
 CHECK-NEXT:   warn_implements_nscopying
 CHECK-NEXT:   warn_incompatible_qualified_id
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,6 +56,7 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: Destructor (SubjectMatchRule_function)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8334,6 +8334,21 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleCountedByAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  if (!AL.isArgIdent(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIdentifier;
+return;
+  }
+
+  IdentifierLoc *IL = AL.getArgAsIdent(0);
+  CountedByAttr *CBA =
+  ::new (S.Context) CountedByAttr(S.Context, AL, IL->Ident);
+  CBA->setCountedByFieldLoc(IL->Loc);
+  D->addAttr(CBA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9280,6 +9295,10 @@
 handleAvailableOnlyInDefaultEvalMethod(S, D, AL);
 break;
 
+  case ParsedAttr::AT_CountedBy:
+handleCountedByAttr(S, D, AL);
+break;
+
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
 handleLayoutVersion(S, D, AL);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17988,6 +17988,38 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithCountedByAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  return FindFieldWithCountedByAttr(SubRD);
+  }
+
+  return nullptr;
+}
+
+/// CheckCountedByAttr - Return an \p IdentifierInfo if the attribute field
+/// doesn't exist in the enclosing structure. Returns \p nullptr if the
+/// attribute field does exist.
+static const IdentifierInfo *CheckCountedByAttr(const RecordDecl *RD,
+const FieldDecl *FD,
+SourceRange ) {
+  const auto *ECA = FD->getAttr();
+
+  auto It = llvm::find_if(RD->fields(), [&](const FieldDecl *Field) {
+return Field->getName() == ECA->getCountedByField()->getName();
+  });
+  if (It == RD->field_end()) {
+Loc = ECA->getCountedByFieldLoc();
+return ECA->getCountedByField();
+  }
+
+  return nullptr;
+}
+
 void 

[PATCH] D148381: [WIP][Clang] Add counted_by attribute

2023-08-29 Thread Bill Wendling via Phabricator via cfe-commits
void marked 4 inline comments as done.
void added a comment.

In D148381#4625462 , @nickdesaulniers 
wrote:

> I assume you plan to add some clang CodeGen tests at some point?

Yes. :-)




Comment at: clang/lib/CodeGen/CodeGenFunction.h:531-532
 
-  /// True if CodeGen currently emits code implementing sanitizer checks.
-  bool IsSanitizerScope = false;
+  /// Non-zero if CodeGen currently emits code implementing sanitizer checks.
+  unsigned IsSanitizerScope = 0;
 

nickdesaulniers wrote:
> I don't understand this change. Grepping for `IsSanitizerScope` doesn't show 
> any changed references to how this variable is used. Intentional?
Ah! Thanks for catching this. I had trouble with this scoping mechanism and for 
a while used a reference counting method to get around it, but put it back to 
its previous impl, except for this. I still think the `SanitizerScope` needs 
work, but that's beyond this project.



Comment at: clang/lib/Sema/SemaDecl.cpp:17911
+return FD;
+}
+

nickdesaulniers wrote:
> unnecessary curly braces?
I prefer it this way in this case (actually, I wish C++ had a way to combine 
those two `if`'s into one). But it's not a big deal.



Comment at: clang/lib/Sema/SemaDecl.cpp:17931
+  auto It = llvm::find_if(RD->fields(), [&](const FieldDecl *Field) {
+return Field->getName() == ECA->getCountedByField()->getName();
+  });

rapidsna wrote:
> What happens in this corner case where the `Field` is actually the field that 
> the attribute appertains to?
> ```
> struct foo {
>   int count;
>   int counted[__attribute__((counted_by(counted)))];
> };
> 
> ```
That should be an error. I'll add that as a check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D159054: [Driver] Removal of C_INCLUDE_DIRS feature

2023-08-29 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

Just FYI I am not in a rush to commit this. I am posting this more so as a 
means of prodding for discussion of the feature.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159054

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


[PATCH] D157813: [Driver][VE] Support VPU flag as a feature for VE

2023-08-29 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 marked 2 inline comments as done.
kaz7 added a comment.

In D157813#4621978 , @MaskRay wrote:

>> [VE][Clang] Change to enable VPU flag by default
>
> For components like llvm/, clang/, we usually use a more specific tag. I'd 
> pick `[Driver]` over `[Clang]`.

I also change it to following.

> [Driver][VE] Support VPU flag as a feature for VE

Thank you so much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

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


[PATCH] D157813: [VE][Clang] Change to enable VPU flag by default

2023-08-29 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 marked an inline comment as done.
kaz7 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/VE.cpp:22
+ std::vector ) {
+  // Defaults.
+  bool EnableVPU = true;

MaskRay wrote:
> Delete the comment. The code speaks itself. 
> 
> ```
> if (Args.hasArg(options::OPT_mvevpu, options::OPT_mno_vevpu, true)
>   Features.push_back("+vpu");
> ```
Thanks.  I remove comments and simplify existing code.



Comment at: clang/test/Driver/ve-features.c:1
+// RUN: %clang -target ve-unknown-linux-gnu -### %s -mvevpu 2>&1 | FileCheck 
%s -check-prefix=VEVPU
+// RUN: %clang -target ve-unknown-linux-gnu -### %s -mno-vevpu 2>&1 | 
FileCheck %s -check-prefix=NO-VEVPU

MaskRay wrote:
> kaz7 wrote:
> > MaskRay wrote:
> > > `-target ` has been deprecated since Clang 3.4. Use `--target=`
> > I didn't know that.  Thank you!
> I think we typically spend just two RUN lines:
> 
> * one for the default
> * one for `-mvevpu -mno-vevpu`
> 
> The additional coverage for having 3 RUN lines is probably not useful.
Thank you for suggesting.  I consider what this patch should do and change the 
purpose to support VPU flag in the backend for VE.  As a result, Tests are two 
RUN lines.

- one for enable VPU
- one for disable VPU


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

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


[PATCH] D157813: [VE][Clang] Change to enable VPU flag by default

2023-08-29 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 updated this revision to Diff 554528.
kaz7 added a comment.

Change to not control backend default bahavior but support VPU flag in
the backend for VE.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/VE.cpp
  clang/test/Driver/ve-features.c


Index: clang/test/Driver/ve-features.c
===
--- /dev/null
+++ clang/test/Driver/ve-features.c
@@ -0,0 +1,5 @@
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s -mvevpu 2>&1 | FileCheck 
%s -check-prefix=VEVPU
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s -mno-vevpu 2>&1 | 
FileCheck %s -check-prefix=NO-VEVPU
+
+// VEVPU: "-target-feature" "+vpu"
+// NO-VEVPU-NOT: "-target-feature" "+vpu"
Index: clang/lib/Driver/ToolChains/Arch/VE.cpp
===
--- clang/lib/Driver/ToolChains/Arch/VE.cpp
+++ clang/lib/Driver/ToolChains/Arch/VE.cpp
@@ -18,4 +18,11 @@
 using namespace llvm::opt;
 
 void ve::getVETargetFeatures(const Driver , const ArgList ,
- std::vector ) {}
+ std::vector ) {
+  if (auto *A = Args.getLastArg(options::OPT_mvevpu, options::OPT_mno_vevpu)) {
+if (A->getOption().matches(options::OPT_mvevpu))
+  Features.push_back("+vpu");
+else
+  Features.push_back("-vpu");
+  }
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -202,6 +202,8 @@
Group, Flags<[CoreOption]>, DocName<"X86">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
+def m_ve_Features_Group : OptionGroup<"">,
+  Group, DocName<"VE">;
 
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
@@ -5160,6 +5162,13 @@
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
 } // let Flags = [TargetSpecific]
 
+// VE feature flags
+let Flags = [TargetSpecific] in {
+def mvevpu : Flag<["-"], "mvevpu">, Group,
+  HelpText<"Emit VPU instructions for VE">;
+def mno_vevpu : Flag<["-"], "mno-vevpu">, Group;
+} // let Flags = [TargetSpecific]
+
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.


Index: clang/test/Driver/ve-features.c
===
--- /dev/null
+++ clang/test/Driver/ve-features.c
@@ -0,0 +1,5 @@
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s -mvevpu 2>&1 | FileCheck %s -check-prefix=VEVPU
+// RUN: %clang --target=ve-unknown-linux-gnu -### %s -mno-vevpu 2>&1 | FileCheck %s -check-prefix=NO-VEVPU
+
+// VEVPU: "-target-feature" "+vpu"
+// NO-VEVPU-NOT: "-target-feature" "+vpu"
Index: clang/lib/Driver/ToolChains/Arch/VE.cpp
===
--- clang/lib/Driver/ToolChains/Arch/VE.cpp
+++ clang/lib/Driver/ToolChains/Arch/VE.cpp
@@ -18,4 +18,11 @@
 using namespace llvm::opt;
 
 void ve::getVETargetFeatures(const Driver , const ArgList ,
- std::vector ) {}
+ std::vector ) {
+  if (auto *A = Args.getLastArg(options::OPT_mvevpu, options::OPT_mno_vevpu)) {
+if (A->getOption().matches(options::OPT_mvevpu))
+  Features.push_back("+vpu");
+else
+  Features.push_back("-vpu");
+  }
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -202,6 +202,8 @@
Group, Flags<[CoreOption]>, DocName<"X86">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
+def m_ve_Features_Group : OptionGroup<"">,
+  Group, DocName<"VE">;
 
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
@@ -5160,6 +5162,13 @@
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, Group;
 } // let Flags = [TargetSpecific]
 
+// VE feature flags
+let Flags = [TargetSpecific] in {
+def mvevpu : Flag<["-"], "mvevpu">, Group,
+  HelpText<"Emit VPU instructions for VE">;
+def mno_vevpu : Flag<["-"], "mno-vevpu">, Group;
+} // let Flags = [TargetSpecific]
+
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] 8f48392 - clang: Update tests after is.fpclass combine change

2023-08-29 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-08-29T19:46:24-04:00
New Revision: 8f48392bc05a130218a15c65302f684988921307

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

LOG: clang: Update tests after is.fpclass combine change

Added: 


Modified: 
clang/test/CodeGen/isfpclass.c
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/test/CodeGen/isfpclass.c b/clang/test/CodeGen/isfpclass.c
index 4b436f8f9e1feb..2ad5bb31882503 100644
--- a/clang/test/CodeGen/isfpclass.c
+++ b/clang/test/CodeGen/isfpclass.c
@@ -4,8 +4,9 @@
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_finite
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 504)
-// CHECK-NEXT:ret i1 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call float @llvm.fabs.f32(float [[X]])
+// CHECK-NEXT:[[TMP1:%.*]] = fcmp one float [[TMP0]], 0x7FF0
+// CHECK-NEXT:ret i1 [[TMP1]]
 //
 _Bool check_isfpclass_finite(float x) {
   return __builtin_isfpclass(x, 504 /*Finite*/);
@@ -14,7 +15,7 @@ _Bool check_isfpclass_finite(float x) {
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_finite_strict
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 504) #[[ATTR4:[0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 504) #[[ATTR5:[0-9]+]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_finite_strict(float x) {
@@ -35,7 +36,7 @@ _Bool check_isfpclass_nan_f32(float x) {
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_nan_f32_strict
 // CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 3) #[[ATTR4]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 3) #[[ATTR5]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_nan_f32_strict(float x) {
@@ -56,7 +57,7 @@ _Bool check_isfpclass_snan_f64(double x) {
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_snan_f64_strict
 // CHECK-SAME: (double noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f64(double 
[[X]], i32 1) #[[ATTR4]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f64(double 
[[X]], i32 1) #[[ATTR5]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_snan_f64_strict(double x) {
@@ -77,7 +78,7 @@ _Bool check_isfpclass_zero_f16(_Float16 x) {
 // CHECK-LABEL: define dso_local i1 @check_isfpclass_zero_f16_strict
 // CHECK-SAME: (half noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f16(half [[X]], 
i32 96) #[[ATTR4]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f16(half [[X]], 
i32 96) #[[ATTR5]]
 // CHECK-NEXT:ret i1 [[TMP0]]
 //
 _Bool check_isfpclass_zero_f16_strict(_Float16 x) {
@@ -85,21 +86,45 @@ _Bool check_isfpclass_zero_f16_strict(_Float16 x) {
   return __builtin_isfpclass(x, 96 /*Zero*/);
 }
 
+// CHECK-LABEL: define dso_local i1 @check_isnan
+// CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 3) #[[ATTR5]]
+// CHECK-NEXT:ret i1 [[TMP0]]
+//
 _Bool check_isnan(float x) {
 #pragma STDC FENV_ACCESS ON
   return __builtin_isnan(x);
 }
 
+// CHECK-LABEL: define dso_local i1 @check_isinf
+// CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 516) #[[ATTR5]]
+// CHECK-NEXT:ret i1 [[TMP0]]
+//
 _Bool check_isinf(float x) {
 #pragma STDC FENV_ACCESS ON
   return __builtin_isinf(x);
 }
 
+// CHECK-LABEL: define dso_local i1 @check_isfinite
+// CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 504) #[[ATTR5]]
+// CHECK-NEXT:ret i1 [[TMP0]]
+//
 _Bool check_isfinite(float x) {
 #pragma STDC FENV_ACCESS ON
   return __builtin_isfinite(x);
 }
 
+// CHECK-LABEL: define dso_local i1 @check_isnormal
+// CHECK-SAME: (float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float 
[[X]], i32 264) #[[ATTR5]]
+// CHECK-NEXT:

[PATCH] D148381: [WIP][Clang] Add counted_by attribute

2023-08-29 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D148381#4626229 , 
@serge-sans-paille wrote:

> Jumping a bit late in the thread, apologize in advance if I missed something.
>
> The GCC version of the attributes seems to be `element_count` (as found in 
> the link https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 mentionned by 
> @kees) I guess we could align (I personally prefer the GCC name, FWIW)

Qing Zhao has been sending out patches to gcc-patches@, so I've been trying to 
follow those as much as possible. I plan to go through my implementation to 
ensure that I copy hers as much as possible. See the thread here: 
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626376.html

> I may be wrong , but it seems to me that there is nothing specific to FAM 
> there, and this would work as well for
>
>   struct foo {
> size_t num_elements;
>  // ...
> struct bar ** data __attribute__((counted_by(num_elements)));
>   };
>   
>   struct foo make_foo(size_t num_elements) {
>   struct foo f;
> f.data = malloc(num_elements *
>sizeof(struct bar *));
>   
> f.num_elements = num_elements;
> return f;
>   }
>
> Which makes us very close to:
>
>   void stuff(int n, int *data __attribute__((counted_by(n {
>   for(int i = 0; i < n; ++i)
> other_stuff(data[i]);
>   }
>
> which is very close to VLA, right?

Yeah. It could definitely be extended to the Apple RFC (which is similar to 
your example).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D159137: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect

2023-08-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 marked 2 inline comments as done.
qiongsiwu1 added inline comments.



Comment at: clang/test/Driver/fprofile-update.c:17
+// AIX specific tests
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate 
-fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate 
-fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX %}

MaskRay wrote:
> The idiom is to use `--target=...`. This driver decision is not dependent on 
> what OS the host runs, so `%if system-aix` should be avoided.
Ah yes thanks for the feedback. Fixed! 


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

https://reviews.llvm.org/D159137

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


[PATCH] D159137: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect

2023-08-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 554523.
qiongsiwu1 added a comment.

Address code review feedback.


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

https://reviews.llvm.org/D159137

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/fprofile-update.c


Index: clang/test/Driver/fprofile-update.c
===
--- clang/test/Driver/fprofile-update.c
+++ clang/test/Driver/fprofile-update.c
@@ -12,3 +12,8 @@
 // RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s 
--check-prefix=ERROR
 
 // ERROR: error: unsupported argument 'unknown' to option '-fprofile-update='
+
+// AIX specific tests
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate 
-fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate 
-fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX
+// AIX: "-latomic"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -429,11 +429,20 @@
 
 void AIX::addProfileRTLibs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const {
-  // Add linker option -u__llvm_profile_runtime to cause runtime
-  // initialization to occur.
-  if (needsProfileRT(Args))
+  if (needsProfileRT(Args)) {
+// Add linker option -u__llvm_profile_runtime to cause runtime
+// initialization to occur.
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-u", llvm::getInstrProfRuntimeHookVarName(;
+
+if (const auto *A =
+Args.getLastArgNoClaim(options::OPT_fprofile_update_EQ)) {
+  StringRef Val = A->getValue();
+  if (Val == "atomic" || Val == "prefer-atomic")
+CmdArgs.push_back("-latomic");
+}
+  }
+
   ToolChain::addProfileRTLibs(Args, CmdArgs);
 }
 


Index: clang/test/Driver/fprofile-update.c
===
--- clang/test/Driver/fprofile-update.c
+++ clang/test/Driver/fprofile-update.c
@@ -12,3 +12,8 @@
 // RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s --check-prefix=ERROR
 
 // ERROR: error: unsupported argument 'unknown' to option '-fprofile-update='
+
+// AIX specific tests
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX
+// AIX: "-latomic"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -429,11 +429,20 @@
 
 void AIX::addProfileRTLibs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const {
-  // Add linker option -u__llvm_profile_runtime to cause runtime
-  // initialization to occur.
-  if (needsProfileRT(Args))
+  if (needsProfileRT(Args)) {
+// Add linker option -u__llvm_profile_runtime to cause runtime
+// initialization to occur.
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-u", llvm::getInstrProfRuntimeHookVarName(;
+
+if (const auto *A =
+Args.getLastArgNoClaim(options::OPT_fprofile_update_EQ)) {
+  StringRef Val = A->getValue();
+  if (Val == "atomic" || Val == "prefer-atomic")
+CmdArgs.push_back("-latomic");
+}
+  }
+
   ToolChain::addProfileRTLibs(Args, CmdArgs);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153924: [OpenMP] Allow exceptions in target regions when offloading to GPUs

2023-08-29 Thread Anton Rydahl via Phabricator via cfe-commits
AntonRydahl updated this revision to Diff 554520.
AntonRydahl added a comment.

Updating the line numbers in the unit tests to match the addition of `// 
REQUIRES: `


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153924

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGException.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/OpenMP/amdgpu_exceptions.cpp
  clang/test/OpenMP/amdgpu_throw.cpp
  clang/test/OpenMP/amdgpu_throw_trap.cpp
  clang/test/OpenMP/amdgpu_try_catch.cpp
  clang/test/OpenMP/nvptx_exceptions.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
  clang/test/OpenMP/nvptx_throw.cpp
  clang/test/OpenMP/nvptx_throw_trap.cpp
  clang/test/OpenMP/nvptx_try_catch.cpp
  clang/test/OpenMP/x86_target_exceptions.cpp
  clang/test/OpenMP/x86_target_throw.cpp
  clang/test/OpenMP/x86_target_try_catch.cpp

Index: clang/test/OpenMP/x86_target_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_try_catch.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		error = 1;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_throw.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_throw.cpp
@@ -0,0 +1,9 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+void foo(void) {
+	throw 404;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_exceptions.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_exceptions.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		throw 404;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/nvptx_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/nvptx_try_catch.cpp
@@ -0,0 +1,47 @@
+// REQUIRES: nvptx-registered-target
+
+/**
+ * The first four lines test that a warning is produced when enabling 
+ * -Wopenmp-target-exception no matter what combination of -fexceptions and 
+ * -fcxx-exceptions are set, as we want OpenMP to always allow exceptions in the
+ * target region but emit a warning instead.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+
+/**
+ * The following four lines test that no warning is emitted when providing 
+ * -Wno-openmp-target-exception no matter the combination of -fexceptions and 
+ * -fcxx-exceptions.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+
+/**
+ * Finally we should test that we only ignore exceptions in the OpenMP 
+ * offloading tool-chain
+*/
+
+// RUN: %clang_cc1 -triple nvptx64 %s -emit-llvm -S -verify=noexceptions -o -
+
+// noexceptions-error@38 {{cannot use 'try' with exceptions disabled}}
+
+#pragma 

[PATCH] D159133: [Sema] Make C++ functional-style cast warn about dropped qualifiers (-Wcast-qual)

2023-08-29 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

This seems like it will generate warning cleanup work for vendors, so I'll 
mention #clang-vendors  , but I 
think the code looks good. I don't think it makes sense to add a fine-grained 
diagnostic category to allow people to clean up incrementally in this case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159133

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


[PATCH] D159103: [Driver][HLSL] Improve diagnostics for invalid shader model and stage

2023-08-29 Thread Justin Bogner via Phabricator via cfe-commits
bogner added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:710-716
+  "Shader model is required in target '%0' for DXIL generation">;
+def err_drv_dxil_unsupported_shader_model : Error<
+  "Shader model '%0' in target '%1' is invalid for DXIL generation">;
+def err_drv_dxil_missing_shader_stage : Error<
+  "Shader stage is required in target '%0' for DXIL generation">;
+def err_drv_dxil_unsupported_shader_stage : Error<
+  "Shader stage '%0' in target '%1' is invalid for DXIL generation">;

aaron.ballman wrote:
> Hmmm in theory:
> ```
> def err_drv_dxil_bad_shader_required_in_target : Error<
>   "shader %select{model|stage}0 is required in target '%1' for DXIL 
> generation">;
> 
> def err_drv_dxil_bad_shader_unsupported : Error<
>   "shader %select{model|stage}0 '%1' in target '%2' is invalid for DXIL 
> generation">;
> ```
To make that readable you kind of have to do something like this:

```
if (T.isDXIL()) {
  enum { ShaderModel, ShaderStage };
  if (T.getOSName().empty()) {
Diags.Report(diag::err_drv_dxil_bad_shader_required_in_target)
<< ShaderModel << T.str();
  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
Diags.Report(diag::err_drv_dxil_bad_shader_invalid)
ShaderModel << T.getOSName() << T.str();
  } else if (T.getEnvironmentName().empty()) {
Diags.Report(diag::err_drv_dxil_bad_shader_required_in_target)
<< ShaderStage << T.str();
  } else if (!T.isShaderStageEnvironment()) {
Diags.Report(diag::err_drv_dxil_bad_shader_invalid)
<< ShaderStage << T.getEnvironmentName() << T.str();
  }
}
```

It's not really clear to me which way is better. WDYT?




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4054
+  if (T.getOSName().empty()) {
+Diags.Report(diag::err_drv_dxil_missing_shader_model) << T.str();
+  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {

aaron.ballman wrote:
> Idle question: can you pass `T` directly here? (I thought we had diagnostic 
> streaming support for `Triple` but I'm not spotting it with a quick look 
> through the source).
Tried it, and no. Looks like we don't have that overload.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159103

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


[PATCH] D158475: [driver] Refactor getRuntimePaths. NFC

2023-08-29 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D158475#4623852 , @glandium wrote:

> In D158475#4623842 , @smeenai wrote:
>
>> In D158475#4623471 , @glandium 
>> wrote:
>>
>>> This conflicts with D146664 
>>
>> It sounds like you want the same logic as D158476 
>>  to apply to the stdlib search as well as 
>> the runtimes search, right?
>
> Sounds about right.
>
>> I can make both be consistent.
>
> That would be much appreciated.

I'm halfway through an implementation of this, but I just realized that on 
Android, Clang never searches for C++ headers installed alongside the driver: 
https://github.com/llvm/llvm-project/blob/7af0eff5405bb88dc96c0b19892da0fbb44db433/clang/lib/Driver/ToolChains/Gnu.cpp#L3116-L3118.
 Are you using the C++ headers from the NDK but a library that you built 
locally, or are you manually specifying the path to your C++ headers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158475

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


[PATCH] D117929: [XRay] Add support for RISCV

2023-08-29 Thread Ashwin Poduval via Phabricator via cfe-commits
ashwin98 updated this revision to Diff 554513.
ashwin98 added a comment.

Sorry - I missed adding updates with the last diff - I think I've addressed 
most of the comments. Just realized that the diff didn't include context, 
updated that as well.


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

https://reviews.llvm.org/D117929

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_riscv.cpp
  compiler-rt/lib/xray/xray_trampoline_riscv32.S
  compiler-rt/lib/xray/xray_trampoline_riscv64.S
  compiler-rt/lib/xray/xray_tsc.h
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/RISCV/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/xray-attribute-instrumentation.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=riscv32-unknown-linux-gnu -mattr=+d -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK %s
+; RUN: llc -mtriple=riscv64-unknown-linux-gnu -mattr=+d -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK --check-prefix=CHECK-RISCV64 %s
+
+define i32 @foo() nounwind "function-instrument"="xray-always" {
+; CHECK:.p2align 2
+; CHECK-LABEL:  .Lxray_sled_0:
+; CHECK-NEXT:   j .Ltmp0
+; CHECK-COUNT-14:   nop
+; CHECK-RISCV64-COUNT-4:nop
+; CHECK-LABEL:  .Ltmp0:
+  ret i32 0
+; CHECK:.p2align 2
+; CHECK-LABEL:  .Lxray_sled_1:
+; CHECK-NEXT:   j .Ltmp1
+; CHECK-COUNT-14:   nop
+; CHECK-RISCV64-COUNT-4:nop
+; CHECK-LABEL:  .Ltmp1:
+; CHECK-NEXT:   ret
+}
+; CHECK:.section xray_instr_map,"ao",@progbits,foo
+; CHECK-LABEL:  .Lxray_sleds_start0:
+; CHECK:.Lxray_sled_0-[[TMP:.Ltmp[0-9]+]]
+; CHECK:.Lxray_sled_1-[[TMP:.Ltmp[0-9]+]]
+; CHECK-LABEL:  .Lxray_sleds_end0:
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -160,6 +160,11 @@
 assert(i < RISCV::NUM_TARGET_REGS && "Register out of range");
 return UserReservedRegister[i];
   }
+  // Add XRay support - needs double precision floats at present and does not
+  // support compressed instructions
+  bool isXRaySupported() const override {
+return hasStdExtD() && !hasStdExtC();
+  }
 
   bool hasMacroFusion() const { return hasLUIADDIFusion(); }
 
Index: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
===
--- llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -16,6 +16,7 @@
 #include "MCTargetDesc/RISCVMCExpr.h"
 #include "MCTargetDesc/RISCVTargetStreamer.h"
 #include "RISCV.h"
+#include "RISCVSubtarget.h"
 #include "RISCVMachineFunctionInfo.h"
 #include "RISCVTargetMachine.h"
 #include "TargetInfo/RISCVTargetInfo.h"
@@ -84,6 +85,11 @@
   // Wrapper needed for tblgenned pseudo lowering.
   bool lowerOperand(const MachineOperand , MCOperand ) const;
 
+  // XRay Support
+  void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr *MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr *MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr *MI);
+
   void emitStartOfAsmFile(Module ) override;
   void emitEndOfAsmFile(Module ) override;
 
@@ -93,6 +99,8 @@
 
 private:
   void emitAttributes();
+  // XRay Support
+  void emitSled(const MachineInstr *MI, SledKind Kind);
 
   void emitNTLHint(const MachineInstr *MI);
 
@@ -167,6 +175,27 @@
   case RISCV::PseudoRVVInitUndefM4:
   case RISCV::PseudoRVVInitUndefM8:
 return;
+  case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
+// This switch case section is only for handling XRay sleds.
+//
+// patchable-function-entry is handled in lowerToMCInst
+// Therefore, we break out of the switch statement if we encounter it here.
+const Function  = MI->getParent()->getParent()->getFunction();
+if (F.hasFnAttribute("patchable-function-entry")) {
+  break;
+}
+
+LowerPATCHABLE_FUNCTION_ENTER(MI);
+return;
+  }
+  case TargetOpcode::PATCHABLE_FUNCTION_EXIT: {
+LowerPATCHABLE_FUNCTION_EXIT(MI);
+return;
+  }
+  case TargetOpcode::PATCHABLE_TAIL_CALL: {
+LowerPATCHABLE_TAIL_CALL(MI);
+return;
+  }
   }
 
   MCInst OutInst;
@@ -282,11 +311,68 @@
   SetupMachineFunction(MF);
   emitFunctionBody();
 
+  // Emit the XRay table
+  emitXRayTable();
+
   if (!isSameAttribute())
 

[clang] 7af0eff - Revert "[OpenMP] Allow exceptions in target regions when offloading to GPUs"

2023-08-29 Thread via cfe-commits

Author: antonrydahl
Date: 2023-08-29T15:59:47-07:00
New Revision: 7af0eff5405bb88dc96c0b19892da0fbb44db433

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

LOG: Revert "[OpenMP] Allow exceptions in target regions when offloading to 
GPUs"

This reverts commit 4c62e943b7178127861ca39163a0ed4caeb14943.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/CodeGen/CGException.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/OpenMP/nvptx_target_exceptions_messages.cpp

Removed: 
clang/test/OpenMP/amdgpu_exceptions.cpp
clang/test/OpenMP/amdgpu_throw.cpp
clang/test/OpenMP/amdgpu_throw_trap.cpp
clang/test/OpenMP/amdgpu_try_catch.cpp
clang/test/OpenMP/nvptx_exceptions.cpp
clang/test/OpenMP/nvptx_throw.cpp
clang/test/OpenMP/nvptx_throw_trap.cpp
clang/test/OpenMP/nvptx_try_catch.cpp
clang/test/OpenMP/x86_target_exceptions.cpp
clang/test/OpenMP/x86_target_throw.cpp
clang/test/OpenMP/x86_target_try_catch.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f2df283c74829f..cd72e254ea3b1a 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -425,13 +425,4 @@ def err_opencl_extension_and_feature_
diff ers : Error<
   "options %0 and %1 are set to 
diff erent values">;
 def err_opencl_feature_requires : Error<
   "feature %0 requires support of %1 feature">;
-
-def warn_throw_not_valid_on_target : Warning<
-  "target '%0' does not support exception handling;"
-  " 'throw' is assumed to be never reached">,
-  InGroup;
-def warn_try_not_valid_on_target : Warning<
-  "target '%0' does not support exception handling;"
-  " 'catch' block is ignored">,
-  InGroup;
 }

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 00c458fb23e73e..d1aa51393ef357 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1292,10 +1292,9 @@ def OpenMPTarget : DiagGroup<"openmp-target", 
[OpenMPMapping]>;
 def OpenMPPre51Compat : DiagGroup<"pre-openmp-51-compat">;
 def OpenMP51Ext : DiagGroup<"openmp-51-extensions">;
 def OpenMPExtensions : DiagGroup<"openmp-extensions">;
-def OpenMPTargetException : DiagGroup<"openmp-target-exception">;
 def OpenMP : DiagGroup<"openmp", [
 SourceUsesOpenMP, OpenMPClauses, OpenMPLoopForm, OpenMPTarget,
-OpenMPMapping, OpenMP51Ext, OpenMPExtensions, OpenMPTargetException
+OpenMPMapping, OpenMP51Ext, OpenMPExtensions
   ]>;
 
 // Backend warnings.

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb..9cb7d4c7731deb 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -440,15 +440,6 @@ llvm::Value *CodeGenFunction::getSelectorFromSlot() {
 
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
bool KeepInsertionPoint) {
-  // If the exception is being emitted in an OpenMP target region,
-  // and the target is a GPU, we do not support exception handling.
-  // Therefore, we emit a trap which will abort the program, and
-  // prompt a warning indicating that a trap will be emitted.
-  const llvm::Triple  = Target.getTriple();
-  if (CGM.getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN())) 
{
-EmitTrapCall(llvm::Intrinsic::trap);
-return;
-  }
   if (const Expr *SubExpr = E->getSubExpr()) {
 QualType ThrowType = SubExpr->getType();
 if (ThrowType->isObjCObjectPointerType()) {
@@ -618,16 +609,9 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 }
 
 void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt ) {
-  const llvm::Triple  = Target.getTriple();
-  // If we encounter a try statement on in an OpenMP target region offloaded to
-  // a GPU, we treat it as a basic block.
-  const bool IsTargetDevice =
-  (CGM.getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || 
T.isAMDGCN()));
-  if (!IsTargetDevice)
-EnterCXXTryStmt(S);
+  EnterCXXTryStmt(S);
   EmitStmt(S.getTryBlock());
-  if (!IsTargetDevice)
-ExitCXXTryStmt(S);
+  ExitCXXTryStmt(S);
 }
 
 void CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt , bool IsFnTryBlock) {

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 472fbdbdb5d0e6..a6e0a8abf81b9a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -864,21 +864,13 @@ Sema::ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr 
*Ex) {
 
 ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
 

Re: [PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-29 Thread Richard Smith via cfe-commits
On Tue, 22 Aug 2023 at 12:43, Nouman Amir via Phabricator via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
> ===
> --- clang/include/clang/Basic/DiagnosticSemaKinds.td
> +++ clang/include/clang/Basic/DiagnosticSemaKinds.td
> @@ -9393,8 +9393,7 @@
>"the parameter for an explicitly-defaulted copy assignment operator
> must be an "
>"lvalue reference type">;
>  def err_incorrect_defaulted_constexpr : Error<
> -  "defaulted definition of %sub{select_special_member_kind}0 "
> -  "is not constexpr">;
> +  "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class or
> struct with virtual base classes">;
>

Please don't say "class or struct" here. Either just say "class" (a struct
is a kind of class) or actually figure out which one it is and say that.


>  def err_incorrect_defaulted_consteval : Error<
>"defaulted declaration of %sub{select_special_member_kind}0 "
>"cannot be consteval because implicit definition is not constexpr">;
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159145: [RISCV] Don't add -unaligned-scalar-mem to target features by default.

2023-08-29 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: wangpc, kito-cheng, asb, reames, jrtc27.
Herald added subscribers: jobnoorman, luke, sunshaoce, VincentWu, vkmr, 
frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, 
psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, 
hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, eopXD, MaskRay.
Herald added projects: clang, LLVM.

Only pass it +unaligned-scalar-mem/-unaligned-scalar-mem if the
user has passed one of the alignment options.

This allows us to add unaligned-scalar-mem as a feature on CPUs
that support it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159145

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-default-features.c
  clang/test/Driver/riscv-features.c
  llvm/lib/Target/RISCV/RISCVProcessors.td


Index: llvm/lib/Target/RISCV/RISCVProcessors.td
===
--- llvm/lib/Target/RISCV/RISCVProcessors.td
+++ llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -181,7 +181,8 @@
FeatureStdExtZfh,
FeatureStdExtZvfh,
FeatureStdExtZba,
-   FeatureStdExtZbb],
+   FeatureStdExtZbb,
+   FeatureUnalignedScalarMem],
   [TuneSiFive7,
TuneDLenFactor2]>;
 
Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -39,8 +39,6 @@
 // NO-UNALIGNED-SCALAR-MEM: "-target-feature" "-unaligned-scalar-mem"
 // UNALIGNED-VECTOR-MEM: "-target-feature" "+unaligned-vector-mem"
 // NO-UNALIGNED-VECTOR-MEM: "-target-feature" "-unaligned-vector-mem"
-// DEFAULT: "-target-feature" "-unaligned-scalar-mem"
-// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem"
 
 // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
Index: clang/test/Driver/riscv-default-features.c
===
--- clang/test/Driver/riscv-default-features.c
+++ clang/test/Driver/riscv-default-features.c
@@ -3,10 +3,8 @@
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
 // RV32-SAME: -save-restore
-// RV32-SAME: -unaligned-scalar-mem
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
 // RV64-SAME: -save-restore
-// RV64-SAME: -unaligned-scalar-mem
 
 // Dummy function
 int foo(void){
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -169,15 +169,17 @@
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   bool HasV = llvm::is_contained(Features, "+zve32x");
-  if (Args.hasFlag(options::OPT_munaligned_access,
-   options::OPT_mno_unaligned_access, false)) {
-Features.push_back("+unaligned-scalar-mem");
-if (HasV)
-  Features.push_back("+unaligned-vector-mem");
-  } else {
-Features.push_back("-unaligned-scalar-mem");
-if (HasV)
-  Features.push_back("-unaligned-vector-mem");
+  if (const Arg *A = Args.getLastArg(options::OPT_munaligned_access,
+ options::OPT_mno_unaligned_access)) {
+if (A->getOption().matches(options::OPT_munaligned_access)) {
+  Features.push_back("+unaligned-scalar-mem");
+  if (HasV)
+Features.push_back("+unaligned-vector-mem");
+} else {
+  Features.push_back("-unaligned-scalar-mem");
+  if (HasV)
+Features.push_back("-unaligned-vector-mem");
+}
   }
 
   // Now add any that the user explicitly requested on the command line,


Index: llvm/lib/Target/RISCV/RISCVProcessors.td
===
--- llvm/lib/Target/RISCV/RISCVProcessors.td
+++ llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -181,7 +181,8 @@
FeatureStdExtZfh,
FeatureStdExtZvfh,
FeatureStdExtZba,
-   FeatureStdExtZbb],
+   FeatureStdExtZbb,
+   FeatureUnalignedScalarMem],
   [TuneSiFive7,
TuneDLenFactor2]>;
 
Index: clang/test/Driver/riscv-features.c

[PATCH] D159137: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:440
+  StringRef Val = A->getValue();
+  if (Val == "atomic" || Val == "prefer-atomic")
+CmdArgs.push_back("-latomic");

qiongsiwu1 wrote:
> This check here is copied from 
> https://github.com/llvm/llvm-project/blob/77596e6b167bf0a5efa790597d6b75ac5e685b55/clang/lib/Driver/ToolChains/Clang.cpp#L867,
>  and I don't think it is good to copy this particular code over because we 
> are doing the same check twice at different places and the code can go out of 
> sync. 
> 
> May I get some suggestions to avoid duplicating the code? Thanks! 
This seems ok to me. You can also use `!= "single"` instead.

`getLastArgNoClaim` is probably slightly better.



Comment at: clang/test/Driver/fprofile-update.c:17
+// AIX specific tests
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate 
-fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate 
-fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX %}

The idiom is to use `--target=...`. This driver decision is not dependent on 
what OS the host runs, so `%if system-aix` should be avoided.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159137

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


[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2023-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Basic/SizedDeallocation.h:23
+namespace clang {
+inline llvm::VersionTuple sizedDeallocMinVersion(llvm::Triple::OSType OS) {
+  switch (OS) {

wangpc wrote:
> MaskRay wrote:
> > Does this need to be in Basic/? It's only used by 
> > clang/lib/Driver/ToolChains/Darwin.cpp
> > 
> > 
> This file is just copied and changed from 
> `clang/include/clang/Basic/AlignedAllocation.h` actually, I don't know which 
> directory is more suitable.
If this is only used by clangDriver, I am not sure we want to expose it as a 
public header under include/.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

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


[PATCH] D153924: [OpenMP] Allow exceptions in target regions when offloading to GPUs

2023-08-29 Thread Anton Rydahl 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 rG4c62e943b717: [OpenMP] Allow exceptions in target regions 
when offloading to GPUs (authored by AntonRydahl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153924

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGException.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/OpenMP/amdgpu_exceptions.cpp
  clang/test/OpenMP/amdgpu_throw.cpp
  clang/test/OpenMP/amdgpu_throw_trap.cpp
  clang/test/OpenMP/amdgpu_try_catch.cpp
  clang/test/OpenMP/nvptx_exceptions.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
  clang/test/OpenMP/nvptx_throw.cpp
  clang/test/OpenMP/nvptx_throw_trap.cpp
  clang/test/OpenMP/nvptx_try_catch.cpp
  clang/test/OpenMP/x86_target_exceptions.cpp
  clang/test/OpenMP/x86_target_throw.cpp
  clang/test/OpenMP/x86_target_try_catch.cpp

Index: clang/test/OpenMP/x86_target_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_try_catch.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		error = 1;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_throw.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_throw.cpp
@@ -0,0 +1,9 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+void foo(void) {
+	throw 404;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_exceptions.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_exceptions.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -analyze
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		throw 404;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/nvptx_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/nvptx_try_catch.cpp
@@ -0,0 +1,47 @@
+// REQUIRES: nvptx-registered-target
+
+/**
+ * The first four lines test that a warning is produced when enabling 
+ * -Wopenmp-target-exception no matter what combination of -fexceptions and 
+ * -fcxx-exceptions are set, as we want OpenMP to always allow exceptions in the
+ * target region but emit a warning instead.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=with -Wopenmp-target-exception -analyze
+
+/**
+ * The following four lines test that no warning is emitted when providing 
+ * -Wno-openmp-target-exception no matter the combination of -fexceptions and 
+ * -fcxx-exceptions.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -analyze
+
+/**
+ * Finally we should test that we only ignore exceptions in the OpenMP 
+ * offloading tool-chain
+*/
+
+// RUN: %clang_cc1 -triple nvptx64 %s -emit-llvm -S -verify=noexceptions 

[clang] 4c62e94 - [OpenMP] Allow exceptions in target regions when offloading to GPUs

2023-08-29 Thread via cfe-commits

Author: Anton Rydahl
Date: 2023-08-29T15:05:59-07:00
New Revision: 4c62e943b7178127861ca39163a0ed4caeb14943

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

LOG: [OpenMP] Allow exceptions in target regions when offloading to GPUs

The motivation for this patch is that many code bases use exception handling. 
As GPUs are not expected to support exception handling in the near future, we 
can experiment with compiling the code for GPU targets anyway. This will
allow us to run the code, as long as no exception is thrown.

The overall idea is very simple:
- If a throw expression is compiled to AMDGCN or NVPTX, it is replaced with a 
trap during code generation.
- If a try/catch statement is compiled to AMDGCN or AMDHSA, we ganerate code 
for the try statement as if it were a basic block.

With this patch, the compilation of the following example
```
int gaussian_sum(int a,int b){
if ((a + b) % 2 == 0) {throw -1;};
return (a+b) * ((a+b)/2);
}

int main(void) {
int gauss = 0;
#pragma omp target map(from:gauss)
{
try {
gauss = gaussian_sum(1,100);
}
catch (int e){
gauss = e;
}
}
std::cout << "GaussianSum(1,100)=";
 def err_opencl_feature_requires : Error<
   "feature %0 requires support of %1 feature">;
+
+def warn_throw_not_valid_on_target : Warning<
+  "target '%0' does not support exception handling;"
+  " 'throw' is assumed to be never reached">,
+  InGroup;
+def warn_try_not_valid_on_target : Warning<
+  "target '%0' does not support exception handling;"
+  " 'catch' block is ignored">,
+  InGroup;
 }

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d1aa51393ef357..00c458fb23e73e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1292,9 +1292,10 @@ def OpenMPTarget : DiagGroup<"openmp-target", 
[OpenMPMapping]>;
 def OpenMPPre51Compat : DiagGroup<"pre-openmp-51-compat">;
 def OpenMP51Ext : DiagGroup<"openmp-51-extensions">;
 def OpenMPExtensions : DiagGroup<"openmp-extensions">;
+def OpenMPTargetException : DiagGroup<"openmp-target-exception">;
 def OpenMP : DiagGroup<"openmp", [
 SourceUsesOpenMP, OpenMPClauses, OpenMPLoopForm, OpenMPTarget,
-OpenMPMapping, OpenMP51Ext, OpenMPExtensions
+OpenMPMapping, OpenMP51Ext, OpenMPExtensions, OpenMPTargetException
   ]>;
 
 // Backend warnings.

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 9cb7d4c7731deb..3996f2948349cb 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -440,6 +440,15 @@ llvm::Value *CodeGenFunction::getSelectorFromSlot() {
 
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
bool KeepInsertionPoint) {
+  // If the exception is being emitted in an OpenMP target region,
+  // and the target is a GPU, we do not support exception handling.
+  // Therefore, we emit a trap which will abort the program, and
+  // prompt a warning indicating that a trap will be emitted.
+  const llvm::Triple  = Target.getTriple();
+  if (CGM.getLangOpts().OpenMPIsTargetDevice && (T.isNVPTX() || T.isAMDGCN())) 
{
+EmitTrapCall(llvm::Intrinsic::trap);
+return;
+  }
   if (const Expr *SubExpr = E->getSubExpr()) {
 QualType ThrowType = SubExpr->getType();
 if (ThrowType->isObjCObjectPointerType()) {
@@ 

[PATCH] D159133: [Sema] Make C++ functional-style cast warn about dropped qualifiers (-Wcast-qual)

2023-08-29 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I think this makes sense especially if it matches up w/ gcc but would like to 
see more feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159133

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


[PATCH] D159024: [Parser] Parse string literal arguments of 'availability', 'external_source_symbol' and 'uuid' attributes as unevaluated

2023-08-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 554497.
barannikov88 added a comment.

Update the failing test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159024

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/attr-availability-xcore.c
  clang/test/Parser/attr-availability.c
  clang/test/Parser/attr-external-source-symbol.m
  clang/test/Parser/ms-square-bracket-attributes.mm

Index: clang/test/Parser/ms-square-bracket-attributes.mm
===
--- clang/test/Parser/ms-square-bracket-attributes.mm
+++ clang/test/Parser/ms-square-bracket-attributes.mm
@@ -17,9 +17,9 @@
 )] struct struct_with_uuid_brace;
 
 // uuids must be ascii string literals.
-// expected-error@+1 {{uuid attribute contains a malformed GUID}}
+// expected-warning@+1 {{encoding prefix 'u8' on an unevaluated string literal has no effect and is incompatible with c++2c}}
 [uuid(u8"00A0---C000-0049")] struct struct_with_uuid_u8;
-// expected-error@+1 {{uuid attribute contains a malformed GUID}}
+// expected-warning@+1 {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}}
 [uuid(L"00A0---C000-0049")] struct struct_with_uuid_L;
 
 // cl.exe doesn't allow raw string literals in []-style attributes, but does
Index: clang/test/Parser/attr-external-source-symbol.m
===
--- clang/test/Parser/attr-external-source-symbol.m
+++ clang/test/Parser/attr-external-source-symbol.m
@@ -95,6 +95,27 @@
 void f28(void)
 __attribute__((external_source_symbol(USR="")));
 
+void f29(void)
+__attribute__((external_source_symbol(language=L"Swift"))); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
+
+void f30(void)
+__attribute__((external_source_symbol(language="Swift", language=L"Swift"))); // expected-error {{duplicate 'language' clause in an 'external_source_symbol' attribute}} \
+  // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
+
+void f31(void)
+__attribute__((external_source_symbol(USR=u"foo"))); // expected-warning {{encoding prefix 'u' on an unevaluated string literal has no effect}}
+
+void f32(void)
+__attribute__((external_source_symbol(USR="foo", USR=u"foo"))); // expected-error {{duplicate 'USR' clause in an 'external_source_symbol' attribute}} \
+// expected-warning {{encoding prefix 'u' on an unevaluated string literal has no effect}}
+
+void f33(void)
+__attribute__((external_source_symbol(defined_in=U"module"))); // expected-warning {{encoding prefix 'U' on an unevaluated string literal has no effect}}
+
+void f34(void)
+__attribute__((external_source_symbol(defined_in="module", defined_in=U"module"))); // expected-error {{duplicate 'defined_in' clause in an 'external_source_symbol' attribute}} \
+// expected-warning {{encoding prefix 'U' on an unevaluated string literal has no effect}}
+
 #if __has_attribute(external_source_symbol) != 20230206
 # error "invalid __has_attribute version"
 #endif
Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -18,17 +18,17 @@
 
 void f6(void) __attribute__((availability(macosx,unavailable,introduced=10.5))); // expected-warning{{'unavailable' availability overrides all other availability information}}
 
-void f7(void) __attribute__((availability(macosx,message=L"wide"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f7(void) __attribute__((availability(macosx,message=L"wide"))); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
 
-void f8(void) __attribute__((availability(macosx,message="a" L"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f8(void) __attribute__((availability(macosx,message="a" L"b"))); // expected-warning {{encoding prefix 'L' on an unevaluated string literal has no effect}}
 
-void f9(void) __attribute__((availability(macosx,message=u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f9(void) __attribute__((availability(macosx,message=u8"b"))); // expected-warning {{encoding prefix 'u8' on an unevaluated string literal has no effect}}
 
-void f10(void) __attribute__((availability(macosx,message="a" u8"b"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}

[PATCH] D159133: [Sema] Make C++ functional-style cast warn about dropped qualifiers (-Wcast-qual)

2023-08-29 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added reviewers: aaron.ballman, clang-language-wg.
shafik added a comment.

Add more reviewers for visibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159133

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


[PATCH] D152752: [MS] Fix passing aligned records by value in some cases

2023-08-29 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I put together a fix here: 
https://github.com/llvm/llvm-project/compare/main...rnk:llvm-project:fix-vararg-align

I don't have arcanist set up like I used to, and I don't write as much code as 
I used to, so I kind of want to submit this as a pull request as soon as they 
are available this Thursday, if that's not an issue for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152752

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


[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-08-29 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

Yea, the gist of it is that in HLSL `this` is a reference not a pointer, which 
means the `CXXThisExpr` is always an LValue.

I think the right fix for this is to cleanup the `CXXThisExpr` creation code 
and create a `CXXThisExpr::Create` method like the other AST nodes. Then I can 
have a simpler way to force the `CXXThisExpr` to always be an LValue for HLSL.

@aaron.ballman, does that sound reasonable?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159126

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


[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-08-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@beanz Oh wow, excellent, i did not expect a solution so fast! I'm glad to know 
there may indeed be an issue with HLSL rather than this patch because I'm not 
sure I could have come up with a different fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159126

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


[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-08-29 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

@cor3ntin, I know what the problem is and I think I can put up a review for a 
fix tonight or (more likely) tomorrow. Is that okay?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159126

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


[PATCH] D159138: [clang][Sema] Fix format size estimator's handling of %o, %x, %X with alternative form

2023-08-29 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet created this revision.
hazohelet added reviewers: aaron.ballman, nickdesaulniers, serge-sans-paille.
Herald added a project: All.
hazohelet requested review of this revision.
Herald added a project: clang.

The wrong handling of %x specifier with alternative form causes a false 
positive in linux kernel 
(https://github.com/ClangBuiltLinux/linux/issues/1923#issuecomment-1696075886)

The kernel code: 
https://github.com/torvalds/linux/blob/651a00bc56403161351090a9d7ddbd7095975324/drivers/media/pci/cx18/cx18-mailbox.c#L99

This patch fixes this handling, and also adds some standard wordings as 
comments to clarify the reason.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159138

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-source.c

Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -85,7 +85,7 @@
   __builtin_memset(buf, 0xff, 11); // expected-warning {{'memset' will always overflow; destination buffer has size 10, but size argument is 11}}
 }
 
-void call_snprintf(double d) {
+void call_snprintf(double d, int n) {
   char buf[10];
   __builtin_snprintf(buf, 10, "merp");
   __builtin_snprintf(buf, 11, "merp"); // expected-warning {{'snprintf' size argument is too large; destination buffer has size 10, but size argument is 11}}
@@ -96,6 +96,8 @@
   __builtin_snprintf(buf, 1, "%.1000g", d); // expected-warning {{'snprintf' will always be truncated; specified size is 1, but format string expands to at least 2}}
   __builtin_snprintf(buf, 5, "%.1000g", d);
   __builtin_snprintf(buf, 5, "%.1000G", d);
+  __builtin_snprintf(buf, 10, " %#08x", n);
+  __builtin_snprintf(buf, 2, "%#x", n);
 }
 
 void call_vsnprintf(void) {
@@ -110,6 +112,8 @@
   __builtin_vsnprintf(buf, 1, "%.1000g", list); // expected-warning {{'vsnprintf' will always be truncated; specified size is 1, but format string expands to at least 2}}
   __builtin_vsnprintf(buf, 5, "%.1000g", list);
   __builtin_vsnprintf(buf, 5, "%.1000G", list);
+  __builtin_vsnprintf(buf, 10, " %#08x", list);
+  __builtin_vsnprintf(buf, 2, "%#x", list);
 }
 
 void call_sprintf_chk(char *buf) {
@@ -147,7 +151,7 @@
   __builtin___sprintf_chk(buf, 1, 2, "%%");
   __builtin___sprintf_chk(buf, 1, 1, "%%"); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
   __builtin___sprintf_chk(buf, 1, 4, "%#x", 9);
-  __builtin___sprintf_chk(buf, 1, 3, "%#x", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 3, but format string expands to at least 4}}
+  __builtin___sprintf_chk(buf, 1, 3, "%#x", 9);
   __builtin___sprintf_chk(buf, 1, 4, "%p", (void *)9);
   __builtin___sprintf_chk(buf, 1, 3, "%p", (void *)9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 3, but format string expands to at least 4}}
   __builtin___sprintf_chk(buf, 1, 3, "%+d", 9);
@@ -184,7 +188,7 @@
   sprintf(buf, "1234%lld", 9ll);
   sprintf(buf, "12345%lld", 9ll); // expected-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
   sprintf(buf, "12%#x", 9);
-  sprintf(buf, "123%#x", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
+  sprintf(buf, "123%#x", 9);
   sprintf(buf, "12%p", (void *)9);
   sprintf(buf, "123%p", (void *)9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 6, but format string expands to at least 7}}
   sprintf(buf, "123%+d", 9);
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -890,6 +890,8 @@
 // %g style conversion switches between %f or %e style dynamically.
 // %g removes trailing zeros, and does not print decimal point if there are
 // no digits that follow it. Thus %g can print a single digit.
+// FIXME: If it is alternative form:
+// For g and G conversions, trailing zeros are not removed from the result.
 case analyze_format_string::ConversionSpecifier::gArg:
 case analyze_format_string::ConversionSpecifier::GArg:
   Size += 1;
@@ -947,18 +949,26 @@
 
 if (FS.hasAlternativeForm()) {
   switch (FS.getConversionSpecifier().getKind()) {
-  default:
-break;
-  // Force a leading '0'.
+  // For o conversion, it increases the precision, if and only if necessary,
+  // to force the first digit of the result to be a zero
+  // (if the value and precision are both 0, a single 0 is printed)
   case analyze_format_string::ConversionSpecifier::oArg:
-Size += 1;
-break;
-  // Force a leading '0x'.
+  // For b 

[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-29 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 554489.

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

https://reviews.llvm.org/D158540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/special/class.copy/p13-0x.cpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -54,5 +54,5 @@
 
 struct W {
   int w;
-  constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor is not constexpr}}
+  constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class or struct}}
 };
Index: clang/test/CXX/special/class.copy/p13-0x.cpp
===
--- clang/test/CXX/special/class.copy/p13-0x.cpp
+++ clang/test/CXX/special/class.copy/p13-0x.cpp
@@ -125,7 +125,7 @@
 mutable A a;
   };
   struct C {
-constexpr C(const C &) = default; // expected-error {{not constexpr}}
+constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}}
 A a;
   };
 }
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -129,19 +129,19 @@
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class or struct}}
 #endif
 union C { int n = 0; constexpr C() = default; };
 struct D { union {}; constexpr D() = default; }; // expected-error {{does not declare anything}}
 struct E { union { int n; }; constexpr E() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class or struct}}
 #endif
 struct F { union { int n = 0; }; constexpr F() = default; };
 
 struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{not constexpr}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class or struct}}
 #endif
 struct H {
   union {
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -328,10 +328,10 @@
 namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
-  union B { constexpr B() = default; int a; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
-  union C { constexpr C() = default; int a, b; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class or struct}} expected-note 2{{candidate}}
+  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}} expected-note 2{{candidate}}
   struct X { constexpr X() = default; union {}; }; // expected-error {{does not declare anything}}
-  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{not constexpr}} expected-note 2{{candidate}}
+  struct Y { constexpr Y() = default; union { int a; }; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'Y' in 'Y' class or struct}} expected-note 2{{candidate}}
 
   constexpr A a = A();
   constexpr B b = B(); // expected-error {{no matching}}
Index: 

[PATCH] D154287: [clang-tidy] Add modernize-use-std-format check

2023-08-29 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 554486.
mikecrowe edited the summary of this revision.
mikecrowe added a comment.

Fix ReleaseNotes order and remove unnecessary .html from list.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154287

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
  clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: true}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: false}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+#include 
+// CHECK-FIXES: #include 
+
+namespace absl
+{
+// Use const char * for the format since the real type is hard to mock up.
+template 
+std::string StrFormat(const char *format, const Args&... args);
+} // namespace absl
+
+template 
+struct iterator {
+  T *operator->();
+  T *();
+};
+
+std::string StrFormat_simple() {
+  return absl::StrFormat("Hello");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Hello");
+}
+
+std::string StrFormat_complex(const char *name, double value) {
+  return absl::StrFormat("'%s'='%f'", name, value);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("'{}'='{:f}'", name, value);
+}
+
+std::string StrFormat_integer_conversions() {
+  return absl::StrFormat("int:%d int:%d char:%c char:%c", 65, 'A', 66, 'B');
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("int:{} int:{:d} char:{:c} char:{}", 65, 'A', 66, 'B');
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_no_newline_removal() {
+  return absl::StrFormat("a line\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("a line\n");
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_cstr_removal(const std::string , const std::string *s2) {
+  return absl::StrFormat("%s %s %s %s", s1.c_str(), s1.data(), s2->c_str(), s2->data());
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("{} {} {} {}", s1, s1, *s2, *s2);
+}
+
+std::string StrFormat_strict_conversion() {
+  const unsigned char uc = 'A';
+  return absl::StrFormat("Integer %hhd from unsigned char\n", uc);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Integer {} from unsigned char\n", uc);
+}
+
+std::string StrFormat_field_width_and_precision() {
+  auto s1 = absl::StrFormat("width only:%*d width and precision:%*.*f precision only:%.*f", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width only:{:{}} width and precision:{:{}.{}f} precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5);
+
+  auto s2 = absl::StrFormat("width and precision positional:%1$*2$.*3$f after", 3.14159265358979323846, 4, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width 

[PATCH] D159137: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect

2023-08-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:440
+  StringRef Val = A->getValue();
+  if (Val == "atomic" || Val == "prefer-atomic")
+CmdArgs.push_back("-latomic");

This check here is copied from 
https://github.com/llvm/llvm-project/blob/77596e6b167bf0a5efa790597d6b75ac5e685b55/clang/lib/Driver/ToolChains/Clang.cpp#L867,
 and I don't think it is good to copy this particular code over because we are 
doing the same check twice at different places and the code can go out of sync. 

May I get some suggestions to avoid duplicating the code? Thanks! 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159137

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-08-29 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 554485.

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

https://reviews.llvm.org/D158540

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/special/class.copy/p13-0x.cpp
  clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -54,5 +54,5 @@
 
 struct W {
   int w;
-  constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}}
+  constexpr W() __constant = default; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'W' in 'W' class or struct}}
 };
Index: clang/test/CXX/special/class.copy/p13-0x.cpp
===
--- clang/test/CXX/special/class.copy/p13-0x.cpp
+++ clang/test/CXX/special/class.copy/p13-0x.cpp
@@ -125,7 +125,7 @@
 mutable A a;
   };
   struct C {
-constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}}
+constexpr C(const C &) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}}
 A a;
   };
 }
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -129,19 +129,19 @@
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'B' in 'B' class or struct}}
 #endif
 union C { int n = 0; constexpr C() = default; };
 struct D { union {}; constexpr D() = default; }; // expected-error {{does not declare anything}}
 struct E { union { int n; }; constexpr E() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'E' in 'E' class or struct}}
 #endif
 struct F { union { int n = 0; }; constexpr F() = default; };
 
 struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; };
 #if __cplusplus <= 201703L
-// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}}
+// expected-error@-2 {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note@-2 {{see reference to function 'G' in 'G' class or struct}}
 #endif
 struct H {
   union {
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -328,10 +328,10 @@
 namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
-  union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note 2{{candidate}}
-  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note 2{{candidate}}
+  union B { constexpr B() = default; int a; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'B' in 'B' class or struct}} expected-note 2{{candidate}}
+  union C { constexpr C() = default; int a, b; }; // expected-error {{default constructor cannot be 'constexpr' in a class or struct with virtual base classes}} expected-note {{see reference to function 'C' in 'C' class or struct}} expected-note 2{{candidate}}
   struct X { constexpr X() = default; union {}; }; // expected-error {{does not declare anything}}
-  struct Y { constexpr Y() = default; union { int a; }; 

[PATCH] D159137: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect

2023-08-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: w2yehia, MaskRay.
qiongsiwu1 added a project: clang.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added a subscriber: cfe-commits.

https://reviews.llvm.org/D157280 enabled `-fprofile-update` for 
`-fprofile-generate`, but omitted adding `-latomic` to the linker command on 
AIX. This omission causes linking to fail due to an undefined symbol. This 
patch fixes the link error.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159137

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/fprofile-update.c


Index: clang/test/Driver/fprofile-update.c
===
--- clang/test/Driver/fprofile-update.c
+++ clang/test/Driver/fprofile-update.c
@@ -12,3 +12,8 @@
 // RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s 
--check-prefix=ERROR
 
 // ERROR: error: unsupported argument 'unknown' to option '-fprofile-update='
+
+// AIX specific tests
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate 
-fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate 
-fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// AIX: "-latomic"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -429,11 +429,19 @@
 
 void AIX::addProfileRTLibs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const {
-  // Add linker option -u__llvm_profile_runtime to cause runtime
-  // initialization to occur.
-  if (needsProfileRT(Args))
+  if (needsProfileRT(Args)) {
+// Add linker option -u__llvm_profile_runtime to cause runtime
+// initialization to occur.
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-u", llvm::getInstrProfRuntimeHookVarName(;
+
+if (const auto *A = Args.getLastArg(options::OPT_fprofile_update_EQ)) {
+  StringRef Val = A->getValue();
+  if (Val == "atomic" || Val == "prefer-atomic")
+CmdArgs.push_back("-latomic");
+}
+  }
+
   ToolChain::addProfileRTLibs(Args, CmdArgs);
 }
 


Index: clang/test/Driver/fprofile-update.c
===
--- clang/test/Driver/fprofile-update.c
+++ clang/test/Driver/fprofile-update.c
@@ -12,3 +12,8 @@
 // RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s --check-prefix=ERROR
 
 // ERROR: error: unsupported argument 'unknown' to option '-fprofile-update='
+
+// AIX specific tests
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate -fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate -fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// AIX: "-latomic"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -429,11 +429,19 @@
 
 void AIX::addProfileRTLibs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const {
-  // Add linker option -u__llvm_profile_runtime to cause runtime
-  // initialization to occur.
-  if (needsProfileRT(Args))
+  if (needsProfileRT(Args)) {
+// Add linker option -u__llvm_profile_runtime to cause runtime
+// initialization to occur.
 CmdArgs.push_back(Args.MakeArgString(
 Twine("-u", llvm::getInstrProfRuntimeHookVarName(;
+
+if (const auto *A = Args.getLastArg(options::OPT_fprofile_update_EQ)) {
+  StringRef Val = A->getValue();
+  if (Val == "atomic" || Val == "prefer-atomic")
+CmdArgs.push_back("-latomic");
+}
+  }
+
   ToolChain::addProfileRTLibs(Args, CmdArgs);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0863051 - Reland "[clang-format] Annotate constructor/destructor names"

2023-08-29 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-29T13:14:52-07:00
New Revision: 0863051208870b284a1ee899defc0ba2b6e53fc4

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

LOG: Reland "[clang-format] Annotate constructor/destructor names"

(0e63f1aacc00 was reverted by 7590b7657004 due to a crash.)

Annotate constructor/destructor names as FunctionDeclarationName.

Fixes #63046.

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index b6b4172818d171..500dc34b2c240a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3097,6 +3097,76 @@ static unsigned maxNestingDepth(const AnnotatedLine 
) {
   return Result;
 }
 
+// Returns the name of a function with no return type, e.g. a constructor or
+// destructor.
+static FormatToken *getFunctionName(const AnnotatedLine ) {
+  for (FormatToken *Tok = Line.getFirstNonComment(), *Name = nullptr; Tok;
+   Tok = Tok->getNextNonComment()) {
+// Skip C++11 attributes both before and after the function name.
+if (Tok->is(tok::l_square) && Tok->is(TT_AttributeSquare)) {
+  Tok = Tok->MatchingParen;
+  if (!Tok)
+break;
+  continue;
+}
+
+// Make sure the name is followed by a pair of parentheses.
+if (Name)
+  return Tok->is(tok::l_paren) && Tok->MatchingParen ? Name : nullptr;
+
+// Skip keywords that may precede the constructor/destructor name.
+if (Tok->isOneOf(tok::kw_friend, tok::kw_inline, tok::kw_virtual,
+ tok::kw_constexpr, tok::kw_consteval, tok::kw_explicit)) {
+  continue;
+}
+
+// A qualified name may start from the global namespace.
+if (Tok->is(tok::coloncolon)) {
+  Tok = Tok->Next;
+  if (!Tok)
+break;
+}
+
+// Skip to the unqualified part of the name.
+while (Tok->startsSequence(tok::identifier, tok::coloncolon)) {
+  assert(Tok->Next);
+  Tok = Tok->Next->Next;
+  if (!Tok)
+return nullptr;
+}
+
+// Skip the `~` if a destructor name.
+if (Tok->is(tok::tilde)) {
+  Tok = Tok->Next;
+  if (!Tok)
+break;
+}
+
+// Make sure the name is not already annotated, e.g. as NamespaceMacro.
+if (Tok->isNot(tok::identifier) || Tok->isNot(TT_Unknown))
+  break;
+
+Name = Tok;
+  }
+
+  return nullptr;
+}
+
+// Checks if Tok is a constructor/destructor name qualified by its class name.
+static bool isCtorOrDtorName(const FormatToken *Tok) {
+  assert(Tok && Tok->is(tok::identifier));
+  const auto *Prev = Tok->Previous;
+
+  if (Prev && Prev->is(tok::tilde))
+Prev = Prev->Previous;
+
+  if (!Prev || !Prev->endsSequence(tok::coloncolon, tok::identifier))
+return false;
+
+  assert(Prev->Previous);
+  return Prev->Previous->TokenText == Tok->TokenText;
+}
+
 void TokenAnnotator::annotate(AnnotatedLine ) {
   for (auto  : Line.Children)
 annotate(*Child);
@@ -3117,6 +3187,14 @@ void TokenAnnotator::annotate(AnnotatedLine ) {
   ExpressionParser ExprParser(Style, Keywords, Line);
   ExprParser.parse();
 
+  if (Style.isCpp()) {
+auto *Tok = getFunctionName(Line);
+if (Tok && ((!Scopes.empty() && Scopes.back() == ST_Class) ||
+Line.endsWith(TT_FunctionLBrace) || isCtorOrDtorName(Tok))) {
+  Tok->setFinalizedType(TT_FunctionDeclarationName);
+}
+  }
+
   if (Line.startsWith(TT_ObjCMethodSpecifier))
 Line.Type = LT_ObjCMethodDecl;
   else if (Line.startsWith(TT_ObjCDecl))
@@ -3133,6 +3211,10 @@ void TokenAnnotator::annotate(AnnotatedLine ) {
 static bool isFunctionDeclarationName(bool IsCpp, const FormatToken ,
   const AnnotatedLine ) {
   assert(Current.Previous);
+
+  if (Current.is(TT_FunctionDeclarationName))
+return true;
+
   if (!Current.Tok.getIdentifierInfo())
 return false;
 
@@ -3313,9 +3395,11 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
   bool LineIsFunctionDeclaration = false;
   for (FormatToken *Tok = Current, *AfterLastAttribute = nullptr; Tok;
Tok = Tok->Next) {
+if (Tok->Previous->EndsCppAttributeGroup)
+  AfterLastAttribute = Tok;
 if (isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
   LineIsFunctionDeclaration = true;
-  Tok->setType(TT_FunctionDeclarationName);
+  Tok->setFinalizedType(TT_FunctionDeclarationName);
   if (AfterLastAttribute &&
   mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
 AfterLastAttribute->MustBreakBefore = true;
@@ -3323,8 +3407,6 @@ void 

[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-29 Thread Ying Yi via Phabricator via cfe-commits
MaggieYi added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:326
 def err_unsupported_abi_for_opt : Error<"'%0' can only be used with the '%1' 
ABI">;
+def err_unsupported_opt_for_execute_only_target
+: Error<"unsupported option '%0' for the execute only target '%1'">;

MaskRay wrote:
> MaggieYi wrote:
> > MaskRay wrote:
> > > We don't need this diagnostic as a common kind (we only use it in driver).
> > > 
> > > I think we can reuse `err_drv_argument_not_allowed_with` . Though for PS5 
> > > you will get `... allowed with '-mexecute-only'` even if the user doesn't 
> > > specify `-mexecute-only`, but I hope it is fine.
> > Since `err_drv_argument_not_allowed_with` is an ARM-only option, We cannot 
> > reuse it.
> `err_drv_argument_not_allowed_with` is a generic diagnostic. My point is that 
> we don't need an extra err_unsupported_opt_for_execute_only_target.
Sorry, I mean that `-mexecute-only` is the arm-only option 
[[https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L4202|Options.td#L4202]].

As you suggested that we could use `err_drv_argument_not_allowed_with` by 
passing `-fsanitize=function` (not `-mexecute-only`) and the target triple. For 
example, "error: invalid argument '-fsanitize=function' not allowed with 
'x86_64-sie-ps5'". I have removed `err_unsupported_opt_for_execute_only_target.`


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

https://reviews.llvm.org/D158614

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


[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-29 Thread Ying Yi via Phabricator via cfe-commits
MaggieYi updated this revision to Diff 554474.
MaggieYi marked 7 inline comments as done.
MaggieYi added a comment.

Thanks @MaskRay, I have updated the patch following your suggestions.


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

https://reviews.llvm.org/D158614

Files:
  clang/include/clang/Basic/Sanitizers.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sanitizers.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGenObjCXX/crash-function-type.mm
  clang/test/Driver/fsanitize.c

Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -970,3 +970,18 @@
 
 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=undefined,function -mcmodel=large %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-CODE-MODEL
 // CHECK-UBSAN-FUNCTION-CODE-MODEL: error: invalid argument '-fsanitize=function' only allowed with '-mcmodel=small'
+
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=undefined -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function -fsanitize=kcfi %s -### 2>&1 | FileCheck %s  --check-prefix=CHECK-UBSAN-KCFI --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: %clang --target=x86_64-sie-ps5 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+
+// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-UNDEFINED-NOT: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-UNDEFINED: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
Index: clang/test/CodeGenObjCXX/crash-function-type.mm
===
--- clang/test/CodeGenObjCXX/crash-function-type.mm
+++ clang/test/CodeGenObjCXX/crash-function-type.mm
@@ -1,3 +1,6 @@
+// Mark test as unsupported on PS5 due to PS5 doesn't support function sanitizer.
+// UNSUPPORTED: target=x86_64-sie-ps5
+
 // RUN: %clang_cc1 -fblocks -fsanitize=function -emit-llvm %s -o %t
 
 void g(void (^)());
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -37,6 +37,8 @@
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
 static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
+static const SanitizerMask NotAllowedWithExecuteOnly =
+SanitizerKind::Function | SanitizerKind::KCFI;
 static const SanitizerMask RequiresPIE =
 SanitizerKind::DataFlow | SanitizerKind::Scudo;
 static const SanitizerMask NeedsUnwindTables =
@@ -395,6 +397,22 @@
   DiagnosedKinds |= SanitizerKind::Function;
 }
   }
+  // -fsanitize=function and -fsanitize=kcfi instrument indirect function
+  // calls to load a type hash before the function label. Therefore, an
+  // execute-only target doesn't support the function and kcfi sanitizers.
+  const llvm::Triple  = TC.getTriple();
+  if (isExecuteOnlyTarget(Triple, Args)) {
+if (SanitizerMask KindsToDiagnose =
+Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
+  if (DiagnoseErrors) {
+std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< Desc << Triple.str();
+  }
+  DiagnosedKinds |= KindsToDiagnose;
+}
+Add &= ~NotAllowedWithExecuteOnly;
+  }
 
   // FIXME: Make CFI on member function calls compatible with cross-DSO CFI.
   // There are currently two problems:
@@ -457,6 +475,10 @@
   if 

[clang] 452cb7f - Reland "[clang-repl] Adapt to the recent dylib-related changes in ORC."

2023-08-29 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2023-08-29T19:42:58Z
New Revision: 452cb7f20bc7b976eb6fec4ac9f2d902f4175c08

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

LOG: Reland "[clang-repl] Adapt to the recent dylib-related changes in ORC."

Original commit message:"

ORC splits into separate dylibs symbols coming from the process and symbols
materialized in the Jit. This patch adapts intent of the existing interface and
adds a regression test to make sure both Jit'd and compiled symbols can be 
found.

Differential revision: https://reviews.llvm.org/D159115
"

This patch disables the test statement on windows as it seems we might have a
bug in the way we model dllimports.

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 3f8d60630de417..2c4dfc9a611e02 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -92,12 +92,19 @@ llvm::Error IncrementalExecutor::runCtors() const {
 llvm::Expected
 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;
+  using namespace llvm::orc;
+  auto SO = makeJITDylibSearchOrder({>getMainJITDylib(),
+ Jit->getPlatformJITDylib().get(),
+ Jit->getProcessSymbolsJITDylib().get()});
+
+  ExecutionSession  = Jit->getExecutionSession();
+
+  auto SymOrErr =
+  ES.lookup(SO, (NameKind == LinkerName) ? ES.intern(Name)
+ : Jit->mangleAndIntern(Name));
+  if (auto Err = SymOrErr.takeError())
+return std::move(Err);
+  return SymOrErr->getAddress();
 }
 
 } // end namespace clang

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 1800bff153b713..07fb0028779ba0 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -234,10 +234,20 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) {
   }
 
   std::string MangledName = MangleName(FD);
-  auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
-  EXPECT_NE(0U, Addr.getValue());
+  auto Addr = Interp->getSymbolAddress(MangledName);
+  EXPECT_FALSE(!Addr);
+  EXPECT_NE(0U, Addr->getValue());
   GlobalDecl GD(FD);
-  EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
+  EXPECT_EQ(*Addr, cantFail(Interp->getSymbolAddress(GD)));
+  cantFail(
+  Interp->ParseAndExecute("extern \"C\" int printf(const char*,...);"));
+  Addr = Interp->getSymbolAddress("printf");
+  EXPECT_FALSE(!Addr);
+
+  // FIXME: Re-enable when we investigate the way we handle dllimports on Win.
+#ifndef _WIN32
+  EXPECT_EQ((unsigned long long), Addr->getValue());
+#endif // _WIN32
 }
 
 static void *AllocateObject(TypeDecl *TD, Interpreter ) {



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


[PATCH] D158778: [CUDA] Propagate __float128 support from the host.

2023-08-29 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D158778#4626181 , @jhuber6 wrote:

> Just doing a simple example here https://godbolt.org/z/Y3E58PKMz shows that 
> for NVPTX we error out (as I would expect) but for AMDGPU we emit an x86 
> 80-bit double.

With this patch NVPTX will behave the same as AMDGPU and we'll no longer error 
out.

I think I may need to explicitly add a diagnostics for the case where the host 
idea of long double and __float128 does not match that of the target. It would 
have to be specific to OpenMP, as CUDA does expect this discrepancy for 
historic reasons.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158778

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


[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

2023-08-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D158872#4626095 , @aaron.ballman 
wrote:

> Out of curiosity, are you testing on Windows with MSVC? My understanding on 
> build time performance impacts was that it's debug builds with MSVC that get 
> hit especially hard. (I can test that setup but I could use some help 
> figuring out how you tested compile times so I can do a similar test instead 
> of something totally different from what you tried.)

I'm not :-( I don't have a windows machine, and the VM I used to have has 
bitrotted beyond repair (not sure how useful benchmarks from there would be 
anyway).

This is with clang on linux, just running `time clang-check-14 
include/clang/ASTMatchers/ASTMatchers.h` a few times.
The "deps only" test was `#if 0` ing out all the code in `ASTMatcher.h`, and 
commenting out the `ASTMatchers/*` includes, and repeating the same.
For object files I just added a dummy `ASTMatchers.cpp` with only `#include 
"clang/ASTMatchers/ASTMatchers.h"`.

I guess the equivalent of clang-check would be `/Zs`, not sure the best way to 
feed it the right flags...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158872

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


[PATCH] D61670: [clang] [MinGW] Add the option -fno-autoimport

2023-08-29 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D61670#4621724 , @aeubanks wrote:

> I don't have all the context here, but seems fine once the commit description 
> is updated with the new spelling

Thanks. Yeah I've updated the commit message locally (I wonder if the `arc` 
tool can resync the patch description? Although that's becoming irrelevant real 
soon now anyway.) I'll update the description here anyway, and I'll probably go 
ahead and push it in a few days if nobody else wants to comment on it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61670

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


[PATCH] D157963: [clang-format] Annotate constructor/destructor names

2023-08-29 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG086305120887: Reland [clang-format] Annotate 
constructor/destructor names (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157963

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1589,6 +1589,59 @@
   Tokens = annotate("void f [[noreturn]] () {}");
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: Foo(); };");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: ~Foo(); };");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("struct Foo { [[deprecated]] Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { ~Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] explicit Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { virtual [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::Foo() {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::~Foo() {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("#define FOO Foo::\n"
+"FOO Foo();");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16541,7 +16541,7 @@
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
-  verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
+  verifyFormat("A::A () : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
@@ -16566,7 +16566,7 @@
   // verifyFormat("T A::operator() () {}", SpaceFuncDef);
   verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
   verifyFormat("int x = int(y);", SpaceFuncDef);
-  verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
+  verifyFormat("M (std::size_t R, std::size_t C) : C(C), data(R) {}",
SpaceFuncDef);
 
   FormatStyle SpaceIfMacros = getLLVMStyle();
@@ -26246,18 +26246,18 @@
   FormatStyle Style = getLLVMStyle();
   EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Never);
 
-  const StringRef Code("[[nodiscard]] inline int f(int );\n"
-   "[[foo([[]])]] [[nodiscard]]\n"
-   "int g(int );\n"
-   "[[nodiscard]]\n"
-   "inline int f(int ) {\n"
-   "  i = 1;\n"
-   "  return 0;\n"
-   "}\n"
-   "[[foo([[]])]] [[nodiscard]] int g(int ) 

[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-08-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D158967#4626156 , @rsmith wrote:

> Adding another fallback in `ASTFrontendAction::ExecuteAction` seems OK to me 
> if that's an entry point that's commonly used by tools. (Where is that being 
> called from in clangd's case? Is there a higher point in the call stack where 
> we could put the call to `noteBottomOfStack` instead?)

clangd calls `FrontendAction::Execute()` (in `clangd::ParsedAST::build`, in 
`clang::PrecompiledPreamble::Build`, and in `clangd::BackgroundIndex::index`). 
I doubt we're the only one.
All of these run somewhere under `main()` or in a thread spawned by an 
`AsyncTaskRunner`.

So to me this fallback makes sense, but we should also add calls to those two 
places so we really get the bottom of the stack.

(If noteBottomOfStack() were part of llvm support, then this could be built 
into llvm::Thread...)




Comment at: clang-tools-extra/clangd/tool/Check.cpp:445
const ClangdLSPServer::Options ) {
+  clang::noteBottomOfStack();
   std::optional LineRange;

I like the idea that we only parse on the main thread with `-check`, but it's 
not quite true: we also do this with `-sync`. I think this should go in main() 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

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


[clang] ca0aa53 - [clang-format] Handle Template Arguments with AlignConsecutiveXX

2023-08-29 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2023-08-29T21:59:44+02:00
New Revision: ca0aa533656ceb806d2744c38766f70c317f1053

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

LOG: [clang-format] Handle Template Arguments with AlignConsecutiveXX

This fixes https://github.com/llvm/llvm-project/issues/64928.

Differential-Revision: https://reviews.llvm.org/D158945

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 04048aedb3e392..6951c2a113a923 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -425,6 +425,10 @@ AlignTokenSequence(const FormatStyle , unsigned 
Start, unsigned End,
   return true;
 }
 
+// Continued template parameter.
+if (Changes[ScopeStart - 1].Tok->is(TT_TemplateOpener))
+  return true;
+
 return false;
   };
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c1368c947af1ef..0d8bc41265199b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18726,6 +18726,13 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
"{a_longer_name_for_wrap,\n"
" a_longer_name_for_wrap}};",
Alignment);
+
+  Alignment.ColumnLimit = 60;
+  verifyFormat("using II = typename TI>::I;\n"
+   "using I  = std::conditional_t= 0,\n"
+   "  std::ic,\n"
+   "  std::ic>;",
+   Alignment);
 }
 
 TEST_F(FormatTest, AlignConsecutiveBitFields) {



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


[PATCH] D152752: [MS] Fix passing aligned records by value in some cases

2023-08-29 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a subscriber: mstorsjo.
rnk added a comment.

I need to get to it, my recollection is that @mstorsjo ran into the same issue 
here for mingw and made some changes, I wanted to go dig those up as a starting 
point. I may have completely forgotten things though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152752

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


[PATCH] D148381: [WIP][Clang] Add counted_by attribute

2023-08-29 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Jumping a bit late in the thread, apologize in advance if I missed something.

The GCC version of the attributes seems to be `element_count` (as found in the 
link https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 mentionned by @kees) I 
guess we could align (I personally prefer the GCC name, FWIW)

I may be wrong , but it seems to me that there is nothing specific to FAM 
there, and this would work as well for

  struct foo {
size_t num_elements;
 // ...
struct bar ** data __attribute__((counted_by(num_elements)));
  };
  
  struct foo make_foo(size_t num_elements) {
  struct foo f;
f.data = malloc(num_elements *
   sizeof(struct bar *));
  
f.num_elements = num_elements;
return f;
  }

Which makes us very close to:

  void stuff(int n, int *data __attribute__((counted_by(n {
  for(int i = 0; i < n; ++i)
other_stuff(data[i]);
  }

which is very close to VLA, right?




Comment at: clang/lib/AST/Expr.cpp:286
-
-  return false;
 }

I really like this cleanup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-08-29 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

I'll apply this patch and debug the issue today.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159126

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


[PATCH] D158869: [clang] Fix timing of propagation of MSInheritanceAttr for template instantiation declarations.

2023-08-29 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp:958
+extern template class a;
+template class a;
+}

tahonermann wrote:
> rnk wrote:
> > My expectation here is that we assign the unknown inheritance model to 
> > `a`, is that right? Can you add a static_assert to that effect, or add 
> > some CHECK lines for the structure,  maybe make an alloca of type `void 
> > (a::*var)()`  and check for the allocated type (it should be a struct 
> > with a pointer with lots of i32s)?
> Yes, when a pointer to member is formed for an incomplete class, in the 
> absence of a `#pragma pointers_to_members` directive, use of inheritance 
> keywords like `__single_inheritance`, or use of the `/vmb` or `/vmg` options 
> (or equivalents), the "full_generality" / "virtual_inheritance" model is 
> selected. I did verify that manually.
> 
> I can add a `static_assert` so long as it follows the explicit template 
> instantiation definition. If it is placed earlier, then code related to 
> obtaining a complete type is run and that ends up avoiding the assertion 
> failure. See https://godbolt.org/z/qzTTfdfY1. This might indicate there is a 
> bug elsewhere; I find it surprising that the early `static_assert` has that 
> effect.
Got it, that makes sense. It's really just anything to document the requirement 
that we expect to get the most general member pointer representation from this 
code (notwithstanding global member pointer settings).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158869

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


[PATCH] D155858: Add a concept AST node.

2023-08-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

OK, so I learned a bit about initializeLocal/trivial TypeSourceInfo. Mostly 
things I didn't want to know :-)
TL;DR I think the current version of the patch is right.

The crash is caused by:

1. `CheckTemplateArgument` calls `SubstType` without passing a `TypeLoc`, which 
synthesizes a trivial `TypeSourceInfo` to instantiate
2. the trivial `TypeSourceInfo` never has a `ConceptReference`
3. instantiating an `AutoTypeLoc` where the type is constrained but there's no 
`ConceptReference` is not supported

We can choose to address any of these.

Fixing #1 is tempting: the SubstType overload with no TypeLoc is deprecated and 
calling it ~always loses information. Cleaning up this call is an improvement, 
but there are ~15 calls to this overload, and probably more places that use 
trivial TypeSourceInfo.
So this is nice to have, but I think leaves us with an AST that will still 
crash in other cases. Consumers will not expect an AutoTypeLoc where the type 
is constrained but the loc isn't, and it's hard to know how to handle this case.

Fixing #2 is what this patch currently does. It also seems to be the pattern 
used by other types (their initializeLocal methods conditionally initialize 
structure based on the underlying type). The only possible downside is because 
we store the ConceptReference subobject by pointer and support replacement but 
not mutation, if the caller calls initializeLocal and then fills in with real 
data we'll waste the original ConceptReference object. Still, I don't think 
this is how non-trivial TSIs are generally created, and I think this is the way 
to go.

Fixing #3 is the previous version of the patch, again it leaves us with a 
bug-prone AST and some extra complexity.




Comment at: clang/include/clang/AST/ASTConcept.h:183
+if (auto QualifierLoc = getNestedNameSpecifierLoc())
+  return QualifierLoc.getBeginLoc();
+return getConceptNameInfo().getBeginLoc();

if the qualifier is null the template KW must also be null
so this is correct, you may or may not want a comment for that! up to you



Comment at: clang/include/clang/AST/ASTConcept.h:188
+  SourceLocation getEndLoc() const LLVM_READONLY {
+return getTemplateArgsAsWritten()->getRAngleLoc().isValid()
+   ? getTemplateArgsAsWritten()->getRAngleLoc()

getTemplateArgsAsWritten() is nullable, right?



Comment at: clang/include/clang/AST/ASTConcept.h:215
+
+  void print(llvm::raw_ostream , PrintingPolicy Policy) const;
 };

nit: printingpolicy by const ref, I think
(we're not totally consistent, but I think ref is more common)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155858

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


[PATCH] D158778: [CUDA] Propagate __float128 support from the host.

2023-08-29 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D158778#4625892 , @tra wrote:

> In D158778#4624408 , @ABataev wrote:
>
>> Just checks removal should be fine
>
> Looks like OpenMP handles long double and __float128 differently -- it always 
> insists on using the host's FP format for both.
> https://github.com/llvm/llvm-project/blob/d037445f3a2c6dc1842b5bfc1d5d81988c2f223d/clang/lib/AST/ASTContext.cpp#L1674
>
> This creates a divergence between what clang thinks and what LLVM can handle.
> I'm not quite sure how it's supposed to work with NVPTX or AMDGPU, where we 
> demote those types to double and can't generate code for the actual types.
>
> @jhuber6 what does OpenMP expect to happen for those types on the GPU side?

That's a good question, I'm not entirely sure what the expectation would be. We 
obviously need to keep things coherent across D2H and H2D memcpy's so we want 
them to be the same size. I'm pretty sure our handling of this is just wrong 
right now. Just doing a simple example here https://godbolt.org/z/Y3E58PKMz 
shows that for NVPTX we error out (as I would expect) but for AMDGPU we emit an 
x86 80-bit double. My guess is that we should make this more explicit, 
considering that both vendors explicitly state that quad precision is not 
available on the GPU, unless we want to implement some software floats.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158778

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


[PATCH] D153907: [AIX] [TOC] Add -mtocdata/-mno-tocdata options on AIX

2023-08-29 Thread Zaara Syeda via Phabricator via cfe-commits
syzaara updated this revision to Diff 554461.

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

https://reviews.llvm.org/D153907

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/CodeGen/PowerPC/toc-data-attribute.c
  clang/test/CodeGen/PowerPC/toc-data-attribute.cpp
  clang/test/CodeGen/PowerPC/toc-data-diagnostics.c
  clang/test/CodeGen/PowerPC/toc-data-structs-arrays.cpp
  clang/test/CodeGen/toc-data.c
  clang/test/Driver/toc-conf.c
  clang/test/Driver/tocdata-cc1.c
  llvm/include/llvm/ADT/STLExtras.h
  llvm/lib/MC/MCSectionXCOFF.cpp
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/test/CodeGen/PowerPC/toc-data-large-array.ll
  llvm/test/CodeGen/PowerPC/toc-data-struct-array.ll

Index: llvm/test/CodeGen/PowerPC/toc-data-struct-array.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/toc-data-struct-array.ll
@@ -0,0 +1,29 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK
+
+%struct.small_struct = type { i16 }
+
+@a = global %struct.small_struct zeroinitializer, align 2 #0
+@b = global [2 x i16] zeroinitializer, align 2 #0
+
+; Function Attrs: noinline
+define i16 @foo() #1 {
+entry:
+  %0 = load i16, ptr @a, align 2
+  %1 = load i16, ptr @b, align 2
+  %add = add nsw i16 %0, %1
+  ret i16 %add
+}
+
+attributes #0 = { "toc-data" }
+attributes #1 = { noinline }
+
+; CHECK:  .toc
+; CHECK-NEXT: .csect a[TD],2
+; CHECK-NEXT: .globla[TD]   # @a
+; CHECK-NEXT: .align1
+; CHECK-NEXT: .space2
+; CHECK-NEXT: .csect b[TD],2
+; CHECK-NEXT: .globlb[TD]   # @b
+; CHECK-NEXT: .align1
+; CHECK-NEXT: .space4
Index: llvm/test/CodeGen/PowerPC/toc-data-large-array.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/toc-data-large-array.ll
@@ -0,0 +1,16 @@
+; RUN: not --crash llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s --check-prefix CHECK-ERROR
+; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s --check-prefix CHECK-ERROR
+
+@a = global [5 x i16] zeroinitializer, align 2 #0
+
+; Function Attrs: noinline
+define i16 @foo() #1 {
+entry:
+  %0 = load i16, ptr @a, align 2
+  ret i16 %0
+}
+
+attributes #0 = { "toc-data" }
+attributes #1 = { noinline }
+
+; CHECK-ERROR: LLVM ERROR: A GlobalVariable with size larger than a TOC entry is not currently supported by the toc data transformation.
Index: llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -533,21 +533,11 @@
   assert(GVType->isSized() && "A GlobalVariable's size must be known to be "
   "supported by the toc data transformation.");
 
-  if (GVType->isVectorTy())
-report_fatal_error("A GlobalVariable of Vector type is not currently "
-   "supported by the toc data transformation.");
-
-  if (GVType->isArrayTy())
-report_fatal_error("A GlobalVariable of Array type is not currently "
-   "supported by the toc data transformation.");
-
-  if (GVType->isStructTy())
-report_fatal_error("A GlobalVariable of Struct type is not currently "
-   "supported by the toc data transformation.");
-
-  assert(GVType->getPrimitiveSizeInBits() <= PointerSize * 8 &&
- "A GlobalVariable with size larger than a TOC entry is not currently "
- "supported by the toc data transformation.");
+  if (GV->getParent()->getDataLayout().getTypeSizeInBits(GVType) >
+  PointerSize * 8)
+report_fatal_error(
+"A GlobalVariable with size larger than a TOC entry is not currently "
+"supported by the toc data transformation.");
 
   if (GV->hasLocalLinkage() || GV->hasPrivateLinkage())
 report_fatal_error("A GlobalVariable with private or local linkage is not "
Index: llvm/lib/MC/MCSectionXCOFF.cpp
===
--- llvm/lib/MC/MCSectionXCOFF.cpp
+++ llvm/lib/MC/MCSectionXCOFF.cpp
@@ -82,8 +82,7 @@
   }
 
   if (isCsect() && getMappingClass() == XCOFF::XMC_TD) {
-assert((getKind().isBSSExtern() || getKind().isBSSLocal()) &&
-   "Unexepected section kind for toc-data");
+assert(getKind().isBSS() && "Unexepected section kind for toc-data");
 printCsectDirective(OS);
 return;
   }
Index: llvm/include/llvm/ADT/STLExtras.h

[clang] e6cd950 - Revert "[clang-repl] Adapt to the recent dylib-related changes in ORC."

2023-08-29 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2023-08-29T19:34:20Z
New Revision: e6cd950d1b4a07f8c339b6f55374e4aa229e42f7

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

LOG: Revert "[clang-repl] Adapt to the recent dylib-related changes in ORC."

This reverts commit 196d8569d46dc5200c44e70cdf839b042148b988 while investigating
bot failure: https://lab.llvm.org/buildbot/#/builders/216/builds/26444

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 2c4dfc9a611e02..3f8d60630de417 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -92,19 +92,12 @@ llvm::Error IncrementalExecutor::runCtors() const {
 llvm::Expected
 IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
   SymbolNameKind NameKind) const {
-  using namespace llvm::orc;
-  auto SO = makeJITDylibSearchOrder({>getMainJITDylib(),
- Jit->getPlatformJITDylib().get(),
- Jit->getProcessSymbolsJITDylib().get()});
-
-  ExecutionSession  = Jit->getExecutionSession();
-
-  auto SymOrErr =
-  ES.lookup(SO, (NameKind == LinkerName) ? ES.intern(Name)
- : Jit->mangleAndIntern(Name));
-  if (auto Err = SymOrErr.takeError())
-return std::move(Err);
-  return SymOrErr->getAddress();
+  auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
+  : Jit->lookup(Name);
+
+  if (!Sym)
+return Sym.takeError();
+  return Sym;
 }
 
 } // end namespace clang

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 0f546d275f82f1..1800bff153b713 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -234,16 +234,10 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) {
   }
 
   std::string MangledName = MangleName(FD);
-  auto Addr = Interp->getSymbolAddress(MangledName);
-  EXPECT_FALSE(!Addr);
-  EXPECT_NE(0U, Addr->getValue());
+  auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
+  EXPECT_NE(0U, Addr.getValue());
   GlobalDecl GD(FD);
-  EXPECT_EQ(*Addr, cantFail(Interp->getSymbolAddress(GD)));
-  cantFail(
-  Interp->ParseAndExecute("extern \"C\" int printf(const char*,...);"));
-  Addr = Interp->getSymbolAddress("printf");
-  EXPECT_FALSE(!Addr);
-  EXPECT_EQ((unsigned long long), Addr->getValue());
+  EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
 }
 
 static void *AllocateObject(TypeDecl *TD, Interpreter ) {



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


[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-08-29 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D158967#4621361 , @zyounan wrote:

>> Currently the code in CompilerInstance::ExecuteAction seems to acknowledge 
>> that there should be a fallback. I'm suggesting to move this fallback down 
>> to a function that actually runs parsing.
>
> One thing I'm afraid of is, that there are/were some compatible reasons that 
> made us decide not to insert this call at `ASTFrontendAction::ExecuteAction` 
> nor `clang::ParseAST`. (I didn't see the explanation in D66361 
> . Richard, could you kindly explain why? 
> @rsmith)

D66361  wasn't intended to cover all possible 
uses by itself. The recovery from deep recursion is best-effort, and it was 
expected that some tools that call into Clang in less common ways would need to 
manually call `noteBottomOfStack` if they wanted to enable this recovery. I put 
the fallback call in `CompilerInstance::ExecuteAction` because I thought it 
would do the right thing in most cases, and not require any effort for most 
tools. Adding another fallback in `ASTFrontendAction::ExecuteAction` seems OK 
to me if that's an entry point that's commonly used by tools. (Where is that 
being called from in clangd's case? Is there a higher point in the call stack 
where we could put the call to `noteBottomOfStack` instead?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

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


[PATCH] D157118: [NFC][Clang] Fix static analyzer concerns

2023-08-29 Thread Elizabeth Andrews 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 rG39191c457715: [NFC][Clang] Fix static analyzer concerns 
(authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157118

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Analysis/PathDiagnostic.cpp


Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@
 PathDiagnosticLocation::createBegin(const Stmt *S,
 const SourceManager ,
 LocationOrAnalysisDeclContext LAC) {
+  assert(S && "Statement cannot be null");
   return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
 SM, SingleLocK);
 }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;
   PrintFPPragmas(Node);
   for (auto *I : Node->body())
@@ -599,8 +600,10 @@
 
   if (auto *FS = static_cast(Node->getFinallyStmt())) {
 Indent() << "@finally";
-PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody()));
-OS << NL;
+if (auto *CS = dyn_cast(FS->getFinallyBody())) {
+  PrintRawCompoundStmt(CS);
+  OS << NL;
+}
   }
 }
 
@@ -635,7 +638,7 @@
 
 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
   Indent() << "@autoreleasepool";
-  PrintRawCompoundStmt(dyn_cast(Node->getSubStmt()));
+  PrintRawCompoundStmt(cast(Node->getSubStmt()));
   OS << NL;
 }
 


Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@
 PathDiagnosticLocation::createBegin(const Stmt *S,
 const SourceManager ,
 LocationOrAnalysisDeclContext LAC) {
+  assert(S && "Statement cannot be null");
   return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
 SM, SingleLocK);
 }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;
   PrintFPPragmas(Node);
   for (auto *I : Node->body())
@@ -599,8 +600,10 @@
 
   if (auto *FS = static_cast(Node->getFinallyStmt())) {
 Indent() << "@finally";
-PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody()));
-OS << NL;
+if (auto *CS = dyn_cast(FS->getFinallyBody())) {
+  PrintRawCompoundStmt(CS);
+  OS << NL;
+}
   }
 }
 
@@ -635,7 +638,7 @@
 
 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
   Indent() << "@autoreleasepool";
-  PrintRawCompoundStmt(dyn_cast(Node->getSubStmt()));
+  PrintRawCompoundStmt(cast(Node->getSubStmt()));
   OS << NL;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 39191c4 - [NFC][Clang] Fix static analyzer concerns

2023-08-29 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-29T12:23:26-07:00
New Revision: 39191c45771564b8a0930d71b4c229147cf839db

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

LOG: [NFC][Clang] Fix static analyzer concerns

Fix static analyzer concerns about dereferencing null values.

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

Added: 


Modified: 
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/PathDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 20e0e5d9cdf59f..a31aa0cfeeed8d 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@ namespace {
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;
   PrintFPPragmas(Node);
   for (auto *I : Node->body())
@@ -599,8 +600,10 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
 
   if (auto *FS = static_cast(Node->getFinallyStmt())) {
 Indent() << "@finally";
-PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody()));
-OS << NL;
+if (auto *CS = dyn_cast(FS->getFinallyBody())) {
+  PrintRawCompoundStmt(CS);
+  OS << NL;
+}
   }
 }
 
@@ -635,7 +638,7 @@ void 
StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
 
 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
   Indent() << "@autoreleasepool";
-  PrintRawCompoundStmt(dyn_cast(Node->getSubStmt()));
+  PrintRawCompoundStmt(cast(Node->getSubStmt()));
   OS << NL;
 }
 

diff  --git a/clang/lib/Analysis/PathDiagnostic.cpp 
b/clang/lib/Analysis/PathDiagnostic.cpp
index ac1306fd80711b..93e6d98492ddef 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@ PathDiagnosticLocation
 PathDiagnosticLocation::createBegin(const Stmt *S,
 const SourceManager ,
 LocationOrAnalysisDeclContext LAC) {
+  assert(S && "Statement cannot be null");
   return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
 SM, SingleLocK);
 }



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


[clang] 196d856 - [clang-repl] Adapt to the recent dylib-related changes in ORC.

2023-08-29 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2023-08-29T19:17:18Z
New Revision: 196d8569d46dc5200c44e70cdf839b042148b988

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

LOG: [clang-repl] Adapt to the recent dylib-related changes in ORC.

ORC splits into separate dylibs symbols coming from the process and symbols
materialized in the Jit. This patch adapts intent of the existing interface and
adds a regression test to make sure both Jit'd and compiled symbols can be 
found.

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

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 3f8d60630de417..2c4dfc9a611e02 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -92,12 +92,19 @@ llvm::Error IncrementalExecutor::runCtors() const {
 llvm::Expected
 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;
+  using namespace llvm::orc;
+  auto SO = makeJITDylibSearchOrder({>getMainJITDylib(),
+ Jit->getPlatformJITDylib().get(),
+ Jit->getProcessSymbolsJITDylib().get()});
+
+  ExecutionSession  = Jit->getExecutionSession();
+
+  auto SymOrErr =
+  ES.lookup(SO, (NameKind == LinkerName) ? ES.intern(Name)
+ : Jit->mangleAndIntern(Name));
+  if (auto Err = SymOrErr.takeError())
+return std::move(Err);
+  return SymOrErr->getAddress();
 }
 
 } // end namespace clang

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 1800bff153b713..0f546d275f82f1 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -234,10 +234,16 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) {
   }
 
   std::string MangledName = MangleName(FD);
-  auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
-  EXPECT_NE(0U, Addr.getValue());
+  auto Addr = Interp->getSymbolAddress(MangledName);
+  EXPECT_FALSE(!Addr);
+  EXPECT_NE(0U, Addr->getValue());
   GlobalDecl GD(FD);
-  EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
+  EXPECT_EQ(*Addr, cantFail(Interp->getSymbolAddress(GD)));
+  cantFail(
+  Interp->ParseAndExecute("extern \"C\" int printf(const char*,...);"));
+  Addr = Interp->getSymbolAddress("printf");
+  EXPECT_FALSE(!Addr);
+  EXPECT_EQ((unsigned long long), Addr->getValue());
 }
 
 static void *AllocateObject(TypeDecl *TD, Interpreter ) {



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


  1   2   3   >