[PATCH] D136936: [clang][Interp] Handle undefined functions better

2022-11-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472853.

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

https://reviews.llvm.org/D136936

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 
-// expected-no-diagnostics
-// ref-no-diagnostics
-
 constexpr void doNothing() {}
 constexpr int gimme5() {
   doNothing();
@@ -73,3 +70,17 @@
 static_assert(getNum<-2>() == -2, "");
 static_assert(getNum<10>() == 10, "");
 static_assert(getNum() == 5, "");
+
+constexpr int f(); // expected-note {{declared here}} \
+   // ref-note {{declared here}}
+static_assert(f() == 5, ""); // expected-error {{not an integral constant expression}} \
+ // expected-note {{undefined function 'f'}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{undefined function 'f'}}
+constexpr int a() {
+  return f();
+}
+constexpr int f() {
+  return 5;
+}
+static_assert(a() == 5, "");
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -95,6 +95,7 @@
   /// Creates a new function from a code range.
   template 
   Function *createFunction(const FunctionDecl *Def, Ts &&... Args) {
+Def = Def->getCanonicalDecl();
 auto *Func = new Function(*this, Def, std::forward(Args)...);
 Funcs.insert({Def, std::unique_ptr(Func)});
 return Func;
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -209,7 +209,8 @@
 }
 
 Function *Program::getFunction(const FunctionDecl *F) {
-  F = F->getDefinition();
+  F = F->getCanonicalDecl();
+  assert(F);
   auto It = Funcs.find(F);
   return It == Funcs.end() ? nullptr : It->second.get();
 }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -83,7 +83,7 @@
 bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
 /// Checks if a method can be called.
-bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F);
+bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F);
 
 /// Checks the 'this' pointer.
 bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This);
@@ -1268,9 +1268,11 @@
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;
 }
-// TODO: CheckCallable
   }
 
+  if (!CheckCallable(S, PC, Func))
+return false;
+
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -338,17 +338,18 @@
   return true;
 }
 
-bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F) {
-  const SourceLocation &Loc = S.Current->getLocation(OpPC);
+bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
 
   if (F->isVirtual()) {
 if (!S.getLangOpts().CPlusPlus20) {
+  const SourceLocation &Loc = S.Current->getLocation(OpPC);
   S.CCEDiag(Loc, diag::note_constexpr_virtual_call);
   return false;
 }
   }
 
   if (!F->isConstexpr()) {
+const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
 
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -135,6 +135,9 @@
 
   bool hasThisPointer() const { return HasThisPointer; }
 
+  // Checks if the funtion already has a body attached.
+  bool hasBody() const { return HasBody; }
+
   unsigned getNumParams() const { return ParamTypes.size(); }
 
 private:
@@ -152,6 +155,7 @@
 SrcMap = std::move(NewSrcMap);
 Scopes = std::move(NewScopes);
 IsValid = true;
+HasBody = true;
   }
 
   void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }
@@ -192,6 +196,8 @@
   /// the return value is constructed in the caller's stack frame.
   /// This is done for functions that return non-primive values.
   bool HasRVO = false;
+  /// If we've already compile

[PATCH] D137240: [clang][Interp] Support alignof()

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:444
+// alignment of the referenced type.
+if (const ReferenceType *Ref = ArgType->getAs())
+  ArgType = Ref->getPointeeType();

aaron.ballman wrote:
> You're missing the rest of the standards quote from 
> http://eel.is/c++draft/expr.alignof#3. There is some logic missing here for 
> array types. Getting the alignment of an array gives you the alignment of its 
> element type. (And there don't seem to be any tests for calling alignof on an 
> array, so we should add some.)
This seems to be handled by `ASTContext`? It "just works" at least and this 
added code block is almost copy/paste from the current constant interpreter. 
I'll add some tests though.


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

https://reviews.llvm.org/D137240

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


[PATCH] D137240: [clang][Interp] Support alignof()

2022-11-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472855.

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

https://reviews.llvm.org/D137240

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/class-layout.cpp

Index: clang/test/AST/Interp/class-layout.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/class-layout.cpp
@@ -0,0 +1,698 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -fexperimental-new-constant-interpreter -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
+// expected-no-diagnostics
+
+// FIXME: This is a copy of clang/test/SemaCXX/class-layout.cpp, but with the
+//   __builtin_offsetof calls commented out. Once that is supported in the
+//   new interpreter, we might as well remove this duplicated file and
+//   just use the one in SemaCXX/.
+
+#define SA(n, p) int a##n[(p) ? 1 : -1]
+
+struct A {
+  int a;
+  char b;
+};
+
+SA(0, sizeof(A) == 8);
+
+struct B : A {
+  char c;
+};
+
+SA(1, sizeof(B) == 12);
+
+struct C {
+// Make fields private so C won't be a POD type.
+private:
+  int a;
+  char b;
+};
+
+SA(2, sizeof(C) == 8);
+
+struct D : C {
+  char c;
+};
+
+SA(3, sizeof(D) == 8);
+
+struct __attribute__((packed)) E {
+  char b;
+  int a;
+};
+
+SA(4, sizeof(E) == 5);
+
+struct __attribute__((packed)) F : E {
+  char d;
+};
+
+SA(5, sizeof(F) == 6);
+
+struct G { G(); };
+struct H : G { };
+
+SA(6, sizeof(H) == 1);
+
+struct I {
+  char b;
+  int a;
+} __attribute__((packed));
+
+SA(6_1, sizeof(I) == 5);
+
+// PR5580
+namespace PR5580 {
+
+class A { bool iv0 : 1; };
+SA(7, sizeof(A) == 1);  
+
+class B : A { bool iv0 : 1; };
+SA(8, sizeof(B) == 2);
+
+struct C { bool iv0 : 1; };
+SA(9, sizeof(C) == 1);  
+
+struct D : C { bool iv0 : 1; };
+SA(10, sizeof(D) == 2);
+
+}
+
+namespace Test1 {
+
+// Test that we don't assert on this hierarchy.
+struct A { };
+struct B : A { virtual void b(); };
+class C : virtual A { int c; };
+struct D : virtual B { };
+struct E : C, virtual D { };
+class F : virtual E { };
+struct G : virtual E, F { };
+
+SA(0, sizeof(G) == 24);
+
+}
+
+namespace Test2 {
+
+// Test that this somewhat complex class structure is laid out correctly.
+struct A { };
+struct B : A { virtual void b(); };
+struct C : virtual B { };
+struct D : virtual A { };
+struct E : virtual B, D { };
+struct F : E, virtual C { };
+struct G : virtual F, A { };
+struct H { G g; };
+
+SA(0, sizeof(H) == 24);
+
+}
+
+namespace PR16537 {
+namespace test1 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test2 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11 __attribute__((aligned(16)));
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only {
+char may_go_into_tail_padding;
+  };
+
+  SA(0, sizeof(might_use_tail_padding) == 16);
+}
+
+namespace test3 {
+  struct pod_in_11_only {
+  private:
+long long x;
+  };
+   
+  struct tail_padded_pod_in_11_only {
+pod_in_11_only pod11;
+char tail_padding;
+  };
+
+  struct second_base {
+  char foo;
+  };
+
+  struct might_use_tail_padding : public tail_padded_pod_in_11_only, public second_base

[PATCH] D137082: [clang][Interp] Fix dereferencing arrays with no offset applied

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



Comment at: clang/lib/AST/Interp/Interp.h:966-967
 return false;
-  S.Stk.push(Ptr.deref());
+  // When getting the first value of an array, we need to offset to the
+  // first element.
+  if (Ptr.inArray() && Ptr.isRoot())

aaron.ballman wrote:
> So why don't we need to do this dance for `Store`/`StorePop`?
We do, I just realized.

It might make more sense to do this in `Pointer::deref()` directly, so 
'deref()`'ing an array always returns the first element.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137082

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


[PATCH] D137316: [Clang][LoongArch] Implement __builtin_loongarch_crc_w_d_w builtin and add diagnostics

2022-11-03 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
gonglingqin requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch adds support to prevent __builtin_loongarch_crc_w_d_w from compiling
on loongarch32 in the front end and adds diagnostics accordingly.

Reference: 
https://github.com/gcc-mirror/gcc/blob/master/gcc/config/loongarch/larchintrin.h#L175-L184

Depends on D136906 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137316

Files:
  clang/include/clang/Basic/BuiltinsLoongArch.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/larchintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/LoongArch/intrinsic-error.c
  clang/test/CodeGen/LoongArch/intrinsic-la64.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
  llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la64.ll

Index: llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+declare i32 @llvm.loongarch.crc.w.d.w(i64, i32)
+
+define i32 @crc_w_d_w(i64 %a, i32 %b) nounwind {
+; CHECK-LABEL: crc_w_d_w:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:crc.w.d.w $a0, $a0, $a1
+; CHECK-NEXT:ret
+  %res = call i32 @llvm.loongarch.crc.w.d.w(i64 %a, i32 %b)
+  ret i32 %res
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
@@ -0,0 +1,10 @@
+; RUN: not llc --mtriple=loongarch32 --disable-verify < %s 2>&1 | FileCheck %s
+
+declare i32 @llvm.loongarch.crc.w.d.w(i64, i32)
+
+define i32 @crc_w_d_w(i64 %a, i32 %b) nounwind {
+; CHECK: llvm.loongarch.crc.w.d.w requires target: loongarch64
+entry:
+  %res = call i32 @llvm.loongarch.crc.w.d.w(i64 %a, i32 %b)
+  ret i32 %res
+}
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -55,6 +55,8 @@
 def loongarch_srl_w : SDNode<"LoongArchISD::SRL_W", SDT_LoongArchIntBinOpW>;
 def loongarch_rotr_w : SDNode<"LoongArchISD::ROTR_W", SDT_LoongArchIntBinOpW>;
 def loongarch_rotl_w : SDNode<"LoongArchISD::ROTL_W", SDT_LoongArchIntBinOpW>;
+def loongarch_crc_w_d_w
+: SDNode<"LoongArchISD::CRC_W_D_W", SDT_LoongArchIntBinOpW>;
 def loongarch_bstrins
 : SDNode<"LoongArchISD::BSTRINS", SDT_LoongArchBStrIns>;
 def loongarch_bstrpick
@@ -1307,6 +1309,9 @@
 
 let Predicates = [IsLA64] in {
 def : Pat<(loongarch_dbar uimm15:$imm15), (DBAR uimm15:$imm15)>;
+
+// CRC Check Instructions
+def : PatGprGpr;
 } // Predicates = [IsLA64]
 
 /// Other pseudo-instructions
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.h
===
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -59,6 +59,9 @@
 
   // Intrinsic operations
   DBAR,
+
+  // CRC check operations
+  CRC_W_D_W
 };
 } // end namespace LoongArchISD
 
@@ -177,6 +180,7 @@
   SDValue lowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
+  SDValue lowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -89,6 +89,7 @@
 setOperationAction(ISD::CTTZ, MVT::i32, Custom);
 setOperationAction(ISD::CTLZ, MVT::i32, Custom);
 setOperationAction(ISD::INTRINSIC_VOID, MVT::i32, Custom);
+setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i32, Custom);
 if (Subtarget.hasBasicF() && !Subtarget.hasBasicD())
   setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
 if (Subtarget.hasBasicF())
@@ -113,6 +114,7 @@
 setOperationAction(ISD::BIT

[clang] fdab9f1 - [Clang] Check for response file existence prior to check for recursion

2022-11-03 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2022-11-03T14:49:58+07:00
New Revision: fdab9f1203eea48a7b8e4c55c7ceafc54653797c

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

LOG: [Clang] Check for response file existence prior to check for recursion

As now errors in file operation are handled, check for file existence
must be done prior to check for recursion, otherwise reported errors are
misleading.

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

Added: 
clang/test/Driver/Inputs/inc-inexistent.rsp
clang/test/Driver/response-file-errs.c

Modified: 
clang/tools/driver/driver.cpp
clang/unittests/Driver/ToolChainTest.cpp
llvm/lib/Support/CommandLine.cpp

Removed: 




diff  --git a/clang/test/Driver/Inputs/inc-inexistent.rsp 
b/clang/test/Driver/Inputs/inc-inexistent.rsp
new file mode 100644
index 0..c9ecfdf88ddd0
--- /dev/null
+++ b/clang/test/Driver/Inputs/inc-inexistent.rsp
@@ -0,0 +1 @@
+@inexistent.txt

diff  --git a/clang/test/Driver/response-file-errs.c 
b/clang/test/Driver/response-file-errs.c
new file mode 100644
index 0..c0e02a984b9af
--- /dev/null
+++ b/clang/test/Driver/response-file-errs.c
@@ -0,0 +1,15 @@
+// If response file does not exist, '@file; directive remains unexpanded in
+// command line.
+//
+// RUN: %clang @%S/Inputs/inexistent.rsp -### 2>&1 | FileCheck 
--check-prefix=INEXISTENT %s
+// INEXISTENT: @{{.*}}Inputs/inexistent.rsp
+
+// As the above case but '@file' is in response file.
+//
+// RUN: %clang @%S/Inputs/inc-inexistent.rsp -### 2>&1 | FileCheck 
--check-prefix=INEXISTENT2 %s
+// INEXISTENT2: @{{.*}}inexistent.txt
+
+// If file in `@file` is a directory, it is an error.
+//
+// RUN: not %clang @%S/Inputs -### 2>&1 | FileCheck --check-prefix=DIRECTORY %s
+// DIRECTORY: cannot not open file '{{.*}}Inputs': {{[Ii]}}s a directory

diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 2cc3b48609cb3..4b1a246d99430 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -378,7 +378,7 @@ int clang_main(int Argc, char **Argv) {
   llvm::cl::ExpansionContext ECtx(A, Tokenizer);
   ECtx.setMarkEOLs(MarkEOLs);
   if (llvm::Error Err = ECtx.expandResponseFiles(Args)) {
-llvm::errs() << Err << '\n';
+llvm::errs() << toString(std::move(Err)) << '\n';
 return 1;
   }
 

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index b143cd6329455..b45bab06d64b8 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -596,9 +596,10 @@ TEST(ToolChainTest, ConfigInexistentInclude) {
 ASSERT_TRUE(C);
 ASSERT_TRUE(C->containsError());
 EXPECT_EQ(1U, DiagConsumer->Errors.size());
-EXPECT_STREQ("cannot read configuration file '" USERCONFIG
- "': cannot not open file '" UNEXISTENT "'",
- DiagConsumer->Errors[0].c_str());
+EXPECT_STRCASEEQ("cannot read configuration file '" USERCONFIG
+ "': cannot not open file '" UNEXISTENT
+ "': no such file or directory",
+ DiagConsumer->Errors[0].c_str());
   }
 
 #undef USERCONFIG

diff  --git a/llvm/lib/Support/CommandLine.cpp 
b/llvm/lib/Support/CommandLine.cpp
index 136b813b1f6c8..fbaacbbbcf8a0 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1158,9 +1158,11 @@ Error ExpansionContext::expandResponseFile(
   assert(sys::path::is_absolute(FName));
   llvm::ErrorOr> MemBufOrErr =
   FS->getBufferForFile(FName);
-  if (!MemBufOrErr)
-return llvm::createStringError(
-MemBufOrErr.getError(), Twine("cannot not open file '") + FName + "'");
+  if (!MemBufOrErr) {
+std::error_code EC = MemBufOrErr.getError();
+return llvm::createStringError(EC, Twine("cannot not open file '") + FName 
+
+   "': " + EC.message());
+  }
   MemoryBuffer &MemBuf = *MemBufOrErr.get();
   StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
 
@@ -1262,7 +1264,7 @@ Error ExpansionContext::expandResponseFiles(
 if (auto CWD = FS->getCurrentWorkingDirectory()) {
   CurrDir = *CWD;
 } else {
-  return make_error(
+  return createStringError(
   CWD.getError(), Twine("cannot get absolute path for: ") + FName);
 }
   } else {
@@ -1271,49 +1273,48 @@ Error ExpansionContext::expandResponseFiles(
   llvm::sys::path::append(CurrDir, FName);
   FName = CurrDir.c_str();
 }
+
+ErrorOr Res = FS->status(FName);
+if (!Res || !Res->exists()) {
+  std::error_code EC = Res.getError();
+  if (!InConfigFile) {
+// If the specified file does not exist, leave '@file' unexpanded, a

[PATCH] D137317: [X86][CET] Add Diags for targets pre to i686

2022-11-03 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added a reviewer: nickdesaulniers.
Herald added a project: All.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I intended to not adding test case since it is NFC to most modern X86 targets.

Fixes #58737


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137317

Files:
  clang/lib/Basic/Targets/X86.h


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -241,12 +241,16 @@
 
   bool
   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionReturnSupported(Diags);
   };
 
   bool
   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionBranchSupported(Diags);
   };
 
   virtual bool validateOperandSize(const llvm::StringMap &FeatureMap,


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -241,12 +241,16 @@
 
   bool
   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionReturnSupported(Diags);
   };
 
   bool
   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionBranchSupported(Diags);
   };
 
   virtual bool validateOperandSize(const llvm::StringMap &FeatureMap,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8cb9e3c - [AArch64] Install arm_neon_sve_bridge.h

2022-11-03 Thread Peter Waller via cfe-commits

Author: Peter Waller
Date: 2022-11-03T07:55:57Z
New Revision: 8cb9e3c3ce1e7e1658921f90420b68ca16bb98fc

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

LOG: [AArch64] Install arm_neon_sve_bridge.h

arm_neon_sve_bridge.h is not generated, so the rules which ensure the
generated files get copied into the installation prefix don't apply to
this one.

Add it to the aarch64_only_files set instead, which ensures it ends up
both in the build directory and the installation directory.

Tested with build targets `clang-resource-headers` and
`install-clang-resource-headers`.

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

Added: 


Modified: 
clang/lib/Headers/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index f69bf14891440..402b7374ca816 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -33,6 +33,7 @@ set(arm_only_files
 
 set(aarch64_only_files
   arm64intr.h
+  arm_neon_sve_bridge.h
   )
 
 set(cuda_files
@@ -326,10 +327,6 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
-  # Copy arm_neon_sve_bridge.h
-  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR}
-arm_neon_sve_bridge.h
-  )
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -345,7 +342,6 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
   list(APPEND aarch64_only_generated_files
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
-"${output_dir}/arm_neon_sve_bridge.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)



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


[PATCH] D137239: [AArch64] Install arm_neon_sve_bridge.h

2022-11-03 Thread Peter Waller via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8cb9e3c3ce1e: [AArch64] Install arm_neon_sve_bridge.h 
(authored by peterwaller-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137239

Files:
  clang/lib/Headers/CMakeLists.txt


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -33,6 +33,7 @@
 
 set(aarch64_only_files
   arm64intr.h
+  arm_neon_sve_bridge.h
   )
 
 set(cuda_files
@@ -326,10 +327,6 @@
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
-  # Copy arm_neon_sve_bridge.h
-  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR}
-arm_neon_sve_bridge.h
-  )
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -345,7 +342,6 @@
   list(APPEND aarch64_only_generated_files
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
-"${output_dir}/arm_neon_sve_bridge.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -33,6 +33,7 @@
 
 set(aarch64_only_files
   arm64intr.h
+  arm_neon_sve_bridge.h
   )
 
 set(cuda_files
@@ -326,10 +327,6 @@
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
-  # Copy arm_neon_sve_bridge.h
-  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR}
-arm_neon_sve_bridge.h
-  )
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -345,7 +342,6 @@
   list(APPEND aarch64_only_generated_files
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
-"${output_dir}/arm_neon_sve_bridge.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136796: [llvm-objdump][Offload] Use common offload extraction method

2022-11-03 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

In D136796#3903393 , @jhuber6 wrote:

> Is this good to land now?

The LLVM community practice is to wait a week between pings unless there's 
something urgent (and if something is urgent, please say so).

Aside from the clang bit of the patch, this seems good to me, but it would be 
worth another person involved with offloading to give the final thumbs up.




Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:1262-1265
+if (identify_magic((*BufferOrErr)->getBuffer()) ==
+file_magic::elf_shared_object)
+  continue;
+

This change seems not really part of the patch, since it's touching `clang` but 
the patch is for `llvm-objdump`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136796

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


[PATCH] D137153: [WIP][X86] Support -march=sierraforest, grandridge, graniterapids.

2022-11-03 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: llvm/include/llvm/Support/X86TargetParser.def:94
+X86_CPU_SUBTYPE(AMDFAM19H_ZNVER4,"znver4")
+X86_CPU_SUBTYPE(INTEL_COREI7_SIERRAFOREST,   "sierraforest")
+X86_CPU_SUBTYPE(INTEL_COREI7_GRANITERAPIDS,  "graniterapids")

FYI: gcc is going to land the [[ 
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603547.html | 
sierraforest patch ]]. They are going to add such E-core based CPUs to CPU_TYPE 
list but not this one, like the previous atom series e.g. tremont, silvermont 
and so on. It's functionally correct, so I'm ok to this change. WDYT


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137153

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


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

2022-11-03 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:7
+//
+// Author: Fabian Keßler "Febbe" 
+//===--===//

Author ditto.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:47
+
+constexpr auto BlockedTypesOption = "BlockedTypes";
+constexpr auto BlockedFunctionsOption = "BlockedFunctions";

These should be static



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:52
+
+constexpr bool PrintDebug = false;
+

This doesn't belong in the final version of this patch.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:59
+
+auto findDeclRefBlock(CFG const *TheCFG, DeclRefExpr const *DeclRef)
+-> FindDeclRefBlockReturn {

Anonymous namespaces should be kept as small as possible and only used for 
decls that don't have another way to specify linkage. Therefore these functions 
should be moved out of the namespace and marked as static.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:111
+  if (!TheCFG) {
+return createStringError(llvm::errc::bad_address,
+ "CFG is nullptr, aborting.\n");

Is this an expected issue to run into, if not this should be seen assert. Same 
goes for below.
Also given no user would ever see the error message, it's probably unnecessary 
to create them. If the errors are situations that are expected to happen during 
runtime, make this function return an optional, if not just return a Usage 
directly.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:141
+  assert(BlockElement.DeclRefBlock);
+  auto Block = BlockElement.DeclRefBlock->succs();
+  // No successing DeclRefExpr found, appending successors

replace auto with type here.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:143
+  // No successing DeclRefExpr found, appending successors
+  for (auto const &Succ : BlockElement.DeclRefBlock->succs()) {
+if (Succ) { // Succ can be nullptr, if a block is unreachable

Ditto



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:214
+
+  Finder->addMatcher(traverse(TK_AsIs, stmt(anyOf(IsMoveAssingable,
+  expr(IsMoveConstructible,

AsIs traversal is the default kind, so there's no need to specify this.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:236
+  for (auto &Type : BlockedTypes) {
+if (Param->getType().getAsString().find(Type) != std::string::npos) {
+  return; // The type is blocked

Isn't blocked types meant to be a regular expression?



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:272
+
+  clang::SourceManager &SM = *Result.SourceManager;
+  SourceLocation EndLoc = Lexer::getLocForEndOfToken(

This code can be moved inside the template check then branch as it's not used 
in the else or after the if.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp:294
+  }
+  // Generate Diagnostic
+}

What's this comment for?



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:7
+//
+// Author: Fabian Keßler "Febbe" 
+//===--===//

We don't include author information in files, that is kept in the got history 
instead.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:10
+
+#pragma once
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_ON_LAST_USE_H

Remove this, the include guard is enough.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:21
+namespace clang {
+namespace tidy::performance {
+

I have no preference either way, but can these namespaces all be nested or none 
nested.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:27
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/performance-unnecessary-copy-on-last-use.html
+





Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h:33
+  bool isLanguageVersionSupported(const L

[PATCH] D137153: [WIP][X86] Support -march=sierraforest, grandridge, graniterapids.

2022-11-03 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: llvm/include/llvm/Support/X86TargetParser.def:94
+X86_CPU_SUBTYPE(AMDFAM19H_ZNVER4,"znver4")
+X86_CPU_SUBTYPE(INTEL_COREI7_SIERRAFOREST,   "sierraforest")
+X86_CPU_SUBTYPE(INTEL_COREI7_GRANITERAPIDS,  "graniterapids")

FreddyYe wrote:
> FYI: gcc is going to land the [[ 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603547.html | 
> sierraforest patch ]]. They are going to add such E-core based CPUs to 
> CPU_TYPE list but not this one, like the previous atom series e.g. tremont, 
> silvermont and so on. It's functionally correct, so I'm ok to this change. 
> WDYT
> FYI: gcc is going to land the [[ 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603547.html | 
> sierraforest patch ]]. They are going to add such E-core based CPUs to 
> CPU_TYPE list but not this one, like the previous atom series e.g. tremont, 
> silvermont and so on. It's functionally correct, so I'm ok to this change. 
> WDYT

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137153

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


[clang] 4ecb2b8 - [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-11-03 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2022-11-03T10:28:38+02:00
New Revision: 4ecb2b8ef6be69b55d46ac274f3b7a7103219f98

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

LOG: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

Having AllEnumtypes to be a vector of TrackingMDNodeRef makes it possible
to reflect changes in metadata in the vector if they took place before DIBuilder
being finalized.

Otherwise, we end up with heap-use-after-free because AllEnumTypes contains
metadata that no longer valid.

Consider a case where we have a class containing a definition of a enum,
so this enum has the class as a scope. For some reason (doesn't matter for
the current issue), we create a temporary debug metadata for this class, and
then resolve it while finalizing CGDebugInfo.

In the case of collision during uniqifying the temporary, we then need
to replace its uses with a new pointer. If a temporary's user is unique
(this is the enum mentioned above), we may need re-uniquefying it,
which may return a new pointer in the case of another collision.
If so, the pointer we stored in AllEnumTypes vector become dangling.
Making AllEnumTypes hodling TrackingMDNodeRef should solve this problem
(see debug-info-enum-metadata-collision.cpp test for details).

Reviewed By: dblaikie

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

Added: 
clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp

Modified: 
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp 
b/clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
new file mode 100644
index 0..dd27acd0a77c5
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-debug-info-kind=constructor %s -o - | FileCheck %s
+
+// Test that clang doesn't crash while resolving temporary debug metadata of
+// a record with collisions in the record's enum users.
+
+// CHECK:  !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME:  scope: [[SCOPE:![0-9]+]]
+// CHECK-SAME:  elements: [[ELEMENTS:![0-9]+]]
+// CHECK:  [[SCOPE]] = !DICompositeType(tag: DW_TAG_structure_type
+// CHECK-SAME:  name: "Struct1"
+// CHECK:  [[ELEMENTS]] = !{[[ELEMENT:![0-9]+]]}
+// CHECK:  [[ELEMENT]] = !DIEnumerator(name: "enumValue1"
+
+template  struct Struct1 {
+  enum { enumValue1 };
+  Struct1();
+};
+void function2() {
+  struct Struct3 {};
+  int i = Struct1::enumValue1;
+}
+void function3() {
+  struct Struct3 {};
+  int i = Struct1::enumValue1;
+}

diff  --git a/llvm/include/llvm/IR/DIBuilder.h 
b/llvm/include/llvm/IR/DIBuilder.h
index dfb65ce341296..61fa4d8f3b9fd 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@ namespace llvm {
 Function *LabelFn;   ///< llvm.dbg.label
 Function *AddrFn;///< llvm.dbg.addr
 
-SmallVector AllEnumTypes;
+SmallVector AllEnumTypes;
 /// Track the RetainTypes, since they can be updated later on.
 SmallVector AllRetainTypes;
 SmallVector AllSubprograms;

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index fada07ac383ae..76d7ade09a88c 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@ void DIBuilder::finalize() {
   }
 
   if (!AllEnumTypes.empty())
-CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
+CUNode->replaceEnumTypes(MDTuple::get(
+VMContext, SmallVector(AllEnumTypes.begin(),
+   AllEnumTypes.end(;
 
   SmallVector RetainValues;
   // Declarations and definitions of the same type may be retained. Some
@@ -556,7 +558,7 @@ DICompositeType *DIBuilder::createEnumerationType(
   getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 
0,
   IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, 
nullptr,
   nullptr, UniqueIdentifier);
-  AllEnumTypes.push_back(CTy);
+  AllEnumTypes.emplace_back(CTy);
   trackIfUnresolved(CTy);
   return CTy;
 }



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


[PATCH] D137067: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-11-03 Thread Kristina Bessonova 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 rG4ecb2b8ef6be: [DebugInfo][Metadata] Make AllEnumTypes 
holding TrackingMDNodeRef (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137067

Files:
  clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   if (!AllEnumTypes.empty())
-CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
+CUNode->replaceEnumTypes(MDTuple::get(
+VMContext, SmallVector(AllEnumTypes.begin(),
+   AllEnumTypes.end(;
 
   SmallVector RetainValues;
   // Declarations and definitions of the same type may be retained. Some
@@ -556,7 +558,7 @@
   getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 
0,
   IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, 
nullptr,
   nullptr, UniqueIdentifier);
-  AllEnumTypes.push_back(CTy);
+  AllEnumTypes.emplace_back(CTy);
   trackIfUnresolved(CTy);
   return CTy;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 Function *LabelFn;   ///< llvm.dbg.label
 Function *AddrFn;///< llvm.dbg.addr
 
-SmallVector AllEnumTypes;
+SmallVector AllEnumTypes;
 /// Track the RetainTypes, since they can be updated later on.
 SmallVector AllRetainTypes;
 SmallVector AllSubprograms;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-debug-info-kind=constructor %s -o - | FileCheck %s
+
+// Test that clang doesn't crash while resolving temporary debug metadata of
+// a record with collisions in the record's enum users.
+
+// CHECK:  !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME:  scope: [[SCOPE:![0-9]+]]
+// CHECK-SAME:  elements: [[ELEMENTS:![0-9]+]]
+// CHECK:  [[SCOPE]] = !DICompositeType(tag: DW_TAG_structure_type
+// CHECK-SAME:  name: "Struct1"
+// CHECK:  [[ELEMENTS]] = !{[[ELEMENT:![0-9]+]]}
+// CHECK:  [[ELEMENT]] = !DIEnumerator(name: "enumValue1"
+
+template  struct Struct1 {
+  enum { enumValue1 };
+  Struct1();
+};
+void function2() {
+  struct Struct3 {};
+  int i = Struct1::enumValue1;
+}
+void function3() {
+  struct Struct3 {};
+  int i = Struct1::enumValue1;
+}


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   if (!AllEnumTypes.empty())
-CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
+CUNode->replaceEnumTypes(MDTuple::get(
+VMContext, SmallVector(AllEnumTypes.begin(),
+   AllEnumTypes.end(;
 
   SmallVector RetainValues;
   // Declarations and definitions of the same type may be retained. Some
@@ -556,7 +558,7 @@
   getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
   IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr,
   nullptr, UniqueIdentifier);
-  AllEnumTypes.push_back(CTy);
+  AllEnumTypes.emplace_back(CTy);
   trackIfUnresolved(CTy);
   return CTy;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 Function *LabelFn;   ///< llvm.dbg.label
 Function *AddrFn;///< llvm.dbg.addr
 
-SmallVector AllEnumTypes;
+SmallVector AllEnumTypes;
 /// Track the RetainTypes, since they can be updated later on.
 SmallVector AllRetainTypes;
 SmallVector AllSubprograms;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -debug-info-kind=constructor %s -o - | FileCheck %s
+
+// Test that clang doesn't crash while resolving temporary debug metadata of
+// a record with collisions in the record's enum users.
+
+// CHECK:  !DICompositeType(tag: DW_TAG_enumeration_type,
+//

[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-03 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh updated this revision to Diff 472875.
Pierre-vh marked 2 inline comments as done.
Pierre-vh added a comment.

Comments

Not sure if the release note is in the right place though.
As for the test, I did something quite targeted/minimal, hope it's fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137251

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/CodeGenCUDA/lambda-noinline.cu
  clang/test/Parser/lambda-attr.cu

Index: clang/test/Parser/lambda-attr.cu
===
--- clang/test/Parser/lambda-attr.cu
+++ clang/test/Parser/lambda-attr.cu
@@ -18,6 +18,10 @@
   ([&](int) __attribute__((device)){ device_fn(); })(0);
   // expected-warning@-1 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
   ([&] __attribute__((device)) (int) { device_fn(); })(0);
+
+  // test that noinline can appear anywhere.
+  ([&] __attribute__((device)) __noinline__ () { device_fn(); })();
+  ([&] __noinline__ __attribute__((device)) () { device_fn(); })();
 }
 
 __attribute__((host)) __attribute__((device)) void host_device_attrs() {
@@ -37,6 +41,11 @@
   // expected-warning@-1 {{nvcc does not allow '__host__' to appear after the parameter list in lambdas}}
   // expected-warning@-2 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
   ([&] __attribute__((host)) __attribute__((device)) (int) { hd_fn(); })(0);
+
+  // test that noinline can also appear anywhere.
+  ([] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
+  ([] __attribute__((host)) __noinline__ __attribute__((device)) () { hd_fn(); })();
+  ([] __attribute__((host)) __attribute__((device)) __noinline__ () { hd_fn(); })();
 }
 
 // TODO: Add tests for __attribute__((global)) once we support global lambdas.
Index: clang/test/CodeGenCUDA/lambda-noinline.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/lambda-noinline.cu
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -no-opaque-pointers -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -triple x86_64-linux-gnu \
+// RUN:   | FileCheck -check-prefix=HOST %s
+// RUN: %clang_cc1 -no-opaque-pointers -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN:   | FileCheck -check-prefix=DEV %s
+
+#include "Inputs/cuda.h"
+
+// Checks noinline is correctly added to the lambda function.
+
+// HOST: define{{.*}}@_ZZ4HostvENKUlvE_clEv({{.*}}) #[[ATTR:[0-9]+]]
+// HOST: attributes #[[ATTR]]{{.*}}noinline
+
+// DEV: define{{.*}}@_ZZ6DevicevENKUlvE_clEv({{.*}}) #[[ATTR:[0-9]+]]
+// DEV: attributes #[[ATTR]]{{.*}}noinline
+
+__device__ int a;
+int b;
+
+__device__ int Device() { return ([&] __device__ __noinline__ (){ return a; })(); }
+
+__host__ int Host() { return ([&] __host__ __noinline__ (){ return b; })(); }
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1291,7 +1291,22 @@
   if (getLangOpts().CUDA) {
 // In CUDA code, GNU attributes are allowed to appear immediately after the
 // "[...]", even if there is no "(...)" before the lambda body.
-MaybeParseGNUAttributes(D);
+//
+// Note that we support __noinline__ as a keyword in this mode and thus
+// it has to be separately handled.
+while (true) {
+  if (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+SourceLocation AttrNameLoc = ConsumeToken();
+Attr.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
+ParsedAttr::AS_Keyword);
+  } else if (Tok.is(tok::kw___attribute))
+ParseGNUAttributes(Attr, nullptr, &D);
+  else
+break;
+}
+
+D.takeAttributes(Attr);
   }
 
   // Helper to emit a warning if we see a CUDA host/device/global attribute
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -615,6 +615,9 @@
 CUDA/HIP Language Changes in Clang
 --
 
+ - Allow the use of `__noinline__` as a keyword (instead of `__attribute__((noinline))`)
+   in lambda declarations.
+
 Objective-C Language Changes in Clang
 -
 
@@ -751,8 +754,8 @@
 - Introduced the new function ``clang_CXXMethod_isCopyAssignmentOperator``,
   which identifies whether a method cursor is a copy-assignment
   operator.
-- ``clang_Cursor_getNumTemplateArguments``, ``clang_Cursor_getTemplateArgumentKind``, 
-  ``clang_Cursor_getTemplateArgumentType``, ``clang_Cursor_getTemplateArgumentValue`` and 
+- ``clang_Cursor_getNumTemplateArguments``, ``clang_Cursor_getTemplateArgumentKind``,
+ 

[PATCH] D137251: [clang][cuda/hip] Allow `__noinline__` lambdas

2022-11-03 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1300
+ParseGNUAttributes(Attr, nullptr, &D);
+  } else if (Tok.is(tok::kw___noinline__)) {
+IdentifierInfo *AttrName = Tok.getIdentifierInfo();

aaron.ballman wrote:
> Any other keyword attributes that are missing?
> 
> `alignas`/`_Alignas`
> `__forceinline`
> `__cdecl`/`__stdcall`/etc
> 
I'm not too familiar with how those attributes work yet, so maybe there's more 
to handle but I don't have any concrete example of it being an issue and would 
rather not touch those unless needed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137251

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


[PATCH] D137319: [include-cleaner] Add export IWYU pragma support.

2022-11-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: kadircet, sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

- add support to PragmaIncludes to handle IWYU export/begin_exports/end_exports 
pragma;
- implement an API to retrieve the direct exporter headers;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137319

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

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -30,6 +30,13 @@
   return false;
 }
 
+MATCHER_P(FileNamed, N, "") {
+  if (arg->tryGetRealPathName() == N)
+return true;
+  *result_listener << arg->tryGetRealPathName().str();
+  return false;
+}
+
 class RecordASTTest : public ::testing::Test {
 protected:
   TestInputs Inputs;
@@ -117,13 +124,31 @@
   Inputs.Code = R"cpp(// Line 1
 #include "keep1.h" // IWYU pragma: keep
 #include "keep2.h" /* IWYU pragma: keep */
+
+#include "export1.h" // IWYU pragma: export // line 5
+// IWYU pragma: begin_exports
+#include "export2.h" // Line 7
+#include "export3.h"
+// IWYU pragma: end_exports
+
+#include "normal.h" // Line 11
   )cpp";
-  Inputs.ExtraFiles["keep1.h"] = Inputs.ExtraFiles["keep2.h"] = "";
+  Inputs.ExtraFiles["keep1.h"] = Inputs.ExtraFiles["keep2.h"] =
+  Inputs.ExtraFiles["export1.h"] = Inputs.ExtraFiles["export2.h"] =
+  Inputs.ExtraFiles["export3.h"] = Inputs.ExtraFiles["normal.h"] = "";
 
   TestAST Processed = build();
   EXPECT_FALSE(PI.shouldKeep(1));
+  // Keep
   EXPECT_TRUE(PI.shouldKeep(2));
   EXPECT_TRUE(PI.shouldKeep(3));
+
+  // Exports
+  EXPECT_TRUE(PI.shouldKeep(5));
+  EXPECT_TRUE(PI.shouldKeep(7));
+  EXPECT_TRUE(PI.shouldKeep(8));
+
+  EXPECT_FALSE(PI.shouldKeep(11));
 }
 
 TEST_F(PragmaIncludeTest, IWYUPrivate) {
@@ -144,5 +169,69 @@
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
 }
 
+TEST_F(PragmaIncludeTest, IWYUExport) {
+  Inputs.Code = R"cpp(// Line 1
+#include "export1.h"
+#include "export2.h"
+  )cpp";
+  Inputs.ExtraFiles["export1.h"] = R"cpp(
+#include "private.h" // IWYU pragma: export
+  )cpp";
+  Inputs.ExtraFiles["export2.h"] = R"cpp(
+#include "export3.h"
+  )cpp";
+  Inputs.ExtraFiles["export3.h"] = R"cpp(
+#include "private.h" // IWYU pragma: export
+  )cpp";
+  Inputs.ExtraFiles["private.h"] = "";
+  TestAST Processed = build();
+  auto &FM = Processed.fileManager();
+
+  EXPECT_THAT(PI.getExporters(FM.getFile("private.h").get(), FM),
+  testing::UnorderedElementsAre(FileNamed("export1.h"),
+FileNamed("export3.h")));
+  EXPECT_TRUE(PI.getExporters(FM.getFile("export3.h").get(), FM).empty());
+}
+
+TEST_F(PragmaIncludeTest, IWYUExportBlock) {
+  Inputs.Code = R"cpp(// Line 1
+   #include "normal.h"
+  )cpp";
+  Inputs.ExtraFiles["normal.h"] = R"cpp(
+#include "foo.h"
+
+// IWYU pragma: begin_exports
+#include "export1.h"
+#include "private1.h"
+// IWYU pragma: end_exports
+  )cpp";
+  Inputs.ExtraFiles["export1.h"] = R"cpp(
+// IWYU pragma: begin_exports
+#include "private1.h"
+#include "private2.h"
+// IWYU pragma: end_exports
+
+#include "bar.h"
+#include "private3.h" // IWYU pragma: export
+  )cpp";
+
+  Inputs.ExtraFiles["private1.h"] = Inputs.ExtraFiles["private2.h"] =
+  Inputs.ExtraFiles["private3.h"] = "";
+  Inputs.ExtraFiles["foo.h"] = Inputs.ExtraFiles["bar.h"] = "";
+  TestAST Processed = build();
+  auto &FM = Processed.fileManager();
+
+  EXPECT_THAT(PI.getExporters(FM.getFile("private1.h").get(), FM),
+  testing::UnorderedElementsAre(FileNamed("export1.h"),
+FileNamed("normal.h")));
+  EXPECT_THAT(PI.getExporters(FM.getFile("private2.h").get(), FM),
+  testing::UnorderedElementsAre(FileNamed("export1.h")));
+  EXPECT_THAT(PI.getExporters(FM.getFile("private3.h").get(), FM),
+  testing::UnorderedElementsAre(FileNamed("export1.h")));
+
+  EXPECT_TRUE(PI.getExporters(FM.getFile("foo.h").get(), FM).empty());
+  EXPECT_TRUE(PI.getExporters(FM.getFile("bar.h").get(), FM).empty());
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -43,6 +43,12 @@
 InMainFile = SM.isWrittenInMainFile(Loc);
   }
 
+  void EndOfMainFile() override {
+const auto *MainFile = SM.getFileEntryForID(SM.getMainFile

[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-03 Thread Zhang Haoyu via Phabricator via cfe-commits
HaoyuZhang updated this revision to Diff 472877.
HaoyuZhang added a comment.

1. add the documentation for this driver.
2. fix a small grammer mistake in Options.td.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/pgo-sample-use-profi.c


Index: clang/test/Driver/pgo-sample-use-profi.c
===
--- /dev/null
+++ clang/test/Driver/pgo-sample-use-profi.c
@@ -0,0 +1,5 @@
+// Test if profi flat is enabled in frontend as user-facing feature.
+//
+// RUN: %clang -c -fsample-profile-use-profi 
-fprofile-sample-use=%S/../CodeGen/Inputs/pgo-sample.prof -### %s 2>&1 | 
FileCheck %s
+
+// CHECK: "-mllvm" "-sample-profile-use-profi"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5760,6 +5760,12 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
+  if (getLastProfileSampleUseArg(Args) &&
+  Args.hasArg(options::OPT_fsample_profile_use_profi)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-sample-profile-use-profi");
+  }
+
   // Add runtime flag for PS4/PS5 when PGO, coverage, or sanitizers are 
enabled.
   if (RawTriple.isPS() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1248,6 +1248,13 @@
as cold. Otherwise, treat callsites without profile samples as 
if
we have no profile}]>,
MarshallingInfoFlag>;
+def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
+Flags<[NoXarchOption, CC1Option]>, Group,
+HelpText<"Use profi to infer block and edge counts.">,
+DocBrief<[{Infer block and edge counts. If the profiles have errors or 
missing
+   blocks caused by sampling, profile inference (profi) can convert
+   basic block counts to branch probabilites to fix them by 
extended
+   and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,
   Group, Flags<[NoXarchOption]>;
 def fauto_profile : Flag<["-"], "fauto-profile">, Group,
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2241,6 +2241,15 @@
 
  $ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof code.cc 
-o code
 
+  [OPTIONAL] During the sampling, the profiles may have errors or missing
+  blocks. Profi (profile inference) algorithm can infer block and edge counts
+  to fix them. For applying this, you can use an additional flag
+  ``-fsample-profile-use-profi`` to the command line.
+
+  .. code-block:: console
+
+$ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof \
+  -fsample-profile-use-profi code.cc -o code
 
 Sample Profile Formats
 ""


Index: clang/test/Driver/pgo-sample-use-profi.c
===
--- /dev/null
+++ clang/test/Driver/pgo-sample-use-profi.c
@@ -0,0 +1,5 @@
+// Test if profi flat is enabled in frontend as user-facing feature.
+//
+// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=%S/../CodeGen/Inputs/pgo-sample.prof -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-mllvm" "-sample-profile-use-profi"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5760,6 +5760,12 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
+  if (getLastProfileSampleUseArg(Args) &&
+  Args.hasArg(options::OPT_fsample_profile_use_profi)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-sample-profile-use-profi");
+  }
+
   // Add runtime flag for PS4/PS5 when PGO, coverage, or sanitizers are enabled.
   if (RawTriple.isPS() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1248,6 +1248,13 @@
as cold. Otherwise, treat callsites without profile samples as if
we have no profile}]>,
MarshallingInfoFlag>;
+def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
+Flags<[NoXarchOption, CC1Option]>, Gro

[PATCH] D137320: [include-cleaner] Initial version for the "Location=>Header" step

2022-11-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: kadircet, sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

This patch implements the initial version of "Location => Header" step:

- define the interface;
- integrate into the existing workflow, and use the PragmaIncludes;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137320

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -7,11 +7,13 @@
 //===--===//
 
 #include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -26,41 +28,67 @@
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
-  llvm::Annotations HeaderCode(R"cpp(
-  void foo();
-  namespace std { class vector {}; })cpp");
+class WalkUsedTest : public ::testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap> walk(TestAST &AST) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls())
+  TopLevelDecls.emplace_back(D);
+auto &SM = AST.sourceManager();
+
+llvm::DenseMap> OffsetToProviders;
+walkUsed(
+TopLevelDecls, PI,
+[&](SourceLocation RefLoc, Symbol S, llvm::ArrayRef Providers) {
+  auto [FID, Offset] = SM.getDecomposedLoc(RefLoc);
+  EXPECT_EQ(FID, SM.getMainFileID());
+  OffsetToProviders.try_emplace(Offset, Providers.vec());
+});
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   void $bar^bar() {
 $foo^foo();
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
-  Inputs.ExtraFiles["header.h"] = HeaderCode.code().str();
+  Inputs.Code = Code.code();
+  Inputs.ExtraFiles["header.h"] = R"cpp(
+  void foo();
+  namespace std { class vector {}; }
+  )cpp";
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("header.h");
   TestAST AST(Inputs);
 
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
-  auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, [&](SourceLocation RefLoc, Symbol S,
-  llvm::ArrayRef Providers) {
-auto [FID, Offset] = SM.getDecomposedLoc(RefLoc);
-EXPECT_EQ(FID, SM.getMainFileID());
-OffsetToProviders.try_emplace(Offset, Providers.vec());
-  });
   auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
-  auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
+  auto MainFile = Header(AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  walk(AST),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
@@ -68,5 +96,56 @@
   Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL;
 }
 
+TEST_F(WalkUsedTest, IWYUPrivate) {
+  llvm::Annotations Code(R"cpp(
+  #include "private.h"
+  void $bar^bar($private^Private) {
+  }
+  )cpp");
+  Inputs.Code = Code.code();
+  Inputs.ExtraFiles["private.h"] = R"cpp(
+// IWYU pragma: private, include "path/public.h"
+class Private {};
+  )cpp";
+  TestAST AST(Inputs);
+
+  auto PublicH = Header("\"path/public.h\"")

[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-03 Thread Zhang Haoyu via Phabricator via cfe-commits
HaoyuZhang added a comment.

Hi @spupyrev , the using of profi algorithm is added as a user-facing flag in 
this patch. And I wrote the documentation in 
https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization. Do 
you have any comments about these?

Hi @MaskRay , some updates have been submitted. PTAL~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

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


[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-03 Thread Zhang Haoyu via Phabricator via cfe-commits
HaoyuZhang added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1254
+HelpText<"Use profi to infer block and edge counts.">,
+DocBrief<[{Profi - a flow-based profile inference algorithm is an extended
+   and significantly re-engineered classic MCMF (min-cost max-flow)

hans wrote:
> HaoyuZhang wrote:
> > hans wrote:
> > > I have to say, just reading this text I don't understand what it does.
> > > 
> > > I think a good description would start with "Infer block and edge counts 
> > > " and then some kind of summary of how it does that.
> > > 
> > > I assume profile info is still needed for this (that's the input, right?) 
> > > That should probably also be explained, and maybe we should warn when 
> > > using -fsample-profile-use-profi without -fprofile-sample-use?
> > > 
> > > 
> > > My main concern is that there's no documentation for this. How is a user 
> > > supposed to learn about this feature and how it works? Why can't someone 
> > > add something to 
> > > https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization 
> > > ? Once that is figured out, describing what the option does will probably 
> > > be easy.
> > Sorry for the unclear description of the DocBrief and I have do some 
> > modification. 
> > 
> > A checking has been added for ensuring that -fsample-profile-use-profi is 
> > only allowed with fprofile-sample-use. Otherwise, there will be an error.
> > 
> > About the document in above link, do you want me to add some contents about 
> > using profi after the patch or invite the author of profi?
> It would ideally be added in this patch. Inviting the author of profi (I 
> didn't realize it was a different person) sounds like a good idea.
Hi Hans, I have added the documentation about profi in this patch and also 
invited the author to take a look. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

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


[clang] fa8aeab - [AArch64] Add support for the Cortex-A715 CPU

2022-11-03 Thread Simi Pallipurath via cfe-commits

Author: Simi Pallipurath
Date: 2022-11-03T09:28:46Z
New Revision: fa8aeab606c1ca2756bf8b6a451998f20671ce52

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

LOG: [AArch64] Add support for the Cortex-A715 CPU

Cortex-A715 is an Armv9-A AArch64 CPU.

This patch introduces support for Cortex-A715.

Technical Reference Manual: 
https://developer.arm.com/documentation/101590/latest.

Reviewed By: vhscampos

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/Driver/aarch64-mcpu.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/lib/Support/Host.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 435d9ded7c72e..763f4cece4634 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -733,6 +733,9 @@ Arm and AArch64 Support in Clang
   them, which it cannot.
 - Add driver and tuning support for Neoverse V2 via the flag 
``-mcpu=neoverse-v2``.
   Native detection is also supported via ``-mcpu=native``.
+- Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
+
+  * Arm Cortex-A715 (cortex-a715).
 
 Floating Point Support in Clang
 ---

diff  --git a/clang/test/Driver/aarch64-mcpu.c 
b/clang/test/Driver/aarch64-mcpu.c
index 0433f6a5b3d3f..b40c579acdf00 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -45,6 +45,8 @@
 // CORTEXA78: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a78"
 // RUN: %clang -target aarch64 -mcpu=cortex-a78c  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A78C %s
 // CORTEX-A78C: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a78c"
+// RUN: %clang -target aarch64 -mcpu=cortex-a715  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A715 %s
+// CORTEX-A715: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a715"
 // RUN: %clang -target aarch64 -mcpu=neoverse-e1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-E1 %s
 // NEOVERSE-E1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-e1"
 // RUN: %clang -target aarch64 -mcpu=neoverse-v1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-V1 %s

diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index f2071c866956f..c0b542086a752 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, 
apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, 
kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, 
thunderxt83, tsv110, a64fx, carmel, ampere1, grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae,

[PATCH] D136957: [AArch64] Add support for the Cortex-A715 CPU

2022-11-03 Thread Simi Pallipurath 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 rGfa8aeab606c1: [AArch64] Add support for the Cortex-A715 CPU 
(authored by simpal01).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136957

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1016,6 +1016,19 @@
  AArch64::AEK_FLAGM | AArch64::AEK_SB |
  AArch64::AEK_I8MM | AArch64::AEK_BF16,
  "9-A"),
+ARMCPUTestParams("cortex-a715", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
+ AArch64::AEK_SB | AArch64::AEK_I8MM |
+ AArch64::AEK_PERFMON | AArch64::AEK_PREDRES |
+ AArch64::AEK_PROFILE | AArch64::AEK_FP16FML |
+ AArch64::AEK_FP16 | AArch64::AEK_FLAGM,
+ "9-A"),
 ARMCPUTestParams(
 "neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
 AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
@@ -1296,7 +1309,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 59;
+static constexpr unsigned NumAArch64CPUArchs = 60;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -64,6 +64,7 @@
 CortexA78,
 CortexA78C,
 CortexA710,
+CortexA715,
 CortexR82,
 CortexX1,
 CortexX1C,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -142,6 +142,7 @@
 MaxBytesForLoopAlignment = 8;
 break;
   case CortexA710:
+  case CortexA715:
   case CortexX2:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -764,6 +764,14 @@
FeatureLSLFast,
FeaturePostRAScheduler]>;
 
+def TuneA715 : SubtargetFeature<"a715", "ARMProcFamily", "CortexA715",
+ "Cortex-A715 ARM processors", [
+ FeatureFuseAES,
+ FeaturePostRAScheduler,
+ FeatureCmpBccFusion,
+ FeatureLSLFast,
+ FeatureFuseAdrpAdd]>;
+
 def TuneR82 : SubtargetFeature<"cortex-r82", "ARMProcFamily",
"CortexR82",
"Cortex-R82 ARM processors", [
@@ -1093,6 +1101,10 @@
   list A710 = [HasV9_0aOps, FeatureNEON, FeaturePerfMon,
  FeatureETE, FeatureMTE, FeatureFP16FML,
  FeatureSVE2BitPerm, FeatureBF16, FeatureMatMulInt8];
+  list A715 = [HasV9_0aOps, FeatureNEON, FeatureMTE,
+ FeatureFP16FML, FeatureSVE, FeatureTRBE,
+ FeatureSVE2BitPerm, FeatureBF16, FeatureETE,
+ FeaturePerfMon, FeatureMatMulInt8, FeatureSPE];
   list R82  = [HasV8_0rOps, FeaturePerfMon, FeatureFullFP16,
  FeatureFP16FML, FeatureSSBS, FeaturePredRes,
  FeatureSB];
@@ -1231,6 +1243,8 @@
  [TuneA78C]>;
 def : ProcessorModel<"cortex-a710", 

[PATCH] D137322: [clang][pdb] Don't include -fmessage-length in PDB buildinfo

2022-11-03 Thread Tobias Hieta via Phabricator via cfe-commits
thieta created this revision.
thieta added reviewers: aganea, rnk, thakis, aeubanks.
Herald added a subscriber: hiraditya.
Herald added a project: All.
thieta requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

As discussed in https://reviews.llvm.org/D136474 -fmessage-length
creates problems with reproduciability in the PDB files.

This patch just drops that argument when writing the PDB file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137322

Files:
  clang/test/CodeGen/debug-info-codeview-buildinfo.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -908,6 +908,9 @@
 }
 if (Arg.startswith("-object-file-name") || Arg == MainFilename)
   continue;
+// Skip fmessage-length for reproduciability
+if (Arg.startswith("-fmessage-length"))
+  continue;
 if (PrintedOneArg)
   OS << " ";
 llvm::sys::printArg(OS, Arg, /*Quote=*/true);
Index: clang/test/CodeGen/debug-info-codeview-buildinfo.c
===
--- clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -8,6 +8,10 @@
 // RUN: %clang_cl -gno-codeview-command-line --target=i686-windows-msvc /c /Z7 
/Fo%t.obj -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix DISABLE
 
+// -fmessage length shouldn't be included in the command line since it breaks 
reproducibility
+// RUN: %clang_cl -gcodeview-command-line --target=i686-windows-msvc -Xclang 
-fmessage-length=100 /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix 
MESSAGELEN
+
 int main(void) { return 42; }
 
 // CHECK:   Types (.debug$T)
@@ -36,3 +40,8 @@
 // DISABLE-NEXT:  0x{{.+}}: `{{.*}}`
 // DISABLE-NEXT:  0x{{.+}}: ``
 // DISABLE-NEXT:  : ``
+
+// MESSAGELEN:   Types (.debug$T)
+// MESSAGELEN: 
+// MESSAGELEN: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// MESSAGELEN-NOT:  0x{{.+}}: `"{{.+}}-fmessage-length=


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -908,6 +908,9 @@
 }
 if (Arg.startswith("-object-file-name") || Arg == MainFilename)
   continue;
+// Skip fmessage-length for reproduciability
+if (Arg.startswith("-fmessage-length"))
+  continue;
 if (PrintedOneArg)
   OS << " ";
 llvm::sys::printArg(OS, Arg, /*Quote=*/true);
Index: clang/test/CodeGen/debug-info-codeview-buildinfo.c
===
--- clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -8,6 +8,10 @@
 // RUN: %clang_cl -gno-codeview-command-line --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix DISABLE
 
+// -fmessage length shouldn't be included in the command line since it breaks reproducibility
+// RUN: %clang_cl -gcodeview-command-line --target=i686-windows-msvc -Xclang -fmessage-length=100 /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix MESSAGELEN
+
 int main(void) { return 42; }
 
 // CHECK:   Types (.debug$T)
@@ -36,3 +40,8 @@
 // DISABLE-NEXT:  0x{{.+}}: `{{.*}}`
 // DISABLE-NEXT:  0x{{.+}}: ``
 // DISABLE-NEXT:  : ``
+
+// MESSAGELEN:   Types (.debug$T)
+// MESSAGELEN: 
+// MESSAGELEN: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// MESSAGELEN-NOT:  0x{{.+}}: `"{{.+}}-fmessage-length=
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136474: [CodeView][clang] Add flag to disable emitting command line into CodeView

2022-11-03 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

I posted https://reviews.llvm.org/D137322 to remove `-fmessage-length`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-11-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

The current patch looks good from my side. There is a remaining discussion 
around the verbosity of unittests, but I think we should not be blocked by that.




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:57
+struct SymbolReference {
+  /// The locaiton in which the reference happened.
+  SourceLocation Loc;

nit: locaition => location.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:61
+  Symbol Target;
+  /// The reason the edge was formed.
+  RefType RT;

what's is the edge? I understand it in some degree, but I'd avoid introducing 
new concept  as it might lead to some confusions (and we haven't defined a 
graph anywhere in the code).



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:24
 
+#include "clang-include-cleaner/Analysis.h" // FIXME: Move RefType into a 
separate header.
 #include "clang/Basic/SourceLocation.h"

this is out-of-date, I think, the RefType is in Types.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

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


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

2022-11-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

FYI just another data point, I haven't taken a closer look yet, but with the 
resugaring patches applied on top of this, we start diagnosing some deprecated 
uses of `std::experimental::pmr::polymorphic_allocator` on current libc++ linux 
CI: 
https://buildkite.com/llvm-project/libcxx-ci/builds/14432#01843b26-a25a-4f74-b8d3-0d5e15676cfd


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D137320: [include-cleaner] Initial version for the "Location=>Header" step

2022-11-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:54
   Header(tooling::stdlib::Header H) : Storage(H) {}
+  Header(llvm::StringRef VerbatimSpelling) : Storage(VerbatimSpelling.str()) {}
 

can you add comments here describing what this case is used for



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:63
+// FIXME: use a real Class!
+using SymbolLocation = std::variant;
+

let's move this to `AnalysisInternal.h`, as it isn't used in any of the public 
apis.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:45
+  llvm::SmallVector Results;
+  if (SLoc.index() == 0) {
+// FIXME: Handle non self-contained files.

nit: `if (auto *Loc = std::get_if(&SLoc))`



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:55
+if (!VerbatimSpelling.empty())
+  return {{VerbatimSpelling}};
+

what about exporters here?



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:58
+Results = {{FE}};
+// FIXME: compute a closure of exporter headers.
+for (const auto *Export : PI.getExporters(FE, SM.getFileManager()))

not sure i follow the fixme here, are you suggesting we should also compute 
transitive exporters?



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:63
+  }
+  if (SLoc.index() == 1) {
+for (const auto &H : std::get(SLoc).headers())

nit: `if (auto *Sym = std::get(&SLoc))`



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:49
+// FIXME: expose signals
+llvm::SmallVector findIncludeHeaders(const SymbolLocation &Loc,
+ const SourceManager &SM,

this is fine for the initial version, but we'll likely lose a lot of 
performance here going forward. we can address it later on though, as this is 
an internal api and those performance concerns won't be a problem until this is 
used more widely. 

we're likely going to call this function multiple times for each symbol, and 
also despite having different sourcelocations, there'll probably be lots of 
declarations that're originating from the same FileID.
Hence we'll want to accumulate outputs on a single container, rather than 
returning a new container at each call, and also have some sort of file-id 
based cache.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:116
+
+  EXPECT_THAT(walk(AST),
+  UnorderedElementsAre(

can we use `findIncludeHeaders` directly?

that way we don't need to set up a referencing file, e.g. you can directly 
create a SourceLocation inside `private.h` (in this case even the decl is not 
important). 


(same for the export test)



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:135
+  )cpp";
+  Inputs.ExtraFiles["private.h"] = R"cpp(class Private {};)cpp";
+  TestAST AST(Inputs);

calling this private is somewhat confusing, maybe call it `Detail`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137320

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


[PATCH] D137200: [clang] Template Specialization Resugaring - Expressions

2022-11-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 472886.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137200

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp
  clang/test/AST/float16.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Index/print-type.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Sema/Resugar/resugar-expr.cpp
  clang/test/SemaTemplate/attributes.cpp
  clang/unittests/Tooling/StencilTest.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D127695
+D137200
Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -555,8 +555,9 @@
 }
 
 TEST_F(StencilTest, DescribeAnonNamespaceType) {
+  // FIXME: We need to implement a __builtin_canonicalize_type for this ;-)
   std::string Snippet = "auto c = desugar(); c;";
-  std::string Expected = "(anonymous namespace)::AnonC";
+  std::string Expected = "AnonC";
   auto StmtMatch =
   matchStmt(Snippet, declRefExpr(hasType(qualType().bind("type";
   ASSERT_TRUE(StmtMatch);
Index: clang/test/SemaTemplate/attributes.cpp
===
--- clang/test/SemaTemplate/attributes.cpp
+++ clang/test/SemaTemplate/attributes.cpp
@@ -616,7 +616,8 @@
   };
   template T desugar(T);
   auto it = desugar(MemberTemplate::Iter());
-  int n = it; // expected-error {{no viable conversion from 'preferred_name::MemberTemplate::const_iterator' to 'int'}}
+  // FIXME: We need to implement a __builtin_canonicalize_type for this ;-)
+  int n = it; // expected-error {{no viable conversion from 'MemberTemplate::Iter' to 'int'}}
 
   template struct Foo;
   template using Bar = Foo<1, 2, T...>;
Index: clang/test/Sema/Resugar/resugar-expr.cpp
===
--- /dev/null
+++ clang/test/Sema/Resugar/resugar-expr.cpp
@@ -0,0 +1,224 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s
+
+enum class Z;
+
+struct bar {};
+
+using Int = int;
+using Float = float;
+using Bar = bar;
+
+namespace t1 {
+template  struct A {
+  static constexpr A1 a = {};
+};
+
+Z x1 = A::a;
+// expected-error@-1 {{with an lvalue of type 'const Int' (aka 'const int')}}
+} // namespace t1
+
+namespace t2 {
+template  struct A {
+  static constexpr A1 A2::*a = {};
+};
+
+Z x1 = A::a;
+// expected-error@-1 {{with an lvalue of type 'Int Bar::*const'}}
+} // namespace t2
+
+namespace t3 {
+template  struct A {
+  template  struct B {
+static constexpr A1 B1::*a = {};
+  };
+};
+
+Z x1 = A::B::a;
+// expected-error@-1 {{with an lvalue of type 'Float Bar::*const'}}
+} // namespace t3
+
+namespace t4 {
+template  A1 (*a) ();
+
+Z x1 = decltype(a){}();
+// expected-error@-1 {{with an rvalue of type 'Int' (aka 'int')}}
+} // namespace t4
+
+namespace t5 {
+template  struct A {
+  A1(*a)
+  ();
+};
+
+Z x1 = decltype(A().a){}();
+// expected-error@-1 {{with an rvalue of type 'Int' (aka 'int')}}
+} // namespace t5
+
+namespace t6 {
+template  struct A { A2 A1::*f(); };
+
+using M = int;
+using N = int;
+
+struct B {};
+using X = B;
+using Y = B;
+
+auto a = &A::f;
+Z x1 = a;
+// expected-error@-1 {{with an lvalue of type 'M X::*(A::*)()'}}
+
+A b;
+Z x2 = (b.*a)();
+// expected-error@-1 {{with an rvalue of type 'M X::*'}}
+
+Z x3 = decltype((b.*a)()){};
+// expected-error@-1 {{with an rvalue of type 'decltype((b .* a)())' (aka 'M X::*')}}
+} // namespace t6
+
+namespace t7 {
+template  struct A { A1 a; };
+auto [a] = A{};
+
+Z x1 = a;
+// expected-error@-1 {{with an lvalue of type 'Int' (aka 'int')}}
+} // namespace t7
+
+namespace t8 {
+template  struct A {
+  template  static constexpr B1 (*b)(A1) = nullptr;
+};
+
+Z x1 = A::b;
+// expected-error@-1 {{with an lvalue of type 'Int (*const)(Float)' (aka 'int (*const)(float)')}}
+} // namespace t8
+
+namespace t9 {
+template  struct A {
+  template  static constexpr auto b = (B1(*)(A1)){};
+};
+
+Z x1 = A::b;
+// expected-error@-1 {{with an lvalue of type 'I

[PATCH] D137153: [WIP][X86] Support -march=sierraforest, grandridge, graniterapids.

2022-11-03 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:1528
+ProcessorFeatures.TRMTuning>;
+def : ProcModel<"grandridge", SLMModel, ProcessorFeatures.GRRFeatures,
+ProcessorFeatures.TRMTuning>;

SLMModel explicitly doesn't have support for AVX/AVX2 - I think you should 
investigate forking SLMModel and creating a AlderlakeEModel for all of these

Also, should these be here or moved up below tremont and the other atom cores?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137153

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


[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits

2022-11-03 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson abandoned this revision.
royjacobson added a comment.

Closing in favor of the much more mature D137302 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135404

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


[PATCH] D137082: [clang][Interp] Fix dereferencing arrays with no offset applied

2022-11-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 472887.

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

https://reviews.llvm.org/D137082

Files:
  clang/lib/AST/Interp/Pointer.h
  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
@@ -42,6 +42,21 @@
   return *(Arr + index);
 }
 
+constexpr int derefPtr(const int *d) {
+  return *d;
+}
+static_assert(derefPtr(data) == 5, "");
+
+constexpr int storePtr() {
+  int b[] = {1,2,3,4};
+  int *c = b;
+
+  *c = 4;
+  return *c;
+}
+static_assert(storePtr() == 4, "");
+
+
 static_assert(getElement(data, 1) == 4, "");
 static_assert(getElement(data, 4) == 1, "");
 
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -225,6 +225,12 @@
 return Offset - Base - Adjust;
   }
 
+  /// Whether this array refers to an array, but not
+  /// to the first element.
+  bool isArrayRoot() const {
+return inArray() && Offset == Base;
+  }
+
   /// Checks if the innermost field is an array.
   bool inArray() const { return getFieldDesc()->IsArray; }
   /// Checks if the structure is a primitive array.
@@ -306,6 +312,9 @@
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
 assert(isLive() && "Invalid pointer");
+if (isArrayRoot())
+  return *reinterpret_cast(Pointee->rawData() + Base + 
sizeof(InitMap*));
+
 return *reinterpret_cast(Pointee->rawData() + Offset);
   }
 


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -42,6 +42,21 @@
   return *(Arr + index);
 }
 
+constexpr int derefPtr(const int *d) {
+  return *d;
+}
+static_assert(derefPtr(data) == 5, "");
+
+constexpr int storePtr() {
+  int b[] = {1,2,3,4};
+  int *c = b;
+
+  *c = 4;
+  return *c;
+}
+static_assert(storePtr() == 4, "");
+
+
 static_assert(getElement(data, 1) == 4, "");
 static_assert(getElement(data, 4) == 1, "");
 
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -225,6 +225,12 @@
 return Offset - Base - Adjust;
   }
 
+  /// Whether this array refers to an array, but not
+  /// to the first element.
+  bool isArrayRoot() const {
+return inArray() && Offset == Base;
+  }
+
   /// Checks if the innermost field is an array.
   bool inArray() const { return getFieldDesc()->IsArray; }
   /// Checks if the structure is a primitive array.
@@ -306,6 +312,9 @@
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
 assert(isLive() && "Invalid pointer");
+if (isArrayRoot())
+  return *reinterpret_cast(Pointee->rawData() + Base + sizeof(InitMap*));
+
 return *reinterpret_cast(Pointee->rawData() + Offset);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0fb763e - [flang] Add -f[no-]honor-infinities and -menable-no-infs

2022-11-03 Thread Tom Eccles via cfe-commits

Author: Tom Eccles
Date: 2022-11-03T10:38:09Z
New Revision: 0fb763e7d0a4b8c9f5978675e7556ae50716d695

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

LOG: [flang] Add -f[no-]honor-infinities and -menable-no-infs

Only add the option processing and store the result. No attributes are
added to FIR yet.

This patch follows Clang in forwarding -fno-honor-infinities as
-menable-no-infs.

Reviewed By: kiranchandramohan awarzynski vzakhari

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/LangOptions.def
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help.f90
flang/test/Driver/flang_fp_opts.f90
flang/test/Driver/frontend-forwarding.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3e15c55ed52ea..65cd6e85da4e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5444,9 +5444,6 @@ def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
   HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
   NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
   MarshallingInfoEnum, "None">;
-def menable_no_infinities : Flag<["-"], "menable-no-infs">,
-  HelpText<"Allow optimization to assume there are no infinities.">,
-  MarshallingInfoFlag>, 
ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
 def menable_no_nans : Flag<["-"], "menable-no-nans">,
   HelpText<"Allow optimization to assume there are no NaNs.">,
   MarshallingInfoFlag>, 
ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
@@ -6060,6 +6057,10 @@ def split_dwarf_output : Separate<["-"], 
"split-dwarf-output">,
 
 let Flags = [CC1Option, FC1Option, NoDriverOption] in {
 
+def menable_no_infinities : Flag<["-"], "menable-no-infs">,
+  HelpText<"Allow optimization to assume there are no infinities.">,
+  MarshallingInfoFlag>, 
ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
+
 def pic_level : Separate<["-"], "pic-level">,
   HelpText<"Value for __PIC__">,
   MarshallingInfoInt>;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6c6895da61299..14547b6f409aa 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -83,6 +83,7 @@ void Flang::AddPicOptions(const ArgList &Args, ArgStringList 
&CmdArgs) const {
 static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
 ArgStringList &CmdArgs) {
   StringRef FPContract;
+  bool HonorINFs = true;
 
   if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
 const StringRef Val = A->getValue();
@@ -101,8 +102,30 @@ static void addFloatingPointOptions(const Driver &D, const 
ArgList &Args,
   << A->getOption().getName() << Val;
   }
 
+  for (const Arg *A : Args) {
+auto optId = A->getOption().getID();
+switch (optId) {
+// if this isn't an FP option, skip the claim below
+default:
+  continue;
+
+case options::OPT_fhonor_infinities:
+  HonorINFs = true;
+  break;
+case options::OPT_fno_honor_infinities:
+  HonorINFs = false;
+  break;
+}
+
+// If we handled this option claim it
+A->claim();
+  }
+
   if (!FPContract.empty())
 CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract));
+
+  if (!HonorINFs)
+CmdArgs.push_back("-menable-no-infs");
 }
 
 void Flang::ConstructJob(Compilation &C, const JobAction &JA,

diff  --git a/flang/include/flang/Frontend/LangOptions.def 
b/flang/include/flang/Frontend/LangOptions.def
index c4d0ec5329b2e..96e9ea63f1964 100644
--- a/flang/include/flang/Frontend/LangOptions.def
+++ b/flang/include/flang/Frontend/LangOptions.def
@@ -21,5 +21,8 @@ LANGOPT(Name, Bits, Default)
 
 ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Off) ///< FP Contract Mode 
(off/fast)
 
+/// Permit floating point optimization without regard to infinities
+LANGOPT(NoHonorInfs, 1, false)
+
 #undef LANGOPT
 #undef ENUM_LANGOPT

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 3a64086be33d3..10c73169d0d02 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -691,6 +691,12 @@ static bool parseFloatingPointArgs(CompilerInvocation 
&invoc,
 opts.setFPContractMode(fpContractMode);
   }
 
+  if (const llvm::opt::Arg *a =
+  args.getLastArg(clang::driver::options::OPT_menable_no_infinities)) {
+diags.Report(diagUnimplemented) << a->getOption().getName();
+opts.NoHonorInfs = true;
+

[PATCH] D137072: [flang] Add -f[no-]honor-infinities and -menable-no-infs

2022-11-03 Thread Tom Eccles via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0fb763e7d0a4: [flang] Add -f[no-]honor-infinities and 
-menable-no-infs (authored by tblah).
Herald added projects: clang, Flang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137072

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/flang_fp_opts.f90
  flang/test/Driver/frontend-forwarding.f90

Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -9,6 +9,7 @@
 ! RUN: -flarge-sizes \
 ! RUN: -fconvert=little-endian \
 ! RUN: -ffp-contract=fast \
+! RUN: -fno-honor-infinities \
 ! RUN: -mllvm -print-before-all\
 ! RUN: -P \
 ! RUN:   | FileCheck %s
@@ -20,5 +21,6 @@
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
 ! CHECK: "-ffp-contract=fast"
+! CHECK: "-menable-no-infs"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK:  "-mllvm" "-print-before-all"
Index: flang/test/Driver/flang_fp_opts.f90
===
--- flang/test/Driver/flang_fp_opts.f90
+++ flang/test/Driver/flang_fp_opts.f90
@@ -1,4 +1,5 @@
 ! Test for handling of floating point options within the frontend driver
 
-! RUN: %flang_fc1 -ffp-contract=fast %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -ffp-contract=fast -menable-no-infs %s 2>&1 | FileCheck %s
 ! CHECK: ffp-contract= is not currently implemented
+! CHECK: menable-no-infs is not currently implemented
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -130,6 +130,7 @@
 ! HELP-FC1-NEXT: -init-only Only execute frontend initialization
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
+! HELP-FC1-NEXT: -menable-no-infs   Allow optimization to assume there are no infinities.
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
 ! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -691,6 +691,12 @@
 opts.setFPContractMode(fpContractMode);
   }
 
+  if (const llvm::opt::Arg *a =
+  args.getLastArg(clang::driver::options::OPT_menable_no_infinities)) {
+diags.Report(diagUnimplemented) << a->getOption().getName();
+opts.NoHonorInfs = true;
+  }
+
   return true;
 }
 
Index: flang/include/flang/Frontend/LangOptions.def
===
--- flang/include/flang/Frontend/LangOptions.def
+++ flang/include/flang/Frontend/LangOptions.def
@@ -21,5 +21,8 @@
 
 ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Off) ///< FP Contract Mode (off/fast)
 
+/// Permit floating point optimization without regard to infinities
+LANGOPT(NoHonorInfs, 1, false)
+
 #undef LANGOPT
 #undef ENUM_LANGOPT
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -83,6 +83,7 @@
 static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
 ArgStringList &CmdArgs) {
   StringRef FPContract;
+  bool HonorINFs = true;
 
   if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
 const StringRef Val = A->getValue();
@@ -101,8 +102,30 @@
   << A->getOption().getName() << Val;
   }
 
+  for (const Arg *A : Args) {
+auto optId = A->getOption().getID();
+switch (optId) {
+// if this isn't an FP option, skip the claim below
+default:
+  continue;
+
+case options::OPT_fhonor_infinities:
+  HonorINFs = true;
+  break;
+case options::OPT_fno_honor_infinities:
+  HonorINFs = false;
+  break;
+}
+
+// If we handled this option claim it
+A->claim();
+  }
+
   if (!FPContract.empty())
 CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract));
+
+  if (!HonorINFs)
+CmdArgs.push_back("-menable-no-infs");
 }
 
 void Flang::ConstructJob(Compilation &C, const JobAction &JA,
Index: clang/include/clang/Driver/Options.td
===

[PATCH] D137313: [NFC] Remove redundant loads when has_device_addr is used.

2022-11-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Whyt it is NFC? I assume it fixes the dereferencing of references, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137313

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


[PATCH] D137154: Adding nvvm_reflect clang builtin

2022-11-03 Thread Hugh Delaney via Phabricator via cfe-commits
hdelan marked an inline comment as not done.
hdelan added a comment.

In DPC++ for CUDA we use libclc as a wrapper around CUDA SDK's libdevice. Like 
libdevice we want to precompile libclc to bc for the CUDA backend without 
specializing for a particular arch, so that we can call different __nv funcs 
based on the arch. For this reason we use the `__nvvm_reflect` llvm intrinsic.

Without a clang builtin a number of workarounds are necessary to get the 
desired behaviour from `__nvvm_reflect`.

1. We must declare `__nvvm_reflect` in source code everywhere where it is used.
2. Some addrspace casting is necessary in openCL, since strings are in 
the__constant address space. We must use an IR wrapper function to ensure the 
correct behaviour. See 
https://github.com/intel/llvm/blob/sycl/libclc/ptx-nvidiacl/libspirv/reflect.ll

We agree that `__nvvm_reflect` is not a perfect solution, but it is something 
we must use because of libdevice. Adding the clang builtin would enable us to 
write libdevice-like libraries without having to resort to the methods 
mentioned above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137154

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


[PATCH] D137319: [include-cleaner] Add export IWYU pragma support.

2022-11-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:82
+  llvm::DenseMap>
+  IWYUExportBy;

what about a smallvector, instead of a denseset here?



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:82
+  llvm::DenseMap>
+  IWYUExportBy;

kadircet wrote:
> what about a smallvector, instead of a denseset here?
nit: instead of `UniqueID`s, you can directly store `StringRef`s in the values, 
if you use an Arena/StringSaver for storing full paths. that should save you 
from doing one extra lookup at query time.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:86
+  /// parsing.
+  llvm::DenseMap
+  RealPathNamesByUID;

i think it's important to mention why we're storing a string to the full path 
here:
`There's no way to get a path for a UniqueID, especially when it hasn't been 
opened before. So store the full path and convert it to a FileEntry by opening 
the file again through a FileManager.`



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:64
+if (!ExportStack.empty() &&
+ExportStack.back().Exporter == SM.getFileID(HashLoc)) {
+  auto Top = ExportStack.back();

this has the nasty downside of:
```
// IWYU pragma: export
void foo();
#include "bar.h"
```

now bar.h will be considered exported :/ i think we have to store the 
line-number for the pragma as well and compare it (we can store `0` for block 
comments).



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:69
+  // main-file #include with export pragma should never be removed.
+  if (Top.Exporter == SM.getMainFileID())
+Out->ShouldKeep.insert(

well, i've just noticed we're not actually doing anything specific to the 
include here (or for the `keep` equivalent) as we're just storing the line 
number we've seen the comment on.
so what about moving this logic (and the pragma keep one) into the 
`HandleComment` callback instead?



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:110
+  if (!ExportStack.empty()) {
+assert(ExportStack.back().Block);
+ExportStack.pop_back();

can you also assert that Stack top and current Range are from the same file id?



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:144
   int LastPragmaKeepInMainFileLine = -1;
+  struct State {
+// The file where we saw the export pragma.

maybe call this `ExportPragma` instead of `State`?



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:146
+// The file where we saw the export pragma.
+FileID Exporter;
+// true if it is a block begin/end_exports pragma; false if it is a

what about just `Location` or `SeenAt`?



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:179
+  auto FE = FM.getFileRef(RealExport->getSecond());
+  assert(FE);
+  Results.push_back(FE.get());

i think this is also a harsh assert. the file might get deleted from disk 
between indexing (e.g. clangd's preamble build) and query (e.g. clangd's AST 
built). so maybe log this occurrence instead and continue?



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:136
   )cpp";
-  Inputs.ExtraFiles["keep1.h"] = Inputs.ExtraFiles["keep2.h"] = "";
+  Inputs.ExtraFiles["keep1.h"] = Inputs.ExtraFiles["keep2.h"] =
+  Inputs.ExtraFiles["export1.h"] = Inputs.ExtraFiles["export2.h"] =

nit: indentation looks weird, maybe:
```
for(llvm::StringRef File : {"keep1.h", ...}) {
  Inputs.ExtraFiles[File] = "";
}
```



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:146
+
+  // Exports
+  EXPECT_TRUE(PI.shouldKeep(5));

i think we should also EXPECT_TRUE for line 6 and 9.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:193
+FileNamed("export3.h")));
+  EXPECT_TRUE(PI.getExporters(FM.getFile("export3.h").get(), FM).empty());
+}

can you also assert that for export1, export2 and mainfile?



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:218-220
+  Inputs.ExtraFiles["private1.h"] = Inputs.ExtraFiles["private2.h"] =
+  Inputs.ExtraFiles["private3.h"] = "";
+  Inputs.ExtraFiles["foo.h"] = Inputs.ExtraFiles["bar.h"] = "";

nit: same indentation comment as above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137319

___
cfe-commits mailing list
cfe-commi

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

2022-11-03 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D137024#3901342 , @mgorny wrote:

> Thanks! Let's hope it works this time.

FYI, this broke builds of mine 
(https://github.com/mstorsjo/llvm-mingw/actions/runs/3382275510/jobs/5617040099),
 but I just need to change/add a workaround so I don't think we need to revert 
it due to that.

My setup is that I'm building LLVM with `-DLLVM_INSTALL_TOOLCHAIN_ONLY=TRUE`, 
so it only installs toolchain binaries, but not files like LLVMConfig.cmake or 
the individual LLVM libraries. I then use this new toolchain to (cross-)build 
compiler-rt (and all other runtimes), to bootstrap new cross-sysroots.

Previously, the compiler-rt cmake files would pick up a distro-installed 
`llvm-config` and due to that, add systemwide install directories into the mix 
when building compiler-rt (for a potential cross target!). I worked around that 
by passing `-DLLVM_CONFIG_PATH=""` to make sure that it doesn't pick up an 
unrelated `llvm-config` binary. 
(https://github.com/mstorsjo/llvm-mingw/commit/3b96433cdf89e8ef444c6669254b386229dbddd9)
 Now after this change, it can again find unrelated `LLVMConfig.cmake` from the 
surrounding distribution, which ends up adding unexpected include directories. 
This time I'm working around it with 
https://github.com/mstorsjo/llvm-mingw/commit/486dcf32274ae6c3e0ea7916fd1e88a58742b7ca,
 by adding `-DCMAKE_FIND_ROOT_PATH=$PREFIX/$arch-w64-mingw32 
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY`, so that cmake won't find unrelated 
cmake files.

These workarounds are fine for me, but I wonder if it would be useful with a 
more direct cmake option to tell it not look for these files at all. I'm 
building out of the git monorepo checkout, so whatever source files and cmake 
scripts can be found there, but other LLVM build products (individual libraries 
etc) aren't available, and cmake shouldn't try to venture out on its own to 
find them in unexpected places.

@phosek - How does this work for general cross compilation of compiler-rt btw - 
when building compiler-rt for a cross target, but it finds `LLVMConfig.cmake` 
for the current host, and ends up including headers (and possibly more) from 
there? (If the include directory added from `LLVMConfig.cmake` is something 
like `/usr/include/llvm-15` it's probably benign, but in the msys2 cases, the 
llvm headers are installed in the toplevel include directory, so it ended up 
adding the equivalent of `-I/usr/include` in something which is supposed to be 
a cross build.) I can manually mitigate this with the `-DCMAKE_FIND_ROOT_PATH*` 
options in my case, but I don't see e.g. `llvm-project/llvm/runtimes` doing 
this anywhere?


Repository:
  rG LLVM Github Monorepo

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] D137327: [clang-format] Handle object instansiation in if-statements

2022-11-03 Thread Tobias Hieta via Phabricator via cfe-commits
thieta created this revision.
thieta added reviewers: MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
thieta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before this patch code like this:

  if (Class* obj{getObject()}) { }

would be mis-formated since the * would be annotated as a
binaryoperator.

This patch changes the * to become a PointerOrReference instead
and fixes the formatting issues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137327

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1035,6 +1035,12 @@
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandIfInitializer) {
+  auto Tokens = annotate("if (Class* obj {getObj()}) ");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -362,7 +362,8 @@
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
+  CurrentToken->is(tok::identifier) &&
+  !Next->isOneOf(tok::equal, tok::l_brace)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
   }
@@ -2385,6 +2386,12 @@
   return TT_PointerOrReference;
 }
 
+// if (Class* obj { function() })
+if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
+NextToken->Next && NextToken->Next->is(tok::l_brace)) {
+  return TT_PointerOrReference;
+}
+
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1035,6 +1035,12 @@
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandIfInitializer) {
+  auto Tokens = annotate("if (Class* obj {getObj()}) ");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -362,7 +362,8 @@
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
+  CurrentToken->is(tok::identifier) &&
+  !Next->isOneOf(tok::equal, tok::l_brace)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
   }
@@ -2385,6 +2386,12 @@
   return TT_PointerOrReference;
 }
 
+// if (Class* obj { function() })
+if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
+NextToken->Next && NextToken->Next->is(tok::l_brace)) {
+  return TT_PointerOrReference;
+}
+
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137223: [clang-format] Remove special case for kw_operator when aligning decls

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

What Owen says.
Apart from that looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137223

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


[PATCH] D135740: [clang-format] Fix multiple preprocessor if sections parsing incorrectly

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

I'm lost at this topic. Is this change still needed? Is it superseded by or 
additional to D137052 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135740

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


[PATCH] D136919: [X86][RFC] Change mangle name of __bf16 from u6__bf16 to DF16b

2022-11-03 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

What are the rules on this? Do we just handle this as an ABI breaking change 
and document it in the release notes - or do we need to provide any 
auto-upgrade path (with a warning?)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136919

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


[PATCH] D96007: [AArch64] Enable stack clash protection for AArch64 linux in clang

2022-11-03 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added inline comments.
Herald added a subscriber: MaskRay.
Herald added a project: All.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:1669-1672
+if (CodeGenOpts.StackProbeSize != 4096)
+  B.addAttribute("stack-probe-size",
+ llvm::utostr(CodeGenOpts.StackProbeSize));
+  }

Would it be worth always setting the `stack-probe-size` attribute so that it is 
always correct and to avoid the risk of it going out-of-sync in case of changes 
to the assumed size in the backend?


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

https://reviews.llvm.org/D96007

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


[PATCH] D136796: [llvm-objdump][Offload] Use common offload extraction method

2022-11-03 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D136796#3904512 , @jhenderson 
wrote:

> In D136796#3903393 , @jhuber6 wrote:
>
>> Is this good to land now?
>
> The LLVM community practice is to wait a week between pings unless there's 
> something urgent (and if something is urgent, please say so).
>
> Aside from the clang bit of the patch, this seems good to me, but it would be 
> worth another person involved with offloading to give the final thumbs up.

I could precommit that part if it would make it cleaner, but since this patch 
changes the extract routine to handle relocatable objects we need to filter 
those out of the input since the linker wrapper can't handle them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136796

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


[clang] cdbe296 - [clang-format] Fix lambda formatting in conditional

2022-11-03 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2022-11-03T13:08:14+01:00
New Revision: cdbe296853b1b3fc6415236f05770360e23f0d39

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

LOG: [clang-format] Fix lambda formatting in conditional

Without the patch UnwrappedLineFormatter::analyzeSolutionSpace just ran
out of possible formattings and would put everything just on one line.
The problem was that the the line break was forbidden, but putting the
conditional colon on the same line is also forbidden.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index f1b5d184963ce..3fa3e6bcbb569 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -331,6 +331,15 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
   if (Previous.is(tok::l_square) && Previous.is(TT_ObjCMethodExpr))
 return false;
 
+  if (Current.is(TT_ConditionalExpr) && Previous.is(tok::r_paren) &&
+  Previous.MatchingParen && Previous.MatchingParen->Previous &&
+  Previous.MatchingParen->Previous->MatchingParen &&
+  Previous.MatchingParen->Previous->MatchingParen->is(TT_LambdaLBrace)) {
+// We have a lambda within a conditional expression, allow breaking here.
+assert(Previous.MatchingParen->Previous->is(tok::r_brace));
+return true;
+  }
+
   return !CurrentState.NoLineBreak;
 }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 82e91b3222715..acf172ea98d9d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25549,6 +25549,54 @@ TEST_F(FormatTest, ShortTemplatedArgumentLists) {
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, MultilineLambdaInConditional) {
+  auto Style = getLLVMStyleWithColumns(70);
+  verifyFormat("auto aLengthyIdentifier = oneExpressionSoThatWeBreak ? []() 
{\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   " : 2;",
+   Style);
+  verifyFormat(
+  "auto aLengthyIdentifier = oneExpressionSoThatWeBreak ? 2 : []() {\n"
+  "  ;\n"
+  "  return 5;\n"
+  "}();",
+  Style);
+
+  Style = getLLVMStyleWithColumns(60);
+  verifyFormat("auto aLengthyIdentifier = oneExpressionSoThatWeBreak\n"
+   "  ? []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   "  : 2;",
+   Style);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak ? 2 : []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}();",
+   Style);
+
+  Style = getLLVMStyleWithColumns(40);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak ? []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   "   : 2;",
+   Style);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak\n"
+   "? 2\n"
+   ": []() {\n"
+   ";\n"
+   "return 5;\n"
+   "  };",
+   Style);
+}
+
 TEST_F(FormatTest, AlignAfterOpenBracketBlockIndent) {
   auto Style = getLLVMStyle();
 



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


[PATCH] D135918: [clang-format] Fix lambda formatting in conditional

2022-11-03 Thread Björn Schäpers 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 rGcdbe296853b1: [clang-format] Fix lambda formatting in 
conditional (authored by HazardyKnusperkeks).

Changed prior to commit:
  https://reviews.llvm.org/D135918?vs=470914&id=472903#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135918

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25549,6 +25549,54 @@
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, MultilineLambdaInConditional) {
+  auto Style = getLLVMStyleWithColumns(70);
+  verifyFormat("auto aLengthyIdentifier = oneExpressionSoThatWeBreak ? []() 
{\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   " : 2;",
+   Style);
+  verifyFormat(
+  "auto aLengthyIdentifier = oneExpressionSoThatWeBreak ? 2 : []() {\n"
+  "  ;\n"
+  "  return 5;\n"
+  "}();",
+  Style);
+
+  Style = getLLVMStyleWithColumns(60);
+  verifyFormat("auto aLengthyIdentifier = oneExpressionSoThatWeBreak\n"
+   "  ? []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   "  : 2;",
+   Style);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak ? 2 : []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}();",
+   Style);
+
+  Style = getLLVMStyleWithColumns(40);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak ? []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   "   : 2;",
+   Style);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak\n"
+   "? 2\n"
+   ": []() {\n"
+   ";\n"
+   "return 5;\n"
+   "  };",
+   Style);
+}
+
 TEST_F(FormatTest, AlignAfterOpenBracketBlockIndent) {
   auto Style = getLLVMStyle();
 
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -331,6 +331,15 @@
   if (Previous.is(tok::l_square) && Previous.is(TT_ObjCMethodExpr))
 return false;
 
+  if (Current.is(TT_ConditionalExpr) && Previous.is(tok::r_paren) &&
+  Previous.MatchingParen && Previous.MatchingParen->Previous &&
+  Previous.MatchingParen->Previous->MatchingParen &&
+  Previous.MatchingParen->Previous->MatchingParen->is(TT_LambdaLBrace)) {
+// We have a lambda within a conditional expression, allow breaking here.
+assert(Previous.MatchingParen->Previous->is(tok::r_brace));
+return true;
+  }
+
   return !CurrentState.NoLineBreak;
 }
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25549,6 +25549,54 @@
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, MultilineLambdaInConditional) {
+  auto Style = getLLVMStyleWithColumns(70);
+  verifyFormat("auto aLengthyIdentifier = oneExpressionSoThatWeBreak ? []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   " : 2;",
+   Style);
+  verifyFormat(
+  "auto aLengthyIdentifier = oneExpressionSoThatWeBreak ? 2 : []() {\n"
+  "  ;\n"
+  "  return 5;\n"
+  "}();",
+  Style);
+
+  Style = getLLVMStyleWithColumns(60);
+  verifyFormat("auto aLengthyIdentifier = oneExpressionSoThatWeBreak\n"
+   "  ? []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}()\n"
+   "  : 2;",
+   Style);
+  verifyFormat("auto aLengthyIdentifier =\n"
+   "oneExpressionSoThatWeBreak ? 2 : []() {\n"
+   "  ;\n"
+   "  return 5;\n"
+   "}();",
+   Style)

[clang] f97639c - [clang-format] Don't misannotate in CTor init list

2022-11-03 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2022-11-03T13:08:48+01:00
New Revision: f97639ce13754e78e26f8d7f564830ddfe4f727c

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

LOG: [clang-format] Don't misannotate in CTor init list

They were annotated with TrailingAnnotation, which they are not. And
that resulted in some quirky formatting in some cases.

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 4901c5ce7106..3d76cc171b0d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1989,7 +1989,9 @@ class AnnotatingParser {
 } else if (Current.isOneOf(tok::identifier, tok::kw_const, 
tok::kw_noexcept,
tok::kw_requires) &&
Current.Previous &&
-   !Current.Previous->isOneOf(tok::equal, tok::at) &&
+   !Current.Previous->isOneOf(tok::equal, tok::at,
+  TT_CtorInitializerComma,
+  TT_CtorInitializerColon) &&
Line.MightBeFunctionDecl && Contexts.size() == 1) {
   // Line.MightBeFunctionDecl can only be true after the parentheses of a
   // function declaration have been found.

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index b4e27d35bc36..fa95f6845f07 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1124,6 +1124,35 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
+  auto Tokens = annotate("Class::Class() : BaseClass(), Member() {}");
+
+  // The TT_Unknown is clearly not binding for the future, please adapt if 
those
+  // tokens get annotated.
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[9], tok::comma, TT_CtorInitializerComma);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Class::Class() : BaseClass{}, Member{} {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::r_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[9], tok::comma, TT_CtorInitializerComma);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang



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


[PATCH] D136635: [clang-format] Don't misannotate in CTor init list

2022-11-03 Thread Björn Schäpers 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 rGf97639ce1375: [clang-format] Don't misannotate in CTor 
init list (authored by HazardyKnusperkeks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136635

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1124,6 +1124,35 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
+  auto Tokens = annotate("Class::Class() : BaseClass(), Member() {}");
+
+  // The TT_Unknown is clearly not binding for the future, please adapt if 
those
+  // tokens get annotated.
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[9], tok::comma, TT_CtorInitializerComma);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Class::Class() : BaseClass{}, Member{} {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::r_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[9], tok::comma, TT_CtorInitializerComma);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1989,7 +1989,9 @@
 } else if (Current.isOneOf(tok::identifier, tok::kw_const, 
tok::kw_noexcept,
tok::kw_requires) &&
Current.Previous &&
-   !Current.Previous->isOneOf(tok::equal, tok::at) &&
+   !Current.Previous->isOneOf(tok::equal, tok::at,
+  TT_CtorInitializerComma,
+  TT_CtorInitializerColon) &&
Line.MightBeFunctionDecl && Contexts.size() == 1) {
   // Line.MightBeFunctionDecl can only be true after the parentheses of a
   // function declaration have been found.


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1124,6 +1124,35 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
+  auto Tokens = annotate("Class::Class() : BaseClass(), Member() {}");
+
+  // The TT_Unknown is clearly not binding for the future, please adapt if those
+  // tokens get annotated.
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[9], tok::comma, TT_CtorInitializerComma);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Class::Class() : BaseClass{}, Member{} {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[8], tok::r_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[9], tok::comma, TT_CtorInitializerComma);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_brace, TT_Unknown);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format

[clang] 691774d - [clang-format][NFC] Fix document of AlignTrailingComments

2022-11-03 Thread Björn Schäpers via cfe-commits

Author: Yusuke Kadowaki
Date: 2022-11-03T13:12:51+01:00
New Revision: 691774d4030d9b7f2941946d9a78acce92f87310

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

LOG: [clang-format][NFC] Fix document of AlignTrailingComments

The documentation of the patch https://reviews.llvm.org/D132131 looks
disorganized on the website
https://clang.llvm.org/docs/ClangFormatStyleOptions.html.
This patch tries to fix that.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0416190a2fd52..44f05cf28270b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -865,7 +865,7 @@ the configuration (without a prefix: ``Auto``).
   Alignment options
 
   * ``TrailingCommentsAlignmentKinds Kind``
-Specifies the way to align trailing comments
+Specifies the way to align trailing comments.
 
 Possible values:
 
@@ -903,8 +903,9 @@ the configuration (without a prefix: ``Auto``).
 int abcd; // comment
 
 
-  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment
-With ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 2,
+  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.
+When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
+it formats like below.
 
 .. code-block:: c++
 
@@ -915,7 +916,8 @@ the configuration (without a prefix: ``Auto``).
 
   int abcdef; // aligned
 
-And with ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 1,
+When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
+to 1, it formats like below.
 
 .. code-block:: c++
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6981dc158d241..3cadb6304dced 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -402,10 +402,11 @@ struct FormatStyle {
 
   /// Alignment options
   struct TrailingCommentsAlignmentStyle {
-/// Specifies the way to align trailing comments
+/// Specifies the way to align trailing comments.
 TrailingCommentsAlignmentKinds Kind;
-/// How many empty lines to apply alignment
-/// With ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 2,
+/// How many empty lines to apply alignment.
+/// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
+/// it formats like below.
 /// \code
 ///   int a;  // all these
 ///
@@ -414,7 +415,9 @@ struct FormatStyle {
 ///
 ///   int abcdef; // aligned
 /// \endcode
-/// And with ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 1,
+///
+/// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
+/// to 1, it formats like below.
 /// \code
 ///   int a;  // these are
 ///



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


[PATCH] D137075: [clang-format] Fix document of AlignTrailingComments

2022-11-03 Thread Björn Schäpers 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 rG691774d4030d: [clang-format][NFC] Fix document of 
AlignTrailingComments (authored by yusuke-kadowaki, committed by 
HazardyKnusperkeks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137075

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -402,10 +402,11 @@
 
   /// Alignment options
   struct TrailingCommentsAlignmentStyle {
-/// Specifies the way to align trailing comments
+/// Specifies the way to align trailing comments.
 TrailingCommentsAlignmentKinds Kind;
-/// How many empty lines to apply alignment
-/// With ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 2,
+/// How many empty lines to apply alignment.
+/// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
+/// it formats like below.
 /// \code
 ///   int a;  // all these
 ///
@@ -414,7 +415,9 @@
 ///
 ///   int abcdef; // aligned
 /// \endcode
-/// And with ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 1,
+///
+/// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
+/// to 1, it formats like below.
 /// \code
 ///   int a;  // these are
 ///
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -865,7 +865,7 @@
   Alignment options
 
   * ``TrailingCommentsAlignmentKinds Kind``
-Specifies the way to align trailing comments
+Specifies the way to align trailing comments.
 
 Possible values:
 
@@ -903,8 +903,9 @@
 int abcd; // comment
 
 
-  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment
-With ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 2,
+  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.
+When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
+it formats like below.
 
 .. code-block:: c++
 
@@ -915,7 +916,8 @@
 
   int abcdef; // aligned
 
-And with ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 1,
+When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
+to 1, it formats like below.
 
 .. code-block:: c++
 


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -402,10 +402,11 @@
 
   /// Alignment options
   struct TrailingCommentsAlignmentStyle {
-/// Specifies the way to align trailing comments
+/// Specifies the way to align trailing comments.
 TrailingCommentsAlignmentKinds Kind;
-/// How many empty lines to apply alignment
-/// With ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 2,
+/// How many empty lines to apply alignment.
+/// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
+/// it formats like below.
 /// \code
 ///   int a;  // all these
 ///
@@ -414,7 +415,9 @@
 ///
 ///   int abcdef; // aligned
 /// \endcode
-/// And with ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 1,
+///
+/// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
+/// to 1, it formats like below.
 /// \code
 ///   int a;  // these are
 ///
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -865,7 +865,7 @@
   Alignment options
 
   * ``TrailingCommentsAlignmentKinds Kind``
-Specifies the way to align trailing comments
+Specifies the way to align trailing comments.
 
 Possible values:
 
@@ -903,8 +903,9 @@
 int abcd; // comment
 
 
-  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment
-With ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 2,
+  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.
+When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
+it formats like below.
 
 .. code-block:: c++
 
@@ -915,7 +916,8 @@
 
   int abcdef; // aligned
 
-And with ``MaxEmptyLinesToKeep`` is 2 and ``OverEmptyLines`` is 1,
+When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
+to 1, it formats like below.
 
 .. code-block:: c++
 
___
cfe-commits mailing list
cfe-commit

[PATCH] D136919: [X86][RFC] Change mangle name of __bf16 from u6__bf16 to DF16b

2022-11-03 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

In D136919#3904925 , @RKSimon wrote:

> What are the rules on this? Do we just handle this as an ABI breaking change 
> and document it in the release notes - or do we need to provide any 
> auto-upgrade path (with a warning?)?

TBH, I don't have a good idea. It supposes to be Itanium ABI problem which I 
know little about. @ldionne WDYT?
I also put an RFC in the discourse 
,
 but no response so far.
The GCC proposal 
 suggests 
for ARM/AArch64 as well. They should have the same problem like us since they 
used `u6__bf16` for several versions, but I don't know any progress so far.
I want to get some feedback by this and I can discuss my GCC colleagues to see 
if we can change it back in GCC if this is not a good direction. There are two 
reasons I get so far:

1. It is a ABI breaking change to LLVM and other targets;
2. A mangled name of `__bf16` will be demanged as `std::bfloat_t`, which might 
confuse the user;

Welcome for suggestions~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136919

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


[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

2022-11-03 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG742970920b7a: [Clang] Implement CWG2358 Explicit capture of 
value (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137172

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13956,7 +13956,7 @@
 https://wg21.link/cwg2358";>2358
 CD5
 Explicit capture of value
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2359";>2359
Index: clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
+// RUN: %clang_cc1 -std=c++17 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
+
+
+const int global = 0;
 
 void f2() {
   int i = 1;
@@ -7,7 +11,20 @@
   void g3(int = ([=]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
   void g4(int = ([=]{ return 0; })());
   void g5(int = ([]{ return sizeof i; })());
+  void g6(int = ([x=1, y = global, &z = global]{ return x; })());
+  void g7(int = ([x=i, &y=i]{ return x; })()); // expected-error 2{{default argument references local variable 'i' of enclosing function}}
+}
+
+#if __cplusplus >= 201703L
+int global_array[] = { 1, 2 };
+auto [ga, gb] = global_array;
+
+void structured_bindings() {
+  int array[] = { 1, 2 };
+  auto [a, b] = array;
+  void func(int c = [x = a, &xref = a, y = ga, &yref = ga] { return x; }()); // expected-error 2{{default argument references local variable 'a' of enclosing function}}
 }
+#endif
 
 namespace lambda_in_default_args {
   int f(int = [] () -> int { int n; return ++n; } ());
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -89,6 +89,16 @@
 #pragma clang __debug dump not_use_2
 }
 
+#if __cplusplus >= 201402L
+namespace dr2358 { // dr2358: 16
+  void f2() {
+int i = 1;
+void g1(int = [xxx=1] { return xxx; }());  // OK
+void g2(int = [xxx=i] { return xxx; }());  // expected-error {{default argument references local variable 'i' of enclosing function}}
+  }
+}
+#endif
+
 #if __cplusplus >= 201707L
 // Otherwise, if the qualified-id std::tuple_size names a complete class
 // type **with a member value**, the expression std::tuple_size::value shall
Index: clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
===
--- clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
+++ clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -27,5 +27,7 @@
   struct S { int i; };
   auto [x] = S();
 
-  extern void h7(int = x); // FIXME: reject
+  extern void h7(int = x);
+  // expected-error@-1 {{default argument references local variable 'x' of enclosing function}}
+
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -102,24 +102,31 @@
   return S.Diag(DRE->getBeginLoc(),
 diag::err_param_default_argument_references_param)
  << Param->getDeclName() << DefaultArg->getSourceRange();
-  } else if (const auto *VDecl = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p7:
-//   Local variables shall not be used in default argument
-//   expressions.
-//
-// C++17 [dcl.fct.default]p7 (by CWG 2082):
-//   A local variable shall not appear as a potentially-evaluated
-//   expression in a default argument.
-//
-// C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
-//   Note: A local variable cannot be odr-used (6.3) in a default argument.
-//
-if (VDecl->isLocalVarDecl() && !DRE->isNonOdrUse())
-  return S.Diag(DRE->getBeginLoc(),
-diag::err_param_default_argument_references_local)
- << VDecl->getDeclName() << DefaultArg->getSourceRange();
+  } else {
+const VarDecl *VD = nullptr;
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {
+  // C++ [dcl.fct.default]

[clang] 7429709 - [Clang] Implement CWG2358 Explicit capture of value

2022-11-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-03T13:27:11+01:00
New Revision: 742970920b7a7fc2fe1cb6bca6fb04f03ab7d5d9

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

LOG: [Clang] Implement CWG2358 Explicit capture of value

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
clang/test/CXX/drs/dr23xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 763f4cece4634..ebf280f4da4a8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -574,6 +574,7 @@ C++ Language Changes in Clang
   This means Clang will by default accept code using features from C++17 and
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
+- Implemented DR2358 allowing init captures in lambdas in default arguments.
 
 C++20 Feature Support
 ^

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 80b748cbb3744..ea7997b347959 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -102,24 +102,31 @@ bool CheckDefaultArgumentVisitor::VisitDeclRefExpr(const 
DeclRefExpr *DRE) {
   return S.Diag(DRE->getBeginLoc(),
 diag::err_param_default_argument_references_param)
  << Param->getDeclName() << DefaultArg->getSourceRange();
-  } else if (const auto *VDecl = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p7:
-//   Local variables shall not be used in default argument
-//   expressions.
-//
-// C++17 [dcl.fct.default]p7 (by CWG 2082):
-//   A local variable shall not appear as a potentially-evaluated
-//   expression in a default argument.
-//
-// C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
-//   Note: A local variable cannot be odr-used (6.3) in a default argument.
-//
-if (VDecl->isLocalVarDecl() && !DRE->isNonOdrUse())
-  return S.Diag(DRE->getBeginLoc(),
-diag::err_param_default_argument_references_local)
- << VDecl->getDeclName() << DefaultArg->getSourceRange();
+  } else {
+const VarDecl *VD = nullptr;
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {
+  // C++ [dcl.fct.default]p7:
+  //   Local variables shall not be used in default argument
+  //   expressions.
+  //
+  // C++17 [dcl.fct.default]p7 (by CWG 2082):
+  //   A local variable shall not appear as a potentially-evaluated
+  //   expression in a default argument.
+  //
+  // C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
+  //   Note: A local variable cannot be odr-used (6.3) in a default
+  //   argument.
+  //
+  if (VD->isLocalVarDecl() && !DRE->isNonOdrUse())
+return S.Diag(DRE->getBeginLoc(),
+  diag::err_param_default_argument_references_local)
+   << Decl->getDeclName() << DefaultArg->getSourceRange();
+}
   }
-
   return false;
 }
 
@@ -149,13 +156,20 @@ bool CheckDefaultArgumentVisitor::VisitPseudoObjectExpr(
 }
 
 bool CheckDefaultArgumentVisitor::VisitLambdaExpr(const LambdaExpr *Lambda) {
-  // C++11 [expr.lambda.prim]p13:
-  //   A lambda-expression appearing in a default argument shall not
-  //   implicitly or explicitly capture any entity.
-  if (Lambda->capture_begin() == Lambda->capture_end())
-return false;
-
-  return S.Diag(Lambda->getBeginLoc(), diag::err_lambda_capture_default_arg);
+  // [expr.prim.lambda.capture]p9
+  // a lambda-expression appearing in a default argument cannot implicitly or
+  // explicitly capture any local entity. Such a lambda-expression can still
+  // have an init-capture if any full-expression in its initializer satisfies
+  // the constraints of an expression appearing in a default argument.
+  bool Invalid = false;
+  for (const LambdaCapture &LC : Lambda->captures()) {
+if (!Lambda->isInitCapture(&LC))
+  return S.Diag(LC.getLocation(), diag::err_lambda_capture_default_arg);
+// Init captures are always VarDecl.
+auto *D = cast(LC.getCapturedVar());
+Invalid |= Visit(D->getInit());
+  }
+  return Invalid;
 }
 } // namespace
 

diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
index 52986faa4e859..97b227222eb09 100644
--- a/c

[clang] b8ceb9f - [C++20] Diagnose invalid and reserved module names

2022-11-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-11-03T08:29:59-04:00
New Revision: b8ceb9f4e4bdb69b5c3ea1ccf8505fa244ca0a1e

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

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

[module.unit]p1 specifies that module and import are invalid components
of a module name, that module names cannot contain reserved
identifiers, and that std followed by zero or more digits is reserved.

The first issue (module and import pseudo-keywords) requires a
diagnostic, the second issue (use of reserved identifiers) does not
require a diagnostic. We diagnose both the same -- the code is ill-
formed unless the module declaration is in a system "header". This
allows STL implementations to use the reserved module names while
preventing users from stealing them out from under us.

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

Added: 
clang/test/Modules/reserved-names-1.cpp
clang/test/Modules/reserved-names-2.cpp
clang/test/Modules/reserved-names-3.cpp
clang/test/Modules/reserved-names-4.cpp
clang/test/Modules/reserved-names-system-header-1.cpp
clang/test/Modules/reserved-names-system-header-2.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaModule.cpp
clang/test/CodeGenCXX/cxx20-module-std-subst-1.cppm
clang/test/Modules/pair-unambiguous-ctor.cppm

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ebf280f4da4a8..73d7aff9b8910 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,6 +377,9 @@ Improvements to Clang's diagnostics
   `Issue 58673 `_.
 - Better diagnostics when the user has missed `auto` in a declaration.
   `Issue 49129 `_.
+- Clang now diagnoses use of invalid or reserved module names in a module
+  export declaration. Both are diagnosed as an error, but the diagnostic is
+  suppressed for use of reserved names in a system header.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a3da8abde58a6..1b1db765fa7a9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11207,6 +11207,8 @@ def err_private_module_fragment_not_module_interface : 
Error<
   "private module fragment in module implementation unit">;
 def note_not_module_interface_add_export : Note<
   "add 'export' here if this is intended to be a module interface unit">;
+def err_invalid_module_name : Error<
+  "%0 is %select{an invalid|a reserved}1 name for a module">;
 
 def ext_equivalent_internal_linkage_decl_in_modules : ExtWarn<
   "ambiguous use of internal linkage declaration %0 defined in multiple 
modules">,

diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 4b01f109fc881..19e2c206375bd 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -144,6 +144,37 @@ void Sema::HandleStartOfHeaderUnit() {
   TU->setLocalOwningModule(Mod);
 }
 
+/// Tests whether the given identifier is reserved as a module name and
+/// diagnoses if it is. Returns true if a diagnostic is emitted and false
+/// otherwise.
+static bool DiagReservedModuleName(Sema &S, const IdentifierInfo *II,
+   SourceLocation Loc) {
+  enum {
+Valid = -1,
+Invalid = 0,
+Reserved = 1,
+  } Reason = Valid;
+
+  StringRef PartName = II->getName();
+  if (II->isStr("module") || II->isStr("import"))
+Reason = Invalid;
+  else if (II->isReserved(S.getLangOpts()) !=
+   ReservedIdentifierStatus::NotReserved)
+Reason = Reserved;
+
+  // If the identifier is reserved (not invalid) but is in a system header,
+  // we do not diagnose (because we expect system headers to use reserved
+  // identifiers).
+  if (Reason == Reserved && S.getSourceManager().isInSystemHeader(Loc))
+Reason = Valid;
+
+  if (Reason != Valid) {
+S.Diag(Loc, diag::err_invalid_module_name) << II << (int)Reason;
+return true;
+  }
+  return false;
+}
+
 Sema::DeclGroupPtrTy
 Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
   ModuleDeclKind MDK, ModuleIdPath Path,
@@ -238,6 +269,32 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
SourceLocation ModuleLoc,
 }
   }
 
+  // C++2b [module.unit]p1: ... The identifiers module and import shall not
+  // appear as identifiers in a module-name or module-partition. All
+  // module-names either beginning with an identifier consisting 

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

2022-11-03 Thread Aaron Ballman 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 rGb8ceb9f4e4bd: [C++20] Diagnose invalid and reserved module 
names (authored by aaron.ballman).

Changed prior to commit:
  https://reviews.llvm.org/D136953?vs=472052&id=472908#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaModule.cpp
  clang/test/CodeGenCXX/cxx20-module-std-subst-1.cppm
  clang/test/Modules/pair-unambiguous-ctor.cppm
  clang/test/Modules/reserved-names-1.cpp
  clang/test/Modules/reserved-names-2.cpp
  clang/test/Modules/reserved-names-3.cpp
  clang/test/Modules/reserved-names-4.cpp
  clang/test/Modules/reserved-names-system-header-1.cpp
  clang/test/Modules/reserved-names-system-header-2.cpp

Index: clang/test/Modules/reserved-names-system-header-2.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names-system-header-2.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// Show that we suppress the reserved identifier diagnostic in a system header.
+# 100 "file.cpp" 1 3  // Enter a system header
+export module __test;
+# 100 "file.cpp" 2 3  // Leave the system header
Index: clang/test/Modules/reserved-names-system-header-1.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names-system-header-1.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// Show that we suppress the reserved identifier diagnostic in a system header.
+# 100 "file.cpp" 1 3  // Enter a system header
+export module std;
+# 100 "file.cpp" 2 3  // Leave the system header
Index: clang/test/Modules/reserved-names-4.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names-4.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// Demonstrate that we don't consider use of 'std' a reserved identifier if it
+// is not the first part of the path.
+export module should_succeed.std;
+
Index: clang/test/Modules/reserved-names-3.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names-3.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// Demonstrate that we don't consider use of 'std' (potentially followed by
+// zero or more digits) to be a reserved identifier if it is not the only part
+// of the path.
+export module std12Three;
Index: clang/test/Modules/reserved-names-2.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names-2.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// Demonstrate that we don't consider use of 'std' followed by digits to be a
+// reserved identifier if it is not the first part of the path.
+export module should_succeed.std0;
Index: clang/test/Modules/reserved-names-1.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names-1.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// expected-note@1 15{{add 'module;' to the start of the file to introduce a global module fragment}}
+
+module std;// expected-error {{'std' is a reserved name for a module}}
+module _Test;  // expected-error {{'_Test' is a reserved name for a module}} \
+  expected-error {{module declaration must occur at the start of the translation unit}}
+module module; // expected-error {{'module' is an invalid name for a module}} \
+  expected-error {{module declaration must occur at the start of the translation unit}}
+module std0;   // expected-error {{'std0' is a reserved name for a module}} \
+  expected-error {{module declaration must occur at the start of the translation unit}}
+
+export module module; // expected-error {{'module' is an invalid name for a module}} \
+ expected-error {{module declaration must occur at the start of the translation unit}}
+export module import; // expected-error {{'import' is an invalid name for a module}} \
+ expected-error {{module declaration must occur at the start of the translation unit}}
+export module _Test;  // expected-error {{'_Test' is a reserved name for a module}} \
+ expected-error {{module declaration must occur at the start of the translation unit}}
+export module __test; // expected-error {{'__test' is a reserved name f

[PATCH] D136919: [X86][RFC] Change mangle name of __bf16 from u6__bf16 to DF16b

2022-11-03 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added reviewers: stuij, tra.
RKSimon added a comment.

Do you think this patch needs to be expanded to handle ARM/AArch64/NVPTX - all 
of which override getBFloat16Mangling in similar ways?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136919

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


[PATCH] D124260: [clang-format] ColumnLimit check for trailing comments alignment acts wrong for multi-byte UTF-8 #47624

2022-11-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks abandoned this revision.
HazardyKnusperkeks added a comment.

You can reopen this, if you wish to continue working on it.


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

https://reviews.llvm.org/D124260

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


[PATCH] D137320: [include-cleaner] Initial version for the "Location=>Header" step

2022-11-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 472911.
hokein marked 6 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137320

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -7,11 +7,14 @@
 //===--===//
 
 #include "clang-include-cleaner/Analysis.h"
+#include "AnalysisInternal.h"
+#include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -26,41 +29,67 @@
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
-  llvm::Annotations HeaderCode(R"cpp(
-  void foo();
-  namespace std { class vector {}; })cpp");
+class WalkUsedTest : public ::testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap> walk(TestAST &AST) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls())
+  TopLevelDecls.emplace_back(D);
+auto &SM = AST.sourceManager();
+
+llvm::DenseMap> OffsetToProviders;
+walkUsed(
+TopLevelDecls, PI,
+[&](SourceLocation RefLoc, Symbol S, llvm::ArrayRef Providers) {
+  auto [FID, Offset] = SM.getDecomposedLoc(RefLoc);
+  EXPECT_EQ(FID, SM.getMainFileID());
+  OffsetToProviders.try_emplace(Offset, Providers.vec());
+});
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   void $bar^bar() {
 $foo^foo();
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
-  Inputs.ExtraFiles["header.h"] = HeaderCode.code().str();
+  Inputs.Code = Code.code();
+  Inputs.ExtraFiles["header.h"] = R"cpp(
+  void foo();
+  namespace std { class vector {}; }
+  )cpp";
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("header.h");
   TestAST AST(Inputs);
 
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
-  auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, [&](SourceLocation RefLoc, Symbol S,
-  llvm::ArrayRef Providers) {
-auto [FID, Offset] = SM.getDecomposedLoc(RefLoc);
-EXPECT_EQ(FID, SM.getMainFileID());
-OffsetToProviders.try_emplace(Offset, Providers.vec());
-  });
   auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
-  auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
+  auto MainFile = Header(AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  walk(AST),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
@@ -68,5 +97,98 @@
   Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL;
 }
 
+TEST_F(WalkUsedTest, IWYUBasic) {
+  llvm::Annotations Code(R"cpp(
+  #include "private.h"
+  #include "header1.h"
+  void $bar^bar($private^Private, $detail^Detail) {
+  }
+  )cpp");
+  Inputs.Code = Code.code();
+  Inputs.ExtraFiles["private.h"] = R"cpp(
+// IWYU pragma: private, include "path/public.h"
+class Private {};
+  )cpp";
+  Inputs.ExtraFiles["header1.h"] = R"cpp(
+#include "header2.h"
+  )cpp";
+  Inputs.ExtraFiles["header2.h"] = R"cpp(
+#include "detail.h" // IWYU pragma:

[PATCH] D98429: [clang-format] Add new option to clang-format: SpaceBeforeForLoopSemiColon

2022-11-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks abandoned this revision.
HazardyKnusperkeks added a comment.

More than a year silence.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98429

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


[PATCH] D137320: [include-cleaner] Initial version for the "Location=>Header" step

2022-11-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:63
+// FIXME: use a real Class!
+using SymbolLocation = std::variant;
+

kadircet wrote:
> let's move this to `AnalysisInternal.h`, as it isn't used in any of the 
> public apis.
I'm not quite sure about this --the SymbolLocation is an important concept and 
API, even though it is not used in public APIs. Moved anyway.




Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:55
+if (!VerbatimSpelling.empty())
+  return {{VerbatimSpelling}};
+

kadircet wrote:
> what about exporters here?
based on our previous discussion, we decided to initially treat the spelling 
header in the IWYU private pragma as the final public header, so no need to do 
the exporters here.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:58
+Results = {{FE}};
+// FIXME: compute a closure of exporter headers.
+for (const auto *Export : PI.getExporters(FE, SM.getFileManager()))

kadircet wrote:
> not sure i follow the fixme here, are you suggesting we should also compute 
> transitive exporters?
Yeah, rephrased the FIXME.



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:49
+// FIXME: expose signals
+llvm::SmallVector findIncludeHeaders(const SymbolLocation &Loc,
+ const SourceManager &SM,

kadircet wrote:
> this is fine for the initial version, but we'll likely lose a lot of 
> performance here going forward. we can address it later on though, as this is 
> an internal api and those performance concerns won't be a problem until this 
> is used more widely. 
> 
> we're likely going to call this function multiple times for each symbol, and 
> also despite having different sourcelocations, there'll probably be lots of 
> declarations that're originating from the same FileID.
> Hence we'll want to accumulate outputs on a single container, rather than 
> returning a new container at each call, and also have some sort of file-id 
> based cache.
Acked, agree that this is likely a hot function, we should not be concern about 
it at the moment.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:116
+
+  EXPECT_THAT(walk(AST),
+  UnorderedElementsAre(

kadircet wrote:
> can we use `findIncludeHeaders` directly?
> 
> that way we don't need to set up a referencing file, e.g. you can directly 
> create a SourceLocation inside `private.h` (in this case even the decl is not 
> important). 
> 
> 
> (same for the export test)
the intention was to do an end-to-end test of the walkUsed API. 

but you're right, we should have a unittest for `findIncludeHeaders`, added 
one, and simplified the end-to-end walkUsed test. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137320

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


[PATCH] D136554: Implement CWG2631

2022-11-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 472912.
cor3ntin added a comment.

Add tests for consteval calls in init captures in 
default parameters.

Clang behavior deviates from the wording of CWG2631
as it is not clear how we can implement the intended behavior 
in that corner case without introducing more complexity.


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,49 @@
   }
   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__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -0,0 +1,65 @@
+// 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'}}
+int d = [](int

[PATCH] D137334: [clang][dataflow] Generalize custom comparison to return tri-value result.

2022-11-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, sgatev, gribozavr2.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Currently, the API for a model's custom value comparison returns a
boolean. Therefore, models cannot distinguish between situations where the
values are recognized by the model and different and those where the values are
just not recognized.  This patch changes the return value to a tri-valued enum,
allowing models to express "don't know".

This patch is essentially a NFC -- no practical differences result from this
change in this patch. But, it prepares for future patches (particularly,
upcoming patches for widening) which will take advantage of the new flexibility.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137334

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -351,24 +351,26 @@
 }
   }
 
-  bool compareEquivalent(QualType Type, const Value &Val1,
- const Environment &Env1, const Value &Val2,
- const Environment &Env2) override {
+  ComparisonStatus compare(QualType Type, const Value &Val1,
+   const Environment &Env1, const Value &Val2,
+   const Environment &Env2) override {
 const auto *Decl = Type->getAsCXXRecordDecl();
 if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
 Decl->getName() != "SpecialBool")
-  return false;
+  return ComparisonStatus::Unknown;
 
 auto *IsSet1 = cast_or_null(Val1.getProperty("is_set"));
+auto *IsSet2 = cast_or_null(Val2.getProperty("is_set"));
 if (IsSet1 == nullptr)
-  return true;
+  return IsSet2 ? ComparisonStatus::Same : ComparisonStatus::Different;
 
-auto *IsSet2 = cast_or_null(Val2.getProperty("is_set"));
 if (IsSet2 == nullptr)
-  return false;
+  return ComparisonStatus::Different;
 
 return Env1.flowConditionImplies(*IsSet1) ==
-   Env2.flowConditionImplies(*IsSet2);
+   Env2.flowConditionImplies(*IsSet2)
+   ? ComparisonStatus::Same
+   : ComparisonStatus::Different;
   }
 
   // Always returns `true` to accept the `MergedVal`.
@@ -509,18 +511,19 @@
 }
   }
 
-  bool compareEquivalent(QualType Type, const Value &Val1,
- const Environment &Env1, const Value &Val2,
- const Environment &Env2) override {
+  ComparisonStatus compare(QualType Type, const Value &Val1,
+   const Environment &Env1, const Value &Val2,
+   const Environment &Env2) override {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
-  return false;
+  return ComparisonStatus::Unknown;
 
 auto *Prop1 = Val1.getProperty("has_value");
 auto *Prop2 = Val2.getProperty("has_value");
 assert(Prop1 != nullptr && Prop2 != nullptr);
-return areEquivalentValues(*Prop1, *Prop2);
+return areEquivalentValues(*Prop1, *Prop2) ? ComparisonStatus::Same
+   : ComparisonStatus::Different;
   }
 
   bool merge(QualType Type, const Value &Val1, const Environment &Env1,
@@ -1181,14 +1184,6 @@
   Env.setStorageLocation(*E, Loc);
 }
   }
-
-  bool compareEquivalent(QualType Type, const Value &Val1,
- const Environment &Env1, const Value &Val2,
- const Environment &Env2) override {
-// Changes to a sound approximation, which allows us to test whether we can
-// (soundly) converge for some loops.
-return false;
-  }
 };
 
 class TopTest : public Test {
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -208,7 +208,7 @@
 }
 
 /// Returns true if and only if `Type` is an optional type.
-bool IsOptionalType(QualType Type) {
+bool isOptionalType(QualType Type) {
   if (!Type->isRec

[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2022-11-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.
Herald added a project: All.

If you still want this to be landed, we need a name and email for the commit.


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

https://reviews.llvm.org/D91950

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


[PATCH] D90121: clang-format: Add a consumer to diagnostics engine

2022-11-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks abandoned this revision.
HazardyKnusperkeks added a comment.

In D90121#3065063 , @dmikis wrote:

> Since we used heavily patched version of clang-format (including this patch) 
> that problem didn't bugged us and I kinda moved on to other things :/




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90121

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


[clang] 964c494 - Remove an unused local variable, NFC.

2022-11-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-11-03T13:57:46+01:00
New Revision: 964c4948cd4adb8e5d436796b02eb4bcd0b9641f

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

LOG: Remove an unused local variable, NFC.

Added: 


Modified: 
clang/lib/Sema/SemaModule.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 19e2c206375b..1db716e77e7d 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -155,7 +155,6 @@ static bool DiagReservedModuleName(Sema &S, const 
IdentifierInfo *II,
 Reserved = 1,
   } Reason = Valid;
 
-  StringRef PartName = II->getName();
   if (II->isStr("module") || II->isStr("import"))
 Reason = Invalid;
   else if (II->isReserved(S.getLangOpts()) !=



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


[PATCH] D134267: [C++] [Modules] Support one phase compilation model for named modules

2022-11-03 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added a comment.

In D134267#3904257 , @ChuanqiXu wrote:

> BTW, this patch should be discarded. And now we're pursuing D137059 
>  and D137058 
> , where there is no modules cache. I know 
> it is a little bit frustrating to change the demo all the time... but let's 
> turn for that direction now.

Sorry, Phab is obtuse/unfamiliar for me right now; the "Abandoned" state isn't 
prevalent enough and all the pages look the same…


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

https://reviews.llvm.org/D134267

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


[PATCH] D137059: [Driver] [Modules] Introduce -fsave-std-c++-module-file= to specify the path of the module file (2/2)

2022-11-03 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added a comment.

In D137059#3904256 , @ChuanqiXu wrote:

> In my mind, it is OK for CMake to support one-phase compilation model in the 
> short term. And  the fact that clang also supports the 2-phase compilation 
> wouldn't affect CMake. Do I understand right?  I mean, if the 2-phase 
> compilation wouldn't affect CMake, CMake should be able to ignore it. My 
> thought is that there are many more build systems in the world. And I know 
> many of them would handle the dependency them self fully instead of translate 
> the dependency to other build scripts like `make` and `ninja`. And I think it 
> should be good for the compiler to remain different possibilities for 
> different build systems (or tools).

Indeed. Even if everything supports 2-phase, I suspect there are cases where 
1-phase might still be better. But again, this needs real world numbers and 
testing to actually perform (more because of build graph shapes than individual 
TU timings).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137059

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


[PATCH] D136919: [X86][RFC] Change mangle name of __bf16 from u6__bf16 to DF16b

2022-11-03 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

In D136919#3905024 , @RKSimon wrote:

> Do you think this patch needs to be expanded to handle ARM/AArch64/NVPTX - 
> all of which override getBFloat16Mangling in similar ways?

I thought of that. It would be great if we can make consensus with other 
backends here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136919

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


[PATCH] D137317: [X86][CET] Add Diags for targets pre to i686

2022-11-03 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 472916.
pengfei added a comment.

Fix lit fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137317

Files:
  clang/lib/Basic/Targets/X86.h


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -241,12 +241,16 @@
 
   bool
   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionReturnSupported(Diags);
   };
 
   bool
   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionBranchSupported(Diags);
   };
 
   virtual bool validateOperandSize(const llvm::StringMap &FeatureMap,


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -241,12 +241,16 @@
 
   bool
   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionReturnSupported(Diags);
   };
 
   bool
   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
-return true;
+if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
+  return true;
+return TargetInfo::checkCFProtectionBranchSupported(Diags);
   };
 
   virtual bool validateOperandSize(const llvm::StringMap &FeatureMap,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137244: [Clang] Correctly capture bindings in dependent lambdas.

2022-11-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 472920.
cor3ntin added a comment.

Use the `getPotentiallyDecomposedVarDecl` everywhere it makes sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137244

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaLambda.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx20-decomposition.cpp

Index: clang/test/SemaCXX/cxx20-decomposition.cpp
===
--- clang/test/SemaCXX/cxx20-decomposition.cpp
+++ clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wunused-variable %s
 
 template 
 constexpr bool is_same = false;
@@ -80,10 +79,21 @@
 namespace std {
 
 template 
-struct tuple_size {
+struct tuple_size;
+
+template 
+struct tuple_size : tuple_size{};
+
+template 
+requires requires { tuple_size::value; }
+struct tuple_size : tuple_size{};
+
+template <>
+struct tuple_size {
   static constexpr unsigned long value = 2;
 };
 
+
 template 
 struct tuple_element;
 
@@ -139,3 +149,37 @@
 };
   }
 }
+
+namespace ODRUseTests {
+  struct P { int a; int b; };
+  void GH57826() {
+const auto [a, b] = P{1, 2}; //expected-note 2{{'b' declared here}} \
+ //expected-note 3{{'a' declared here}}
+(void)[&](auto c) { return b + [&a] {
+return a;
+}() ; }(0);
+(void)[&](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[=](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a,&b](auto c) { return b + [&a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a,&b](auto c) { return b + [a](auto) {
+return a;
+}(0) ; }(0);
+(void)[&a](auto c) { return b + [&a](auto) { // expected-error 2{{variable 'b' cannot be implicitly captured}} \
+ // expected-note 2{{lambda expression begins here}} \
+ // expected-note 4{{capture 'b'}}
+return a;
+}(0) ; }(0); // expected-note {{in instantiation}}
+(void)[&b](auto c) { return b + [](auto) {   // expected-note 3{{lambda expression begins here}} \
+ // expected-note 6{{capture 'a'}} \
+ // expected-note 6{{default capture}} \
+ // expected-note {{in instantiation}}
+return a;  // expected-error 3{{variable 'a' cannot be implicitly captured}}
+}(0) ; }(0); // expected-note 2{{in instantiation}}
+  }
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13323,9 +13323,8 @@
 }
 
 // Transform the captured variable.
-VarDecl *CapturedVar
-  = cast_or_null(getDerived().TransformDecl(C->getLocation(),
- C->getCapturedVar()));
+ValueDecl *CapturedVar = cast_or_null(
+getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
   Invalid = true;
   continue;
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -62,7 +62,7 @@
 static inline Optional
 getStackIndexOfNearestEnclosingCaptureReadyLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture) {
+ValueDecl *VarToCapture) {
   // Label failure to capture.
   const Optional NoLambdaIsCaptureReady;
 
@@ -172,7 +172,7 @@
 
 Optional clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture, Sema &S) {
+ValueDecl *VarToCapture, Sema &S) {
 
   const Optional NoLambdaIsCaptureCapable;
 
@@ -1231,11 +1231,7 @@
 if (Var->isInvalidDecl())
   continue;
 
-VarDecl *Underlying;
-if (auto *BD = dyn_cast(Var))
-  Underlying = dyn_cast(BD->getDecomposedDecl());
-else
-  Underlying = cast(Var);
+VarDecl *Underlying = Var->getPotentiallyDecomposedVarDecl();
 
 if (!Underlying->hasLocalStorage()) {
   Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp

[PATCH] D135740: [clang-format] Fix multiple preprocessor if sections parsing incorrectly

2022-11-03 Thread sstwcw via Phabricator via cfe-commits
sstwcw abandoned this revision.
sstwcw added a comment.

It does some more than D137052 .  But the 
addition stuff is not very important and no one can review it.  So I am closing 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135740

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


[PATCH] D136554: Implement CWG2631

2022-11-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 472922.
cor3ntin added a comment.

Tweak comment in source_location tests with
a suggestion Aaron made offline.


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,51 @@
   }
   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__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -0,0 +1,65 @@
+// 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'}}
+int d = [](int defaulted = sizeof(undefined())) {
+return defaulted;
+  

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

2022-11-03 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

> These workarounds are fine for me, but I wonder if it would be useful with a 
> more direct cmake option to tell it not look for these files at all.

CMake has something like that built-in. I think it's 
`-DCMAKE_DISABLE_FIND_PACKAGE_LLVM=ON`.


Repository:
  rG LLVM Github Monorepo

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] D135859: [Includecleaner] Introduce RefType to ast walking

2022-11-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 472925.
kadircet marked 5 inline comments as done.
kadircet added a comment.

- Fix typo
- Change comment
- Use Types.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -12,11 +12,15 @@
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
 #include 
 
 namespace clang::include_cleaner {
@@ -24,10 +28,23 @@
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
+llvm::StringLiteral to_string(RefType RT) {
+  switch (RT) {
+  case RefType::Explicit:
+return "explicit";
+  case RefType::Implicit:
+return "implicit";
+  case RefType::Ambiguous:
+return "ambiguous";
+  }
+  llvm_unreachable("Unexpected RefType");
+}
+
 // Specifies a test of which symbols are referenced by a piece of code.
-//
+// If `// c++-header` is present, treats referencing code as a header file.
+// Target should contain points annotated with the reference kind.
 // Example:
-//   Target:  int ^foo();
+//   Target:  int $explicit^foo();
 //   Referencing: int x = ^foo();
 // There must be exactly one referencing location marked.
 void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
@@ -39,6 +56,8 @@
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
   Inputs.ExtraArgs.push_back("-std=c++17");
+  if (Referencing.code().contains("// c++-header\n"))
+Inputs.ExtraArgs.push_back("-xc++-header");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -51,20 +70,21 @@
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
   // Perform the walk, and capture the offsets of the referenced targets.
-  std::vector ReferencedOffsets;
+  std::unordered_map> ReferencedOffsets;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
 if (ReferencingFile != SM.getDecomposedExpansionLoc(D->getLocation()).first)
   continue;
-walkAST(*D, [&](SourceLocation Loc, NamedDecl &ND) {
+walkAST(*D, [&](SourceLocation Loc, NamedDecl &ND, RefType RT) {
   if (SM.getFileLoc(Loc) != ReferencingLoc)
 return;
   auto NDLoc = SM.getDecomposedLoc(SM.getFileLoc(ND.getLocation()));
   if (NDLoc.first != TargetFile)
 return;
-  ReferencedOffsets.push_back(NDLoc.second);
+  ReferencedOffsets[RT].push_back(NDLoc.second);
 });
   }
-  llvm::sort(ReferencedOffsets);
+  for (auto &Entry : ReferencedOffsets)
+llvm::sort(Entry.second);
 
   // Compare results to the expected points.
   // For each difference, show the target point in context, like a diagnostic.
@@ -74,17 +94,22 @@
   DiagOpts->ShowLevel = 0;
   DiagOpts->ShowNoteIncludeStack = 0;
   TextDiagnostic Diag(DiagOS, AST.context().getLangOpts(), DiagOpts);
-  auto DiagnosePoint = [&](const char *Message, unsigned Offset) {
+  auto DiagnosePoint = [&](llvm::StringRef Message, unsigned Offset) {
 Diag.emitDiagnostic(
 FullSourceLoc(SM.getComposedLoc(TargetFile, Offset), SM),
 DiagnosticsEngine::Note, Message, {}, {});
   };
-  for (auto Expected : Target.points())
-if (!llvm::is_contained(ReferencedOffsets, Expected))
-  DiagnosePoint("location not marked used", Expected);
-  for (auto Actual : ReferencedOffsets)
-if (!llvm::is_contained(Target.points(), Actual))
-  DiagnosePoint("location unexpectedly used", Actual);
+  for (auto RT : {RefType::Explicit, RefType::Implicit, RefType::Ambiguous}) {
+auto RTStr = to_string(RT);
+for (auto Expected : Target.points(RTStr))
+  if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
+DiagnosePoint(("location not marked used with type " + RTStr).str(),
+  Expected);
+for (auto Actual : ReferencedOffsets[RT])
+  if (!llvm::is_contained(Target.points(RTStr), Actual))
+DiagnosePoint(("location unexpectedly used with type " + RT

[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-11-03 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:25
 namespace clang::include_cleaner {
 namespace {
+using DeclCallback =

There is a cuter way to use anonymous namespaces:
https://llvm.org/docs/CodingStandards.html#anonymous-namespaces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

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


[PATCH] D137320: [include-cleaner] Initial version for the "Location=>Header" step

2022-11-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:54
+  /// A verbatim header spelling, a string quoted with <> or "" that can be
+  /// #included directly
+  Header(StringRef VerbatimSpelling) : Storage(VerbatimSpelling) {}

nit: `.` at the end of comment



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:67
+  }
+  return Results;
+}

can you actually put an `llvm_unreachable` here?



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:55
+if (!VerbatimSpelling.empty())
+  return {{VerbatimSpelling}};
+

hokein wrote:
> kadircet wrote:
> > what about exporters here?
> based on our previous discussion, we decided to initially treat the spelling 
> header in the IWYU private pragma as the final public header, so no need to 
> do the exporters here.
yeah SG, can you put a comment about that though? saying `// Note that we might 
need to look for exporters in this case as well.`



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:58
+Results = {{FE}};
+// FIXME: compute a closure of exporter headers.
+for (const auto *Export : PI.getExporters(FE, SM.getFileManager()))

hokein wrote:
> kadircet wrote:
> > not sure i follow the fixme here, are you suggesting we should also compute 
> > transitive exporters?
> Yeah, rephrased the FIXME.
i see, i am not sure if that's desired though.

e.g. if we have `foo.h` exporting `bar.h` exporting `baz.h`, I don't think 
`baz.h` counts (or should count) as an alternative to `foo.h`. do we have 
information proving otherwise?



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:135
+
+TEST(FindIncludeHeaders, IWYU) {
+  TestInputs Inputs;

you can still use the same fixture here, if you want a different name you can 
always do: `using FindIncludeHeaders = WalkUsedTest;` or `class 
FindIncludeHeaders : public WalkUsedTest {};`



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:116
+
+  EXPECT_THAT(walk(AST),
+  UnorderedElementsAre(

hokein wrote:
> kadircet wrote:
> > can we use `findIncludeHeaders` directly?
> > 
> > that way we don't need to set up a referencing file, e.g. you can directly 
> > create a SourceLocation inside `private.h` (in this case even the decl is 
> > not important). 
> > 
> > 
> > (same for the export test)
> the intention was to do an end-to-end test of the walkUsed API. 
> 
> but you're right, we should have a unittest for `findIncludeHeaders`, added 
> one, and simplified the end-to-end walkUsed test. 
> the intention was to do an end-to-end test of the walkUsed API.

We can update the `Basic` test above for that purpose (and turn it into a smoke 
test instead).

> but you're right, we should have a unittest for findIncludeHeaders, added 
> one, and simplified the end-to-end walkUsed test.

Since these are all trying to test specific IWYU pragma behaviour, I still 
think it's better to test them in isolation, both for test brevity but also for 
debuggability in the future when something breaks.
Also making sure majority of the tests are smaller is good for incremental 
progress as well, when we update ast walking logic, we shouldn't be updating 
these tests for whatever reasons (+ arguments around test times).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137320

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


[PATCH] D137337: Replace LLVM_LIBDIR_SUFFIX by CMAKE_INSTALL_LIBDIR

2022-11-03 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added reviewers: MaskRay, tstellar, mgorny, sylvestre.ledru.
Herald added subscribers: libc-commits, libcxx-commits, Moerafaat, zero9178, 
Enna1, bzcheeseman, kosarev, ayermolo, sdasgup3, wenzhicui, wrengr, cota, 
StephenFan, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, 
grosul1, Joonsoo, kerbowa, liufengdb, aartbik, mgester, arpith-jacob, csigg, 
antiagainst, shauheen, rriddle, mehdi_amini, whisperity, jvesely.
Herald added a reviewer: bollu.
Herald added a reviewer: sscalpone.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a reviewer: NoQ.
Herald added projects: libunwind, libc-project, Flang, All.
Herald added a reviewer: libunwind.
serge-sans-paille requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, openmp-commits, lldb-commits, 
Sanitizers, cfe-commits, yota9, sstefan1, stephenneuendorffer, 
nicolasvasilache, jdoerfert.
Herald added projects: clang, Sanitizers, LLDB, libc++, OpenMP, libc++abi, 
MLIR, LLVM.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.

There are a few advantages of using CMAKE_INSTALL_LIBDIR in place of
LLVM_LIBDIR_SUFFIX:

1. it's a standard flag, no need to support an extra cmake configuration
2. it has sane defaults, and picks lib64 instead of lib on some syssyems 
(including Fedora)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137337

Files:
  bolt/CMakeLists.txt
  bolt/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
  bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
  bolt/runtime/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/caches/Android-stage2.cmake
  clang/cmake/caches/Android.cmake
  clang/cmake/modules/AddClang.cmake
  clang/cmake/modules/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/runtime/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  cmake/Modules/GNUInstallPackageDir.cmake
  compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/docs/BuildingCompilerRT.rst
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/cmake/modules/CMakeLists.txt
  libc/lib/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/docs/BuildingLibcxx.rst
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/docs/BuildingLibunwind.rst
  lld/CMakeLists.txt
  lld/cmake/modules/AddLLD.cmake
  lld/cmake/modules/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBGenerateConfig.cmake
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/source/API/CMakeLists.txt
  lldb/test/CMakeLists.txt
  lldb/tools/intel-features/CMakeLists.txt
  lldb/utils/lldb-dotest/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/AddOCaml.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/docs/CMake.rst
  llvm/tools/llvm-config/BuildVariables.inc.in
  llvm/tools/llvm-config/llvm-config.cpp
  llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  mlir/cmake/modules/AddMLIRPython.cmake
  mlir/cmake/modules/CMakeLists.txt
  mlir/test/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/README.rst
  openmp/libompd/src/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
  openmp/libomptarget/plugins/CMakeLists.txt
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/plugins/cuda/CMakeLists.txt
  openmp/libomptarget/plugins/remote/src/CMakeLists.txt
  openmp/libomptarget/plugins/ve/CMakeLists.txt
  openmp/libomptarget/src/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/Modules/CMakeLists.txt
  openmp/tools/archer/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/cmake/polly_macros.cmake

Index: polly/cmake/polly_macros.cmake
===
--- polly/cmake/polly_macros.cmake
+++ polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@
   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
 install(TARGETS ${name}
   EXPORT LLVMExports
-  LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
   endif()
   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
 endmacro(add_polly_library)
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -7,7 +7,7 

[clang] 37f8010 - Silence a "not all control paths return" MSVC warning; NFC

2022-11-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-11-03T10:27:16-04:00
New Revision: 37f80101a9120c95eb3c1022b8cc4a390f561700

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

LOG: Silence a "not all control paths return" MSVC warning; NFC

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 55182ec383fa1..f645063acdd01 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -184,6 +184,7 @@ static BlockCtorFn getCtorArrayPrim(PrimType Type) {
 
 static BlockDtorFn getDtorArrayPrim(PrimType Type) {
   TYPE_SWITCH(Type, return dtorArrayTy);
+  llvm_unreachable("unknown Expr");
 }
 
 static BlockMoveFn getMoveArrayPrim(PrimType Type) {



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


[clang] 9ea2b15 - [OpenMP][OMPIRBuilder] Migrate createOffloadEntriesAndInfoMetadata from clang to OpenMPIRBuilder

2022-11-03 Thread Jan Sjodin via cfe-commits

Author: Jan Sjodin
Date: 2022-11-03T10:27:44-04:00
New Revision: 9ea2b150b5455b907ba3b9aa24703b5d4faabedd

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

LOG: [OpenMP][OMPIRBuilder] Migrate createOffloadEntriesAndInfoMetadata from 
clang to OpenMPIRBuilder

This patch moves the createOffloadEntriesAndInfoMetadata to OpenMPIRBuilder,
the createOffloadEntry helper function. The clang specific error handling is
invoked using a callback. This code will also be used by flang in the future.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 9a2fc93ce40c6..6b0908d139f47 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2950,194 +2950,57 @@ enum KmpTaskTFields {
 };
 } // anonymous namespace
 
-void CGOpenMPRuntime::createOffloadEntry(
-llvm::Constant *ID, llvm::Constant *Addr, uint64_t Size, int32_t Flags,
-llvm::GlobalValue::LinkageTypes Linkage) {
-  OMPBuilder.emitOffloadingEntry(ID, Addr->getName(), Size, Flags);
-}
-
 void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
-  // Emit the offloading entries and metadata so that the device codegen side
-  // can easily figure out what to emit. The produced metadata looks like
-  // this:
-  //
-  // !omp_offload.info = !{!1, ...}
-  //
-  // Right now we only generate metadata for function that contain target
-  // regions.
-
   // If we are in simd mode or there are no entries, we don't need to do
   // anything.
   if (CGM.getLangOpts().OpenMPSimd || OffloadEntriesInfoManager.empty())
 return;
 
-  llvm::Module &M = CGM.getModule();
-  llvm::LLVMContext &C = M.getContext();
-  SmallVector<
-  std::tuple,
-  16>
-  OrderedEntries(OffloadEntriesInfoManager.size());
-  llvm::SmallVector ParentFunctions(
-  OffloadEntriesInfoManager.size());
-
-  // Auxiliary methods to create metadata values and strings.
-  auto &&GetMDInt = [this](unsigned V) {
-return llvm::ConstantAsMetadata::get(
-llvm::ConstantInt::get(CGM.Int32Ty, V));
-  };
-
-  auto &&GetMDString = [&C](StringRef V) { return llvm::MDString::get(C, V); };
-
-  // Create the offloading info metadata node.
-  llvm::NamedMDNode *MD = M.getOrInsertNamedMetadata("omp_offload.info");
-
-  // Create function that emits metadata for each target region entry;
-  auto &&TargetRegionMetadataEmitter =
-  [this, &C, MD, &OrderedEntries, &ParentFunctions, &GetMDInt,
-   &GetMDString](
-  const llvm::TargetRegionEntryInfo &EntryInfo,
-  const llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion
-  &E) {
-// Generate metadata for target regions. Each entry of this metadata
-// contains:
-// - Entry 0 -> Kind of this type of metadata (0).
-// - Entry 1 -> Device ID of the file where the entry was identified.
-// - Entry 2 -> File ID of the file where the entry was identified.
-// - Entry 3 -> Mangled name of the function where the entry was
-// identified.
-// - Entry 4 -> Line in the file where the entry was identified.
-// - Entry 5 -> Order the entry was created.
-// The first element of the metadata node is the kind.
-llvm::Metadata *Ops[] = {
-GetMDInt(E.getKind()),  GetMDInt(EntryInfo.DeviceID),
-GetMDInt(EntryInfo.FileID), GetMDString(EntryInfo.ParentName),
-GetMDInt(EntryInfo.Line),   GetMDInt(E.getOrder())};
-
-SourceLocation Loc;
-for (auto I = CGM.getContext().getSourceManager().fileinfo_begin(),
-  E = CGM.getContext().getSourceManager().fileinfo_end();
- I != E; ++I) {
-  if (I->getFirst()->getUniqueID().getDevice() == EntryInfo.DeviceID &&
-  I->getFirst()->getUniqueID().getFile() == EntryInfo.FileID) {
-Loc = CGM.getContext().getSourceManager().translateFileLineCol(
-I->getFirst(), EntryInfo.Line, 1);
-break;
-  }
-}
-// Save this entry in the right position of the ordered entries array.
-OrderedEntries[E.getOrder()] =
-std::make_tuple(&E, Loc, StringRef(EntryInfo.ParentName));
-ParentFunctions[E.getOrder()] = StringRef(EntryInfo.ParentName);
-
-// Add metadata to the named metadata node.
-MD->addOperand(llvm::MDNode::get(C, Ops));
-  };
-
-  OffloadEntriesInfoManager.actOnTargetRegionEntriesInfo(

[PATCH] D136919: [X86][RFC] Change mangle name of __bf16 from u6__bf16 to DF16b

2022-11-03 Thread Thorsten via Phabricator via cfe-commits
tschuett added subscribers: aaron.ballman, tschuett.
tschuett added a comment.

@aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136919

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


[PATCH] D137337: Replace LLVM_LIBDIR_SUFFIX by CMAKE_INSTALL_LIBDIR

2022-11-03 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Maybe add it to the release notes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137337

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


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

2022-11-03 Thread Aaron Gokaslan via Phabricator via cfe-commits
Skylion007 added a comment.

Use llvm::find_if instead of std::find_if


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137338: Fix dupe word typos

2022-11-03 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.
Herald added a reviewer: jdoerfert.
Herald added subscribers: Michael137, sstefan1, JDevlieghere.

This is going to be impossible to cleanly review as-is. Could it be broken into 
lots of smaller chunks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137338

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


[PATCH] D137340: [clang-tidy] Add modernize-use-anonymous-namespace check

2022-11-03 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137340

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-use-anonymous-namespace %t
+
+static void f1();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+static int v1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
+
+namespace {
+  static void f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
+  static int v2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
+}
+
+namespace a {
+  static void f3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+  static int v3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+}
+
+namespace a {
+namespace {
+  static void f4();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
+  static int v4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
+}
+}
+
+// OK
+void f5();
+int v5;
+
+// OK
+namespace {
+  void f6();
+  int v6;
+}
+
+namespace a {
+namespace {
+  void f7();
+  int v7;
+}
+}
+
+// OK
+struct Foo {
+  static void f();
+  static int x;
+};
+
+// OK
+void foo()
+{
+  static int x;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - modernize-use-anonymous-namespace
+
+modernize-use-anonymous-namespace
+=
+
+Finds instances of ``static`` functions or variables declared at global scope
+that could instead be moved into the anonymous namespace. It also detects
+instances moved to the anonymous namespace that still keep the redundant
+``static``.
+
+Anonymous namespaces are the "superior alternative" according to the C++
+Standard. ``static`` was proposed for deprecation, but later un-deprecated to
+keep C compatibility. ``static`` is an overloaded term with different meaning in
+different contexts, so it can create confusion.
+
+Examples:
+
+.. code-block:: c++
+
+  // Bad
+  static void foo();
+  static int x;
+
+  // Good
+  namespace {
+void foo();
+int x;
+  } // namespace
+
+.. code-block:: c++
+
+  // Bad
+  namespace {
+static void foo();
+static int x;
+  }
+
+  // Good
+  namespace {
+void foo();
+int x;
+  }  // namespace
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -277,6 +277,7 @@
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
+   `modernize-use-anonymous-namespace `_,
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
`modernize-use-default-member-init `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,11 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`modernize-use-anonymous-namespace
+  ` check.
+
+  FIXME: add release notes.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck

[PATCH] D137340: [clang-tidy] Add modernize-use-anonymous-namespace check

2022-11-03 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 472946.
carlosgalvezp added a comment.

Fix release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137340

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp
@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s modernize-use-anonymous-namespace %t
+
+static void f1();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+static int v1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
+
+namespace {
+  static void f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
+  static int v2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
+}
+
+namespace a {
+  static void f3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+  static int v3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+}
+
+namespace a {
+namespace {
+  static void f4();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
+  static int v4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
+}
+}
+
+// OK
+void f5();
+int v5;
+
+// OK
+namespace {
+  void f6();
+  int v6;
+}
+
+// OK
+namespace a {
+namespace {
+  void f7();
+  int v7;
+}
+}
+
+// OK
+struct Foo {
+  static void f();
+  static int x;
+};
+
+// OK
+void foo()
+{
+  static int x;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - modernize-use-anonymous-namespace
+
+modernize-use-anonymous-namespace
+=
+
+Finds instances of ``static`` functions or variables declared at global scope
+that could instead be moved into the anonymous namespace. It also detects
+instances moved to the anonymous namespace that still keep the redundant
+``static``.
+
+Anonymous namespaces are the "superior alternative" according to the C++
+Standard. ``static`` was proposed for deprecation, but later un-deprecated to
+keep C compatibility. ``static`` is an overloaded term with different meaning in
+different contexts, so it can create confusion.
+
+Examples:
+
+.. code-block:: c++
+
+  // Bad
+  static void foo();
+  static int x;
+
+  // Good
+  namespace {
+void foo();
+int x;
+  } // namespace
+
+.. code-block:: c++
+
+  // Bad
+  namespace {
+static void foo();
+static int x;
+  }
+
+  // Good
+  namespace {
+void foo();
+int x;
+  }  // namespace
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -277,6 +277,7 @@
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
+   `modernize-use-anonymous-namespace `_,
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
`modernize-use-default-member-init `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,12 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`modernize-use-anonymous-namespace
+  ` check.
+
+  Warns when using ``static`` function or variables at global scope, and suggests
+  moving them to the anonymous namespace.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-ti

[PATCH] D137337: Replace LLVM_LIBDIR_SUFFIX by CMAKE_INSTALL_LIBDIR

2022-11-03 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 472945.
serge-sans-paille added a comment.

+ Release Note


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

https://reviews.llvm.org/D137337

Files:
  bolt/CMakeLists.txt
  bolt/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
  bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
  bolt/runtime/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/caches/Android-stage2.cmake
  clang/cmake/caches/Android.cmake
  clang/cmake/modules/AddClang.cmake
  clang/cmake/modules/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/runtime/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  cmake/Modules/GNUInstallPackageDir.cmake
  compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/docs/BuildingCompilerRT.rst
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/cmake/modules/CMakeLists.txt
  libc/lib/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/docs/BuildingLibcxx.rst
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/docs/BuildingLibunwind.rst
  lld/CMakeLists.txt
  lld/cmake/modules/AddLLD.cmake
  lld/cmake/modules/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBGenerateConfig.cmake
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/source/API/CMakeLists.txt
  lldb/test/CMakeLists.txt
  lldb/tools/intel-features/CMakeLists.txt
  lldb/utils/lldb-dotest/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/AddOCaml.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/docs/CMake.rst
  llvm/docs/ReleaseNotes.rst
  llvm/tools/llvm-config/BuildVariables.inc.in
  llvm/tools/llvm-config/llvm-config.cpp
  llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  mlir/cmake/modules/AddMLIRPython.cmake
  mlir/cmake/modules/CMakeLists.txt
  mlir/test/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/README.rst
  openmp/libompd/src/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
  openmp/libomptarget/plugins/CMakeLists.txt
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/plugins/cuda/CMakeLists.txt
  openmp/libomptarget/plugins/remote/src/CMakeLists.txt
  openmp/libomptarget/plugins/ve/CMakeLists.txt
  openmp/libomptarget/src/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/Modules/CMakeLists.txt
  openmp/tools/archer/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/cmake/polly_macros.cmake

Index: polly/cmake/polly_macros.cmake
===
--- polly/cmake/polly_macros.cmake
+++ polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@
   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
 install(TARGETS ${name}
   EXPORT LLVMExports
-  LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
   endif()
   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
 endmacro(add_polly_library)
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -7,7 +7,7 @@
 set(POLLY_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/polly" CACHE STRING
   "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
-set(polly_cmake_builddir "${POLLY_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
+set(polly_cmake_builddir "${POLLY_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/polly")
 
 set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
   "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
@@ -93,7 +93,7 @@
 find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
 extend_path(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
 extend_path(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${POLLY_INSTALL_PACKAGE_DIR}")
-extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "lib${LLVM_LIBDIR_SUFFIX}")
+extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}")
 extend_path(base_includedir "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
 if (POLLY_BUNDLED_ISL)
   set(POLLY_CONFIG_INCLUDE_DIRS
Index: openmp/tools/archer/CMakeLists.txt
===

[PATCH] D137338: Fix dupe word typos

2022-11-03 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added subscribers: pcc, glider.
glider added inline comments.



Comment at: clang/docs/DataFlowSanitizerDesign.rst:54
 
-  /// Returns whether the given label label contains the label elem.
+  /// Returns whether the given label contains the label elem.
   int dfsan_has_label(dfsan_label label, dfsan_label elem);

I believe the word duplication is on purpose here. I'd rewrite the comment as:

```
Returns whether the given label @label contains the label @elem.
```

@pcc, what do you think?



Comment at: compiler-rt/include/sanitizer/dfsan_interface.h:65
 
-/// Returns whether the given label label contains the label elem.
+/// Returns whether the given label contains the label elem.
 int dfsan_has_label(dfsan_label label, dfsan_label elem);

Same as clang/docs/DataFlowSanitizerDesign.rst above.



Comment at: compiler-rt/lib/asan/asan_allocator.cpp:1161
   // the `pthread_create()` interceptor doesn't wait for the child thread to
-  // start before returning and thus loosing the the only live reference to the
+  // start before returning and thus loosing the only live reference to the
   // heap object on the stack.

Ack.



Comment at: 
compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp:211
 
-  // This the the truncation case.
+  // This the truncation case.
   ASSERT_GT(actual_len, sizeof(tinybuf));

Ack.



Comment at: compiler-rt/lib/tsan/rtl-old/tsan_interceptors_posix.cpp:2510
 // Can't use internal_memcpy, because it copies byte-by-byte,
-// and signal handler reads the handler concurrently. It it can read
+// and signal handler reads the handler concurrently. It can read
 // some bytes from old value and some bytes from new value.

Ack.



Comment at: compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:2529
 // Can't use internal_memcpy, because it copies byte-by-byte,
-// and signal handler reads the handler concurrently. It it can read
+// and signal handler reads the handler concurrently. It can read
 // some bytes from old value and some bytes from new value.

Ack.



Comment at: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp:540
   Type *getShadowTy(Type *OrigTy);
-  /// Returns the shadow type of of V's type.
+  /// Returns the shadow type of V's type.
   Type *getShadowTy(Value *V);

Ack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137338

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


[PATCH] D125860: [clang] Only use major version in resource dir

2022-11-03 Thread Michał Górny via Phabricator via cfe-commits
mgorny added reviewers: serge-sans-paille, sylvestre.ledru, phosek, MaskRay.
mgorny added a comment.
Herald added subscribers: Michael137, StephenFan.

To be honest, I've never seen much purpose in the x.y.z directory naming and I 
feel like it's making packaging unnecessarily more complex, at least for us in 
Gentoo.

That said, I'd personally prefer if the directory was entirely configurable 
just like CLANG_RESOURCE_DIR can specify arbitrary path right now. But I'm also 
fine with this as-is.

Adding some more people who may have an opinion.


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

https://reviews.llvm.org/D125860

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


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

2022-11-03 Thread Aaron Gokaslan via Phabricator via cfe-commits
Skylion007 added a comment.

I noticed one other bug from testing this out on some C++ codebases.

Specifically in pybind11 we have an object class which is a child of the handle 
object. The object class is non-trivially copyable, while the handle object is 
not. Therefore, when we do not want to increase / decrease the reference count 
of object, we often rely on object's implicit casting to a handle. While I 
suppose you could std::move() to cast an object for a handle, there isn't a 
good reason to do so. You get all the drawbacks of using std::move (ie. use 
after free bugs potentially) with none of the benefits.

Finally, this is a smaller issue but there seems to be a bug where the fix it 
can apply `std::move(std::move(obj));`. That is relatively low pri and not 
blocking by any means though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137340: [clang-tidy] Add modernize-use-anonymous-namespace check

2022-11-03 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 472948.
carlosgalvezp added a comment.

Add reference to undeprecation of static.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137340

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-anonymous-namespace.cpp
@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s modernize-use-anonymous-namespace %t
+
+static void f1();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+static int v1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
+
+namespace {
+  static void f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
+  static int v2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
+}
+
+namespace a {
+  static void f3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+  static int v3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead [modernize-use-anonymous-namespace]
+}
+
+namespace a {
+namespace {
+  static void f4();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
+  static int v4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
+}
+}
+
+// OK
+void f5();
+int v5;
+
+// OK
+namespace {
+  void f6();
+  int v6;
+}
+
+// OK
+namespace a {
+namespace {
+  void f7();
+  int v7;
+}
+}
+
+// OK
+struct Foo {
+  static void f();
+  static int x;
+};
+
+// OK
+void foo()
+{
+  static int x;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-anonymous-namespace.rst
@@ -0,0 +1,44 @@
+.. title:: clang-tidy - modernize-use-anonymous-namespace
+
+modernize-use-anonymous-namespace
+=
+
+Finds instances of ``static`` functions or variables declared at global scope
+that could instead be moved into the anonymous namespace. It also detects
+instances moved to the anonymous namespace that still keep the redundant
+``static``.
+
+Anonymous namespaces are the "superior alternative" according to the C++
+Standard. ``static`` was proposed for deprecation, but later un-deprecated to
+keep C compatibility [1]. ``static`` is an overloaded term with different meanings in
+different contexts, so it can create confusion.
+
+Examples:
+
+.. code-block:: c++
+
+  // Bad
+  static void foo();
+  static int x;
+
+  // Good
+  namespace {
+void foo();
+int x;
+  } // namespace
+
+.. code-block:: c++
+
+  // Bad
+  namespace {
+static void foo();
+static int x;
+  }
+
+  // Good
+  namespace {
+void foo();
+int x;
+  }  // namespace
+
+[1] `Undeprecating static `_
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -277,6 +277,7 @@
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
+   `modernize-use-anonymous-namespace `_,
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
`modernize-use-default-member-init `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,12 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`modernize-use-anonymous-namespace
+  ` check.
+
+  Warns when using ``static`` function or variables at global scope, and

[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-11-03 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D137107#3897568 , @mstorsjo wrote:

> In D137107#3897326 , @rnk wrote:
>
>> Unless I'm missing something, I think Clang's behavior here is preferable to 
>> MSVC's. MSVC produces code which will not link. Clang turns the linker error 
>> into a compiler error, which is generally easier for the user to understand. 
>> To my knowledge, it is still true that there is no COFF relocation which can 
>> statically initialize a global variable with the address of a dllimported 
>> symbol.
>>
>> For the use case you are considering, how do things work out in practice? Is 
>> there some new import patching facility that I'm not aware of? Is the 
>> variable linked statically instead of dynamically, and then the linker 
>> relaxes the __imp references to direct references?
>
> The testcase that is shown here is peculiar in the sense that `constexpr int& 
> val_ref = val;` is located within `main()`, so it isn't really constexpr (as 
> far as I'd undestand it), but MSVC produces a load from `__imp_val`.

I think I can be convinced that generating a compiler error instead of a link 
error for the first use case is better, but about this use case (I am not sure 
I understand why you say “it isn’t a real constexpr”):

extern int __declspec(dllimport) next(int n);
int main () {

  extern int _declspec(dllimport) val;
  constexpr int& val_ref = val;
  int i = next(val_ref);
  return i;

}

With MSVC with or without constexpr will lead to the same generated symbol

012  UNDEF  notype   External | __imp_?val@@3HA 
(__declspec(dllimport) int val)

and the same assembly (load __imp_?val) (is that why you made the comment 
above?). And the test case runs.

But that’s not the case for clang (without this patch).
With constexpr it’s failing with the error mentioned above.

Without  constexpr the symbol generated is

0E  UNDEF  notype   External | __imp_?val@@3HA 
(__declspec(dllimport) int val)

and the assembly generates a ‘load __imp_? Val’. Same than MSVC, but the test 
case fails to run.  @rnk Shouldn't this run?

>> I am ready to be wrong here: if things have changed and my info is stale, we 
>> should definitely adapt.
>
> I'm not aware of anything that would have changed here...
>
> For the cases where this needs to be really statically initialized, the mingw 
> pseudo relocations do fill that spot (which fakes it by initializing it very 
> early on, from a linker-generated list of spots in the binary that needs 
> patching). For non-constexpr cases in C++, Clang solves it by implicitly 
> generating a static constructor which fetches it from the dllimported 
> variable.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137107

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


[clang] 3edd188 - [AArch64] Add a baseline test for fp16 target intrinsics. NFC

2022-11-03 Thread David Green via cfe-commits

Author: David Green
Date: 2022-11-03T15:18:36Z
New Revision: 3edd18876950693cbc69edda429f223616e3c052

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

LOG: [AArch64] Add a baseline test for fp16 target intrinsics. NFC

Added: 
clang/test/Sema/aarch64-fp16-target.c

Modified: 


Removed: 




diff  --git a/clang/test/Sema/aarch64-fp16-target.c 
b/clang/test/Sema/aarch64-fp16-target.c
new file mode 100644
index 0..13cee64c52f56
--- /dev/null
+++ b/clang/test/Sema/aarch64-fp16-target.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon 
-fsyntax-only -verify -emit-llvm -o - %s
+// REQUIRES: aarch64-registered-target
+
+// Test that functions with the correct target attributes can use the correct 
FP16 intrinsics.
+
+#include 
+
+__attribute__((target("fullfp16")))
+void test_fullfp16(float16_t f16) {
+  vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+}
+
+__attribute__((target("arch=armv8-a+fp16")))
+void test_fp16_arch(float16_t f16) {
+vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+}
+
+__attribute__((target("+fp16")))
+void test_fp16(float16_t f16) {
+vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+}
+
+void undefined(float16_t f16) {
+  vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+}



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


[PATCH] D137340: [clang-tidy] Add modernize-use-anonymous-namespace check

2022-11-03 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseAnonymousNamespaceCheck.cpp:31
+static bool isInAnonymousNamespace(const Decl *Decl) {
+  const auto *DC = Decl->getDeclContext();
+  if (DC && DC->isNamespace()) {

Please don't use `auto` unless type is explicitly spelled in same statement or 
iterator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137340

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


[PATCH] D125860: [clang] Only use major version in resource dir

2022-11-03 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

The consensus in the discourse thread you mention is not super strong, but I 
tend to agree with that patch. +1 for me.


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

https://reviews.llvm.org/D125860

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


[PATCH] D137338: Fix dupe word typos

2022-11-03 Thread Jay Foad via Phabricator via cfe-commits
foad added a comment.

I committed the lib/Target/AMDGPU parts as 5073ae2a883f 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137338

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


[PATCH] D137287: [Test] Fix CHECK typo.

2022-11-03 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Nice work!
have you verified that all the modified tests pass? naively it looks like you'd 
need at least 3 different targets to run them all (windows, webassembly, 
powerpc)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137287

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


[PATCH] D137334: [clang][dataflow] Generalize custom comparison to return tri-value result.

2022-11-03 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:52
+/// Indicates the result of a tentative comparison.
+enum class ComparisonStatus {
+  Same,

Alternative that I slightly prefer - `ComparisonResult`.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:75
+///   `Different`:`Val1` is distinct from `Val2`, according to the model.
+///   `Unknown`: The model does not determine a relationship between `Val1`
+///and `Val2`.

Perhaps replace "does not" with "can't"?



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:365
 if (IsSet1 == nullptr)
-  return true;
+  return IsSet2 ? ComparisonStatus::Same : ComparisonStatus::Different;
 

Why is it same if `IsSet1` is null and `IsSet2` isn't null?



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:1185
-
-  bool compareEquivalent(QualType Type, const Value &Val1,
- const Environment &Env1, const Value &Val2,

Why remove this? It's not the same as the default implementation, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137334

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


[PATCH] D137338: Fix dupe word typos

2022-11-03 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

Changes in `/polly/` look good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137338

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


[PATCH] D137256: [AArch64] Alter arm_fp16.h to be target-based, not preprocessor based.

2022-11-03 Thread Dave Green 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 rGe7deca525058: [AArch64] Alter arm_fp16.h to be target-based, 
not preprocessor based. (authored by dmgreen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137256

Files:
  clang/include/clang/Basic/arm_fp16.td
  clang/test/Sema/aarch64-fp16-target.c


Index: clang/test/Sema/aarch64-fp16-target.c
===
--- clang/test/Sema/aarch64-fp16-target.c
+++ clang/test/Sema/aarch64-fp16-target.c
@@ -7,19 +7,19 @@
 
 __attribute__((target("fullfp16")))
 void test_fullfp16(float16_t f16) {
-  vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+  vabdh_f16(f16, f16);
 }
 
 __attribute__((target("arch=armv8-a+fp16")))
 void test_fp16_arch(float16_t f16) {
-vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+vabdh_f16(f16, f16);
 }
 
 __attribute__((target("+fp16")))
 void test_fp16(float16_t f16) {
-vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+vabdh_f16(f16, f16);
 }
 
 void undefined(float16_t f16) {
-  vabdh_f16(f16, f16); // expected-error {{call to undeclared function 
'vabdh_f16'}}
+  vabdh_f16(f16, f16); // expected-error {{'__builtin_neon_vabdh_f16' needs 
target feature fullfp16}}
 }
Index: clang/include/clang/Basic/arm_fp16.td
===
--- clang/include/clang/Basic/arm_fp16.td
+++ clang/include/clang/Basic/arm_fp16.td
@@ -14,7 +14,7 @@
 include "arm_neon_incl.td"
 
 // ARMv8.2-A FP16 intrinsics.
-let ArchGuard = "defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC) && 
defined(__aarch64__)" in {
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "fullfp16" in {
 
   // Negate
   def VNEGSH  : SInst<"vneg", "11", "Sh">;


Index: clang/test/Sema/aarch64-fp16-target.c
===
--- clang/test/Sema/aarch64-fp16-target.c
+++ clang/test/Sema/aarch64-fp16-target.c
@@ -7,19 +7,19 @@
 
 __attribute__((target("fullfp16")))
 void test_fullfp16(float16_t f16) {
-  vabdh_f16(f16, f16); // expected-error {{call to undeclared function 'vabdh_f16'}}
+  vabdh_f16(f16, f16);
 }
 
 __attribute__((target("arch=armv8-a+fp16")))
 void test_fp16_arch(float16_t f16) {
-vabdh_f16(f16, f16); // expected-error {{call to undeclared function 'vabdh_f16'}}
+vabdh_f16(f16, f16);
 }
 
 __attribute__((target("+fp16")))
 void test_fp16(float16_t f16) {
-vabdh_f16(f16, f16); // expected-error {{call to undeclared function 'vabdh_f16'}}
+vabdh_f16(f16, f16);
 }
 
 void undefined(float16_t f16) {
-  vabdh_f16(f16, f16); // expected-error {{call to undeclared function 'vabdh_f16'}}
+  vabdh_f16(f16, f16); // expected-error {{'__builtin_neon_vabdh_f16' needs target feature fullfp16}}
 }
Index: clang/include/clang/Basic/arm_fp16.td
===
--- clang/include/clang/Basic/arm_fp16.td
+++ clang/include/clang/Basic/arm_fp16.td
@@ -14,7 +14,7 @@
 include "arm_neon_incl.td"
 
 // ARMv8.2-A FP16 intrinsics.
-let ArchGuard = "defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC) && defined(__aarch64__)" in {
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "fullfp16" in {
 
   // Negate
   def VNEGSH  : SInst<"vneg", "11", "Sh">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >