[PATCH] D141784: [clang][Interp] Fix binary comma operators

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

  We left the result of RHS on the stack in case DiscardResult was true.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141784

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/SemaCXX/constexpr-duffs-device.cpp


Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter 
%s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,22 +212,11 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
   std::optional T = classify(BO->getType());
+
   if (!LT || !RT || !T) {
 return this->bail(BO);
   }
@@ -238,6 +227,13 @@
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))


Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter %s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,22 +212,11 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
   std::optional T = classify(BO->getType());
+
   if (!LT || !RT || !T) {
 return this->bail(BO);
   }
@@ -238,6 +227,13 @@
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141784: [clang][Interp] Fix binary comma operators

2023-01-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 489334.

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

https://reviews.llvm.org/D141784

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/SemaCXX/constexpr-duffs-device.cpp


Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter 
%s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,18 +212,6 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
@@ -238,6 +226,13 @@
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))


Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter %s
 
 // expected-no-diagnostics
 constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,18 +212,6 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
-  // Deal with operations which have composite or void types.
-  switch (BO->getOpcode()) {
-  case BO_Comma:
-if (!discard(LHS))
-  return false;
-if (!this->visit(RHS))
-  return false;
-return true;
-  default:
-break;
-  }
-
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
@@ -238,6 +226,13 @@
 return DiscardResult ? this->emitPop(*T, BO) : true;
   };
 
+  // Deal with operations which have composite or void types.
+  if (BO->isCommaOp()) {
+if (!discard(LHS))
+  return false;
+return Discard(this->visit(RHS));
+  }
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-01-15 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, gonglingqin, MaskRay, xry111.
Herald added subscribers: luismarques, s.egerton, PkmX, simoncook, hiraditya, 
arichardson.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
xen0n requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead.
Herald added projects: clang, LLVM.

Similar to D98610  for RISCV.

This is going to be required by the upcoming Linux/LoongArch
[[ support for dynamic ftrace | https://git.kernel.org/linus/4733f09d88074 ]].


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141785

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fpatchable-function-entry.c
  clang/test/Sema/patchable-function-entry-attr.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
  llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
  llvm/test/CodeGen/LoongArch/patchable-function-entry.ll

Index: llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
@@ -0,0 +1,62 @@
+;; Test the function attribute "patchable-function-entry".
+; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefixes=CHECK,LA32
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefixes=CHECK,LA64
+
+define void @f0() "patchable-function-entry"="0" {
+; CHECK-LABEL: f0:
+; CHECK-NEXT:  .Lfunc_begin0:
+; CHECK-NOT: nop
+; CHECK: ret
+; CHECK-NOT:   .section __patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="1" {
+; CHECK-LABEL: f1:
+; CHECK-NEXT: .Lfunc_begin1:
+; CHECK: nop
+; CHECK-NEXT:ret
+; CHECK:   .section __patchable_function_entries,"awo",@progbits,f1{{$}}
+; LA32:.p2align 2
+; LA32-NEXT:   .word .Lfunc_begin1
+; LA64:.p2align 3
+; LA64-NEXT:   .dword .Lfunc_begin1
+  ret void
+}
+
+$f5 = comdat any
+define void @f5() "patchable-function-entry"="5" comdat {
+; CHECK-LABEL:   f5:
+; CHECK-NEXT:.Lfunc_begin2:
+; CHECK-COUNT-5:   nop
+; CHECK-NEXT:  ret
+; CHECK: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5{{$}}
+; LA32:  .p2align 2
+; LA32-NEXT: .word .Lfunc_begin2
+; LA64:  .p2align 3
+; LA64-NEXT: .dword .Lfunc_begin2
+  ret void
+}
+
+;; -fpatchable-function-entry=3,2
+;; "patchable-function-prefix" emits data before the function entry label.
+define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
+; CHECK-LABEL:   .type f3_2,@function
+; CHECK-NEXT:.Ltmp0: # @f3_2
+; CHECK-COUNT-2:   nop
+; CHECK-NEXT:f3_2:
+; CHECK: # %bb.0:
+; CHECK-NEXT:  nop
+; LA32-NEXT:   addi.w $sp, $sp, -16
+; LA64-NEXT:   addi.d $sp, $sp, -16
+;; .size does not include the prefix.
+; CHECK:  .Lfunc_end3:
+; CHECK-NEXT: .size f3_2, .Lfunc_end3-f3_2
+; CHECK:  .section __patchable_function_entries,"awo",@progbits,f3_2{{$}}
+; LA32:   .p2align 2
+; LA32-NEXT:  .word .Ltmp0
+; LA64:   .p2align 3
+; LA64-NEXT:  .dword .Ltmp0
+  %frame = alloca i8, i32 16
+  ret void
+}
Index: llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
+++ llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
@@ -138,5 +138,22 @@
 if (lowerLoongArchMachineOperandToMCOperand(MO, MCOp, AP))
   OutMI.addOperand(MCOp);
   }
+
+  switch (OutMI.getOpcode()) {
+  case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
+const Function &F = MI->getParent()->getParent()->getFunction();
+if (F.hasFnAttribute("patchable-function-entry")) {
+  unsigned Num;
+  if (F.getFnAttribute("patchable-function-entry")
+  .getValueAsString()
+  .getAsInteger(10, Num))
+return false;
+  AP.emitNops(Num);
+  return true;
+}
+break;
+  }
+  }
+
   return false;
 }
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
@@ -27,6 +27,8 @@
 public:
   explicit LoongArchInstrInfo(LoongArchSubtarget &STI);
 
+  MCInst getNop() const override;
+
   void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg,
bool KillSrc) const override;
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@

[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-15 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry created this revision.
v1nh1shungry added reviewers: carlosgalvezp, Eugene.Zelenko.
Herald added a subscriber: xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Currently this check will complain when there're preprocessor directives
like macro definitions between the namespaces, e.g.

  namespace a { // warns, but it shouldn't
   #define FOO
  namespace b {
  } // namespace b
  } // namespace a

Fixes https://github.com/llvm/llvm-project/issues/60035 partly


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141787

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -156,6 +156,18 @@
 } // namespace n41
 // CHECK-FIXES: }
 
+namespace n43 {
+#define FOO
+namespace n44 {
+} // namespace n44
+} // namespace n43
+
+namespace n45 {
+namespace n46 {
+} // namespace n46
+#define BAR
+} // namespace n45
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -24,13 +24,37 @@
   return ND.isAnonymousNamespace() || ND.isInlineNamespace();
 }
 
-static bool singleNamedNamespaceChild(const NamespaceDecl &ND) {
+static bool hasPPDirective(SourceRange Range, const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  CharSourceRange CharRange =
+  Lexer::makeFileCharRange({Range, true}, SM, LangOpts);
+  StringRef BetweenText = Lexer::getSourceText(CharRange, SM, LangOpts);
+  std::string Buffer{BetweenText};
+  Lexer Lex(Range.getBegin(), LangOpts, Buffer.c_str(), Buffer.c_str(),
+Buffer.c_str() + Buffer.size());
+  Token Tok;
+  while (!Lex.LexFromRawLexer(Tok)) {
+if (Tok.getKind() == tok::hash)
+  return true;
+  }
+  return false;
+}
+
+static bool singleNamedNamespaceChild(const NamespaceDecl &ND,
+  const SourceManager &SM,
+  const LangOptions &LangOpts) {
   NamespaceDecl::decl_range Decls = ND.decls();
   if (std::distance(Decls.begin(), Decls.end()) != 1)
 return false;
 
   const auto *ChildNamespace = dyn_cast(*Decls.begin());
-  return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace);
+  if (!ChildNamespace || anonymousOrInlineNamespace(*ChildNamespace))
+return false;
+
+  return !hasPPDirective({ND.getBeginLoc(), ChildNamespace->getBeginLoc()}, SM,
+ LangOpts) &&
+ !hasPPDirective({ChildNamespace->getRBraceLoc(), ND.getRBraceLoc()},
+ SM, LangOpts);
 }
 
 static bool alreadyConcatenated(std::size_t NumCandidates,
@@ -76,6 +100,7 @@
 const ast_matchers::MatchFinder::MatchResult &Result) {
   const NamespaceDecl &ND = 
*Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Result.SourceManager;
+  const LangOptions &LangOpts = getLangOpts();
 
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
@@ -85,7 +110,7 @@
 
   Namespaces.push_back(&ND);
 
-  if (singleNamedNamespaceChild(ND))
+  if (singleNamedNamespaceChild(ND, Sources, LangOpts))
 return;
 
   SourceRange FrontReplacement(Namespaces.front()->getBeginLoc(),
@@ -94,7 +119,7 @@
   Namespaces.front()->getRBraceLoc());
 
   if (!alreadyConcatenated(Namespaces.size(), FrontReplacement, Sources,
-   getLangOpts()))
+   LangOpts))
 reportDiagnostic(FrontReplacement, BackReplacement);
 
   Namespaces.clear();


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -156,6 +156,18 @@
 } // namespace n41
 // CHECK-FIXES: }
 
+namespace n43 {
+#define FOO
+namespace n44 {
+} // namespace n44
+} // namespace n43
+
+namespace n45 {
+namespace n46 {
+} // namespace n46
+#define BAR
+} // namespace n45
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNames

[PATCH] D141788: [NFC] Use `llvm::enumerate` in llvm/unittests/Object

2023-01-15 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added subscribers: s.egerton, simoncook, fedor.sergeev.
Herald added a project: All.
barannikov88 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141788

Files:
  clang/docs/tools/clang-formatted-files.txt
  llvm/unittests/Object/ELFObjectFileTest.cpp

Index: llvm/unittests/Object/ELFObjectFileTest.cpp
===
--- llvm/unittests/Object/ELFObjectFileTest.cpp
+++ llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -7,8 +7,9 @@
 //===--===//
 
 #include "llvm/Object/ELFObjectFile.h"
-#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ObjectYAML/yaml2obj.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
@@ -86,38 +87,33 @@
 TEST(ELFObjectFileTest, MachineTestForNoneOrUnused) {
   std::array Formats = {"elf32-unknown", "elf32-unknown",
   "elf64-unknown", "elf64-unknown"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_NONE))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_NONE)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 
   // Test an arbitrary unused EM_* value (255).
-  I = 0;
-  for (const DataForTest &D : generateData(255))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (const auto &[Idx, Data] : enumerate(generateData(255)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 }
 
 TEST(ELFObjectFileTest, MachineTestForVE) {
   std::array Formats = {"elf32-unknown", "elf32-unknown",
   "elf64-ve", "elf64-ve"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_VE))
-checkFormatAndArch(D, Formats[I++], Triple::ve);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_VE)))
+checkFormatAndArch(Data, Formats[Idx], Triple::ve);
 }
 
 TEST(ELFObjectFileTest, MachineTestForX86_64) {
   std::array Formats = {"elf32-x86-64", "elf32-x86-64",
   "elf64-x86-64", "elf64-x86-64"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_X86_64))
-checkFormatAndArch(D, Formats[I++], Triple::x86_64);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_X86_64)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86_64);
 }
 
 TEST(ELFObjectFileTest, MachineTestFor386) {
   std::array Formats = {"elf32-i386", "elf32-i386", "elf64-i386",
   "elf64-i386"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_386))
-checkFormatAndArch(D, Formats[I++], Triple::x86);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_386)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86);
 }
 
 TEST(ELFObjectFileTest, MachineTestForMIPS) {
@@ -125,27 +121,22 @@
   "elf64-mips"};
   std::array Archs = {Triple::mipsel, Triple::mips,
Triple::mips64el, Triple::mips64};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_MIPS)) {
-checkFormatAndArch(D, Formats[I], Archs[I]);
-++I;
-  }
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_MIPS)))
+checkFormatAndArch(Data, Formats[Idx], Archs[Idx]);
 }
 
 TEST(ELFObjectFileTest, MachineTestForAMDGPU) {
   std::array Formats = {"elf32-amdgpu", "elf32-amdgpu",
   "elf64-amdgpu", "elf64-amdgpu"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_AMDGPU))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_AMDGPU)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 }
 
 TEST(ELFObjectFileTest, MachineTestForIAMCU) {
   std::array Formats = {"elf32-iamcu", "elf32-iamcu",
   "elf64-unknown", "elf64-unknown"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_IAMCU))
-checkFormatAndArch(D, Formats[I++], Triple::x86);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_IAMCU)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86);
 }
 
 TEST(ELFObjectFileTest, MachineTestForAARCH64) {
@@ -154,11 +145,8 @@
   "elf64-bigaarch64"};
   std::array Archs = {Triple::aarch64, Triple::aarch64_be,
Triple::aarch64, Triple::aarch64_be};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_AARCH64)) {
-checkFormatAndArch(D,

[PATCH] D141788: [NFC] Use `llvm::enumerate` in llvm/unittests/Object

2023-01-15 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 489341.
barannikov88 added a comment.

Rebase onto main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141788

Files:
  clang/docs/tools/clang-formatted-files.txt
  llvm/unittests/Object/ELFObjectFileTest.cpp

Index: llvm/unittests/Object/ELFObjectFileTest.cpp
===
--- llvm/unittests/Object/ELFObjectFileTest.cpp
+++ llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -7,8 +7,9 @@
 //===--===//
 
 #include "llvm/Object/ELFObjectFile.h"
-#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ObjectYAML/yaml2obj.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
@@ -86,38 +87,33 @@
 TEST(ELFObjectFileTest, MachineTestForNoneOrUnused) {
   std::array Formats = {"elf32-unknown", "elf32-unknown",
   "elf64-unknown", "elf64-unknown"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_NONE))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_NONE)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 
   // Test an arbitrary unused EM_* value (255).
-  I = 0;
-  for (const DataForTest &D : generateData(255))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (const auto &[Idx, Data] : enumerate(generateData(255)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 }
 
 TEST(ELFObjectFileTest, MachineTestForVE) {
   std::array Formats = {"elf32-unknown", "elf32-unknown",
   "elf64-ve", "elf64-ve"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_VE))
-checkFormatAndArch(D, Formats[I++], Triple::ve);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_VE)))
+checkFormatAndArch(Data, Formats[Idx], Triple::ve);
 }
 
 TEST(ELFObjectFileTest, MachineTestForX86_64) {
   std::array Formats = {"elf32-x86-64", "elf32-x86-64",
   "elf64-x86-64", "elf64-x86-64"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_X86_64))
-checkFormatAndArch(D, Formats[I++], Triple::x86_64);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_X86_64)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86_64);
 }
 
 TEST(ELFObjectFileTest, MachineTestFor386) {
   std::array Formats = {"elf32-i386", "elf32-i386", "elf64-i386",
   "elf64-i386"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_386))
-checkFormatAndArch(D, Formats[I++], Triple::x86);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_386)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86);
 }
 
 TEST(ELFObjectFileTest, MachineTestForMIPS) {
@@ -125,27 +121,22 @@
   "elf64-mips"};
   std::array Archs = {Triple::mipsel, Triple::mips,
Triple::mips64el, Triple::mips64};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_MIPS)) {
-checkFormatAndArch(D, Formats[I], Archs[I]);
-++I;
-  }
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_MIPS)))
+checkFormatAndArch(Data, Formats[Idx], Archs[Idx]);
 }
 
 TEST(ELFObjectFileTest, MachineTestForAMDGPU) {
   std::array Formats = {"elf32-amdgpu", "elf32-amdgpu",
   "elf64-amdgpu", "elf64-amdgpu"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_AMDGPU))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_AMDGPU)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 }
 
 TEST(ELFObjectFileTest, MachineTestForIAMCU) {
   std::array Formats = {"elf32-iamcu", "elf32-iamcu",
   "elf64-unknown", "elf64-unknown"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_IAMCU))
-checkFormatAndArch(D, Formats[I++], Triple::x86);
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_IAMCU)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86);
 }
 
 TEST(ELFObjectFileTest, MachineTestForAARCH64) {
@@ -154,11 +145,8 @@
   "elf64-bigaarch64"};
   std::array Archs = {Triple::aarch64, Triple::aarch64_be,
Triple::aarch64, Triple::aarch64_be};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_AARCH64)) {
-checkFormatAndArch(D, Formats[I], Archs[I]);
-++I;
-  }
+  for (const auto &[Idx, Data] : enumerate(generateData(ELF::EM_AARCH64)

[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2023-01-15 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 489342.
njames93 marked an inline comment as done.
njames93 added a comment.

Remove unneeded static keyword
Improved fix-it logic if there is a space between the template name and the `<` 
token


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -check-suffixes=',MACRO'
+// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -- \
+// RUN:   -config='{CheckOptions: {modernize-type-traits.IgnoreMacros: true}}'
+// RUN: %check_clang_tidy -std=c++17 %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
+
+
+namespace std{
+  template 
+  struct is_const {
+static constexpr bool value = true;
+  };
+
+  template 
+  struct is_same {
+static constexpr bool value = true;
+  };
+
+  template
+  struct enable_if {
+using type = T;
+  };
+} // namespace std
+
+bool NoTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: bool NoTemplate = std::is_const_v
+
+template
+constexpr bool InTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:29: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool InTemplate = std::is_const_v;
+
+template
+constexpr bool Template2Params = std::is_same::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool Template2Params = std::is_same_v;
+
+template
+typename std::enable_if::type inTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tinTemplate();
+
+typename std::enable_if::type noTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplate();
+
+std::enable_if::type noTemplateOrTypename();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplateOrTypename();
+
+using UsingNoTypename = std::enable_if::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingNoTypename = std::enable_if_t;
+
+using UsingSpace = std::enable_if ::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingSpace = std::enable_if_t ;
+
+template
+using UsingSpaceTemplate = typename std::enable_if ::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingSpaceTemplate = std::enable_if_t ;
+
+bool NoTemplateSpace = std::is_const  ::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:24: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: bool NoTemplateSpace = std::is_const_v  ;
+
+template
+constexpr bool InTemplateSpace = std::is_const   ::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool InTemplateSpace = std::is_const_v   ;
+
+// For macros, no diagnostics if IgnoreMacros is set,
+// No fixes emitted even if IgnoreMacros is unset.
+
+#define VALUE_MACRO std::is_same::value
+bool MacroValue = VALUE_MACRO;
+// CHECK-MESSAGES-CXX17MACRO: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17MACRO: #define VALUE_MACRO std::is_same::value
+
+#define TYPE_MACRO typename std::enable_if::type
+using MacroType = TYPE_MACRO;
+// CHECK-MESSAGES-MACRO: :[[@LINE-1]]:19: warning: use c++14 style type templates
+// CHECK-FIXES-MACRO: #define TYPE_MACRO typename std::enable_if::type
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
@@ -0,0 +1,40 @@
+.. title:: clang-tidy - modernize-type-traits
+
+modernize-type-traits
+=
+
+Converts standard library type traits of the form ``traits<...>::type`` and
+``traits<...>::value`` into ``traits_t<...>`` and ``traits_v<...>`` respectively.
+
+For example:
+

[PATCH] D141056: [SVE][CGBuiltins] Remove need for instcombine from ACLE tests.

2023-01-15 Thread Paul Walker via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
paulwalker-arm marked an inline comment as done.
Closed by commit rG909ac0e97dcb: [SVE][CGBuiltins] Remove need for instcombine 
from ACLE tests. (authored by paulwalker-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141056

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abs.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_addv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_and.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_andv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_asr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_asrd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfdot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmmla.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bic.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brka.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkn.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpa.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cadd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cls.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clz.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmla.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntp.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_compact.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create4-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create4.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cvt-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cvt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cvtnt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_div.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_divr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_eor.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_eorv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_expa.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ext-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ext.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_extb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_exth.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_extw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_get2-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_get2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_get3-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_get3.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_get4-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_get4.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_index.c
  clang/test/Co

[PATCH] D141789: [WIP][12/N][Clang][RISCV][NFC] Refine the way to check for Policy in riscv_vector_builtin_cg.inc

2023-01-15 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
Herald added subscribers: sunshaoce, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

The current way creates a fallacy that checking for
`PolicyAttrs == TAIL_AGNOSTIC` is implicitly equivalant to
`TAIL_AGNOSTIC_MASK_UNDISTURBED`.

This way of checking is wrong when the default policy is not TAMU.
As this patch-set is changing the default from TAMU to TAMA, we need
to perform this refactoring before chaning the default.

Depends on D141768 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141789

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/CodeGen/CGBuiltin.cpp

Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -19468,10 +19468,11 @@
 
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
   unsigned NF = 1;
-  constexpr unsigned TAIL_UNDISTURBED = 0;
-  constexpr unsigned TAIL_AGNOSTIC = 1;
-  constexpr unsigned TAIL_AGNOSTIC_MASK_AGNOSTIC = 3;
-  int PolicyAttrs = TAIL_UNDISTURBED;
+  // The 0th bit simulates the `vta` of RVV
+  // The 1st bit simultaes the `vma` of RVV
+  constexpr unsigned RVV_VTA = 0x1;
+  constexpr unsigned RVV_VMA = 0x2;
+  int PolicyAttrs = 0;
   bool IsMasked = false;
 
   // Required for overloaded intrinsics.
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -423,12 +423,13 @@
 return PolicyAttrs;
   }
   unsigned getPolicyAttrsBits() const {
-// Return following value.
-// constexpr unsigned TAIL_UNDISTURBED = 0;
-// constexpr unsigned TAIL_AGNOSTIC = 1;
-// constexpr unsigned TAIL_AGNOSTIC_MASK_AGNOSTIC = 3;
-// FIXME: how about value 2
-// int PolicyAttrs = TAIL_UNDISTURBED;
+// CGBuiltin.cpp
+// The 0th bit simulates the `vta` of RVV
+// The 1st bit simultaes the `vma` of RVV
+// constexpr unsigned RVV_VTA = 0x1;
+// constexpr unsigned RVV_VMA = 0x2;
+// int PolicyAttrs = 0;
+
 assert(PolicyAttrs.IsUnspecified == false);
 
 if (PolicyAttrs.isTUMAPolicy())
@@ -439,10 +440,6 @@
   return 0;
 if (PolicyAttrs.isTAMUPolicy())
   return 1;
-if (PolicyAttrs.isTUPolicy())
-  return 0;
-if (PolicyAttrs.isTAPolicy())
-  return 1;
 
 llvm_unreachable("unsupport policy");
 return 0;
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -467,10 +467,10 @@
 ManualCodegen = [{
   if (IsMasked) {
 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
-if (PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC)
+if ((PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA))
   Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
   } else {
-if (PolicyAttrs == TAIL_AGNOSTIC)
+if (PolicyAttrs & RVV_VTA)
   Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
   }
 
@@ -649,12 +649,12 @@
 if (IsMasked) {
   // Move mask to right before vl.
   std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
-  if (PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC)
+  if ((PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA))
 Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
   Ops.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
   IntrinsicTypes = {ResultType, Ops[4]->getType()};
 } else {
-  if (PolicyAttrs == TAIL_AGNOSTIC)
+  if (PolicyAttrs & RVV_VTA)
 Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
   IntrinsicTypes = {ResultType, Ops[3]->getType()};
 }
@@ -939,8 +939,8 @@
   SmallVector Operands;
 
   // Please refer to comment under 'defvar NFList' in this file
-  if ((IsMasked && PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC) ||
-  (!IsMasked && PolicyAttrs == TAIL_AGNOSTIC))
+  if ((IsMasked && (PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA)) ||
+  (!IsMasked && PolicyAttrs & RVV_VTA))
 Operands.append(NF, llvm::PoisonValue::get(ResultType));
   else {
 if (IsMasked)
@@ -949,8 +949,8 @@
   Operands.append(Ops.

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 489345.
TIFitis marked 7 inline comments as done.
TIFitis added a comment.

Added verifiers, removed use of magic constants and addressed other reviewer 
comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/CMakeLists.txt
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -451,6 +451,32 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %device_ptr: memref, %device_addr: memref, %map1: memref, %map2: memref) -> () {
+// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64
+%c0_i64 = arith.constant 0 : i64
+
+// CHECK: %[[VAL_1:.*]] = arith.constant 6 : i64
+%c6_i64 = arith.constant 6 : i64
+
+// CHECK: omp.target_data if(%[[VAL_2:.*]] : i1) device(%[[VAL_3:.*]] : si32) map((%[[VAL_1]] -> always , from : %[[VAL_4:.*]] : memref))
+omp.target_data if(%if_cond : i1) device(%device : si32) map((%c6_i64 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data use_device_ptr(%[[VAL_5:.*]] : memref) use_device_addr(%[[VAL_6:.*]] : memref) map((%[[VAL_1]] -> always , from : %[[VAL_4]] : memref))
+omp.target_data use_device_ptr(%device_ptr : memref) use_device_addr(%device_addr : memref) map((%c6_i64 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data map((%[[VAL_1]] -> always , from : %[[VAL_4]] : memref), (%[[VAL_0]] -> none , alloc : %[[VAL_7:.*]] : memref))
+omp.target_data map((%c6_i64 -> always , from : %map1 : memref), (%c0_i64 -> none , alloc : %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_2]] : i1) device(%[[VAL_3]] : si32) nowait map((%[[VAL_0]] -> none , alloc : %[[VAL_7]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) nowait map((%c0_i64 -> none , alloc : %map2 : memref))
+
+// CHECK: omp.target_exit_data if(%[[VAL_2]] : i1) device(%[[VAL_3]] : si32) nowait map((%[[VAL_0]] -> none , release : %[[VAL_7]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) nowait map((%c0_i64 -> none , release : %map2 : memref))
+
+return
+}
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/DialectImplementation.h"
@@ -22,7 +23,9 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include 
+#include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
 #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc"
@@ -536,6 +539,159 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+static ParseResult parseMapClause(
+OpAsmParser &parser,
+SmallVector> &map_operands,
+SmallVector> &map_operand_types) {
+  StringRef mapTypeMod, mapType;
+  OpAsmParser::UnresolvedOperand arg1, arg2;
+  Type arg2Type;
+  auto parseKeyword = [&]() -> ParseResult {
+if (parser.parseLParen() || parser.parseOperand(arg1) ||
+parser.parseArrow() || parser.parseKeyword(&mapTypeMod) ||
+parser.parseComma() || parser.parseKeyword(&mapType) ||
+parser.parseColon() || parser.parseOperand(arg2) ||
+parser.parseColon() || parser.parseType(arg2Type) ||
+parser.parseRParen())
+  return failure();
+map_operands.push_back({arg1, arg2});
+map_operand_types.push_back({parser.getBuilder().getI64Type(), arg2Type});
+return success();
+  };
+  if (parser.parseCommaSeparatedList(parseKeyword))
+return failure();
+  return success();
+}
+
+static void printMapClause(OpAsmPrinter &p, Operation *op,
+   OperandRangeRange map_operands,
+   TypeRangeRange map_operand_types) {
+
+  // Helper function to get bitwise AND of `value` and 'flag'
+  auto bitAnd = [](int64_t value,
+   llvm::om

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 4 inline comments as done.
TIFitis added inline comments.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:829
+  VariadicOfVariadic:$map_operands,
+  DenseI32ArrayAttr:$map_operand_segments);
+

kiranchandramohan wrote:
> Is `map_operand_segments` currently unused?
`map_operand_segments` is required by VariadicOfVariadic type to keep track of 
the dimensions. I haven't made explicit use of it, however, it is used 
internally and cant be avoided AFAIK. 

It is akin to the `operand_segment_sizes` which is implicitly present for 
Operations with `Optional` or `Variadic` operands.



Comment at: mlir/lib/Dialect/OpenMP/CMakeLists.txt:15
   MLIRLLVMDialect
+  MLIRArithDialect
   )

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > Why is this needed here?
> > The Arith Dialect needs to be linked against as we're using it extract the 
> > int value from arith.constant in the custom printer.
> Can this be avoided by modelling constants as attributes?
The issue with attributes is AFAIK `Variadic` is not supported, and 
as previously discussed we need it be `Variadic` to support multiple map 
clauses.

If I am wrong and there is indeed a way to have `Variadic` then this 
can be avoided.



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:577-583
+if (auto constOp =
+mlir::dyn_cast(a.front().getDefiningOp()))
+  mapTypeBits = constOp.getValue()
+.cast()
+.getValue()
+.getSExtValue();
+else if (auto constOp = mlir::dyn_cast(

kiranchandramohan wrote:
> Generally, constant values are modelled as attributes in MLIR representation. 
> Can we switch to that representation? This will also avoid the need for this 
> `if-else` and dependence on the `arith` dialect.
Copy:
The issue with attributes is AFAIK `Variadic` is not supported, and 
as previously discussed we need it be `Variadic` to support multiple map 
clauses.

If I am wrong and there is indeed a way to have `Variadic` then this 
can be avoided.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

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


[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-15 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry planned changes to this revision.
v1nh1shungry added a comment.

This patch doesn't handle situations like:

  namespace a {
  namespace b {
  #define FOO
  namespace c {
  }
  }
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141787

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


[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2023-01-15 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 489347.
njames93 added a comment.

Extend test cases to check inline namespace, extension namespaces and alias 
namespaces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
@@ -0,0 +1,119 @@
+// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -check-suffixes=',MACRO'
+// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -- \
+// RUN:   -config='{CheckOptions: {modernize-type-traits.IgnoreMacros: true}}'
+// RUN: %check_clang_tidy -std=c++17 %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
+
+namespace std {
+  template 
+  struct is_const {
+static constexpr bool value = true;
+  };
+
+  template 
+  struct is_same {
+static constexpr bool value = true;
+  };
+
+  template
+  struct enable_if {
+using type = T;
+  };
+
+inline namespace __std_lib_version1 {
+  template
+  struct add_const {
+using type = T;
+  };
+} // namespace __std_lib_version1
+
+namespace ext {
+  template
+  struct add_const {
+using type = T;
+  };
+} // namespace ext
+
+} // namespace std
+
+bool NoTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: bool NoTemplate = std::is_const_v
+
+template
+constexpr bool InTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:29: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool InTemplate = std::is_const_v;
+
+template
+constexpr bool Template2Params = std::is_same::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool Template2Params = std::is_same_v;
+
+template
+typename std::enable_if::type inTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tinTemplate();
+
+typename std::enable_if::type noTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplate();
+
+std::enable_if::type noTemplateOrTypename();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplateOrTypename();
+
+using UsingNoTypename = std::enable_if::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingNoTypename = std::enable_if_t;
+
+using UsingSpace = std::enable_if ::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingSpace = std::enable_if_t ;
+
+template
+using UsingSpaceTemplate = typename std::enable_if ::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingSpaceTemplate = std::enable_if_t ;
+
+bool NoTemplateSpace = std::is_const  ::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:24: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: bool NoTemplateSpace = std::is_const_v  ;
+
+template
+constexpr bool InTemplateSpace = std::is_const   ::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool InTemplateSpace = std::is_const_v   ;
+
+// For macros, no diagnostics if IgnoreMacros is set,
+// No fixes emitted even if IgnoreMacros is unset.
+
+#define VALUE_MACRO std::is_same::value
+bool MacroValue = VALUE_MACRO;
+// CHECK-MESSAGES-CXX17MACRO: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17MACRO: #define VALUE_MACRO std::is_same::value
+
+#define TYPE_MACRO typename std::enable_if::type
+using MacroType = TYPE_MACRO;
+// CHECK-MESSAGES-MACRO: :[[@LINE-1]]:19: warning: use c++14 style type templates
+// CHECK-FIXES-MACRO: #define TYPE_MACRO typename std::enable_if::type
+
+
+// Names defined and accessed inside an inline namespace should be converted.
+// Whether or not the inline namespace is specified
+
+using InlineUnspecified = std::add_const::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use c++14 style type templates
+// CHECK-FIXES: using InlineUnspecified = std::add_const_t;
+
+using Inline = std::__std

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2023-01-15 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe added a comment.

In D137205#4047828 , @Skylion007 
wrote:

> I am trying this in the wild and getting some false positives where it tries 
> to call std::move inside loop conditions and in the boolean condition for an 
> if statement. Stuff like:
>
>   if (SmartPtr new_ptr = steal_ptr(std::move(old_ptr))) {
> ...
>   }
>   else {
> return old_ptr; // Now it's moved from and invalid
>   }
>
> Also this can be happen for similar boolean conditionals in while, for, do 
> while loops.
>
> Interestingly, the logic in bugprone-use-after-move flags this error so maybe 
> we can reuse some of that logic to detect bad std::move.

Does this only happen on "init-statements" of while/if/switch?
And thanks for the catch, I'll take a look into it as soon I have more time.

Btw. I've oriented myself at the "bugprone-use-after-move" check, but simply 
inverting it does not work here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-15 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 489350.
v1nh1shungry added a comment.

add a test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141787

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -156,6 +156,29 @@
 } // namespace n41
 // CHECK-FIXES: }
 
+namespace n43 {
+#define FOO
+namespace n44 {
+} // namespace n44
+} // namespace n43
+
+namespace n45 {
+namespace n46 {
+} // namespace n46
+#define BAR
+} // namespace n45
+
+namespace n47 {
+namespace n48 {
+// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES: namespace n47::n48
+#define FOOBAR
+namespace n49 {
+} // namespace n49
+} // namespace n48
+} // namespace n47
+// CHECK-FIXES: }
+
 int main() {
   n26::n27::n28::n29::n30::t();
 #ifdef IEXIST
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -24,13 +24,37 @@
   return ND.isAnonymousNamespace() || ND.isInlineNamespace();
 }
 
-static bool singleNamedNamespaceChild(const NamespaceDecl &ND) {
+static bool hasPPDirective(SourceRange Range, const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  CharSourceRange CharRange =
+  Lexer::makeFileCharRange({Range, true}, SM, LangOpts);
+  StringRef BetweenText = Lexer::getSourceText(CharRange, SM, LangOpts);
+  std::string Buffer{BetweenText};
+  Lexer Lex(Range.getBegin(), LangOpts, Buffer.c_str(), Buffer.c_str(),
+Buffer.c_str() + Buffer.size());
+  Token Tok;
+  while (!Lex.LexFromRawLexer(Tok)) {
+if (Tok.getKind() == tok::hash)
+  return true;
+  }
+  return false;
+}
+
+static bool singleNamedNamespaceChild(const NamespaceDecl &ND,
+  const SourceManager &SM,
+  const LangOptions &LangOpts) {
   NamespaceDecl::decl_range Decls = ND.decls();
   if (std::distance(Decls.begin(), Decls.end()) != 1)
 return false;
 
   const auto *ChildNamespace = dyn_cast(*Decls.begin());
-  return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace);
+  if (!ChildNamespace || anonymousOrInlineNamespace(*ChildNamespace))
+return false;
+
+  return !hasPPDirective({ND.getBeginLoc(), ChildNamespace->getBeginLoc()}, SM,
+ LangOpts) &&
+ !hasPPDirective({ChildNamespace->getRBraceLoc(), ND.getRBraceLoc()},
+ SM, LangOpts);
 }
 
 static bool alreadyConcatenated(std::size_t NumCandidates,
@@ -76,6 +100,7 @@
 const ast_matchers::MatchFinder::MatchResult &Result) {
   const NamespaceDecl &ND = *Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Result.SourceManager;
+  const LangOptions &LangOpts = getLangOpts();
 
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
@@ -85,7 +110,7 @@
 
   Namespaces.push_back(&ND);
 
-  if (singleNamedNamespaceChild(ND))
+  if (singleNamedNamespaceChild(ND, Sources, LangOpts))
 return;
 
   SourceRange FrontReplacement(Namespaces.front()->getBeginLoc(),
@@ -94,7 +119,7 @@
   Namespaces.front()->getRBraceLoc());
 
   if (!alreadyConcatenated(Namespaces.size(), FrontReplacement, Sources,
-   getLangOpts()))
+   LangOpts))
 reportDiagnostic(FrontReplacement, BackReplacement);
 
   Namespaces.clear();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-15 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added a comment.

In D141787#4054514 , @v1nh1shungry 
wrote:

> This patch doesn't handle situations like:
>
>   namespace a {
>   namespace b {
>   #define FOO
>   namespace c {
>   }
>   }
>   }

It did. I must be mad :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141787

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


[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-01-15 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

Does anyone know why `patchable-function-entry` is not documented in 
https://llvm.org/docs/LangRef.html#function-attributes?




Comment at: llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp:150
+  .getAsInteger(10, Num))
+return false;
+  AP.emitNops(Num);

Seems should return `true`? Consider when verifier is disabled.

How about handling `PATCHABLE_FUNCTION_ENTER` in `LoongArchAsmPrinter.cpp` like 
D140727?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141785

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


[PATCH] D100955: [-Wcalled-once] Do not run analysis on Obj-C++

2023-01-15 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.
Herald added a project: All.

Can you say a few words on _why_ this is emitted in only Objective-C? What's 
missing for Objective-C++? I was surprised that this warning fired in a .m file 
but not in a .mm file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100955

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


[PATCH] D141792: [WIP][13/N][Clang][RISCV][NFC] Remove repeating test cases under rvv-intrinsics-autogenerated

2023-01-15 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
Herald added subscribers: VincentWu, vkmr, frasercrmck, evandro, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, 
kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

These files were oversights from D141198 

Depends on D141789 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141792

Files:
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vle.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vloxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vloxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlsseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vluxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vluxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsoxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsoxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vssseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsuxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsuxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vle.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vloxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vloxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlsseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vluxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vluxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsoxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsoxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vssseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsuxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsuxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vle.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vloxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vloxseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vlse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vlseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vlsseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vluxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vluxseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vle.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vloxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vloxseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vlse.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vlseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vlsseg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vluxei.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vluxseg.c

___
c

[PATCH] D141793: [WIP][14/15][Clang][RISCV] Change default policy from TAMU to TAMA

2023-01-15 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
Herald added subscribers: VincentWu, vkmr, frasercrmck, evandro, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, 
kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

The non-policy variants of `vid` and `viota` is no longer available for
an oveloaded version since the default policy is now TAMA and the
masked-off operand is removed.

Through this change, the intrinsics now operate under the general
assumption that the policy behaviors are both now "agnostic". Therefore
this patch also changes the semantic of policy intrinsics with the
suffix of `_ta` and `tu`. These intrinsics don't have their mask policy
specified and was assumed to be undisturbed. It is now changed to
agnostic.

Depends on D141792 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141793

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vand.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vdivu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfabs.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfclass.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfneg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrec7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredosum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredusum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsqrt7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnj.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjx.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1down.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1up.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsqrt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-

[PATCH] D100955: [-Wcalled-once] Do not run analysis on Obj-C++

2023-01-15 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D100955#4054569 , @thakis wrote:

> Can you say a few words on _why_ this is emitted in only Objective-C? What's 
> missing for Objective-C++? I was surprised that this warning fired in a .m 
> file but not in a .mm file.

Technically there is nothing that prevents us from supporting Objective-C++, 
but the warning implementation will need to handle it correctly. Currently, it 
doesn't support lambda expressions and C++ exceptions from the top of my head. 
Probably there are more language constructs that can cause incorrect warnings. 
Long story short, it needs additional logic and testing.

Cheers!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100955

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2023-01-15 Thread Aaron Gokaslan via Phabricator via cfe-commits
Skylion007 added a comment.

In D137205#4054534 , @Febbe wrote:

> In D137205#4047828 , @Skylion007 
> wrote:
>
>> I am trying this in the wild and getting some false positives where it tries 
>> to call std::move inside loop conditions and in the boolean condition for an 
>> if statement. Stuff like:
>>
>>   if (SmartPtr new_ptr = steal_ptr(std::move(old_ptr))) {
>> ...
>>   }
>>   else {
>> return old_ptr; // Now it's moved from and invalid
>>   }
>>
>> Also this can be happen for similar boolean conditionals in while, for, do 
>> while loops.
>>
>> Interestingly, the logic in bugprone-use-after-move flags this error so 
>> maybe we can reuse some of that logic to detect bad std::move.
>
> Does this only happen on "init-statements" of while/if/switch?
> And thanks for the catch, I'll take a look into it as soon I have more time.
>
> Btw. I've oriented myself at the "bugprone-use-after-move" check, but simply 
> inverting it does not work here.

It happens in any conditional statements.

Another common failure case

  while(shouldStop(std::move(a))){
  // doSomething
  // a is last usage, but shouldStop called multiple times
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-15 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added inline comments.



Comment at: mlir/lib/Dialect/OpenMP/CMakeLists.txt:15
   MLIRLLVMDialect
+  MLIRArithDialect
   )

TIFitis wrote:
> kiranchandramohan wrote:
> > TIFitis wrote:
> > > kiranchandramohan wrote:
> > > > Why is this needed here?
> > > The Arith Dialect needs to be linked against as we're using it extract 
> > > the int value from arith.constant in the custom printer.
> > Can this be avoided by modelling constants as attributes?
> The issue with attributes is AFAIK `Variadic` is not supported, 
> and as previously discussed we need it be `Variadic` to support multiple map 
> clauses.
> 
> If I am wrong and there is indeed a way to have `Variadic` then 
> this can be avoided.
Can we use an ArrayAttr 
(https://mlir.llvm.org/docs/Dialects/Builtin/#arrayattr) or something derived 
from it?
https://github.com/llvm/llvm-project/blob/6ee5a1a090f3f4b6ae7ec9915900023277daf8d7/mlir/include/mlir/IR/OpBase.td#L1467


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

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


[PATCH] D141230: [clang-format-diff.py] give clang-format-diff a job pool (10x speed)

2023-01-15 Thread Sean Maher via Phabricator via cfe-commits
seanptmaher added a comment.

I can't actually commit this -- could one of you? Or has it already been done? 
I remember reading that someone had to manually push the patch upstream.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141230

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


[PATCH] D141793: [14/15][Clang][RISCV] Change default policy from TAMU to TAMA

2023-01-15 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 489370.
eopXD edited the summary of this revision.
eopXD added a comment.

Update test cases that were leftout in the previous diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141793

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vand.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vdivu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfabs.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfclass.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfneg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrec7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredosum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredusum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsqrt7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnj.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjx.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1down.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1up.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsqrt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwredosum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerat

[PATCH] D141796: [15/15][Clang][RISCV][NFC] Set data member under Policy as constants

2023-01-15 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: craig.topper, kito-cheng, rogfer01, frasercrmck.
Herald added subscribers: VincentWu, vkmr, evandro, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, shiva0217, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

The object is now correct by construction.

This is the 15th commit of a patch-set that aims to change the default policy
for RVV intrinsics from TAMU to TAMA.

Please refer to the cover letter in the 1st commit (D141573 
) for an
overview.

Depends on D141793 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141796

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Support/RISCVVIntrinsicUtils.cpp


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1011,7 +1011,6 @@
   };
 
   if (PolicyAttrs.isUnspecified()) {
-PolicyAttrs.IsUnspecified = false;
 if (IsMasked) {
   Name += "_m";
   if (HasPolicy)
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -93,13 +93,15 @@
 };
 
 struct Policy {
-  bool IsUnspecified = false;
+  const bool IsUnspecified = false;
   enum PolicyType {
 Undisturbed,
 Agnostic,
   };
-  PolicyType TailPolicy = Agnostic;
-  PolicyType MaskPolicy = Agnostic;
+  // The default assumption for an RVV instruction is TAMA, as an undisturbed
+  // policy generally will affect the performance of an out-of-order core.
+  const PolicyType TailPolicy = Agnostic;
+  const PolicyType MaskPolicy = Agnostic;
   Policy() : IsUnspecified(true) {}
   Policy(PolicyType TailPolicy) : TailPolicy(TailPolicy) {}
   Policy(PolicyType TailPolicy, PolicyType MaskPolicy)
@@ -419,7 +421,6 @@
 return IntrinsicTypes;
   }
   Policy getPolicyAttrs() const {
-assert(PolicyAttrs.IsUnspecified == false);
 return PolicyAttrs;
   }
   unsigned getPolicyAttrsBits() const {
@@ -430,8 +431,6 @@
 // constexpr unsigned RVV_VMA = 0x2;
 // int PolicyAttrs = 0;
 
-assert(PolicyAttrs.IsUnspecified == false);
-
 if (PolicyAttrs.isTUMAPolicy())
   return 2;
 if (PolicyAttrs.isTAMAPolicy())


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1011,7 +1011,6 @@
   };
 
   if (PolicyAttrs.isUnspecified()) {
-PolicyAttrs.IsUnspecified = false;
 if (IsMasked) {
   Name += "_m";
   if (HasPolicy)
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -93,13 +93,15 @@
 };
 
 struct Policy {
-  bool IsUnspecified = false;
+  const bool IsUnspecified = false;
   enum PolicyType {
 Undisturbed,
 Agnostic,
   };
-  PolicyType TailPolicy = Agnostic;
-  PolicyType MaskPolicy = Agnostic;
+  // The default assumption for an RVV instruction is TAMA, as an undisturbed
+  // policy generally will affect the performance of an out-of-order core.
+  const PolicyType TailPolicy = Agnostic;
+  const PolicyType MaskPolicy = Agnostic;
   Policy() : IsUnspecified(true) {}
   Policy(PolicyType TailPolicy) : TailPolicy(TailPolicy) {}
   Policy(PolicyType TailPolicy, PolicyType MaskPolicy)
@@ -419,7 +421,6 @@
 return IntrinsicTypes;
   }
   Policy getPolicyAttrs() const {
-assert(PolicyAttrs.IsUnspecified == false);
 return PolicyAttrs;
   }
   unsigned getPolicyAttrsBits() const {
@@ -430,8 +431,6 @@
 // constexpr unsigned RVV_VMA = 0x2;
 // int PolicyAttrs = 0;
 
-assert(PolicyAttrs.IsUnspecified == false);
-
 if (PolicyAttrs.isTUMAPolicy())
   return 2;
 if (PolicyAttrs.isTAMAPolicy())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141798: Remove ZeroBehavior of countLeadingZeros and the like (NFC)

2023-01-15 Thread Kazu Hirata via Phabricator via cfe-commits
kazu created this revision.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, kosarev, sdasgup3, 
wenzhicui, wrengr, ormris, foad, cota, teijeong, frasercrmck, rdzhabarov, 
tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, kerbowa, liufengdb, 
aartbik, mgester, arpith-jacob, csigg, antiagainst, shauheen, rriddle, 
mehdi_amini, luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, 
arichardson, jvesely, arsenm.
Herald added a project: All.
kazu requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, 
stephenneuendorffer, nicolasvasilache, MaskRay.
Herald added projects: clang, MLIR, LLVM.

This patch removes ZeroBehavior from bit counting functions like
countLeadingZeros and findFirstSet.  ZeroBehavior specifies the
behavior when the input to count{Leading,Trailing}Zeros is zero and
when the input to count{Leading,Trailing}Ones is all ones.

ZeroBehavior was first introduced on May 24, 2013 in commit
eb91eac9fb866ab1243366d2e238b9961895612d.  While that patch did not
state the intention, I would guess ZeroBehavior was for performance
reasons.  The x86 machines around that time required a conditional
branch to implement countLeadingZero that returns the
std::numeric_limits::digits on zero:

  testedi, edi
  je  .LBB0_2
  bsr eax, edi
  xor eax, 31

.LBB1_2:

  mov eax, 32

That is, we can remove the conditional branch if we don't care about
the behavior on zero.

IIUC, Intel's Haswell architecture, launched on June 4, 2013,
introduced several bit manipulation instructions, including lzcnt and
tzcnt, which eliminated the need for the conditional branch.

I think it's time to retire ZeroBehavior as its utility is very
limited.  If you care about compilation speed, you should build LLVM
with an appropriate -march= to take advantage of lzcnt and tzcnt.
Even if not, modern host compilers should be able to optimize away
quite a few conditional branches because the input is often known to
be nonzero from dominating conditional branches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141798

Files:
  clang/lib/CodeGen/SwiftCallingConv.cpp
  llvm/include/llvm/Support/MathExtras.h
  llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Index: mlir/lib/Bytecode/Reader/BytecodeReader.cpp
===
--- mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -281,8 +281,7 @@
 // here because we only care about the first byte, and so that be actually
 // get ctz intrinsic calls when possible (the `uint8_t` overload uses a loop
 // implementation).
-uint32_t numBytes =
-llvm::countTrailingZeros(result, llvm::ZB_Undefined);
+uint32_t numBytes = llvm::countTrailingZeros(result);
 assert(numBytes > 0 && numBytes <= 7 &&
"unexpected number of trailing zeros in varint encoding");
 
Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -259,8 +259,7 @@
 if (I < B.size())
   BitsUsed |= B[I];
   if (BitsUsed != 0xff)
-return (MinByte + I) * 8 +
-   countTrailingZeros(uint8_t(~BitsUsed), ZB_Undefined);
+return (MinByte + I) * 8 + countTrailingZeros(uint8_t(~BitsUsed));
 }
   } else {
 // Find a free (Size/8) byte region in each member of Used.
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -172,7 +172,7 @@
 
   BSI.AlignLog2 = 0;
   if (Mask != 0)
-BSI.AlignLog2 = countTrailingZeros(Mask, ZB_Undefined);
+BSI.AlignLog2 = countTrailingZeros(Mask);
 
   // Build the compressed bitset while normalizing the offsets against the
   // computed alignment.
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -111,7 +111,7 @@
 
   // Val might now be valid for LUI without needing a shift.
   if (!isInt<32>(Val)) {
-ShiftAmount = findFirstSet((uint64_t)Val, ZB_Undefined);
+ShiftAmount = findFirstSet((uint64_t)Val);
 Val >>= ShiftAmount;
 
 // If the remaining bits don't fit in 12 bits, we might be able to reduce the
@@ -18

[PATCH] D138958: [clang] Better UX for Clang’s unwind-affecting attributes

2023-01-15 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D138958#4045567 , @efriedma wrote:

> From an IR semantics standpoint, I'm not sure the `memory(none)` marking is 
> right if the function throws an exception.  LangRef doesn't explicitly 
> exclude the possibility, but take the following:
>
>   void f() { throw 1; }
>
> It gets lowered to:
>
>   define dso_local void @_Z1fv() local_unnamed_addr #0 {
>   entry:
> %exception = tail call ptr @__cxa_allocate_exception(i64 4) #1
> store i32 1, ptr %exception, align 16, !tbaa !5
> tail call void @__cxa_throw(ptr nonnull %exception, ptr nonnull @_ZTIi, 
> ptr null) #2
> unreachable
>   }

If you mark this one as `readonly/none` we might, at some point, see the 
mismatch in the body and declare it UB. 
From the outside, it should almost be fine since it's not-`nounwind` and the 
memory that is accessed is freshly allocated.
However, it still would be a problem waiting to happen to have escaping memory 
being written in a `readonly/none` function.

That said, I think we anyway want a `memory` category to express all accesses 
are to freshly allocated memory that may escape the function. This is a common 
pattern.
So `memory(allocated, inaccessiblemem)` would express that the allocation does 
access some inaccesible memory and the function will also access the newly 
allocated memory.
Its arguably not as good as `readnone` but I'm not sure how to get there. 
The best idea I have off the top of my head is a dedicated `exception` category 
for `memory` such that it won't interfere with anything but other exceptions, 
which it already does due to `unwind`.
Thus, `pure/const` -> `memory(exception).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138958

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


[PATCH] D141800: [clangd] Fix qualifier not being dropped for using declaration referring to scoped enum

2023-01-15 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders created this revision.
tom-anders added reviewers: nridge, kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
tom-anders requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Relevant issue: https://github.com/clangd/clangd/issues/1361

The problem here was that writing something like `using ns::ScopedEnum`
does not cause Sema to visit this scope, to it won't be added into
`CodeCompletionBuilder`'s `AccessibleScopes`, leading to the qualifier not
being dropped.

To detect this, walk up the DeclContext to check if we have a matching
using declaration. If so, drop the qualifiers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141800

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3059,6 +3059,25 @@
   AllOf(qualifier(""), scope("na::"), named("ClangdA";
 }
 
+// https://github.com/clangd/clangd/issues/1361
+TEST(CompletionTest, ScopedEnumUsingDecl) {
+  clangd::CodeCompleteOptions Opts = {};
+  Opts.AllScopes = true;
+
+  auto Results = completions(
+  R"cpp(
+namespace ns { enum class Scoped { FooBar }; }
+using ns::Scoped;
+void f() { 
+Foo^ 
+}
+  )cpp",
+  {enmConstant("ns::Scoped::FooBar")}, Opts);
+  EXPECT_THAT(Results.Completions, UnorderedElementsAre(AllOf(
+   qualifier("Scoped::"), named("FooBar"),
+   kind(CompletionItemKind::EnumMember;
+}
+
 TEST(CompletionTest, AllScopesCompletion) {
   clangd::CodeCompleteOptions Opts = {};
   Opts.AllScopes = true;
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -305,7 +305,8 @@
 // computed from the first candidate, in the constructor.
 // Others vary per candidate, so add() must be called for remaining candidates.
 struct CodeCompletionBuilder {
-  CodeCompletionBuilder(ASTContext *ASTCtx, const CompletionCandidate &C,
+  CodeCompletionBuilder(ASTContext *ASTCtx, DeclContext *SemaDeclCtx,
+const CompletionCandidate &C,
 CodeCompletionString *SemaCCS,
 llvm::ArrayRef AccessibleScopes,
 const IncludeInserter &Includes,
@@ -360,14 +361,39 @@
   // If the completion was visible to Sema, no qualifier is needed. This
   // avoids unneeded qualifiers in cases like with `using ns::X`.
   if (Completion.RequiredQualifier.empty() && !C.SemaResult) {
-llvm::StringRef ShortestQualifier = C.IndexResult->Scope;
-for (llvm::StringRef Scope : AccessibleScopes) {
-  llvm::StringRef Qualifier = C.IndexResult->Scope;
-  if (Qualifier.consume_front(Scope) &&
-  Qualifier.size() < ShortestQualifier.size())
-ShortestQualifier = Qualifier;
+// With all-scopes-completion, we can complete enum constants of scoped
+// enums, in which case the completion might not be visible to Sema.
+// So, if there's a using declaration for the enum class, manually
+// drop the qualifiers.
+if (C.IndexResult->SymInfo.Kind == index::SymbolKind::EnumConstant &&
+SemaDeclCtx && ASTCtx) {
+  for (auto *Ctx = SemaDeclCtx; Ctx; Ctx = Ctx->getParent()) {
+auto MatchingUsingDecl = llvm::find_if(Ctx->decls(), [&C](Decl *D) {
+  if (const auto *UD = dyn_cast(D))
+if (const auto *ED = dyn_cast(UD->getTargetDecl()))
+  if (ED->isScoped() &&
+  printQualifiedName(*ED) + "::" == C.IndexResult->Scope)
+return true;
+  return false;
+});
+if (MatchingUsingDecl != Ctx->decls_end()) {
+  assert(MatchingUsingDecl->isNamed());
+  Completion.RequiredQualifier =
+  dyn_cast(*MatchingUsingDecl)->getName().str() +
+  "::";
+  break;
+}
+  }
+} else {
+  llvm::StringRef ShortestQualifier = C.IndexResult->Scope;
+  for (llvm::StringRef Scope : AccessibleScopes) {
+llvm::StringRef Qualifier = C.IndexResult->Scope;
+if (Qualifier.consume_front(Scope) &&
+Qualifier.size() < ShortestQualifier.size())
+  ShortestQualifier = Qualifier;
+  }
+  Completion.RequiredQualifier = std::string(ShortestQualifier);
 }
-Completion.RequiredQualifier = std:

[clang] 931d04b - [ADT] Make StringRef::compare like std::string_view::compare

2023-01-15 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-01-15T20:59:21+01:00
New Revision: 931d04be2fc8f3f0505b43e64297f75d526cb42a

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

LOG: [ADT] Make StringRef::compare like std::string_view::compare

string_view has a slightly weaker contract, which only specifies whether
the value is bigger or smaller than 0. Adapt users accordingly and just
forward to the standard function (that also compiles down to memcmp)

Added: 


Modified: 
clang/lib/AST/DeclarationName.cpp
clang/lib/Analysis/PathDiagnostic.cpp
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
lld/COFF/Writer.cpp
llvm/include/llvm/ADT/SmallString.h
llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/ProfileData/SampleProf.h
llvm/lib/Transforms/IPO/MergeFunctions.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/unittests/ADT/SmallStringTest.cpp
llvm/unittests/ADT/StringRefTest.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclarationName.cpp 
b/clang/lib/AST/DeclarationName.cpp
index b2232ddfced32..c1219041a466b 100644
--- a/clang/lib/AST/DeclarationName.cpp
+++ b/clang/lib/AST/DeclarationName.cpp
@@ -72,15 +72,9 @@ int DeclarationName::compare(DeclarationName LHS, 
DeclarationName RHS) {
 }
 unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
 for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
-  switch (LHSSelector.getNameForSlot(I).compare(
-  RHSSelector.getNameForSlot(I))) {
-  case -1:
-return -1;
-  case 1:
-return 1;
-  default:
-break;
-  }
+  if (int Compare = LHSSelector.getNameForSlot(I).compare(
+  RHSSelector.getNameForSlot(I)))
+return Compare;
 }
 
 return compareInt(LN, RN);

diff  --git a/clang/lib/Analysis/PathDiagnostic.cpp 
b/clang/lib/Analysis/PathDiagnostic.cpp
index 9e1215fe3d01d..ac1306fd80711 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -342,7 +342,7 @@ static bool compareCrossTUSourceLocs(FullSourceLoc XL, 
FullSourceLoc YL) {
 return XFE && !YFE;
   int NameCmp = XFE->getName().compare(YFE->getName());
   if (NameCmp != 0)
-return NameCmp == -1;
+return NameCmp < 0;
   // Last resort: Compare raw file IDs that are possibly expansions.
   return XL.getFileID() < YL.getFileID();
 }

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b38d18d3691d9..12b948a65261f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -2146,7 +2146,7 @@ void CStringChecker::evalStrcmpCommon(CheckerContext &C, 
const CallExpr *CE,
 DefinedSVal zeroVal = svalBuilder.makeIntVal(0, CE->getType());
 // Constrain strcmp's result range based on the result of StringRef's
 // comparison methods.
-BinaryOperatorKind op = (compareRes == 1) ? BO_GT : BO_LT;
+BinaryOperatorKind op = (compareRes > 0) ? BO_GT : BO_LT;
 SVal compareWithZero =
   svalBuilder.evalBinOp(state, op, resultVal, zeroVal,
   svalBuilder.getConditionType());

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 1fb4c83052c4a..1daa58f20fd5b 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -1272,8 +1272,8 @@ linkAndWrapDeviceFiles(SmallVectorImpl 
&LinkerInputFiles,
 // We sort the entries before bundling so they appear in a deterministic
 // order in the final binary.
 llvm::sort(Input, [](OffloadingImage &A, OffloadingImage &B) {
-  return A.StringData["triple"].compare(B.StringData["triple"]) == 1 ||
- A.StringData["arch"].compare(B.StringData["arch"]) == 1 ||
+  return A.StringData["triple"] > B.StringData["triple"] ||
+ A.StringData["arch"] > B.StringData["arch"] ||
  A.TheOffloadKind < B.TheOffloadKind;
 });
 auto BundledImagesOrErr = bundleLinkedOutput(Input, Args, Kind);

diff  --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 09cca5667a470..b02ad01bdef74 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -188,7 +188,7 @@ class PartialSectionKey {
 
   bool operator<(const PartialSectionKey &other) const {
 int c = name.compare(other.name);
-if (c == 1)
+if (c > 0)
   return false;
 if (c == 0)
   return characteristics < other.characteristics;

diff  --git a/llvm/include/llvm/ADT/SmallString.h 
b/llvm/include/llvm/ADT/SmallString.h
index 874968f0a1

[PATCH] D141297: [OpenCL] Allow undefining header-only features

2023-01-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D141297#4047148 , @svenvh wrote:

> In D141297#4043122 , @Anastasia 
> wrote:
>
>> Btw I wonder if in the future we could add some error or warning in case 
>> someone uses the same approach for frontend specific features, i.e.
>>
>>   #ifdef __undef___opencl_c_generic_address_space
>>   #error "Feature __opencl_c_generic_address_space can only be disabled via 
>> -cl-ext flag"
>>   #endif
>
> Interesting idea, but I'm a bit hesitant of doing so:
> It increases the size of `opencl-c-base.h` so it will take longer to parse, 
> which will affect every OpenCL compilation. Luckily we can avoid that cost if 
> we keep the `__undef_` mechanism an internal solution, which it will be once 
> we let `-cl-ext=-feature` generate `__undef_` macros for extensions that are 
> not in `OpenCLExtensions.def`. So longer term users will never have to pass 
> `__undef_` macros.

Ok that would be better indeed. Btw I hope we won't have that many feature 
macros that it would be too long to parse those. :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141297

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


[PATCH] D141700: AMDGPU: Move enqueued block handling into clang

2023-01-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:12440
+/// AMDHSAKernelDescriptor.h)
+static llvm::StructType *getKernelDescriptorType(llvm::LLVMContext &C) {
+  llvm::Type *Int8 = llvm::IntegerType::getInt8Ty(C);

Is this AMDGPU target specific? If so perhaps it's better to reflect this in 
the name.


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

https://reviews.llvm.org/D141700

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


[PATCH] D141620: clang/OpenCL: Apply default attributes to enqueued blocks

2023-01-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl:26
+// SPIR32-SAME: (ptr addrspace(1) align 4 [[A:%.*]], ptr addrspace(1) align 4 
[[B:%.*]], i32 [[I:%.*]]) #[[ATTR0:[0-9]+]] !kernel_arg_addr_space !2 
!kernel_arg_access_qual !3 !kernel_arg_type !4 !kernel_arg_base_type !4 
!kernel_arg_type_qual !5 {
+// SPIR32-NEXT:  entry:
+// SPIR32-NEXT:[[A_ADDR:%.*]] = alloca ptr addrspace(1), align 4

`ATTR0` seems to be set but never used.

Do we need to be checking the output of the whole function body?

I imagine checking the function definition and attributes should be enough for 
this patch?



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

https://reviews.llvm.org/D141620

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


[PATCH] D141800: [clangd] Fix qualifier not being dropped for using declaration referring to scoped enum

2023-01-15 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 489391.
tom-anders added a comment.

Factor out logic into helper function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141800

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3063,6 +3063,25 @@
   AllOf(qualifier(""), scope("na::"), named("ClangdA";
 }
 
+// https://github.com/clangd/clangd/issues/1361
+TEST(CompletionTest, ScopedEnumUsingDecl) {
+  clangd::CodeCompleteOptions Opts = {};
+  Opts.AllScopes = true;
+
+  auto Results = completions(
+  R"cpp(
+namespace ns { enum class Scoped { FooBar }; }
+using ns::Scoped;
+void f() { 
+Foo^ 
+}
+  )cpp",
+  {enmConstant("ns::Scoped::FooBar")}, Opts);
+  EXPECT_THAT(Results.Completions, UnorderedElementsAre(AllOf(
+   qualifier("Scoped::"), named("FooBar"),
+   kind(CompletionItemKind::EnumMember;
+}
+
 TEST(CompletionTest, AllScopesCompletion) {
   clangd::CodeCompleteOptions Opts = {};
   Opts.AllScopes = true;
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -311,7 +311,8 @@
 // computed from the first candidate, in the constructor.
 // Others vary per candidate, so add() must be called for remaining candidates.
 struct CodeCompletionBuilder {
-  CodeCompletionBuilder(ASTContext *ASTCtx, const CompletionCandidate &C,
+  CodeCompletionBuilder(ASTContext *ASTCtx, DeclContext *SemaDeclCtx,
+const CompletionCandidate &C,
 CodeCompletionString *SemaCCS,
 llvm::ArrayRef QueryScopes,
 const IncludeInserter &Includes,
@@ -374,6 +375,8 @@
 ShortestQualifier = Qualifier;
 }
 Completion.RequiredQualifier = std::string(ShortestQualifier);
+
+stripNamespaceForEnumConstantIfUsingDecl(*C.IndexResult, SemaDeclCtx);
   }
 }
 if (C.IdentifierResult) {
@@ -430,6 +433,30 @@
   });
   }
 
+  // With all-scopes-completion, we can complete enum constants of scoped
+  // enums, in which case the completion might not be visible to Sema.
+  // So, if there's a using declaration for the enum class, manually
+  // drop the qualifiers.
+  void stripNamespaceForEnumConstantIfUsingDecl(const Symbol &IndexResult,
+DeclContext *SemaDeclCtx) {
+if (IndexResult.SymInfo.Kind != index::SymbolKind::EnumConstant)
+  return;
+for (auto *Ctx = SemaDeclCtx; Ctx; Ctx = Ctx->getParent())
+  for (auto *D : Ctx->decls()) {
+const auto *UD = dyn_cast(D);
+if (!UD)
+  continue;
+const auto *ED = dyn_cast(UD->getTargetDecl());
+if (!ED || !ED->isScoped())
+  continue;
+auto EnumName = printQualifiedName(*ED) + "::";
+if (EnumName == IndexResult.Scope) {
+  Completion.RequiredQualifier = ED->getName().str() + "::";
+  return;
+}
+  }
+  }
+
   void add(const CompletionCandidate &C, CodeCompletionString *SemaCCS) {
 assert(bool(C.SemaResult) == bool(SemaCCS));
 Bundled.emplace_back();
@@ -1963,7 +1990,8 @@
   : nullptr;
   if (!Builder)
 Builder.emplace(Recorder ? &Recorder->CCSema->getASTContext() : 
nullptr,
-Item, SemaCCS, QueryScopes, *Inserter, FileName,
+Recorder ? Recorder->CCSema->CurContext : nullptr, 
Item,
+SemaCCS, QueryScopes, *Inserter, FileName,
 CCContextKind, Opts, IsUsingDeclaration, 
NextTokenKind);
   else
 Builder->add(Item, SemaCCS);


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3063,6 +3063,25 @@
   AllOf(qualifier(""), scope("na::"), named("ClangdA";
 }
 
+// https://github.com/clangd/clangd/issues/1361
+TEST(CompletionTest, ScopedEnumUsingDecl) {
+  clangd::CodeCompleteOptions Opts = {};
+  Opts.AllScopes = true;
+
+  auto Results = completions(
+  R"cpp(
+namespace ns { enum class Scoped { FooBar }; }
+using ns::Scoped;
+void f() { 
+Foo^ 
+}
+  )cpp",
+  {enmConstant("ns::Scoped::FooBar")}, Opts);
+  EXPECT_THAT(Results.C

[PATCH] D141798: Remove ZeroBehavior of countLeadingZeros and the like (NFC)

2023-01-15 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/include/llvm/Support/MathExtras.h:212
 /// Only unsigned integral types are allowed.
-///
-/// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are
-///   valid arguments.
-template  T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
-  if (ZB == ZB_Max && Val == 0)
+template  T findFirstSet(T Val) {
+  if (Val == 0)

Note, x86 does not have an efficient instruction for find first set with zero 
returning -1. It will require a cmov to handle zero.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141620: clang/OpenCL: Apply default attributes to enqueued blocks

2023-01-15 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl:26
+// SPIR32-SAME: (ptr addrspace(1) align 4 [[A:%.*]], ptr addrspace(1) align 4 
[[B:%.*]], i32 [[I:%.*]]) #[[ATTR0:[0-9]+]] !kernel_arg_addr_space !2 
!kernel_arg_access_qual !3 !kernel_arg_type !4 !kernel_arg_base_type !4 
!kernel_arg_type_qual !5 {
+// SPIR32-NEXT:  entry:
+// SPIR32-NEXT:[[A_ADDR:%.*]] = alloca ptr addrspace(1), align 4

Anastasia wrote:
> `ATTR0` seems to be set but never used.
> 
> Do we need to be checking the output of the whole function body?
> 
> I imagine checking the function definition and attributes should be enough 
> for this patch?
> 
Yes, but I don't think update_cc_test_checks has that option


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

https://reviews.llvm.org/D141620

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


[PATCH] D141700: AMDGPU: Move enqueued block handling into clang

2023-01-15 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 489394.
arsenm added a comment.

Rename


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

https://reviews.llvm.org/D141700

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel-linking.cl
  clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  llvm/docs/AMDGPUUsage.rst
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AMDGPU.h
  llvm/lib/Target/AMDGPU/AMDGPUExportKernelRuntimeHandles.cpp
  llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
  llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
  llvm/lib/Target/AMDGPU/AMDGPUOpenCLEnqueuedBlockLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/test/Bitcode/amdgpu-autoupgrade-enqueued-block.ll
  llvm/test/CodeGen/AMDGPU/amdgpu-export-kernel-runtime-handles.ll
  llvm/test/CodeGen/AMDGPU/enqueue-kernel.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full-v3.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -41,7 +41,7 @@
 ; GCN-O0-NEXT:Call Graph SCC Pass Manager
 ; GCN-O0-NEXT:  Inliner for always_inline functions
 ; GCN-O0-NEXT:A No-Op Barrier Pass
-; GCN-O0-NEXT:Lower OpenCL enqueued blocks
+; GCN-O0-NEXT:Externalize enqueued block runtime handles
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
 ; GCN-O0-NEXT:  Expand Atomic instructions
@@ -186,7 +186,7 @@
 ; GCN-O1-NEXT:Call Graph SCC Pass Manager
 ; GCN-O1-NEXT:  Inliner for always_inline functions
 ; GCN-O1-NEXT:A No-Op Barrier Pass
-; GCN-O1-NEXT:Lower OpenCL enqueued blocks
+; GCN-O1-NEXT:Externalize enqueued block runtime handles
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
@@ -454,7 +454,7 @@
 ; GCN-O1-OPTS-NEXT:Call Graph SCC Pass Manager
 ; GCN-O1-OPTS-NEXT:  Inliner for always_inline functions
 ; GCN-O1-OPTS-NEXT:A No-Op Barrier Pass
-; GCN-O1-OPTS-NEXT:Lower OpenCL enqueued blocks
+; GCN-O1-OPTS-NEXT:Externalize enqueued block runtime handles
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
@@ -754,7 +754,7 @@
 ; GCN-O2-NEXT:Call Graph SCC Pass Manager
 ; GCN-O2-NEXT:  Inliner for always_inline functions
 ; GCN-O2-NEXT:A No-Op Barrier Pass
-; GCN-O2-NEXT:Lower OpenCL enqueued blocks
+; GCN-O2-NEXT:Externalize enqueued block runtime handles
 ; GCN-O2-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O2-NEXT:FunctionPass Manager
 ; GCN-O2-NEXT:  Infer address spaces
@@ -1057,7 +1057,7 @@
 ; GCN-O3-NEXT:Call Graph SCC Pass Manager
 ; GCN-O3-NEXT:  Inliner for always_inline functions
 ; GCN-O3-NEXT:A No-Op Barrier Pass
-; GCN-O3-NEXT:Lower OpenCL enqueued blocks
+; GCN-O3-NEXT:Externalize enqueued block runtime handles
 ; GCN-O3-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O3-NEXT:FunctionPass Manager
 ; GCN-O3-NEXT:  Infer address spaces
Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
===
--- llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
@@ -14,7 +14,8 @@
 %struct.B = type { ptr addrspace(1)}
 %opencl.clk_event_t = type opaque
 
-@__test_block_invoke_kernel_runtime_handle = external addrspace(1) externally_initialized constant ptr addrspace(1)
+@__test_block_invoke_kernel_runtime_handle = external addrspace(1) externally_initialized constant ptr addrspace(1), section ".amdgpu.kernel.runtime.handle"
+@not.a.handle = external addrspace(1) externally_initialized constant ptr addrspace(1)
 
 ; CHECK: ---
 ; CHECK:  Version: [ 1, 0 ]
@@ -1808,7 +1809,7 @@
 ; CHECK-NEXT:   ValueKind: HiddenMultiGridSyncArg
 ; CHECK-NEXT:   AddrSpaceQual: Global
 define amdgpu_kernel void @__test_block_invoke_kernel(
-<{ i32, i32, ptr, ptr addrspace(1), i8 }> %arg) #1
+<{ i32, i32, ptr, ptr addrspace(1), i8 }> %arg) #1 !associated !112
 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !110
 !kernel_arg_base_type !110 !kernel_arg_type_qual !4 {
   ret void
@@ -1866,9 +1867,30 @@
   ret void
 }
 
+; Make sure the RuntimeHandle is not reported
+; CHECK: - Name:associated_global_not_handle
+; CHECK-NEXT: SymbolName:  'associated_global_not_handle@kd'
+; CHECK-NEXT: Language:OpenCL C
+; CHECK-NEXT:

[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-15 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added inline comments.
This revision now requires changes to proceed.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp:173
+namespace n48 {
+// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES: namespace n47::n48

Is `CHECK-MESSAGES-DAG` needed here, why does it fail if this is omitted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141787

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


[PATCH] D141803: [Clang] Reject in-class defaulting of previously declared comparison operators

2023-01-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added a reviewer: clang-language-wg.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Comparison operators are not allowed to be defaulted if they were previously 
declared outside the class.
Pretty low-impact, but it's nice to reject this without a linking error.
Fixes https://github.com/llvm/llvm-project/issues/51227.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141803

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p3.cpp

Index: clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
@@ -165,22 +165,22 @@
 // FIXME: This rule creates problems for reordering of declarations; is this
 // really the right model?
 struct G;
-bool operator==(const G&, const G&);
-bool operator!=(const G&, const G&);
-std::strong_ordering operator<=>(const G&, const G&);
-bool operator<(const G&, const G&);
-bool operator<=(const G&, const G&);
-bool operator>(const G&, const G&);
-bool operator>=(const G&, const G&);
+bool operator==(const G&, const G&); // expected-note {{previous declaration}}
+bool operator!=(const G&, const G&); // expected-note {{previous declaration}}
+std::strong_ordering operator<=>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<(const G&, const G&); // expected-note {{previous declaration}}
+bool operator<=(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>(const G&, const G&); // expected-note {{previous declaration}}
+bool operator>=(const G&, const G&); // expected-note {{previous declaration}}
 struct G {
-  friend bool operator==(const G&, const G&) = default;
-  friend bool operator!=(const G&, const G&) = default;
-
-  friend std::strong_ordering operator<=>(const G&, const G&) = default;
-  friend bool operator<(const G&, const G&) = default;
-  friend bool operator<=(const G&, const G&) = default;
-  friend bool operator>(const G&, const G&) = default;
-  friend bool operator>=(const G&, const G&) = default;
+  friend bool operator==(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator!=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+
+  friend std::strong_ordering operator<=>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator<=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
+  friend bool operator>=(const G&, const G&) = default; // expected-error {{because it was already declared outside}}
 };
 bool operator==(const G&, const G&);
 bool operator!=(const G&, const G&);
Index: clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
@@ -139,13 +139,13 @@
 
 struct F;
 bool operator==(const F&, const F&);
-bool operator!=(const F&, const F&);
+bool operator!=(const F&, const F&); // expected-note {{previous declaration}}
 bool operator<=>(const F&, const F&);
-bool operator<(const F&, const F&);
+bool operator<(const F&, const F&); // expected-note {{previous declaration}}
 struct F {
   union { int a; };
   friend bool operator==(const F&, const F&) = default; // expected-error {{defaulting this equality comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator!=(const F&, const F&) = default;
+  friend bool operator!=(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
   friend bool operator<=>(const F&, const F&) = default; // expected-error {{defaulting this three-way comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
-  friend bool operator<(const F&, const F&) = default;
+  friend bool operator<(const F&, const F&) = default; // expected-error {{because it was already declared outside}}
 };
Index: clang/test/CX

[PATCH] D141798: Remove ZeroBehavior of countLeadingZeros and the like (NFC)

2023-01-15 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

It would be nice to have comments reflecting the new behavior in the case of 0 
/ max value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141811: [clang-format] Allow trailing return types in macros

2023-01-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
rymiel added a project: clang-format.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The trailing return type arrow checker verifies that a declaration is
being parsed, however, this isn't true when inside of macros.

It turns out the existence of the auto keyword is enough to make
sure that we're dealing with a trailing return type, and whether we're
in a declaration doesn't matter.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141811

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7986,6 +7986,10 @@
"auto aa(T t)\n"
"-> decltype(eaaa(t.a).());");
 
+  verifyFormat("#define MAKE_DEF(NAME) 
"
+   "\\\n"
+   "  auto NAME() -> int { return 42; }");
+
   // Not trailing return types.
   verifyFormat("void f() { auto a = b->c(); }");
   verifyFormat("auto a = p->foo();");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1880,7 +1880,8 @@
 } else if (Current.is(tok::arrow) &&
Style.Language == FormatStyle::LK_Java) {
   Current.setType(TT_LambdaArrow);
-} else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&
+} else if (Current.is(tok::arrow) && AutoFound &&
+   (Line.MustBeDeclaration || Line.InPPDirective) &&
Current.NestingLevel == 0 &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
   // not auto operator->() -> xxx;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7986,6 +7986,10 @@
"auto aa(T t)\n"
"-> decltype(eaaa(t.a).());");
 
+  verifyFormat("#define MAKE_DEF(NAME) "
+   "\\\n"
+   "  auto NAME() -> int { return 42; }");
+
   // Not trailing return types.
   verifyFormat("void f() { auto a = b->c(); }");
   verifyFormat("auto a = p->foo();");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1880,7 +1880,8 @@
 } else if (Current.is(tok::arrow) &&
Style.Language == FormatStyle::LK_Java) {
   Current.setType(TT_LambdaArrow);
-} else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&
+} else if (Current.is(tok::arrow) && AutoFound &&
+   (Line.MustBeDeclaration || Line.InPPDirective) &&
Current.NestingLevel == 0 &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
   // not auto operator->() -> xxx;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138958: [clang] Better UX for Clang’s unwind-affecting attributes

2023-01-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added subscribers: nlopes, regehr.
lebedev.ri added a comment.

In D138958#4054903 , @jdoerfert wrote:

> In D138958#4045567 , @efriedma 
> wrote:
>
>> From an IR semantics standpoint, I'm not sure the `memory(none)` marking is 
>> right if the function throws an exception.  LangRef doesn't explicitly 
>> exclude the possibility, but take the following:
>>
>>   void f() { throw 1; }
>>
>> It gets lowered to:
>>
>>   define dso_local void @_Z1fv() local_unnamed_addr #0 {
>>   entry:
>> %exception = tail call ptr @__cxa_allocate_exception(i64 4) #1
>> store i32 1, ptr %exception, align 16, !tbaa !5
>> tail call void @__cxa_throw(ptr nonnull %exception, ptr nonnull @_ZTIi, 
>> ptr null) #2
>> unreachable
>>   }
>
> If you mark this one as `readonly/none` we might, at some point, see the 
> mismatch in the body and declare it UB. 
> From the outside, it should almost be fine since it's not-`nounwind` and the 
> memory that is accessed is freshly allocated.
> However, it still would be a problem waiting to happen to have escaping 
> memory being written in a `readonly/none` function.
>
> That said, I think we anyway want a `memory` category to express all accesses 
> are to freshly allocated memory that may escape the function. This is a 
> common pattern.
> So `memory(allocated, inaccessiblemem)` would express that the allocation 
> does access some inaccesible memory and the function will also access the 
> newly allocated memory.
> Its arguably not as good as `readnone` but I'm not sure how to get there. 
> The best idea I have off the top of my head is a dedicated `exception` 
> category for `memory` such that it won't interfere with anything but other 
> exceptions, which it already does due to `unwind`.
> Thus, `pure/const` -> `memory(exception).

Thank you for commenting! Is there a feeling that just dropping the attributes,
until they can be reasonably represented, hinders optimizations too much,
and we must retain the ongoing miscompile?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138958

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


[PATCH] D141573: [1/15][Clang][RISCV][NFC] Extract common utility to RISCVVIntrinsicUtils

2023-01-15 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng 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/D141573/new/

https://reviews.llvm.org/D141573

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


[PATCH] D133574: [C2x] reject type definitions in offsetof

2023-01-15 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

our nekbone app is failing from this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133574

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


[PATCH] D141788: [NFC] Use `llvm::enumerate` in llvm/unittests/Object

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

non-reference `auto` shall work better in these cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141788

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


[PATCH] D141572: [C++] [Coroutines] Deprecates the '-fcoroutines-ts' flag

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 489412.
ChuanqiXu added a comment.

Update the header tests.


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

https://reviews.llvm.org/D141572

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/coroutines.cpp
  libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
  libcxx/test/libcxx/clang_tidy.sh.cpp
  libcxx/test/libcxx/double_include.sh.cpp
  libcxx/test/libcxx/min_max_macros.compile.pass.cpp
  libcxx/test/libcxx/modules_include.sh.cpp
  libcxx/test/libcxx/nasty_macros.compile.pass.cpp
  libcxx/test/libcxx/no_assert_include.compile.pass.cpp
  libcxx/utils/generate_header_tests.py

Index: libcxx/utils/generate_header_tests.py
===
--- libcxx/utils/generate_header_tests.py
+++ libcxx/utils/generate_header_tests.py
@@ -19,6 +19,8 @@
 
 "filesystem": "!defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)",
 
+"coroutine": "(defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)",
+
 "clocale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
 "codecvt": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
 "fstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION) && !defined(_LIBCPP_HAS_NO_FSTREAM)",
Index: libcxx/test/libcxx/no_assert_include.compile.pass.cpp
===
--- libcxx/test/libcxx/no_assert_include.compile.pass.cpp
+++ libcxx/test/libcxx/no_assert_include.compile.pass.cpp
@@ -66,7 +66,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/nasty_macros.compile.pass.cpp
===
--- libcxx/test/libcxx/nasty_macros.compile.pass.cpp
+++ libcxx/test/libcxx/nasty_macros.compile.pass.cpp
@@ -193,7 +193,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/modules_include.sh.cpp
===
--- libcxx/test/libcxx/modules_include.sh.cpp
+++ libcxx/test/libcxx/modules_include.sh.cpp
@@ -154,7 +154,7 @@
 #include 
 #endif
 // RUN: %{cxx} %s %{flags} %{compile_flags} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only -DTEST_26
-#if defined(TEST_26)
+#if defined(TEST_26) && (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
 #include 
 #endif
 // RUN: %{cxx} %s %{flags} %{compile_flags} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only -DTEST_27
Index: libcxx/test/libcxx/min_max_macros.compile.pass.cpp
===
--- libcxx/test/libcxx/min_max_macros.compile.pass.cpp
+++ libcxx/test/libcxx/min_max_macros.compile.pass.cpp
@@ -95,8 +95,10 @@
 TEST_MACROS();
 #include 
 TEST_MACROS();
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
 TEST_MACROS();
+#endif
 #include 
 TEST_MACROS();
 #include 
Index: libcxx/test/libcxx/double_include.sh.cpp
===
--- libcxx/test/libcxx/double_include.sh.cpp
+++ libcxx/test/libcxx/double_include.sh.cpp
@@ -69,7 +69,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/clang_tidy.sh.cpp
===
--- libcxx/test/libcxx/clang_tidy.sh.cpp
+++ libcxx/test/libcxx/clang_tidy.sh.cpp
@@ -68,7 +68,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
===
--- libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
+++ libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
@@ -199,7 +199,7 @@
 #endif
 
 // RUN: %{build} -DTEST_26
-#if defined(TEST_26)
+#if defined(TEST_26) && (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 2017

[PATCH] D141572: [C++] [Coroutines] Deprecates the '-fcoroutines-ts' flag

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D141572#4050758 , @philnik wrote:

> In D141572#4050492 , @ChuanqiXu 
> wrote:
>
>> @philnik when I run `ninja libcxx-generate-files` locally, it says `ninja: 
>> error: unknown target 'libcxx-generate-files'`. The following off is my 
>> configuring command:
>>
>>   cmake -G Ninja -S llvm -B build_libcxx_modules 
>> -DLLVM_ENABLE_PROJECTS="clang"  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" 
>> -DCMAKE_BUILD_TYPE=Release
>>
>> Do you know if anything goes wrong?
>
> It's probably because you're using the bootstrapping build. Since this 
> invokes another CMake command internally to build libc++, the targets aren't 
> available. It should work with `cmake -G Ninja -S runtimes -B <...> 
> -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"`.

Got it. It fixed my problem.


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

https://reviews.llvm.org/D141572

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D137058#4050188 , @dblaikie wrote:

> I really don't think this is the right thing to do - the Split DWARF code, 
> for instance, has support for GPU bundling that's missing in the module file 
> naming code, which seems likely to be broken & within reason handle-able 
> today by reusing the Split DWARF code, similarly with the multi-arch bundling 
> for MachO. But I've tried to explain these things in several ways, and 
> haven't managed to connect.
>
> Carry on.

Thanks for your patient reviewing! We can merge the logics with Split DWARF 
code someday when we find it necessary.


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

https://reviews.llvm.org/D137058

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

Oh, I forgot to submit the inline comments. My bad.


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

https://reviews.llvm.org/D137534

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a subscriber: h-vetinari.
ChuanqiXu added a comment.

@jansvoboda11 gentle ping~ (although I feel it may be hard to land this before 
the branching since I'll take a vacation in 19th until February, @h-vetinari 
said it should be OK to backport these patches to branched 16.x.)


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

https://reviews.llvm.org/D137534

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-15 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

In D137534#4055283 , @ChuanqiXu wrote:

> @h-vetinari said it should be OK to backport these patches to branched 16.x.

That should be considered a comment from the peanut gallery, not a definite 
statement. What I had said in https://reviews.llvm.org/D137058 was:

>> [...] but I am not sure if we can land them in time. I guess it may be 
>> possible to backport these patches to 16.x since it is relatively important?
>
> Might make sense tagging the release managers if things get tight - perhaps 
> it's possible. E.g. ranges for LLVM 15 was also finished after the branch.




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

https://reviews.llvm.org/D137534

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


[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-15 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp:173
+namespace n48 {
+// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES: namespace n47::n48

njames93 wrote:
> Is `CHECK-MESSAGES-DAG` needed here, why does it fail if this is omitted?
Hmm, doesn't `CHECK-MESSAGES-DAG` means to check whether there is a message? (I 
referred to the tests above.)

If it's other cases, maybe it's due to 
https://github.com/llvm/llvm-project/issues/60051.

I'm not sure I understand what you mean, sorry!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141787

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

In D137534#4055286 , @h-vetinari 
wrote:

> In D137534#4055283 , @ChuanqiXu 
> wrote:
>
>> @h-vetinari said it should be OK to backport these patches to branched 16.x.
>
> That should be considered a comment from the peanut gallery, not a definite 
> statement. What I had said in https://reviews.llvm.org/D137058 was:
>
>>> [...] but I am not sure if we can land them in time. I guess it may be 
>>> possible to backport these patches to 16.x since it is relatively important?
>>
>> Might make sense tagging the release managers if things get tight - perhaps 
>> it's possible. E.g. ranges for LLVM 15 was also finished after the branch.

Sorry for the misleading and thanks for the quick clarification. So it looks 
like the status quo is a little bit worse than I imaged...


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

https://reviews.llvm.org/D137534

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2023-01-15 Thread Chuanqi Xu 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 rGf89327e28bc1: [Driver] [Modules] Support -fmodule-output 
(1/2) (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137058

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/lit.local.cfg
  clang/test/Driver/module-output.cppm

Index: clang/test/Driver/module-output.cppm
===
--- /dev/null
+++ clang/test/Driver/module-output.cppm
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// Tests that the .pcm file will be generated in the same directory with the specified
+// output and the name of the .pcm file should be the same with the input file.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output -c -o %t/output/Hello.o \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm
+//
+// Tests that the output file will be generated in the input directory if the output
+// file is not the corresponding object file.
+// RUN: %clang -std=c++20 %t/Hello.cppm %t/AnotherModule.cppm -fmodule-output -o \
+// RUN:   %t/output/a.out -### 2>&1 | FileCheck  %t/AnotherModule.cppm
+//
+// Tests that clang will reject the command line if it specifies -fmodule-output with
+// multiple archs.
+// RUN: %clang %t/Hello.cppm -fmodule-output -arch i386 -arch x86_64 -### -target \
+// RUN:   x86_64-apple-darwin 2>&1 | FileCheck %t/Hello.cppm -check-prefix=MULTIPLE-ARCH
+
+//--- Hello.cppm
+export module Hello;
+
+// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.o" "-x" "pcm" "{{.*}}/output/Hello.pcm"
+
+// MULTIPLE-ARCH: option '-fmodule-output' can't be used with multiple arch options
+
+//--- AnotherModule.cppm
+export module AnotherModule;
+// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello-{{.*}}.o" "-x" "pcm" "{{.*}}/Hello.pcm"
+// CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" "{{.*}}/AnotherModule.pcm" "-x" "c++" "{{.*}}/AnotherModule.cppm"
+// CHECK: "-emit-obj" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" "{{.*}}/AnotherModule-{{.*}}.o" "-x" "pcm" "{{.*}}/AnotherModule.pcm"
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -1,6 +1,6 @@
 from lit.llvm import llvm_config
 
-config.suffixes = ['.c', '.cpp', '.h', '.m', '.mm', '.S', '.s', '.f90', '.F90', '.f95',
+config.suffixes = ['.c', '.cpp', '.cppm', '.h', '.m', '.mm', '.S', '.s', '.f90', '.F90', '.f95',
'.cu', '.rs', '.cl', '.clcpp', '.hip', '.hipi', '.hlsl']
 config.substitutions = list(config.substitutions)
 config.substitutions.insert(0,
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5553,6 +5553,30 @@
   return C.addTempFile(C.getArgs().MakeArgString(TmpName));
 }
 
+// Calculate the output path of the module file when compiling a module unit
+// with the `-fmodule-output` option specified. The behavior is:
+// - If the output object file of the module unit is specified, the output path
+//   of the module file should be the same with the output object file except
+//   the corresponding suffix. This requires both `-o` and `-c` are specified.
+// - Otherwise, the output path of the module file will be the same with the
+//   input with the corresponding suffix.
+static const char *GetModuleOutputPath(Compilation &C, const JobAction &JA,
+   const char *BaseInput) {
+  assert(isa(JA) && JA.getType() == types::TY_ModuleFile &&
+ C.getArgs().hasArg(options::OPT_fmodule_output));
+
+  SmallString<64> OutputPath;
+  Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
+  if (FinalOutput && C.getArgs().hasArg(options::OPT_c))
+OutputPath = FinalOutput->getValue();
+  else
+OutputPath = BaseInput;
+
+  const char *Extension = types::getTypeTempSuffix(JA.getType());
+  llvm::sys::path::replace_extension(OutputPath, Extension);
+  return C.addResultFile(C.getArgs().MakeArgString(OutputPath.c_str()), &JA);
+}
+
 const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput,
StringRef OrigBoundArch, bool

[clang] f89327e - [Driver] [Modules] Support -fmodule-output (1/2)

2023-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-16T11:05:33+08:00
New Revision: f89327e28bc17a1d80fd5523520e62d8dd53c1cb

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

LOG: [Driver] [Modules] Support -fmodule-output (1/2)

Patches to support the one-phase compilation model for modules.

The behavior:
(1) If -o and -c is specified , the module file is in the same path
within the same directory as the output the -o specified and with a new
suffix .pcm.
(2) Otherwise, the module file is in the same path within the working
directory directory with the name of the input file with a new suffix
.pcm

For example,

```
Hello.cppm Use.cpp
```

A trivial one and the contents are ignored. When we run:

```
clang++ -std=c++20 -fmodule-output Hello.cppm -c
```

The directory would look like:

```
Hello.cppm  Hello.o  Hello.pcm Use.cpp
```

And if we run:

```
clang++ -std=c++20 -fmodule-output Hello.cppm -c -o output/Hello.o
```

Then the `output` directory may look like:

```
Hello.o  Hello.pcm
```

Reviewed By: dblaikie, iains, tahonermann

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

Added: 
clang/test/Driver/module-output.cppm

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/lit.local.cfg

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 61b7a161da36e..08be6966f6864 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -489,6 +489,9 @@ def err_test_module_file_extension_format : Error<
   "-ftest-module-file-extension argument '%0' is not of the required form "
   "'blockname:major:minor:hashed:user info'">;
 
+def err_drv_module_output_with_multiple_arch : Error<
+  "option '-fmodule-output' can't be used with multiple arch options">;
+
 def err_drv_extract_api_wrong_kind : Error<
   "header file '%0' input '%1' does not match the type of prior input "
   "in api extraction; use '-x %2' to override">;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6cee51f72702f..eaaaebf8702ea 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2306,6 +2306,9 @@ defm prebuilt_implicit_modules : 
BoolFOption<"prebuilt-implicit-modules",
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CC1Option]>>;
 
+def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption, 
CC1Option]>,
+  HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
+
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">,

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index fe9e9bb7055f3..bc70a92551811 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5553,6 +5553,30 @@ const char *Driver::CreateTempFile(Compilation &C, 
StringRef Prefix,
   return C.addTempFile(C.getArgs().MakeArgString(TmpName));
 }
 
+// Calculate the output path of the module file when compiling a module unit
+// with the `-fmodule-output` option specified. The behavior is:
+// - If the output object file of the module unit is specified, the output path
+//   of the module file should be the same with the output object file except
+//   the corresponding suffix. This requires both `-o` and `-c` are specified.
+// - Otherwise, the output path of the module file will be the same with the
+//   input with the corresponding suffix.
+static const char *GetModuleOutputPath(Compilation &C, const JobAction &JA,
+   const char *BaseInput) {
+  assert(isa(JA) && JA.getType() == types::TY_ModuleFile 
&&
+ C.getArgs().hasArg(options::OPT_fmodule_output));
+
+  SmallString<64> OutputPath;
+  Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
+  if (FinalOutput && C.getArgs().hasArg(options::OPT_c))
+OutputPath = FinalOutput->getValue();
+  else
+OutputPath = BaseInput;
+
+  const char *Extension = types::getTypeTempSuffix(JA.getType());
+  llvm::sys::path::replace_extension(OutputPath, Extension);
+  return C.addResultFile(C.getArgs().MakeArgString(OutputPath.c_str()), &JA);
+}
+
 const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput,
StringRef OrigBoundArch, bool 
AtTopLevel,
@@ -5609,6 +5633,16 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &J

[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-15 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

> Sorry for the misleading and thanks for the quick clarification. So it looks 
> like the status quo is a little bit worse than I imaged...

I opened a thread on discourse for more visibility: 
https://discourse.llvm.org/t/land-c-modules-changes-required-for-cmake-before-llvm-16-branch/67717


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

https://reviews.llvm.org/D137534

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


[clang] 6f2e781 - [NFC] Require tests to skip on windows to avoid handling the different

2023-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-16T11:48:08+08:00
New Revision: 6f2e78195f644f024df5b5167e26bdd56b4c1c2b

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

LOG: [NFC] Require tests to skip on windows to avoid handling the different
slash in the filesystem

The modified test fails on windows for the diffeent slash direction ('/'
in linux and '/' on windows). The patch requires the test to skip on
windows to avoid such differences.

Added: 


Modified: 
clang/test/Driver/module-output.cppm

Removed: 




diff  --git a/clang/test/Driver/module-output.cppm 
b/clang/test/Driver/module-output.cppm
index 2a9fb55f4b66..d3d707061251 100644
--- a/clang/test/Driver/module-output.cppm
+++ b/clang/test/Driver/module-output.cppm
@@ -1,3 +1,8 @@
+// It is annoying to handle 
diff erent slash direction
+// in Windows and Linux. So we disable the test on Windows
+// here.
+// REQUIRES: !system-windows
+//
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: split-file %s %t



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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D137534#4055323 , @h-vetinari 
wrote:

>> Sorry for the misleading and thanks for the quick clarification. So it looks 
>> like the status quo is a little bit worse than I imaged...
>
> I opened a thread on discourse for more visibility: 
> https://discourse.llvm.org/t/land-c-modules-changes-required-for-cmake-before-llvm-16-branch/67717

Thanks for chime in!


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

https://reviews.llvm.org/D137534

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


[PATCH] D141814: [llvm][ADT] Replace uses of `makeMutableArrayRef` with deduction guides

2023-01-15 Thread Joe Loser via Phabricator via cfe-commits
jloser created this revision.
jloser added reviewers: MaskRay, serge-sans-paille, dblaikie.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, kosarev, ayermolo, 
sdasgup3, wenzhicui, wrengr, foad, cota, teijeong, rdzhabarov, tatianashp, 
msifontes, jurahul, Kayjukh, grosul1, Joonsoo, kerbowa, liufengdb, aartbik, 
mgester, arpith-jacob, csigg, antiagainst, shauheen, rriddle, mehdi_amini, 
kadircet, arphaman, hiraditya, arichardson, jvesely, emaste, arsenm.
Herald added a reviewer: aartbik.
Herald added a reviewer: bondhugula.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
jloser requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: cfe-commits, llvm-commits, lldb-commits, 
pcwang-thead, yota9, stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: dcaballe.
Herald added projects: clang, LLDB, MLIR, LLVM, clang-tools-extra.

Similar to how `makeArrayRef` is deprecated in favor of deduction guides, do the
same for `makeMutableArrayRef`.

Once all of the places in-tree are using the deduction guides for
`MutableArrayRef`, we can mark `makeMutableArrayRef` as deprecated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141814

Files:
  bolt/lib/Profile/DataAggregator.cpp
  clang-tools-extra/clangd/FuzzyMatch.cpp
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/index/dex/Trigram.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang/include/clang/AST/DeclOpenMP.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Lex/MacroInfo.h
  clang/lib/AST/StmtOpenMP.cpp
  lld/COFF/Chunks.cpp
  lld/COFF/DebugTypes.cpp
  lld/COFF/Writer.cpp
  lld/ELF/InputFiles.h
  lld/ELF/SyntheticSections.cpp
  lldb/source/Host/common/NativeProcessProtocol.cpp
  llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/Metadata.h
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/Support/Parallel.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/ExecutionEngine/ExecutionEngine.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
  llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/unittests/Support/Path.cpp
  mlir/lib/Bytecode/Writer/IRNumbering.cpp
  mlir/lib/Dialect/Affine/Transforms/LoopCoalescing.cpp
  mlir/test/mlir-tblgen/constraint-unique.td
  mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Index: mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
===
--- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2746,7 +2746,7 @@
   ///
   /// {0}: The region's index.
   const char *const getSingleRegion =
-  "::llvm::makeMutableArrayRef((*this)->getRegion({0}))";
+  "::llvm::MutableArrayRef((*this)->getRegion({0}))";
 
   // If we have no regions, there is nothing more to do.
   const auto canSkip = [](const NamedRegion ®ion) {
@@ -2781,7 +2781,7 @@
   /// Get a single successor.
   ///
   /// {0}: The successor's name.
-  const char *const getSingleSuccessor = "::llvm::makeMutableArrayRef({0}())";
+  const char *const getSingleSuccessor = "::llvm::MutableArrayRef({0}())";
 
   // If we have no successors, there is nothing more to do.
   const auto canSkip = [](const NamedSuccessor &successor) {
Index: mlir/test/mlir-tblgen/constraint-unique.td
===
--- mlir/test/mlir-tblgen/constraint-unique.td
+++ mlir/test/mlir-tblgen/constraint-unique.td
@@ -127,10 +127,10 @@
 // CHECK: for (auto [[$RET_VALUE:.*]] : [[$RET_VALUE_GROUP]])
 // CHECK-NEXT:  if (::mlir::failed([[$A_TYPE_CONSTRAINT]](*this, [[$RET_VALUE]].getType(), "result", index++)))
 // CHECK-NEXT:return ::mlir::failure();
-// CHECK: for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0)))
+// CHECK: for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0)))
 // CHECK-NEXT:  if (::mlir::failed([[$A_REGION_CONSTRAINT]](*this, region, "d", index++)))
 // CHECK-NEXT:return ::mlir::failure();
-// CHECK: for (auto *successor : ::llvm::makeMutableArrayRef(c()))
+// CHECK: for (auto *successor : ::llvm::MutableArrayRef(c()))
 // CHECK-NEXT:  if (::mlir::failed([[$A_SUCCESSOR_CONSTRAINT]](*this, successor, "c", index++)))
 // CHECK-NEXT:return ::mlir::failure();
 
@@ -148,9 +148,9 @@
 // CHECK: for (auto [[$RET_VALUE:.*]] : [[$RET_VALUE_GROUP]])
 // CHECK-NEXT:  if (::mlir::failed([[$O_TYPE_CONSTRAINT]](*this, [[$RET_VALUE]].getType(), "result", index++)))
 // CHECK-NEXT:return ::mlir::failure();
-// CHECK: for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0)))
+// CHECK: for (auto ®io

[PATCH] D141572: [C++] [Coroutines] Deprecates the '-fcoroutines-ts' flag

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a reviewer: philnik.
ChuanqiXu added a comment.

Now it looks like the failure are not related to the patch. Although there are 
some clang-format related failures, the related changes are generated 
automatically and I roughly remember libcxx don't use libcxx. @philnik would 
you like to take a look to ensure if the failures are related to the patch or 
not?


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

https://reviews.llvm.org/D141572

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


[clang] b1ac375 - [NFC] Only run clang/test/Driver/module-output.cppm on x86 registered targets

2023-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-16T13:49:37+08:00
New Revision: b1ac375e11c801be2a1e07e87be91ae54decf2eb

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

LOG: [NFC] Only run clang/test/Driver/module-output.cppm on x86 registered 
targets

On other targets (like ppc64-aix), the default output for `-c` may be `.s` 
instead of `.o`,
which makes the test failing. The patch require the test only run on
x86 registered targets to avoid the problem.

Added: 


Modified: 
clang/test/Driver/module-output.cppm

Removed: 




diff  --git a/clang/test/Driver/module-output.cppm 
b/clang/test/Driver/module-output.cppm
index d3d707061251..7d566f4eda63 100644
--- a/clang/test/Driver/module-output.cppm
+++ b/clang/test/Driver/module-output.cppm
@@ -2,6 +2,7 @@
 // in Windows and Linux. So we disable the test on Windows
 // here.
 // REQUIRES: !system-windows
+// REQUIRES: x86-registered-target
 //
 // RUN: rm -rf %t
 // RUN: mkdir %t



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


[PATCH] D137059: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 489426.
ChuanqiXu added a comment.

Update since the dependent one changes.


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

https://reviews.llvm.org/D137059

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/module-output.cppm


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -23,6 +23,11 @@
 // RUN: %clang %t/Hello.cppm -fmodule-output -arch i386 -arch x86_64 -### 
-target \
 // RUN:   x86_64-apple-darwin 2>&1 | FileCheck %t/Hello.cppm 
-check-prefix=MULTIPLE-ARCH
 
+// Tests that the .pcm file will be generated in the same path with the 
specified one
+// in the comamnd line.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o 
%t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+
 //--- Hello.cppm
 export module Hello;
 
@@ -31,6 +36,9 @@
 
 // MULTIPLE-ARCH: option '-fmodule-output' can't be used with multiple arch 
options
 
+// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" 
"Hello.cppm" {{.*}}"-o" "{{.*}}/pcm/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/pcm/Hello.pcm"
+
 //--- AnotherModule.cppm
 export module AnotherModule;
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5554,8 +5554,12 @@
 }
 
 // Calculate the output path of the module file when compiling a module unit
-// with the `-fmodule-output` option specified. The behavior is:
-// - If the output object file of the module unit is specified, the output path
+// with the `-fmodule-output` option or `-fmodule-output=` option specified.
+// The behavior is:
+// - If `-fmodule-output=` is specfied, then the module file is
+//   writing to the value.
+// - Otherwise if the output object file of the module unit is specified, the
+// output path
 //   of the module file should be the same with the output object file except
 //   the corresponding suffix. This requires both `-o` and `-c` are specified.
 // - Otherwise, the output path of the module file will be the same with the
@@ -5563,7 +5567,12 @@
 static const char *GetModuleOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput) {
   assert(isa(JA) && JA.getType() == types::TY_ModuleFile 
&&
- C.getArgs().hasArg(options::OPT_fmodule_output));
+ (C.getArgs().hasArg(options::OPT_fmodule_output) ||
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ)));
+
+  if (Arg *ModuleOutputEQ =
+  C.getArgs().getLastArg(options::OPT_fmodule_output_EQ))
+return C.addResultFile(ModuleOutputEQ->getValue(), &JA);
 
   SmallString<64> OutputPath;
   Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
@@ -5633,14 +5642,16 @@
 &JA);
   }
 
-  if (MultipleArchs && C.getArgs().hasArg(options::OPT_fmodule_output))
+  bool SpecifiedModuleOutput =
+  C.getArgs().hasArg(options::OPT_fmodule_output) ||
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ);
+  if (MultipleArchs && SpecifiedModuleOutput)
 Diag(clang::diag::err_drv_module_output_with_multiple_arch);
 
   // If we're emitting a module output with the specified option
   // `-fmodule-output`.
   if (!AtTopLevel && isa(JA) &&
-  JA.getType() == types::TY_ModuleFile &&
-  C.getArgs().hasArg(options::OPT_fmodule_output))
+  JA.getType() == types::TY_ModuleFile && SpecifiedModuleOutput)
 return GetModuleOutputPath(C, JA, BaseInput);
 
   // Output to a temporary file?
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2306,6 +2306,8 @@
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CC1Option]>>;
 
+def fmodule_output_EQ : Joined<["-"], "fmodule-output=">, 
Flags<[NoXarchOption, CC1Option]>,
+  HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption, 
CC1Option]>,
   HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -23,6 +23,11 @@
 // RUN: %clang %t/Hello.cppm -fmodule-output -arch i386 -arch x86_64 -### -target \
 // RUN:   

[clang] 3e9e8d6 - [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

2023-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-16T14:01:05+08:00
New Revision: 3e9e8d6ef44244491e25f7bc918f6e91e16b7714

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

LOG: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

The patch implements `-fmodule-output=`. This is helpful if the build
systems want to generate these output files in other places which is not
the same with -o specified or the input file lived.

Reviewed By: dblaikie, iains

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/module-output.cppm

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index eaaaebf8702ea..38f2f68b93860 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2306,6 +2306,8 @@ defm prebuilt_implicit_modules : 
BoolFOption<"prebuilt-implicit-modules",
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CC1Option]>>;
 
+def fmodule_output_EQ : Joined<["-"], "fmodule-output=">, 
Flags<[NoXarchOption, CC1Option]>,
+  HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption, 
CC1Option]>,
   HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index bc70a92551811..e20aad49b0cdf 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5554,8 +5554,12 @@ const char *Driver::CreateTempFile(Compilation &C, 
StringRef Prefix,
 }
 
 // Calculate the output path of the module file when compiling a module unit
-// with the `-fmodule-output` option specified. The behavior is:
-// - If the output object file of the module unit is specified, the output path
+// with the `-fmodule-output` option or `-fmodule-output=` option specified.
+// The behavior is:
+// - If `-fmodule-output=` is specfied, then the module file is
+//   writing to the value.
+// - Otherwise if the output object file of the module unit is specified, the
+// output path
 //   of the module file should be the same with the output object file except
 //   the corresponding suffix. This requires both `-o` and `-c` are specified.
 // - Otherwise, the output path of the module file will be the same with the
@@ -5563,7 +5567,12 @@ const char *Driver::CreateTempFile(Compilation &C, 
StringRef Prefix,
 static const char *GetModuleOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput) {
   assert(isa(JA) && JA.getType() == types::TY_ModuleFile 
&&
- C.getArgs().hasArg(options::OPT_fmodule_output));
+ (C.getArgs().hasArg(options::OPT_fmodule_output) ||
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ)));
+
+  if (Arg *ModuleOutputEQ =
+  C.getArgs().getLastArg(options::OPT_fmodule_output_EQ))
+return C.addResultFile(ModuleOutputEQ->getValue(), &JA);
 
   SmallString<64> OutputPath;
   Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
@@ -5633,14 +5642,16 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
 &JA);
   }
 
-  if (MultipleArchs && C.getArgs().hasArg(options::OPT_fmodule_output))
+  bool SpecifiedModuleOutput =
+  C.getArgs().hasArg(options::OPT_fmodule_output) ||
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ);
+  if (MultipleArchs && SpecifiedModuleOutput)
 Diag(clang::diag::err_drv_module_output_with_multiple_arch);
 
   // If we're emitting a module output with the specified option
   // `-fmodule-output`.
   if (!AtTopLevel && isa(JA) &&
-  JA.getType() == types::TY_ModuleFile &&
-  C.getArgs().hasArg(options::OPT_fmodule_output))
+  JA.getType() == types::TY_ModuleFile && SpecifiedModuleOutput)
 return GetModuleOutputPath(C, JA, BaseInput);
 
   // Output to a temporary file?

diff  --git a/clang/test/Driver/module-output.cppm 
b/clang/test/Driver/module-output.cppm
index 7d566f4eda636..604cd1791bcdf 100644
--- a/clang/test/Driver/module-output.cppm
+++ b/clang/test/Driver/module-output.cppm
@@ -23,6 +23,11 @@
 // RUN: %clang %t/Hello.cppm -fmodule-output -arch i386 -arch x86_64 -### 
-target \
 // RUN:   x86_64-apple-darwin 2>&1 | FileCheck %t/Hello.cppm 
-check-prefix=MULTIPLE-ARCH
 
+// Tests that the .pcm file will be generated in the same path with the 
specified one
+// in the comamnd line.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o 
%t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+
 //--- Hello.cppm
 export modu

[PATCH] D137059: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

2023-01-15 Thread Chuanqi Xu 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 rG3e9e8d6ef442: [Driver] [C++20] [Modules] Support 
-fmodule-output= (2/2) (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137059

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/module-output.cppm


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -23,6 +23,11 @@
 // RUN: %clang %t/Hello.cppm -fmodule-output -arch i386 -arch x86_64 -### 
-target \
 // RUN:   x86_64-apple-darwin 2>&1 | FileCheck %t/Hello.cppm 
-check-prefix=MULTIPLE-ARCH
 
+// Tests that the .pcm file will be generated in the same path with the 
specified one
+// in the comamnd line.
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o 
%t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+
 //--- Hello.cppm
 export module Hello;
 
@@ -31,6 +36,9 @@
 
 // MULTIPLE-ARCH: option '-fmodule-output' can't be used with multiple arch 
options
 
+// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" 
"Hello.cppm" {{.*}}"-o" "{{.*}}/pcm/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/pcm/Hello.pcm"
+
 //--- AnotherModule.cppm
 export module AnotherModule;
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5554,8 +5554,12 @@
 }
 
 // Calculate the output path of the module file when compiling a module unit
-// with the `-fmodule-output` option specified. The behavior is:
-// - If the output object file of the module unit is specified, the output path
+// with the `-fmodule-output` option or `-fmodule-output=` option specified.
+// The behavior is:
+// - If `-fmodule-output=` is specfied, then the module file is
+//   writing to the value.
+// - Otherwise if the output object file of the module unit is specified, the
+// output path
 //   of the module file should be the same with the output object file except
 //   the corresponding suffix. This requires both `-o` and `-c` are specified.
 // - Otherwise, the output path of the module file will be the same with the
@@ -5563,7 +5567,12 @@
 static const char *GetModuleOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput) {
   assert(isa(JA) && JA.getType() == types::TY_ModuleFile 
&&
- C.getArgs().hasArg(options::OPT_fmodule_output));
+ (C.getArgs().hasArg(options::OPT_fmodule_output) ||
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ)));
+
+  if (Arg *ModuleOutputEQ =
+  C.getArgs().getLastArg(options::OPT_fmodule_output_EQ))
+return C.addResultFile(ModuleOutputEQ->getValue(), &JA);
 
   SmallString<64> OutputPath;
   Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
@@ -5633,14 +5642,16 @@
 &JA);
   }
 
-  if (MultipleArchs && C.getArgs().hasArg(options::OPT_fmodule_output))
+  bool SpecifiedModuleOutput =
+  C.getArgs().hasArg(options::OPT_fmodule_output) ||
+  C.getArgs().hasArg(options::OPT_fmodule_output_EQ);
+  if (MultipleArchs && SpecifiedModuleOutput)
 Diag(clang::diag::err_drv_module_output_with_multiple_arch);
 
   // If we're emitting a module output with the specified option
   // `-fmodule-output`.
   if (!AtTopLevel && isa(JA) &&
-  JA.getType() == types::TY_ModuleFile &&
-  C.getArgs().hasArg(options::OPT_fmodule_output))
+  JA.getType() == types::TY_ModuleFile && SpecifiedModuleOutput)
 return GetModuleOutputPath(C, JA, BaseInput);
 
   // Output to a temporary file?
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2306,6 +2306,8 @@
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CC1Option]>>;
 
+def fmodule_output_EQ : Joined<["-"], "fmodule-output=">, 
Flags<[NoXarchOption, CC1Option]>,
+  HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption, 
CC1Option]>,
   HelpText<"Save intermediate module file results when compiling a standard 
C++ module unit.">;
 


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module

[clang] fcb6afb - [Driver] [C++20] [Modules] Don't emit unused-argument warning for '-fmodule-output' and '-fmodule-output='

2023-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-16T14:08:02+08:00
New Revision: fcb6afb508c420c3a95e6e1324b1586255a08f40

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

LOG: [Driver] [C++20] [Modules] Don't emit unused-argument warning for 
'-fmodule-output'  and '-fmodule-output='

Suppres the r unused-argument warning for -fmodule-output according to
the discussion thread in
https://gcc.gnu.org/pipermail/gcc/2022-December/240239.html.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/module-output.cppm

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b2eadaf67e951..5462634aa96da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3798,6 +3798,10 @@ static bool RenderModulesOptions(Compilation &C, const 
Driver &D,
 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
   }
 
+  // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
+  Args.ClaimAllArgs(options::OPT_fmodule_output);
+  Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+
   return HaveModules;
 }
 

diff  --git a/clang/test/Driver/module-output.cppm 
b/clang/test/Driver/module-output.cppm
index 604cd1791bcdf..a01531b889a3e 100644
--- a/clang/test/Driver/module-output.cppm
+++ b/clang/test/Driver/module-output.cppm
@@ -27,6 +27,9 @@
 // in the comamnd line.
 // RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o 
%t/Hello.o \
 // RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm 
-fmodule-output -c -fsyntax-only \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-NOT-USED
 
 //--- Hello.cppm
 export module Hello;
@@ -39,6 +42,11 @@ export module Hello;
 // CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" 
"Hello.cppm" {{.*}}"-o" "{{.*}}/pcm/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/pcm/Hello.pcm"
 
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: 
'-fmodule-output'
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: 
'-fmodule-output=Hello.pcm'
+// CHECK-NOT-USED-NOT: "-fmodule-output"
+// CHECK-NOT-USED-NOT: "-fmodule-output="
+
 //--- AnotherModule.cppm
 export module AnotherModule;
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"



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


[PATCH] D140001: [Driver] [C++20] [Modules] Don't emit unused-argument warning for ` -fmodule-output=` and `-fmodule-output`

2023-01-15 Thread Chuanqi Xu 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 rGfcb6afb508c4: [Driver] [C++20] [Modules] Don't emit 
unused-argument warning for '-fmodule… (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D140001?vs=482763&id=489428#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140001

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/module-output.cppm


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -27,6 +27,9 @@
 // in the comamnd line.
 // RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o 
%t/Hello.o \
 // RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm 
-fmodule-output -c -fsyntax-only \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-NOT-USED
 
 //--- Hello.cppm
 export module Hello;
@@ -39,6 +42,11 @@
 // CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" 
"Hello.cppm" {{.*}}"-o" "{{.*}}/pcm/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/pcm/Hello.pcm"
 
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: 
'-fmodule-output'
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: 
'-fmodule-output=Hello.pcm'
+// CHECK-NOT-USED-NOT: "-fmodule-output"
+// CHECK-NOT-USED-NOT: "-fmodule-output="
+
 //--- AnotherModule.cppm
 export module AnotherModule;
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" 
{{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3798,6 +3798,10 @@
 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
   }
 
+  // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
+  Args.ClaimAllArgs(options::OPT_fmodule_output);
+  Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+
   return HaveModules;
 }
 


Index: clang/test/Driver/module-output.cppm
===
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -27,6 +27,9 @@
 // in the comamnd line.
 // RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \
 // RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm -fmodule-output -c -fsyntax-only \
+// RUN:   -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-NOT-USED
 
 //--- Hello.cppm
 export module Hello;
@@ -39,6 +42,11 @@
 // CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/pcm/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/pcm/Hello.pcm"
 
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: '-fmodule-output'
+// CHECK-NOT-USED-NOT: warning: argument unused during compilation: '-fmodule-output=Hello.pcm'
+// CHECK-NOT-USED-NOT: "-fmodule-output"
+// CHECK-NOT-USED-NOT: "-fmodule-output="
+
 //--- AnotherModule.cppm
 export module AnotherModule;
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3798,6 +3798,10 @@
 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
   }
 
+  // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
+  Args.ClaimAllArgs(options::OPT_fmodule_output);
+  Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+
   return HaveModules;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141818: Add test for an invalid requirement in requires expr.

2023-01-15 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 created this revision.
usaxena95 added reviewers: ilya-biryukov, erichkeane.
Herald added a project: All.
usaxena95 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The one introduced in D140547  was brittle. 
Fixing max template depth to
a small value would still test the same issue without causing actual
stack exhaustion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141818

Files:
  clang/test/SemaCXX/invalid-requirement-requires-expr.cpp


Index: clang/test/SemaCXX/invalid-requirement-requires-expr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-requirement-requires-expr.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -fsyntax-only -std=c++2a -Xclang -verify -ftemplate-depth=5 
-ftemplate-backtrace-limit=4 %s
+
+// RequiresExpr contains invalid requirement. (Eg. Highly recurisive template).
+template
+struct A { static constexpr bool far(); };
+class B {
+bool data_member;
+friend struct A<1>;
+};
+
+template<>
+constexpr bool A<0>::far() { return true; }
+
+template
+constexpr bool A::far() {
+return requires(B b) {
+  b.data_member;
+  requires A::far(); // #Invalid
+  // expected-error@#Invalid {{recursive template instantiation exceeded 
maximum depth}}
+  // expected-note@#Invalid {{in instantiation}}
+  // expected-note@#Invalid 2 {{while}}
+  // expected-note@#Invalid {{contexts in backtrace}}
+  // expected-note@#Invalid {{increase recursive template instantiation 
depth}}
+};
+}
+static_assert(A<1>::far());
+static_assert(!A<6>::far()); // expected-note {{in instantiation of member 
function}}


Index: clang/test/SemaCXX/invalid-requirement-requires-expr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-requirement-requires-expr.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -fsyntax-only -std=c++2a -Xclang -verify -ftemplate-depth=5 -ftemplate-backtrace-limit=4 %s
+
+// RequiresExpr contains invalid requirement. (Eg. Highly recurisive template).
+template
+struct A { static constexpr bool far(); };
+class B {
+bool data_member;
+friend struct A<1>;
+};
+
+template<>
+constexpr bool A<0>::far() { return true; }
+
+template
+constexpr bool A::far() {
+return requires(B b) {
+  b.data_member;
+  requires A::far(); // #Invalid
+  // expected-error@#Invalid {{recursive template instantiation exceeded maximum depth}}
+  // expected-note@#Invalid {{in instantiation}}
+  // expected-note@#Invalid 2 {{while}}
+  // expected-note@#Invalid {{contexts in backtrace}}
+  // expected-note@#Invalid {{increase recursive template instantiation depth}}
+};
+}
+static_assert(A<1>::far());
+static_assert(!A<6>::far()); // expected-note {{in instantiation of member function}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2563ad8 - [NFC] [Modules] Add test from PR60036

2023-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-16T15:08:16+08:00
New Revision: 2563ad8ef1a88907049715b582eb2342fd69cf89

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

LOG: [NFC] [Modules] Add test from PR60036

Although I failed to reproduce the problem in pr60036, it should be
always good to have more tests.

Added: 
clang/test/Modules/pr60036.cppm

Modified: 


Removed: 




diff  --git a/clang/test/Modules/pr60036.cppm b/clang/test/Modules/pr60036.cppm
new file mode 100644
index 0..187a68f8733d0
--- /dev/null
+++ b/clang/test/Modules/pr60036.cppm
@@ -0,0 +1,103 @@
+// Test case from https://github.com/llvm/llvm-project/issues/60036
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface 
-fprebuilt-module-path=%t -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface 
-fprebuilt-module-path=%t -o %t/c.pcm
+// RUN: %clang_cc1 -std=c++20 %t/d.cppm -emit-module-interface 
-fprebuilt-module-path=%t -o %t/d.pcm
+// RUN: %clang_cc1 -std=c++20 %t/e.cppm -emit-module-interface 
-fprebuilt-module-path=%t -o %t/e.pcm
+// RUN: %clang_cc1 -std=c++20 %t/f.cppm -emit-module-interface 
-fprebuilt-module-path=%t -o %t/f.pcm
+// RUN: %clang_cc1 -std=c++20 %t/g.cppm -fprebuilt-module-path=%t -verify 
-fsyntax-only 
+//
+// Tests that the behavior is fine with specifying module file with 
`-fmodule-file`.
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface 
-fmodule-file=%t/a.pcm -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface 
-fmodule-file=%t/a.pcm -o %t/c.pcm
+// RUN: %clang_cc1 -std=c++20 %t/d.cppm -emit-module-interface  -o %t/d.pcm
+// RUN: %clang_cc1 -std=c++20 %t/e.cppm -emit-module-interface 
-fmodule-file=%t/d.pcm -o %t/e.pcm
+// RUN: %clang_cc1 -std=c++20 %t/f.cppm -emit-module-interface 
-fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm -fmodule-file=%t/c.pcm 
-fmodule-file=%t/d.pcm -o %t/f.pcm
+// RUN: %clang_cc1 -std=c++20 %t/g.cppm -fmodule-file=%t/e.pcm 
-fmodule-file=%t/f.pcm -verify -fsyntax-only 
+
+//--- a.cppm
+export module a;
+
+export template
+struct a;
+
+template
+struct a {
+   using type = char;
+};
+
+//--- b.cppm
+export module b;
+
+import a;
+
+typename a::type;
+
+//--- c.cppm
+export module c;
+
+import a;
+
+typename a::type;
+
+//--- d.cppm
+export module d;
+
+export template
+struct d {
+   d() {}
+   explicit d(int) requires(true) {}
+   d(auto &&) {}
+};
+
+//--- e.cppm
+export module e;
+
+import d;
+
+auto r = d();
+
+//--- f.cppm
+export module f;
+
+import a;
+import b;
+import c;
+import d;
+
+template
+struct array {
+   friend void fr(array const &) {
+   }
+};
+
+array() -> array::type>;
+
+struct wrap {
+   d m;
+};
+
+template
+int f1(T) {
+   return 1;
+}
+
+void f2() {
+   d view;
+   int x = f1(view);
+   typename a::type;
+   wrap w;
+}
+
+//--- g.cppm
+// expected-no-diagnostics
+export module g;
+
+import e;
+import f;



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


[PATCH] D141572: [C++] [Coroutines] Deprecates the '-fcoroutines-ts' flag

2023-01-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 489437.
ChuanqiXu added a comment.

Move the release note to `Deprecated Compiler Flags` section.


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

https://reviews.llvm.org/D141572

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/coroutines.cpp
  libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
  libcxx/test/libcxx/clang_tidy.sh.cpp
  libcxx/test/libcxx/double_include.sh.cpp
  libcxx/test/libcxx/min_max_macros.compile.pass.cpp
  libcxx/test/libcxx/modules_include.sh.cpp
  libcxx/test/libcxx/nasty_macros.compile.pass.cpp
  libcxx/test/libcxx/no_assert_include.compile.pass.cpp
  libcxx/utils/generate_header_tests.py

Index: libcxx/utils/generate_header_tests.py
===
--- libcxx/utils/generate_header_tests.py
+++ libcxx/utils/generate_header_tests.py
@@ -19,6 +19,8 @@
 
 "filesystem": "!defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)",
 
+"coroutine": "(defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)",
+
 "clocale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
 "codecvt": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
 "fstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION) && !defined(_LIBCPP_HAS_NO_FSTREAM)",
Index: libcxx/test/libcxx/no_assert_include.compile.pass.cpp
===
--- libcxx/test/libcxx/no_assert_include.compile.pass.cpp
+++ libcxx/test/libcxx/no_assert_include.compile.pass.cpp
@@ -66,7 +66,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/nasty_macros.compile.pass.cpp
===
--- libcxx/test/libcxx/nasty_macros.compile.pass.cpp
+++ libcxx/test/libcxx/nasty_macros.compile.pass.cpp
@@ -193,7 +193,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/modules_include.sh.cpp
===
--- libcxx/test/libcxx/modules_include.sh.cpp
+++ libcxx/test/libcxx/modules_include.sh.cpp
@@ -154,7 +154,7 @@
 #include 
 #endif
 // RUN: %{cxx} %s %{flags} %{compile_flags} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only -DTEST_26
-#if defined(TEST_26)
+#if defined(TEST_26) && (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
 #include 
 #endif
 // RUN: %{cxx} %s %{flags} %{compile_flags} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only -DTEST_27
Index: libcxx/test/libcxx/min_max_macros.compile.pass.cpp
===
--- libcxx/test/libcxx/min_max_macros.compile.pass.cpp
+++ libcxx/test/libcxx/min_max_macros.compile.pass.cpp
@@ -95,8 +95,10 @@
 TEST_MACROS();
 #include 
 TEST_MACROS();
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
 TEST_MACROS();
+#endif
 #include 
 TEST_MACROS();
 #include 
Index: libcxx/test/libcxx/double_include.sh.cpp
===
--- libcxx/test/libcxx/double_include.sh.cpp
+++ libcxx/test/libcxx/double_include.sh.cpp
@@ -69,7 +69,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/clang_tidy.sh.cpp
===
--- libcxx/test/libcxx/clang_tidy.sh.cpp
+++ libcxx/test/libcxx/clang_tidy.sh.cpp
@@ -68,7 +68,9 @@
 #include 
 #include 
 #include 
-#include 
+#if (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_coroutines) && __cpp_coroutines >= 201703L)
+#   include 
+#endif
 #include 
 #include 
 #include 
Index: libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
===
--- libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
+++ libcxx/test/libcxx/assertions/headers_declare_verbose_abort.sh.cpp
@@ -199,7 +199,7 @@
 #endif
 
 // RUN: %{build} -DTEST_26
-#if defined(TEST_26)
+#if defined(TEST_26) && (defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L) || (defined(__cpp_co

[PATCH] D141811: [clang-format] Allow trailing return types in macros

2023-01-15 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

What about `decltype(auto)`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141811

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


[PATCH] D141750: [docs] Add llvm & clang release notes for LoongArch

2023-01-15 Thread Renato Golin via Phabricator via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

Nice! Thanks for the detailed reporting. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141750

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


[PATCH] D141814: [llvm][ADT] Replace uses of `makeMutableArrayRef` with deduction guides

2023-01-15 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

LGTM




Comment at: lldb/source/Host/common/NativeProcessProtocol.cpp:652
 
   auto data =
+  llvm::MutableArrayRef(static_cast(buf), bytes_read);

random nit: This could be rewritten as

```
llvm::MutableArrayRef data(static_cast(buf), bytes_read);
```

now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141814

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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-01-15 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca added a comment.

In D140756#4051383 , @aaron.ballman 
wrote:

> LGTM aside from some minor things you can correct when landing.
> 

Thank you for the great suggestions!

I'll try to correct it as soon as possible, hopefully this weekend.
Should I update the revision or should I just modify it and land it after 
ensuring that it works correctly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140756

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