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

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

> 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`?


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] D157066: [clang][modules][deps] Create more efficient API for visitation of `ModuleFile` inputs

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

Remove leftover `std::string` constructor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157066

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -459,18 +459,19 @@
   serialization::ModuleFile *MF =
   MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
   M->getASTFile());
-  MDC.ScanInstance.getASTReader()->visitInputFiles(
-  *MF, true, true, [&](const serialization::InputFile , bool isSystem) {
+  MDC.ScanInstance.getASTReader()->visitInputFileInfos(
+  *MF, /*IncludeSystem=*/true,
+  [&](const serialization::InputFileInfo , bool IsSystem) {
 // __inferred_module.map is the result of the way in which an implicit
 // module build handles inferred modules. It adds an overlay VFS with
 // this file in the proper directory and relies on the rest of Clang to
 // handle it like normal. With explicitly built modules we don't need
 // to play VFS tricks, so replace it with the correct module map.
-if (IF.getFile()->getName().endswith("__inferred_module.map")) {
+if (StringRef(IFI.Filename).endswith("__inferred_module.map")) {
   MDC.addFileDep(MD, ModuleMap->getName());
   return;
 }
-MDC.addFileDep(MD, IF.getFile()->getName());
+MDC.addFileDep(MD, IFI.Filename);
   });
 
   llvm::DenseSet SeenDeps;
@@ -478,11 +479,15 @@
   addAllSubmoduleDeps(M, MD, SeenDeps);
   addAllAffectingClangModules(M, MD, SeenDeps);
 
-  MDC.ScanInstance.getASTReader()->visitTopLevelModuleMaps(
-  *MF, [&](FileEntryRef FE) {
-if (FE.getNameAsRequested().endswith("__inferred_module.map"))
+  MDC.ScanInstance.getASTReader()->visitInputFileInfos(
+  *MF, /*IncludeSystem=*/true,
+  [&](const serialization::InputFileInfo , bool IsSystem) {
+if (!(IFI.TopLevel && IFI.ModuleMap))
   return;
-MD.ModuleMapFileDeps.emplace_back(FE.getNameAsRequested());
+if (StringRef(IFI.FilenameAsRequested)
+.endswith("__inferred_module.map"))
+  return;
+MD.ModuleMapFileDeps.emplace_back(IFI.FilenameAsRequested);
   });
 
   CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1525,7 +1525,8 @@
   bool IsSystemFile;
   bool IsTransient;
   bool BufferOverridden;
-  bool IsTopLevelModuleMap;
+  bool IsTopLevel;
+  bool IsModuleMap;
   uint32_t ContentHash[2];
 
   InputFileEntry(FileEntryRef File) : File(File) {}
@@ -1547,8 +1548,10 @@
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient
+  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Top-level
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map
-  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
+  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // Name as req. len
+  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name as req. + name
   unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev));
 
   // Create input file hash abbreviation.
@@ -1582,8 +1585,8 @@
 Entry.IsSystemFile = isSystem(File.getFileCharacteristic());
 Entry.IsTransient = Cache->IsTransient;
 Entry.BufferOverridden = Cache->BufferOverridden;
-Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) &&
-File.getIncludeLoc().isInvalid();
+Entry.IsTopLevel = File.getIncludeLoc().isInvalid();
+Entry.IsModuleMap = isModuleMap(File.getFileCharacteristic());
 
 auto ContentHash = hash_code(-1);
 if (PP->getHeaderSearchInfo()
@@ -1631,6 +1634,15 @@
 // Emit size/modification time for this file.
 // And whether this file was overridden.
 {
+  SmallString<128> NameAsRequested = Entry.File.getNameAsRequested();
+  SmallString<128> Name = Entry.File.getName();
+
+  PreparePathForOutput(NameAsRequested);
+  PreparePathForOutput(Name);
+
+  if (Name == NameAsRequested)
+

[PATCH] D157066: [clang][modules][deps] Create more efficient API for visitation of `ModuleFile` inputs

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The current `ASTReader::visitInputFiles()` function calls into `FileManager` to 
create `FileEntryRef` objects. This ends up being fairly costly in 
`clang-scan-deps`, where we mostly only care about file paths.

This patch introduces new `ASTReader` API that gives clients access to just the 
serialized paths. Since the scanner needs both the as-requested path and the 
on-disk one (and doesn't want to transform the former into the latter via 
`FileManager`), this patch starts serializing both of them into the PCM file if 
they differ.

This increases the size of scanning PCMs by 0.1% and speeds up scanning by 5%.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157066

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -459,18 +459,19 @@
   serialization::ModuleFile *MF =
   MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
   M->getASTFile());
-  MDC.ScanInstance.getASTReader()->visitInputFiles(
-  *MF, true, true, [&](const serialization::InputFile , bool isSystem) {
+  MDC.ScanInstance.getASTReader()->visitInputFileInfos(
+  *MF, /*IncludeSystem=*/true,
+  [&](const serialization::InputFileInfo , bool IsSystem) {
 // __inferred_module.map is the result of the way in which an implicit
 // module build handles inferred modules. It adds an overlay VFS with
 // this file in the proper directory and relies on the rest of Clang to
 // handle it like normal. With explicitly built modules we don't need
 // to play VFS tricks, so replace it with the correct module map.
-if (IF.getFile()->getName().endswith("__inferred_module.map")) {
+if (StringRef(IFI.Filename).endswith("__inferred_module.map")) {
   MDC.addFileDep(MD, ModuleMap->getName());
   return;
 }
-MDC.addFileDep(MD, IF.getFile()->getName());
+MDC.addFileDep(MD, IFI.Filename);
   });
 
   llvm::DenseSet SeenDeps;
@@ -478,11 +479,15 @@
   addAllSubmoduleDeps(M, MD, SeenDeps);
   addAllAffectingClangModules(M, MD, SeenDeps);
 
-  MDC.ScanInstance.getASTReader()->visitTopLevelModuleMaps(
-  *MF, [&](FileEntryRef FE) {
-if (FE.getNameAsRequested().endswith("__inferred_module.map"))
+  MDC.ScanInstance.getASTReader()->visitInputFileInfos(
+  *MF, /*IncludeSystem=*/true,
+  [&](const serialization::InputFileInfo , bool IsSystem) {
+if (!(IFI.TopLevel && IFI.ModuleMap))
   return;
-MD.ModuleMapFileDeps.emplace_back(FE.getNameAsRequested());
+if (StringRef(IFI.FilenameAsRequested)
+.endswith("__inferred_module.map"))
+  return;
+MD.ModuleMapFileDeps.emplace_back(IFI.FilenameAsRequested);
   });
 
   CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1525,7 +1525,8 @@
   bool IsSystemFile;
   bool IsTransient;
   bool BufferOverridden;
-  bool IsTopLevelModuleMap;
+  bool IsTopLevel;
+  bool IsModuleMap;
   uint32_t ContentHash[2];
 
   InputFileEntry(FileEntryRef File) : File(File) {}
@@ -1547,8 +1548,10 @@
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient
+  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Top-level
   IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map
-  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
+  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // Name as req. len
+  IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name as req. + name
   unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev));
 
   // Create input file hash abbreviation.
@@ -1582,8 +1585,8 @@
 Entry.IsSystemFile = isSystem(File.getFileCharacteristic());
 Entry.IsTransient = Cache->IsTransient;
 Entry.BufferOverridden = Cache->BufferOverridden;
-Entry.IsTopLevelModuleMap = 

[PATCH] D157046: [clang] Abstract away string allocation in command line generation

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



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4323
+GenerateArg(Consumer, OPT_darwin_target_variant_sdk_version_EQ,
+Opts.DarwinTargetVariantSDKVersion.getAsString());
 }

benlangmuir wrote:
> Maybe not worth micro optimizing, but I noticed these two are allocating 
> strings unnecessarily if we had an overload for things that can print to a 
> raw_ostream.
Interesting, there are a couple of other instances where this might help. I 
probably won't be spending time on this right now, but good to be aware.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157046

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


[PATCH] D157052: [clang][deps] NFC: Speed up canonical context hash computation

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8fd56ea11256: [clang][deps] NFC: Speed up canonical context 
hash computation (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157052

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


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -269,12 +269,13 @@
   HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
 
   // Hash the BuildInvocation without any input files.
-  SmallVector Args;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver(Alloc);
-  CI.generateCC1CommandLine(
-  Args, [&](const Twine ) { return Saver.save(Arg).data(); });
-  HashBuilder.addRange(Args);
+  SmallString<0> ArgVec;
+  ArgVec.reserve(4096);
+  CI.generateCC1CommandLine([&](const Twine ) {
+Arg.toVector(ArgVec);
+ArgVec.push_back('\0');
+  });
+  HashBuilder.add(ArgVec);
 
   // Hash the module dependencies. These paths may differ even if the 
invocation
   // is identical if they depend on the contents of the files in the TU -- for


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -269,12 +269,13 @@
   HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
 
   // Hash the BuildInvocation without any input files.
-  SmallVector Args;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver(Alloc);
-  CI.generateCC1CommandLine(
-  Args, [&](const Twine ) { return Saver.save(Arg).data(); });
-  HashBuilder.addRange(Args);
+  SmallString<0> ArgVec;
+  ArgVec.reserve(4096);
+  CI.generateCC1CommandLine([&](const Twine ) {
+Arg.toVector(ArgVec);
+ArgVec.push_back('\0');
+  });
+  HashBuilder.add(ArgVec);
 
   // Hash the module dependencies. These paths may differ even if the invocation
   // is identical if they depend on the contents of the files in the TU -- for
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8fd56ea - [clang][deps] NFC: Speed up canonical context hash computation

2023-08-03 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-08-03T20:36:34-07:00
New Revision: 8fd56ea11256f220502fe9819b496b15582f8d1e

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

LOG: [clang][deps] NFC: Speed up canonical context hash computation

This patch makes use of the infrastructure established in D157046 to speed up 
computation of the canonical context hash in the dependency scanner. This is 
somewhat hot code, since it's ran for all modules in the dependency graph of 
every TU.

I also tried an alternative approach that tried to avoid allocations as much as 
possible (essentially doing `HashBuilder.add(Arg.toStringRef(ArgVec))`), but 
that turned out to be slower than approach in this patch.

Note that this is not problematic in the same way command-line hashing used to 
be prior D143027. The lambda is now being called even for constant strings.

Depends on D157046.

Reviewed By: benlangmuir

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 060c5389b06d26..fa75c83ef64017 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -269,12 +269,13 @@ static std::string getModuleContextHash(const ModuleDeps 
,
   HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
 
   // Hash the BuildInvocation without any input files.
-  SmallVector Args;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver(Alloc);
-  CI.generateCC1CommandLine(
-  Args, [&](const Twine ) { return Saver.save(Arg).data(); });
-  HashBuilder.addRange(Args);
+  SmallString<0> ArgVec;
+  ArgVec.reserve(4096);
+  CI.generateCC1CommandLine([&](const Twine ) {
+Arg.toVector(ArgVec);
+ArgVec.push_back('\0');
+  });
+  HashBuilder.add(ArgVec);
 
   // Hash the module dependencies. These paths may 
diff er even if the invocation
   // is identical if they depend on the contents of the files in the TU -- for



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


[PATCH] D157048: [clang] NFC: Avoid double allocation when generating command line

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGacd1ab869fca: [clang] NFC: Avoid double allocation when 
generating command line (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157048

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including 
"-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including "-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] acd1ab8 - [clang] NFC: Avoid double allocation when generating command line

2023-08-03 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-08-03T20:35:42-07:00
New Revision: acd1ab869fca0cfa09065aac518da399f755ed5c

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

LOG: [clang] NFC: Avoid double allocation when generating command line

This patch makes use of the infrastructure established in D157046 to avoid 
needless allocations via `StringSaver`.

Depends on D157046.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2e2f1de36482fa..be53ce3e472659 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@ void CompilerInvocation::generateCC1CommandLine(
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including 
"-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {



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


[PATCH] D157046: [clang] Abstract away string allocation in command line generation

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG83452650490e: [clang] Abstract away string allocation in 
command line generation (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157046

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -165,6 +165,8 @@
 // Normalizers
 //===--===//
 
+using ArgumentConsumer = CompilerInvocation::ArgumentConsumer;
+
 #define SIMPLE_ENUM_VALUE_TABLE
 #include "clang/Driver/Options.inc"
 #undef SIMPLE_ENUM_VALUE_TABLE
@@ -191,13 +193,10 @@
 /// denormalizeSimpleFlags never looks at it. Avoid bloating compile-time with
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
-static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const Twine ,
-  CompilerInvocation::StringAllocator,
-  Option::OptionClass, unsigned, /*T*/...) {
-  // Spelling is already allocated or a static string, no need to call SA.
-  assert(*Spelling.getSingleStringRef().end() == '\0');
-  Args.push_back(Spelling.getSingleStringRef().data());
+static void denormalizeSimpleFlag(ArgumentConsumer Consumer,
+  const Twine , Option::OptionClass,
+  unsigned, /*T*/...) {
+  Consumer(Spelling);
 }
 
 template  static constexpr bool is_uint64_t_convertible() {
@@ -234,34 +233,27 @@
 }
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
-  return [Value](SmallVectorImpl , const Twine ,
- CompilerInvocation::StringAllocator, Option::OptionClass,
- unsigned, bool KeyPath) {
-if (KeyPath == Value) {
-  // Spelling is already allocated or a static string, no need to call SA.
-  assert(*Spelling.getSingleStringRef().end() == '\0');
-  Args.push_back(Spelling.getSingleStringRef().data());
-}
+  return [Value](ArgumentConsumer Consumer, const Twine ,
+ Option::OptionClass, unsigned, bool KeyPath) {
+if (KeyPath == Value)
+  Consumer(Spelling);
   };
 }
 
-static void denormalizeStringImpl(SmallVectorImpl ,
+static void denormalizeStringImpl(ArgumentConsumer Consumer,
   const Twine ,
-  CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned,
   const Twine ) {
   switch (OptClass) {
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
   case Option::JoinedAndSeparateClass:
-// Spelling is already allocated or a static string, no need to call SA.
-assert(*Spelling.getSingleStringRef().end() == '\0');
-Args.push_back(Spelling.getSingleStringRef().data());
-Args.push_back(SA(Value));
+Consumer(Spelling);
+Consumer(Value);
 break;
   case Option::JoinedClass:
   case Option::CommaJoinedClass:
-Args.push_back(SA(Twine(Spelling) + Value));
+Consumer(Spelling + Value);
 break;
   default:
 llvm_unreachable("Cannot denormalize an option with option class "
@@ -270,11 +262,10 @@
 }
 
 template 
-static void
-denormalizeString(SmallVectorImpl , const Twine ,
-  CompilerInvocation::StringAllocator SA,
-  Option::OptionClass OptClass, unsigned TableIndex, T Value) {
-  denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, Twine(Value));
+static void denormalizeString(ArgumentConsumer Consumer, const Twine ,
+  Option::OptionClass OptClass, unsigned TableIndex,
+  T Value) {
+  denormalizeStringImpl(Consumer, Spelling, OptClass, TableIndex, Twine(Value));
 }
 
 static std::optional
@@ -315,15 +306,14 @@
   return std::nullopt;
 }
 
-static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
+static void denormalizeSimpleEnumImpl(ArgumentConsumer Consumer,
   const Twine ,
-  CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable  = SimpleEnumValueTables[TableIndex];
   if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
-denormalizeString(Args, Spelling, SA, OptClass, TableIndex,
+denormalizeString(Consumer, Spelling, OptClass, TableIndex,
   

[clang] 8345265 - [clang] Abstract away string allocation in command line generation

2023-08-03 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-08-03T20:35:00-07:00
New Revision: 83452650490eb1021939129682b01fcdff34c691

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

LOG: [clang] Abstract away string allocation in command line generation

This patch abstracts away the string allocation and vector push-back from 
command line generation. Instead, **all** generated arguments are passed into 
`ArgumentConsumer`, which may choose to do the string allocation and vector 
push-back, or something else entirely.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 1dbd1eda62b3f2..4142499f2dd703 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -223,7 +223,7 @@ class CompilerInvocation : public CompilerInvocationRefBase,
   /// identifying the conditions under which the module was built.
   std::string getModuleHash() const;
 
-  using StringAllocator = llvm::function_ref;
+  using StringAllocator = llvm::function_ref;
   /// Generate cc1-compatible command line arguments from this instance.
   ///
   /// \param [out] Args - The generated arguments. Note that the caller is
@@ -233,7 +233,21 @@ class CompilerInvocation : public 
CompilerInvocationRefBase,
   /// command line argument and return a pointer to the newly allocated string.
   /// The returned pointer is what gets appended to Args.
   void generateCC1CommandLine(llvm::SmallVectorImpl ,
-  StringAllocator SA) const;
+  StringAllocator SA) const {
+generateCC1CommandLine([&](const Twine ) {
+  // No need to allocate static string literals.
+  Args.push_back(Arg.isSingleStringLiteral()
+ ? Arg.getSingleStringRef().data()
+ : SA(Arg));
+});
+  }
+
+  using ArgumentConsumer = llvm::function_ref;
+  /// Generate cc1-compatible command line arguments from this instance.
+  ///
+  /// \param Consumer - Callback that gets invoked for every single generated
+  /// command line argument.
+  void generateCC1CommandLine(ArgumentConsumer Consumer) const;
 
   /// Generate cc1-compatible command line arguments from this instance,
   /// wrapping the result as a std::vector.
@@ -267,8 +281,8 @@ class CompilerInvocation : public CompilerInvocationRefBase,
 
   /// Generate command line options from DiagnosticOptions.
   static void GenerateDiagnosticArgs(const DiagnosticOptions ,
- SmallVectorImpl ,
- StringAllocator SA, bool 
DefaultDiagColor);
+ ArgumentConsumer Consumer,
+ bool DefaultDiagColor);
 
   /// Parse command line options that map to LangOptions.
   static bool ParseLangArgs(LangOptions , llvm::opt::ArgList ,
@@ -278,8 +292,7 @@ class CompilerInvocation : public CompilerInvocationRefBase,
 
   /// Generate command line options from LangOptions.
   static void GenerateLangArgs(const LangOptions ,
-   SmallVectorImpl ,
-   StringAllocator SA, const llvm::Triple ,
+   ArgumentConsumer Consumer, const llvm::Triple 
,
InputKind IK);
 
   /// Parse command line options that map to CodeGenOptions.
@@ -291,8 +304,8 @@ class CompilerInvocation : public CompilerInvocationRefBase,
 
   // Generate command line options from CodeGenOptions.
   static void GenerateCodeGenArgs(const CodeGenOptions ,
-  SmallVectorImpl ,
-  StringAllocator SA, const llvm::Triple ,
+  ArgumentConsumer Consumer,
+  const llvm::Triple ,
   const std::string ,
   const LangOptions *LangOpts);
 };

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1e990f4663d44f..2e2f1de36482fa 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -165,6 +165,8 @@ CompilerInvocationRefBase::~CompilerInvocationRefBase() = 
default;
 // Normalizers
 
//===--===//
 
+using ArgumentConsumer = CompilerInvocation::ArgumentConsumer;
+
 #define SIMPLE_ENUM_VALUE_TABLE
 #include "clang/Driver/Options.inc"
 #undef 

[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

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



Comment at: lld/ELF/Driver.h:28
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Options.inc"

MaskRay wrote:
> lld/wasm lld/COFF lld/MachO are not updated?
You're right, I accidentally missed some LLD parts. Updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

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


[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 547090.
jansvoboda11 added a comment.
Herald added subscribers: pmatos, asb, aheejin, sbc100.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.

Convert missed LLD parts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

Files:
  clang/include/clang/Driver/Options.h
  clang/lib/Driver/DriverOptions.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/MachO/Driver.h
  lld/MinGW/Driver.cpp
  lld/wasm/Driver.cpp
  lldb/tools/driver/Driver.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.h
  llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
  llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
  llvm/tools/llvm-dwp/llvm-dwp.cpp
  llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
  llvm/tools/llvm-ifs/llvm-ifs.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/tools/llvm-lipo/llvm-lipo.cpp
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/tools/llvm-mt/llvm-mt.cpp
  llvm/tools/llvm-nm/llvm-nm.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-objdump/ObjdumpOptID.h
  llvm/tools/llvm-objdump/llvm-objdump.cpp
  llvm/tools/llvm-rc/llvm-rc.cpp
  llvm/tools/llvm-readobj/llvm-readobj.cpp
  llvm/tools/llvm-size/llvm-size.cpp
  llvm/tools/llvm-strings/llvm-strings.cpp
  llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
  llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
  llvm/tools/sancov/sancov.cpp
  llvm/unittests/Option/OptionParsingTest.cpp

Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -17,9 +17,7 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -47,10 +45,7 @@
 };
 
 static constexpr OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
-   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
+#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/sancov/sancov.cpp
===
--- llvm/tools/sancov/sancov.cpp
+++ llvm/tools/sancov/sancov.cpp
@@ -63,9 +63,7 @@
 using namespace llvm::opt;
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
@@ -78,13 +76,7 @@
 #undef PREFIX
 
 static constexpr opt::OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {\
-  PREFIX,  NAME,  HELPTEXT,\
-  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
-  PARAM,   FLAGS, OPT_##GROUP, \
-  OPT_##ALIAS, ALIASARGS, VALUES},
+#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
===
--- llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -28,9 +28,7 @@
 namespace {
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
@@ 

[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

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



Comment at: lld/ELF/Driver.h:28
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Options.inc"

lld/wasm lld/COFF lld/MachO are not updated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

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


[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

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

In D157028#4558724 , @jansvoboda11 
wrote:

> Here's an example of a patch that changes the `OPTION` macro: D157029 
> . I wonder if we could have counterparts to 
> `LLVM_MAKE_OPT_ID` and `LLVM_CONSTRUCT_OPT_INFO` that allow overriding the 
> default `OPT_` prefix. That would make D157029 
>  even smaller. WDYT @MaskRay?

The `#define OPTION(...) LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(COFF_OPT_, 
__VA_ARGS__),` use case looks good:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

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


[PATCH] D156771: [clang][hexagon] Handle library path arguments earlier

2023-08-03 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

ping?  any concerns about this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156771

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


[PATCH] D156962: [Driver] Mark m_x86_Features_Group options as TargetSpecific

2023-08-03 Thread Fangrui Song 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 rG5fd5f8027fa1: [Driver] Mark m_x86_Features_Group options as 
TargetSpecific (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D156962?vs=546676=547080#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156962

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/x86-target-features.c


Index: clang/test/Driver/x86-target-features.c
===
--- clang/test/Driver/x86-target-features.c
+++ clang/test/Driver/x86-target-features.c
@@ -374,6 +374,13 @@
 // CRC32: "-target-feature" "+crc32"
 // NO-CRC32: "-target-feature" "-crc32"
 
+// RUN: not %clang -### --target=aarch64 -mcrc32 -msse4.1 -msse4.2 -mno-sgx %s 
2>&1 | FileCheck --check-prefix=NONX86 %s
+// NONX86:  error: unsupported option '-mcrc32' for target 'aarch64'
+// NONX86-NEXT: error: unsupported option '-msse4.1' for target 'aarch64'
+/// TODO: This warning is a workaround for 
https://github.com/llvm/llvm-project/issues/63270
+// NONX86-NEXT: warning: argument unused during compilation: '-msse4.2' 
[-Wunused-command-line-argument]
+// NONX86-NEXT: error: unsupported option '-mno-sgx' for target 'aarch64'
+
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=return %s -### -o %t.o 
2>&1 | FileCheck -check-prefixes=SLS-RET,NO-SLS %s
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=indirect-jmp %s -### -o 
%t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,NO-SLS %s
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=none -mharden-sls=all %s 
-### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,SLS-RET %s
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4890,6 +4890,7 @@
 } // let Flags = [TargetSpecific]
 
 // X86 feature flags
+let Flags = [TargetSpecific] in {
 def mx87 : Flag<["-"], "mx87">, Group;
 def mno_x87 : Flag<["-"], "mno-x87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
@@ -4923,7 +4924,11 @@
 def mno_ssse3 : Flag<["-"], "mno-ssse3">, Group;
 def msse4_1 : Flag<["-"], "msse4.1">, Group;
 def mno_sse4_1 : Flag<["-"], "mno-sse4.1">, Group;
+} // let Flags = [TargetSpecific]
+// TODO: Make -msse4.2 TargetSpecific after
+// https://github.com/llvm/llvm-project/issues/63270 is fixed.
 def msse4_2 : Flag<["-"], "msse4.2">, Group;
+let Flags = [TargetSpecific] in {
 def mno_sse4_2 : Flag<["-"], "mno-sse4.2">, Group;
 def msse4 : Flag<["-"], "msse4">, Alias;
 // -mno-sse4 turns off sse4.1 which has the effect of turning off everything
@@ -5104,6 +5109,7 @@
 def mno_retpoline_external_thunk : Flag<["-"], 
"mno-retpoline-external-thunk">, Group;
 def mvzeroupper : Flag<["-"], "mvzeroupper">, Group;
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
+} // let Flags = [TargetSpecific]
 
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag


Index: clang/test/Driver/x86-target-features.c
===
--- clang/test/Driver/x86-target-features.c
+++ clang/test/Driver/x86-target-features.c
@@ -374,6 +374,13 @@
 // CRC32: "-target-feature" "+crc32"
 // NO-CRC32: "-target-feature" "-crc32"
 
+// RUN: not %clang -### --target=aarch64 -mcrc32 -msse4.1 -msse4.2 -mno-sgx %s 2>&1 | FileCheck --check-prefix=NONX86 %s
+// NONX86:  error: unsupported option '-mcrc32' for target 'aarch64'
+// NONX86-NEXT: error: unsupported option '-msse4.1' for target 'aarch64'
+/// TODO: This warning is a workaround for https://github.com/llvm/llvm-project/issues/63270
+// NONX86-NEXT: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
+// NONX86-NEXT: error: unsupported option '-mno-sgx' for target 'aarch64'
+
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=return %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-RET,NO-SLS %s
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=indirect-jmp %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,NO-SLS %s
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=none -mharden-sls=all %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,SLS-RET %s
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4890,6 +4890,7 @@
 } // let Flags = [TargetSpecific]
 
 // X86 feature flags
+let Flags = [TargetSpecific] in {
 def mx87 : Flag<["-"], "mx87">, Group;
 def mno_x87 : Flag<["-"], "mno-x87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
@@ -4923,7 +4924,11 @@
 

[clang] 5fd5f80 - [Driver] Mark m_x86_Features_Group options as TargetSpecific

2023-08-03 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-03T19:04:53-07:00
New Revision: 5fd5f8027fa196913138a34082a933abd5be0b4e

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

LOG: [Driver] Mark m_x86_Features_Group options as TargetSpecific

so that they lead to an error when compiled for non-x86 targets.
Follow-up to D151590.

```
% aarch64-linux-gnu-gcc -c -mavx a.c
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mavx’
% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # without this patch
clang: warning: argument unused during compilation: '-mavx' 
[-Wunused-command-line-argument]
...

% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # with this patch
clang: error: unsupported option '-mavx' for target 'aarch64-unknown-linux-gnu'
```

As a workaround for https://github.com/llvm/llvm-project/issues/63270, we don't
report an error for -msse4.2.

Reviewed By: pengfei, skan

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/x86-target-features.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ebf7e0c9f39979..f752a191e5318f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4890,6 +4890,7 @@ foreach i = {0-7} in
 } // let Flags = [TargetSpecific]
 
 // X86 feature flags
+let Flags = [TargetSpecific] in {
 def mx87 : Flag<["-"], "mx87">, Group;
 def mno_x87 : Flag<["-"], "mno-x87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
@@ -4923,7 +4924,11 @@ def mssse3 : Flag<["-"], "mssse3">, 
Group;
 def mno_ssse3 : Flag<["-"], "mno-ssse3">, Group;
 def msse4_1 : Flag<["-"], "msse4.1">, Group;
 def mno_sse4_1 : Flag<["-"], "mno-sse4.1">, Group;
+} // let Flags = [TargetSpecific]
+// TODO: Make -msse4.2 TargetSpecific after
+// https://github.com/llvm/llvm-project/issues/63270 is fixed.
 def msse4_2 : Flag<["-"], "msse4.2">, Group;
+let Flags = [TargetSpecific] in {
 def mno_sse4_2 : Flag<["-"], "mno-sse4.2">, Group;
 def msse4 : Flag<["-"], "msse4">, Alias;
 // -mno-sse4 turns off sse4.1 which has the effect of turning off everything
@@ -5104,6 +5109,7 @@ def mretpoline_external_thunk : Flag<["-"], 
"mretpoline-external-thunk">, Group<
 def mno_retpoline_external_thunk : Flag<["-"], 
"mno-retpoline-external-thunk">, Group;
 def mvzeroupper : Flag<["-"], "mvzeroupper">, Group;
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
+} // let Flags = [TargetSpecific]
 
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag

diff  --git a/clang/test/Driver/x86-target-features.c 
b/clang/test/Driver/x86-target-features.c
index a2f537d55ef66b..385176d2923e4e 100644
--- a/clang/test/Driver/x86-target-features.c
+++ b/clang/test/Driver/x86-target-features.c
@@ -374,6 +374,13 @@
 // CRC32: "-target-feature" "+crc32"
 // NO-CRC32: "-target-feature" "-crc32"
 
+// RUN: not %clang -### --target=aarch64 -mcrc32 -msse4.1 -msse4.2 -mno-sgx %s 
2>&1 | FileCheck --check-prefix=NONX86 %s
+// NONX86:  error: unsupported option '-mcrc32' for target 'aarch64'
+// NONX86-NEXT: error: unsupported option '-msse4.1' for target 'aarch64'
+/// TODO: This warning is a workaround for 
https://github.com/llvm/llvm-project/issues/63270
+// NONX86-NEXT: warning: argument unused during compilation: '-msse4.2' 
[-Wunused-command-line-argument]
+// NONX86-NEXT: error: unsupported option '-mno-sgx' for target 'aarch64'
+
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=return %s -### -o %t.o 
2>&1 | FileCheck -check-prefixes=SLS-RET,NO-SLS %s
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=indirect-jmp %s -### -o 
%t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,NO-SLS %s
 // RUN: %clang --target=i386 -march=i386 -mharden-sls=none -mharden-sls=all %s 
-### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,SLS-RET %s



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


[PATCH] D156866: [Clang][LoongArch] Use the ClangBuiltin class to automatically generate support for CBE and CFE

2023-08-03 Thread Lu Weining via Phabricator via cfe-commits
SixWeining accepted this revision.
SixWeining added a comment.
This revision is now accepted and ready to land.

The change is loongarch-specific and it looks goold to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156866

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


[PATCH] D156866: [Clang][LoongArch] Use the ClangBuiltin class to automatically generate support for CBE and CFE

2023-08-03 Thread wanglei via Phabricator via cfe-commits
wangleiat updated this revision to Diff 547072.
wangleiat added a comment.

Address @SixWeining's commonts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156866

Files:
  clang/include/clang/Basic/BuiltinsLoongArch.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/IR/Function.cpp

Index: llvm/lib/IR/Function.cpp
===
--- llvm/lib/IR/Function.cpp
+++ llvm/lib/IR/Function.cpp
@@ -37,6 +37,7 @@
 #include "llvm/IR/IntrinsicsBPF.h"
 #include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsHexagon.h"
+#include "llvm/IR/IntrinsicsLoongArch.h"
 #include "llvm/IR/IntrinsicsMips.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsPowerPC.h"
Index: llvm/include/llvm/IR/IntrinsicsLoongArch.td
===
--- llvm/include/llvm/IR/IntrinsicsLoongArch.td
+++ llvm/include/llvm/IR/IntrinsicsLoongArch.td
@@ -51,74 +51,75 @@
 //===--===//
 // LoongArch BASE
 
-def int_loongarch_break : Intrinsic<[], [llvm_i32_ty], [ImmArg>]>;
-def int_loongarch_cacop_d : Intrinsic<[], [llvm_i64_ty, llvm_i64_ty, llvm_i64_ty],
-[ImmArg>, ImmArg>]>;
-def int_loongarch_cacop_w : Intrinsic<[], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
-[ImmArg>, ImmArg>]>;
-def int_loongarch_dbar : Intrinsic<[], [llvm_i32_ty], [ImmArg>]>;
-def int_loongarch_ibar : Intrinsic<[], [llvm_i32_ty], [ImmArg>]>;
-def int_loongarch_movfcsr2gr : Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
-   [ImmArg>]>;
-def int_loongarch_movgr2fcsr : Intrinsic<[], [llvm_i32_ty, llvm_i32_ty],
-   [ImmArg>]>;
-def int_loongarch_syscall : Intrinsic<[], [llvm_i32_ty], [ImmArg>]>;
-
-def int_loongarch_crc_w_b_w : Intrinsic<[llvm_i32_ty],
-[llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_crc_w_h_w : Intrinsic<[llvm_i32_ty],
-[llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_crc_w_w_w : Intrinsic<[llvm_i32_ty],
-[llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_crc_w_d_w : Intrinsic<[llvm_i32_ty],
-[llvm_i64_ty, llvm_i32_ty]>;
-
-def int_loongarch_crcc_w_b_w : Intrinsic<[llvm_i32_ty],
- [llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_crcc_w_h_w : Intrinsic<[llvm_i32_ty],
- [llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_crcc_w_w_w : Intrinsic<[llvm_i32_ty],
- [llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_crcc_w_d_w : Intrinsic<[llvm_i32_ty],
- [llvm_i64_ty, llvm_i32_ty]>;
-
-def int_loongarch_csrrd_w : Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
-  [ImmArg>]>;
-def int_loongarch_csrrd_d : Intrinsic<[llvm_i64_ty], [llvm_i32_ty],
-  [ImmArg>]>;
-def int_loongarch_csrwr_w : Intrinsic<[llvm_i32_ty],
-  [llvm_i32_ty, llvm_i32_ty],
-  [ImmArg>]>;
-def int_loongarch_csrwr_d : Intrinsic<[llvm_i64_ty],
-  [llvm_i64_ty, llvm_i32_ty],
-  [ImmArg>]>;
-def int_loongarch_csrxchg_w : Intrinsic<[llvm_i32_ty],
-[llvm_i32_ty, llvm_i32_ty,
- llvm_i32_ty],
-[ImmArg>]>;
-def int_loongarch_csrxchg_d : Intrinsic<[llvm_i64_ty],
-[llvm_i64_ty, llvm_i64_ty,
- llvm_i32_ty],
-[ImmArg>]>;
-
-def int_loongarch_iocsrrd_b : Intrinsic<[llvm_i32_ty], [llvm_i32_ty]>;
-def int_loongarch_iocsrrd_h : Intrinsic<[llvm_i32_ty], [llvm_i32_ty]>;
-def int_loongarch_iocsrrd_w : Intrinsic<[llvm_i32_ty], [llvm_i32_ty]>;
-def int_loongarch_iocsrrd_d : Intrinsic<[llvm_i64_ty], [llvm_i32_ty]>;
-
-def int_loongarch_iocsrwr_b : Intrinsic<[], [llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_iocsrwr_h : Intrinsic<[], [llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_iocsrwr_w : Intrinsic<[], [llvm_i32_ty, llvm_i32_ty]>;
-def int_loongarch_iocsrwr_d : Intrinsic<[], [llvm_i64_ty, llvm_i32_ty]>;
-
-def int_loongarch_cpucfg : Intrinsic<[llvm_i32_ty], [llvm_i32_ty]>;
-
-def int_loongarch_asrtle_d : Intrinsic<[], [llvm_i64_ty, llvm_i64_ty]>;
-def int_loongarch_asrtgt_d : Intrinsic<[], [llvm_i64_ty, llvm_i64_ty]>;
-
-def 

[PATCH] D157057: [clang-tidy] Implement cppcoreguidelines CP.52

2023-08-03 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:156
 
+- New :doc:`cppcoreguidelines-no-suspend-with-lock
+  ` check.

Please keep alphabetical order in new checks list.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst:6
+
+Warns when a coroutine suspends while a lock guard object is in scope.
+

Please synchronize with statement in Release Notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157057

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


[PATCH] D156901: [OpenMP] Change OpenMP default version in documentation and help text for -fopenmp-version

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

Removed whitespace that caused CI tests to fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156901

Files:
  clang/docs/OpenMPSupport.rst
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  openmp/docs/CommandLineArgumentReference.rst


Index: openmp/docs/CommandLineArgumentReference.rst
===
--- openmp/docs/CommandLineArgumentReference.rst
+++ openmp/docs/CommandLineArgumentReference.rst
@@ -37,8 +37,7 @@
 ^^
 Set the OpenMP version to a specific version  of the OpenMP standard. 
 For example, you may use ``-fopenmp-version=45`` to select version 4.5 of 
-the OpenMP standard. The default value is ``-fopenmp-version=50`` for 
``Clang`` 
-and ``-fopenmp-version=11`` for ``flang-new``.
+the OpenMP standard. The default value is ``-fopenmp-version=51`` for 
``Clang``.
 
 .. _offload_command_line_arguments:
 
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -52,7 +52,7 @@
 ! HELP-NEXT:Do not create unit-strided loops (default)
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp-version=
-! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel 
code.
 ! HELP-NEXT: -foptimization-record-file=
 ! HELP-NEXT:Specify the output name of the file 
containing the optimization remarks. Implies -fsave-optimization-record. On 
Darwin platforms, this cannot be used with multiple -arch  options.
@@ -170,7 +170,7 @@
 ! HELP-FC1-NEXT:Generate code only for an OpenMP 
target device.
 ! HELP-FC1-NEXT: -fopenmp-target-debug  Enable debugging in the OpenMP 
offloading device RTL
 ! HELP-FC1-NEXT: -fopenmp-version=
-! HELP-FC1-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! HELP-FC1-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate 
parallel code.
 ! HELP-FC1-NEXT: -fpass-plugin= Load pass plugin from a dynamic 
shared object file (only with new pass manager).
 ! HELP-FC1-NEXT: -freciprocal-math  Allow division operations to be 
reassociated
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -56,7 +56,7 @@
 ! CHECK-NEXT:Do not create unit-strided loops (default)
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp-version=
-! CHECK-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! CHECK-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate 
parallel code.
 ! CHECK-NEXT: -foptimization-record-file=
 ! CHECK-NEXT:Specify the output name of the file 
containing the optimization remarks. Implies -fsave-optimization-record. On 
Darwin platforms, this cannot be used with multiple -arch  options.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2782,7 +2782,7 @@
   HelpText<"Parse OpenMP pragmas and generate parallel code.">;
 def fno_openmp : Flag<["-"], "fno-openmp">, Group, 
Flags<[NoArgumentUnused]>;
 def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group, 
Flags<[CC1Option, NoArgumentUnused, FlangOption, FC1Option]>,
-  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). 
Default value is 50 for Clang and 11 for Flang">;
+  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). 
Default value is 51 for Clang">;
 defm openmp_extensions: BoolFOption<"openmp-extensions",
   LangOpts<"OpenMPExtensions">, DefaultTrue,
   PosFlagIndex: openmp/docs/CommandLineArgumentReference.rst
===
--- 

[PATCH] D156259: [clang-format] Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-08-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:167-168
 
+- Fix a bug that erroneously placed function arguments on a new line despite
+all arguments being able to fit on the same line.
 

Please delete it. We only update the release note for new options.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:658-659
+  bool DisallowLineBreaksOnThisLine =
+  (Style.Language == FormatStyle::LK_Cpp ||
+   Style.Language == FormatStyle::LK_ObjC) &&
+  [] {





Comment at: clang/lib/Format/ContinuationIndenter.cpp:667-669
+if (!PrevNonComment)
+  return false;
+if (!PrevNonComment->is(tok::l_paren))





Comment at: clang/lib/Format/ContinuationIndenter.cpp:676
+  return false;
+
+if (BlockParameterCount > 1)

// Multiple lambdas in the same function call.




Comment at: clang/lib/Format/ContinuationIndenter.cpp:679
+  return true;
+
+if (!PrevNonComment->Role)

// A lambda followed by another arg.




Comment at: clang/lib/Format/ContinuationIndenter.cpp:686-692
+if (!Next)
+  return false;
+
+if (!Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret))
+  return true;
+
+return false;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

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


[PATCH] D157057: [clang-tidy] Implement cppcoreguidelines CP.52

2023-08-03 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 547061.
ccotter added a comment.

- Specify version


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157057

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
@@ -0,0 +1,189 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-no-suspend-with-lock %t
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct coroutine_traits {
+  using promise_type = typename T::promise_type;
+};
+template 
+struct coroutine_handle;
+template <>
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+};
+template 
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+  operator coroutine_handle<>() const noexcept;
+};
+
+template 
+class unique_lock {
+public:
+  unique_lock() noexcept;
+  explicit unique_lock(Mutex );
+  unique_lock& operator=(unique_lock&&);
+  void unlock();
+  Mutex* release() noexcept;
+  Mutex* mutex() const noexcept;
+  void swap(unique_lock& other) noexcept;
+};
+
+class mutex {
+public:
+  mutex() noexcept;
+  ~mutex();
+  mutex(const mutex &) = delete;
+  mutex =(const mutex &) = delete;
+
+  void lock();
+  void unlock();
+};
+} // namespace std
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+Awaiter yield_value(int);
+  };
+};
+// NOLINTEND
+
+std::mutex mtx;
+std::mutex mtx2;
+
+Coro awaits_with_lock() {
+  std::unique_lock lock(mtx);
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  if (true) {
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  if (true) {
+std::unique_lock lock2;
+lock2.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock2' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+}
+
+Coro awaits_with_lock_in_try() try {
+  std::unique_lock lock(mtx);
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+} catch (...) {}
+
+Coro lock_possibly_unlocked() {
+  // CppCoreGuideline CP.52's enforcement strictly requires flagging
+  // code that suspends while any lock guard is not destructed.
+
+  {
+std::unique_lock lock(mtx);
+lock.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock.release();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2;
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2{mtx2};
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock = std::unique_lock{};
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held 

[PATCH] D157057: [clang-tidy] Implement cppcoreguidelines CP.52

2023-08-03 Thread Chris Cotter via Phabricator via cfe-commits
ccotter created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, shchenz, kbarton, xazax.hun, 
nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
ccotter requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Flag code that suspends a coroutine while a lock is held.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157057

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
@@ -0,0 +1,189 @@
+// RUN: %check_clang_tidy -std=c++20-or-later %s cppcoreguidelines-no-suspend-with-lock %t
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct coroutine_traits {
+  using promise_type = typename T::promise_type;
+};
+template 
+struct coroutine_handle;
+template <>
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+};
+template 
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+  operator coroutine_handle<>() const noexcept;
+};
+
+template 
+class unique_lock {
+public:
+  unique_lock() noexcept;
+  explicit unique_lock(Mutex );
+  unique_lock& operator=(unique_lock&&);
+  void unlock();
+  Mutex* release() noexcept;
+  Mutex* mutex() const noexcept;
+  void swap(unique_lock& other) noexcept;
+};
+
+class mutex {
+public:
+  mutex() noexcept;
+  ~mutex();
+  mutex(const mutex &) = delete;
+  mutex =(const mutex &) = delete;
+
+  void lock();
+  void unlock();
+};
+} // namespace std
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+Awaiter yield_value(int);
+  };
+};
+// NOLINTEND
+
+std::mutex mtx;
+std::mutex mtx2;
+
+Coro awaits_with_lock() {
+  std::unique_lock lock(mtx);
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  if (true) {
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  if (true) {
+std::unique_lock lock2;
+lock2.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock2' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+}
+
+Coro awaits_with_lock_in_try() try {
+  std::unique_lock lock(mtx);
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+} catch (...) {}
+
+Coro lock_possibly_unlocked() {
+  // CppCoreGuideline CP.52's enforcement strictly requires flagging
+  // code that suspends while any lock guard is not destructed.
+
+  {
+std::unique_lock lock(mtx);
+lock.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock.release();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2;
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2{mtx2};
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held 

[PATCH] D157055: [clang][deps] Avoid unnecessary work for seen dependencies

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Modular dependencies the client has already seen don't need to be reported 
again. This patch leverages that to skip somewhat expensive computation: 
generating the full command line and collecting the full set of file 
dependencies. Everything else is necessary for computation of the canonical 
context hash, which we cannot skip.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157055

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

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -406,7 +406,8 @@
 MDC.ProvidedStdCXXModule, MDC.RequiredStdCXXModules);
 
   for (auto & : MDC.ModularDeps)
-MDC.Consumer.handleModuleDependency(*I.second);
+if (!MDC.Consumer.alreadySeenModuleDependency(I.second->ID))
+  MDC.Consumer.handleModuleDependency(*I.second);
 
   for (const Module *M : MDC.DirectModularDeps) {
 auto It = MDC.ModularDeps.find(M);
@@ -458,19 +459,6 @@
   serialization::ModuleFile *MF =
   MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
   M->getASTFile());
-  MDC.ScanInstance.getASTReader()->visitInputFiles(
-  *MF, true, true, [&](const serialization::InputFile , bool isSystem) {
-// __inferred_module.map is the result of the way in which an implicit
-// module build handles inferred modules. It adds an overlay VFS with
-// this file in the proper directory and relies on the rest of Clang to
-// handle it like normal. With explicitly built modules we don't need
-// to play VFS tricks, so replace it with the correct module map.
-if (IF.getFile()->getName().endswith("__inferred_module.map")) {
-  MDC.addFileDep(MD, ModuleMap->getName());
-  return;
-}
-MDC.addFileDep(MD, IF.getFile()->getName());
-  });
 
   llvm::DenseSet SeenDeps;
   addAllSubmodulePrebuiltDeps(M, MD, SeenDeps);
@@ -493,11 +481,28 @@
 
   MDC.associateWithContextHash(CI, MD);
 
+  if (MDC.Consumer.alreadySeenModuleDependency(MD.ID))
+return MD.ID;
+
   // Finish the compiler invocation. Requires dependencies and the context hash.
   MDC.addOutputPaths(CI, MD);
 
   MD.BuildArguments = CI.getCC1CommandLine();
 
+  MDC.ScanInstance.getASTReader()->visitInputFiles(
+  *MF, true, true, [&](const serialization::InputFile , bool isSystem) {
+// __inferred_module.map is the result of the way in which an implicit
+// module build handles inferred modules. It adds an overlay VFS with
+// this file in the proper directory and relies on the rest of Clang to
+// handle it like normal. With explicitly built modules we don't need
+// to play VFS tricks, so replace it with the correct module map.
+if (IF.getFile()->getName().endswith("__inferred_module.map")) {
+  MDC.addFileDep(MD, ModuleMap->getName());
+  return;
+}
+MDC.addFileDep(MD, IF.getFile()->getName());
+  });
+
   return MD.ID;
 }
 
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -172,15 +172,7 @@
   TU.FileDeps = std::move(Dependencies);
   TU.PrebuiltModuleDeps = std::move(PrebuiltModuleDeps);
   TU.Commands = std::move(Commands);
-
-  for (auto & : ClangModuleDeps) {
-auto  = M.second;
-// TODO: Avoid handleModuleDependency even being called for modules
-//   we've already seen.
-if (AlreadySeen.count(M.first))
-  continue;
-TU.ModuleGraph.push_back(std::move(MD));
-  }
+  TU.ModuleGraph = takeModuleGraphDeps();
   TU.ClangModuleDeps = std::move(DirectModuleDeps);
 
   return TU;
@@ -189,14 +181,8 @@
 ModuleDepsGraph FullDependencyConsumer::takeModuleGraphDeps() {
   ModuleDepsGraph ModuleGraph;
 
-  for (auto & : ClangModuleDeps) {
-auto  = M.second;
-// TODO: Avoid handleModuleDependency even being called for modules
-//   we've already seen.
-if (AlreadySeen.count(M.first))
-  continue;
+  for (auto &&[ID, MD] : ClangModuleDeps)
 ModuleGraph.push_back(std::move(MD));
-  }
 
   return ModuleGraph;
 }
Index: 

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

2023-08-03 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

> rpass flag now prints remarks when requested but does not display
> the passName used, i.e [-Rpass=inline]

I think the location information is also not printed. Please check the 
difference in implementation of the `TextDiagnosticPrinter::HandleDiagnostic` 
function in clang 
(https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/clang/lib/Frontend/TextDiagnosticPrinter.cpp#L109)
 and flang 
(https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/flang/lib/Frontend/TextDiagnosticPrinter.cpp#L32).
In particular, the passName is printed in the printDiagnosticOptions function 
https://github.com/llvm/llvm-project/blob/7240008c0afa3e2d12f3f51cfe0235668feb6ef3/clang/lib/Frontend/TextDiagnosticPrinter.cpp#L85




Comment at: clang/lib/Basic/DiagnosticIDs.cpp:796-797
 Diag.ErrorOccurred = true;
-if (Diag.Client->IncludeInDiagnosticCounts()) {
+if (Diag.Client->IncludeInDiagnosticCounts())
   ++Diag.NumErrors;
 

Looks like an unrelated change.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:772
 
-  Diags.Report(Loc, DiagID)
-  << AddFlagValue(D.getPassName())
-  << MsgStream.str();
+  Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName()) << 
MsgStream.str();
 

Looks like an unrelated change.


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] D157046: [clang] Abstract away string allocation in command line generation

2023-08-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4323
+GenerateArg(Consumer, OPT_darwin_target_variant_sdk_version_EQ,
+Opts.DarwinTargetVariantSDKVersion.getAsString());
 }

Maybe not worth micro optimizing, but I noticed these two are allocating 
strings unnecessarily if we had an overload for things that can print to a 
raw_ostream.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157046

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


[PATCH] D157054: [clang] NFC: Use compile-time option spelling when generating command line

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When generating command lines, use the option spelling generated by TableGen 
(`StringLiteral`) instead of constructing it at runtime. This saves some 
needless allocations.

Depends on D157029 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157054

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -628,7 +628,7 @@
 llvm::opt::OptSpecifier OptSpecifier,
 CompilerInvocation::StringAllocator SA) {
   Option Opt = getDriverOptTable().getOption(OptSpecifier);
-  denormalizeSimpleFlag(Args, SA(Opt.getPrefix() + Opt.getName()), SA,
+  denormalizeSimpleFlag(Args, Opt.getSpelling(), SA,
 Option::OptionClass::FlagClass, 0);
 }
 
@@ -637,8 +637,7 @@
 const Twine ,
 CompilerInvocation::StringAllocator SA) {
   Option Opt = getDriverOptTable().getOption(OptSpecifier);
-  denormalizeString(Args, SA(Opt.getPrefix() + Opt.getName()), SA,
-Opt.getKind(), 0, Value);
+  denormalizeString(Args, Opt.getSpelling(), SA, Opt.getKind(), 0, Value);
 }
 
 // Parse command line arguments into CompilerInvocation.


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -628,7 +628,7 @@
 llvm::opt::OptSpecifier OptSpecifier,
 CompilerInvocation::StringAllocator SA) {
   Option Opt = getDriverOptTable().getOption(OptSpecifier);
-  denormalizeSimpleFlag(Args, SA(Opt.getPrefix() + Opt.getName()), SA,
+  denormalizeSimpleFlag(Args, Opt.getSpelling(), SA,
 Option::OptionClass::FlagClass, 0);
 }
 
@@ -637,8 +637,7 @@
 const Twine ,
 CompilerInvocation::StringAllocator SA) {
   Option Opt = getDriverOptTable().getOption(OptSpecifier);
-  denormalizeString(Args, SA(Opt.getPrefix() + Opt.getName()), SA,
-Opt.getKind(), 0, Value);
+  denormalizeString(Args, Opt.getSpelling(), SA, Opt.getKind(), 0, Value);
 }
 
 // Parse command line arguments into CompilerInvocation.
___
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-03 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a subscriber: lei.
jroelofs added a comment.

In D74094#4559037 , @dexonsmith wrote:

> In D74094#4554327 , @foad wrote:
>
>> Hi @erik.pilkington, I see this got reverted:
>
> I'm not sure if @erik.pilkington is still watching Phabricator, but in any 
> case I think (like me) he no longer has rdar access. Since this was a Linux 
> PPC bot, it's possible Erik didn't get far investigating the failure. Three 
> years later, the sands may have shifted substantially... maybe the best 
> option to is rebase and investigate the new failures (if any).
>
> @akyrtzi @arphaman @jroelofs, is one of you available to check 
> rdar://58552124, in case it has extra context from the PPC bot failure?

I found rdar://59400672&60009515, which track the revert and reminder to 
investigate.  Neither go into any more detail on how/why it broke that bot, 
unfortunately.  I also found 
https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 has a tiny 
bit more context than this review.  Maybe @lei can share the reproducer 
mentioned in that thread?  Otherwise, as Duncan said, I think your best bet is 
to try to re-land and see what breaks.


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] D157050: [clang] NFC: Avoid double allocation when generating command line

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 abandoned this revision.
jansvoboda11 added a comment.

In D157050#4559138 , @benlangmuir 
wrote:

> Dupe of https://reviews.llvm.org/D157048 ?

Yes, weird. Closing this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157050

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


[PATCH] D157052: [clang][deps] NFC: Speed up canonical context hash computation

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch makes use of the infrastructure established in D157046 
 to speed up computation of the canonical 
context hash in the dependency scanner. This is somewhat hot code, since it's 
ran for all modules in the dependency graph of every TU.

I also tried an alternative approach that tried to avoid allocations as much as 
possible (essentially doing `HashBuilder.add(Arg.toStringRef(ArgVec))`), but 
that turned out to be slower than approach in this patch.

Note that this is not problematic in the same way command-line hashing used to 
be prior D143027 . The lambda is now being 
called even for constant strings.

Depends on D157046 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157052

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


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -269,12 +269,13 @@
   HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
 
   // Hash the BuildInvocation without any input files.
-  SmallVector Args;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver(Alloc);
-  CI.generateCC1CommandLine(
-  Args, [&](const Twine ) { return Saver.save(Arg).data(); });
-  HashBuilder.addRange(Args);
+  SmallString<0> ArgVec;
+  ArgVec.reserve(4096);
+  CI.generateCC1CommandLine([&](const Twine ) {
+Arg.toVector(ArgVec);
+ArgVec.push_back('\0');
+  });
+  HashBuilder.add(ArgVec);
 
   // Hash the module dependencies. These paths may differ even if the 
invocation
   // is identical if they depend on the contents of the files in the TU -- for


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -269,12 +269,13 @@
   HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
 
   // Hash the BuildInvocation without any input files.
-  SmallVector Args;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver(Alloc);
-  CI.generateCC1CommandLine(
-  Args, [&](const Twine ) { return Saver.save(Arg).data(); });
-  HashBuilder.addRange(Args);
+  SmallString<0> ArgVec;
+  ArgVec.reserve(4096);
+  CI.generateCC1CommandLine([&](const Twine ) {
+Arg.toVector(ArgVec);
+ArgVec.push_back('\0');
+  });
+  HashBuilder.add(ArgVec);
 
   // Hash the module dependencies. These paths may differ even if the invocation
   // is identical if they depend on the contents of the files in the TU -- for
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157050: [clang] NFC: Avoid double allocation when generating command line

2023-08-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

Dupe of https://reviews.llvm.org/D157048 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157050

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


[PATCH] D157050: [clang] NFC: Avoid double allocation when generating command line

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch makes use of the infrastructure established in D157046 
 to avoid needless allocations via 
`StringSaver`.

Depends on D157046 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157050

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including 
"-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including "-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157048: [clang] NFC: Avoid double allocation when generating command line

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch makes use of the infrastructure established in D157046 
 to avoid needless allocations via 
`StringSaver`.

Depends on D157046 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157048

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including 
"-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4611,17 +4611,10 @@
 }
 
 std::vector CompilerInvocation::getCC1CommandLine() const {
-  // Set up string allocator.
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Strings(Alloc);
-  auto SA = [](const Twine ) { return Strings.save(Arg).data(); };
-
-  // Synthesize full command line from the CompilerInvocation, including "-cc1".
-  SmallVector Args{"-cc1"};
-  generateCC1CommandLine(Args, SA);
-
-  // Convert arguments to the return type.
-  return std::vector{Args.begin(), Args.end()};
+  std::vector Args{"-cc1"};
+  generateCC1CommandLine(
+  [](const Twine ) { Args.push_back(Arg.str()); });
+  return Args;
 }
 
 void CompilerInvocation::resetNonModularOptions() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157046: [clang] Abstract string allocation in command line generation

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This patch abstracts away the string allocation and vector push-back from 
command line generation. Instead, **all** generated arguments are passed into 
`ArgumentConsumer`, which may choose to do the string allocation and vector 
push-back, or something else entirely.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157046

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -165,6 +165,8 @@
 // Normalizers
 //===--===//
 
+using ArgumentConsumer = CompilerInvocation::ArgumentConsumer;
+
 #define SIMPLE_ENUM_VALUE_TABLE
 #include "clang/Driver/Options.inc"
 #undef SIMPLE_ENUM_VALUE_TABLE
@@ -191,13 +193,10 @@
 /// denormalizeSimpleFlags never looks at it. Avoid bloating compile-time with
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
-static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const Twine ,
-  CompilerInvocation::StringAllocator,
-  Option::OptionClass, unsigned, /*T*/...) {
-  // Spelling is already allocated or a static string, no need to call SA.
-  assert(*Spelling.getSingleStringRef().end() == '\0');
-  Args.push_back(Spelling.getSingleStringRef().data());
+static void denormalizeSimpleFlag(ArgumentConsumer Consumer,
+  const Twine , Option::OptionClass,
+  unsigned, /*T*/...) {
+  Consumer(Spelling);
 }
 
 template  static constexpr bool is_uint64_t_convertible() {
@@ -234,34 +233,27 @@
 }
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
-  return [Value](SmallVectorImpl , const Twine ,
- CompilerInvocation::StringAllocator, Option::OptionClass,
- unsigned, bool KeyPath) {
-if (KeyPath == Value) {
-  // Spelling is already allocated or a static string, no need to call SA.
-  assert(*Spelling.getSingleStringRef().end() == '\0');
-  Args.push_back(Spelling.getSingleStringRef().data());
-}
+  return [Value](ArgumentConsumer Consumer, const Twine ,
+ Option::OptionClass, unsigned, bool KeyPath) {
+if (KeyPath == Value)
+  Consumer(Spelling);
   };
 }
 
-static void denormalizeStringImpl(SmallVectorImpl ,
+static void denormalizeStringImpl(ArgumentConsumer Consumer,
   const Twine ,
-  CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned,
   const Twine ) {
   switch (OptClass) {
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
   case Option::JoinedAndSeparateClass:
-// Spelling is already allocated or a static string, no need to call SA.
-assert(*Spelling.getSingleStringRef().end() == '\0');
-Args.push_back(Spelling.getSingleStringRef().data());
-Args.push_back(SA(Value));
+Consumer(Spelling);
+Consumer(Value);
 break;
   case Option::JoinedClass:
   case Option::CommaJoinedClass:
-Args.push_back(SA(Twine(Spelling) + Value));
+Consumer(Spelling + Value);
 break;
   default:
 llvm_unreachable("Cannot denormalize an option with option class "
@@ -270,11 +262,10 @@
 }
 
 template 
-static void
-denormalizeString(SmallVectorImpl , const Twine ,
-  CompilerInvocation::StringAllocator SA,
-  Option::OptionClass OptClass, unsigned TableIndex, T Value) {
-  denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, Twine(Value));
+static void denormalizeString(ArgumentConsumer Consumer, const Twine ,
+  Option::OptionClass OptClass, unsigned TableIndex,
+  T Value) {
+  denormalizeStringImpl(Consumer, Spelling, OptClass, TableIndex, Twine(Value));
 }
 
 static std::optional
@@ -315,15 +306,14 @@
   return std::nullopt;
 }
 
-static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
+static void denormalizeSimpleEnumImpl(ArgumentConsumer Consumer,
   const Twine ,
-  CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < 

[PATCH] D155850: [Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-08-03 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 547024.
AlexVlx added a comment.

Remove noise, correct style.


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

https://reviews.llvm.org/D155850

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenStdPar/unannotated-functions-get-emitted.cpp
  clang/test/CodeGenStdPar/unsupported-builtins.cpp

Index: clang/test/CodeGenStdPar/unsupported-builtins.cpp
===
--- /dev/null
+++ clang/test/CodeGenStdPar/unsupported-builtins.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --stdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo() { return __builtin_ia32_pause(); }
+
+// CHECK: declare void @__builtin_ia32_pause__stdpar_unsupported()
Index: clang/test/CodeGenStdPar/unannotated-functions-get-emitted.cpp
===
--- /dev/null
+++ clang/test/CodeGenStdPar/unannotated-functions-get-emitted.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=NO-STDPAR-DEV %s
+
+// RUN: %clang_cc1 --stdpar -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=STDPAR-DEV %s
+
+#define __device__ __attribute__((device))
+
+// NO-STDPAR-DEV-NOT: define {{.*}} void @_Z3fooPff({{.*}})
+// STDPAR-DEV: define {{.*}} void @_Z3fooPff({{.*}})
+void foo(float *a, float b) {
+  *a = b;
+}
+
+// NO-STDPAR-DEV: define {{.*}} void @_Z3barPff({{.*}})
+// STDPAR-DEV: define {{.*}} void @_Z3barPff({{.*}})
+__device__ void bar(float *a, float b) {
+  *a = b;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3550,7 +3550,10 @@
   !Global->hasAttr() &&
   !Global->hasAttr() &&
   !Global->getType()->isCUDADeviceBuiltinSurfaceType() &&
-  !Global->getType()->isCUDADeviceBuiltinTextureType())
+  !Global->getType()->isCUDADeviceBuiltinTextureType() &&
+  !(LangOpts.HIPStdPar &&
+isa(Global) &&
+!Global->hasAttr()))
 return;
 } else {
   // We need to emit host-side 'shadows' for all global
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -2238,6 +2238,19 @@
   return nullptr;
 }
 
+static RValue EmitStdParUnsupportedBuiltin(CodeGenFunction *CGF,
+   const FunctionDecl *FD) {
+  auto Name = FD->getNameAsString() + "__stdpar_unsupported";
+  auto FnTy = CGF->CGM.getTypes().GetFunctionType(FD);
+  auto UBF = CGF->CGM.getModule().getOrInsertFunction(Name, FnTy);
+
+  SmallVector Args;
+  for (auto & : FnTy->params())
+Args.push_back(llvm::PoisonValue::get(FormalTy));
+
+  return RValue::get(CGF->Builder.CreateCall(UBF, Args));
+}
+
 RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -5545,6 +5558,9 @@
 llvm_unreachable("Bad evaluation kind in EmitBuiltinExpr");
   }
 
+  if (getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice)
+return EmitStdParUnsupportedBuiltin(this, FD);
+
   ErrorUnsupported(E, "builtin function");
 
   // Unknown builtin, for now just dump it out and return undef.
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -77,6 +77,7 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/StdPar/StdPar.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -1093,6 +1094,16 @@
   TheModule->addModuleFlag(Module::Error, "UnifiedLTO", uint32_t(1));
   }
 
+  if (LangOpts.HIPStdPar) {
+if (LangOpts.CUDAIsDevice) {
+  if (!TargetTriple.isAMDGCN())
+MPM.addPass(StdParAcceleratorCodeSelectionPass());
+}
+else if (LangOpts.HIPStdParInterposeAlloc) {
+  MPM.addPass(StdParAllocationInterpositionPass());
+}
+  }
+
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154999: [clang-tidy] Add bugprone-std-forward-type-mismatch check

2023-08-03 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/std-forward-type-mismatch.rst:18
+doSomething(std::forward(base)); // Incorrect usage
+doSomething(static_cast(base)); // Suggested usage
+  }

How confident are we to suggest a fixit to use `static_cast`? Although 
equivalent, the code could be incorrect to begin with and merit manual review 
to decide what the correct cast really should be.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/std-forward-type-mismatch.cpp:116
+void testPartialTemplateBad(WrapperEx value) {
+  test(std::forward>(value));
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: using 'std::forward' for type 
conversions from 'WrapperEx' to 'Wrapper' is not recommended here, use 
'static_cast' instead

Does this check work if `testPartialTemplateBad` is not instantiated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154999

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


[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals

2023-08-03 Thread Alex Voicu 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 rG7240008c0afa: [Clang][CodeGen] `__dynamic_cast` should care 
about `type_info`s address space (authored by AlexVlx).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155870

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/dynamic-cast-address-space.cpp


Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm 
-fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1338,15 +1338,16 @@
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction ) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptrdiff_t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 


Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1338,15 +1338,16 @@
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction ) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptrdiff_t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7240008 - [Clang][CodeGen] `__dynamic_cast` should care about `type_info`'s address space

2023-08-03 Thread Alex Voicu via cfe-commits

Author: Alex Voicu
Date: 2023-08-03T23:25:06+01:00
New Revision: 7240008c0afa3e2d12f3f51cfe0235668feb6ef3

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

LOG: [Clang][CodeGen] `__dynamic_cast` should care about `type_info`'s address 
space

`__dynamic_cast` relies on `type_info`, which its signature assumed to be in 
the generic / default address space. This patch corrects the oversight (we know 
that `type_info` resides in the GlobalVar address space)  and adds an 
associated test.

Reviewed By: yaxunl

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

Added: 
clang/test/CodeGenCXX/dynamic-cast-address-space.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index c8073e248f5c1f..36730875ef0aa4 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1338,15 +1338,16 @@ void ItaniumCXXABI::emitThrow(CodeGenFunction , 
const CXXThrowExpr *E) {
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction ) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptr
diff _t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 

diff  --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
new file mode 100644
index 00..c278988c9647ba
--- /dev/null
+++ b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm 
-fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }



___
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-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added subscribers: arphaman, akyrtzi, jroelofs.
dexonsmith added a comment.

In D74094#4554327 , @foad wrote:

> Hi @erik.pilkington, I see this got reverted:

I'm not sure if @erik.pilkington is still watching Phabricator, but in any case 
I think (like me) he no longer has rdar access. Since this was a Linux PPC bot, 
it's possible Erik didn't get far investigating the failure. Three years later, 
the sands may have shifted substantially... maybe the best option to is rebase 
and investigate the new failures (if any).

@akyrtzi @arphaman @jroelofs, is one of you available to check rdar://58552124, 
in case it has extra context from the PPC bot failure?


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] D157029: [llvm] Construct option spelling at compile-time

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

Rebase on top of D157028 .


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/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  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/include/llvm/Option/Option.h
===
--- llvm/include/llvm/Option/Option.h
+++ llvm/include/llvm/Option/Option.h
@@ -100,6 +100,11 @@
 return Info->Name;
   }
 
+  StringLiteral getSpelling() const {
+assert(Info && "Must have a valid info!");
+return Info->Spelling;
+  }
+
   const Option getGroup() const {
 assert(Info && "Must have a valid info!");
 assert(Owner && "Must have a valid owner!");
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -45,6 +45,7 @@
 /// matching.
 ArrayRef Prefixes;
 StringRef Name;
+StringLiteral Spelling;
 const char *HelpText;
 const char *MetaVar;
 unsigned ID;
@@ -298,31 +299,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, SPELLING, 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, SPELLING, ID, KIND, GROUP, ALIAS,   \
+ ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)   \
+  LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, NAME, SPELLING, 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, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS,  \
+FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)   \
   llvm::opt::OptTable::Info {  \
-PREFIX, NAME, HELPTEXT, METAVAR, ID_PREFIX##ID,\
+PREFIX, NAME, SPELLING, HELPTEXT, METAVAR, ID_PREFIX##ID,  \
 llvm::opt::Option::KIND##Class, PARAM, FLAGS, ID_PREFIX##GROUP,\
 ID_PREFIX##ALIAS, ALIASARGS, VALUES\
   }
 
-#define LLVM_CONSTRUCT_OPT_INFO(PREFIX, NAME, ID, KIND, GROUP, ALIAS,  \
-ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR,\
-VALUES)\
-  LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX(OPT_, PREFIX, NAME, ID, KIND, GROUP,  \
- ALIAS, ALIASARGS, FLAGS, PARAM,   \
- HELPTEXT, METAVAR, VALUES)
+#define 

[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 547018.
jansvoboda11 added a comment.
Herald added a reviewer: alexander-shaposhnikov.

Consolidate all usages by extra `_WITH_ID_PREFIX` macros


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

Files:
  clang/include/clang/Driver/Options.h
  clang/lib/Driver/DriverOptions.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  lld/ELF/Driver.h
  lldb/tools/driver/Driver.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.h
  llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
  llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
  llvm/tools/llvm-dwp/llvm-dwp.cpp
  llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
  llvm/tools/llvm-ifs/llvm-ifs.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/tools/llvm-lipo/llvm-lipo.cpp
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/tools/llvm-mt/llvm-mt.cpp
  llvm/tools/llvm-nm/llvm-nm.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-objdump/ObjdumpOptID.h
  llvm/tools/llvm-objdump/llvm-objdump.cpp
  llvm/tools/llvm-rc/llvm-rc.cpp
  llvm/tools/llvm-readobj/llvm-readobj.cpp
  llvm/tools/llvm-size/llvm-size.cpp
  llvm/tools/llvm-strings/llvm-strings.cpp
  llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
  llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
  llvm/tools/sancov/sancov.cpp
  llvm/unittests/Option/OptionParsingTest.cpp

Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -17,9 +17,7 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -47,10 +45,7 @@
 };
 
 static constexpr OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
-   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
+#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/sancov/sancov.cpp
===
--- llvm/tools/sancov/sancov.cpp
+++ llvm/tools/sancov/sancov.cpp
@@ -63,9 +63,7 @@
 using namespace llvm::opt;
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
@@ -78,13 +76,7 @@
 #undef PREFIX
 
 static constexpr opt::OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {\
-  PREFIX,  NAME,  HELPTEXT,\
-  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
-  PARAM,   FLAGS, OPT_##GROUP, \
-  OPT_##ALIAS, ALIASARGS, VALUES},
+#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
===
--- llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -28,9 +28,7 @@
 namespace {
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
@@ -43,13 +41,7 @@
 #undef PREFIX
 
 static constexpr opt::OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   

[PATCH] D157035: [clang][cli] Accept option spelling as `Twine`

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG243bc7504965: [clang][cli] Accept option spelling as `Twine` 
(authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157035

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,12 @@
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no need to call SA.
+  assert(*Spelling.getSingleStringRef().end() == '\0');
+  Args.push_back(Spelling.getSingleStringRef().data());
 }
 
 template  static constexpr bool is_uint64_t_convertible() {
@@ -232,16 +234,19 @@
 }
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
-  return [Value](SmallVectorImpl , const char *Spelling,
+  return [Value](SmallVectorImpl , const Twine ,
  CompilerInvocation::StringAllocator, Option::OptionClass,
  unsigned, bool KeyPath) {
-if (KeyPath == Value)
-  Args.push_back(Spelling);
+if (KeyPath == Value) {
+  // Spelling is already allocated or a static string, no need to call SA.
+  assert(*Spelling.getSingleStringRef().end() == '\0');
+  Args.push_back(Spelling.getSingleStringRef().data());
+}
   };
 }
 
 static void denormalizeStringImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned,
   const Twine ) {
@@ -249,7 +254,9 @@
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
   case Option::JoinedAndSeparateClass:
-Args.push_back(Spelling);
+// Spelling is already allocated or a static string, no need to call SA.
+assert(*Spelling.getSingleStringRef().end() == '\0');
+Args.push_back(Spelling.getSingleStringRef().data());
 Args.push_back(SA(Value));
 break;
   case Option::JoinedClass:
@@ -264,7 +271,7 @@
 
 template 
 static void
-denormalizeString(SmallVectorImpl , const char *Spelling,
+denormalizeString(SmallVectorImpl , const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned TableIndex, T Value) {
   denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, 
Twine(Value));
@@ -309,7 +316,7 @@
 }
 
 static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
@@ -326,7 +333,7 @@
 
 template 
 static void denormalizeSimpleEnum(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, T Value) {
@@ -367,7 +374,7 @@
 }
 
 static void denormalizeStringVector(SmallVectorImpl ,
-const char *Spelling,
+const Twine ,
 CompilerInvocation::StringAllocator SA,
 Option::OptionClass OptClass,
 unsigned TableIndex,


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,12 @@
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  

[clang] 243bc75 - [clang][cli] Accept option spelling as `Twine`

2023-08-03 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-08-03T15:09:52-07:00
New Revision: 243bc7504965b885c34487f358d2a4b4a355a6b5

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

LOG: [clang][cli] Accept option spelling as `Twine`

This will make it possible to accept the spelling as `StringLiteral` in D157029 
and avoid some unnecessary allocations in a later patch.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1fba91bed04141..1e990f4663d44f 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,12 @@ static std::optional 
normalizeSimpleNegativeFlag(OptSpecifier Opt,
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no need to call SA.
+  assert(*Spelling.getSingleStringRef().end() == '\0');
+  Args.push_back(Spelling.getSingleStringRef().data());
 }
 
 template  static constexpr bool is_uint64_t_convertible() {
@@ -232,16 +234,19 @@ static auto makeBooleanOptionNormalizer(bool Value, bool 
OtherValue,
 }
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
-  return [Value](SmallVectorImpl , const char *Spelling,
+  return [Value](SmallVectorImpl , const Twine ,
  CompilerInvocation::StringAllocator, Option::OptionClass,
  unsigned, bool KeyPath) {
-if (KeyPath == Value)
-  Args.push_back(Spelling);
+if (KeyPath == Value) {
+  // Spelling is already allocated or a static string, no need to call SA.
+  assert(*Spelling.getSingleStringRef().end() == '\0');
+  Args.push_back(Spelling.getSingleStringRef().data());
+}
   };
 }
 
 static void denormalizeStringImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned,
   const Twine ) {
@@ -249,7 +254,9 @@ static void denormalizeStringImpl(SmallVectorImpl ,
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
   case Option::JoinedAndSeparateClass:
-Args.push_back(Spelling);
+// Spelling is already allocated or a static string, no need to call SA.
+assert(*Spelling.getSingleStringRef().end() == '\0');
+Args.push_back(Spelling.getSingleStringRef().data());
 Args.push_back(SA(Value));
 break;
   case Option::JoinedClass:
@@ -264,7 +271,7 @@ static void denormalizeStringImpl(SmallVectorImpl ,
 
 template 
 static void
-denormalizeString(SmallVectorImpl , const char *Spelling,
+denormalizeString(SmallVectorImpl , const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned TableIndex, T Value) {
   denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, 
Twine(Value));
@@ -309,7 +316,7 @@ static std::optional 
normalizeSimpleEnum(OptSpecifier Opt,
 }
 
 static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
@@ -326,7 +333,7 @@ static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
 
 template 
 static void denormalizeSimpleEnum(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, T Value) {
@@ -367,7 +374,7 @@ normalizeStringVector(OptSpecifier Opt, int, const ArgList 
,
 }
 
 static void denormalizeStringVector(SmallVectorImpl ,
-const char *Spelling,
+const Twine ,
 CompilerInvocation::StringAllocator SA,
  

[PATCH] D157035: [clang][cli] Accept option spelling as `Twine`

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

That's a good point. Updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157035

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


[PATCH] D157035: [clang][cli] Accept option spelling as `Twine`

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

Assert that spelling is null-terminated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157035

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,12 @@
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no need to call SA.
+  assert(*Spelling.getSingleStringRef().end() == '\0');
+  Args.push_back(Spelling.getSingleStringRef().data());
 }
 
 template  static constexpr bool is_uint64_t_convertible() {
@@ -232,16 +234,19 @@
 }
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
-  return [Value](SmallVectorImpl , const char *Spelling,
+  return [Value](SmallVectorImpl , const Twine ,
  CompilerInvocation::StringAllocator, Option::OptionClass,
  unsigned, bool KeyPath) {
-if (KeyPath == Value)
-  Args.push_back(Spelling);
+if (KeyPath == Value) {
+  // Spelling is already allocated or a static string, no need to call SA.
+  assert(*Spelling.getSingleStringRef().end() == '\0');
+  Args.push_back(Spelling.getSingleStringRef().data());
+}
   };
 }
 
 static void denormalizeStringImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned,
   const Twine ) {
@@ -249,7 +254,9 @@
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
   case Option::JoinedAndSeparateClass:
-Args.push_back(Spelling);
+// Spelling is already allocated or a static string, no need to call SA.
+assert(*Spelling.getSingleStringRef().end() == '\0');
+Args.push_back(Spelling.getSingleStringRef().data());
 Args.push_back(SA(Value));
 break;
   case Option::JoinedClass:
@@ -264,7 +271,7 @@
 
 template 
 static void
-denormalizeString(SmallVectorImpl , const char *Spelling,
+denormalizeString(SmallVectorImpl , const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned TableIndex, T Value) {
   denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, 
Twine(Value));
@@ -309,7 +316,7 @@
 }
 
 static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
@@ -326,7 +333,7 @@
 
 template 
 static void denormalizeSimpleEnum(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, T Value) {
@@ -367,7 +374,7 @@
 }
 
 static void denormalizeStringVector(SmallVectorImpl ,
-const char *Spelling,
+const Twine ,
 CompilerInvocation::StringAllocator SA,
 Option::OptionClass OptClass,
 unsigned TableIndex,


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,12 @@
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no need to call SA.
+  

[PATCH] D156704: [clang][HeaderSearch] Treat framework headers as System for suggestPath

2023-08-03 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 547011.
dgoldman added a comment.

run clang-format again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156704

Files:
  clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -47,14 +47,18 @@
 Search.AddSearchPath(DL, /*isAngled=*/false);
   }
 
-  void addSystemFrameworkSearchDir(llvm::StringRef Dir) {
+  void addFrameworkSearchDir(llvm::StringRef Dir, bool IsSystem = true) {
 VFS->addFile(
 Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/std::nullopt,
 /*Group=*/std::nullopt, llvm::sys::fs::file_type::directory_file);
 auto DE = FileMgr.getOptionalDirectoryRef(Dir);
 assert(DE);
-auto DL = DirectoryLookup(*DE, SrcMgr::C_System, /*isFramework=*/true);
-Search.AddSystemSearchPath(DL);
+auto DL = DirectoryLookup(*DE, IsSystem ? SrcMgr::C_System : SrcMgr::C_User,
+  /*isFramework=*/true);
+if (IsSystem)
+  Search.AddSystemSearchPath(DL);
+else
+  Search.AddSearchPath(DL, /*isAngled=*/true);
   }
 
   void addHeaderMap(llvm::StringRef Filename,
@@ -175,20 +179,32 @@
 }
 
 TEST_F(HeaderSearchTest, SdkFramework) {
-  addSystemFrameworkSearchDir(
+  addFrameworkSearchDir(
   "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/Frameworks/");
-  bool IsSystem = false;
+  bool IsAngled = false;
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics(
 "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"
 "Frameworks/AppKit.framework/Headers/NSView.h",
 /*WorkingDir=*/"",
-/*MainFile=*/"", ),
+/*MainFile=*/"", ),
 "AppKit/NSView.h");
-  EXPECT_TRUE(IsSystem);
+  EXPECT_TRUE(IsAngled);
+
+  addFrameworkSearchDir("/System/Developer/Library/Framworks/",
+/*IsSystem*/ false);
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics(
+"/System/Developer/Library/Framworks/"
+"Foo.framework/Headers/Foo.h",
+/*WorkingDir=*/"",
+/*MainFile=*/"", ),
+"Foo/Foo.h");
+  // Expect to be true even though we passed false to IsSystem earlier since
+  // all frameworks should be treated as <>.
+  EXPECT_TRUE(IsAngled);
 }
 
 TEST_F(HeaderSearchTest, NestedFramework) {
-  addSystemFrameworkSearchDir("/Platforms/MacOSX/Frameworks");
+  addFrameworkSearchDir("/Platforms/MacOSX/Frameworks");
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics(
 "/Platforms/MacOSX/Frameworks/AppKit.framework/Frameworks/"
 "Sub.framework/Headers/Sub.h",
@@ -199,7 +215,7 @@
 
 TEST_F(HeaderSearchTest, HeaderFrameworkLookup) {
   std::string HeaderPath = "/tmp/Frameworks/Foo.framework/Headers/Foo.h";
-  addSystemFrameworkSearchDir("/tmp/Frameworks");
+  addFrameworkSearchDir("/tmp/Frameworks");
   VFS->addFile(HeaderPath, 0,
llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath),
/*User=*/std::nullopt, /*Group=*/std::nullopt,
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -5682,10 +5682,10 @@
 /// suggesting the addition of a #include of the specified file.
 static std::string getHeaderNameForHeader(Preprocessor , const FileEntry *E,
   llvm::StringRef IncludingFile) {
-  bool IsSystem = false;
+  bool IsAngled = false;
   auto Path = PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(
-  E, IncludingFile, );
-  return (IsSystem ? '<' : '"') + Path + (IsSystem ? '>' : '"');
+  E, IncludingFile, );
+  return (IsAngled ? '<' : '"') + Path + (IsAngled ? '>' : '"');
 }
 
 void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1928,17 +1928,17 @@
 }
 
 std::string HeaderSearch::suggestPathToFileForDiagnostics(
-const FileEntry *File, llvm::StringRef MainFile, bool *IsSystem) const {
+const FileEntry *File, llvm::StringRef MainFile, bool *IsAngled) const {
   // FIXME: We assume that the 

[PATCH] D156762: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-03 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2219
+  // cannot be fixed...
+  eraseVarsForUnfixableGroupMates(FixItsForVariable, VarGrpMgr);
+  // Now `FixItsForVariable` gets further reduced: a variable is in

NoQ wrote:
> NoQ wrote:
> > Architecturally speaking, I think I just realized something confusing about 
> > our code.
> > 
> > We already have variable groups well-defined at the Strategy phase, i.e. 
> > before we call `getFixIts()`, but then `getFixIts()` continues to reason 
> > about all variables collectively and indiscriminately. It continues to use 
> > entities such as the `FixItsForVariable` map which contain fixits for 
> > variables from *all* groups, not just the ones that are currently relevant. 
> > Then it re-introduces per-group data structures such as `ParmsNeedFixMask` 
> > on an ad-hoc basis, and it tries to compute them this way using the global, 
> > indiscriminate data structures.
> > 
> > I'm starting to suspect that the code would start making a lot more sense 
> > if we invoke `getFixIts()` separately for each variable group. So that each 
> > such invocation produced a single collective fixit for the group, or failed 
> > doing so.
> > 
> > This way we might be able to avoid sending steganographic messages through 
> > `FixItsForVariable`, but instead say directly "these are the variables that 
> > we're currently focusing on". It is the responsibility of the `Strategy` 
> > class to answer "should this variable be fixed?"; we shouldn't direct that 
> > question to any other data structures.
> > 
> > And if a group fails at any point, just early-return `None` and proceed 
> > directly to the next getFixIts() invocation for the next group. We don't 
> > need to separately record which individual variables have failed. In 
> > particular, `eraseVarsForUnfixableGroupMates()` would become a simple early 
> > return.
> > 
> > It probably also makes sense to store groups themselves inside the 
> > `Strategy` class. After all, fixing variables together is a form of 
> > strategy.
> (I don't think this needs to be addressed in the current patch, but this 
> could help us untangle the code in general.)
This makes absolute sense!  Each group is independent for fix-it generation.  
Moreover, when we support more strategy kinds, the constraint solving for a 
proper strategy will also be group-based.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156762

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


[PATCH] D157033: [clang][CFG] Fix 2 memory errors in interval computation.

2023-08-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 547008.
ymandel added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157033

Files:
  clang/lib/Analysis/IntervalPartition.cpp
  clang/unittests/Analysis/IntervalPartitionTest.cpp

Index: clang/unittests/Analysis/IntervalPartitionTest.cpp
===
--- clang/unittests/Analysis/IntervalPartitionTest.cpp
+++ clang/unittests/Analysis/IntervalPartitionTest.cpp
@@ -360,5 +360,38 @@
   Optional(blockOrder(9, 8, 7, 6, 1, 0, 5, 4, 2, 3)));
 }
 
+TEST(GetIntervalWTO, UnreachablePred) {
+  const char *Code = R"(
+  void target(bool Foo) {
+bool Bar = false;
+if (Foo)
+  Bar = Foo;
+else
+  __builtin_unreachable();
+(void)0;
+  })";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+  EXPECT_THAT(getIntervalWTO(*Result.getCFG()),
+  Optional(blockOrder(5, 4, 3, 2, 1, 0)));
+}
+
+TEST(WTOCompare, UnreachableBlock) {
+  const char *Code = R"(
+void target() {
+  while (true) {}
+  (void)0;
+  /*[[p]]*/
+})";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+  std::optional WTO = getIntervalWTO(*Result.getCFG());
+  ASSERT_THAT(WTO, Optional(blockOrder(4, 3, 2)));
+  auto Cmp = WTOCompare(*WTO);
+  const CFGBlock  = Result.getCFG()->getEntry();
+  const CFGBlock  = Result.getCFG()->getExit();
+  EXPECT_TRUE(Cmp(, ));
+}
+
 } // namespace
 } // namespace clang
Index: clang/lib/Analysis/IntervalPartition.cpp
===
--- clang/lib/Analysis/IntervalPartition.cpp
+++ clang/lib/Analysis/IntervalPartition.cpp
@@ -16,7 +16,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include 
 #include 
-#include 
 #include 
 
 namespace clang {
@@ -24,23 +23,25 @@
 // Intermediate data used in constructing a CFGIntervalNode.
 template  struct BuildResult {
   // Use a vector to maintain the insertion order. Given the expected small
-  // number of nodes, vector should be sufficiently efficient.
+  // number of nodes, vector should be sufficiently efficient. Elements must not
+  // be null.
   std::vector Nodes;
+  // Elements must not be null.
   llvm::SmallDenseSet Successors;
 };
 
 namespace internal {
-static unsigned getID(const CFGBlock *B) { return B->getBlockID(); }
-static unsigned getID(const CFGIntervalNode *I) { return I->ID; }
+static unsigned getID(const CFGBlock ) { return B.getBlockID(); }
+static unsigned getID(const CFGIntervalNode ) { return I.ID; }
 
 // `Node` must be one of `CFGBlock` or `CFGIntervalNode`.
 template 
 BuildResult buildInterval(llvm::BitVector ,
 const Node *Header) {
-  assert(Header);
+  assert(Header != nullptr);
   BuildResult Interval;
   Interval.Nodes.push_back(Header);
-  Partitioned.set(getID(Header));
+  Partitioned.set(getID(*Header));
 
   // FIXME: Compare performance against using RPO to consider nodes, rather than
   // following successors.
@@ -50,7 +51,7 @@
   llvm::BitVector Workset(Partitioned.size(), false);
   for (const Node *S : Header->succs())
 if (S != nullptr)
-  if (auto SID = getID(S); !Partitioned.test(SID)) {
+  if (auto SID = getID(*S); !Partitioned.test(SID)) {
 // Successors are unique, so we don't test against `Workset` before
 // adding to `Worklist`.
 Worklist.push(S);
@@ -63,12 +64,12 @@
   // yet. In the latter case, we'll revisit the block through some other path
   // from the interval. At the end of processing the worklist, we filter out any
   // that ended up in the interval to produce the output set of interval
-  // successors.
+  // successors. Elements are never null.
   std::vector MaybeSuccessors;
 
   while (!Worklist.empty()) {
 const auto *B = Worklist.front();
-auto ID = getID(B);
+auto ID = getID(*B);
 Worklist.pop();
 Workset.reset(ID);
 
@@ -82,7 +83,7 @@
   Partitioned.set(ID);
   for (const Node *S : B->succs())
 if (S != nullptr)
-  if (auto SID = getID(S);
+  if (auto SID = getID(*S);
   !Partitioned.test(SID) && !Workset.test(SID)) {
 Worklist.push(S);
 Workset.set(SID);
@@ -116,8 +117,9 @@
   // graph. In this case, the new interval has identifier `ID` so all of its
   // nodes (`Result.Nodes`) map to `ID`.
   for (const auto *N : Result.Nodes) {
-assert(getID(N) < Index.size());
-Index[getID(N)] = 
+assert(N != nullptr);
+assert(getID(*N) < Index.size());
+Index[getID(*N)] = 
   }
 
   if constexpr (std::is_same_v, CFGBlock>)
@@ -159,7 +161,8 @@
   while (!Successors.empty()) {
 const auto *B = Successors.front();
 Successors.pop();
-if (Partitioned.test(getID(B)))
+assert(B != nullptr);
+if (Partitioned.test(getID(*B)))
   continue;
 

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

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

In D74094#4554327 , @foad wrote:

> Hi @erik.pilkington, I see this got reverted:
>
>   commit e26c24b849211f35a988d001753e0cd15e4a9d7b
>   Author: Erik Pilkington 
>   Date:   Wed Feb 12 12:02:58 2020 -0800
>   
>   Revert "[IRGen] Emit lifetime intrinsics around temporary aggregate 
> argument allocas"
>   
>   This reverts commit fafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402.
>   
>   Should fix ppc stage2 failure: 
> http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/23546
>
> Do you have any more info on the "ppc stage2 failure"? I'd like to pursue 
> something like this patch to get more accurate lifetime markers for 
> temporaries, so that LLVM stack slot coloring can do a better job, and we get 
> smaller stack usage. This is prompted by 
> https://github.com/llvm/llvm-project/issues/41896

I too am very interested, as this was flagged as a potential help for 
https://github.com/llvm/llvm-project/issues/41896.


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] D157035: [clang][cli] Accept option spelling as `Twine`

2023-08-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

This code asserts that the Twine is a single stringref, but it's also relying 
on the fact it's null-terminated; can we check for that as well, or at least 
document it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157035

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


[PATCH] D157035: [clang][cli] Accept option spelling as `Twine`

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This will make it possible to accept the spelling as `StringLiteral` in D157029 
 and avoid some unnecessary allocations in a 
later patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157035

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,11 @@
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no need to call SA.
+  Args.push_back(Spelling.getSingleStringRef().data());
 }
 
 template  static constexpr bool is_uint64_t_convertible() {
@@ -232,16 +233,17 @@
 }
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
-  return [Value](SmallVectorImpl , const char *Spelling,
+  return [Value](SmallVectorImpl , const Twine ,
  CompilerInvocation::StringAllocator, Option::OptionClass,
  unsigned, bool KeyPath) {
 if (KeyPath == Value)
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no need to call SA.
+  Args.push_back(Spelling.getSingleStringRef().data());
   };
 }
 
 static void denormalizeStringImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned,
   const Twine ) {
@@ -249,7 +251,8 @@
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
   case Option::JoinedAndSeparateClass:
-Args.push_back(Spelling);
+// Spelling is already allocated or a static string, no need to call SA.
+Args.push_back(Spelling.getSingleStringRef().data());
 Args.push_back(SA(Value));
 break;
   case Option::JoinedClass:
@@ -264,7 +267,7 @@
 
 template 
 static void
-denormalizeString(SmallVectorImpl , const char *Spelling,
+denormalizeString(SmallVectorImpl , const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass, unsigned TableIndex, T Value) {
   denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, 
Twine(Value));
@@ -309,7 +312,7 @@
 }
 
 static void denormalizeSimpleEnumImpl(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
@@ -326,7 +329,7 @@
 
 template 
 static void denormalizeSimpleEnum(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
   unsigned TableIndex, T Value) {
@@ -367,7 +370,7 @@
 }
 
 static void denormalizeStringVector(SmallVectorImpl ,
-const char *Spelling,
+const Twine ,
 CompilerInvocation::StringAllocator SA,
 Option::OptionClass OptClass,
 unsigned TableIndex,


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -192,10 +192,11 @@
 /// unnecessary template instantiations and just ignore it with a variadic
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl ,
-  const char *Spelling,
+  const Twine ,
   CompilerInvocation::StringAllocator,
   Option::OptionClass, unsigned, /*T*/...) {
-  Args.push_back(Spelling);
+  // Spelling is already allocated or a static string, no 

[PATCH] D157033: [clang][CFG] Fix 2 memory errors in interval computation.

2023-08-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

This fixes 2 bugs and adds corresponding tests. Both related to unreachable
blocks. One occured in the `WTOCompare` construction, which assumed the size of
the order was the same as the number of blocks in the CFG, which isn't true when
some blocks are unreachable.  The other assumed predecessor pointers were
non-null, which can be false for blocks with unreachable predecessors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157033

Files:
  clang/lib/Analysis/IntervalPartition.cpp
  clang/unittests/Analysis/IntervalPartitionTest.cpp

Index: clang/unittests/Analysis/IntervalPartitionTest.cpp
===
--- clang/unittests/Analysis/IntervalPartitionTest.cpp
+++ clang/unittests/Analysis/IntervalPartitionTest.cpp
@@ -360,5 +360,38 @@
   Optional(blockOrder(9, 8, 7, 6, 1, 0, 5, 4, 2, 3)));
 }
 
+TEST(GetIntervalWTO, UnreachablePred) {
+  const char *Code = R"(
+  void target(bool Foo) {
+bool Bar = false;
+if (Foo)
+  Bar = Foo;
+else
+  __builtin_unreachable();
+(void)0;
+  })";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+  EXPECT_THAT(getIntervalWTO(*Result.getCFG()),
+  Optional(blockOrder(5, 4, 3, 2, 1, 0)));
+}
+
+TEST(WTOCompare, UnreachableBlock) {
+  const char *Code = R"(
+void target() {
+  while (true) {}
+  (void)0;
+  /*[[p]]*/
+})";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+  std::optional WTO = getIntervalWTO(*Result.getCFG());
+  ASSERT_THAT(WTO, Optional(blockOrder(4, 3, 2)));
+  auto Cmp = WTOCompare(*WTO);
+  const CFGBlock  = Result.getCFG()->getEntry();
+  const CFGBlock  = Result.getCFG()->getExit();
+  EXPECT_TRUE(Cmp(, ));
+}
+
 } // namespace
 } // namespace clang
Index: clang/lib/Analysis/IntervalPartition.cpp
===
--- clang/lib/Analysis/IntervalPartition.cpp
+++ clang/lib/Analysis/IntervalPartition.cpp
@@ -16,7 +16,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include 
 #include 
-#include 
 #include 
 
 namespace clang {
@@ -24,23 +23,25 @@
 // Intermediate data used in constructing a CFGIntervalNode.
 template  struct BuildResult {
   // Use a vector to maintain the insertion order. Given the expected small
-  // number of nodes, vector should be sufficiently efficient.
+  // number of nodes, vector should be sufficiently efficient. Elements must not
+  // be null.
   std::vector Nodes;
+  // Elements must not be null.
   llvm::SmallDenseSet Successors;
 };
 
 namespace internal {
-static unsigned getID(const CFGBlock *B) { return B->getBlockID(); }
-static unsigned getID(const CFGIntervalNode *I) { return I->ID; }
+static unsigned getID(const CFGBlock ) { return B.getBlockID(); }
+static unsigned getID(const CFGIntervalNode ) { return I.ID; }
 
 // `Node` must be one of `CFGBlock` or `CFGIntervalNode`.
 template 
 BuildResult buildInterval(llvm::BitVector ,
 const Node *Header) {
-  assert(Header);
+  assert(Header != nullptr);
   BuildResult Interval;
   Interval.Nodes.push_back(Header);
-  Partitioned.set(getID(Header));
+  Partitioned.set(getID(*Header));
 
   // FIXME: Compare performance against using RPO to consider nodes, rather than
   // following successors.
@@ -50,7 +51,7 @@
   llvm::BitVector Workset(Partitioned.size(), false);
   for (const Node *S : Header->succs())
 if (S != nullptr)
-  if (auto SID = getID(S); !Partitioned.test(SID)) {
+  if (auto SID = getID(*S); !Partitioned.test(SID)) {
 // Successors are unique, so we don't test against `Workset` before
 // adding to `Worklist`.
 Worklist.push(S);
@@ -63,12 +64,12 @@
   // yet. In the latter case, we'll revisit the block through some other path
   // from the interval. At the end of processing the worklist, we filter out any
   // that ended up in the interval to produce the output set of interval
-  // successors.
+  // successors. Elements are never null.
   std::vector MaybeSuccessors;
 
   while (!Worklist.empty()) {
 const auto *B = Worklist.front();
-auto ID = getID(B);
+auto ID = getID(*B);
 Worklist.pop();
 Workset.reset(ID);
 
@@ -82,7 +83,7 @@
   Partitioned.set(ID);
   for (const Node *S : B->succs())
 if (S != nullptr)
-  if (auto SID = getID(S);
+  if (auto SID = getID(*S);
   !Partitioned.test(SID) && !Workset.test(SID)) {
 Worklist.push(S);
 Workset.set(SID);
@@ -116,8 +117,9 @@
   // graph. In this case, the new interval has identifier `ID` so all of its
   // nodes (`Result.Nodes`) map to `ID`.
   for (const auto *N : Result.Nodes) {
-  

[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-03 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 546996.
ccotter added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
@@ -5,6 +5,22 @@
 // CHECK-FIXES-NOT: for ({{.*[^:]:[^:].*}})
 // CHECK-MESSAGES-NOT: modernize-loop-convert
 
+namespace somenamespace {
+  template  auto begin(T& t) -> decltype(t.begin());
+  template  auto begin(const T& t) -> decltype(t.begin());
+  template  auto end(T& t) -> decltype(t.end());
+  template  auto end(const T& t) -> decltype(t.end());
+  template  auto size(const T& t) -> decltype(t.size());
+} // namespace somenamespace
+
+struct SomeClass {
+  template  static auto begin(T& t) -> decltype(t.begin());
+  template  static auto begin(const T& t) -> decltype(t.begin());
+  template  static auto end(T& t) -> decltype(t.end());
+  template  static auto end(const T& t) -> decltype(t.end());
+  template  static auto size(const T& t) -> decltype(t.size());
+};
+
 namespace Negative {
 
 const int N = 6;
@@ -92,7 +108,7 @@
   }
 }
 
-}
+} // namespace Negative
 
 namespace NegativeIterator {
 
@@ -103,6 +119,10 @@
 struct BadBeginEnd : T {
   iterator notBegin();
   iterator notEnd();
+  iterator begin(int);
+  iterator end(int);
+  iterator begin();
+  iterator end();
 };
 
 void notBeginOrEnd() {
@@ -112,6 +132,9 @@
 
   for (T::iterator I = Bad.begin(), E = Bad.notEnd();  I != E; ++I)
 int K = *I;
+
+  for (T::iterator I = Bad.begin(0), E = Bad.end(0);  I != E; ++I)
+int K = *I;
 }
 
 void badLoopShapes() {
@@ -202,6 +225,8 @@
   T Other;
   for (T::iterator I = Tt.begin(), E = Other.end();  I != E; ++I)
 int K = *I;
+  for (T::iterator I = begin(Tt), E = end(Other);  I != E; ++I)
+int K = *I;
 
   for (T::iterator I = Other.begin(), E = Tt.end();  I != E; ++I)
 int K = *I;
@@ -214,6 +239,24 @@
 MutableVal K = *I;
 }
 
+void mixedMemberAndADL() {
+  for (T::iterator I = Tt.begin(), E = end(Tt);  I != E; ++I)
+int K = *I;
+  for (T::iterator I = begin(Tt), E = Tt.end();  I != E; ++I)
+int K = *I;
+  for (T::iterator I = std::begin(Tt), E = Tt.end();  I != E; ++I)
+int K = *I;
+  for (T::iterator I = std::begin(Tt), E = end(Tt);  I != E; ++I)
+int K = *I;
+}
+
+void nonADLOrStdCalls() {
+  for (T::iterator I = SomeClass::begin(Tt), E = SomeClass::end(Tt);  I != E; ++I)
+int K = *I;
+  for (T::iterator I = somenamespace::begin(Tt), E = somenamespace::end(Tt);  I != E; ++I)
+int K = *I;
+}
+
 void wrongIterators() {
   T::iterator Other;
   for (T::iterator I = Tt.begin(), E = Tt.end(); I != Other; ++I)
@@ -379,6 +422,13 @@
 Sum += V[I];
 }
 
+void nonADLOrStdCalls() {
+  for (int I = 0, E = somenamespace::size(V); E != I; ++I)
+printf("Fibonacci number is %d\n", V[I]);
+  for (int I = 0, E = SomeClass::size(V); E != I; ++I)
+printf("Fibonacci number is %d\n", V[I]);
+}
+
 // Checks to see that non-const member functions are not called on the container
 // object.
 // These could be conceivably allowed with a lower required confidence level.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -445,6 +445,41 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & I : Dpp)
   // CHECK-FIXES-NEXT: printf("%d\n", I->X);
+
+  for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) {
+printf("s0 has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s0 has value %d\n", It.X);
+
+  for (S::iterator It = std::begin(Ss), E = std::end(Ss); It != E; ++It) {
+printf("s1 has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s1 has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; 

[PATCH] D156911: [clang][CodeGen] Drop some typed pointer bitcasts

2023-08-03 Thread Bjorn Pettersson via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2bdc86484d03: [clang][CodeGen] Drop some typed pointer 
bitcasts (authored by bjope).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156911

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp

Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -647,9 +647,7 @@
   // Apply the adjustment and cast back to the original struct type
   // for consistency.
   llvm::Value *This = ThisAddr.getPointer();
-  llvm::Value *Ptr = Builder.CreateBitCast(This, Builder.getInt8PtrTy());
-  Ptr = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), Ptr, Adj);
-  This = Builder.CreateBitCast(Ptr, This->getType(), "this.adjusted");
+  This = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), This, Adj);
   ThisPtrForCall = This;
 
   // Load the function pointer.
@@ -740,9 +738,8 @@
   ? llvm::Intrinsic::type_test
   : llvm::Intrinsic::public_type_test;
 
-CheckResult = Builder.CreateCall(
-CGM.getIntrinsic(IID),
-{Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId});
+CheckResult =
+Builder.CreateCall(CGM.getIntrinsic(IID), {VFPAddr, TypeId});
   }
 
   if (CGM.getItaniumVTableContext().isRelativeLayout()) {
@@ -812,8 +809,6 @@
   };
 
   llvm::Value *Bit = Builder.getFalse();
-  llvm::Value *CastedNonVirtualFn =
-  Builder.CreateBitCast(NonVirtualFn, CGF.Int8PtrTy);
   for (const CXXRecordDecl *Base : CGM.getMostBaseClasses(RD)) {
 llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(
 getContext().getMemberPointerType(
@@ -824,13 +819,13 @@
 
 llvm::Value *TypeTest =
 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::type_test),
-   {CastedNonVirtualFn, TypeId});
+   {NonVirtualFn, TypeId});
 Bit = Builder.CreateOr(Bit, TypeTest);
   }
 
   CGF.EmitCheck(std::make_pair(Bit, SanitizerKind::CFIMFCall),
 SanitizerHandler::CFICheckFail, StaticData,
-{CastedNonVirtualFn, llvm::UndefValue::get(CGF.IntPtrTy)});
+{NonVirtualFn, llvm::UndefValue::get(CGF.IntPtrTy)});
 
   FnNonVirtual = Builder.GetInsertBlock();
 }
@@ -1253,8 +1248,7 @@
 CGF.getPointerAlign());
 
 // Apply the offset.
-llvm::Value *CompletePtr =
-  CGF.Builder.CreateBitCast(Ptr.getPointer(), CGF.Int8PtrTy);
+llvm::Value *CompletePtr = Ptr.getPointer();
 CompletePtr =
 CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, CompletePtr, Offset);
 
@@ -1454,7 +1448,6 @@
 
   if (CGM.getItaniumVTableContext().isRelativeLayout()) {
 // Load the type info.
-Value = CGF.Builder.CreateBitCast(Value, CGM.Int8PtrTy);
 Value = CGF.Builder.CreateCall(
 CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
 {Value, llvm::ConstantInt::get(CGM.Int32Ty, -4)});
@@ -2211,8 +2204,7 @@
NonVirtualAdjustment);
   }
 
-  // Cast back to the original type.
-  return CGF.Builder.CreateBitCast(ResultPtr, InitialPtr.getType());
+  return ResultPtr;
 }
 
 llvm::Value *ItaniumCXXABI::performThisAdjustment(CodeGenFunction ,
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2049,8 +2049,7 @@
NullConstant, Twine());
 CharUnits NullAlign = DestPtr.getAlignment();
 NullVariable->setAlignment(NullAlign.getAsAlign());
-Address SrcPtr(Builder.CreateBitCast(NullVariable, Builder.getInt8PtrTy()),
-   Builder.getInt8Ty(), NullAlign);
+Address SrcPtr(NullVariable, Builder.getInt8Ty(), NullAlign);
 
 if (vla) return emitNonZeroVLAInit(*this, Ty, DestPtr, SrcPtr, SizeVal);
 
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -3690,8 +3690,8 @@
 
 index = CGF.Builder.CreateMul(index, objectSize);
 
-Value *result = CGF.Builder.CreateBitCast(pointer, CGF.VoidPtrTy);
-result = 

[clang] 2bdc864 - [clang][CodeGen] Drop some typed pointer bitcasts

2023-08-03 Thread Bjorn Pettersson via cfe-commits

Author: Bjorn Pettersson
Date: 2023-08-03T22:54:33+02:00
New Revision: 2bdc86484d03234f5155b0865f33009d0da74da9

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

LOG: [clang][CodeGen] Drop some typed pointer bitcasts

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

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 2023be8838f8a7..a35bae91dc5ba1 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -942,7 +942,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const 
CGBlockInfo ) {
   if (CI.isNested())
 byrefPointer = Builder.CreateLoad(src, "byref.capture");
   else
-byrefPointer = Builder.CreateBitCast(src.getPointer(), VoidPtrTy);
+byrefPointer = src.getPointer();
 
   // Write that void* into the capture field.
   Builder.CreateStore(byrefPointer, blockField);
@@ -1667,7 +1667,6 @@ struct CallBlockRelease final : EHScopeStack::Cleanup {
 llvm::Value *BlockVarAddr;
 if (LoadBlockVarAddr) {
   BlockVarAddr = CGF.Builder.CreateLoad(Addr);
-  BlockVarAddr = CGF.Builder.CreateBitCast(BlockVarAddr, CGF.VoidPtrTy);
 } else {
   BlockVarAddr = Addr.getPointer();
 }
@@ -1975,9 +1974,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const 
CGBlockInfo ) {
 }
 case BlockCaptureEntityKind::BlockObject: {
   llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
-  srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy);
-  llvm::Value *dstAddr =
-  Builder.CreateBitCast(dstField.getPointer(), VoidPtrTy);
+  llvm::Value *dstAddr = dstField.getPointer();
   llvm::Value *args[] = {
 dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, flags.getBitMask())
   };
@@ -2774,10 +2771,8 @@ void CodeGenFunction::emitByrefStructureInit(const 
AutoVarEmission ) {
 void CodeGenFunction::BuildBlockRelease(llvm::Value *V, BlockFieldFlags flags,
 bool CanThrow) {
   llvm::FunctionCallee F = CGM.getBlockObjectDispose();
-  llvm::Value *args[] = {
-Builder.CreateBitCast(V, Int8PtrTy),
-llvm::ConstantInt::get(Int32Ty, flags.getBitMask())
-  };
+  llvm::Value *args[] = {V,
+ llvm::ConstantInt::get(Int32Ty, flags.getBitMask())};
 
   if (CanThrow)
 EmitRuntimeCallOrInvoke(F, args);

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 94ae4cf273055c..45fbbbed1275df 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -215,16 +215,12 @@ static Value *MakeBinaryAtomicValue(
   assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
 
   llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E);
-  unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace();
 
-  llvm::IntegerType *IntType =
-llvm::IntegerType::get(CGF.getLLVMContext(),
-   CGF.getContext().getTypeSize(T));
-  llvm::Type *IntPtrType =
-  llvm::PointerType::get(CGF.getLLVMContext(), AddrSpace);
+  llvm::IntegerType *IntType = llvm::IntegerType::get(
+  CGF.getLLVMContext(), CGF.getContext().getTypeSize(T));
 
   llvm::Value *Args[2];
-  Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
+  Args[0] = DestPtr;
   Args[1] = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Type *ValueType = Args[1]->getType();
   Args[1] = EmitToInt(CGF, Args[1], T, IntType);
@@ -238,12 +234,8 @@ static Value *EmitNontemporalStore(CodeGenFunction , 
const CallExpr *E) {
   Value *Val = CGF.EmitScalarExpr(E->getArg(0));
   Value *Address = CGF.EmitScalarExpr(E->getArg(1));
 
-  // Convert the type of the pointer to a pointer to the stored type.
   Val = CGF.EmitToMemory(Val, E->getArg(0)->getType());
-  unsigned SrcAddrSpace = Address->getType()->getPointerAddressSpace();
-  Value *BC = CGF.Builder.CreateBitCast(
-  Address, llvm::PointerType::get(Val->getType(), SrcAddrSpace), "cast");
-  LValue LV = CGF.MakeNaturalAlignAddrLValue(BC, E->getArg(0)->getType());
+  LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType());
   LV.setNontemporal(true);
   CGF.EmitStoreOfScalar(Val, LV, false);
   return nullptr;
@@ -800,11 +792,6 @@ EncompassingIntegerType(ArrayRef Types) {
 }
 
 Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) {
-  llvm::Type *DestType = Int8PtrTy;
-  if (ArgValue->getType() != DestType)
-ArgValue =
-

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-08-03 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 546991.
ccotter marked an inline comment as done.
ccotter added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-cxx17.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-avoid-c-arrays %t
+// RUN: %check_clang_tidy -std=c++11 %s modernize-avoid-c-arrays %t
+
+//CHECK-FIXES: #include 
 
 int a[] = {1, 2};
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
@@ -86,3 +88,280 @@
   int j[1];
 };
 }
+
+template  struct TStruct {};
+
+void replacements() {
+  int ar[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar;
+  TStruct ar2[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar2;
+  TStruct< int > ar3[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar3;
+  int * ar4[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar4;
+  int * /*comment*/ar5[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array /*comment*/ar5;
+  volatile const int * ar6[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar6;
+  volatile int ar7[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array ar7;
+  int const * ar8[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar8;
+  int ar9[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar9;
+  static int volatile constexpr ar10[10] = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static volatile constexpr std::array ar10 = {{[{][{]}}{{[}][}]}};
+  thread_local int ar11[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local std::array ar11;
+  thread_local/*a*/int/*b*/ar12[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local/*a*/std::array/*b*/ar12;
+  /*a*/ int/*b*/ /*c*/*/*d*/ /*e*/ /*f*/ar13[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: /*a*/ std::array/*d*/ /*e*/ /*f*/ar13;
+  TStruct ar14[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar14;
+  volatile TStruct ar15[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array, 10> ar15;
+  TStruct ar16[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar16;
+  TStruct ar17[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar17;
+  volatile int static thread_local * ar18[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static thread_local std::array ar18;
+
+  // Note, there is a tab '\t' before the semicolon in the declaration below.
+  int ar19[3]	;
+  // 

[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Here's an example of a patch that changes the `OPTION` macro: D157029 
. I wonder if we could have counterparts to 
`LLVM_MAKE_OPT_ID` and `LLVM_CONSTRUCT_OPT_INFO` that allow overriding the 
default `OPT_` prefix. That would make D157029 
 even smaller. WDYT @MaskRay?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

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


[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

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

I'll be away for a few days but I took a quick glance. This change looks 
reasonable. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157028

___
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-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: MaskRay.
Herald added subscribers: ormris, ributzka, kadircet, arphaman, hiraditya.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: jhenderson.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added projects: clang, LLVM, clang-tools-extra.
Herald added subscribers: cfe-commits, llvm-commits.

Some Clang command-line handling code could benefit from the option spelling 
being a `StringLiteral`. This patch changes the `llvm::opt` TableGen backend to 
generate the "canonical" spelling and emit it into the .inc file.

Depends on D157028 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157029

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp
  llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.h
  llvm/tools/llvm-lipo/llvm-lipo.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-objdump/ObjdumpOptID.h
  llvm/tools/llvm-objdump/llvm-objdump.cpp
  llvm/tools/llvm-rc/llvm-rc.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/tools/llvm-rc/llvm-rc.cpp
===
--- llvm/tools/llvm-rc/llvm-rc.cpp
+++ llvm/tools/llvm-rc/llvm-rc.cpp
@@ -77,8 +77,8 @@
 
 enum Windres_ID {
   WINDRES_INVALID = 0, // This is not a correct option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
+#define OPTION(PREFIX, NAME, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS,  \
+   FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)\
   WINDRES_##ID,
 #include "WindresOpts.inc"
 #undef OPTION
@@ -93,12 +93,21 @@
 #undef PREFIX
 
 static constexpr opt::OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {PREFIX,  NAME, HELPTEXT,\
-   METAVAR, WINDRES_##ID, opt::Option::KIND##Class,\
-   PARAM,   FLAGS,WINDRES_##GROUP, \
-   WINDRES_##ALIAS, ALIASARGS,VALUES},
+#define OPTION(PREFIX, NAME, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS,  \
+   FLAGS, PARAM, HELPTEXT, METAVAR, VALUES)\
+  {PREFIX, \
+   NAME,   \
+   SPELLING,   \
+   HELPTEXT,   \
+   METAVAR,\
+   WINDRES_##ID,   \
+   opt::Option::KIND##Class,   \
+   PARAM,  \
+   FLAGS,  \
+   WINDRES_##GROUP,\
+   WINDRES_##ALIAS,\
+   ALIASARGS,  \
+   VALUES},
 #include "WindresOpts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -128,12 +128,21 @@
 #undef PREFIX
 
 static constexpr opt::OptTable::Info ObjdumpInfoTable[] = 

[PATCH] D156172: [clang][CodeGen] Emit annotations for function declarations.

2023-08-03 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl updated this revision to Diff 546986.
brendandahl added a comment.

Cleanup some extra brackets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156172

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/annotations-decl-use-decl.c
  clang/test/CodeGen/annotations-decl-use-define.c
  clang/test/CodeGen/annotations-declaration.c
  clang/test/CodeGen/annotations-global.c
  clang/test/CodeGenCXX/attr-annotate-destructor.cpp
  clang/test/CodeGenCXX/attr-annotate.cpp

Index: clang/test/CodeGenCXX/attr-annotate.cpp
===
--- clang/test/CodeGenCXX/attr-annotate.cpp
+++ clang/test/CodeGenCXX/attr-annotate.cpp
@@ -3,9 +3,9 @@
 //CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata"
 //CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1
 //CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
-//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
-//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
-//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS:.*]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS2]] }]
+//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
+//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
+//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS2:.*]] }]
 
 constexpr const char* str() {
   return "abc";
Index: clang/test/CodeGenCXX/attr-annotate-destructor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-annotate-destructor.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
+
+// Test annotation attributes on destructors doesn't crash.
+
+struct k {
+  ~k() __attribute__((annotate(""))) {}
+};
+void m() { k(); }
+
+// CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{
Index: clang/test/CodeGen/annotations-global.c
===
--- clang/test/CodeGen/annotations-global.c
+++ clang/test/CodeGen/annotations-global.c
@@ -33,15 +33,15 @@
 // CHECK: @llvm.global.annotations = appending global [11 x { ptr, ptr, ptr, i32, ptr }] [{
 // CHECK-SAME: { ptr @a.bar,
 // CHECK-SAME: { ptr @a.bar,
-// CHECK-SAME: { ptr @a,
-// CHECK-SAME: { ptr @a,
-// CHECK-SAME: { ptr @a,
-// CHECK-SAME: { ptr @a,
 // CHECK-SAME: { ptr @sfoo,
 // CHECK-SAME: { ptr @sfoo,
 // CHECK-SAME: { ptr @foo,
 // CHECK-SAME: { ptr @foo,
 // CHECK-SAME: { ptr addrspacecast (ptr addrspace(1) @addrspace1_var to ptr),
+// CHECK-SAME: { ptr @a,
+// CHECK-SAME: { ptr @a,
+// CHECK-SAME: { ptr @a,
+// CHECK-SAME: { ptr @a,
 // CHECK-SAME: }], section "llvm.metadata"
 
 // AS1-GLOBALS: target datalayout = "{{.+}}-A5-G1"
Index: clang/test/CodeGen/annotations-declaration.c
===
--- /dev/null
+++ clang/test/CodeGen/annotations-declaration.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+// Test annotation attributes are emitted for declarations.
+
+__attribute__((annotate("bar"))) int foo();
+
+int main() {
+  return foo();
+}
+
+// CHECK: target triple
+// CHECK-DAG: private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata"
+
+// CHECK: @llvm.global.annotations = appending global [1 x { ptr, ptr, ptr, i32, ptr }] [{
+// CHECK-SAME: { ptr @foo,
+// CHECK-SAME: }], section "llvm.metadata"
+
Index: clang/test/CodeGen/annotations-decl-use-define.c
===
--- /dev/null
+++ clang/test/CodeGen/annotations-decl-use-define.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+// Test annotation attributes are still emitted when the function is used before
+// it is defined with annotations.
+
+void 

[PATCH] D156259: [clang-format] Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-08-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D156259#4558570 , @jp4a50 wrote:

> @HazardyKnusperkeks could you merge this for me assuming the build is green 
> please? I don't have merge rights. Thanks.

That will have to wait, but if no one else stepped in, I'll do it in ~2 weeks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

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


[PATCH] D157028: [llvm] Extract common `OptTable` bits into macros

2023-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: MaskRay.
Herald added subscribers: jhenderson, ormris, ributzka, steven_wu, hiraditya, 
arichardson, emaste.
Herald added a reviewer: JDevlieghere.
Herald added a reviewer: jhenderson.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added projects: clang, LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits, cfe-commits.

All command-line tools using `llvm::opt` create an enum of option IDs and a 
table of `OptTable::Info` object. Most of the tools use the same ID 
(`OPT_##ID`), kind (`Option::KIND##Class`), group ID (`OPT_##GROUP`) and alias 
ID (`OPT_##ALIAS`). This patch extracts that common code into canonical macros. 
This results in fewer changes when tweaking the `OPTION` macros emitted by the 
TableGen backend.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157028

Files:
  clang/include/clang/Driver/Options.h
  clang/lib/Driver/DriverOptions.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  lld/ELF/Driver.h
  lldb/tools/driver/Driver.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
  llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
  llvm/tools/llvm-dwp/llvm-dwp.cpp
  llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
  llvm/tools/llvm-ifs/llvm-ifs.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/tools/llvm-mt/llvm-mt.cpp
  llvm/tools/llvm-nm/llvm-nm.cpp
  llvm/tools/llvm-rc/llvm-rc.cpp
  llvm/tools/llvm-readobj/llvm-readobj.cpp
  llvm/tools/llvm-size/llvm-size.cpp
  llvm/tools/llvm-strings/llvm-strings.cpp
  llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
  llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
  llvm/tools/sancov/sancov.cpp
  llvm/unittests/Option/OptionParsingTest.cpp

Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -17,9 +17,7 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -47,10 +45,7 @@
 };
 
 static constexpr OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
-   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
+#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/sancov/sancov.cpp
===
--- llvm/tools/sancov/sancov.cpp
+++ llvm/tools/sancov/sancov.cpp
@@ -63,9 +63,7 @@
 using namespace llvm::opt;
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  OPT_##ID,
+#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
@@ -78,13 +76,7 @@
 #undef PREFIX
 
 static constexpr opt::OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES)  \
-  {\
-  PREFIX,  NAME,  HELPTEXT,\
-  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
-  PARAM,   FLAGS, OPT_##GROUP, \
-  OPT_##ALIAS, ALIASARGS, VALUES},
+#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
===
--- llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -28,9 +28,7 @@
 namespace {
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR, VALUES) 

[PATCH] D156799: Update generic scheduling to use A510 scheduling model

2023-08-03 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks. Looks good. You may need to rebase over new tests, make sure everything 
is still passing when you do.

LGTM




Comment at: llvm/test/CodeGen/AArch64/misched-detail-resource-booking-01.mir:1
+# NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
 # RUN: llc -mtriple=aarch64-none-linux-gnu -mattr=+neon  %s -o - 2>&1 \

harviniriawan wrote:
> dmgreen wrote:
> > This doesn't look right. Should it be using -mcpu=cortex-a55 instead?
> shouldn't it be a510 as it's the default scheduling policy now?
Sorry I forgot to reply to the old comment. AFAIU this is testing some of the 
info in the scheduling model, not which model is being used. So pinning it to 
the A55 makes sense for keeping the old testing in place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156799

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


[PATCH] D156762: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-03 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2145
 
-static bool impossibleToFixForVar(const FixableGadgetSets ,
-  const Strategy ,
-  const VarDecl * Var) {
-  for (const auto  : FixablesForAllVars.byVar.find(Var)->second) {
-std::optional Fixits = F->getFixits(S);
-if (!Fixits) {
-  return true;
+// Erasing variables in `FixItsForVariable`, if such a variable has an 
unfixable
+// group mate.  A variable `v` is unfixable iff `FixItsForVariable` does not

// Erases variables in `FixItsForVariable`, if such a variable has an unfixable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156762

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


[PATCH] D156506: [clang][Interp] Check floating results for NaNs

2023-08-03 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:503
+  //   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.

tbaeder wrote:
> @jcranmer-intel Doesn't this comment (which I've coped from 
> `ExprConstant.cpp`) contradict what you said about not checking the result?
Immediately following that in the specification is this:
> [Note 3: Treatment of division by zero, forming a remainder using a zero 
> divisor, and all floating-point exceptions varies among machines, and is 
> sometimes adjustable by a library function. — end note]

The current C++ specification is rather clear about its unclarity on 
floating-point. Also note that IEEE 754 defines floating-point data as 
consisting of {-inf, ..., -0} union {+0, ..., +inf} union {NaN}. So NaN is 
arguable to be a well-defined mathematical result, if you consider that 
floating-point types don't model real numbers but an approximation of real 
numbers (just as unsigned integers model not integers but integers mod 2^N).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156506

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


[PATCH] D156259: [clang-format] Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-08-03 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

@HazardyKnusperkeks could you merge this for me assuming the build is green 
please? I don't have merge rights. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

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


[PATCH] D156259: [clang-format] Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-08-03 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 546972.
jp4a50 added a comment.

Format files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22177,8 +22177,25 @@
"  }\n"
"};");
 
-  // Multiple lambdas in the same parentheses change indentation rules. These
-  // lambdas are forced to start on new lines.
+  // Lambdas that fit on a single line within an argument list are not forced
+  // onto new lines.
+  verifyFormat("SomeFunction([] {});");
+  verifyFormat("SomeFunction(0, [] {});");
+  verifyFormat("SomeFunction([] {}, 0);");
+  verifyFormat("SomeFunction(0, [] {}, 0);");
+  verifyFormat("SomeFunction([] { return 0; }, 0);");
+  verifyFormat("SomeFunction(a, [] { return 0; }, b);");
+  verifyFormat("SomeFunction([] { return 0; }, [] { return 0; });");
+  verifyFormat("SomeFunction([] { return 0; }, [] { return 0; }, b);");
+  verifyFormat("auto lng =\n"
+   "SomeFunction([] { return 0; }, [] { return 0; }, b);");
+  // Exceeded column limit. We need to break.
+  verifyFormat("auto lngName = SomeFunction(\n"
+   "[] { return anotherLooonngName; }, [] { "
+   "return 0; }, b);");
+
+  // Multiple multi-line lambdas in the same parentheses change indentation
+  // rules. These lambdas are always forced to start on new lines.
   verifyFormat("SomeFunction(\n"
"[]() {\n"
"  //\n"
@@ -22187,7 +22204,7 @@
"  //\n"
"});");
 
-  // A lambda passed as arg0 is always pushed to the next line.
+  // A multi-line lambda passed as arg0 is always pushed to the next line.
   verifyFormat("SomeFunction(\n"
"[this] {\n"
"  //\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5203,30 +5203,6 @@
   return true;
   }
 
-  // Deal with lambda arguments in C++ - we want consistent line breaks whether
-  // they happen to be at arg0, arg1 or argN. The selection is a bit nuanced
-  // as aggressive line breaks are placed when the lambda is not the last arg.
-  if ((Style.Language == FormatStyle::LK_Cpp ||
-   Style.Language == FormatStyle::LK_ObjC) &&
-  Left.is(tok::l_paren) && Left.BlockParameterCount > 0 &&
-  !Right.isOneOf(tok::l_paren, TT_LambdaLSquare)) {
-// Multiple lambdas in the same function call force line breaks.
-if (Left.BlockParameterCount > 1)
-  return true;
-
-// A lambda followed by another arg forces a line break.
-if (!Left.Role)
-  return false;
-auto Comma = Left.Role->lastComma();
-if (!Comma)
-  return false;
-auto Next = Comma->getNextNonComment();
-if (!Next)
-  return false;
-if (!Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret))
-  return true;
-  }
-
   return false;
 }
 
Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -433,6 +433,9 @@
   /// literal sequence, 0 otherwise.
   unsigned StartOfStringLiteral;
 
+  /// Disallow line breaks for this line.
+  bool NoLineBreak;
+
   /// A stack keeping track of properties applying to parenthesis
   /// levels.
   SmallVector Stack;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -260,6 +260,7 @@
/*NoLineBreak=*/false));
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
+  State.NoLineBreak = false;
   State.StartOfLineLevel = 0;
   State.LowestLevelOnLine = 0;
   State.IgnoreStackForComparison = false;
@@ -342,7 +343,7 @@
 return true;
   }
 
-  return !CurrentState.NoLineBreak;
+  return !State.NoLineBreak && !CurrentState.NoLineBreak;
 }
 
 bool ContinuationIndenter::mustBreak(const LineState ) {
@@ -653,6 +654,47 @@
   const FormatToken  = *State.NextToken->Previous;
   auto  = State.Stack.back();
 
+  bool DisallowLineBreaksOnThisLine =
+  (Style.Language == FormatStyle::LK_Cpp ||
+   Style.Language == FormatStyle::LK_ObjC) &&
+  [] {
+// Deal with lambda arguments in C++. The aim here is 

[PATCH] D156877: Update Clang-REPL docs with removing the redundant subsections

2023-08-03 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54081868dd22: [clang-repl] Remove redundant subsections from 
the table of content. (authored by Krishna-13-cyber, committed by v.g.vassilev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156877

Files:
  clang/docs/ClangRepl.rst


Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -47,7 +47,6 @@
 
 8. The machine code is then executed.
 
-===
 Build Instructions:
 ===
 
@@ -75,7 +74,6 @@
clang-repl>
 
 
-
 Clang-Repl Usage
 
 


Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -47,7 +47,6 @@
 
 8. The machine code is then executed.
 
-===
 Build Instructions:
 ===
 
@@ -75,7 +74,6 @@
clang-repl>
 
 
-
 Clang-Repl Usage
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5408186 - [clang-repl] Remove redundant subsections from the table of content.

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

Author: Krishna-13-cyber
Date: 2023-08-03T19:16:18Z
New Revision: 54081868dd2220c4de77f481648ec7e10a68618b

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

LOG: [clang-repl] Remove redundant subsections from the table of content.

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

Added: 


Modified: 
clang/docs/ClangRepl.rst

Removed: 




diff  --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst
index ff986be9da89b6..bd99bc82f1 100644
--- a/clang/docs/ClangRepl.rst
+++ b/clang/docs/ClangRepl.rst
@@ -47,7 +47,6 @@ Clang-Repl data flow can be divided into roughly 8 phases:
 
 8. The machine code is then executed.
 
-===
 Build Instructions:
 ===
 
@@ -75,7 +74,6 @@ Build Instructions:
clang-repl>
 
 
-
 Clang-Repl Usage
 
 



___
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-03 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/docs/index.rst:96
ClangRepl
+   ExecutionResultsHandling
 

We should probably move that under `ClangRepl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156858

___
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-03 Thread Aiden Grossman via Phabricator via cfe-commits
aidengrossman added a comment.

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.


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] D156172: [clang][CodeGen] Emit annotations for function declarations.

2023-08-03 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl updated this revision to Diff 546966.
brendandahl added a comment.

Update deferred annotations whenever EmitGlobalDefinition is called
with a FunctionDecl and it has already been used or defined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156172

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/annotations-decl-use-decl.c
  clang/test/CodeGen/annotations-decl-use-define.c
  clang/test/CodeGen/annotations-declaration.c
  clang/test/CodeGen/annotations-global.c
  clang/test/CodeGenCXX/attr-annotate-destructor.cpp
  clang/test/CodeGenCXX/attr-annotate.cpp

Index: clang/test/CodeGenCXX/attr-annotate.cpp
===
--- clang/test/CodeGenCXX/attr-annotate.cpp
+++ clang/test/CodeGenCXX/attr-annotate.cpp
@@ -3,9 +3,9 @@
 //CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata"
 //CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1
 //CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
-//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
-//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
-//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS:.*]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS2]] }]
+//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
+//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
+//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS2:.*]] }]
 
 constexpr const char* str() {
   return "abc";
Index: clang/test/CodeGenCXX/attr-annotate-destructor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-annotate-destructor.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
+
+// Test annotation attributes on destructors doesn't crash.
+
+struct k {
+  ~k() __attribute__((annotate(""))) {}
+};
+void m() { k(); }
+
+// CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{
Index: clang/test/CodeGen/annotations-global.c
===
--- clang/test/CodeGen/annotations-global.c
+++ clang/test/CodeGen/annotations-global.c
@@ -33,15 +33,15 @@
 // CHECK: @llvm.global.annotations = appending global [11 x { ptr, ptr, ptr, i32, ptr }] [{
 // CHECK-SAME: { ptr @a.bar,
 // CHECK-SAME: { ptr @a.bar,
-// CHECK-SAME: { ptr @a,
-// CHECK-SAME: { ptr @a,
-// CHECK-SAME: { ptr @a,
-// CHECK-SAME: { ptr @a,
 // CHECK-SAME: { ptr @sfoo,
 // CHECK-SAME: { ptr @sfoo,
 // CHECK-SAME: { ptr @foo,
 // CHECK-SAME: { ptr @foo,
 // CHECK-SAME: { ptr addrspacecast (ptr addrspace(1) @addrspace1_var to ptr),
+// CHECK-SAME: { ptr @a,
+// CHECK-SAME: { ptr @a,
+// CHECK-SAME: { ptr @a,
+// CHECK-SAME: { ptr @a,
 // CHECK-SAME: }], section "llvm.metadata"
 
 // AS1-GLOBALS: target datalayout = "{{.+}}-A5-G1"
Index: clang/test/CodeGen/annotations-declaration.c
===
--- /dev/null
+++ clang/test/CodeGen/annotations-declaration.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+// Test annotation attributes are emitted for declarations.
+
+__attribute__((annotate("bar"))) int foo();
+
+int main() {
+  return foo();
+}
+
+// CHECK: target triple
+// CHECK-DAG: private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata"
+
+// CHECK: @llvm.global.annotations = appending global [1 x { ptr, ptr, ptr, i32, ptr }] [{
+// CHECK-SAME: { ptr @foo,
+// CHECK-SAME: }], section "llvm.metadata"
+
Index: clang/test/CodeGen/annotations-decl-use-define.c
===
--- /dev/null
+++ clang/test/CodeGen/annotations-decl-use-define.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+
+// Test annotation 

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

2023-08-03 Thread Changpeng Fang via Phabricator via cfe-commits
cfang added a comment.






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

Are you sure Non-HSA does not have the four directives you deleted?  



Comment at: llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp:122
 std::optional getHsaAbiVersion(const MCSubtargetInfo *STI) {
   if (STI && STI->getTargetTriple().getOS() != Triple::AMDHSA)
 return std::nullopt;

It is fine now. But I think STI could never be null. 



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

Should we keep this field, and just mention "unsupported"?



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,

Are all these "isHsaAbiVersionX" no longer needed? 


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] D150646: [clang][X86] Add __cpuidex function to cpuid.h

2023-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D150646#4450915 , @aidengrossman 
wrote:

> In D150646#4450551 , @glandium 
> wrote:
>
>> Did you find something?
>
> Not yet. I just finished finals a week ago so I haven't had as much time as I 
> would've liked to get through this. I'll contact some people tonight in 
> regards to the Windows flag situation and ask for their thoughts on this and 
> hopefully have some sort of solution at least by next Monday.

I think these changes exacerbate an issue that we had but didn't know about, 
because I'm able to reproduce the redefinition problem in both Clang 16 and 
trunk: https://godbolt.org/z/8Yq1vzEnT

What's happening is that the aux-triple is not being honored when compiling for 
an offload device (OpenMP, SYCL, etc) and so the wrong builtins are being 
enabled, leading to exposing `__cpuidex` as a builtin on non-Windows targets. 
This means the workaround to look for `_MSC_EXTENSIONS` doesn't solve the 
underlying issue -- we already try to only expose the intrinsic when MS 
extensions are enabled: 
https://github.com/llvm/llvm-project/blob/40f3708205430a7a562d58f48fd9c294fb80d5e0/clang/include/clang/Basic/BuiltinsX86.def#L2098
 and 
https://github.com/llvm/llvm-project/blob/40f3708205430a7a562d58f48fd9c294fb80d5e0/clang/lib/Basic/Builtins.cpp#L91

The changes in this patch are causing us problems with our downstream at Intel. 
I think we might want to consider reverting the change temporarily (and on the 
17.x branch) because they're exacerbating an existing problem. That gives us 
time to solve the problem of exposing the wrong set of builtins, and hopefully 
means we can remove the `_MSC_EXTENSIONS` workaround in the header file. WDYT?


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] D156901: [OpenMP] Change OpenMP default version in documentation and help text for -fopenmp-version

2023-08-03 Thread Anton Rydahl via Phabricator via cfe-commits
AntonRydahl added a comment.

The unit test that fails, `flang/test/Driver/omp-driver-offload.f90`, also 
fails on main. I don't see that it should be related to this patch.




Comment at: flang/test/Driver/driver-help.f90:55
 ! HELP-NEXT: -fopenmp-version=
-! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang and 11 for Flang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel 
code.

clementval wrote:
> jdoerfert wrote:
> > tianshilei1992 wrote:
> > > clementval wrote:
> > > > AntonRydahl wrote:
> > > > > tianshilei1992 wrote:
> > > > > > Does Flang also switch to 5.1 by default?
> > > > > As far as I know, `flang` is still OpenMP 1.1 by default but still 
> > > > > depends on the same command line options as `clang`. 
> > > > `flang` does not differentiate between versions. 
> > > I see.
> > I would remove the flang part of the wording for now.
> +1
Thanks a lot for pointing this out. Is the new hep text fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156901

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


[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

2023-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this! FWIW, precommit Ci found a relevant test failure 
that should also be addressed.




Comment at: clang/lib/Sema/SemaExpr.cpp:1062-1073
+  // C2x 6.5.2.2p6:
+  //   The integer promotions are performed on each trailing argument, and
+  //   trailing arguments that have type float are promoted to double. These 
are
+  //   called the default argument promotions. No other conversions are
+  //   performed implicitly.
+
+  // C++ [expr.call]p7, per DR722:

Oh fun, C and C++ solved this issue differently. In C++, there's an implicit 
conversion so the nullptr_t is converted to void * on the call, and in C 
there's an allowance for va_arg to handle nullptr_t as a void *.

And without further changes, C++ picks that rule up automatically once it 
rebases onto C23: http://eel.is/c++draft/support#cstdarg.syn-1



Comment at: clang/lib/Sema/SemaExpr.cpp:17328
+  PromoteType = Context.VoidPtrTy;
+if (TInfo->getType()->isArrayType())
+  PromoteType = Context.getArrayDecayedType(TInfo->getType());

MitalAshok wrote:
> This warns if you call `va_arg(ap, double[2])`. However this might be valid 
> since the actual argument only has to be a "compatible type" and I think 
> `double _Complex` is compatible with `double[2]`. I think we should warn 
> anyways, since array rvalues are tricky to work with, and the user probably 
> passed a `double[2]` and should retrieve the `double*`.
`_Complex double` and `double[2]` are not compatible types in C.

C2x 6.2.7p1: Two types are compatible types if they are the same. Additional 
rules for determining whether two types are compatible are described in 6.7.2 
for type specifiers, in 6.7.3 for type qualifiers, and in 6.7.6 for 
declarators. ... (The rest is talking about structures, enumerations, and 
unions).

`_Complex` is a type specifier, so

C2x 6.7.2p7: Each of the comma-separated multisets designates the same type, 
except that for bit-fields, it is implementation-defined whether the specifier 
int designates the same type as signed int or the same type as unsigned int.

(The multisets it describes do not include any array types.)



Comment at: clang/test/Sema/format-strings-pedantic.c:21
+#elif !__is_identifier(nullptr)
+  printf("%p", nullptr); // expected-warning {{format specifies type 'void *' 
but the argument has type 'nullptr_t'}}
 #endif

MitalAshok wrote:
> In C2x, nullptr passed as an argument and retrieved via `va_arg(ap, void *)` 
> is valid (See C2x 7.16.1.1p2) and this is the same as `printf("%p", (void*) 
> nullptr)`, but this should still be fine as a "pedantic" warning
I don't think this should be diagnosed pedantically; the code is correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

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


[PATCH] D156901: [OpenMP] Change OpenMP default version in documentation and help text for -fopenmp-version

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

Removing information about Flang default version of OpenMP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156901

Files:
  clang/docs/OpenMPSupport.rst
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  openmp/docs/CommandLineArgumentReference.rst


Index: openmp/docs/CommandLineArgumentReference.rst
===
--- openmp/docs/CommandLineArgumentReference.rst
+++ openmp/docs/CommandLineArgumentReference.rst
@@ -37,8 +37,7 @@
 ^^
 Set the OpenMP version to a specific version  of the OpenMP standard. 
 For example, you may use ``-fopenmp-version=45`` to select version 4.5 of 
-the OpenMP standard. The default value is ``-fopenmp-version=50`` for 
``Clang`` 
-and ``-fopenmp-version=11`` for ``flang-new``.
+the OpenMP standard. The default value is ``-fopenmp-version=51`` for 
``Clang``.
 
 .. _offload_command_line_arguments:
 
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -52,7 +52,7 @@
 ! HELP-NEXT:Do not create unit-strided loops (default)
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp-version=
-! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel 
code.
 ! HELP-NEXT: -foptimization-record-file=
 ! HELP-NEXT:Specify the output name of the file 
containing the optimization remarks. Implies -fsave-optimization-record. On 
Darwin platforms, this cannot be used with multiple -arch  options.
@@ -170,7 +170,7 @@
 ! HELP-FC1-NEXT:Generate code only for an OpenMP 
target device.
 ! HELP-FC1-NEXT: -fopenmp-target-debug  Enable debugging in the OpenMP 
offloading device RTL
 ! HELP-FC1-NEXT: -fopenmp-version=
-! HELP-FC1-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! HELP-FC1-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate 
parallel code.
 ! HELP-FC1-NEXT: -fpass-plugin= Load pass plugin from a dynamic 
shared object file (only with new pass manager).
 ! HELP-FC1-NEXT: -freciprocal-math  Allow division operations to be 
reassociated
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -56,7 +56,7 @@
 ! CHECK-NEXT:Do not create unit-strided loops (default)
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp-version=
-! CHECK-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
+! CHECK-NEXT:Set OpenMP version (e.g. 45 for OpenMP 
4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate 
parallel code.
 ! CHECK-NEXT: -foptimization-record-file=
 ! CHECK-NEXT:Specify the output name of the file 
containing the optimization remarks. Implies -fsave-optimization-record. On 
Darwin platforms, this cannot be used with multiple -arch  options.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2782,7 +2782,7 @@
   HelpText<"Parse OpenMP pragmas and generate parallel code.">;
 def fno_openmp : Flag<["-"], "fno-openmp">, Group, 
Flags<[NoArgumentUnused]>;
 def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group, 
Flags<[CC1Option, NoArgumentUnused, FlangOption, FC1Option]>,
-  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). 
Default value is 50 for Clang and 11 for Flang">;
+  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). 
Default value is 51 for Clang">;
 defm openmp_extensions: BoolFOption<"openmp-extensions",
   LangOpts<"OpenMPExtensions">, DefaultTrue,
   PosFlagIndex: openmp/docs/CommandLineArgumentReference.rst
===
--- 

[PATCH] D156989: FloatingPointMode: Use -1 for "Dynamic"

2023-08-03 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D156989#4558134 , @arsenm wrote:

> In D156989#4558133 , @sepavloff 
> wrote:
>
>> Rounding mode is presented in FPOptions with 3 bits, so there is only 8 
>> values available for particular modes. 5 of them, which are specified in 
>> IEEE-754, are listed in `RoundingMode`. `Dynamic` (which is -1 in 3-bit 
>> numbers) is not a real rounding mode,
>
> But it is a spec'd value as -1 for FLT_ROUNDS

It is no more than failure indicator for this function or macro. `fegetround` 
may use any negative value for this purpose. -1 does not represent any rounding 
mode, just like EOF does not represent any character in a stream.

>> Probably `Dynamic` is what you need. It prevents from constant folding and 
>> other transformations that rely on particular rounding mode and does not 
>> restrict actual rounding modes used in runtime. What  prevents from using 
>> this mode for your case?
>
> I can do better by reporting something meaningful, two different modes is not 
> unknown. The enum here should just be exactly equal to the FLT_ROUNDS values 
> and not pick a random other number, I just need the wrong value for Dynamic 
> to get out of the way to avoid creating additional wrappers

Support of rounding mode in C standard is based on IEEE-754 model, where 
rounding mode is a global state and affects all FP operations. The case of two 
rounding modes does not fit this model. So in C/C++ you anyway need to invent 
special tools for setting this or that rounding mode or reading them. If static 
rounding mode is not needed, IEEE-754 rounding mode could be represented by 
`Dynamic` value.

In IR there are more possibilities to represent many rounding modes. Each 
constrained intrinsic call contains rounding mode and that mode may be 
different for different FP types. Actually this model can support the general 
case. For example, rounding mode for one type can be static but for the other 
type it can be dynamic. There must be intrinsic functions that set/get rounding 
mode for different types.

It looks like adding special bultin functions to get/set rounding mode for 
different types is enough to support rounding in AMDGPU. In any case IEEE-754 
rounding mode should be honored, which means that `fegetround` and `FLT_ROUNDS` 
probably should return negative value, and `fesetround` probably should set all 
rounding modes. The difference between `Dynamic` and -1 does not matter because 
`Dynamic` can never be an argument of rounding mode type and `Invalid` (-1) is 
an error indicator and must not be treated as rounding mode.


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

https://reviews.llvm.org/D156989

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


[PATCH] D154646: Fix some typos in comments: evalute -> evaluate (NFC)

2023-08-03 Thread Tianlan Zhou via Phabricator via cfe-commits
SuperSodaSea updated this revision to Diff 546962.
SuperSodaSea added a comment.

Update patch.


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

https://reviews.llvm.org/D154646

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/Serialization/ASTWriter.cpp
  flang/include/flang/Lower/Support/Utils.h
  flang/lib/Evaluate/shape.cpp
  mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
  openmp/libomptarget/test/lit.cfg

Index: openmp/libomptarget/test/lit.cfg
===
--- openmp/libomptarget/test/lit.cfg
+++ openmp/libomptarget/test/lit.cfg
@@ -49,7 +49,7 @@
 else:
 config.environment[name] = value
 
-# Evalute the environment variable which is a string boolean value.
+# Evaluate the environment variable which is a string boolean value.
 def evaluate_bool_env(env):
 env = env.lower()
 possible_true_values = ["on", "true", "1"]
Index: mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
===
--- mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
+++ mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
@@ -324,7 +324,7 @@
 // MLIR currently does not support dependent interfaces or interface
 // inheritance. By construction all ops with StructuredOpInterface must
 // implement DestinationStyleOpInterface.
-// TODO: reevalute the need for a cast when a better mechanism exists.
+// TODO: reevaluate the need for a cast when a better mechanism exists.
 return getBlock()->getArguments().take_front(
 cast(*this->getOperation())
 .getNumDpsInputs());
@@ -342,7 +342,7 @@
 // MLIR currently does not support dependent interfaces or interface
 // inheritance. By construction all ops with StructuredOpInterface must
 // implement DestinationStyleOpInterface.
-// TODO: reevalute the need for a cast when a better mechanism exists.
+// TODO: reevaluate the need for a cast when a better mechanism exists.
 return getBlock()->getArguments().take_back(
 cast(*this->getOperation())
 .getNumDpsInits());
@@ -421,7 +421,7 @@
 // MLIR currently does not support dependent interfaces or interface
 // inheritance. By construction all ops with StructuredOpInterface must
 // implement DestinationStyleOpInterface.
-// TODO: reevalute the need for a cast when a better mechanism exists.
+// TODO: reevaluate the need for a cast when a better mechanism exists.
 return *(indexingMaps.begin() +
  cast(*this->getOperation())
  .getNumDpsInputs() +
@@ -442,7 +442,7 @@
 // MLIR currently does not support dependent interfaces or interface
 // inheritance. By construction all ops with StructuredOpInterface must
 // implement DestinationStyleOpInterface.
-// TODO: reevalute the need for a cast when a better mechanism exists.
+// TODO: reevaluate the need for a cast when a better mechanism exists.
 int64_t resultIndex =
 opOperand->getOperandNumber() -
 cast(*this->getOperation())
@@ -807,7 +807,7 @@
 // MLIR currently does not support dependent interfaces or interface
 // inheritance. By construction all ops with StructuredOpInterface must
 // implement DestinationStyleOpInterface.
-// TODO: reevalute the need for a cast when a better mechanism exists.
+// TODO: reevaluate the need for a cast when a better mechanism exists.
 ////
 
 int64_t getNumDpsInputs() {
Index: flang/lib/Evaluate/shape.cpp
===
--- flang/lib/Evaluate/shape.cpp
+++ flang/lib/Evaluate/shape.cpp
@@ -1066,7 +1066,7 @@
   result = std::move(result) + std::move(n);
   if (context_) {
 // Fold during expression creation to avoid creating an expression so
-// large we can't evalute it without overflowing the stack.
+// large we can't evaluate it without overflowing the stack.
 result = Fold(*context_, std::move(result));
   }
 }
Index: flang/include/flang/Lower/Support/Utils.h
===
--- flang/include/flang/Lower/Support/Utils.h
+++ flang/include/flang/Lower/Support/Utils.h
@@ -89,7 +89,7 @@
 // Fortran::evaluate::Expr are functional values organized like an AST. A
 // Fortran::evaluate::Expr is meant to be moved and cloned. Using the front end
 // tools can often cause copies and extra wrapper classes to be added to any
-// Fortran::evalute::Expr. These values should not be assumed or relied upon to
+// Fortran::evaluate::Expr. These values should not be assumed or relied upon to
 // have an *object* identity. They are deeply recursive, irregular structures
 // built from a 

[clang] 32056aa - [docs] Fix doxygen markers for grouping methods. NFC.

2023-08-03 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-08-03T11:16:42-07:00
New Revision: 32056aa3443786822963e6e469d98deb7b857d79

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

LOG: [docs] Fix doxygen markers for grouping methods. NFC.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index c6af1fd5dd010f..377055e8f6f924 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -189,7 +189,7 @@ class CompilerInstance : public ModuleLoader {
   ~CompilerInstance() override;
 
   /// @name High-Level Operations
-  /// {
+  /// @{
 
   /// ExecuteAction - Execute the provided action against the compiler's
   /// CompilerInvocation object.
@@ -223,9 +223,9 @@ class CompilerInstance : public ModuleLoader {
   /// Load the list of plugins requested in the \c FrontendOptions.
   void LoadRequestedPlugins();
 
-  /// }
+  /// @}
   /// @name Compiler Invocation and Options
-  /// {
+  /// @{
 
   bool hasInvocation() const { return Invocation != nullptr; }
 
@@ -248,9 +248,9 @@ class CompilerInstance : public ModuleLoader {
 BuildGlobalModuleIndex = Build;
   }
 
-  /// }
+  /// @}
   /// @name Forwarding Methods
-  /// {
+  /// @{
 
   AnalyzerOptionsRef getAnalyzerOpts() {
 return Invocation->getAnalyzerOpts();
@@ -329,9 +329,9 @@ class CompilerInstance : public ModuleLoader {
 return Invocation->getTargetOpts();
   }
 
-  /// }
+  /// @}
   /// @name Diagnostics Engine
-  /// {
+  /// @{
 
   bool hasDiagnostics() const { return Diagnostics != nullptr; }
 
@@ -355,9 +355,9 @@ class CompilerInstance : public ModuleLoader {
 return *Diagnostics->getClient();
   }
 
-  /// }
+  /// @}
   /// @name VerboseOutputStream
-  /// }
+  /// @{
 
   /// Replace the current stream for verbose output.
   void setVerboseOutputStream(raw_ostream );
@@ -370,9 +370,9 @@ class CompilerInstance : public ModuleLoader {
 return *VerboseOutputStream;
   }
 
-  /// }
+  /// @}
   /// @name Target Info
-  /// {
+  /// @{
 
   bool hasTarget() const { return Target != nullptr; }
 
@@ -389,9 +389,9 @@ class CompilerInstance : public ModuleLoader {
   /// Replace the current Target.
   void setTarget(TargetInfo *Value);
 
-  /// }
+  /// @}
   /// @name AuxTarget Info
-  /// {
+  /// @{
 
   TargetInfo *getAuxTarget() const { return AuxTarget.get(); }
 
@@ -401,15 +401,15 @@ class CompilerInstance : public ModuleLoader {
   // Create Target and AuxTarget based on current options
   bool createTarget();
 
-  /// }
+  /// @}
   /// @name Virtual File System
-  /// {
+  /// @{
 
   llvm::vfs::FileSystem () const;
 
-  /// }
+  /// @}
   /// @name File Manager
-  /// {
+  /// @{
 
   bool hasFileManager() const { return FileMgr != nullptr; }
 
@@ -432,9 +432,9 @@ class CompilerInstance : public ModuleLoader {
   /// Replace the current file manager and virtual file system.
   void setFileManager(FileManager *Value);
 
-  /// }
+  /// @}
   /// @name Source Manager
-  /// {
+  /// @{
 
   bool hasSourceManager() const { return SourceMgr != nullptr; }
 
@@ -457,9 +457,9 @@ class CompilerInstance : public ModuleLoader {
   /// setSourceManager - Replace the current source manager.
   void setSourceManager(SourceManager *Value);
 
-  /// }
+  /// @}
   /// @name Preprocessor
-  /// {
+  /// @{
 
   bool hasPreprocessor() const { return PP != nullptr; }
 
@@ -478,9 +478,9 @@ class CompilerInstance : public ModuleLoader {
   /// Replace the current preprocessor.
   void setPreprocessor(std::shared_ptr Value);
 
-  /// }
+  /// @}
   /// @name ASTContext
-  /// {
+  /// @{
 
   bool hasASTContext() const { return Context != nullptr; }
 
@@ -506,9 +506,9 @@ class CompilerInstance : public ModuleLoader {
   /// of S.
   void setSema(Sema *S);
 
-  /// }
+  /// @}
   /// @name ASTConsumer
-  /// {
+  /// @{
 
   bool hasASTConsumer() const { return (bool)Consumer; }
 
@@ -525,9 +525,9 @@ class CompilerInstance : public ModuleLoader {
   /// takes ownership of \p Value.
   void setASTConsumer(std::unique_ptr Value);
 
-  /// }
+  /// @}
   /// @name Semantic analysis
-  /// {
+  /// @{
   bool hasSema() const { return (bool)TheSema; }
 
   Sema () const {
@@ -538,9 +538,9 @@ class CompilerInstance : public ModuleLoader {
   std::unique_ptr takeSema();
   void resetAndLeakSema();
 
-  /// }
+  /// @}
   /// @name Module Management
-  /// {
+  /// @{
 
   IntrusiveRefCntPtr getASTReader() const;
   void setASTReader(IntrusiveRefCntPtr Reader);
@@ -581,9 +581,9 @@ class CompilerInstance : public ModuleLoader {
 return *Reader;
   }
 
-  /// }
+  /// @}
   /// @name Code Completion
-  /// {
+  /// @{
 
   bool 

[PATCH] D156337: [clang] Allow setting the uninitialized attribute on record

2023-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Was there an RFC for this extension to the attribute? (There doesn't need to be 
one, I'm just wondering if there's more background info on what's driving this 
patch forward and discussion around the design.)

I'd like some more details about how this attribute impacts class hierarchies. 
e.g., if you put the attribute on the base class, does it impact the derived 
class members as well, or just the base class members? Also, what should happen 
in a case like this:

  template 
  void func() {
Ty Val; // Does this know it's uninitialized? Or did we lose that 
information because this isn't a type attribute?
  }
  
  struct __attribute__((uninitialized)) S { int  value; };
  
  int main() {
func();
  }




Comment at: clang/include/clang/Basic/AttrDocs.td:5789
+command-line parameter, forcing variables to remain uninitialized.
+When set on a struct or class, all stack variables of this type are affected.
+





Comment at: clang/lib/CodeGen/CGDecl.cpp:1908
 
-  // Note: constexpr already initializes everything correctly.
-  LangOptions::TrivialAutoVarInitKind trivialAutoVarInit =
-  (D.isConstexpr()
-   ? LangOptions::TrivialAutoVarInitKind::Uninitialized
-   : (D.getAttr()
-  ? LangOptions::TrivialAutoVarInitKind::Uninitialized
-  : getContext().getLangOpts().getTrivialAutoVarInit()));
+  LangOptions::TrivialAutoVarInitKind trivialAutoVarInit;
+  if (D.isConstexpr()) {




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

https://reviews.llvm.org/D156337

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


[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth 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 rG43dfe0f08eca: [Driver] Allow for sparcv8plus subdir with 
Solaris/SPARC GCC (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157013

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/solaris-sparc-gcc-search.test

Index: clang/test/Driver/solaris-sparc-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-sparc-gcc-search.test
@@ -0,0 +1,56 @@
+/// Check that clang can handle both old-style (32) and new-style (sparcv8plus)
+/// 32-bit sparc multilib subdirs.
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC48 %s
+// CHECK-SPARC32-GCC48: Selected GCC installation: {{.*}}4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC32-GCC48-NEXT: Selected multilib: .;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC10 %s
+// CHECK-SPARC32-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC32-GCC10-NEXT: Selected multilib: 32;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC11 %s
+// CHECK-SPARC32-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC32-GCC11-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC48 %s
+// CHECK-SPARC64-GCC48: Selected GCC installation: {{.*}}gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC64-GCC48-NEXT: Selected multilib: sparcv9;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC10 %s
+// CHECK-SPARC64-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC64-GCC10-NEXT: Selected multilib: .;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC11 %s
+// CHECK-SPARC64-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC64-GCC11-NEXT: Selected multilib: .;@m64
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -20,6 +20,7 @@
 ".hipi",
 ".hlsl",
 ".yaml",
+".test",
 ]
 config.substitutions = list(config.substitutions)
 config.substitutions.insert(
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ 

[clang] 43dfe0f - [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-08-03T20:01:13+02:00
New Revision: 43dfe0f08ecaf50f986512d0548bd3ac84d1813b

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

LOG: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

Since GCC 11, the bundled Solaris/SPARC GCC uses the `sparcv8plus`
subdirectory for 32-bit objects, just like upstream GCC.  Before that, it
used `32` instead from a local patch.

Since `clang` doesn't know about that `sparcv8plus` subdirectory, it
wouldn't properly use GCC 11+ installations.

The new `solaris-sparc-gcc-search.test` testcase wasn't run initially (like
the existing `crash-report-null.test`) because the `.test` suffix wasn't
handled.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.

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

Added: 

clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o

clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o

clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o

clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
clang/test/Driver/solaris-sparc-gcc-search.test

Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/lit.local.cfg

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7aa6984ab8f353..485fd67ca53d3e 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1874,6 +1874,12 @@ static bool findBiarchMultilibs(const Driver ,
 .flag("-m64", /*Disallow=*/true)
 .flag("-mx32")
 .makeMultilib();
+  Multilib Alt32sparc = MultilibBuilder()
+.gccSuffix("/sparcv8plus")
+.includeSuffix("/sparcv8plus")
+.flag("-m32")
+.flag("-m64", /*Disallow=*/true)
+.makeMultilib();
 
   // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a.
   FilterNonExistent NonExistent(
@@ -1885,10 +1891,14 @@ static bool findBiarchMultilibs(const Driver ,
   const bool IsX32 = TargetTriple.isX32();
   if (TargetTriple.isArch32Bit() && !NonExistent(Alt32))
 Want = WANT64;
+  if (TargetTriple.isArch32Bit() && !NonExistent(Alt32sparc))
+Want = WANT64;
   else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32))
 Want = WANT64;
   else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64))
 Want = WANT32;
+  else if (TargetTriple.isArch64Bit() && !NonExistent(Alt32sparc))
+Want = WANT64;
   else {
 if (TargetTriple.isArch32Bit())
   Want = NeedsBiarchSuffix ? WANT64 : WANT32;
@@ -1919,6 +1929,7 @@ static bool findBiarchMultilibs(const Driver ,
   Result.Multilibs.push_back(Alt64);
   Result.Multilibs.push_back(Alt32);
   Result.Multilibs.push_back(Altx32);
+  Result.Multilibs.push_back(Alt32sparc);
 
   Result.Multilibs.FilterOut(NonExistent);
 
@@ -1932,7 +1943,8 @@ static bool findBiarchMultilibs(const Driver ,
 
   if (Result.SelectedMultilibs.back() == Alt64 ||
   Result.SelectedMultilibs.back() == Alt32 ||
-  Result.SelectedMultilibs.back() == Altx32)
+  Result.SelectedMultilibs.back() == Altx32 ||
+  Result.SelectedMultilibs.back() == Alt32sparc)
 Result.BiarchSibling = Default;
 
   return true;

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
 
b/clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
new file mode 100644

[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

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



Comment at: clang/test/Driver/lit.local.cfg:23
 ".yaml",
+".test",
 ]

ro wrote:
> MaskRay wrote:
> > Instead of adding a new extension, you can just name your test `.c`?
> I could, but went for  `.test` instead because the `clang` invocations don't 
> need input.
> 
> Besides, there's still the issue of the existing `crash-report-null.test` 
> that's currently ignored.
OK, sounds good since many other directories accept `.test`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157013

___
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-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Boolean.h:113
+  static Boolean bitcastFromMemory(const std::byte *Buff) {
+bool Val = static_cast(*Buff);
+return Boolean(Val);

tbaeder wrote:
> MitalAshok wrote:
> > Does this handle padding bits correctly? E.g., `__builtin_bit_cast(bool, 
> > (unsigned char) 0b10u)` should be false
> No, it doesn't. But clang has a completely different opinion about that test.
I think Clang diagnoses that as an invalid constant expression because of 
https://eel.is/c++draft/utilities#bit.cast-2.sentence-5 which we're allowed to 
do because of http://eel.is/c++draft/expr.const#5.31



Comment at: clang/lib/AST/Interp/Interp.h:1546
+  const Pointer  = S.Stk.pop();
+  Pointer  = S.Stk.peek();
+

Should we be checking that we don't have a member pointer at this point?



Comment at: clang/lib/AST/Interp/InterpBitcast.cpp:19
+
+// TODO: Try to e-duplicate the primitive and composite versions.
+

Alternatively: `e-duplicate2000`



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

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?



Comment at: clang/lib/AST/Interp/InterpBitcast.cpp:72
+struct ByteTracker {
+  std::vector Initialized;
+  std::vector Data;

`llvm::BitVector` instead of `std::vector`?


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] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/test/Driver/lit.local.cfg:23
 ".yaml",
+".test",
 ]

MaskRay wrote:
> Instead of adding a new extension, you can just name your test `.c`?
I could, but went for  `.test` instead because the `clang` invocations don't 
need input.

Besides, there's still the issue of the existing `crash-report-null.test` 
that's currently ignored.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157013

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


[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/lit.local.cfg:23
 ".yaml",
+".test",
 ]

Instead of adding a new extension, you can just name your test `.c`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157013

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


[PATCH] D156506: [clang][Interp] Check floating results for NaNs

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



Comment at: clang/lib/AST/Interp/Interp.cpp:503
+  //   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.

@jcranmer-intel Doesn't this comment (which I've coped from `ExprConstant.cpp`) 
contradict what you said about not checking the result?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156506

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


[PATCH] D156704: [clang][HeaderSearch] Treat framework headers as System for suggestPath

2023-08-03 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 546927.
dgoldman added a comment.

Rename IsSystem to IsAngled


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156704

Files:
  clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -47,14 +47,18 @@
 Search.AddSearchPath(DL, /*isAngled=*/false);
   }
 
-  void addSystemFrameworkSearchDir(llvm::StringRef Dir) {
+  void addFrameworkSearchDir(llvm::StringRef Dir, bool IsSystem = true) {
 VFS->addFile(
 Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/std::nullopt,
 /*Group=*/std::nullopt, llvm::sys::fs::file_type::directory_file);
 auto DE = FileMgr.getOptionalDirectoryRef(Dir);
 assert(DE);
-auto DL = DirectoryLookup(*DE, SrcMgr::C_System, /*isFramework=*/true);
-Search.AddSystemSearchPath(DL);
+auto DL = DirectoryLookup(*DE,
+IsSystem ? SrcMgr::C_System : SrcMgr::C_User, /*isFramework=*/true);
+if (IsSystem)
+  Search.AddSystemSearchPath(DL);
+else
+  Search.AddSearchPath(DL, /*isAngled=*/true);
   }
 
   void addHeaderMap(llvm::StringRef Filename,
@@ -175,20 +179,32 @@
 }
 
 TEST_F(HeaderSearchTest, SdkFramework) {
-  addSystemFrameworkSearchDir(
+  addFrameworkSearchDir(
   "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/Frameworks/");
-  bool IsSystem = false;
+  bool IsAngled = false;
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics(
 "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"
 "Frameworks/AppKit.framework/Headers/NSView.h",
 /*WorkingDir=*/"",
-/*MainFile=*/"", ),
+/*MainFile=*/"", ),
 "AppKit/NSView.h");
-  EXPECT_TRUE(IsSystem);
+  EXPECT_TRUE(IsAngled);
+
+  addFrameworkSearchDir(
+  "/System/Developer/Library/Framworks/", /*IsSystem*/false);
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics(
+"/System/Developer/Library/Framworks/"
+"Foo.framework/Headers/Foo.h",
+/*WorkingDir=*/"",
+/*MainFile=*/"", ),
+"Foo/Foo.h");
+  // Expect to be true even though we passed false to IsSystem earlier since
+  // all frameworks should be treated as <>.
+  EXPECT_TRUE(IsAngled);
 }
 
 TEST_F(HeaderSearchTest, NestedFramework) {
-  addSystemFrameworkSearchDir("/Platforms/MacOSX/Frameworks");
+  addFrameworkSearchDir("/Platforms/MacOSX/Frameworks");
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics(
 "/Platforms/MacOSX/Frameworks/AppKit.framework/Frameworks/"
 "Sub.framework/Headers/Sub.h",
@@ -199,7 +215,7 @@
 
 TEST_F(HeaderSearchTest, HeaderFrameworkLookup) {
   std::string HeaderPath = "/tmp/Frameworks/Foo.framework/Headers/Foo.h";
-  addSystemFrameworkSearchDir("/tmp/Frameworks");
+  addFrameworkSearchDir("/tmp/Frameworks");
   VFS->addFile(HeaderPath, 0,
llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath),
/*User=*/std::nullopt, /*Group=*/std::nullopt,
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -5682,10 +5682,10 @@
 /// suggesting the addition of a #include of the specified file.
 static std::string getHeaderNameForHeader(Preprocessor , const FileEntry *E,
   llvm::StringRef IncludingFile) {
-  bool IsSystem = false;
+  bool IsAngled = false;
   auto Path = PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(
-  E, IncludingFile, );
-  return (IsSystem ? '<' : '"') + Path + (IsSystem ? '>' : '"');
+  E, IncludingFile, );
+  return (IsAngled ? '<' : '"') + Path + (IsAngled ? '>' : '"');
 }
 
 void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1928,17 +1928,17 @@
 }
 
 std::string HeaderSearch::suggestPathToFileForDiagnostics(
-const FileEntry *File, llvm::StringRef MainFile, bool *IsSystem) const {
+const FileEntry *File, llvm::StringRef MainFile, bool *IsAngled) const {
   // FIXME: We assume that the path name currently cached in the 

[PATCH] D156911: [clang][CodeGen] Drop some typed pointer bitcasts

2023-08-03 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope updated this revision to Diff 546921.
bjope added a comment.

Rebased+updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156911

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp

Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -647,9 +647,7 @@
   // Apply the adjustment and cast back to the original struct type
   // for consistency.
   llvm::Value *This = ThisAddr.getPointer();
-  llvm::Value *Ptr = Builder.CreateBitCast(This, Builder.getInt8PtrTy());
-  Ptr = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), Ptr, Adj);
-  This = Builder.CreateBitCast(Ptr, This->getType(), "this.adjusted");
+  This = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), This, Adj);
   ThisPtrForCall = This;
 
   // Load the function pointer.
@@ -740,9 +738,8 @@
   ? llvm::Intrinsic::type_test
   : llvm::Intrinsic::public_type_test;
 
-CheckResult = Builder.CreateCall(
-CGM.getIntrinsic(IID),
-{Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId});
+CheckResult =
+Builder.CreateCall(CGM.getIntrinsic(IID), {VFPAddr, TypeId});
   }
 
   if (CGM.getItaniumVTableContext().isRelativeLayout()) {
@@ -812,8 +809,6 @@
   };
 
   llvm::Value *Bit = Builder.getFalse();
-  llvm::Value *CastedNonVirtualFn =
-  Builder.CreateBitCast(NonVirtualFn, CGF.Int8PtrTy);
   for (const CXXRecordDecl *Base : CGM.getMostBaseClasses(RD)) {
 llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(
 getContext().getMemberPointerType(
@@ -824,13 +819,13 @@
 
 llvm::Value *TypeTest =
 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::type_test),
-   {CastedNonVirtualFn, TypeId});
+   {NonVirtualFn, TypeId});
 Bit = Builder.CreateOr(Bit, TypeTest);
   }
 
   CGF.EmitCheck(std::make_pair(Bit, SanitizerKind::CFIMFCall),
 SanitizerHandler::CFICheckFail, StaticData,
-{CastedNonVirtualFn, llvm::UndefValue::get(CGF.IntPtrTy)});
+{NonVirtualFn, llvm::UndefValue::get(CGF.IntPtrTy)});
 
   FnNonVirtual = Builder.GetInsertBlock();
 }
@@ -1253,8 +1248,7 @@
 CGF.getPointerAlign());
 
 // Apply the offset.
-llvm::Value *CompletePtr =
-  CGF.Builder.CreateBitCast(Ptr.getPointer(), CGF.Int8PtrTy);
+llvm::Value *CompletePtr = Ptr.getPointer();
 CompletePtr =
 CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, CompletePtr, Offset);
 
@@ -1454,7 +1448,6 @@
 
   if (CGM.getItaniumVTableContext().isRelativeLayout()) {
 // Load the type info.
-Value = CGF.Builder.CreateBitCast(Value, CGM.Int8PtrTy);
 Value = CGF.Builder.CreateCall(
 CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
 {Value, llvm::ConstantInt::get(CGM.Int32Ty, -4)});
@@ -2211,8 +2204,7 @@
NonVirtualAdjustment);
   }
 
-  // Cast back to the original type.
-  return CGF.Builder.CreateBitCast(ResultPtr, InitialPtr.getType());
+  return ResultPtr;
 }
 
 llvm::Value *ItaniumCXXABI::performThisAdjustment(CodeGenFunction ,
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2049,8 +2049,7 @@
NullConstant, Twine());
 CharUnits NullAlign = DestPtr.getAlignment();
 NullVariable->setAlignment(NullAlign.getAsAlign());
-Address SrcPtr(Builder.CreateBitCast(NullVariable, Builder.getInt8PtrTy()),
-   Builder.getInt8Ty(), NullAlign);
+Address SrcPtr(NullVariable, Builder.getInt8Ty(), NullAlign);
 
 if (vla) return emitNonZeroVLAInit(*this, Ty, DestPtr, SrcPtr, SizeVal);
 
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -3690,8 +3690,8 @@
 
 index = CGF.Builder.CreateMul(index, objectSize);
 
-Value *result = CGF.Builder.CreateBitCast(pointer, CGF.VoidPtrTy);
-result = CGF.Builder.CreateGEP(CGF.Int8Ty, result, index, "add.ptr");
+Value *result =
+CGF.Builder.CreateGEP(CGF.Int8Ty, pointer, index, "add.ptr");
 return CGF.Builder.CreateBitCast(result, pointer->getType());
   }
 
Index: 

[PATCH] D157013: [Driver] Allow for sparcv8plus subdir with Solaris/SPARC GCC

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

Since GCC 11, the bundled Solaris/SPARC GCC uses the `sparcv8plus` subdirectory 
for 32-bit objects, just like upstream GCC.  Before that, it used `32` instead 
from a local patch.

Since `clang` doesn't know about that `sparcv8plus` subdirectory, it wouldn't 
properly use GCC 11+ installations.

The new `solaris-sparc-gcc-search.test` testcase wasn't run initially (like the 
existing `crash-report-null.test`) because the `.test` suffix wasn't handled.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and 
`x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157013

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparc32_tree/usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_sparcv8+_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0/sparcv8plus/crtbegin.o
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/solaris-sparc-gcc-search.test

Index: clang/test/Driver/solaris-sparc-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-sparc-gcc-search.test
@@ -0,0 +1,56 @@
+/// Check that clang can handle both old-style (32) and new-style (sparcv8plus)
+/// 32-bit sparc multilib subdirs.
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC48 %s
+// CHECK-SPARC32-GCC48: Selected GCC installation: {{.*}}4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC32-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC32-GCC48-NEXT: Selected multilib: .;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC10 %s
+// CHECK-SPARC32-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC32-GCC10-NEXT: Selected multilib: 32;@m32
+
+/// Check sparc-sun-solaris2.11, 32-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC32-GCC11 %s
+// CHECK-SPARC32-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC32-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC32-GCC11-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 4.8 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc_tree/usr/gcc/4.8 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC48 %s
+// CHECK-SPARC64-GCC48: Selected GCC installation: {{.*}}gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: .;@m32
+// CHECK-SPARC64-GCC48-NEXT: Candidate multilib: sparcv9;@m64
+// CHECK-SPARC64-GCC48-NEXT: Selected multilib: sparcv9;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 10 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparc32_tree/usr/gcc/10 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC10 %s
+// CHECK-SPARC64-GCC10: Selected GCC installation: {{.*}}10/lib/gcc/sparcv9-sun-solaris2.11/10.4.0
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC10-NEXT: Candidate multilib: 32;@m32
+// CHECK-SPARC64-GCC10-NEXT: Selected multilib: .;@m64
+
+/// Check sparcv9-sun-solaris2.11, 64-bit, GCC 11 tree
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain=%S/Inputs/solaris_sparcv8+_tree/usr/gcc/11 \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC64-GCC11 %s
+// CHECK-SPARC64-GCC11: Selected GCC installation: {{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.3.0
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC64-GCC11-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC64-GCC11-NEXT: Selected multilib: .;@m64
Index: clang/test/Driver/lit.local.cfg

[PATCH] D156989: FloatingPointMode: Use -1 for "Dynamic"

2023-08-03 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D156989#4558133 , @sepavloff wrote:

> Rounding mode is presented in FPOptions with 3 bits, so there is only 8 
> values available for particular modes. 5 of them, which are specified in 
> IEEE-754, are listed in `RoundingMode`. `Dynamic` (which is -1 in 3-bit 
> numbers) is not a real rounding mode,

But it is a spec'd value as -1 for FLT_ROUNDS

> `RoundingMode::Invalid` is not a mode at all, it is used to represent 
> unspecified value at compile-time and can be eliminated by using things like 
> `std::optional`. In 3 bits it would have the same value as `Dynamic`, but it 
> is not a problem, because `Invalid` never appears in AST and IR.

Right it's just filler here

> Probably `Dynamic` is what you need. It prevents from constant folding and 
> other transformations that rely on particular rounding mode and does not 
> restrict actual rounding modes used in runtime. What  prevents from using 
> this mode for your case?

I can do better by reporting something meaningful, two different modes is not 
unknown. The enum here should just be exactly equal to the FLT_ROUNDS values 
and not pick a random other number, I just need the wrong value for Dynamic to 
get out of the way to avoid creating additional wrappers


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

https://reviews.llvm.org/D156989

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


[PATCH] D156989: FloatingPointMode: Use -1 for "Dynamic"

2023-08-03 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Rounding mode is presented in FPOptions with 3 bits, so there is only 8 values 
available for particular modes. 5 of them, which are specified in IEEE-754, are 
listed in `RoundingMode`. `Dynamic` (which is -1 in 3-bit numbers) is not a 
real rounding mode, it represents rounding mode unknown at compiler time. 
`RoundingMode::Invalid` is not a mode at all, it is used to represent 
unspecified value at compile-time and can be eliminated by using things like 
`std::optional`. In 3 bits it would have the same value as `Dynamic`, but it is 
not a problem, because `Invalid` never appears in AST and IR.

Probably `Dynamic` is what you need. It prevents from constant folding and 
other transformations that rely on particular rounding mode and does not 
restrict actual rounding modes used in runtime. What  prevents from using this 
mode for your case?


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

https://reviews.llvm.org/D156989

___
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-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 546915.
cor3ntin added a comment.

Fix release notes formatting


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,255 @@
+///
+// 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}}
+int _; 

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

2023-08-03 Thread QuillPusher via Phabricator via cfe-commits
QuillPusher requested changes to this revision.
QuillPusher added a comment.
This revision now requires changes to proceed.

added some comments for minor changes. Two sections to be removed since they 
are not yet merged to upstream code:

- Complex Data Types
- Users can create their own types




Comment at: clang/docs/ExecutionResultsHandling.rst:50-52
+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.

@Krishna-13-cyber  This paragraph is exceeding 80 columns. Please reformat to 
limit to 80 columns



Comment at: clang/docs/ExecutionResultsHandling.rst:55
+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 

Please remove the hyphen: 

right-away -> right away

(must have carried through from previous tool's preview)



Comment at: clang/docs/ExecutionResultsHandling.rst:257-259
+`Above is an example of interoperability between the compiled code and the 
+interpreted code. Interoperability between languages (e.g., C++ and Python) 
+works similarly.`

Formatting for this note seems different, it is enclosed in single quotes. Did 
you mean **Note:** or  " " ?



Comment at: clang/docs/ExecutionResultsHandling.rst:268
+
+How it works?
+---

Please remove the question mark, this is an expression, not a question (common 
mistake)

How it works? -> How it works

Note that another heading has a question mark (**Where is the captured result 
stored?**). That question mark is OK, since that is actually mimicking a user's 
question. So leave that one as it is.



Comment at: clang/docs/ExecutionResultsHandling.rst:283
+
+.. code-block:: console
+

@Krishna-13-cyber please add a note/comment above the code block:

Note: Following is a sample code snippet. Actual code may vary over time.



Comment at: clang/docs/ExecutionResultsHandling.rst:329-356
+
+Complex Data Types:
+---
+
+This feature can print out primitive types (int, char, bool, etc.) easily. 
+For more complex types (e.g., `std::vector`), it falls back to a runtime 
+function call using the following helper function.

@Krishna-13-cyber please remove the "Complex Data Types" section, since this is 
not merged into the upstream LLVM code yet.
@junaire can confirm.



Comment at: clang/docs/ExecutionResultsHandling.rst:357-371
+
+Users can create their own types:
+-
+
+All overloads live in a header, which are included at runtime. So **print a 
+std::vector** is equivalent to `PrintValueRuntime();`.
+

@Krishna-13-cyber please remove the "Users can create their own types" section, 
since this is not merged into the upstream LLVM code yet.
@junaire can confirm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156858

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


[PATCH] D156596: [Clang] Produce a warning instead of an error in unevaluated strings before C++26

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

Note: we are waiting for feedback from @hubert.reinterpretcast's people before 
progressing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156596

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


[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals

2023-08-03 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 546911.
AlexVlx added a comment.

Rebase.


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

https://reviews.llvm.org/D155870

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/dynamic-cast-address-space.cpp


Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm 
-fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1344,15 +1344,16 @@
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction ) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptrdiff_t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 


Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1344,15 +1344,16 @@
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction ) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptrdiff_t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 
___
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-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 546910.
cor3ntin marked an inline comment as done.
cor3ntin added a comment.

- Rebase
- Address Aaron's comments
- Mention the lack of debugging support in the release notes.


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,255 @@
+///
+// 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 '_' 

[PATCH] D153969: [clang][ExprConstant] Fix crash on uninitialized base class subobject

2023-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Because this is fixing a regression, it may be worth backporting it to the 17.x 
branch: 
https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches


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

https://reviews.llvm.org/D153969

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


  1   2   3   >