[clang] a0d83c3 - Revert "[clang][Diagnostics] Split source ranges into line ranges before..."

2023-06-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-02T09:02:34+02:00
New Revision: a0d83c3dc364688a223e0031d134e2a1bde4ba78

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

LOG: Revert "[clang][Diagnostics] Split source ranges into line ranges 
before..."

This reverts commit fc1262bd58ac54ad0a0bfa9750254b81c742bbb5.

This causes build bot failures because of a parser test case:
https://lab.llvm.org/buildbot/#/builders/139/builds/41961

Added: 


Modified: 
clang/lib/Frontend/TextDiagnostic.cpp
clang/test/Misc/caret-diags-multiline.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index c17508f37c7fd..ad5f1d45cb631 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -945,43 +945,87 @@ maybeAddRange(std::pair A, 
std::pair B,
   return A;
 }
 
-struct LineRange {
-  unsigned LineNo;
-  unsigned StartCol;
-  unsigned EndCol;
-};
+/// Highlight a SourceRange (with ~'s) for any characters on LineNo.
+static void highlightRange(const CharSourceRange &R,
+   unsigned LineNo, FileID FID,
+   const SourceColumnMap &map,
+   std::string &CaretLine,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  if (!R.isValid()) return;
 
-/// Highlight \p R (with ~'s) on the current source line.
-static void highlightRange(const LineRange &R, const SourceColumnMap &Map,
-   std::string &CaretLine) {
-  // Pick the first non-whitespace column.
-  unsigned StartColNo = R.StartCol;
-  while (StartColNo < Map.getSourceLine().size() &&
- (Map.getSourceLine()[StartColNo] == ' ' ||
-  Map.getSourceLine()[StartColNo] == '\t'))
-StartColNo = Map.startOfNextColumn(StartColNo);
-
-  // Pick the last non-whitespace column.
-  unsigned EndColNo =
-  std::min(static_cast(R.EndCol), Map.getSourceLine().size());
-  while (EndColNo && (Map.getSourceLine()[EndColNo - 1] == ' ' ||
-  Map.getSourceLine()[EndColNo - 1] == '\t'))
-EndColNo = Map.startOfPreviousColumn(EndColNo);
-
-  // If the start/end passed each other, then we are trying to highlight a
-  // range that just exists in whitespace. That most likely means we have
-  // a multi-line highlighting range that covers a blank line.
-  if (StartColNo > EndColNo)
-return;
+  SourceLocation Begin = R.getBegin();
+  SourceLocation End = R.getEnd();
+
+  unsigned StartLineNo = SM.getExpansionLineNumber(Begin);
+  if (StartLineNo > LineNo || SM.getFileID(Begin) != FID)
+return;  // No intersection.
+
+  unsigned EndLineNo = SM.getExpansionLineNumber(End);
+  if (EndLineNo < LineNo || SM.getFileID(End) != FID)
+return;  // No intersection.
+
+  // Compute the column number of the start.
+  unsigned StartColNo = 0;
+  if (StartLineNo == LineNo) {
+StartColNo = SM.getExpansionColumnNumber(Begin);
+if (StartColNo) --StartColNo;  // Zero base the col #.
+  }
+
+  // Compute the column number of the end.
+  unsigned EndColNo = map.getSourceLine().size();
+  if (EndLineNo == LineNo) {
+EndColNo = SM.getExpansionColumnNumber(End);
+if (EndColNo) {
+  --EndColNo;  // Zero base the col #.
+
+  // Add in the length of the token, so that we cover multi-char tokens if
+  // this is a token range.
+  if (R.isTokenRange())
+EndColNo += Lexer::MeasureTokenLength(End, SM, LangOpts);
+} else {
+  EndColNo = CaretLine.size();
+}
+  }
+
+  assert(StartColNo <= EndColNo && "Invalid range!");
+
+  // Check that a token range does not highlight only whitespace.
+  if (R.isTokenRange()) {
+// Pick the first non-whitespace column.
+while (StartColNo < map.getSourceLine().size() &&
+   (map.getSourceLine()[StartColNo] == ' ' ||
+map.getSourceLine()[StartColNo] == '\t'))
+  StartColNo = map.startOfNextColumn(StartColNo);
+
+// Pick the last non-whitespace column.
+if (EndColNo > map.getSourceLine().size())
+  EndColNo = map.getSourceLine().size();
+while (EndColNo &&
+   (map.getSourceLine()[EndColNo-1] == ' ' ||
+map.getSourceLine()[EndColNo-1] == '\t'))
+  EndColNo = map.startOfPreviousColumn(EndColNo);
+
+// If the start/end passed each other, then we are trying to highlight a
+// range that just exists in whitespace. That most likely means we have
+// a multi-line highlighting range that covers a blank line.
+if (StartColNo > EndColNo) {
+  assert(StartLineNo != EndLineNo && "trying to highlight whitespace");
+  StartColNo = EndColNo;
+}
+  }
+
+  assert(StartColNo <= map.getSourceLine().size() && "Invalid range!");
+  assert(EndCo

[PATCH] D151876: [NVPTX] Signed char and (unsigned)long overloads of ldg and ldu

2023-06-02 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda added a comment.

In D151876#433 , @tra wrote:

> I'd change the patch title:
>
> - `[NVPTX]` -> `[cuda, NVPTX]` as these are clang changes, not NVPTX back-end.
> - `overloads ` -> `builtins`

Sure, will do. Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151876

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


[clang] 3e37c98 - [cuda, NVPTX] Signed char and (unsigned)long builtins of ldg and ldu

2023-06-02 Thread Jakub Chlanda via cfe-commits

Author: Jakub Chlanda
Date: 2023-06-02T09:10:19+02:00
New Revision: 3e37c98bdb512425cab91f6cf156cc66d6103b2f

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

LOG: [cuda, NVPTX] Signed char and (unsigned)long builtins of ldg and ldu

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-nvptx.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 7ffb38d50a6cf..3275d50a85a4b 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -817,6 +817,7 @@ BUILTIN(__nvvm_compiler_error, "vcC*4", "n")
 BUILTIN(__nvvm_compiler_warn, "vcC*4", "n")
 
 BUILTIN(__nvvm_ldu_c, "ccC*", "")
+BUILTIN(__nvvm_ldu_sc, "ScScC*", "")
 BUILTIN(__nvvm_ldu_s, "ssC*", "")
 BUILTIN(__nvvm_ldu_i, "iiC*", "")
 BUILTIN(__nvvm_ldu_l, "LiLiC*", "")
@@ -833,11 +834,14 @@ BUILTIN(__nvvm_ldu_f, "ffC*", "")
 BUILTIN(__nvvm_ldu_d, "ddC*", "")
 
 BUILTIN(__nvvm_ldu_c2, "E2cE2cC*", "")
+BUILTIN(__nvvm_ldu_sc2, "E2ScE2ScC*", "")
 BUILTIN(__nvvm_ldu_c4, "E4cE4cC*", "")
+BUILTIN(__nvvm_ldu_sc4, "E4ScE4ScC*", "")
 BUILTIN(__nvvm_ldu_s2, "E2sE2sC*", "")
 BUILTIN(__nvvm_ldu_s4, "E4sE4sC*", "")
 BUILTIN(__nvvm_ldu_i2, "E2iE2iC*", "")
 BUILTIN(__nvvm_ldu_i4, "E4iE4iC*", "")
+BUILTIN(__nvvm_ldu_l2, "E2LiE2LiC*", "")
 BUILTIN(__nvvm_ldu_ll2, "E2LLiE2LLiC*", "")
 
 BUILTIN(__nvvm_ldu_uc2, "E2UcE2UcC*", "")
@@ -846,6 +850,7 @@ BUILTIN(__nvvm_ldu_us2, "E2UsE2UsC*", "")
 BUILTIN(__nvvm_ldu_us4, "E4UsE4UsC*", "")
 BUILTIN(__nvvm_ldu_ui2, "E2UiE2UiC*", "")
 BUILTIN(__nvvm_ldu_ui4, "E4UiE4UiC*", "")
+BUILTIN(__nvvm_ldu_ul2, "E2ULiE2ULiC*", "")
 BUILTIN(__nvvm_ldu_ull2, "E2ULLiE2ULLiC*", "")
 
 BUILTIN(__nvvm_ldu_h2, "E2hE2hC*", "")
@@ -854,6 +859,7 @@ BUILTIN(__nvvm_ldu_f4, "E4fE4fC*", "")
 BUILTIN(__nvvm_ldu_d2, "E2dE2dC*", "")
 
 BUILTIN(__nvvm_ldg_c, "ccC*", "")
+BUILTIN(__nvvm_ldg_sc, "ScScC*", "")
 BUILTIN(__nvvm_ldg_s, "ssC*", "")
 BUILTIN(__nvvm_ldg_i, "iiC*", "")
 BUILTIN(__nvvm_ldg_l, "LiLiC*", "")
@@ -870,11 +876,14 @@ BUILTIN(__nvvm_ldg_f, "ffC*", "")
 BUILTIN(__nvvm_ldg_d, "ddC*", "")
 
 BUILTIN(__nvvm_ldg_c2, "E2cE2cC*", "")
+BUILTIN(__nvvm_ldg_sc2, "E2ScE2ScC*", "")
 BUILTIN(__nvvm_ldg_c4, "E4cE4cC*", "")
+BUILTIN(__nvvm_ldg_sc4, "E4ScE4ScC*", "")
 BUILTIN(__nvvm_ldg_s2, "E2sE2sC*", "")
 BUILTIN(__nvvm_ldg_s4, "E4sE4sC*", "")
 BUILTIN(__nvvm_ldg_i2, "E2iE2iC*", "")
 BUILTIN(__nvvm_ldg_i4, "E4iE4iC*", "")
+BUILTIN(__nvvm_ldg_l2, "E2LiE2LiC*", "")
 BUILTIN(__nvvm_ldg_ll2, "E2LLiE2LLiC*", "")
 
 BUILTIN(__nvvm_ldg_uc2, "E2UcE2UcC*", "")
@@ -883,6 +892,7 @@ BUILTIN(__nvvm_ldg_us2, "E2UsE2UsC*", "")
 BUILTIN(__nvvm_ldg_us4, "E4UsE4UsC*", "")
 BUILTIN(__nvvm_ldg_ui2, "E2UiE2UiC*", "")
 BUILTIN(__nvvm_ldg_ui4, "E4UiE4UiC*", "")
+BUILTIN(__nvvm_ldg_ul2, "E2ULiE2ULiC*", "")
 BUILTIN(__nvvm_ldg_ull2, "E2ULLiE2ULLiC*", "")
 
 BUILTIN(__nvvm_ldg_h2, "E2hE2hC*", "")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3a61fdd65592a..bfa6fd716c5ec 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18422,8 +18422,11 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   }
 
   case NVPTX::BI__nvvm_ldg_c:
+  case NVPTX::BI__nvvm_ldg_sc:
   case NVPTX::BI__nvvm_ldg_c2:
+  case NVPTX::BI__nvvm_ldg_sc2:
   case NVPTX::BI__nvvm_ldg_c4:
+  case NVPTX::BI__nvvm_ldg_sc4:
   case NVPTX::BI__nvvm_ldg_s:
   case NVPTX::BI__nvvm_ldg_s2:
   case NVPTX::BI__nvvm_ldg_s4:
@@ -18431,6 +18434,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_ldg_i2:
   case NVPTX::BI__nvvm_ldg_i4:
   case NVPTX::BI__nvvm_ldg_l:
+  case NVPTX::BI__nvvm_ldg_l2:
   case NVPTX::BI__nvvm_ldg_ll:
   case NVPTX::BI__nvvm_ldg_ll2:
   case NVPTX::BI__nvvm_ldg_uc:
@@ -18443,6 +18447,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_ldg_ui2:
   case NVPTX::BI__nvvm_ldg_ui4:
   case NVPTX::BI__nvvm_ldg_ul:
+  case NVPTX::BI__nvvm_ldg_ul2:
   case NVPTX::BI__nvvm_ldg_ull:
   case NVPTX::BI__nvvm_ldg_ull2:
 // PTX Interoperability section 2.2: "For a vector with an even number of
@@ -18457,8 +18462,11 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
 return MakeLdgLdu(Intrinsic::nvvm_ldg_global_f, *this, E);
 
   case NVPTX::BI__nvvm_ldu_c:
+  case NVPTX::BI__nvvm_ldu_sc:
   case NVPTX::BI__nvvm_ldu_c2:
+  case NVPTX::BI__nvvm_ldu_sc2:
   case NVPTX::BI__nvvm_ldu_c4:
+  case NVPTX::BI__nvvm_ldu_sc4:
   case NVPTX::BI__nvvm_ldu_s:
   case NVPTX::BI__nvvm_ldu_s2:
   case NVPTX::BI__nvvm_ldu_s4:
@@ -18466,6 +18474,7 @@ Value *Cod

[PATCH] D151876: [NVPTX] Signed char and (unsigned)long overloads of ldg and ldu

2023-06-02 Thread Jakub Chlanda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e37c98bdb51: [cuda, NVPTX] Signed char and (unsigned)long 
builtins of ldg and ldu (authored by jchlanda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151876

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx.c

Index: clang/test/CodeGen/builtins-nvptx.c
===
--- clang/test/CodeGen/builtins-nvptx.c
+++ clang/test/CodeGen/builtins-nvptx.c
@@ -554,10 +554,12 @@
 
 // CHECK-LABEL: nvvm_ldg
 __device__ void nvvm_ldg(const void *p) {
+  // CHECK: call i8 @llvm.nvvm.ldg.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldg.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldg.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   __nvvm_ldg_c((const char *)p);
   __nvvm_ldg_uc((const unsigned char *)p);
+  __nvvm_ldg_sc((const signed char *)p);
 
   // CHECK: call i16 @llvm.nvvm.ldg.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call i16 @llvm.nvvm.ldg.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
@@ -590,19 +592,25 @@
   // elements, its alignment is set to number of elements times the alignment of
   // its member: n*alignof(t)."
 
+  // CHECK: call <2 x i8> @llvm.nvvm.ldg.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldg.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldg.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   typedef char char2 __attribute__((ext_vector_type(2)));
   typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
+  typedef signed char schar2 __attribute__((ext_vector_type(2)));
   __nvvm_ldg_c2((const char2 *)p);
   __nvvm_ldg_uc2((const uchar2 *)p);
+  __nvvm_ldg_sc2((const schar2 *)p);
 
+  // CHECK: call <4 x i8> @llvm.nvvm.ldg.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <4 x i8> @llvm.nvvm.ldg.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <4 x i8> @llvm.nvvm.ldg.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   typedef char char4 __attribute__((ext_vector_type(4)));
   typedef unsigned char uchar4 __attribute__((ext_vector_type(4)));
+  typedef signed char schar4 __attribute__((ext_vector_type(4)));
   __nvvm_ldg_c4((const char4 *)p);
   __nvvm_ldg_uc4((const uchar4 *)p);
+  __nvvm_ldg_sc4((const schar4 *)p);
 
   // CHECK: call <2 x i16> @llvm.nvvm.ldg.global.i.v2i16.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <2 x i16> @llvm.nvvm.ldg.global.i.v2i16.p0(ptr {{%[0-9]+}}, i32 4)
@@ -632,6 +640,15 @@
   __nvvm_ldg_i4((const int4 *)p);
   __nvvm_ldg_ui4((const uint4 *)p);
 
+  // LP32: call <2 x i32> @llvm.nvvm.ldg.global.i.v2i32.p0(ptr {{%[0-9]+}}, i32 8)
+  // LP32: call <2 x i32> @llvm.nvvm.ldg.global.i.v2i32.p0(ptr {{%[0-9]+}}, i32 8)
+  // LP64: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
+  // LP64: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
+  typedef long long2 __attribute__((ext_vector_type(2)));
+  typedef unsigned long ulong2 __attribute__((ext_vector_type(2)));
+  __nvvm_ldg_l2((const long2 *)p);
+  __nvvm_ldg_ul2((const ulong2 *)p);
+
   // CHECK: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
   // CHECK: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
   typedef long long longlong2 __attribute__((ext_vector_type(2)));
@@ -654,10 +671,12 @@
 
 // CHECK-LABEL: nvvm_ldu
 __device__ void nvvm_ldu(const void *p) {
+  // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   __nvvm_ldu_c((const char *)p);
   __nvvm_ldu_uc((const unsigned char *)p);
+  __nvvm_ldu_sc((const signed char *)p);
 
   // CHECK: call i16 @llvm.nvvm.ldu.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call i16 @llvm.nvvm.ldu.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
@@ -681,19 +700,25 @@
   // CHECK: call double @llvm.nvvm.ldu.global.f.f64.p0(ptr {{%[0-9]+}}, i32 8)
   __nvvm_ldu_d((const double *)p);
 
+  // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   typedef char char2 __attribute__((ext_vector_type(2)));
   typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
+  typedef signed char schar2 __attribute__((ext_vector_type(2)));
   __nvvm_ldu_c2((const char2 *)p);
   __nvvm_ldu_uc2((const uchar2 *)p);
+  __nvvm_ldu_sc2((const schar2 *)p);
 
+  // CHECK: call <4 x i8> @llvm.nvvm.ldu.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <4 x i8> @llvm.nvvm.ldu.global.i.v4i8.p0(ptr {{%[0-

[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse updated this revision to Diff 527764.
akshaykhadse added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

Files:
  clang/test/CodeGen/ms-inline-asm-64.c
  clang/test/CodeGen/ms-inline-asm.c
  llvm/lib/Target/X86/AsmParser/X86Operand.h
  llvm/test/MC/X86/x86-64-movdir64b-intel.s


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel 
-output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -383,6 +383,9 @@
   bool isMem512_GR16() const {
 if (!isMem512())
   return false;
+if (getMemBaseReg() == X86::AH) {
+  return true;
+}
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR16RegClassID].contains(getMemBaseReg()))
   return false;
@@ -391,27 +394,33 @@
   bool isMem512_GR32() const {
 if (!isMem512())
   return false;
-if (getMemBaseReg() &&
-!X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemBaseReg()) &&
-getMemBaseReg() != X86::EIP)
-  return false;
 if (getMemIndexReg() &&
 !X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemIndexReg()) 
&&
 getMemIndexReg() != X86::EIZ)
   return false;
+if (getMemBaseReg() == X86::AH) {
+  return true;
+}
+if (getMemBaseReg() &&
+!X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemBaseReg()) &&
+getMemBaseReg() != X86::EIP)
+  return false;
 return true;
   }
   bool isMem512_GR64() const {
 if (!isMem512())
   return false;
-if (getMemBaseReg() &&
-!X86MCRegisterClasses[X86::GR64RegClassID].contains(getMemBaseReg()) &&
-getMemBaseReg() != X86::RIP)
-  return false;
 if (getMemIndexReg() &&
 !X86MCRegisterClasses[X86::GR64RegClassID].contains(getMemIndexReg()) 
&&
 getMemIndexReg() != X86::RIZ)
   return false;
+if (getMemBaseReg() == X86::AH) {
+  return true;
+}
+if (getMemBaseReg() &&
+!X86MCRegisterClasses[X86::GR64RegClassID].contains(getMemBaseReg()) &&
+getMemBaseReg() != X86::RIP)
+  return false;
 return true;
   }
 
Index: clang/test/CodeGen/ms-inline-asm.c
===
--- clang/test/CodeGen/ms-inline-asm.c
+++ clang/test/CodeGen/ms-inline-asm.c
@@ -675,6 +675,13 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", 
"~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm movdir64b eax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "movdir64b eax, zmmword ptr 
$0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) %arr)
+}
+
 void dot_operator(void){
   // CHECK-LABEL: define{{.*}} void @dot_operator
__asm { mov eax, 3[ebx]A.b}
Index: clang/test/CodeGen/ms-inline-asm-64.c
===
--- clang/test/CodeGen/ms-inline-asm-64.c
+++ clang/test/CodeGen/ms-inline-asm-64.c
@@ -72,3 +72,10 @@
   // CHECK-SAME: jmp ${1:P}
   // CHECK-SAME: "*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(void 
(...)) @bar, ptr elementtype(void (...)) @bar)
 }
+
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm movdir64b rax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "movdir64b rax, zmmword ptr 
$0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) %arr)
+}


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -383,6 +383,9 @@
   bool isMem512_GR16() const {
 if (!isMem512())
   return false;
+if (getMemBaseReg() == X86::AH)

[PATCH] D151215: [clang][Diagnostics] Split source ranges into line ranges before...

2023-06-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 527766.
tbaeder added a comment.

@cor3ntin I added changes to the two brackets tests in `test/Parser/`. They 
look like an improvement to me, but maybe there's something I'm missing, so 
please have a quick look.


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

https://reviews.llvm.org/D151215

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Misc/caret-diags-multiline.cpp
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp

Index: clang/test/Parser/brackets.cpp
===
--- clang/test/Parser/brackets.cpp
+++ clang/test/Parser/brackets.cpp
@@ -33,7 +33,7 @@
   int [3] (*a) = 0;
   // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
   // CHECK: {{^}}  int [3] (*a) = 0;
-  // CHECK: {{^}}  ^
+  // CHECK: {{^}}  ~~~ ^
   // CHECK: {{^}}  [3]
   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[3]"
@@ -67,7 +67,7 @@
 int [5] *B::x = 0;
 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
 // CHECK: {{^}}int [5] *B::x = 0;
-// CHECK: {{^}} ^
+// CHECK: {{^}}~~~  ^
 // CHECK: {{^}}()[5]
 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""
 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:9-[[@LINE-6]]:9}:"("
@@ -77,7 +77,7 @@
   int [3] *a;
   // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
   // CHECK: {{^}}  int [3] *a;
-  // CHECK: {{^}}    ^
+  // CHECK: {{^}}  ~~~   ^
   // CHECK: {{^}}  ( )[3]
   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
@@ -90,7 +90,7 @@
   int [2] a;
   // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
   // CHECK: {{^}}  int [2] a;
-  // CHECK: {{^}}   ^
+  // CHECK: {{^}}  ~~~  ^
   // CHECK: {{^}}   [2]
   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:12-[[@LINE-6]]:12}:"[2]"
@@ -98,7 +98,7 @@
   int [2] &b = a;
   // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
   // CHECK: {{^}}  int [2] &b = a;
-  // CHECK: {{^}}    ^
+  // CHECK: {{^}}  ~~~   ^
   // CHECK: {{^}}  ( )[2]
   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
@@ -130,7 +130,7 @@
 int [3] ::test6::A::arr = {1,2,3};
 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
 // CHECK: {{^}}int [3] ::test6::A::arr = {1,2,3};
-// CHECK: {{^}}   ^
+// CHECK: {{^}}~~~^
 // CHECK: {{^}}   [3]
 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""
 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:24-[[@LINE-6]]:24}:"[3]"
@@ -143,7 +143,7 @@
   int [3] A::*a;
   // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}
   // CHECK: {{^}}  int [3] A::*a;
-  // CHECK: {{^}}   ^
+  // CHECK: {{^}}  ~~~  ^
   // CHECK: {{^}}  ()[3]
   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
Index: clang/test/Parser/brackets.c
===
--- clang/test/Parser/brackets.c
+++ clang/test/Parser/brackets.c
@@ -55,7 +55,7 @@
   // CHECK-NOT: fix-it
   // expected-error@-5{{brackets are not allowed here; to declare an array, place the brackets after the identifier}}
   // CHECK: {{^}}  int [5] *;
-  // CHECK: {{^}}   ^
+  // CHECK: {{^}}  ~~~  ^
   // CHECK: {{^}}  ()[5]
   // CHECK: fix-it:{{.*}}:{[[@LINE-9]]:7-[[@LINE-9]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-10]]:11-[[@LINE-10]]:11}:"("
@@ -64,7 +64,7 @@
   int [5] * a;
   // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the identifier}}
   // CHECK: {{^}}  int [5] * a;
-  // CHECK: {{^}}     ^
+  // CHECK: {{^}}  ~~~^
   // CHECK: {{^}}  (  )[5]
   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
Index: clang/test/Misc/caret-diags-multiline.cpp
===
--- clang/test/Misc/caret-diags-multiline.cpp
+++ clang/test/Misc/caret-diags-multiline.cpp
@@ -14,9 +14,9 @@
 // CHECK-NEXT: {{^}}  if (cond) {
 // CHECK-NEXT: {{^}}  ^~~{{$}}
 // CHECK-NEXT: {{^}}line(1);
-// CHECK-NEXT: {{^}}{{$}}
+// CHECK-NEXT: {{^}}{{

[PATCH] D151954: [clang-format] Fix overlapping whitespace replacements before PPDirective

2023-06-02 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 527765.
owenpan added a comment.

Removed the `RootToken` parameter.


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

https://reviews.llvm.org/D151954

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12856,6 +12856,22 @@
"  void f() {}\n"
"};\n",
Style);
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "#endif\n"
+   "};",
+   "struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "\n"
+   "#endif\n"
+   "};",
+   Style);
 
   Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
   verifyFormat("struct foo {\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,19 +1418,12 @@
   return Penalty;
 }
 
-void UnwrappedLineFormatter::formatFirstToken(
-const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl &Lines, unsigned Indent,
-unsigned NewlineIndent) {
-  FormatToken &RootToken = *Line.First;
-  if (RootToken.is(tok::eof)) {
-unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
-unsigned TokenIndent = Newlines ? NewlineIndent : 0;
-Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
-   TokenIndent);
-return;
-  }
+static auto newlinesBeforeLine(const AnnotatedLine &Line,
+   const AnnotatedLine *PreviousLine,
+   const AnnotatedLine *PrevPrevLine,
+   const SmallVectorImpl &Lines,
+   const FormatStyle &Style) {
+  const auto &RootToken = *Line.First;
   unsigned Newlines =
   std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
   // Remove empty lines before "}" where applicable.
@@ -1510,6 +1503,27 @@
 }
   }
 
+  return Newlines;
+}
+
+void UnwrappedLineFormatter::formatFirstToken(
+const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl &Lines, unsigned Indent,
+unsigned NewlineIndent) {
+  FormatToken &RootToken = *Line.First;
+  if (RootToken.is(tok::eof)) {
+unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
+unsigned TokenIndent = Newlines ? NewlineIndent : 0;
+Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
+   TokenIndent);
+return;
+  }
+
+  const auto Newlines =
+  RootToken.Finalized
+  ? RootToken.NewlinesBefore
+  : newlinesBeforeLine(Line, PreviousLine, PrevPrevLine, Lines, Style);
   if (Newlines)
 Indent = NewlineIndent;
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12856,6 +12856,22 @@
"  void f() {}\n"
"};\n",
Style);
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "#endif\n"
+   "};",
+   "struct foo {\n"
+   "#ifdef FOO\n"
+   "#else\n"
+   "private:\n"
+   "\n"
+   "\n"
+   "#endif\n"
+   "};",
+   Style);
 
   Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
   verifyFormat("struct foo {\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1418,19 +1418,12 @@
   return Penalty;
 }
 
-void UnwrappedLineFormatter::formatFirstToken(
-const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl &Lines, unsigned Indent,
-unsigned NewlineIndent) {
-  FormatToken &RootToken = *Line.First;
-  if (RootToken.is(tok::eof)) {
-unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u);
-unsigned TokenIndent = Newlines ? NewlineIndent : 0;
-Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
-   TokenIndent);
-return;
-  

[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse added a comment.

If we could get rid of `BaseReg = BaseReg ? BaseReg : 1;` in 
`X86AsmParser::CreateMemForMSInlineAsm`, then we don't need any changes in the 
`X86Operand.h`.
F27787125: image.png 

I was not able to find any failing tests after making the change. But, this has 
existed for 11 years in the codebase, so I am not sure if making this change 
will break things in unexpected ways. Let me know what you think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

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


[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I still think replacing the `1` with a valid register for the mode is the 
better fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

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


[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Wang, Xin via Phabricator via cfe-commits
XinWang10 added a comment.

In D151863#4390132 , @craig.topper 
wrote:

> I still think replacing the `1` with a valid register for the mode is the 
> better fix.

But if you give that, we couldn't take a mem operand without base reg.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

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


[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse added a comment.

In D151863#4390132 , @craig.topper 
wrote:

> I still think replacing the `1` with a valid register for the mode is the 
> better fix.

So, should I create a new registers? Something like `X86::Sym16`, `X86::Sym32` 
and `X86::Sym64`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

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


[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D151863#4390172 , @akshaykhadse 
wrote:

> In D151863#4390132 , @craig.topper 
> wrote:
>
>> I still think replacing the `1` with a valid register for the mode is the 
>> better fix.
>
> So, should I create a new registers? Something like `X86::Sym16`, 
> `X86::Sym32` and `X86::Sym64`?

Use RAX and EAX and AX. It just needs to have the right size.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

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


[PATCH] D149946: [LoongArch] Define `ual` feature and override `allowsMisalignedMemoryAccesses`

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

I've thought about this a bit harder; it now seems better longer-term to enable 
unaligned accesses by default (making the UAL-less models the special case).

But most importantly, there's new information suggesting that UAL support is to 
become ubiquitous in the future. A sample `/proc/cpuinfo` output on a Loongson 
2K2000 (LA364 uarch) recently is circulated in various user groups 
(unfortunately there doesn't seem to be a public link), that clearly shows 
LA364 has UAL. So this very likely means all future Loongson-2 series will 
feature UAL, and that the non-UAL case is to gradually become less relevant.

Also, in some cases (distro packaging, mesa llvmpipe, etc.) it may not be as 
easy to specify `march` flags, but we may want to assume a more popular model 
nevertheless. Again the UAL-less models should be seen as special cases and get 
adapted individually later.

With the reasoning becoming clear, the LoongArch target part of the change 
LGTM; thanks for taking care of this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149946

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks, a few comments to simplify the code/test further.




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:94
+/// shortest spelling.
+std::string spellHeader(const IncludeSpellerInput &Input);
 } // namespace include_cleaner

can you move it to the `IncludeSpeller.h` file? I think it is a more suitable 
place.





Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h:22
+/// Provides the necessary information for custom spelling computations.
+struct IncludeSpellerInput {
+  const Header &H;

This struct is the input for the IncludeSpeller interface, thus I prefer to 
move the structure to IncludeSpeller class, and call it `Input`. 



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:83
 
-std::string spellHeader(const Header &H, HeaderSearch &HS,
-const FileEntry *Main) {
+std::string spellHeader(const IncludeSpellerInput &Input) {
+  const Header &H = Input.H;

similar to .h file, I think we should move this implementation to the 
`IncludeSpeller.cpp` file.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:96
+
+// Fallback to default spelling via header search.
+bool IsSystem = false;

I think it may be clearer to make this fallback spelling implementation as a 
`DefaultIncludeSpeller` class, and append it to the end of `Spellers` (but not 
register it to make sure it always the last one of the spelling 
IncludeSpellingStrategy). 

The code looks like 

```
class DefaultIncludeSpeller : IncludeSpeller {
   ...
};
std::string mapHeader(const IncludeSpellerInput &Input) {
  static auto Spellers = [] {
auto Result =
llvm::SmallVector>{};
for (const auto &Strategy :
 include_cleaner::IncludeSpellingStrategy::entries())
  Result.push_back(Strategy.instantiate());
Result.push_back(std::make_unique());
return Result;
  }();
  
}

std::string spellerHeader(...) {
   ...
   case Header::Physical:
  return mapHeader(Input);
}
```



Comment at: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp:2
+//===--- IncludeSpellerTest.cpp
+//-===//
+//

line: line 1 and line 2 should be merged into a single line.



Comment at: 
clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp:60
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";

nit: inline the Result.

```
if (!AbsolutePath.consume_front())
  return "";
return "\"" + AbsolutePath.str() + "\"";
```



Comment at: 
clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp:81
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));

I think there should be `""` around the `foo.h`, the `spellHeader` API returns 
the spelling contains the ""<> characters, so we need to add "" to the result 
in the `DummyIncludeSpeller::operator()` method.



Comment at: 
clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp:90
+   HS, MainFile}));
+  EXPECT_EQ("\"foo/bar.h\"",
+spellHeader({Header{*FM.getFile("foo/bar.h")}, HS, MainFile}));

I think the unittest is mainly for testing our llvm-registry mechanism work by 
verifying DummyIncludeSpeller is used for file path starting with 
`clangd-test`, and fallback one is used otherwise. 

we're less interested in the the different file separator per platform. Let's 
try to simplify the unittest to avoid subtle platform issues, something like 
below should cover the thing we want:

```
Inputs.ExtraFiles["/include-cleaner-test/foo.h"] = "";
Inputs.ExtraFiles["system_header.h"] = "";

Inputs.ExtraFlags = {"-isystem."};
...

EXPECT_EQ("\"foo.h\"",
spellHeader({Header{*FM.getFile("foo.h")}, HS, MainFile})); // 
spelled by the dummerIncludeSpeller.
EXPECT_EQ("",
spellHeader({Header{*FM.getFile("system_header.h")}, HS, 
MainFile})); // spelled by the fallback one.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

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


[PATCH] D151730: [RISCV] Support target attribute for function

2023-06-02 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/test/CodeGen/RISCV/riscv-func-attr-target.c:10
+// CHECK-ASM: .option pop
+__attribute__((target("arch=rv64g,+c,+v"))) void test1 () {}
+

It's ext list or full arch, can't mixed together.

```
ARCH-ATTR   := 'arch=' EXTENSIONS-OR-FULLARCH
EXTENSIONS-OR-FULLARCH := 
| 
```



Comment at: clang/test/CodeGen/RISCV/riscv-func-attr-target.c:34
+// CHECK-ASM: .option pop
+__attribute__((target("arch=+experimental-zihintntl"))) void test5 () {}
+

The extension name is `zihintntl` not `experimental-zihintntl`, I would suggest 
either drop the experimental extension support or requiring the version number 
to be specified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151730

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro added a comment.

In D151833#4386128 , @tbaeder wrote:

> Can you add a test case for the change? Looks like there's something similar 
> already in `clang/test/Frontend/absolute-paths.c`

Is it possible to use substitutions inside let's say `NORMAL: `? How could I 
resolve the absolute path without hard-coding my path inside the test case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151833

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


[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse updated this revision to Diff 527783.
akshaykhadse added a comment.

Implement solution mentioned in comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

Files:
  clang/test/CodeGen/ms-inline-asm-64.c
  clang/test/CodeGen/ms-inline-asm.c
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/test/MC/X86/x86-64-movdir64b-intel.s


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel 
-output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1777,9 +1777,21 @@
 return false;
   }
   // Otherwise, we set the base register to a non-zero value
-  // if we don't know the actual value at this time.  This is necessary to
+  // if we don't know the actual value at this time. This is necessary to
   // get the matching correct in some cases.
-  BaseReg = BaseReg ? BaseReg : 1;
+  if (BaseReg == X86::NoRegister) {
+switch (getPointerWidth()) {
+  case 16:
+BaseReg = X86::AX;
+break;
+  case 32:
+BaseReg = X86::EAX;
+break;
+  case 64:
+BaseReg = X86::RAX;
+break;
+}
+  }
   Operands.push_back(X86Operand::CreateMem(
   getPointerWidth(), SegReg, Disp, BaseReg, IndexReg, Scale, Start, End,
   Size,
Index: clang/test/CodeGen/ms-inline-asm.c
===
--- clang/test/CodeGen/ms-inline-asm.c
+++ clang/test/CodeGen/ms-inline-asm.c
@@ -675,6 +675,13 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", 
"~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm movdir64b eax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "movdir64b eax, zmmword ptr 
$0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) %arr)
+}
+
 void dot_operator(void){
   // CHECK-LABEL: define{{.*}} void @dot_operator
__asm { mov eax, 3[ebx]A.b}
Index: clang/test/CodeGen/ms-inline-asm-64.c
===
--- clang/test/CodeGen/ms-inline-asm-64.c
+++ clang/test/CodeGen/ms-inline-asm-64.c
@@ -72,3 +72,10 @@
   // CHECK-SAME: jmp ${1:P}
   // CHECK-SAME: "*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(void 
(...)) @bar, ptr elementtype(void (...)) @bar)
 }
+
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm movdir64b rax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "movdir64b rax, zmmword ptr 
$0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) %arr)
+}


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1777,9 +1777,21 @@
 return false;
   }
   // Otherwise, we set the base register to a non-zero value
-  // if we don't know the actual value at this time.  This is necessary to
+  // if we don't know the actual value at this time. This is necessary to
   // get the matching correct in some cases.
-  BaseReg = BaseReg ? BaseReg : 1;
+  if (BaseReg == X86::NoRegister) {
+switch (getPointerWidth()) {
+  case 16:
+BaseReg = X86::AX;
+break;
+  case 32:
+BaseReg = X86::EAX;
+break;
+  case 64:
+BaseReg = X86::RAX;
+break;
+}
+  }
   Operands.push_back(X86Operand::CreateMem(
   getPointerWidth(), SegReg, Disp, BaseReg, IndexReg, Scale, Start, End,
   Size,
Index: clang/test/CodeGen/ms-inline-asm.c
===
--- clang/test/CodeGen/ms-inline-asm.c
+++ clang/test/CodeGen/ms-inline-asm.c
@@ -675,6 +675,13 @@
   // CHECK: call void asm sideeffect inteldiale

[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-02 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse updated this revision to Diff 527797.
akshaykhadse added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

Files:
  clang/test/CodeGen/ms-inline-asm-64.c
  clang/test/CodeGen/ms-inline-asm.c
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/test/MC/X86/x86-64-movdir64b-intel.s


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel 
-output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1777,9 +1777,21 @@
 return false;
   }
   // Otherwise, we set the base register to a non-zero value
-  // if we don't know the actual value at this time.  This is necessary to
+  // if we don't know the actual value at this time. This is necessary to
   // get the matching correct in some cases.
-  BaseReg = BaseReg ? BaseReg : 1;
+  if (BaseReg == X86::NoRegister) {
+switch (getPointerWidth()) {
+case 16:
+  BaseReg = X86::AX;
+  break;
+case 32:
+  BaseReg = X86::EAX;
+  break;
+case 64:
+  BaseReg = X86::RAX;
+  break;
+}
+  }
   Operands.push_back(X86Operand::CreateMem(
   getPointerWidth(), SegReg, Disp, BaseReg, IndexReg, Scale, Start, End,
   Size,
Index: clang/test/CodeGen/ms-inline-asm.c
===
--- clang/test/CodeGen/ms-inline-asm.c
+++ clang/test/CodeGen/ms-inline-asm.c
@@ -675,6 +675,13 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", 
"~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm movdir64b eax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "movdir64b eax, zmmword ptr 
$0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) %arr)
+}
+
 void dot_operator(void){
   // CHECK-LABEL: define{{.*}} void @dot_operator
__asm { mov eax, 3[ebx]A.b}
Index: clang/test/CodeGen/ms-inline-asm-64.c
===
--- clang/test/CodeGen/ms-inline-asm-64.c
+++ clang/test/CodeGen/ms-inline-asm-64.c
@@ -72,3 +72,10 @@
   // CHECK-SAME: jmp ${1:P}
   // CHECK-SAME: "*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(void 
(...)) @bar, ptr elementtype(void (...)) @bar)
 }
+
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm movdir64b rax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "movdir64b rax, zmmword ptr 
$0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) %arr)
+}


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1777,9 +1777,21 @@
 return false;
   }
   // Otherwise, we set the base register to a non-zero value
-  // if we don't know the actual value at this time.  This is necessary to
+  // if we don't know the actual value at this time. This is necessary to
   // get the matching correct in some cases.
-  BaseReg = BaseReg ? BaseReg : 1;
+  if (BaseReg == X86::NoRegister) {
+switch (getPointerWidth()) {
+case 16:
+  BaseReg = X86::AX;
+  break;
+case 32:
+  BaseReg = X86::EAX;
+  break;
+case 64:
+  BaseReg = X86::RAX;
+  break;
+}
+  }
   Operands.push_back(X86Operand::CreateMem(
   getPointerWidth(), SegReg, Disp, BaseReg, IndexReg, Scale, Start, End,
   Size,
Index: clang/test/CodeGen/ms-inline-asm.c
===
--- clang/test/CodeGen/ms-inline-asm.c
+++ clang/test/CodeGen/ms-inline-asm.c
@@ -675,6 +675,13 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", "~{eax},~{flags},~{dirflag},~{fp

[clang-tools-extra] be8da1f - [clangd] Use FileManager for getCanonicalPath, NFC

2023-06-02 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-02T12:55:21+02:00
New Revision: be8da1f6e68603fd49ee7faa7c309f44f5b1a8b2

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

LOG: [clangd] Use FileManager for getCanonicalPath, NFC

get rid of the SourceManager dependency -- getCanonicalPath doesn't use
other SourceManager fields.

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/indexer/IndexerMain.cpp
clang-tools-extra/clangd/refactor/Tweak.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 4c5def3063f1..bae528a105c8 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -710,7 +710,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
 auto FID = SM.getFileID(Info.getLocation());
 if (const auto FE = SM.getFileEntryRefForID(FID)) {
   D.File = FE->getName().str();
-  D.AbsFile = getCanonicalPath(*FE, SM);
+  D.AbsFile = getCanonicalPath(*FE, SM.getFileManager());
 }
 D.ID = Info.getID();
 return D;

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 18be1329f1fa..a3e08bc56b31 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -336,7 +336,7 @@ std::string spellHeader(ParsedAST &AST, const FileEntry 
*MainFile,
 include_cleaner::Header Provider) {
   if (Provider.kind() == include_cleaner::Header::Physical) {
 if (auto CanonicalPath = 
getCanonicalPath(Provider.physical()->getLastRef(),
-  AST.getSourceManager())) {
+  
AST.getSourceManager().getFileManager())) {
   std::string SpelledHeader =
   llvm::cantFail(URI::includeSpelling(URI::create(*CanonicalPath)));
   if (!SpelledHeader.empty())

diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 831adc3d5fd8..c460ae307f11 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -514,11 +514,11 @@ std::vector replacementsToEdits(llvm::StringRef 
Code,
 }
 
 std::optional getCanonicalPath(const FileEntryRef F,
-const SourceManager &SourceMgr) {
+FileManager &FileMgr) {
   llvm::SmallString<128> FilePath = F.getName();
   if (!llvm::sys::path::is_absolute(FilePath)) {
 if (auto EC =
-SourceMgr.getFileManager().getVirtualFileSystem().makeAbsolute(
+FileMgr.getVirtualFileSystem().makeAbsolute(
 FilePath)) {
   elog("Could not turn relative path '{0}' to absolute: {1}", FilePath,
EC.message());
@@ -537,10 +537,10 @@ std::optional getCanonicalPath(const 
FileEntryRef F,
   //
   //  The file path of Symbol is "/project/src/foo.h" instead of
   //  "/tmp/build/foo.h"
-  if (auto Dir = SourceMgr.getFileManager().getDirectory(
+  if (auto Dir = FileMgr.getDirectory(
   llvm::sys::path::parent_path(FilePath))) {
 llvm::SmallString<128> RealPath;
-llvm::StringRef DirName = 
SourceMgr.getFileManager().getCanonicalName(*Dir);
+llvm::StringRef DirName = FileMgr.getCanonicalName(*Dir);
 llvm::sys::path::append(RealPath, DirName,
 llvm::sys::path::filename(FilePath));
 return RealPath.str().str();

diff  --git a/clang-tools-extra/clangd/SourceCode.h 
b/clang-tools-extra/clangd/SourceCode.h
index 8b7c028eb247..3ba6f8b80ef3 100644
--- a/clang-tools-extra/clangd/SourceCode.h
+++ b/clang-tools-extra/clangd/SourceCode.h
@@ -164,7 +164,7 @@ TextEdit toTextEdit(const FixItHint &FixIt, const 
SourceManager &M,
 /// component that generate it, so that paths are normalized as much as
 /// possible.
 std::optional getCanonicalPath(const FileEntryRef F,
-const SourceManager &SourceMgr);
+FileManager &FileMgr);
 
 /// Choose the clang-format style we should apply to a certain file.
 /// This will usually use FS to look for .clang-format directories.

diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 51a3ef894c54..ad4819fe4b4d 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -

[PATCH] D143241: [Clang] Reset FP options before function instantiations

2023-06-02 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 527800.
sepavloff added a comment.

Use FPOptions from the place where template is defined rather than default


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143241

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CodeGen/fp-template.cpp


Index: clang/test/CodeGen/fp-template.cpp
===
--- clang/test/CodeGen/fp-template.cpp
+++ clang/test/CodeGen/fp-template.cpp
@@ -15,4 +15,40 @@
 // CHECK-SAME:  (float noundef %{{.*}}, float noundef %{{.*}}) 
#[[ATTR01:[0-9]+]]{{.*}} {
 // CHECK:   call float @llvm.experimental.constrained.fadd.f32
 
+
+template 
+Ty templ_02(Ty x, Ty y) {
+  return x + y;
+}
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+template 
+Ty templ_03(Ty x, Ty y) {
+  return x - y;
+}
+
+#pragma STDC FENV_ROUND FE_TONEAREST
+
+float func_02(float x, float y) {
+  return templ_02(x, y);
+}
+
+// CHECK-LABEL: define {{.*}} float @_Z8templ_02IfET_S0_S0_
+// CHECK:   %add = fadd float %0, %1
+
+float func_03(float x, float y) {
+  return templ_03(x, y);
+}
+
+// CHECK-LABEL: define {{.*}} float @_Z8templ_03IfET_S0_S0_
+// CHECK:   call float @llvm.experimental.constrained.fsub.f32({{.*}}, 
metadata !"round.upward", metadata !"fpexcept.ignore")
+
+
+// This pragma sets non-default rounding mode before delayed parsing occurs. It
+// is used to check that the parsing uses FP options defined by command line
+// options or by pragma before the template definition but not by this pragma.
+#pragma STDC FENV_ROUND FE_TOWARDZERO
+
+
 // CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -11342,6 +11342,7 @@
   // Take tokens to avoid allocations
   LPT->Toks.swap(Toks);
   LPT->D = FnD;
+  LPT->FPO = getCurFPFeatures();
   LateParsedTemplateMap.insert(std::make_pair(FD, std::move(LPT)));
 
   FD->setLateTemplateParsed(true);
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -1731,6 +1731,10 @@
   Actions.PushDeclContext(Actions.getCurScope(), DC);
   }
 
+  // Parsing should occur with empty FP pragma stack and FP options used in the
+  // point of the template definition.
+  Actions.resetFPOptions(LPT.FPO);
+
   assert(!LPT.Toks.empty() && "Empty body!");
 
   // Append the current token at the end of the new token stream so that it
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -710,6 +710,12 @@
 return result;
   }
 
+  void resetFPOptions(FPOptions FPO) {
+CurFPFeatures = FPO;
+FpPragmaStack.Stack.clear();
+FpPragmaStack.CurrentValue = FPO.getChangesFrom(FPOptions(LangOpts));
+  }
+
   // RAII object to push / pop sentinel slots for all MS #pragma stacks.
   // Actions should be performed only if we enter / exit a C++ method body.
   class PragmaStackSentinelRAII {
@@ -13974,6 +13980,8 @@
   CachedTokens Toks;
   /// The template function declaration to be late parsed.
   Decl *D;
+  /// Floating-point options in the point of definition.
+  FPOptions FPO;
 };
 
 template <>


Index: clang/test/CodeGen/fp-template.cpp
===
--- clang/test/CodeGen/fp-template.cpp
+++ clang/test/CodeGen/fp-template.cpp
@@ -15,4 +15,40 @@
 // CHECK-SAME:  (float noundef %{{.*}}, float noundef %{{.*}}) #[[ATTR01:[0-9]+]]{{.*}} {
 // CHECK:   call float @llvm.experimental.constrained.fadd.f32
 
+
+template 
+Ty templ_02(Ty x, Ty y) {
+  return x + y;
+}
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+template 
+Ty templ_03(Ty x, Ty y) {
+  return x - y;
+}
+
+#pragma STDC FENV_ROUND FE_TONEAREST
+
+float func_02(float x, float y) {
+  return templ_02(x, y);
+}
+
+// CHECK-LABEL: define {{.*}} float @_Z8templ_02IfET_S0_S0_
+// CHECK:   %add = fadd float %0, %1
+
+float func_03(float x, float y) {
+  return templ_03(x, y);
+}
+
+// CHECK-LABEL: define {{.*}} float @_Z8templ_03IfET_S0_S0_
+// CHECK:   call float @llvm.experimental.constrained.fsub.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.ignore")
+
+
+// This pragma sets non-default rounding mode before delayed parsing occurs. It
+// is used to check that the parsing uses FP options defined by command line
+// options or by pragma before the template definition but not by this pragma.
+#pragma STDC FENV_ROUND FE_TOWARDZERO
+
+
 // CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
Index: clang/lib/Sema/SemaTemplate.cpp
===

[PATCH] D151553: [clang] Fix consteval operators in template contexts

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 527808.
Fznamznon added a comment.

Transform the callee, add a test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151553

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/consteval-operators.cpp
  clang/test/SemaCXX/overloaded-operator.cpp

Index: clang/test/SemaCXX/overloaded-operator.cpp
===
--- clang/test/SemaCXX/overloaded-operator.cpp
+++ clang/test/SemaCXX/overloaded-operator.cpp
@@ -585,3 +585,16 @@
   float &operator->*(B, B);
   template void f();
 }
+
+namespace test {
+namespace A {
+template T f(T t) {
+  T operator+(T, T);
+  return t + t;
+}
+}
+namespace B {
+  struct X {};
+}
+void g(B::X x) { A::f(x); }
+}
Index: clang/test/SemaCXX/consteval-operators.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/consteval-operators.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
+
+// expected-no-diagnostics
+
+struct A {
+  consteval A operator+() { return {}; }
+};
+consteval A operator~(A) { return {}; }
+consteval A operator+(A, A) { return {}; }
+
+template  void f() {
+  A a;
+  A b = ~a;
+  A c = a + a;
+  A d = +a;
+}
+template void f();
+
+template  void foo() {
+  T a;
+  T b = ~a;
+  T c = a + a;
+  T d = +a;
+}
+
+template void foo();
+
+template  struct B { DataT D; };
+
+template 
+consteval B operator+(B lhs, B rhs) {
+  return B{lhs.D + rhs.D};
+}
+
+template  consteval T template_add(T a, T b) { return a + b; }
+
+consteval B non_template_add(B a, B b) { return a + b; }
+
+void bar() {
+  constexpr B a{};
+  constexpr B b{};
+  auto constexpr c = a + b;
+}
+
+static_assert((template_add(B{7}, B{3})).D == 10);
+static_assert((non_template_add(B{7}, B{3})).D == 10);
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3037,10 +3037,11 @@
   /// argument-dependent lookup, etc. Subclasses may override this routine to
   /// provide different behavior.
   ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
-  SourceLocation OpLoc,
-  Expr *Callee,
-  Expr *First,
-  Expr *Second);
+SourceLocation OpLoc,
+SourceLocation CalleeLoc,
+bool RequiresADL,
+const UnresolvedSetImpl &Functions,
+Expr *First, Expr *Second);
 
   /// Build a new C++ "named" cast expression, such as static_cast or
   /// reinterpret_cast.
@@ -11937,10 +11938,6 @@
 llvm_unreachable("not an overloaded operator?");
   }
 
-  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
-  if (Callee.isInvalid())
-return ExprError();
-
   ExprResult First;
   if (E->getOperator() == OO_Amp)
 First = getDerived().TransformAddressOfOperand(E->getArg(0));
@@ -11957,23 +11954,41 @@
   return ExprError();
   }
 
-  if (!getDerived().AlwaysRebuild() &&
-  Callee.get() == E->getCallee() &&
-  First.get() == E->getArg(0) &&
-  (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
-return SemaRef.MaybeBindToTemporary(E);
-
   Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
   FPOptionsOverride NewOverrides(E->getFPFeatures());
   getSema().CurFPFeatures =
   NewOverrides.applyOverrides(getSema().getLangOpts());
   getSema().FpPragmaStack.CurrentValue = NewOverrides;
 
-  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
- E->getOperatorLoc(),
- Callee.get(),
- First.get(),
- Second.get());
+  bool RequiresADL = false;
+  Expr *Callee = E->getCallee();
+  if (UnresolvedLookupExpr *ULE = dyn_cast(Callee)) {
+RequiresADL = ULE->requiresADL();
+LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
+   Sema::LookupOrdinaryName);
+if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
+  return ExprError();
+
+return getDerived().RebuildCXXOperatorCallExpr(
+E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
+RequiresADL, R.asUnresolvedSet(), First.get(), Second.get());
+  }
+
+  UnresolvedSet<16> Functions;
+  if (ImplicitCastExpr *ICE = dyn_cast(Callee))
+Callee = ICE->getSubExprAsWritten();
+  NamedDecl *DR = cast(Callee)->getDecl();
+  ValueDecl *VD = cas

[PATCH] D151634: [clang] Add test for CWG253

2023-06-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill updated this revision to Diff 527804.
Endill edited the summary of this revision.
Endill added a comment.

Mark CWG78 as superseded by 2536
Expand CWG253 test

@shafik I think rather than leave 78 out, we better mark it as superseded, so 
that we don't forget about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151634

Files:
  clang/test/CXX/drs/dr0xx.cpp
  clang/test/CXX/drs/dr2xx.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
@@ -505,7 +505,7 @@
 https://cplusplus.github.io/CWG/issues/78.html";>78
 CD1
 Section 8.5 paragraph 9 should state it only applies to non-static 
objects
-Superseded by 
+Superseded by 2536
   
   
 https://cplusplus.github.io/CWG/issues/79.html";>79
@@ -1556,7 +1556,7 @@
 https://cplusplus.github.io/CWG/issues/253.html";>253
 C++17
 Why must empty or fully-initialized const objects be initialized?
-Unknown
+Clang 3.9
   
   
 https://cplusplus.github.io/CWG/issues/254.html";>254
@@ -3021,7 +3021,7 @@
 https://cplusplus.github.io/CWG/issues/497.html";>497
 CD1
 Missing required initialization in example
-Superseded by 253
+Superseded by 253
   
   
 https://cplusplus.github.io/CWG/issues/498.html";>498
Index: clang/test/CXX/drs/dr2xx.cpp
===
--- clang/test/CXX/drs/dr2xx.cpp
+++ clang/test/CXX/drs/dr2xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
 // PR13819 -- __SIZE_TYPE__ is incompatible.
 typedef __SIZE_TYPE__ size_t; // expected-error 0-1 {{extension}}
@@ -682,6 +683,24 @@
   G::~G() {}
 }
 
+namespace dr253 { // dr253: 3.9
+struct X {};
+struct Y {
+  X x;
+};
+
+struct Z {
+  operator int() const { return 0; }
+};
+
+void f() {
+  const X x1;
+  const X x2 = { };
+  const Z z1;  
+  const Z z2 = { };
+}
+} // namespace dr253
+
 namespace dr254 { // dr254: yes
   template struct A {
 typedef typename T::type type; // ok even if this is a typedef-name, 
because
Index: clang/test/CXX/drs/dr0xx.cpp
===
--- clang/test/CXX/drs/dr0xx.cpp
+++ clang/test/CXX/drs/dr0xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -triple %itanium_abi_triple
 
 namespace dr1 { // dr1: no
   namespace X { extern "C" void dr1_f(int a = 1); }
@@ -1018,7 +1019,7 @@
   };
 }
 
-namespace dr78 { // dr78: sup 
+namespace dr78 { // dr78: sup 2536
   // Under DR78, this is valid, because 'k' has static storage duration, so is
   // zero-initialized.
   const int k; // expected-error {{default initialization of an object of 
const}}


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -505,7 +505,7 @@
 https://cplusplus.github.io/CWG/issues/78.html";>78
 CD1
 Section 8.5 paragraph 9 should state it only applies to non-static objects
-Superseded by 
+Superseded by 2536
   
   
 https://cplusplus.github.io/CWG/issues/79.html";>79
@@ -1556,7 +1556,7 @@
 https://cplusplus.github.io/CWG/issues/253.html";>253
 C++17
 Why must empty or fully-initialized const objects be initialized?
-Unknown
+Clang 3.9
   
   
 https://cplusplus.github.io/CWG/issues/254.html";>254
@@ -3021,7 +3021,7 @@
 https://cplusplus.github.io/CWG/issues/497.html";>497
 CD1
 Missing required initialization in example
-Superseded by 253
+Superseded by 253
   
   
 https://cplusplus.github.io/CWG/issues/498.html";>498
Index: clang/test/CXX/drs/dr2xx.cpp
===
--- clang/test/CXX/drs/dr2xx.cpp
+++ clang/test/CXX/drs/dr2xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pe

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527812.
VitaNuo added a comment.

Escape the slashes in regex.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,236 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include "gtest/gtest.h"
+#include 
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Result;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
+  "bar.h;{0};{1};vector",
+  llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
+  llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
+   {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions[

[PATCH] D151990: Test for emitIncludeLocation with "-fdiagnostics-absolute-paths"

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro created this revision.
Herald added a project: All.
charmitro requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151990

Files:
  clang/test/Frontend/absolute-paths-import.h
  clang/test/Frontend/absolute-paths.c


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE 
-check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s 
-check-prefix=ABSOLUTE -check-prefix=CHECK %s --dump-input-filter=all
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=ABSOLUTE -check-prefix=CHECK %s --dump-input-filter=all
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro updated this revision to Diff 527821.

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

https://reviews.llvm.org/D151833

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Frontend/absolute-paths-import.h
  clang/test/Frontend/absolute-paths.c


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE 
-check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s 
-check-prefix=ABSOLUTE -check-prefix=CHECK %s --dump-input-filter=all
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=ABSOLUTE -check-prefix=CHECK %s --dump-input-filter=all
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527822.
VitaNuo added a comment.

Remove path handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,221 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Regex.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{
+  llvm::formatv("bar.h;{0};{1};vector", llvm::Regex::escape("foo/qux.h"),
+llvm::Regex::escape("baz/qux"))};
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] =
+  llvm::StringRef{"baz.h;" + llvm::Regex::escape("foo/qux.h")};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, runCheckOnCode(
+ PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+ {{"bar.h", R"(#pragma once
+  #include "baz.h"
+  #include "foo/qux.h"
+  int bar();
+ 

[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro added a comment.

In D151833#4390279 , @charmitro wrote:

> In D151833#4386128 , @tbaeder wrote:
>
>> Can you add a test case for the change? Looks like there's something similar 
>> already in `clang/test/Frontend/absolute-paths.c`
>
> Is it possible to use substitutions inside let's say `NORMAL: `? How could I 
> resolve the absolute path without hard-coding my path inside the test case?

I was able to make it work using `-DNAME=` in the FileCheck invocation 
inside `absolute-paths.c` test file.


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

https://reviews.llvm.org/D151833

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


[PATCH] D150746: [CodeGen]Translating pointer arguments can require an address space cast

2023-06-02 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1630-1632
+LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr);
+QualType Q = Context.getAddrSpaceQualType(Context.VoidPtrTy, AS);
+QualType T = Context.getPointerType(Q);

AlexVlx wrote:
> yaxunl wrote:
> > Does it worth extracting the code as Context.getVTTType() since it is used 
> > at three locations. Since VTT seems to be immutable, in case we want to put 
> > it in constant addr space in the future, it will make things easier.
> That's not a bad idea. I think it might be profitable to do something like 
> `Context.getVTableType()`, since there's actually 2.5 interlinked things here 
> (VTT, vtable & vptr), and it makes intuitive to me to base it all around that 
> (vptr points to vtbl) etc.
Actually, I think I should probably do this in a separate patch; we already 
have `getVtblPtrAddressSpace()` in `TargetInfo`, but it doesn't seem to be used 
anywhere but for generating debug info. I suspect the latter will be subtly 
wrong for us anyway, because we'll advertise the constant AS, even though we're 
today using global. TL;DR, I'd handle this suggestion separately @yaxunl, if 
you don't mind.


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

https://reviews.llvm.org/D150746

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro updated this revision to Diff 527828.

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

https://reviews.llvm.org/D151833

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Frontend/absolute-paths-import.h
  clang/test/Frontend/absolute-paths.c


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE 
-check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s 
-check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150746: [CodeGen]Translating pointer arguments can require an address space cast

2023-06-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1630-1632
+LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr);
+QualType Q = Context.getAddrSpaceQualType(Context.VoidPtrTy, AS);
+QualType T = Context.getPointerType(Q);

AlexVlx wrote:
> AlexVlx wrote:
> > yaxunl wrote:
> > > Does it worth extracting the code as Context.getVTTType() since it is 
> > > used at three locations. Since VTT seems to be immutable, in case we want 
> > > to put it in constant addr space in the future, it will make things 
> > > easier.
> > That's not a bad idea. I think it might be profitable to do something like 
> > `Context.getVTableType()`, since there's actually 2.5 interlinked things 
> > here (VTT, vtable & vptr), and it makes intuitive to me to base it all 
> > around that (vptr points to vtbl) etc.
> Actually, I think I should probably do this in a separate patch; we already 
> have `getVtblPtrAddressSpace()` in `TargetInfo`, but it doesn't seem to be 
> used anywhere but for generating debug info. I suspect the latter will be 
> subtly wrong for us anyway, because we'll advertise the constant AS, even 
> though we're today using global. TL;DR, I'd handle this suggestion separately 
> @yaxunl, if you don't mind.
OK for me


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

https://reviews.llvm.org/D150746

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

This checks the same thing in both cases, but in the `NORMAL` case, it should 
//not// use the absolute path, shouldn't it?


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

https://reviews.llvm.org/D151833

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


[PATCH] D150122: [Clang] Fix status of P0960

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

LGTM as well, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D151964: [NFC][CLANG] Fix Static Code Analyzer Concerns with dereference null return value in applyObjCTypeArgs()

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaType.cpp:956
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {
 // When the type argument is 'id', the only acceptable type

Note for future reviewers: This 'if' on both branches dereferences the 
`boundObjC` pointer. The true path is just below here, on 959.  Second is in 
the condition inside of the `else if` on 961, `canAssignObjCInterfaces` 
immediately dereferences the parameters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151964

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


[PATCH] D151963: [clang][NFC] Remove trailing whitespaces and enforce it in lib, include and docs

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

This looks fine to me.  HOWEVER, please make sure to add this commit to 
`https://github.com/llvm/llvm-project/blob/main/.git-blame-ignore-revs` in a 
follow-up NFC commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151963

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


[PATCH] D151625: [clang] Add `clang::equality_operator_compares_members_lexicographically`

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

1- This needs a release note.
2- I want others to comment on the name.  I like its verbosity in that it'll 
discourage people from using it without knowing what it means, but I want to 
hear Aaron/others' opinion as well.
3- Trailing WS thing, I see you did a cleanup patch, so just make sure this 
gets commited after that.




Comment at: clang/include/clang/Basic/AttrDocs.td:541
   let Content = [{
-If a statement is marked ``nomerge`` and contains call expressions, those call
-expressions inside the statement will not be merged during optimization. This 
+If a statement is marked ``nomerge`` and contains call expressions, those call 
+expressions inside the statement will not be merged during optimization. This

Trailing WS change, please don't do in this commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151625

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


[PATCH] D147875: [clang][Diagnostics] Show line numbers when printing code snippets

2023-06-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/docs/UsersManual.rst:578
+
+.. option:: -fcaret-diagnostics-max-lines:
+

I think this is still a cc1-only option. Should it be made available as a 
driver option now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147875

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527839.
VitaNuo added a comment.

Re-introduce path handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,236 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include "gtest/gtest.h"
+#include 
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Result;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
+  "bar.h;{0};{1};vector",
+  llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
+  llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
+   {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["

[PATCH] D147875: [clang][Diagnostics] Show line numbers when printing code snippets

2023-06-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/docs/UsersManual.rst:578
+
+.. option:: -fcaret-diagnostics-max-lines:
+

hans wrote:
> I think this is still a cc1-only option. Should it be made available as a 
> driver option now?
No strong opinion from my side, but would certainly make sense to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147875

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Needs a release note.

Also, is this something that has been requested by library?  I'd hope this is 
something that will be used, so I'd like evidence of that.




Comment at: clang/include/clang/AST/Stmt.h:796-802
+/// If this expression is not value-dependent, this stores the value.
+unsigned Value : 8;
 
 /// The number of arguments to this type trait. According to [implimits]
 /// 8 bits would be enough, but we require (and test for) at least 16 bits
 /// to mirror FunctionType.
+unsigned NumArgs : 16;

dblaikie wrote:
> cjdb wrote:
> > These numbers feel very low for how this modification is using them. 
> > Perhaps they should both be bumped to 32?
> clang does, I think, have specific implementation limits for this sort of 
> thing - 
> 
> Well, maybe we don't actually enforce a limit on number of template 
> arguments... https://godbolt.org/z/accncYson compiles successfully, and has 
> 2^18 parameters, beyond the 2^16 suggested here.
> 
> But maybe 2^16 is just what we test for/somewhat guarantee.
> 
> But if the `Value` is going to be the index into the args, shouldn't it be 
> the same size as `NumArgs`, at least? (& the comment says 16, so 16 for both 
> Value and NumArgs would seem suitably symmetric, and no larger than the 
> current situation - since it'd just be splitting NumArgs in half, while still 
> meeting the comment's suggestion/requirements?)
> 
> An assert, at least, when populating NumArgs to ensure it's no larger might 
> not hurt... (which might be reachable from code/not checked prior - so it 
> could be a hard compilation error, I guess, but I wouldn't feel super 
> strongly about it)
Can you explain the math here of how you chose to change this to 16?  I see 
that you removed 7 bits, but took away 16.  I'm not sure what NumExprBits is 
doing though, I got lost a little in that, so if you can calculate that to make 
sure this needs to be done, it would be appreciated.

Additionally, a static_assert after this to ensure the size isn't changing 
would also be appreciated.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2960
+def err_type_pack_index_not_found : Error<
+  "'__type_pack_index' couldn't find type %0">;
+





Comment at: clang/lib/Sema/SemaExprCXX.cpp:5562
+  if (IsDependent)
+goto Return;
+

Oh, please don't do this.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5591
+  default:
+llvm_unreachable("unhandled type trait (usualy deliberate)");
+  }

What do you mean by `usually deliberate` here? This is a message users will 
see, so telling them an assertion is deliberate seems incorrect? 



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5620
 
+  if (Kind == clang::TT_TypePackIndex)
+return EvaluateIntegralTypeTrait(*this, Kind, KWLoc, Args, RParenLoc,

I realize this is the 1st, but this seems like it is going to be a maintenance 
pain.  Can you at least split this into a static-function of 
`IsIntegralTypeTrait` that we can use later with table-gen if this gets out of 
hand?



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5625
   bool Result = false;
   if (!Dependent)
+Result = EvaluateBooleanTypeTrait(*this, Kind, KWLoc, Args, RParenLoc);

For the purposes of making the two the same, can you integrate this into 
`EvaluateBooleanTypeTrait`?  That would be something like:

```
if (IsIntegralTypeTrait(Kind))
  return EvaluateIntegralTypeTrait(...);
return EvaluateBooleanTypeTrait(...);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D151928: [NFC][CLANG] Fix nullptr dereference issue in ConvertQualTypeToKind()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

Thank you @erichkeane for reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151928

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


[PATCH] D151947: [NFC][CLANG] Fix Static Code Analyzer Concerns

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

Thank you @erichkeane for reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151947

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


[PATCH] D151957: [NFC][CLANG] Fix bug with dereference null return value in GetFunctionTypeForVTable()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

Thank you @erichkeane for reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151957

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I don't understand our consteval implementation enough to approve this, but I 
didn't see anything to comment on while going through this.




Comment at: clang/include/clang/Sema/Sema.h:1071
 FD->setWillHaveBody(true);
-  else
+S.ExprEvalContexts.back().InImmediateFunctionContext =
+FD->isImmediateFunction();

I'm annoyed that we do `ExprEvalContexts.back()` as often as we do, and don't 
just have `Sema::curExprEvalContext`.

There isn't really anything for you to do here, but I wanted to tell someone of 
this annoyance, as this is the 3rd time its popped up in a week for me :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro added inline comments.



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

tbaeder wrote:
> This checks the same thing in both cases, but in the `NORMAL` case, it should 
> //not// use the absolute path, shouldn't it?
You're correct. I was constantly testing it from the same path.

Since the relative path is going to be different depending on where you running 
from, would it be wise to accept a regular expression of any string in the 
`NORMAL` case?

For example, 
```
NORMAL: In file included from {{.*}}:
```


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

https://reviews.llvm.org/D151833

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


[PATCH] D151964: [NFC][CLANG] Fix Static Code Analyzer Concerns with dereference null return value in applyObjCTypeArgs()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:956
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {
 // When the type argument is 'id', the only acceptable type

erichkeane wrote:
> Note for future reviewers: This 'if' on both branches dereferences the 
> `boundObjC` pointer. The true path is just below here, on 959.  Second is in 
> the condition inside of the `else if` on 961, `canAssignObjCInterfaces` 
> immediately dereferences the parameters.
>>This 'if' on both branches dereferences the boundObjC pointer. The true path 
>>is just below here, on 959. Second is in the condition inside of the else if 
>>on 961, canAssignObjCInterfaces immediately dereferences the parameters.

Yes.

Thank you @erichkeane for reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151964

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


[PATCH] D147219: [OpenMP][Flang][MLIR] Lowering of requires directive from MLIR to LLVM IR

2023-06-02 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 527854.
skatrak added a comment.
Herald added subscribers: cfe-commits, hiraditya.
Herald added a project: clang.

Update and remove OpenMP dialect dependency from the generic LLVM IR 
translation.

Followed @kiranchandramohan's suggestion in the comments for D147172 
, since the
current approach prevents the use of OpenMP dialect-specific attributes for
initializing the `OpenMPIRBuilder` configuration. One of these is defined for
representing 'requires' clauses, which need to be stored in the
`OpenMPIRBuilderConfig`, so a different approach is necessary. The approach
implemented in this review is based on the `amendOperation` translation flow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147219

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir

Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir
===
--- mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -2543,3 +2543,13 @@
 // CHECK: @__omp_rtl_assume_no_thread_state = weak_odr hidden constant i32 1
 // CHECK: @__omp_rtl_assume_no_nested_parallelism = weak_odr hidden constant i32 0
 module attributes {omp.flags = #omp.flags} {}
+
+// -
+
+// Check that OpenMP requires flags are registered by a global constructor.
+// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }]
+// CHECK-SAME: [{ i32, ptr, ptr } { i32 0, ptr @[[REG_FN:.*]], ptr null }]
+// CHECK: define {{.*}} @[[REG_FN]]({{.*}})
+// CHECK-NOT: }
+// CHECK:   call void @__tgt_register_requires(i64 10)
+module attributes {omp.requires = #omp} {}
Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -20,8 +20,6 @@
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
 #include "mlir/Dialect/LLVMIR/Transforms/LegalizeForExport.h"
-#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
-#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/BuiltinTypes.h"
@@ -1273,30 +1271,18 @@
 llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
   if (!ompBuilder) {
 ompBuilder = std::make_unique(*llvmModule);
+ompBuilder->initialize();
 
-bool isDevice = false;
-llvm::StringRef hostIRFilePath = "";
-
-if (Attribute deviceAttr = mlirModule->getAttr("omp.is_device"))
-  if (::llvm::isa(deviceAttr))
-isDevice = ::llvm::dyn_cast(deviceAttr).getValue();
-
-if (Attribute filepath = mlirModule->getAttr("omp.host_ir_filepath"))
-  if (::llvm::isa(filepath))
-hostIRFilePath =
-::llvm::dyn_cast(filepath).getValue();
-
-ompBuilder->initialize(hostIRFilePath);
-
-// TODO: set the flags when available
-llvm::OpenMPIRBuilderConfig config(
-isDevice, /* IsTargetCodegen */ false,
+// Flags represented as top-level OpenMP dialect attributes are set in
+// OpenMPDialectLLVMIRTranslationInterface::amendOperation(). Here we set
+// the default configuration.
+ompBuilder->setConfig(llvm::OpenMPIRBuilderConfig(
+/* IsEmbedded */ false, /* IsTargetCodegen */ false,
 /* OpenMPOffloadMandatory */ false,
 /* HasRequiresReverseOffload */ false,
 /* HasRequiresUnifiedAddress */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
-/* OpenMPOffloadMandatory */ false);
-ompBuilder->setConfig(config);
+/* OpenMPOffloadMandatory */ false));
   }
   return ompBuilder.get();
 }
@@ -1383,11 +1369,17 @@
 return nullptr;
   if (failed(translator.createTBAAMetadata()))
 return nullptr;
+
+  // Convert module itself before any functions and operations inside, so that
+  // the OpenMPIRBuilder is configured with the OpenMP dialect attributes
+  // attached to the module by the amendOperation() flow before then.
+  llvm::IRBuilder<> llvmBuilder(llvmContext);
+  if (failed(translator.convertOperation(*module, llvmBuilder)))
+return nullptr;
   if (failed(translator.convertFunctions()))
 return nullptr;
 
   // Convert other top-level operations if possible.
-  llvm::IRBuilder<> llvmBuilder(llvmContext);
   for (Operation &o : getModuleBody(module).getOperations()) {
 if (!isa(&o) &&
@@ -1397,10 +1389,6 @@
 }
   }
 
-  // Convert module itself.
-  if (failed(translator.convertOperation(*module, llvmBuilder)))
-return nullptr;
-
   if (llvm::verifyModule(*translator.llv

[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Nothing more from me, but I would wait for someone else's approval.




Comment at: clang/lib/Sema/SemaExpr.cpp:18204
+const NamedDecl *ND = cast(DR->getDecl());
+if (const auto *MD = llvm::dyn_cast(ND);
 MD && (MD->isLambdaStaticInvoker() || isLambdaCallOperator(MD)))

Fznamznon wrote:
> 
This one seems to be missed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread Ties Stuij via Phabricator via cfe-commits
stuij added a comment.

This is going to be a very unhelpful comment. After looking through the 
changes, I don't have any comments to make, but I also don't feel comfortable 
to accept this revision as I don't feel to know enough about the front-end.


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

https://reviews.llvm.org/D149573

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

charmitro wrote:
> tbaeder wrote:
> > This checks the same thing in both cases, but in the `NORMAL` case, it 
> > should //not// use the absolute path, shouldn't it?
> You're correct. I was constantly testing it from the same path.
> 
> Since the relative path is going to be different depending on where you 
> running from, would it be wise to accept a regular expression of any string 
> in the `NORMAL` case?
> 
> For example, 
> ```
> NORMAL: In file included from {{.*}}:
> ```
I wonder if it would make sense to just check for the filename in the `NORMAL` 
case and then do a `NORMAL-NOT: [[ROOT_ABSOLUTE]]`?


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

https://reviews.llvm.org/D151833

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


[clang] 24231df - [clang-format] Parse the Verilog language option in configuration

2023-06-02 Thread via cfe-commits

Author: sstwcw
Date: 2023-06-02T14:59:27Z
New Revision: 24231df9b8ef560cc6d3c713d5dba1de703e2cb9

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

LOG: [clang-format] Parse the Verilog language option in configuration

Reviewed By: HazardyKnusperkeks, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d7128ed558dc5..6e2b6a662e7e1 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -375,6 +375,7 @@ template <> struct 
ScalarEnumerationTraits {
 IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto);
 IO.enumCase(Value, "CSharp", FormatStyle::LK_CSharp);
 IO.enumCase(Value, "Json", FormatStyle::LK_Json);
+IO.enumCase(Value, "Verilog", FormatStyle::LK_Verilog);
   }
 };
 

diff  --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 0e47abed12472..169c93d1143eb 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -1022,6 +1022,23 @@ TEST(ConfigParseTest, ParsesConfigurationWithLanguages) {
 ParseError::Error);
 
   EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+
+  Style.Language = FormatStyle::LK_Verilog;
+  CHECK_PARSE("---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 12\n"
+  "---\n"
+  "Language: Cpp\n"
+  "IndentWidth: 34\n"
+  "...\n",
+  IndentWidth, 12u);
+  CHECK_PARSE("---\n"
+  "IndentWidth: 78\n"
+  "---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 56\n"
+  "...\n",
+  IndentWidth, 56u);
 }
 
 TEST(ConfigParseTest, UsesLanguageForBasedOnStyle) {



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


[PATCH] D151632: [clang-format] Parse the Verilog language option in configuration

2023-06-02 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24231df9b8ef: [clang-format] Parse the Verilog language 
option in configuration (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151632

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -1022,6 +1022,23 @@
 ParseError::Error);
 
   EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+
+  Style.Language = FormatStyle::LK_Verilog;
+  CHECK_PARSE("---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 12\n"
+  "---\n"
+  "Language: Cpp\n"
+  "IndentWidth: 34\n"
+  "...\n",
+  IndentWidth, 12u);
+  CHECK_PARSE("---\n"
+  "IndentWidth: 78\n"
+  "---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 56\n"
+  "...\n",
+  IndentWidth, 56u);
 }
 
 TEST(ConfigParseTest, UsesLanguageForBasedOnStyle) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -375,6 +375,7 @@
 IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto);
 IO.enumCase(Value, "CSharp", FormatStyle::LK_CSharp);
 IO.enumCase(Value, "Json", FormatStyle::LK_Json);
+IO.enumCase(Value, "Verilog", FormatStyle::LK_Verilog);
   }
 };
 


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -1022,6 +1022,23 @@
 ParseError::Error);
 
   EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+
+  Style.Language = FormatStyle::LK_Verilog;
+  CHECK_PARSE("---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 12\n"
+  "---\n"
+  "Language: Cpp\n"
+  "IndentWidth: 34\n"
+  "...\n",
+  IndentWidth, 12u);
+  CHECK_PARSE("---\n"
+  "IndentWidth: 78\n"
+  "---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 56\n"
+  "...\n",
+  IndentWidth, 56u);
 }
 
 TEST(ConfigParseTest, UsesLanguageForBasedOnStyle) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -375,6 +375,7 @@
 IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto);
 IO.enumCase(Value, "CSharp", FormatStyle::LK_CSharp);
 IO.enumCase(Value, "Json", FormatStyle::LK_Json);
+IO.enumCase(Value, "Verilog", FormatStyle::LK_Verilog);
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a comment.

In D149573#4390863 , @stuij wrote:

> This is going to be a very unhelpful comment. After looking through the 
> changes, I don't have any comments to make, but I also don't feel comfortable 
> to accept this revision as I don't feel to know enough about the front-end.

@stuij, I sincerely appreciate you taking the time to review the changes. Your 
hesitation due to unfamiliarity with the front-end elements is completely 
understandable, and I respect your candid feedback.

@erichkeane, given your extensive contributions to the core `Sema`* files, I 
believe your expertise and experience would be particularly valuable in 
reviewing the changes I've made. I recall your initial informal approval for 
the change, and since then, I've further refined it after incorporating the 
outcomes of D150913 . I'd be most 
appreciative if you could please review this revision once again.

My intention is to ensure this revision aligns with our shared vision for 
LLVM/Clang, and your reviews will greatly contribute to this goal. If there are 
any other changes or improvements required for the successful landing of this 
revision, please feel free to let me know.


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

https://reviews.llvm.org/D149573

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro added inline comments.



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

tbaeder wrote:
> charmitro wrote:
> > tbaeder wrote:
> > > This checks the same thing in both cases, but in the `NORMAL` case, it 
> > > should //not// use the absolute path, shouldn't it?
> > You're correct. I was constantly testing it from the same path.
> > 
> > Since the relative path is going to be different depending on where you 
> > running from, would it be wise to accept a regular expression of any string 
> > in the `NORMAL` case?
> > 
> > For example, 
> > ```
> > NORMAL: In file included from {{.*}}:
> > ```
> I wonder if it would make sense to just check for the filename in the 
> `NORMAL` case and then do a `NORMAL-NOT: [[ROOT_ABSOLUTE]]`?
Yes, that way we are testing if the warning contains the correct filename+LOC.

Something like: `// NORMAL: In file included from {{.*absolute-paths.c:4}}:`.

But why changefrom `ABSOLUTE:` to `NORMAL-NOT`?


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

https://reviews.llvm.org/D151833

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


[clang] cecd847 - [Clang][Parser] Accept GNU attributes preceding C++ attributes on templates

2023-06-02 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-06-02T08:11:18-07:00
New Revision: cecd8471e4991b4bea5d2b38a3758cafdb1cbe29

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

LOG: [Clang][Parser] Accept GNU attributes preceding C++ attributes on templates

Clang was rejecting valid code where GNU style attributes preceded C++ style
attributes in template declarations as follows:

template
__attribute__((deprecated("oh no!"))) [[deprecated("oh no!")]] void foo();

This PR fixes the bug.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseTemplate.cpp
clang/test/Parser/attr-order.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02736f2ee67fc..69ab645d49c23 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -473,6 +473,10 @@ Bug Fixes to Attribute Support
   structs, unions, and scoped enums) were not properly ignored, resulting in
   misleading warning messages. Now, such attribute annotations are correctly
   ignored. (`#61660 `_)
+- GNU attributes preceding C++ style attributes on templates were not properly
+  handled, resulting in compilation error. This has been corrected to match the
+  behavior exhibited by GCC, which permits mixed ordering of GNU and C++
+  attributes.
 
 Bug Fixes to C++ Support
 

diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 79f4ab683281e..d2e8a81ad521a 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into 
diff erent containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, &DiagsFromTParams);
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));

diff  --git a/clang/test/Parser/attr-order.cpp 
b/clang/test/Parser/attr-order.cpp
index 9a8490d819ee3..10bad38cac644 100644
--- a/clang/test/Parser/attr-order.cpp
+++ b/clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@ struct [[]] __attribute__((lockable)) [[]] 
__declspec(dllexport) H {}; // ok
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok



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


[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-02 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcecd8471e499: [Clang][Parser] Accept GNU attributes 
preceding C++ attributes on templates (authored by eandrews).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D151837?vs=527406&id=527867#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151837

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Parser/attr-order.cpp


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into different containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, &DiagsFromTParams);
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -473,6 +473,10 @@
   structs, unions, and scoped enums) were not properly ignored, resulting in
   misleading warning messages. Now, such attribute annotations are correctly
   ignored. (`#61660 `_)
+- GNU attributes preceding C++ style attributes on templates were not properly
+  handled, resulting in compilation error. This has been corrected to match the
+  behavior exhibited by GCC, which permits mixed ordering of GNU and C++
+  attributes.
 
 Bug Fixes to C++ Support
 


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noretu

[PATCH] D152002: [clang][wip] Better handling of dependent lambda. This is an attempt to fix GH62916. However, it breaks GH57960 I seem unable to find something that works for both issues.

2023-06-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152002

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-expressions.cpp


Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -715,3 +715,23 @@
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+#if __cplusplus > 201402L
+namespace GH62916 {
+
+template  int { return T(42); }()>
+struct P {
+static constexpr int value = U;
+};
+
+template 
+constexpr P foo() {
+return {};
+}
+
+void test() {
+  static_assert(foo().value == 42);
+}
+
+}
+#endif
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -761,6 +761,8 @@
   /// the body.
   StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
 
+  bool LambdaExpressionShouldBeConsideredDependent(LambdaExpr *E) const;
+
   QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
 
   StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
@@ -13294,18 +13296,9 @@
 
   // Create the local class that will describe the lambda.
 
-  // FIXME: DependencyKind below is wrong when substituting inside a templated
-  // context that isn't a DeclContext (such as a variable template), or when
-  // substituting an unevaluated lambda inside of a function's parameter's type
-  // - as parameter types are not instantiated from within a function's DC. We
-  // use evaluation contexts to distinguish the function parameter case.
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
-  CXXRecordDecl::LDK_Unknown;
-  if ((getSema().isUnevaluatedContext() ||
-   getSema().isConstantEvaluatedContext()) &&
-  (getSema().CurContext->isFileContext() ||
-   !getSema().CurContext->getParent()->isDependentContext()))
-DependencyKind = CXXRecordDecl::LDK_NeverDependent;
+  getDerived().LambdaExpressionShouldBeConsideredDependent(E) ?
+  CXXRecordDecl::LDK_AlwaysDependent : CXXRecordDecl::LDK_NeverDependent;
 
   CXXRecordDecl *OldClass = E->getLambdaClass();
   CXXRecordDecl *Class = getSema().createLambdaClosureType(
@@ -13578,6 +13571,12 @@
   return S;
 }
 
+template
+bool 
TreeTransform::LambdaExpressionShouldBeConsideredDependent(LambdaExpr 
*) const {
+  return false;
+}
+
+
 template
 ExprResult
 TreeTransform::TransformCXXUnresolvedConstructExpr(
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1435,6 +1435,20 @@
   return Result;
 }
 
+bool LambdaExpressionShouldBeConsideredDependent(LambdaExpr * E) const {
+  if(E->getLambdaClass()->isNeverDependentLambda())
+return false;
+
+  if(SemaRef.CurContext->isDependentContext())
+return true;
+
+  return llvm::any_of(TemplateArgs.getInnermost(), [](const 
TemplateArgument & C) {
+return C.isDependent();
+  });
+
+}
+
+
 ExprResult TransformRequiresExpr(RequiresExpr *E) {
   LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
   ExprResult TransReq = inherited::TransformRequiresExpr(E);


Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -715,3 +715,23 @@
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+#if __cplusplus > 201402L
+namespace GH62916 {
+
+template  int { return T(42); }()>
+struct P {
+static constexpr int value = U;
+};
+
+template 
+constexpr P foo() {
+return {};
+}
+
+void test() {
+  static_assert(foo().value == 42);
+}
+
+}
+#endif
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -761,6 +761,8 @@
   /// the body.
   StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
 
+  bool LambdaExpressionShouldBeConsideredDependent(LambdaExpr *E) const;
+
   QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
 
   StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
@@ -13294,18 +13296,9 @@
 
   // Create the local class that will describe the lambda.
 
-  // FIXME: DependencyKind below is wrong when substituting inside a templated
-  // context that isn't a DeclContext (such as a variable template), or when
-  // substituting an unevaluated lambda inside of a functi

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527872.
VitaNuo marked 6 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,78 @@
+//===--- IncludeSpellerTest.cpp===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpeller::Input &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+if (!AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator}))
+  return "";
+return "\"" + AbsolutePath.str() + "\"";
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+
+  Inputs.ExtraArgs.push_back("-isystemdir");
+
+  Inputs.ExtraFiles[testPath("foo.h")] = "";
+  Inputs.ExtraFiles["dir/header.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("\"foo.h\"", spellHeader({Header{*FM.getFile(testPath("foo.h"))},
+  HS, MainFile}));
+  EXPECT_EQ("",
+spellHeader({Header{*FM.getFile("dir/header.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
@@ -0,0 +1,68 @@
+//===--- IncludeSpeller.cpp===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Types.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/ErrorHandling.h"
+#

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Per P1975R0 an expression like `static_cast(...)` defines the type
of the expression as U[1].

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152003

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,14 @@
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
 }
+
+namespace gh62863 {
+int (&&arr)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arrr2)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr3)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8818,6 +8818,17 @@
   }
 }
   }
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();
+  if (const auto *AT = dyn_cast(InnerType);
+  AT && AT->getSize() == 1) {
+Cast->setType(SubInit->getType());
+  }
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -463,6 +463,8 @@
 - Fix crash when passing a braced initializer list to a parentehsized aggregate
   initialization expression.
   (`#63008 `_).
+- Fixed `static_cast` to array of unknown bound.
+  (`#62863 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,14 @@
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
+
+namespace gh62863 {
+int (&&arr)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arrr2)[2] = static_cast(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&&arr3)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8818,6 +8818,17 @@
   }
 }
   }
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();
+  if (const auto *AT = dyn_cast(InnerType);
+  AT && AT->getSize() == 1) {
+Cast->setType(SubInit->getType());
+  }
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
=

[clang-tools-extra] c28506b - [clang-tidy] Implement an include-cleaner check.

2023-06-02 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-06-02T15:21:20Z
New Revision: c28506ba4b6961950849f8fdecd0cf7e503a14f9

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

LOG: [clang-tidy] Implement an include-cleaner check.

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

Added: 
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/unittests/clang-tidy/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index a72362906e0b8..1703ff82b942d 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -7,6 +7,7 @@ setup_host_tool(clang-tidy-confusable-chars-gen 
CLANG_TIDY_CONFUSABLE_CHARS_GEN
 
 add_subdirectory(ConfusableTable)
 
+include_directories(BEFORE 
"${CMAKE_CURRENT_SOURCE_DIR}/../../include-cleaner/include")
 
 add_custom_command(
 OUTPUT Confusables.inc
@@ -19,6 +20,7 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
+  IncludeCleanerCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp
   MisleadingIdentifier.cpp
@@ -53,6 +55,7 @@ clang_target_link_libraries(clangTidyMiscModule
   clangAST
   clangASTMatchers
   clangBasic
+  clangIncludeCleaner
   clangLex
   clangSerialization
   clangTooling

diff  --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
new file mode 100644
index 0..c7aca83f2ca8c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -0,0 +1,202 @@
+//===--- IncludeCleanerCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IncludeCleanerCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../ClangTidyOptions.h"
+#include "../utils/OptionsUtils.h"
+#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/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Format/Format.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "clang/Tooling/Inclusions/HeaderIncludes.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Regex.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+struct MissingIncludeInfo {
+  SourceLocation SymRefLocation;
+  include_cleaner::Header Missing;
+};
+} // namespace
+
+IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreHeaders(utils::options::parseStringList(
+  Options.getLocalOrGlobal("IgnoreHeaders", ""))) {
+  for (const auto &Header : IgnoreHeaders) {
+if (!llvm:

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc28506ba4b69: [clang-tidy] Implement an include-cleaner 
check. (authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,236 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include "gtest/gtest.h"
+#include 
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Result;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
+  "bar.h;{0};{1};vector",
+  llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
+  llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
+   {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();

[clang-tools-extra] 5c2072e - [clang-tidy] Fix docs.

2023-06-02 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-06-02T15:31:55Z
New Revision: 5c2072e74b42d55e8bf7a9c8fee8800bad591f12

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

LOG: [clang-tidy] Fix docs.

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
index 30865680ac023..3246fea78cd42 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
@@ -10,6 +10,7 @@ Findings correspond to 
https://clangd.llvm.org/design/include-cleaner.
 Example:
 
 .. code-block:: c++
+   
// foo.h
class Foo{};
// bar.h



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


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8824
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();

I am not really sure this is the right way about this.  You're supposed to be 
testing `T`, but this looks like it is checking the type of `E`, isn't it?  I 
think you just need to check `Cast->getType()`.



Comment at: clang/lib/Sema/SemaType.cpp:8826
+  const Type *InnerType = SubInit->getType().getTypePtr();
+  if (const auto *AT = dyn_cast(InnerType);
+  AT && AT->getSize() == 1) {

Not supposed to have curleys here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5562
+  if (IsDependent)
+goto Return;
+

erichkeane wrote:
> Oh, please don't do this.
perhaps another way to do this if you want to avoid repeating the return 
expression would be a small lambda that contains the return expression and uses 
a simple name - so the returns can just be `return ret();` ? (or I guess nest 
the switch in an `if`, or in another function that uses ref parameters to 
populate the result)

Though in this case it's only twice, so I'd probably repeat the expression?



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5591
+  default:
+llvm_unreachable("unhandled type trait (usualy deliberate)");
+  }

erichkeane wrote:
> What do you mean by `usually deliberate` here? This is a message users will 
> see, so telling them an assertion is deliberate seems incorrect? 
I second the question - though I'd push back on the "This is a message users 
will see" - unreachables won't be seen by users, they get lowered to UB in 
release builds - the text isn't in the program anymore. The text is only for 
Clang developers (and/or clang-as-library users).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8824
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();

erichkeane wrote:
> I am not really sure this is the right way about this.  You're supposed to be 
> testing `T`, but this looks like it is checking the type of `E`, isn't it?  I 
> think you just need to check `Cast->getType()`.
For the case I'm trying to fix, `T` is array of unknown bound, it is already 
checked before calling `completeExprArrayBound`. Right now when you write 
something like
```
int (&&arr1)[1] = static_cast(42);
```
Clang actually is able to realize that parenthesized initialization is made, so 
it actually generates `CXXParenListInitExpr` that has type int[1]. Here I'm 
just paranoidally double-checking that is the case before switching the type. 
Maybe I don't need this double-check at all then?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8824
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();

Fznamznon wrote:
> erichkeane wrote:
> > I am not really sure this is the right way about this.  You're supposed to 
> > be testing `T`, but this looks like it is checking the type of `E`, isn't 
> > it?  I think you just need to check `Cast->getType()`.
> For the case I'm trying to fix, `T` is array of unknown bound, it is already 
> checked before calling `completeExprArrayBound`. Right now when you write 
> something like
> ```
> int (&&arr1)[1] = static_cast(42);
> ```
> Clang actually is able to realize that parenthesized initialization is made, 
> so it actually generates `CXXParenListInitExpr` that has type int[1]. Here 
> I'm just paranoidally double-checking that is the case before switching the 
> type. Maybe I don't need this double-check at all then?
> 
That makes me wonder if this is the correct place for this?  Should when we 
generate this type when we do the `CXXParenListInitExpr` fixup?

Either way, I think making this depend on that behavior (which would possibly 
be fragile), we should just do it based on the type passed ot the `static_cast`.

Another question: is this something that needs to be done for other cast types? 
 Does similar behavior exist for the other casts?  Should it also happen with 
'clobber' casts (C-style) that are effectively static?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D149573#4390895 , @codemzs wrote:

> In D149573#4390863 , @stuij wrote:
>
>> This is going to be a very unhelpful comment. After looking through the 
>> changes, I don't have any comments to make, but I also don't feel 
>> comfortable to accept this revision as I don't feel to know enough about the 
>> front-end.
>
> @stuij, I sincerely appreciate you taking the time to review the changes. 
> Your hesitation due to unfamiliarity with the front-end elements is 
> completely understandable, and I respect your candid feedback.
>
> @erichkeane, given your extensive contributions to the core `Sema`* files, I 
> believe your expertise and experience would be particularly valuable in 
> reviewing the changes I've made. I recall your initial informal approval for 
> the change, and since then, I've further refined it after incorporating the 
> outcomes of D150913 . I'd be most 
> appreciative if you could please review this revision once again.
>
> My intention is to ensure this revision aligns with our shared vision for 
> LLVM/Clang, and your reviews will greatly contribute to this goal. If there 
> are any other changes or improvements required for the successful landing of 
> this revision, please feel free to let me know.

I'll put you on my list to re-review for early next week, though Aaron probably 
needs to do a look through this as well.


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

https://reviews.llvm.org/D149573

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


[clang] 19841e4 - [OpenMP] Fix transformed loop's var privacy

2023-06-02 Thread Joel E. Denny via cfe-commits

Author: Joel E. Denny
Date: 2023-06-02T12:18:13-04:00
New Revision: 19841e4dcaabe573d35eb88a130fc34d32ecd708

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

LOG: [OpenMP] Fix transformed loop's var privacy

Without this patch, the following example crashes Clang:

```
 #pragma omp target map(i)
 #pragma omp tile sizes(2)
 for (i = 0; i < N; ++i)
   ;
```

This patch fixes the crash by changing `Sema::isOpenMPPrivateDecl` not
to identify `i` as private just because it's the loop variable of a
`tile` construct.

While OpenMP TR11 and earlier do specify privacy for loop variables of
loops *generated* from a `tile` construct, I haven't found text
stating that the original loop variable must be private in the above
example, so this patch leaves it shared.  Even so, it is a bit
unexpected that value of `i` after the loop is `N - 1` instead of `N`.

Reviewed By: ABataev

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

Added: 
openmp/libomptarget/test/offloading/target-tile.c

Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6e83e20d96d59..0b6f5be9f0447 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2551,7 +2551,8 @@ OpenMPClauseKind Sema::isOpenMPPrivateDecl(ValueDecl *D, 
unsigned Level,
   }
 }
   }
-  if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) {
+  if (isOpenMPLoopDirective(DSAStack->getCurrentDirective()) &&
+  !isOpenMPLoopTransformationDirective(DSAStack->getCurrentDirective())) {
 if (DSAStack->getAssociatedLoops() > 0 && !DSAStack->isLoopStarted()) {
   DSAStack->resetPossibleLoopCounter(D);
   DSAStack->loopStart();

diff  --git a/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp 
b/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
index 44127525b2527..a710d889a0b6d 100644
--- a/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
+++ b/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
@@ -21,7 +21,7 @@ extern "C" void body(...) {}
 // IR-NEXT:store i32 %[[START:.+]], ptr %[[START_ADDR]], align 4
 // IR-NEXT:store i32 %[[END:.+]], ptr %[[END_ADDR]], align 4
 // IR-NEXT:store i32 %[[STEP:.+]], ptr %[[STEP_ADDR]], align 4
-// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, 
ptr @func.omp_outlined, ptr %[[END_ADDR]], ptr %[[STEP_ADDR]], ptr 
%[[START_ADDR]])
+// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, 
ptr @func.omp_outlined, ptr %[[START_ADDR]], ptr %[[END_ADDR]], ptr 
%[[STEP_ADDR]])
 // IR-NEXT:ret void
 // IR-NEXT:  }
 extern "C" void func(int start, int end, int step) {
@@ -36,9 +36,9 @@ extern "C" void func(int start, int end, int step) {
 // IR-NEXT:  [[ENTRY:.*]]:
 // IR-NEXT:%[[DOTGLOBAL_TID__ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTBOUND_TID__ADDR:.+]] = alloca ptr, align 8
+// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[END_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[STEP_ADDR:.+]] = alloca ptr, align 8
-// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
 // IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
 // IR-NEXT:%[[I:.+]] = alloca i32, align 4
@@ -57,12 +57,12 @@ extern "C" void func(int start, int end, int step) {
 // IR-NEXT:%[[DOTUNROLL_INNER_IV_I:.+]] = alloca i32, align 4
 // IR-NEXT:store ptr %[[DOTGLOBAL_TID_:.+]], ptr %[[DOTGLOBAL_TID__ADDR]], 
align 8
 // IR-NEXT:store ptr %[[DOTBOUND_TID_:.+]], ptr %[[DOTBOUND_TID__ADDR]], 
align 8
+// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
 // IR-NEXT:store ptr %[[END:.+]], ptr %[[END_ADDR]], align 8
 // IR-NEXT:store ptr %[[STEP:.+]], ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
+// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP0:.+]] = load ptr, ptr %[[END_ADDR]], align 8
 // IR-NEXT:%[[TMP1:.+]] = load ptr, ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP3:.+]] = load i32, ptr %[[TMP2]], align 4
 // IR-NEXT:store i32 %[[TMP3]], ptr %[[I]], align 4
 // IR-NEXT:%[[TMP4:.+]] = load i32, ptr %[[TMP2]], align 4

diff  --git a/openmp/libomptarget/test/offloading/target-tile.c 
b/openmp/libomptarget/test/offloading/target-tile.c
new file mode 100644
index 0..8460b43b6f9c7
--- /dev/null
+++ b/openmp/libomptarget/test/offloading/target-tile.c
@@ -0,0 +1,62 @@
+// Check that omp tile (introduced in OpenMP 5.1) is permitted and behaves when
+//

[PATCH] D151356: [OpenMP] Fix transformed loop's var privacy

2023-06-02 Thread Joel E. Denny 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 rG19841e4dcaab: [OpenMP] Fix transformed loop's var 
privacy (authored by jdenny).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151356

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
  openmp/libomptarget/test/offloading/target-tile.c

Index: openmp/libomptarget/test/offloading/target-tile.c
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/target-tile.c
@@ -0,0 +1,62 @@
+// Check that omp tile (introduced in OpenMP 5.1) is permitted and behaves when
+// strictly nested within omp target.
+
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic
+
+#include 
+
+#define I_NTILES 8
+#define J_NTILES 9
+#define I_NELEMS 2
+#define J_NELEMS 3
+
+int main() {
+  int order[I_NTILES][J_NTILES][I_NELEMS][J_NELEMS];
+  int i, j;
+  #pragma omp target map(tofrom: i, j)
+  {
+int next = 0;
+#pragma omp tile sizes(I_NELEMS, J_NELEMS)
+for (i = 0; i < I_NTILES * I_NELEMS; ++i) {
+  for (j = 0; j < J_NTILES * J_NELEMS; ++j) {
+int iTile = i / I_NELEMS;
+int jTile = j / J_NELEMS;
+int iElem = i % I_NELEMS;
+int jElem = j % J_NELEMS;
+order[iTile][jTile][iElem][jElem] = next++;
+  }
+}
+  }
+  int expected = 0;
+  for (int iTile = 0; iTile < I_NTILES; ++iTile) {
+for (int jTile = 0; jTile < J_NTILES; ++jTile) {
+  for (int iElem = 0; iElem < I_NELEMS; ++iElem) {
+for (int jElem = 0; jElem < J_NELEMS; ++jElem) {
+  int actual = order[iTile][jTile][iElem][jElem];
+  if (expected != actual) {
+printf("error: order[%d][%d][%d][%d] = %d, expected %d\n",
+   iTile, jTile, iElem, jElem, actual, expected);
+return 1;
+  }
+  ++expected;
+}
+  }
+}
+  }
+  // Tiling leaves the loop variables with their values from the final iteration
+  // rather than with the usual +1.
+  expected = I_NTILES * I_NELEMS - 1;
+  if (i != expected) {
+printf("error: i = %d, expected %d\n", i, expected);
+return 1;
+  }
+  expected = J_NTILES * J_NELEMS - 1;
+  if (j != expected) {
+printf("error: j = %d, expected %d\n", j, expected);
+return 1;
+  }
+  // CHECK: success
+  printf("success\n");
+  return 0;
+}
Index: clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
===
--- clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
+++ clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
@@ -21,7 +21,7 @@
 // IR-NEXT:store i32 %[[START:.+]], ptr %[[START_ADDR]], align 4
 // IR-NEXT:store i32 %[[END:.+]], ptr %[[END_ADDR]], align 4
 // IR-NEXT:store i32 %[[STEP:.+]], ptr %[[STEP_ADDR]], align 4
-// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, ptr @func.omp_outlined, ptr %[[END_ADDR]], ptr %[[STEP_ADDR]], ptr %[[START_ADDR]])
+// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, ptr @func.omp_outlined, ptr %[[START_ADDR]], ptr %[[END_ADDR]], ptr %[[STEP_ADDR]])
 // IR-NEXT:ret void
 // IR-NEXT:  }
 extern "C" void func(int start, int end, int step) {
@@ -36,9 +36,9 @@
 // IR-NEXT:  [[ENTRY:.*]]:
 // IR-NEXT:%[[DOTGLOBAL_TID__ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTBOUND_TID__ADDR:.+]] = alloca ptr, align 8
+// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[END_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[STEP_ADDR:.+]] = alloca ptr, align 8
-// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
 // IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
 // IR-NEXT:%[[I:.+]] = alloca i32, align 4
@@ -57,12 +57,12 @@
 // IR-NEXT:%[[DOTUNROLL_INNER_IV_I:.+]] = alloca i32, align 4
 // IR-NEXT:store ptr %[[DOTGLOBAL_TID_:.+]], ptr %[[DOTGLOBAL_TID__ADDR]], align 8
 // IR-NEXT:store ptr %[[DOTBOUND_TID_:.+]], ptr %[[DOTBOUND_TID__ADDR]], align 8
+// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
 // IR-NEXT:store ptr %[[END:.+]], ptr %[[END_ADDR]], align 8
 // IR-NEXT:store ptr %[[STEP:.+]], ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
+// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP0:.+]] = load ptr, ptr %[[END_ADDR]], align 8
 // IR-NEXT:%[[TMP1:.+]] = load ptr, ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP3:.+]] = load i32, ptr %[[TMP2]], align 4
 // IR-NEXT:store i32 %[[TMP3]], ptr %[[I]], align 4
 // IR-

[PATCH] D151356: [OpenMP] Fix transformed loop's var privacy

2023-06-02 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151356

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


[PATCH] D151350: [OpenMP] Extend omp teams to permit nested omp tile

2023-06-02 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Ping.


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

https://reviews.llvm.org/D151350

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


[clang] 8b5dbc3 - [CodeGen] Use llvm::LLVMContext::MD_invariant_load (NFC)

2023-06-02 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-06-02T09:25:00-07:00
New Revision: 8b5dbc37a899faf0d2cb842bcb1ebc66a319c394

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

LOG: [CodeGen] Use llvm::LLVMContext::MD_invariant_load (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 7df2088a81d79..c8f0070192dd6 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -140,7 +140,7 @@ llvm::Value 
*CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,
 LValue LV = MakeNaturalAlignAddrLValue(Constant, IdTy);
 llvm::Value *Ptr = EmitLoadOfScalar(LV, E->getBeginLoc());
 cast(Ptr)->setMetadata(
-CGM.getModule().getMDKindID("invariant.load"),
+llvm::LLVMContext::MD_invariant_load,
 llvm::MDNode::get(getLLVMContext(), std::nullopt));
 return Builder.CreateBitCast(Ptr, ConvertType(E->getType()));
   }

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 5f4cdc6d91f1d..d52e560234bdf 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -7229,7 +7229,7 @@ 
CGObjCNonFragileABIMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
   CGF.getSizeAlign(), "ivar");
 if (IsIvarOffsetKnownIdempotent(CGF, Ivar))
   cast(IvarOffsetValue)
-  ->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
+  ->setMetadata(llvm::LLVMContext::MD_invariant_load,
 llvm::MDNode::get(VMContext, std::nullopt));
   }
 
@@ -7629,7 +7629,7 @@ llvm::Value 
*CGObjCNonFragileABIMac::EmitSelector(CodeGenFunction &CGF,
   Address Addr = EmitSelectorAddr(Sel);
 
   llvm::LoadInst* LI = CGF.Builder.CreateLoad(Addr);
-  LI->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
+  LI->setMetadata(llvm::LLVMContext::MD_invariant_load,
   llvm::MDNode::get(VMContext, std::nullopt));
   return LI;
 }



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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a subscriber: aaron.ballman.
codemzs added a comment.

In D149573#4391013 , @erichkeane 
wrote:

> In D149573#4390895 , @codemzs wrote:
>
>> In D149573#4390863 , @stuij wrote:
>>
>>> This is going to be a very unhelpful comment. After looking through the 
>>> changes, I don't have any comments to make, but I also don't feel 
>>> comfortable to accept this revision as I don't feel to know enough about 
>>> the front-end.
>>
>> @stuij, I sincerely appreciate you taking the time to review the changes. 
>> Your hesitation due to unfamiliarity with the front-end elements is 
>> completely understandable, and I respect your candid feedback.
>>
>> @erichkeane, given your extensive contributions to the core `Sema`* files, I 
>> believe your expertise and experience would be particularly valuable in 
>> reviewing the changes I've made. I recall your initial informal approval for 
>> the change, and since then, I've further refined it after incorporating the 
>> outcomes of D150913 . I'd be most 
>> appreciative if you could please review this revision once again.
>>
>> My intention is to ensure this revision aligns with our shared vision for 
>> LLVM/Clang, and your reviews will greatly contribute to this goal. If there 
>> are any other changes or improvements required for the successful landing of 
>> this revision, please feel free to let me know.
>
> I'll put you on my list to re-review for early next week, though Aaron 
> probably needs to do a look through this as well.

Thank you, @erichkeane that would be great, are you referring to @aaron.ballman 
?


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

https://reviews.llvm.org/D149573

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


[clang] 5b77e75 - [Driver] Move -nostdinc like options into IncludePath_Group

2023-06-02 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-06-02T09:33:08-07:00
New Revision: 5b77e752dcd073846b89559d6c0e1a7699e58615

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

LOG: [Driver] Move -nostdinc like options into IncludePath_Group

With only a link action, we claim all CompileOnly_Group options (including -f*,
-m*, -i*, etc). It makes sense to claim -nostdinc family options as well.
We can achieve this by placing these options into IncludePath_Group, a 
derivative of
CompileOnly_Group.

Reviewed By: theuni

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/linker-opts.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b77fec6720792..29b41002cf37b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,7 @@ def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names"
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
 FlangOption]>, HelpText<"Display available options">,
 MarshallingInfoFlag>;
-def ibuiltininc : Flag<["-"], "ibuiltininc">,
+def ibuiltininc : Flag<["-"], "ibuiltininc">, Group,
   HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
@@ -4194,12 +4194,13 @@ def no_cpp_precomp : Flag<["-"], "no-cpp-precomp">, 
Group
 def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, 
Flags<[NoXarchOption]>;
 def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group;
 def no__dead__strip__inits__and__terms : Flag<["-"], 
"no_dead_strip_inits_and_terms">;
-def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
+def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, 
CoreOption]>, Group,
   HelpText<"Disable builtin #include directories">,
   MarshallingInfoNegativeFlag>;
-def nogpuinc : Flag<["-"], "nogpuinc">, HelpText<"Do not add include paths for 
CUDA/HIP and"
+def nogpuinc : Flag<["-"], "nogpuinc">, Group,
+  HelpText<"Do not add include paths for CUDA/HIP and"
   " do not include the default CUDA/HIP wrapper headers">;
-def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group,
   HelpText<"Do not include the default HIP wrapper headers and include paths">;
 def : Flag<["-"], "nocudainc">, Alias;
 def nogpulib : Flag<["-"], "nogpulib">, 
MarshallingInfoFlag>,
@@ -4216,9 +4217,9 @@ def noprebind : Flag<["-"], "noprebind">;
 def noprofilelib : Flag<["-"], "noprofilelib">;
 def noseglinkedit : Flag<["-"], "noseglinkedit">;
 def nostartfiles : Flag<["-"], "nostartfiles">, Group;
-def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>;
-def nostdlibinc : Flag<["-"], "nostdlibinc">;
-def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>,
+def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>, 
Group;
+def nostdlibinc : Flag<["-"], "nostdlibinc">, Group;
+def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>, 
Group,
   HelpText<"Disable standard #include directories for the C++ standard 
library">,
   MarshallingInfoNegativeFlag>;
 def nostdlib : Flag<["-"], "nostdlib">, Group;

diff  --git a/clang/test/Driver/linker-opts.c b/clang/test/Driver/linker-opts.c
index e3c4e00ea0c75..319cc591cc3c8 100644
--- a/clang/test/Driver/linker-opts.c
+++ b/clang/test/Driver/linker-opts.c
@@ -15,9 +15,8 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
-// NO-UNUSED-NOT: warning:{{.*}}unused
-//
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null 
--implicit-check-not=warning:
+
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s 
--check-prefix=UNUSED
 // UNUSED: warning:{{.*}}unused



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


[PATCH] D151944: [Driver] Move -nostdinc like options into IncludePath_Group

2023-06-02 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b77e752dcd0: [Driver] Move -nostdinc like options into 
IncludePath_Group (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D151944?vs=527645&id=527884#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151944

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/linker-opts.c


Index: clang/test/Driver/linker-opts.c
===
--- clang/test/Driver/linker-opts.c
+++ clang/test/Driver/linker-opts.c
@@ -15,9 +15,8 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
-// NO-UNUSED-NOT: warning:{{.*}}unused
-//
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null 
--implicit-check-not=warning:
+
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s 
--check-prefix=UNUSED
 // UNUSED: warning:{{.*}}unused
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,7 @@
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
 FlangOption]>, HelpText<"Display available options">,
 MarshallingInfoFlag>;
-def ibuiltininc : Flag<["-"], "ibuiltininc">,
+def ibuiltininc : Flag<["-"], "ibuiltininc">, Group,
   HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
@@ -4194,12 +4194,13 @@
 def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, 
Flags<[NoXarchOption]>;
 def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group;
 def no__dead__strip__inits__and__terms : Flag<["-"], 
"no_dead_strip_inits_and_terms">;
-def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
+def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, 
CoreOption]>, Group,
   HelpText<"Disable builtin #include directories">,
   MarshallingInfoNegativeFlag>;
-def nogpuinc : Flag<["-"], "nogpuinc">, HelpText<"Do not add include paths for 
CUDA/HIP and"
+def nogpuinc : Flag<["-"], "nogpuinc">, Group,
+  HelpText<"Do not add include paths for CUDA/HIP and"
   " do not include the default CUDA/HIP wrapper headers">;
-def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group,
   HelpText<"Do not include the default HIP wrapper headers and include paths">;
 def : Flag<["-"], "nocudainc">, Alias;
 def nogpulib : Flag<["-"], "nogpulib">, 
MarshallingInfoFlag>,
@@ -4216,9 +4217,9 @@
 def noprofilelib : Flag<["-"], "noprofilelib">;
 def noseglinkedit : Flag<["-"], "noseglinkedit">;
 def nostartfiles : Flag<["-"], "nostartfiles">, Group;
-def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>;
-def nostdlibinc : Flag<["-"], "nostdlibinc">;
-def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>,
+def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>, 
Group;
+def nostdlibinc : Flag<["-"], "nostdlibinc">, Group;
+def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>, 
Group,
   HelpText<"Disable standard #include directories for the C++ standard 
library">,
   MarshallingInfoNegativeFlag>;
 def nostdlib : Flag<["-"], "nostdlib">, Group;


Index: clang/test/Driver/linker-opts.c
===
--- clang/test/Driver/linker-opts.c
+++ clang/test/Driver/linker-opts.c
@@ -15,9 +15,8 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
-// NO-UNUSED-NOT: warning:{{.*}}unused
-//
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ -nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null --implicit-check-not=warning:
+
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s --check-prefix=UNUSED
 // UNUSED: warning:{{.*}}unused
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,7 @@
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
 FlangOption]>, HelpText<"Display available options">,
 MarshallingInfoFlag>;
-def ibuiltininc : Flag<["-"], "ibuil

[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D149573#4391083 , @codemzs wrote:

> In D149573#4391013 , @erichkeane 
> wrote:
>
>> In D149573#4390895 , @codemzs 
>> wrote:
>>
>>> In D149573#4390863 , @stuij wrote:
>>>
 This is going to be a very unhelpful comment. After looking through the 
 changes, I don't have any comments to make, but I also don't feel 
 comfortable to accept this revision as I don't feel to know enough about 
 the front-end.
>>>
>>> @stuij, I sincerely appreciate you taking the time to review the changes. 
>>> Your hesitation due to unfamiliarity with the front-end elements is 
>>> completely understandable, and I respect your candid feedback.
>>>
>>> @erichkeane, given your extensive contributions to the core `Sema`* files, 
>>> I believe your expertise and experience would be particularly valuable in 
>>> reviewing the changes I've made. I recall your initial informal approval 
>>> for the change, and since then, I've further refined it after incorporating 
>>> the outcomes of D150913 . I'd be most 
>>> appreciative if you could please review this revision once again.
>>>
>>> My intention is to ensure this revision aligns with our shared vision for 
>>> LLVM/Clang, and your reviews will greatly contribute to this goal. If there 
>>> are any other changes or improvements required for the successful landing 
>>> of this revision, please feel free to let me know.
>>
>> I'll put you on my list to re-review for early next week, though Aaron 
>> probably needs to do a look through this as well.
>
> Thank you, @erichkeane that would be great, are you referring to 
> @aaron.ballman ?

Yes.


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

https://reviews.llvm.org/D149573

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/include/clang/AST/Stmt.h:796-802
+/// If this expression is not value-dependent, this stores the value.
+unsigned Value : 8;
 
 /// The number of arguments to this type trait. According to [implimits]
 /// 8 bits would be enough, but we require (and test for) at least 16 bits
 /// to mirror FunctionType.
+unsigned NumArgs : 16;

erichkeane wrote:
> dblaikie wrote:
> > cjdb wrote:
> > > These numbers feel very low for how this modification is using them. 
> > > Perhaps they should both be bumped to 32?
> > clang does, I think, have specific implementation limits for this sort of 
> > thing - 
> > 
> > Well, maybe we don't actually enforce a limit on number of template 
> > arguments... https://godbolt.org/z/accncYson compiles successfully, and has 
> > 2^18 parameters, beyond the 2^16 suggested here.
> > 
> > But maybe 2^16 is just what we test for/somewhat guarantee.
> > 
> > But if the `Value` is going to be the index into the args, shouldn't it be 
> > the same size as `NumArgs`, at least? (& the comment says 16, so 16 for 
> > both Value and NumArgs would seem suitably symmetric, and no larger than 
> > the current situation - since it'd just be splitting NumArgs in half, while 
> > still meeting the comment's suggestion/requirements?)
> > 
> > An assert, at least, when populating NumArgs to ensure it's no larger might 
> > not hurt... (which might be reachable from code/not checked prior - so it 
> > could be a hard compilation error, I guess, but I wouldn't feel super 
> > strongly about it)
> Can you explain the math here of how you chose to change this to 16?  I see 
> that you removed 7 bits, but took away 16.  I'm not sure what NumExprBits is 
> doing though, I got lost a little in that, so if you can calculate that to 
> make sure this needs to be done, it would be appreciated.
> 
> Additionally, a static_assert after this to ensure the size isn't changing 
> would also be appreciated.
> 
> But if the Value is going to be the index into the args, shouldn't it be the 
> same size as NumArgs, at least? (& the comment says 16, so 16 for both Value 
> and NumArgs would seem suitably symmetric, and no larger than the current 
> situation - since it'd just be splitting NumArgs in half, while still meeting 
> the comment's suggestion/requirements?)

Someone independently confirmed that you can have 200k types in a template, so 
we should probably be able to count at least that high (or alternatively, we 
should possibly consider not allowing more than 2^16 template parameters).

> Can you explain the math here of how you chose to change this to 16? I see 
> that you removed 7 bits, but took away 16. I'm not sure what NumExprBits is 
> doing though, I got lost a little in that, so if you can calculate that to 
> make sure this needs to be done, it would be appreciated.

The value of `NumArgs` hasn't changed: I've just codified it. I can't work out 
why we need `NumExprBits`, but it's apparently required padding (when I removed 
it, a bunch of tests failed). Its value is 18, courtesy of clangd in VS Code.

> Additionally, a static_assert after this to ensure the size isn't changing 
> would also be appreciated.

There's a static_assert in one of the `Stmt` constructors, which doesn't want 
more than eight bytes (we apparently need 16 if we're to change this).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/AST/Stmt.h:796-802
+/// If this expression is not value-dependent, this stores the value.
+unsigned Value : 8;
 
 /// The number of arguments to this type trait. According to [implimits]
 /// 8 bits would be enough, but we require (and test for) at least 16 bits
 /// to mirror FunctionType.
+unsigned NumArgs : 16;

cjdb wrote:
> erichkeane wrote:
> > dblaikie wrote:
> > > cjdb wrote:
> > > > These numbers feel very low for how this modification is using them. 
> > > > Perhaps they should both be bumped to 32?
> > > clang does, I think, have specific implementation limits for this sort of 
> > > thing - 
> > > 
> > > Well, maybe we don't actually enforce a limit on number of template 
> > > arguments... https://godbolt.org/z/accncYson compiles successfully, and 
> > > has 2^18 parameters, beyond the 2^16 suggested here.
> > > 
> > > But maybe 2^16 is just what we test for/somewhat guarantee.
> > > 
> > > But if the `Value` is going to be the index into the args, shouldn't it 
> > > be the same size as `NumArgs`, at least? (& the comment says 16, so 16 
> > > for both Value and NumArgs would seem suitably symmetric, and no larger 
> > > than the current situation - since it'd just be splitting NumArgs in 
> > > half, while still meeting the comment's suggestion/requirements?)
> > > 
> > > An assert, at least, when populating NumArgs to ensure it's no larger 
> > > might not hurt... (which might be reachable from code/not checked prior - 
> > > so it could be a hard compilation error, I guess, but I wouldn't feel 
> > > super strongly about it)
> > Can you explain the math here of how you chose to change this to 16?  I see 
> > that you removed 7 bits, but took away 16.  I'm not sure what NumExprBits 
> > is doing though, I got lost a little in that, so if you can calculate that 
> > to make sure this needs to be done, it would be appreciated.
> > 
> > Additionally, a static_assert after this to ensure the size isn't changing 
> > would also be appreciated.
> > 
> > But if the Value is going to be the index into the args, shouldn't it be 
> > the same size as NumArgs, at least? (& the comment says 16, so 16 for both 
> > Value and NumArgs would seem suitably symmetric, and no larger than the 
> > current situation - since it'd just be splitting NumArgs in half, while 
> > still meeting the comment's suggestion/requirements?)
> 
> Someone independently confirmed that you can have 200k types in a template, 
> so we should probably be able to count at least that high (or alternatively, 
> we should possibly consider not allowing more than 2^16 template parameters).
> 
> > Can you explain the math here of how you chose to change this to 16? I see 
> > that you removed 7 bits, but took away 16. I'm not sure what NumExprBits is 
> > doing though, I got lost a little in that, so if you can calculate that to 
> > make sure this needs to be done, it would be appreciated.
> 
> The value of `NumArgs` hasn't changed: I've just codified it. I can't work 
> out why we need `NumExprBits`, but it's apparently required padding (when I 
> removed it, a bunch of tests failed). Its value is 18, courtesy of clangd in 
> VS Code.
> 
> > Additionally, a static_assert after this to ensure the size isn't changing 
> > would also be appreciated.
> 
> There's a static_assert in one of the `Stmt` constructors, which doesn't want 
> more than eight bytes (we apparently need 16 if we're to change this).
Got it, thanks!  We need the `NumExprBits` because this gets cast to that 
`ExprBitFields` (since this inherits from Expr).  So thats the 'base type' bits.

18 + 8 + 8 (for the `NumExprbits` and `Kind` and `Value` fields) is 34, so that 
leaves plenty of extra bits here, right?  Usually in these cases we leave 
things 'as big as we can without growing the thing', then comment where extra 
bits can be stolen in the future.

So I would just make this 'the rest' of our size, since we're already over 4 
bytes, mind as well use them as long as we can.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D151634: [clang] Add test for CWG253

2023-06-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/CXX/drs/dr0xx.cpp:1022
 
-namespace dr78 { // dr78: sup 
+namespace dr78 { // dr78: no
   // Under DR78, this is valid, because 'k' has static storage duration, so is

shafik wrote:
> This is [issue 1380](https://github.com/cplusplus/papers/issues/1380) and the 
> issue is whether we want static initialization to happen before constant 
> initialization or whether constant initialization excludes zero-init. 
> 
> I think dr77 is now part of [cwg 
> 2536](https://cplusplus.github.io/CWG/issues/2536.html) and we need to wait 
> for the resolution of that in order to know what to do here. 
I was mistaken and completely missed: 
https://eel.is/c++draft/dcl.init#general-8.sentence-2

DR 78 is just repeating what we have in: 
https://eel.is/c++draft/basic.start#static

The wording has changed a lot since DR 78.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151634

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


cfe-commits@lists.llvm.org

2023-06-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

@massberg did we figure out if there is anything else left from P2002R1? Are 
there blockers to landing this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148924

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


[PATCH] D152009: [clang] Fix assertion while parsing an invalid for loop

2023-06-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

with multiple declarations followed by a colon.

Fixes #63010


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152009

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Parser/cxx0x-for-range.cpp
  clang/test/Parser/objc-foreach-syntax.m


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -11,18 +11,16 @@
 
 int LOOP(void);
 
-@implementation MyList (BasicTest) 
+@implementation MyList (BasicTest)
 - (void)compilerTestAgainst {
-MyList * el; 
- for (el in @"foo") 
+MyList * el;
+ for (el in @"foo")
  { LOOP(); }
 }
 @end
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 
'in'}} \
-   // expected-error {{expected ';' in 'for' statement 
specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement 
specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' 
statement specifier}} \
+  // expected-error {{expected expression}}
+for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' 
in 'for' statement specifier}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
 if (Tok.isNot(tok::semi)) {
   if (!SecondPart.isInvalid())
 Diag(Tok, diag::err_expected_semi_for);
-  else
-// Skip until semicolon or rparen, don't consume it.
-SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
+  SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
 }
 
 if (Tok.is(tok::semi)) {
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2138,8 +2138,6 @@
 DeclGroupPtrTy DG = ParseSimpleDeclaration(
 DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false, FRI);
 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
-assert((FRI->ColonLoc.isValid() || !DG) &&
-   "cannot find for range declaration");
 return Sema::ConditionResult();
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -455,6 +455,9 @@
 - Fix crash when diagnosing default comparison method.
   (`#62791 `_) and
   (`#62102 `_).
+- Fix assertion and quality of diagnostic messages in a for loop
+  containing multiple declarations and a range specifier
+  (`#63010 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -11,18 +11,16 @@
 
 int LOOP(void);
 
-@implementation MyList (BasicTest) 
+@implementation MyList (BasicTest)
 - (void)compilerTestAgainst {
-MyList * el; 
- for (el in @"foo") 
+MyList * el;
+ for (el in @"foo")
 	  { LOOP(); }
 }
 @end
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 'in'}} \
-   // expected-error {{expected ';' in 'for' statement specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); 

[PATCH] D144911: adding bf16 support to NVPTX

2023-06-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D144911#4389187 , @manishucsd 
wrote:

> I fail to compile this patch. Please find the compilation error below:
>
>   [build] ./llvm-project/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:1117:40: 
> error: Variable not defined: 'hasPTX70'
>   [build] Requires<[useFP16Math, hasPTX70, hasSM80, Pred]>;
>   [build]^

You need to update your patch. Recent LLVM changes have changed `hasPTXab` -> 
`hasPTX`, and similarly `hasSMab` > `hasSM`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144911

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


[PATCH] D152009: [clang] Fix assertion while parsing an invalid for loop

2023-06-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 527902.
cor3ntin added a comment.

revert ws changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152009

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Parser/cxx0x-for-range.cpp
  clang/test/Parser/objc-foreach-syntax.m


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -21,8 +21,6 @@
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 
'in'}} \
-   // expected-error {{expected ';' in 'for' statement 
specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement 
specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' 
statement specifier}} \
+  // expected-error {{expected expression}}
+for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' 
in 'for' statement specifier}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
 if (Tok.isNot(tok::semi)) {
   if (!SecondPart.isInvalid())
 Diag(Tok, diag::err_expected_semi_for);
-  else
-// Skip until semicolon or rparen, don't consume it.
-SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
+  SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
 }
 
 if (Tok.is(tok::semi)) {
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2138,8 +2138,6 @@
 DeclGroupPtrTy DG = ParseSimpleDeclaration(
 DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false, FRI);
 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
-assert((FRI->ColonLoc.isValid() || !DG) &&
-   "cannot find for range declaration");
 return Sema::ConditionResult();
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -455,6 +455,9 @@
 - Fix crash when diagnosing default comparison method.
   (`#62791 `_) and
   (`#62102 `_).
+- Fix assertion and quality of diagnostic messages in a for loop
+  containing multiple declarations and a range specifier
+  (`#63010 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -21,8 +21,6 @@
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 'in'}} \
-   // expected-error {{expected ';' in 'for' statement specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}} \
+  // expected-error {{expected expression}}
+for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
 if (Tok.isNot(tok::semi)) {
   if (!SecondPart.isInvalid())
 Diag(Tok, diag::er

[PATCH] D151634: [clang] Add test for CWG253

2023-06-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/CXX/drs/dr0xx.cpp:1022
 
-namespace dr78 { // dr78: sup 
+namespace dr78 { // dr78: no
   // Under DR78, this is valid, because 'k' has static storage duration, so is

shafik wrote:
> shafik wrote:
> > This is [issue 1380](https://github.com/cplusplus/papers/issues/1380) and 
> > the issue is whether we want static initialization to happen before 
> > constant initialization or whether constant initialization excludes 
> > zero-init. 
> > 
> > I think dr77 is now part of [cwg 
> > 2536](https://cplusplus.github.io/CWG/issues/2536.html) and we need to wait 
> > for the resolution of that in order to know what to do here. 
> I was mistaken and completely missed: 
> https://eel.is/c++draft/dcl.init#general-8.sentence-2
> 
> DR 78 is just repeating what we have in: 
> https://eel.is/c++draft/basic.start#static
> 
> The wording has changed a lot since DR 78.
Can you please elaborate how does your conclusion affect this patch? Because I 
feel a bit lost at this point.
Was my initial analysis correct, and we should say that this DR is not 
available in Clang?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151634

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


[clang-tools-extra] 860e439 - [Clang] Fix missing libraries for the include cleaner check

2023-06-02 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-06-02T12:43:55-05:00
New Revision: 860e439fb27f86b97bfd9acce5e27f4337c471c7

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

LOG: [Clang] Fix missing libraries for the include cleaner check

Summary:
Recently, the changes in https://reviews.llvm.org/D148793 introduced
some extra dependencies that caused link failured on my machine. This
patch adds the necessary libraries to resolve the link failures and
allow me to build again.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 1703ff82b942d..fde72f6b25a54 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -55,8 +55,11 @@ clang_target_link_libraries(clangTidyMiscModule
   clangAST
   clangASTMatchers
   clangBasic
+  clangFormat
   clangIncludeCleaner
   clangLex
   clangSerialization
   clangTooling
+  clangToolingInclusions
+  clangToolingInclusionsStdlib
   )



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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1324
 // This is a string literal initializing an array in an initializer.
-return CGM.GetConstantArrayFromStringLiteral(E);
+return E->isLValue() ?
+  CGM.GetAddrOfConstantStringFromLiteral(E).getPointer() :

efriedma wrote:
> nickdesaulniers wrote:
> > nickdesaulniers wrote:
> > > efriedma wrote:
> > > > nickdesaulniers wrote:
> > > > > efriedma wrote:
> > > > > > Maybe we should have a separate ConstExprEmitterLValue... trying to 
> > > > > > handle both LValues and RValues on the same codepath has been 
> > > > > > problematic in the past.  It's very easy for code to get confused 
> > > > > > what it's actually trying to emit.
> > > > > So we'd have a `ConstExprEmitterLValue` class with some visitor 
> > > > > methods, and a `ConstExprEmitterRValue` with other methods 
> > > > > implemented?
> > > > Something like that.
> > > > 
> > > > Actually thinking about it a bit more, not sure you need to actually 
> > > > implement ConstExprEmitterLValue for now.  You might just be able to 
> > > > ensure we don't ever call ConstExprEmitter with an lvalue.  The current 
> > > > ConstExprEmitter doesn't expect lvalues, and shouldn't call itself with 
> > > > lvalues.  (We bail on explicit LValueToRValue conversions.)  And 
> > > > Evaluate() shouldn't actually evaluate the contents of an lvalue if it 
> > > > isn't dereferenced, so there hopefully aren't any performance issues 
> > > > using that codepath.
> > > > 
> > > > In terms of implementation, I guess that's basically restoring the 
> > > > destType->isReferenceType() that got removed?  (I know I suggested it, 
> > > > but I wasn't really thinking about it...)
> > > One thing I think we may need to add to `ConstExprEmitter` is the ability 
> > > to evaluate `CallExpr`s based on certain test case failures...does that 
> > > seem right?
> > See also the calls to `constexpr f()` in 
> > clang/test/CodeGenCXX/const-init-cxx1y.cpp
> The only things I know of that Evaluate() can't handle are CK_ToUnion, 
> CK_ReinterpretMemberPointer, and DesignatedInitUpdateExpr.  
> DesignatedInitUpdateExpr is related to the failures in 
> test/CodeGenCXX/designated-init.cpp; I don't think the others show up in any 
> of the testcases you've mentioned.  (CK_ToUnion can't appear in C++ code. 
> CK_ReinterpretMemberPointer is a `reinterpret_cast` where T is a member 
> pointer type.)
> 
> Given none of those constructs show up in const-init-cxx1y.cpp, the only 
> reason for it to fail is if we aren't correctly falling back for a construct 
> the current code doesn't know how to handle.  You shouldn't need to implement 
> any new constructs.
in clang/test/CodeGenCXX/designated-init.cpp we have:
```
>> 22 namespace ModifyStaticTemporary { 
>>   
   23   struct A { int &&temporary; int x; };   
  
   24   constexpr int f(int &r) { r *= 9; return r - 12; }  
  
   25   A a = { 6, f(a.temporary) };
```
In the AST, that looks like:
```
| |-VarDecl 0x562b77df39b0  col:5 used a 
'A':'ModifyStaticTemporary::A' cinit
| | `-ExprWithCleanups 0x562b77df3c68  
'A':'ModifyStaticTemporary::A'
| |   `-InitListExpr 0x562b77df3bb8  
'A':'ModifyStaticTemporary::A'
| | |-MaterializeTemporaryExpr 0x562b77df3c08  'int' xvalue 
extended by Var 0x562b77df39b0 'a' 'A':'ModifyStaticTemporary::A'
| | | `-IntegerLiteral 0x562b77df3a18  'int' 6
| | `-CallExpr 0x562b77df3b30  'int'
| |   |-ImplicitCastExpr 0x562b77df3b18  'int (*)(int &)' 

| |   | `-DeclRefExpr 0x562b77df3ad0  'int (int &)' lvalue Function 
0x562b77df37a0 'f' 'int (int &)'
| |   `-MemberExpr 0x562b77df3aa0  'int' lvalue .temporary 
0x562b77df35c0
| | `-DeclRefExpr 0x562b77df3a80  
'A':'ModifyStaticTemporary::A' lvalue Var 0x562b77df39b0 'a' 
'A':'ModifyStaticTemporary::A'
```
(So, indeed no `DesignatedInitUpdateExpr`) but the call to the `constexpr` 
`f()` updates the reference (to `54`).  If I remove the visitor for 
`MaterializeTemporaryExpr`, we fail to evaluate `f` and end up emitting `6` 
rather than `54`.  Doesn't that mean that the fast path (`ConstExprEmitter`) 
needs to be able to evaluate `CallExpr`?

Or should `VisitInitListExpr` bail if any of the inits 
`isa` (or perhaps `isa`)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro updated this revision to Diff 527914.

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

https://reviews.llvm.org/D151833

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Frontend/absolute-paths-import.h
  clang/test/Frontend/absolute-paths.c


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE 
-check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s 
-check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from {{.*absolute-paths.c:4}}:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from {{.*absolute-paths.c:4}}:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152016: Remove 3-byte characters causing clang-tblgen to get I/O error.

2023-06-02 Thread Zibi Sarbino via Phabricator via cfe-commits
zibi created this revision.
zibi added reviewers: Kai, fanbo-meng, abhina.sreeskantharajan.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
zibi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[SystemZ} This revision fixes the following error caused by 
301eb6b68f30074ee3a90e2dfbd11dfd87076323 
.
LLVM ERROR: IO failure on output stream: EDC5122I Input/output error.

The characters seems to be 3-byte characters which cause the failure with auto 
conversion from EBCDIC to ASCII.
Credit to @Kai who found this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152016

Files:
  clang/include/clang/Basic/AttrDocs.td


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6559,7 +6559,7 @@
 
 The ``__arm_streaming`` keyword is only available on AArch64 targets.
 It applies to function types and specifies that the function has a
-“streaming interface”.  This means that:
+"streaming interface".  This means that:
 
 * the function requires the Scalable Matrix Extension (SME)
 
@@ -6578,7 +6578,7 @@
 that switches into streaming mode before calling the function and
 switches back to non-streaming mode on return.
 
-``__arm_streaming`` can appear anywhere that a standard ``[[…]]`` type
+``__arm_streaming`` can appear anywhere that a standard ``[[...]]`` type
 attribute can appear.
 
 See `Arm C Language Extensions `_


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6559,7 +6559,7 @@
 
 The ``__arm_streaming`` keyword is only available on AArch64 targets.
 It applies to function types and specifies that the function has a
-“streaming interface”.  This means that:
+"streaming interface".  This means that:
 
 * the function requires the Scalable Matrix Extension (SME)
 
@@ -6578,7 +6578,7 @@
 that switches into streaming mode before calling the function and
 switches back to non-streaming mode on return.
 
-``__arm_streaming`` can appear anywhere that a standard ``[[…]]`` type
+``__arm_streaming`` can appear anywhere that a standard ``[[...]]`` type
 attribute can appear.
 
 See `Arm C Language Extensions `_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152017: [DebugInfo] Add flag to only emit referenced member functions

2023-06-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: probinson.
Herald added a project: All.
dblaikie requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Complete C++ type information can be quite expensive - and there's
limited value in representing every member function, even those that
can't be called (we don't do similarly for every non-member function
anyway). So add a flag to opt out of this behavior for experimenting
with this more terse behavior.

I think Sony already does this by default, so perhaps with a change to
the defaults, Sony can migrate to this rather than a downstream patch.

This breaks current debuggers in some expected ways - but those
breakages are visible without this feature too. Consider member function
template instantiations - they can't be consistently enumerated in every
translation unit:

a.h:
struct t1 {

  template 
  static int f1() {
return i;
  }

};
namespace ns {
template 
int f1() {

  return i;

}
}  // namespace ns
a.cpp:
#include "a.h"
void f1() {

  t1::f1<0>();
  ns::f1<0>();

}
b.cpp:
#include "a.h"
void f1();
int main() {

  f1();
  t1::f1<1>();
  ns::f1<1>();

}

(gdb) p ns::f1<0>()
$1 = 0
(gdb) p ns::f1<1>()
$2 = 1
(gdb) p t1::f1<0>()
Couldn't find method t1::f1<0>
(gdb) p t1::f1<1>()
$3 = 1
(gdb) s
f1 () at a.cpp:3
3 t1::f1<0>();
(gdb) p t1::f1<0>()
$4 = 0
(gdb) p t1::f1<1>()
Couldn't find method t1::f1<1>
(gdb)

(other similar non-canonical features are implicit special members
(copy/move ctor/assignment operator, default ctor) and nested types (eg:
pimpl idiom, where the nested type is declared-but-not-defined in one
TU, and defined in another TU))

lldb can't parse the template expressions above, so I'm not sure how to
test it there, but I'd guess it has similar problems. (
https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging
so... I guess that's just totally not supported in lldb, how
unfortunate. And implicit special members are instantiated implicitly by
lldb, so missing those doesn't tickle the same issue)

@probinson - would this be an accurate upstreaming of your internal 
handling/would you use this functionality? If it wouldn't be useful to you, 
it's maybe not worth adding upstream yet - not sure we'll use it at Google, but 
if it was useful to you folks and meant other folks could test with it it 
seemed maybe useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152017

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -259,6 +259,9 @@
 // RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 // RUN: %clang -### -c -fdebug-ranges-base-address 
-fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 //
+// RUN: %clang -### -c -gincomplete-types %s 2>&1 | FileCheck 
-check-prefix=INCTYPES %s
+// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
+//
 // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
@@ -398,6 +401,9 @@
 // RNGBSE: -fdebug-ranges-base-address
 // NORNGBSE-NOT: -fdebug-ranges-base-address
 //
+// INCTYPES: -gincomplete-types
+// NOINCTYPES-NOT: -gincomplete-types
+//
 // GARANGE-DAG: -generate-arange-section
 //
 // FDTS: "-mllvm" "-generate-type-units"
Index: clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gincomplete-types %s -emit-llvm 
-o - | FileCheck %s
+
+struct t1 {
+  void f1();
+  void f2();
+};
+
+void t1::f1() { }
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1"
+// CHECK-SAME: elements: [[ELEMENTS:![0-9]+]]
+// CHECK: [[ELEMENTS]] = !{}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4308,6 +4308,12 @@
  DebuggerTuning != llvm::DebuggerKind::DBX)))
 CmdArgs.push_back("-gno-column-info");
 
+  if (const Arg *A = Args.getLastArg(options::OPT_gincomplete_types))
+(void)checkDebugInfoOption(A, Args, D, TC);
+  if (Args.has

[PATCH] D152016: Remove 3-byte characters causing clang-tblgen to get I/O error.

2023-06-02 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan accepted this revision.
abhina.sreeskantharajan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152016

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


[PATCH] D152017: [DebugInfo] Add flag to only emit referenced member functions

2023-06-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 527920.
dblaikie added a comment.

Updating commit message with extra details


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152017

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -259,6 +259,9 @@
 // RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 // RUN: %clang -### -c -fdebug-ranges-base-address 
-fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 //
+// RUN: %clang -### -c -gincomplete-types %s 2>&1 | FileCheck 
-check-prefix=INCTYPES %s
+// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
+//
 // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
@@ -398,6 +401,9 @@
 // RNGBSE: -fdebug-ranges-base-address
 // NORNGBSE-NOT: -fdebug-ranges-base-address
 //
+// INCTYPES: -gincomplete-types
+// NOINCTYPES-NOT: -gincomplete-types
+//
 // GARANGE-DAG: -generate-arange-section
 //
 // FDTS: "-mllvm" "-generate-type-units"
Index: clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gincomplete-types %s -emit-llvm 
-o - | FileCheck %s
+
+struct t1 {
+  void f1();
+  void f2();
+};
+
+void t1::f1() { }
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1"
+// CHECK-SAME: elements: [[ELEMENTS:![0-9]+]]
+// CHECK: [[ELEMENTS]] = !{}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4308,6 +4308,12 @@
  DebuggerTuning != llvm::DebuggerKind::DBX)))
 CmdArgs.push_back("-gno-column-info");
 
+  if (const Arg *A = Args.getLastArg(options::OPT_gincomplete_types))
+(void)checkDebugInfoOption(A, Args, D, TC);
+  if (Args.hasFlag(options::OPT_gincomplete_types,
+   options::OPT_gno_incomplete_types, false))
+CmdArgs.push_back("-gincomplete-types");
+
   // FIXME: Move backend command line options to the module.
   if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) {
 // If -gline-tables-only or -gline-directives-only is the last option it
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2740,7 +2740,7 @@
 
   // Collect data fields (including static variables and any initializers).
   CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
-  if (CXXDecl)
+  if (CXXDecl && !CGM.getCodeGenOpts().DebugIncompleteTypes)
 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
 
   LexicalBlockStack.pop_back();
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3346,6 +3346,10 @@
   CodeGenOpts<"DebugStrictDwarf">, DefaultFalse,
   PosFlag, NegFlag, BothFlags<[CoreOption]>>,
   Group;
+defm incomplete_types : BoolOption<"g", "incomplete-types",
+  CodeGenOpts<"DebugIncompleteTypes">, DefaultFalse,
+  PosFlag, NegFlag, BothFlags<[CoreOption]>>,
+  Group;
 defm column_info : BoolOption<"g", "column-info",
   CodeGenOpts<"DebugColumnInfo">, DefaultTrue,
   NegFlag, PosFlag, BothFlags<[CoreOption]>>,
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -333,6 +333,8 @@
 VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via 
-fwarn-stack-size.
 CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF 
info.
+/// Whether or not to include all members in a type in debug info.
+CODEGENOPT(DebugIncompleteTypes, 1, 0)
 
 /// Control the Assignment Tracking debug info feature.
 ENUM_CODEGENOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, 
AssignmentTrackingOpts::Disabled)


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/tes

[PATCH] D151601: [NVPTX] Coalesce register classes for {i16,f16,bf16}, {i32,v2f16,v2bf16}

2023-06-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I've tested the change on a bunch of tensorflow tests and the patch didn't 
cause any apparent issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151601

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


[PATCH] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-02 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: llvm/include/llvm/ADT/APFloat.h:190
+// greater throughput than single precision (32-bit) formats.
+S_FloatTF32,
 

Hmm,  this says improved precision than half but the semantics you gave say 11 
digits? Does NVIDIA document how many bits we should expect?



Comment at: llvm/lib/Support/APFloat.cpp:141
 4, -10, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloatTF32 = {127, -126, 11, 19};
 static constexpr fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};

NVIDIA's 
[docs](https://docs.nvidia.com/cuda/parallel-thread-execution/#alternate-floating-point-data-formats)
 say:
> This data format is a special 32-bit floating point format supported by the 
> matrix multiply-and-accumulate instructions, with the same range as .f32 and 
> reduced precision (>=10 bits). The internal layout of tf32 format is 
> implementation defined. PTX facilitates conversion from single precision .f32 
> type to tf32 format. A register variable containing tf32 data must be 
> declared with .b32 type.

As written, it's at least 11 bits but it can change over time. Will we need 
corresponding flavors of this for future architectures over time?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151923

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


[PATCH] D151601: [NVPTX] Coalesce register classes for {i16,f16,bf16}, {i32,v2f16,v2bf16}

2023-06-02 Thread Justin Lebar via Phabricator via cfe-commits
jlebar accepted this revision.
jlebar added a comment.
This revision is now accepted and ready to land.

I cannot say that I 100% looked over every line, but in principle this seems 
fine, and if it's passing TF tests then that's pretty strong evidence this is 
working.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151601

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 527924.
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.

- just failing clang/test/CodeGenCXX/atomicinit.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1204,6 +1204,19 @@
 }
 llvm_unreachable("Invalid CastKind");
   }
+  llvm::Constant *VisitImplicitCastExpr(ImplicitCastExpr *I, QualType T) {
+//if (I->isLValue())
+  //return nullptr;
+return VisitCastExpr(I, T);
+  }
+  llvm::Constant *VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *C, QualType T) {
+//if (C->isLValue())
+  //return nullptr;
+return VisitCastExpr(C, T);
+  }
+  llvm::Constant *VisitCStyleCastExpr(CStyleCastExpr *C, QualType T) {
+return VisitCastExpr(C, T);
+  }
 
   llvm::Constant *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE, QualType T) {
 // No need for a DefaultInitExprScope: we don't handle 'this' in a
@@ -1216,8 +1229,10 @@
   }
 
   llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
+  QualType T) {
+if (E->isLValue() || E->isXValue())
+  return Visit(E->getSubExpr(), T);
+return nullptr;
   }
 
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
@@ -1276,6 +1291,9 @@
   }
 
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE, QualType T) {
+if (ILE->getNumInits() && isa(ILE->getInit(0)))
+return nullptr;
+
 if (ILE->isTransparent())
   return Visit(ILE->getInit(0), T);
 
@@ -1655,27 +1673,30 @@
 
   QualType destType = D.getType();
 
-  // Try to emit the initializer.  Note that this can allow some things that
-  // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
-
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
   // then constant initialization is performed. ConstExprEmitter will
   // incorrectly emit a prvalue constant in this case, and the calling code
   // interprets that as the (pointer) value of the reference, rather than the
   // desired value of the referee.
-  if (destType->isReferenceType())

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 527925.
nickdesaulniers added a comment.

- remove commented out code, still WIP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1204,6 +1204,15 @@
 }
 llvm_unreachable("Invalid CastKind");
   }
+  llvm::Constant *VisitImplicitCastExpr(ImplicitCastExpr *I, QualType T) {
+return VisitCastExpr(I, T);
+  }
+  llvm::Constant *VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *C, QualType T) {
+return VisitCastExpr(C, T);
+  }
+  llvm::Constant *VisitCStyleCastExpr(CStyleCastExpr *C, QualType T) {
+return VisitCastExpr(C, T);
+  }
 
   llvm::Constant *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE, QualType T) {
 // No need for a DefaultInitExprScope: we don't handle 'this' in a
@@ -1216,8 +1225,10 @@
   }
 
   llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
+  QualType T) {
+if (E->isLValue() || E->isXValue())
+  return Visit(E->getSubExpr(), T);
+return nullptr;
   }
 
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
@@ -1276,6 +1287,9 @@
   }
 
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE, QualType T) {
+if (ILE->getNumInits() && isa(ILE->getInit(0)))
+return nullptr;
+
 if (ILE->isTransparent())
   return Visit(ILE->getInit(0), T);
 
@@ -1655,27 +1669,27 @@
 
   QualType destType = D.getType();
 
-  // Try to emit the initializer.  Note that this can allow some things that
-  // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
-
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
   // then constant initialization is performed. ConstExprEmitter will
   // incorrectly emit a prvalue constant in this case, and the calling code
   // interprets that as the (pointer) value of the reference, rather than the
   // desired value of the referee.
-  if (destType->isReferenceType())
-return nullptr;
 
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
   QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
-  i

[clang] 583e028 - [test] Add -Wno-msvc-not-found to fix linker-opts.c on *-windows-msvc

2023-06-02 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-06-02T11:59:23-07:00
New Revision: 583e02831c6d081f43f2d5c5b9be5d773b7ae8b8

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

LOG: [test] Add -Wno-msvc-not-found to fix linker-opts.c on *-windows-msvc

Added: 


Modified: 
clang/test/Driver/linker-opts.c

Removed: 




diff  --git a/clang/test/Driver/linker-opts.c b/clang/test/Driver/linker-opts.c
index 319cc591cc3c8..181aeadb8dc97 100644
--- a/clang/test/Driver/linker-opts.c
+++ b/clang/test/Driver/linker-opts.c
@@ -15,7 +15,7 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null 
--implicit-check-not=warning:
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -Wno-msvc-not-found -o /dev/null 2>&1 | 
FileCheck /dev/null --implicit-check-not=warning:
 
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s 
--check-prefix=UNUSED



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


[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-06-02 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis accepted this revision.
TIFitis added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

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


[PATCH] D152021: [clang][AIX] Fix Overly Strick LTO Option Checking against `data-sections` when `mxcoff-roptr` is in Effect

2023-06-02 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: hubert.reinterpretcast, w2yehia.
qiongsiwu1 added a project: clang.
Herald added subscribers: kbarton, inglorion, nemanjai.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.

The LTO `mxcoff-roptr` check 

 against data sections is overly strict and it ignores the fact that data 
sections is on by default on AIX 
,
 causing valid LTO compilation to fail when `fdata-sections` is not explicitly 
specified for LTO.

This patch revises the check so that an error is reported only if data sections 
is explicitly turned off for LTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/ppc-roptr.c


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 
2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s 
--check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | 
\
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr 
-flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -747,7 +747,8 @@
 
 if (HasRoptr) {
   if (!Args.hasFlag(options::OPT_fdata_sections,
-options::OPT_fno_data_sections, UseSeparateSections))
+options::OPT_fno_data_sections, UseSeparateSections) &&
+  Args.hasArg(options::OPT_fno_data_sections))
 D.Diag(diag::err_roptr_requires_data_sections);
 
   CmdArgs.push_back(


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s --check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bfo

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-02 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 527931.
TIFitis marked 2 inline comments as done.
TIFitis added a comment.

Addressed reviewer comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4083,7 +4083,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4094,9 +4096,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy UnusedIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1897,6 +1897,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -1904,7 +1908,9 @@
   function_ref GenMapInfoCB,
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, 

  1   2   >