[PATCH] D157029: [llvm] Construct option's prefixed name at compile-time

2023-08-04 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

This increases the size of  `Info` (static data size and static relocations). 
In return, some dynamic relocations are saved. Is this a net win?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157029

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


[PATCH] D157029: [llvm] Construct option's prefixed name at compile-time

2023-08-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: llvm/include/llvm/Option/Option.h:103
 
+  StringLiteral getSpelling() const {
+assert(Info && "Must have a valid info!");

benlangmuir wrote:
> This could use a doc comment to differentiate it from other string 
> representations.
> 
> How does this compare with `Arg::getSpelling`? With `Arg`, IIUC the 
> "spelling" is how it was actually written rather than a canonical form.  That 
> might be confusing if this one is canonical; so we should at least clearly 
> document it or maybe put "canonical" in the API name?
You're right `Arg::getSpelling()` is the as-written prefix and name, while 
`Option::getSpelling()` was the canonical prefix and name. I noticed there's 
also `Option::getPrefixedName()` which used to return `std::string`. I decided 
to reuse that and return `StringLiteral` instead. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157029

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


[PATCH] D157029: [llvm] Construct option spelling at compile-time

2023-08-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 547298.
jansvoboda11 added a comment.

Improve `Option::getPrefixedName()` instead of introducing new 
`Option::getSpelling()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157029

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Tooling/Tooling.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -105,8 +105,6 @@
   }
 
   void emit(raw_ostream ) const {
-write_cstring(OS, StringRef(getOptionSpelling(R)));
-OS << ", ";
 OS << ShouldParse;
 OS << ", ";
 OS << ShouldAlwaysEmit;
@@ -306,6 +304,9 @@
 // The option string.
 OS << ", \"" << R.getValueAsString("Name") << '"';
 
+// The option spelling.
+OS << ", \"" << R.getValueAsString("Name") << '"';
+
 // The option identifier name.
 OS << ", " << getOptionName(R);
 
@@ -349,6 +350,11 @@
 // The option string.
 emitNameUsingSpelling(OS, R);
 
+// The option spelling.
+OS << ", llvm::StringLiteral(";
+write_cstring(OS, getOptionSpelling(R));
+OS << ")";
+
 // The option identifier name.
 OS << ", " << getOptionName(R);
 
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -529,7 +529,7 @@
 
 static std::string getOptionHelpName(const OptTable , OptSpecifier Id) {
   const Option O = Opts.getOption(Id);
-  std::string Name = O.getPrefixedName();
+  std::string Name = O.getPrefixedName().str();
 
   // Add metavar, if used.
   switch (O.getKind()) {
Index: llvm/include/llvm/Option/Option.h
===
--- llvm/include/llvm/Option/Option.h
+++ llvm/include/llvm/Option/Option.h
@@ -130,10 +130,9 @@
   }
 
   /// Get the name of this option with the default prefix.
-  std::string getPrefixedName() const {
-std::string Ret(getPrefix());
-Ret += getName();
-return Ret;
+  StringLiteral getPrefixedName() const {
+assert(Info && "Must have a valid info!");
+return Info->PrefixedName;
   }
 
   /// Get the help text for this option.
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,9 @@
 /// A null terminated array of prefix strings to apply to name while
 /// matching.
 ArrayRef Prefixes;
+// TODO: Compute this from PrefixedName.
 StringRef Name;
+StringLiteral PrefixedName;
 const char *HelpText;
 const char *MetaVar;
 unsigned ID;
@@ -298,31 +300,31 @@
 
 } // end namespace llvm
 
-#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(ID_PREFIX, PREFIX, NAME, ID, KIND, \
-GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-HELPTEXT, METAVAR, VALUES) \
+#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(   \
+ID_PREFIX, PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
+FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)   \
   ID_PREFIX##ID
 
-#define LLVM_MAKE_OPT_ID(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS,  \
- FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)  \
-  LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, NAME, ID, KIND, GROUP, ALIAS,  \
-  ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR,  \
-  VALUE)
+#define LLVM_MAKE_OPT_ID(PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS,  \
+ ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)   \
+  LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, NAME, PREFIXED_NAME, ID, KIND, \
+  GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,   \
+  HELPTEXT, METAVAR, VALUE)
 
 #define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX(\
-ID_PREFIX, PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-HELPTEXT, METAVAR, VALUES) \
+ID_PREFIX, PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
+FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)   \
   llvm::opt::OptTable::Info {  \
-PREFIX, NAME, HELPTEXT, METAVAR, ID_PREFIX##ID,

[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2023-08-04 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 547297.
saiislam added a comment.

Another attempt at cov5 support by using CodeGen for 
buitlin_amdgpu_workgroup_size.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/Driver/ToolChain.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h

Index: openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
===
--- openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
+++ openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
@@ -25,6 +25,7 @@
 #include "llvm/Support/MemoryBufferRef.h"
 
 #include "llvm/Support/YAMLTraits.h"
+using namespace llvm::ELF;
 
 namespace llvm {
 namespace omp {
@@ -32,19 +33,55 @@
 namespace plugin {
 namespace utils {
 
-// The implicit arguments of AMDGPU kernels.
-struct AMDGPUImplicitArgsTy {
-  uint64_t OffsetX;
-  uint64_t OffsetY;
-  uint64_t OffsetZ;
-  uint64_t HostcallPtr;
-  uint64_t Unused0;
-  uint64_t Unused1;
-  uint64_t Unused2;
+enum IMPLICITARGS : uint32_t {
+  COV4_SIZE = 56,
+  COV4_HOSTCALL_PTR_OFFSET = 24,
+  HOSTCALL_PTR_SIZE = 8,
+
+  COV5_SIZE = 256,
+
+  COV5_BLOCK_COUNT_X_OFFSET = 0,
+  COV5_BLOCK_COUNT_X_SIZE = 4,
+
+  COV5_BLOCK_COUNT_Y_OFFSET = 4,
+  COV5_BLOCK_COUNT_Y_SIZE = 4,
+
+  COV5_BLOCK_COUNT_Z_OFFSET = 8,
+  COV5_BLOCK_COUNT_Z_SIZE = 4,
+
+  COV5_GROUP_SIZE_X_OFFSET = 12,
+  COV5_GROUP_SIZE_X_SIZE = 2,
+
+  COV5_GROUP_SIZE_Y_OFFSET = 14,
+  COV5_GROUP_SIZE_Y_SIZE = 2,
+
+  COV5_GROUP_SIZE_Z_OFFSET = 16,
+  COV5_GROUP_SIZE_Z_SIZE = 2,
+
+  COV5_REMAINDER_X_OFFSET = 18,
+  COV5_REMAINDER_X_SIZE = 2,
+
+  COV5_REMAINDER_Y_OFFSET = 20,
+  COV5_REMAINDER_Y_SIZE = 2,
+
+  COV5_REMAINDER_Z_OFFSET = 22,
+  COV5_REMAINDER_Z_SIZE = 2,
+
+  COV5_GRID_DIMS_OFFSET = 64,
+  COV5_GRID_DIMS_SIZE = 2,
+
+  COV5_HOSTCALL_PTR_OFFSET = 80,
+
+  COV5_HEAPV1_PTR_OFFSET = 96,
+  COV5_HEAPV1_PTR_SIZE = 8,
+
+  // 128 KB
+  PER_DEVICE_PREALLOC_SIZE = 131072
 };
 
-static_assert(sizeof(AMDGPUImplicitArgsTy) == 56,
-  "Unexpected size of implicit arguments");
+uint16_t getImplicitArgsSize(uint16_t Version) {
+  return Version < ELF::ELFABIVERSION_AMDGPU_HSA_V5 ? 56 : 256;
+}
 
 /// Parse a TargetID to get processor arch and feature map.
 /// Returns processor subarch.
@@ -295,7 +332,8 @@
 /// Reads the AMDGPU specific metadata from the ELF file and propagates the
 /// KernelInfoMap
 Error readAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer,
-  StringMap ) {
+  StringMap ,
+  uint16_t ) {
   Error Err = Error::success(); // Used later as out-parameter
 
   auto ELFOrError = object::ELF64LEFile::create(MemBuffer.getBuffer());
@@ -305,6 +343,12 @@
   const object::ELF64LEFile ELFObj = ELFOrError.get();
   ArrayRef Sections = cantFail(ELFObj.sections());
   KernelInfoReader Reader(KernelInfoMap);
+
+  // Read the code object version from ELF image header
+  auto Header = ELFObj.getHeader();
+  ELFABIVersion = (uint8_t)(Header.e_ident[ELF::EI_ABIVERSION]);
+  DP("ELFABIVERSION Version: %u\n", ELFABIVersion);
+
   for (const auto  : Sections) {
 if (S.sh_type != ELF::SHT_NOTE)
   continue;
Index: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -253,6 +253,13 @@
 return Plugin::check(Status, "Error in hsa_amd_agents_allow_access: %s");
   }
 
+  Error zeroInitializeMemory(void *Ptr, size_t Size) {
+uint64_t Rounded = sizeof(uint32_t) * ((Size + 3) / sizeof(uint32_t));
+hsa_status_t Status =
+hsa_amd_memory_fill(Ptr, 0, Rounded / sizeof(uint32_t));
+return Plugin::check(Status, "Error in hsa_amd_memory_fill: %s");
+  }
+
   /// Get attribute from the memory pool.
   template 
   Error getAttr(hsa_amd_memory_pool_info_t Kind, Ty ) const {
@@ -381,6 +388,9 @@
   /// Get the executable.
   hsa_executable_t getExecutable() const { return Executable; }
 
+  /// Get to Code Object Version of the ELF
+  uint16_t getELFABIVersion() const { return ELFABIVersion; }
+
   /// Find an HSA device symbol by its name on the executable.
   Expected
   findDeviceSymbol(GenericDeviceTy , StringRef SymbolName) const;
@@ -401,6 +411,7 @@
   hsa_executable_t Executable;
   hsa_code_object_t CodeObject;
   StringMap KernelInfoMap;
+  uint16_t ELFABIVersion;
 };
 
 /// Class implementing the AMDGPU kernel functionalities which derives from 

[PATCH] D156928: [Clang][AMDGPU] Fix handling of -mcode-object-version=none arg

2023-08-04 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam marked 2 inline comments as done.
saiislam added a comment.

In D156928#4555121 , @yaxunl wrote:

> `-mcode-object-version=none` was intentionally designed to work with `clang 
> -cc1` only, since it does not work with clang driver if users link with 
> device library. Device library can still use it by  using it with `-Xclang`.

Thanks for the tip @yaxunl . I will abandon this revision and use Xclang for 
passing cov_none to devicertl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156928

___
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-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM though there may be some additional changes worth considering; I don't 
insist on changes though.




Comment at: clang/lib/AST/StmtPrinter.cpp:178
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;

Hmmm, I think this is what we're effectively already hoping is the case today, 
but I don't think that's a safe assertion by itself. Consider: 
https://github.com/llvm/llvm-project/blob/cd29ebb862b5c7a81c9f39c8c493f9246d6e5f0b/clang/lib/AST/StmtPrinter.cpp#L602

It might be worth looking at all the calls to `PrintRawCompoundStmt()` to see 
which ones potentially can pass null in, and decide if there are additional 
changes to make. e.g., should that `dyn_cast` be a `cast` instead so it cannot 
return nullptr and we get the assertion a little bit earlier when calling 
`cast<>`?


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

https://reviews.llvm.org/D157118

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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

missed one more: 3d756c32cdf005d0f4c05f561fec4a37b64b7ddd 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

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


[PATCH] D157029: [llvm] Construct option spelling at compile-time

2023-08-04 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: llvm/include/llvm/Option/Option.h:103
 
+  StringLiteral getSpelling() const {
+assert(Info && "Must have a valid info!");

This could use a doc comment to differentiate it from other string 
representations.

How does this compare with `Arg::getSpelling`? With `Arg`, IIUC the "spelling" 
is how it was actually written rather than a canonical form.  That might be 
confusing if this one is canonical; so we should at least clearly document it 
or maybe put "canonical" in the API name?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157029

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


[clang] 3d756c3 - cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs via cfe-commits

Author: Jon Roelofs
Date: 2023-08-04T10:43:31-07:00
New Revision: 3d756c32cdf005d0f4c05f561fec4a37b64b7ddd

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

LOG: cmake: add missing dependencies on ClangDriverOptions tablegen

This is a follow-up to 2fb1c1082c01

Added: 


Modified: 
clang/lib/ARCMigrate/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/ARCMigrate/CMakeLists.txt 
b/clang/lib/ARCMigrate/CMakeLists.txt
index e2e13e5700a554..515d0960920afc 100644
--- a/clang/lib/ARCMigrate/CMakeLists.txt
+++ b/clang/lib/ARCMigrate/CMakeLists.txt
@@ -44,4 +44,5 @@ add_clang_library(clangARCMigrate
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )



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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

back-porting to the release branch: 
https://github.com/llvm/llvm-project/issues/64432


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs 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 rG2fb1c1082c01: cmake: add missing dependencies on 
ClangDriverOptions tablegen (authored by jroelofs).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

Files:
  clang-tools-extra/clang-apply-replacements/CMakeLists.txt
  clang-tools-extra/clang-change-namespace/CMakeLists.txt
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt
  clang-tools-extra/clang-move/CMakeLists.txt
  clang-tools-extra/clang-query/CMakeLists.txt
  clang-tools-extra/clang-reorder-fields/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/altera/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/boost/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/darwin/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/mpi/CMakeLists.txt
  clang-tools-extra/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/zircon/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/unimplemented/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/xpc/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang-tools-extra/pp-trace/CMakeLists.txt
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang/CMakeLists.txt
  clang/lib/AST/CMakeLists.txt
  clang/lib/ASTMatchers/CMakeLists.txt
  clang/lib/ASTMatchers/Dynamic/CMakeLists.txt
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Index/CMakeLists.txt
  clang/lib/Parse/CMakeLists.txt
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Serialization/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Index: clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -148,4 +148,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Serialization/CMakeLists.txt
===
--- clang/lib/Serialization/CMakeLists.txt
+++ clang/lib/Serialization/CMakeLists.txt
@@ -34,4 +34,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Sema/CMakeLists.txt
===
--- clang/lib/Sema/CMakeLists.txt
+++ clang/lib/Sema/CMakeLists.txt
@@ -71,6 +71,7 @@
   DEPENDS
   ClangOpenCLBuiltinsImpl
   omp_gen
+  ClangDriverOptions
 
   LINK_LIBS
   clangAST
Index: clang/lib/Parse/CMakeLists.txt
===
--- clang/lib/Parse/CMakeLists.txt
+++ clang/lib/Parse/CMakeLists.txt
@@ -32,4 +32,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Index/CMakeLists.txt
===
--- clang/lib/Index/CMakeLists.txt
+++ clang/lib/Index/CMakeLists.txt
@@ -28,4 +28,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Basic/CMakeLists.txt
===
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -125,6 +125,7 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
 
 target_link_libraries(clangBasic
Index: clang/lib/Analysis/CMakeLists.txt
===
--- clang/lib/Analysis/CMakeLists.txt
+++ clang/lib/Analysis/CMakeLists.txt
@@ -43,6 +43,7 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
 

[clang] 2fb1c10 - cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs via cfe-commits

Author: Jon Roelofs
Date: 2023-08-04T10:27:19-07:00
New Revision: 2fb1c1082c01ddf9b2531083196ff2dace1fdab7

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

LOG: cmake: add missing dependencies on ClangDriverOptions tablegen

The modules build trips over this frequently because there is no textual
include of the tablegen output, but the module includes it.

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

Added: 


Modified: 
clang-tools-extra/clang-apply-replacements/CMakeLists.txt
clang-tools-extra/clang-change-namespace/CMakeLists.txt
clang-tools-extra/clang-doc/CMakeLists.txt
clang-tools-extra/clang-include-fixer/CMakeLists.txt
clang-tools-extra/clang-include-fixer/find-all-symbols/CMakeLists.txt
clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt
clang-tools-extra/clang-move/CMakeLists.txt
clang-tools-extra/clang-query/CMakeLists.txt
clang-tools-extra/clang-reorder-fields/CMakeLists.txt
clang-tools-extra/clang-tidy/CMakeLists.txt
clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/clang-tidy/altera/CMakeLists.txt
clang-tools-extra/clang-tidy/android/CMakeLists.txt
clang-tools-extra/clang-tidy/boost/CMakeLists.txt
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/clang-tidy/cert/CMakeLists.txt
clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
clang-tools-extra/clang-tidy/darwin/CMakeLists.txt
clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
clang-tools-extra/clang-tidy/google/CMakeLists.txt
clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/clang-tidy/mpi/CMakeLists.txt
clang-tools-extra/clang-tidy/objc/CMakeLists.txt
clang-tools-extra/clang-tidy/performance/CMakeLists.txt
clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/clang-tidy/portability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/clang-tidy/utils/CMakeLists.txt
clang-tools-extra/clang-tidy/zircon/CMakeLists.txt
clang-tools-extra/clangd/index/remote/unimplemented/CMakeLists.txt
clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
clang-tools-extra/clangd/xpc/CMakeLists.txt
clang-tools-extra/include-cleaner/lib/CMakeLists.txt
clang-tools-extra/modularize/CMakeLists.txt
clang-tools-extra/pp-trace/CMakeLists.txt
clang-tools-extra/pseudo/lib/CMakeLists.txt
clang/CMakeLists.txt
clang/lib/AST/CMakeLists.txt
clang/lib/ASTMatchers/CMakeLists.txt
clang/lib/ASTMatchers/Dynamic/CMakeLists.txt
clang/lib/Analysis/CMakeLists.txt
clang/lib/Basic/CMakeLists.txt
clang/lib/Index/CMakeLists.txt
clang/lib/Parse/CMakeLists.txt
clang/lib/Sema/CMakeLists.txt
clang/lib/Serialization/CMakeLists.txt
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt 
b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt
index 27383b488e4dff..93198ccbfc406f 100644
--- a/clang-tools-extra/clang-apply-replacements/CMakeLists.txt
+++ b/clang-tools-extra/clang-apply-replacements/CMakeLists.txt
@@ -4,6 +4,9 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_library(clangApplyReplacements
   lib/Tooling/ApplyReplacements.cpp
+
+  DEPENDS
+  ClangDriverOptions
 )
 
 clang_target_link_libraries(clangApplyReplacements

diff  --git a/clang-tools-extra/clang-change-namespace/CMakeLists.txt 
b/clang-tools-extra/clang-change-namespace/CMakeLists.txt
index 4cd9e7520b97b1..ded91edb8e34f0 100644
--- a/clang-tools-extra/clang-change-namespace/CMakeLists.txt
+++ b/clang-tools-extra/clang-change-namespace/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangChangeNamespace
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
 )
 
 clang_target_link_libraries(clangChangeNamespace

diff  --git a/clang-tools-extra/clang-doc/CMakeLists.txt 
b/clang-tools-extra/clang-doc/CMakeLists.txt
index a43660c4884956..975ad8e242e490 100644
--- a/clang-tools-extra/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/CMakeLists.txt
@@ -18,6 +18,7 @@ add_clang_library(clangDoc
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
 )
 
 clang_target_link_libraries(clangDoc

diff  --git a/clang-tools-extra/clang-include-fixer/CMakeLists.txt 
b/clang-tools-extra/clang-include-fixer/CMakeLists.txt
index 

[PATCH] D89001: [clang] Don't look into for C++ headers if they are found alongside the toolchain

2023-08-04 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.
Herald added a subscriber: MaskRay.
Herald added a project: All.

@ldionne and @dexonsmith, it seems that this diff breaks clang-tools like 
clang-tidy and clangd if `-isysroot` is specified in the compilation database. 
Moreover, clang from Xcode 14 and 15 uses paths specified in `-sysroot` and 
ignores headers alongside the clang binary. I don’t know if it is new behavior 
or it was this way when this diff was committed. Minimal reproducer is 
following:

  $ cat compile_commands.json
  [
  {
  "directory": "/Users/test/test",
  "file": "test.cpp",
  "arguments": [
  
"/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
  "-isysroot",
  
"/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk",
  "-c",
  "test.cpp",
  "-v"
  ]
  }
  ]
  
  $ /build/bin/clang-tidy -p compile_commands.json test.cpp
  ...
  #include <...> search starts here:
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
   /build/lib/clang/18/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
 (framework directory)
  End of search list.
  1 error generated.
  Error while processing test.cpp.
  test.cpp:1:10: error: 'cxxabi.h' file not found [clang-diagnostic-error]
  1 | #include 
|  ^~
  Found compiler error(s).
  
  $ 
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
 -isysroot 
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
 -c test.cpp -v
  ...
  #include <...> search starts here:
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.3/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
 (framework directory)
  End of search list.

So upstream clang-tools uses a path to the compiler binary specified in CDB as 
an installation dir and searches in 
".../XcodeDefault.xctoolchain/usr/bin/../include/c++/v1" but the Apple compiler 
from CDB searches in the path specified in sysroot 
".../MacOSX.sdk/usr/include/c++/v1". I also checked clangd from Apple 
toolchain, it also uses path species in `-sysroot`. I have a local patch that 
honors `-isysroot` if it is explicitly specified in the command line but 
prefers headers alongside the binary in other cases and it seems that it 
matches the behavior of Apple compiler.  But it breaks all tests that 
specifically test that `-isysroot` is ignored. Should I change the test and 
send the patch for review?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89001

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


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-08-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 547271.
nickdesaulniers retitled this revision from "[IRGen] Emit lifetime intrinsics 
around temporary aggregate argument allocas" to "Reapply: [IRGen] Emit lifetime 
intrinsics around temporary aggregate argument allocas".
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a reverted change: rGe26c24b84921: Revert "[IRGen] Emit 
lifetime intrinsics around temporary aggregate argument….
nickdesaulniers added a comment.
Herald added a subscriber: jvesely.

- rebase on opaque ptrs

WIP, the following tests now fail and need to be updated:
Failed Tests (3):

  Clang :: CodeGenCXX/amdgcn-call-with-aggarg.cpp
  Clang :: CodeGenCoroutines/pr59181.cpp
  Clang :: Driver/ps4-ps5-relax-relocations.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/test/CodeGen/lifetime-call-temp.c
  clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
  clang/test/CodeGenCXX/stack-reuse-miscompile.cpp

Index: clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
===
--- clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
+++ clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
@@ -26,6 +26,8 @@
 // CHECK: [[T2:%.*]] = alloca %class.T, align 4
 // CHECK: [[T3:%.*]] = alloca %class.T, align 4
 //
+// CHECK: [[AGG:%.*]] = alloca %class.S, align 4
+//
 // FIXME: We could defer starting the lifetime of the return object of concat
 // until the call.
 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T1]])
@@ -34,7 +36,9 @@
 // CHECK: [[T4:%.*]] = call noundef ptr @_ZN1TC1EPKc(ptr {{[^,]*}} [[T2]], ptr noundef @.str)
 //
 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T3]])
+// CHECK: call void @llvm.lifetime.start.p0(i64 8, ptr [[AGG]])
 // CHECK: [[T5:%.*]] = call noundef ptr @_ZN1TC1E1S(ptr {{[^,]*}} [[T3]], [2 x i32] %{{.*}})
+// CHECK: call void @llvm.lifetime.end.p0(i64 8, ptr [[AGG]]
 //
 // CHECK: call void @_ZNK1T6concatERKS_(ptr sret(%class.T) align 4 [[T1]], ptr {{[^,]*}} [[T2]], ptr noundef nonnull align 4 dereferenceable(16) [[T3]])
 // CHECK: [[T6:%.*]] = call noundef ptr @_ZNK1T3strEv(ptr {{[^,]*}} [[T1]])
Index: clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -O3 -disable-llvm-passes -o - %s | FileCheck %s
+
+struct A {
+  float x, y, z, w;
+};
+
+void foo(A a);
+
+// CHECK-LABEL: @_Z4testv
+// CHECK: %[[lvar:.*]] = alloca %struct.A, align 4, addrspace(5)
+// CHECK: %[[atmp:.*]] = alloca %struct.A, align 4, addrspace(5)
+// CHECK: %[[lcst:.*]] = bitcast %struct.A addrspace(5)* %[[lvar]] to i8 addrspace(5)*
+// CHECK: call void @llvm.lifetime.start.p5i8(i64 16, i8 addrspace(5)* %[[lcst]]
+// CHECK: %[[acst:.*]] = bitcast %struct.A addrspace(5)* %[[atmp]] to i8 addrspace(5)*
+// CHECK: call void @llvm.lifetime.start.p5i8(i64 16, i8 addrspace(5)* %[[acst]]
+void test() {
+  A a;
+  foo(a);
+}
Index: clang/test/CodeGen/lifetime-call-temp.c
===
--- /dev/null
+++ clang/test/CodeGen/lifetime-call-temp.c
@@ -0,0 +1,81 @@
+// RUN: %clang -cc1  -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime
+// RUN: %clang -cc1 -xc++ -std=c++17 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - -Wno-return-type-c-linkage | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=CXX
+// RUN: %clang -cc1 -xobjective-c-triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=OBJC
+
+typedef struct { int x[100]; } aggregate;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void takes_aggregate(aggregate);
+aggregate gives_aggregate();
+
+// CHECK-LABEL: define void @t1
+void t1() {
+  takes_aggregate(gives_aggregate());
+
+  // CHECK: [[AGGTMP:%.*]] = alloca %struct.aggregate, align 8
+  // CHECK: call void @llvm.lifetime.start.p0(i64 400, ptr [[AGGTMP]])
+  // CHECK: call void{{.*}} @gives_aggregate(ptr sret(%struct.aggregate) align 4 [[AGGTMP]])
+  // CHECK: call void @takes_aggregate(ptr noundef byval(%struct.aggregate) align 8 [[AGGTMP]])
+  // CHECK: call void @llvm.lifetime.end.p0(i64 400, ptr [[AGGTMP]])
+}
+
+// CHECK: declare {{.*}}llvm.lifetime.start
+// CHECK: declare {{.*}}llvm.lifetime.end
+
+#ifdef __cplusplus
+// CXX: define void @t2
+void t2() {
+  struct S {
+S(aggregate) {}
+  };
+  S{gives_aggregate()};
+
+  // CXX: [[AGG:%.*]] = alloca %struct.aggregate
+  // CXX: call void @llvm.lifetime.start.p0(i64 400, ptr
+  // 

[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-08-04 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D148997#4561068 , @bnbarham wrote:

> In D148997#4561022 , @v.g.vassilev 
> wrote:
>
>> I meant that I'd like to figure out if we could use the 
>> `annot_repl_input_end` before considering a new flag.
>
> Oh sure, that's why I'm here :). Just trying to figure out what we think the 
> best way forward is.
>
>>> The issue is that all these actions (and the parser checks) can run with 
>>> and without `isIncrementalProcessingEnabled`, so they would need to check 
>>> both `eof` and `annot_repl_input_end`. For some concrete locations (but no 
>>> where near complete):
>>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L82
>>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L955
>>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp#L542
>>
>> These three seem to be useful for `clang-repl` too, so we might want to 
>> extend it with like `!(eof || annot_repl_input_end)`
>
> Sure, though to be clear this isn't all of them, there's also the dump 
> actions too (though not sure that makes sense for `clang-repl`)

The dump actions are also somewhat interesting because in that case we will 
dump the delta that was accumulated and repeat.

and a few in other files (`VerifyDiagnosticConsumer.cpp`, 
`PrintPreprocessedOutput.cpp`).

These ones are also interesting.

>>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Parse/ParseExprCXX.cpp#L4070
>>
>> That looks a bit obscure to me. Looks like we are trying to reach some error 
>> recovery anchor but do you happen to have some use case at hand? In 
>> principle we could do the same as for the other 3.
>
> This was just one I picked at random from my grep over the parser. It's 
> unclear how often this would be hit, but I have to assume it (and the other 
> references) can, even if they're obscure/unlikely. My main point is that 
> `!eof` is being used somewhat frequently to end loops, but with this change 
> they will now all never end.

Since `eof` there were several `eof`-like tokens that were added: 
`annot_module_begin`, `annot_module_end`, `tok::annot_module_include` which are 
commonly handled in `isEofOrEom`. We could update these uses with `isEofOrEom` 
but I am pretty sure that @rsmith will point out cases where that's not a good 
very good idea :) We could either experiment with using `isEofOrEom` or have a 
similar utility function only for the two tokens (say `isEoI` -- end of input 
whatever that means).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D74094: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-08-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

(I am working on rebasing this; tests need updating for opaque ptr)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added subscribers: aprantl, dblaikie.
steven_wu added a comment.
This revision is now accepted and ready to land.

LGTM. @aprantl @dblaikie who cares about module builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

related discussion: 
https://discourse.llvm.org/t/rfc-permanently-fixing-the-missing-tablegen-dependency-issue/70442/14


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-04 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs created this revision.
jroelofs added a reviewer: steven_wu.
Herald added subscribers: PiotrZSL, kadircet, steakhal, carlosgalvezp, 
abrachet, martong, arphaman, kbarton, nemanjai.
Herald added a reviewer: NoQ.
Herald added a reviewer: njames93.
Herald added a project: All.
jroelofs requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

The modules build trips over this frequently because there is no textual 
include of the tablegen output, but the module includes it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157119

Files:
  clang-tools-extra/clang-apply-replacements/CMakeLists.txt
  clang-tools-extra/clang-change-namespace/CMakeLists.txt
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/plugin/CMakeLists.txt
  clang-tools-extra/clang-move/CMakeLists.txt
  clang-tools-extra/clang-query/CMakeLists.txt
  clang-tools-extra/clang-reorder-fields/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/altera/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/boost/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/darwin/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
  clang-tools-extra/clang-tidy/linuxkernel/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/mpi/CMakeLists.txt
  clang-tools-extra/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/zircon/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/unimplemented/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/xpc/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang-tools-extra/pp-trace/CMakeLists.txt
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang/CMakeLists.txt
  clang/lib/AST/CMakeLists.txt
  clang/lib/ASTMatchers/CMakeLists.txt
  clang/lib/ASTMatchers/Dynamic/CMakeLists.txt
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Index/CMakeLists.txt
  clang/lib/Parse/CMakeLists.txt
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Serialization/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Index: clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -148,4 +148,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Serialization/CMakeLists.txt
===
--- clang/lib/Serialization/CMakeLists.txt
+++ clang/lib/Serialization/CMakeLists.txt
@@ -34,4 +34,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Sema/CMakeLists.txt
===
--- clang/lib/Sema/CMakeLists.txt
+++ clang/lib/Sema/CMakeLists.txt
@@ -71,6 +71,7 @@
   DEPENDS
   ClangOpenCLBuiltinsImpl
   omp_gen
+  ClangDriverOptions
 
   LINK_LIBS
   clangAST
Index: clang/lib/Parse/CMakeLists.txt
===
--- clang/lib/Parse/CMakeLists.txt
+++ clang/lib/Parse/CMakeLists.txt
@@ -32,4 +32,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Index/CMakeLists.txt
===
--- clang/lib/Index/CMakeLists.txt
+++ clang/lib/Index/CMakeLists.txt
@@ -28,4 +28,5 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
Index: clang/lib/Basic/CMakeLists.txt
===
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -125,6 +125,7 @@
 
   DEPENDS
   omp_gen
+  ClangDriverOptions
   )
 
 

[PATCH] D156466: [clang][CGExprConstant] handle implicit widening/narrowing Int-to-Int casts

2023-08-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156466

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


[PATCH] D156378: [clang][CGExprConstant] handle unary negation on integrals

2023-08-04 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156378

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


[PATCH] D156948: [clang][modules] Add -Wsystem-headers-in-module=

2023-08-04 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir marked an inline comment as done.
benlangmuir added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticOptions.h:128
+  /// whether -Wsystem-headers is enabled on a per-module basis.
+  std::vector SystemHeaderWarningsModules;
+

jansvoboda11 wrote:
> Out of interest, is there an existing use-case for having multiple modules 
> here, or is this just future-proofing?
I'm not using it currently, but I think it makes sense to handle any number. 
You could have multiple such modules you're testing together.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:1238-1239
 
+  for (StringRef Name : DiagOpts.SystemHeaderWarningsModules)
+if (Name == ModuleName)
+  Instance.getDiagnostics().setSuppressSystemWarnings(false);

jansvoboda11 wrote:
> I assume `llvm::is_contained()` wouldn't be okay with the `std::string` and 
> `StringRef` mismatch?
Nope, I just didn't think of it here for some reason. Updated.


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

https://reviews.llvm.org/D156948

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


[PATCH] D156948: [clang][modules] Add -Wsystem-headers-in-module=

2023-08-04 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 547266.
benlangmuir added a comment.

Use `llvm::is_contained`


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

https://reviews.llvm.org/D156948

Files:
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Wsystem-headers-in-module.c
  clang/test/Modules/Wsystem-headers-in-module.c

Index: clang/test/Modules/Wsystem-headers-in-module.c
===
--- /dev/null
+++ clang/test/Modules/Wsystem-headers-in-module.c
@@ -0,0 +1,32 @@
+// Check that Wsystem-headers-in-module shows diagnostics in the named system
+// module, but not in other system headers or modules.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp \
+// RUN:   -isystem %t/sys %t/tu.c -fsyntax-only -Wextra-semi -Wsystem-headers-in-module=sys_mod \
+// RUN:   2>&1 | FileCheck %s
+
+// CHECK-NOT: warning:
+// CHECK: sys_mod.h:2:7: warning: extra ';'
+// CHECK-NOT: warning:
+
+//--- sys/other_sys_header.h
+int x;;
+//--- sys_mod.h
+#include "dependent_sys_mod.h"
+int y;;
+//--- other_sys_mod.h
+int z;;
+//--- dependent_sys_mod.h
+int w;;
+//--- module.modulemap
+module sys_mod [system] { header "sys_mod.h" }
+module other_sys_mod [system] { header "other_sys_mod.h" }
+module dependent_sys_mod [system] { header "dependent_sys_mod.h" }
+
+//--- tu.c
+#include "sys_mod.h"
+#include "other_sys_mod.h"
+#include "other_sys_header.h"
Index: clang/test/ClangScanDeps/Wsystem-headers-in-module.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/Wsystem-headers-in-module.c
@@ -0,0 +1,56 @@
+// Check that Wsystem-headers-in-module shows diagnostics in the named system
+// module, but not in other system headers or modules when built with explicit
+// modules.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/deps.json
+
+// RUN: %deps-to-rsp %t/deps.json --module-name=dependent_sys_mod > %t/dependent_sys_mod.rsp
+// RUN: %deps-to-rsp %t/deps.json --module-name=sys_mod > %t/sys_mod.rsp
+// RUN: %deps-to-rsp %t/deps.json --module-name=other_sys_mod > %t/other_sys_mod.rsp
+// RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
+
+// RUN: %clang @%t/dependent_sys_mod.rsp -verify
+// RUN: %clang @%t/sys_mod.rsp -verify
+// RUN: %clang @%t/other_sys_mod.rsp -verify
+// RUN: %clang @%t/tu.rsp -verify
+
+// CHECK-NOT: warning:
+// CHECK: sys_mod.h:2:7: warning: extra ';'
+// CHECK-NOT: warning:
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/mcp DIR/tu.c -isystem DIR/sys -Wextra-semi -Wsystem-headers-in-module=sys_mod",
+  "file": "DIR/tu.c"
+}]
+
+//--- sys/other_sys_header.h
+int x;;
+
+//--- sys_mod.h
+#include "dependent_sys_mod.h"
+int y;; // expected-warning {{extra ';' outside of a function}}
+
+//--- other_sys_mod.h
+int z;;
+// expected-no-diagnostics
+
+//--- dependent_sys_mod.h
+int w;;
+// expected-no-diagnostics
+
+//--- module.modulemap
+module sys_mod [system] { header "sys_mod.h" }
+module other_sys_mod [system] { header "other_sys_mod.h" }
+module dependent_sys_mod [system] { header "dependent_sys_mod.h" }
+
+//--- tu.c
+#include "sys_mod.h"
+#include "other_sys_mod.h"
+#include "other_sys_header.h"
+// expected-no-diagnostics
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -12,6 +12,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/BLAKE3.h"
 #include "llvm/Support/StringSaver.h"
 #include 
@@ -172,6 +173,13 @@
 CI.getHeaderSearchOpts().ModulesIgnoreMacros.clear();
   }
 
+  // Apply -Wsystem-headers-in-module for the current module.
+  if (llvm::is_contained(CI.getDiagnosticOpts().SystemHeaderWarningsModules,
+ Deps.ID.ModuleName))
+CI.getDiagnosticOpts().Warnings.push_back("system-headers");
+  // Remove the now unused option(s).
+  CI.getDiagnosticOpts().SystemHeaderWarningsModules.clear();
+
   Optimize(CI);
 
   return CI;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ 

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 547265.
evelez7 added a comment.

Format DeclarationFragments.h, try to address buildbot fail on clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  

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

2023-08-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a project: All.
eandrews requested review of this revision.

Fix static analyzer concerns about dereferencing null values


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())


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())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156948: [clang][modules] Add -Wsystem-headers-in-module=

2023-08-04 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/include/clang/Basic/DiagnosticOptions.h:128
+  /// whether -Wsystem-headers is enabled on a per-module basis.
+  std::vector SystemHeaderWarningsModules;
+

Out of interest, is there an existing use-case for having multiple modules 
here, or is this just future-proofing?



Comment at: clang/lib/Frontend/CompilerInstance.cpp:1238-1239
 
+  for (StringRef Name : DiagOpts.SystemHeaderWarningsModules)
+if (Name == ModuleName)
+  Instance.getDiagnostics().setSuppressSystemWarnings(false);

I assume `llvm::is_contained()` wouldn't be okay with the `std::string` and 
`StringRef` mismatch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156948

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


[PATCH] D157115: Revert "[clang][X86] Add __cpuidex function to cpuid.h"

2023-08-04 Thread Aiden Grossman via Phabricator via cfe-commits
aidengrossman added a comment.

Assuming everyone agrees to this going in, I'll land it and then open a 
backport for the 17 release and reland once the auxiliary triple issues are 
resolved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157115

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-08-04 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added a comment.

In D148997#4561022 , @v.g.vassilev 
wrote:

> I meant that I'd like to figure out if we could use the 
> `annot_repl_input_end` before considering a new flag.

Oh sure, that's why I'm here :). Just trying to figure out what we think the 
best way forward is.

>> The issue is that all these actions (and the parser checks) can run with and 
>> without `isIncrementalProcessingEnabled`, so they would need to check both 
>> `eof` and `annot_repl_input_end`. For some concrete locations (but no where 
>> near complete):
>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L82
>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L955
>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp#L542
>
> These three seem to be useful for `clang-repl` too, so we might want to 
> extend it with like `!(eof || annot_repl_input_end)`

Sure, though to be clear this isn't all of them, there's also the dump actions 
too (though not sure that makes sense for `clang-repl`) and a few in other 
files (`VerifyDiagnosticConsumer.cpp`, `PrintPreprocessedOutput.cpp`).

>> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Parse/ParseExprCXX.cpp#L4070
>
> That looks a bit obscure to me. Looks like we are trying to reach some error 
> recovery anchor but do you happen to have some use case at hand? In principle 
> we could do the same as for the other 3.

This was just one I picked at random from my grep over the parser. It's unclear 
how often this would be hit, but I have to assume it (and the other references) 
can, even if they're obscure/unlikely. My main point is that `!eof` is being 
used somewhat frequently to end loops, but with this change they will now all 
never end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D157115: Revert "[clang][X86] Add __cpuidex function to cpuid.h"

2023-08-04 Thread Aiden Grossman via Phabricator via cfe-commits
aidengrossman created this revision.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit 2df77ac20a1ed996706b164b0c4ed5ad140f635f 
.

This has been causing some issues with some windows builds as `_MSC_EXTENSIONS` 
isn't defined when only `-fms-extensions` is set, but the builtin that 
conflicts with __cpuidex is. This was also causing problems as it exposed some 
latent issues with how auxiliary triples are handled in clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157115

Files:
  clang/lib/Headers/cpuid.h
  clang/test/Headers/__cpuidex_conflict.c
  clang/test/Headers/cpuid.c


Index: clang/test/Headers/cpuid.c
===
--- clang/test/Headers/cpuid.c
+++ clang/test/Headers/cpuid.c
@@ -6,19 +6,14 @@

 // CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm "  xchgq  %rbx,${1:q}\0A 
cpuid\0A xchgq %rbx,${1:q}", 
"={ax},=r,={cx},={dx},0,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}})
 // CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm "  xchgq  %rbx,${1:q}\0A  
cpuid\0A  xchgq  %rbx,${1:q}", 
"={ax},=r,={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 
%{{[a-z0-9]+}})
-// CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm "  xchgq  %rbx,${1:q}\0A  
cpuid\0A  xchgq  %rbx,${1:q}", 
"={ax},=r,={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 
%{{[a-z0-9]+}})

 // CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", 
"={ax},={bx},={cx},={dx},0,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}})
 // CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", 
"={ax},={bx},={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, 
i32 %{{[a-z0-9]+}})
-// CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", 
"={ax},={bx},={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, 
i32 %{{[a-z0-9]+}})

 unsigned eax0, ebx0, ecx0, edx0;
 unsigned eax1, ebx1, ecx1, edx1;

-int cpuid_info[4];
-
 void test_cpuid(unsigned level, unsigned count) {
   __cpuid(level, eax1, ebx1, ecx1, edx1);
   __cpuid_count(level, count, eax0, ebx0, ecx0, edx0);
-  __cpuidex(cpuid_info, level, count);
 }
Index: clang/test/Headers/__cpuidex_conflict.c
===
--- clang/test/Headers/__cpuidex_conflict.c
+++ /dev/null
@@ -1,15 +0,0 @@
-// Make sure that __cpuidex in cpuid.h doesn't conflict with the MS
-// compatibility built in by ensuring compilation succeeds:
-// RUN: %clang_cc1 %s -ffreestanding -fms-extensions -fms-compatibility \
-// RUN:  -fms-compatibility-version=19.00 -triple x86_64-pc-windows-msvc 
-emit-llvm -o -
-
-typedef __SIZE_TYPE__ size_t;
-
-#include 
-#include 
-
-int cpuid_info[4];
-
-void test_cpuidex(unsigned level, unsigned count) {
-  __cpuidex(cpuid_info, level, count);
-}
Index: clang/lib/Headers/cpuid.h
===
--- clang/lib/Headers/cpuid.h
+++ clang/lib/Headers/cpuid.h
@@ -328,14 +328,4 @@
 return 1;
 }

-// If MS extensions are enabled, __cpuidex is defined as a builtin which will
-// conflict with the __cpuidex definition below.
-#ifndef _MSC_EXTENSIONS
-static __inline void __cpuidex (int __cpu_info[4], int __leaf, int __subleaf)
-{
-  __cpuid_count(__leaf, __subleaf, __cpu_info[0], __cpu_info[1], __cpu_info[2],
-__cpu_info[3]);
-}
-#endif
-
 #endif /* __CPUID_H */


Index: clang/test/Headers/cpuid.c
===
--- clang/test/Headers/cpuid.c
+++ clang/test/Headers/cpuid.c
@@ -6,19 +6,14 @@

 // CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm "  xchgq  %rbx,${1:q}\0A cpuid\0A xchgq %rbx,${1:q}", "={ax},=r,={cx},={dx},0,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}})
 // CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm "  xchgq  %rbx,${1:q}\0A  cpuid\0A  xchgq  %rbx,${1:q}", "={ax},=r,={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 %{{[a-z0-9]+}})
-// CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm "  xchgq  %rbx,${1:q}\0A  cpuid\0A  xchgq  %rbx,${1:q}", "={ax},=r,={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 %{{[a-z0-9]+}})

 // CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},0,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}})
 // CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 %{{[a-z0-9]+}})
-// CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 %{{[a-z0-9]+}})

 unsigned eax0, ebx0, ecx0, edx0;
 unsigned eax1, ebx1, ecx1, edx1;

-int cpuid_info[4];
-
 void test_cpuid(unsigned level, unsigned count) {
   __cpuid(level, eax1, ebx1, ecx1, 

[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-08-04 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D148997#4561015 , @bnbarham wrote:

> In D148997#4559788 , @v.g.vassilev 
> wrote:
>
>> I'd prefer to avoid adding a new flag. Is there a way to see how does the 
>> diff looks like?
>
> You mean for a new flag? I don't have one prepared, but it would basically 
> just be adding an extra check where `isIncrementalProcessingEnabled` is 
> currently used to skip resetting `CurLexer` and `TUScope`. I don't believe 
> we'd want any difference in parsing in Swift's clang importer use case.

I meant that I'd like to figure out if we could use the `annot_repl_input_end` 
before considering a new flag.

>> Maybe it would make more sense to use the `annot_repl_input_end` token? If 
>> the token name does not capture well the generic use-case I am happy to 
>> change it to something better.
>
> The issue is that all these actions (and the parser checks) can run with and 
> without `isIncrementalProcessingEnabled`, so they would need to check both 
> `eof` and `annot_repl_input_end`. For some concrete locations (but no where 
> near complete):
> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L82
> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L955
> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp#L542

These three seem to be useful for `clang-repl` too, so we might want to extend 
it with like `!(eof || annot_repl_input_end)`

> https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Parse/ParseExprCXX.cpp#L4070

That looks a bit obscure to me. Looks like we are trying to reach some error 
recovery anchor but do you happen to have some use case at hand? In principle 
we could do the same as for the other 3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-08-04 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added a comment.

In D148997#4559788 , @v.g.vassilev 
wrote:

> I'd prefer to avoid adding a new flag. Is there a way to see how does the 
> diff looks like?

You mean for a new flag? I don't have one prepared, but it would basically just 
be adding an extra check where `isIncrementalProcessingEnabled` is currently 
used to skip resetting `CurLexer` and `TUScope`, ie. . I don't believe we'd 
want any difference in parsing in Swift's clang importer use case.

> Maybe it would make more sense to use the `annot_repl_input_end` token? If 
> the token name does not capture well the generic use-case I am happy to 
> change it to something better.

The issue is that all these actions (and the parser checks) can run with and 
without `isIncrementalProcessingEnabled`, so they would need to check both 
`eof` and `annot_repl_input_end`. For some concrete locations (but no where 
near complete):
https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L82
https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/FrontendActions.cpp#L955
https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp#L542
https://github.com/llvm/llvm-project/blob/df6b35e329ebecad6dc3bfb83183e482eb7a0020/clang/lib/Parse/ParseExprCXX.cpp#L4070


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-08-04 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D150446#4560892 , @donat.nagy 
wrote:

> I'm abandoning this commit because it amalgamates several unrelated changes 
> and I think it'd be better to handle them separately:
>
> 1. First, there is a very simple, independent improvement related to 
> underflows and UnknownSpaces. I already created the separate commit D157104 
>  for this (reviews are welcome ;) ).
> 2. As the title of this commit says, I wanted to turn this checker into a 
> `Checker>` instead of a 
> `Checker`. I'm still planning to do this transition in a 
> separate commit because I feel that this will be needed to compose good 
> warning messages and there are a few situations like the testcase 
> `test_field` where the `check::Location` model produces counter-intuitive 
> results. (When I implement this, I'll also ensure that `*p` and `p->field` 
> are handled analogously to `p[0]`, but perhaps these will be in a separate 
> commit.)
> 3. Finally there is the "simplify `RegionRawOffsetV2::computeOffset` and fix 
> multidimensional array handling" change. This is the modification that was 
> responsible for the multitude of false positives caused by this commit; and I 
> don't have a quick fix for it (the engine abuses `ElementRegion` to record 
> pointer arithmetic and I didn't find a clear way to distinguish it from real 
> element access). On the short-term I think I'll need to accept that this 
> checker will produce false negatives in situations when one element of a 
> multi-dimensional array is over-indexed without overflowing the whole array 
> (e.g. if `arr` is declared as `int arr[5][5]`, then `arr[1][10]` over-indexes 
> `arr[1]`, but points inside the full area of the matrix); but fortunately 
> this is not a fatal limitation (it only produces false negatives, 
> multi-dimensional arrays are not too common).

I'd like to thank you your effort on this subject.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150446

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


[PATCH] D157114: [clang][ASTImporter] Improve StructuralEquivalence algorithm on repeated friends

2023-08-04 Thread Balázs Benics via Phabricator via cfe-commits
steakhal resigned from this revision.
steakhal added a comment.

In general, I'm not really involved with the ASTImporter.
Please, put me as a reviewer if the ASTImporter directly affects the Static 
Analyzer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157114

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


[PATCH] D157114: [clang][ASTImporter] Improve StructuralEquivalence algorithm on repeated friends

2023-08-04 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added reviewers: balazske, steakhal, aaron.ballman, shafik, martong.
Herald added a reviewer: a.sidorin.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repeated friends are deduplicated when imported, but StructuralEquivalence 
checks friends by exact matching.
If `ToContext` is empty (not containing the class to be imported), the imported 
friends are deduplicated, any
further importing of the class would be rejected at the structure equivalence 
checking, i.e:

  struct foo { friend class X; friend class X; }; // FromContext

only one friend is imported, similar to the following:

  struct foo { friend class X; }; // ToContext

but when imported again, `struct foo` in FromContext is reported as not 
equivalent to `struct foo` in `ToContext`,
thus rejected.

The structural equivalence checking algorithm is improved by applying similar 
deduplication as Importer does.
Thus from StructuralEquivalence's point of view, the above two `RecordDecl`s 
are equivalent.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157114

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

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -833,7 +833,7 @@
   auto t = makeNamedDecls("struct foo { friend class X; };",
   "struct foo { friend class X; friend class X; };",
   Lang_CXX11);
-  EXPECT_FALSE(testStructuralMatch(t));
+  EXPECT_TRUE(testStructuralMatch(t));
 }
 
 TEST_F(StructuralEquivalenceRecordTest, SameFriendsDifferentOrder) {
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/StringMap.h"
@@ -4351,6 +4352,44 @@
   EXPECT_EQ(ToFriend2, ToImportedFriend2);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportRepeatedFriendDeclIntoEmptyDC) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(R"(
+  template 
+  class A {
+  public:
+template  friend A ();
+template  friend A ();
+  };
+  )",
+   Lang_CXX17, "", Lang_CXX17, "A");
+
+  auto *FromFriend1 = FirstDeclMatcher().match(From, friendDecl());
+  auto *FromFriend2 = LastDeclMatcher().match(From, friendDecl());
+  auto *ToFriend1 = FirstDeclMatcher().match(To, friendDecl());
+  auto *ToFriend2 = LastDeclMatcher().match(To, friendDecl());
+
+  // Two different FriendDecls in From context.
+  EXPECT_TRUE(FromFriend1 != FromFriend2);
+  // Only one is imported into empty DC.
+  EXPECT_TRUE(ToFriend1 == ToFriend2);
+
+  // 'A' is imported into empty DC, keeping structure equivalence.
+  llvm::DenseSet> NonEquivalentDecls01;
+  llvm::DenseSet> NonEquivalentDecls10;
+  StructuralEquivalenceContext Ctx01(
+  From->getASTContext(), To->getASTContext(), NonEquivalentDecls01,
+  StructuralEquivalenceKind::Default, false, false);
+  StructuralEquivalenceContext Ctx10(
+  To->getASTContext(), From->getASTContext(), NonEquivalentDecls10,
+  StructuralEquivalenceKind::Default, false, false);
+
+  bool Eq01 = Ctx01.IsEquivalent(From, To);
+  bool Eq10 = Ctx10.IsEquivalent(To, From);
+  EXPECT_EQ(Eq01, Eq10);
+  EXPECT_TRUE(Eq01);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, FriendFunInClassTemplate) {
   auto *Code = R"(
   template 
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1464,6 +1464,160 @@
   return IsStructurallyEquivalent(GetName(D1), GetName(D2));
 }
 
+static bool
+IsCXXRecordBaseStructurallyEquivalent(StructuralEquivalenceContext ,
+  RecordDecl *D1, RecordDecl *D2) {
+  auto *D1CXX = cast(D1);
+  auto *D2CXX = cast(D2);
+
+  if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
+if (Context.Complain) {
+  Context.Diag2(D2->getLocation(), Context.getApplicableDiagnostic(
+   diag::err_odr_tag_type_inconsistent))
+  << Context.ToCtx.getTypeDeclType(D2);
+  Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases)
+  << D2CXX->getNumBases();
+  Context.Diag1(D1->getLocation(), 

[PATCH] D154382: [ClangRepl] support code completion at a REPL

2023-08-04 Thread Fred Fu via Phabricator via cfe-commits
capfredf updated this revision to Diff 547241.
capfredf marked 2 inline comments as done.
capfredf added a comment.

changes per discussions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154382

Files:
  clang/include/clang/Interpreter/CodeCompletion.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/CodeCompletion.cpp
  clang/lib/Interpreter/DeviceOffload.cpp
  clang/lib/Interpreter/ExternalSource.cpp
  clang/lib/Interpreter/ExternalSource.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/incrememal-mode-completion-no-error.cpp
  clang/test/CodeCompletion/incremental-top-level.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/CodeCompletionTest.cpp
  clang/unittests/Interpreter/IncrementalProcessingTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -41,6 +41,7 @@
 
 namespace {
 using Args = std::vector;
+
 static std::unique_ptr
 createInterpreter(const Args  = {},
   DiagnosticConsumer *Client = nullptr) {
Index: clang/unittests/Interpreter/IncrementalProcessingTest.cpp
===
--- clang/unittests/Interpreter/IncrementalProcessingTest.cpp
+++ clang/unittests/Interpreter/IncrementalProcessingTest.cpp
@@ -55,6 +55,7 @@
   auto CB = clang::IncrementalCompilerBuilder();
   CB.SetCompilerArgs(ClangArgv);
   auto CI = cantFail(CB.CreateCpp());
+
   auto Interp = llvm::cantFail(Interpreter::create(std::move(CI)));
 
   std::array PTUs;
Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -0,0 +1,107 @@
+#include "clang/Interpreter/CodeCompletion.h"
+#include "clang/Interpreter/Interpreter.h"
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+namespace {
+auto CB = clang::IncrementalCompilerBuilder();
+
+static std::unique_ptr createInterpreter() {
+  auto CI = cantFail(CB.CreateCpp());
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+static std::vector runComp(clang::Interpreter ,
+llvm::StringRef Prefix,
+llvm::Error ) {
+  std::vector Results;
+  auto CI = CB.CreateCpp();
+  if (auto Err = CI.takeError()) {
+ErrR = std::move(Err);
+return {};
+  }
+
+  size_t Lines = std::count(Prefix.begin(), Prefix.end(), '\n') + 1;
+  auto CFG = clang::CodeCompletionCfg{
+  Prefix.size(), Lines,
+  const_cast(MainInterp.getCompilerInstance()),
+  Results};
+
+  auto Interp = clang::Interpreter::create(std::move(*CI), CFG);
+  if (auto Err = Interp.takeError()) {
+// log the error and returns an empty vector;
+ErrR = std::move(Err);
+
+return {};
+  }
+
+  if (auto PTU = (*Interp)->Parse(Prefix); !PTU) {
+ErrR = std::move(PTU.takeError());
+return {};
+  }
+
+  std::vector Comps;
+  for (auto c : ConvertToCodeCompleteStrings(Results)) {
+if (c.startswith(Prefix))
+  Comps.push_back(c.substr(Prefix.size()).str());
+  }
+
+  return Comps;
+}
+
+TEST(CodeCompletionTest, Sanity) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "f", Err);
+  EXPECT_EQ((size_t)2, comps.size()); // foo and float
+  EXPECT_EQ(comps[0], std::string("oo"));
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, SanityNoneValid) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "babanana", Err);
+  EXPECT_EQ((size_t)0, comps.size()); // foo and float
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, TwoDecls) {
+  auto Interp = createInterpreter();
+  if (auto R = 

[PATCH] D157104: [analyzer] Improve underflow handling in ArrayBoundV2

2023-08-04 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added reviewers: dkrupp, steakhal, Szelethus, gamesh411.
donat.nagy added a comment.

I'll try to upload results on open source projects, probably on Tuesday (I'm on 
vacation on Monday).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157104

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


[clang] df6b35e - Fix Clang Sphinx bot

2023-08-04 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-08-04T11:43:35-04:00
New Revision: df6b35e329ebecad6dc3bfb83183e482eb7a0020

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

LOG: Fix Clang Sphinx bot

Addresses the issue found in:
https://lab.llvm.org/buildbot/#/builders/92/builds/48490

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 46a7aff15da9dc..f03e5231215eb2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -74,6 +74,7 @@ C++2c Feature Support
   is not supported.
 
   .. code-block:: cpp
+
 struct S {
   int _, _; // Was invalid, now OK
 };



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


[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-08-04 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy abandoned this revision.
donat.nagy added a comment.
Herald added a subscriber: wangpc.

I'm abandoning this commit because it amalgamates several unrelated changes and 
I think it'd be better to handle them separately:

1. First, there is a very simple, independent improvement related to underflows 
and UnknownSpaces. I already created the separate commit D157104 
 for this (reviews are welcome ;) ).
2. As the title of this commit says, I wanted to turn this checker into a 
`Checker>` instead of a 
`Checker`. I'm still planning to do this transition in a 
separate commit because I feel that this will be needed to compose good warning 
messages and there are a few situations like the testcase `test_field` where 
the `check::Location` model produces counter-intuitive results. (When I 
implement this, I'll also ensure that `*p` and `p->field` are handled 
analogously to `p[0]`, but perhaps these will be in a separate commit.)
3. Finally there is the "simplify `RegionRawOffsetV2::computeOffset` and fix 
multidimensional array handling" change. This is the modification that was 
responsible for the multitude of false positives caused by this commit; and I 
don't have a quick fix for it (the engine abuses `ElementRegion` to record 
pointer arithmetic and I didn't find a clear way to distinguish it from real 
element access). On the short-term I think I'll need to accept that this 
checker will produce false negatives in situations when one element of a 
multi-dimensional array is over-indexed without overflowing the whole array 
(e.g. if `arr` is declared as `int arr[5][5]`, then `arr[1][10]` over-indexes 
`arr[1]`, but points inside the full area of the matrix); but fortunately this 
is not a fatal limitation (it only produces false negatives, multi-dimensional 
arrays are not too common).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150446

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


[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-04 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 547231.
Krishna-13-cyber added a comment.

- Addressed the comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,341 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+- The Automatic Printf feature makes it easy to display variable values 
+  during program execution.
+
+- The Value Synthesis feature helps store the execution results 
+  (to be able to bring them back to the compiled program).
+
+- The Pretty Printing feature helps create a temporary dump to display the value
+  and type (pretty print) of the desired data. 
+
+1. Automatic Printf
+===
+
+The `Automatic Printf` feature makes it easy to display variable values during 
+program execution. Using the `printf` function repeatedly is not required. 
+This is achieved using an extension in the `libclangInterpreter` library.
+
+To automatically print the value of an expression, simply write the expression 
+in the global scope **without a semicolon**.
+
+.. image:: autoprint.png
+   :align: center
+   :alt: autoprint design
+
+Examples
+
+.. code-block:: console
+
+clang-repl> int x = 42;
+clang-repl> x   // equivalent to calling printf("(int &) %d\n", x);
+(int &) 42
+
+clang-repl> std::vector v = {1,2,3};
+clang-repl> v  // This syntax is fine after D127284 
+(std::vector &) {1,2,3}
+
+clang-repl> "Hello, interactive C++!"
+(const char [24]) "Hello, interactive C++!"
+
+Significance of this feature
+
+
+Inspired by a similar implementation in `Cling `_,
+this feature added to upstream Clang repo has essentially extended the syntax of
+C++,so that it can be more helpful for people that are writing code for data 
+science applications.
+ 
+This is useful, for example, when you want to experiment with a set of values 
+against a set of functions, and you'd like to know the results right away. 
+This is similar to how Python works (hence its popularity in data science 
+research), but the superior performance of C++, along with this flexibility 
+makes it a more attractive option.
+
+Annotation Token (annot_repl_input_end)
+---
+
+This feature uses a new token (annot_repl_input_end) to consider printing the 
+value of an expression if it doesn't end with a semicolon. When parsing an 
+Expression Statement, if the last semicolon is missing, then the code will 
+pretend that there one and set a marker there for later utilization, and 
+continue parsing.
+
+A semicolon is normally required in C++, but this feature expands the C++ 
+syntax to handle cases where a missing semicolon is expected (i.e., when 
+handling an expression statement). It also makes sure that an error is not 
+generated for the missing semicolon in this specific case. 
+
+This is accomplished by identifying the end position of the user input 
+(expression statement). This helps store and return the expression statement 
+effectively, so that it can be printed (displayed to the user automatically).
+
+**Note:** This logic is only available for C++ for now, since part of the 
+implementation itself requires C++ features. Future versions may support more 
+languages.
+
+.. code-block:: console
+
+  Token *CurTok = nullptr;
+  // If the semicolon is missing at the end of REPL input, consider if
+  // we want to do value printing. Note this is only enabled in C++ mode
+  // since part of the implementation requires C++ language features.
+  // Note we shouldn't eat the token since the callback needs it.
+  if (Tok.is(tok::annot_repl_input_end) && Actions.getLangOpts().CPlusPlus)
+CurTok = 
+  else
+// Otherwise, eat the semicolon.
+ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
+
+  StmtResult R = handleExprStmt(Expr, StmtCtx);
+  if (CurTok && !R.isInvalid())
+CurTok->setAnnotationValue(R.get());
+
+  return R;
+}
+
+AST 

[PATCH] D156320: [FLang] Add support for Rpass flag

2023-08-04 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Hey @victorkingi , thank you for working on this :)

There's quite a lot going on here and I am thinking that it might be good to 
split this into a few patches? Also, please note that Flang's driver, unlike 
Clang, uses MLIR's coding style (use `camelCase` instead of `CamelCase`).

> A StandaloneBackendConsumer was implemented but the DiagnosticsEngine still 
> doesn't print to console the remarks produced.

This could mean that it's not being deconstructed correctly. Or that it 
requires explicit flushing. Can you verify that it contains the expected 
remarks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

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


[PATCH] D157104: [analyzer] Improve underflow handling in ArrayBoundV2

2023-08-04 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

Note: this commit is split off from the larger commit 
https://reviews.llvm.org/D150446, which combined this simple improvement with 
other, more complex changes that had problematic side-effects.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157104

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


[PATCH] D157104: [analyzer] Improve underflow handling in ArrayBoundV2

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

This minor change ensures that underflow errors are reported on arrays that are 
in unknown space but have well-defined size.

As a concrete example, the following test case did not produce a warning 
previously, but will produce a warning after this patch:

  typedef struct {
int id;
char name[256];
  } user_t;
  
  user_t *get_symbolic_user(void);
  char test_underflow_symbolic_2() {
user_t *user = get_symbolic_user();
return user->name[-1];
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157104

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/test/Analysis/out-of-bounds.c


Index: clang/test/Analysis/out-of-bounds.c
===
--- clang/test/Analysis/out-of-bounds.c
+++ clang/test/Analysis/out-of-bounds.c
@@ -151,11 +151,23 @@
 // Don't warn when indexing below the start of a symbolic region's whose
 // base extent we don't know.
 int *get_symbolic(void);
-void test_index_below_symboloc(void) {
+void test_underflow_symbolic(void) {
   int *buf = get_symbolic();
   buf[-1] = 0; // no-warning;
 }
 
+// But warn if we understand the internal memory layout of a symbolic region.
+typedef struct {
+  int id;
+  char name[256];
+} user_t;
+
+user_t *get_symbolic_user(void);
+char test_underflow_symbolic_2() {
+  user_t *user = get_symbolic_user();
+  return user->name[-1]; // expected-warning{{Out of bound memory access}}
+}
+
 void test_incomplete_struct(void) {
   extern struct incomplete incomplete;
   int *p = (int *)
@@ -173,4 +185,3 @@
   buf[x] = 1;
   clang_analyzer_eval(x <= 99); // expected-warning{{TRUE}}
 }
-
Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -172,13 +172,17 @@
 return;
 
   NonLoc ByteOffset = RawOffset->getByteOffset();
+  const SubRegion *Reg = RawOffset->getRegion();
 
   // CHECK LOWER BOUND
-  const MemSpaceRegion *SR = RawOffset->getRegion()->getMemorySpace();
-  if (!llvm::isa(SR)) {
-// A pointer to UnknownSpaceRegion may point to the middle of
-// an allocated region.
-
+  const MemSpaceRegion *Space = Reg->getMemorySpace();
+  if (!(isa(Reg) && isa(Space))) {
+// A symbolic region in unknown space represents an unknown pointer that
+// may point into the middle of an array, so we don't look for underflows.
+// Both conditions are significant because we want to check underflows in
+// symbolic regions on the heap (which may be introduced by checkers that
+// call SValBuilder::getConjuredHeapSymbolVal()) and non-symbolic regions
+// (e.g. a field subregion of a symbolic region) in unknown space.
 auto [state_precedesLowerBound, state_withinLowerBound] =
 compareValueToThreshold(state, ByteOffset,
 svalBuilder.makeZeroArrayIndex(), svalBuilder);
@@ -195,7 +199,7 @@
 
   // CHECK UPPER BOUND
   DefinedOrUnknownSVal Size =
-  getDynamicExtent(state, RawOffset->getRegion(), svalBuilder);
+  getDynamicExtent(state, Reg, svalBuilder);
   if (auto KnownSize = Size.getAs()) {
 auto [state_withinUpperBound, state_exceedsUpperBound] =
 compareValueToThreshold(state, ByteOffset, *KnownSize, svalBuilder);


Index: clang/test/Analysis/out-of-bounds.c
===
--- clang/test/Analysis/out-of-bounds.c
+++ clang/test/Analysis/out-of-bounds.c
@@ -151,11 +151,23 @@
 // Don't warn when indexing below the start of a symbolic region's whose
 // base extent we don't know.
 int *get_symbolic(void);
-void test_index_below_symboloc(void) {
+void test_underflow_symbolic(void) {
   int *buf = get_symbolic();
   buf[-1] = 0; // no-warning;
 }
 
+// But warn if we understand the internal memory layout of a symbolic region.
+typedef struct {
+  int id;
+  char name[256];
+} user_t;
+
+user_t *get_symbolic_user(void);
+char test_underflow_symbolic_2() {
+  user_t *user = get_symbolic_user();
+  return user->name[-1]; // expected-warning{{Out of bound memory access}}
+}
+
 void test_incomplete_struct(void) {
   extern struct incomplete incomplete;
   int *p = (int *)
@@ -173,4 +185,3 @@
   buf[x] = 1;
   clang_analyzer_eval(x <= 99); // expected-warning{{TRUE}}
 }
-
Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-08-04 Thread Corentin Jabot 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 rGa8bef8865e4a: [Clang] Implement P2169 A nice placeholder 
with no name (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/unicode.c
  clang/test/SemaCXX/anonymous-union-export.cpp
  clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -150,7 +150,7 @@
  
   Placeholder variables with no name
   https://wg21.link/P2169R4;>P2169R4
-  No
+  Clang 18
  
 
 
Index: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
@@ -0,0 +1,254 @@
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused -Wpre-c++26-compat %s
+
+void static_var() {
+static int _; // expected-note {{previous definition is here}} \
+  // expected-note {{candidate}}
+static int _; // expected-error {{redefinition of '_'}}
+int _;// expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
+  // expected-note {{candidate}}
+_++; // expected-error{{reference to '_' is ambiguous}}
+}
+
+void static_var_2() {
+int _; // expected-note {{previous definition is here}}
+static int _; // expected-error {{redefinition of '_'}}
+}
+
+void bindings() {
+int arr[4] = {0, 1, 2, 3};
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}} \
+ // expected-note 4{{placeholder declared here}}
+_ == 42; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+{
+// no extension warning as we only introduce a single placeholder.
+auto [_, a, b, c] = arr; // expected-warning {{unused variable '[_, a, b, c]'}}
+}
+{
+auto [_, _, b, c] = arr; // expected-warning {{unused variable '[_, _, b, c]'}} \
+ // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
+}
+{
+// There are only 3 extension warnings because the first
+// introduction of `_` is valid in all C++ standards
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}}
+}
+}
+
+namespace StaticBindings {
+
+int arr[2] = {0, 1};
+static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
+  // expected-note  {{previous definition is here}}
+
+void f() {
+int arr[2] = {0, 1};
+static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
+// expected-note  {{previous definition is here}}
+}
+
+}
+
+void lambda() {
+(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
+   // expected-note 4{{placeholder declared here}}
+(void)_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+};
+
+{
+int _ = 12;
+(void)[_ = 0]{}; // no warning (different scope)
+}
+}
+
+namespace global_var {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+namespace {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+
+namespace global_fun {
+void _();
+void _();
+
+void _() {} // expected-note {{previous definition is here}}
+void _() {} // expected-error {{redefinition of '_'}}
+void _(int){}
+}
+
+typedef int _;
+typedef int _; // Type redeclaration, nothing to do with placeholders
+
+void extern_test() {
+extern int _;
+extern int _; // expected-note {{candidate}}
+int _; //expected-note {{candidate}}
+_++; // expected-error 

[clang] a8bef88 - [Clang] Implement P2169 A nice placeholder with no name

2023-08-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-04T16:51:15+02:00
New Revision: a8bef8865e4a4226ee608df327fddd380870c620

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

LOG: [Clang] Implement P2169 A nice placeholder with no name

This is a C++ feature that allows the use of `_` to
declare multiple variable of that name in the same scope;
these variables can then not be referred to.

In addition, while P2169 does not extend to parameter
declarations, we stop warning on unused parameters of that name,
for consistency.

The feature is backported to all C++ language modes.

Reviewed By: #clang-language-wg, aaron.ballman

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

Added: 
clang/test/SemaCXX/cxx2c-placeholder-vars.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Sema/Lookup.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaLookup.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/Lexer/unicode.c
clang/test/SemaCXX/anonymous-union-export.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a98ad496d22498..46a7aff15da9dc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -66,6 +66,26 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Implemented `P2169R4: A nice placeholder with no name 
`_. This allows using ``_``
+  as a variable name multiple times in the same scope and is supported in all 
C++ language modes as an extension.
+  An extension warning is produced when multiple variables are introduced by 
``_`` in the same scope.
+  Unused warnings are no longer produced for variables named ``_``.
+  Currently, inspecting placeholders variables in a debugger when more than 
one are declared in the same scope
+  is not supported.
+
+  .. code-block:: cpp
+struct S {
+  int _, _; // Was invalid, now OK
+};
+void func() {
+  int _, _; // Was invalid, now OK
+}
+void other() {
+  int _; // Previously diagnosed under -Wunused, no longer diagnosed
+}
+
+
+
 Resolutions to C++ Defect Reports
 ^
 

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 788f6ab97b1bbf..f6e38e5c57440d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -452,6 +452,8 @@ class NamedDecl : public Decl {
 return hasCachedLinkage();
   }
 
+  bool isPlaceholderVar(const LangOptions ) const;
+
   /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
   /// the underlying named decl.
   NamedDecl *getUnderlyingDecl() {

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b531babf0449c4..4979f9f86d236d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6611,6 +6611,16 @@ def warn_atomic_member_access : Warning<
   InGroup>, DefaultError;
 
 // Expressions.
+def err_using_placeholder_variable : Error<
+  "ambiguous reference to placeholder '_', which is defined multiple times">;
+def note_reference_placeholder : Note<
+  "placeholder declared here">;
+def ext_placeholder_var_definition : ExtWarn<
+  "placeholder variables are a C++2c extension">, InGroup;
+def warn_cxx23_placeholder_var_definition : Warning<
+  "placeholder variables are incompatible with C++ standards before C++2c">,
+  DefaultIgnore, InGroup;
+
 def ext_sizeof_alignof_function_type : Extension<
   "invalid application of '%0' to a function type">, InGroup;
 def ext_sizeof_alignof_void_type : Extension<

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index f87f7671481579..1a1ffddf2b1c60 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -504,6 +504,9 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// If the identifier is an "uglified" reserved name, return a cleaned form.
   /// e.g. _Foo => Foo. Otherwise, just returns the name.
   StringRef deuglifiedName() const;
+  bool isPlaceholder() const {
+return getLength() == 1 && getNameStart()[0] == 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-08-04 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 547206.
cor3ntin marked an inline comment as done.
cor3ntin added a comment.

Fix nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/unicode.c
  clang/test/SemaCXX/anonymous-union-export.cpp
  clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -150,7 +150,7 @@
  
   Placeholder variables with no name
   https://wg21.link/P2169R4;>P2169R4
-  No
+  Clang 18
  
 
 
Index: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
@@ -0,0 +1,254 @@
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused -Wpre-c++26-compat %s
+
+void static_var() {
+static int _; // expected-note {{previous definition is here}} \
+  // expected-note {{candidate}}
+static int _; // expected-error {{redefinition of '_'}}
+int _;// expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
+  // expected-note {{candidate}}
+_++; // expected-error{{reference to '_' is ambiguous}}
+}
+
+void static_var_2() {
+int _; // expected-note {{previous definition is here}}
+static int _; // expected-error {{redefinition of '_'}}
+}
+
+void bindings() {
+int arr[4] = {0, 1, 2, 3};
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}} \
+ // expected-note 4{{placeholder declared here}}
+_ == 42; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+{
+// no extension warning as we only introduce a single placeholder.
+auto [_, a, b, c] = arr; // expected-warning {{unused variable '[_, a, b, c]'}}
+}
+{
+auto [_, _, b, c] = arr; // expected-warning {{unused variable '[_, _, b, c]'}} \
+ // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
+}
+{
+// There are only 3 extension warnings because the first
+// introduction of `_` is valid in all C++ standards
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}}
+}
+}
+
+namespace StaticBindings {
+
+int arr[2] = {0, 1};
+static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
+  // expected-note  {{previous definition is here}}
+
+void f() {
+int arr[2] = {0, 1};
+static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
+// expected-note  {{previous definition is here}}
+}
+
+}
+
+void lambda() {
+(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
+   // expected-note 4{{placeholder declared here}}
+(void)_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+};
+
+{
+int _ = 12;
+(void)[_ = 0]{}; // no warning (different scope)
+}
+}
+
+namespace global_var {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+namespace {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+
+namespace global_fun {
+void _();
+void _();
+
+void _() {} // expected-note {{previous definition is here}}
+void _() {} // expected-error {{redefinition of '_'}}
+void _(int){}
+}
+
+typedef int _;
+typedef int _; // Type redeclaration, nothing to do with placeholders
+
+void extern_test() {
+extern int _;
+extern int _; // expected-note {{candidate}}
+int _; //expected-note {{candidate}}
+_++; // expected-error {{reference to '_' is ambiguous}}
+}
+
+
+struct Members {
+int _; // expected-note 2{{placeholder declared here}}
+

[PATCH] D157093: [clangd][clang-tidy][stdlib] Add a missing symbol to the mapping.

2023-08-04 Thread Viktoriia Bakalova 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 rG5d492766a8fb: [clangd][clang-tidy][stdlib] Add a missing 
symbol to the mapping. (authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157093

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -360,6 +360,10 @@
 SYMBOL(make_index_sequence, std::, )
 SYMBOL(make_integer_sequence, std::, )
 
+// Symbols missing from the generated symbol map as reported by users.
+// Remove when the generator starts producing them.
+SYMBOL(make_any, std::, )
+
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"
 // text, which are not handled by the script.


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -360,6 +360,10 @@
 SYMBOL(make_index_sequence, std::, )
 SYMBOL(make_integer_sequence, std::, )
 
+// Symbols missing from the generated symbol map as reported by users.
+// Remove when the generator starts producing them.
+SYMBOL(make_any, std::, )
+
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, ..., _N"
 // text, which are not handled by the script.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5d49276 - [clangd][clang-tidy][stdlib] Add a missing symbol to the mapping.

2023-08-04 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-08-04T14:15:01Z
New Revision: 5d492766a8fbfadb39c9830ebb64137edddfe0e5

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

LOG: [clangd][clang-tidy][stdlib] Add a missing symbol to the mapping.

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

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index ae620a0b995816..aa0bc50445f473 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -360,6 +360,10 @@ SYMBOL(index_sequence_for, std::, )
 SYMBOL(make_index_sequence, std::, )
 SYMBOL(make_integer_sequence, std::, )
 
+// Symbols missing from the generated symbol map as reported by users.
+// Remove when the generator starts producing them.
+SYMBOL(make_any, std::, )
+
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"
 // text, which are not handled by the script.



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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.
Herald added a subscriber: wangpc.

I've not spotted any major concerns with this patch, but I did have some minor 
nits to look into. I'd love to hear from @rsmith and @erichkeane before signing 
off on this, as the changes are pretty involved and they've both done some 
in-depth looks at the patch already.




Comment at: clang/include/clang/AST/TemplateBase.h:168-173
+  void initFromType(QualType, bool isNullPtr, bool IsDefaulted);
+  void initFromDeclaration(ValueDecl *, QualType, bool IsDefaulted);
+  void initFromIntegral(const ASTContext &, const llvm::APSInt &, QualType,
+bool IsDefaulted);
+  void initFromStructural(const ASTContext &, QualType, const APValue &,
+  bool IsDefaulted);

Can you add parameter names for the unnamed ones (we typically only leave a 
parameter unnamed when it is unused).



Comment at: clang/include/clang/AST/TemplateBase.h:382-385
+  /// Get the value of an StructuralValue.
+  const APValue () const { return *Value.Value; }
+
+  /// Get the type of an StructuralValue.





Comment at: clang/lib/AST/MicrosoftMangle.cpp:1624-1626
+  return const_cast(
+  V.getLValueBase().dyn_cast());
+}

Does this work or is the `const_cast` actually required?



Comment at: clang/lib/AST/ODRHash.cpp:1324-1327
+if (auto *AT = TypeSoFar->getAsArrayTypeUnsafe()) {
+  if (auto *CAT = dyn_cast(AT))
+OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
+  TypeSoFar = AT->getElementType();





Comment at: clang/lib/AST/ODRHash.cpp:1330
+  const Decl *D = E.getAsBaseOrMember().getPointer();
+  if (auto *FD = dyn_cast(D)) {
+if (FD->getParent()->isUnion())





Comment at: clang/lib/AST/ODRHash.cpp:1341-1342
+}
+ID.AddInteger((Value.isNullPointer() ? 1 : 0) | (OnePastTheEnd ? 2 : 0) |
+  (Value.hasLValuePath() ? 4 : 0));
+break;

I think this might be a bit clearer, but I don't insist on the change.



Comment at: clang/lib/AST/TemplateBase.cpp:163
 
-TemplateArgument::TemplateArgument(ASTContext , const llvm::APSInt ,
-   QualType Type, bool IsDefaulted) {
+void TemplateArgument::initFromType(QualType T, bool isNullPtr,
+bool IsDefaulted) {





Comment at: clang/lib/AST/TemplateBase.cpp:408-409
   case Integral:
-getAsIntegral().Profile(ID);
 getIntegralType().Profile(ID);
+getAsIntegral().Profile(ID);
+break;

Why did the order of these calls change?



Comment at: clang/lib/AST/TemplateBase.cpp:619
+  case TemplateArgument::UncommonValue: {
+// FIXME: We're guessing at LangOptions!
+SmallString<32> Str;

bolshakov-a wrote:
> erichkeane wrote:
> > aaron.ballman wrote:
> > > It's probably okay enough, but this is now the third instance of adding 
> > > the same bug to this helper method -- maybe we should fix that instead?
> > Agreed, seems to me we should do the work NOW to just wire in the lang-opts 
> > to this function.
> The problem here is because this function is called from a stream insertion 
> operator, and there isn't obviously any way to pass 3rd parameter into it 
> without switching it into an ordinary function.
Okay, that's reasonable enough to hold off on changing. Thanks!



Comment at: clang/lib/Sema/SemaOverload.cpp:5983-5985
+  Expr *E = Result.get();
+  if (!isa(E))
+E = ConstantExpr::Create(S.Context, Result.get(), Value);

I thought we could run into situations where we had a `ConstantExpr` but it did 
not yet have its result stored in it. Should we assert that isn't the case here?



Comment at: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp:56
+using CF = ComplexFloat<1.0f + 3.0fi>;
+using CF = ComplexFloat<3.0fi + 1.0f>;
 

bolshakov-a wrote:
> shafik wrote:
> > Can we add an enum example e.g.:
> > 
> > ```
> > enum E{ E1, E2};
> > template  struct SE {};
> > using IPE = SE;
> > using IPE = SE;
> > 
> > ```
> What for? Enumerators as non-type template arguments are allowed since C++98, 
> AFAIK. And this test is about changes in C++20.
Sometimes we're lacking coverage for existing features, so when updating code 
in the area, we'll sometimes ask for extra coverage just to be sure we're not 
regressing something we think might not have a lot of existing test coverage.



Comment at: clang/www/cxx_status.html:1061
+
+  Clang 17 (Partial)
+  Reference type template arguments referring to 
instantiation-dependent objects and subobjects




CHANGES SINCE LAST ACTION
  

[PATCH] D157093: [clangd][clang-tidy][stdlib] Add a missing symbol to the mapping.

2023-08-04 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: carlosgalvezp, kadircet, arphaman, xazax.hun.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157093

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -360,6 +360,10 @@
 SYMBOL(make_index_sequence, std::, )
 SYMBOL(make_integer_sequence, std::, )
 
+// Symbols missing from the generated symbol map as reported by users.
+// Remove when the generator starts producing them.
+SYMBOL(make_any, std::, )
+
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"
 // text, which are not handled by the script.


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -360,6 +360,10 @@
 SYMBOL(make_index_sequence, std::, )
 SYMBOL(make_integer_sequence, std::, )
 
+// Symbols missing from the generated symbol map as reported by users.
+// Remove when the generator starts producing them.
+SYMBOL(make_any, std::, )
+
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, ..., _N"
 // text, which are not handled by the script.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 16a0fc2 - Add my Discord, IRC, and Discourse handles

2023-08-04 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-08-04T09:12:14-04:00
New Revision: 16a0fc2bb81f1d66ff66f08053e45d8857afd66d

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

LOG: Add my Discord, IRC, and Discourse handles

Just in case there was confusion on how to reach me via these services.

Added: 


Modified: 
clang/CodeOwners.rst

Removed: 




diff  --git a/clang/CodeOwners.rst b/clang/CodeOwners.rst
index 672abd1acaaa15..820cb3cccd2ea7 100644
--- a/clang/CodeOwners.rst
+++ b/clang/CodeOwners.rst
@@ -19,7 +19,7 @@ assistance.
 All parts of Clang not covered by someone else
 --
 | Aaron Ballman
-| aaron\@aaronballman.com (email), aaron.ballman (Phabricator), AaronBallman 
(GitHub)
+| aaron\@aaronballman.com (email), aaron.ballman (Phabricator), AaronBallman 
(GitHub), AaronBallman (Discourse), aaronballman (Discord), AaronBallman (IRC)
 
 
 Contained Components
@@ -222,7 +222,7 @@ standard, when fixing standards bugs, or when implementing 
a new standard featur
 C conformance
 ~
 | Aaron Ballman
-| aaron\@aaronballman.com (email), aaron.ballman (Phabricator), AaronBallman 
(GitHub)
+| aaron\@aaronballman.com (email), aaron.ballman (Phabricator), AaronBallman 
(GitHub), AaronBallman (Discourse), aaronballman (Discord), AaronBallman (IRC)
 
 
 C++ conformance



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


[clang] 5d8bbe1 - Reword the intro to the code owners file

2023-08-04 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-08-04T09:09:53-04:00
New Revision: 5d8bbe196a0782f5e003e2ba080745b2111a22f0

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

LOG: Reword the intro to the code owners file

Instead of describing the job of a code owner within the code owners
file, link to where we describe code ownership for the project.

Added: 


Modified: 
clang/CodeOwners.rst

Removed: 




diff  --git a/clang/CodeOwners.rst b/clang/CodeOwners.rst
index d7f6b4e56a440f..672abd1acaaa15 100644
--- a/clang/CodeOwners.rst
+++ b/clang/CodeOwners.rst
@@ -2,10 +2,9 @@
 Clang Code Owners
 =
 
-This file is a list of the people responsible for ensuring that patches for a
-particular part of Clang are reviewed, either by themself or by someone else.
-They are also the gatekeepers for their part of Clang, with the final word on
-what goes in or not.
+This file is a list of the
+`code owners `_ for
+Clang.
 
 .. contents::
:depth: 2



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


[PATCH] D155610: [Clang][Sema] Fix display of characters on static assertion failure

2023-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:103-137
+- When describing the failure of static assertion of `==` expression, clang 
prints the integer
+  representation of the value as well as its character representation when
+  the user-provided expression is of character type. If the character is
+  non-printable, clang now shows the escpaed character.
+  Clang also prints multi-byte characters if the user-provided expression
+  is of multi-byte character type.
+

hazohelet wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > aaron.ballman wrote:
> > > > cor3ntin wrote:
> > > > > @aaron.ballman One one hand this is nice, on the other hand maybe too 
> > > > > detailed. What do you think?
> > > > I'm happy with it -- better too much detail than too little, but this 
> > > > really helps users see what's been improved and why it matters.
> > > > 
> > > > That said, I think `0x0A` and `0x1F30D` would arguably be better than 
> > > > printing the values in decimal. For `\n`, perhaps folks remember that 
> > > > it's decimal value 10, but nobody is going to know what `127757` means 
> > > > compared to the hex representation (esp because the value is specified 
> > > > in hex with the prefix printed in the error message). WDYT?
> > > For `wchar_t`, `charN_t` I think that makes sense.
> > > for `char`... hard to know, I think this is mostly useful for people who 
> > > treat char as some kind of integer. I could go either way. using hex 
> > > consistently seems reasonable
> > I don't insist on using hex, but I have a slight preference for using it 
> > consistently everywhere. CC @cjdb for more opinions since this relates to 
> > user experience of diagnostics.
> I generally agree that hex code would be better for characters.
> I think we still have some arguable points.
> 1. Should we print the unsigned code point or the (possibly signed) integer? 
> (e.g. `0xFF` vs `-0x01` for `(char)-1`, on targets where `char` is signed)
> 2. Should we print the hex code when the other subexpression of the `==` 
> expression is not a textual type? (e.g. `0x11` vs `17` for LHS of `(char)17 
> == 11`)
> 
> For 1, I think we should always print unsigned code point for all textual 
> types for consistency. Also we don't want to print `-0x3` for `L'\xFFFD'` on 
> targets where `wchar_t` is signed and 16-bit width (I haven't checked whether 
> that target exists, though).
> For 2, I want to see decimal (possibly signed) integer if the other side of 
> the expression is not textual type.
> Displaying `expression evaluates to ''' (0xFF) == 255'` for the following 
> code would be highly confusing.
> ```
> static_assert((char)-1 == (unsigned char)-1);
> ```
> WDYT?
> Should we print the unsigned code point or the (possibly signed) integer? 
> (e.g. 0xFF vs -0x01 for (char)-1, on targets where char is signed)

Personally, I find -0x01 to be kind of weird and I slightly prefer 0xFF.

> Should we print the hex code when the other subexpression of the == 
> expression is not a textual type? (e.g. 0x11 vs 17 for LHS of (char)17 == 11)

I don't have a strong opinion on this because I think we can come up with 
arguments for either approach. My intuition is that we should just use hex 
values everywhere, but others may have a different opinion.


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

https://reviews.llvm.org/D155610

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


[PATCH] D157090: [Flang][Sema] Move directive sets to a shared location

2023-08-04 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 547181.
skatrak added a comment.

Add missing newline at end of file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157090

Files:
  clang/docs/tools/clang-formatted-files.txt
  flang/include/flang/Semantics/openmp-directive-sets.h
  flang/lib/Semantics/CMakeLists.txt
  flang/lib/Semantics/check-omp-structure.cpp
  flang/lib/Semantics/check-omp-structure.h
  flang/lib/Semantics/openmp-directive-sets.cpp
  flang/lib/Semantics/resolve-directives.cpp

Index: flang/lib/Semantics/resolve-directives.cpp
===
--- flang/lib/Semantics/resolve-directives.cpp
+++ flang/lib/Semantics/resolve-directives.cpp
@@ -1345,7 +1345,7 @@
 if (targetIt == dirContext_.rend()) {
   return;
 }
-if (llvm::omp::parallelSet.test(targetIt->directive) ||
+if (llvm::omp::allParallelSet.test(targetIt->directive) ||
 llvm::omp::taskGeneratingSet.test(targetIt->directive)) {
   break;
 }
@@ -1446,7 +1446,7 @@
 return;
   }
   Symbol::Flag ivDSA;
-  if (!llvm::omp::simdSet.test(GetContext().directive)) {
+  if (!llvm::omp::allSimdSet.test(GetContext().directive)) {
 ivDSA = Symbol::Flag::OmpPrivate;
   } else if (level == 1) {
 ivDSA = Symbol::Flag::OmpLinear;
Index: flang/lib/Semantics/openmp-directive-sets.cpp
===
--- /dev/null
+++ flang/lib/Semantics/openmp-directive-sets.cpp
@@ -0,0 +1,270 @@
+//===-- lib/Semantics/openmp-directive-sets.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Semantics/openmp-directive-sets.h"
+
+//===--===//
+// Single directives
+//===--===//
+
+OmpDirectiveSet llvm::omp::topParallelSet{
+Directive::OMPD_parallel,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_sections,
+Directive::OMPD_parallel_workshare,
+};
+
+OmpDirectiveSet llvm::omp::allParallelSet{
+Directive::OMPD_distribute_parallel_do,
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_parallel,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_sections,
+Directive::OMPD_parallel_workshare,
+Directive::OMPD_target_parallel,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+};
+
+OmpDirectiveSet llvm::omp::topDoSet{
+Directive::OMPD_do,
+Directive::OMPD_do_simd,
+};
+
+OmpDirectiveSet llvm::omp::allDoSet{
+Directive::OMPD_distribute_parallel_do,
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_do,
+Directive::OMPD_do_simd,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+};
+
+OmpDirectiveSet llvm::omp::topTaskloopSet{
+Directive::OMPD_taskloop,
+Directive::OMPD_taskloop_simd,
+};
+
+OmpDirectiveSet llvm::omp::allTaskloopSet = llvm::omp::topTaskloopSet;
+
+OmpDirectiveSet llvm::omp::topTargetSet{
+Directive::OMPD_target,
+Directive::OMPD_target_parallel,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_simd,
+Directive::OMPD_target_teams,
+Directive::OMPD_target_teams_distribute,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_simd,
+};
+
+OmpDirectiveSet llvm::omp::allTargetSet = llvm::omp::topTargetSet;
+
+OmpDirectiveSet llvm::omp::topSimdSet{
+Directive::OMPD_simd,
+};
+
+OmpDirectiveSet llvm::omp::allSimdSet{
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_distribute_simd,
+Directive::OMPD_do_simd,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_simd,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_simd,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+

[PATCH] D157090: [Flang][Sema] Move directive sets to a shared location

2023-08-04 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak created this revision.
skatrak added reviewers: kiranchandramohan, jsjodin, domada, agozillon, 
TIFitis, raghavendhra.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
skatrak requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1, jdoerfert.
Herald added a project: clang.

This patch moves directive sets defined internally in Semantics to a header 
accessible by other stages of the compiler to enable reuse. Some sets are 
renamed/rearranged and others are lifted from local definitions to provide a 
single source of truth.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157090

Files:
  clang/docs/tools/clang-formatted-files.txt
  flang/include/flang/Semantics/openmp-directive-sets.h
  flang/lib/Semantics/CMakeLists.txt
  flang/lib/Semantics/check-omp-structure.cpp
  flang/lib/Semantics/check-omp-structure.h
  flang/lib/Semantics/openmp-directive-sets.cpp
  flang/lib/Semantics/resolve-directives.cpp

Index: flang/lib/Semantics/resolve-directives.cpp
===
--- flang/lib/Semantics/resolve-directives.cpp
+++ flang/lib/Semantics/resolve-directives.cpp
@@ -1345,7 +1345,7 @@
 if (targetIt == dirContext_.rend()) {
   return;
 }
-if (llvm::omp::parallelSet.test(targetIt->directive) ||
+if (llvm::omp::allParallelSet.test(targetIt->directive) ||
 llvm::omp::taskGeneratingSet.test(targetIt->directive)) {
   break;
 }
@@ -1446,7 +1446,7 @@
 return;
   }
   Symbol::Flag ivDSA;
-  if (!llvm::omp::simdSet.test(GetContext().directive)) {
+  if (!llvm::omp::allSimdSet.test(GetContext().directive)) {
 ivDSA = Symbol::Flag::OmpPrivate;
   } else if (level == 1) {
 ivDSA = Symbol::Flag::OmpLinear;
Index: flang/lib/Semantics/openmp-directive-sets.cpp
===
--- /dev/null
+++ flang/lib/Semantics/openmp-directive-sets.cpp
@@ -0,0 +1,270 @@
+//===-- lib/Semantics/openmp-directive-sets.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Semantics/openmp-directive-sets.h"
+
+//===--===//
+// Single directives
+//===--===//
+
+OmpDirectiveSet llvm::omp::topParallelSet{
+Directive::OMPD_parallel,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_sections,
+Directive::OMPD_parallel_workshare,
+};
+
+OmpDirectiveSet llvm::omp::allParallelSet{
+Directive::OMPD_distribute_parallel_do,
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_parallel,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_sections,
+Directive::OMPD_parallel_workshare,
+Directive::OMPD_target_parallel,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+};
+
+OmpDirectiveSet llvm::omp::topDoSet{
+Directive::OMPD_do,
+Directive::OMPD_do_simd,
+};
+
+OmpDirectiveSet llvm::omp::allDoSet{
+Directive::OMPD_distribute_parallel_do,
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_do,
+Directive::OMPD_do_simd,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+};
+
+OmpDirectiveSet llvm::omp::topTaskloopSet{
+Directive::OMPD_taskloop,
+Directive::OMPD_taskloop_simd,
+};
+
+OmpDirectiveSet llvm::omp::allTaskloopSet = llvm::omp::topTaskloopSet;
+
+OmpDirectiveSet llvm::omp::topTargetSet{
+Directive::OMPD_target,
+Directive::OMPD_target_parallel,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_simd,
+Directive::OMPD_target_teams,
+Directive::OMPD_target_teams_distribute,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_simd,
+};
+
+OmpDirectiveSet llvm::omp::allTargetSet = 

[PATCH] D156743: clang/OpenCL: Add inline implementations of sqrt in builtin header

2023-08-04 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Headers/opencl-c-base.h:832
+
+inline float __ovld __cnfn sqrt(float __x) {
+  return __builtin_elementwise_sqrt(__x);

arsenm wrote:
> svenvh wrote:
> > Anastasia wrote:
> > > Is this a generic implementation enough? Would some targets not need to 
> > > do something different for this built-in?
> > > 
> > > Ideally this header is to be kept light so I am a bit worried about 
> > > adding definitions of the functions here. Otherwise we will end up in the 
> > > same situation as we one day were with opencl-c.h. So could these be left 
> > > there instead? It might be good to check with @svenvh if TableGen header 
> > > has already a way to do this function forwarding or can be extended to do 
> > > such a thing. Then it would be implementable in the both header 
> > > mechanisms. I don't know if Sven has some other ideas or opinions...
> > We did already discuss this a bit on the GitHub issue: 
> > https://github.com/llvm/llvm-project/issues/64264
> As I mentioned on the ticket, it's only this one case so I'm not worried 
> about adding a lot more to the base header. I think we can start by assuming 
> llvm.sqrt always works correctly, I don't want to add more complexity to 
> handle this case without a specific reason
> As I mentioned on the ticket, it's only this one case so I'm not worried 
> about adding a lot more to the base header.

This is how things normally start. Someone else might want to continue this 
approach because it is already there.

>I think we can start by assuming llvm.sqrt always works correctly, I don't 
>want to add more complexity to handle this case without a specific reason

Do you mean it would apply to all implementations? What I am missing here is 
why it is required to be in the headers? Is this because it needs to be inlined 
or is it because the compiler must see `__builtin_elementwise_sqrt` with the 
surrounding code where it is called from?


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

https://reviews.llvm.org/D156743

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-04 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Is this patch to support `thread_limit` on `target` directive on the host?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

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

LGTM aside from some minor tweaks (some extra parens to remove, a spurious 
comment to remove).




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:4359
+  llvm::find_if(Result, [this](const NamedDecl *Elem) {
+return (isa(Elem)) &&
+   Elem->isPlaceholderVar(getLangOpts());





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:4370
+  break;
+if ((isa(ND)) &&
+ND->isPlaceholderVar(getLangOpts()))





Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:1-2
+///
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused -Wpre-c++26-compat %s
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D150646: [clang][X86] Add __cpuidex function to cpuid.h

2023-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: jdoerfert, ABataev, rnk.
aaron.ballman added a comment.

In D150646#4558543 , @aidengrossman 
wrote:

> I'm not opposed to a revert, but I know some downstream users like MinGW have 
> already adapted to this change so I'm not sure how much headache it would 
> cause them to do a revert.
>
> Maybe I'm not understanding things correctly, but I originally 
> `_MSC_EXTENSIONS` patch as people were enabling the microsoft extensions 
> (thus enabling the builtin) and still including `cpuid.h` which caused an 
> error due to redefining a builtin function. There seems to be another issue 
> there where multiple flags need to be set (`-fms-extensions`, 
> `-fms-compatibility`, and `fms-compatibility-version`) in order to get 
> `_MSC_EXTENSIONS` defined while only passing `fms-extensions` gets the 
> builtin defined, but not the macro. I'm not sure if just passing 
> `-fms-extensions` is even a valid configuration, but it does error out then. 
> I believe that's a separate issue to the auxiliary triple issue you mentioned.

Separating threads a bit:

- Regarding removing the `_MSC_EXTENSIONS` check -- you're right, that was a 
think-o suggestion on my part, we still need that to guard the definition in 
the header file. Sorry for that!
- Regarding when `_MSC_EXTENSIONS` is defined -- I think it's possibly a 
mistake that we don't define that when passing `-fms-extensions`. 
`-fms-extensions` is intended to control whether we support extensions to MSVC, 
such as use of `__declspec` attributes. And `-fms-compatibility` is intended to 
control whether we're trying to be compatible with MSVC rather than be 
compatible with GCC or the standards. Passing `-fms-compatibility` 
automatically adds `-fms-extensions`. I think the issue is here: 
https://github.com/llvm/llvm-project/blob/a6d673070963ed0900bd33963a9b62add07339f4/clang/lib/Basic/Targets/OSTargets.cpp#L265
 -- we're looking for `MSVCCompat` to decide what macros to define, and only if 
we're in compatibility mode and enabled extensions do we enable 
`_MSC_EXTENSIONS` here 
https://github.com/llvm/llvm-project/blob/a6d673070963ed0900bd33963a9b62add07339f4/clang/lib/Basic/Targets/OSTargets.cpp#L229
 -- I think it might be reasonable for us to lift the `_MSC_EXTENSIONS` logic 
out so it's not controlled by `MSVCCompat`, wdyt @rnk? (That's a separate 
concern from this patch though.)
- A revert would be appreciated so that we have time to untangle the actual 
root cause of the problems we're seeing at Intel where the wrong set of 
builtins are being enabled for offload targets. That's not caused by your 
patch, but your patch is causing us to hit the issue when we previously hadn't 
been hitting it. However, if it's quicker/easier for someone to fix that 
problem instead of doing a revert, that'd be even better -- but I do worry 
about timing given that we just cut the Clang 17 branch.  CC @ABataev 
@jdoerfert as they may have seen this problem (https://godbolt.org/z/8Yq1vzEnT) 
with offload targets before and have opinions/ideas as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150646

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


[PATCH] D156728: [Sema] Ignore nullability qualifiers when deducing types for `auto` and `__auto_type`

2023-08-04 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:3933
   //   type are ignored for type deduction.
+  // Ignore top level nullability qualifiers too.
   ArgType = ArgType.getUnqualifiedType();

ahatanak wrote:
> gribozavr2 wrote:
> > This comment merely duplicates the code. Please add an explanation why it 
> > is done.
> I guess we were dropping the nullability qualifiers for the same reason we 
> drop cv qualifiers. The new variable declared with `auto` is a separate 
> variable, so it doesn't inherit the qualifiers the argument type.
> 
> Of course, I'm assuming that's the rule we want, but I'm not sure as 
> nullability qualifiers aren't part of the C/C++ standards.
> I guess we were dropping the nullability qualifiers for the same reason we 
> drop cv qualifiers.

I don't think that argument applies. If the null dereference warning was flow 
sensitive, we would want to do exactly the opposite - that is, preserve 
nullability qualifiers during deduction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156728

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


[PATCH] D155610: [Clang][Sema] Fix display of characters on static assertion failure

2023-08-04 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:103-137
+- When describing the failure of static assertion of `==` expression, clang 
prints the integer
+  representation of the value as well as its character representation when
+  the user-provided expression is of character type. If the character is
+  non-printable, clang now shows the escpaed character.
+  Clang also prints multi-byte characters if the user-provided expression
+  is of multi-byte character type.
+

aaron.ballman wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > cor3ntin wrote:
> > > > @aaron.ballman One one hand this is nice, on the other hand maybe too 
> > > > detailed. What do you think?
> > > I'm happy with it -- better too much detail than too little, but this 
> > > really helps users see what's been improved and why it matters.
> > > 
> > > That said, I think `0x0A` and `0x1F30D` would arguably be better than 
> > > printing the values in decimal. For `\n`, perhaps folks remember that 
> > > it's decimal value 10, but nobody is going to know what `127757` means 
> > > compared to the hex representation (esp because the value is specified in 
> > > hex with the prefix printed in the error message). WDYT?
> > For `wchar_t`, `charN_t` I think that makes sense.
> > for `char`... hard to know, I think this is mostly useful for people who 
> > treat char as some kind of integer. I could go either way. using hex 
> > consistently seems reasonable
> I don't insist on using hex, but I have a slight preference for using it 
> consistently everywhere. CC @cjdb for more opinions since this relates to 
> user experience of diagnostics.
I generally agree that hex code would be better for characters.
I think we still have some arguable points.
1. Should we print the unsigned code point or the (possibly signed) integer? 
(e.g. `0xFF` vs `-0x01` for `(char)-1`, on targets where `char` is signed)
2. Should we print the hex code when the other subexpression of the `==` 
expression is not a textual type? (e.g. `0x11` vs `17` for LHS of `(char)17 == 
11`)

For 1, I think we should always print unsigned code point for all textual types 
for consistency. Also we don't want to print `-0x3` for `L'\xFFFD'` on targets 
where `wchar_t` is signed and 16-bit width (I haven't checked whether that 
target exists, though).
For 2, I want to see decimal (possibly signed) integer if the other side of the 
expression is not textual type.
Displaying `expression evaluates to ''' (0xFF) == 255'` for the following 
code would be highly confusing.
```
static_assert((char)-1 == (unsigned char)-1);
```
WDYT?


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

https://reviews.llvm.org/D155610

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


[PATCH] D154951: [clang][Interp] __builtin_bit_cast, Take 2

2023-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/InterpBitcast.cpp:71
+/// All offsets are in bytes.
+struct ByteTracker {
+  std::vector Initialized;

tbaeder wrote:
> aaron.ballman wrote:
> > Don't we need to track this at the *bit* level instead of the *byte* level? 
> > e.g., padding bits in structures, anonymous bit-fields, `bool`, `_BitInt`, 
> > etc?
> I actually started doing it in bits, but later realized that I can't use that 
> since I have little support for bitfields and the current interpreter doesn't 
> support bitcasts between bitfields. (That's why it's still 
> `IndeterminateBits` down in `BitcastBuffer`).
I think we have to do it at the bit level if we want to conform to the 
standard, so perhaps the best path forward is to work on bitfield support 
first, then come back to bitcast?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154951

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


[PATCH] D157011: [Clang][Tooling] Accept preprocessed input files

2023-08-04 Thread J. Ryan Stinnett via Phabricator via cfe-commits
jryans updated this revision to Diff 547159.
jryans added a comment.

- Fixed formatting
- Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157011

Files:
  clang/lib/Tooling/Tooling.cpp
  clang/unittests/Tooling/ToolingTest.cpp


Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -449,6 +449,13 @@
   EXPECT_NE(extractCC1Arguments(Args), nullptr);
 }
 
+TEST_F(CommandLineExtractorTest, AcceptPreprocessedInputFile) {
+  addFile("test.i", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0", "-c",
+"test.i"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
 TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
   addFile("test.c", "int main() {}\n");
   const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -147,6 +147,13 @@
 if (IsCC1Command(Job) && llvm::all_of(Job.getInputInfos(), IsSrcFile))
   CC1Jobs.push_back();
 
+  // If there are no jobs for source files, try checking again for a single job
+  // with any file type. This accepts a preprocessed file as input.
+  if (CC1Jobs.empty())
+for (const driver::Command  : Jobs)
+  if (IsCC1Command(Job))
+CC1Jobs.push_back();
+
   if (CC1Jobs.empty() ||
   (CC1Jobs.size() > 1 && !ignoreExtraCC1Commands(Compilation))) {
 SmallString<256> error_msg;


Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -449,6 +449,13 @@
   EXPECT_NE(extractCC1Arguments(Args), nullptr);
 }
 
+TEST_F(CommandLineExtractorTest, AcceptPreprocessedInputFile) {
+  addFile("test.i", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0", "-c",
+"test.i"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
 TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
   addFile("test.c", "int main() {}\n");
   const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -147,6 +147,13 @@
 if (IsCC1Command(Job) && llvm::all_of(Job.getInputInfos(), IsSrcFile))
   CC1Jobs.push_back();
 
+  // If there are no jobs for source files, try checking again for a single job
+  // with any file type. This accepts a preprocessed file as input.
+  if (CC1Jobs.empty())
+for (const driver::Command  : Jobs)
+  if (IsCC1Command(Job))
+CC1Jobs.push_back();
+
   if (CC1Jobs.empty() ||
   (CC1Jobs.size() > 1 && !ignoreExtraCC1Commands(Compilation))) {
 SmallString<256> error_msg;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154951: [clang][Interp] __builtin_bit_cast, Take 2

2023-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/InterpBitcast.cpp:71
+/// All offsets are in bytes.
+struct ByteTracker {
+  std::vector Initialized;

aaron.ballman wrote:
> Don't we need to track this at the *bit* level instead of the *byte* level? 
> e.g., padding bits in structures, anonymous bit-fields, `bool`, `_BitInt`, 
> etc?
I actually started doing it in bits, but later realized that I can't use that 
since I have little support for bitfields and the current interpreter doesn't 
support bitcasts between bitfields. (That's why it's still `IndeterminateBits` 
down in `BitcastBuffer`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154951

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


[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-04 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

The summary tells nothing about what is the real problem to fix here. In the 
lit test I see that an error message is displayed, this causes the test 
failure. The problem is that the structural equivalence check is not good for 
this special case. The imported AST contains a class template specialization 
for `A`, in this specialization the friend class template `A` has a previous 
decl that points to the original friend class template that is in a 
`ClassTemplateDecl`. In the specialization the "depth" of template arguments is 
0, but in the original template it is 1 (the "to" code at import contains only 
the "original template", no specialization). This difference in the "depth" 
causes the type mismatch when the specialization is imported.
AST dump of this code can show the problem:

  template
  class A;
  
  template
  class A {
  public:
template
friend class A;
  
A(T x):x(x){}

  private:
T x;
  };
  
  A a1(0);

It is really interesting that at friend templates the depth is 1 but friend 
declarations point to objects outside the class, so really the depth should not 
increase in a friend template from this point of view. But this is an AST issue.




Comment at: clang/lib/AST/ASTImporter.cpp:5829
+!IsStructuralMatch(D, FoundTemplate, false))
+  continue;
 if (IsStructuralMatch(D, FoundTemplate)) {

It is not good to use `ParentMap` in the AST importer because it does AST 
traversal, even worse if this is done on the To context where the AST is 
modified and may be in incomplete state.
This way of fix is probably not good for a case when there is a real structural 
in-equivalence, this would be not detected. And the current solution skips this 
`FoundDecl` but (at least in the used test code) this should be found, not 
skipped. (But we can create code where the skip is correct, if there is a real 
structural in-equivalence.)




Comment at: clang/unittests/AST/ASTImporterTest.cpp:4218
+  R"(
+namespace __1{
+

I think the `namespace __1` is not important for reproduction of this problem.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4234
+  int j=1/i;
+  (void)j;
+}

Functions `foo`, `bar`, `main` are not required. It is only important to have a 
variable of type `A` like `A a1(0);` in the imported code at getTuDecl.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4247
+  }
+  )",
+  Lang_CXX11);

The coding format should be aligned to the format of other test codes in this 
file, and this is normally same as the clang format guidelines (automatic 
reformatting does not work in the test code).



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4284
+  Lang_CXX11, "input1.cc");
+  auto *Definition = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("A")));

`Definition` is misleading because this is not the definition, it matches the 
first declaration of `A` in the AST. Better name is like `FromA` like in the 
other tests, or FromXxx.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4286
+  FromTU, classTemplateDecl(hasName("A")));
+  auto *Template = Import(Definition, Lang_CXX11);
+  EXPECT_TRUE(Template);

The imported name can be `ToA` or ToXxx or ImportedXxx, this makes real 
distinction between the from and to objects.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4288
+  EXPECT_TRUE(Template);
+  auto *TemplateClass = cast(Template);
+  EXPECT_EQ(Fwd->getTemplatedDecl()->getTypeForDecl(),

This cast is not needed, type of `Template` is already `ClassTemplateDecl*`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-04 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky added a comment.

In D156693#4560023 , @Michael137 
wrote:

> Could you please elaborate in the commit message what exactly the issue 
> currently is and how the patch addresses it?



In D156693#4560023 , @Michael137 
wrote:

> Could you please elaborate in the commit message what exactly the issue 
> currently is and how the patch addresses it?

details are added to commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D157080: [clangd] Symbol search includes parameter types for (member) functions

2023-08-04 Thread Florian Humblot via Phabricator via cfe-commits
florianhumblot updated this revision to Diff 547150.
florianhumblot added a comment.

Forgot to update the tests.


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

https://reviews.llvm.org/D157080

Files:
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/test/symbols.test


Index: clang-tools-extra/clangd/test/symbols.test
===
--- clang-tools-extra/clangd/test/symbols.test
+++ clang-tools-extra/clangd/test/symbols.test
@@ -36,7 +36,7 @@
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "void ()",
 # CHECK-NEXT:"kind": 12,
-# CHECK-NEXT:"name": "foo",
+# CHECK-NEXT:"name": "foo()",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": {{.*}},
@@ -61,7 +61,7 @@
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int ()",
 # CHECK-NEXT:"kind": 12,
-# CHECK-NEXT:"name": "main",
+# CHECK-NEXT:"name": "main()",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": {{.*}},
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -895,8 +895,16 @@
 {"range", S.range},
 {"selectionRange", S.selectionRange}};
 
-  if (!S.detail.empty())
+  if (!S.detail.empty()) {
+if (S.kind == SymbolKind::Method || S.kind == SymbolKind::Function) {
+  llvm::StringRef Detail{S.detail};
+  const auto Start = Detail.find_first_of('(');
+  const auto End = Detail.find_last_of(')');
+  const auto Distance = End - Start;
+  Result["name"] = S.name + Detail.substr(Start, Distance).str() + ')';
+}
 Result["detail"] = S.detail;
+  }
   if (!S.children.empty())
 Result["children"] = S.children;
   if (S.deprecated)


Index: clang-tools-extra/clangd/test/symbols.test
===
--- clang-tools-extra/clangd/test/symbols.test
+++ clang-tools-extra/clangd/test/symbols.test
@@ -36,7 +36,7 @@
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "void ()",
 # CHECK-NEXT:"kind": 12,
-# CHECK-NEXT:"name": "foo",
+# CHECK-NEXT:"name": "foo()",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": {{.*}},
@@ -61,7 +61,7 @@
 # CHECK-NEXT:  {
 # CHECK-NEXT:"detail": "int ()",
 # CHECK-NEXT:"kind": 12,
-# CHECK-NEXT:"name": "main",
+# CHECK-NEXT:"name": "main()",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": {{.*}},
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -895,8 +895,16 @@
 {"range", S.range},
 {"selectionRange", S.selectionRange}};
 
-  if (!S.detail.empty())
+  if (!S.detail.empty()) {
+if (S.kind == SymbolKind::Method || S.kind == SymbolKind::Function) {
+  llvm::StringRef Detail{S.detail};
+  const auto Start = Detail.find_first_of('(');
+  const auto End = Detail.find_last_of(')');
+  const auto Distance = End - Start;
+  Result["name"] = S.name + Detail.substr(Start, Distance).str() + ')';
+}
 Result["detail"] = S.detail;
+  }
   if (!S.children.empty())
 Result["children"] = S.children;
   if (S.deprecated)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157074: [clang][ExprConst] Add RHS source range to div by zero diags

2023-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:2835
 if (RHS == 0) {
-  Info.FFDiag(E, diag::note_expr_divide_by_zero);
+  Info.FFDiag(E, diag::note_expr_divide_by_zero) << RHSRange;
   return false;

cor3ntin wrote:
> Why not just use ` E->getRHS()->getSourceRange()` here? It avoids an extra 
> param
I thought there are cases where `E` is not a `BinaryOperator`, but that was 
wrong, thanks.


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

https://reviews.llvm.org/D157074

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


[PATCH] D157074: [clang][ExprConst] Add RHS source range to div by zero diags

2023-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 547145.

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

https://reviews.llvm.org/D157074

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.h
  clang/test/Misc/constexpr-source-ranges.cpp


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -23,3 +23,16 @@
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
 // CHECK: constexpr-source-ranges.cpp:24:23:{24:23-24:39}
+
+
+constexpr int zero() {
+  return 0;
+}
+constexpr int divByZero() {
+  return 1 / zero();
+}
+static_assert(divByZero() == 0, "");
+/// We see this twice. Once from sema and once when
+/// evaluating the static_assert above.
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -152,8 +152,9 @@
 template 
 bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T ) {
   if (RHS.isZero()) {
-const SourceInfo  = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+const auto *Op = cast(S.Current->getExpr(OpPC));
+S.FFDiag(Op, diag::note_expr_divide_by_zero)
+<< Op->getRHS()->getSourceRange();
 return false;
   }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2808,9 +2808,9 @@
 }
 
 /// Perform the given binary integer operation.
-static bool handleIntIntBinOp(EvalInfo , const Expr *E, const APSInt ,
-  BinaryOperatorKind Opcode, APSInt RHS,
-  APSInt ) {
+static bool handleIntIntBinOp(EvalInfo , const BinaryOperator *E,
+  const APSInt , BinaryOperatorKind Opcode,
+  APSInt RHS, APSInt ) {
   bool HandleOverflowResult = true;
   switch (Opcode) {
   default:
@@ -2831,7 +2831,8 @@
   case BO_Div:
   case BO_Rem:
 if (RHS == 0) {
-  Info.FFDiag(E, diag::note_expr_divide_by_zero);
+  Info.FFDiag(E, diag::note_expr_divide_by_zero)
+  << E->getRHS()->getSourceRange();
   return false;
 }
 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -23,3 +23,16 @@
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
 // CHECK: constexpr-source-ranges.cpp:24:23:{24:23-24:39}
+
+
+constexpr int zero() {
+  return 0;
+}
+constexpr int divByZero() {
+  return 1 / zero();
+}
+static_assert(divByZero() == 0, "");
+/// We see this twice. Once from sema and once when
+/// evaluating the static_assert above.
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -152,8 +152,9 @@
 template 
 bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T ) {
   if (RHS.isZero()) {
-const SourceInfo  = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+const auto *Op = cast(S.Current->getExpr(OpPC));
+S.FFDiag(Op, diag::note_expr_divide_by_zero)
+<< Op->getRHS()->getSourceRange();
 return false;
   }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2808,9 +2808,9 @@
 }
 
 /// Perform the given binary integer operation.
-static bool handleIntIntBinOp(EvalInfo , const Expr *E, const APSInt ,
-  BinaryOperatorKind Opcode, APSInt RHS,
-  APSInt ) {
+static bool handleIntIntBinOp(EvalInfo , const BinaryOperator *E,
+  const APSInt , BinaryOperatorKind Opcode,
+  APSInt RHS, APSInt ) {
   bool HandleOverflowResult = true;
   switch (Opcode) {
   default:
@@ -2831,7 +2831,8 @@
   case BO_Div:
   case BO_Rem:
 if (RHS == 0) {
-  Info.FFDiag(E, diag::note_expr_divide_by_zero);
+  Info.FFDiag(E, diag::note_expr_divide_by_zero)
+  << E->getRHS()->getSourceRange();
   return false;
 }
 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports
___
cfe-commits mailing list

[PATCH] D157080: [clangd] Symbol search includes parameter types for (member) functions

2023-08-04 Thread Florian Humblot via Phabricator via cfe-commits
florianhumblot created this revision.
florianhumblot added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
florianhumblot requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

When using clangd as a language server in an editor such as vscode, it is 
currently hard to use the `List Document Symbols` feature with files where a 
function is overloaded many times.
Other language servers (such as the one provided by Microsoft) return more than 
just the symbol's name for the view, namely it also returns the parameters of 
the (member) functions in the file.
i.e. clang's current view:
F28575822: image.png 
versus Microsoft's current view:
F28575823: image.png 

This patch adds the parameter information to symbol listings of free functions 
and member functions, resulting in the following symbol navigation view:
F28575826: image.png 

This patch has been tested with vscode V1.80.2 and the vscode clangd extension 
version v0.1.24
No additional changes were necessary to either clang(d) or the vscode extension 
for the fix to work (other than specifying the custom clangd executable)

Resolves https://github.com/clangd/clangd/issues/1344


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157080

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


Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -895,8 +895,16 @@
 {"range", S.range},
 {"selectionRange", S.selectionRange}};
 
-  if (!S.detail.empty())
+  if (!S.detail.empty()) {
+if (S.kind == SymbolKind::Method || S.kind == SymbolKind::Function) {
+  llvm::StringRef Detail{S.detail};
+  const auto Start = Detail.find_first_of('(');
+  const auto End = Detail.find_last_of(')');
+  const auto Distance = End - Start;
+  Result["name"] = S.name + Detail.substr(Start, Distance).str() + ')';
+}
 Result["detail"] = S.detail;
+  }
   if (!S.children.empty())
 Result["children"] = S.children;
   if (S.deprecated)


Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -895,8 +895,16 @@
 {"range", S.range},
 {"selectionRange", S.selectionRange}};
 
-  if (!S.detail.empty())
+  if (!S.detail.empty()) {
+if (S.kind == SymbolKind::Method || S.kind == SymbolKind::Function) {
+  llvm::StringRef Detail{S.detail};
+  const auto Start = Detail.find_first_of('(');
+  const auto End = Detail.find_last_of(')');
+  const auto Distance = End - Start;
+  Result["name"] = S.name + Detail.substr(Start, Distance).str() + ')';
+}
 Result["detail"] = S.detail;
+  }
   if (!S.children.empty())
 Result["children"] = S.children;
   if (S.deprecated)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157074: [clang][ExprConst] Add RHS source range to div by zero diags

2023-08-04 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:2835
 if (RHS == 0) {
-  Info.FFDiag(E, diag::note_expr_divide_by_zero);
+  Info.FFDiag(E, diag::note_expr_divide_by_zero) << RHSRange;
   return false;

Why not just use ` E->getRHS()->getSourceRange()` here? It avoids an extra param


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157074

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


[PATCH] D157078: [include-cleaner] Handle files with unnamed buffers

2023-08-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31873d3fca38: [include-cleaner] Handle files with unnamed 
buffers (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157078

Files:
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -7,18 +7,32 @@
 //===--===//
 
 #include "clang-include-cleaner/Record.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -509,5 +523,38 @@
   EXPECT_TRUE(PI.shouldKeep(FM.getFile("always_keep.h").get()));
   EXPECT_FALSE(PI.shouldKeep(FM.getFile("usual.h").get()));
 }
+
+TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
+  llvm::StringLiteral Filename = "test.cpp";
+  auto Code = R"cpp(#include "exporter.h")cpp";
+  Inputs.ExtraFiles["exporter.h"] = R"cpp(
+  #pragma once
+  #include "foo.h" // IWYU pragma: export
+  )cpp";
+  Inputs.ExtraFiles["foo.h"] = "";
+
+  auto Clang = std::make_unique(
+  std::make_shared());
+  Clang->createDiagnostics();
+
+  Clang->setInvocation(std::make_unique());
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
+  Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
+  "clang"));
+
+  // Create unnamed memory buffers for all the files.
+  auto VFS = llvm::makeIntrusiveRefCnt();
+  VFS->addFile(Filename, /*ModificationTime=*/0,
+   llvm::MemoryBuffer::getMemBufferCopy(Code, /*BufferName=*/""));
+  for (const auto  : Inputs.ExtraFiles)
+VFS->addFile(Extra.getKey(), /*ModificationTime=*/0,
+ llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
+  /*BufferName=*/""));
+  auto *FM = Clang->createFileManager(VFS);
+  ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));
+  EXPECT_THAT(
+  PI.getExporters(llvm::cantFail(FM->getFileRef("foo.h")), *FM),
+  testing::ElementsAre(llvm::cantFail(FM->getFileRef("exporter.h";
+}
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -279,20 +279,6 @@
 
 auto [CommentFID, CommentOffset] = SM.getDecomposedLoc(Range.getBegin());
 int CommentLine = SM.getLineNumber(CommentFID, CommentOffset);
-auto Filename = SM.getBufferName(Range.getBegin());
-// Record export pragma.
-if (Pragma->startswith("export")) {
-  ExportStack.push_back({CommentLine, CommentFID, save(Filename), false});
-} else if (Pragma->startswith("begin_exports")) {
-  ExportStack.push_back({CommentLine, CommentFID, save(Filename), true});
-} else if (Pragma->startswith("end_exports")) {
-  // FIXME: be robust on unmatching cases. We should only pop the stack if
-  // the begin_exports and end_exports is in the same file.
-  if (!ExportStack.empty()) {
-assert(ExportStack.back().Block);
-ExportStack.pop_back();
-  }
-}
 
 if (InMainFile) {
   if (Pragma->startswith("keep")) {
@@ -307,8 +293,10 @@
 
 auto FE = SM.getFileEntryRefForID(CommentFID);
 if (!FE) {
-  // FIXME: Support IWYU pragmas in virtual files. Our mappings rely on
-  // "persistent" UniqueIDs and that is not the case for virtual files.
+  // This can only happen when the buffer was registered virtually into
+  // SourceManager and FileManager has no idea about it. In such a scenario,
+  // that file cannot be discovered by HeaderSearch, therefore no "explicit"
+  // includes 

[clang-tools-extra] 31873d3 - [include-cleaner] Handle files with unnamed buffers

2023-08-04 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-08-04T11:13:03+02:00
New Revision: 31873d3fca38e32a17c2b0aa8975e09aca0f8f89

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

LOG: [include-cleaner] Handle files with unnamed buffers

Some tools can register virtual buffers without identifiers into the
filemanager. Make sure we can handle pragmas in such cases.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index e6fe859b2fb360..62eaa16dbf3373 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -279,20 +279,6 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 
 auto [CommentFID, CommentOffset] = SM.getDecomposedLoc(Range.getBegin());
 int CommentLine = SM.getLineNumber(CommentFID, CommentOffset);
-auto Filename = SM.getBufferName(Range.getBegin());
-// Record export pragma.
-if (Pragma->startswith("export")) {
-  ExportStack.push_back({CommentLine, CommentFID, save(Filename), false});
-} else if (Pragma->startswith("begin_exports")) {
-  ExportStack.push_back({CommentLine, CommentFID, save(Filename), true});
-} else if (Pragma->startswith("end_exports")) {
-  // FIXME: be robust on unmatching cases. We should only pop the stack if
-  // the begin_exports and end_exports is in the same file.
-  if (!ExportStack.empty()) {
-assert(ExportStack.back().Block);
-ExportStack.pop_back();
-  }
-}
 
 if (InMainFile) {
   if (Pragma->startswith("keep")) {
@@ -307,8 +293,10 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 
 auto FE = SM.getFileEntryRefForID(CommentFID);
 if (!FE) {
-  // FIXME: Support IWYU pragmas in virtual files. Our mappings rely on
-  // "persistent" UniqueIDs and that is not the case for virtual files.
+  // This can only happen when the buffer was registered virtually into
+  // SourceManager and FileManager has no idea about it. In such a 
scenario,
+  // that file cannot be discovered by HeaderSearch, therefore no 
"explicit"
+  // includes for that file.
   return false;
 }
 auto CommentUID = FE->getUniqueID();
@@ -327,6 +315,20 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   Out->ShouldKeep.insert(CommentUID);
   return false;
 }
+auto Filename = FE->getName();
+// Record export pragma.
+if (Pragma->startswith("export")) {
+  ExportStack.push_back({CommentLine, CommentFID, save(Filename), false});
+} else if (Pragma->startswith("begin_exports")) {
+  ExportStack.push_back({CommentLine, CommentFID, save(Filename), true});
+} else if (Pragma->startswith("end_exports")) {
+  // FIXME: be robust on unmatching cases. We should only pop the stack if
+  // the begin_exports and end_exports is in the same file.
+  if (!ExportStack.empty()) {
+assert(ExportStack.back().Block);
+ExportStack.pop_back();
+  }
+}
 return false;
   }
 

diff  --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index 79a5b559a67efb..69bec04ed60194 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -7,18 +7,32 @@
 
//===--===//
 
 #include "clang-include-cleaner/Record.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -509,5 

[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-04 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Could you please elaborate in the commit message what exactly the issue 
currently is and how the patch addresses it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D157071: [clangd] Dont assert on specific uris for diagnostics docs

2023-08-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG734da23e21eb: [clangd] Dont assert on specific uris for 
diagnostics docs (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157071

Files:
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -1961,8 +1962,8 @@
   withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
   withFix(Fix(Test.range("fix"), "", "remove #include directive");
   auto  = AST.getDiagnostics().front();
-  EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
-std::string("https://clangd.llvm.org/guides/include-cleaner;));
+  EXPECT_THAT(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
+  llvm::ValueIs(Not(IsEmpty(;
   Cfg.Diagnostics.SuppressAll = true;
   WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
   EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -34,7 +34,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "missing-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "No header providing \"Foo\" is directly 
included (fixes available)",
 # CHECK-NEXT: "range": {
@@ -53,7 +53,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "missing-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "No header providing \"Bar\" is directly 
included (fixes available)",
 # CHECK-NEXT: "range": {
@@ -72,7 +72,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "unused-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "Included header all1.h is not used directly 
(fixes available)",
 # CHECK-NEXT: "range": {
@@ -94,7 +94,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "unused-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "Included header all2.h is not used directly 
(fixes available)",
 # CHECK-NEXT: "range": {


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -1961,8 +1962,8 @@
   withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
   withFix(Fix(Test.range("fix"), "", "remove #include directive");
   auto  = AST.getDiagnostics().front();
-  EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
-std::string("https://clangd.llvm.org/guides/include-cleaner;));
+  EXPECT_THAT(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
+  llvm::ValueIs(Not(IsEmpty(;
   Cfg.Diagnostics.SuppressAll = true;
   WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
   EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -34,7 +34,7 @@
 # CHECK-NEXT:   

[clang-tools-extra] 734da23 - [clangd] Dont assert on specific uris for diagnostics docs

2023-08-04 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-08-04T11:09:19+02:00
New Revision: 734da23e21eb687ff4a613d520cbef5348e26a65

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

LOG: [clangd] Dont assert on specific uris for diagnostics docs

To enable customization of links in downstream projects without
breaking tests (and also ease of pointing at different links in the future).
Just check for existence instead.

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

Added: 


Modified: 
clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test 
b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
index bf9e5abca83312..72d69ec0d49415 100644
--- a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -34,7 +34,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "missing-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "No header providing \"Foo\" is directly 
included (fixes available)",
 # CHECK-NEXT: "range": {
@@ -53,7 +53,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "missing-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "No header providing \"Bar\" is directly 
included (fixes available)",
 # CHECK-NEXT: "range": {
@@ -72,7 +72,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "unused-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "Included header all1.h is not used directly 
(fixes available)",
 # CHECK-NEXT: "range": {
@@ -94,7 +94,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "unused-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "Included header all2.h is not used directly 
(fixes available)",
 # CHECK-NEXT: "range": {

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 51ffa45dbc8f6f..f9b71a32304f21 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -1961,8 +1962,8 @@ TEST(DiagnosticsTest, IncludeCleaner) {
   withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
   withFix(Fix(Test.range("fix"), "", "remove #include directive");
   auto  = AST.getDiagnostics().front();
-  EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
-std::string("https://clangd.llvm.org/guides/include-cleaner;));
+  EXPECT_THAT(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
+  llvm::ValueIs(Not(IsEmpty(;
   Cfg.Diagnostics.SuppressAll = true;
   WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
   EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());



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


[PATCH] D157007: [clang][ExtractAPI] Add support for C++ classes with fix

2023-08-04 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157007

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


[PATCH] D157078: [include-cleaner] Handle files with unnamed buffers

2023-08-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Some tools can register virtual buffers without identifiers into the
filemanager. Make sure we can handle pragmas in such cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157078

Files:
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -7,18 +7,32 @@
 //===--===//
 
 #include "clang-include-cleaner/Record.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -509,5 +523,38 @@
   EXPECT_TRUE(PI.shouldKeep(FM.getFile("always_keep.h").get()));
   EXPECT_FALSE(PI.shouldKeep(FM.getFile("usual.h").get()));
 }
+
+TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
+  llvm::StringLiteral Filename = "test.cpp";
+  auto Code = R"cpp(#include "exporter.h")cpp";
+  Inputs.ExtraFiles["exporter.h"] = R"cpp(
+  #pragma once
+  #include "foo.h" // IWYU pragma: export
+  )cpp";
+  Inputs.ExtraFiles["foo.h"] = "";
+
+  auto Clang = std::make_unique(
+  std::make_shared());
+  Clang->createDiagnostics();
+
+  Clang->setInvocation(std::make_unique());
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
+  Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
+  "clang"));
+
+  // Create unnamed memory buffers for all the files.
+  auto VFS = llvm::makeIntrusiveRefCnt();
+  VFS->addFile(Filename, /*ModificationTime=*/0,
+   llvm::MemoryBuffer::getMemBufferCopy(Code, /*BufferName=*/""));
+  for (const auto  : Inputs.ExtraFiles)
+VFS->addFile(Extra.getKey(), /*ModificationTime=*/0,
+ llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
+  /*BufferName=*/""));
+  auto *FM = Clang->createFileManager(VFS);
+  ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));
+  EXPECT_THAT(
+  PI.getExporters(llvm::cantFail(FM->getFileRef("foo.h")), *FM),
+  testing::ElementsAre(llvm::cantFail(FM->getFileRef("exporter.h";
+}
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -279,20 +279,6 @@
 
 auto [CommentFID, CommentOffset] = SM.getDecomposedLoc(Range.getBegin());
 int CommentLine = SM.getLineNumber(CommentFID, CommentOffset);
-auto Filename = SM.getBufferName(Range.getBegin());
-// Record export pragma.
-if (Pragma->startswith("export")) {
-  ExportStack.push_back({CommentLine, CommentFID, save(Filename), false});
-} else if (Pragma->startswith("begin_exports")) {
-  ExportStack.push_back({CommentLine, CommentFID, save(Filename), true});
-} else if (Pragma->startswith("end_exports")) {
-  // FIXME: be robust on unmatching cases. We should only pop the stack if
-  // the begin_exports and end_exports is in the same file.
-  if (!ExportStack.empty()) {
-assert(ExportStack.back().Block);
-ExportStack.pop_back();
-  }
-}
 
 if (InMainFile) {
   if (Pragma->startswith("keep")) {
@@ -307,8 +293,10 @@
 
 auto FE = SM.getFileEntryRefForID(CommentFID);
 if (!FE) {
-  // FIXME: Support IWYU pragmas in virtual files. Our mappings rely on
-  // "persistent" UniqueIDs and that is not the case for virtual files.
+  // This can only happen when the buffer was registered virtually into
+  // SourceManager and FileManager 

[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-04 Thread Mariya Podchishchaeva 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 rGaf91092c449d: [clang] Do not crash on use of a variadic 
overloaded operator (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/overloaded-operator-decl.cpp

Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 struct X { 
   X();
   X(int); 
@@ -58,3 +59,67 @@
 A()(i);
   }
 }
+
+namespace GH42535 {
+class E {
+  E& operator=(const E& rhs, ...); // expected-error{{overloaded 'operator=' cannot be variadic}}
+  E& operator+=(const E& rhs, ...); // expected-error{{overloaded 'operator+=' cannot be variadic}}
+
+};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be variadic}}
+void operator-(E, ...) {} // expected-error{{overloaded 'operator-' cannot be variadic}}
+void operator*(E, ...) {} // expected-error{{overloaded 'operator*' cannot be variadic}}
+void operator/(E, ...) {} // expected-error{{overloaded 'operator/' must be a binary operator}}
+void operator/(E, E, ...) {} // expected-error{{overloaded 'operator/' cannot be variadic}}
+void operator%(E, ...) {} // expected-error{{overloaded 'operator%' must be a binary operator}}
+void operator%(E, E, ...) {} // expected-error{{overloaded 'operator%' cannot be variadic}}
+E& operator++(E&, ...); // expected-error{{overloaded 'operator++' cannot be variadic}}
+E& operator--(E&, ...); // expected-error{{overloaded 'operator--' cannot be variadic}}
+bool operator<(const E& lhs, ...); // expected-error{{overloaded 'operator<' must be a binary operator}}
+bool operator<(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>(const E& lhs, ...); // expected-error{{overloaded 'operator>' must be a binary operator}}
+bool operator>(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>=(const E& lhs, ...); // expected-error{{overloaded 'operator>=' must be a binary operator}}
+bool operator>=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator<=(const E& lhs, ...); // expected-error{{overloaded 'operator<=' must be a binary operator}}
+bool operator<=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator==(const E& lhs, ...); // expected-error{{overloaded 'operator==' must be a binary operator}}
+bool operator==(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator!=(const E& lhs, ...); // expected-error{{overloaded 'operator!=' must be a binary operator}}
+bool operator!=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator&&(const E& lhs, ...); // expected-error{{overloaded 'operator&&' must be a binary operator}}
+bool operator&&(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator||(const E& lhs, ...); // expected-error{{overloaded 'operator||' must be a binary operator}}
+bool operator||(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>>(const E& lhs, ...); // expected-error{{overloaded 'operator>>' must be a binary operator}}
+bool operator>>(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator&(const E& lhs, ...); // expected-error{{cannot be variadic}}
+#if __cplusplus >= 202002L
+auto operator<=>(const E& lhs, ...);  // expected-error{{overloaded 'operator<=>' must be a binary operator}}
+#endif
+void d() {
+  E() + E();
+  E() - E();
+  E() * E();
+  E() / E();
+  E() % E();
+  ++E(); // expected-error{{cannot increment value of type 'E'}}
+  --E(); // expected-error{{cannot decrement value of type 'E'}}
+  E() < E();
+  E() > E();
+  E() <= E();
+  E() >= E();
+  E() == E();
+  E() != E();
+#if __cplusplus >= 202002L
+  E() <=> E();
+#endif
+  E e;
+  E e1 = e;
+  e += e1;
+  E() && E();
+  E() || E();
+  E() & E();
+  E() >> E();
+}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9850,7 +9850,7 @@
 }
 
 static bool haveSameParameterTypes(ASTContext , const FunctionDecl *F1,
-   const FunctionDecl *F2, unsigned NumParams) {
+   const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
 
@@ -9863,8 +9863,14 @@
 return 

[clang] af91092 - [clang] Do not crash on use of a variadic overloaded operator

2023-08-04 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-08-04T01:44:10-07:00
New Revision: af91092c449d6d4bcf60b0cd233c48cd8a41e0e1

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

LOG: [clang] Do not crash on use of a variadic overloaded operator

Just exit instead.
Fixes https://github.com/llvm/llvm-project/issues/42535

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/overloaded-operator-decl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da3cb85dce8e76..a98ad496d22498 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -107,6 +107,8 @@ Bug Fixes in This Version
   instantiated in one module and whose definition is instantiated in another
   module may end up with members associated with the wrong declaration of the
   class, which can result in miscompiles in some cases.
+- Fix crash on use of a variadic overloaded operator.
+  (`#42535 _`)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 40a94e13c72950..ad47b81b9dfadf 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -9850,7 +9850,7 @@ getImplicitObjectParamType(ASTContext , const 
FunctionDecl *F) {
 }
 
 static bool haveSameParameterTypes(ASTContext , const FunctionDecl *F1,
-   const FunctionDecl *F2, unsigned NumParams) 
{
+   const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
 
@@ -9863,8 +9863,14 @@ static bool haveSameParameterTypes(ASTContext , 
const FunctionDecl *F1,
 return F->getParamDecl(I++)->getType();
   };
 
+  unsigned F1NumParams = F1->getNumParams() + isa(F1);
+  unsigned F2NumParams = F2->getNumParams() + isa(F2);
+
+  if (F1NumParams != F2NumParams)
+return false;
+
   unsigned I1 = 0, I2 = 0;
-  for (unsigned I = 0; I != NumParams; ++I) {
+  for (unsigned I = 0; I != F1NumParams; ++I) {
 QualType T1 = NextParam(F1, I1, I == 0);
 QualType T2 = NextParam(F2, I2, I == 0);
 assert(!T1.isNull() && !T2.isNull() && "Unexpected null param types");
@@ -10032,8 +10038,7 @@ bool clang::isBetterOverloadCandidate(
 case ImplicitConversionSequence::Worse:
   if (Cand1.Function && Cand2.Function &&
   Cand1.isReversed() != Cand2.isReversed() &&
-  haveSameParameterTypes(S.Context, Cand1.Function, Cand2.Function,
- NumArgs)) {
+  haveSameParameterTypes(S.Context, Cand1.Function, Cand2.Function)) {
 // Work around large-scale breakage caused by considering reversed
 // forms of operator== in C++20:
 //
@@ -13997,6 +14002,10 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation 
OpLoc,
 std::swap(Args[0], Args[1]);
 
   if (FnDecl) {
+
+if (FnDecl->isInvalidDecl())
+  return ExprError();
+
 Expr *Base = nullptr;
 // We matched an overloaded operator. Build a call to that
 // operator.
@@ -14029,7 +14038,7 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation 
OpLoc,
   llvm::SmallVector AmbiguousWith;
   for (OverloadCandidate  : CandidateSet) {
 if (Cand.Viable && Cand.Function && Cand.isReversed() &&
-haveSameParameterTypes(Context, Cand.Function, FnDecl, 2)) {
+haveSameParameterTypes(Context, Cand.Function, FnDecl)) {
   for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) {
 if (CompareImplicitConversionSequences(
 *this, OpLoc, Cand.Conversions[ArgIdx],

diff  --git a/clang/test/SemaCXX/overloaded-operator-decl.cpp 
b/clang/test/SemaCXX/overloaded-operator-decl.cpp
index 777be6c5a0487f..8a76c9251e419a 100644
--- a/clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ b/clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 struct X { 
   X();
   X(int); 
@@ -58,3 +59,67 @@ namespace PR14120 {
 A()(i);
   }
 }
+
+namespace GH42535 {
+class E {
+  E& operator=(const E& rhs, ...); // expected-error{{overloaded 'operator=' 
cannot be variadic}}
+  E& operator+=(const E& rhs, ...); // expected-error{{overloaded 'operator+=' 
cannot be variadic}}
+
+};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be 
variadic}}
+void operator-(E, ...) {} // expected-error{{overloaded 'operator-' cannot be 
variadic}}
+void operator*(E, ...) {} 

[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-04 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Hmm, clang-format reports failure, but applying git-clang-format to the commit 
doesn't give me anything. It seems the whole SemaOverload.cpp file has broken 
formatting, maybe that is the reason for the failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

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


[libunwind] 3537338 - [libc++][libunwind] Fixes to allow GCC 13 to compile libunwind/libc++abi/libc++

2023-08-04 Thread Nikolas Klauser via cfe-commits

Author: Nikolas Klauser
Date: 2023-08-04T00:51:43-07:00
New Revision: 3537338d1ab9b6da4b58499877953deb81c59e5e

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

LOG: [libc++][libunwind] Fixes to allow GCC 13 to compile 
libunwind/libc++abi/libc++

These are changes to allow GCC 13 to successfully compile the runtimes stack.

Reviewed By: ldionne, #libc, #libunwind, MaskRay

Spies: MaskRay, zibi, SeanP, power-llvm-team, mstorsjo, arichardson, 
libcxx-commits

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

Added: 


Modified: 
libcxx/include/__type_traits/remove_cv.h
libcxx/include/__type_traits/remove_cvref.h
libunwind/src/CMakeLists.txt

Removed: 




diff  --git a/libcxx/include/__type_traits/remove_cv.h 
b/libcxx/include/__type_traits/remove_cv.h
index 8fe8fb0e49596f..c4bf612794bd55 100644
--- a/libcxx/include/__type_traits/remove_cv.h
+++ b/libcxx/include/__type_traits/remove_cv.h
@@ -19,7 +19,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__remove_cv)
+#if __has_builtin(__remove_cv) && !defined(_LIBCPP_COMPILER_GCC)
 template 
 struct remove_cv {
   using type _LIBCPP_NODEBUG = __remove_cv(_Tp);

diff  --git a/libcxx/include/__type_traits/remove_cvref.h 
b/libcxx/include/__type_traits/remove_cvref.h
index 4dc950ac31ad8e..e8e8745ab09609 100644
--- a/libcxx/include/__type_traits/remove_cvref.h
+++ b/libcxx/include/__type_traits/remove_cvref.h
@@ -20,7 +20,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__remove_cvref)
+#if __has_builtin(__remove_cvref) && !defined(_LIBCPP_COMPILER_GCC)
 template 
 using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cvref(_Tp);
 #else

diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e5897fedd2125e..bb2ada94d939d4 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -80,11 +80,6 @@ endif()
 
 # Setup flags.
 add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-  add_link_flags_if_supported(-nostdlib++)
-else()
-  add_link_flags_if_supported(-nodefaultlibs)
-endif()
 
 # MINGW_LIBRARIES is defined in config-ix.cmake
 add_library_flags_if(MINGW "${MINGW_LIBRARIES}")



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


[PATCH] D156221: [RISCV] Support overloaded version ntlh intrinsic function

2023-08-04 Thread Piyou Chen 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 rG2df05cd01c17: [RISCV] Support overloaded version ntlh 
intrinsic function (authored by BeMg).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156221

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/riscv_ntlh.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c

Index: clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
===
--- clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
+++ clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
@@ -100,6 +100,24 @@
   *scvs1 = __riscv_ntl_load(scvs2, __RISCV_NTLH_ALL);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
   *scvc1 = __riscv_ntl_load(scvc2, __RISCV_NTLH_ALL);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
 
+  uc = __riscv_ntl_load();   // CHECK: load i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
+  sc = __riscv_ntl_load();   // CHECK: load i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
+  us = __riscv_ntl_load();   // CHECK: load i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
+  ss = __riscv_ntl_load();   // CHECK: load i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
+  ui = __riscv_ntl_load();   // CHECK: load i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
+  si = __riscv_ntl_load();   // CHECK: load i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
+  ull = __riscv_ntl_load(); // CHECK: load i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  sll = __riscv_ntl_load(); // CHECK: load i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  h1 = __riscv_ntl_load();   // CHECK: load half{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
+  f1 = __riscv_ntl_load();   // CHECK: load float{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
+  d1 = __riscv_ntl_load();   // CHECK: load double{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  v4si1 = __riscv_ntl_load();   // CHECK: load <4 x i32>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
+  v8ss1 = __riscv_ntl_load();   // CHECK: load <8 x i16>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
+  v16sc1 = __riscv_ntl_load();   // CHECK: load <16 x i8>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
+  *scvi1 = __riscv_ntl_load(scvi2);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  *scvs1 = __riscv_ntl_load(scvs2);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  *scvc1 = __riscv_ntl_load(scvc2);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+
   __riscv_ntl_store(, 1, __RISCV_NTLH_INNERMOST_PRIVATE);// CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !5
   __riscv_ntl_store(, 1, __RISCV_NTLH_INNERMOST_PRIVATE);// CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !5
   __riscv_ntl_store(, 1, __RISCV_NTLH_INNERMOST_PRIVATE);// CHECK: store i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !5
@@ -172,6 +190,23 @@
   __riscv_ntl_store(scvs2, *scvs1, __RISCV_NTLH_ALL);  // CHECK: store {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
   __riscv_ntl_store(scvc2, *scvc1, __RISCV_NTLH_ALL);  // CHECK: store {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
 
+  __riscv_ntl_store(, 1);// CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);// CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);// CHECK: store i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);// CHECK: store i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);// CHECK: store i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);// CHECK: store i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);   // CHECK: store i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1);   // CHECK: store i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1.0);  // CHECK: store half{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1.0);  // CHECK: store float{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, 1.0);  // CHECK: store double{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
+  __riscv_ntl_store(, v4si2);  // CHECK: store <4 x 

[clang] 2df05cd - [RISCV] Support overloaded version ntlh intrinsic function

2023-08-04 Thread Piyou Chen via cfe-commits

Author: Piyou Chen
Date: 2023-08-04T00:39:25-07:00
New Revision: 2df05cd01c17f3ef720e554dc7cde43df27e5224

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

LOG: [RISCV] Support overloaded version ntlh intrinsic function

Here is the proposal https://github.com/riscv-non-isa/riscv-c-api-doc/pull/47.

The version that omit the domain argument imply domain=__RISCV_NTLH_ALL.

```
type __riscv_ntl_load (type *ptr);
void __riscv_ntl_store (type *ptr, type val);
```

Reviewed By: kito-cheng, craig.topper

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/riscv_ntlh.h
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 45fbbbed1275df..36d3aa987bb49a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20298,11 +20298,13 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
   // Zihintntl
   case RISCV::BI__builtin_riscv_ntl_load: {
 llvm::Type *ResTy = ConvertType(E->getType());
-ConstantInt *Mode = cast(Ops[1]);
+unsigned DomainVal = 5; // Default __RISCV_NTLH_ALL
+if (Ops.size() == 2)
+  DomainVal = cast(Ops[1])->getZExtValue();
 
 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
 getLLVMContext(),
-llvm::ConstantAsMetadata::get(Builder.getInt32(Mode->getZExtValue(;
+llvm::ConstantAsMetadata::get(Builder.getInt32(DomainVal)));
 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
 getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 
@@ -20324,11 +20326,13 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
 return Load;
   }
   case RISCV::BI__builtin_riscv_ntl_store: {
-ConstantInt *Mode = cast(Ops[2]);
+unsigned DomainVal = 5; // Default __RISCV_NTLH_ALL
+if (Ops.size() == 3)
+  DomainVal = cast(Ops[2])->getZExtValue();
 
 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
 getLLVMContext(),
-llvm::ConstantAsMetadata::get(Builder.getInt32(Mode->getZExtValue(;
+llvm::ConstantAsMetadata::get(Builder.getInt32(DomainVal)));
 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
 getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 

diff  --git a/clang/lib/Headers/riscv_ntlh.h b/clang/lib/Headers/riscv_ntlh.h
index 9ce17092058353..c92e580a0a6317 100644
--- a/clang/lib/Headers/riscv_ntlh.h
+++ b/clang/lib/Headers/riscv_ntlh.h
@@ -21,8 +21,6 @@ enum {
   __RISCV_NTLH_ALL
 };
 
-#define __riscv_ntl_load(PTR, DOMAIN) __builtin_riscv_ntl_load((PTR), (DOMAIN))
-#define __riscv_ntl_store(PTR, VAL, DOMAIN)
\
-  __builtin_riscv_ntl_store((PTR), (VAL), (DOMAIN))
-
-#endif
\ No newline at end of file
+#define __riscv_ntl_load __builtin_riscv_ntl_load
+#define __riscv_ntl_store __builtin_riscv_ntl_store
+#endif

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502c583a48d6df..dd08d755b5cd05 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5287,12 +5287,16 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const 
TargetInfo ,
 bool IsStore = BuiltinID == RISCV::BI__builtin_riscv_ntl_store;
 unsigned NumArgs = IsStore ? 3 : 2;
 
-if (checkArgCount(*this, TheCall, NumArgs))
+if (checkArgCountAtLeast(*this, TheCall, NumArgs - 1))
+  return true;
+
+if (checkArgCountAtMost(*this, TheCall, NumArgs))
   return true;
 
 // Domain value should be compile-time constant.
 // 2 <= domain <= 5
-if (SemaBuiltinConstantArgRange(TheCall, NumArgs - 1, 2, 5))
+if (TheCall->getNumArgs() == NumArgs &&
+SemaBuiltinConstantArgRange(TheCall, NumArgs - 1, 2, 5))
   return true;
 
 Expr *PointerArg = TheCall->getArg(0);

diff  --git a/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c 
b/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
index 5276e486604dee..f27f89df704858 100644
--- a/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
+++ b/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
@@ -100,6 +100,24 @@ void ntl_all_sizes() { 
  // CHECK-LABEL: ntl
   *scvs1 = __riscv_ntl_load(scvs2, __RISCV_NTLH_ALL);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
   *scvc1 = __riscv_ntl_load(scvc2, __RISCV_NTLH_ALL);   // CHECK: load {{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
 
+  uc = __riscv_ntl_load();   // CHECK: load i8{{.*}}align 1, !nontemporal 
!4, !riscv-nontemporal-domain !8
+  

[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-04 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 547124.
jcsxky added a comment.

add unittest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
  clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
  clang/test/Analysis/Inputs/ctu-friend-template.h
  clang/test/Analysis/ctu-friend-template.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4212,6 +4212,84 @@
   EXPECT_TRUE(Imported->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses, SkipFriendTemplateDeclaration) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+namespace __1{
+
+  template
+  class A;
+
+  template
+  class A{
+  public:
+template
+friend class A;
+
+A(T x):x(x){}
+
+void foo(){
+  int i=0;
+  int j=1/i;
+  (void)j;
+}
+
+  private:
+T x;
+  };
+
+  }
+  void bar();
+
+  int main(){
+bar();
+  }
+  )",
+  Lang_CXX11);
+
+  auto *Fwd = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("A")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  namespace __1{
+
+  template
+  class A;
+
+  template
+  class A{
+  public:
+template
+friend class A;
+
+A(T x):x(x){}
+
+void foo(){
+  int i=0;
+  int j=1/i;
+  (void)j;
+}
+
+  private:
+T x;
+  };
+
+}
+void bar(){
+  __1::A a1(0);
+  a1.foo();
+}
+  )",
+  Lang_CXX11, "input1.cc");
+  auto *Definition = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("A")));
+  auto *Template = Import(Definition, Lang_CXX11);
+  EXPECT_TRUE(Template);
+  auto *TemplateClass = cast(Template);
+  EXPECT_EQ(Fwd->getTemplatedDecl()->getTypeForDecl(),
+TemplateClass->getTemplatedDecl()->getTypeForDecl());
+}
+
 TEST_P(ImportFriendClasses,
ImportOfClassTemplateDefinitionShouldConnectToFwdFriend) {
   Decl *ToTU = getToTuDecl(
Index: clang/test/Analysis/ctu-friend-template.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-friend-template.cpp
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-friend-template-other.cpp.ast %S/Inputs/ctu-friend-template-other.cpp
+// RUN: cp %S/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt %t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -Werror=ctu \
+// RUN:   -verify %s
+
+// CHECK: CTU loaded AST file
+
+#include "Inputs/ctu-friend-template.h"
+
+void bar();
+
+int main(){
+	bar(); // expected-no-diagnostics
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.h
@@ -0,0 +1,20 @@
+namespace __1{
+
+template
+class A;
+
+template
+class A{
+public:
+	template
+	friend class A;
+
+	A(T x):x(x){}
+	
+	void foo(){}
+	
+private:
+	T x;
+};
+
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
@@ -0,0 +1 @@
+9:c:@F@bar# ctu-friend-template-other.cpp.ast
Index: clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
@@ -0,0 +1,6 @@
+#include "ctu-friend-template.h"
+
+void bar(){
+	__1::A a1(0);
+	a1.foo();
+}
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,6 +34,7 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -5821,7 +5822,11 @@
   if (FoundTemplate) 

[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add has_template template, DeclarationFragmentBuilder functions, and tests for 
class templates, specializations/partial specs, and concepts.

Depends on D157007 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json 

[PATCH] D157075: [clang][ExtractAPI] Add support for C++ class templates and concepts Depends on D157007

2023-08-04 Thread Erick Velez via Phabricator via cfe-commits
evelez7 created this revision.
evelez7 added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
evelez7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add has_template template, DeclarationFragments, and serialization for class 
templates and concepts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157075

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,205 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo {};
+
+template<> class Foo {};
+
+/// 

[PATCH] D146023: [AMDGPU] Remove Code Object V2

2023-08-04 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added inline comments.



Comment at: llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp:5598
   return ParseDirectiveHSAMetadata();
   } else {
-if (IDVal == ".hsa_code_object_version")

cfang wrote:
> Are you sure Non-HSA does not have the four directives you deleted?  
I'm really not sure, I saw `hsa` in the name and I thought it only applied to 
HSA, but some tests are failing.
I'll leave them in until someone can answer for sure.



Comment at: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h:46
 enum {
-  AMDHSA_COV2 = 2,
   AMDHSA_COV3 = 3,

cfang wrote:
> Should we keep this field, and just mention "unsupported"?
I'm not sure about that, I assume that we're removing as many traces of V2 as 
possible from the backend. No point in keeping an unused enum entry IMO, but 
I'm okay with keeping it if there's a good reason to



Comment at: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h:59
 /// false otherwise.
 bool isHsaAbiVersion3(const MCSubtargetInfo *STI);
 /// \returns True if HSA OS ABI Version identification is 4,

cfang wrote:
> Are all these "isHsaAbiVersionX" no longer needed? 
Yes they're needed because they implicitly check for HSA as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146023

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


[PATCH] D156221: [RISCV] Support overloaded version ntlh intrinsic function

2023-08-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156221

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-08-04 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D148997#4559646 , @bnbarham wrote:

>> Are there other users of incremental processing mode, other than the REPL / 
>> IncrementalParser?
>
> It seems Swift's clang importer also uses incremental processing mode, I'm 
> assuming to keep the `TUScope` and `CurLexer` alive after EOF. We also end up 
> using the same context with various actions, which leads to a few hangs as 
> there's various checks for `eof` only, eg. `ReadPCHAndPreprocessAction`, 
> `PreprocessOnlyAction`, and `RewriteIncludesAction`. There's also quite a few 
> places in the parser that only check for `eof` as well (I just grepped for 
> `Tok.isNot(tok::eof)`).
>
> Should these all be updated to handle `annot_repl_input_end` or should we 
> instead have a different flag that we set for this purpose instead of 
> co-opting `isIncrementalProcessingEnabled`?

I'd prefer to avoid adding a new flag. Is there a way to see how does the diff 
looks like? Maybe it would make more sense to use the `annot_repl_input_end` 
token? If the token name does not capture well the generic use-case I am happy 
to change it to something better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D157074: [clang][ExprConst] Add RHS source range to div by zero diags

2023-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin, hazohelet.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157074

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.h
  clang/test/Misc/constexpr-source-ranges.cpp


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -23,3 +23,16 @@
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
 // CHECK: constexpr-source-ranges.cpp:24:23:{24:23-24:39}
+
+
+constexpr int zero() {
+  return 0;
+}
+constexpr int divByZero() {
+  return 1 / zero();
+}
+static_assert(divByZero() == 0, "");
+/// We see this twice. Once from sema and once when
+/// evaluating the static_assert above.
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -152,8 +152,9 @@
 template 
 bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T ) {
   if (RHS.isZero()) {
-const SourceInfo  = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+const auto *Op = cast(S.Current->getExpr(OpPC));
+S.FFDiag(Op, diag::note_expr_divide_by_zero)
+<< Op->getRHS()->getSourceRange();
 return false;
   }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2810,7 +2810,8 @@
 /// Perform the given binary integer operation.
 static bool handleIntIntBinOp(EvalInfo , const Expr *E, const APSInt ,
   BinaryOperatorKind Opcode, APSInt RHS,
-  APSInt ) {
+  APSInt ,
+  SourceRange RHSRange = SourceRange()) {
   bool HandleOverflowResult = true;
   switch (Opcode) {
   default:
@@ -2831,7 +2832,7 @@
   case BO_Div:
   case BO_Rem:
 if (RHS == 0) {
-  Info.FFDiag(E, diag::note_expr_divide_by_zero);
+  Info.FFDiag(E, diag::note_expr_divide_by_zero) << RHSRange;
   return false;
 }
 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports
@@ -3070,8 +3071,9 @@
   else if (BinaryOperator::isComparisonOp(Opcode))
 Success = handleCompareOpForVector(LHSElt, Opcode, RHSElt, EltResult);
   else
-Success = handleIntIntBinOp(Info, E, LHSElt.getInt(), Opcode,
-RHSElt.getInt(), EltResult);
+Success =
+handleIntIntBinOp(Info, E, LHSElt.getInt(), Opcode, 
RHSElt.getInt(),
+  EltResult, E->getRHS()->getSourceRange());
 
   if (!Success) {
 Info.FFDiag(E);
@@ -12892,7 +12894,7 @@
   APSInt Value(Info.Ctx.getIntWidth(E->getType()),
E->getType()->isUnsignedIntegerOrEnumerationType());
   if (!handleIntIntBinOp(Info, E, LHSVal.getInt(), E->getOpcode(),
- RHSVal.getInt(), Value))
+ RHSVal.getInt(), Value, 
E->getRHS()->getSourceRange()))
 return false;
   return Success(Value, E, Result);
 }


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -23,3 +23,16 @@
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
 // CHECK: constexpr-source-ranges.cpp:24:23:{24:23-24:39}
+
+
+constexpr int zero() {
+  return 0;
+}
+constexpr int divByZero() {
+  return 1 / zero();
+}
+static_assert(divByZero() == 0, "");
+/// We see this twice. Once from sema and once when
+/// evaluating the static_assert above.
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -152,8 +152,9 @@
 template 
 bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T ) {
   if (RHS.isZero()) {
-const SourceInfo  = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+const auto *Op = cast(S.Current->getExpr(OpPC));
+S.FFDiag(Op, diag::note_expr_divide_by_zero)
+<< Op->getRHS()->getSourceRange();
 return false;
   }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- 

[clang] b82c2b9 - Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"

2023-08-04 Thread Yi Kong via cfe-commits

Author: Yi Kong
Date: 2023-08-04T16:02:27+09:00
New Revision: b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9

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

LOG: Reland "Fix __cfi_check not aligned to 4k on relocatable files with no 
executable code"

This reverts commit a093598e50e7b252205f1164751ac9c74874e254.

Fixed test breakage.

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGen/cfi-check-fail.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 0aadaeaba69f3d..07e204387804c8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3431,14 +3431,12 @@ void CodeGenFunction::EmitCfiCheckStub() {
   llvm::Function *F = llvm::Function::Create(
   llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
   llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  F->setAlignment(llvm::Align(4096));
   CGM.setDSOLocal(F);
   llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
-  // FIXME: consider emitting an intrinsic call like
-  // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
-  // which can be lowered in CrossDSOCFI pass to the actual contents of
-  // __cfi_check. This would allow inlining of __cfi_check calls.
-  llvm::CallInst::Create(
-  llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
+  // CrossDSOCFI pass is not executed if there is no executable code.
+  SmallVector Args{F->getArg(2), F->getArg(1)};
+  llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
   llvm::ReturnInst::Create(Ctx, nullptr, BB);
 }
 
@@ -3532,9 +3530,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
   }
 
   FinishFunction();
-  // The only reference to this function will be created during LTO link.
-  // Make sure it survives until then.
-  CGM.addUsedGlobal(F);
 }
 
 void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {

diff  --git a/clang/test/CodeGen/cfi-check-fail.c 
b/clang/test/CodeGen/cfi-check-fail.c
index a4d940641090e5..2f12cee9dec602 100644
--- a/clang/test/CodeGen/cfi-check-fail.c
+++ b/clang/test/CodeGen/cfi-check-fail.c
@@ -72,7 +72,7 @@ void caller(void (*f)(void)) {
 // CHECK: [[CONT5]]:
 // CHECK:   ret void
 
-// CHECK: define weak void @__cfi_check(i64 %0, ptr %1, ptr %2)
+// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], 
ptr %[[DATA:.*]]) align 4096
 // CHECK-NOT: }
-// CHECK: call void @llvm.trap()
+// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
 // CHECK-NEXT: ret void



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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-04 Thread Sandeep via Phabricator via cfe-commits
sandeepkosuri added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9866
+  (CGM.getLangOpts().OpenMP >= 51 &&
+   needsTaskBasedThreadLimit(D.getDirectiveKind()) &&
+   D.hasClausesOfKind());

ABataev wrote:
> I think you don't need needsTaskBasedThreadLimit call here, the 
> emitTargetCall function itself can be called only for target-based directives
`emitTargetCall()` is called for all the target based directives, even target - 
team based directives, which already have a thread limit implementation in 
place. So, I need `needsTaskBasedThreadLimit` to select applicable directives 
only.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5143
+if (CGF.CGM.getLangOpts().OpenMP >= 51 &&
+needsTaskBasedThreadLimit(S.getDirectiveKind()) && TL) {
+  // Emit __kmpc_set_thread_limit() to set the thread_limit for the task

ABataev wrote:
> Same regarding needsTaskBasedThreadLimit(S.getDirectiveKind()) , the function 
> EmitOMPTargetTaskBasedDirective is called only for target-based directives
Similarly here as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D156320: [FLang] Add support for Rpass flag

2023-08-04 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: flang/include/flang/Frontend/CodeGenOptions.h:72
 
+  enum RemarkKind {
+RK_Missing,// Remark argument not present on the command line.

enum class?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

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


[PATCH] D157072: [clang][ExprConst] Check float operation input for signaling NaNs

2023-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: jcranmer-intel, clang.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Split out from https://reviews.llvm.org/D156506.

Before adding this behavior to the new constexpr interpreter, I'd like to first 
see it in the current one.

This patch removes the checks for a NaN result of floating point operations and 
instead checks the input operands for signaling NaNs.

There are only three tests for the NaN-result check as far as I can see, so I 
added a few new ones.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157072

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/SemaCXX/constexpr-float.cpp

Index: clang/test/SemaCXX/constexpr-float.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-float.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+
+template
+constexpr bool isNan(T V) {
+  return __builtin_isnan(V);
+}
+
+constexpr double Signaling = __builtin_nans("");
+static_assert(isNan(Signaling), "");
+constexpr double Quiet = __builtin_nan("");
+static_assert(isNan(Quiet), "");
+
+
+static_assert(Signaling + 1 == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{NaN input to a floating point operation}}
+static_assert(Signaling - 1 == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{NaN input to a floating point operation}}
+static_assert(Signaling / 1 == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{NaN input to a floating point operation}}
+static_assert(Signaling * 1 == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{NaN input to a floating point operation}}
+
+static_assert(Quiet + 1 != 0, "");
+static_assert(isNan(Quiet + 1), "");
+static_assert(-Signaling != 0, "");
+static_assert(+Signaling != 0, "");
Index: clang/test/CXX/expr/expr.const/p2-0x.cpp
===
--- clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -278,9 +278,9 @@
 constexpr float f7 = 0.f / 0.f; // expected-error {{constant expression}} expected-note {{division by zero}}
 constexpr float f8 = 1.f / 0.f; // expected-error {{constant expression}} expected-note {{division by zero}}
 constexpr float f9 = 1e308 / 1e-308; // ok, +inf
-constexpr float f10 = f2 - f2; // expected-error {{constant expression}} expected-note {{produces a NaN}}
-constexpr float f11 = f2 + f4; // expected-error {{constant expression}} expected-note {{produces a NaN}}
-constexpr float f12 = f2 / f2; // expected-error {{constant expression}} expected-note {{produces a NaN}}
+constexpr float f10 = f2 - f2;
+constexpr float f11 = f2 + f4;
+constexpr float f12 = f2 / f2;
 #pragma float_control(push)
 #pragma float_control(except, on)
 constexpr float pi = 3.14f;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2628,6 +2628,16 @@
   return RM;
 }
 
+/// Signaling NaNs are invalid inputs to floating point operations.
+static bool checkFloatingPointInput(EvalInfo , const Expr *E,
+const APFloat ) {
+  if (!Input.isSignaling())
+return true;
+
+  Info.CCEDiag(E, diag::note_constexpr_float_nan_input) << E->getSourceRange();
+  return Info.noteUndefinedBehavior();
+}
+
 /// Check if the given evaluation result is allowed for constant evaluation.
 static bool checkFloatingPointResult(EvalInfo , const Expr *E,
  APFloat::opStatus St) {
@@ -2904,6 +2914,10 @@
 static bool handleFloatFloatBinOp(EvalInfo , const BinaryOperator *E,
   APFloat , BinaryOperatorKind Opcode,
   const APFloat ) {
+  if (!checkFloatingPointInput(Info, E->getLHS(), LHS) ||
+  !checkFloatingPointInput(Info, E->getRHS(), RHS))
+return false;
+
   llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
   APFloat::opStatus St;
   switch (Opcode) {
@@ -2928,15 +2942,6 @@
 break;
   }
 
-  // [expr.pre]p4:
-  //   If during the evaluation of an expression, the result is not
-  //   mathematically defined [...], the behavior is undefined.
-  // FIXME: C++ rules require us to not conform to IEEE 754 here.
-  if (LHS.isNaN()) {
-Info.CCEDiag(E, diag::note_constexpr_float_arithmetic) << LHS.isNaN();
-return Info.noteUndefinedBehavior();
-  

[PATCH] D157071: [clangd] Dont assert on specific uris for diagnostics docs

2023-08-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

To enable customization of links in downstream projects without
breaking tests (and also ease of pointing at different links in the future).
Just check for existence instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157071

Files:
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -1961,8 +1962,8 @@
   withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
   withFix(Fix(Test.range("fix"), "", "remove #include directive");
   auto  = AST.getDiagnostics().front();
-  EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
-std::string("https://clangd.llvm.org/guides/include-cleaner;));
+  EXPECT_THAT(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
+  llvm::ValueIs(Not(IsEmpty(;
   Cfg.Diagnostics.SuppressAll = true;
   WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
   EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -34,7 +34,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "missing-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "No header providing \"Foo\" is directly 
included (fixes available)",
 # CHECK-NEXT: "range": {
@@ -53,7 +53,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "missing-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "No header providing \"Bar\" is directly 
included (fixes available)",
 # CHECK-NEXT: "range": {
@@ -72,7 +72,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "unused-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "Included header all1.h is not used directly 
(fixes available)",
 # CHECK-NEXT: "range": {
@@ -94,7 +94,7 @@
 # CHECK-NEXT:   {
 # CHECK-NEXT: "code": "unused-includes",
 # CHECK-NEXT: "codeDescription": {
-# CHECK-NEXT:   "href": 
"https://clangd.llvm.org/guides/include-cleaner;
+# CHECK-NEXT:   "href": "{{.*}}"
 # CHECK-NEXT: },
 # CHECK-NEXT: "message": "Included header all2.h is not used directly 
(fixes available)",
 # CHECK-NEXT: "range": {


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -1961,8 +1962,8 @@
   withTag(DiagnosticTag::Unnecessary), diagSource(Diag::Clangd),
   withFix(Fix(Test.range("fix"), "", "remove #include directive");
   auto  = AST.getDiagnostics().front();
-  EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
-std::string("https://clangd.llvm.org/guides/include-cleaner;));
+  EXPECT_THAT(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
+  llvm::ValueIs(Not(IsEmpty(;
   Cfg.Diagnostics.SuppressAll = true;
   WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
   EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

[clang] 121e15f - [Driver] Minor formatting fixes in Options.td. NFC

2023-08-04 Thread Justin Bogner via cfe-commits

Author: Justin Bogner
Date: 2023-08-03T22:55:22-07:00
New Revision: 121e15f96ce401c875e717992a4d054e308ba775

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

LOG: [Driver] Minor formatting fixes in Options.td. NFC

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12324dbaf204e5..840cfa3f368504 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3513,8 +3513,9 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, 
Group,
 Flags<[NoXarchOption]>,
 HelpText<"Restore the default behavior of not embedding source text in 
DWARF debug sections">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
-def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
-FlangOption]>, HelpText<"Display available options">,
+def help : Flag<["-", "--"], "help">,
+Flags<[CC1Option, CC1AsOption, FC1Option, FlangOption]>,
+HelpText<"Display available options">,
 MarshallingInfoFlag>;
 def ibuiltininc : Flag<["-"], "ibuiltininc">, Group,
   HelpText<"Enable builtin #include directories even when -nostdinc is used "
@@ -4411,8 +4412,8 @@ def nostdincxx : Flag<["-"], "nostdinc++">, 
Flags<[CC1Option]>, Group, Group;
 def nostdlibxx : Flag<["-"], "nostdlib++">;
 def object : Flag<["-"], "object">;
-def o : JoinedOrSeparate<["-"], "o">, Flags<[NoXarchOption,
-  CC1Option, CC1AsOption, FC1Option, FlangOption]>,
+def o : JoinedOrSeparate<["-"], "o">,
+  Flags<[NoXarchOption, CC1Option, CC1AsOption, FC1Option, FlangOption]>,
   HelpText<"Write output to ">, MetaVarName<"">,
   MarshallingInfoString>;
 def object_file_name_EQ : Joined<["-"], "object-file-name=">, 
Flags<[CC1Option, CC1AsOption, CoreOption]>,



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


[clang] 7affa07 - [Driver] Remove Flags from `cl_Group`. NFC

2023-08-04 Thread Justin Bogner via cfe-commits

Author: Justin Bogner
Date: 2023-08-03T22:55:22-07:00
New Revision: 7affa07cadd19c1413b3806e5cb6fb95f0a6fa8b

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

LOG: [Driver] Remove Flags from `cl_Group`. NFC

These flags are redundant since everything in the `cl_Group`
explicitly sets flags anyway. Remove the Flags because they're
confusing and will cause problems with some later refactorings.

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f752a191e5318f..12324dbaf204e5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6883,7 +6883,7 @@ def defsym : Separate<["-"], "defsym">,
 // clang-cl Options
 
//===--===//
 
-def cl_Group : OptionGroup<"">, Flags<[CLDXCOption]>,
+def cl_Group : OptionGroup<"">,
   HelpText<"CL.EXE COMPATIBILITY OPTIONS">;
 
 def cl_compile_Group : OptionGroup<"">,



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


<    1   2