[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-08-24 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:166
+  }
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const Decl *Callee = Call->getMethodDecl();





Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:194
+  }
+  return ContainsFunc && Overlap;
+}

This will always be false as if it's true, the loop would return.


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

https://reviews.llvm.org/D128401

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


[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 455477.
inclyc added a comment.

comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/FixIt/format.mm
  clang/test/Sema/format-strings-freebsd.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/test/SemaObjC/format-strings-objc.m
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -819,13 +819,7 @@
 
   Unclear type relationship between a format specifier and its argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf;>N2562
-  
-Partial
-  Clang supports diagnostics checking format specifier validity, but
-  does not yet account for all of the changes in this paper, especially
-  regarding length modifiers like h and hh.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaObjC/format-strings-objc.m
===
--- clang/test/SemaObjC/format-strings-objc.m
+++ clang/test/SemaObjC/format-strings-objc.m
@@ -80,7 +80,7 @@
 
 //  - Catch use of long long with int arguments.
 void rdar_7068334(void) {
-  long long test = 500;  
+  long long test = 500;
   printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   CFStringCreateWithFormat(CFSTR("%i"),test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
@@ -191,7 +191,7 @@
   NSLog(@"%C", data);  // no-warning
 
   const wchar_t wchar_data = L'a';
-  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
+  NSLog(@"%C", wchar_data);  // no-warning
 }
 
 // Test that %@ works with toll-free bridging ().
@@ -273,7 +273,7 @@
 
 void testUnicode(void) {
   NSLog(@"%C", 0x2022); // no-warning
-  NSLog(@"%C", 0x202200); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
+  NSLog(@"%C", 0x202200); // no-warning
 }
 
 // Test Objective-C modifier flags.
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -830,3 +830,57 @@
   printf_arg2("foo", "%s string %i\n", "aaa", 123);
   printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
 }
+
+void test_promotion(void) {
+  // Default argument promotions for *printf in N2562
+  // https://github.com/llvm/llvm-project/issues/57102
+  // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf
+  int i;
+  signed char sc;
+  unsigned char uc;
+  char c;
+  short ss;
+  unsigned short us;
+
+  printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning
+  printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning
+
+  // %ld %lld %llx
+  printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+  printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+  printf("%ld", sc); // expected-warning{{format specifies type 'long' but the argument has type 'signed char'}}
+  printf("%lld", sc); // expected-warning{{format specifies type 'long long' but the argument has type 'signed char'}}
+  printf("%ld", uc); // expected-warning{{format specifies type 'long' but the argument has type 'unsigned char'}}
+  printf("%lld", uc); // expected-warning{{format specifies type 'long long' but the argument has type 'unsigned char'}}
+  printf("%llx", i); // expected-warning{{format specifies type 'unsigned long long' but the argument has type 'int'}}
+
+  // ill formed spec for floats
+  printf("%hf", // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
+  sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+
+  // for %hhd and `short` they are compatible by promotions but more likely misuse
+  printf("%hd", ss); // no-warning
+  printf("%hhd", ss); // expected-warning{{format specifies type 'char' but the argument has type 'short'}}
+  printf("%hu", us); // no-warning
+  printf("%hhu", ss); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
+
+  // floats & integers are not compatible
+  printf("%f", i); // 

[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 455475.
inclyc added a comment.

Comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/FixIt/format.mm
  clang/test/Sema/format-strings-freebsd.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/test/SemaObjC/format-strings-objc.m
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -819,13 +819,7 @@
 
   Unclear type relationship between a format specifier and its argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf;>N2562
-  
-Partial
-  Clang supports diagnostics checking format specifier validity, but
-  does not yet account for all of the changes in this paper, especially
-  regarding length modifiers like h and hh.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaObjC/format-strings-objc.m
===
--- clang/test/SemaObjC/format-strings-objc.m
+++ clang/test/SemaObjC/format-strings-objc.m
@@ -80,7 +80,7 @@
 
 //  - Catch use of long long with int arguments.
 void rdar_7068334(void) {
-  long long test = 500;  
+  long long test = 500;
   printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   CFStringCreateWithFormat(CFSTR("%i"),test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
@@ -191,7 +191,7 @@
   NSLog(@"%C", data);  // no-warning
 
   const wchar_t wchar_data = L'a';
-  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
+  NSLog(@"%C", wchar_data);  // no-warning
 }
 
 // Test that %@ works with toll-free bridging ().
@@ -273,7 +273,7 @@
 
 void testUnicode(void) {
   NSLog(@"%C", 0x2022); // no-warning
-  NSLog(@"%C", 0x202200); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
+  NSLog(@"%C", 0x202200); // no-warning
 }
 
 // Test Objective-C modifier flags.
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -830,3 +830,57 @@
   printf_arg2("foo", "%s string %i\n", "aaa", 123);
   printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
 }
+
+void test_promotion(void) {
+  // Default argument promotions for *printf in N2562
+  // https://github.com/llvm/llvm-project/issues/57102
+  // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf
+  int i;
+  signed char sc;
+  unsigned char uc;
+  char c;
+  short ss;
+  unsigned short us;
+
+  printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning
+  printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning
+
+  // %ld %lld %llx
+  printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+  printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+  printf("%ld", sc); // expected-warning{{format specifies type 'long' but the argument has type 'signed char'}}
+  printf("%lld", sc); // expected-warning{{format specifies type 'long long' but the argument has type 'signed char'}}
+  printf("%ld", uc); // expected-warning{{format specifies type 'long' but the argument has type 'unsigned char'}}
+  printf("%lld", uc); // expected-warning{{format specifies type 'long long' but the argument has type 'unsigned char'}}
+  printf("%llx", i); // expected-warning{{format specifies type 'unsigned long long' but the argument has type 'int'}}
+
+  // ill formed spec for floats
+  printf("%hf", // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
+  sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+
+  // for %hhd and `short` they are compatible by promotions but more likely misuse
+  printf("%hd", ss); // no-warning
+  printf("%hhd", ss); // expected-warning{{format specifies type 'char' but the argument has type 'short'}}
+  printf("%hu", us); // no-warning
+  printf("%hhu", ss); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
+
+  // floats & integers are not compatible
+  printf("%f", i); // 

[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 455474.
inclyc added a comment.

Add tests for character literals

I've noticed that Linus mentioned the following code triggered warning by
clang. (With a little modifications shown below)

Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=21f9c8a13bb2a0c24d9c6b86bc0896542a28c197

  printf("%hhd", 'a');
  printf("%hd", 'a');

character literals are `int` in C. So clang-14 generates warnings like this:

  local/format.c:9:20: warning: format specifies type 'char' but the argument 
has type 'int' [-Wformat]
  printf("%hhd", 'a');
     ^~~
  %d
  local/format.c:10:19: warning: format specifies type 'short' but the argument 
has type 'char' [-Wformat]
  printf("%hd", 'a');
  ~~~   ^~~
  %hhd
  2 warnings generated.

Ironically, we advise our users to change their source code, which leads to
another warning. I've added tests for this case, after this patch, only (%hd,
"char") will cause warnings. And clang will generate warning like this:

  local/format.c:10:19: warning: format specifies type 'short' but the argument 
has type 'char' [-Wformat]
  printf("%hd", 'a');
  ~~~   ^~~
  %hhd
  1 warning generated.

Use `%hd` with `char` is not reasonable. (Probabaly another misuse) So I kept
this warning as-is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/FixIt/format.mm
  clang/test/Sema/format-strings-freebsd.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/test/SemaObjC/format-strings-objc.m
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -819,13 +819,7 @@
 
   Unclear type relationship between a format specifier and its argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf;>N2562
-  
-Partial
-  Clang supports diagnostics checking format specifier validity, but
-  does not yet account for all of the changes in this paper, especially
-  regarding length modifiers like h and hh.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaObjC/format-strings-objc.m
===
--- clang/test/SemaObjC/format-strings-objc.m
+++ clang/test/SemaObjC/format-strings-objc.m
@@ -80,7 +80,7 @@
 
 //  - Catch use of long long with int arguments.
 void rdar_7068334(void) {
-  long long test = 500;  
+  long long test = 500;
   printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   CFStringCreateWithFormat(CFSTR("%i"),test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
@@ -191,7 +191,7 @@
   NSLog(@"%C", data);  // no-warning
 
   const wchar_t wchar_data = L'a';
-  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
+  NSLog(@"%C", wchar_data);  // no-warning
 }
 
 // Test that %@ works with toll-free bridging ().
@@ -273,7 +273,7 @@
 
 void testUnicode(void) {
   NSLog(@"%C", 0x2022); // no-warning
-  NSLog(@"%C", 0x202200); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
+  NSLog(@"%C", 0x202200); // no-warning
 }
 
 // Test Objective-C modifier flags.
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -830,3 +830,57 @@
   printf_arg2("foo", "%s string %i\n", "aaa", 123);
   printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
 }
+
+void test_promotion(void) {
+  // Default argument promotions for *printf in N2562
+  // https://github.com/llvm/llvm-project/issues/57102
+  // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf
+  int i;
+  signed char sc;
+  unsigned char uc;
+  char c;
+  short ss;
+  unsigned short us;
+
+  printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning
+  printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning
+
+  // %ld %lld %llx
+  printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+  printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+  printf("%ld", sc); // 

[PATCH] D132600: [llvm-profdata] Handle internal linkage functions in profile supplementation

2022-08-24 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: llvm/tools/llvm-profdata/llvm-profdata.cpp:606
+} else {
+  StaticFuncMap[NewName] = "---";
+}

define a macro for the marker string.



Comment at: llvm/tools/llvm-profdata/llvm-profdata.cpp:655
 const sampleprof::FunctionSamples  = PD.second;
 auto It = InstrProfileMap.find(FContext.toString());
+if (It == InstrProfileMap.end()) {

Skip to the next (using continue) when FS is not interesting (cold etc)



Comment at: llvm/tools/llvm-profdata/llvm-profdata.cpp:667
+}
+if (FS.getMaxCountInside() > ColdSampleThreshold &&
 It != InstrProfileMap.end() &&

continue when Itr == end or when Itr is not cold


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

https://reviews.llvm.org/D132600

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


[PATCH] D132617: [clang][deps] Minor ModuleDepCollector refactorings NFC

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 455468.

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

https://reviews.llvm.org/D132617

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

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -57,15 +57,7 @@
   // These are technically *inputs* to the compilation, but we populate them
   // here in order to make \c getModuleContextHash() independent of
   // \c lookupModuleOutput().
-  for (ModuleID MID : Deps.ClangModuleDeps) {
-auto PCMPath =
-Consumer.lookupModuleOutput(MID, ModuleOutputKind::ModuleFile);
-if (EagerLoadModules)
-  CI.getFrontendOpts().ModuleFiles.push_back(PCMPath);
-else
-  CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
-  {MID.ModuleName, PCMPath});
-  }
+  addModuleFiles(CI, Deps.ClangModuleDeps);
 
   CI.getFrontendOpts().OutputFile =
   Consumer.lookupModuleOutput(Deps.ID, ModuleOutputKind::ModuleFile);
@@ -125,24 +117,12 @@
   CI.getFrontendOpts().Inputs.emplace_back(Deps.ClangModuleMapFile,
ModuleMapInputKind);
   CI.getFrontendOpts().ModuleMapFiles = Deps.ModuleMapFileDeps;
+  addModuleMapFiles(CI, Deps.ClangModuleDeps);
 
   // Report the prebuilt modules this module uses.
   for (const auto  : Deps.PrebuiltModuleDeps)
 CI.getFrontendOpts().ModuleFiles.push_back(PrebuiltModule.PCMFile);
 
-  if (!EagerLoadModules) {
-ModuleMap  =
-ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
-for (ModuleID MID : Deps.ClangModuleDeps) {
-  const Module *M = ModMap.findModule(MID.ModuleName);
-  assert(M && "Modular dependency not found");
-  auto MDeps = ModularDeps.find(M);
-  assert(MDeps != ModularDeps.end() && "Inconsistent dependency info");
-  CI.getFrontendOpts().ModuleMapFiles.push_back(
-  MDeps->second->ClangModuleMapFile);
-}
-  }
-
   // Remove any macro definitions that are explicitly ignored.
   if (!CI.getHeaderSearchOpts().ModulesIgnoreMacros.empty()) {
 llvm::erase_if(
@@ -169,6 +149,31 @@
   return CI;
 }
 
+void ModuleDepCollector::addModuleMapFiles(
+CompilerInvocation , ArrayRef ClangModuleDeps) const {
+  if (EagerLoadModules)
+return; // Only pcm is needed for eager load.
+
+  for (const ModuleID  : ClangModuleDeps) {
+ModuleDeps *MD = ModuleDepsByID.lookup(MID);
+assert(MD && "Inconsistent dependency info");
+CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);
+  }
+}
+
+void ModuleDepCollector::addModuleFiles(
+CompilerInvocation , ArrayRef ClangModuleDeps) const {
+  for (const ModuleID  : ClangModuleDeps) {
+std::string PCMPath =
+Consumer.lookupModuleOutput(MID, ModuleOutputKind::ModuleFile);
+if (EagerLoadModules)
+  CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
+else
+  CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
+  {MID.ModuleName, std::move(PCMPath)});
+  }
+}
+
 static std::string getModuleContextHash(const ModuleDeps ,
 const CompilerInvocation ,
 bool EagerLoadModules) {
@@ -210,6 +215,14 @@
   return toString(llvm::APInt(sizeof(Words) * 8, Words), 36, /*Signed=*/false);
 }
 
+void ModuleDepCollector::associateWithContextHash(const CompilerInvocation ,
+  ModuleDeps ) {
+  Deps.ID.ContextHash = getModuleContextHash(Deps, CI, EagerLoadModules);
+  bool Inserted = ModuleDepsByID.insert({Deps.ID, }).second;
+  (void)Inserted;
+  assert(Inserted && "duplicate module mapping");
+}
+
 void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -260,7 +273,8 @@
   const Module *TopLevelModule = Imported->getTopLevelModule();
 
   if (MDC.isPrebuiltModule(TopLevelModule))
-DirectPrebuiltModularDeps.insert(TopLevelModule);
+MDC.DirectPrebuiltModularDeps.insert(
+{TopLevelModule, PrebuiltModuleDep{TopLevelModule}});
   else
 DirectModularDeps.insert(TopLevelModule);
 }
@@ -297,8 +311,8 @@
   for (auto & : MDC.FileDeps)
 MDC.Consumer.handleFileDependency(I);
 
-  for (auto & : DirectPrebuiltModularDeps)
-MDC.Consumer.handlePrebuiltModuleDependency(PrebuiltModuleDep{I});
+  for (auto & : MDC.DirectPrebuiltModularDeps)
+MDC.Consumer.handlePrebuiltModuleDependency(I.second);
 }
 
 ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
@@ -400,8 +414,8 @@
*MDC.ScanInstance.getASTReader(), *MF);
  

[PATCH] D132616: [clang][deps] Remove CompilerInvocation from ModuleDeps

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8febb23a07b: [clang][deps] Remove CompilerInvocation from 
ModuleDeps (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132616

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -304,7 +304,7 @@
   {"file-deps", toJSONSorted(MD.FileDeps)},
   {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
   {"clang-modulemap-file", MD.ClangModuleMapFile},
-  {"command-line", MD.getCanonicalCommandLine()},
+  {"command-line", MD.BuildArguments},
   };
   OutModules.push_back(std::move(O));
 }
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -52,9 +52,8 @@
   return Result;
 }
 
-void ModuleDepCollector::addOutputPaths(ModuleDeps ) {
-  CompilerInvocation  = Deps.BuildInvocation;
-
+void ModuleDepCollector::addOutputPaths(CompilerInvocation ,
+ModuleDeps ) {
   // These are technically *inputs* to the compilation, but we populate them
   // here in order to make \c getModuleContextHash() independent of
   // \c lookupModuleOutput().
@@ -170,11 +169,8 @@
   return CI;
 }
 
-std::vector ModuleDeps::getCanonicalCommandLine() const {
-  return BuildInvocation.getCC1CommandLine();
-}
-
 static std::string getModuleContextHash(const ModuleDeps ,
+const CompilerInvocation ,
 bool EagerLoadModules) {
   llvm::HashBuilder,
 llvm::support::endianness::native>
@@ -188,7 +184,7 @@
 
   // Hash the BuildInvocation without any input files.
   SmallVector DummyArgs;
-  MD.BuildInvocation.generateCC1CommandLine(DummyArgs, [&](const Twine ) {
+  CI.generateCC1CommandLine(DummyArgs, [&](const Twine ) {
 Scratch.clear();
 StringRef Str = Arg.toStringRef(Scratch);
 HashBuilder.add(Str);
@@ -397,7 +393,7 @@
   llvm::DenseSet ProcessedModules;
   addAllAffectingModules(M, MD, ProcessedModules);
 
-  MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutOutputs(
+  CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
   MD, [&](CompilerInvocation ) {
 if (MDC.OptimizeArgs)
   optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
@@ -405,9 +401,12 @@
   });
 
   // Compute the context hash from the inputs. Requires dependencies.
-  MD.ID.ContextHash = getModuleContextHash(MD, MDC.EagerLoadModules);
+  MD.ID.ContextHash = getModuleContextHash(MD, CI, MDC.EagerLoadModules);
   // Finish the compiler invocation. Requires dependencies and the context hash.
-  MDC.addOutputPaths(MD);
+  MDC.addOutputPaths(CI, MD);
+
+  MD.BuildArguments = CI.getCC1CommandLine();
+
   return MD.ID;
 }
 
Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
===
--- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -119,11 +119,9 @@
   // the primary TU.
   bool ImportedByMainFile = false;
 
-  /// Compiler invocation that can be used to build this module (without paths).
-  CompilerInvocation BuildInvocation;
-
-  /// Gets the canonical command line suitable for passing to clang.
-  std::vector getCanonicalCommandLine() const;
+  /// Compiler invocation that can be used to build this module. Does not
+  /// include argv[0].
+  std::vector BuildArguments;
 };
 
 class ModuleDepCollector;
@@ -238,7 +236,7 @@
   llvm::function_ref Optimize) const;
 
   /// Add paths that require looking up outputs to the given dependencies.
-  void addOutputPaths(ModuleDeps );
+  void addOutputPaths(CompilerInvocation , ModuleDeps );
 };
 
 } // end namespace dependencies
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e8febb2 - [clang][deps] Remove CompilerInvocation from ModuleDeps

2022-08-24 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-08-24T19:51:12-07:00
New Revision: e8febb23a07bde8c02aee5545a0206e6f3851237

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

LOG: [clang][deps] Remove CompilerInvocation from ModuleDeps

The invocation is only ever used to serialize cc1 arguments from, so
instead serialize the arguments inside the dep scanner to simplify the
interface.

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

Added: 


Modified: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index a82355e60ee8..37eb4ef215b5 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -119,11 +119,9 @@ struct ModuleDeps {
   // the primary TU.
   bool ImportedByMainFile = false;
 
-  /// Compiler invocation that can be used to build this module (without 
paths).
-  CompilerInvocation BuildInvocation;
-
-  /// Gets the canonical command line suitable for passing to clang.
-  std::vector getCanonicalCommandLine() const;
+  /// Compiler invocation that can be used to build this module. Does not
+  /// include argv[0].
+  std::vector BuildArguments;
 };
 
 class ModuleDepCollector;
@@ -238,7 +236,7 @@ class ModuleDepCollector final : public DependencyCollector 
{
   llvm::function_ref Optimize) const;
 
   /// Add paths that require looking up outputs to the given dependencies.
-  void addOutputPaths(ModuleDeps );
+  void addOutputPaths(CompilerInvocation , ModuleDeps );
 };
 
 } // end namespace dependencies

diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index ad2d9939896e..fe0de00f6244 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -52,9 +52,8 @@ static std::vector splitString(std::string S, 
char Separator) {
   return Result;
 }
 
-void ModuleDepCollector::addOutputPaths(ModuleDeps ) {
-  CompilerInvocation  = Deps.BuildInvocation;
-
+void ModuleDepCollector::addOutputPaths(CompilerInvocation ,
+ModuleDeps ) {
   // These are technically *inputs* to the compilation, but we populate them
   // here in order to make \c getModuleContextHash() independent of
   // \c lookupModuleOutput().
@@ -170,11 +169,8 @@ 
ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
   return CI;
 }
 
-std::vector ModuleDeps::getCanonicalCommandLine() const {
-  return BuildInvocation.getCC1CommandLine();
-}
-
 static std::string getModuleContextHash(const ModuleDeps ,
+const CompilerInvocation ,
 bool EagerLoadModules) {
   llvm::HashBuilder,
 llvm::support::endianness::native>
@@ -188,7 +184,7 @@ static std::string getModuleContextHash(const ModuleDeps 
,
 
   // Hash the BuildInvocation without any input files.
   SmallVector DummyArgs;
-  MD.BuildInvocation.generateCC1CommandLine(DummyArgs, [&](const Twine ) {
+  CI.generateCC1CommandLine(DummyArgs, [&](const Twine ) {
 Scratch.clear();
 StringRef Str = Arg.toStringRef(Scratch);
 HashBuilder.add(Str);
@@ -397,7 +393,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const 
Module *M) {
   llvm::DenseSet ProcessedModules;
   addAllAffectingModules(M, MD, ProcessedModules);
 
-  MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutOutputs(
+  CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
   MD, [&](CompilerInvocation ) {
 if (MDC.OptimizeArgs)
   optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
@@ -405,9 +401,12 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const 
Module *M) {
   });
 
   // Compute the context hash from the inputs. Requires dependencies.
-  MD.ID.ContextHash = getModuleContextHash(MD, MDC.EagerLoadModules);
+  MD.ID.ContextHash = getModuleContextHash(MD, CI, MDC.EagerLoadModules);
   // Finish the compiler invocation. Requires dependencies and the context 
hash.
-  MDC.addOutputPaths(MD);
+  MDC.addOutputPaths(CI, MD);
+
+  MD.BuildArguments = CI.getCC1CommandLine();
+
   return MD.ID;
 }
 

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index a192d131c822..2d3415145bc6 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ 

[clang] bdc20d6 - [clang][tooling] Allow -cc1 arguments in ToolInvocation

2022-08-24 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-08-24T19:51:12-07:00
New Revision: bdc20d61b8e4a62ea00e1eb05ba87eefaf820434

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

LOG: [clang][tooling] Allow -cc1 arguments in ToolInvocation

ToolInvocation is useful even if you already have a -cc1 invocation,
since it provides a standard way to setup diagnostics, parse arguments,
and handoff to a ToolAction. So teach it to support -cc1 commands by
skipping the driver bits.

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

Added: 


Modified: 
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/ToolingTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index b36f58ad3046..52a81cd9e778 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -508,7 +508,7 @@ void 
addTargetAndModeForProgramName(std::vector ,
 
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList ,
+  ArrayRef CC1Args,
   const char *const BinaryName);
 
 } // namespace tooling

diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 6314615f83c8..65d850842432 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -161,7 +161,7 @@ getCC1Arguments(DiagnosticsEngine *Diagnostics,
 
 /// Returns a clang build invocation initialized from the CC1 flags.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList ,
+  ArrayRef CC1Args,
   const char *const BinaryName) {
   assert(!CC1Args.empty() && "Must at least contain the program name!");
   CompilerInvocation *Invocation = new CompilerInvocation;
@@ -339,7 +339,7 @@ ToolInvocation::~ToolInvocation() {
 }
 
 bool ToolInvocation::run() {
-  std::vector Argv;
+  llvm::opt::ArgStringList Argv;
   for (const std::string  : CommandLine)
 Argv.push_back(Str.c_str());
   const char *const BinaryName = Argv[0];
@@ -362,6 +362,17 @@ bool ToolInvocation::run() {
   SourceManager SrcMgr(*Diagnostics, *Files);
   Diagnostics->setSourceManager();
 
+  // We already have a cc1, just create an invocation.
+  if (CommandLine.size() >= 2 && CommandLine[1] == "-cc1") {
+ArrayRef CC1Args = makeArrayRef(Argv).drop_front();
+std::unique_ptr Invocation(
+newInvocation(&*Diagnostics, CC1Args, BinaryName));
+if (Diagnostics->hasErrorOccurred())
+  return false;
+return Action->runInvocation(std::move(Invocation), Files,
+ std::move(PCHContainerOps), DiagConsumer);
+  }
+
   const std::unique_ptr Driver(
   newDriver(&*Diagnostics, BinaryName, >getVirtualFileSystem()));
   // The "input file not found" diagnostics from the driver are useful.

diff  --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index aca343a963da..a476a9e3b510 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -326,6 +326,46 @@ TEST(ToolInvocation, DiagConsumerExpectingSourceManager) {
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+TEST(ToolInvocation, CC1Args) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-fsyntax-only");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_TRUE(Invocation.run());
+}
+
+TEST(ToolInvocation, CC1ArgsInvalid) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-invalid-arg");
+  Args.push_back("test.cpp");

[PATCH] D132615: [clang][tooling] Allow -cc1 arguments in ToolInvocation

2022-08-24 Thread Ben Langmuir 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 rGbdc20d61b8e4: [clang][tooling] Allow -cc1 arguments in 
ToolInvocation (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132615

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

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -326,6 +326,46 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+TEST(ToolInvocation, CC1Args) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-fsyntax-only");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_TRUE(Invocation.run());
+}
+
+TEST(ToolInvocation, CC1ArgsInvalid) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-invalid-arg");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_FALSE(Invocation.run());
+}
+
 namespace {
 /// Overlays the real filesystem with the given VFS and returns the result.
 llvm::IntrusiveRefCntPtr
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -161,7 +161,7 @@
 
 /// Returns a clang build invocation initialized from the CC1 flags.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList ,
+  ArrayRef CC1Args,
   const char *const BinaryName) {
   assert(!CC1Args.empty() && "Must at least contain the program name!");
   CompilerInvocation *Invocation = new CompilerInvocation;
@@ -339,7 +339,7 @@
 }
 
 bool ToolInvocation::run() {
-  std::vector Argv;
+  llvm::opt::ArgStringList Argv;
   for (const std::string  : CommandLine)
 Argv.push_back(Str.c_str());
   const char *const BinaryName = Argv[0];
@@ -362,6 +362,17 @@
   SourceManager SrcMgr(*Diagnostics, *Files);
   Diagnostics->setSourceManager();
 
+  // We already have a cc1, just create an invocation.
+  if (CommandLine.size() >= 2 && CommandLine[1] == "-cc1") {
+ArrayRef CC1Args = makeArrayRef(Argv).drop_front();
+std::unique_ptr Invocation(
+newInvocation(&*Diagnostics, CC1Args, BinaryName));
+if (Diagnostics->hasErrorOccurred())
+  return false;
+return Action->runInvocation(std::move(Invocation), Files,
+ std::move(PCHContainerOps), DiagConsumer);
+  }
+
   const std::unique_ptr Driver(
   newDriver(&*Diagnostics, BinaryName, >getVirtualFileSystem()));
   // The "input file not found" diagnostics from the driver are useful.
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -508,7 +508,7 @@
 
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList ,
+  ArrayRef CC1Args,
   const char *const BinaryName);
 
 } // namespace tooling
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131388: [docs] Add "Standard C++ Modules"

2022-08-24 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 455462.
ChuanqiXu retitled this revision from "[docs] Add "C++20 Modules"" to "[docs] 
Add "Standard C++ Modules"".
ChuanqiXu edited the summary of this revision.
ChuanqiXu added a comment.

Replace `C++20 Modules` with `Standard C++ Modules` since @ruoso pointed out 
that `Modules` is not specific to certain versions of C++ (for example, Modules 
may get some big changes in C++23, C++26, ...).


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

https://reviews.llvm.org/D131388

Files:
  clang/docs/CPlusPlus20Modules.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -40,6 +40,7 @@
SafeStack
ShadowCallStack
SourceBasedCodeCoverage
+   CPlusPlus20Modules
Modules
MSVCCompatibility
MisExpect
Index: clang/docs/CPlusPlus20Modules.rst
===
--- /dev/null
+++ clang/docs/CPlusPlus20Modules.rst
@@ -0,0 +1,825 @@
+
+Standard C++ Modules
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+The term ``modules`` has a lot of meanings. For the users of Clang, modules may
+refer to ``Objective-C Modules``, ``Clang C++ Modules`` (or ``Clang Header Modules``,
+etc.) or ``Standard C++ Modules``. The implementation of all these kinds of modules in Clang
+has a lot of shared code, but from the perspective of users, their semantics and
+command line interfaces are very different. This document focuses on
+an introduction of how to use standard C++ modules in Clang.
+
+There is already a detailed document about `Clang modules `_, it
+should be helpful to read `Clang modules `_ if you want to know
+more about the general idea of modules. Since standard C++ modules have different semantics
+(and work flows) from `Clang modules`, this page describes the background and use of
+Clang with standard C++ modules.
+
+Although the term ``modules`` has a unique meaning in C++20 Language Specification,
+when people talk about standard C++ modules, they may refer to another C++20 feature:
+header units, which are also covered in this document.
+
+standard C++ modules
+
+
+This document was intended to be a manual first and foremost, however, we consider it helpful to
+introduce some language background here for readers who are not familiar with
+the new language feature. This document is not intended to be a language
+tutorial; it will only introduce necessary concepts about the
+structure and building of the project.
+
+Background and terminology
+--
+
+Modules
+~~~
+
+In this document, the term ``Modules``/``modules`` refers to standard C++ modules
+feature if it is not decorated by ``Clang``.
+
+Clang Modules
+~
+
+In this document, the term ``Clang Modules``/``Clang modules`` refer to Clang
+c++ modules extension. These are also known as ``Clang header modules``,
+``Clang module map modules`` or ``Clang c++ modules``.
+
+Module and module unit
+~~
+
+A module consists of one or more module units. A module unit is a special
+translation unit. Every module unit must have a module declaration. The syntax
+of the module declaration is:
+
+.. code-block:: c++
+
+  [export] module module_name[:partition_name];
+
+Terms enclosed in ``[]`` are optional. The syntax of ``module_name`` and ``partition_name``
+in regex form corresponds to ``[a-zA-Z_][a-zA-Z_0-9\.]*``. In particular, a literal dot ``.``
+in the name has no semantic meaning (e.g. implying a hierarchy).
+
+In this document, module units are classified into:
+
+* Primary module interface unit.
+
+* Module implementation unit.
+
+* Module interface partition unit.
+
+* Internal module partition unit.
+
+A primary module interface unit is a module unit whose module declaration is
+``export module module_name;``. The ``module_name`` here denotes the name of the
+module. A module should have one and only one primary module interface unit.
+
+A module implementation unit is a module unit whose module declaration is
+``module module_name;``. A module could have multiple module implementation
+units with the same declaration.
+
+A module interface partition unit is a module unit whose module declaration is
+``export module module_name:partition_name;``. The ``partition_name`` should be
+unique to the module.
+
+A internal module partition unit is a module unit whose module declaration
+is ``module module_name:partition_name;``. The ``partition_name`` should be
+unique to the module.
+
+In this document, we use the following umbrella terms:
+
+* A ``module interface unit`` refers to either a ``primary module interface unit``
+  or a ``module interface partition unit``.
+
+* An ``importable module unit`` refers to either a ``module interface unit``
+  or a ``internal module partition unit``.
+
+* A 

[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 455459.
inclyc added a comment.

rm {}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/FixIt/format.mm
  clang/test/Sema/format-strings-freebsd.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/test/SemaObjC/format-strings-objc.m
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -819,13 +819,7 @@
 
   Unclear type relationship between a format specifier and its argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf;>N2562
-  
-Partial
-  Clang supports diagnostics checking format specifier validity, but
-  does not yet account for all of the changes in this paper, especially
-  regarding length modifiers like h and hh.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaObjC/format-strings-objc.m
===
--- clang/test/SemaObjC/format-strings-objc.m
+++ clang/test/SemaObjC/format-strings-objc.m
@@ -80,7 +80,7 @@
 
 //  - Catch use of long long with int arguments.
 void rdar_7068334(void) {
-  long long test = 500;  
+  long long test = 500;
   printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   CFStringCreateWithFormat(CFSTR("%i"),test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
@@ -191,7 +191,7 @@
   NSLog(@"%C", data);  // no-warning
 
   const wchar_t wchar_data = L'a';
-  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
+  NSLog(@"%C", wchar_data);  // no-warning
 }
 
 // Test that %@ works with toll-free bridging ().
@@ -273,7 +273,7 @@
 
 void testUnicode(void) {
   NSLog(@"%C", 0x2022); // no-warning
-  NSLog(@"%C", 0x202200); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
+  NSLog(@"%C", 0x202200); // no-warning
 }
 
 // Test Objective-C modifier flags.
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -830,3 +830,48 @@
   printf_arg2("foo", "%s string %i\n", "aaa", 123);
   printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
 }
+
+void test_promotion(void) {
+  // Default argument promotions for *printf in N2562
+  // https://github.com/llvm/llvm-project/issues/57102
+  // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf
+  int i;
+  signed char sc;
+  unsigned char uc;
+  char c;
+  short ss;
+  unsigned short us;
+
+  printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning
+  printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning
+
+  // %ld %lld %llx
+  printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+  printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+  printf("%ld", sc); // expected-warning{{format specifies type 'long' but the argument has type 'signed char'}}
+  printf("%lld", sc); // expected-warning{{format specifies type 'long long' but the argument has type 'signed char'}}
+  printf("%ld", uc); // expected-warning{{format specifies type 'long' but the argument has type 'unsigned char'}}
+  printf("%lld", uc); // expected-warning{{format specifies type 'long long' but the argument has type 'unsigned char'}}
+  printf("%llx", i); // expected-warning{{format specifies type 'unsigned long long' but the argument has type 'int'}}
+
+  // ill formed spec for floats
+  printf("%hf", // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
+  sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+
+  // for %hhd and `short` they are compatible by promotions but more likely misuse
+  printf("%hd", ss); // no-warning
+  printf("%hhd", ss); // expected-warning{{format specifies type 'char' but the argument has type 'short'}}
+  printf("%hu", us); // no-warning
+  printf("%hhu", ss); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
+
+  // floats & integers are not compatible
+  printf("%f", i); // expected-warning{{format 

[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 455458.
inclyc added a comment.

Address comments & more tests & docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/FixIt/format.mm
  clang/test/Sema/format-strings-freebsd.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/test/SemaObjC/format-strings-objc.m
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -819,13 +819,7 @@
 
   Unclear type relationship between a format specifier and its argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf;>N2562
-  
-Partial
-  Clang supports diagnostics checking format specifier validity, but
-  does not yet account for all of the changes in this paper, especially
-  regarding length modifiers like h and hh.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaObjC/format-strings-objc.m
===
--- clang/test/SemaObjC/format-strings-objc.m
+++ clang/test/SemaObjC/format-strings-objc.m
@@ -80,7 +80,7 @@
 
 //  - Catch use of long long with int arguments.
 void rdar_7068334(void) {
-  long long test = 500;  
+  long long test = 500;
   printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
   CFStringCreateWithFormat(CFSTR("%i"),test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}}
@@ -191,7 +191,7 @@
   NSLog(@"%C", data);  // no-warning
 
   const wchar_t wchar_data = L'a';
-  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
+  NSLog(@"%C", wchar_data);  // no-warning
 }
 
 // Test that %@ works with toll-free bridging ().
@@ -273,7 +273,7 @@
 
 void testUnicode(void) {
   NSLog(@"%C", 0x2022); // no-warning
-  NSLog(@"%C", 0x202200); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
+  NSLog(@"%C", 0x202200); // no-warning
 }
 
 // Test Objective-C modifier flags.
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -830,3 +830,48 @@
   printf_arg2("foo", "%s string %i\n", "aaa", 123);
   printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
 }
+
+void test_promotion(void) {
+  // Default argument promotions for *printf in N2562
+  // https://github.com/llvm/llvm-project/issues/57102
+  // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf
+  int i;
+  signed char sc;
+  unsigned char uc;
+  char c;
+  short ss;
+  unsigned short us;
+
+  printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning
+  printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning
+
+  // %ld %lld %llx
+  printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+  printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+  printf("%ld", sc); // expected-warning{{format specifies type 'long' but the argument has type 'signed char'}}
+  printf("%lld", sc); // expected-warning{{format specifies type 'long long' but the argument has type 'signed char'}}
+  printf("%ld", uc); // expected-warning{{format specifies type 'long' but the argument has type 'unsigned char'}}
+  printf("%lld", uc); // expected-warning{{format specifies type 'long long' but the argument has type 'unsigned char'}}
+  printf("%llx", i); // expected-warning{{format specifies type 'unsigned long long' but the argument has type 'int'}}
+
+  // ill formed spec for floats
+  printf("%hf", // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
+  sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+
+  // for %hhd and `short` they are compatible by promotions but more likely misuse
+  printf("%hd", ss); // no-warning
+  printf("%hhd", ss); // expected-warning{{format specifies type 'char' but the argument has type 'short'}}
+  printf("%hu", us); // no-warning
+  printf("%hhu", ss); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
+
+  // floats & integers are not compatible
+  printf("%f", 

[PATCH] D132236: [analyzer] Fix liveness of LazyCompoundVals

2022-08-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

So to be clear, I think your solution is probably an ok stop-gap solution. 
False negatives aren't that bad, I'm more worried that existing leak reports 
may become less understandable because they'll be reported later than 
necessary, which may obscure the reason why we think they're finally leaking. 
But I really want us to agree on how this facility is supposed to work, and 
explore the perfect solution, before implementing an imperfect solution.

Maybe we should introduce "weak region roots" that aren't necessarily live 
themselves but anything derived from them (any `SymbolRegionValue` or 
`SymbolDerived` for arbitrary sub-region `R'` of a weak-region-root 
`R`) is live. This could be pretty straightforward.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132236

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


[PATCH] D128314: [Clang-tidy] Fixing a bug in clang-tidy infinite-loop checker

2022-08-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Still looks good to me, let's commit!


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

https://reviews.llvm.org/D128314

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


[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-08-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think let's commit. @ziqingluo-90 addressed all existing concerns and 
promises follow-up patches where he'll have a chance to address future concerns 
as well.


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

https://reviews.llvm.org/D128401

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


[PATCH] D132538: [AArch64] Filter out invalid code model in frontend.

2022-08-24 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added inline comments.



Comment at: clang/test/Driver/mcmodel.c:9
 // RUN: not %clang -c -mcmodel=lager %s 2>&1 | FileCheck 
--check-prefix=INVALID %s
+// RUN: %clang -target aarch64 -### -c -mcmodel=medium %s 2>&1 | FileCheck 
--check-prefix=AARCH64-MEDIUM %s
+// RUN: %clang -target aarch64 -### -c -mcmodel=kernel %s 2>&1 | FileCheck 
--check-prefix=AARCH64-KERNEL %s

paquette wrote:
> Do you need `not` in front of this? Can't remember.
I use `-###` in the test lines. It will not execute commands. I changed them to 
be consistent with the previous 'invalid' test lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132538

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


[PATCH] D131009: [analyzer] Fixing a bug raising false positives of stack block object leaking under ARC

2022-08-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Works for me!


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

https://reviews.llvm.org/D131009

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


[PATCH] D132538: [AArch64] Filter out invalid code model in frontend.

2022-08-24 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 455454.
HsiangKai added a comment.

Make the test lines consistent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132538

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/mcmodel.c


Index: clang/test/Driver/mcmodel.c
===
--- clang/test/Driver/mcmodel.c
+++ clang/test/Driver/mcmodel.c
@@ -6,6 +6,8 @@
 // RUN: %clang -target powerpc-unknown-aix -### -S -mcmodel=medium %s 2> %t.log
 // RUN: FileCheck --check-prefix=AIX-MCMEDIUM-OVERRIDE %s < %t.log
 // RUN: not %clang -c -mcmodel=lager %s 2>&1 | FileCheck 
--check-prefix=INVALID %s
+// RUN: not %clang -c -target aarch64 -mcmodel=medium %s 2>&1 | FileCheck 
--check-prefix=AARCH64-MEDIUM %s
+// RUN: not %clang -c -target aarch64 -mcmodel=kernel %s 2>&1 | FileCheck 
--check-prefix=AARCH64-KERNEL %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -15,3 +17,6 @@
 // AIX-MCMEDIUM-OVERRIDE: "-mcmodel=large"
 
 // INVALID: error: invalid argument 'lager' to -mcmodel=
+
+// AARCH64-MEDIUM: error: invalid argument 'medium' to -mcmodel=
+// AARCH64-KERNEL: error: invalid argument 'kernel' to -mcmodel=
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5421,6 +5421,9 @@
 CM == "tiny") {
   if (Triple.isOSAIX() && CM == "medium")
 CmdArgs.push_back("-mcmodel=large");
+  else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium"))
+D.Diag(diag::err_drv_invalid_argument_to_option)
+<< CM << A->getOption().getName();
   else
 A->render(Args, CmdArgs);
 } else {


Index: clang/test/Driver/mcmodel.c
===
--- clang/test/Driver/mcmodel.c
+++ clang/test/Driver/mcmodel.c
@@ -6,6 +6,8 @@
 // RUN: %clang -target powerpc-unknown-aix -### -S -mcmodel=medium %s 2> %t.log
 // RUN: FileCheck --check-prefix=AIX-MCMEDIUM-OVERRIDE %s < %t.log
 // RUN: not %clang -c -mcmodel=lager %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// RUN: not %clang -c -target aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AARCH64-MEDIUM %s
+// RUN: not %clang -c -target aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AARCH64-KERNEL %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -15,3 +17,6 @@
 // AIX-MCMEDIUM-OVERRIDE: "-mcmodel=large"
 
 // INVALID: error: invalid argument 'lager' to -mcmodel=
+
+// AARCH64-MEDIUM: error: invalid argument 'medium' to -mcmodel=
+// AARCH64-KERNEL: error: invalid argument 'kernel' to -mcmodel=
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5421,6 +5421,9 @@
 CM == "tiny") {
   if (Triple.isOSAIX() && CM == "medium")
 CmdArgs.push_back("-mcmodel=large");
+  else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium"))
+D.Diag(diag::err_drv_invalid_argument_to_option)
+<< CM << A->getOption().getName();
   else
 A->render(Args, CmdArgs);
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-08-24 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added a comment.

This needs rebase. I failed to apply this patch due to conflict.


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

https://reviews.llvm.org/D130513

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


[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread YingChi Long via Phabricator via cfe-commits
inclyc added a comment.

> Do we want to encode that in `test_promotion` in 
> `clang/test/Sema/format-strings.c`? Seems like tests on shorts are missing.

Tests for short and char "incompatibility" could be found elsewhere in this 
file.

format-strings.c

  void should_understand_small_integers(void) {
printf("%hhu", (short) 10); // expected-warning{{format specifies type 
'unsigned char' but the argument has type 'short'}}
printf("%hu\n", (unsigned char)1); // warning with -Wformat-pedantic only
printf("%hu\n", (uint8_t)1);   // warning with -Wformat-pedantic only
  }
  /* ... */
  void test13(short x) {
char bel = 007;
printf("bel: '0%hhd'\n", bel); // no-warning
printf("x: '0%hhd'\n", x); // expected-warning {{format specifies type 
'char' but the argument has type 'short'}}
  }

Do I need to explicitly test again in the `test_promotion`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-24 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D128113#3746674 , @mizvekov wrote:

> In D128113#3745888 , @alexfh wrote:
>
>> The main questions we need to answer here are:
>>
>> 1. is the cost of storing parameter pack substitution indices while building 
>> AST worth the benefits?
>> 2. is there an alternative solution that would shift the cost to the moment 
>> when this information is about to be used (when formatting diagnostic, I 
>> suppose)?
>> 3. is there a good way to make this cost optional (using a flag or somehow 
>> else)?
>
>
>
> 1. For me yes, this was a fairly simple patch that got reviewed quickly and 
> got the job done. But it seems it was not good for your use case :)
> 2. I think there is a chance the approach I mentioned earlier could work. 
> It's hard for me to tell without spending some time trying. This could though 
> end up being a much more complicated patch, which hits my projects 
> bottleneck: it's pretty hard to find reviewers for this sort of stuff.
> 3. That has the advantage of change simplicity, but not user simplicity. It 
> could provide a escape hatch in allowing us to have a simple solution now, 
> but then iterate to something better later. But since this is an externally 
> visible change to the AST, it does seem far from ideal to be changing this 
> twice. It would be pretty unfortunate if someone else started using this 
> feature and then we decided to take it away.
>
> I would be fine though reverting this, and then doing some more 
> investigation, and also perhaps waiting for a second opinion from @rsmith.

For now we've added a workaround for the most problematic use case and got us 
unblocked. Thus there is no need now in introducing additional flags. However, 
I'm rather concerned about the cumulative additional overhead our build 
infrastructure gets as a result of this patch. Measuring this would 
unfortunately be a project of its own, which I'm not ready to commit to. If 
reverting this and discussing with Richard Smith is an option for you, I'd 
suggest doing this now and if you end up not finding a good alternative, we 
would probably need to find a way to estimate the impact of this patch. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D131683: Diagnosing the Future Keywords

2022-08-24 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman added inline comments.



Comment at: clang/test/Parser/static_assert.c:1
-// RUN: %clang_cc1 -fsyntax-only -std=c2x -DTEST_SPELLING -verify=c2x %s
-// RUN: %clang_cc1 -fsyntax-only -std=c2x -DTEST_SPELLING -fms-compatibility 
-verify=c2x-ms %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -DTEST_SPELLING -Weverything 
-verify=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -DTEST_SPELLING -fms-compatibility 
-verify=c17-ms %s

aaron.ballman wrote:
> Why did you add `-Weverything` here? That seems odd.
> Why did you add `-Weverything` here? That seems odd.

Totally unintentional. I was initially exploring something. will fix this. 
Thank you for pointing out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131683

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


[PATCH] D128619: [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

2022-08-24 Thread Haowei Wu via Phabricator via cfe-commits
haowei added subscribers: haowei, phosek, mcgrathr.
haowei added a comment.

Hi,

We are seeing build failures on Fuchsia build bots after this change was 
landed. and we suspect this patch causes clang to miscompile certain code. I 
filed bug https://github.com/llvm/llvm-project/issues/57351 and included a 
reproducer. Could you take a look? If it is confirmed to be a bug and take long 
time to fix, could you revert this change please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128619

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


[PATCH] D132425: [clang] Do not instrument relative vtables under hwasan

2022-08-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D132425#3743276 , @mcgrathr wrote:

> lgtm.
> You might add some comments in CGVTables.cpp about why this is done and what 
> the alternatives might be in the future.

Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132425

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


[PATCH] D132425: [clang] Do not instrument relative vtables under hwasan

2022-08-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 455423.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132425

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-hwasan.cpp

Index: clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-hwasan.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-hwasan.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -S -o - -emit-llvm -fsanitize=hwaddress | FileCheck %s
+
+/// The usual vtable will have default visibility. In this case, the actual
+/// vtable is hidden and the alias is made public. With hwasan enabled, we want
+/// to ensure the local one self-referenced in the hidden vtable is not
+/// hwasan-instrumented.
+// CHECK-DAG: @_ZTV1A.local = private unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1A.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1A3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, no_sanitize_hwaddress, align 4
+// CHECK-DAG: @_ZTV1A = unnamed_addr alias { [3 x i32] }, ptr @_ZTV1A.local
+
+class A {
+public:
+  virtual void foo();
+};
+
+void A::foo() {}
+
+void A_foo(A *a) {
+  a->foo();
+}
+
+/// If the vtable happens to be hidden, then the alias is not needed. In this
+/// case, the original vtable struct itself should be unsanitized.
+// CHECK-DAG: @_ZTV1B = hidden unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1B.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1B3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32)] }, no_sanitize_hwaddress, align 4
+
+class __attribute__((visibility("hidden"))) B {
+public:
+  virtual void foo();
+};
+
+void B::foo() {}
+
+void B_foo(B *b) {
+  b->foo();
+}
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1769,8 +1769,11 @@
 }
   }
 
-  if (VTContext.isRelativeLayout() && !VTable->isDSOLocal())
-CGVT.GenerateRelativeVTableAlias(VTable, VTable->getName());
+  if (VTContext.isRelativeLayout()) {
+CGVT.RemoveHwasanMetadata(VTable);
+if (!VTable->isDSOLocal())
+  CGVT.GenerateRelativeVTableAlias(VTable, VTable->getName());
+  }
 }
 
 bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField(
Index: clang/lib/CodeGen/CGVTables.h
===
--- clang/lib/CodeGen/CGVTables.h
+++ clang/lib/CodeGen/CGVTables.h
@@ -154,6 +154,9 @@
   /// when a vtable may not be dso_local.
   void GenerateRelativeVTableAlias(llvm::GlobalVariable *VTable,
llvm::StringRef AliasNameRef);
+
+  /// Specify a vtable should not be instrumented with hwasan.
+  void RemoveHwasanMetadata(llvm::GlobalValue *VTable);
 };
 
 } // end namespace CodeGen
Index: clang/lib/CodeGen/CGVTables.cpp
===
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -921,12 +921,33 @@
 
   CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout.get());
 
-  if (UsingRelativeLayout && !VTable->isDSOLocal())
-GenerateRelativeVTableAlias(VTable, OutName);
+  if (UsingRelativeLayout) {
+RemoveHwasanMetadata(VTable);
+if (!VTable->isDSOLocal())
+  GenerateRelativeVTableAlias(VTable, OutName);
+  }
 
   return VTable;
 }
 
+// Ensure this vtable is not instrumented by hwasan. That is, a global alias is
+// not generated for it. This is mainly used by the relative-vtables ABI where
+// vtables instead contain 32-bit offsets between the vtable and function
+// pointers. Hwasan is disabled for these vtables for now because the tag in a
+// vtable pointer may fail the overflow check when resolving 32-bit PLT
+// relocations. A future alternative for this would be finding which usages of
+// the vtable can continue to use the untagged hwasan value without any loss of
+// value in hwasan.
+void CodeGenVTables::RemoveHwasanMetadata(llvm::GlobalValue *VTable) {
+  if (CGM.getLangOpts().Sanitize.has(SanitizerKind::HWAddress)) {
+llvm::GlobalValue::SanitizerMetadata Meta;
+if (VTable->hasSanitizerMetadata())
+  Meta = VTable->getSanitizerMetadata();
+

[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-24 Thread Denis Nikitin via Phabricator via cfe-commits
denik added inline comments.



Comment at: clang/include/clang/Frontend/SARIFDiagnostic.h:24-26
+  raw_ostream *OS;
+
+  SarifDocumentWriter *Writer;

cjdb wrote:
> These can go in the private section below.
In addition, I think it's worth putting a comment here about Writer's ownership 
and why it's a raw pointer here (like we discussed offline).



Comment at: clang/include/clang/Frontend/SARIFDiagnosticPrinter.h:2
+//===--- SARIFDiagnosticPrinter.h - SARIF Diagnostic Client ---*- C++
+//-*-===//
+//

Please adjust the length to fit it in one line.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:2
+//===--- SARIFDiagnostic.cpp - SARIF Diagnostic Formatting
+//-===//
+//

Same here.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:38
+: DiagnosticRenderer(LangOpts, DiagOpts), OS(), Writer(Writer) {}
+
+void SARIFDiagnostic::emitDiagnosticMessage(

Could you please add FIXME with a pointer to llvm-project/issues/57323 to 
refactor Diagnostic classes?



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:58
+
+  if (Loc.isValid())
+Result = addLocationToResult(Result, Loc, PLoc, Ranges, *Diag);

I think we should add a test case when Loc or/and Source Manager is not set.
If Loc is not set SarifDocumentWriter might not create the `locations` property 
which is required by the spec.
If this is the case we need to fix it. But I'm not sure if 
emitDiagnosticMessage() is going to be called when Loc.isInvalid() ).



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:116
+
+Locations.push_back(
+CharSourceRange{SourceRange{BeginLoc, EndLoc}, /* ITR = */ false});

abrahamcd wrote:
> I noticed that when processing additional source ranges, regular source 
> locations are used instead of the presumed locations. Is this an intentional 
> difference from single location diagnostics? (This issue is present in the 
> current TextDiagnostics as well.)
Put FIXME here (if it's not already somewhere else).



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:78
+emitFilename(FE->getName(), Loc.getManager());
+// FIXME: No current way to add file-only location to SARIF object
+  }

aaron.ballman wrote:
> cjdb wrote:
> > I think it would be good to file an issue on GitHub and change to 
> > `FIXME(llvm-project/)`. @aaron.ballman WDYT?
> I'd be fine with that.
@abrahamcd please file the llvm-project/issues and link it here.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:191
+#ifdef _WIN32
+  TmpFilename = (*File)->getName();
+  llvm::sys::fs::make_absolute(TmpFilename);

cjdb wrote:
> aaron.ballman wrote:
> > Note: this is not a particularly small string when it requires 4k by 
> > default.
> There's a bug either here or in the function's interface: the function 
> returns a `StringRef` to a stack object. Do we really need ownership here?
> Note: this is not a particularly small string when it requires 4k by default.

This still has to be addressed.



Comment at: clang/lib/Frontend/SARIFDiagnosticPrinter.cpp:2
+//===--- SARIFDiagnosticPrinter.cpp - Diagnostic
+// Printer===//
+//

Same as above. One line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

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


[PATCH] D132620: [WIP][llvm] Extend aarch64 and x86_64 elf targets to use gotpcrel relocations

2022-08-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
Herald added subscribers: pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
leonardchan requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132620

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
  llvm/lib/Target/X86/X86TargetObjectFile.h

Index: llvm/lib/Target/X86/X86TargetObjectFile.h
===
--- llvm/lib/Target/X86/X86TargetObjectFile.h
+++ llvm/lib/Target/X86/X86TargetObjectFile.h
@@ -42,6 +42,7 @@
   public:
 X86ELFTargetObjectFile() {
   PLTRelativeVariantKind = MCSymbolRefExpr::VK_PLT;
+  SupportIndirectSymViaGOTPCRel = true;
 }
 /// Describe a TLS variable address within debug info.
 const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override;
Index: llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
===
--- llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
+++ llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
@@ -21,6 +21,7 @@
 public:
   AArch64_ELFTargetObjectFile() {
 PLTRelativeVariantKind = MCSymbolRefExpr::VK_PLT;
+SupportIndirectSymViaGOTPCRel = true;
   }
 };
 
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1425,6 +1425,15 @@
   return SSym;
 }
 
+const MCExpr *TargetLoweringObjectFileELF::getIndirectSymViaGOTPCRel(
+const GlobalValue *GV, const MCSymbol *Sym, const MCValue ,
+int64_t Offset, MachineModuleInfo *MMI, MCStreamer ) const {
+  const MCExpr *Res =
+MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
+  const MCExpr *Off = MCConstantExpr::create(Offset, getContext());
+  return MCBinaryExpr::createAdd(Res, Off, getContext());
+}
+
 const MCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(
 const GlobalValue *GV, const MCSymbol *Sym, const MCValue ,
 int64_t Offset, MachineModuleInfo *MMI, MCStreamer ) const {
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1749,8 +1749,10 @@
   // GlobalVariable or Function, i.e., as GlobalValue.
   if (!GV->hasGlobalUnnamedAddr() || !GV->hasInitializer() ||
   !GV->isConstant() || !GV->isDiscardableIfUnused() ||
-  !isa(GV->getOperand(0)))
+  !isa(GV->getOperand(0))) {
+//llvm::errs() << "Failed isGOTEquivalentCandidate for " << GV->getName() << "\n";
 return false;
+  }
 
   // To be a got equivalent, at least one of its users need to be a constant
   // expression used by another global variable.
@@ -3172,6 +3174,8 @@
 static void handleIndirectSymViaGOTPCRel(AsmPrinter , const MCExpr **ME,
  const Constant *BaseCst,
  uint64_t Offset) {
+  //llvm::errs() << "BaseCst:\n"; BaseCst->print(llvm::errs()); llvm::errs() << "\n";
+  //llvm::errs() << "ME: " << (**ME) << "\n";
   // The global @foo below illustrates a global that uses a got equivalent.
   //
   //  @bar = global i32 42
@@ -3193,7 +3197,14 @@
   //  cstexpr :=  -  + gotpcrelcst, where
   //gotpcrelcst :=  + 
   MCValue MV;
-  if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
+  if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr)) {
+//llvm::errs() << "ME not relocatable\n";
+return;
+  }
+
+  //llvm::errs() << "MV: "; MV.print(llvm::errs()); llvm::errs() << "\n";
+
+  if (MV.isAbsolute())
 return;
   const MCSymbolRefExpr *SymA = MV.getSymA();
   if (!SymA)
@@ -3201,19 +3212,24 @@
 
   // Check that GOT equivalent symbol is cached.
   const MCSymbol *GOTEquivSym = >getSymbol();
-  if (!AP.GlobalGOTEquivs.count(GOTEquivSym))
+  if (!AP.GlobalGOTEquivs.count(GOTEquivSym)) {
+//llvm::errs() << "No GlobalGOTEquivs for " << *GOTEquivSym << "\n";
 return;
+  }
 
   const GlobalValue *BaseGV = dyn_cast_or_null(BaseCst);
   if (!BaseGV)
 return;
+  //llvm::errs() << "Good BaseGV\n";
 
   // Check for a valid base symbol
   const MCSymbol *BaseSym = AP.getSymbol(BaseGV);
   const MCSymbolRefExpr *SymB = MV.getSymB();
 
-  if (!SymB || BaseSym != >getSymbol())
+  if (!SymB || BaseSym != >getSymbol()) {
+//llvm::errs() << "Bad base symbol\n";
 return;
+  }
 
   // Make sure to match:
   //
@@ -3223,8 +3239,9 @@
   // displacement into the 

[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-08-24 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a subscriber: ayzhao.
rnk added a comment.

In D119051#3747201 , @dblaikie wrote:

> So... my conclusion is that Clang's AArch64 appears to be correct for x86  as 
> well, and we should just rename the function and use it unconditionally, 
> removing any use of Clang's AST POD property in the MSVC ABI handling?

Sounds good to me, I think you did the hard work of verifying, thanks for that. 
:)

Anyway, removing this isPOD usage should be it's own patch, with tests. We 
should already have test coverage for aarch64 that can be reused. @ayzhao, can 
you help David with this? This is not C++20-related, but it is clang frontend 
related.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D132236: [analyzer] Fix liveness of LazyCompoundVals

2022-08-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Nice catch but I don't think this is the right solution.

Symbol liveness corresponds to a concrete runtime property of the program: can 
the program obtain this value by executing further runtime instructions? The 
program cannot obtain a pointer to variable `n`, or even a pointer to a region 
`*n`, just by looking at the data in a struct that was copied from region `*n` 
previously. Therefore neither `n` nor `*n` should not be marked live just 
because they are mentioned in a base region of a lazy compound value. In 
particular, memory leaks should be reported against `n` if the last place it's 
mentioned is a base region of a lazy compound value, as the program cannot 
possibly free that memory. You can most likely write a MallocChecker test for 
that, which will become a false negative after your patch.

For the same reason, for any region `R`, if `reg` or `derived` is 
live, does not mean `R` is live. //The program cannot guess a memory address by 
only looking at a value loaded from that address.//

If you look at how a simpler example works:

  void clang_analyzer_warnIfReached();
  
  void foo(int **n) {
int *n2 = *n;
if (!**n) {
  if (*n2) {
clang_analyzer_warnIfReached();
  }
}
  }

You will notice that it does not try to keep VarRegion `n` or even the symbol 
`reg_$0` alive. It is *sufficient* to keep `reg_$1},0 S64b,int *}>` alive in order to keep the 
test passing, and it does match the actual definition of live symbol (`reg_$0` 
can no longer be retrieved by the program but `reg_$1` can).

The original code tries to do the same for lazy compound values. I suspect that 
you'll find the actual bug when you descend into `getInterestingValues()`.

What looks fishy about `getInterestingValues()` is that it assumes that the 
amount of interesting values is finite. This sounds incredibly wrong to me. If 
a lazy compound value contains any pointer symbol `$p`, then all values in the 
following infinite series are interesting:

  $p,  *$p,  **$p,  ***$p,  ...

So I think the correct solution would be to maintain a list of explicitly-live 
compound values. Just like we already maintain a list of explicitly live 
symbols - `TheLiving`, and explicitly live regions - `RegionRoots`; neither of 
these lists enumerates all live symbols or regions as there are infinitely many 
of them, but each of these lists enumerates the ones that we've learned to be 
definitely live, and they're sufficient to determine liveness of any other 
symbol through recursive descent into the identity of that symbol. So with a 
list of live compound value regions, we can ask a question like "is this symbol 
stored in any of the known-live compound values?" to determine that symbol's 
liveness. This will keep the stored symbol alive without making the lazy 
compound value's base region alive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132236

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


[PATCH] D132617: [clang][deps] Minor ModuleDepCollector refactorings NFC

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

LGTM with a nit.




Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:277
+MDC.DirectPrebuiltModularDeps.insert(
+std::make_pair(TopLevelModule, PrebuiltModuleDep{TopLevelModule}));
   else

Nit: I think you should be able to drop `std::make_pair()` and use 
brace-initialization. Also applies to the other call to `insert` above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132617

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


[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h:224
+  /// a preprocessor. Storage owned by \c ModularDeps.
+  llvm::StringMap ModuleDepsByID;
+  /// Directly imported prebuilt deps.

jansvoboda11 wrote:
> I assume you're not using `llvm::DenseMap` because 
> it's a hassle to implement for custom keys and performance is not a concern, 
> correct? Any other aspects?
No good reason.  I switched it to DenseMap and included the change in 
https://reviews.llvm.org/D132617



Comment at: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h:226
+  /// Directly imported prebuilt deps.
+  std::vector DirectPrebuiltDeps;
+

jansvoboda11 wrote:
> Would this allow us to remove 
> `ModuleDepCollectorPP::DirectPrebuiltModularDeps`?
I sunk it to MDC in https://reviews.llvm.org/D132617.  It needed to change to 
`MapVector` since we are also uniquing them.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:358
+  for (auto & : DirectPrebuiltModularDeps) {
+MDC.DirectPrebuiltDeps.emplace_back(I);
+MDC.Consumer.handlePrebuiltModuleDependency(MDC.DirectPrebuiltDeps.back());

jansvoboda11 wrote:
> As said in a previous comment, we might avoid the copy by storing this in 
> `MDC` in the first place.
We don't save any copies, since we need to actually store the 
`PrebuiltModuleDep` in `MDC` in order to apply it to a secondary 
CompilerInvocation after the preprocessor etc. is gone.  But I still like 
sinking it down.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:471
+
+  MDC.setModuleDepsForID(MD.ID, );
   return MD.ID;

jansvoboda11 wrote:
> Nit: this function might get easier to think about if we did this in one step 
> with the context hash calculation:
> 
> ```
> MDC.associateWithContextHash(MD, CI);
> MDC.addOutputPaths(MD, CI);
> MD.BuildArguments = CI.getCC1CommandLine();
> ```
Good idea, included in https://reviews.llvm.org/D132617


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

https://reviews.llvm.org/D132405

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


[PATCH] D132616: [clang][deps] Remove CompilerInvocation from ModuleDeps

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132616

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


[PATCH] D132615: [clang][tooling] Allow -cc1 arguments in ToolInvocation

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

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132615

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


[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

In D132405#3747232 , @jansvoboda11 
wrote:

> I'd like to see this split into multiple patches. I can see some formatting 
> changes, removal of `CompilerInvocation` from `ModuleDeps`, isolated changes 
> to `Tooling`, etc. That'd make it much easier to review.

`ToolInvocation` change: https://reviews.llvm.org/D132615
Remove `CompilerInvocation` from `ModuleDeps`: https://reviews.llvm.org/D132616
Factoring out the `addModule*Files` functions, sink 
`DirectPrebuiltModularDeps`, etc: https://reviews.llvm.org/D132617


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

https://reviews.llvm.org/D132405

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


[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D132568#3746551 , @aaron.ballman 
wrote:

> Thank you for the patch, but it'd be really helpful to me as a reviewer if 
> you and @nickdesaulniers could coordinate so there's only one patch trying to 
> address #57102 instead of two competing patches (I'm happy to review 
> whichever patch comes out). From a quick look over the test case changes, 
> this patch looks like it's more in line with how I'd expect to resolve that 
> issue compared to D132266 .

The addition to clang/test/Sema/format-strings.c looks like it will resolve 
Linus' complaints in https://github.com/llvm/llvm-project/issues/57102; I'm 
happy to abandon D132266  in preference of 
this.

> However, the usage of %hhd corresponding to short is relatively rare, and it 
> is more likely to be a misuse.

Do we want to encode that in `test_promotion` in 
`clang/test/Sema/format-strings.c`? Seems like tests on shorts are missing.




Comment at: clang/lib/AST/FormatString.cpp:359
 
-  if (const BuiltinType *BT = argTy->getAs())
+  if (const BuiltinType *BT = argTy->getAs()) {
 switch (BT->getKind()) {

might as well make this `auto` while you're here.



Comment at: clang/lib/AST/FormatString.cpp:408-410
+T == C.ShortTy || T == C.UnsignedShortTy) {
+  return MatchPromotion;
+}

`{}` aren't necessary



Comment at: clang/lib/AST/FormatString.cpp:414-417
+if (T == C.SignedCharTy || T == C.UnsignedCharTy || T == C.IntTy ||
+T == C.UnsignedIntTy) {
+  return NoMatchPromotionTypeConfusion;
+}

`{}` aren't necessary



Comment at: clang/lib/AST/FormatString.cpp:426-428
+if (T == C.IntTy || T == C.UnsignedIntTy) {
+  return NoMatchPromotionTypeConfusion;
+}

`{}` aren't necessary



Comment at: clang/lib/Sema/SemaChecking.cpp:10084-10085
 
-  analyze_printf::ArgType::MatchKind Match = AT.matchesType(S.Context, ExprTy);
-  if (Match == analyze_printf::ArgType::Match)
+  ArgType::MatchKind ImplicitMatch = ArgType::NoMatch,
+ Match = AT.matchesType(S.Context, ExprTy);
+  if (Match == ArgType::Match)

I think it would be slightly more readable to make these two assignments two 
dedicated statements.



Comment at: clang/test/Sema/format-strings-scanf.c:271-272
+  scanf("%llx", ); // expected-warning{{format specifies type 'unsigned long 
long *' but the argument has type 'int *'}}
+  scanf("%hf", // expected-warning{{length modifier 'h' results in undefined 
behavior or no effect with 'f' conversion specifier}}
+  ); // Is this a clang bug ?
+  scanf("%s", i); // expected-warning{{format specifies type 'char *' but the 
argument has type 'int'}}

Hmm...



Comment at: clang/test/Sema/format-strings-scanf.c:274
+  scanf("%s", i); // expected-warning{{format specifies type 'char *' but the 
argument has type 'int'}}
+
+}

delete empty newline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

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


[PATCH] D119296: KCFI sanitizer

2022-08-24 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added inline comments.



Comment at: llvm/include/llvm/CodeGen/MachineInstr.h:265
+  PointerSumTypeMember,
+  PointerSumTypeMember>,
+  PointerSumTypeMember>

samitolvanen wrote:
> This fails on 32-bit architectures as `PointerEmbeddedInt` doesn't allow 
> storing 32 bits in a 32-bit pointer:
> ```
>   // Note: This '<' is correct; using '<=' would result in some shifts
>   // overflowing their storage types.
>   static_assert(Bits < sizeof(uintptr_t) * CHAR_BIT,
> "Cannot embed more bits than we have in a pointer!")
> ```
`PointerSumType` also needs space for a tag, which we don't have in a 32-bit 
pointer. Looks like we just need to always store `CFIType` in `ExtraInfo` to 
avoid this issue, similarly to `HeapAllocMarker`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119296

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


[PATCH] D132617: [clang][deps] Minor ModuleDepCollector refactorings NFC

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added a reviewer: jansvoboda11.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Factor module map and module file path functions out
- Use a secondary mapping to lookup module deps by ID instead of the 
preprocessor module map.
- Sink DirectPrebuiltModularDeps into MDC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132617

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

Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -57,15 +57,7 @@
   // These are technically *inputs* to the compilation, but we populate them
   // here in order to make \c getModuleContextHash() independent of
   // \c lookupModuleOutput().
-  for (ModuleID MID : Deps.ClangModuleDeps) {
-auto PCMPath =
-Consumer.lookupModuleOutput(MID, ModuleOutputKind::ModuleFile);
-if (EagerLoadModules)
-  CI.getFrontendOpts().ModuleFiles.push_back(PCMPath);
-else
-  CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
-  {MID.ModuleName, PCMPath});
-  }
+  addModuleFiles(CI, Deps.ClangModuleDeps);
 
   CI.getFrontendOpts().OutputFile =
   Consumer.lookupModuleOutput(Deps.ID, ModuleOutputKind::ModuleFile);
@@ -125,24 +117,12 @@
   CI.getFrontendOpts().Inputs.emplace_back(Deps.ClangModuleMapFile,
ModuleMapInputKind);
   CI.getFrontendOpts().ModuleMapFiles = Deps.ModuleMapFileDeps;
+  addModuleMapFiles(CI, Deps.ClangModuleDeps);
 
   // Report the prebuilt modules this module uses.
   for (const auto  : Deps.PrebuiltModuleDeps)
 CI.getFrontendOpts().ModuleFiles.push_back(PrebuiltModule.PCMFile);
 
-  if (!EagerLoadModules) {
-ModuleMap  =
-ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
-for (ModuleID MID : Deps.ClangModuleDeps) {
-  const Module *M = ModMap.findModule(MID.ModuleName);
-  assert(M && "Modular dependency not found");
-  auto MDeps = ModularDeps.find(M);
-  assert(MDeps != ModularDeps.end() && "Inconsistent dependency info");
-  CI.getFrontendOpts().ModuleMapFiles.push_back(
-  MDeps->second->ClangModuleMapFile);
-}
-  }
-
   // Remove any macro definitions that are explicitly ignored.
   if (!CI.getHeaderSearchOpts().ModulesIgnoreMacros.empty()) {
 llvm::erase_if(
@@ -169,6 +149,31 @@
   return CI;
 }
 
+void ModuleDepCollector::addModuleMapFiles(
+CompilerInvocation , ArrayRef ClangModuleDeps) const {
+  if (EagerLoadModules)
+return; // Only pcm is needed for eager load.
+
+  for (const ModuleID  : ClangModuleDeps) {
+ModuleDeps *MD = ModuleDepsByID.lookup(MID);
+assert(MD && "Inconsistent dependency info");
+CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);
+  }
+}
+
+void ModuleDepCollector::addModuleFiles(
+CompilerInvocation , ArrayRef ClangModuleDeps) const {
+  for (const ModuleID  : ClangModuleDeps) {
+std::string PCMPath =
+Consumer.lookupModuleOutput(MID, ModuleOutputKind::ModuleFile);
+if (EagerLoadModules)
+  CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
+else
+  CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
+  {MID.ModuleName, std::move(PCMPath)});
+  }
+}
+
 static std::string getModuleContextHash(const ModuleDeps ,
 const CompilerInvocation ,
 bool EagerLoadModules) {
@@ -210,6 +215,14 @@
   return toString(llvm::APInt(sizeof(Words) * 8, Words), 36, /*Signed=*/false);
 }
 
+void ModuleDepCollector::associateWithContextHash(const CompilerInvocation ,
+  ModuleDeps ) {
+  Deps.ID.ContextHash = getModuleContextHash(Deps, CI, EagerLoadModules);
+  bool Inserted = ModuleDepsByID.insert(std::make_pair(Deps.ID, )).second;
+  (void)Inserted;
+  assert(Inserted && "duplicate module mapping");
+}
+
 void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -260,7 +273,8 @@
   const Module *TopLevelModule = Imported->getTopLevelModule();
 
   if (MDC.isPrebuiltModule(TopLevelModule))
-DirectPrebuiltModularDeps.insert(TopLevelModule);
+MDC.DirectPrebuiltModularDeps.insert(
+std::make_pair(TopLevelModule, PrebuiltModuleDep{TopLevelModule}));
   else
 DirectModularDeps.insert(TopLevelModule);
 }
@@ -297,8 +311,8 @@
   for (auto & : MDC.FileDeps)
 MDC.Consumer.handleFileDependency(I);
 
-  for (auto & : 

[PATCH] D132616: [clang][deps] Remove CompilerInvocation from ModuleDeps

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added a reviewer: jansvoboda11.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The invocation is only ever used to serialize cc1 arguments from, so
instead serialize the arguments inside the dep scanner to simplify the
interface.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132616

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -304,7 +304,7 @@
   {"file-deps", toJSONSorted(MD.FileDeps)},
   {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
   {"clang-modulemap-file", MD.ClangModuleMapFile},
-  {"command-line", MD.getCanonicalCommandLine()},
+  {"command-line", MD.BuildArguments},
   };
   OutModules.push_back(std::move(O));
 }
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -52,9 +52,8 @@
   return Result;
 }
 
-void ModuleDepCollector::addOutputPaths(ModuleDeps ) {
-  CompilerInvocation  = Deps.BuildInvocation;
-
+void ModuleDepCollector::addOutputPaths(CompilerInvocation ,
+ModuleDeps ) {
   // These are technically *inputs* to the compilation, but we populate them
   // here in order to make \c getModuleContextHash() independent of
   // \c lookupModuleOutput().
@@ -170,11 +169,8 @@
   return CI;
 }
 
-std::vector ModuleDeps::getCanonicalCommandLine() const {
-  return BuildInvocation.getCC1CommandLine();
-}
-
 static std::string getModuleContextHash(const ModuleDeps ,
+const CompilerInvocation ,
 bool EagerLoadModules) {
   llvm::HashBuilder,
 llvm::support::endianness::native>
@@ -188,7 +184,7 @@
 
   // Hash the BuildInvocation without any input files.
   SmallVector DummyArgs;
-  MD.BuildInvocation.generateCC1CommandLine(DummyArgs, [&](const Twine ) {
+  CI.generateCC1CommandLine(DummyArgs, [&](const Twine ) {
 Scratch.clear();
 StringRef Str = Arg.toStringRef(Scratch);
 HashBuilder.add(Str);
@@ -397,7 +393,7 @@
   llvm::DenseSet ProcessedModules;
   addAllAffectingModules(M, MD, ProcessedModules);
 
-  MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutOutputs(
+  CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
   MD, [&](CompilerInvocation ) {
 if (MDC.OptimizeArgs)
   optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
@@ -405,9 +401,12 @@
   });
 
   // Compute the context hash from the inputs. Requires dependencies.
-  MD.ID.ContextHash = getModuleContextHash(MD, MDC.EagerLoadModules);
+  MD.ID.ContextHash = getModuleContextHash(MD, CI, MDC.EagerLoadModules);
   // Finish the compiler invocation. Requires dependencies and the context hash.
-  MDC.addOutputPaths(MD);
+  MDC.addOutputPaths(CI, MD);
+
+  MD.BuildArguments = CI.getCC1CommandLine();
+
   return MD.ID;
 }
 
Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
===
--- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -119,11 +119,9 @@
   // the primary TU.
   bool ImportedByMainFile = false;
 
-  /// Compiler invocation that can be used to build this module (without paths).
-  CompilerInvocation BuildInvocation;
-
-  /// Gets the canonical command line suitable for passing to clang.
-  std::vector getCanonicalCommandLine() const;
+  /// Compiler invocation that can be used to build this module. Does not
+  /// include argv[0].
+  std::vector BuildArguments;
 };
 
 class ModuleDepCollector;
@@ -238,7 +236,7 @@
   llvm::function_ref Optimize) const;
 
   /// Add paths that require looking up outputs to the given dependencies.
-  void addOutputPaths(ModuleDeps );
+  void addOutputPaths(CompilerInvocation , ModuleDeps );
 };
 
 } // end namespace dependencies
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132615: [clang][tooling] Allow -cc1 arguments in ToolInvocation

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added a reviewer: jansvoboda11.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

ToolInvocation is useful even if you already have a -cc1 invocation,
since it provides a standard way to setup diagnostics, parse arguments,
and handoff to a ToolAction. So teach it to support -cc1 commands by
skipping the driver bits.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132615

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

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -326,6 +326,46 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+TEST(ToolInvocation, CC1Args) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-fsyntax-only");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_TRUE(Invocation.run());
+}
+
+TEST(ToolInvocation, CC1ArgsInvalid) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-invalid-arg");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_FALSE(Invocation.run());
+}
+
 namespace {
 /// Overlays the real filesystem with the given VFS and returns the result.
 llvm::IntrusiveRefCntPtr
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -161,7 +161,7 @@
 
 /// Returns a clang build invocation initialized from the CC1 flags.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList ,
+  ArrayRef CC1Args,
   const char *const BinaryName) {
   assert(!CC1Args.empty() && "Must at least contain the program name!");
   CompilerInvocation *Invocation = new CompilerInvocation;
@@ -339,7 +339,7 @@
 }
 
 bool ToolInvocation::run() {
-  std::vector Argv;
+  llvm::opt::ArgStringList Argv;
   for (const std::string  : CommandLine)
 Argv.push_back(Str.c_str());
   const char *const BinaryName = Argv[0];
@@ -362,6 +362,17 @@
   SourceManager SrcMgr(*Diagnostics, *Files);
   Diagnostics->setSourceManager();
 
+  // We already have a cc1, just create an invocation.
+  if (CommandLine.size() >= 2 && CommandLine[1] == "-cc1") {
+ArrayRef CC1Args = makeArrayRef(Argv).drop_front();
+std::unique_ptr Invocation(
+newInvocation(&*Diagnostics, CC1Args, BinaryName));
+if (Diagnostics->hasErrorOccurred())
+  return false;
+return Action->runInvocation(std::move(Invocation), Files,
+ std::move(PCHContainerOps), DiagConsumer);
+  }
+
   const std::unique_ptr Driver(
   newDriver(&*Diagnostics, BinaryName, >getVirtualFileSystem()));
   // The "input file not found" diagnostics from the driver are useful.
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -508,7 +508,7 @@
 
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList ,
+  ArrayRef CC1Args,
   const char *const BinaryName);
 
 } // namespace tooling
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132266: [Clang][SemaChecking] move %hh and %h -Wformat warnings to -Wformat-pedantic

2022-08-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers abandoned this revision.
nickdesaulniers added a comment.

Prefer D132568 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132266

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


[PATCH] D132592: [Clang] Implement function attribute nouwtable

2022-08-24 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 455395.
ychen added a comment.
Herald added a subscriber: jdoerfert.

- update test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132592

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-nouwtable.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test


Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -114,6 +114,7 @@
 // CHECK-NEXT: NoStackProtector (SubjectMatchRule_function)
 // CHECK-NEXT: NoThreadSafetyAnalysis (SubjectMatchRule_function)
 // CHECK-NEXT: NoThrow (SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: NoUwtable (SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: OSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: OSReturnsNotRetained (SubjectMatchRule_function, 
SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, 
SubjectMatchRule_variable_is_parameter)
Index: clang/test/CodeGen/attr-nouwtable.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-nouwtable.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -funwind-tables=2 -S -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((nouwtable))
+int test1(void) { return 0; }
+
+// CHECK: @test1{{.*}}[[ATTR1:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = {
+// CHECK-NOT: uwtable
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1942,7 +1942,7 @@
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());
 
-  if (CodeGenOpts.UnwindTables)
+  if ((!D || !D->hasAttr()) && CodeGenOpts.UnwindTables)
 B.addUWTableAttr(llvm::UWTableKind(CodeGenOpts.UnwindTables));
 
   if (CodeGenOpts.StackClashProtector)
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -4537,6 +4537,16 @@
 }];
 }
 
+def NoUwtableDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``nouwtable`` attribute which skips emitting
+the unwind table entry for the specified function. This attribute is useful for
+selectively emitting the unwind table entry on some functions when building 
with
+``-funwind-tables`` compiler option.
+}];
+}
+
 def InternalLinkageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2086,6 +2086,13 @@
   let Documentation = [NoThrowDocs];
 }
 
+def NoUwtable : InheritableAttr {
+  let Spellings = [Clang<"nouwtable">];
+  let Subjects = SubjectList<[FunctionLike]>;
+  let Documentation = [NoUwtableDocs];
+  let SimpleHandler = 1;
+}
+
 def NvWeak : IgnoredAttr {
   // No Declspec spelling of this attribute; the CUDA headers use
   // __attribute__((nv_weak)) unconditionally. Does not receive an [[]]


Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -114,6 +114,7 @@
 // CHECK-NEXT: NoStackProtector (SubjectMatchRule_function)
 // CHECK-NEXT: NoThreadSafetyAnalysis (SubjectMatchRule_function)
 // CHECK-NEXT: NoThrow (SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: NoUwtable (SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: OSConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: OSReturnsNotRetained (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_variable_is_parameter)
Index: clang/test/CodeGen/attr-nouwtable.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-nouwtable.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -funwind-tables=2 -S -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((nouwtable))
+int test1(void) { return 0; }
+
+// CHECK: @test1{{.*}}[[ATTR1:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = {
+// CHECK-NOT: uwtable
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenModule.cpp

[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-24 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd updated this revision to Diff 455394.
abrahamcd marked 4 inline comments as done.
abrahamcd added a comment.

Deleted copy/move from renderer and returned OS to reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

Files:
  clang/include/clang/Frontend/SARIFDiagnostic.h
  clang/include/clang/Frontend/SARIFDiagnosticPrinter.h
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/SARIFDiagnostic.cpp
  clang/lib/Frontend/SARIFDiagnosticPrinter.cpp
  clang/test/Frontend/sarif-diagnostics.cpp

Index: clang/test/Frontend/sarif-diagnostics.cpp
===
--- /dev/null
+++ clang/test/Frontend/sarif-diagnostics.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang -fsyntax-only -Wall -Wextra -fdiagnostics-format=sarif %s > %t 2>&1 || true
+// RUN: FileCheck -dump-input=always %s --input-file=%t
+// CHECK: warning: diagnostic formatting in SARIF mode is currently unstable [-Wsarif-format-unstable]
+// CHECK: {"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":
+// Omit exact length of this file
+// CHECK: ,"location":{"index":0,"uri":"file://
+// Omit filepath to llvm project directory
+// CHECK: clang/test/Frontend/sarif-diagnostics.cpp"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":1,"startColumn":1,"startLine":12}}}],"message":{"text":"'main' must return 'int'"},"ruleId":"3464","ruleIndex":0},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":11,"startColumn":11,"startLine":13}}}],"message":{"text":"use of undeclared identifier 'hello'"},"ruleId":"4603","ruleIndex":1},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":17,"startColumn":17,"startLine":15}}}],"message":{"text":"invalid digit 'a' in decimal constant"},"ruleId":"898","ruleIndex":2},{"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":5,"startColumn":5,"startLine":19}}}],"message":{"text":"misleading indentation; statement is not part of the previous 'if'"},"ruleId":"1806","ruleIndex":3},{"level":"note","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":3,"startColumn":3,"startLine":17}}}],"message":{"text":"previous statement is here"},"ruleId":"1730","ruleIndex":4},{"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":10,"startColumn":10,"startLine":18}}}],"message":{"text":"unused variable 'Yes'"},"ruleId":"6538","ruleIndex":5},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":12,"startColumn":12,"startLine":21}}}],"message":{"text":"use of undeclared identifier 'hi'"},"ruleId":"4603","ruleIndex":6},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":1,"startColumn":1,"startLine":23}}}],"message":{"text":"extraneous closing brace ('}')"},"ruleId":"1399","ruleIndex":7},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":6,"endLine":27,"startColumn":5,"startLine":27}}},{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":10,"endLine":27,"startColumn":9,"startLine":27}}},{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":7,"startColumn":7,"startLine":27}}}],"message":{"text":"invalid operands to binary expression ('t1' and 

[clang] bbf19a6 - [AST] Use std::apply to pop front of tuples. NFCI.

2022-08-24 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-08-25T00:03:08+02:00
New Revision: bbf19a6745d5e2caa60d466c3c9fc8bc8eac3474

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

LOG: [AST] Use std::apply to pop front of tuples. NFCI.

Added: 


Modified: 
clang/lib/AST/ParentMapContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ParentMapContext.cpp 
b/clang/lib/AST/ParentMapContext.cpp
index e0d4700e4b10b..0840c573e0e45 100644
--- a/clang/lib/AST/ParentMapContext.cpp
+++ b/clang/lib/AST/ParentMapContext.cpp
@@ -265,16 +265,6 @@ class ParentMapContext::ParentMap {
   }
 };
 
-template 
-auto tuple_pop_front_impl(const Tuple , std::index_sequence) {
-  return std::make_tuple(std::get<1 + Is>(tuple)...);
-}
-
-template  auto tuple_pop_front(const Tuple ) {
-  return tuple_pop_front_impl(
-  tuple, std::make_index_sequence::value - 1>());
-}
-
 template  struct MatchParents {
   static std::tuple
   match(const DynTypedNodeList ,
@@ -285,10 +275,11 @@ template  struct MatchParents {
   if (NextParentList.size() == 1) {
 auto TailTuple = MatchParents::match(NextParentList, ParentMap);
 if (std::get(TailTuple)) {
-  return std::tuple_cat(
-  std::make_tuple(true, std::get(TailTuple),
-  TypedNode),
-  tuple_pop_front(tuple_pop_front(TailTuple)));
+  return std::apply(
+  [TypedNode](bool, DynTypedNodeList NodeList, auto... TupleTail) {
+return std::make_tuple(true, NodeList, TypedNode, 
TupleTail...);
+  },
+  TailTuple);
 }
   }
 }



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


[PATCH] D132607: [OffloadPackager] Add ability to extract mages from other file types

2022-08-24 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

> before or after this patch.

That would be your call. I personally would be biased towards doing refactoring 
early. Once something is in place, the temptation not to fix what already works 
might win.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132607

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


[PATCH] D132421: [HLSL] Support PCH for cc1 mode

2022-08-24 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 455389.
python3kgae added a comment.

Reuse decls already in PCH when initailize HLSLExternalSemaSource.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132421

Files:
  clang/include/clang/Sema/HLSLExternalSemaSource.h
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/test/AST/HLSL/Inputs/pch.hlsl
  clang/test/AST/HLSL/pch.hlsl

Index: clang/test/AST/HLSL/pch.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/pch.hlsl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl \
+// RUN:  -finclude-default-header -emit-pch -o %t %S/Inputs/pch.hlsl
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl \
+// RUN:  -finclude-default-header -include-pch %t -fsyntax-only -ast-dump-all %s \
+// RUN: | FileCheck  %s
+
+// Make sure PCH works by using function declared in PCH header and declare a RWBuffer in current file.
+// CHECK:FunctionDecl 0x[[FOO:[0-9a-f]+]] <{{.*}}:2:1, line:4:1> line:2:8 imported used foo 'float2 (float2, float2)'
+// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:10:1, col:23> col:23 Buffer 'hlsl::RWBuffer':'hlsl::RWBuffer<>'
+hlsl::RWBuffer Buffer;
+
+float2 bar(float2 a, float2 b) {
+// CHECK:CallExpr 0x{{[0-9a-f]+}}  'float2':'float __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}}  'float2 (*)(float2, float2)' 
+// CHECK-NEXT:`-DeclRefExpr 0x{{[0-9a-f]+}}  'float2 (float2, float2)' lvalue Function 0x[[FOO]] 'foo' 'float2 (float2, float2)'
+  return foo(a, b);
+}
Index: clang/test/AST/HLSL/Inputs/pch.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/Inputs/pch.hlsl
@@ -0,0 +1,4 @@
+
+float2 foo(float2 a, float2 b) {
+  return a + b;
+}
Index: clang/lib/Sema/HLSLExternalSemaSource.cpp
===
--- clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -250,9 +250,51 @@
 
 HLSLExternalSemaSource::~HLSLExternalSemaSource() {}
 
+static NamedDecl *findDecl(ASTContext , Sema , StringRef Name,
+  Sema::LookupNameKind Kind) {
+  IdentifierInfo  = AST.Idents.get(Name, tok::TokenKind::identifier);
+  DeclarationNameInfo NameInfo{DeclarationName{}, SourceLocation()};
+  LookupResult R(S, NameInfo, Kind);
+  S.LookupName(R, S.getCurScope());
+  NamedDecl *D = nullptr;
+  if (!R.isAmbiguous() && !R.empty())
+D = R.getRepresentativeDecl();
+  return D;
+}
+
 void HLSLExternalSemaSource::InitializeSema(Sema ) {
   SemaPtr = 
   ASTContext  = SemaPtr->getASTContext();
+
+  if (ExternalSema) {
+NamespaceDecl *ExternlHLSL = llvm::dyn_cast_if_present(
+findDecl(AST, S, "hlsl", Sema::LookupNameKind::LookupNamespaceName));
+// Try to initailize from ExternalSema.
+if (ExternlHLSL) {
+  auto *Resource = llvm::dyn_cast_if_present(
+  findDecl(AST, S, "Resource", Sema::LookupNameKind::LookupOrdinaryName));
+
+  auto *RWBuffer = llvm::dyn_cast_if_present(
+  findDecl(AST, S, "RWBuffer", Sema::LookupNameKind::LookupAnyName));
+  
+  // Find all things from ExternalSema, use them and return.
+  if (Resource && RWBuffer) {
+HLSLNamespace = ExternlHLSL;
+ResourceDecl = Resource;
+CXXRecordDecl *Decl = RWBuffer->getTemplatedDecl();
+if (!Decl->hasDefinition()) {
+  // Mark ExternalLexicalStorage so complete type will be called for
+  // ExternalAST path.
+  Decl->setHasExternalLexicalStorage();
+  Completions.insert(std::make_pair(
+  Decl, std::bind(::completeBufferType, this,
+  std::placeholders::_1)));
+}
+return;
+  }
+}
+  }
+
   IdentifierInfo  = AST.Idents.get("hlsl", tok::TokenKind::identifier);
   HLSLNamespace =
   NamespaceDecl::Create(AST, AST.getTranslationUnitDecl(), false,
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -1018,9 +1018,16 @@
 
   // Setup HLSL External Sema Source
   if (CI.getLangOpts().HLSL && CI.hasASTContext()) {
-IntrusiveRefCntPtr HLSLSema(
-new HLSLExternalSemaSource());
-CI.getASTContext().setExternalSource(HLSLSema);
+if (auto *SemaSource = dyn_cast_if_present(
+CI.getASTContext().getExternalSource())) {
+  IntrusiveRefCntPtr HLSLSema(
+  new HLSLExternalSemaSourceChain(SemaSource));
+  CI.getASTContext().setExternalSource(HLSLSema);
+} else {
+  IntrusiveRefCntPtr HLSLSema(
+  new HLSLExternalSemaSource());
+  CI.getASTContext().setExternalSource(HLSLSema);
+}
   }
 
   FailureCleanup.release();
Index: 

[PATCH] D132550: Changes to code ownership in clang and clang-tidy

2022-08-24 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

LGTM Thank you!




Comment at: clang/CODE_OWNERS.TXT:117
 N: Richard Smith
 E: rich...@metafoo.co.uk
+D: Emeritus owner




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132550

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


[PATCH] D132607: [OffloadPackager] Add ability to extract mages from other file types

2022-08-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D132607#3747394 , @tra wrote:

>> Should these be merged into a public interface via Object/OffloadBinary.h?
>
> I'm all for consolidating relevant code.

Basically it would be a free function doing that `extractFromBuffer` does here. 
I would also need to define a wrapper around `OwningBinary` as 
that's what I use in the linker wrapper.

I'm not sure if it would be easier to consolidate this before or after this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132607

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


[PATCH] D132550: Changes to code ownership in clang and clang-tidy

2022-08-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

LGTM thanks a lot for handling this!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132550

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


[PATCH] D132607: [OffloadPackager] Add ability to extract mages from other file types

2022-08-24 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

> Should these be merged into a public interface via Object/OffloadBinary.h?

I'm all for consolidating relevant code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132607

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


[PATCH] D132612: [HLSL] add asin library function

2022-08-24 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
bob80905 added reviewers: beanz, pow2clk.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change exposes the asin library function for HLSL scalar types, 
excluding long long doubles. Asin is supported for all scalar, vector,
and matrix types. This patch only adds a subset of scalar type support.

Long long double support is missing in this patch because that type
doesn't exist in HLSL.

The full documentation of the HLSL asin function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-asin


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132612

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/asin.hlsl


Index: clang/test/CodeGenHLSL/builtins/asin.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/asin.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s
+
+double asin_d(double x)
+{
+  return asin(x);
+}
+
+// CHECK: define noundef double @"?asin_d@@YANN@Z"(
+// CHECK: call noundef double @asin(double noundef %0) #2
+
+float asin_f(float x)
+{
+  return asin(x);
+}
+
+// CHECK: define noundef float @"?asin_f@@YAMM@Z"(
+// CHECK: call noundef float @asinf(float noundef %0)
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -12,4 +12,9 @@
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 
+
+__attribute__((clang_builtin_alias(__builtin_asin))) double asin(double In);
+__attribute__((clang_builtin_alias(__builtin_asinf))) float asin(float In);
+
+
 #endif //_HLSL_HLSL_INTRINSICS_H_


Index: clang/test/CodeGenHLSL/builtins/asin.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/asin.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s
+
+double asin_d(double x)
+{
+  return asin(x);
+}
+
+// CHECK: define noundef double @"?asin_d@@YANN@Z"(
+// CHECK: call noundef double @asin(double noundef %0) #2
+
+float asin_f(float x)
+{
+  return asin(x);
+}
+
+// CHECK: define noundef float @"?asin_f@@YAMM@Z"(
+// CHECK: call noundef float @asinf(float noundef %0)
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -12,4 +12,9 @@
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
+
+__attribute__((clang_builtin_alias(__builtin_asin))) double asin(double In);
+__attribute__((clang_builtin_alias(__builtin_asinf))) float asin(float In);
+
+
 #endif //_HLSL_HLSL_INTRINSICS_H_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132415: [LLDB] Add data formatter for std::coroutine_handle

2022-08-24 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91389000abe8: [LLDB] Add data formatter for 
std::coroutine_handle (authored by avogelsgesang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132415

Files:
  clang/docs/tools/clang-formatted-files.txt
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/packages/Python/lldbsuite/test/lldbutil.py
  lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
  lldb/source/Plugins/Language/CPlusPlus/Coroutines.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp
@@ -0,0 +1,40 @@
+#include 
+
+// `int_generator` is a stripped down, minimal coroutine generator
+// type.
+struct int_generator {
+  struct promise_type {
+int current_value = -1;
+
+auto get_return_object() {
+  return std::coroutine_handle::from_promise(*this);
+}
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+auto return_void() { return std::suspend_always(); }
+void unhandled_exception() { __builtin_unreachable(); }
+auto yield_value(int v) {
+  current_value = v;
+  return std::suspend_always();
+}
+  };
+
+  std::coroutine_handle hdl;
+
+  int_generator(std::coroutine_handle h) : hdl(h) {}
+  ~int_generator() { hdl.destroy(); }
+};
+
+int_generator my_generator_func() { co_yield 42; }
+
+// This is an empty function which we call just so the debugger has
+// a place to reliably set a breakpoint on.
+void empty_function_so_we_can_set_a_breakpoint() {}
+
+int main() {
+  int_generator gen = my_generator_func();
+  std::coroutine_handle<> type_erased_hdl = gen.hdl;
+  gen.hdl.resume();// Break at initial_suspend
+  gen.hdl.resume();// Break after co_yield
+  empty_function_so_we_can_set_a_breakpoint(); // Break at final_suspend
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py
@@ -0,0 +1,79 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+USE_LIBSTDCPP = "USE_LIBSTDCPP"
+USE_LIBCPP = "USE_LIBCPP"
+
+class TestCoroutineHandle(TestBase):
+def do_test(self, stdlib_type):
+"""Test std::coroutine_handle is displayed correctly."""
+self.build(dictionary={stdlib_type: "1"})
+
+test_generator_func_ptr_re = re.compile(
+r"^\(a.out`my_generator_func\(\) at main.cpp:[0-9]*\)$")
+
+# Run until the initial suspension point
+lldbutil.run_to_source_breakpoint(self, '// Break at initial_suspend',
+lldb.SBFileSpec("main.cpp", False))
+# Check that we show the correct function pointers and the `promise`. 
+self.expect_expr("gen.hdl",
+result_summary=re.compile("^coro frame = 0x[0-9a-f]*$"),
+result_children=[
+ValueCheck(name="resume", summary = test_generator_func_ptr_re),
+ValueCheck(name="destroy", summary = test_generator_func_ptr_re),
+ValueCheck(name="promise", children=[
+ValueCheck(name="current_value", value = "-1"),
+])
+])
+# For type-erased `coroutine_handle<>` we are missing the `promise`
+# but still show `resume` and `destroy`.
+self.expect_expr("type_erased_hdl",
+result_summary=re.compile("^coro frame = 0x[0-9a-f]*$"),
+result_children=[
+ValueCheck(name="resume", summary = test_generator_func_ptr_re),
+ValueCheck(name="destroy", summary = test_generator_func_ptr_re),
+])
+
+# Run until after the `co_yield`
+process = self.process()
+lldbutil.continue_to_source_breakpoint(self, process,
+'// Break after co_yield', lldb.SBFileSpec("main.cpp", False))
+# We correctly show the updated 

[clang] 9138900 - [LLDB] Add data formatter for std::coroutine_handle

2022-08-24 Thread Adrian Vogelsgesang via cfe-commits

Author: Adrian Vogelsgesang
Date: 2022-08-24T14:40:53-07:00
New Revision: 91389000abe8ef5d06d98cbbefd3fa03ac7e4480

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

LOG: [LLDB] Add data formatter for std::coroutine_handle

This patch adds a formatter for `std::coroutine_handle`, both for libc++
and libstdc++. For the type-erased `coroutine_handle<>`, it shows the
`resume` and `destroy` function pointers. For a non-type-erased
`coroutine_handle` it also shows the `promise` value.

With this change, executing the `v t` command on the example from
https://clang.llvm.org/docs/DebuggingCoroutines.html now outputs

```
(task) t = {
  handle = coro frame = 0xb2a0 {
resume = 0x5a10 (a.out`coro_task(int, int) at 
llvm-example.cpp:36)
destroy = 0x6090 (a.out`coro_task(int, int) at 
llvm-example.cpp:36)
  }
}
```

instead of just

```
(task) t = {
  handle = {
__handle_ = 0xb2a0
  }
}
```

Note, how the symbols for the `resume` and `destroy` function pointer
reveal which coroutine is stored inside the `std::coroutine_handle`.
A follow-up commit will use this fact to infer the coroutine's promise
type and the representation of its internal coroutine state based on
the `resume` and `destroy` pointers.

The same formatter is used for both libc++ and libstdc++. It would
also work for MSVC's standard library, however it is not registered
for MSVC, given that lldb does not provide pretty printers for other
MSVC types, either.

The formatter is in a newly added  `Coroutines.{h,cpp}` file because there
does not seem to be an already existing place where we could share
formatters across libc++ and libstdc++. Also, I expect this code to grow
as we improve debugging experience for coroutines further.

**Testing**

* Added API test

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

Added: 
lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
lldb/source/Plugins/Language/CPlusPlus/Coroutines.h

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/Makefile

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp

Modified: 
clang/docs/tools/clang-formatted-files.txt
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/packages/Python/lldbsuite/test/lldbutil.py
lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Removed: 




diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index f89e19ca7cd3a..c49acfaec58aa 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -4180,6 +4180,8 @@ 
lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
 lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.h
 lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
 lldb/source/Plugins/Language/CPlusPlus/BlockPointer.h
+lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
+lldb/source/Plugins/Language/CPlusPlus/Coroutines.h
 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
 lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.h
 lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.h

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 69bb5ac5629e4..1c090395e6c4c 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -292,8 +292,12 @@ def check_value(self, test_base, val, error_msg=None):
 test_base.assertEqual(self.expect_type, val.GetDisplayTypeName(),
   this_error_msg)
 if self.expect_summary:
-test_base.assertEqual(self.expect_summary, val.GetSummary(),
-  this_error_msg)
+if isinstance(self.expect_summary, re.Pattern):
+test_base.assertRegex(val.GetSummary(), self.expect_summary,
+  this_error_msg)
+else:
+test_base.assertEqual(self.expect_summary, val.GetSummary(),
+  this_error_msg)
 if self.children is not None:
 self.check_value_children(test_base, val, error_msg)
 

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 8bd49c742cb04..7e64afb3639cd 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -988,6 +988,21 @@ def 

[PATCH] D132502: [clang][modules] Consider M affecting after mapping M.Private to M_Private

2022-08-24 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 rG94e64df5763b: [clang][modules] Consider M affecting after 
mapping M.Private to M_Private (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D132502?vs=454964=455379#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132502

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/test/ClangScanDeps/modules-implicit-dot-private.m
  clang/test/Modules/implicit-map-dot-private.m

Index: clang/test/Modules/implicit-map-dot-private.m
===
--- clang/test/Modules/implicit-map-dot-private.m
+++ clang/test/Modules/implicit-map-dot-private.m
@@ -1,5 +1,17 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -verify -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/implicit-private-canonical -emit-pch -o %t-A.pch %s -Wprivate-module
+
+// Implicit modules.
+// RUN: %clang_cc1 -verify -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN:   -F %S/Inputs/implicit-private-canonical -fsyntax-only %s -Wprivate-module
+
+// Explicit modules.
+// RUN: %clang_cc1 -x objective-c -fmodules -emit-module -fmodule-name=A -o %t/A.pcm \
+// RUN:   %S/Inputs/implicit-private-canonical/A.framework/Modules/module.modulemap -Wprivate-module
+// RUN: %clang_cc1 -x objective-c -fmodules -emit-module -fmodule-name=A_Private -o %t/A_Private.pcm \
+// RUN:   %S/Inputs/implicit-private-canonical/A.framework/Modules/module.private.modulemap -Wprivate-module
+// RUN: %clang_cc1 -verify -fmodules -fimplicit-module-maps -fno-implicit-modules \
+// RUN:   -fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm \
+// RUN:   -F %S/Inputs/implicit-private-canonical -fsyntax-only %s -Wprivate-module
 
 #ifndef HEADER
 #define HEADER
Index: clang/test/ClangScanDeps/modules-implicit-dot-private.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-implicit-dot-private.m
@@ -0,0 +1,85 @@
+// This test checks that modules loaded during compilation (but not imported)
+// are still reported as dependencies.
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- frameworks/FW.framework/Modules/module.modulemap
+framework module FW { umbrella header "FW.h" }
+//--- frameworks/FW.framework/Headers/FW.h
+//--- frameworks/FW.framework/Modules/module.private.modulemap
+framework module FW_Private { umbrella header "FW_Private.h" }
+//--- frameworks/FW.framework/PrivateHeaders/FW_Private.h
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -iframework DIR/frameworks -c DIR/tu.m -o DIR/tu.o"
+}]
+//--- tu.m
+@import FW.Private;
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "FW"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/FW_Private.h"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "FW_Private"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "FW"
+// CHECK-NEXT:  

[clang] 94e64df - [clang][modules] Consider M affecting after mapping M.Private to M_Private

2022-08-24 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-08-24T14:36:06-07:00
New Revision: 94e64df5763b49d750a9a87ecdd4a6583ad6154f

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

LOG: [clang][modules] Consider M affecting after mapping M.Private to M_Private

When Clang encounters `@import M.Private` during implicit build, it precompiles 
module `M` and looks through its submodules. If the `Private` submodule is not 
found, Clang assumes `@import M_Private`. In the dependency scanner, we don't 
capture the dependency on `M`, since it's not imported. It's an affecting 
module, though: compilation of the import statement will fail when implicit 
modules are disabled and `M` is not precompiled and explicitly provided. This 
patch fixes that.

Depends on D132430.

Reviewed By: benlangmuir

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

Added: 
clang/test/ClangScanDeps/modules-implicit-dot-private.m

Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Lex/PPDirectives.cpp
clang/test/Modules/implicit-map-dot-private.m

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 5f54a44e604e2..470299b133a4a 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1335,6 +1335,16 @@ class Preprocessor {
 
   /// \}
 
+  /// Mark the given module as affecting the current module or translation 
unit.
+  void markModuleAsAffecting(Module *M) {
+if (!BuildingSubmoduleStack.empty()) {
+  if (M != BuildingSubmoduleStack.back().M)
+BuildingSubmoduleStack.back().M->AffectingModules.insert(M);
+} else {
+  AffectingModules.insert(M);
+}
+  }
+
   /// Get the set of top-level modules that affected preprocessing, but were 
not
   /// imported.
   const llvm::SmallSetVector () const {

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 6d1e378bf4dc1..c44ee00d90ffc 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -2013,8 +2013,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
 // match Foo_Private and emit a warning asking for the user to write
 // @import Foo_Private instead. FIXME: remove this when existing clients
 // migrate off of Foo.Private syntax.
-if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
-Module == Module->getTopLevelModule()) {
+if (!Sub && Name == "Private" && Module == Module->getTopLevelModule()) {
   SmallString<128> PrivateModule(Module->Name);
   PrivateModule.append("_Private");
 
@@ -2028,6 +2027,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
 Sub = loadModule(ImportLoc, PrivPath, Visibility, 
IsInclusionDirective);
   if (Sub) {
 MapPrivateSubModToTopLevel = true;
+PP->markModuleAsAffecting(Module);
 if (!getDiagnostics().isIgnored(
 diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
   getDiagnostics().Report(Path[I].second,

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 716f866e139ab..f5a9698c57c07 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2281,13 +2281,8 @@ Preprocessor::ImportAction 
Preprocessor::HandleHeaderIncludeOrImport(
 if (Imported) {
   Action = Import;
 } else if (Imported.isMissingExpected()) {
-  Module *M = static_cast(Imported)->getTopLevelModule();
-  if (!BuildingSubmoduleStack.empty()) {
-if (Imported != BuildingSubmoduleStack.back().M)
-  BuildingSubmoduleStack.back().M->AffectingModules.insert(M);
-  } else {
-AffectingModules.insert(M);
-  }
+  markModuleAsAffecting(
+  static_cast(Imported)->getTopLevelModule());
   // We failed to find a submodule that we assumed would exist (because it
   // was in the directory of an umbrella header, for instance), but no
   // actual module containing it exists (because the umbrella header is

diff  --git a/clang/test/ClangScanDeps/modules-implicit-dot-private.m 
b/clang/test/ClangScanDeps/modules-implicit-dot-private.m
new file mode 100644
index 0..6ae8eb2947067
--- /dev/null
+++ b/clang/test/ClangScanDeps/modules-implicit-dot-private.m
@@ -0,0 +1,85 @@
+// This test checks that modules loaded during compilation (but not imported)
+// are still reported as dependencies.
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- frameworks/FW.framework/Modules/module.modulemap
+framework module FW { umbrella header "FW.h" }
+//--- frameworks/FW.framework/Headers/FW.h
+//--- 

[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:86-88
+if (Range.isInvalid()) {
+  continue;
+}

cjdb wrote:
> It seems @aaron.ballman has finally trained me :(
{meme, src=ohno}

My work here is done. ;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

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


[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Frontend/SARIFDiagnosticPrinter.h:31
+class SARIFDiagnosticPrinter : public DiagnosticConsumer {
+  raw_ostream 
+  IntrusiveRefCntPtr DiagOpts;

cjdb wrote:
> cjdb wrote:
> > Please make OS a pointer instead of a reference, since member references 
> > make usage very unpleasant.
> Nit: please move all private members below the public interface, where 
> possible.
> Please make OS a pointer instead of a reference, since member references make 
> usage very unpleasant.

Err... I disagree (and just deleted a comment above asking for `OS` to turn 
into a reference rather than a pointer because it can never be null). I think 
we want to use a reference here because 1) it conveys the correct "I can never 
be null" semantics so maintainers don't have to ask when that can happen, and 
2) copies of this class are a bad idea to begin with (we should probably delete 
the copy and move operations).

We use reference members elsewhere: 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Sema/Sema.h#L407
 (not that I would hold Sema up as an example of best practices, lol).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

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


[PATCH] D132608: [CMake] Clean up CMake binary dir handling

2022-08-24 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Ericson2314 added reviewers: sebastian-ne, beanz, phosek, ldionne.
Herald added subscribers: libc-commits, libcxx-commits, Enna1, bzcheeseman, 
pmatos, asb, ayermolo, sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, 
tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, 
mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, pengfei, 
jgravelle-google, whisperity, sbc100, mgorny, nemanjai, dschuff.
Herald added a reviewer: bollu.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a reviewer: NoQ.
Herald added projects: libunwind, libc-project, Flang, All.
Herald added a reviewer: libunwind.
Ericson2314 requested review of this revision.
Herald added subscribers: llvm-commits, openmp-commits, lldb-commits, 
Sanitizers, cfe-commits, yota9, sstefan1, stephenneuendorffer, 
nicolasvasilache, jdoerfert, aheejin.
Herald added a reviewer: jdoerfert.
Herald added projects: clang, Sanitizers, LLDB, libc++, OpenMP, libc++abi, 
MLIR, LLVM.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.

There are a few goals here:

- Match what D132316  for `LLVM_BINARY_DIR`, 
for `CMAKE_BINARY_DIR`.

- Decrease the usages of `LLVM_LIBDIR_SUFFIX`, preparing us for D130586 
.

- Deduplicate code repeated across projects

Do this in this way:

- Shuffle around `CMAKE_MODULE_PATH` appending to allow `include`-ing our own 
modules earlier.

- Create new private/internal CMake modules and use them:
  - `GNUBinaryDirs`

Like upstream CMake `GNUInstallDirs`, but sets variations of 
`CMAKE_BINARY_DIR`. These are not CACHE PATHS because they are not intended to 
be user-modifyable.

`CMAKE_BINARY_LIBDIR` is based on the base name of `CMAKE_INSTALL_LIBDIR` 
rather than `LLVM_LIBDIR_SUFFIX`. This cannot just end with "lib", because the 
"install" and "binary" base names need to line up for various relative paths to 
work. It doesn't just use `LLVM_LIBDIR_SUFFIX` because we are trying to phase 
that out.
  - `LLVMLibdirSuffix`

A compat shim that defaults `CMAKE_INSTALL_LIBDIR` based on 
`LLVM_LIBDIR_SUFFIX`.
  - `LLVMSetIntDirs`

Just here to deduplicate the defining of `LLVM_LIBRARY_OUTPUT_INTDIR` and 
friends between projects.

- Do these replacements to make use of deps
  - `${CMAKE_BINARY_DIR}/lib(${CMAKE_LIBDIR_SUFFIX})?\>` -> 
`${CMAKE_BINARY_LIBDIR}`
  - `${CMAKE_BINARY_DIR}/bin\>` -> `${CMAKE_BINARY_BINDIR}`
  - `${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}` -> 
`${LLVM_LIBRARY_OUTPUT_INTDIR}`
  - `${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin` -> 
`${LLVM_RUNTIME_OUTPUT_INTDIR}`

It is somewhat odd to me that those last two vars start with `LLVM_` not 
`CMAKE_` when they are based on `CMAKE_BINARY_DIR`, but that can be tackled 
some other time.

- Cleanup custom install path initialization code in the runtimes

  Most significantly, they no longer have their


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132608

Files:
  bolt/CMakeLists.txt
  bolt/tools/driver/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  cmake/Modules/GNUBinaryDirs.cmake
  cmake/Modules/LLVMLibdirSuffix.cmake
  cmake/Modules/LLVMSetIntDirs.cmake
  compiler-rt/CMakeLists.txt
  compiler-rt/cmake/base-config-ix.cmake
  flang/CMakeLists.txt
  flang/cmake/modules/CMakeLists.txt
  flang/tools/f18/CMakeLists.txt
  libc/CMakeLists.txt
  libc/test/utils/tools/WrapperGen/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/docs/BuildingLibcxx.rst
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/docs/BuildingLibunwind.rst
  lld/CMakeLists.txt
  lld/cmake/modules/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt
  lldb/cmake/modules/LLDBConfig.cmake
  lldb/cmake/modules/LLDBStandalone.cmake
  llvm/CMakeLists.txt
  llvm/tools/llvm-go/CMakeLists.txt
  llvm/unittests/Target/AArch64/CMakeLists.txt
  llvm/unittests/Target/PowerPC/CMakeLists.txt
  llvm/unittests/Target/WebAssembly/CMakeLists.txt
  llvm/unittests/Target/X86/CMakeLists.txt
  mlir/CMakeLists.txt
  mlir/cmake/modules/CMakeLists.txt
  mlir/examples/standalone/CMakeLists.txt
  mlir/test/CMakeLists.txt
  mlir/utils/mbr/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/libomptarget/plugins/remote/CMakeLists.txt
  polly/CMakeLists.txt

Index: polly/CMakeLists.txt
===
--- polly/CMakeLists.txt
+++ polly/CMakeLists.txt
@@ -1,12 +1,28 @@
 # Check if this is a in tree build.
+
+set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
   

[PATCH] D132607: [OffloadPackager] Add ability to extract mages from other file types

2022-08-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: saiislam, JonChesterfield, yaxunl, ronlieb, tra, 
jdoerfert.
Herald added a subscriber: mgorny.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

A previous patch added support for extracting images from offloading
binaries. Users may wish to extract these files from the file types they
are most commonly emebedded in, such as an ELF or bitcode. This can be
difficult for the user to do manually, as these could be stored in
different section names potentially. This patch addsp support for
extracting these file types.

Note, this patch duplicated a lot of code from the `ClangLinkerWrapper`
that does a nearly identical extraction. Should these be merged into a
public interface via `Object/OffloadBinary.h`?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132607

Files:
  clang/test/Driver/offload-packager.c
  clang/tools/clang-offload-packager/CMakeLists.txt
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp

Index: clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
===
--- clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
+++ clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
@@ -14,7 +14,14 @@
 
 #include "clang/Basic/Version.h"
 
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IRReader/IRReader.h"
+#include "llvm/Object/Archive.h"
+#include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
+#include "llvm/Object/ELFObjectFile.h"
+#include "llvm/Object/IRObjectFile.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Object/OffloadBinary.h"
 #include "llvm/Support/CommandLine.h"
@@ -23,6 +30,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/WithColor.h"
 
@@ -54,6 +62,12 @@
   OS << clang::getClangToolFullVersion("clang-offload-packager") << '\n';
 }
 
+/// A single OffloadBinary and its associated memory.
+using OffloadFile = OwningBinary;
+
+Error extractFromBuffer(std::unique_ptr Buffer,
+SmallVectorImpl );
+
 // Get a map containing all the arguments for the image. Repeated arguments will
 // be placed in a comma separated list.
 static DenseMap getImageArguments(StringRef Image,
@@ -123,12 +137,11 @@
   return Error::success();
 }
 
-static Expected>>
-extractOffloadFiles(MemoryBufferRef Contents) {
-  if (identify_magic(Contents.getBuffer()) != file_magic::offload_binary)
-return createStringError(inconvertibleErrorCode(),
- "Input buffer not an offloading binary");
-  SmallVector> Binaries;
+/// Attempts to extract all the embedded device images contained inside the
+/// buffer \p Contents. The buffer is expected to contain a valid offloading
+/// binary format.
+Error extractOffloadFiles(MemoryBufferRef Contents,
+  SmallVectorImpl ) {
   uint64_t Offset = 0;
   // There could be multiple offloading binaries stored at this section.
   while (Offset < Contents.getBuffer().size()) {
@@ -138,12 +151,136 @@
 auto BinaryOrErr = OffloadBinary::create(*Buffer);
 if (!BinaryOrErr)
   return BinaryOrErr.takeError();
+OffloadBinary  = **BinaryOrErr;
+
+// Create a new owned binary with a copy of the original memory.
+std::unique_ptr BufferCopy = MemoryBuffer::getMemBufferCopy(
+Binary.getData().take_front(Binary.getSize()),
+Contents.getBufferIdentifier());
+auto NewBinaryOrErr = OffloadBinary::create(*BufferCopy);
+if (!NewBinaryOrErr)
+  return NewBinaryOrErr.takeError();
+DeviceFiles.emplace_back(std::move(*NewBinaryOrErr), std::move(BufferCopy));
+
+Offset += Binary.getSize();
+  }
+
+  return Error::success();
+}
+
+// Extract offloading binaries from an Object file \p Obj.
+Error extractFromBinary(const ObjectFile ,
+SmallVectorImpl ) {
+  for (ELFSectionRef Sec : Obj.sections()) {
+if (Sec.getType() != ELF::SHT_LLVM_OFFLOADING)
+  continue;
+
+Expected Buffer = Sec.getContents();
+if (!Buffer)
+  return Buffer.takeError();
+
+MemoryBufferRef Contents(*Buffer, Obj.getFileName());
+if (Error Err = extractOffloadFiles(Contents, DeviceFiles))
+  return Err;
+  }
+
+  return Error::success();
+}
+
+Error extractFromBitcode(std::unique_ptr Buffer,
+ SmallVectorImpl ) {
+  LLVMContext Context;
+  SMDiagnostic Err;
+  std::unique_ptr M = getLazyIRModule(std::move(Buffer), Err, Context);
+  if (!M)
+return createStringError(inconvertibleErrorCode(),
+ "Failed to create module");
+
+  // Extract offloading data from globals referenced by the
+  // `llvm.embedded.object` metadata with the 

[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

I left a couple of smaller initial comments. I'd like to see this split into 
multiple patches. I can see some formatting changes, removal of 
`CompilerInvocation` from `ModuleDeps`, isolated changes to `Tooling`, etc. 
That'd make it much easier to review.




Comment at: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h:204
+  /// invocation, for example when there are multiple chained invocations.
+  void handleInvocation(CompilerInvocation CI);
+

Nit: `handle*()` functions are associated with `DependencyConsumer` in my 
brain. Could we find a distinct name to avoid confusion between all the 
different types we're using here?



Comment at: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h:224
+  /// a preprocessor. Storage owned by \c ModularDeps.
+  llvm::StringMap ModuleDepsByID;
+  /// Directly imported prebuilt deps.

I assume you're not using `llvm::DenseMap` because it's 
a hassle to implement for custom keys and performance is not a concern, 
correct? Any other aspects?



Comment at: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h:226
+  /// Directly imported prebuilt deps.
+  std::vector DirectPrebuiltDeps;
+

Would this allow us to remove `ModuleDepCollectorPP::DirectPrebuiltModularDeps`?



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:358
+  for (auto & : DirectPrebuiltModularDeps) {
+MDC.DirectPrebuiltDeps.emplace_back(I);
+MDC.Consumer.handlePrebuiltModuleDependency(MDC.DirectPrebuiltDeps.back());

As said in a previous comment, we might avoid the copy by storing this in `MDC` 
in the first place.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:471
+
+  MDC.setModuleDepsForID(MD.ID, );
   return MD.ID;

Nit: this function might get easier to think about if we did this in one step 
with the context hash calculation:

```
MDC.associateWithContextHash(MD, CI);
MDC.addOutputPaths(MD, CI);
MD.BuildArguments = CI.getCC1CommandLine();
```


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

https://reviews.llvm.org/D132405

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-08-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Each godbolt link shows  MSVC 19.latest and clang, both in x86 and aarch64, 
with a reference pod and non-pod example at the start and end, and the variable 
test in the middle to see whether the codegen matches the pod or non-pod 
baselines above and below.

> 1. checked (second): has base classes

https://godbolt.org/z/d76fEGP1M - all agreed

> 2. checked (third): virtual functions/polymorphic

Oh, I guess if you can't have base classes then testing 'is polymorphic' is 
equivalent to 'has virtual functions'

This one's slightly less obvious to verify due to the existence of a virtual 
function changing the codegen of the `f1` test functions so comparing it to the 
pod/non-pod reference  & maybe me think about how to better isolate the test - 
though I don't think it's possible to totally isolate it, adding a virtual 
functions adds a vptr that has to be copied ,etc and extra globals for the 
vtalbe itself (MSVC doesn't home vtables), etc.

So I've got this: https://godbolt.org/z/nGa4drG4h - but it looks like they all 
agree, despite the extra variations in the output

> 3. only user-provided ctors, so it can have non-implicit (user-declared) but 
> defaulted ctors

User-defined ctor (`t1(int)` unrelated to any usage/copy operation, etc): 
https://godbolt.org/z/e79b1zeqr - everyone agrees
User-declared-but-not-user-defined ctor (`t1() = default`): Clang x86 is 
incorrect, believes it to be non-trivial - that's the original issue under 
discussion in this bug

> 4. specifically checking non-trivial copy assignment (no restriction on move 
> assignment and it could have any number of other member functions, I think?)

Oh, everyone allows a non-trivial non-special member function, I misread the 
Clang code - those don't affect retro-POD either, so everyone agrees on that. 
https://godbolt.org/z/hnMfqjov7

Restricting this to Special Member Functions, defaulted copy constructor... 
https://godbolt.org/z/sGvxcEPjo Clang x86 is incorrect

> 5. checked (first)

Used this as the baseline - everyone agrees.

> 6. nope/not relevant?



-

> 7. Presumably tested by "hasNonTrivialDestructor" and 
> "hasNonTrivialCopyAssignment"?

Having a field of a type with a protected member (property 5) - Clang x86 is 
incorrect: https://godbolt.org/z/GY48qxh3G
Having a field of a type with a non-trivial dtor - everyone agrees: 
https://godbolt.org/z/4dq9b43ac
Having a field of a type with a non-trivial copy-assignment - everyone agrees: 
https://godbolt.org/z/WEnKcz7oW

> 8. would a non-static data member initializer make the ctor user-provided? 
> Presumably not, so I don't think this property is checked at all, which seems 
> fair - how you pass something shouldn't be changed by how its constructed

Non-static data member initializer: https://godbolt.org/z/Mb1PYhjrP - Clang x86 
is incorrect

So... my conclusion is that Clang's AArch64 appears to be correct for x86  as 
well, and we should just rename the function and use it unconditionally, 
removing any use of Clang's AST POD property in the MSVC ABI handling?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D132605: Add test cases

2022-08-24 Thread fedeBuonco via Phabricator via cfe-commits
fedeBuonco created this revision.
Herald added subscribers: carlosgalvezp, kbarton, nemanjai.
Herald added a project: All.
fedeBuonco requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132605

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp
@@ -1,5 +1,22 @@
 // RUN: %check_clang_tidy %s cppcoreguidelines-declare-not-null %t
 
-void f(int *a);
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Found a pointer passed as a param 
[cppcoreguidelines-declare-not-null]
-void f2(int a);
\ No newline at end of file
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+
+void f(int *a){
+if(a == nullptr)
+return;
+else a++;
+return;
+}
+// CHECK-MESSAGES: [[@LINE-5]]:8: warning: pointer parameter checked against 
nullptr
+// CHECK-MESSAGES: [[@LINE-7]]:13: note: consider declaring as not_null
+
+void f2(gsl::not_nulla){
+return;
+}
+
+void f3(int a);
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
@@ -17,13 +17,29 @@
 namespace cppcoreguidelines {
 
 void DeclareNotNullCheck::registerMatchers(MatchFinder *Finder) {
-  auto PointerType = hasType(pointerType());
-  Finder->addMatcher(parmVarDecl(PointerType).bind("param"), this);
+  auto NullCondition = expr(ignoringImpCasts(anyOf(
+  binaryOperator(hasOperatorName("=="),
+ hasLHS(ignoringImpCasts(cxxNullPtrLiteralExpr())),
+ hasRHS(ignoringImpCasts(expr().bind("exp",
+  binaryOperator(hasOperatorName("=="),
+ hasLHS(ignoringImpCasts(expr().bind("exp"))),
+ hasRHS(ignoringImpCasts(cxxNullPtrLiteralExpr()));
+  auto functMatcher =
+  functionDecl(
+  hasAnyParameter(parmVarDecl(hasType(pointerType())).bind("param")))
+  .bind("funct");
+  Finder->addMatcher(ifStmt(hasParent(compoundStmt(hasParent(functMatcher))),
+hasCondition(NullCondition)),
+ this);
 }
 
 void DeclareNotNullCheck::check(const MatchFinder::MatchResult ) {
+  const FunctionDecl *Funct = Result.Nodes.getNodeAs("funct");
   const ParmVarDecl *Par = Result.Nodes.getNodeAs("param");
-  diag(Par->getLocation(), "Found a pointer passed as a param") << Par;
+  const Expr *Ex = Result.Nodes.getNodeAs("exp");
+  diag(Ex->getExprLoc(), "pointer parameter checked against nullptr") << Par;
+  diag(Par->getLocation(), "consider declaring as not_null",
+   DiagnosticIDs::Note);
 }
 
 } // namespace cppcoreguidelines


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/declare-not-null.cpp
@@ -1,5 +1,22 @@
 // RUN: %check_clang_tidy %s cppcoreguidelines-declare-not-null %t
 
-void f(int *a);
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Found a pointer passed as a param [cppcoreguidelines-declare-not-null]
-void f2(int a);
\ No newline at end of file
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+
+void f(int *a){
+if(a == nullptr)
+return;
+else a++;
+return;
+}
+// CHECK-MESSAGES: [[@LINE-5]]:8: warning: pointer parameter checked against nullptr
+// CHECK-MESSAGES: [[@LINE-7]]:13: note: consider declaring as not_null
+
+void f2(gsl::not_nulla){
+return;
+}
+
+void f3(int a);
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/DeclareNotNullCheck.cpp
@@ -17,13 +17,29 @@
 namespace cppcoreguidelines {
 
 void DeclareNotNullCheck::registerMatchers(MatchFinder *Finder) {
-  auto PointerType = hasType(pointerType());
-  Finder->addMatcher(parmVarDecl(PointerType).bind("param"), this);
+  auto NullCondition = expr(ignoringImpCasts(anyOf(
+  binaryOperator(hasOperatorName("=="),
+ 

[PATCH] D113107: Support of expression granularity for _Float16.

2022-08-24 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D113107#3747095 , @rjmccall wrote:

> Thanks, LGTM

Thanks for all the reviews. There is still more work to be done :) 
I will push it tomorrow as it's the end of day for me and I am afraid there 
will be some fails that I wouldn't be able to attend to right away.
Thank you!


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

https://reviews.llvm.org/D113107

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


[PATCH] D113107: Support of expression granularity for _Float16.

2022-08-24 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM


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

https://reviews.llvm.org/D113107

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


[PATCH] D132600: [llvm-profdata] Handle internal linkage functions in profile supplementation

2022-08-24 Thread Rong Xu via Phabricator via cfe-commits
xur created this revision.
xur added reviewers: davidxl, tmsriram.
Herald added a subscriber: wenlei.
Herald added a project: All.
xur requested review of this revision.
Herald added a project: LLVM.

This patch has the following changes:
(1) Handling of internal linkage functions (static functions)
Static functions in FDO have a prefix of source file name, while they do not
have one in SampleFDO. Current implementation does not handle this and we are
not updating the profile for static functions. This patch fixes this.

(2) Handling of -funique-internal-linakge-symbols
Again this is for the internal linkage functions. Option
-funique-internal-linakge-symbols can now be applied to both FDO and SampleFDO
compilation. When it is used, it demangles internal linkage function names and
adds a hash value as the postfix.

When both SampleFDO and FDO profiles use this option, or both
not use this option, changes in (1) should handle this.

Here we also handle when the SampleFDO profile using this option while FDO
profile not using this option, or vice versa.

There is one case where this patch won't work: If one of the profiles used
mangled name and the other does not. For example, if the SampleFDO profile
uses clang c-compiler and without -funique-internal-linakge-symbols, while
the FDO profile uses -funique-internal-linakge-symbols. The SampleFDO profile
contains unmangled names while the FDO profile contains mangled names. If
both profiles use c++ compiler, this won't happen. We think this use case
is rare and does not justify the effort to fix.


https://reviews.llvm.org/D132600

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/test/tools/llvm-profdata/Inputs/FUnique.afdotext
  llvm/test/tools/llvm-profdata/Inputs/FUnique.proftext
  llvm/test/tools/llvm-profdata/Inputs/NoFUnique.afdotext
  llvm/test/tools/llvm-profdata/Inputs/NoFUnique.proftext
  llvm/test/tools/llvm-profdata/suppl-instr-with-sample-static-func.test
  llvm/tools/llvm-profdata/llvm-profdata.cpp

Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/MD5.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ThreadPool.h"
@@ -478,7 +479,7 @@
   ZeroCounterRatio = (float)ZeroCntNum / CntNum;
 }
 
-/// Either set all the counters in the instr profile entry \p IFE to -1
+// Either set all the counters in the instr profile entry \p IFE to -1
 /// in order to drop the profile or scale up the counters in \p IFP to
 /// be above hot threshold. We use the ratio of zero counters in the
 /// profile of a function to decide the profile is helpful or harmful
@@ -539,7 +540,73 @@
unsigned InstrProfColdThreshold) {
   // Function to its entry in instr profile.
   StringMap InstrProfileMap;
+  StringMap StaticFuncMap;
   InstrProfSummaryBuilder IPBuilder(ProfileSummaryBuilder::DefaultCutoffs);
+
+  auto checkSampleProfileHasFUnique = []() {
+for (const auto  : Reader->getProfiles()) {
+  auto  = PD.first;
+  if (FContext.toString().find(FunctionSamples::UniqSuffix) !=
+  std::string::npos) {
+return true;
+  }
+}
+return false;
+  };
+
+  bool SampleProfileHasFUnique = checkSampleProfileHasFUnique();
+
+  auto buildStaticFuncMap = [,
+ SampleProfileHasFUnique](const StringRef ) {
+std::string Prefixes[] = {".cpp:", "cc:", ".c:", ".hpp:", ".h:"};
+size_t PrefixPos = StringRef::npos;
+for (auto  : Prefixes) {
+  PrefixPos = Name.find_insensitive(Prefix);
+  if (PrefixPos == StringRef::npos)
+continue;
+  PrefixPos += Prefix.size();
+  break;
+}
+
+if (PrefixPos == StringRef::npos) {
+  return;
+}
+
+StringRef NewName = Name.drop_front(PrefixPos);
+StringRef FName = Name.substr(0, PrefixPos - 1);
+if (NewName.size() == 0) {
+  return;
+}
+
+// This name should have a static linkage.
+size_t PostfixPos = NewName.find(FunctionSamples::UniqSuffix);
+bool ProfileHasFUnique = (PostfixPos != StringRef::npos);
+
+if (SampleProfileHasFUnique) {
+  // If profile also uses funqiue, nothing to do here.
+  // Otherwise, we need to build the map.
+  if (!ProfileHasFUnique) {
+std::string NStr =
+NewName.str() + getUniqueInternalLinkagePostfix(FName);
+NewName = StringRef(NStr);
+StaticFuncMap[NewName] = Name;
+return;
+  }
+} else {
+  // If profile does not use -funique-internal-linakge-symbols, nothing to
+  // do here. Otherwise, we need to trim.
+  if (ProfileHasFUnique) {
+NewName = NewName.substr(0, PostfixPos);
+ 

[PATCH] D132589: [HLSL] Add acos library function

2022-08-24 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 455343.
bob80905 added a comment.

remove scalar types lld and ld from test since hlsl won't support them


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132589

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/acos.hlsl


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===
--- clang/test/CodeGenHLSL/builtins/acos.hlsl
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -17,18 +17,3 @@
 
 // CHECK: define noundef float @"?acos_f@@YAMM@Z"(
 // CHECK: call noundef float @acosf(float noundef %0)
-
-long double acos_ld(long double x)
-{
-  return acos(x);
-}
-
-// CHECK: define noundef double @"?acos_ld@@YAOO@Z"(
-// CHECK: call noundef double @acosl(double noundef %0)
-
-/*
-long long double acos_lld(long long double x)
-{
-  return acos(x);
-}
-*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -15,9 +15,6 @@
 
 __attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
 __attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
-__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long 
double In);
-//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 
acos(__float128 In);
-
 
 
 #endif //_HLSL_HLSL_INTRINSICS_H_


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===
--- clang/test/CodeGenHLSL/builtins/acos.hlsl
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -17,18 +17,3 @@
 
 // CHECK: define noundef float @"?acos_f@@YAMM@Z"(
 // CHECK: call noundef float @acosf(float noundef %0)
-
-long double acos_ld(long double x)
-{
-  return acos(x);
-}
-
-// CHECK: define noundef double @"?acos_ld@@YAOO@Z"(
-// CHECK: call noundef double @acosl(double noundef %0)
-
-/*
-long long double acos_lld(long long double x)
-{
-  return acos(x);
-}
-*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -15,9 +15,6 @@
 
 __attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
 __attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
-__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long double In);
-//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 acos(__float128 In);
-
 
 
 #endif //_HLSL_HLSL_INTRINSICS_H_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131009: [analyzer] Fixing a bug raising false positives of stack block object leaking under ARC

2022-08-24 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added a comment.

In D131009#3744416 , @NoQ wrote:

> Aha perfect, now the entire static analyzer knows how to work with these 
> regions!
>
> I have one tiny remark and I think we can commit.

Thank you!  I will make the change then directly commit.


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

https://reviews.llvm.org/D131009

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


[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 455338.

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

https://reviews.llvm.org/D132405

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/test/ClangScanDeps/deprecated-driver-api.c
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/header-search-pruning-transitive.c
  clang/test/ClangScanDeps/modules-context-hash-ignore-macros.c
  clang/test/ClangScanDeps/modules-context-hash-outputs.c
  clang/test/ClangScanDeps/modules-context-hash-warnings.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-dep-args.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/multiple-commands.c
  clang/test/ClangScanDeps/removed-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  clang/unittests/Tooling/ToolingTest.cpp
  clang/utils/module-deps-to-rsp.py

Index: clang/utils/module-deps-to-rsp.py
===
--- clang/utils/module-deps-to-rsp.py
+++ clang/utils/module-deps-to-rsp.py
@@ -48,6 +48,9 @@
   type=str)
   action.add_argument("--tu-index", help="The index of the translation unit to get arguments for",
   type=int)
+  parser.add_argument("--tu-cmd-index",
+  help="The index of the command within the translation unit (default=0)",
+  type=int, default=0)
   args = parser.parse_args()
 
   full_deps = parseFullDeps(json.load(open(args.full_deps_file, 'r')))
@@ -58,7 +61,8 @@
 if args.module_name:
   cmd = findModule(args.module_name, full_deps)['command-line']
 elif args.tu_index != None:
-  cmd = full_deps.translation_units[args.tu_index]['command-line']
+  tu = full_deps.translation_units[args.tu_index]
+  cmd = tu['commands'][args.tu_cmd_index]['command-line']
 
 print(" ".join(map(quote, cmd)))
   except:
Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -326,6 +326,46 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+TEST(ToolInvocation, CC1Args) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-fsyntax-only");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_TRUE(Invocation.run());
+}
+
+TEST(ToolInvocation, CC1ArgsInvalid) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-invalid-arg");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_FALSE(Invocation.run());
+}
+
 namespace {
 /// Overlays the real filesystem with the given VFS and returns the result.
 llvm::IntrusiveRefCntPtr
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -182,6 +182,11 @@
 llvm::cl::desc("The names of dependency targets for 

[PATCH] D132597: remove scalar types lld and ld from test since hlsl won't support them

2022-08-24 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132597

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/acos.hlsl


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===
--- clang/test/CodeGenHLSL/builtins/acos.hlsl
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -17,18 +17,3 @@
 
 // CHECK: define noundef float @"?acos_f@@YAMM@Z"(
 // CHECK: call noundef float @acosf(float noundef %0)
-
-long double acos_ld(long double x)
-{
-  return acos(x);
-}
-
-// CHECK: define noundef double @"?acos_ld@@YAOO@Z"(
-// CHECK: call noundef double @acosl(double noundef %0)
-
-/*
-long long double acos_lld(long long double x)
-{
-  return acos(x);
-}
-*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -15,9 +15,6 @@
 
 __attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
 __attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
-__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long 
double In);
-//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 
acos(__float128 In);
-
 
 
 #endif //_HLSL_HLSL_INTRINSICS_H_


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===
--- clang/test/CodeGenHLSL/builtins/acos.hlsl
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -17,18 +17,3 @@
 
 // CHECK: define noundef float @"?acos_f@@YAMM@Z"(
 // CHECK: call noundef float @acosf(float noundef %0)
-
-long double acos_ld(long double x)
-{
-  return acos(x);
-}
-
-// CHECK: define noundef double @"?acos_ld@@YAOO@Z"(
-// CHECK: call noundef double @acosl(double noundef %0)
-
-/*
-long long double acos_lld(long long double x)
-{
-  return acos(x);
-}
-*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -15,9 +15,6 @@
 
 __attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
 __attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
-__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long double In);
-//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 acos(__float128 In);
-
 
 
 #endif //_HLSL_HLSL_INTRINSICS_H_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131718: [HLSL] Add abs library function

2022-08-24 Thread Justin Bogner via Phabricator via cfe-commits
bogner accepted this revision.
bogner added a comment.
This revision is now accepted and ready to land.

LGTM. Make sure you update the description from saying that this doesn't handle 
half because of https://llvm.org/pr57100 to saying that it fixes the bug 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131718

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


[PATCH] D132503: Add cxx scope if needed for requires clause.

2022-08-24 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google added a comment.

Note that the following tests:

  Builtins-i386-linux :: muldc3_test.c
  SanitizerCommon-asan-i386-Linux :: Linux/crypt_r.cpp
  SanitizerCommon-asan-i386-Linux :: Posix/crypt.cpp
  SanitizerCommon-lsan-i386-Linux :: Linux/crypt_r.cpp
  SanitizerCommon-lsan-i386-Linux :: Posix/crypt.cpp
  SanitizerCommon-ubsan-i386-Linux :: Linux/crypt_r.cpp
  SanitizerCommon-ubsan-i386-Linux :: Posix/crypt.cpp

Are failing at HEAD and at this base diff without this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132503

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


[PATCH] D132502: [clang][modules] Consider M affecting after mapping M.Private to M_Private

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Frontend/CompilerInstance.cpp:2017
 // migrate off of Foo.Private syntax.
-if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
-Module == Module->getTopLevelModule()) {
+if (!Sub && Name == "Private" && Module == Module->getTopLevelModule()) {
   SmallString<128> PrivateModule(Module->Name);

jansvoboda11 wrote:
> jansvoboda11 wrote:
> > benlangmuir wrote:
> > > Not sure if this is a good idea, but have you considered having the 
> > > scanner provide the module with `Foo.Private=` syntax instead? It would 
> > > be nice to keep this hack contained to implicit builds if we can.
> > Interesting idea, that didn't occur to me. What implementation strategy are 
> > you thinking of?
> > 
> > If we want to avoid this hack, it seems like we'd need to pass 
> > `ModuleIdPath ImportPath` instead of `StringRef ModuleName` to 
> > `findOrCompileModuleAndReadAST()` and friends. That would allow us to look 
> > up the most specific `-fmodule-file=` argument. I'm not convinced changing 
> > multiple functions (and then changing them back when we don't need the 
> > hack) is better than extending the hack to explicit modules.
> > 
> > The upside is that we wouldn't need to report `M` as a dependency. WDYT?
> Another thing to consider: implicit build would need to propagate the 
> information that module `Foo_Private` needs to be spelled on the command-line 
> as `Foo.Private` to the scanner.
Okay, it sounds like the current patch is less invasive than the alternative. 
Thanks for talking it through.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132502

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-08-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie marked an inline comment as done.
dblaikie added a comment.

In D119051#3724121 , @rnk wrote:

> Regarding the usage of isPOD in the MSVC ABI code, we should have a routine 
> similar to `isTrivialForAArch64MSVC` that works for the other MSVC 
> architectures that we support (x86, x64, and arm32). I don't think we should 
> try to rely on definition data bits. Clang is almost always tracking 
> something slightly different than what MSVC tracks, so we should write down 
> MSVC's logic once and keep it separate from Clang's notion of POD.
>
> I think you can work out MSVC's behavior with godbolt, but if you need a 
> hand, I volunteer @hans to take a stab at refactoring 
> `MicrosoftCXXABI::classifyReturnType`. I remember making lots of comments to 
> try to simplify the code during review, but everyone is always wary of scope 
> creep.

Well, my first attempt at this - essentially using `isTrivialForAArch64MSVC` 
for everything, including x86, doesn't fail any Clang tests...

Do we still have those various fuzzers Majnemer setup? I'd guess we'd need to 
fuzz around here again to discover what the intended behavior is?

Hmm, let's compare the things that make `PlainOldData` `false`...

1. has base classes
2. any virtual member function
3. non-implicit ctor (so even user-declared-but-defaulted ctor)
4. non-implicit member function (so even user-declared-but-defaulted assignment 
operators or dtor)
5. any non-public field member
6. some ObjC thing (non-trivial ObjC lifetime)
7. any field that is of C++98 POD type... (mostly a recursive definition, when 
it comes to record types - but then there's some rules about incomplete array 
types, which couldn't be field types anyway, and some other cases)
8. non-static data member initializers

Let's compare that with `isTrivialForAArch64MSVC`...

1. checked (second)
2. checked (third) - well, it checks "is polymorphic" rather than virtual 
functions, so does that change things if you've got virtual bases but no 
virtual functions, can you have that?
3. only user-provided ctors, so it can have non-implicit (user-declared) but 
defaulted ctors
4. specifically checking non-trivial copy assignment (no restriction on move 
assignment and it could have any number of other member functions, I think?)
5. checked (first)
6. nope/not relevant?
7. Presumably tested by "hasNonTrivialDestructor" and 
"hasNonTrivialCopyAssignment"?
8. would a non-static data member initializer make the ctor user-provided? 
Presumably not, so I don't think this property is checked at all, which seems 
fair - how you pass something shouldn't be changed by how its constructed

I'll test the cases where these things differ with the godbolt-like testing 
earlier...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D131625: [HLSL] Entry functions require param annotation

2022-08-24 Thread Chris Bieneman 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 rGbdf1327fea63: [HLSL] Entry functions require param 
annotation (authored by beanz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131625

Files:
  clang/include/clang/AST/Attr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2897,7 +2897,8 @@
   { "INHERITABLE_ATTR", "InheritableAttr" },
   { "DECL_OR_TYPE_ATTR", "DeclOrTypeAttr" },
   { "INHERITABLE_PARAM_ATTR", "InheritableParamAttr" },
-  { "PARAMETER_ABI_ATTR", "ParameterABIAttr" }
+  { "PARAMETER_ABI_ATTR", "ParameterABIAttr" },
+  { "HLSL_ANNOTATION_ATTR", "HLSLAnnotationAttr"}
 };
 
 static void emitDefaultDefine(raw_ostream , StringRef name,
Index: clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -hlsl-entry main -verify %s
+
+[numthreads(1,1, 1)]
+void main(int GI) { } // expected-error{{semantic annotations must be present for all parameters of an entry function or patch constant function}} expected-note{{'GI' declared here}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11894,6 +11894,16 @@
 }
 break;
   }
+
+  for (const auto *Param : FD->parameters()) {
+if (!Param->hasAttr()) {
+  // FIXME: Handle struct parameters where annotations are on struct fields.
+  Diag(FD->getLocation(), diag::err_hlsl_missing_semantic_annotation);
+  Diag(Param->getLocation(), diag::note_previous_decl) << Param;
+  FD->setInvalidDecl();
+}
+  }
+  // FIXME: Verify return type semantic annotation.
 }
 
 bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11643,6 +11643,9 @@
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed %0">;
 def err_hlsl_missing_numthreads : Error<"missing numthreads attribute for %0 shader entry">;
 def err_hlsl_attribute_param_mismatch : Error<"%0 attribute parameters do not match the previous declaration">;
+def err_hlsl_missing_semantic_annotation : Error<
+  "semantic annotations must be present for all parameters of an entry "
+  "function or patch constant function">;
 
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -608,6 +608,9 @@
 /// A attribute is either a declaration attribute or a statement attribute.
 class DeclOrStmtAttr : InheritableAttr;
 
+/// An attribute class for HLSL Annotations.
+class HLSLAnnotationAttr : InheritableAttr;
+
 /// A target-specific attribute.  This class is meant to be used as a mixin
 /// with InheritableAttr or Attr depending on the attribute's needs.
 class TargetSpecificAttr {
@@ -4011,7 +4014,7 @@
   let Documentation = [NumThreadsDocs];
 }
 
-def HLSLSV_GroupIndex: InheritableAttr {
+def HLSLSV_GroupIndex: HLSLAnnotationAttr {
   let Spellings = [HLSLSemantic<"SV_GroupIndex">];
   let Subjects = SubjectList<[ParmVar, GlobalVar]>;
   let LangOpts = [HLSL];
Index: clang/include/clang/AST/Attr.h
===
--- clang/include/clang/AST/Attr.h
+++ clang/include/clang/AST/Attr.h
@@ -190,6 +190,22 @@
   }
 };
 
+class HLSLAnnotationAttr : public InheritableAttr {
+protected:
+  HLSLAnnotationAttr(ASTContext , const AttributeCommonInfo ,
+ attr::Kind AK, bool IsLateParsed,
+ bool InheritEvenIfAlreadyPresent)
+  : InheritableAttr(Context, CommonInfo, AK, IsLateParsed,
+InheritEvenIfAlreadyPresent) {}
+
+public:
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Attr *A) {
+return A->getKind() >= attr::FirstHLSLAnnotationAttr &&
+   A->getKind() <= attr::LastHLSLAnnotationAttr;
+  }
+};
+
 /// A parameter attribute which 

[clang] bdf1327 - [HLSL] Entry functions require param annotation

2022-08-24 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-24T14:35:11-05:00
New Revision: bdf1327fea632bf9736924acf59675182b528b23

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

LOG: [HLSL] Entry functions require param annotation

HLSL entry function parameters must have parameter annotations. This
allows appropriate intrinsic values to be populated into parameters
during code generation.

This does not handle entry function return values, which will be
handled in a subsequent commit because we don't currently support any
annotations that are valid for function returns.

Reviewed By: aaron.ballman

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

Added: 
clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl

Modified: 
clang/include/clang/AST/Attr.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 070e160d65170..4478c5fd91d4a 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -190,6 +190,22 @@ class InheritableParamAttr : public InheritableAttr {
   }
 };
 
+class HLSLAnnotationAttr : public InheritableAttr {
+protected:
+  HLSLAnnotationAttr(ASTContext , const AttributeCommonInfo 
,
+ attr::Kind AK, bool IsLateParsed,
+ bool InheritEvenIfAlreadyPresent)
+  : InheritableAttr(Context, CommonInfo, AK, IsLateParsed,
+InheritEvenIfAlreadyPresent) {}
+
+public:
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Attr *A) {
+return A->getKind() >= attr::FirstHLSLAnnotationAttr &&
+   A->getKind() <= attr::LastHLSLAnnotationAttr;
+  }
+};
+
 /// A parameter attribute which changes the argument-passing ABI rule
 /// for the parameter.
 class ParameterABIAttr : public InheritableParamAttr {

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 129055982c543..f962f84f3b7a7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -608,6 +608,9 @@ class DeclOrTypeAttr : InheritableAttr;
 /// A attribute is either a declaration attribute or a statement attribute.
 class DeclOrStmtAttr : InheritableAttr;
 
+/// An attribute class for HLSL Annotations.
+class HLSLAnnotationAttr : InheritableAttr;
+
 /// A target-specific attribute.  This class is meant to be used as a mixin
 /// with InheritableAttr or Attr depending on the attribute's needs.
 class TargetSpecificAttr {
@@ -4011,7 +4014,7 @@ def HLSLNumThreads: InheritableAttr {
   let Documentation = [NumThreadsDocs];
 }
 
-def HLSLSV_GroupIndex: InheritableAttr {
+def HLSLSV_GroupIndex: HLSLAnnotationAttr {
   let Spellings = [HLSLSemantic<"SV_GroupIndex">];
   let Subjects = SubjectList<[ParmVar, GlobalVar]>;
   let LangOpts = [HLSL];

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f544bd345a556..ae10b13c8c769 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11643,6 +11643,9 @@ def err_hlsl_numthreads_argument_oor : Error<"argument 
'%select{X|Y|Z}0' to numt
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
 def err_hlsl_missing_numthreads : Error<"missing numthreads attribute for %0 
shader entry">;
 def err_hlsl_attribute_param_mismatch : Error<"%0 attribute parameters do not 
match the previous declaration">;
+def err_hlsl_missing_semantic_annotation : Error<
+  "semantic annotations must be present for all parameters of an entry "
+  "function or patch constant function">;
 
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3ca5bf3b1254c..ef59ecebb70ac 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11894,6 +11894,16 @@ void Sema::CheckHLSLEntryPoint(FunctionDecl *FD) {
 }
 break;
   }
+
+  for (const auto *Param : FD->parameters()) {
+if (!Param->hasAttr()) {
+  // FIXME: Handle struct parameters where annotations are on struct 
fields.
+  Diag(FD->getLocation(), diag::err_hlsl_missing_semantic_annotation);
+  Diag(Param->getLocation(), diag::note_previous_decl) << Param;
+  FD->setInvalidDecl();
+}
+  }
+  // FIXME: Verify return type semantic annotation.
 }
 
 bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {

diff  --git a/clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl 

[PATCH] D119296: KCFI sanitizer

2022-08-24 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added inline comments.



Comment at: llvm/include/llvm/CodeGen/MachineInstr.h:265
+  PointerSumTypeMember,
+  PointerSumTypeMember>,
+  PointerSumTypeMember>

This fails on 32-bit architectures as `PointerEmbeddedInt` doesn't allow 
storing 32 bits in a 32-bit pointer:
```
  // Note: This '<' is correct; using '<=' would result in some shifts
  // overflowing their storage types.
  static_assert(Bits < sizeof(uintptr_t) * CHAR_BIT,
"Cannot embed more bits than we have in a pointer!")
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119296

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


[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-24 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb accepted this revision.
cjdb added a comment.
This revision is now accepted and ready to land.

Open comments notwithstanding, I'm happy with this patch. Thank you for working 
on this, it's a huge step towards getting more helpful diagnostics for C++!

@aaron.ballman, @vaibhav.y, do you folks have any further concerns? (@denik has 
some commentary incoming)




Comment at: clang/include/clang/Frontend/SARIFDiagnostic.h:24-26
+  raw_ostream *OS;
+
+  SarifDocumentWriter *Writer;

These can go in the private section below.



Comment at: clang/include/clang/Frontend/SARIFDiagnosticPrinter.h:72
+
+  bool OwnsOutputStream = true;
+};

This can't ever happen, because there's no constructor that doesn't set 
`OwnsOutputStream`.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:86-88
+if (Range.isInvalid()) {
+  continue;
+}

It seems @aaron.ballman has finally trained me :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

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


[PATCH] D132592: Clang] Implement function attribute nouwtable

2022-08-24 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added reviewers: aaron.ballman, rnk, rsmith.
Herald added a project: All.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

To have finer control of IR uwtable attribute generation. For target code 
generation,
IR nounwind and uwtable may have some interaction. However, for frontend, there 
are
no semantic interactions so the this new `nouwtable` is marked "SimpleHandler = 
1".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132592

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-nouwtable.c


Index: clang/test/CodeGen/attr-nouwtable.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-nouwtable.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -funwind-tables=2 -S -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((nouwtable))
+int test1(void) { return 0; }
+
+// CHECK: @test1{{.*}}[[ATTR1:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = {
+// CHECK-NOT: uwtable
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1942,7 +1942,7 @@
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());
 
-  if (CodeGenOpts.UnwindTables)
+  if ((!D || !D->hasAttr()) && CodeGenOpts.UnwindTables)
 B.addUWTableAttr(llvm::UWTableKind(CodeGenOpts.UnwindTables));
 
   if (CodeGenOpts.StackClashProtector)
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -4537,6 +4537,16 @@
 }];
 }
 
+def NoUwtableDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``nouwtable`` attribute which skips emitting
+the unwind table entry for the specified function. This attribute is useful for
+selectively emitting the unwind table entry on some functions when building 
with
+``-funwind-tables`` compiler option.
+}];
+}
+
 def InternalLinkageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2086,6 +2086,13 @@
   let Documentation = [NoThrowDocs];
 }
 
+def NoUwtable : InheritableAttr {
+  let Spellings = [Clang<"nouwtable">];
+  let Subjects = SubjectList<[FunctionLike]>;
+  let Documentation = [NoUwtableDocs];
+  let SimpleHandler = 1;
+}
+
 def NvWeak : IgnoredAttr {
   // No Declspec spelling of this attribute; the CUDA headers use
   // __attribute__((nv_weak)) unconditionally. Does not receive an [[]]


Index: clang/test/CodeGen/attr-nouwtable.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-nouwtable.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -funwind-tables=2 -S -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((nouwtable))
+int test1(void) { return 0; }
+
+// CHECK: @test1{{.*}}[[ATTR1:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = {
+// CHECK-NOT: uwtable
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1942,7 +1942,7 @@
llvm::Function *F) {
   llvm::AttrBuilder B(F->getContext());
 
-  if (CodeGenOpts.UnwindTables)
+  if ((!D || !D->hasAttr()) && CodeGenOpts.UnwindTables)
 B.addUWTableAttr(llvm::UWTableKind(CodeGenOpts.UnwindTables));
 
   if (CodeGenOpts.StackClashProtector)
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -4537,6 +4537,16 @@
 }];
 }
 
+def NoUwtableDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``nouwtable`` attribute which skips emitting
+the unwind table entry for the specified function. This attribute is useful for
+selectively emitting the unwind table entry on some functions when building with
+``-funwind-tables`` compiler option.
+}];
+}
+
 def InternalLinkageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2086,6 +2086,13 @@
   let Documentation = [NoThrowDocs];
 }
 
+def NoUwtable : InheritableAttr {
+  let Spellings = 

[PATCH] D118511: Add a warning for not packing non-POD members in packed structs

2022-08-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D118511#3732200 , @tstellar wrote:

> @dblaikie Can you file a bug and add the 15.0.0 Release Milestone, so we 
> don't forget to fix this in the release branch.

Yeah, sorry about the delay on this, last week was a lot on my side. Filed 
https://github.com/llvm/llvm-project/issues/57346 - happy to edit/change/have 
that changed in whatever way you were thinking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118511

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


[PATCH] D132589: [HLSL] Add acos library function This change exposes the acos library function for HLSL scalar types, excluding long long doubles. Acos is supported for all scalar, vector, and matri

2022-08-24 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
bob80905 added reviewers: beanz, pow2clk.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

...rt.

Long long double support is missing in this patch because that type
doesn't exist in HLSL.

The full documentation of the HLSL acos function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-acos


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132589

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/acos.hlsl


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s
+
+double acos_d(double x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef double @"?acos_d@@YANN@Z"(
+// CHECK: call noundef double @acos(double noundef %0) #2
+
+float acos_f(float x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef float @"?acos_f@@YAMM@Z"(
+// CHECK: call noundef float @acosf(float noundef %0)
+
+long double acos_ld(long double x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef double @"?acos_ld@@YAOO@Z"(
+// CHECK: call noundef double @acosl(double noundef %0)
+
+/*
+long long double acos_lld(long long double x)
+{
+  return acos(x);
+}
+*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -12,4 +12,12 @@
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 
+
+__attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
+__attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
+__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long 
double In);
+//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 
acos(__float128 In);
+
+
+
 #endif //_HLSL_HLSL_INTRINSICS_H_


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s
+
+double acos_d(double x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef double @"?acos_d@@YANN@Z"(
+// CHECK: call noundef double @acos(double noundef %0) #2
+
+float acos_f(float x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef float @"?acos_f@@YAMM@Z"(
+// CHECK: call noundef float @acosf(float noundef %0)
+
+long double acos_ld(long double x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef double @"?acos_ld@@YAOO@Z"(
+// CHECK: call noundef double @acosl(double noundef %0)
+
+/*
+long long double acos_lld(long long double x)
+{
+  return acos(x);
+}
+*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -12,4 +12,12 @@
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
+
+__attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
+__attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
+__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long double In);
+//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 acos(__float128 In);
+
+
+
 #endif //_HLSL_HLSL_INTRINSICS_H_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir marked 11 inline comments as done.
benlangmuir added inline comments.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h:44
+
+  enum CommandKind {
+CK_CC1,

tschuett wrote:
> Why is this not an enum class?
Removed in latest change.



Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h:80
+
+  static bool classof(const Command *C) { return C->getKind() == CK_Simple; }
+};

tschuett wrote:
> Why are all members public?
Latest change simplifies this to a struct.



Comment at: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp:155
+void FullDependencyConsumer::handleInvocation(CompilerInvocation CI) {
+  clearImplicitModuleBuildOptions(CI);
+  Commands.push_back(std::make_unique(std::move(CI)));

jansvoboda11 wrote:
> benlangmuir wrote:
> > jansvoboda11 wrote:
> > > Shouldn't this be a responsibility of the dependency scanner?
> > Good question! I was mirroring how it works for modules where we do this in 
> > the `ModuleDepCollector` and store the whole invocation in the 
> > `ModuleDeps`.  But I guess that's "inside" the dep scanner, and this is 
> > "outside".  Happy to shuffle things around.
> > 
> > What is your opinion of  `takeFullDependencies()` adding to 
> > `FrontendOpts.ModuleFiles`, ? That is also arguably the scanner's 
> > responsibility.
> > 
> > Another thing we could do here is remove `BuildInvocation` from 
> > `FullDependencies` and `ModuleDeps` and only expose the serialized `-cc1` 
> > arguments.  It would simplify the new code a bit since there'd only be one 
> > kind of "command".   On the other hand, I could also see it being 
> > potentially useful to have the whole invocation available if you were 
> > writing a C++ tool that used the scanner API rather than just 
> > clang-scan-deps itself.
> > Good question! I was mirroring how it works for modules where we do this in 
> > the `ModuleDepCollector` and store the whole invocation in the 
> > `ModuleDeps`. But I guess that's "inside" the dep scanner, and this is 
> > "outside". Happy to shuffle things around.
> As discussed offline, I'd prefer keeping `CompilerInvocation` internal to the 
> dependency scanner and exposing simple types (`std::vector` for 
> the command line) unless clients need more flexibility.
> 
> > What is your opinion of `takeFullDependencies()` adding to 
> > `FrontendOpts.ModuleFiles`, ? That is also arguably the scanner's 
> > responsibility.
> I'd prefer adding to `FrontendOpts.ModuleFiles` earlier, before the consumer.
> 
> > Another thing we could do here is remove `BuildInvocation` from 
> > `FullDependencies` and `ModuleDeps` and only expose the serialized `-cc1` 
> > arguments. It would simplify the new code a bit since there'd only be one 
> > kind of "command". On the other hand, I could also see it being potentially 
> > useful to have the whole invocation available if you were writing a C++ 
> > tool that used the scanner API rather than just clang-scan-deps itself.
> +1
Done in latest changes. The logic for mutating the compiler invocation is now 
contained in the ModuleDepCollector, alongside the existing logic for doing the 
same kind of changes to module build commands.


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

https://reviews.llvm.org/D132405

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


[PATCH] D132531: [AArch64] Reserve more physical registers

2022-08-24 Thread Guozhi Wei via Phabricator via cfe-commits
Carrot abandoned this revision.
Carrot added a comment.

Thanks for the clarification, I will propose another patch for my purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132531

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


[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 455315.
benlangmuir added a comment.

- Remove CompilerInvocation from Command and ModuleDeps. Only the arg strings 
are exposed now.
- Simplify Command, which is now just a simple struct.
- Move the logic for mutating the CompilerInvocation for the TU into the 
scanner.
- Minor refactoring to reduce nesting in DependencyScanningWorker.
- Rebase


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

https://reviews.llvm.org/D132405

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/test/ClangScanDeps/deprecated-driver-api.c
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/header-search-pruning-transitive.c
  clang/test/ClangScanDeps/modules-context-hash-ignore-macros.c
  clang/test/ClangScanDeps/modules-context-hash-outputs.c
  clang/test/ClangScanDeps/modules-context-hash-warnings.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-dep-args.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/multiple-commands.c
  clang/test/ClangScanDeps/removed-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  clang/unittests/Tooling/ToolingTest.cpp
  clang/utils/module-deps-to-rsp.py

Index: clang/utils/module-deps-to-rsp.py
===
--- clang/utils/module-deps-to-rsp.py
+++ clang/utils/module-deps-to-rsp.py
@@ -48,6 +48,9 @@
   type=str)
   action.add_argument("--tu-index", help="The index of the translation unit to get arguments for",
   type=int)
+  parser.add_argument("--tu-cmd-index",
+  help="The index of the command within the translation unit (default=0)",
+  type=int, default=0)
   args = parser.parse_args()
 
   full_deps = parseFullDeps(json.load(open(args.full_deps_file, 'r')))
@@ -58,7 +61,8 @@
 if args.module_name:
   cmd = findModule(args.module_name, full_deps)['command-line']
 elif args.tu_index != None:
-  cmd = full_deps.translation_units[args.tu_index]['command-line']
+  tu = full_deps.translation_units[args.tu_index]
+  cmd = tu['commands'][args.tu_cmd_index]['command-line']
 
 print(" ".join(map(quote, cmd)))
   except:
Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -326,6 +326,46 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+TEST(ToolInvocation, CC1Args) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-fsyntax-only");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_TRUE(Invocation.run());
+}
+
+TEST(ToolInvocation, CC1ArgsInvalid) {
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
+  std::vector Args;
+  Args.push_back("tool-executable");
+  Args.push_back("-cc1");
+  Args.push_back("-invalid-arg");
+  Args.push_back("test.cpp");
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
+  InMemoryFileSystem->addFile(
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void foo(void);\n"));
+  EXPECT_FALSE(Invocation.run());
+}
+
 namespace {
 /// Overlays the real filesystem with the given VFS and 

[PATCH] D113107: Support of expression granularity for _Float16.

2022-08-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thank you!  I think all the invariants look right here; just some minor 
comments now, and then it should be ready to commit.




Comment at: clang/lib/CodeGen/CGExprComplex.cpp:403
+  Builder.CreateStore(Val.second, ImagPtr, isVolatile);
+}
+

This looks to be dead code now, right?



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2860
+  result = Builder.CreateFPTrunc(result, ConvertType(E->getType()),
+ "unpromotion");
+  return result;

Please use your `EmitUnPromotedValue` function here (and in the similar 
functions below).


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

https://reviews.llvm.org/D113107

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-24 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3745888 , @alexfh wrote:

> The main questions we need to answer here are:
>
> 1. is the cost of storing parameter pack substitution indices while building 
> AST worth the benefits?
> 2. is there an alternative solution that would shift the cost to the moment 
> when this information is about to be used (when formatting diagnostic, I 
> suppose)?
> 3. is there a good way to make this cost optional (using a flag or somehow 
> else)?



1. For me yes, this was a fairly simple patch that got reviewed quickly and got 
the job done. But it seems it was not good for your use case :)
2. I think there is a chance the approach I mentioned earlier could work. It's 
hard for me to tell without spending some time trying. This could though end up 
being a much more complicated patch, which hits my projects bottleneck: it's 
pretty hard to find reviewers for this sort of stuff.
3. That has the advantage of change simplicity, but not user simplicity. It 
could provide a escape hatch in allowing us to have a simple solution now, but 
then iterate to something better later. But since this is an externally visible 
change to the AST, it does seem far from ideal to be changing this twice. It 
would be pretty unfortunate if someone else started using this feature and then 
we decided to take it away.

I would be fine though reverting this, and then doing some more investigation, 
and also perhaps waiting for a second opinion from @rsmith.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D132502: [clang][modules] Consider M affecting after mapping M.Private to M_Private

2022-08-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:2017
 // migrate off of Foo.Private syntax.
-if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
-Module == Module->getTopLevelModule()) {
+if (!Sub && Name == "Private" && Module == Module->getTopLevelModule()) {
   SmallString<128> PrivateModule(Module->Name);

jansvoboda11 wrote:
> benlangmuir wrote:
> > Not sure if this is a good idea, but have you considered having the scanner 
> > provide the module with `Foo.Private=` syntax instead? It would be nice to 
> > keep this hack contained to implicit builds if we can.
> Interesting idea, that didn't occur to me. What implementation strategy are 
> you thinking of?
> 
> If we want to avoid this hack, it seems like we'd need to pass `ModuleIdPath 
> ImportPath` instead of `StringRef ModuleName` to 
> `findOrCompileModuleAndReadAST()` and friends. That would allow us to look up 
> the most specific `-fmodule-file=` argument. I'm not convinced changing 
> multiple functions (and then changing them back when we don't need the hack) 
> is better than extending the hack to explicit modules.
> 
> The upside is that we wouldn't need to report `M` as a dependency. WDYT?
Another thing to consider: implicit build would need to propagate the 
information that module `Foo_Private` needs to be spelled on the command-line 
as `Foo.Private` to the scanner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132502

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


[PATCH] D132502: [clang][modules] Consider M affecting after mapping M.Private to M_Private

2022-08-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:2017
 // migrate off of Foo.Private syntax.
-if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
-Module == Module->getTopLevelModule()) {
+if (!Sub && Name == "Private" && Module == Module->getTopLevelModule()) {
   SmallString<128> PrivateModule(Module->Name);

benlangmuir wrote:
> Not sure if this is a good idea, but have you considered having the scanner 
> provide the module with `Foo.Private=` syntax instead? It would be nice to 
> keep this hack contained to implicit builds if we can.
Interesting idea, that didn't occur to me. What implementation strategy are you 
thinking of?

If we want to avoid this hack, it seems like we'd need to pass `ModuleIdPath 
ImportPath` instead of `StringRef ModuleName` to 
`findOrCompileModuleAndReadAST()` and friends. That would allow us to look up 
the most specific `-fmodule-file=` argument. I'm not convinced changing 
multiple functions (and then changing them back when we don't need the hack) is 
better than extending the hack to explicit modules.

The upside is that we wouldn't need to report `M` as a dependency. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132502

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


[PATCH] D132538: [AArch64] Filter out invalid code model in frontend.

2022-08-24 Thread Jessica Paquette via Phabricator via cfe-commits
paquette added inline comments.



Comment at: clang/test/Driver/mcmodel.c:9
 // RUN: not %clang -c -mcmodel=lager %s 2>&1 | FileCheck 
--check-prefix=INVALID %s
+// RUN: %clang -target aarch64 -### -c -mcmodel=medium %s 2>&1 | FileCheck 
--check-prefix=AARCH64-MEDIUM %s
+// RUN: %clang -target aarch64 -### -c -mcmodel=kernel %s 2>&1 | FileCheck 
--check-prefix=AARCH64-KERNEL %s

Do you need `not` in front of this? Can't remember.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132538

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


[PATCH] D132538: [AArch64] Filter out invalid code model in frontend.

2022-08-24 Thread Jessica Paquette via Phabricator via cfe-commits
paquette accepted this revision.
paquette added a comment.
This revision is now accepted and ready to land.

Looks reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132538

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


[PATCH] D132531: [AArch64] Reserve more physical registers

2022-08-24 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> A reserved physical register doesn't mean it can't be used by 
> compiler/linker, it just means it can't be used by register allocator, see 
> the comments in TargetRegisterInfo::getReservedRegs().

The target feature to "reserve" a register is meant to be "don't use this 
register for anything".  For some registers, making sure the register isn't 
used by the register allocator is sufficient because the compiler/linker won't 
use them in any other way... but if the compiler uses a register outside 
register allocation, that doesn't work.

If you want a target feature to simulate high register pressure without any 
expectation that the resulting code actually works, please add a separate 
"regalloc-test-reserve-all-regs" feature or something like that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132531

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


[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: nickdesaulniers.
aaron.ballman added a comment.

Thank you for the patch, but it'd be really helpful to me as a reviewer if you 
and @nickdesaulniers could coordinate so there's only one patch trying to 
address #57102 instead of two competing patches (I'm happy to review whichever 
patch comes out). From a quick look over the test case changes, this patch 
looks like it's more in line with how I'd expect to resolve that issue compared 
to D132266 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

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


[PATCH] D132502: [clang][modules] Consider M affecting after mapping M.Private to M_Private

2022-08-24 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:2017
 // migrate off of Foo.Private syntax.
-if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
-Module == Module->getTopLevelModule()) {
+if (!Sub && Name == "Private" && Module == Module->getTopLevelModule()) {
   SmallString<128> PrivateModule(Module->Name);

Not sure if this is a good idea, but have you considered having the scanner 
provide the module with `Foo.Private=` syntax instead? It would be nice to keep 
this hack contained to implicit builds if we can.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132502

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


[PATCH] D132430: [clang][modules] Track affecting modules

2022-08-24 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 rG002bfdd6b119: [clang][modules] Track affecting modules 
(authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D132430?vs=454979=455298#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132430

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleLoader.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-incomplete-umbrella.c

Index: clang/test/ClangScanDeps/modules-incomplete-umbrella.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-incomplete-umbrella.c
@@ -0,0 +1,202 @@
+// This test checks that modules loaded during compilation (but not imported)
+// are still reported as dependencies.
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- frameworks/FW.framework/Modules/module.modulemap
+framework module FW {
+  umbrella header "FW.h"
+  module * { export * }
+}
+//--- frameworks/FW.framework/Headers/FW.h
+//--- frameworks/FW.framework/Modules/module.private.modulemap
+framework module FW_Private {
+  umbrella header "FW_Private.h"
+  module * { export * }
+}
+//--- frameworks/FW.framework/PrivateHeaders/FW_Private.h
+#include "One.h"
+//--- frameworks/FW.framework/PrivateHeaders/One.h
+//--- frameworks/FW.framework/PrivateHeaders/Two.h
+
+// Let's check we report the non-imported modular dependencies for a translation unit.
+
+//--- from_tu.cdb.json.template
+[{
+  "file": "DIR/from_tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -iframework DIR/frameworks -c DIR/from_tu.m -o DIR/from_tu.o"
+}]
+//--- from_tu.m
+#include "FW/FW.h"
+#include "FW/Two.h"
+
+// RUN: sed -e "s|DIR|%/t|g" %t/from_tu.cdb.json.template > %t/from_tu.cdb.json
+// RUN: clang-scan-deps -compilation-database %t/from_tu.cdb.json -format experimental-full > %t/from_tu_result.json
+// RUN: cat %t/from_tu_result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefixes=CHECK_TU
+// CHECK_TU:  {
+// CHECK_TU-NEXT:   "modules": [
+// CHECK_TU-NEXT: {
+// CHECK_TU-NEXT:   "clang-module-deps": [],
+// CHECK_TU-NEXT:   "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
+// CHECK_TU-NEXT:   "command-line": [
+// CHECK_TU:],
+// CHECK_TU-NEXT:   "context-hash": "{{.*}}",
+// CHECK_TU-NEXT:   "file-deps": [
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h",
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap"
+// CHECK_TU-NEXT:   ],
+// CHECK_TU-NEXT:   "name": "FW"
+// CHECK_TU-NEXT: },
+// CHECK_TU-NEXT: {
+// CHECK_TU-NEXT:   "clang-module-deps": [],
+// CHECK_TU-NEXT:   "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
+// CHECK_TU-NEXT:   "command-line": [
+// CHECK_TU:],
+// CHECK_TU-NEXT:   "context-hash": "{{.*}}",
+// CHECK_TU-NEXT:   "file-deps": [
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap",
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/FW_Private.h",
+// CHECK_TU-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/One.h"
+// CHECK_TU-NEXT:   ],
+// CHECK_TU-NEXT:   "name": "FW_Private"
+// CHECK_TU-NEXT: }
+// CHECK_TU-NEXT:   ],
+// CHECK_TU-NEXT:   "translation-units": [
+// CHECK_TU-NEXT: {
+// CHECK_TU-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK_TU-NEXT:   "clang-module-deps": [
+// CHECK_TU-NEXT: {
+// CHECK_TU-NEXT:   "context-hash": "{{.*}}",
+// CHECK_TU-NEXT:   "module-name": "FW"
+// CHECK_TU-NEXT: },
+// CHECK_TU-NEXT: {
+// CHECK_TU-NEXT:   "context-hash": "{{.*}}",
+// CHECK_TU-NEXT:   "module-name": "FW_Private"
+// CHECK_TU-NEXT: }
+// CHECK_TU-NEXT:   ],
+// CHECK_TU-NEXT:   "command-line": [
+// CHECK_TU:  "-fmodule-file={{.*}}/FW-{{.*}}.pcm"
+// CHECK_TU:  "-fmodule-file={{.*}}/FW_Private-{{.*}}.pcm"
+// CHECK_TU:

[clang] 002bfdd - [clang][modules] Track affecting modules

2022-08-24 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-08-24T11:09:50-07:00
New Revision: 002bfdd6b119e3543415971fbb219768fd96f86f

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

LOG: [clang][modules] Track affecting modules

When compiling a module, its semantics and Clang's behavior are affected by 
other modules. These modules are typically the **imported** ones. However, 
during implicit build, some modules end up being compiled and read without 
being actually imported. This patch starts tracking such modules and 
serializing them into `.pcm` files. This enables the dependency scanner to 
construct explicit compilations that mimic implicit build.

Reviewed By: benlangmuir

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

Added: 
clang/test/ClangScanDeps/modules-incomplete-umbrella.c

Modified: 
clang/include/clang/Basic/Module.h
clang/include/clang/Lex/ModuleLoader.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 8ef1c5991c56e..a2309f5d7faeb 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -345,6 +345,10 @@ class Module {
   /// module depends.
   llvm::SmallSetVector Imports;
 
+  /// The set of top-level modules that affected the compilation of this 
module,
+  /// but were not imported.
+  llvm::SmallSetVector AffectingModules;
+
   /// Describes an exported module.
   ///
   /// The pointer is the module being re-exported, while the bit will be true

diff  --git a/clang/include/clang/Lex/ModuleLoader.h 
b/clang/include/clang/Lex/ModuleLoader.h
index bf044e0e5f506..f880a9091a2ed 100644
--- a/clang/include/clang/Lex/ModuleLoader.h
+++ b/clang/include/clang/Lex/ModuleLoader.h
@@ -51,6 +51,11 @@ class ModuleLoadResult {
   ModuleLoadResult() = default;
   ModuleLoadResult(Module *M) : Storage(M, Normal) {}
   ModuleLoadResult(LoadResultKind Kind) : Storage(nullptr, Kind) {}
+  ModuleLoadResult(Module *M, LoadResultKind Kind) : Storage(M, Kind) {}
+
+  operator bool() const {
+return Storage.getInt() == Normal && Storage.getPointer();
+  }
 
   operator Module *() const { return Storage.getPointer(); }
 

diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 6e2517632717f..5f54a44e604e2 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -860,6 +860,10 @@ class Preprocessor {
   /// The files that have been included.
   IncludedFilesSet IncludedFiles;
 
+  /// The set of top-level modules that affected preprocessing, but were not
+  /// imported.
+  llvm::SmallSetVector AffectingModules;
+
   /// The set of known macros exported from modules.
   llvm::FoldingSet ModuleMacros;
 
@@ -1331,6 +1335,12 @@ class Preprocessor {
 
   /// \}
 
+  /// Get the set of top-level modules that affected preprocessing, but were 
not
+  /// imported.
+  const llvm::SmallSetVector () const {
+return AffectingModules;
+  }
+
   /// Mark the file as included.
   /// Returns true if this is the first time the file was included.
   bool markIncluded(const FileEntry *File) {

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 297af86d0203d..8b0d2c0de1fe5 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -829,6 +829,9 @@ enum SubmoduleRecordTypes {
   /// Specifies the name of the module that will eventually
   /// re-export the entities in this module.
   SUBMODULE_EXPORT_AS = 17,
+
+  /// Specifies affecting modules that were not imported.
+  SUBMODULE_AFFECTING_MODULES = 18,
 };
 
 /// Record types used within a comments block.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 25b14f4dfa422..19a18a2ef4030 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -689,7 +689,7 @@ class ASTReader
 Module *Mod;
 
 /// The kind of module reference.
-enum { Import, Export, Conflict } Kind;
+enum { Import, Export, Conflict, Affecting } Kind;
 
 /// The local ID of the module that is being exported.
 unsigned ID;

diff  --git 

[PATCH] D131683: Diagnosing the Future Keywords

2022-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.def:384
+C2X_KEYWORD(true, BOOLSUPPORT)
+C2X_KEYWORD(remove_quals, KEYC2X)
+

Codesbyusman wrote:
> aaron.ballman wrote:
> > This is technically correct, but I think we should remove it until we go to 
> > implement that paper instead of introducing the keyword out of thin air 
> > here.
> > 
> > Btw, I think that should be `, 0` instead of `, KEYC2X` given the use of 
> > `C2X_KEYWORD`, right?
> > This is technically correct, but I think we should remove it until we go to 
> > implement that paper instead of introducing the keyword out of thin air 
> > here.
> > 
> > Btw, I think that should be `, 0` instead of `, KEYC2X` given the use of 
> > `C2X_KEYWORD`, right?
> 
> Don't know much but what I understand that this is a keyword but not 
> published officially by language but will be in future. so I think will be 
> good to remove it or can add Fixme?
> Don't know much but what I understand that this is a keyword but not 
> published officially by language but will be in future. so I think will be 
> good to remove it or can add Fixme?

Close -- the issue is more that we have no support for `remove_quals` in the 
compiler and it's easier for someone to add the keyword when implementing that 
feature. So you should remove the line entirely -- someone else will add it in 
the future.



Comment at: clang/lib/Basic/IdentifierTable.cpp:852
+
+//===--===//
+// IdentifierTable Implementation

erichkeane wrote:
> This comment block shouldn't be here at all.
It looks like you might have missed this comment.



Comment at: clang/lib/Basic/IdentifierTable.cpp:863
+
+  // Getting the flag value. i.e bool keyword passing it name to the function
+  // and will return the flag value that which keys are used then will use for

erichkeane wrote:
> This comment doesn't really make any sense here.  I dont understand what 
> you're trying to say.
It looks like you might have missed this comment (it's about `Checking the 
Language mode and then for the diagnostics.`)



Comment at: clang/test/Parser/static_assert.c:1
-// RUN: %clang_cc1 -fsyntax-only -std=c2x -DTEST_SPELLING -verify=c2x %s
-// RUN: %clang_cc1 -fsyntax-only -std=c2x -DTEST_SPELLING -fms-compatibility 
-verify=c2x-ms %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -DTEST_SPELLING -Weverything 
-verify=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -DTEST_SPELLING -fms-compatibility 
-verify=c17-ms %s

Why did you add `-Weverything` here? That seems odd.



Comment at: clang/test/Parser/static_assert.c:23
+  // c17-error {{type specifier missing, defaults to 
'int'; ISO C99 and later do not support implicit int}} \
+  // c17-warning {{ function declaration without a 
prototype is deprecated in all versions of C}} \
+  // c17-ms-warning {{use of 'static_assert' without 
inclusion of  is a Microsoft extension}} 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131683

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-08-24 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D126907#3740536 , @erichkeane 
wrote:

> For example, this enable-modules flag isn't covered by my local check-cxx, 
> which I went out of my way to run on this patch locally.

Unfortunately there are a lot of different options and combination of options 
to test libc++.
So it's indeed not possible to test all options with once check-cxx invocation.

In D126907#3746408 , @erichkeane 
wrote:

> Fixing the assert was pretty easy, and fixing it revealed the same 8 failures 
> from the buildbot above.

Great to hear you can reproduce the issue!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126907

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


[PATCH] D132531: [AArch64] Reserve more physical registers

2022-08-24 Thread Guozhi Wei via Phabricator via cfe-commits
Carrot added a comment.

I want to reserve most of the physical registers, so only a small number of 
registers can be used by register allocator. Then I can write small test cases 
to simulate high register pressure situation, it will be much easier to test 
and debug register allocation changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132531

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


[PATCH] D132352: Introduce noread_thread_id to address the thread identification problem in coroutines

2022-08-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Seems okay to me, but like I said, it'd be good to get AA eyes on it.


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

https://reviews.llvm.org/D132352

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


[PATCH] D132440: [Clang] Avoid using unwind library in the MSVC environment

2022-08-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D132440#3744960 , @mstorsjo wrote:

>> This reverts commit eca29d4a37b8d1c93fe99be6289a60bb11cf789d 
>>  since 
>> the test fails in the per-target-runtime-dir layout.
>
> Does that mean that the testcase ended up looking at other libraries next to 
> clang, in the build dir where the tests are run? That's rather annoying... I 
> guess it could be fixed by adding `-resource-dir` in the testcase? (And 
> ideally in the future, by making a harder switch between the two runtime 
> install layouts in clang, as discussed on Discourse.)

Yes, that's the issue, I added `-resource-dir` which is the solution we use in 
other tests as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132440

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


[clang] 74af56c - [Clang] Avoid using unwind library in the MSVC environment

2022-08-24 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-08-24T17:34:47Z
New Revision: 74af56c1c342038d385134add13cd2a7db7f0a70

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

LOG: [Clang] Avoid using unwind library in the MSVC environment

We're seeing the following warnings with --rtlib=compiler-rt:

  lld-link: warning: ignoring unknown argument '--as-needed'
  lld-link: warning: ignoring unknown argument '-lunwind'
  lld-link: warning: ignoring unknown argument '--no-as-needed'

MSVC doesn't use the unwind library, so just omit it.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/compiler-rt-unwind.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b48dd40760ccd..3b084dfdbfa2c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1529,7 +1529,7 @@ static void AddUnwindLibrary(const ToolChain , const 
Driver ,
   // Targets that don't use unwind libraries.
   if ((TC.getTriple().isAndroid() && UNW == ToolChain::UNW_Libgcc) ||
   TC.getTriple().isOSIAMCU() || TC.getTriple().isOSBinFormatWasm() ||
-  UNW == ToolChain::UNW_None)
+  TC.getTriple().isWindowsMSVCEnvironment() || UNW == ToolChain::UNW_None)
 return;
 
   LibGccType LGT = getLibGccType(TC, D, Args);

diff  --git a/clang/test/Driver/compiler-rt-unwind.c 
b/clang/test/Driver/compiler-rt-unwind.c
index c5f63fba065e0..af36382a9b58a 100644
--- a/clang/test/Driver/compiler-rt-unwind.c
+++ b/clang/test/Driver/compiler-rt-unwind.c
@@ -88,6 +88,13 @@
 // RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires 
--unwindlib=libgcc"
 //
 // RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-pc-windows-msvc -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck 
--check-prefix=MSVC-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// MSVC-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: 
"{{.*}}clang_rt.builtins-x86_64.lib"
+// MSVC-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT-NOT: "{{.*}}unwind.lib"
+//
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
 // RUN: -shared-libgcc \
 // RUN: --gcc-toolchain="" \



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


  1   2   >