[clang] caa83d2 - [clang][Interp][NFC] Simplify InterpFrame::describe

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T08:49:44+02:00
New Revision: caa83d23295ae42334ea692a300e9acc77a30449

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

LOG: [clang][Interp][NFC] Simplify InterpFrame::describe

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 1a97e2ad02b4..781b6d8a845a 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -157,12 +157,7 @@ void InterpFrame::describe(llvm::raw_ostream &OS) {
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
 QualType Ty = F->getParamDecl(I)->getType();
 
-PrimType PrimTy;
-if (llvm::Optional T = S.Ctx.classify(Ty)) {
-  PrimTy = *T;
-} else {
-  PrimTy = PT_Ptr;
-}
+PrimType PrimTy = S.Ctx.classify(Ty).value_or(PT_Ptr);
 
 TYPE_SWITCH(PrimTy, print(OS, stackRef(Off), S.getCtx(), Ty));
 Off += align(primSize(PrimTy));



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


[clang] 751f1bf - [clang][Interp][NFC] Assert we have a valid Record instance

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T08:49:31+02:00
New Revision: 751f1bfb5f77dfab27456c6964721ed3a4f9f896

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

LOG: [clang][Interp][NFC] Assert we have a valid Record instance

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 4f54193dcf3a..bdb072c3b0aa 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -98,6 +98,7 @@ bool ByteCodeStmtGen::visitFunc(const FunctionDecl 
*F) {
   if (const auto Ctor = dyn_cast(F)) {
 const RecordDecl *RD = Ctor->getParent();
 const Record *R = this->getRecord(RD);
+assert(R);
 
 for (const auto *Init : Ctor->inits()) {
   const Expr *InitExpr = Init->getInit();



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


[clang] 4a9b727 - [clang][Interp][NFC] Make InitMap final

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T08:49:20+02:00
New Revision: 4a9b7273260d2ed071737e48210159bc47347fed

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

LOG: [clang][Interp][NFC] Make InitMap final

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/AST/Interp/Descriptor.h
index 823ecd144e7c..dacec6be89c7 100644
--- a/clang/lib/AST/Interp/Descriptor.h
+++ b/clang/lib/AST/Interp/Descriptor.h
@@ -186,7 +186,7 @@ struct InlineDescriptor {
 /// A pointer to this is embedded at the end of all primitive arrays.
 /// If the map was not yet created and nothing was initialized, the pointer to
 /// this structure is 0. If the object was fully initialized, the pointer is 
-1.
-struct InitMap {
+struct InitMap final {
 private:
   /// Type packing bits.
   using T = uint64_t;



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


[PATCH] D136670: [clang][Interp] Fix InterpFrame::describe() for This pointers

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf007c99ed12f: [clang][Interp] Fix InterpFrame::describe() 
for This pointers (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136670

Files:
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -257,11 +257,6 @@
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}}
 
-#if 0
-  // FIXME: This test is currently disabled because the failing constructor 
call
-  //   causes us to run into an assertion later on in the new interpreter.
-  //   Once that is fixed, we fail successfully but the diagnostic uses the
-  //   wrong value.
   struct AnotherBase {
 int Val;
 constexpr AnotherBase(int i) : Val(12 / i) {} //ref-note {{division by 
zero}} \
@@ -274,9 +269,7 @@
   constexpr AnotherBase Derp(0); // ref-error {{must be initialized by a 
constant expression}} \
  // ref-note {{in call to 'AnotherBase(0)'}} \
  // expected-error {{must be initialized by a 
constant expression}} \
- // expected-note {{in call to 'AnotherBase(}}
- // FIXME Previous note uses the wrong value
-#endif
+ // expected-note {{in call to 
'AnotherBase(0)'}}
 
   struct YetAnotherBase {
 int Val;
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -149,7 +149,11 @@
 OS << "->";
   }
   OS << *F << "(";
-  unsigned Off = Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  unsigned Off = 0;
+
+  Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0;
+
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
 QualType Ty = F->getParamDecl(I)->getType();
 


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -257,11 +257,6 @@
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
  // ref-note {{initializer of 'D' is not a constant expression}}
 
-#if 0
-  // FIXME: This test is currently disabled because the failing constructor call
-  //   causes us to run into an assertion later on in the new interpreter.
-  //   Once that is fixed, we fail successfully but the diagnostic uses the
-  //   wrong value.
   struct AnotherBase {
 int Val;
 constexpr AnotherBase(int i) : Val(12 / i) {} //ref-note {{division by zero}} \
@@ -274,9 +269,7 @@
   constexpr AnotherBase Derp(0); // ref-error {{must be initialized by a constant expression}} \
  // ref-note {{in call to 'AnotherBase(0)'}} \
  // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{in call to 'AnotherBase(}}
- // FIXME Previous note uses the wrong value
-#endif
+ // expected-note {{in call to 'AnotherBase(0)'}}
 
   struct YetAnotherBase {
 int Val;
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -149,7 +149,11 @@
 OS << "->";
   }
   OS << *F << "(";
-  unsigned Off = Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  unsigned Off = 0;
+
+  Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0;
+
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
 QualType Ty = F->getParamDecl(I)->getType();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ea25966 - [clang][Interp][NFC] Simplify generated code for references

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T08:49:11+02:00
New Revision: ea2596692f5f15e911020c0779c7ee0df51382a9

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

LOG: [clang][Interp][NFC] Simplify generated code for references

Instead of getting a pointer to a pointer to a value, followed by
dereferencing once, leaving us with a pointer to a value, we can instead
just get the pointer to the value (the reference in question) directly.
This simplifies (and shrinks) the generated bytecode somewhat.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 64bd5172b7f8..9472f1aed917 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1093,25 +1093,28 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 template 
 bool ByteCodeExprGen::VisitDeclRefExpr(const DeclRefExpr *E) {
   const auto *Decl = E->getDecl();
-  bool FoundDecl = false;
+  // References are implemented via pointers, so when we see a DeclRefExpr
+  // pointing to a reference, we need to get its value directly (i.e. the
+  // pointer to the actual value) instead of a pointer to the pointer to the
+  // value.
+  bool IsReference = Decl->getType()->isReferenceType();
 
   if (auto It = Locals.find(Decl); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
-if (!this->emitGetPtrLocal(Offset, E))
-  return false;
 
-FoundDecl = true;
+if (IsReference)
+  return this->emitGetLocal(PT_Ptr, Offset, E);
+return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(Decl)) {
-if (!this->emitGetPtrGlobal(*GlobalIndex, E))
-  return false;
+if (IsReference)
+  return this->emitGetGlobal(PT_Ptr, *GlobalIndex, E);
 
-FoundDecl = true;
+return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(Decl)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
-  if (!this->emitGetPtrParam(It->second, E))
-return false;
-
-  FoundDecl = true;
+  if (IsReference)
+return this->emitGetParam(PT_Ptr, It->second, E);
+  return this->emitGetPtrParam(It->second, E);
 }
   } else if (const auto *ECD = dyn_cast(Decl)) {
 PrimType T = *classify(ECD->getType());
@@ -1119,17 +1122,6 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 return this->emitConst(T, ECD->getInitVal(), E);
   }
 
-  // References are implemented using pointers, so when we get here,
-  // we have a pointer to a pointer, which we need to de-reference once.
-  if (FoundDecl) {
-if (Decl->getType()->isReferenceType()) {
-  if (!this->emitLoadPopPtr(E))
-return false;
-}
-
-return true;
-  }
-
   return false;
 }
 



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


[PATCH] D135764: [clang][Interp] Implement for loops

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6f02e090072: [clang][Interp] Implement for loops (authored 
by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D135764?vs=467089&id=470727#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135764

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/test/AST/Interp/loops.cpp

Index: clang/test/AST/Interp/loops.cpp
===
--- clang/test/AST/Interp/loops.cpp
+++ clang/test/AST/Interp/loops.cpp
@@ -187,3 +187,91 @@
   }
 #endif
 };
+
+namespace ForLoop {
+  constexpr int f() {
+int i = 0;
+for (;false;) {
+  i = i + 1;
+}
+return i;
+  }
+  static_assert(f() == 0, "");
+
+  constexpr int f2() {
+int m = 0;
+for (int i = 0; i < 10; i = i + 1){
+  m = i;
+}
+return m;
+  }
+  static_assert(f2() == 9, "");
+
+  constexpr int f3() {
+int i = 0;
+for (; i != 5; i = i + 1);
+return i;
+  }
+  static_assert(f3() == 5, "");
+
+  constexpr int f4() {
+int i = 0;
+for (;;) {
+  i = i + 1;
+
+  if (i == 5)
+break;
+}
+return i;
+  }
+  static_assert(f4() == 5, "");
+
+  constexpr int f5() {
+int i = 0;
+for (;i != 5;) {
+  i = i + 1;
+  continue;
+  i = i - 1;
+}
+return i;
+  }
+  static_assert(f5() == 5, "");
+
+  constexpr int f6(bool b) {
+int i = 0;
+
+for (;true;) {
+  if (!b) {
+if (i == 5)
+  break;
+  }
+
+  if (b) {
+for (; i != 10; i = i + 1) {
+  if (i == 8)
+break;
+  continue;
+}
+  }
+
+  if (b)
+break;
+
+  i = i + 1;
+  continue;
+}
+
+return i;
+  }
+  static_assert(f6(true) == 8, "");
+  static_assert(f6(false) == 5, "");
+
+#if 0
+  /// FIXME: This is an infinite loop, which should
+  ///   be rejected.
+  constexpr int f6() {
+for(;;);
+  }
+#endif
+
+};
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -60,6 +60,7 @@
   bool visitIfStmt(const IfStmt *IS);
   bool visitWhileStmt(const WhileStmt *S);
   bool visitDoStmt(const DoStmt *S);
+  bool visitForStmt(const ForStmt *S);
   bool visitBreakStmt(const BreakStmt *S);
   bool visitContinueStmt(const ContinueStmt *S);
 
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -171,6 +171,8 @@
 return visitWhileStmt(cast(S));
   case Stmt::DoStmtClass:
 return visitDoStmt(cast(S));
+  case Stmt::ForStmtClass:
+return visitForStmt(cast(S));
   case Stmt::BreakStmtClass:
 return visitBreakStmt(cast(S));
   case Stmt::ContinueStmtClass:
@@ -331,6 +333,39 @@
   return true;
 }
 
+template 
+bool ByteCodeStmtGen::visitForStmt(const ForStmt *S) {
+  // for (Init; Cond; Inc) { Body }
+  const Stmt *Init = S->getInit();
+  const Expr *Cond = S->getCond();
+  const Expr *Inc = S->getInc();
+  const Stmt *Body = S->getBody();
+
+  LabelTy EndLabel = this->getLabel();
+  LabelTy CondLabel = this->getLabel();
+  LabelTy IncLabel = this->getLabel();
+  LoopScope LS(this, EndLabel, IncLabel);
+
+  if (Init && !this->visitStmt(Init))
+return false;
+  this->emitLabel(CondLabel);
+  if (Cond) {
+if (!this->visitBool(Cond))
+  return false;
+if (!this->jumpFalse(EndLabel))
+  return false;
+  }
+  if (Body && !this->visitStmt(Body))
+return false;
+  this->emitLabel(IncLabel);
+  if (Inc && !this->discard(Inc))
+return false;
+  if (!this->jump(CondLabel))
+return false;
+  this->emitLabel(EndLabel);
+  return true;
+}
+
 template 
 bool ByteCodeStmtGen::visitBreakStmt(const BreakStmt *S) {
   if (!BreakLabel)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f007c99 - [clang][Interp] Fix InterpFrame::describe() for This pointers

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T08:48:55+02:00
New Revision: f007c99ed12f15f23e39f02d0fcb71eecead9b97

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

LOG: [clang][Interp] Fix InterpFrame::describe() for This pointers

Since we pass this via the stack, we need to account for it when
desribing the stack frame (parameters). This fixes a previously
commented-out test case.

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

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 427de28f2419..1a97e2ad02b4 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -149,7 +149,11 @@ void InterpFrame::describe(llvm::raw_ostream &OS) {
 OS << "->";
   }
   OS << *F << "(";
-  unsigned Off = Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  unsigned Off = 0;
+
+  Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0;
+
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
 QualType Ty = F->getParamDecl(I)->getType();
 

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 3edc0d89b29c..18caf5d8f4f0 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -257,11 +257,6 @@ namespace DeriveFailures {
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}}
 
-#if 0
-  // FIXME: This test is currently disabled because the failing constructor 
call
-  //   causes us to run into an assertion later on in the new interpreter.
-  //   Once that is fixed, we fail successfully but the diagnostic uses the
-  //   wrong value.
   struct AnotherBase {
 int Val;
 constexpr AnotherBase(int i) : Val(12 / i) {} //ref-note {{division by 
zero}} \
@@ -274,9 +269,7 @@ namespace DeriveFailures {
   constexpr AnotherBase Derp(0); // ref-error {{must be initialized by a 
constant expression}} \
  // ref-note {{in call to 'AnotherBase(0)'}} \
  // expected-error {{must be initialized by a 
constant expression}} \
- // expected-note {{in call to 'AnotherBase(}}
- // FIXME Previous note uses the wrong value
-#endif
+ // expected-note {{in call to 
'AnotherBase(0)'}}
 
   struct YetAnotherBase {
 int Val;



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


[clang] f6f02e0 - [clang][Interp] Implement for loops

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T08:48:36+02:00
New Revision: f6f02e090072002674c85c9d015b42f61c41656e

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

LOG: [clang][Interp] Implement for loops

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h
clang/test/AST/Interp/loops.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index addcb4dff1ff8..4f54193dcf3af 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -171,6 +171,8 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
 return visitWhileStmt(cast(S));
   case Stmt::DoStmtClass:
 return visitDoStmt(cast(S));
+  case Stmt::ForStmtClass:
+return visitForStmt(cast(S));
   case Stmt::BreakStmtClass:
 return visitBreakStmt(cast(S));
   case Stmt::ContinueStmtClass:
@@ -331,6 +333,39 @@ bool ByteCodeStmtGen::visitDoStmt(const DoStmt 
*S) {
   return true;
 }
 
+template 
+bool ByteCodeStmtGen::visitForStmt(const ForStmt *S) {
+  // for (Init; Cond; Inc) { Body }
+  const Stmt *Init = S->getInit();
+  const Expr *Cond = S->getCond();
+  const Expr *Inc = S->getInc();
+  const Stmt *Body = S->getBody();
+
+  LabelTy EndLabel = this->getLabel();
+  LabelTy CondLabel = this->getLabel();
+  LabelTy IncLabel = this->getLabel();
+  LoopScope LS(this, EndLabel, IncLabel);
+
+  if (Init && !this->visitStmt(Init))
+return false;
+  this->emitLabel(CondLabel);
+  if (Cond) {
+if (!this->visitBool(Cond))
+  return false;
+if (!this->jumpFalse(EndLabel))
+  return false;
+  }
+  if (Body && !this->visitStmt(Body))
+return false;
+  this->emitLabel(IncLabel);
+  if (Inc && !this->discard(Inc))
+return false;
+  if (!this->jump(CondLabel))
+return false;
+  this->emitLabel(EndLabel);
+  return true;
+}
+
 template 
 bool ByteCodeStmtGen::visitBreakStmt(const BreakStmt *S) {
   if (!BreakLabel)

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 49a7b79b1c4b5..10452079c65bd 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -60,6 +60,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen 
{
   bool visitIfStmt(const IfStmt *IS);
   bool visitWhileStmt(const WhileStmt *S);
   bool visitDoStmt(const DoStmt *S);
+  bool visitForStmt(const ForStmt *S);
   bool visitBreakStmt(const BreakStmt *S);
   bool visitContinueStmt(const ContinueStmt *S);
 

diff  --git a/clang/test/AST/Interp/loops.cpp b/clang/test/AST/Interp/loops.cpp
index 30a38ca573b28..4157f65e21688 100644
--- a/clang/test/AST/Interp/loops.cpp
+++ b/clang/test/AST/Interp/loops.cpp
@@ -187,3 +187,91 @@ namespace DoWhileLoop {
   }
 #endif
 };
+
+namespace ForLoop {
+  constexpr int f() {
+int i = 0;
+for (;false;) {
+  i = i + 1;
+}
+return i;
+  }
+  static_assert(f() == 0, "");
+
+  constexpr int f2() {
+int m = 0;
+for (int i = 0; i < 10; i = i + 1){
+  m = i;
+}
+return m;
+  }
+  static_assert(f2() == 9, "");
+
+  constexpr int f3() {
+int i = 0;
+for (; i != 5; i = i + 1);
+return i;
+  }
+  static_assert(f3() == 5, "");
+
+  constexpr int f4() {
+int i = 0;
+for (;;) {
+  i = i + 1;
+
+  if (i == 5)
+break;
+}
+return i;
+  }
+  static_assert(f4() == 5, "");
+
+  constexpr int f5() {
+int i = 0;
+for (;i != 5;) {
+  i = i + 1;
+  continue;
+  i = i - 1;
+}
+return i;
+  }
+  static_assert(f5() == 5, "");
+
+  constexpr int f6(bool b) {
+int i = 0;
+
+for (;true;) {
+  if (!b) {
+if (i == 5)
+  break;
+  }
+
+  if (b) {
+for (; i != 10; i = i + 1) {
+  if (i == 8)
+break;
+  continue;
+}
+  }
+
+  if (b)
+break;
+
+  i = i + 1;
+  continue;
+}
+
+return i;
+  }
+  static_assert(f6(true) == 8, "");
+  static_assert(f6(false) == 5, "");
+
+#if 0
+  /// FIXME: This is an infinite loop, which should
+  ///   be rejected.
+  constexpr int f6() {
+for(;;);
+  }
+#endif
+
+};



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


[PATCH] D135972: [clang-format] Don't crash on malformed preprocessor conditions

2022-10-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Format/FormatTest.cpp:5209
+  verifyNoCrash("#if X\n"
+"#else\n"
+"#else\n"

`#elif Y` instead of `#else`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135972

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


[PATCH] D136743: [HLSL] support ConstantBuffer

2022-10-25 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: pow2clk, beanz, bogner.
Herald added a subscriber: Anastasia.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Support ConstantBuffer by define it like

  template
  struct ConstantBuffer : public T {
  };


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136743

Files:
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/test/AST/HLSL/CBV.hlsl
  clang/test/SemaHLSL/BuiltIns/CBV.hlsl

Index: clang/test/SemaHLSL/BuiltIns/CBV.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BuiltIns/CBV.hlsl
@@ -0,0 +1,8 @@
+// RUN: not %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only -verify %s 2>&1 | FileCheck %s
+
+// CHECK:error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT:  (frontend): base specifier must name a class
+// CHECK:1 error generated
+
+// expected-note@+1 {{in instantiation of template class 'hlsl::ConstantBuffer' requested here}}
+ConstantBuffer CB;
Index: clang/test/AST/HLSL/CBV.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/CBV.hlsl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s
+
+// CHECK:-ClassTemplateDecl 0x{{[0-9a-f]+}} <>  implicit ConstantBuffer
+// CHECK-NEXT:-TemplateTypeParmDecl 0x{{[0-9a-f]+}} <>  class depth 0 index 0 element_type
+// CHECK-NEXT:-CXXRecordDecl 0x{{[0-9a-f]+}} <>  implicit class ConstantBuffer definition
+// CHECK:-public 'element_type'
+// CHECK-NEXT:-FinalAttr 0x{{[0-9a-f]+}} <> Implicit final
+// CHECK-NEXT:-HLSLResourceAttr 0x{{[0-9a-f]+}} <> Implicit CBuffer CBufferKind
+
+// CHECK:-CXXRecordDecl 0x{{[0-9a-f]+}}  col:8 implicit struct S
+// CHECK-NEXT:-FieldDecl 0x[[A:[0-9a-f]+]]  col:11 referenced a 'float'
+struct S {
+float a;
+};
+
+// CHECK:VarDecl 0x[[CB:[0-9a-f]+]]  col:19 used CB 'ConstantBuffer':'hlsl::ConstantBuffer'
+ConstantBuffer CB;
+
+float foo() {
+// CHECK:ReturnStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK-NEXT:-MemberExpr 0x{{[0-9a-f]+}}  'float' lvalue .a 0x[[A]]
+// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9a-f]+}}  'S' lvalue 
+// CHECK-NEXT:-DeclRefExpr 0x{{[0-9a-f]+}}  'ConstantBuffer':'hlsl::ConstantBuffer' lvalue Var 0x[[CB]] 'CB' 'ConstantBuffer':'hlsl::ConstantBuffer'
+return CB.a;
+}
Index: clang/lib/Sema/HLSLExternalSemaSource.cpp
===
--- clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -34,6 +34,7 @@
   ClassTemplateDecl *PrevTemplate = nullptr;
   NamespaceDecl *HLSLNamespace = nullptr;
   llvm::StringMap Fields;
+  llvm::SmallVector Bases;
 
   BuiltinTypeDeclBuilder(CXXRecordDecl *R) : Record(R) {
 Record->startDefinition();
@@ -306,6 +307,27 @@
 return *this;
   }
 
+  BuiltinTypeDeclBuilder &addBase(TypeDecl *Parent) {
+if (Record->isCompleteDefinition())
+  return *this;
+TypeSourceInfo *TInfo =
+HLSLNamespace->getASTContext().getTrivialTypeSourceInfo(
+QualType(Parent->getTypeForDecl(), 0));
+CXXBaseSpecifier Base(SourceRange(), false, false,
+  AccessSpecifier::AS_public, TInfo, SourceLocation());
+Bases.emplace_back(&Base);
+return *this;
+  }
+
+  BuiltinTypeDeclBuilder &setBases() {
+if (Record->isCompleteDefinition())
+  return *this;
+
+Record->setBases(Bases.data(), Bases.size());
+Bases.clear();
+return *this;
+  }
+
   TemplateParameterListBuilder addTemplateArgumentList();
 };
 
@@ -336,6 +358,13 @@
 return *this;
   }
 
+  TemplateParameterListBuilder &addTypeParameterAsBase(uint32_t I) {
+if (Params.size() <= I)
+  return *this;
+Builder.addBase(cast(Params[I]));
+return *this;
+  }
+
   BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
 if (Params.empty())
   return Builder;
@@ -466,6 +495,20 @@
  .addHandleMember(AccessSpecifier::AS_public)
  .completeDefinition()
  .Record;
+  // Add CBV as
+  // template
+  // struct ConstantBuffer : T {
+  // };
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConstantBuffer")
+  .startDefinition()
+  .addTemplateArgumentList()
+  .addTypeParameter("element_type")
+  .addTypeParameterAsBase(0)
+  .finalizeTemplateArgs()
+  .setBases()
+  .annotateResourceClass(HLSLResourceAttr::CBuffer,
+ HLSLResourceAttr::CBufferKind)
+  .completeDefinition();
 }
 
 void HLSLExternalSemaSource::forwardDeclareHLSLTypes() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136571: [RISCV] add svinval extension

2022-10-25 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 470722.
BeMg marked 2 inline comments as done.
BeMg added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/priv-valid.s

Index: llvm/test/MC/RISCV/priv-valid.s
===
--- llvm/test/MC/RISCV/priv-valid.s
+++ llvm/test/MC/RISCV/priv-valid.s
@@ -1,12 +1,12 @@
-# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
 
 # CHECK-INST: uret
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -37,6 +37,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV32SVNAPOT %s
+; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -74,6 +75,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
 ; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck --check-prefix=RV64SVNAPOT %s
+; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -114,6 +116,7 @@
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
 ; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
+; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -153,6 +156,7 @@
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
 ; RV64SVNAPOT: .attribute 5, "rv64i2p0_svnapot1p0"
+; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -86,6 +86,7 @@
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
   bool HasStdExtSvnapot = false;
+  bool HasStdExtSvinval = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -184,6 +185,7 @@
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
   bool hasStdExtSvnapot() const { return HasStdExtSvnapot; }
+  bool hasStdExtSvinval() const { return HasStdExtSvinval; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -796,6 +796,7 @@
   let rs2 = 0b00101;
 }
 
+l

[PATCH] D136435: [clang][Driver] Add gcc-toolset-12 and devtoolset-12 prefixes

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4a5184f4c357: [clang][driver] Remove dynamic 
gcc-toolset/devtoolset logic (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136435

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -20,7 +20,6 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/Host.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -394,96 +393,6 @@
   std::vector> Errors;
 };
 
-TEST(ToolChainTest, Toolsets) {
-  // Ignore this test on Windows hosts.
-  llvm::Triple Host(llvm::sys::getProcessTriple());
-  if (Host.isOSWindows())
-GTEST_SKIP();
-
-  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
-
-  // Check (newer) GCC toolset installation.
-  {
-IntrusiveRefCntPtr InMemoryFileSystem(
-new llvm::vfs::InMemoryFileSystem);
-
-// These should be ignored.
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--1", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-
-// File needed for GCC installation detection.
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-12/root/usr/lib/gcc/"
-"x86_64-redhat-linux/11/crtbegin.o",
-0, llvm::MemoryBuffer::getMemBuffer("\n"));
-
-DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
-Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
- "clang LLVM compiler", InMemoryFileSystem);
-std::unique_ptr C(
-TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
-ASSERT_TRUE(C);
-std::string S;
-{
-  llvm::raw_string_ostream OS(S);
-  C->getDefaultToolChain().printVerboseInfo(OS);
-}
-EXPECT_EQ("Found candidate GCC installation: "
-  "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Selected GCC installation: "
-  "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Candidate multilib: .;@m64\n"
-  "Selected multilib: .;@m64\n",
-  S);
-  }
-
-  // And older devtoolset.
-  {
-IntrusiveRefCntPtr InMemoryFileSystem(
-new llvm::vfs::InMemoryFileSystem);
-
-// These should be ignored.
-InMemoryFileSystem->addFile("/opt/rh/devtoolset-2", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/devtoolset-", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/devtoolset--", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/devtoolset--1", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-
-// File needed for GCC installation detection.
-InMemoryFileSystem->addFile("/opt/rh/devtoolset-12/root/usr/lib/gcc/"
-"x86_64-redhat-linux/11/crtbegin.o",
-0, llvm::MemoryBuffer::getMemBuffer("\n"));
-
-DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
-Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
- "clang LLVM compiler", InMemoryFileSystem);
-std::unique_ptr C(
-TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
-ASSERT_TRUE(C);
-std::string S;
-{
-  llvm::raw_string_ostream OS(S);
-  C->getDefaultToolChain().printVerboseInfo(OS);
-}
-EXPECT_EQ("Found candidate GCC installation: "
-  "/opt/rh/devtoolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Selected GCC installation: "
-  "/opt/rh/devtoolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Candidate multilib: .;@m64\n"
-  "Selected multilib: .;@m64\n",
-  S);
-  }
-}
-
 TEST(ToolChainTest, ConfigFileSearch) {
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   IntrusiveRefCn

[clang] 4a5184f - [clang][driver] Remove dynamic gcc-toolset/devtoolset logic

2022-10-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-26T07:29:32+02:00
New Revision: 4a5184f4c357eeafcced3371cd8539fa0ac9f24d

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

LOG: [clang][driver] Remove dynamic gcc-toolset/devtoolset logic

This breaks when the newest available devtoolset directory is not a
complete toolset: https://github.com/llvm/llvm-project/issues/57843

Remove this again in favor or just adding the two new directories for
devtoolset/gcc-toolset 12.

This reverts commit 35aaf548237a4f213ba9d95de53b33c5ce1eadce.
This reverts commit 9f97720268911abae2ad9d90e270358db234a1c1.

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

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9a172dbd057e4..ae0602d0bbf5d 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2162,31 +2162,21 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   // and gcc-toolsets.
   if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux &&
   D.getVFS().exists("/opt/rh")) {
-// Find the directory in /opt/rh/ starting with gcc-toolset-* or
-// devtoolset-* with the highest version number and add that
-// one to our prefixes.
-std::string ChosenToolsetDir;
-unsigned ChosenToolsetVersion = 0;
-std::error_code EC;
-for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin("/opt/rh", 
EC),
-   LE;
- !EC && LI != LE; LI = LI.increment(EC)) {
-  StringRef ToolsetDir = llvm::sys::path::filename(LI->path());
-  unsigned ToolsetVersion;
-  if ((!ToolsetDir.startswith("gcc-toolset-") &&
-   !ToolsetDir.startswith("devtoolset-")) ||
-  ToolsetDir.substr(ToolsetDir.rfind('-') + 1)
-  .getAsInteger(10, ToolsetVersion))
-continue;
-
-  if (ToolsetVersion > ChosenToolsetVersion) {
-ChosenToolsetVersion = ToolsetVersion;
-ChosenToolsetDir = "/opt/rh/" + ToolsetDir.str();
-  }
-}
-
-if (ChosenToolsetVersion > 0)
-  Prefixes.push_back(ChosenToolsetDir + "/root/usr");
+// TODO: We may want to remove this, since the functionality
+//   can be achieved using config files.
+Prefixes.push_back("/opt/rh/gcc-toolset-12/root/usr");
+Prefixes.push_back("/opt/rh/gcc-toolset-11/root/usr");
+Prefixes.push_back("/opt/rh/gcc-toolset-10/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-12/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-11/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-10/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-9/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-4/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-3/root/usr");
+Prefixes.push_back("/opt/rh/devtoolset-2/root/usr");
   }
 
   // Fall back to /usr which is used by most non-Solaris systems.

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index a9ac309bdc113..10b20a91aee27 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -20,7 +20,6 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/Host.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -394,96 +393,6 @@ struct SimpleDiagnosticConsumer : public 
DiagnosticConsumer {
   std::vector> Errors;
 };
 
-TEST(ToolChainTest, Toolsets) {
-  // Ignore this test on Windows hosts.
-  llvm::Triple Host(llvm::sys::getProcessTriple());
-  if (Host.isOSWindows())
-GTEST_SKIP();
-
-  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
-
-  // Check (newer) GCC toolset installation.
-  {
-IntrusiveRefCntPtr InMemoryFileSystem(
-new llvm::vfs::InMemoryFileSystem);
-
-// These should be ignored.
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-In

[PATCH] D136737: [Draft] [clang] Add builtin_unspecified_value

2022-10-25 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

The updates are analogous to how `GNUNullExprClass` is processed because 
`UnspecifiedValueExprClass` and it is similar (have no operand).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136737

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


[PATCH] D136737: [Draft] [clang] Add builtin_unspecified_value

2022-10-25 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune created this revision.
Herald added subscribers: steakhal, martong, arphaman.
Herald added a reviewer: shafik.
Herald added a reviewer: NoQ.
Herald added a project: All.
aqjune requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a builtin constant that lowers to `freeze(poison)`.
This is necessary to patch the intrinsics like e.g., `mm256_castsi128_si256` to 
be lowered to the following sequence:

  %a1 = freeze <2 x double> poison // <- would like to represent this as 
'__builtin_unspecified_value' in C/C++.
  %res = shufflevector <2 x double> %a0, <2 x double> %a1, <4 x i32> 

Currently it is being lowered to:

  %res = shufflevector <2x  double> %a0, undef, <4 x i32> 

The current lowering may incorrectly introduce undefined behavior.

A related, previous patch was here: https://reviews.llvm.org/D130339


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136737

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -475,6 +475,10 @@
 K = CXCursor_GNUNullExpr;
 break;
 
+  case Stmt::UnspecifiedValueExprClass:
+K = CXCursor_UnspecifiedValueExpr;
+break;
+
   case Stmt::CXXStaticCastExprClass:
 K = CXCursor_CXXStaticCastExpr;
 break;
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1889,6 +1889,7 @@
 case Stmt::ObjCSelectorExprClass:
 case Stmt::ParenListExprClass:
 case Stmt::ShuffleVectorExprClass:
+case Stmt::UnspecifiedValueExprClass:
 case Stmt::ConvertVectorExprClass:
 case Stmt::VAArgExprClass:
 case Stmt::CUDAKernelCallExprClass:
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1195,6 +1195,12 @@
   Code = serialization::EXPR_GNU_NULL;
 }
 
+void ASTStmtWriter::VisitUnspecifiedValueExpr(UnspecifiedValueExpr *E) {
+  VisitExpr(E);
+  Record.AddSourceLocation(E->getTokenLocation());
+  Code = serialization::EXPR_UNSPECIFIED_VALUE;
+}
+
 void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
   VisitExpr(E);
   Record.push_back(E->getNumSubExprs());
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1316,6 +1316,11 @@
   E->setTokenLocation(readSourceLocation());
 }
 
+void ASTStmtReader::VisitUnspecifiedValueExpr(UnspecifiedValueExpr *E) {
+  VisitExpr(E);
+  E->setTokenLocation(readSourceLocation());
+}
+
 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
   VisitExpr(E);
   SmallVector Exprs;
@@ -3077,6 +3082,10 @@
   S = new (Context) GNUNullExpr(Empty);
   break;
 
+case EXPR_UNSPECIFIED_VALUE:
+  S = new (Context) UnspecifiedValueExpr(Empty);
+  break;
+
 case EXPR_SHUFFLE_VECTOR:
   S = new (Context) ShuffleVectorExpr(Empty);
   break;
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -11719,6 +11719,12 @@
   return E;
 }
 
+template
+ExprResult
+TreeTransform::TransformUnspecifiedValueExpr(UnspecifiedValueExpr *E) {
+  return E;
+}
+
 template
 ExprResult
 TreeTransform::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Index: clang/lib/Sema/SemaExceptionSpec.cpp
===
--- clang/lib/Sema/SemaExceptionSpec.cpp
+++ clang/lib/Sema/SemaExceptionSpec.cpp
@@ -1404,6 +1404,7 @@
   case Expr::SourceLocExprClass:
   case Expr::ConceptSpecializationExprClass:
   case Expr::RequiresExprClass:
+  case Expr::UnspecifiedValueExprClass:
 // These expressions can never throw.
 return CT_Cannot;
 
Index: clang/lib/AST/StmtProfile.cpp
===
--- clang/lib/AST/StmtProfile.cpp
+++ clang/lib/AST/StmtProfile.cpp
@@ -1472,6 +1472

[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-25 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470702.
lime added a comment.

Update for the format check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4097,8 +4097,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool EvaluateConstraints) {
   TemplateDeclInstantiator Instantiator

[PATCH] D136564: [clang] Instantiate NTTPs and template default arguments with sugar

2022-10-25 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

This broke building Firefox with:

  In file included from Unified_cpp_dom_canvas0.cpp:65:
  /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:355:19: error: call to deleted 
function 'IdByMethod'
const auto id = IdByMethod();
^~
  /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:438:3: note: in instantiation of 
function template specialization 'mozilla::ClientWebGLContext::Run' requested here
Run(xrFb ? xrFb->mId : 0, type, webvr, asyncOptions);
^
  /tmp/gecko/dom/canvas/WebGLMethodDispatcher.h:20:8: note: candidate function 
[with MethodT = void (mozilla::HostWebGLContext::*)(unsigned long, 
mozilla::layers::TextureType, bool, const mozilla::webgl::SwapChainOptions &) 
const, Method = &mozilla::HostWebGLContext::Present] has been explicitly deleted
  size_t IdByMethod() = delete;
 ^
  In file included from Unified_cpp_dom_canvas0.cpp:65:
  /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:355:19: error: call to deleted 
function 'IdByMethod'
const auto id = IdByMethod();
^~
  /tmp/gecko/dom/canvas/ClientWebGLContext.cpp:447:3: note: in instantiation of 
function template specialization 'mozilla::ClientWebGLContext::Run' requested 
here
Run(fb ? fb->mId : 0, texType, asyncOptions);
^
  /tmp/gecko/dom/canvas/WebGLMethodDispatcher.h:20:8: note: candidate function 
[with MethodT = void (mozilla::HostWebGLContext::*)(unsigned long, 
mozilla::layers::TextureType, const mozilla::webgl::SwapChainOptions &) const, 
Method = &mozilla::HostWebGLContext::CopyToSwapChain] has been explicitly 
deleted
  size_t IdByMethod() = delete;
 ^

(etc.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136564

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

This broke building Firefox with:

  In file included from Unified_cpp_editor_txmgr0.cpp:2:
  In file included from /tmp/gecko/editor/txmgr/TransactionItem.cpp:6:
  In file included from /tmp/gecko/editor/txmgr/TransactionItem.h:9:
  In file included from 
/tmp/gecko/obj-x86_64-pc-linux-gnu/dist/include/nsCOMPtr.h:31:
  In file included from 
/tmp/gecko/obj-x86_64-pc-linux-gnu/dist/include/nsISupportsUtils.h:16:
  /tmp/gecko/obj-x86_64-pc-linux-gnu/dist/include/nsISupportsImpl.h:238:31: 
error: definition with same mangled name 
'_ZN27nsCycleCollectingAutoRefCnt4incrIXadL_Z25NS_CycleCollectorSuspect3mPvP28nsCycleCollectionParticipant'
 as another definition
MOZ_ALWAYS_INLINE uintptr_t incr(void* aOwner,
^
  /tmp/gecko/obj-x86_64-pc-linux-gnu/dist/include/nsISupportsImpl.h:238:31: 
note: previous definition is here
  /tmp/gecko/obj-x86_64-pc-linux-gnu/dist/include/nsISupportsImpl.h:266:31: 
error: definition with same mangled name 
'_ZN27nsCycleCollectingAutoRefCnt4decrIXadL_Z25NS_CycleCollectorSuspect3mPvP28nsCycleCollectionParticipantPb'
 as another definition
MOZ_ALWAYS_INLINE uintptr_t decr(void* aOwner,
^
  /tmp/gecko/obj-x86_64-pc-linux-gnu/dist/include/nsISupportsImpl.h:266:31: 
note: previous definition is here
  2 errors generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D104963: [ODR] Fix using uninitialized FunctionTypeBits.FastTypeQuals in FunctionNoProtoType.

2022-10-25 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai abandoned this revision.
vsapsai added a comment.
Herald added a project: All.

The issue is addressed in D133586 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104963

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-25 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470686.
lime added a comment.

Solve the conflicts, and the issue about `CMakeLists.txt` had been solved by 
upstream.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4097,8 +4097,10 @@
 
 TemplateParameterList *
 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool Eval

[PATCH] D135930: [X86] Add AVX-NE-CONVERT instructions.

2022-10-25 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsX86.def:2106-2107
+TARGET_BUILTIN(__builtin_ia32_vcvtneoph2ps256, "V8fV16xC*", "nV:256:", 
"avxneconvert")
+TARGET_BUILTIN(__builtin_ia32_vcvtneps2bf16128, "V8sV4f", "nV:128:", 
"avxneconvert")
+TARGET_BUILTIN(__builtin_ia32_vcvtneps2bf16256, "V8sV8f", "nV:256:", 
"avxneconvert")
 TARGET_HEADER_BUILTIN(_InterlockedAnd64, "WiWiD*Wi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")

These should be shared with AVX512-BF16.



Comment at: clang/lib/Headers/avxneconvertintrin.h:86-94
+static __inline__ __m128bh __DEFAULT_FN_ATTRS128
+_mm_cvtneps_avx_pbh(__m128 __A) {
+  return (__m128bh)__builtin_ia32_vcvtneps2bf16128((__v4sf)__A);
+}
+
+static __inline__ __m128bh __DEFAULT_FN_ATTRS256
+_mm256_cvtneps_avx_pbh(__m256 __A) {

Add unified intrinsics like AVXVNNI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135930

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


[PATCH] D136103: OpenMP asynchronous memory copy support

2022-10-25 Thread Jisheng Zhao via Phabricator via cfe-commits
jz10 updated this revision to Diff 470684.
jz10 added a comment.

Thanks Shilei

1. "Can you check all resolved comments to make sure there is no open comments?"

checked through the comments you and Johannes made, no more issues

2. "Since this function is not part of `libomp` and it's not gonna be an 
interface function, no need to name it as `__kmpc`."

revised helper functions' names


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

https://reviews.llvm.org/D136103

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/src/api.cpp
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/private.h
  openmp/libomptarget/test/api/omp_target_memcpy_async1.c
  openmp/libomptarget/test/api/omp_target_memcpy_async2.c
  openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
  openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c

Index: openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c
@@ -0,0 +1,89 @@
+// RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda
+
+#include 
+#include 
+
+#define NUM_DIMS 3
+
+int main () {
+  int d = omp_get_default_device ();
+  int id = omp_get_initial_device ();
+  int a[128], b[64], c[128], e[16], q[128], i;
+  void *p;
+  
+  if (d < 0 || d >= omp_get_num_devices ())
+d = id;
+
+  p = omp_target_alloc (130 * sizeof (int), d);
+  if (p == NULL)
+return 0;
+  
+  for (i = 0; i < 128; i++)
+q[i] = 0;
+  if (omp_target_memcpy (p, q, 128 * sizeof (int), 0, 0, d, id) != 0)
+abort ();
+  
+  size_t volume[NUM_DIMS] = { 2, 2, 3 };
+  size_t dst_offsets[NUM_DIMS] = { 0, 0, 0 };
+  size_t src_offsets[NUM_DIMS] = { 0, 0, 0 };
+  size_t dst_dimensions[NUM_DIMS] = { 3, 4, 5 };
+  size_t src_dimensions[NUM_DIMS] = { 2, 3, 4 };
+  
+  for (i = 0; i < 128; i++)
+a[i] = 42;
+  for (i = 0; i < 64; i++)
+b[i] = 24;
+  for (i = 0; i < 128; i++)
+c[i] = 0;
+  for (i = 0; i < 16; i++)
+e[i] = 77;
+
+  omp_depend_t obj[2];
+  
+#pragma omp parallel num_threads(5)
+#pragma omp single
+  {
+#pragma omp task depend (out: p)
+omp_target_memcpy (p, a, 128 * sizeof (int), 0, 0, d, id);
+
+#pragma omp task depend(inout: p)
+omp_target_memcpy (p, b, 64 * sizeof (int), 0, 0, d, id);
+
+#pragma omp task depend(out: c)
+for (i = 0; i < 128; i++)
+  c[i] = i + 1;
+
+#pragma omp depobj(obj[0]) depend(inout: p)
+#pragma omp depobj(obj[1]) depend(in: c)
+
+/*  This produces: 1 2 3 - - 5 6 7 - - at positions 0..9 and
+	13 14 15 - - 17 18 19 - - at positions 20..29.  */
+omp_target_memcpy_rect_async (p, c, sizeof (int), NUM_DIMS, volume,
+  dst_offsets, src_offsets, dst_dimensions,
+  src_dimensions, d, id, 2, obj);
+
+#pragma omp task depend(in: p)
+omp_target_memcpy (p, e, 16 * sizeof (int), 0, 0, d, id);
+  }
+  
+#pragma omp taskwait
+  
+  if (omp_target_memcpy (q, p, 128 * sizeof(int), 0, 0, id, d) != 0)
+abort ();
+  
+  for (i = 0; i < 16; ++i)
+if (q[i] != 77)
+  abort ();
+  if (q[20] != 13 || q[21] != 14 || q[22] != 15 || q[25] != 17 || q[26] != 18
+  || q[27] != 19)
+abort ();
+  for (i = 28; i < 64; ++i)
+if (q[i] != 24)
+  abort ();
+  for (i = 64; i < 128; ++i)
+   if (q[i] != 42)
+ abort ();
+  
+  omp_target_free (p, d);
+  return 0;
+}
Index: openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
@@ -0,0 +1,66 @@
+// RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda
+
+#include 
+#include 
+#include 
+
+#define NUM_DIMS 3
+
+int main() {
+  int d = omp_get_default_device ();
+  int id = omp_get_initial_device ();
+  int q[128], q2[128], i;
+  void *p;
+  
+  if (d < 0 || d >= omp_get_num_devices ())
+d = id;
+  
+  p = omp_target_alloc (130 * sizeof (int), d);
+  if (p == NULL)
+return 0;
+
+  if (omp_target_memcpy_rect_async (NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+NULL, d, id, 0, NULL) < 3
+  || omp_target_memcpy_rect_async (NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, id, d, 0, NULL) < 3
+  || omp_target_memcpy_rect_async (NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, id, id, 0, NULL) < 3)
+abort ();
+ 
+  for (i = 0; i < 128; i++)
+q[i] = 0;
+  if (omp_target_memcpy (p, q, 128 * sizeof (int), 0, 0, d, id) != 0)
+abort ();
+  
+  for (i = 0; i < 128; i++)
+q[i] = i + 1;
+  
+  size_t volume[NUM_DIMS] = { 1, 2, 3 };
+  size_t dst_offsets[NUM_DIMS] = { 0, 0, 0 };
+  size_t src_offsets[NUM_DIMS] = { 0, 0, 0 };
+  size_t dst_dimensions[NUM_DIMS] = { 3, 4, 5 };
+  size_t src_dimensions[NUM_DIMS] = { 2, 3, 4 };
+  
+  if (omp_target_memcpy_rect_async (p, q, sizeof (int), NUM_DIMS, volume,
+dst_offsets, src_offsets, dst_dimensions,

[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-25 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

(And specifically, FuzzerFork.cpp doesn't use any of those declared things. Its 
only sin is to `#include `, which happens to have /some/ methods 
(std::filesystem-related) only available on macos 10.15+.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-25 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

> In either case, this seems to be an issue with libc++ that is out there in 
> the wild.

I don't think it is, actually. I think it's doing something legitimate. That 
is, it's declaring in its headers that some things are only available on some 
versions of macos, which is fine if you don't use them, or if you use them in a 
block guarded with `__builtin_available`. The problem this patch introduces is 
that it makes it an error to even have those declarations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-25 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 470679.
lime added a comment.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Update as required. Also, I need the following modification to complete `ninja 
check-all`. Maybe, I should submit another patch.

  diff --git a/clang/unittests/Support/CMakeLists.txt 
b/clang/unittests/Support/CMakeLists.txt
  index 956b3a7561..2413088a2b 100644
  --- a/clang/unittests/Support/CMakeLists.txt
  +++ b/clang/unittests/Support/CMakeLists.txt
  @@ -9,4 +9,7 @@ add_clang_unittest(ClangSupportTests
   clang_target_link_libraries(ClangSupportTests
 PRIVATE
 clangFrontend
  +  clangAST
  +  clangSerialization
  +  clangBasic
 )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D134128
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0";>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -61,9 +61,9 @@
 
   // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
 
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
-
+template struct W { }; // #W
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F 1-2{{similar constraint expressions not considered equivalent}}
+// expected-note@#C 1-2{{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,25 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+tem

[PATCH] D136103: OpenMP asynchronous memory copy support

2022-10-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Generally looks good to me. Can you check all resolved comments to make sure 
there is no open comments?




Comment at: openmp/libomptarget/src/api.cpp:206
+// The helper function that calls omp_target_memcpy or omp_target_memcpy_rect
+static int __kmpc_target_memcpy_async_helper(kmp_int32 Gtid, kmp_task_t *Task) 
{
+  if (Task == nullptr)

same here



Comment at: openmp/libomptarget/src/api.cpp:238
+// Allocate and launch helper task
+static int __kmpc_helper_task_creation(TargetMemcpyArgsTy *Args,
+   int DepObjCount,

Since this function is not part of `libomp` and it's not gonna be an interface 
function, no need to name it as `__kmpc`.


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

https://reviews.llvm.org/D136103

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


[PATCH] D136103: OpenMP asynchronous memory copy support

2022-10-25 Thread Jisheng Zhao via Phabricator via cfe-commits
jz10 added a subscriber: jdoerfert.
jz10 added a comment.

hi Johannes and Shilei, is there revision that needs to be done on this
patch? please let me know


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

https://reviews.llvm.org/D136103

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


[PATCH] D136566: [clang] Instantiate concepts with sugared template arguments

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd0a6de59c780: [clang] Instantiate concepts with sugared 
template arguments (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D136566?vs=470013&id=470671#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136566

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/AST/ast-dump-concepts.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp
  clang/test/SemaTemplate/pr52970.cpp

Index: clang/test/SemaTemplate/pr52970.cpp
===
--- clang/test/SemaTemplate/pr52970.cpp
+++ clang/test/SemaTemplate/pr52970.cpp
@@ -53,7 +53,7 @@
 #if __cplusplus >= 202002L
 template 
 concept C = requires(T t) { t.begin(); };
-  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Holder *' is a pointer}}
+  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Bad' (aka 'Holder *') is a pointer}}
 
 static_assert(C);
 static_assert(!C);
Index: clang/test/SemaTemplate/instantiate-requires-expr.cpp
===
--- clang/test/SemaTemplate/instantiate-requires-expr.cpp
+++ clang/test/SemaTemplate/instantiate-requires-expr.cpp
@@ -76,8 +76,8 @@
   // expected-note@-2 {{because 'false_v::temp >; }>' evaluated to false}}
   struct r2 {};
 
-  using r2i1 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = type_requirement::contains_template]}}
-  using r2i2 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = type_requirement::contains_template]}}
+  using r2i1 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = contains_template]}}
+  using r2i2 = r2>; // expected-error{{constraints not satisfied for class template 'r2' [with T = contains_template]}}
 
   // substitution error occurs, then requires expr is instantiated again
 
@@ -108,7 +108,7 @@
   // expected-note@-1 {{because 'false_v>; } && requires { <>; }>' evaluated to false}}
   struct r7 {};
 
-  using r7i = r7; // expected-error{{constraints not satisfied for class template 'r7' [with Ts = ]}}
+  using r7i = r7; // expected-error{{constraints not satisfied for class template 'r7' [with Ts = ]}}
 }
 
 namespace expr_requirement {
@@ -227,3 +227,13 @@
 
 using r6i = r6;
 // expected-error@-1 {{constraints not satisfied for class template 'r6' [with T = int]}}
+
+namespace sugared_instantiation {
+  template  concept C = requires { C1{}; };
+  template  concept D = requires { new D1; };
+
+  // Test that 'deduced auto' doesn't get confused with 'undeduced auto'.
+  auto f() { return 0; }
+  static_assert(requires { { f() } -> C; });
+  static_assert(requires { { f() } -> D; });
+} // namespace sugared_instantiation
Index: clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
===
--- clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
+++ clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
@@ -14,15 +14,13 @@
 namespace a {
   struct A {};
   constexpr void f(A a) {}
-}
 
-static_assert(C);
-static_assert(foo());
+  static_assert(C);
+  static_assert(foo());
 
-namespace a {
   // This makes calls to f ambiguous, but the second check will still succeed
   // because the constraint satisfaction results are cached.
   constexpr void f(A a, int = 2) {}
-}
-static_assert(C);
-static_assert(foo());
+  static_assert(C);
+  static_assert(foo());
+} // namespace a
Index: clang/test/CXX/temp/temp.param/p10-2a.cpp
===
--- clang/test/CXX/temp/temp.param/p10-2a.cpp
+++ clang/test/CXX/temp/temp.param/p10-2a.cpp
@@ -94,8 +94,8 @@
 // expected-note@-5 {{and 'is_same_v' evaluated to false}}
 // expected-note@-6 3{{because 'is_same_v' evaluated to false}}
 // expected-note@-7 3{{and 'is_same_v' evaluated to false}}
-// expected-note@-8 2{{because 'is_same_v' evaluated to false}}
-// expected-note@-9 2{{and 'is_same_v' evaluated to false}}
+// expected-note@-8 2{{because 'is_same_v' evaluated to false}}
+// expected-note@-9 2{{and 'is_same_v' evaluated to false}}
 
 template T, OneOf U>
 // expected-note@-1 2{{because 

[clang] d0a6de5 - [clang] Instantiate concepts with sugared template arguments

2022-10-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T03:24:20+02:00
New Revision: d0a6de59c78010118fea811514e03ed9f400215a

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

LOG: [clang] Instantiate concepts with sugared template arguments

Since we don't unique specializations for concepts, we can just instantiate
them with the sugared template arguments, at negligible cost.

If we don't track their specializations, we can't resugar them later
anyway, and that would be more expensive than just instantiating them
sugared in the first place since it would require an additional pass.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/AST/ast-dump-concepts.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
clang/test/CXX/temp/temp.param/p10-2a.cpp
clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
clang/test/SemaTemplate/instantiate-requires-expr.cpp
clang/test/SemaTemplate/pr52970.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 83b23b249d4e8..ff1f650a52084 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1077,7 +1077,7 @@ static bool substituteParameterMappings(Sema &S, 
NormalizedConstraint &N,
   TemplateArgumentList TAL{TemplateArgumentList::OnStack,
CSE->getTemplateArguments()};
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-  CSE->getNamedConcept(), /*Final=*/false, &TAL,
+  CSE->getNamedConcept(), /*Final=*/true, &TAL,
   /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr,
   /*ForConstraintInstantiation=*/true);

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 25eeab370eeb8..bb9cfe30e5d4d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1475,53 +1475,57 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
   // C++2b:
   //   Otherwise, if the type contains a placeholder type, it is replaced by 
the
   //   type determined by placeholder type deduction.
-  DeducedType *Deduced = Ty->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
-Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity,
- Kind, Exprs);
-if (Ty.isNull())
-  return ExprError();
-Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
-  } else if (Deduced) {
-MultiExprArg Inits = Exprs;
-if (ListInitialization) {
-  auto *ILE = cast(Exprs[0]);
-  Inits = MultiExprArg(ILE->getInits(), ILE->getNumInits());
-}
+  if (const DeducedType *Deduced = Ty->getContainedDeducedType();
+  Deduced && !Deduced->isDeduced()) {
+if (isa(Deduced)) {
+  Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity, Kind,
+   Exprs);
+  if (Ty.isNull())
+return ExprError();
+  Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
+} else {
+  assert(isa(Deduced));
+  MultiExprArg Inits = Exprs;
+  if (ListInitialization) {
+auto *ILE = cast(Exprs[0]);
+Inits = MultiExprArg(ILE->getInits(), ILE->getNumInits());
+  }
 
-if (Inits.empty())
-  return ExprError(Diag(TyBeginLoc, diag::err_auto_expr_init_no_expression)
-   << Ty << FullRange);
-if (Inits.size() > 1) {
-  Expr *FirstBad = Inits[1];
-  return ExprError(Diag(FirstBad->getBeginLoc(),
-diag::err_auto_expr_init_multiple_expressions)
-   << Ty << FullRange);
-}
-if (getLangOpts().CPlusPlus2b) {
-  if (Ty->getAs())
-Diag(TyBeginLoc, diag::warn_cxx20_compat_auto_expr) << FullRange;
-}
-Expr *Deduce = Inits[0];
-if (isa(Deduce))
-  return ExprError(
-  Diag(Deduce->getBeginLoc(), diag::err_auto_expr_init_paren_braces)
-  << ListInitialization << Ty << FullRange);
-QualType DeducedType;
-TemplateDeductionInfo Info(Deduce->getExprLoc());
-TemplateDeductionResult Result =
-DeduceAutoType(TInfo->getTypeLoc(), Deduce, DeducedType, Info);
-if (Result != TDK_Success && Result != TDK_AlreadyDi

[PATCH] D136565: [clang] Instantiate alias templates with sugar

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c44c91ad980: [clang] Instantiate alias templates with sugar 
(authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136565

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  
lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Index: lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
@@ -24,9 +24,9 @@
  result_type="std::weak_ptr",
  result_summary="3 strong=1 weak=2",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*w.lock()", result_type="int", result_value="3")
-self.expect_expr("*w.lock() = 5", result_type="int", result_value="5")
-self.expect_expr("*w.lock()", result_type="int", result_value="5")
+self.expect_expr("*w.lock()", result_type="element_type", result_value="3")
+self.expect_expr("*w.lock() = 5", result_type="element_type", result_value="5")
+self.expect_expr("*w.lock()", result_type="element_type", result_value="5")
 self.expect_expr("w.use_count()", result_type="long", result_value="1")
 self.expect("expr w.reset()")
 self.expect_expr("w.use_count()", result_type="long", result_value="0")
Index: lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
@@ -23,7 +23,7 @@
 self.expect_expr("w",
  result_type="std::weak_ptr",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*w.lock()", result_type="Foo")
+self.expect_expr("*w.lock()", result_type="element_type")
 self.expect_expr("w.lock()->a", result_type="int", result_value="3")
 self.expect_expr("w.lock()->a = 5",
  result_type="int",
Index: lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
@@ -24,9 +24,9 @@
  result_type="std::shared_ptr",
  result_summary="3 strong=1 weak=1",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*s", result_type="int", result_value="3")
-self.expect_expr("*s = 5", result_type="int", result_value="5")
-self.expect_expr("*s", result_type="int", result_value="5")
+self.expect_expr("*s", result_type="element_type", result_value="3")
+self.expect_expr("*s = 5", result_type="element_type", result_value="5")
+self.expect_expr("*s", result_type="element_type", result_value="5")
 self.expect_expr("(bool)s", result_type="bool", result_value="true")
 self.expect("expr s.reset()")
 self.expect_expr("(bool)s", result_type="bool", result_value="false")
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template class X> struct A {
 template N> struct B; // expected-note 2{{here}}
-template struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'type-parameter-0-0 *')}}
+template  struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'T *')}}

[clang] 4c44c91 - [clang] Instantiate alias templates with sugar

2022-10-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T03:23:24+02:00
New Revision: 4c44c91ad980304c5cca3792115349e68cfafd2b

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

LOG: [clang] Instantiate alias templates with sugar

This makes use of the changes introduced in D134604, in order to
instantiate alias templates witn a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/test/CXX/temp/temp.deduct.guide/p3.cpp
clang/test/Misc/diag-template-diffing.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 9f64defaf898f..8bca0dc974539 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1067,7 +1067,7 @@ class Foo final {})cpp";
  HI.LocalScope = "";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "template  using AA = A";
- HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
+ HI.Type = {"A", "T"};
  HI.TemplateParameters = {{{"typename"}, std::string("T"), 
llvm::None}};
}},
   {// Constant array

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 37eaa2a5795aa..c5a86486b2dea 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3854,8 +3854,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 
 // Only substitute for the innermost template argument list.
 MultiLevelTemplateArgumentList TemplateArgLists;
-TemplateArgLists.addOuterTemplateArguments(Template, CanonicalConverted,
-   /*Final=*/false);
+TemplateArgLists.addOuterTemplateArguments(Template, SugaredConverted,
+   /*Final=*/true);
 TemplateArgLists.addOuterRetainedLevels(
 AliasTemplate->getTemplateParameters()->getDepth());
 

diff  --git a/clang/test/AST/ast-dump-template-decls.cpp 
b/clang/test/AST/ast-dump-template-decls.cpp
index 49760d17c7f22..3bc0357d1b51f 100644
--- a/clang/test/AST/ast-dump-template-decls.cpp
+++ b/clang/test/AST/ast-dump-template-decls.cpp
@@ -120,8 +120,6 @@ using type2 = typename C::type1;
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 
0 index 0 U
-// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 
index 0 T
 // CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
@@ -129,38 +127,24 @@ using type2 = typename C::type1;
 } // namespace PR55886
 
 namespace PR56099 {
-template  struct Y;
-template  using Z = Y;
-template  struct foo {
-  template  using bind = Z;
-};
-using t1 = foo::bind;
-// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename 
depth 0 index 0 ... Bs pack_index 3
-// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename 
depth 0 index 0 ... Bs pack_index 2
-// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename 
depth 0 index 0 ... Bs pack_index 1
-// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename 
depth 0 index 0 ... Bs pack_index 0
-// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-
 template  struct D {
-  template  using B = int(int (*...p)(T, U));
+  template  struct bind {
+using bound_type = int(int (*...p)(T, U));
+  };
 };
-using t2 = D::B;
-// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'B' sugar 
alias B
+templ

[PATCH] D136564: [clang] Instantiate NTTPs and template default arguments with sugar

2022-10-25 Thread Matheus Izvekov 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 rG2560c1266993: [clang] Instantiate NTTPs and template default 
arguments with sugar (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136564

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaTemplate/instantiation-default-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp

Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -69,14 +69,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 
   using test4 = __make_integer_seq;
@@ -88,14 +88,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template A
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T' 
 // CHECK-NEXT: `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 
   using test5 = __make_integer_seq;
Index: clang/test/SemaTemplate/instantiation-default-1.cpp
===
--- clang/test/SemaTemplate/instantiation-default-1.cpp
+++ clang/test/SemaTemplate/instantiation-default-1.cpp
@@ -33,7 +33,7 @@
 }
 
 typedef int& int_ref_t;
-Def2 *d2; // expected-note{{in instantiation of default argument for 'Def2' required here}}
+Def2 *d2; // expected-note{{in instantiation of default argument for 'Def2' required here}}
 
 
 template<> struct Def1 { }; // expected-error{{redefinition of 'Def1'}}
Index: clang/test/Misc/diag-template-diffing.cpp
===
--- clang/test/Misc/diag-template-diffing.cpp
+++ clang/test/Misc/diag-template-diffing.cpp
@@ -1454,7 +1454,7 @@
   D(VectorType());
 }
 // CHECK-ELIDE-NOTREE: error: no matching function for call to 'D'
-// CHECK-ELIDE-NOTREE: note: candidate function template not viable: no known conversion from 'VectorType' to 'const VectorType<(TypeAlias::X)0>' for 1st argument
+// CHECK-ELIDE-NOTREE: note: candidate function template not viable: no known conversion from 'VectorType' to 'const VectorType<(X)0>' for 1st argument
 }
 
 namespace TypeAlias2 {
Index: clang/test/CXX/expr/expr.const/p3-0x.cpp
===
--- clang/test/CXX/expr/expr.const/p3-0x.cpp
+++ clang/test/CXX/expr/expr.const/p3-0x.cpp
@@ -88,7 +88,7 @@
 Val remove_noexcept;
 Val add_noexcept;
 #if __cplusplus > 201402L
-// expected-error@-2 {{value of type 'void (*)() noexcept(fals

[clang] 2560c12 - [clang] Instantiate NTTPs and template default arguments with sugar

2022-10-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T03:22:22+02:00
New Revision: 2560c1266993af6e6c15900ce673c6db23132f8b

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

LOG: [clang] Instantiate NTTPs and template default arguments with sugar

This makes use of the changes introduced in D134604, in order to
instantiate non-type template parameters and default template arguments
with a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.const/p3-0x.cpp
clang/test/Misc/diag-template-diffing.cpp
clang/test/SemaTemplate/instantiation-default-1.cpp
clang/test/SemaTemplate/make_integer_seq.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d0757f874303f..37ad78f3d7969 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8199,14 +8199,11 @@ class Sema final {
 SourceLocation TemplateLoc,
 Declarator &D);
 
-  TemplateArgumentLoc
-  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
-  SourceLocation TemplateLoc,
-  SourceLocation RAngleLoc,
-  Decl *Param,
-  SmallVectorImpl
-&Converted,
-  bool &HasDefaultArg);
+  TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(
+  TemplateDecl *Template, SourceLocation TemplateLoc,
+  SourceLocation RAngleLoc, Decl *Param,
+  ArrayRef SugaredConverted,
+  ArrayRef CanonicalConverted, bool &HasDefaultArg);
 
   /// Specifies the context in which a particular template
   /// argument is being checked.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 73c681035b161..37eaa2a5795aa 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5261,27 +5261,25 @@ bool Sema::CheckTemplateTypeArgument(
 /// \param Converted the list of template arguments provided for template
 /// parameters that precede \p Param in the template parameter list.
 /// \returns the substituted template argument, or NULL if an error occurred.
-static TypeSourceInfo *
-SubstDefaultTemplateArgument(Sema &SemaRef,
- TemplateDecl *Template,
- SourceLocation TemplateLoc,
- SourceLocation RAngleLoc,
- TemplateTypeParmDecl *Param,
- SmallVectorImpl &Converted) {
+static TypeSourceInfo *SubstDefaultTemplateArgument(
+Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc,
+SourceLocation RAngleLoc, TemplateTypeParmDecl *Param,
+ArrayRef SugaredConverted,
+ArrayRef CanonicalConverted) {
   TypeSourceInfo *ArgType = Param->getDefaultArgumentInfo();
 
   // If the argument type is dependent, instantiate it now based
   // on the previously-computed template arguments.
   if (ArgType->getType()->isInstantiationDependentType()) {
-Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc,
- Param, Template, Converted,
+Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc, Param, Template,
+ SugaredConverted,
  SourceRange(TemplateLoc, RAngleLoc));
 if (Inst.isInvalid())
   return nullptr;
 
 // Only substitute for the innermost template argument list.
-MultiLevelTemplateArgumentList TemplateArgLists(Template, Converted,
-/*Final=*/false);
+MultiLevelTemplateArgumentList TemplateArgLists(Template, SugaredConverted,
+/*Final=*/true);
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
@@ -5320,22 +5318,20 @@ SubstDefaultTemplateArgument(Sema &SemaRef,
 /// parameters that precede \p Param in the template parameter list.
 ///
 /// \returns the substituted template argument, or NULL if an error occurred.
-static ExprResult
-SubstDefaultTemplateArgument(Sema &SemaRef,
-

[PATCH] D134604: [clang] Implement sugared substitution changes to infrastructure

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4c2a3c65684: [clang] Implement sugared substitution changes 
to infrastructure (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/test/SemaTemplate/nested-name-spec-template.cpp

Index: clang/test/SemaTemplate/nested-name-spec-template.cpp
===
--- clang/test/SemaTemplate/nested-name-spec-template.cpp
+++ clang/test/SemaTemplate/nested-name-spec-template.cpp
@@ -147,3 +147,10 @@
 
   template void f(); // expected-note{{in instantiation of}}
 }
+
+namespace sugared_template_instantiation {
+  // Test that we ignore local qualifiers.
+  template  struct A {};
+  struct B { typedef int type1; };
+  typedef A type2;
+} // namespace sugated_template_instantiation
Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -64,6 +64,10 @@
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L);
 
+  /// Pushes 'T' with all locations pointing to 'Loc'.
+  /// The builder must be empty for this to work.
+  void pushTrivial(ASTContext &Context, QualType T, SourceLocation Loc);
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
Index: clang/lib/Sema/TypeLocBuilder.cpp
===
--- clang/lib/Sema/TypeLocBuilder.cpp
+++ clang/lib/Sema/TypeLocBuilder.cpp
@@ -41,6 +41,29 @@
   }
 }
 
+void TypeLocBuilder::pushTrivial(ASTContext &Context, QualType T,
+ SourceLocation Loc) {
+  auto L = TypeLoc(T, nullptr);
+  reserve(L.getFullDataSize());
+
+  SmallVector TypeLocs;
+  for (auto CurTL = L; CurTL; CurTL = CurTL.getNextTypeLoc())
+TypeLocs.push_back(CurTL);
+
+  for (const auto &CurTL : llvm::reverse(TypeLocs)) {
+switch (CurTL.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: {   \
+auto NewTL = push(CurTL.getType());  \
+NewTL.initializeLocal(Context, Loc);   \
+break; \
+  }
+#include "clang/AST/TypeLocNodes.def"
+}
+  }
+}
+
 void TypeLocBuilder::grow(size_t NewCapacity) {
   assert(NewCapacity > Capacity);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -636,6 +636,14 @@
   QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
 #include "clang/AST/TypeLocNodes.def"
 
+  QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
+ TemplateTypeParmTypeLoc TL,
+ bool SuppressObjCLifetime);
+  QualType
+  TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
+ SubstTemplateTypeParmPackTypeLoc TL,
+ bool SuppressObjCLifetime);
+
   template
   QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
   FunctionProtoTypeLoc TL,
@@ -1285,9 +1293,10 @@
   /// template name. Subclasses may override this routine to provide different
   /// behavior.
   TemplateName RebuildTemplateName(const TemplateArgument &ArgPack,
-   Decl *AssociatedDecl, unsigned Index) {
+   Decl *AssociatedDecl, unsigned Index,
+   bool Final) {
 return getSema().Context.getSubstTemplateTemplateParmPack(
-ArgPack, AssociatedDecl, Index);
+ArgPack, AssociatedDecl, Index, Final);
   }
 
   /// Build a new compound statemen

[clang] c4c2a3c - [clang] Implement sugared substitution changes to infrastructure

2022-10-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T03:21:15+02:00
New Revision: c4c2a3c65684e062efcd101a957c6cae0a304a7a

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

LOG: [clang] Implement sugared substitution changes to infrastructure

Implements the changes required to perform substitution with
non-canonical template arguments, and to 'finalize' them
by not placing 'Subst' nodes.

A finalized substitution means we won't resugar them later,
because these templates themselves were eagerly substituted
with the intended arguments at the point of use. We may still
resugar other templates used within those, though.

This patch does not actually implement any uses of this
functionality, those will be added in subsequent patches,
so expect no changes to existing tests.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/TemplateName.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/Template.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Sema/TypeLocBuilder.cpp
clang/lib/Sema/TypeLocBuilder.h
clang/test/SemaTemplate/nested-name-spec-template.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a6b3301f2a73a..2a21f2d1f37ee 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1621,7 +1621,7 @@ class ASTContext : public RefCountedBase {
 Decl *AssociatedDecl, unsigned Index,
 Optional PackIndex) const;
   QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
-unsigned Index,
+unsigned Index, bool Final,
 const TemplateArgument &ArgPack);
 
   QualType
@@ -2207,7 +2207,8 @@ class ASTContext : public RefCountedBase {
 Optional PackIndex) 
const;
   TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument 
&ArgPack,
 Decl *AssociatedDecl,
-unsigned Index) const;
+unsigned Index,
+bool Final) const;
 
   enum GetBuiltinTypeError {
 /// No error

diff  --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index 9fe80440953f4..f952b08502db1 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -730,8 +730,11 @@ let Class = PropertyTypeCase in {
   def : Property<"index", UInt32> {
 let Read = [{ parm->getIndex() }];
   }
+  def : Property<"final", Bool> {
+let Read = [{ parm->getFinal() }];
+  }
   def : Creator<[{
-return ctx.getSubstTemplateTemplateParmPack(argumentPack, associatedDecl, 
index);
+return ctx.getSubstTemplateTemplateParmPack(argumentPack, associatedDecl, 
index, final);
   }]>;
 }
 

diff  --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 25aa991d3b841..82bbe72d22e58 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -139,25 +139,24 @@ class OverloadedTemplateStorage : public 
UncommonTemplateNameStorage {
 class SubstTemplateTemplateParmPackStorage : public 
UncommonTemplateNameStorage,
  public llvm::FoldingSetNode {
   const TemplateArgument *Arguments;
-  Decl *AssociatedDecl;
+  llvm::PointerIntPair AssociatedDeclAndFinal;
 
 public:
   SubstTemplateTemplateParmPackStorage(ArrayRef ArgPack,
-   Decl *AssociatedDecl, unsigned Index)
-  : UncommonTemplateNameStorage(SubstTemplateTemplateParmPack, Index,
-ArgPack.size()),
-Arguments(ArgPack.data()), AssociatedDecl(AssociatedDecl) {
-assert(AssociatedDecl != nullptr);
-  }
+   Decl *AssociatedDecl, unsigned Index,
+

[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(In other words, all known people who care about clang's determinism do not 
care about having the command recorded in the debug data -- and some (me :) ) 
mentioned concerns about determinism about the patch adding that feature. It 
seems weird to put those people on the hook to fix the bugs, then.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> This is true, but the cc1 flag isn't inherently non-deterministic. I would 
> prefer to fix the determinism bugs instead of adding flags and more 
> divergence.

See https://reviews.llvm.org/D136474#3875546


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136311: [CUDA,NVPTX] Implement __bf16 support for NVPTX.

2022-10-25 Thread Allen zhong via Phabricator via cfe-commits
Allen added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:186
+ !eq(name, "v2f16"): Float16x2Regs,
+ !eq(name, "bf16"): Float16Regs,
+ !eq(name, "v2bf16"): Float16x2Regs,

tra wrote:
> tra wrote:
> > Allen wrote:
> > > sorry for a basic question: what's the different between bf16 and f16 ?
> > https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
> > 
> If your question is why both bf16 and f16 use Float16Regs, then the answer is 
> that both use 'untyped' 16-bit *integer * registers.
> The difference from Int16Regs is that those are signed. PTX has some awkward 
> restrictions on matching instructions and register kinds, even though under 
> the hood it all boils down to everything using 32-bit registers.
Thanks for your explanation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136311

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


[PATCH] D136725: [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

(I'm sure this doesn't matter much, I just ran into it while trying to 
understand lifetimes of various macro description objects)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136725

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


[PATCH] D136725: [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This list was originally used for to make sure MacroInfo's clever memory
management got called (1f1e4bdbf7815c), but that was
simplified in 73a29662b9bf640a and 1f1e4bdbf7815c, and there's nothing left.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136725

Files:
  clang/include/clang/Lex/MacroInfo.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/Preprocessor.cpp


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -165,12 +165,6 @@
 
   IncludeMacroStack.clear();
 
-  // Destroy any macro definitions.
-  while (MacroInfoChain *I = MIChainHead) {
-MIChainHead = I->Next;
-I->~MacroInfoChain();
-  }
-
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
   // before the code below that frees up the MacroArgCache list.
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -57,9 +57,8 @@
 
//===--===//
 
 MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
-  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};
-  MIChainHead = MIChain;
-  return &MIChain->MI;
+  static_assert(std::is_trivially_destructible_v, "");
+  return new (BP) MacroInfo(L);
 }
 
 DefMacroDirective *Preprocessor::AllocateDefMacroDirective(MacroInfo *MI,
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1011,15 +1011,6 @@
   /// invoked (at which point the last position is popped).
   std::vector BacktrackPositions;
 
-  struct MacroInfoChain {
-MacroInfo MI;
-MacroInfoChain *Next;
-  };
-
-  /// MacroInfos are managed as a chain for easy disposal.  This is the head
-  /// of that list.
-  MacroInfoChain *MIChainHead = nullptr;
-
   /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
   /// This is used to guard against calling this function recursively.
   ///
Index: clang/include/clang/Lex/MacroInfo.h
===
--- clang/include/clang/Lex/MacroInfo.h
+++ clang/include/clang/Lex/MacroInfo.h
@@ -117,9 +117,8 @@
   /// Whether this macro was used as header guard.
   bool UsedForHeaderGuard : 1;
 
-  // Only the Preprocessor gets to create and destroy these.
+  // Only the Preprocessor gets to create these.
   MacroInfo(SourceLocation DefLoc);
-  ~MacroInfo() = default;
 
 public:
   /// Return the location that the macro was defined at.


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -165,12 +165,6 @@
 
   IncludeMacroStack.clear();
 
-  // Destroy any macro definitions.
-  while (MacroInfoChain *I = MIChainHead) {
-MIChainHead = I->Next;
-I->~MacroInfoChain();
-  }
-
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
   // before the code below that frees up the MacroArgCache list.
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -57,9 +57,8 @@
 //===--===//
 
 MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
-  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};
-  MIChainHead = MIChain;
-  return &MIChain->MI;
+  static_assert(std::is_trivially_destructible_v, "");
+  return new (BP) MacroInfo(L);
 }
 
 DefMacroDirective *Preprocessor::AllocateDefMacroDirective(MacroInfo *MI,
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1011,15 +1011,6 @@
   /// invoked (at which point the last position is popped).
   std::vector BacktrackPositions;
 
-  struct MacroInfoChain {
-MacroInfo MI;
-MacroInfoChain *Next;
-  };
-
-  /// MacroInfos are managed as a chain for easy disposal.  This is the head
-  /// of that list.
-  MacroInfoChain *MIChainHead = nullptr;
-
   /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
   /// This is used to guard against calling this function recursively.
   ///
Index: clang/include/clang/Lex/MacroInfo.h

[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-25 Thread Michele Scandale via Phabricator via cfe-commits
michele.scandale added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1865-1869
+if ((LangOpts.FastMath ||
+ !LangOpts.FastMath && LangOpts.AllowFPReassoc && LangOpts.AllowRecip 
&&
+ !LangOpts.FiniteMathOnly && LangOpts.NoSignedZero &&
+ LangOpts.ApproxFunc) &&
+LangOpts.getDefaultFPContractMode() != 
LangOptions::FPModeKind::FPM_Off)

zahiraam wrote:
> michele.scandale wrote:
> > If I look at the clang driver code, `-funsafe-math-optimizations` is 
> > specified on the CC1 command line if
> > ```
> > !MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && 
> > ApproxFunc && !TrappingMath
> > ```
> > is true.
> > This means that it shouldn't matter the value of the floating point 
> > contraction, or whether infs/nans are honored or not.
> > 
> > Was there another issue that this specific part of the change addresses?
> This is to make sure that if we are using -ffast-math or 
> -funsafe-math-optimization along with -ffp-contract=off, fma instructions are 
> not generated.  In this case the function shouldn't be marked with the 
> unsafe-fp-math attribute.
> This is to make sure that if we are using -ffast-math or 
> -funsafe-math-optimization along with -ffp-contract=off, fma instructions are 
> not generated.  In this case the function shouldn't be marked with the 
> unsafe-fp-math attribute.

If I understand correctly this is because the function attribute 
`unsafe-fp-math` from backends perspective allow any kind of contraction?
If so, shouldn't then this be valid only when the fp-contraction mode is 
`fast`, given that `on` means that only in-statement contraction is allowed, 
and clang handles that by generating `llvm.fmuladd` to lower expressions like 
`a * b + c` in given statement?

What about the `!LangOpts.FiniteMathOnly` part? I'd would think this shouldn't 
be checked at all as there are separate function attributes for infs and nans.



Comment at: clang/lib/CodeGen/CGCall.cpp:1865-1869
+if ((LangOpts.FastMath ||
+ !LangOpts.FastMath && LangOpts.AllowFPReassoc && LangOpts.AllowRecip 
&&
+ !LangOpts.FiniteMathOnly && LangOpts.NoSignedZero &&
+ LangOpts.ApproxFunc) &&
+LangOpts.getDefaultFPContractMode() != 
LangOptions::FPModeKind::FPM_Off)

michele.scandale wrote:
> zahiraam wrote:
> > michele.scandale wrote:
> > > If I look at the clang driver code, `-funsafe-math-optimizations` is 
> > > specified on the CC1 command line if
> > > ```
> > > !MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && 
> > > ApproxFunc && !TrappingMath
> > > ```
> > > is true.
> > > This means that it shouldn't matter the value of the floating point 
> > > contraction, or whether infs/nans are honored or not.
> > > 
> > > Was there another issue that this specific part of the change addresses?
> > This is to make sure that if we are using -ffast-math or 
> > -funsafe-math-optimization along with -ffp-contract=off, fma instructions 
> > are not generated.  In this case the function shouldn't be marked with the 
> > unsafe-fp-math attribute.
> > This is to make sure that if we are using -ffast-math or 
> > -funsafe-math-optimization along with -ffp-contract=off, fma instructions 
> > are not generated.  In this case the function shouldn't be marked with the 
> > unsafe-fp-math attribute.
> 
> If I understand correctly this is because the function attribute 
> `unsafe-fp-math` from backends perspective allow any kind of contraction?
> If so, shouldn't then this be valid only when the fp-contraction mode is 
> `fast`, given that `on` means that only in-statement contraction is allowed, 
> and clang handles that by generating `llvm.fmuladd` to lower expressions like 
> `a * b + c` in given statement?
> 
> What about the `!LangOpts.FiniteMathOnly` part? I'd would think this 
> shouldn't be checked at all as there are separate function attributes for 
> infs and nans.
> This is to make sure that if we are using -ffast-math or 
> -funsafe-math-optimization along with -ffp-contract=off, fma instructions are 
> not generated.  In this case the function shouldn't be marked with the 
> unsafe-fp-math attribute.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

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


[PATCH] D134604: [clang] Implement sugared substitution changes to infrastructure

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 470660.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/test/SemaTemplate/nested-name-spec-template.cpp

Index: clang/test/SemaTemplate/nested-name-spec-template.cpp
===
--- clang/test/SemaTemplate/nested-name-spec-template.cpp
+++ clang/test/SemaTemplate/nested-name-spec-template.cpp
@@ -147,3 +147,10 @@
 
   template void f(); // expected-note{{in instantiation of}}
 }
+
+namespace sugared_template_instantiation {
+  // Test that we ignore local qualifiers.
+  template  struct A {};
+  struct B { typedef int type1; };
+  typedef A type2;
+} // namespace sugated_template_instantiation
Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -64,6 +64,10 @@
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L);
 
+  /// Pushes 'T' with all locations pointing to 'Loc'.
+  /// The builder must be empty for this to work.
+  void pushTrivial(ASTContext &Context, QualType T, SourceLocation Loc);
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
Index: clang/lib/Sema/TypeLocBuilder.cpp
===
--- clang/lib/Sema/TypeLocBuilder.cpp
+++ clang/lib/Sema/TypeLocBuilder.cpp
@@ -41,6 +41,29 @@
   }
 }
 
+void TypeLocBuilder::pushTrivial(ASTContext &Context, QualType T,
+ SourceLocation Loc) {
+  auto L = TypeLoc(T, nullptr);
+  reserve(L.getFullDataSize());
+
+  SmallVector TypeLocs;
+  for (auto CurTL = L; CurTL; CurTL = CurTL.getNextTypeLoc())
+TypeLocs.push_back(CurTL);
+
+  for (const auto &CurTL : llvm::reverse(TypeLocs)) {
+switch (CurTL.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: {   \
+auto NewTL = push(CurTL.getType());  \
+NewTL.initializeLocal(Context, Loc);   \
+break; \
+  }
+#include "clang/AST/TypeLocNodes.def"
+}
+  }
+}
+
 void TypeLocBuilder::grow(size_t NewCapacity) {
   assert(NewCapacity > Capacity);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -636,6 +636,14 @@
   QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
 #include "clang/AST/TypeLocNodes.def"
 
+  QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
+ TemplateTypeParmTypeLoc TL,
+ bool SuppressObjCLifetime);
+  QualType
+  TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
+ SubstTemplateTypeParmPackTypeLoc TL,
+ bool SuppressObjCLifetime);
+
   template
   QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
   FunctionProtoTypeLoc TL,
@@ -1285,9 +1293,10 @@
   /// template name. Subclasses may override this routine to provide different
   /// behavior.
   TemplateName RebuildTemplateName(const TemplateArgument &ArgPack,
-   Decl *AssociatedDecl, unsigned Index) {
+   Decl *AssociatedDecl, unsigned Index,
+   bool Final) {
 return getSema().Context.getSubstTemplateTemplateParmPack(
-ArgPack, AssociatedDecl, Index);
+ArgPack, AssociatedDecl, Index, Final);
   }
 
   /// Build a new compound statement.
@@ -4152,9 +4161,13 @@
 NestedNameSpecifierLoc NNS, QualType ObjectType,
 NamedDecl *FirstQualifierInScope) {
   SmallVector Qualifiers;
- 

[PATCH] D136563: [clang] Perform sugared substitution of builtin templates

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe5d9e802e50d: [clang] Perform sugared substitution of 
builtin templates (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136563

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp

Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,13 +11,11 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1 ... pack_index 0
-// CHECK-NEXT: |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__type_pack_element'
-// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -37,7 +35,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -57,7 +55,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test4 = __type_pack_element;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -14,20 +14,18 @@
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
-// CHECK-NEXT: |-TemplateArgument type 'int':'int'
-// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1
-// CHECK-NEXT: |   |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__make_integer_seq'
-// CHECK-NEXT: |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 // CHECK-NEXT: |-TemplateArgument expr
 // CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT: |   |-value: Int 0
-// CHECK-NEXT: |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int':'int' 0
+// CHECK-NEXT: |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT: `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
 
 template  using B = __make_integer_seq;
 using test2 = B;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' sugar alias B
 // CHECK-NEXT:   |-TemplateArgument type 'int'
@@ -44,

[clang] e5d9e80 - [clang] Perform sugared substitution of builtin templates

2022-10-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-26T02:34:42+02:00
New Revision: e5d9e802e50dd55a326e31a0d562e5263b208f3b

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

LOG: [clang] Perform sugared substitution of builtin templates

Since these are much like template type aliases, where we don't
track a specialization for them and just substitute them eagerly,
we can't resugar them anyway, and there is no relevant cost in just
performing a finalizing sugared substitution.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/type_pack_element.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 86c7ce1b8ee8..9c22fd91dd0f 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3577,18 +3577,11 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
 
 static QualType
 checkBuiltinTemplateIdType(Sema &SemaRef, BuiltinTemplateDecl *BTD,
-   const SmallVectorImpl &Converted,
+   ArrayRef Converted,
SourceLocation TemplateLoc,
TemplateArgumentListInfo &TemplateArgs) {
   ASTContext &Context = SemaRef.getASTContext();
 
-  // Wrap the type in substitution sugar.
-  auto getSubstType = [&](QualType Replacement, unsigned IndexReplaced,
-  Optional PackIndexReplaced) {
-return SemaRef.Context.getSubstTemplateTypeParmType(
-Replacement, BTD, IndexReplaced, PackIndexReplaced);
-  };
-
   switch (BTD->getBuiltinTemplateKind()) {
   case BTK__make_integer_seq: {
 // Specializations of __make_integer_seq are treated like
@@ -3611,19 +3604,18 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
 TemplateArgumentListInfo SyntheticTemplateArgs;
 // The type argument, wrapped in substitution sugar, gets reused as the
 // first template argument in the synthetic template argument list.
-QualType SyntheticType = getSubstType(OrigType, 1, None);
 SyntheticTemplateArgs.addArgument(
-TemplateArgumentLoc(TemplateArgument(SyntheticType),
+TemplateArgumentLoc(TemplateArgument(OrigType),
 SemaRef.Context.getTrivialTypeSourceInfo(
-SyntheticType, 
TemplateArgs[1].getLocation(;
+OrigType, TemplateArgs[1].getLocation(;
 
 if (llvm::APSInt NumArgs = NumArgsArg.getAsIntegral(); NumArgs >= 0) {
   // Expand N into 0 ... N-1.
   for (llvm::APSInt I(NumArgs.getBitWidth(), NumArgs.isUnsigned());
I < NumArgs; ++I) {
-TemplateArgument TA(Context, I, SyntheticType);
+TemplateArgument TA(Context, I, OrigType);
 
SyntheticTemplateArgs.addArgument(SemaRef.getTrivialTemplateArgumentLoc(
-TA, SyntheticType, TemplateArgs[2].getLocation()));
+TA, OrigType, TemplateArgs[2].getLocation()));
   }
 } else {
   // C++14 [inteseq.make]p1:
@@ -3633,13 +3625,10 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
   return QualType();
 }
 
-// Wrap the template in substitution sugar.
-TemplateName TN = SemaRef.Context.getSubstTemplateTemplateParm(
-Converted[0].getAsTemplate(), BTD, 0, None);
-
 // The first template argument will be reused as the template decl that
 // our synthetic template arguments will be applied to.
-return SemaRef.CheckTemplateIdType(TN, TemplateLoc, SyntheticTemplateArgs);
+return SemaRef.CheckTemplateIdType(Converted[0].getAsTemplate(),
+   TemplateLoc, SyntheticTemplateArgs);
   }
 
   case BTK__type_pack_element:
@@ -3666,8 +3655,7 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
 
 // We simply return the type at index `Index`.
 int64_t N = Index.getExtValue();
-return getSubstType(Ts.getPackAsArray()[N].getAsType(), 1,
-Ts.pack_size() - 1 - N);
+return Ts.getPackAsArray()[N].getAsType();
   }
   llvm_unreachable("unexpected BuiltinTemplateDecl!");
 }
@@ -3915,7 +3903,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
   return QualType();
 }
   } else if (auto *BTD = dyn_cast(Template)) {
-CanonType = checkBuiltinTemplateIdType(*this, BTD, CanonicalConverted,
+CanonType = checkBuiltinTemplateIdType(*this, BTD, SugaredConverted,
TemplateLoc, TemplateArgs);
   } else if (Name.isDependent() ||
  TemplateSpecializationType::anyDependentTemplateArguments(

di

[PATCH] D136723: [include-cleaner] Record main-file macro occurences and includes

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:75
+//  - for a logical file like , we check Spelled
+llvm::SmallVector match(Header H) const;
+

in the prototype I reimplemented this function in clangd, but I expect we can 
just reuse the RecordedIncludes class instead, copying from clangd's includes 
list is cheap.

(That's one argument for putting this in a different header, which I can do 
already if you prefer)



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:22
 
-#ifndef CLANG_INCLUDE_CLEANER_RECORD_H
-#define CLANG_INCLUDE_CLEANER_RECORD_H
+#ifndef CLANG_INCLUDE_CLEANER_TYPES_H
+#define CLANG_INCLUDE_CLEANER_TYPES_H

(this is already fixed at head)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136723

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


[PATCH] D136723: [include-cleaner] Record main-file macro occurences and includes

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: kadircet, hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The occurrences are roots for finding used headers, like walkAST.
Includes are the targets we're matching used headers against.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136723

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

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -8,13 +8,19 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
+using testing::ElementsAreArray;
 
 // Matches a Decl* if it is a NamedDecl with the given name.
 MATCHER_P(Named, N, "") {
@@ -88,5 +94,145 @@
   EXPECT_THAT(Recorded.Roots, testing::ElementsAre(Named("x")));
 }
 
+class RecordPPTest : public ::testing::Test {
+protected:
+  TestInputs Inputs;
+  RecordedPP Recorded;
+
+  RecordPPTest() {
+struct RecordAction : public PreprocessOnlyAction {
+  RecordedPP &Out;
+  RecordAction(RecordedPP &Out) : Out(Out) {}
+
+  void ExecuteAction() override {
+auto &PP = getCompilerInstance().getPreprocessor();
+PP.addPPCallbacks(Out.record(PP));
+PreprocessOnlyAction::ExecuteAction();
+  }
+};
+Inputs.MakeAction = [this] {
+  return std::make_unique(Recorded);
+};
+  }
+
+  TestAST build() { return TestAST(Inputs); }
+};
+
+// Matches an Include with a particular spelling.
+MATCHER_P(spelled, S, "") { return arg.Spelled == S; }
+
+TEST_F(RecordPPTest, CapturesIncludes) {
+  llvm::Annotations MainFile(R"cpp(
+$H^#include "./header.h"
+$M^#include "missing.h"
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["header.h"] = "";
+  Inputs.ErrorOK = true; // missing header
+  auto AST = build();
+
+  ASSERT_THAT(
+  Recorded.Includes.all(),
+  testing::ElementsAre(spelled("./header.h"), spelled("missing.h")));
+
+  auto &H = Recorded.Includes.all().front();
+  EXPECT_EQ(H.Line, 2u);
+  EXPECT_EQ(H.Location,
+AST.sourceManager().getComposedLoc(
+AST.sourceManager().getMainFileID(), MainFile.point("H")));
+  EXPECT_EQ(H.Resolved, AST.fileManager().getFile("header.h").get());
+
+  auto &M = Recorded.Includes.all().back();
+  EXPECT_EQ(M.Line, 3u);
+  EXPECT_EQ(M.Location,
+AST.sourceManager().getComposedLoc(
+AST.sourceManager().getMainFileID(), MainFile.point("M")));
+  EXPECT_EQ(M.Resolved, nullptr);
+}
+
+TEST_F(RecordPPTest, CapturesMacroRefs) {
+  llvm::Annotations Header(R"cpp(
+#define $def^X 1
+
+// Refs, but not in main file.
+#define Y X
+int one = x;
+  )cpp");
+  llvm::Annotations MainFile(R"cpp(
+#define EARLY X // not a ref, no definition
+#include "header.h"
+#define LATE ^X
+#define LATE2 ^X // a ref even if not expanded
+
+int one = ^X;
+int uno = $exp^LATE; // a ref in LATE's expansion
+
+#define IDENT(X) X // not a ref, shadowed
+int eins = IDENT(^X);
+
+#undef ^X
+// Not refs, rather a new macro with the same name.
+#define X 2
+int two = X;
+  )cpp");
+  Inputs.Code = MainFile.code();
+  Inputs.ExtraFiles["header.h"] = Header.code();
+  Inputs.ErrorOK = true; // missing header
+  auto AST = build();
+  const auto &SM = AST.sourceManager();
+
+  SourceLocation Def = SM.getComposedLoc(
+  SM.translateFile(AST.fileManager().getFile("header.h").get()),
+  Header.point("def"));
+  ASSERT_NE(Recorded.MacroReferences.size(), 0u);
+  Symbol OrigX = Recorded.MacroReferences.front().Symbol;
+  EXPECT_EQ("X", OrigX.macro().Name->getName());
+  EXPECT_EQ(Def, OrigX.macro().Definition);
+
+  std::vector RefOffsets;
+  std::vector ExpOffsets; // Expansion locs of refs in macro locs.
+  std::vector RefMacroLocs;
+  for (const auto &Ref : Recorded.MacroReferences) {
+if (Ref.Symbol == OrigX) {
+  auto [FID, Off] = SM.getDecomposedLoc(Ref.RefLocation);
+  if (FID == SM.getMainFileID()) {
+RefOffsets.push_back(Off);
+  } else if (Ref.RefLocat

[PATCH] D136715: [NFC][Offload Bundler] Formatting clang offloadbundler source file

2022-10-25 Thread Raghav Medicherla via Phabricator via cfe-commits
raghavmedicherla added a comment.

@jdoerfert Sorry for the inconvenience! 
I had no idea that you would be added as a reviewer by default, so I was trying 
to remove you as a reviewer.
I'll be careful next time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136715

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


[PATCH] D131469: [Clang] change default storing path of `-ftime-trace`

2022-10-25 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo added a comment.

> Hey @dongjunduo,
> Are you still interested in finishing this? If not I was thinking that I 
> would pick it up, so I can work on the follow ups.

@Maetveis Sorry for delaying the issue due to some personal trifles...

This part of the implementation has been preliminarily completed. I will submit 
the new patch in a day or two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131469

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG11ce78940b4c: [clang] Changes to produce sugared converted 
template arguments (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

Files:
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/ppc-pair-mma-types.cpp
  clang/test/SemaTemplate/deduction.cpp

Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2b
 
 // Template argument deduction with template template parameters.
 template class A> 
@@ -661,3 +662,25 @@
   template void f(Y);
   void g(Y y) { f(y); }
 }
+
+namespace sugared_deduction {
+using Int = int;
+
+template  void f1(T(&)[C], T(&)[C+1]);
+// expected-note@-1 {{candidate template ignored: deduced type 'int[3]' of 2nd parameter does not match adjusted type 'Int[2]' (aka 'int[2]') of argument [with T = Int, C = 2]}}
+
+void t1() {
+  Int a[2], b[2];
+  f1(a, b); // expected-error {{no matching function for call to 'f1'}}
+}
+
+#if defined(__cpp_concepts)
+template  void f2() requires false {}
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with T = Int]}}
+// expected-note@-2 {{because 'false' evaluated to false}}
+
+void t2() {
+  f2(); // expected-error {{no matching function for call to 'f2'}}
+}
+#endif
+} // namespace sugared_deduction
Index: clang/test/SemaCXX/ppc-pair-mma-types.cpp
===
--- clang/test/SemaCXX/ppc-pair-mma-types.cpp
+++ clang/test/SemaCXX/ppc-pair-mma-types.cpp
@@ -85,8 +85,8 @@
 
   // template argument
   template 
-  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
+  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vq_t]: invalid use of PPC MMA type}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
@@ -276,8 +276,8 @@
 
   // template argument
   template 
-  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
+  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vp_t]: invalid use of PPC MMA type}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3752,12 +3752,10 @@
 
   // Check that the template argument list is well-formed for this
   // class template.
-  SmallVector Converted;
-  if (SemaRef.CheckTemplateArgumentList(InstClassTemplate,
-D->getLocation(),
-InstTemplateArgs,
-false,
-Converted,
+  SmallVector SugaredConverted, CanonicalConverted;
+  if (SemaRef.CheckTemplateArgumentList(InstClassTemplate, D->getLocation(),
+InstTemplateArgs, false,
+SugaredConverted, CanonicalConverted,
 /*UpdateArgsWithConversions=*/true))
 return nullptr;
 
@@ -3765,7 +3763,7 @@
   // in the member template's set of class template explicit specializations.
   void *InsertPos = nullptr;
   ClassTemplateSpecializationDecl *PrevDecl =
-  InstClassTemplate->findSpecialization(Converted, InsertPos);
+  InstClassTemplate->findSpecialization(CanonicalC

[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-25 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

It's not really a regression, just a bug in the feature.  The rpmalloc code is 
checking `__has_builtin(__builtin_memset_inline)`, so older versions of clang 
aren't seeing the same source code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126903

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


[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2022-10-25 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added inline comments.



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:3002
+// The format of the stat cache is (pseudo-code):
+//  struct stat_cache {
+//char Magic[4];   // "STAT" or "Stat"

Few comments about stats representation.
1. Can we version the stat cache file so we can evolve it in the future if 
needed?
2. I wonder if we need to have a more flexible representation for DataType 
other than `sys::fs::file_status`. Current entry is locked with the endian of 
the host and can't be used to encode more information than file_status. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D136715: formatting clang offloadbundler source file

2022-10-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.

I'm not sure why you fight with phabricator so much. I was going to edit your 
revision metadata but you for some reason disallowed that.
I would generally suggest against that.

---

The patch itself is fine, the commit subject line and comment should be 
revisited though:

- Use an [NFC] tag and potentially an additional tag for the subcomponent, 
e.g., [Driver] or [OffloadBundler], to help people filter for relevant changes.
- The description should not duplicate the subject. Since this is a simple 
clang-format NFC patch, no description is necessary anyway.

Please address the above points before commiting the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136715

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


[PATCH] D126903: [clang] Add support for __builtin_memset_inline

2022-10-25 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

Hello @gchatelet! This patches introduces a regression in a two-stage build 
using rpmalloc on Windows. Bisection lead me here. Would you have a chance to 
take a look please? Thanks in advance.

To reproduce, I used the following script (rename to make_llvm.bat) F25053901: 
make_llvm.txt 

  C:\git\llvm-project>make_llvm.bat stage1
  ...
  C:\git\llvm-project>ninja clang lld -C stage1
  ...
  C:\git\llvm-project>make_llvm.bat stage2_rpmalloc
  ...
  C:\git\llvm-project>ninja lld -C stage2_rpmalloc

generates:

  [158/2714] Building C object 
lib\Support\CMakeFiles\LLVMSupport.dir\C_\git\rpmalloc\rpmalloc\rpmalloc.c.obj
  FAILED: 
lib/Support/CMakeFiles/LLVMSupport.dir/C_/git/rpmalloc/rpmalloc/rpmalloc.c.obj
  C:\git\llvm-project\stage1\bin\clang-cl.exe  /nologo -DENABLE_OVERRIDE 
-DENABLE_PRELOAD -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE 
-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS 
-D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS 
-D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -IC:\git\llvm-project\stage2_rpmalloc\lib\Support 
-IC:\git\llvm-project\llvm\lib\Support 
-IC:\git\llvm-project\stage2_rpmalloc\include 
-IC:\git\llvm-project\llvm\include /GS- /D_ITERATOR_DEBUG_LEVEL=0 -Xclang -O3 
-fstrict-aliasing -march=native -flto=thin -fwhole-program-vtables -fuse-ld=lld 
/Zc:inline /Zi -gcodeview-ghash /Zc:strictStrings /Oi /W4  -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion 
-Wmisleading-indentation /Gw -flto=thin /MT /O2 /Ob2 /DNDEBUG /showIncludes 
/Folib\Support\CMakeFiles\LLVMSupport.dir\C_\git\rpmalloc\rpmalloc\rpmalloc.c.obj
 /Fdlib\Support\CMakeFiles\LLVMSupport.dir\LLVMSupport.pdb -c -- 
C:\git\rpmalloc\rpmalloc\rpmalloc.c
  Assertion failed: isa(Val) && "cast() argument of incompatible 
type!", file C:/git/llvm-project/llvm/include\llvm/Support/Casting.h, line 578
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: C:\\git\\llvm-project\\stage1\\bin\\clang-cl.exe 
/nologo -DENABLE_OVERRIDE -DENABLE_PRELOAD -DGTEST_HAS_RTTI=0 -DUNICODE 
-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 
-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:\\git\\llvm-project\\stage2_rpmalloc\\lib\\Support 
-IC:\\git\\llvm-project\\llvm\\lib\\Support 
-IC:\\git\\llvm-project\\stage2_rpmalloc\\include 
-IC:\\git\\llvm-project\\llvm\\include /GS- /D_ITERATOR_DEBUG_LEVEL=0 -Xclang 
-O3 -fstrict-aliasing -march=native -flto=thin -fwhole-program-vtables 
-fuse-ld=lld /Zc:inline /Zi -gcodeview-ghash /Zc:strictStrings /Oi /W4 -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion 
-Wmisleading-indentation /Gw -flto=thin /MT /O2 /Ob2 /DNDEBUG /showIncludes 
/Folib\\Support\\CMakeFiles\\LLVMSupport.dir\\C_\\git\\rpmalloc\\rpmalloc\\rpmalloc.c.obj
 /Fdlib\\Support\\CMakeFiles\\LLVMSupport.dir\\LLVMSupport.pdb -c -- 
C:\\git\\rpmalloc\\rpmalloc\\rpmalloc.c
  1.   parser at end of file
  2.  Optimizer
   #0 0x7ff7f877ca86 HandleAbort 
C:\git\llvm-project\llvm\lib\Support\Windows\Signals.inc:418:0
   #1 0x7ff7fcdfc6bb raise 
C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\misc\signal.cpp:547:0
   #2 0x7ff7fcdf1ff4 abort 
C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:71:0
   #3 0x7ff7fcdf2672 common_assert_to_stderr 
C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:186:0
   #4 0x7ff7fcdf251a _wassert 
C:\git\llvm-project\stage1\minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:443:0
   #5 0x7ff7f9b48e7b 
llvm::VNCoercion::analyzeLoadFromClobberingMemInst(class llvm::Type *, class 
llvm::Value *, class llvm::MemIntrinsic *, class llvm::DataLayout const &) 
C:\git\llvm-project\llvm\lib\Transforms\Utils\VNCoercion.cpp:381:0
   #6 0x7ff7f85a1ec4 llvm::GVNPass::AnalyzeLoadAvailability(class 
llvm::LoadInst *, class llvm::MemDepResult, class llvm::Value *, struct 
llvm::gvn::AvailableValue &) 
C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:1211:0
   #7 0x7ff7f85a8a5c llvm::GVNPass::processLoad(class llvm::LoadInst *) 
C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:2068:0
   #8 0x7ff7f85aa465 llvm::GVNPass::processInstruction(class 
llvm::Instruction *) 
C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:2483:0
   #9 0x7ff7f85ab3ed llvm::GVNPass::processBlock(class llvm::BasicBlock *) 
C:\git\llvm-project\llvm\lib\Transforms\Scalar\GVN.cpp:

[PATCH] D136715: formatting clang offloadbundler source file

2022-10-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136715

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 470645.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

Files:
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/ppc-pair-mma-types.cpp
  clang/test/SemaTemplate/deduction.cpp

Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2b
 
 // Template argument deduction with template template parameters.
 template class A> 
@@ -661,3 +662,25 @@
   template void f(Y);
   void g(Y y) { f(y); }
 }
+
+namespace sugared_deduction {
+using Int = int;
+
+template  void f1(T(&)[C], T(&)[C+1]);
+// expected-note@-1 {{candidate template ignored: deduced type 'int[3]' of 2nd parameter does not match adjusted type 'Int[2]' (aka 'int[2]') of argument [with T = Int, C = 2]}}
+
+void t1() {
+  Int a[2], b[2];
+  f1(a, b); // expected-error {{no matching function for call to 'f1'}}
+}
+
+#if defined(__cpp_concepts)
+template  void f2() requires false {}
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with T = Int]}}
+// expected-note@-2 {{because 'false' evaluated to false}}
+
+void t2() {
+  f2(); // expected-error {{no matching function for call to 'f2'}}
+}
+#endif
+} // namespace sugared_deduction
Index: clang/test/SemaCXX/ppc-pair-mma-types.cpp
===
--- clang/test/SemaCXX/ppc-pair-mma-types.cpp
+++ clang/test/SemaCXX/ppc-pair-mma-types.cpp
@@ -85,8 +85,8 @@
 
   // template argument
   template 
-  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
+  void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vq_t]: invalid use of PPC MMA type}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
@@ -276,8 +276,8 @@
 
   // template argument
   template 
-  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}} \
- expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
+  void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = vp_t]: invalid use of PPC MMA type}} \
+  expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
 *(p + 1) = v;
   }
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3752,12 +3752,10 @@
 
   // Check that the template argument list is well-formed for this
   // class template.
-  SmallVector Converted;
-  if (SemaRef.CheckTemplateArgumentList(InstClassTemplate,
-D->getLocation(),
-InstTemplateArgs,
-false,
-Converted,
+  SmallVector SugaredConverted, CanonicalConverted;
+  if (SemaRef.CheckTemplateArgumentList(InstClassTemplate, D->getLocation(),
+InstTemplateArgs, false,
+SugaredConverted, CanonicalConverted,
 /*UpdateArgsWithConversions=*/true))
 return nullptr;
 
@@ -3765,7 +3763,7 @@
   // in the member template's set of class template explicit specializations.
   void *InsertPos = nullptr;
   ClassTemplateSpecializationDecl *PrevDecl =
-  InstClassTemplate->findSpecialization(Converted, InsertPos);
+  InstClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
 
   // Check whether we've already seen a conflicting instantiation of this
   // declaration (for instance, if there was a pr

[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2022-10-25 Thread Frederic Riss via Phabricator via cfe-commits
friss updated this revision to Diff 470644.
friss added a comment.

Address some review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/HeaderSearchOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/vfsstatcache.c
  clang/test/clang-stat-cache/cache-effects.c
  clang/test/clang-stat-cache/errors.test
  clang/tools/CMakeLists.txt
  clang/tools/clang-stat-cache/CMakeLists.txt
  clang/tools/clang-stat-cache/clang-stat-cache.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp

Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 
@@ -3159,3 +3160,300 @@
 "  DummyFileSystem (RecursiveContents)\n",
 Output);
 }
+
+class StatCacheFileSystemTest : public ::testing::Test {
+public:
+  void SetUp() override {}
+
+  template 
+  void createStatCacheFileSystem(
+  StringRef OutputFile, StringRef BaseDir, bool IsCaseSensitive,
+  IntrusiveRefCntPtr &Result,
+  StringCollection &Filenames,
+  IntrusiveRefCntPtr Lower = new ErrorDummyFileSystem(),
+  uint64_t ValidityToken = 0) {
+vfs::StatCacheFileSystem::StatCacheWriter Generator(
+BaseDir, IsCaseSensitive, ValidityToken);
+std::error_code ErrorCode;
+
+Result.reset();
+
+for (sys::fs::recursive_directory_iterator I(BaseDir, ErrorCode), E;
+ I != E && !ErrorCode; I.increment(ErrorCode)) {
+  Filenames.push_back(I->path());
+  StringRef Path(Filenames.back().c_str());
+  sys::fs::file_status s;
+  status(Path, s);
+  Generator.addEntry(Path, s);
+}
+
+{
+  raw_fd_ostream StatCacheFile(OutputFile, ErrorCode);
+  ASSERT_FALSE(ErrorCode);
+  Generator.writeStatCache(StatCacheFile);
+}
+
+loadCacheFile(OutputFile, ValidityToken, Lower, Result);
+  }
+
+  void loadCacheFile(StringRef OutputFile, uint64_t ExpectedValidityToken,
+ IntrusiveRefCntPtr Lower,
+ IntrusiveRefCntPtr &Result) {
+auto ErrorOrBuffer = MemoryBuffer::getFile(OutputFile);
+EXPECT_TRUE(ErrorOrBuffer);
+StringRef CacheBaseDir;
+bool IsCaseSensitive;
+uint64_t FileValidityToken;
+auto E = vfs::StatCacheFileSystem::validateCacheFile(
+(*ErrorOrBuffer)->getMemBufferRef(), CacheBaseDir, IsCaseSensitive,
+FileValidityToken);
+ASSERT_FALSE(E);
+EXPECT_EQ(FileValidityToken, ExpectedValidityToken);
+auto ExpectedCache = vfs::StatCacheFileSystem::create(
+std::move(*ErrorOrBuffer), OutputFile, Lower);
+ASSERT_FALSE(ExpectedCache.takeError());
+Result = *ExpectedCache;
+  }
+
+  template 
+  void
+  compareStatCacheToRealFS(IntrusiveRefCntPtr CacheFS,
+   const StringCollection &Files) {
+IntrusiveRefCntPtr RealFS = vfs::getRealFileSystem();
+
+for (auto &File : Files) {
+  auto ErrorOrStatus1 = RealFS->status(File);
+  auto ErrorOrStatus2 = CacheFS->status(File);
+
+  EXPECT_EQ((bool)ErrorOrStatus1, (bool)ErrorOrStatus2);
+  if (!ErrorOrStatus1 || !ErrorOrStatus2)
+continue;
+
+  vfs::Status s1 = *ErrorOrStatus1, s2 = *ErrorOrStatus2;
+  EXPECT_EQ(s1.getName(), s2.getName());
+  EXPECT_EQ(s1.getType(), s2.getType());
+  EXPECT_EQ(s1.getPermissions(), s2.getPermissions());
+  EXPECT_EQ(s1.getLastModificationTime(), s2.getLastModificationTime());
+  EXPECT_EQ(s1.getUniqueID(), s2.getUniqueID());
+  EXPECT_EQ(s1.getUser(), s2.getUser());
+  EXPECT_EQ(s1.getGroup(), s2.getGroup());
+  EXPECT_EQ(s1.getSize(), s2.getSize());
+}
+  }
+};
+
+TEST_F(StatCacheFileSystemTest, Basic) {
+  TempDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
+  TempDir _a(TestDirectory.path("a"));
+  TempFile _ab(TestDirectory.path("a/b"));
+  TempDir _ac(TestDirectory.path("a/c"));
+  TempFile _acd(TestDirectory.path("a/c/d"), "", "Dummy contents");
+  TempFile _ace(TestDirectory.path("a/c/e"));
+  TempFile _acf(TestDirectory.path("a/c/f"), "", "More dummy contents");
+  TempDir _ag(TestDirectory.path("a/g"));
+  TempFile _agh(TestDirectory.path("a/g/h"));
+
+  StringRef BaseDir(_a.path());
+
+  SmallVector Filenames;
+  IntrusiveRefCntPtr StatCacheFS;
+  createStatCacheFileSystem(TestDirectory.path("stat.cache"), BaseDir,
+/* IsCaseSensitive= */ true, StatCacheFS,
+   

[PATCH] D136707: [clang][Toolchains][Gnu] pass -gdwarf-* through to assembler

2022-10-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7966
   }
+  unsigned DwarfVersion = GetDwarfVersion(getToolChain(), Args);
   RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DwarfVersion,

Consider `const` if this variable is not modified.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.h:114
+const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
+unsigned GetDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
 

If this patch touches all use cases of `GetDwarfVersion`, consider switching 
the case to `getDwarfVersion`.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:979
+  unsigned DwarfVersion = GetDwarfVersion(getToolChain(), Args);
+  std::string DV = "-gdwarf-" + std::to_string(DwarfVersion);
+  CmdArgs.push_back(Args.MakeArgString(DV));

MakeArgString accepts a Twine. Just use `"-gdwarf-" + Twine(DwarfVersion);` as 
the argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136707

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


[PATCH] D136707: [clang][Toolchains][Gnu] pass -gdwarf-* through to assembler

2022-10-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 470638.
nickdesaulniers added a comment.

- more refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136707

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/as-options.s

Index: clang/test/Driver/as-options.s
===
--- clang/test/Driver/as-options.s
+++ clang/test/Driver/as-options.s
@@ -122,7 +122,33 @@
 // RUN:   FileCheck --check-prefix=DEBUG %s
 // RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g0 -g %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=DEBUG %s
-// DEBUG: "-g"
+// DEBUG: "-g" "-gdwarf-5"
 // RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g -g0 %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=NODEBUG %s
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf-5 -g0 %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=NODEBUG %s
 // NODEBUG-NOT: "-g"
+// NODEBUG-NOT: "-gdwarf-
+
+// Test that -gdwarf-* is passed through to GAS.
+// TODO: test without -g
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf-5 %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GDWARF5 %s
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf-4 %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GDWARF4 %s
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf-3 %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GDWARF3 %s
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf-2 %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GDWARF2 %s
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GDWARF5 %s
+
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -gdwarf-5 %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GDWARF5 %s
+// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g \
+// RUN:   -fdebug-default-version=2 %s -### 2>&1 | FileCheck --check-prefix=GDWARF2 %s
+
+// GDWARF5: "-gdwarf-5"
+// GDWARF4: "-gdwarf-4"
+// GDWARF3: "-gdwarf-3"
+// GDWARF2: "-gdwarf-2"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -969,10 +969,17 @@
   for (const auto &II : Inputs)
 CmdArgs.push_back(II.getFilename());
 
-  if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group))
-if (!A->getOption().matches(options::OPT_g0))
+  if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group,
+options::OPT_gdwarf_2, options::OPT_gdwarf_3, options::OPT_gdwarf_4,
+options::OPT_gdwarf_5, options::OPT_gdwarf))
+if (!A->getOption().matches(options::OPT_g0)) {
   Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
 
+  unsigned DwarfVersion = GetDwarfVersion(getToolChain(), Args);
+  std::string DV = "-gdwarf-" + std::to_string(DwarfVersion);
+  CmdArgs.push_back(Args.MakeArgString(DV));
+}
+
   const char *Exec =
   Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler));
   C.addCommand(std::make_unique(JA, *this,
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -14,6 +14,9 @@
 #include "clang/Driver/Multilib.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Support/CodeGen.h"
 
 namespace clang {
@@ -101,8 +104,14 @@
 unsigned ParseFunctionAlignment(const ToolChain &TC,
 const llvm::opt::ArgList &Args);
 
-unsigned ParseDebugDefaultVersion(const ToolChain &TC,
-  const llvm::opt::ArgList &Args);
+// Extract the integer N from a string spelled "-dwarf-N", returning 0
+// on mismatch. The StringRef input (rather than an Arg) allows
+// for use by the "-Xassembler" option parser.
+unsigned DwarfVersionNum(StringRef ArgValue);
+// Find a DWARF format version option.
+// This function is a complementary for DwarfVersionNum().
+const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
+unsigned GetDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
 
 void AddAssemblerKPIC(const ToolChain &ToolChain,
   const llvm::opt::ArgList &Args,
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1520,7 +1520,7 @@
   retur

[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-25 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added inline comments.



Comment at: clang/lib/Serialization/ASTReaderStmt.cpp:2179
+  for (unsigned I = 0; I < E->NumExprs; I++)
+E->getTrailingObjects()[I] = Record.readSubExpr();
+}

ilya-biryukov wrote:
> FYI: I think this is where the crash comes from.
> We should allocate the trailing objects first.
> E.g. see how `PragmaCommentDecl::CreateDeserialized` does this.
This sounds like it could be the solution - thanks for looking at it!

Currently, I'm working on the refactor that shafik@ suggested, which was to 
inherit from `InitListExpr`. Hopefully, that refactor will fix this issue as 
`InitListExpr` stores it's subexpressions in a class member instead of using 
`llvm::TrailingObjects`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D101526: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg constraints

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

Looks great to me, thanks!!




Comment at: 
clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp:32-33
 __buf_size_arg_constraint_concrete(buf); // \
-// expected-note{{The size of the 1st arg should be equal to or less than 
the value of 10}} \
+// expected-note{{The size of the 1st argument should be equal to or 
greater than the value of 10}} \
 // expected-warning{{}}
 break;

The warning is the same as the note here right?

Our warnings traditionally describe the problem (the 1st argument *is* less 
than 10, and this *is* bad because...), not how things "should" be. I guess we 
can think more about that later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101526

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


[PATCH] D135972: [clang-format] Don't crash on malformed preprocessor conditions

2022-10-25 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 3 inline comments as done.
sstwcw added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:5196-5206
+  std::function FormatBadBranches =
+  [&](std::string Prefix, unsigned Lines) {
+const std::string Directives[] = {"", "#if X\n", "#else X\n",
+  "#endif\n"};
+if (Lines == 0)
+  verifyNoCrash(Prefix);
+else

HazardyKnusperkeks wrote:
> sstwcw wrote:
> > owenpan wrote:
> > > Can we have individual `verifyFormat` or `verifyNoCrash`tests for easy 
> > > reading and to avoid the overhead? Some examples:
> > > ```
> > > #else
> > > a;
> > > #if X
> > > b;
> > > #endif
> > > #endif
> > > 
> > > #elif X
> > > a;
> > > #endif
> > > #ifdef X
> > > b;
> > > #endif
> > > ```
> > I added some tests like the examples.  But I kept the generated cases.  I 
> > feel more secure that way.  At first I only found the bug because of the 
> > generated cases.  As for overhead, the debug build of this test took 1.6s 
> > on my laptop.
> > I added some tests like the examples.  But I kept the generated cases.  I 
> > feel more secure that way.  At first I only found the bug because of the 
> > generated cases.  As for overhead, the debug build of this test took 1.6s 
> > on my laptop.
> 
> Couldn't you just take the previously crashing ones, you find important, as 
> test cases?
> The overhead is not only compile and runtime, it's also while trying to 
> understand what's happening here.
> The overhead is not only compile and runtime, it's also while trying to 
> understand what's happening here.

I see.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135972

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


[PATCH] D135972: [clang-format] Don't crash on malformed preprocessor conditions

2022-10-25 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 470623.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135972

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,27 @@
   verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
   verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
   verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() {  \n)}");
+  verifyNoCrash("#else\n"
+"#else\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#else\n"
+"#if X\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#else\n"
+"#endif\n"
+"#if X\n"
+"#endif");
+  verifyNoCrash("#if X\n"
+"#else\n"
+"#else\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#else");
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1212,9 +1212,12 @@
   // If a potential include guard has an #else, it's not an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == 0)
 IncludeGuard = IG_Rejected;
+  // Don't crash when there is an #else without an #if.
+  assert(PPBranchLevel >= -1);
+  if (PPBranchLevel == -1)
+conditionalCompilationStart(/*Unreachable=*/true);
   conditionalCompilationAlternative();
-  if (PPBranchLevel > -1)
---PPBranchLevel;
+  --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,27 @@
   verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
   verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
   verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() {  \n)}");
+  verifyNoCrash("#else\n"
+"#else\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#else\n"
+"#if X\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#else\n"
+"#endif\n"
+"#if X\n"
+"#endif");
+  verifyNoCrash("#if X\n"
+"#else\n"
+"#else\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#else");
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1212,9 +1212,12 @@
   // If a potential include guard has an #else, it's not an include guard.
   if (IncludeGuard == IG_Defined && PPBranchLevel == 0)
 IncludeGuard = IG_Rejected;
+  // Don't crash when there is an #else without an #if.
+  assert(PPBranchLevel >= -1);
+  if (PPBranchLevel == -1)
+conditionalCompilationStart(/*Unreachable=*/true);
   conditionalCompilationAlternative();
-  if (PPBranchLevel > -1)
---PPBranchLevel;
+  --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136701: [LinkerWrapper] Perform device linking steps in parallel

2022-10-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In general, I think parallelizing the linking workload for multiple GPU's in 
the linker wrapper is a useful feature. I am not sure whether the workload to 
be parallelized includes the LLVM passes and codegen, which is usually the 
bottleneck. Parallelizing this workload when there are many GPU arch's can 
significantly improve build time.

It is preferable if the parallelization can be coordinated with GNU make 
through the job server provided by GNU make 
(https://www.gnu.org/software/make/manual/html_node/Job-Slots.html#Job-Slots). 
However, some efforts are needed to implement that.

For now, I think an option to enable parallelization (by default off) should be 
fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136701

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


[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D136474#3883629 , @thakis wrote:

> FWIW we do have precedent of deviating from cl.exe for determinism reasons. I 
> think having deterministic output is a good default.

This is true, but the cc1 flag isn't inherently non-deterministic. I would 
prefer to fix the determinism bugs instead of adding flags and more divergence.

Can we use the `grecord-command-line` flag here instead of adding a new one?
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-grecord-command-line
I understand it has different semantics. We'd record the command line 
differently depending on whether codeview or DWARF is in use, and potentially 
both ways when both are in use (🙄 ).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136293: [IncludeCleaner] Add public API

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:27
+  Symbol(Decl &D) : Storage(&D) {}
+  Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
+

Doh, I was skimming and missed that you removed the `Location` concept and 
folded stdlib handling into `Symbol`.

`tooling::stdlib::Symbol` only captures top-level symbols, so we've thrown away 
the identity of the actual symbol being accessed. This is not a complete 
disaster, but I think it causes problems, and I think we should be very 
deliberate and consistent about what information we preserve vs throw away.

Some examples of how this might bite us:
 - distinguishing between macros/decls is non-uniform (need to check separately 
for decl vs macro vs stdlib-decl vs stdlib-macro)
 - can't treat different types of symbols e.g. constructors vs classes 
differently (you suggested elsewhere we could check the kind of targetdecl to 
implement external policies)
 - can't treat nested classes differently (i.e. must treat `std::vector` and 
`decltype(myvec)::iterator` the same). 
 - can't print the name, e.g. the fixit hint for `auto x = TimePoint<>::min()` 
becomes `include header  for 'std::chrono::time_point'` instead of 
`include header  for 'std::chrono::time_point<...>::min()'`
 - can't insert forward declarations with a code action (legal for c symbols)
 - harder to understand/debug (is this an implicit reference to a copy 
constructor, move constructor, conversion operator, or the type itself? where 
*are* all the redecls? is this misclassified user code, such as a trait 
specialization)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136293

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


[PATCH] D133998: [HIP][test] Avoid %T

2022-10-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D133998#3883517 , @probinson wrote:

> @MaskRay I see that you restored the `clang-driver` keyword in 
> hip-link-bc-to-bc.hip, and of course that keyword is not defined anywhere so 
> the test is never being run.
> Is there an issue filed to track this?  Or is the original author aware? 
> @lamb-j

Thanks for reporting the issue. I forgot to mention it. You are right that 
`Driver/hip-link-bc-to-bc.hip` needs fixing @lamb-j


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133998

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


[PATCH] D136701: [LinkerWrapper] Perform device linking steps in parallel

2022-10-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D136701#3883416 , @tra wrote:

> In D136701#3883300 , @jhuber6 wrote:
>
>> However, as an opt-in feature it would be very helpful in some cases.
>
> I'm OK with the explicit opt-in.

Might be good to start with it as opt-in for this patch and we can discuss 
defaults later, I'll make that change.

>> Like consider someone creating a static library that supports every GPU 
>> architecture LLVM supports, it would be nice to be able to optionally turn 
>> on parallelism in the driver.
>
> Yes, but the implicit assumption here is that you have sufficient resources. 
> If you create N libraries, each for M architectures, your build machine may 
> not have enough memory for N*M linkers.
> Having N*M processes may or may not be an issue, but if each of the linkers 
> is an `lld` which may want to run their own K parallel threads, it would not 
> help anything.

That's true, `AMDGPU` uses `lld` as its linker so we would be invoking a 
potentially parallel link step in multiple threads. I'm not sure how much this 
could impact

> In other words, I agree that it may be helpful in some cases, but I can also 
> see how it may actually hurt the build, possibly catastrophically.
>
> My point is that grabbing resources will likely break build system's 
> assumptions about their availability. How that would affect the build is 
> anyone's guess. With infinite resources, parallel-everything would win, but 
> in practice it's a big maybe. It would likely be a win for small builds and 
> probably would be a wash or a regression for a larger build with multiple 
> such targets.
>
> Ideally it would be great if there would be a way to cooperate with the build 
> system and let it manage the scheduling, but I don't think we have a good way 
> of doing that. 
> E.g. for CUDA compilation I was thinking of exposing per-GPU sub-compilations 
> (well, we already do with --cuda-device-only/--cuda-device-only) and 
> providing a way to create  combined object from them, and then let the build 
> system manage how those per-GPU compilations would be launched. The problem 
> there is that the build system would need to know our under-the-hood 
> implementation details, so such an approach will be very fragile. The way the 
> new driver does things may be a bit more suitable for this, but I suspect it 
> would still be hard to do.
>
>> `lld` already uses all available threads for its parallel linking, the 
>> linker wrapper runs before the host linker invocation so it shouldn't 
>> interfere either.
>
> You do have a point here. As long as we don't end up with too many threads 
> (e.g. we guarantee that per-offload linker instance does not run their own 
> parallel threads, offload linking may be similar to parallel lld.

AMDGPU calls `lld` for its device linking stage, as LTO has `thin-lto` which 
could potentually use more threads. But generally I think the amount of threads 
required for device linking will probably be small and will always be 
beneficial compared to running them sequentially.

>> This is only non-deterministic for the order of linking jobs between several 
>> targets and architectures. If the user only links a single architecture it 
>> should behave as before.
>
> I'm not sure what you mean. Are you saying that linking with 
> `--offload-arch=gfx700` is repeatable, but with 
> `--offload-arch=gfx700,gfx701` it's not? That would still be a problem.
>
>> The average case is still probably going to be one or two architectures at 
>> once, in which case this change won't make much of a difference.
>
> Any difference is a difference, as far as content-based caching and 
> provenance tracking is concerned.

This does bring up a good point. The linked output is going to be entered into 
an arbitrary order now. We should probably sort it by some metric at least. 
Otherwise we'd have the same binary creating different images depending on 
this. I'll also make that change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136701

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


[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-25 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 470611.
manojgupta added a comment.

Removed c++ limitation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136712

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Driver/arm-baremetal-defines.cpp


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 
2>&1 | FileCheck %s
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,10 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 2>&1 | FileCheck %s
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,10 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136638: [clang-doc] Fix typedef/using output.

2022-10-25 Thread Brett Wilson 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 rG7231c9966e52: [clang-doc] Fix typedef/using output. 
(authored by brettw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136638

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -183,11 +183,33 @@
   I.Underlying = TypeInfo("unsigned");
   I.IsUsing = true;
 
+  CommentInfo Top;
+  Top.Kind = "FullComment";
+
+  Top.Children.emplace_back(std::make_unique());
+  CommentInfo *BlankLine = Top.Children.back().get();
+  BlankLine->Kind = "ParagraphComment";
+  BlankLine->Children.emplace_back(std::make_unique());
+  BlankLine->Children.back()->Kind = "TextComment";
+
+  I.Description.emplace_back(std::move(Top));
+
   std::string WriteResult = writeInfo(&I);
   EXPECT_TRUE(WriteResult.size() > 0);
   std::vector> ReadResults = readInfo(WriteResult, 1);
 
   CheckTypedefInfo(&I, InfoAsTypedef(ReadResults[0].get()));
+
+  // Check one with no IsUsing set, no description, and no definition location.
+  TypedefInfo I2;
+  I2.Name = "SomethingElse";
+  I2.IsUsing = false;
+  I2.Underlying = TypeInfo("int");
+
+  WriteResult = writeInfo(&I2);
+  EXPECT_TRUE(WriteResult.size() > 0);
+  ReadResults = readInfo(WriteResult, 1);
+  CheckTypedefInfo(&I2, InfoAsTypedef(ReadResults[0].get()));
 }
 
 TEST(SerializeTest, emitInfoWithCommentBitcode) {
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -365,7 +365,7 @@
   //   using MyVector = std::vector
   // False means it's a C-style typedef:
   //   typedef std::vector MyVector;
-  bool IsUsing;
+  bool IsUsing = false;
 };
 
 struct BaseRecordInfo : public RecordInfo {
Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp
===
--- clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -432,6 +432,8 @@
   emitRecord(T.Name, TYPEDEF_NAME);
   for (const auto &N : T.Namespace)
 emitBlock(N, FieldId::F_namespace);
+  for (const auto &CI : T.Description)
+emitBlock(CI);
   if (T.DefLoc)
 emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION);
   emitRecord(T.IsUsing, TYPEDEF_IS_USING);
Index: clang-tools-extra/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -368,28 +368,27 @@
 }
 
 template <> llvm::Expected getCommentInfo(FunctionInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(NamespaceInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(RecordInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(MemberTypeInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(EnumInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
+}
+
+template <> llvm::Expected getCommentInfo(TypedefInfo *I) {
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(CommentInfo *I) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 7231c99 - [clang-doc] Fix typedef/using output.

2022-10-25 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-10-25T13:47:24-07:00
New Revision: 7231c9966e523a6fa20aa63b9a9245aff49cf881

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

LOG: [clang-doc] Fix typedef/using output.

Provides an initializer for the TypedefInfo.IsUsing member. Previously
this member was uninitialized and would produce random output.

Adds the Description (code comments) to the bitcode reader/writer.
Previously the typedef/using descriptions were lost during the bitcode
round-trip. Adds a test for this.

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

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 8e1db35532a05..524b82d9fcc53 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -368,28 +368,27 @@ template  llvm::Expected 
getCommentInfo(T I) {
 }
 
 template <> llvm::Expected getCommentInfo(FunctionInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(NamespaceInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(RecordInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(MemberTypeInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(EnumInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
+}
+
+template <> llvm::Expected getCommentInfo(TypedefInfo *I) {
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(CommentInfo *I) {

diff  --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index 7768f4b06519b..bb0698a5a4028 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -432,6 +432,8 @@ void ClangDocBitcodeWriter::emitBlock(const TypedefInfo &T) 
{
   emitRecord(T.Name, TYPEDEF_NAME);
   for (const auto &N : T.Namespace)
 emitBlock(N, FieldId::F_namespace);
+  for (const auto &CI : T.Description)
+emitBlock(CI);
   if (T.DefLoc)
 emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION);
   emitRecord(T.IsUsing, TYPEDEF_IS_USING);

diff  --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index d416306704611..7d76844462885 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -365,7 +365,7 @@ struct TypedefInfo : public SymbolInfo {
   //   using MyVector = std::vector
   // False means it's a C-style typedef:
   //   typedef std::vector MyVector;
-  bool IsUsing;
+  bool IsUsing = false;
 };
 
 struct BaseRecordInfo : public RecordInfo {

diff  --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp 
b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
index db6569419d579..53e84b1814453 100644
--- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -183,11 +183,33 @@ TEST(BitcodeTest, emitTypedefInfoBitcode) {
   I.Underlying = TypeInfo("unsigned");
   I.IsUsing = true;
 
+  CommentInfo Top;
+  Top.Kind = "FullComment";
+
+  Top.Children.emplace_back(std::make_unique());
+  CommentInfo *BlankLine = Top.Children.back().get();
+  BlankLine->Kind = "ParagraphComment";
+  BlankLine->Children.emplace_back(std::make_unique());
+  BlankLine->Children.back()->Kind = "TextComment";
+
+  I.Description.emplace_back(std::move(Top));
+
   std::string WriteResult = writeInfo(&I);
   EXPECT_TRUE(WriteResult.size() > 0);
   std::vector> ReadResults = readInfo(WriteResult, 1);
 
   CheckTypedefInfo(&I, InfoAsTypedef(ReadResults[0].get()));
+
+  // Check one with no IsUsing set, no description, and no definition location.
+  TypedefInfo I2;
+  I2.Name = "SomethingElse";
+  I2.IsUsing = false;
+  I2.Underlying = TypeInfo("int");
+
+  WriteResult = writeInfo(&I2);
+  EXPECT_TRUE(WriteResult.size() > 0);
+  ReadResults = readInfo(WriteResult, 1);
+  CheckTypedefInfo(&I2, InfoAsTypedef(ReadResults[0].get()));
 }
 
 TEST(SerializeTest, emitInfoWithCommentBitcode) {



__

[PATCH] D136638: [clang-doc] Fix typedef/using output.

2022-10-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth accepted this revision.
paulkirth added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:396-397
+template <> llvm::Expected getCommentInfo(TypedefInfo *I) {
+  I->Description.emplace_back();
+  return &I->Description.back();
+}

paulkirth wrote:
> nit: I know this is in the style of the rest of the file, but I believe that 
> code was written before LLVM allowed C++17.   I //think// we can just return 
> the reference from `emplace_back()` directly, right?
oh, I didn't intend for you to update the whole file, just what was in your 
change, but thank you for the code clean up!


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

https://reviews.llvm.org/D136638

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


[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

FWIW we do have precedent of deviating from cl.exe for determinism reasons. I 
think having deterministic output is a good default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

LG other than removing the redundant same-sloc-address check again (sorry!)




Comment at: clang/lib/Lex/TokenLexer.cpp:1010
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();

hokein wrote:
> sammccall wrote:
> > hokein wrote:
> > > sammccall wrote:
> > > > sammccall wrote:
> > > > > This seems to be missing the same-sloc-address-space check: it can 
> > > > > create a single file ID spanning a local and loaded sloc entry, which 
> > > > > will be corrupted by saving+loading
> > > > > 
> > > > (getOffset() would be much clearly correct than getRawEncoding())
> > > > missing the same-sloc-address-space check
> > > 
> > > oops, good spot. Indeed this is another behavior change in the 
> > > previous-rewriting patch :( -- the original behavior was that if two 
> > > consecutive tokens are not in the same address space, it split to two 
> > > expansion SLocEntries.
> > > 
> > > Fixed.
> > > oops, good spot. Indeed this is another behavior change in the 
> > > previous-rewriting patch :( 
> > 
> > Argh, I'm so sorry, this prompted me to take another look and there is no 
> > bug/need for the check at all.
> > 
> > Before we do the NearLast check we've already established that the FileID 
> > is the same, which means the locations are necessarily in the same address 
> > space.
> > 
> > We can replace the isInSameSLocAddrSpace with a raw offset comparison 
> > again...
> hmm, I think there was some misunderstanding here -- I thought you meant a 
> corner case where Last and T are in the same file, but Last.offset < 
> `CurrentLoadedOffset`, and T.offset > `CurrentLoadedOffset`. For this case, 
> there is a behavior change between both versions. 
> 
> I'm not sure whether this case is possible or it is reasonable to handle it, 
> since it is a running-out-of-sourcelocation-space case (clang's behavior is 
> somewhat inconsistent, in CreateFileID, we emit a too-large diagnostic, in 
> `createExpansionLocImpl`, it is just an assertion), maybe we should not worry 
> about this case, treat it as UB.
> hmm, I think there was some misunderstanding here -- I thought you meant a 
> corner case where Last and T are in the same file, but Last.offset < 
> CurrentLoadedOffset and T.offset > CurrentLoadedOffset

That's not possible, loaded vs local is a property of the FileID. I was missing 
that we'd established they're in the same FileID before checking deltas.



Comment at: clang/test/Lexer/update_consecutive_macro_address_space.c:2
+// RUN: %clang -cc1 -print-stats %s 2>&1 | FileCheck %s
+// CHECK: 6 local SLocEntry's allocated
+//

it's a shame there's no -cc1 flag for SourceManager::dump() or this could be 
much more direct...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


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

2022-10-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-25 Thread Tom Hughes via Phabricator via cfe-commits
tomhughes added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:697-698
 Builder.defineMacro("__ELF__");
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
+  }

I think this should apply to both C and C++


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136712

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


[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals

2022-10-25 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1345
   while (CurrentToken) {
-if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
+if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) {
   CurrentToken->setType(TT_ImplicitStringLiteral);

HazardyKnusperkeks wrote:
> This shouldn't be here. There is no closing brace for this, or am I missing 
> something?
No you are right it was a miss in the rebase. But it's fixed on main now. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136336

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


[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-25 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

Also this should have a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136474: [CodeView][clang] Disable emitting command line into CodeView by default and add flag to enable

2022-10-25 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

We have tooling that uses this command line from the PDB. I think the 
conservative approach is to emit the command line by default since this is how 
MSVC behaves. I don't mind this flag now that I know about it, but I think we 
should keep the default to what MSVC does for clang-cl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136615: [Instrumentation] Remove legacy passes

2022-10-25 Thread Arthur Eubanks 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 rGef37504879ee: [Instrumentation] Remove legacy passes 
(authored by aeubanks).

Changed prior to commit:
  https://reviews.llvm.org/D136615?vs=470185&id=470602#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136615

Files:
  clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  llvm/bindings/python/llvm/core.py
  llvm/include/llvm-c/Initialization.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h
  llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
  llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
  llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
  llvm/tools/bugpoint/bugpoint.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

Index: llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
===
--- llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -198,7 +198,6 @@
   initializeTransformUtils(Registry);
   initializeInstCombine(Registry);
   initializeAggressiveInstCombine(Registry);
-  initializeInstrumentation(Registry);
   initializeTarget(Registry);
 
   // Parse input options
Index: llvm/tools/bugpoint/bugpoint.cpp
===
--- llvm/tools/bugpoint/bugpoint.cpp
+++ llvm/tools/bugpoint/bugpoint.cpp
@@ -149,7 +149,6 @@
   initializeTransformUtils(Registry);
   initializeInstCombine(Registry);
   initializeAggressiveInstCombine(Registry);
-  initializeInstrumentation(Registry);
   initializeTarget(Registry);
 
   if (std::getenv("bar") == (char*) -1) {
Index: llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
===
--- llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
+++ llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
@@ -204,22 +204,6 @@
   Value *DynamicShadowOffset = nullptr;
 };
 
-class MemProfilerLegacyPass : public FunctionPass {
-public:
-  static char ID;
-
-  explicit MemProfilerLegacyPass() : FunctionPass(ID) {
-initializeMemProfilerLegacyPassPass(*PassRegistry::getPassRegistry());
-  }
-
-  StringRef getPassName() const override { return "MemProfilerFunctionPass"; }
-
-  bool runOnFunction(Function &F) override {
-MemProfiler Profiler(*F.getParent());
-return Profiler.instrumentFunction(F);
-  }
-};
-
 class ModuleMemProfiler {
 public:
   ModuleMemProfiler(Module &M) { TargetTriple = Triple(M.getTargetTriple()); }
@@ -232,24 +216,6 @@
   Function *MemProfCtorFunction = nullptr;
 };
 
-class ModuleMemProfilerLegacyPass : public ModulePass {
-public:
-  static char ID;
-
-  explicit ModuleMemProfilerLegacyPass() : ModulePass(ID) {
-initializeModuleMemProfilerLegacyPassPass(*PassRegistry::getPassRegistry());
-  }
-
-  StringRef getPassName() const override { return "ModuleMemProfiler"; }
-
-  void getAnalysisUsage(AnalysisUsage &AU) const override {}
-
-  bool runOnModule(Module &M) override {
-ModuleMemProfiler MemProfiler(M);
-return MemProfiler.instrumentModule(M);
-  }
-};
-
 } // end anonymous namespace
 
 MemProfilerPass::MemProfilerPass() = default;
@@ -273,30 +239,6 @@
   return PreservedAnalyses::all();
 }
 
-char MemProfilerLegacyPass::ID = 0;
-
-INITIALIZE_PASS_BEGIN(MemProfilerLegacyPass, "memprof",
-  "MemProfiler: profile memory allocations and accesses.",
-  false, false)
-INITIALIZE_PASS_END(MemProfilerLegacyPass, "memprof",
-"MemProfiler: profile memory allocations and accesses.",
-false, false)
-
-FunctionPass *llvm::createMemProfilerFunctionPass() {
-  return new MemProfilerLegacyPass();
-}
-
-char ModuleMemProfilerLegacyPass::ID = 0;
-
-INITIALIZE_PASS(ModuleMemProfilerLegacyPass, "memprof-module",
-"MemProfiler: profile memory allocations and accesses."
-"ModulePass",
-false, false)
-
-ModulePass *llvm::createModuleMemProfilerLegacyPassPass() {
-  return new ModuleMemProfilerLegacyPass();
-}
-
 Value *MemProfiler::memToShadow(Value *Shadow, IRBuilder<> &IRB) {
   // (Shadow & mask) >> scale
   Shadow = IRB.CreateAnd(Shadow, Mapping.Mask);
Index: llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -88,16 +88,3 @@
   return C;
 }
 
-/// initializeInstrumentation - Initialize all passes in the TransformUtils
-/// library.
-void llvm::initializeInstrumentation(PassRegistry &Registry) {
-  initializeMemProfilerLegacyPassPass(Registry);
-  initializeModuleMemP

[clang] ef37504 - [Instrumentation] Remove legacy passes

2022-10-25 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2022-10-25T13:11:07-07:00
New Revision: ef37504879eecab1af98c70888bee0be403b9c60

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

LOG: [Instrumentation] Remove legacy passes

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
llvm/bindings/python/llvm/core.py
llvm/include/llvm-c/Initialization.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h
llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
llvm/tools/bugpoint/bugpoint.cpp
llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

Removed: 




diff  --git a/clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp 
b/clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
index 20cf98896e220..235ff150523e2 100644
--- a/clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
+++ b/clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
@@ -49,7 +49,6 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
   initializeTransformUtils(Registry);
   initializeInstCombine(Registry);
   initializeAggressiveInstCombine(Registry);
-  initializeInstrumentation(Registry);
   initializeTarget(Registry);
 
   CLArgs.push_back("-O2");

diff  --git a/llvm/bindings/python/llvm/core.py 
b/llvm/bindings/python/llvm/core.py
index a9ec107faab71..4e99aac91182b 100644
--- a/llvm/bindings/python/llvm/core.py
+++ b/llvm/bindings/python/llvm/core.py
@@ -470,9 +470,6 @@ def register_library(library):
 library.LLVMInitializeIPO.argtypes = [PassRegistry]
 library.LLVMInitializeIPO.restype = None
 
-library.LLVMInitializeInstrumentation.argtypes = [PassRegistry]
-library.LLVMInitializeInstrumentation.restype = None
-
 library.LLVMInitializeAnalysis.argtypes = [PassRegistry]
 library.LLVMInitializeAnalysis.restype = None
 
@@ -626,7 +623,6 @@ def initialize_llvm():
 lib.LLVMInitializeVectorization(p)
 lib.LLVMInitializeInstCombine(p)
 lib.LLVMInitializeIPO(p)
-lib.LLVMInitializeInstrumentation(p)
 lib.LLVMInitializeAnalysis(p)
 lib.LLVMInitializeCodeGen(p)
 lib.LLVMInitializeTarget(p)

diff  --git a/llvm/include/llvm-c/Initialization.h 
b/llvm/include/llvm-c/Initialization.h
index 2f3f0f890d786..c7770d911969a 100644
--- a/llvm/include/llvm-c/Initialization.h
+++ b/llvm/include/llvm-c/Initialization.h
@@ -37,7 +37,6 @@ void LLVMInitializeVectorization(LLVMPassRegistryRef R);
 void LLVMInitializeInstCombine(LLVMPassRegistryRef R);
 void LLVMInitializeAggressiveInstCombiner(LLVMPassRegistryRef R);
 void LLVMInitializeIPO(LLVMPassRegistryRef R);
-void LLVMInitializeInstrumentation(LLVMPassRegistryRef R);
 void LLVMInitializeAnalysis(LLVMPassRegistryRef R);
 void LLVMInitializeIPA(LLVMPassRegistryRef R);
 void LLVMInitializeCodeGen(LLVMPassRegistryRef R);

diff  --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index 55aaa09caf9af..6d389d432998f 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -39,9 +39,6 @@ void initializeAggressiveInstCombine(PassRegistry&);
 /// Initialize all passes linked into the IPO library.
 void initializeIPO(PassRegistry&);
 
-/// Initialize all passes linked into the Instrumentation library.
-void initializeInstrumentation(PassRegistry&);
-
 /// Initialize all passes linked into the Analysis library.
 void initializeAnalysis(PassRegistry&);
 

diff  --git a/llvm/include/llvm/LinkAllPasses.h 
b/llvm/include/llvm/LinkAllPasses.h
index a2cf1f06e88e9..b8c52620e9c99 100644
--- a/llvm/include/llvm/LinkAllPasses.h
+++ b/llvm/include/llvm/LinkAllPasses.h
@@ -80,7 +80,6 @@ namespace {
   (void) llvm::createSCEVAAWrapperPass();
   (void) llvm::createTypeBasedAAWrapperPass();
   (void) llvm::createScopedNoAliasAAWrapperPass();
-  (void) llvm::createBoundsCheckingLegacyPass();
   (void) llvm::createBreakCriticalEdgesPass();
   (void) llvm::createCallGraphDOTPrinterPass();
   (void) llvm::createCallGraphViewerPass();

diff  --git a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h 
b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h
index 5e68141e3399c..6c961c247cba1 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h
@@ -22,10 +22,6 @@ struct BoundsCheckingPass : 
PassInfoMixin {
   static bool isRequired() { return true; }
 };
 
-
-/// Legacy pass creation functio

[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-25 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: abidh, tomhughes.
Herald added subscribers: kristof.beyls, ki.stfu, dschuff.
Herald added a project: All.
manojgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This matches other C++ drivers e.g. Linux that define
_GNU_SOURCE. This lets clang compiler more code by default
without explicitly passing _GNU_SOURCE on command line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136712

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Driver/arm-baremetal-defines.cpp


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o 
- 2>&1 | FileCheck %s
+
+// ECHO: {{.*}} "-cc1" {{.*}}mipsel-nacl-defines.c
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,11 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 2>&1 | FileCheck %s
+
+// ECHO: {{.*}} "-cc1" {{.*}}mipsel-nacl-defines.c
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,11 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D136539#3882922 , @sammccall wrote:

> In D136539#3882316 , @hokein wrote:
>
>>> This is a subtle change that needs careful review, and honestly should have 
>>> a test.
>>
>> I agree, and thanks for the nice review comments!
>>
>> I'd like to add a unittest, but I don't see a straight way (I manually test 
>> it by comparing the number of allocated SLocEntries and the used 
>> SourceLocation address space in `clang --print-stats` with/out this patch), 
>> some options:
>>
>> 1. construct a large TU that will make clang fails to compile without the 50 
>> trick patch;
>> 2. create a small test, and verify the the source location is split when the 
>> two consecutive tokens distance > 50, and verify the number of  in `clang 
>> print-stats`;
>>
>> 1 feels better to reflect the real behavior, the only concern is that this 
>> is a stress test, running it is expensive (we also have a similar 
>> `SourceLocationsOverlow.c`, I guess it is ok to add it).
>
> I was all ready to say that option 2 is the only practical one, and was 
> surprised that you had an actual testcase.
> I'm a bit nervous (it must be slow and eat tons of ram) but if we already 
> have a similar test...

now I change my mind -- this test is very expensive, taking ~8s to run (which 
is 4x slower than the `SourceLocationsOverlow.c`), adding it is not a good 
idea. Switched to 2.




Comment at: clang/lib/Lex/TokenLexer.cpp:1010
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > sammccall wrote:
> > > > This seems to be missing the same-sloc-address-space check: it can 
> > > > create a single file ID spanning a local and loaded sloc entry, which 
> > > > will be corrupted by saving+loading
> > > > 
> > > (getOffset() would be much clearly correct than getRawEncoding())
> > > missing the same-sloc-address-space check
> > 
> > oops, good spot. Indeed this is another behavior change in the 
> > previous-rewriting patch :( -- the original behavior was that if two 
> > consecutive tokens are not in the same address space, it split to two 
> > expansion SLocEntries.
> > 
> > Fixed.
> > oops, good spot. Indeed this is another behavior change in the 
> > previous-rewriting patch :( 
> 
> Argh, I'm so sorry, this prompted me to take another look and there is no 
> bug/need for the check at all.
> 
> Before we do the NearLast check we've already established that the FileID is 
> the same, which means the locations are necessarily in the same address space.
> 
> We can replace the isInSameSLocAddrSpace with a raw offset comparison again...
hmm, I think there was some misunderstanding here -- I thought you meant a 
corner case where Last and T are in the same file, but Last.offset < 
`CurrentLoadedOffset`, and T.offset > `CurrentLoadedOffset`. For this case, 
there is a behavior change between both versions. 

I'm not sure whether this case is possible or it is reasonable to handle it, 
since it is a running-out-of-sourcelocation-space case (clang's behavior is 
somewhat inconsistent, in CreateFileID, we emit a too-large diagnostic, in 
`createExpansionLocImpl`, it is just an assertion), maybe we should not worry 
about this case, treat it as UB.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 470599.
hokein marked an inline comment as not done.
hokein added a comment.

refine the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

Files:
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Lexer/update_consecutive_macro_address_space.c


Index: clang/test/Lexer/update_consecutive_macro_address_space.c
===
--- /dev/null
+++ clang/test/Lexer/update_consecutive_macro_address_space.c
@@ -0,0 +1,36 @@
+// RUN: %clang -cc1 -print-stats %s 2>&1 | FileCheck %s
+// CHECK: 6 local SLocEntry's allocated
+//
+// Verify that the macro arg expansion is split to two file ids, we have 6 file
+// ids rather than 5:
+//   0: invalid file id
+//   1: main file
+//   2: builtin file
+//   3: macro expansion for X
+//   4: macro arg expansions for 1
+//   5: macro arg expansions for == 2
+#define X(x) (int)(x);
+void func() {
+  X(1
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+/*/
+== 2);
+}
\ No newline at end of file
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -993,6 +993,16 @@
   llvm::MutableArrayRef All(begin_tokens, end_tokens);
   llvm::MutableArrayRef Partition;
 
+  auto NearLast = [&, Last = BeginLoc](SourceLocation Loc) mutable {
+// The maximum distance between two consecutive tokens in a partition.
+// This is an important trick to avoid using too much SourceLocation 
address
+// space!
+static constexpr SourceLocation::IntTy MaxDistance = 50;
+auto Distance = Loc.getRawEncoding() - Last.getRawEncoding();
+Last = Loc;
+return Distance <= MaxDistance;
+  };
+
   // Partition the tokens by their FileID.
   // This is a hot function, and calling getFileID can be expensive, the
   // implementation is optimized by reducing the number of getFileID.
@@ -1000,7 +1010,7 @@
 // Consecutive tokens not written in macros must be from the same file.
 // (Neither #include nor eof can occur inside a macro argument.)
 Partition = All.take_while([&](const Token &T) {
-  return T.getLocation().isFileID();
+  return T.getLocation().isFileID() && NearLast(T.getLocation());
 });
   } else {
 // Call getFileID once to calculate the bounds, and use the cheaper
@@ -1009,7 +1019,8 @@
 SourceLocation Limit =
 SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID));
 Partition = All.take_while([&](const Token &T) {
-  return T.getLocation() >= BeginLoc && T.getLocation() < Limit;
+  return T.getLocation() >= BeginLoc && T.getLocation() < Limit &&
+ NearLast(T.getLocation());
 });
   }
   assert(!Partition.empty());


Index: clang/test/Lexer/update_consecutive_macro_address_space.c
===
--- /dev/null
+++ clang/test/Lexer/update_co

[PATCH] D136638: [clang-doc] Fix typedef/using output.

2022-10-25 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 470598.

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

https://reviews.llvm.org/D136638

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -183,11 +183,33 @@
   I.Underlying = TypeInfo("unsigned");
   I.IsUsing = true;
 
+  CommentInfo Top;
+  Top.Kind = "FullComment";
+
+  Top.Children.emplace_back(std::make_unique());
+  CommentInfo *BlankLine = Top.Children.back().get();
+  BlankLine->Kind = "ParagraphComment";
+  BlankLine->Children.emplace_back(std::make_unique());
+  BlankLine->Children.back()->Kind = "TextComment";
+
+  I.Description.emplace_back(std::move(Top));
+
   std::string WriteResult = writeInfo(&I);
   EXPECT_TRUE(WriteResult.size() > 0);
   std::vector> ReadResults = readInfo(WriteResult, 1);
 
   CheckTypedefInfo(&I, InfoAsTypedef(ReadResults[0].get()));
+
+  // Check one with no IsUsing set, no description, and no definition location.
+  TypedefInfo I2;
+  I2.Name = "SomethingElse";
+  I2.IsUsing = false;
+  I2.Underlying = TypeInfo("int");
+
+  WriteResult = writeInfo(&I2);
+  EXPECT_TRUE(WriteResult.size() > 0);
+  ReadResults = readInfo(WriteResult, 1);
+  CheckTypedefInfo(&I2, InfoAsTypedef(ReadResults[0].get()));
 }
 
 TEST(SerializeTest, emitInfoWithCommentBitcode) {
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -365,7 +365,7 @@
   //   using MyVector = std::vector
   // False means it's a C-style typedef:
   //   typedef std::vector MyVector;
-  bool IsUsing;
+  bool IsUsing = false;
 };
 
 struct BaseRecordInfo : public RecordInfo {
Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp
===
--- clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -432,6 +432,8 @@
   emitRecord(T.Name, TYPEDEF_NAME);
   for (const auto &N : T.Namespace)
 emitBlock(N, FieldId::F_namespace);
+  for (const auto &CI : T.Description)
+emitBlock(CI);
   if (T.DefLoc)
 emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION);
   emitRecord(T.IsUsing, TYPEDEF_IS_USING);
Index: clang-tools-extra/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -368,28 +368,27 @@
 }
 
 template <> llvm::Expected getCommentInfo(FunctionInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(NamespaceInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(RecordInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(MemberTypeInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(EnumInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
+}
+
+template <> llvm::Expected getCommentInfo(TypedefInfo *I) {
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(CommentInfo *I) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals

2022-10-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1345
   while (CurrentToken) {
-if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
+if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) {
   CurrentToken->setType(TT_ImplicitStringLiteral);

This shouldn't be here. There is no closing brace for this, or am I missing 
something?



Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:653
+TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) {
+  // Everything after #pragma region should be ImplicitStringLiteral
+  auto Tokens = annotate("#pragma region Foo(Bar: Hello)");

Maybe you can add that in a additional commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136336

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


[PATCH] D133998: [HIP][test] Avoid %T

2022-10-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added subscribers: lamb-j, probinson.
probinson added a comment.

@MaskRay I see that you restored the `clang-driver` keyword in 
hip-link-bc-to-bc.hip, and of course that keyword is not defined anywhere so 
the test is never being run.
Is there an issue filed to track this?  Or is the original author aware? @lamb-j


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133998

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


[PATCH] D135340: [PGO] Make emitted symbols hidden

2022-10-25 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

In D135340#3882280 , @thakis wrote:

> This is still breaking `   Profile-x86_64 :: instrprof-darwin-dead-strip.c` 
> on mac. I'm reverting this again for now.

Sorry about that, I've tested it locally and it should be good to go now. But 
I'll give some time before resubmitting if you'd like to look it over.


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

https://reviews.llvm.org/D135340

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


[PATCH] D135340: [PGO] Make emitted symbols hidden

2022-10-25 Thread Alex Brachet via Phabricator via cfe-commits
abrachet updated this revision to Diff 470597.
abrachet added a comment.

Use sed to filter nm output instead of grep. grep exits with exit code 1 
because there are no matching lines. This is expected because there are no more 
external symbols other than `_main` and `__mh_execute_header`, note `_foo` has 
been dead stripped.


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

https://reviews.llvm.org/D135340

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld.c
  compiler-rt/lib/profile/InstrProfilingNameVar.c
  compiler-rt/lib/profile/InstrProfilingVersionVar.c
  compiler-rt/test/profile/instrprof-darwin-dead-strip.c
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Transforms/PGOProfile/branch1.ll
  llvm/test/Transforms/PGOProfile/branch2.ll
  llvm/test/Transforms/PGOProfile/comdat_internal.ll
  llvm/test/Transforms/PGOProfile/criticaledge.ll
  llvm/test/Transforms/PGOProfile/filename.ll
  llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
  llvm/test/Transforms/PGOProfile/landingpad.ll
  llvm/test/Transforms/PGOProfile/loop1.ll
  llvm/test/Transforms/PGOProfile/loop2.ll
  llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
  llvm/test/Transforms/PGOProfile/single_bb.ll
  llvm/test/Transforms/PGOProfile/switch.ll
  llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll

Index: llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll
===
--- llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll
+++ llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll
@@ -17,11 +17,11 @@
 ; RUN: llvm-dis %t.2.4.opt.bc -o - | FileCheck %s --check-prefixes=CSGEN,NOPREVAILING
 
 ;; Prevailing __llvm_profile_raw_version is kept by LTO.
-; PREVAILING: @__llvm_profile_raw_version = constant i64
+; PREVAILING: @__llvm_profile_raw_version = hidden constant i64
 
 ;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
 ;; declaration is retained.
-; NOPREVAILING: @__llvm_profile_raw_version = external constant i64
+; NOPREVAILING: @__llvm_profile_raw_version = external hidden constant i64
 ; CSGEN: @__profc_
 ; CSGEN: @__profd_
 
Index: llvm/test/Transforms/PGOProfile/switch.ll
===
--- llvm/test/Transforms/PGOProfile/switch.ll
+++ llvm/test/Transforms/PGOProfile/switch.ll
@@ -8,7 +8,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_switch = private constant [11 x i8] c"test_switch"
 
 define void @test_switch(i32 %i) {
Index: llvm/test/Transforms/PGOProfile/single_bb.ll
===
--- llvm/test/Transforms/PGOProfile/single_bb.ll
+++ llvm/test/Transforms/PGOProfile/single_bb.ll
@@ -3,7 +3,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_single_bb = private constant [9 x i8] c"single_bb"
 
 define i32 @single_bb() {
Index: llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
===
--- llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
+++ llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
@@ -11,11 +11,11 @@
 ; RUN: llvm-dis %t.0.0.preopt.bc -o - | FileCheck %s --check-prefix=IRPGOBE
 
 ;; Before LTO, we should have the __llvm_profile_raw_version definition.
-; IRPGOPRE: @__llvm_profile_raw_version = constant i64
+; IRPGOPRE: @__llvm_profile_raw_version = hidden constant i64
 
 ;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
 ;; declaration is retained.
-; IRPGOBE: @__llvm_profile_raw_version = external constant i64
+; IRPGOBE: @__llvm_profile_raw_version = external hidden constant i64
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
Index: llvm/test/Transforms/PGOProfile/loop2.ll
===
--- llvm/test/Transforms/PGOProfile/loop2.ll
+++ llvm/test/Transforms/PGOProfile/loop2.ll
@@ -8,7 +8,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_nested_for = private constant [15 x i8] c"test_nested_for"
 
 define i32 @test_nested_for(i32 %r, i32 %s) {
Index: llvm/test/Transforms/PGOProfile/loop1.ll
===
--- llvm/te

[PATCH] D136658: [clang-format] Move InsertBraces unit tests out of FormatTest.cpp

2022-10-25 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.

In D136658#3883372 , @rymiel wrote:

> Is the intent here to somewhat reduce the 30k line behemoth of FormatTest.cpp?

I'm all in for that! (And will provide a first patch soonish.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136658

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


[PATCH] D136710: [include-cleaner] Add the missing parts of Symbol and Header clases.

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136710

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/Types.cpp

Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -0,0 +1,38 @@
+//===--- Types.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/FileEntry.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace clang::include_cleaner {
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S) {
+  switch (S.kind()) {
+  case Symbol::Declaration:
+if (const auto *ND = llvm::dyn_cast(&S.declaration()))
+  return OS << ND->getNameAsString();
+return OS << S.declaration().getDeclKindName();
+  case Symbol::Standard:
+return OS << S.standard().scope() << S.standard().name();
+  }
+  llvm_unreachable("Unhandled Symbol kind");
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Header &H) {
+  switch (H.kind()) {
+  case Header::Physical:
+return OS << H.physical()->getName();
+  case Header::Standard:
+return OS << H.standard().name();
+  }
+  llvm_unreachable("Unhandled Header kind");
+}
+
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/lib/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/lib/CMakeLists.txt
@@ -4,6 +4,7 @@
   Analysis.cpp
   HTMLReport.cpp
   Record.cpp
+  Types.cpp
   WalkAST.cpp
 
   LINK_LIBS
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 
+namespace llvm {
+class raw_ostream;
+} // namespace llvm
 namespace clang {
 class Decl;
 class FileEntry;
@@ -33,28 +36,56 @@
 
 /// An entity that can be referenced in the code.
 struct Symbol {
+  enum Kind {
+// A canonical clang declaration.
+Declaration,
+// A recognized symbol from the standard library, like std::string.
+Standard,
+  };
+
   Symbol(Decl &D) : Storage(&D) {}
   Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
 
+  Kind kind() const { return static_cast(Storage.index()); }
+  bool operator==(const Symbol &RHS) const { return Storage == RHS.Storage; }
+
+  tooling::stdlib::Symbol standard() const {
+return std::get(Storage);
+  }
+  Decl &declaration() const { return *std::get(Storage); }
+
 private:
   // FIXME: Add support for macros.
-  std::variant Storage;
+  std::variant Storage;
 };
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Symbol &);
 
 /// Represents a file that provides some symbol. Might not be includeable, e.g.
 /// built-in or main-file itself.
 struct Header {
-  /// A physical (or logical, in case of a builtin) file.
+  enum Kind {
+// A source file parsed by clang. (May also be a  buffer).
+Physical,
+// A recognized standard library header, like .
+Standard,
+  };
+
   Header(const FileEntry *FE) : Storage(FE) {}
-  /// A logical file representing a stdlib header.
   Header(tooling::stdlib::Header H) : Storage(H) {}
 
+  Kind kind() const { return static_cast(Storage.index()); }
   bool operator==(const Header &RHS) const { return Storage == RHS.Storage; }
 
+  const FileEntry *physical() const { return std::get(Storage); }
+  tooling::stdlib::Header standard() const {
+return std::get(Storage);
+  }
+
 private:
   // FIXME: Handle verbatim spellings.
   std::variant Storage;
 };
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Header &);
 
 } // namespace include_cleaner
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131469: [Clang] change default storing path of `-ftime-trace`

2022-10-25 Thread Mészáros Gergely via Phabricator via cfe-commits
Maetveis added a comment.

In D131469#3808758 , @dongjunduo 
wrote:

> I'm sorry that I didn't see the comments until now because of some personal 
> work... Thank you for your kindness and suppot, I will improve this part of 
> work according to your idea in D133662  : )

Hey @dongjunduo,
Are you still interested in finishing this? If not I was thinking that I would 
pick it up, so I can work on the follow ups.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131469

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


[PATCH] D136703: [Driver][Fuchsia] Make -mfix-cortex-a53-835769 default when targeting Fuchsia

2022-10-25 Thread Alex Brachet 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 rG4981a186b3aa: [Driver][Fuchsia] Make -mfix-cortex-a53-835769 
default when targeting Fuchsia (authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136703

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-fix-cortex-a53-835769.c


Index: clang/test/Driver/aarch64-fix-cortex-a53-835769.c
===
--- clang/test/Driver/aarch64-fix-cortex-a53-835769.c
+++ clang/test/Driver/aarch64-fix-cortex-a53-835769.c
@@ -8,6 +8,12 @@
 // RUN: %clang -target aarch64-android-eabi %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-YES %s
 
+// RUN: %clang --target=aarch64-fuchsia %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-YES %s
+
+// RUN: %clang --target=aarch64-fuchsia -mcpu=cortex-a73 %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-DEF %s
+
 // CHECK-DEF-NOT: "{[+-]}fix-cortex-a53-835769"
 // CHECK-YES: "+fix-cortex-a53-835769"
 // CHECK-NO: "-fix-cortex-a53-835769"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "AArch64.h"
+#include "../CommonArgs.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -615,6 +616,10 @@
   } else if (Triple.isAndroid()) {
 // Enabled A53 errata (835769) workaround by default on android
 Features.push_back("+fix-cortex-a53-835769");
+  } else if (Triple.isOSFuchsia()) {
+std::string CPU = getCPUName(D, Args, Triple);
+if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
+  Features.push_back("+fix-cortex-a53-835769");
   }
 
   if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))


Index: clang/test/Driver/aarch64-fix-cortex-a53-835769.c
===
--- clang/test/Driver/aarch64-fix-cortex-a53-835769.c
+++ clang/test/Driver/aarch64-fix-cortex-a53-835769.c
@@ -8,6 +8,12 @@
 // RUN: %clang -target aarch64-android-eabi %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-YES %s
 
+// RUN: %clang --target=aarch64-fuchsia %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-YES %s
+
+// RUN: %clang --target=aarch64-fuchsia -mcpu=cortex-a73 %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-DEF %s
+
 // CHECK-DEF-NOT: "{[+-]}fix-cortex-a53-835769"
 // CHECK-YES: "+fix-cortex-a53-835769"
 // CHECK-NO: "-fix-cortex-a53-835769"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "AArch64.h"
+#include "../CommonArgs.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -615,6 +616,10 @@
   } else if (Triple.isAndroid()) {
 // Enabled A53 errata (835769) workaround by default on android
 Features.push_back("+fix-cortex-a53-835769");
+  } else if (Triple.isOSFuchsia()) {
+std::string CPU = getCPUName(D, Args, Triple);
+if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
+  Features.push_back("+fix-cortex-a53-835769");
   }
 
   if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4981a18 - [Driver][Fuchsia] Make -mfix-cortex-a53-835769 default when targeting Fuchsia

2022-10-25 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2022-10-25T19:17:52Z
New Revision: 4981a186b3aa5fbe207dce4902d4dce504974f3f

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

LOG: [Driver][Fuchsia] Make -mfix-cortex-a53-835769 default when targeting 
Fuchsia

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/test/Driver/aarch64-fix-cortex-a53-835769.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 7956a0be46280..514db4ca4f7e3 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "AArch64.h"
+#include "../CommonArgs.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -615,6 +616,10 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
   } else if (Triple.isAndroid()) {
 // Enabled A53 errata (835769) workaround by default on android
 Features.push_back("+fix-cortex-a53-835769");
+  } else if (Triple.isOSFuchsia()) {
+std::string CPU = getCPUName(D, Args, Triple);
+if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
+  Features.push_back("+fix-cortex-a53-835769");
   }
 
   if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))

diff  --git a/clang/test/Driver/aarch64-fix-cortex-a53-835769.c 
b/clang/test/Driver/aarch64-fix-cortex-a53-835769.c
index 287d9bcd5797e..7e809866fc502 100644
--- a/clang/test/Driver/aarch64-fix-cortex-a53-835769.c
+++ b/clang/test/Driver/aarch64-fix-cortex-a53-835769.c
@@ -8,6 +8,12 @@
 // RUN: %clang -target aarch64-android-eabi %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-YES %s
 
+// RUN: %clang --target=aarch64-fuchsia %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-YES %s
+
+// RUN: %clang --target=aarch64-fuchsia -mcpu=cortex-a73 %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-DEF %s
+
 // CHECK-DEF-NOT: "{[+-]}fix-cortex-a53-835769"
 // CHECK-YES: "+fix-cortex-a53-835769"
 // CHECK-NO: "-fix-cortex-a53-835769"



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


[PATCH] D136639: [CodeGen][ObjC] Fix a memory leak that occurs when a non-trivial C struct property is set using dot notation

2022-10-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/test/CodeGenObjC/nontrivial-c-struct-property.m:89
+
+// CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP_ENSURED]])
+

It looks like we're copying `a` into a temporary and then copying out of that 
temporary into the argument slot.  I don't see any reason the extra copy is 
required.

Also, aren't non-trivial structs consumed as arguments?  If so, this would be 
an over-release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136639

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


[PATCH] D136701: [LinkerWrapper] Perform device linking steps in parallel

2022-10-25 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D136701#3883300 , @jhuber6 wrote:

> However, as an opt-in feature it would be very helpful in some cases.

I'm OK with the explicit opt-in.

> Like consider someone creating a static library that supports every GPU 
> architecture LLVM supports, it would be nice to be able to optionally turn on 
> parallelism in the driver.

Yes, but the implicit assumption here is that you have sufficient resources. If 
you create N libraries, each for M architectures, your build machine may not 
have enough memory for N*M linkers.
Having N*M processes may or may not be an issue, but if each of the linkers is 
an `lld` which may want to run their own K parallel threads, it would not help 
anything.

In other words, I agree that it may be helpful in some cases, but I can also 
see how it may actually hurt the build, possibly catastrophically.

>   clang lib.c -fopenmp -O3 -fvisibility=hidden -foffload-lto -nostdlib 
> --offload-arch=gfx700,gfx701,gfx801,gfx803,gfx900,gfx902,gfx906,gfx908,gfx90a,gfx90c,gfx940,gfx1010,gfx1030,gfx1031,gfx1032,gfx1033,gfx1034,gfx1035,gfx1036,gfx1100,gfx1101,gfx1102,gfx1103,sm_35,sm_37,sm_50,sm_52,sm_53,sm_60,sm_61,sm_62,sm_70,sm_72,sm_75,sm_80,sm_86
>
> This is something we might be doing more often as we start trying to provide 
> standard library features on the GPU via static libraries. It might be 
> wasteful to compile for every architecture but I think it's the soundest 
> approach if we want compatibility.

My point is that grabbing resources will likely break build system's 
assumptions about their availability. How that would affect the build is 
anyone's guess. With infinite resources, parallel-everything would win, but in 
practice it's a big maybe. It would likely be a win for small builds and 
probably would be a wash or a regression for a larger build with multiple such 
targets.

Ideally it would be great if there would be a way to cooperate with the build 
system and let it manage the scheduling, but I don't think we have a good way 
of doing that. 
E.g. for CUDA compilation I was thinking of exposing per-GPU sub-compilations 
(well, we already do with --cuda-device-only/--cuda-device-only) and providing 
a way to create  combined object from them, and then let the build system 
manage how those per-GPU compilations would be launched. The problem there is 
that the build system would need to know our under-the-hood implementation 
details, so such an approach will be very fragile. The way the new driver does 
things may be a bit more suitable for this, but I suspect it would still be 
hard to do.

> `lld` already uses all available threads for its parallel linking, the linker 
> wrapper runs before the host linker invocation so it shouldn't interfere 
> either.

You do have a point here. As long as we don't end up with too many threads 
(e.g. we guarantee that per-offload linker instance does not run their own 
parallel threads, offload linking may be similar to parallel lld.

> This is only non-deterministic for the order of linking jobs between several 
> targets and architectures. If the user only links a single architecture it 
> should behave as before.

I'm not sure what you mean. Are you saying that linking with 
`--offload-arch=gfx700` is repeatable, but with `--offload-arch=gfx700,gfx701` 
it's not? That would still be a problem.

> The average case is still probably going to be one or two architectures at 
> once, in which case this change won't make much of a difference.

Any difference is a difference, as far as content-based caching and provenance 
tracking is concerned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136701

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-25 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1865-1869
+if ((LangOpts.FastMath ||
+ !LangOpts.FastMath && LangOpts.AllowFPReassoc && LangOpts.AllowRecip 
&&
+ !LangOpts.FiniteMathOnly && LangOpts.NoSignedZero &&
+ LangOpts.ApproxFunc) &&
+LangOpts.getDefaultFPContractMode() != 
LangOptions::FPModeKind::FPM_Off)

michele.scandale wrote:
> If I look at the clang driver code, `-funsafe-math-optimizations` is 
> specified on the CC1 command line if
> ```
> !MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc 
> && !TrappingMath
> ```
> is true.
> This means that it shouldn't matter the value of the floating point 
> contraction, or whether infs/nans are honored or not.
> 
> Was there another issue that this specific part of the change addresses?
This is to make sure that if we are using -ffast-math or 
-funsafe-math-optimization along with -ffp-contract=off, fma instructions are 
not generated.  In this case the function shouldn't be marked with the 
unsafe-fp-math attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

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


[PATCH] D125728: [WebAssembly] Update supported features in -mcpu=generic

2022-10-25 Thread Dan Gohman 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 rG1e4e2433bcd1: [WebAssembly] Update supported features in the 
generic CPU configuration (authored by sunfish).

Changed prior to commit:
  https://reviews.llvm.org/D125728?vs=431067&id=470584#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125728

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/test/Driver/wasm-features.c


Index: clang/test/Driver/wasm-features.c
===
--- /dev/null
+++ clang/test/Driver/wasm-features.c
@@ -0,0 +1,43 @@
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -fsyntax-only 2>&1 | 
FileCheck %s
+
+// CHECK: "-fvisibility=hidden"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s 2>&1 | FileCheck %s 
-check-prefix=DEFAULT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=mvp 2>&1 | 
FileCheck %s -check-prefix=MVP
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=bleeding-edge 
2>&1 | FileCheck %s -check-prefix=BLEEDING-EDGE
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mbulk-memory 2>&1 | 
FileCheck %s -check-prefix=BULK-MEMORY
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-bulk-memory 2>&1 | 
FileCheck %s -check-prefix=NO-BULK-MEMORY
+
+// BULK-MEMORY: "-target-feature" "+bulk-memory"
+// NO-BULK-MEMORY: "-target-feature" "-bulk-memory"
+// DEFAULT-NOT: "-target-feature" "-bulk-memory"
+// MVP-NOT: "-target-feature" "+bulk-memory"
+// BLEEDING-EDGE-NOT: "-target-feature" "-bulk-memory"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mmutable-globals 2>&1 
| FileCheck %s -check-prefix=MUTABLE-GLOBALS
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-mutable-globals 
2>&1 | FileCheck %s -check-prefix=NO-MUTABLE-GLOBALS
+
+// MUTABLE-GLOBALS: "-target-feature" "+mutable-globals"
+// NO-MUTABLE-GLOBALS: "-target-feature" "-mutable-globals"
+// DEFAULT-NOT: "-target-feature" "-mutable-globals"
+// MVP-NOT: "-target-feature" "+mutable-globals"
+// BLEEDING-EDGE-NOT: "-target-feature" "-mutable-globals"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -msign-ext 2>&1 | 
FileCheck %s -check-prefix=SIGN-EXT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-sign-ext 2>&1 | 
FileCheck %s -check-prefix=NO-SIGN-EXT
+
+// SIGN-EXT: "-target-feature" "+sign-ext"
+// NO-SIGN-EXT: "-target-feature" "-sign-ext"
+// DEFAULT-NOT: "-target-feature" "-sign-ext"
+// MVP-NOT: "-target-feature" "+sign-ext"
+// BLEEDING-EDGE-NOT: "-target-feature" "-sign-ext"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mnontrapping-fptoint 
2>&1 | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s 
-mno-nontrapping-fptoint 2>&1 | FileCheck %s 
-check-prefix=NO-NONTRAPPING-FPTOINT
+
+// NONTRAPPING-FPTOINT: "-target-feature" "+nontrapping-fptoint"
+// NO-NONTRAPPING-FPTOINT: "-target-feature" "-nontrapping-fptoint"
+// DEFAULT-NOT: "-target-feature" "-nontrapping-fptoint"
+// MVP-NOT: "-target-feature" "+nontrapping-fptoint"
+// BLEEDING-EDGE-NOT: "-target-feature" "-nontrapping-fptoint"
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,6 +147,9 @@
 Features["mutable-globals"] = true;
 Features["tail-call"] = true;
 setSIMDLevel(Features, SIMD128, true);
+  } else if (CPU == "generic") {
+Features["sign-ext"] = true;
+Features["mutable-globals"] = true;
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -607,6 +607,12 @@
   * Support intrinsic of ``__cmpccxadd_epi32``.
   * Support intrinsic of ``__cmpccxadd_epi64``.
 
+WebAssembly Support in Clang
+
+
+The -mcpu=generic configuration now enables sign-ext and mutable-globals. These
+proposals are standardized and available in all major engines.
+
 DWARF Support in Clang
 --
 


Index: clang/test/Driver/wasm-features.c
===
--- /dev/null
+++ clang/test/Driver/wasm-features.c
@@ -0,0 +1,43 @@
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -fsyntax-only 2>&1 | FileCheck %s
+
+// CHECK: "-fvisibility=hidden"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=mvp 2>&1 | FileCheck %s -check-prefix=MVP
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=bleeding-edge 2

[clang] 1e4e243 - [WebAssembly] Update supported features in the generic CPU configuration

2022-10-25 Thread Dan Gohman via cfe-commits

Author: Dan Gohman
Date: 2022-10-25T11:44:22-07:00
New Revision: 1e4e2433bcd1a0296ef1043c462252f0d087d90c

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

LOG: [WebAssembly] Update supported features in the generic CPU configuration

Enable sign-ext and mutable-globals in -mcpu=generic. This makes these features
enabled by default.

These features are all [finished proposals], and all major wasm engines
support them.

[finished proposals]: 
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md

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

Added: 
clang/test/Driver/wasm-features.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/WebAssembly.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 93462a16ef8fa..5beaf8e532c91 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -607,6 +607,12 @@ X86 Support in Clang
   * Support intrinsic of ``__cmpccxadd_epi32``.
   * Support intrinsic of ``__cmpccxadd_epi64``.
 
+WebAssembly Support in Clang
+
+
+The -mcpu=generic configuration now enables sign-ext and mutable-globals. These
+proposals are standardized and available in all major engines.
+
 DWARF Support in Clang
 --
 

diff  --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index e0e7f6a25f2b7..a170a7e9f8cdd 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,6 +147,9 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["mutable-globals"] = true;
 Features["tail-call"] = true;
 setSIMDLevel(Features, SIMD128, true);
+  } else if (CPU == "generic") {
+Features["sign-ext"] = true;
+Features["mutable-globals"] = true;
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);

diff  --git a/clang/test/Driver/wasm-features.c 
b/clang/test/Driver/wasm-features.c
new file mode 100644
index 0..e5f71b42b5055
--- /dev/null
+++ b/clang/test/Driver/wasm-features.c
@@ -0,0 +1,43 @@
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -fsyntax-only 2>&1 | 
FileCheck %s
+
+// CHECK: "-fvisibility=hidden"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s 2>&1 | FileCheck %s 
-check-prefix=DEFAULT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=mvp 2>&1 | 
FileCheck %s -check-prefix=MVP
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=bleeding-edge 
2>&1 | FileCheck %s -check-prefix=BLEEDING-EDGE
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mbulk-memory 2>&1 | 
FileCheck %s -check-prefix=BULK-MEMORY
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-bulk-memory 2>&1 | 
FileCheck %s -check-prefix=NO-BULK-MEMORY
+
+// BULK-MEMORY: "-target-feature" "+bulk-memory"
+// NO-BULK-MEMORY: "-target-feature" "-bulk-memory"
+// DEFAULT-NOT: "-target-feature" "-bulk-memory"
+// MVP-NOT: "-target-feature" "+bulk-memory"
+// BLEEDING-EDGE-NOT: "-target-feature" "-bulk-memory"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mmutable-globals 2>&1 
| FileCheck %s -check-prefix=MUTABLE-GLOBALS
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-mutable-globals 
2>&1 | FileCheck %s -check-prefix=NO-MUTABLE-GLOBALS
+
+// MUTABLE-GLOBALS: "-target-feature" "+mutable-globals"
+// NO-MUTABLE-GLOBALS: "-target-feature" "-mutable-globals"
+// DEFAULT-NOT: "-target-feature" "-mutable-globals"
+// MVP-NOT: "-target-feature" "+mutable-globals"
+// BLEEDING-EDGE-NOT: "-target-feature" "-mutable-globals"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -msign-ext 2>&1 | 
FileCheck %s -check-prefix=SIGN-EXT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-sign-ext 2>&1 | 
FileCheck %s -check-prefix=NO-SIGN-EXT
+
+// SIGN-EXT: "-target-feature" "+sign-ext"
+// NO-SIGN-EXT: "-target-feature" "-sign-ext"
+// DEFAULT-NOT: "-target-feature" "-sign-ext"
+// MVP-NOT: "-target-feature" "+sign-ext"
+// BLEEDING-EDGE-NOT: "-target-feature" "-sign-ext"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mnontrapping-fptoint 
2>&1 | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT
+// RUN: %clang --target=wasm32-unknown-unknown -### %s 
-mno-nontrapping-fptoint 2>&1 | FileCheck %s 
-check-prefix=NO-NONTRAPPING-FPTOINT
+
+// NONTRAPPING-FPTOINT: "-target-feature" "+nontrapping-fptoint"
+// NO-NONTRAPPING-FPTOINT: "-target-feature" "-nontrapping-fptoint"
+// DEFAULT-NOT: "-target-feature" "-nontrapping-fptoint"
+// MVP-NOT: "-target-feature" "+nontrapping-fptoint"
+// BLEEDING-EDGE-NOT: "-target-feature" "-nontrapping-fptoint"



___
cfe-commits mailing list
cfe-commit

[PATCH] D136658: [clang-format] Move InsertBraces unit tests out of FormatTest.cpp

2022-10-25 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Is the intent here to somewhat reduce the 30k line behemoth of FormatTest.cpp?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136658

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


[PATCH] D136707: [clang][Toolchains][Gnu] pass -gdwarf-* through to assembler

2022-10-25 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.h:107
 
 unsigned ParseDebugDefaultVersion(const ToolChain &TC,
   const llvm::opt::ArgList &Args);

This can be made static to the .cpp file now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136707

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


  1   2   3   >