[clang] efae1a7 - [docs] clang.rst: gnu++14 => gnu++17

2022-10-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-10-29T00:15:24-07:00
New Revision: efae1a7cf06bd71f7ec6e8dc9e5c2b085150a451

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

LOG: [docs] clang.rst: gnu++14 => gnu++17

Added: 


Modified: 
clang/docs/CommandGuide/clang.rst

Removed: 




diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 5e344ec702777..7277b598f0cad 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -201,7 +201,7 @@ Language Selection and Mode Options
 
Working draft for ISO C++ 2023 with GNU extensions
 
- The default C++ language standard is ``gnu++14``.
+ The default C++ language standard is ``gnu++17``.
 
  Supported values for the OpenCL language are:
 



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


[PATCH] D134410: [clang][CodeGen] Add noundef metadata to load instructions (preliminary 1 or 2)

2022-10-29 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

I think adding this under a default-disabled flag is fine for evaluation 
purposes, but I have doubts that we will ever be able to enable this by 
default. There is a lot of code out there assuming that copying uninitialized 
data around is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134410

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


[PATCH] D136998: Try to implement lambdas with inalloca parameters by inlining the call operator function.

2022-10-29 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added inline comments.



Comment at: clang/lib/CodeGen/CGClass.cpp:3080
+  if (I.getName().equals("this")) {
+VMap[&I] = llvm::UndefValue::get(I.getType());
+  }

Please use PoisonValue instead whenever possible, as we are trying to remove 
undef from LLVM.
Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136998

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


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Inching closer to ClangBuiltLinux on LoongArch it seems!




Comment at: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp:64
+  break;
+  // TODO: handle other extra codes if we have.
 }

nit: "if any"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136841

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


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 471729.
SixWeining added a comment.

Fix nit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136841

Files:
  clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/test/CodeGen/LoongArch/inline-asm-operand-modidiers.ll

Index: llvm/test/CodeGen/LoongArch/inline-asm-operand-modidiers.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-operand-modidiers.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s
+
+define i32 @modifier_z_zero(i32 %a) nounwind {
+; CHECK-LABEL: modifier_z_zero:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:#APP
+; CHECK-NEXT:add.w $a0, $a0, $zero
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+  %1 = tail call i32 asm "add.w $0, $1, ${2:z}", "=r,r,ri"(i32 %a, i32 0)
+  ret i32 %1
+}
+
+define i32 @modifier_z_nonzero(i32 %a) nounwind {
+; CHECK-LABEL: modifier_z_nonzero:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:#APP
+; CHECK-NEXT:addi.w $a0, $a0, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, ${2:z}", "=r,r,ri"(i32 %a, i32 1)
+  ret i32 %1
+}
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -47,24 +47,38 @@
   if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
 return false;
 
-  // TODO: handle other extra codes if we have.
-  if (!ExtraCode) {
-const MachineOperand &MO = MI->getOperand(OpNo);
-switch (MO.getType()) {
-case MachineOperand::MO_Immediate:
-  OS << MO.getImm();
-  return false;
-case MachineOperand::MO_Register:
-  OS << '$' << LoongArchInstPrinter::getRegisterName(MO.getReg());
-  return false;
-case MachineOperand::MO_GlobalAddress:
-  PrintSymbolOperand(MO, OS);
-  return false;
+  const MachineOperand &MO = MI->getOperand(OpNo);
+  if (ExtraCode && ExtraCode[0]) {
+if (ExtraCode[1] != 0)
+  return true; // Unknown modifier.
+
+switch (ExtraCode[0]) {
 default:
-  llvm_unreachable("not implemented");
+  return true; // Unknown modifier.
+case 'z':  // Print $zero register if zero, regular printing otherwise.
+  if (MO.isImm() && MO.getImm() == 0) {
+OS << '$' << LoongArchInstPrinter::getRegisterName(LoongArch::R0);
+return false;
+  }
+  break;
+  // TODO: handle other extra codes if any.
 }
   }
 
+  switch (MO.getType()) {
+  case MachineOperand::MO_Immediate:
+OS << MO.getImm();
+return false;
+  case MachineOperand::MO_Register:
+OS << '$' << LoongArchInstPrinter::getRegisterName(MO.getReg());
+return false;
+  case MachineOperand::MO_GlobalAddress:
+PrintSymbolOperand(MO, OS);
+return false;
+  default:
+llvm_unreachable("not implemented");
+  }
+
   return true;
 }
 
Index: clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
===
--- /dev/null
+++ clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
@@ -0,0 +1,25 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple loongarch32 -O2 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple loongarch64 -O2 -emit-llvm %s -o - | FileCheck %s
+
+/// Test LoongArch specific operand modifiers (i.e. operand codes).
+
+// CHECK-LABEL: @test_z_zero(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 asm sideeffect "add.w $0, $1, ${2:z}", "=r,r,ri"(i32 [[A:%.*]], i32 0) #[[ATTR1]], !srcloc !4
+// CHECK-NEXT:ret void
+//
+void test_z_zero(int a) {
+  int tmp;
+  asm volatile ("add.w %0, %1, %z2" : "=r" (tmp) : "r" (a), "ri" (0));
+}
+
+// CHECK-LABEL: @test_z_nonzero(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 asm sideeffect "add.w $0, $1, ${2:z}", "=r,r,ri"(i32 [[A:%.*]], i32 1) #[[ATTR1]], !srcloc !5
+// CHECK-NEXT:ret void
+//
+void test_z_nonzero(int a) {
+  int tmp;
+  asm volatile ("add.w %0, %1, %z2" : "=r" (tmp) : "r" (a), "ri" (1));
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Ah. There's a typo in the name of the testcase file...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136841

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


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

In D136841#3893966 , @xen0n wrote:

> Ah. There's a typo in the name of the testcase file...

:(-


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136841

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


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 471730.
SixWeining added a comment.

Fix testcase file name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136841

Files:
  clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/test/CodeGen/LoongArch/inline-asm-operand-modifiers.ll

Index: llvm/test/CodeGen/LoongArch/inline-asm-operand-modifiers.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-operand-modifiers.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s
+
+define i32 @modifier_z_zero(i32 %a) nounwind {
+; CHECK-LABEL: modifier_z_zero:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:#APP
+; CHECK-NEXT:add.w $a0, $a0, $zero
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+  %1 = tail call i32 asm "add.w $0, $1, ${2:z}", "=r,r,ri"(i32 %a, i32 0)
+  ret i32 %1
+}
+
+define i32 @modifier_z_nonzero(i32 %a) nounwind {
+; CHECK-LABEL: modifier_z_nonzero:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:#APP
+; CHECK-NEXT:addi.w $a0, $a0, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, ${2:z}", "=r,r,ri"(i32 %a, i32 1)
+  ret i32 %1
+}
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -47,24 +47,38 @@
   if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
 return false;
 
-  // TODO: handle other extra codes if we have.
-  if (!ExtraCode) {
-const MachineOperand &MO = MI->getOperand(OpNo);
-switch (MO.getType()) {
-case MachineOperand::MO_Immediate:
-  OS << MO.getImm();
-  return false;
-case MachineOperand::MO_Register:
-  OS << '$' << LoongArchInstPrinter::getRegisterName(MO.getReg());
-  return false;
-case MachineOperand::MO_GlobalAddress:
-  PrintSymbolOperand(MO, OS);
-  return false;
+  const MachineOperand &MO = MI->getOperand(OpNo);
+  if (ExtraCode && ExtraCode[0]) {
+if (ExtraCode[1] != 0)
+  return true; // Unknown modifier.
+
+switch (ExtraCode[0]) {
 default:
-  llvm_unreachable("not implemented");
+  return true; // Unknown modifier.
+case 'z':  // Print $zero register if zero, regular printing otherwise.
+  if (MO.isImm() && MO.getImm() == 0) {
+OS << '$' << LoongArchInstPrinter::getRegisterName(LoongArch::R0);
+return false;
+  }
+  break;
+  // TODO: handle other extra codes if any.
 }
   }
 
+  switch (MO.getType()) {
+  case MachineOperand::MO_Immediate:
+OS << MO.getImm();
+return false;
+  case MachineOperand::MO_Register:
+OS << '$' << LoongArchInstPrinter::getRegisterName(MO.getReg());
+return false;
+  case MachineOperand::MO_GlobalAddress:
+PrintSymbolOperand(MO, OS);
+return false;
+  default:
+llvm_unreachable("not implemented");
+  }
+
   return true;
 }
 
Index: clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
===
--- /dev/null
+++ clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
@@ -0,0 +1,25 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple loongarch32 -O2 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple loongarch64 -O2 -emit-llvm %s -o - | FileCheck %s
+
+/// Test LoongArch specific operand modifiers (i.e. operand codes).
+
+// CHECK-LABEL: @test_z_zero(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 asm sideeffect "add.w $0, $1, ${2:z}", "=r,r,ri"(i32 [[A:%.*]], i32 0) #[[ATTR1]], !srcloc !4
+// CHECK-NEXT:ret void
+//
+void test_z_zero(int a) {
+  int tmp;
+  asm volatile ("add.w %0, %1, %z2" : "=r" (tmp) : "r" (a), "ri" (0));
+}
+
+// CHECK-LABEL: @test_z_nonzero(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 asm sideeffect "add.w $0, $1, ${2:z}", "=r,r,ri"(i32 [[A:%.*]], i32 1) #[[ATTR1]], !srcloc !5
+// CHECK-NEXT:ret void
+//
+void test_z_nonzero(int a) {
+  int tmp;
+  asm volatile ("add.w %0, %1, %z2" : "=r" (tmp) : "r" (a), "ri" (1));
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136815: [clang][Interp] Ignore visitDecl() for local declarations

2022-10-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471731.
tbaeder edited the summary of this revision.

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

https://reviews.llvm.org/D136815

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h

Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -78,7 +78,8 @@
   llvm::Optional getGlobal(const ValueDecl *VD);
 
   /// Returns or creates a global an creates an index to it.
-  llvm::Optional getOrCreateGlobal(const ValueDecl *VD);
+  llvm::Optional getOrCreateGlobal(const ValueDecl *VD,
+ const Expr *Init = nullptr);
 
   /// Returns or creates a dummy value for parameters.
   llvm::Optional getOrCreateDummy(const ParmVarDecl *PD);
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -125,11 +125,12 @@
   return Index;
 }
 
-llvm::Optional Program::getOrCreateGlobal(const ValueDecl *VD) {
+llvm::Optional Program::getOrCreateGlobal(const ValueDecl *VD,
+const Expr *Init) {
   if (auto Idx = getGlobal(VD))
 return Idx;
 
-  if (auto Idx = createGlobal(VD, nullptr)) {
+  if (auto Idx = createGlobal(VD, Init)) {
 GlobalIndices[VD] = *Idx;
 return Idx;
   }
@@ -157,6 +158,7 @@
 
 llvm::Optional Program::createGlobal(const ValueDecl *VD,
const Expr *Init) {
+  assert(!getGlobal(VD));
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast(VD)) {
 IsStatic = !Var->hasLocalStorage();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -65,7 +65,6 @@
   bool visitContinueStmt(const ContinueStmt *S);
 
   /// Compiles a variable declaration.
-  bool visitVarDecl(const VarDecl *VD);
 
 private:
   /// Type of the expression returned by the function.
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -206,7 +206,7 @@
   for (auto *D : DS->decls()) {
 // Variable declarator.
 if (auto *VD = dyn_cast(D)) {
-  if (!visitVarDecl(VD))
+  if (!this->visitVarDecl(VD))
 return false;
   continue;
 }
@@ -386,37 +386,6 @@
   return this->jump(*ContinueLabel);
 }
 
-template 
-bool ByteCodeStmtGen::visitVarDecl(const VarDecl *VD) {
-  if (!VD->hasLocalStorage()) {
-// No code generation required.
-return true;
-  }
-
-  // Integers, pointers, primitives.
-  if (Optional T = this->classify(VD->getType())) {
-const Expr *Init = VD->getInit();
-
-unsigned Offset =
-this->allocateLocalPrimitive(VD, *T, VD->getType().isConstQualified());
-// Compile the initializer in its own scope.
-if (Init) {
-  ExprScope Scope(this);
-  if (!this->visit(Init))
-return false;
-
-  return this->emitSetLocal(*T, Offset, VD);
-}
-return true;
-  }
-
-  // Composite types - allocate storage and initialize it.
-  if (Optional Offset = this->allocateLocal(VD))
-return this->visitLocalInitializer(VD->getInit(), *Offset);
-
-  return this->bail(VD);
-}
-
 namespace clang {
 namespace interp {
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -93,8 +93,8 @@
 protected:
   bool visitExpr(const Expr *E) override;
   bool visitDecl(const VarDecl *VD) override;
+  bool visitVarDecl(const VarDecl *VD);
 
-protected:
   /// Emits scope cleanup instructions.
   void emitCleanup();
 
@@ -275,6 +275,12 @@
 
   /// Expression being initialized.
   llvm::Optional InitFn = {};
+
+  /// Returns whether we should create a global variable for the
+  /// given VarDecl.
+  bool isGlobalDecl(const VarDecl *VD) const {
+return !VD->hasLocalStorage() || VD->isConstexpr();
+  }
 };
 
 extern template class ByteCodeExprGen;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -799,6 +799,12 @@
   PrimType Ty,
   bool IsConst,
   bool IsExtended) {
+  // Make s

[PATCH] D136839: [clang][Interp] Handle non-primitive locals without initializer

2022-10-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

This got merged into https://reviews.llvm.org/D136815, so abandoning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136839

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


[PATCH] D136886: [clang] [ASTImporter] RFC: Correct importer to not duplicate sugared types

2022-10-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

In D136886#3892261 , @balazske wrote:

> `ASTImporterLookupTable` do not contain an entry for `__va_list_tag`, I do 
> not know why it is missing. If it is added "manually" the crash disappears 
> (without fix in `VisitTypedefType`). Following code was used to add 
> VaListTagDecl:
>
>   ASTImporterLookupTable::ASTImporterLookupTable(TranslationUnitDecl &TU) {
> Builder B(*this);
> B.TraverseDecl(&TU);
> // Add __va_list_tag to the table, it is not visited by the builder.
> if (NamedDecl *D = 
> dyn_cast_or_null(TU.getASTContext().getVaListTagDecl()))
>   add(&TU, D);
>   }
>
> The problem probably existed before but did not have visible effect until the 
> new assertion was added.

Nice find @balazske. Is this fix correct, and would you like to commandeer this 
crash for a correct fix? If so, we can wait for your patch and I'll just 
abandon this one. Thank you! - Vince


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

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


[PATCH] D136554: Implement CWG2631

2022-10-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 471748.
cor3ntin added a comment.

- Fix initialization of nested struct default

initializer.

- Fix handling of templates.
- Better track the initiulization context to

make source_location::current work as a consteval function.

I've tried to treat SourceLocExpr as an immediate invocation,
but it added more complexity than it was worth.

In the end, properly tracking the context of initialization is
During BuildCXXDefault*Expr is sufficient to make
SourceLocExpr behave properly in immediate contexts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp

Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,22 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
+
+
+consteval int undefined();  // expected-note 4{{declared here}}
+
+void check_lambdas_unused(
+int a = []
+{
+return undefined();  // expected-error {{not a constant expression}} \
+ // expected-note  {{undefined function 'undefined'}}
+}(),
+int b = [](int no_error = undefined()) {
+return no_error;
+}(0),
+int c = [](int defaulted = undefined()) {
+return defaulted;
+}()
+) {}
+
+int check_lambdas_used(
+int b = [](int no_error = undefined()) {
+return no_error;
+}(0),
+int c = [](int defaulted = undefined()) { // expected-error {{not a constant expression}} \
+  // expected-note  {{declared here}} \
+  // expected-note  {{undefined function 'undefined'}}
+return defaulted;
+}()  // expected-note {{in the default initalizer of 'defaulted'}}
+) {
+return 0;
+}
+
+int test_check_lambdas_used = check_lambdas_used();
+
+struct UnusedInitWithLambda {
+int a = [] {
+return undefined();  // expected-error {{not a constant expression}} \
+ // expected-note  {{undefined function 'undefined'}}
+}();
+int b = [](int no_error = undefined()) {
+return no_error;
+}();
+};
+
+struct InitWithLambda {
+int b = [](int error = undefined()) { // expected-error {{not a constant expression}} \
+  // expected-note  {{declared here}} \
+  // expected-note

[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-29 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:148
+/// Tests whether the given identifier is reserved as a module name and
+/// diagnoses if it is. Returs true if a diagnostic is emitted and false
+/// otherwise.

Returns


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

https://reviews.llvm.org/D136953

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


[PATCH] D137020: [clang][AST] Handle variable declaration with unknown typedef in C

2022-10-29 Thread Dilshod Urazov via Phabricator via cfe-commits
urazoff created this revision.
urazoff added reviewers: sammccall, hokein, adamcz.
Herald added a project: All.
urazoff requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  With this patch, declarations containing unknown types are parsed
  like declarations, not like expressions. This leads to better
  diagnostics and yields InvalidDecl in AST (thus DeclRefExpr's to
  them) which is good for compiler users and AST consumers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137020

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Driver/types.c
  clang/test/Parser/CompoundStmtScope.c
  clang/test/Parser/opencl-atomics-cl20.cl
  clang/test/Parser/recovery.c
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl

Index: clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
@@ -28,7 +28,7 @@
 void bar(void) {
  reserve_id_t r;
 #if defined(__OPENCL_C_VERSION__)
-// expected-error@-2 {{use of undeclared identifier 'reserve_id_t'}}
+// expected-error@-2 {{unknown type name 'reserve_id_t'}}
 #else
 // expected-error@-4 {{unknown type name 'reserve_id_t'}}
 #endif
Index: clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl
===
--- clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl
+++ clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl
@@ -5,8 +5,8 @@
   clk_event_t e;
   queue_t q;
 #ifndef __opencl_c_device_enqueue
-// expected-error@-3 {{use of undeclared identifier 'clk_event_t'}}
-// expected-error@-3 {{use of undeclared identifier 'queue_t'}}
+// expected-error@-3 {{unknown type name 'clk_event_t'}}
+// expected-error@-3 {{unknown type name 'queue_t'}}
 #else
 // expected-no-diagnostics
 #endif
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -46,19 +46,19 @@
 // expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
 // expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an expression of incompatible type 'int'}}
 #else
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_mce_payload_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_payload_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ref_payload_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_sic_payload_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_mce_result_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_result_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ref_result_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_sic_result_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_result_single_reference_streamout_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_result_dual_reference_streamout_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_dual_reference_streamin_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_single_reference_streamin_t'}}
-// expected-error@-28 {{use of undeclared identifier 'intel_sub_group_avc_ime_dual_reference_streamin_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_mce_payload_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ime_payload_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ref_payload_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_sic_payload_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_mce_result_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ime_result_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ref_result_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_sic_result_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ime_result_single_reference_streamout_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ime_result_dual_reference_streamout_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ime_dual_reference_streamin_t'}}
+// expected-error@-28 {{unknown type name 'intel_sub_group_avc_ime_single_referenc

[PATCH] D137020: [clang][AST] Handle variable declaration with unknown typedef in C

2022-10-29 Thread Dilshod Urazov via Phabricator via cfe-commits
urazoff added a comment.

https://github.com/llvm/llvm-project/issues/58355 corresponding github issue 
with current clang behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137020

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


[Diffusion] rGe4ec6ce8a75c: Clang: Add release note for defaulted-special-members-POD GCC ABI fix

2022-10-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In rGe4ec6ce8a75c208b49b163c81cda90dc7373c791#1139062 
, 
@dblaikie wrote:

> Posted, awaiting approval.

Thank you!


BRANCHES
  main

Users:
  dblaikie (Author)

https://reviews.llvm.org/rGe4ec6ce8a75c

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


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

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



Comment at: clang/include/clang/Driver/Options.td:4595-4596
 def mno_avxvnniint8 : Flag<["-"], "mno-avxvnniint8">, 
Group;
+def mavxneconvert : Flag<["-"], "mavxneconvert">, Group;
+def mno_avxneconvert : Flag<["-"], "mno-avxneconvert">, 
Group;
 def mavxvnni : Flag<["-"], "mavxvnni">, Group;

Need to move it before `mavxvnniint8 `.



Comment at: clang/lib/Basic/Targets/X86.cpp:1033
   .Case("avxvnniint8", HasAVXVNNIINT8)
+  .Case("avxneconvert", HasAVXNECONVERT)
   .Case("bmi", HasBMI)

Move it ahead.



Comment at: clang/lib/Headers/avx512vlbf16intrin.h:164
+#define _mm_cvtneps_pbh(A) \
+  ((__m128bh)__builtin_ia32_vcvtneps2bf16128((__v4sf)(A)))
 

pengfei wrote:
> RKSimon wrote:
> > Is there no way for __attribute__ to allow different attribute permutations?
> > 
> > Also, can we keep the __builtin_ia32_cvtneps2bf16_128 naming convention?
> > Is there no way for attribute to allow different attribute permutations?
> 
> We have discussed this problem with GCC folks. There are two problems here:
> 1. Unlike builtins, function attributes are more generic. It may introduce a 
> lot of checks between callers and callees. I had a research to limit it to 
> `__always_inline__` functions only. However, Clang handles inlining in 
> middle-end, we don't have such information in the front-end. Besides, we 
> don't know how to merge different permutations if they are inlining to the 
> same function.
> 2. We don't know how to put the permutations into IR's function attributes. 
> We need to preserve all permutations for inlining reference, but the backend 
> needs a determine feature list rather than selective.
It's better to use `__builtin_ia32_cvtneps2bf16_128`.



Comment at: clang/lib/Headers/avxneconvertintrin.h:106
+///
+/// This intrinsic corresponds to the \c VBCSTNEBF162PS instruction.
+///

VBCSTNESH2PS



Comment at: clang/lib/Headers/avxneconvertintrin.h:139
+///
+/// This intrinsic corresponds to the \c VBCSTNEBF162PS instruction.
+///

VBCSTNESH2PS



Comment at: clang/lib/Headers/avxneconvertintrin.h:207
+/// \param __A
+///A pointer to a 256-bit memory location containing 8 consecutive
+///BF16 (16-bit) floating-point values.

16



Comment at: clang/lib/Headers/avxneconvertintrin.h:273
+/// \param __A
+///A pointer to a 256-bit memory location containing 8 consecutive
+///half-precision (16-bit) floating-point values.

16



Comment at: clang/lib/Headers/avxneconvertintrin.h:339
+/// \param __A
+///A pointer to a 256-bit memory location containing 8 consecutive
+///BF16 (16-bit) floating-point values.

16



Comment at: clang/lib/Headers/avxneconvertintrin.h:405
+/// \param __A
+///A pointer to a 256-bit memory location containing 8 consecutive
+///half-precision (16-bit) floating-point values.

16



Comment at: clang/test/Preprocessor/x86_target_features.c:593-599
+// RUN: %clang -target i686-unknown-linux-gnu -march=atom -mavxneconvert -x c 
-E -dM -o - %s | FileCheck  -check-prefix=AVXNECONVERT %s
+// AVXNECONVERT: #define __AVXNECONVERT__ 1
+
+// RUN: %clang -target i686-unknown-linux-gnu -march=atom -mno-avxneconvert -x 
c -E -dM -o - %s | FileCheck  -check-prefix=NO-AVXNECONVERT %s
+// RUN: %clang -target i686-unknown-linux-gnu -march=atom -mavxneconvert 
-mno-avx2 -x c -E -dM -o - %s | FileCheck  -check-prefix=NO-AVXNECONVERT %s
+
+// NO-AVXNECONVERT-NOT: #define __AVXNECONVERT__ 1

Should we check `__AVX2__` like we did for AVXVNNI?



Comment at: llvm/lib/Support/Host.cpp:1818
 
+  Features["avxneconvert"] = HasLeaf7Subleaf1 && ((EDX >> 5) & 1) && 
HasAVXSave;
+

Move it ahead and remove the blank line.



Comment at: llvm/lib/Target/X86/X86ISelLowering.cpp:2186-2203
   if (!Subtarget.useSoftFloat() && Subtarget.hasBF16()) {
 addRegisterClass(MVT::v8bf16, &X86::VR128XRegClass);
 addRegisterClass(MVT::v16bf16, &X86::VR256XRegClass);
 addRegisterClass(MVT::v32bf16, &X86::VR512RegClass);
 // We set the type action of bf16 to TypeSoftPromoteHalf, but we don't
 // provide the method to promote BUILD_VECTOR. Set the operation action
 // Custom to do the customization later.

How about merge it here?



Comment at: llvm/lib/Target/X86/X86InstrSSE.td:8260-8261
+let Predicates = [HasAVXNECONVERT] in {
+  defm VBCSTNEBF162PS : AVX_NE_CONVERT_BASE<0xb1, "vbcstnebf162ps", i16mem,
+   i16mem>, T8XS;
+  defm VBCSTNESH2PS : AVX_NE_CONVERT_BASE<0xb1, "vbcstnesh2ps", f16mem, 
f16mem>,

This can be f16 mem now.



Comment at: llvm/lib/Target/X86/X86InstrSSE.td:8264-8265
+  

[PATCH] D136090: Handle errors in expansion of response files

2022-10-29 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[clang] 17eb198 - Handle errors in expansion of response files

2022-10-29 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2022-10-29T22:01:47+07:00
New Revision: 17eb198de934eced784e16ec15e020a574ba07e1

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

LOG: Handle errors in expansion of response files

Previously an error raised during an expansion of response files (including
configuration files) was ignored and only the fact of its presence was
reported to the user with generic error messages. This made it difficult to
analyze problems. For example, if a configuration file tried to read an
inexistent file, the error message said that 'configuration file cannot
be found', which is wrong and misleading.

This change enhances handling errors in the expansion so that users
could get more informative error messages.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/test/Driver/config-file-errs.c
clang/tools/driver/driver.cpp
clang/unittests/Driver/ToolChainTest.cpp
flang/tools/flang-driver/driver.cpp
llvm/include/llvm/Support/CommandLine.h
llvm/lib/Support/CommandLine.cpp
llvm/unittests/Support/CommandLineTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index b09e124206213..e477d93ba067f 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -214,14 +214,14 @@ def err_drv_malformed_sanitizer_coverage_ignorelist : 
Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
-def err_drv_config_file_not_exist : Error<
-  "configuration file '%0' does not exist">;
+def err_drv_cannot_open_config_file : Error<
+  "configuration file '%0' cannot be opened: %1">;
 def err_drv_config_file_not_found : Error<
   "configuration file '%0' cannot be found">;
 def note_drv_config_file_searched_in : Note<
   "was searched for in the directory: %0">;
 def err_drv_cannot_read_config_file : Error<
-  "cannot read configuration file '%0'">;
+  "cannot read configuration file '%0': %1">;
 def err_drv_nested_config_file: Error<
   "option '--config' is not allowed inside configuration file">;
 def err_drv_arg_requires_bitcode_input: Error<

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 26729f1d03ea8..80e6ec76d16f7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -940,10 +940,24 @@ static void appendOneArg(InputArgList &Args, const Arg 
*Opt,
 
 bool Driver::readConfigFile(StringRef FileName,
 llvm::cl::ExpansionContext &ExpCtx) {
+  // Try opening the given file.
+  auto Status = getVFS().status(FileName);
+  if (!Status) {
+Diag(diag::err_drv_cannot_open_config_file)
+<< FileName << Status.getError().message();
+return true;
+  }
+  if (Status->getType() != llvm::sys::fs::file_type::regular_file) {
+Diag(diag::err_drv_cannot_open_config_file)
+<< FileName << "not a regular file";
+return true;
+  }
+
   // Try reading the given file.
   SmallVector NewCfgArgs;
-  if (!ExpCtx.readConfigFile(FileName, NewCfgArgs)) {
-Diag(diag::err_drv_cannot_read_config_file) << FileName;
+  if (llvm::Error Err = ExpCtx.readConfigFile(FileName, NewCfgArgs)) {
+Diag(diag::err_drv_cannot_read_config_file)
+<< FileName << toString(std::move(Err));
 return true;
   }
 
@@ -1025,12 +1039,9 @@ bool Driver::loadConfigFiles() {
   if (llvm::sys::path::has_parent_path(CfgFileName)) {
 CfgFilePath.assign(CfgFileName);
 if (llvm::sys::path::is_relative(CfgFilePath)) {
-  if (getVFS().makeAbsolute(CfgFilePath))
-return true;
-  auto Status = getVFS().status(CfgFilePath);
-  if (!Status ||
-  Status->getType() != llvm::sys::fs::file_type::regular_file) {
-Diag(diag::err_drv_config_file_not_exist) << CfgFilePath;
+  if (getVFS().makeAbsolute(CfgFilePath)) {
+Diag(diag::err_drv_cannot_open_config_file)
+<< CfgFilePath << "cannot get absolute path";
 return true;
   }
 }

diff  --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp 
b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
index c4b3abc1a0a45..88d20ba3957d2 100644
--- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -61,9 +61,11 @@ class ExpandResponseFilesDatabase : public 
CompilationDatabase {
 continue;
  

[PATCH] D136090: Handle errors in expansion of response files

2022-10-29 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG17eb198de934: Handle errors in expansion of response files 
(authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D136090?vs=469978&id=471753#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/test/Driver/config-file-errs.c
  clang/tools/driver/driver.cpp
  clang/unittests/Driver/ToolChainTest.cpp
  flang/tools/flang-driver/driver.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -871,7 +871,7 @@
   llvm::BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot).setRelativeNames(true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   EXPECT_THAT(Argv, testing::Pointwise(
 StringEquality(),
 {"test/test", "-flag_1", "-option_1", "-option_2",
@@ -933,7 +933,14 @@
 #endif
   llvm::cl::ExpansionContext ECtx(A, Tokenizer);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot);
-  ASSERT_FALSE(ECtx.expandResponseFiles(Argv));
+  llvm::Error Err = ECtx.expandResponseFiles(Argv);
+  ASSERT_TRUE((bool)Err);
+  SmallString<128> FilePath = SelfFilePath;
+  std::error_code EC = FS.makeAbsolute(FilePath);
+  ASSERT_FALSE((bool)EC);
+  std::string ExpectedMessage =
+  std::string("recursive expansion of: '") + std::string(FilePath) + "'";
+  ASSERT_TRUE(toString(std::move(Err)) == ExpectedMessage);
 
   EXPECT_THAT(Argv,
   testing::Pointwise(StringEquality(),
@@ -971,7 +978,7 @@
   BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot);
-  ASSERT_FALSE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
 
   // ASSERT instead of EXPECT to prevent potential out-of-bounds access.
   ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2);
@@ -1005,7 +1012,7 @@
   BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot).setRelativeNames(true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   EXPECT_THAT(Argv,
   testing::Pointwise(StringEquality(), {"test/test", "-flag"}));
 }
@@ -1025,7 +1032,7 @@
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeWindowsCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot).setMarkEOLs(true).setRelativeNames(
   true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   const char *Expected[] = {"clang", "-Xclang", "-Wno-whatever", nullptr,
 "input.cpp"};
   ASSERT_EQ(std::size(Expected), Argv.size());
@@ -1038,6 +1045,30 @@
   }
 }
 
+TEST(CommandLineTest, BadResponseFile) {
+  BumpPtrAllocator A;
+  StringSaver Saver(A);
+  TempDir ADir("dir", /*Unique*/ true);
+  SmallString<128> AFilePath = ADir.path();
+  llvm::sys::path::append(AFilePath, "file.rsp");
+  std::string AFileExp = std::string("@") + std::string(AFilePath.str());
+  SmallVector Argv = {"clang", AFileExp.c_str()};
+
+  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  ASSERT_TRUE(Res);
+  ASSERT_EQ(2U, Argv.size());
+  ASSERT_STREQ(Argv[0], "clang");
+  ASSERT_STREQ(Argv[1], AFileExp.c_str());
+
+  std::string ADirExp = std::string("@") + std::string(ADir.path());
+  Argv = {"clang", ADirExp.c_str()};
+  Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  ASSERT_FALSE(Res);
+  ASSERT_EQ(2U, Argv.size());
+  ASSERT_STREQ(Argv[0], "clang");
+  ASSERT_STREQ(Argv[1], ADirExp.c_str());
+}
+
 TEST(CommandLineTest, SetDefaultValue) {
   cl::ResetCommandLineParser();
 
@@ -1145,9 +1176,9 @@
 
   llvm::BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::tokenizeConfigFile);
-  bool Result = ECtx.readConfigFile(ConfigFile.path(), Argv);
+  llvm::Error Result = ECtx.readConfigFile(ConfigFile.path(), Argv);
 
-  EXPECT_TRUE(Result);
+  EXPECT_FALSE((bool)Result);
   EXPECT_EQ(Argv.size(), 13U);
   EXPECT_STREQ(Argv[0], "-option_1");
   EXPECT_STREQ(Argv[1],
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -1153,14 +1153,14 @@
 }
 
 // FName must be an absolute path.
-llv

[PATCH] D137024: [compiler-rt] Switch from llvm-config to find_package(LLVM)

2022-10-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: dberris, justinkb, tstellar, MaskRay, 
serge-sans-paille, Hahnfeld, mstorsjo, delcypher, phosek.
Herald added subscribers: Enna1, StephenFan.
Herald added a project: All.
mgorny requested review of this revision.

Replace the use of the deprecated `llvm-config` tool with LLVM's CMake
files for detecting LLVM in standalone builds.


https://reviews.llvm.org/D137024

Files:
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/lib/xray/tests/CMakeLists.txt

Index: compiler-rt/lib/xray/tests/CMakeLists.txt
===
--- compiler-rt/lib/xray/tests/CMakeLists.txt
+++ compiler-rt/lib/xray/tests/CMakeLists.txt
@@ -59,19 +59,26 @@
 LLVM_ENABLE_TERMINFO
 -l${COMPILER_RT_TERMINFO_LIB} XRAY_UNITTEST_LINK_FLAGS)
 
+  # We add the library directories one at a time in our CFLAGS.
+  foreach (DIR ${LLVM_LIBRARY_DIR})
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -L${DIR})
+  endforeach()
+
   if (COMPILER_RT_STANDALONE_BUILD)
-append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LDFLAGS} XRAY_UNITTEST_LINK_FLAGS)
-append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LIBLIST} XRAY_UNITTEST_LINK_FLAGS)
-append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
-  ${LLVM_TESTINGSUPPORT_LDFLAGS} XRAY_UNITTEST_LINK_FLAGS)
-append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
-  ${LLVM_TESTINGSUPPORT_LIBLIST} XRAY_UNITTEST_LINK_FLAGS)
+if (COMPILER_RT_HAS_LLVMXRAY OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  if (LLVM_LINK_LLVM_DYLIB)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVM)
+  endif()
+else()
+  if (COMPILER_RT_HAS_LLVMXRAY)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)
+  endif()
+  if (COMPILER_RT_HAS_TESTINGSUPPORT)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMTestingSupport)
+  endif()
+  list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMSupport -lLLVMDemangle)
+endif()
   else()
-# We add the library directories one at a time in our CFLAGS.
-foreach (DIR ${LLVM_LIBRARY_DIR})
-  list(APPEND XRAY_UNITTEST_LINK_FLAGS -L${DIR})
-endforeach()
-
 # We also add the actual libraries to link as dependencies.
 list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay -lLLVMSupport -lLLVMDemangle -lLLVMTestingSupport)
   endif()
Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -268,16 +268,6 @@
 endfunction()
 
 macro(load_llvm_config)
-  if (NOT LLVM_CONFIG_PATH)
-find_program(LLVM_CONFIG_PATH "llvm-config"
- DOC "Path to llvm-config binary")
-if (NOT LLVM_CONFIG_PATH)
-  message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
-  "llvm-config not found.\n"
-  "Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config.")
-endif()
-  endif()
-
   # Compute path to LLVM sources assuming the monorepo layout.
   # We don't set `LLVM_MAIN_SRC_DIR` directly to avoid overriding a user provided
   # CMake cache value.
@@ -290,114 +280,33 @@
   "You are not using the monorepo layout. This configuration is DEPRECATED.")
   endif()
 
-  set(FOUND_LLVM_CMAKE_DIR FALSE)
-  if (LLVM_CONFIG_PATH)
-execute_process(
-  COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" "--includedir"
-  RESULT_VARIABLE HAD_ERROR
-  OUTPUT_VARIABLE CONFIG_OUTPUT)
-if (HAD_ERROR)
-  message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
-endif()
-string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
-list(GET CONFIG_OUTPUT 0 BINARY_DIR)
-list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
-list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
-list(GET CONFIG_OUTPUT 3 MAIN_SRC_DIR)
-list(GET CONFIG_OUTPUT 4 INCLUDE_DIR)
-
-set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree")
-set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
-set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
-set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers")
-
-if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_DEFAULT}")
-  # TODO(dliew): Remove this legacy fallback path.
-  message(WARNING
-"Consulting llvm-config for the LLVM source path "
-"as a fallback. This behavior will be removed in the future.")
-  # We don't set `LLVM_MAIN_SRC_DIR` directly to avoid overriding a user
-  # provided CMake cache value.
-  set(LLVM_MAIN_SRC_DIR_DEFAULT "${MAIN_SRC_DIR}")
-  message(STATUS "Using LLVM source path (${LLVM_MAIN_SRC_DIR_DEFAULT}) from llvm-config")
-endif()
-
-# Detect if we have the LLVMXRay and TestingSupport library installed and
-# available from llvm-config.
-execute_process(
-  COMMAND ${

[PATCH] D137024: [compiler-rt] Switch from llvm-config to find_package(LLVM)

2022-10-29 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: compiler-rt/lib/xray/tests/CMakeLists.txt:68-80
+if (COMPILER_RT_HAS_LLVMXRAY OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  if (LLVM_LINK_LLVM_DYLIB)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVM)
+  endif()
+else()
+  if (COMPILER_RT_HAS_LLVMXRAY)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)

Rather than manually linking against libraries and their dependencies (which 
may change over time and break this code), we should use import targets 
provided by the LLVM CMake config: `LLVMXRay` and `LLVMTestingSupport`. That 
can be done in a follow up change though.


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

https://reviews.llvm.org/D137024

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


[PATCH] D137024: [compiler-rt] Switch from llvm-config to find_package(LLVM)

2022-10-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: compiler-rt/lib/xray/tests/CMakeLists.txt:68-80
+if (COMPILER_RT_HAS_LLVMXRAY OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  if (LLVM_LINK_LLVM_DYLIB)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVM)
+  endif()
+else()
+  if (COMPILER_RT_HAS_LLVMXRAY)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)

phosek wrote:
> Rather than manually linking against libraries and their dependencies (which 
> may change over time and break this code), we should use import targets 
> provided by the LLVM CMake config: `LLVMXRay` and `LLVMTestingSupport`. That 
> can be done in a follow up change though.
I actually wanted to do that but couldn't figure out how. Perhaps my approach 
was wrong, as I was trying to get linked libraries out of target properties.


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

https://reviews.llvm.org/D137024

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


[clang] c1728a4 - Revert "Handle errors in expansion of response files"

2022-10-29 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2022-10-30T02:03:12+07:00
New Revision: c1728a40aae31abc0a5d4d07f6f6a6773d803f2c

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

LOG: Revert "Handle errors in expansion of response files"

This reverts commit 17eb198de934eced784e16ec15e020a574ba07e1.
Reverted for investigation, because ClangDriverTests failed on some builders.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/test/Driver/config-file-errs.c
clang/tools/driver/driver.cpp
clang/unittests/Driver/ToolChainTest.cpp
flang/tools/flang-driver/driver.cpp
llvm/include/llvm/Support/CommandLine.h
llvm/lib/Support/CommandLine.cpp
llvm/unittests/Support/CommandLineTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e477d93ba067f..b09e124206213 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -214,14 +214,14 @@ def err_drv_malformed_sanitizer_coverage_ignorelist : 
Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
-def err_drv_cannot_open_config_file : Error<
-  "configuration file '%0' cannot be opened: %1">;
+def err_drv_config_file_not_exist : Error<
+  "configuration file '%0' does not exist">;
 def err_drv_config_file_not_found : Error<
   "configuration file '%0' cannot be found">;
 def note_drv_config_file_searched_in : Note<
   "was searched for in the directory: %0">;
 def err_drv_cannot_read_config_file : Error<
-  "cannot read configuration file '%0': %1">;
+  "cannot read configuration file '%0'">;
 def err_drv_nested_config_file: Error<
   "option '--config' is not allowed inside configuration file">;
 def err_drv_arg_requires_bitcode_input: Error<

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 80e6ec76d16f7..26729f1d03ea8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -940,24 +940,10 @@ static void appendOneArg(InputArgList &Args, const Arg 
*Opt,
 
 bool Driver::readConfigFile(StringRef FileName,
 llvm::cl::ExpansionContext &ExpCtx) {
-  // Try opening the given file.
-  auto Status = getVFS().status(FileName);
-  if (!Status) {
-Diag(diag::err_drv_cannot_open_config_file)
-<< FileName << Status.getError().message();
-return true;
-  }
-  if (Status->getType() != llvm::sys::fs::file_type::regular_file) {
-Diag(diag::err_drv_cannot_open_config_file)
-<< FileName << "not a regular file";
-return true;
-  }
-
   // Try reading the given file.
   SmallVector NewCfgArgs;
-  if (llvm::Error Err = ExpCtx.readConfigFile(FileName, NewCfgArgs)) {
-Diag(diag::err_drv_cannot_read_config_file)
-<< FileName << toString(std::move(Err));
+  if (!ExpCtx.readConfigFile(FileName, NewCfgArgs)) {
+Diag(diag::err_drv_cannot_read_config_file) << FileName;
 return true;
   }
 
@@ -1039,9 +1025,12 @@ bool Driver::loadConfigFiles() {
   if (llvm::sys::path::has_parent_path(CfgFileName)) {
 CfgFilePath.assign(CfgFileName);
 if (llvm::sys::path::is_relative(CfgFilePath)) {
-  if (getVFS().makeAbsolute(CfgFilePath)) {
-Diag(diag::err_drv_cannot_open_config_file)
-<< CfgFilePath << "cannot get absolute path";
+  if (getVFS().makeAbsolute(CfgFilePath))
+return true;
+  auto Status = getVFS().status(CfgFilePath);
+  if (!Status ||
+  Status->getType() != llvm::sys::fs::file_type::regular_file) {
+Diag(diag::err_drv_config_file_not_exist) << CfgFilePath;
 return true;
   }
 }

diff  --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp 
b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
index 88d20ba3957d2..c4b3abc1a0a45 100644
--- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -61,11 +61,9 @@ class ExpandResponseFilesDatabase : public 
CompilationDatabase {
 continue;
   llvm::BumpPtrAllocator Alloc;
   llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
-  llvm::Error Err = ECtx.setVFS(FS.get())
-.setCurrentDir(Cmd.Directory)
-.expandResponseFiles(Argv);
-  if (Err)
-llvm::errs() << Err;
+  ECtx.setVFS(FS.get())
+  .setCurrentDir(Cmd.Directory)
+  .expandResponseFiles(Argv);
   // Don't assign

[PATCH] D136886: [clang] [ASTImporter] RFC: Correct importer to not duplicate sugared types

2022-10-29 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a subscriber: gamesh411.
vabridgers added a comment.

Adding more information, seems this patch's "hack" returns the following

QualType(T, 0).getDesugaredType(T->getDecl()->getASTContext()); ->

  ConstantArrayType 0x11413090 'struct __va_list_tag[1]' imported 1 
  `-RecordType 0x11412ed0 'struct __va_list_tag' imported
`-Record 0x11412e38 '__va_list_tag'

The recent change from @mizvekov returns 
T->desugar(); ->

  ElaboratedType 0x11442870 '__builtin_va_list' sugar imported
  `-TypedefType 0x11442840 '__builtin_va_list' sugar imported
|-Typedef 0x114130e8 '__builtin_va_list'
`-ConstantArrayType 0x11413090 'struct __va_list_tag[1]' imported 1 
  `-RecordType 0x11412ed0 'struct __va_list_tag' imported
`-Record 0x11412e38 '__va_list_tag'

And the code prior to @mizvekov code returns the following...
T->getDecl()->getASTContext().getTypeDeclType(*ToDeclOrErr); ->

  TypedefType 0x11442bf0 'va_list' sugar
  |-Typedef 0x113d4ad0 'va_list'
  `-ElaboratedType 0x1136dbc0 '__builtin_va_list' sugar
`-TypedefType 0x1136db90 '__builtin_va_list' sugar
  |-Typedef 0x1136db38 '__builtin_va_list'
  `-ConstantArrayType 0x1136dae0 'struct __va_list_tag[1]' 1 
`-RecordType 0x1136d920 'struct __va_list_tag'
  `-Record 0x1136d898 '__va_list_tag'

Should import desugar types to a canonical underlying type free of syntactic 
sugar? That's not clear to me at least. @gamesh411 pointed out in our debug 
session that there are sections of code that iteratively strip sugar until 
there's no more sugar left wrapping the type. But there's at least one instance 
where only a single level of sugar is removed.

OTOH, I did find a section of code where va_list is not desugared - looks like 
for diagnostic purposes - maybe this is a reason to use a solution following 
@balazske's finding.

Any suggestions on how to proceed with this?

Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

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


[PATCH] D136886: [clang] [ASTImporter] RFC: Correct importer to not duplicate sugared types

2022-10-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

It's not clear to me there is anything wrong besides our not importing of 
`va_list_tag`.
The imported TypedefType should have the same underlying type as the original 
one, and I did not find anything different is happening on that test case.

I will post a patch fixing the import situation soon, let me know if there is 
still anything amiss.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

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


[PATCH] D133756: [clangd] Pass the entire tooling::CompileCommand to CommandMangler

2022-10-29 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

(I frequently forget that `arc diff` does not update the commit message of an 
existing revision...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133756

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


[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-10-29 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

For reference, earlier work along these lines which never landed: 
https://reviews.llvm.org/D119077


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136594

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


[PATCH] D136786: Fix `unsafe-fp-math` attribute emission.

2022-10-29 Thread Michele Scandale via Phabricator via cfe-commits
michele.scandale updated this revision to Diff 471801.
michele.scandale added a comment.

Use low level properties to set `"unsafe-fp-math"="true"`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136786

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/fp-function-attrs.cpp
  clang/test/CodeGen/func-attr.c
  clang/test/CodeGenOpenCL/relaxed-fpmath.cl

Index: clang/test/CodeGenOpenCL/relaxed-fpmath.cl
===
--- clang/test/CodeGenOpenCL/relaxed-fpmath.cl
+++ clang/test/CodeGenOpenCL/relaxed-fpmath.cl
@@ -51,7 +51,7 @@
 // UNSAFE-NOT: "no-infs-fp-math"
 // UNSAFE-NOT: "no-nans-fp-math"
 // UNSAFE: "no-signed-zeros-fp-math"="true"
-// UNSAFE: "unsafe-fp-math"="true"
+// UNSAFE-NOT: "unsafe-fp-math"="true"
 
 // MAD: "less-precise-fpmad"="true"
 // MAD-NOT: "no-infs-fp-math"
Index: clang/test/CodeGen/func-attr.c
===
--- clang/test/CodeGen/func-attr.c
+++ clang/test/CodeGen/func-attr.c
@@ -1,12 +1,28 @@
-// RUN: %clang -c -target x86_64 -ffast-math \
-// RUN: -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math \
+// RUN: -ffp-contract=fast -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-UNSAFE
 
-// RUN: %clang -c -target x86_64 -funsafe-math-optimizations \
-// RUN: -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -funsafe-math-optimizations \
+// RUN: -ffp-contract=fast -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-UNSAFE
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -funsafe-math-optimizations \
+// RUN: -ffp-contract=on -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-NOUNSAFE
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -funsafe-math-optimizations \
+// RUN: -ffp-contract=off -emit-llvm -o - %s | \
+// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-NOUNSAFE
 
 float foo(float a, float b) {
   return a+b;
 }
 
-// CHECK: define{{.*}} float @foo(float noundef %{{.*}}, float noundef %{{.*}}){{.*}} [[FAST_ATTRS:#[0-9]+]]
-// CHECK: attributes [[FAST_ATTRS]] = { {{.*}} "approx-func-fp-math"="true" {{.*}} "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" {{.*}} "unsafe-fp-math"="true"
+// CHECK:  define{{.*}} float @foo(float noundef %{{.*}}, float noundef %{{.*}}){{.*}} [[ATTRS:#[0-9]+]]
+// CHECK:  attributes [[ATTRS]] = {
+// CHECK-SAME:   "approx-func-fp-math"="true"
+// CHECK-SAME:   "no-signed-zeros-fp-math"="true"
+// CHECK-SAME:   "no-trapping-math"="true"
+// CHECK-UNSAFE-SAME:"unsafe-fp-math"="true"
+// CHECK-NOUNSAFE-NOT:   "unsafe-fp-math"="true"
+// CHECK-SAME: }
Index: clang/test/CodeGen/fp-function-attrs.cpp
===
--- clang/test/CodeGen/fp-function-attrs.cpp
+++ clang/test/CodeGen/fp-function-attrs.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffp-contract=fast -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffp-contract=fast-honor-pragmas -emit-llvm -o - %s | FileCheck %s
 
 float test_default(float a, float b, float c) {
   float tmp = a;
@@ -35,10 +36,23 @@
   return tmp;
 }
 
-// CHECK: define{{.*}} float @_Z27test_reassociate_off_pragmafff(float noundef %a, float noundef %b, float noundef %c) [[NOREASSOC_ATTRS:#[0-9]+]]
+// CHECK: define{{.*}} float @_Z27test_reassociate_off_pragmafff(float noundef %a, float noundef %b, float noundef %c) [[NO_UNSAFE_ATTRS:#[0-9]+]]
 // CHECK: fadd nnan ninf nsz arcp contract afn float {{%.+}}, {{%.+}}
 // CHECK: fadd fast float {{%.+}}, {{%.+}}
 
+float test_contract_on_pragma(float a, float b, float c) {
+  float tmp = a * b;
+  {
+#pragma clang fp contract(on)
+tmp += c;
+  }
+  return tmp;
+}
+
+// CHECK: define{{.*}} float @_Z23test_contract_on_pragmafff(float noundef %a, float noundef %b, float noundef %c) [[NO_UNSAFE_ATTRS:#[0-9]+]]
+// CHECK: fmul fast float {{%.+}}, {{%.+}}
+// CHECK: fadd reassoc nnan ninf nsz arcp afn float {{%.+}}, {{%.+}}
+
 // CHECK: attributes [[FAST_ATTRS]] = { {{.*}}"no-infs-fp-math"="true" {{.*}}"no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" {{.*}}"unsafe-fp-math"="true"{{.*}} }
 // CHECK: attributes [[PRECISE_ATTRS]] = { {{.*}}"no-infs-fp-math"="false" {{.*}}"no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" {{.*}}"unsafe-fp-math"="false"{{.*}} }
-// CHECK: attributes [[NOREASSOC_ATTRS]] = { {{.*}}"no-infs-fp-math"="true" {{.*}}"no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" {{.*}}"unsafe-fp-math"="false"{{.*}} }
+// CHECK: attributes [[NO_UNSAFE_ATTRS]] = { {{.*}}"no-infs-fp-math"="true" {{.*}}"no-nans-fp-math"="true" "no-signed-zeros-fp

[PATCH] D137024: [compiler-rt] Switch from llvm-config to find_package(LLVM)

2022-10-29 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: compiler-rt/lib/xray/tests/CMakeLists.txt:68-80
+if (COMPILER_RT_HAS_LLVMXRAY OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  if (LLVM_LINK_LLVM_DYLIB)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVM)
+  endif()
+else()
+  if (COMPILER_RT_HAS_LLVMXRAY)
+list(APPEND XRAY_UNITTEST_LINK_FLAGS -lLLVMXRay)

mgorny wrote:
> phosek wrote:
> > Rather than manually linking against libraries and their dependencies 
> > (which may change over time and break this code), we should use import 
> > targets provided by the LLVM CMake config: `LLVMXRay` and 
> > `LLVMTestingSupport`. That can be done in a follow up change though.
> I actually wanted to do that but couldn't figure out how. Perhaps my approach 
> was wrong, as I was trying to get linked libraries out of target properties.
I can take a look once this change lands, it might require changes to 
compiler-rt helpers.


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

https://reviews.llvm.org/D137024

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


[PATCH] D136786: Fix `unsafe-fp-math` attribute emission.

2022-10-29 Thread Michele Scandale via Phabricator via cfe-commits
michele.scandale added a comment.

In D136786#3893485 , @andrew.w.kaylor 
wrote:

> My understanding is this:
>
>   unsafe-fp-math = exception_behavior(ignore) +
>fenv_access(off) +
>no_signed_zeros(on) +
>allow_reciprocal(on) +
>allow_approximate_fns(on) +
>allow_reassociation(on) +
>fp_contract(fast)
>
> The first two of those settings are the default behavior. The others can be 
> turned on by individual command line options. If all of those semantic modes 
> are in the states above, then we are in "unsafe-fp-math" mode. That's my 
> proposal.

I've updated the patch to use the low level options as you suggested. In the 
current version of the patch I'm not currently checking explicitly 
`exception_behavior(ignore) &&  fenv_access(off)` given that the other modes of 
these properties seems to work only if overall there is the "precise" profile. 
I don't know if that's acceptable, or if instead the CC1 shouldn't make any 
assumption about the compiler driver doing the right thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136786

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


[clang] d5be155 - [clang-format] Don't crash on malformed preprocessor conditions

2022-10-29 Thread via cfe-commits

Author: sstwcw
Date: 2022-10-30T02:18:58Z
New Revision: d5be1550f1406844501ab87a3e92622927a203e0

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

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

Previously the program would crash on this input:

```
#else
#if X
```

The problem was that in `parsePPElse`, `PPBranchLevel` would be
incremented when the first `#else` gets parsed, but `PPLevelBranchCount`
and `PPLevelBranchIndex` would not be updated together.

I found the problem when working on D135740.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 25d9018fa1093..0372b89397db9 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,9 +1215,12 @@ void UnwrappedLineParser::parsePPElse() {
   // 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;
 }

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 69bd39590589f..e2eced46c3b4b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5193,6 +5193,34 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
   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("#if X\n"
+"#elif Y\n"
+"#elif Y\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#else");
+  verifyNoCrash("#endif\n"
+"#elif Y");
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {



___
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-29 Thread sstwcw 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 rGd5be1550f140: [clang-format] Don't crash on malformed 
preprocessor conditions (authored by sstwcw).

Changed prior to commit:
  https://reviews.llvm.org/D135972?vs=470623&id=471804#toc

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,34 @@
   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("#if X\n"
+"#elif Y\n"
+"#elif Y\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#else");
+  verifyNoCrash("#endif\n"
+"#elif Y");
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,9 +1215,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,34 @@
   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("#if X\n"
+"#elif Y\n"
+"#elif Y\n"
+"#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#endif");
+  verifyNoCrash("#endif\n"
+"#else");
+  verifyNoCrash("#endif\n"
+"#elif Y");
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,9 +1215,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] D136962: [clang] Improve error recovery for pack expansion of expressions

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136962

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp


Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fblocks 
-fms-extensions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fblocks 
-fms-extensions -fsyntax-only -verify=expected,cxx11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++2b -fblocks 
-fms-extensions -fsyntax-only -verify=expected %s
 
 template struct pair;
 template struct tuple;
@@ -164,7 +165,9 @@
 // FIXME: this should test that the diagnostic reads "type contains..."
 struct alignas(Types) TestUnexpandedDecls : T{ // expected-error{{expression 
contains unexpanded parameter pack 'Types'}}
   void member_function(Types);  // expected-error{{declaration type contains 
unexpanded parameter pack 'Types'}}
+#if __cplusplus < 201703L
   void member_function () throw(Types); // expected-error{{exception type 
contains unexpanded parameter pack 'Types'}}
+#endif
   void member_function2() noexcept(Types()); // expected-error{{expression 
contains unexpanded parameter pack 'Types'}}
   operator Types() const; // expected-error{{declaration type contains 
unexpanded parameter pack 'Types'}}
   Types data_member;  // expected-error{{data member type contains unexpanded 
parameter pack 'Types'}}
@@ -427,7 +430,7 @@
 namespace PR21289 {
   template using T = int;
   template struct S { static const int value = 0; };
-  template const int vt = 0; // expected-warning {{extension}}
+  template const int vt = 0; // cxx11-warning {{extension}}
   int f(...);
   template void g() {
 f(T()...);
@@ -491,3 +494,11 @@
 using t2 = E::B;
 // expected-note@-1 {{in instantiation of template class 'pr56094::E' 
requested here}}
 } // namespace pr56094
+
+namespace GH56094 {
+#if __cplusplus >= 201402L
+template  struct A; // expected-note {{template is declared here}}
+template  using B = char;
+template  int C{ A>{}... }; // expected-error {{implicit 
instantiation of undefined template}}
+#endif
+} // namespace GH56094
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -573,7 +573,7 @@
   //   - type-dependent if we don't know the type (fallback to an opaque
   // dependent type), or the type is known and dependent, or it has
   // type-dependent subexpressions.
-  auto D = toExprDependenceForImpliedType(E->getType()->getDependence()) |
+  auto D = toExprDependenceAsWritten(E->getType()->getDependence()) |
ExprDependence::ErrorDependent;
   // FIXME: remove the type-dependent bit from subexpressions, if the
   // RecoveryExpr has a non-dependent type.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -344,6 +344,8 @@
   potentially problematic function type casts.
 - Clang will now disambiguate NTTP types when printing diagnostic that contain 
NTTP types.
   Fixes `Issue 57562 `_.
+- Better error recovery for pack expansion of expressions.
+  `Issue 58673 `_.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fblocks -fms-extensions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fblocks -fms-extensions -fsyntax-only -verify=expected,cxx11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++2b -fblocks -fms-extensions -fsyntax-only -verify=expected %s
 
 template struct pair;
 template struct tuple;
@@ -164,7 +165,9 @@
 // FIXME: this should test that the diagnostic reads "type contains..."
 struct alignas(Types) TestUnexpandedDecls : T{ // expected-error{{expression contains unexpanded parameter pack 'Types'}}
   void member_function(Types);  // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
+#if __cplusplus < 201703L
   void member_function () throw(Types); // expected-error{{exception type contains unexpanded par

[PATCH] D136977: [clang] Fix handling of unexpanded packs in template argument expressions.

2022-10-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 471807.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136977

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp

Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -502,3 +502,22 @@
 template  int C{ A>{}... }; // expected-error {{implicit instantiation of undefined template}}
 #endif
 } // namespace GH56094
+
+namespace GH58679 {
+#if __cplusplus >= 201402L
+template  constexpr int A = 1;
+
+template  struct B;
+template <> struct B<1> { using b1 = void; };
+
+template  using C = char;
+
+template  int D{ B>>{}... };
+
+struct E {
+  template >::b1> E(E1);
+};
+
+template  int F{ E(C{})... };
+#endif
+} // namespace GH58679
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -7156,11 +7156,8 @@
   }
 
   // If either the parameter has a dependent type or the argument is
-  // type-dependent, there's nothing we can check now. The argument only
-  // contains an unexpanded pack during partial ordering, and there's
-  // nothing more we can check in that case.
-  if (ParamType->isDependentType() || Arg->isTypeDependent() ||
-  Arg->containsUnexpandedParameterPack()) {
+  // type-dependent, there's nothing we can check now.
+  if (ParamType->isDependentType() || Arg->isTypeDependent()) {
 // Force the argument to the type of the parameter to maintain invariants.
 auto *PE = dyn_cast(Arg);
 if (PE)
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5862,9 +5862,9 @@
 
   // C++2a [intro.execution]p5:
   //   A full-expression is [...] a constant-expression [...]
-  Result =
-  S.ActOnFinishFullExpr(Result.get(), From->getExprLoc(),
-/*DiscardedValue=*/false, /*IsConstexpr=*/true);
+  Result = S.ActOnFinishFullExpr(Result.get(), From->getExprLoc(),
+ /*DiscardedValue=*/false, /*IsConstexpr=*/true,
+ CCE == Sema::CCEKind::CCEK_TemplateArg);
   if (Result.isInvalid())
 return Result;
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8713,14 +8713,14 @@
 }
 
 ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
- bool DiscardedValue,
- bool IsConstexpr) {
+ bool DiscardedValue, bool IsConstexpr,
+ bool IsTemplateArgument) {
   ExprResult FullExpr = FE;
 
   if (!FullExpr.get())
 return ExprError();
 
-  if (DiagnoseUnexpandedParameterPack(FullExpr.get()))
+  if (!IsTemplateArgument && DiagnoseUnexpandedParameterPack(FullExpr.get()))
 return ExprError();
 
   if (DiscardedValue) {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -6817,7 +6817,8 @@
 Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue);
   }
   ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
- bool DiscardedValue, bool IsConstexpr = false);
+ bool DiscardedValue, bool IsConstexpr = false,
+ bool IsTemplateArgument = false);
   StmtResult ActOnFinishFullStmt(Stmt *Stmt);
 
   // Marks SS invalid if it represents an incomplete type.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -264,6 +264,8 @@
   constraint, which re-evaluated the same constraint.
   `Issue 53213 `_
   `Issue 45736 `_
+- Fix handling of unexpanded packs in template argument expressions.
+  `Issue 58679 `_
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136886: [clang] ASTImporter: Fix importing of va_list types and declarations

2022-10-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "[clang] [ASTImporter] RFC: Correct 
importer to not duplicate sugared types" to "[clang] ASTImporter: Fix importing 
of va_list types and declarations".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 471808.
Herald added a reviewer: jdoerfert.
Herald added subscribers: carlosgalvezp, sstefan1.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

Files:
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
  clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/ASTMerge.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/AST/ast-dump-file-line-json.c
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-traits.cpp
  clang/test/AST/fixed_point.c
  clang/test/AST/float16.cpp
  clang/test/PCH/stmt-openmp_structured_block-bit.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7499,7 +7499,14 @@
   }
   )",
   Lang_CXX14);
-  auto *FromFD = FirstDeclMatcher().match(FromTU, fieldDecl());
+
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  CXXRecordDecl *FromLambda =
+  cast((cast(FromF->getBody())->body_back()))
+  ->getLambdaClass();
+
+  auto *FromFD = *FromLambda->field_begin();
   ASSERT_TRUE(FromFD);
   ASSERT_TRUE(FromFD->hasCapturedVLAType());
 
@@ -8075,6 +8082,24 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaList) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/test/PCH/stmt-openmp_structured_block-bit.cpp
===
--- clang/test/PCH/stmt-openmp_structured_block-bit.cpp
+++ clang/test/PCH/stmt-openmp_structured_block-bit.cpp
@@ -13,7 +13,7 @@
 // expected-no-diagnostics
 
 // CHECK: TranslationUnitDecl 0x{{.*}} <> 
-// CHECK: `-FunctionDecl 0x{{.*}} <{{.*}}stmt-openmp_structured_block-bit.cpp:8:1, line:11:1> line:8:6 {{(test|imported test)}} 'void ()'
+// CHECK:  -FunctionDecl 0x{{.*}} <{{.*}}stmt-openmp_structured_block-bit.cpp:8:1, line:11:1> line:8:6 {{(test|imported test)}} 'void ()'
 // CHECK-NEXT:   `-CompoundStmt 0x{{.*}} 
 // CHECK-NEXT: `-OMPParallelDirective 0x{{.*}} 
 // CHECK-NEXT:   `-CapturedStmt 0x{{.*}} 
Index: clang/test/AST/float16.cpp
===
--- clang/test/AST/float16.cpp
+++ clang/test/AST/float16.cpp
@@ -29,7 +29,7 @@
   }
 }
 
-//CHECK:  |-NamespaceDecl
+//CHECK:  |-NamespaceDecl {{.*}} <{{.*}}:22:1,
 //CHECK-NEXT: | |-VarDecl {{.*}} f1n '_Float16'
 //CHECK-NEXT: | |-VarDecl {{.*}} f2n '_Float16' cinit
 //CHECK-NEXT: | | `-FloatingLiteral {{.*}} '_Float16' 3.30e+01
Index: clang/test/AST/fixed_point.c
===
--- clang/test/AST/fixed_point.c
+++ clang/test/AST/fixed_point.c
@@ -402,5 +402,5 @@
 
 _Accum literallast = 1.0k;// One
 
-//CHECK-NEXT: `-VarDecl {{.*}} literallast '_Accum' cinit
+//CHECK-NEXT:  -VarDecl {{.*}} literallast '_Accum' cinit
 //CHECK-NEXT:   `-FixedPointLiteral {{.*}} '_Accum' 1.0
Index: clang/test/AST/ast-dump-traits.cpp
===
--- clang/test/AST/ast-dump-traits.cpp
+++ clang/test/AST/ast-dump-traits.cpp
@@ -52,7 +52,7 @@
 // CHECK-NEXT: | `-CompoundStmt {{.*}} 
 // CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: | `-ExpressionTraitExpr {{.*}}  'bool' __is_lvalue_expr
-// CHECK-NEXT: `-FunctionDecl {{.*}}  line:30:6{{( imported)?}} test_unary_expr_or_type_trait 'void ()'
+// CHECK-NEXT:  -FunctionDecl {{.*}}  line:30:6{{( imported)?}} test_unary_expr_or_type_trait 'void ()'
 // CHECK-NEXT:   `-CompoundStmt {{.*}} 
 // CHECK-NEXT: |-CStyleCastExp

[PATCH] D136886: [clang] ASTImporter: Fix importing of va_list types and declarations

2022-10-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 471809.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

Files:
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
  clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/ASTMerge.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/AST/ast-dump-file-line-json.c
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-traits.cpp
  clang/test/AST/fixed_point.c
  clang/test/AST/float16.cpp
  clang/test/PCH/stmt-openmp_structured_block-bit.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7499,7 +7499,14 @@
   }
   )",
   Lang_CXX14);
-  auto *FromFD = FirstDeclMatcher().match(FromTU, fieldDecl());
+
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  CXXRecordDecl *FromLambda =
+  cast((cast(FromF->getBody())->body_back()))
+  ->getLambdaClass();
+
+  auto *FromFD = *FromLambda->field_begin();
   ASSERT_TRUE(FromFD);
   ASSERT_TRUE(FromFD->hasCapturedVLAType());
 
@@ -8075,6 +8082,24 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaList) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/test/PCH/stmt-openmp_structured_block-bit.cpp
===
--- clang/test/PCH/stmt-openmp_structured_block-bit.cpp
+++ clang/test/PCH/stmt-openmp_structured_block-bit.cpp
@@ -13,7 +13,7 @@
 // expected-no-diagnostics
 
 // CHECK: TranslationUnitDecl 0x{{.*}} <> 
-// CHECK: `-FunctionDecl 0x{{.*}} <{{.*}}stmt-openmp_structured_block-bit.cpp:8:1, line:11:1> line:8:6 {{(test|imported test)}} 'void ()'
+// CHECK:  -FunctionDecl 0x{{.*}} <{{.*}}stmt-openmp_structured_block-bit.cpp:8:1, line:11:1> line:8:6 {{(test|imported test)}} 'void ()'
 // CHECK-NEXT:   `-CompoundStmt 0x{{.*}} 
 // CHECK-NEXT: `-OMPParallelDirective 0x{{.*}} 
 // CHECK-NEXT:   `-CapturedStmt 0x{{.*}} 
Index: clang/test/AST/float16.cpp
===
--- clang/test/AST/float16.cpp
+++ clang/test/AST/float16.cpp
@@ -29,7 +29,7 @@
   }
 }
 
-//CHECK:  |-NamespaceDecl
+//CHECK:  |-NamespaceDecl {{.*}} <{{.*}}:22:1,
 //CHECK-NEXT: | |-VarDecl {{.*}} f1n '_Float16'
 //CHECK-NEXT: | |-VarDecl {{.*}} f2n '_Float16' cinit
 //CHECK-NEXT: | | `-FloatingLiteral {{.*}} '_Float16' 3.30e+01
Index: clang/test/AST/fixed_point.c
===
--- clang/test/AST/fixed_point.c
+++ clang/test/AST/fixed_point.c
@@ -402,5 +402,5 @@
 
 _Accum literallast = 1.0k;// One
 
-//CHECK-NEXT: `-VarDecl {{.*}} literallast '_Accum' cinit
+//CHECK-NEXT:  -VarDecl {{.*}} literallast '_Accum' cinit
 //CHECK-NEXT:   `-FixedPointLiteral {{.*}} '_Accum' 1.0
Index: clang/test/AST/ast-dump-traits.cpp
===
--- clang/test/AST/ast-dump-traits.cpp
+++ clang/test/AST/ast-dump-traits.cpp
@@ -52,7 +52,7 @@
 // CHECK-NEXT: | `-CompoundStmt {{.*}} 
 // CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: | `-ExpressionTraitExpr {{.*}}  'bool' __is_lvalue_expr
-// CHECK-NEXT: `-FunctionDecl {{.*}}  line:30:6{{( imported)?}} test_unary_expr_or_type_trait 'void ()'
+// CHECK-NEXT:  -FunctionDecl {{.*}}  line:30:6{{( imported)?}} test_unary_expr_or_type_trait 'void ()'
 // CHECK-NEXT:   `-CompoundStmt {{.*}} 
 // CHECK-NEXT: |-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}}  'unsigned long' sizeof 'int'
Index: clang/test/AST/ast-dump-template-decls-json.cpp
===
--- clang/test/AST/ast-dump-template-decls-json.cpp
+++ clang/test/AST/ast-dump-template-decls

[PATCH] D132131: [clang-format] Adds a formatter for aligning trailing comments over empty lines

2022-10-29 Thread Yusuke Kadowaki via Phabricator via cfe-commits
yusuke-kadowaki added a comment.

@MyDeveloperDay @HazardyKnusperkeks

Could you land this please if we are not waiting for anything?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132131

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


[PATCH] D136920: [clang][Interp] Array initialization via CXXConstructExpr

2022-10-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471813.

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

https://reviews.llvm.org/D136920

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/arrays.cpp


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -185,6 +185,20 @@
   }
 };
 
+class A {
+public:
+  int a;
+  constexpr A(int m = 2) : a(10 + m) {}
+};
+class B {
+public:
+  A a[2];
+  constexpr B() {}
+};
+constexpr B b;
+static_assert(b.a[0].a == 12, "");
+static_assert(b.a[1].a == 12, "");
+
 namespace IncDec {
   // FIXME: Pointer arithmethic needs to be supported in inc/dec
   //   unary operators
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -957,6 +957,36 @@
   assert(false && "default initializer for non-primitive type");
 }
 
+return true;
+  } else if (const auto *Ctor = dyn_cast(Initializer)) {
+const ArrayType *AT = Ctor->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+const Function *Func = getFunction(Ctor->getConstructor());
+if (!Func || !Func->isConstexpr())
+  return false;
+
+// FIXME(perf): We're calling the constructor once per array element here,
+//   in the old intepreter we had a special-case for trivial constructors.
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitDupPtr(Initializer))
+return false;
+  if (!this->emitConstUint64(I, Initializer))
+return false;
+  if (!this->emitAddOffsetUint64(Initializer))
+return false;
+  if (!this->emitNarrowPtr(Initializer))
+return false;
+
+  // Constructor arguments.
+  for (const auto *Arg : Ctor->arguments()) {
+if (!this->visit(Arg))
+  return false;
+  }
+
+  if (!this->emitCall(Func, Initializer))
+return false;
+}
 return true;
   }
 


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -185,6 +185,20 @@
   }
 };
 
+class A {
+public:
+  int a;
+  constexpr A(int m = 2) : a(10 + m) {}
+};
+class B {
+public:
+  A a[2];
+  constexpr B() {}
+};
+constexpr B b;
+static_assert(b.a[0].a == 12, "");
+static_assert(b.a[1].a == 12, "");
+
 namespace IncDec {
   // FIXME: Pointer arithmethic needs to be supported in inc/dec
   //   unary operators
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -957,6 +957,36 @@
   assert(false && "default initializer for non-primitive type");
 }
 
+return true;
+  } else if (const auto *Ctor = dyn_cast(Initializer)) {
+const ArrayType *AT = Ctor->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+const Function *Func = getFunction(Ctor->getConstructor());
+if (!Func || !Func->isConstexpr())
+  return false;
+
+// FIXME(perf): We're calling the constructor once per array element here,
+//   in the old intepreter we had a special-case for trivial constructors.
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitDupPtr(Initializer))
+return false;
+  if (!this->emitConstUint64(I, Initializer))
+return false;
+  if (!this->emitAddOffsetUint64(Initializer))
+return false;
+  if (!this->emitNarrowPtr(Initializer))
+return false;
+
+  // Constructor arguments.
+  for (const auto *Arg : Ctor->arguments()) {
+if (!this->visit(Arg))
+  return false;
+  }
+
+  if (!this->emitCall(Func, Initializer))
+return false;
+}
 return true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-10-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471814.
tbaeder added a comment.

Moved the tests to their own file and moved the `isConstantContext()` changes 
to `InterpState` to their own NFC commit.


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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float, B)\
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -25,6 +25,7 @@
 def Uint32 : Type;
 def Sint64 : Type;
 def Uint64 : Type;
+def Float : Type;
 def Ptr : Type;
 
 //===--===//
@@ -40,12 +41,15 @@
 def ArgUint32 : ArgType { let Name = "uint32_t"; }
 def ArgSint64 : ArgType { let Name = "int64_t"; }
 def ArgUint64 : ArgType { let Name = "uint64_t"; }
+def ArgFloat : ArgType { let Name = "Floating"; }
 def ArgBool : ArgType { let Name = "bool"; }
 
 def ArgFunction : ArgType { let Name = "const Function *"; }
 def ArgRecordDecl : ArgType { let Name = "const RecordDecl *"; }
 def ArgRecordField : ArgType { let Name = "const Record::Field *"; }
 def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
+def ArgFltSemantics : ArgType { let Name = "const llvm::fltSemantics *"; }
+def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
 
 //===--===//
 // Classes of types instructions operate on.
@@ -55,18 +59,21 @@
   list Types;
 }
 
-def NumberTypeClass : TypeClass {
+def IntegerTypeClass : TypeClass {
   let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
Uint32, Sint64, Uint64];
 }
 
-def IntegerTypeClass : TypeClass {
-  let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
-   Uint32, Sint64, Uint64];
+def NumberTypeClass : TypeClass {
+  let Types = !listconcat(IntegerTypeClass.Types, [Float]);
+}
+
+def FloatTypeClass : TypeClass {
+  let Types = [Float];
 }
 
 def AluTypeClass : TypeClass {
-  let Types = !listconcat(NumberTypeClass.Types, [Bool]);
+  let Types = !listconcat(IntegerTypeClass.Types, [Bool]);
 }
 
 def PtrTypeClass : TypeClass {
@@ -77,12 +84,16 @@
   let Types = [Bool];
 }
 
+def NonPtrT