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

2023-06-01 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse added inline comments.



Comment at: llvm/lib/Target/X86/AsmParser/X86Operand.h:386
   return false;
+if (getMemBaseReg() == X86::NoRegister)
+  return true;

craig.topper wrote:
> Now we're not checking the index register if there is no base register?
Let me fix this.


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] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie 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:
> 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)


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] D151863: [x86][MC] Fix movdir64b addressing

2023-06-01 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse added inline comments.



Comment at: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1781
+  // value at this time.
+  BaseReg = BaseReg ? BaseReg : 0;
   Operands.push_back(X86Operand::CreateMem(

craig.topper wrote:
> This sets BaseReg to 0 if its already 0?
Oops. Is this even required? I think we can get rid of this. There are no tests 
that failed.


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-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/AsmParser/X86Operand.h:386
   return false;
+if (getMemBaseReg() == X86::NoRegister)
+  return true;

Now we're not checking the index register if there is no base register?


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-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:1781
+  // value at this time.
+  BaseReg = BaseReg ? BaseReg : 0;
   Operands.push_back(X86Operand::CreateMem(

This sets BaseReg to 0 if its already 0?


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-01 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse updated this revision to Diff 527725.
akshaykhadse added a comment.

Update AsmParser


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/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,8 @@
   bool isMem512_GR16() const {
 if (!isMem512())
   return false;
+if (getMemBaseReg() == X86::NoRegister)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR16RegClassID].contains(getMemBaseReg()))
   return false;
@@ -391,6 +393,8 @@
   bool isMem512_GR32() const {
 if (!isMem512())
   return false;
+if (getMemBaseReg() == X86::NoRegister)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemBaseReg()) &&
 getMemBaseReg() != X86::EIP)
@@ -404,6 +408,8 @@
   bool isMem512_GR64() const {
 if (!isMem512())
   return false;
+if (getMemBaseReg() == X86::NoRegister)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR64RegClassID].contains(getMemBaseReg()) &&
 getMemBaseReg() != X86::RIP)
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1776,10 +1776,9 @@
  BaseReg && IndexReg));
 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
-  // get the matching correct in some cases.
-  BaseReg = BaseReg ? BaseReg : 1;
+  // Otherwise, we set the base register to a zero if we don't know the actual 
+  // value at this time.
+  BaseReg = BaseReg ? BaseReg : 0;
   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/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ 

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

2023-06-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:1425
+   const SmallVectorImpl ,
+   const FormatToken ,
+   const FormatStyle ) {

I will remove this parameter as it's `Line.First`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151954

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


[PATCH] D150253: [RISCV] Add Zvfhmin extension for clang.

2023-06-01 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:2219
+  def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
+  let RequiredFeatures = ["ZvfhminOrZvfh"] in
+def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {

eopXD wrote:
> craig.topper wrote:
> > eopXD wrote:
> > > I think using `ZvfhminOrZvfh` is not accurate here. By the v-spec:
> > > 
> > > > When the Zvfhmin extension is implemented, the vfwcvt.f.f.v and 
> > > > vfncvt.f.f.w instructions become defined when SEW=16. 
> > > > The Zvfh extension depends on the Zve32f and Zfhmin extensions.
> > > 
> > > I think making it `let RequiredFeatures = ["Zvfhmin"]` would be clearer.
> > Note that the spec says Zfhmin(no v) not Zvfhmin. 
> My mistake. I suspect this is an oversight of the v-spec, just created an 
> issue for this.
> 
> https://github.com/riscv/riscv-v-spec/issues/885
Thanks for comment. I think that v-spec is in accordance with the scalar spec 
to some degree. Since `zfh` doesn't imply `zfhmin`, I don't think they will let 
`zvfh` imply `zvfhmin`.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c:15
+//
+vfloat16m1_t test_vfncvt_f_f_w_f16m1(vfloat32m2_t src, size_t vl) {
+  return __riscv_vfncvt_f(src, vl);

eopXD wrote:
> This test case is already covered.
> 
> https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt.c#L356
Yes, but this test is for zvfhmin. `vfncvt.c` contains other convert cases not 
enable for zvfhmin so we can't just add a zvfhmin check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

___
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-01 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

This patch uses castAs instead of getAs to resolve dereference issue with 
nullptr boundObjC when calling canAssignObjCInterfaces() or isObjCIdType() in 
applyObjCTypeArgs() since getAs returns nullptr.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151964

Files:
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -950,7 +950,7 @@
 
   // Retrieve the bound.
   QualType bound = typeParam->getUnderlyingType();
-  const auto *boundObjC = bound->getAs();
+  const auto *boundObjC = bound->castAs();
 
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -950,7 +950,7 @@
 
   // Retrieve the bound.
   QualType bound = typeParam->getUnderlyingType();
-  const auto *boundObjC = bound->getAs();
+  const auto *boundObjC = bound->castAs();
 
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {
___
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-01 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik created this revision.
philnik added reviewers: erichkeane, aaron.ballman.
Herald added subscribers: luke, steakhal, frasercrmck, martong, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb, kbarton, arichardson, nemanjai, dschuff.
Herald added a reviewer: paulkirth.
Herald added a reviewer: NoQ.
Herald added a project: All.
Herald added a comment.
philnik requested review of this revision.
Herald added subscribers: libcxx-commits, cfe-commits, pcwang-thead, MaskRay, 
aheejin.
Herald added projects: clang, libc++.
Herald added a reviewer: libc++.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to ClangFormatStyleOptions.rst but not a change 
to clang/include/clang/Format/Format.h

ClangFormatStyleOptions.rst is auto generated from Format.h via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


A lot of editors remove trailing whitespaces. This patch removes any trailing 
whitespaces and makes sure that no new ones are added.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151963

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ClangLinkerWrapper.rst
  clang/docs/ClangOffloadPackager.rst
  clang/docs/ClangTransformerTutorial.rst
  clang/docs/DebuggingCoroutines.rst
  clang/docs/ExternalClangExamples.rst
  clang/docs/JSONCompilationDatabase.rst
  clang/docs/MisExpect.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/SourceBasedCodeCoverage.rst
  clang/docs/StandardCPlusPlusModules.rst
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/docs/analyzer/checkers.rst
  clang/docs/analyzer/developer-docs/DebugChecks.rst
  clang/docs/tools/dump_ast_matchers.py
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/include/clang/Analysis/CallGraph.h
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/CMakeLists.txt
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/UninitializedValues.cpp
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  libcxx/utils/ci/buildkite-pipeline-clang.yml

Index: libcxx/utils/ci/buildkite-pipeline-clang.yml
===
--- libcxx/utils/ci/buildkite-pipeline-clang.yml
+++ libcxx/utils/ci/buildkite-pipeline-clang.yml
@@ -17,6 +17,21 @@
 # LLVM RELEASE bump version
 LLVM_HEAD_VERSION: "17"
 steps:
+  - label: "Format"
+commands:
+  - "! grep -rn '[[:blank:]]$' clang/lib clang/include clang/docs || false"
+
+agents:
+  queue: "libcxx-builders"
+  os: "linux"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
+  - wait
+
   - label: "Building clang"
 commands:
   - "mkdir install"
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1242,7 +1242,7 @@
 const QualType ,
 const LocationContext *LCtx,
 SVal *ElementCountVal) {
-  assert(Region != nullptr && "Not-null region expected");	
+  assert(Region != nullptr && "Not-null region expected");
 
   QualType Ty = ElementTy.getDesugaredType(getContext());
   while (const auto *NTy = dyn_cast(Ty))
Index: clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
@@ -80,7 +80,7 @@
   mgr.registerChecker();
 }
 
-bool 

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

2023-06-01 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse added inline comments.



Comment at: clang/test/CodeGen/ms-inline-asm-64.c:79
+  int arr[1000];
+  __asm enqcmds rax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "enqcmds rax, zmmword ptr 
$0", "*m,~{flags},~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) 
%arr)

XinWang10 wrote:
> This could be movdir64b?
You are correct. Thanks! I will update it


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] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-01 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini accepted this revision.
mehdi_amini added a comment.
This revision is now accepted and ready to land.

Ok, sorry I missed the mangle update, seeing how I missed the MLIR mention as 
well: I need more sleep!! :)


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] D151625: [clang] Add `clang::equality_operator_compares_members_lexicographically`

2023-06-01 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 527704.
philnik marked 2 inline comments as done.
philnik added a comment.
Herald added a subscriber: jdoerfert.

- Address comments
- Try to fix CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151625

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Type.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  
clang/test/SemaCXX/attr-equality-operator-compares-members-lexicographically.cpp

Index: clang/test/SemaCXX/attr-equality-operator-compares-members-lexicographically.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-equality-operator-compares-members-lexicographically.cpp
@@ -0,0 +1,139 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -std=c++20
+
+void __attribute__((equality_operator_compares_members_lexicographically)) foo(); // expected-warning {{'equality_operator_compares_members_lexicographically' attribute only applies to classes and enums}}
+
+struct [[clang::equality_operator_compares_members_lexicographically]] TriviallyEqualityComparabe1 {
+  int i;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparabe1));
+
+struct __attribute__((equality_operator_compares_members_lexicographically)) TriviallyEqualityComparabe2 {
+  int i;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparabe2));
+
+struct [[clang::equality_operator_compares_members_lexicographically(1)]] TestMessage {}; // expected-error {{'equality_operator_compares_members_lexicographically' attribute takes no arguments}}
+
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableHasPadding {
+  short i;
+  int j;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding), "");
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableHasFloat {
+  float i;
+  int j;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat), "");
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableHasTailPadding {
+  int i;
+  char j;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding), "");
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding {
+  char j;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase), "");
+
+class [[clang::equality_operator_compares_members_lexicographically]] TriviallyEqualityComparablePaddedOutBase {
+  int i;
+  char c;
+};
+static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOutBase), "");
+
+struct [[clang::equality_operator_compares_members_lexicographically]] TriviallyEqualityComparablePaddedOut : TriviallyEqualityComparablePaddedOutBase {
+  char j[3];
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOut), "");
+
+struct [[clang::equality_operator_compares_members_lexicographically]] TriviallyEqualityComparable1 {
+  char i;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable1));
+
+struct [[clang::equality_operator_compares_members_lexicographically]] TriviallyEqualityComparable2 {
+  int i;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable2));
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableTriviallyEqualityComparableBases
+: TriviallyEqualityComparable1, TriviallyEqualityComparable2 {
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableTriviallyEqualityComparableBases));
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableBitfield {
+  int i : 1;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield));
+
+// TODO: This is trivially equality comparable
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableBitfieldFilled {
+  char i : __CHAR_BIT__;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield));
+
+union [[clang::equality_operator_compares_members_lexicographically]] U {
+  int i;
+};
+
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion {
+  U u;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion));
+
+struct NotTriviallyEqualityComparableExplicitlyDeleted {
+  int i;
+
+  friend bool operator==(const 

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

2023-06-01 Thread Jeremy Furtek via Phabricator via cfe-commits
jfurtek added a comment.

In D151923#4389405 , @mehdi_amini 
wrote:

> I think this LG, but David had to update clang/lib/AST/MicrosoftMangle.cpp 
> when some other float format was added, you don't need this here?

I did update that file - it is part of this diff. (I used that diff as a 
template - otherwise I probably would have missed that change...)

The associated MLIR changes are done - just haven't submitted the diff yet.


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] D148490: [AIX] use system assembler for assembly files

2023-06-01 Thread ChenZheng via Phabricator via cfe-commits
shchenz added inline comments.



Comment at: clang/test/Driver/target-as.s:1
 // Make sure the -march is passed down to cc1as.
 // RUN: %clang -target i386-unknown-freebsd -### -c -integrated-as %s \

MaskRay wrote:
> shchenz wrote:
> > MaskRay wrote:
> > > aix-as.c will be more appropriate.
> > Do you mean we change this file to `aix-as.s` or we change back to previous 
> > version? The file `target-as.s` can not be renamed to `aix-as.s`, it also 
> > contains tests for i386, see the first run line.
> You can add the new tests to the existing `aix-as.s`. The behavior is about 
> assemblers on AIX. `aix-as.s` seems more appropriate than `target-as.s`.
hmm, we want to use assembly file for test. There is aix-as.c but no aix-as.s.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148490

___
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-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/AsmParser/X86Operand.h:386
   return false;
+if (getMemDisp()->getKind() == llvm::MCExpr::SymbolRef)
+  return true;

Wouldn't this allow "symbol + %eax" to pick the 64-bit instruction which is 
what the original change was trying to avoid?


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-01 Thread Wang, Xin via Phabricator via cfe-commits
XinWang10 added inline comments.



Comment at: clang/test/CodeGen/ms-inline-asm-64.c:79
+  int arr[1000];
+  __asm enqcmds rax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "enqcmds rax, zmmword ptr 
$0", "*m,~{flags},~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) 
%arr)

This could be movdir64b?


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-01 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse added a comment.

Please let me know if these tests and changes look okay.


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] D151957: [NFC][CLANG] Fix bug with dereference null return value in GetFunctionTypeForVTable()

2023-06-01 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

This patch uses castAs instead of getAs which will assert if the type doesn't 
match In 
clang::​CodeGen::​CodeGenTypes::​GetFunctionTypeForVTable(clang::​GlobalDecl).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151957

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1751,7 +1751,7 @@
 
 llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) {
   const CXXMethodDecl *MD = cast(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs();
+  const FunctionProtoType *FPT = MD->getType()->castAs();
 
   if (!isFuncTypeConvertible(FPT))
 return llvm::StructType::get(getLLVMContext());


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1751,7 +1751,7 @@
 
 llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) {
   const CXXMethodDecl *MD = cast(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs();
+  const FunctionProtoType *FPT = MD->getType()->castAs();
 
   if (!isFuncTypeConvertible(FPT))
 return llvm::StructType::get(getLLVMContext());
___
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-01 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;

These numbers feel very low for how this modification is using them. Perhaps 
they should both be bumped to 32?


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] D151954: [clang-format] Fix overlapping whitespace replacements before PPDirective

2023-06-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

If the first token of an annotated line is finalized, reuse its 
`NewlinesBefore` value to avoid potential overlapping whitespace replacements 
before preprocessor branching directives.

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


Repository:
  rG LLVM Github Monorepo

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 , const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl , unsigned Indent,
-unsigned NewlineIndent) {
-  FormatToken  = *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 ,
+   const AnnotatedLine *PreviousLine,
+   const AnnotatedLine *PrevPrevLine,
+   const SmallVectorImpl ,
+   const FormatToken ,
+   const FormatStyle ) {
   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 , const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
+const SmallVectorImpl , unsigned Indent,
+unsigned NewlineIndent) {
+  FormatToken  = *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, RootToken, 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 , const AnnotatedLine *PreviousLine,
-const AnnotatedLine *PrevPrevLine,
-const SmallVectorImpl , unsigned Indent,
-unsigned 

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

2023-06-01 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

> Also do you have plans for MLIR? (nothing required for this patch, just 
> curious).

Actually it's the last sentence of the patch description (/facepalm)


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] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-01 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

I think this LG, but David had to update clang/lib/AST/MicrosoftMangle.cpp when 
some other float format was added, you don't need this here?

Also do you have plans for MLIR? (nothing required for this patch, just 
curious).


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] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 527681.
cjdb added a comment.

fixes some code I wrote when debugging


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type_pack_index.cpp

Index: clang/test/SemaCXX/type_pack_index.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/type_pack_index.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+using size_t = decltype(sizeof(0));
+
+static_assert(__type_pack_index(int, int) == 0, "");
+static_assert(__type_pack_index(long, long, int) == 0, "");
+static_assert(__type_pack_index(int, long, int) == 1, "");
+
+// This will be used by parameter packs most of the time, so we should check they
+// work too.
+template
+constexpr size_t mock_get()
+{
+  return __type_pack_index(T, Ts...);
+}
+
+static_assert(mock_get() == 0, "");
+static_assert(mock_get() == 1, "");
+static_assert(mock_get() == 2, "");
+
+// Types mentioned twice return the first occurrence
+// -
+enum E {};
+enum class EC : int {};
+struct S;
+union U;
+static_assert(__type_pack_index(S, U, S, S) == 1, "");
+static_assert(__type_pack_index(U, int, long, EC, U, double, __int128, S, EC, U) == 3, "");
+
+template
+union UT;
+static_assert(__type_pack_index(UT, int, long, EC, U, double, __int128, S, EC, U, UT, UT, UT) == 10, "");
+
+// Qualifiers
+// --
+static_assert(__type_pack_index(int const, int const, int) == 0, "");
+static_assert(__type_pack_index(int, int const, int) == 1, "");
+
+static_assert(__type_pack_index(int volatile, int volatile, int) == 0, "");
+static_assert(__type_pack_index(int, int volatile, int) == 1, "");
+
+static_assert(__type_pack_index(int const volatile, int const volatile, int) == 0, "");
+static_assert(__type_pack_index(int, int const volatile, int) == 1, "");
+
+static_assert(__type_pack_index(int&, int const, int, int&) == 2, "");
+static_assert(__type_pack_index(int const&, int const, int const&) == 1, "");
+static_assert(__type_pack_index(int volatile&, int volatile, int const&, int&, int volatile&) == 3, "");
+static_assert(__type_pack_index(int const volatile&, int volatile, int const&, int&, int volatile&, int const volatile&) == 4, "");
+
+static_assert(__type_pack_index(int&&, int const, int, int&, int&&, int const&&) == 3, "");
+static_assert(__type_pack_index(int const&&, int const, int const&, int const&&) == 2, "");
+static_assert(__type_pack_index(int volatile&&, int volatile, int const&, int&, int volatile&, int volatile&&) == 4, "");
+static_assert(__type_pack_index(int const volatile&&, int volatile, int const&, int&, int volatile&, int volatile&&, int const volatile&&) == 5, "");
+
+static_assert(__type_pack_index(int* __restrict, int*, int * __restrict) == 1, "");
+
+// Aliases
+// ---
+using Int = int;
+typedef long Long;
+static_assert(__type_pack_index(int, Int, Long) == 0, "");
+static_assert(__type_pack_index(Int, Int, Long) == 0, "");
+static_assert(__type_pack_index(long, Int, Long) == 1, "");
+static_assert(__type_pack_index(Long, Int, Long) == 1, "");
+
+// Error handling
+// --
+//
+// Not enough arguments
+// 
+static_assert(__type_pack_index(), "");// expected-error{{expected a type}}
+static_assert(__type_pack_index(int), ""); // expected-error{{type trait requires 2 or more arguments; have 1 argument}}
+
+// Type not found
+// --
+static_assert(__type_pack_index(int, long long, double));
+// expected-error@-1{{'__type_pack_index' couldn't find type 'int'}}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5378,9 +5378,9 @@
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
-static bool evaluateTypeTrait(Sema , TypeTrait Kind, SourceLocation KWLoc,
-  ArrayRef Args,
-  SourceLocation RParenLoc) {
+static bool EvaluateBooleanTypeTrait(Sema , TypeTrait Kind, SourceLocation KWLoc,
+ ArrayRef Args,
+ SourceLocation RParenLoc) {
   if (Kind <= UTT_Last)
 return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
 
@@ -5548,6 +5548,54 @@
   return true;
 }
 
+static ExprResult EvaluateIntegralTypeTrait(Sema , TypeTrait Kind,
+   

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

2023-06-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: aaron.ballman, erichkeane, shafik, dblaikie.
Herald added subscribers: arphaman, martong.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Similarly to `__type_pack_element`, C++ doesn't offer a way to extract a
the index of the first occurrence of a type in a parameter pack. This
means that we need to build up context for something that the compiler
already has, and then compute the value in a much less efficient manner
than the  compiler.

Clang can compute this information without needing to use extra
resources.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151952

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type_pack_index.cpp

Index: clang/test/SemaCXX/type_pack_index.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/type_pack_index.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+using size_t = decltype(sizeof(0));
+
+static_assert(__type_pack_index(int, int) == 0, "");
+static_assert(__type_pack_index(long, long, int) == 0, "");
+static_assert(__type_pack_index(int, long, int) == 1, "");
+
+// This will be used by parameter packs most of the time, so we should check they
+// work too.
+template
+constexpr size_t mock_get()
+{
+  return __type_pack_index(T, Ts...);
+}
+
+static_assert(mock_get() == 0, "");
+static_assert(mock_get() == 1, "");
+static_assert(mock_get() == 2, "");
+
+// Types mentioned twice return the first occurrence
+// -
+enum E {};
+enum class EC : int {};
+struct S;
+union U;
+static_assert(__type_pack_index(S, U, S, S) == 1, "");
+static_assert(__type_pack_index(U, int, long, EC, U, double, __int128, S, EC, U) == 3, "");
+
+template
+union UT;
+static_assert(__type_pack_index(UT, int, long, EC, U, double, __int128, S, EC, U, UT, UT, UT) == 10, "");
+
+// Qualifiers
+// --
+static_assert(__type_pack_index(int const, int const, int) == 0, "");
+static_assert(__type_pack_index(int, int const, int) == 1, "");
+
+static_assert(__type_pack_index(int volatile, int volatile, int) == 0, "");
+static_assert(__type_pack_index(int, int volatile, int) == 1, "");
+
+static_assert(__type_pack_index(int const volatile, int const volatile, int) == 0, "");
+static_assert(__type_pack_index(int, int const volatile, int) == 1, "");
+
+static_assert(__type_pack_index(int&, int const, int, int&) == 2, "");
+static_assert(__type_pack_index(int const&, int const, int const&) == 1, "");
+static_assert(__type_pack_index(int volatile&, int volatile, int const&, int&, int volatile&) == 3, "");
+static_assert(__type_pack_index(int const volatile&, int volatile, int const&, int&, int volatile&, int const volatile&) == 4, "");
+
+static_assert(__type_pack_index(int&&, int const, int, int&, int&&, int const&&) == 3, "");
+static_assert(__type_pack_index(int const&&, int const, int const&, int const&&) == 2, "");
+static_assert(__type_pack_index(int volatile&&, int volatile, int const&, int&, int volatile&, int volatile&&) == 4, "");
+static_assert(__type_pack_index(int const volatile&&, int volatile, int const&, int&, int volatile&, int volatile&&, int const volatile&&) == 5, "");
+
+static_assert(__type_pack_index(int* __restrict, int*, int * __restrict) == 1, "");
+
+// Aliases
+// ---
+using Int = int;
+typedef long Long;
+static_assert(__type_pack_index(int, Int, Long) == 0, "");
+static_assert(__type_pack_index(Int, Int, Long) == 0, "");
+static_assert(__type_pack_index(long, Int, Long) == 1, "");
+static_assert(__type_pack_index(Long, Int, Long) == 1, "");
+
+// Error handling
+// --
+//
+// Not enough arguments
+// 
+static_assert(__type_pack_index(), "");// expected-error{{expected a type}}
+static_assert(__type_pack_index(int), ""); // expected-error{{type trait requires 2 or more arguments; have 1 argument}}
+
+// Type not found
+// --
+static_assert(__type_pack_index(int, long long, double));
+// expected-error@-1{{'__type_pack_index' couldn't find type 'int'}}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5378,9 +5378,10 @@
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
-static bool evaluateTypeTrait(Sema , TypeTrait Kind, SourceLocation KWLoc,
- 

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

2023-06-01 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao accepted this revision.
ayzhao added a comment.
This revision is now accepted and ready to land.

In D150122#4388978 , @ayzhao wrote:

> In D150122#4388972 , @cor3ntin 
> wrote:
>
>> I guess we should land that now @erichkeane ?
>
> Sorry, but there's actually one more crash that was just reported earlier 
> this week: https://github.com/llvm/llvm-project/issues/63008. We should wait 
> until the backport PR 
>  has been approved.

That backport has just been merged, so this patch LGTM.


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] D151277: [clang][modules] Mark fewer identifiers as out-of-date

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a project: clang-modules.
jansvoboda11 added a comment.

Thanks, Ben. Maybe someone subscribed to `clang-modules` could take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151277

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


[PATCH] D144911: adding bf16 support to NVPTX

2023-06-01 Thread Manish Gupta via Phabricator via cfe-commits
manishucsd added a comment.

I tried this patch to resolve lowering `nvvm.mma.sync` on bf16 operands for the 
PR 13858 

  nvvm.mma.sync A[%293, %295, %297, %299]  B[%392, %394]  C[%484, %485, %487, 
%488]  {layoutA = #nvvm.mma_layout, layoutB = #nvvm.mma_layout, 
multiplicandAPtxType = #nvvm.mma_type, multiplicandBPtxType = 
#nvvm.mma_type, shape = #nvvm.shape} : 
(vector<2xbf16>, vector<2xbf16>, f32) -> !llvm.struct<(f32, f32, f32, f32)>

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]^

  


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] D151947: [NFC][CLANG] Fix Static Code Analyzer Concern with nullptr dereference issue

2023-06-01 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

This patch uses castAs instead of getAs which will assert if the type doesn't 
match.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151947

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3307,7 +3307,7 @@
 Flags);
 
   const FunctionProtoType *FPT =
-  Ty->getPointeeType()->getAs();
+  Ty->getPointeeType()->castAs();
   return DBuilder.createMemberPointerType(
   getOrCreateInstanceMethodType(
   CXXMethodDecl::getThisType(FPT, Ty->getMostRecentCXXRecordDecl()),


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3307,7 +3307,7 @@
 Flags);
 
   const FunctionProtoType *FPT =
-  Ty->getPointeeType()->getAs();
+  Ty->getPointeeType()->castAs();
   return DBuilder.createMemberPointerType(
   getOrCreateInstanceMethodType(
   CXXMethodDecl::getThisType(FPT, Ty->getMostRecentCXXRecordDecl()),
___
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-01 Thread Cory Fields via Phabricator via cfe-commits
theuni accepted this revision.
theuni added a comment.
This revision is now accepted and ready to land.

Looks good to me. I can confirm that this fixes my test-case from D151926 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151944

___
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-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 527645.
MaskRay added a comment.

Include -nobuiltininc


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,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 -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
+// RUN: %clang -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
 // NO-UNUSED-NOT: warning:{{.*}}unused
 //
 // Make sure that we do warn in other cases.
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,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 -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
+// RUN: %clang -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ -nostdlibinc -nogpuinc -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
 // NO-UNUSED-NOT: warning:{{.*}}unused
 //
 // Make sure that we do warn in other cases.
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 

[PATCH] D150803: [WebAssembly] Add a new `wasm_async` clang attribute for marking async functions.

2023-06-01 Thread Dan Gohman via Phabricator via cfe-commits
sunfish added a comment.

In D150803#4389040 , @dschuff wrote:

> Hm, this is interesting because in the long term we plan to have stack 
> switching in wasm, which could allow for similar async behavior that JSPI 
> has, and could be useful in non-web systems. But that's a ways off. The file 
> format we are generating with this CL will be used in emscripten sooner (and 
> we may want to try to stabilize it some point, possibly before pure wasm 
> stack switching is usable in non-web systems).
> So overall I kind of feel like I could go either way on this. Curious if 
> @sunfish has had any thoughts about async outside of emscripten.

When we do have stack switching, would you anticipate still using this 
`wasm_async` attribute, or would we switch to something else at that point?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150803

___
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-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma 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() :

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.


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] D151944: [Driver] Move -nostdinc like options into IncludePath_Group

2023-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: jansvoboda11, theuni.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

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,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 -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
+// RUN: %clang -I. -ibuiltininc -nostdinc -nostdinc++ -nostdlibinc -nogpuinc 
-Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
 // NO-UNUSED-NOT: warning:{{.*}}unused
 //
 // Make sure that we do warn in other cases.
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">;
@@ -4197,9 +4197,10 @@
 def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
   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,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 -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
+// RUN: %clang -I. -ibuiltininc -nostdinc -nostdinc++ -nostdlibinc -nogpuinc -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
 // NO-UNUSED-NOT: warning:{{.*}}unused
 //
 // Make sure that we do warn in other cases.
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">;
@@ -4197,9 +4197,10 @@
 def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
   HelpText<"Disable builtin #include directories">,
   MarshallingInfoNegativeFlag>;
-def nogpuinc : Flag<["-"], 

[PATCH] D150803: [WebAssembly] Add a new `wasm_async` clang attribute for marking async functions.

2023-06-01 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

In D150803#4350554 , @sbc100 wrote:

> This change looks really nice.  I like the new relocation type, I think we 
> would have had to add that sooner or later anyway.
>
> My only major concern is making this attribute available outside of 
> emscripten (i.e. wasm32-unknown-emscripten).  It seems like we should maybe 
> called it `em_async` or something like that?  And make it illegal on other 
> targets?
>
> @dschuff WDYT?

Hm, this is interesting because in the long term we plan to have stack 
switching in wasm, which could allow for similar async behavior that JSPI has, 
and could be useful in non-web systems. But that's a ways off. The file format 
we are generating with this CL will be used in emscripten sooner (and we may 
want to try to stabilize it some point, possibly before pure wasm stack 
switching is usable in non-web systems).
So overall I kind of feel like I could go either way on this. Curious if 
@sunfish has had any thoughts about async outside of emscripten.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150803

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


[PATCH] D151277: [clang][modules] Mark fewer identifiers as out-of-date

2023-06-01 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

LGTM, but I would prefer at least one more person who understands the 
identifier handling code review this. It's been years since I thought about 
this code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151277

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


[PATCH] D151938: [clang][index] NFCI: Make `CXFile` a `FileEntryRef`

2023-06-01 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: clang/test/Modules/crash-vfs-umbrella-frameworks.m:13
 // RUN: env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
-// RUN: not %clang -nostdinc -fsyntax-only %s \
+// RUN: not --crash %clang -nostdinc -fsyntax-only %s \
 // RUN: -F %/t/i/Frameworks -fmodules \

This looks suspicious; what's going on here?



Comment at: clang/tools/libclang/CXFile.h:1
+//===--===//
+//

Missing filename and C++ language tag from header comment.



Comment at: clang/tools/libclang/CXLoadedDiagnostic.cpp:279
   else {
-LoadedLoc.file = const_cast(TopDiags->Files[FileID]);
+LoadedLoc.file = cxfile::makeCXFile(TopDiags->Files.find(FileID)->second);
 if (!LoadedLoc.file)

Does this preserve behaviour in call cases? operator[] will construct nullptr 
if the key is missing, but the new code will crash dereferencing an invalid 
iterator.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151938

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


[PATCH] D150803: [WebAssembly] Add a new `wasm_async` clang attribute for marking async functions.

2023-06-01 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:892
   if (const auto *Attr = FD->getAttr()) {
-llvm::Function *Fn = cast(GV);
+auto *Fn = cast(GV);
 llvm::AttrBuilder B(GV->getContext());

Whoops, I changed the wrong one here. I'll fix that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150803

___
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-01 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

In D150122#4388972 , @cor3ntin wrote:

> I guess we should land that now @erichkeane ?

Sorry, but there's actually one more crash that was just reported earlier this 
week: https://github.com/llvm/llvm-project/issues/63008. We should wait until 
the backport PR  has 
been approved.


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] D150122: [Clang] Fix status of P0960

2023-06-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I guess we should land that now @erichkeane ?


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] D151277: [clang][modules] Mark fewer identifiers as out-of-date

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 527634.
jansvoboda11 added a comment.

Rebase and switch back to `IdentifierTable::getOwn()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151277

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -3546,14 +3546,16 @@
 // the mapping from persistent IDs to strings.
 Writer.SetIdentifierOffset(II, Out.tell());
 
+auto MacroOffset = Writer.getMacroDirectivesOffset(II);
+
 // Emit the offset of the key/data length information to the interesting
 // identifiers table if necessary.
-if (InterestingIdentifierOffsets && isInterestingIdentifier(II))
+if (InterestingIdentifierOffsets &&
+isInterestingIdentifier(II, MacroOffset))
   InterestingIdentifierOffsets->push_back(Out.tell());
 
 unsigned KeyLen = II->getLength() + 1;
 unsigned DataLen = 4; // 4 bytes for the persistent ID << 1
-auto MacroOffset = Writer.getMacroDirectivesOffset(II);
 if (isInterestingIdentifier(II, MacroOffset)) {
   DataLen += 2; // 2 bytes for builtin ID
   DataLen += 2; // 2 bytes for flags
@@ -3632,9 +3634,8 @@
   // strings.
   {
 llvm::OnDiskChainedHashTableGenerator Generator;
-ASTIdentifierTableTrait Trait(
-*this, PP, IdResolver, IsModule,
-(getLangOpts().CPlusPlus && IsModule) ?  : nullptr);
+ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule,
+  IsModule ?  : nullptr);
 
 // Look for any identifiers that were named while processing the
 // headers, but are otherwise not needed. We add these to the hash
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4386,27 +4386,56 @@
 if (F.OriginalSourceFileID.isValid())
   F.OriginalSourceFileID = TranslateFileID(F, F.OriginalSourceFileID);
 
-// Preload all the pending interesting identifiers by marking them out of
-// date.
 for (auto Offset : F.PreloadIdentifierOffsets) {
   const unsigned char *Data = F.IdentifierTableData + Offset;
 
   ASTIdentifierLookupTrait Trait(*this, F);
   auto KeyDataLen = Trait.ReadKeyDataLength(Data);
   auto Key = Trait.ReadKey(Data, KeyDataLen.first);
-  auto  = PP.getIdentifierTable().getOwn(Key);
-  II.setOutOfDate(true);
+
+  IdentifierInfo *II;
+  if (!PP.getLangOpts().CPlusPlus) {
+// Identifiers present in both the module file and the importing
+// instance are marked out-of-date so that they can be deserialized
+// on next use via ASTReader::updateOutOfDateIdentifier().
+// Identifiers present in the module file but not in the importing
+// instance are ignored for now, preventing growth of the identifier
+// table. They will be deserialized on first use via ASTReader::get().
+auto It = PP.getIdentifierTable().find(Key);
+if (It == PP.getIdentifierTable().end())
+  continue;
+II = It->second;
+  } else {
+// With C++ modules, not many identifiers are considered interesting.
+// All identifiers in the module file can be placed into the identifier
+// table of the importing instance and marked as out-of-date. This makes
+// ASTReader::get() a no-op, and deserialization will take place on
+// first/next use via ASTReader::updateOutOfDateIdentifier().
+II = ().getOwn(Key);
+  }
+
+  II->setOutOfDate(true);
 
   // Mark this identifier as being from an AST file so that we can track
   // whether we need to serialize it.
-  markIdentifierFromAST(*this, II);
+  markIdentifierFromAST(*this, *II);
 
   // Associate the ID with the identifier so that the writer can reuse it.
   auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first);
-  SetIdentifierInfo(ID, );
+  SetIdentifierInfo(ID, II);
 }
   }
 
+  // Builtins and library builtins have already been initialized. Mark all
+  // identifiers as out-of-date, so that they are deserialized on first use.
+  if (Type == MK_PCH || Type == MK_Preamble || Type == MK_MainFile)
+for (auto  : PP.getIdentifierTable())
+  Id.second->setOutOfDate(true);
+
+  // Mark selectors as out of date.
+  for (const auto  : SelectorGeneration)
+SelectorOutOfDate[Sel.first] = true;
+
   // Setup the import locations and notify the module manager that we've
   // committed to these module files.
   for (ImportedModule  : Loaded) {
@@ -4424,25 +4453,6 @@
   F.ImportLoc = TranslateSourceLocation(*M.ImportedBy, M.ImportLoc);
   }
 
-  if 

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

2023-06-01 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() :

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


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] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-01 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:
> > 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?


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] D142569: [OpenMP] Introduce kernel environment

2023-06-01 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

ping @arsenm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


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

2023-06-01 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

I'd change the patch title:

- `[NVPTX]` -> `[cuda, NVPTX]` as these are clang changes, not NVPTX back-end.
- `overloads ` -> `builtins`




Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:862
 BUILTIN(__nvvm_ldg_c, "ccC*", "")
+BUILTIN(__nvvm_ldg_sc, "ScScC*", "")
 BUILTIN(__nvvm_ldg_s, "ssC*", "")

One thing that bugs me is that ldg should technically be a `TARGET_BUILTIN(..., 
AND(PTX31,SM_32))`.

Oh, well, that train is gone now that pre-sm3x GPUs are no longer supported by 
NVIDIA anyways.



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


[PATCH] D151938: [clang][index] NFCI: Make `CXFile` a `FileEntryRef`

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added subscribers: ributzka, arphaman.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch swaps out the `void *` behind `CXFile` from `FileEntry *` to 
`FileEntryRef::MapEntry *`. This allows us to remove some deprecated uses of 
`FileEntry::getName()`.

Depends on D151854 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151938

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Frontend/ASTUnit.h
  clang/lib/Basic/Module.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/crash-vfs-umbrella-frameworks.m
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexHigh.cpp
  clang/tools/libclang/CIndexInclusionStack.cpp
  clang/tools/libclang/CLog.h
  clang/tools/libclang/CXFile.h
  clang/tools/libclang/CXIndexDataConsumer.cpp
  clang/tools/libclang/CXIndexDataConsumer.h
  clang/tools/libclang/CXLoadedDiagnostic.cpp
  clang/tools/libclang/CXSourceLocation.cpp
  clang/tools/libclang/Indexing.cpp

Index: clang/tools/libclang/Indexing.cpp
===
--- clang/tools/libclang/Indexing.cpp
+++ clang/tools/libclang/Indexing.cpp
@@ -255,7 +255,8 @@
 
 if (Loc == MainFileLoc && Reason == PPCallbacks::EnterFile) {
   IsMainFileEntered = true;
-  DataConsumer.enteredMainFile(SM.getFileEntryForID(SM.getMainFileID()));
+  DataConsumer.enteredMainFile(
+  *SM.getFileEntryRefForID(SM.getMainFileID()));
 }
   }
 
@@ -350,8 +351,8 @@
 PreprocessorOptions  = CI.getPreprocessorOpts();
 
 if (!PPOpts.ImplicitPCHInclude.empty()) {
-  auto File = CI.getFileManager().getFile(PPOpts.ImplicitPCHInclude);
-  if (File)
+  if (auto File =
+  CI.getFileManager().getOptionalFileRef(PPOpts.ImplicitPCHInclude))
 DataConsumer->importedPCH(*File);
 }
 
@@ -694,17 +695,18 @@
 
   ASTUnit::ConcurrencyCheck Check(*Unit);
 
-  if (const FileEntry *PCHFile = Unit->getPCHFile())
-DataConsumer.importedPCH(PCHFile);
+  if (OptionalFileEntryRef PCHFile = Unit->getPCHFile())
+DataConsumer.importedPCH(*PCHFile);
 
   FileManager  = Unit->getFileManager();
 
   if (Unit->getOriginalSourceFileName().empty())
-DataConsumer.enteredMainFile(nullptr);
-  else if (auto MainFile = FileMgr.getFile(Unit->getOriginalSourceFileName()))
+DataConsumer.enteredMainFile(std::nullopt);
+  else if (auto MainFile =
+   FileMgr.getFileRef(Unit->getOriginalSourceFileName()))
 DataConsumer.enteredMainFile(*MainFile);
   else
-DataConsumer.enteredMainFile(nullptr);
+DataConsumer.enteredMainFile(std::nullopt);
 
   DataConsumer.setASTContext(Unit->getASTContext());
   DataConsumer.startedTranslationUnit();
Index: clang/tools/libclang/CXSourceLocation.cpp
===
--- clang/tools/libclang/CXSourceLocation.cpp
+++ clang/tools/libclang/CXSourceLocation.cpp
@@ -13,6 +13,7 @@
 #include "CXSourceLocation.h"
 #include "CIndexer.h"
 #include "CLog.h"
+#include "CXFile.h"
 #include "CXLoadedDiagnostic.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
@@ -128,19 +129,19 @@
   LogRef Log = Logger::make(__func__);
   ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
   ASTUnit::ConcurrencyCheck Check(*CXXUnit);
-  const FileEntry *File = static_cast(file);
+  FileEntryRef File = *cxfile::getFileEntryRef(file);
   SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
   if (SLoc.isInvalid()) {
 if (Log)
   *Log << llvm::format("(\"%s\", %d, %d) = invalid",
-   File->getName().str().c_str(), line, column);
+   File.getName().str().c_str(), line, column);
 return clang_getNullLocation();
   }
   
   CXSourceLocation CXLoc =
   cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
   if (Log)
-*Log << llvm::format("(\"%s\", %d, %d) = ", File->getName().str().c_str(),
+*Log << llvm::format("(\"%s\", %d, %d) = ", File.getName().str().c_str(),
  line, column)
  << CXLoc;
 
@@ -160,7 +161,7 @@
   ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
 
   SourceLocation SLoc 
-= CXXUnit->getLocation(static_cast(file), offset);
+= CXXUnit->getLocation(*cxfile::getFileEntryRef(file), offset);
 
   if (SLoc.isInvalid())
 return clang_getNullLocation();
@@ -251,7 +252,7 @@
   }
   
   if (file)
-*file = const_cast(SM.getFileEntryForSLocEntry(sloc));
+*file = cxfile::makeCXFile(SM.getFileEntryRefForID(fileID));
   if (line)
 *line = SM.getExpansionLineNumber(ExpansionLoc);
   if (column)
@@ -328,7 +329,7 @@
 return createNullLocation(file, line, column, offset);
   
   if (file)
-

[PATCH] D151931: [clang] Remove `DirectoryEntry::getName()`

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Yes, I'd like to get the deprecation (and fixes in other LLVM sub-projects) 
into `main` ASAP and then land this patch after the branch for the 17 release 
is cut.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151931

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


[PATCH] D151931: [clang] Remove `DirectoryEntry::getName()`

2023-06-01 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

Given this was a commonly used function before and there's a decent chance it's 
used out of tree somewhere, should we wait until the next llvm release branch 
has been cut before landing this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151931

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


[PATCH] D151931: [clang] Remove `DirectoryEntry::getName()`

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch finally removes the deprecated `DirectoryEntry::getName()` function.

Depends on D151927 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151931

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  clang/lib/Basic/FileManager.cpp


Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -107,7 +107,6 @@
 
   // Add the virtual directory to the cache.
   auto *UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
-  UDE->Name = NamedDirEnt.first();
   NamedDirEnt.second = *UDE;
   VirtualDirectoryEntries.push_back(UDE);
 
@@ -179,7 +178,6 @@
 // We don't have this directory yet, add it.  We use the string
 // key from the SeenDirEntries map as the string.
 UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
-UDE->Name = InterndDirName;
   }
   NamedDirEnt.second = *UDE;
 
Index: clang/include/clang/Basic/DirectoryEntry.h
===
--- clang/include/clang/Basic/DirectoryEntry.h
+++ clang/include/clang/Basic/DirectoryEntry.h
@@ -41,13 +41,6 @@
   DirectoryEntry =(const DirectoryEntry &) = delete;
   friend class FileManager;
   friend class FileEntryTestHelper;
-
-  // FIXME: We should not be storing a directory entry name here.
-  StringRef Name; // Name of the directory.
-
-public:
-  LLVM_DEPRECATED("Use DirectoryEntryRef::getName() instead.", "")
-  StringRef getName() const { return Name; }
 };
 
 /// A reference to a \c DirectoryEntry  that includes the name of the directory


Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -107,7 +107,6 @@
 
   // Add the virtual directory to the cache.
   auto *UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
-  UDE->Name = NamedDirEnt.first();
   NamedDirEnt.second = *UDE;
   VirtualDirectoryEntries.push_back(UDE);
 
@@ -179,7 +178,6 @@
 // We don't have this directory yet, add it.  We use the string
 // key from the SeenDirEntries map as the string.
 UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
-UDE->Name = InterndDirName;
   }
   NamedDirEnt.second = *UDE;
 
Index: clang/include/clang/Basic/DirectoryEntry.h
===
--- clang/include/clang/Basic/DirectoryEntry.h
+++ clang/include/clang/Basic/DirectoryEntry.h
@@ -41,13 +41,6 @@
   DirectoryEntry =(const DirectoryEntry &) = delete;
   friend class FileManager;
   friend class FileEntryTestHelper;
-
-  // FIXME: We should not be storing a directory entry name here.
-  StringRef Name; // Name of the directory.
-
-public:
-  LLVM_DEPRECATED("Use DirectoryEntryRef::getName() instead.", "")
-  StringRef getName() const { return Name; }
 };
 
 /// A reference to a \c DirectoryEntry  that includes the name of the directory
___
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-01 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

This patch uses castAs instead of getAs which will assert if the type doesn't 
match in ConvertQualTypeToKind(clang::​ASTContext const &, clang::​QualType).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151928

Files:
  clang/lib/Interpreter/Value.cpp


Index: clang/lib/Interpreter/Value.cpp
===
--- clang/lib/Interpreter/Value.cpp
+++ clang/lib/Interpreter/Value.cpp
@@ -108,7 +108,7 @@
   if (!BT || BT->isNullPtrType())
 return Value::K_PtrOrObj;
 
-  switch (QT->getAs()->getKind()) {
+  switch (QT->castAs()->getKind()) {
   default:
 assert(false && "Type not supported");
 return Value::K_Unspecified;


Index: clang/lib/Interpreter/Value.cpp
===
--- clang/lib/Interpreter/Value.cpp
+++ clang/lib/Interpreter/Value.cpp
@@ -108,7 +108,7 @@
   if (!BT || BT->isNullPtrType())
 return Value::K_PtrOrObj;
 
-  switch (QT->getAs()->getKind()) {
+  switch (QT->castAs()->getKind()) {
   default:
 assert(false && "Type not supported");
 return Value::K_Unspecified;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar updated this revision to Diff 527591.
fahadnayyar added a comment.

Edits in comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-header-search-libcxx.cpp
  clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp


Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===
--- /dev/null
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -0,0 +1,28 @@
+// UNSUPPORTED: system-windows
+
+// Tests to check that we pass -L /bin/../lib/ to the linker to 
prioritize the toolchain's libc++.dylib over system's libc++.tbd in all cases.
+
+// Check that even if stdlib is not passed, on apple platforms we pass the 
toolchain's dylib path to the linker.
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// Check with -stdlib on both cases of toolchain installations (with and 
without libcxx).
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx 
--check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain 
--check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// CHECK-TOOLCHAIN-LIBCXX-LINKING-1: "/usr/bin/ld"
+// CHECK-TOOLCHAIN-LIBCXX-LINKING-1: "-L" "[[TOOLCHAIN]]/usr/bin/../lib"
Index: clang/test/Driver/darwin-header-search-libcxx.cpp
===
--- clang/test/Driver/darwin-header-search-libcxx.cpp
+++ clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -92,7 +92,7 @@
 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v1"
 
-// Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the 
toolchain
+// Make sure that using -nostdinc, -nostdinc++ or -nostdlibinc will drop both 
the toolchain
 // C++ include path and the sysroot one.
 //
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
@@ -116,7 +116,7 @@
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN: -stdlib=platform \
 // RUN: -nostdinc++ \
-// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
 // RUN:   --check-prefix=CHECK-LIBCXX-NOSTDINCXX %s
 // CHECK-LIBCXX-NOSTDINCXX: "-cc1"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -417,6 +417,17 @@
   Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
   Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
 
+  // Pass -L /bin/../lib/ to linker to prioritize 
toolchain's
+  // libc++.dylib over the sysroot-provided one. This matches what we do for
+  // determining which libc++ headers to use.
+  llvm::SmallString<128> InstallBinPath =
+  llvm::StringRef(D.getInstalledDir()); // /bin
+  llvm::SmallString<128> LibCxxDylibDirPath = InstallBinPath;
+  llvm::sys::path::append(LibCxxDylibDirPath, "..",
+  "lib"); // /bin/../lib
+  CmdArgs.push_back("-L");
+  CmdArgs.push_back(C.getArgs().MakeArgString(LibCxxDylibDirPath));
+
   // Give --sysroot= preference, over the Apple specific behavior to also use
   // --isysroot as the syslibroot.
   StringRef sysroot = C.getSysRoot();


Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===
--- /dev/null
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -0,0 +1,28 @@
+// UNSUPPORTED: system-windows
+
+// Tests to check that we pass -L /bin/../lib/ to the linker to prioritize the toolchain's libc++.dylib over system's libc++.tbd in all cases.
+
+// Check that even if stdlib is not passed, on apple platforms we pass the toolchain's dylib path to the linker.
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | 

[PATCH] D151927: [clang] Deprecate `DirectoryEntry::getName()`

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This finally oficially deprecates `DirectoryEntry::getName()`. I checked no 
usages remain in targets built by any of `check-clang`, `check-clang-tools`, 
`check-clang-extra`. There are probably some remaining usages in places
like LLDB and other clients. This will give them a chance to transition to 
`DirectoryEntryRef::getName()` before we remove the function altogether.

Depends on D151922 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151927

Files:
  clang/include/clang/Basic/DirectoryEntry.h


Index: clang/include/clang/Basic/DirectoryEntry.h
===
--- clang/include/clang/Basic/DirectoryEntry.h
+++ clang/include/clang/Basic/DirectoryEntry.h
@@ -46,6 +46,7 @@
   StringRef Name; // Name of the directory.
 
 public:
+  LLVM_DEPRECATED("Use DirectoryEntryRef::getName() instead.", "")
   StringRef getName() const { return Name; }
 };
 


Index: clang/include/clang/Basic/DirectoryEntry.h
===
--- clang/include/clang/Basic/DirectoryEntry.h
+++ clang/include/clang/Basic/DirectoryEntry.h
@@ -46,6 +46,7 @@
   StringRef Name; // Name of the directory.
 
 public:
+  LLVM_DEPRECATED("Use DirectoryEntryRef::getName() instead.", "")
   StringRef getName() const { return Name; }
 };
 
___
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-01 Thread Jeremy Furtek via Phabricator via cfe-commits
jfurtek created this revision.
Herald added subscribers: bzcheeseman, rriddle, hiraditya.
Herald added a project: All.
jfurtek requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, stephenneuendorffer.
Herald added projects: clang, LLVM.

This diff adds APFloat support for a semantic that matches the TF32 data type
used by some accelerators (most notably GPUs from both NVIDIA and AMD).

For more information on the TF32 data type, see 
https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/.
Some intrinsics that support the TF32 data type were added in 
https://reviews.llvm.org/D122044.

For some discussion on supporting common semantics in `APFloat`, see similar
efforts for 8-bit formats at https://reviews.llvm.org/D146441, as well as
https://discourse.llvm.org/t/rfc-adding-the-amd-graphcore-maybe-others-float8-formats-to-apfloat/67969.

A subsequent diff will extend MLIR to use this data type. (Those changes are
not part of this diff to simplify the review process.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151923

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp

Index: llvm/unittests/ADT/APFloatTest.cpp
===
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -682,6 +682,27 @@
 EXPECT_TRUE(T.isDenormal());
 EXPECT_EQ(fcPosSubnormal, T.classify());
   }
+
+  // Test TF32
+  {
+const char *MinNormalStr = "1.17549435082228750797e-38";
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), MinNormalStr).isDenormal());
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), 0).isDenormal());
+
+APFloat Val2(APFloat::FloatTF32(), 2);
+APFloat T(APFloat::FloatTF32(), MinNormalStr);
+T.divide(Val2, rdmd);
+EXPECT_TRUE(T.isDenormal());
+EXPECT_EQ(fcPosSubnormal, T.classify());
+
+
+const char *NegMinNormalStr = "-1.17549435082228750797e-38";
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), NegMinNormalStr).isDenormal());
+APFloat NegT(APFloat::FloatTF32(), NegMinNormalStr);
+NegT.divide(Val2, rdmd);
+EXPECT_TRUE(NegT.isDenormal());
+EXPECT_EQ(fcNegSubnormal, NegT.classify());
+  }
 }
 
 TEST(APFloatTest, IsSmallestNormalized) {
@@ -1350,6 +1371,16 @@
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), false, true, 0xaaULL },
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), true, false, 0xaaULL },
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), true, true,  0xaaULL },
+{0x3fe00ULL, APFloat::FloatTF32(), false, false,  0xULL },
+{0x7fe00ULL, APFloat::FloatTF32(), false,  true,  0xULL },
+{0x3feaaULL, APFloat::FloatTF32(), false, false,0xaaULL },
+{0x3ffaaULL, APFloat::FloatTF32(), false, false,   0xdaaULL },
+{0x3ffaaULL, APFloat::FloatTF32(), false, false,  0xfdaaULL },
+{0x3fd00ULL, APFloat::FloatTF32(),  true, false,  0xULL },
+{0x7fd00ULL, APFloat::FloatTF32(),  true,  true,  0xULL },
+{0x3fcaaULL, APFloat::FloatTF32(),  true, false,0xaaULL },
+{0x3fdaaULL, APFloat::FloatTF32(),  true, false,   0xfaaULL },
+{0x3fdaaULL, APFloat::FloatTF32(),  true, false,   0x1aaULL },
   // clang-format on
   };
 
@@ -1780,6 +1811,7 @@
 APFloat::getLargest(APFloat::Float8E5M2FNUZ()).convertToDouble());
   EXPECT_EQ(
   30, APFloat::getLargest(APFloat::Float8E4M3B11FNUZ()).convertToDouble());
+  EXPECT_EQ(3.40116213421e+38f, APFloat::getLargest(APFloat::FloatTF32()).convertToFloat());
 }
 
 TEST(APFloatTest, getSmallest) {
@@ -1831,6 +1863,14 @@
   EXPECT_TRUE(test.isFiniteNonZero());
   EXPECT_TRUE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
+  test = APFloat::getSmallest(APFloat::FloatTF32(), true);
+  expected = APFloat(APFloat::FloatTF32(), "-0x0.004p-126");
+  EXPECT_TRUE(test.isNegative());
+  EXPECT_TRUE(test.isFiniteNonZero());
+  EXPECT_TRUE(test.isDenormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
 }
 
 TEST(APFloatTest, getSmallestNormalized) {
@@ -1905,6 +1945,14 @@
   EXPECT_FALSE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
   EXPECT_TRUE(test.isSmallestNormalized());
+
+  test = APFloat::getSmallestNormalized(APFloat::FloatTF32(), false);
+  expected = APFloat(APFloat::FloatTF32(), "0x1p-126");
+  EXPECT_FALSE(test.isNegative());
+  EXPECT_TRUE(test.isFiniteNonZero());
+  EXPECT_FALSE(test.isDenormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+  EXPECT_TRUE(test.isSmallestNormalized());
 }
 
 TEST(APFloatTest, getZero) {
@@ -1936,7 +1984,9 @@
   {::Float8E4M3FNUZ(), false, 

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

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

Undo.


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,233 @@
+//===--- 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 "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  : 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, , "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", appendPathFileSystemIndependent({"foo", "qux.h"}),
+  appendPathFileSystemIndependent({"baz", "qux"}))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, , "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, , "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;" + appendPathFileSystemIndependent({"foo", "qux.h"})};
+  std::vector Errors;
+  

[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:105
 // RUN: -nostdinc \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \

ldionne wrote:
> 
Nevermind.



Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:133
 // RUN: -nostdlibinc \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \

ldionne wrote:
> 
Nevermind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

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


[PATCH] D151922: [clang] NFC: Use `DirectoryEntryRef` in `FileManager::getCanonicalName()`

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added subscribers: ributzka, kadircet, arphaman.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

This patch removes the last use of deprecated `DirectoryEntry::getName()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151922

Files:
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Lex/ModuleMap.cpp


Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1319,9 +1319,9 @@
   }
 
   FileManager  = SourceMgr.getFileManager();
-  auto DirEntry = FM.getDirectory(Dir.empty() ? "." : Dir);
+  auto DirEntry = FM.getDirectoryRef(Dir.empty() ? "." : Dir);
   if (!DirEntry)
-return DirEntry.getError();
+return llvm::errorToErrorCode(DirEntry.takeError());
 
   // Canonicalize the directory.
   StringRef CanonicalDir = FM.getCanonicalName(*DirEntry);
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -631,16 +631,15 @@
 UIDToFiles[VFE->getUID()] = VFE;
 }
 
-StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
-  llvm::DenseMap::iterator Known
-= CanonicalNames.find(Dir);
+StringRef FileManager::getCanonicalName(DirectoryEntryRef Dir) {
+  auto Known = CanonicalNames.find(Dir);
   if (Known != CanonicalNames.end())
 return Known->second;
 
-  StringRef CanonicalName(Dir->getName());
+  StringRef CanonicalName(Dir.getName());
 
   SmallString<4096> CanonicalNameBuf;
-  if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf))
+  if (!FS->getRealPath(Dir.getName(), CanonicalNameBuf))
 CanonicalName = CanonicalNameBuf.str().copy(CanonicalNameStorage);
 
   CanonicalNames.insert({Dir, CanonicalName});
Index: clang/include/clang/Basic/FileManager.h
===
--- clang/include/clang/Basic/FileManager.h
+++ clang/include/clang/Basic/FileManager.h
@@ -320,7 +320,7 @@
   /// This is a very expensive operation, despite its results being cached,
   /// and should only be used when the physical layout of the file system is
   /// required, which is (almost) never.
-  StringRef getCanonicalName(const DirectoryEntry *Dir);
+  StringRef getCanonicalName(DirectoryEntryRef Dir);
 
   /// Retrieve the canonical name for a given file.
   ///
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -537,7 +537,7 @@
   //
   //  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 = SourceMgr.getFileManager().getOptionalDirectoryRef(
   llvm::sys::path::parent_path(FilePath))) {
 llvm::SmallString<128> RealPath;
 llvm::StringRef DirName = 
SourceMgr.getFileManager().getCanonicalName(*Dir);
Index: clang-tools-extra/clang-move/Move.cpp
===
--- clang-tools-extra/clang-move/Move.cpp
+++ clang-tools-extra/clang-move/Move.cpp
@@ -92,7 +92,7 @@
  << '\n';
   // Handle symbolic link path cases.
   // We are trying to get the real file path of the symlink.
-  auto Dir = SM.getFileManager().getDirectory(
+  auto Dir = SM.getFileManager().getOptionalDirectoryRef(
   llvm::sys::path::parent_path(AbsolutePath.str()));
   if (Dir) {
 StringRef DirName = SM.getFileManager().getCanonicalName(*Dir);


Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1319,9 +1319,9 @@
   }
 
   FileManager  = SourceMgr.getFileManager();
-  auto DirEntry = FM.getDirectory(Dir.empty() ? "." : Dir);
+  auto DirEntry = FM.getDirectoryRef(Dir.empty() ? "." : Dir);
   if (!DirEntry)
-return DirEntry.getError();
+return llvm::errorToErrorCode(DirEntry.takeError());
 
   // Canonicalize the directory.
   StringRef CanonicalDir = FM.getCanonicalName(*DirEntry);
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -631,16 +631,15 @@
 UIDToFiles[VFE->getUID()] = VFE;
 }
 
-StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
-  llvm::DenseMap::iterator Known
-= CanonicalNames.find(Dir);
+StringRef FileManager::getCanonicalName(DirectoryEntryRef Dir) {
+  auto Known 

[PATCH] D148490: [AIX] use system assembler for assembly files

2023-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/target-as.s:1
 // Make sure the -march is passed down to cc1as.
 // RUN: %clang -target i386-unknown-freebsd -### -c -integrated-as %s \

shchenz wrote:
> MaskRay wrote:
> > aix-as.c will be more appropriate.
> Do you mean we change this file to `aix-as.s` or we change back to previous 
> version? The file `target-as.s` can not be renamed to `aix-as.s`, it also 
> contains tests for i386, see the first run line.
You can add the new tests to the existing `aix-as.s`. The behavior is about 
assemblers on AIX. `aix-as.s` seems more appropriate than `target-as.s`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148490

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


[PATCH] D151088: [flang][hlfir] Separate -emit-fir and -emit-hlfir for flang-new

2023-06-01 Thread Tom Eccles via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39ecf9d8a153: [flang][hlfir] Separate -emit-fir and 
-emit-hlfir for flang-new (authored by tblah).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151088

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/HLFIR/flang-experimental-hlfir-flag.f90

Index: flang/test/HLFIR/flang-experimental-hlfir-flag.f90
===
--- flang/test/HLFIR/flang-experimental-hlfir-flag.f90
+++ flang/test/HLFIR/flang-experimental-hlfir-flag.f90
@@ -1,19 +1,38 @@
-! Test -flang-experimental-hlfir flag
-! RUN: %flang_fc1 -flang-experimental-hlfir -emit-fir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s --check-prefix NO-HLFIR
+! Test -flang-experimental-hlfir, -emit-hlfir, -emit-fir flags
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix HLFIR --check-prefix ALL %s
+! RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -o - %s | FileCheck --check-prefix HLFIR --check-prefix ALL %s
+! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s --check-prefix NO-HLFIR --check-prefix ALL
+! RUN: %flang_fc1 -emit-fir -flang-experimental-hlfir -o - %s | FileCheck --check-prefix FIR --check-prefix ALL %s
+
+! | Action  | -flang-experimental-hlfir? | Result  |
+! | === | == | === |
+! | -emit-hlfir | N  | Outputs HLFIR   |
+! | -emit-hlfir | Y  | Outputs HLFIR   |
+! | -emit-fir   | N  | Outputs FIR, using old lowering |
+! | -emit-fir   | Y  | Outputs FIR, lowering via HLFIR |
 
 subroutine test(a, res)
   real :: a(:), res
   res = SUM(a)
 end subroutine
-! CHECK-LABEL: func.func @_QPtest
-! CHECK:   %[[A:.*]]: !fir.box>
-! CHECK:   %[[RES:.*]]: !fir.ref
-! CHECK-DAG: %[[A_VAR:.*]]:2 = hlfir.declare %[[A]]
-! CHECK-DAG: %[[RES_VAR:.*]]:2 = hlfir.declare %[[RES]]
-! CHECK-NEXT:%[[SUM_RES:.*]] = hlfir.sum %[[A_VAR]]#0
-! CHECK-NEXT:hlfir.assign %[[SUM_RES]] to %[[RES_VAR]]#0
-! CHECK-NEXT:return
-! CHECK-NEXT:  }
+! ALL-LABEL: func.func @_QPtest
+! ALL: %[[A:.*]]: !fir.box>
+! ALL: %[[RES:.*]]: !fir.ref
+
+! HLFIR: %[[A_VAR:.*]]:2 = hlfir.declare %[[A]]
+! fir.declare is only generated via the hlfir -> fir lowering
+! FIR:   %[[A_VAR:.*]] = fir.declare %[[A]]
+! NO-HLFIR-NOT:  fir.declare
+
+! HLFIR-DAG: %[[RES_VAR:.*]]:2 = hlfir.declare %[[RES]]
+! FIR:   %[[RES_VAR:.*]] = fir.declare %[[RES]]
+! NO-HLFIR-NOT:  fir.declare
+
+! HLFIR-NEXT:%[[SUM_RES:.*]] = hlfir.sum %[[A_VAR]]#0
+! HLFIR-NEXT:hlfir.assign %[[SUM_RES]] to %[[RES_VAR]]#0
+! FIR-NOT:   hlfir.
+! NO-HLFIR-NOT:  hlfir.
+
+! ALL:   return
+! ALL-NEXT:  }
 
-! NO-HLFIR-NOT: hlfir.
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -94,9 +94,10 @@
 ! HELP-FC1-NEXT:OPTIONS:
 ! HELP-FC1-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -emit-fir  Build the parse tree, then lower it to FIR
+! HELP-FC1-NEXT: -emit-hlfirBuild the parse tree, then lower it to HLFIR
 ! HELP-FC1-NEXT: -emit-llvm-bc  Build ASTs then convert to LLVM, emit .bc file
 ! HELP-FC1-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
-! HELP-FC1-NEXT: -emit-mlir Build the parse tree, then lower it to MLIR
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -falternative-parameter-statement
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -40,8 +40,10 @@
 return std::make_unique();
   case ParseSyntaxOnly:
 return std::make_unique();
-  case EmitMLIR:
-return std::make_unique();
+  case EmitFIR:
+return std::make_unique();
+  case EmitHLFIR:
+return std::make_unique();
   case EmitLLVM:
 return std::make_unique();
   case EmitLLVMBitcode:
Index: flang/lib/Frontend/FrontendActions.cpp
===

[clang] 39ecf9d - [flang][hlfir] Separate -emit-fir and -emit-hlfir for flang-new

2023-06-01 Thread Tom Eccles via cfe-commits

Author: Tom Eccles
Date: 2023-06-01T19:29:16Z
New Revision: 39ecf9d8a1533a434bb9544a1bc275c4d02e2efb

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

LOG: [flang][hlfir] Separate -emit-fir and -emit-hlfir for flang-new

In review for https://reviews.llvm.org/D146278, @vzakhari asked to
separate -emit-fir and -emit-hlfir. This will allow FIR to be easily
outputted after the HLFIR passes have been run.

The new semantics are as follows:

| Action  | -flang-experimental-hlfir? | Result |
| === | == | === |
| -emit-hlfir | N  | Outputs HLFIR   |
| -emit-hlfir | Y  | Outputs HLFIR   |
| -emit-fir   | N  | Outputs FIR, using old lowering |
| -emit-fir   | Y  | Outputs FIR, lowering via HLFIR |

A patch for bbc will follow.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Driver/driver-help.f90
flang/test/HLFIR/flang-experimental-hlfir-flag.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 41bd1c00eb229..b77fec6720792 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5268,9 +5268,12 @@ def fno_reformat : Flag<["-"], "fno-reformat">, 
Group,
   HelpText<"Dump the cooked character stream in -E mode">;
 defm analyzed_objects_for_unparse : 
OptOutFC1FFlag<"analyzed-objects-for-unparse", "", "Do not use the analyzed 
objects when unparsing">;
 
-def emit_mlir : Flag<["-"], "emit-mlir">, Group,
-  HelpText<"Build the parse tree, then lower it to MLIR">;
-def emit_fir : Flag<["-"], "emit-fir">, Alias;
+def emit_fir : Flag<["-"], "emit-fir">, Group,
+  HelpText<"Build the parse tree, then lower it to FIR">;
+def emit_mlir : Flag<["-"], "emit-mlir">, Alias;
+
+def emit_hlfir : Flag<["-"], "emit-hlfir">, Group,
+  HelpText<"Build the parse tree, then lower it to HLFIR">;
 
 } // let Flags = [FC1Option, FlangOnlyOption]
 

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 2b96125e41639..8272e0729ce3f 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -191,7 +191,8 @@ enum class BackendActionTy {
   Backend_EmitObj,  ///< Emit native object files
   Backend_EmitBC,   ///< Emit LLVM bitcode files
   Backend_EmitLL,   ///< Emit human-readable LLVM assembly
-  Backend_EmitMLIR  ///< Emit MLIR files
+  Backend_EmitFIR,  ///< Emit FIR files, possibly lowering via HLFIR
+  Backend_EmitHLFIR,///< Emit HLFIR files before any passes run
 };
 
 /// Abstract base class for actions that generate code (MLIR, LLVM IR, assembly
@@ -224,6 +225,9 @@ class CodeGenAction : public FrontendAction {
   /// Embeds offload objects given with specified with -fembed-offload-object
   void embedOffloadObjects();
 
+  /// Runs pass pipeline to lower HLFIR into FIR
+  void lowerHLFIRToFIR();
+
   /// Generates an LLVM IR module from CodeGenAction::mlirModule and saves it
   /// in CodeGenAction::llvmModule.
   void generateLLVMIR();
@@ -236,9 +240,14 @@ class CodeGenAction : public FrontendAction {
   ~CodeGenAction() override;
 };
 
-class EmitMLIRAction : public CodeGenAction {
+class EmitFIRAction : public CodeGenAction {
+public:
+  EmitFIRAction() : CodeGenAction(BackendActionTy::Backend_EmitFIR) {}
+};
+
+class EmitHLFIRAction : public CodeGenAction {
 public:
-  EmitMLIRAction() : CodeGenAction(BackendActionTy::Backend_EmitMLIR) {}
+  EmitHLFIRAction() : CodeGenAction(BackendActionTy::Backend_EmitHLFIR) {}
 };
 
 class EmitLLVMAction : public CodeGenAction {

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 4691dfe87a731..06b1318f243b0 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -34,8 +34,11 @@ enum ActionKind {
   /// -fsyntax-only
   ParseSyntaxOnly,
 
-  /// Emit a .mlir file
-  EmitMLIR,
+  /// Emit FIR mlir file
+  EmitFIR,
+
+  /// Emit HLFIR mlir file
+  EmitHLFIR,
 
   /// Emit an .ll file
   EmitLLVM,

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 98a87143f0f6d..02973178d9c28 100644
--- 

[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:1553-1554
 return TPResult::Error;
-  if (Tok.isNot(tok::identifier))
+  if (NextToken().isNot(tok::identifier))
 break;
 }

rsmith wrote:
> This doesn't seem correct to me. If we had `scope::foo bar`, and we annotate 
> `scope::foo` as a type, then this will get confused by the next token now 
> being an (unrelated) identifier. This code is trying to detect if an 
> annotation was performed, so I think it intended to check if the current 
> token's kind has changed, like is done on line 1295.
The confusing bit is that Tok is always an annotated scope already here 
(L1598), so TryAnnotateName should not modify that first token (unless 
TryAnnotateTypeOrScopeTokenAfterScopeSpec can somehow replace the current 
annot_cxxscope by another one, which i don't think can happen?) 


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

https://reviews.llvm.org/D134334

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


[PATCH] D151761: clang-format: Add AlignConsecutiveShortCaseLabels

2023-06-01 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D151761#4385571 , @galenelias 
wrote:

> In D151761#4385163 , 
> @HazardyKnusperkeks wrote:
>
>> When I read the title I thought "Yay, some one is doing what I want and 
>> don't find the time.", but (for me) sadly you're not.
>> I'd like to align the colon (and thus the statement behind that). Do you 
>> think you can add that option too?
>
> Hmm, it had not occurred to me that there are folks who would want to insert 
> the spaces after the 'case'.  I can think about how that might be 
> accomplished, but it doesn't seem straightforward given the current alignment 
> infrastructure since the token you want to align (the colon) isn't the token 
> which should be padded (the token after the case keyword).  I think I'd have 
> to write custom alignment code to allow for the separation of these two.

After sleeping over it I want to revoke my request. Aligning the statements is 
sufficient, we don't need too much options. It just has to work with 
`SpaceBeforeCaseColon`, which I assume it already does.




Comment at: clang/docs/ClangFormatStyleOptions.rst:790
+
+**AlignConsecutiveShortCaseLabels** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 17` :ref:`¶ `
+  Style of aligning consecutive short case labels.

MyDeveloperDay wrote:
> galenelias wrote:
> > MyDeveloperDay wrote:
> > > Did you generate this by hand or run the dump_format_style.py function? 
> > > Format.h and the rst look out of sync
> > This was generated from dump_format_style.py.  What looks out of sync?  My 
> > guess is the confusing thing is all the styles which use 
> > `AlignConsecutiveStyle` get the same documentation pasted for them which 
> > specifically references `AlignConsecutiveMacros` and makes it look like 
> > it's for the wrong option.
> that doesn't feel right to me.. not saying its not dump_format_style.py but 
> it shouldn't do that in my view
What shouldn't it be doing?
The struct is used for multiple options and the documentation is that ways 
since we have the struct.



Comment at: clang/include/clang/Format/Format.h:308
+  /// \version 17
+  AlignConsecutiveStyle AlignConsecutiveShortCaseLabels;
 

galenelias wrote:
> HazardyKnusperkeks wrote:
> > We need another name, you're not aligning the label, but the statement.
> I was taking the name from the GitHub issue, which while I agree is a slight 
> misnomer seemed to yield what I assumed most people would expect.  I guess 
> `AlignConsecutiveStatementsAfterShortCaseLabels` is more correct, but is also 
> getting pretty verbose.
Maybe just `AlignConsecutiveShortCaseStatements`?



Comment at: clang/unittests/Format/FormatTest.cpp:19195
 
+TEST_F(FormatTest, AlignConsecutiveShortCaseLabels) {
+  FormatStyle Alignment = getLLVMStyle();

Could you add test cases with not short cases between/at the begin of/at the 
end of the short ones?



Comment at: clang/unittests/Format/FormatTest.cpp:19255
+   Alignment);
+}
+

galenelias wrote:
> HazardyKnusperkeks wrote:
> > Add a test with `AcrossEmptyLines` and `AcrossComments`.
> There is a test for both `AcrossEmptyLines` and `AcrossComments`.  Maybe I'm 
> not understanding your comment?
A test where both are `true`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151761

___
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-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527554.
VitaNuo added a comment.

Experiment with paths.


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,233 @@
+//===--- 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 "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  : 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, , "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", appendPathFileSystemIndependent({"foo", "qux.h"}),
+  appendPathFileSystemIndependent({"baz", "qux"}))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, , "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, , "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;" + appendPathFileSystemIndependent({"foo", "qux.h"})};
+  

[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-06-01 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D149867#4387189 , @glaubitz wrote:

> In D149867#4386271 , @jrtc27 wrote:
>
>> I disagree. Being experimental doesn't mean you should do the wrong thing. 
>> Reusing stdcall in the frontend is ugly, pollutes non-m68k code paths (doing 
>> your own thing _avoids_ that and makes the experimental backend get out of 
>> the way, even) and introduces a bug where you can write garbage code and 
>> have it compile rather than be rejected like it should be.
>
> Maybe we can get the TLS stuff merged first before dealing with this more 
> complex change?

They're totally independent, so nothing's blocking that being merged. Plus this 
isn't a complex change to make, just a bunch of copy pasta.


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

https://reviews.llvm.org/D149867

___
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-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527545.
VitaNuo added a comment.

Undo.


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,233 @@
+//===--- 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 "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  : 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, , "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", appendPathFileSystemIndependent({"foo", "qux.h"}),
+  appendPathFileSystemIndependent({"baz", "qux"}))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, , "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, , "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;" + appendPathFileSystemIndependent({"foo", "qux.h"})};
+  std::vector Errors;
+  

[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith requested changes to this revision.
rsmith added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Parse/ParseTentative.cpp:1553-1554
 return TPResult::Error;
-  if (Tok.isNot(tok::identifier))
+  if (NextToken().isNot(tok::identifier))
 break;
 }

This doesn't seem correct to me. If we had `scope::foo bar`, and we annotate 
`scope::foo` as a type, then this will get confused by the next token now being 
an (unrelated) identifier. This code is trying to detect if an annotation was 
performed, so I think it intended to check if the current token's kind has 
changed, like is done on line 1295.


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

https://reviews.llvm.org/D134334

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


[clang] 0a21fb3 - [Fuchsia] Reland: Add llvm-debuginfod to toolchain

2023-06-01 Thread Daniel Thornburgh via cfe-commits

Author: Daniel Thornburgh
Date: 2023-06-01T11:48:22-07:00
New Revision: 0a21fb3441dcffa2ccd8215f423100fbe4182f12

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

LOG: [Fuchsia] Reland: Add llvm-debuginfod to toolchain

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 8f5aa21be6fb8..78c123f191305 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -296,6 +296,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-ar
   llvm-cov
   llvm-cxxfilt
+  llvm-debuginfod
   llvm-debuginfod-find
   llvm-dlltool
   ${LLVM_DRIVER_TARGET}

diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index 5596cc61359cd..bd882647312b9 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -32,8 +32,10 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
   LLVM_ENABLE_LIBXML2
   LibXml2_ROOT
   LLVM_ENABLE_CURL
+  LLVM_ENABLE_HTTPLIB
   CURL_ROOT
   OpenSSL_ROOT
+  httplib_ROOT
   FUCHSIA_ENABLE_LLDB
   LLDB_ENABLE_CURSES
   LLDB_ENABLE_LIBEDIT



___
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-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527543.
VitaNuo added a comment.

Fix last test.


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,232 @@
+//===--- 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 "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  : 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, , "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", appendPathFileSystemIndependent({"foo", "qux.h"}),
+  appendPathFileSystemIndependent({"baz", "qux"}))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, , "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, , "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;foo/qux.h"};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, runCheckOnCode(
+

[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

This LGTM w/ comments applied. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

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


[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:95
 
 // Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the 
toolchain
 // C++ include path and the sysroot one.





Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:105
 // RUN: -nostdinc \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \





Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:133
 // RUN: -nostdlibinc \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \





Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:119
 // RUN: -nostdinc++ \
-// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \

fahadnayyar wrote:
> ldionne wrote:
> > Is this change really needed anymore? Why?
> This is unrelated small bug in darwin-header-search-libcxx.cpp. I thought 
> maybe we fix that small issue also in this patch. What you think?
Ah, I see. I think I understand the bug. Yeah I think it makes sense to fix it 
here but I added a few more fixes in comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

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


[PATCH] D151732: [clang][docs] document __attribute__((cleanup())) GNU C extension

2023-06-01 Thread Nick Desaulniers 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 rG8dc13957cb17: [clang][docs] document 
__attribute__((cleanup())) GNU C extension (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151732

Files:
  clang/include/clang/Basic/Attr.td
  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
@@ -7023,3 +7023,30 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1097,7 +1097,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -7023,3 +7023,30 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1097,7 +1097,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8dc1395 - [clang][docs] document __attribute__((cleanup())) GNU C extension

2023-06-01 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-06-01T11:24:53-07:00
New Revision: 8dc13957cb1752b6a90e299d016e09bb98b0df54

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

LOG: [clang][docs] document __attribute__((cleanup())) GNU C extension

Provide an example of how to use this extension and more importantly,
document that cleanup functions are run in reverse nested order.

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index e11439158fc0..3fdd84d2b13b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1097,7 +1097,7 @@ def Cleanup : InheritableAttr {
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index d719f4691251..e3d83234b316 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7023,3 +7023,30 @@ This attribute may be attached to a function pointer 
type, where it modifies
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}



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


[PATCH] D151732: [clang][docs] document __attribute__((cleanup())) GNU C extension

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

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151732

Files:
  clang/include/clang/Basic/Attr.td
  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
@@ -7023,3 +7023,30 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1097,7 +1097,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -7023,3 +7023,30 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1097,7 +1097,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151732: [clang][docs] document __attribute__((cleanup())) GNU C extension

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

- add note about reverse declaration order for variables declared in the same 
scope


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151732

Files:
  clang/include/clang/Basic/Attr.td
  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
@@ -6988,3 +6988,30 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1084,7 +1084,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6988,3 +6988,30 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y`` when ``y`` goes out of scope, then a call to ``foo`` being passed the
+address of ``x`` when ``x`` goes out of scope. If two or more variables share
+the same scope, their ``cleanup`` callbacks are invoked in the reverse order
+the variables were declared in. It is not possible to check the return value
+(if any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1084,7 +1084,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151732: [clang][docs] document __attribute__((cleanup())) GNU C extension

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

- add note about function signature


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151732

Files:
  clang/include/clang/Basic/Attr.td
  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
@@ -6988,3 +6988,28 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y``, then a call to ``foo`` being passed the address of ``x`` (as ``y`` goes
+out of scope before ``x``). It is not possible to check the return value (if
+any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1084,7 +1084,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6988,3 +6988,28 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+int x __attribute__((cleanup(foo)));
+{
+  int y __attribute__((cleanup(bar)));
+}
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y``, then a call to ``foo`` being passed the address of ``x`` (as ``y`` goes
+out of scope before ``x``). It is not possible to check the return value (if
+any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1084,7 +1084,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar marked 2 inline comments as done.
fahadnayyar added inline comments.



Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:119
 // RUN: -nostdinc++ \
-// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \

ldionne wrote:
> Is this change really needed anymore? Why?
This is unrelated small bug in darwin-header-search-libcxx.cpp. I thought maybe 
we fix that small issue also in this patch. What you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

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


[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar updated this revision to Diff 527512.
fahadnayyar added a comment.

Simplifying the test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-header-search-libcxx.cpp
  clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp


Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===
--- /dev/null
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -0,0 +1,28 @@
+// UNSUPPORTED: system-windows
+
+// Tests to check that we pass -L /bin/../lib/ to the linker to 
prioritize the toolchain's libc++.dylib over system's libc++.tbd in all cases.
+
+// Check that even if stdlib is not passed, on apple platforms we pass the 
toolchain's dylib path to the linker.
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// Check with -stdlib on both cases of toolchain installations (with and 
without libcxx).
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx 
--check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain 
--check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// CHECK-TOOLCHAIN-LIBCXX-LINKING-1: "/usr/bin/ld"
+// CHECK-TOOLCHAIN-LIBCXX-LINKING-1: "-L" "[[TOOLCHAIN]]/usr/bin/../lib"
Index: clang/test/Driver/darwin-header-search-libcxx.cpp
===
--- clang/test/Driver/darwin-header-search-libcxx.cpp
+++ clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -116,7 +116,7 @@
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN: -stdlib=platform \
 // RUN: -nostdinc++ \
-// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
 // RUN:   --check-prefix=CHECK-LIBCXX-NOSTDINCXX %s
 // CHECK-LIBCXX-NOSTDINCXX: "-cc1"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -417,6 +417,17 @@
   Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
   Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
 
+  // Pass -L /bin/../lib/ to linker to prioritize 
toolchain's
+  // libc++.dylib over the sysroot-provided one. This matches what we do for
+  // determining which libc++ headers to use.
+  llvm::SmallString<128> InstallBinPath =
+  llvm::StringRef(D.getInstalledDir()); // /bin
+  llvm::SmallString<128> LibCxxDylibDirPath = InstallBinPath;
+  llvm::sys::path::append(LibCxxDylibDirPath, "..",
+  "lib"); // /bin/../lib
+  CmdArgs.push_back("-L");
+  CmdArgs.push_back(C.getArgs().MakeArgString(LibCxxDylibDirPath));
+
   // Give --sysroot= preference, over the Apple specific behavior to also use
   // --isysroot as the syslibroot.
   StringRef sysroot = C.getSysRoot();


Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===
--- /dev/null
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -0,0 +1,28 @@
+// UNSUPPORTED: system-windows
+
+// Tests to check that we pass -L /bin/../lib/ to the linker to prioritize the toolchain's libc++.dylib over system's libc++.tbd in all cases.
+
+// Check that even if stdlib is not passed, on apple platforms we pass the toolchain's dylib path to the linker.
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// Check with -stdlib on both cases of toolchain installations (with and without libcxx).
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN:   | FileCheck 

[PATCH] D150253: [RISCV] Add Zvfhmin extension for clang.

2023-06-01 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:2219
+  def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
+  let RequiredFeatures = ["ZvfhminOrZvfh"] in
+def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {

craig.topper wrote:
> eopXD wrote:
> > I think using `ZvfhminOrZvfh` is not accurate here. By the v-spec:
> > 
> > > When the Zvfhmin extension is implemented, the vfwcvt.f.f.v and 
> > > vfncvt.f.f.w instructions become defined when SEW=16. 
> > > The Zvfh extension depends on the Zve32f and Zfhmin extensions.
> > 
> > I think making it `let RequiredFeatures = ["Zvfhmin"]` would be clearer.
> Note that the spec says Zfhmin(no v) not Zvfhmin. 
My mistake. I suspect this is an oversight of the v-spec, just created an issue 
for this.

https://github.com/riscv/riscv-v-spec/issues/885


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

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


[PATCH] D151855: [clang] Use `{File,Directory}EntryRef` in modular header search (part 2/2)

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

I noticed the `Modules/crash-vfs-umbrella-frameworks.m` test fails. I'll need 
to look into this some more.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151855

___
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-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527509.
VitaNuo added a comment.

Try ignoring verbatim spelling.


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,232 @@
+//===--- 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 "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  : 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, , "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", appendPathFileSystemIndependent({"foo", "qux.h"}),
+  appendPathFileSystemIndependent({"baz", "qux"}))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, , "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, , "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;\"foo/qux.h\""};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, 

[PATCH] D151855: [clang] Use `{File,Directory}EntryRef` in modular header search (part 2/2)

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 527508.
jansvoboda11 added a comment.

Rebase, reformat


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151855

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp

Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -700,13 +700,12 @@
   return It->second;
 }
 
-bool ModuleMap::isHeaderInUnavailableModule(const FileEntry *Header) const {
+bool ModuleMap::isHeaderInUnavailableModule(FileEntryRef Header) const {
   return isHeaderUnavailableInModule(Header, nullptr);
 }
 
-bool
-ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
-   const Module *RequestingModule) const {
+bool ModuleMap::isHeaderUnavailableInModule(
+FileEntryRef Header, const Module *RequestingModule) const {
   resolveHeaderDirectives(Header);
   HeadersMap::const_iterator Known = Headers.find(Header);
   if (Known != Headers.end()) {
@@ -734,8 +733,8 @@
 return true;
   }
 
-  const DirectoryEntry *Dir = Header->getDir();
-  SmallVector SkippedDirs;
+  OptionalDirectoryEntryRef Dir = Header.getDir();
+  SmallVector SkippedDirs;
   StringRef DirName = Dir->getName();
 
   auto IsUnavailable = [&](const Module *M) {
@@ -746,8 +745,7 @@
   // Keep walking up the directory hierarchy, looking for a directory with
   // an umbrella header.
   do {
-llvm::DenseMap::const_iterator KnownDir
-  = UmbrellaDirs.find(Dir);
+auto KnownDir = UmbrellaDirs.find(*Dir);
 if (KnownDir != UmbrellaDirs.end()) {
   Module *Found = KnownDir->second;
   if (IsUnavailable(Found))
@@ -761,11 +759,11 @@
 UmbrellaModule = UmbrellaModule->Parent;
 
   if (UmbrellaModule->InferSubmodules) {
-for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) {
+for (DirectoryEntryRef SkippedDir : llvm::reverse(SkippedDirs)) {
   // Find or create the module that corresponds to this directory name.
   SmallString<32> NameBuf;
   StringRef Name = sanitizeFilenameAsIdentifier(
-  llvm::sys::path::stem(SkippedDir->getName()), NameBuf);
+  llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
   Found = lookupModuleQualified(Name, Found);
   if (!Found)
 return false;
@@ -776,7 +774,7 @@
 // Infer a submodule with the same name as this header file.
 SmallString<32> NameBuf;
 StringRef Name = sanitizeFilenameAsIdentifier(
-   llvm::sys::path::stem(Header->getName()),
+   llvm::sys::path::stem(Header.getName()),
NameBuf);
 Found = lookupModuleQualified(Name, Found);
 if (!Found)
@@ -786,7 +784,7 @@
   return IsUnavailable(Found);
 }
 
-SkippedDirs.push_back(Dir);
+SkippedDirs.push_back(*Dir);
 
 // Retrieve our parent path.
 DirName = llvm::sys::path::parent_path(DirName);
@@ -794,10 +792,7 @@
   break;
 
 // Resolve the parent path to a directory entry.
-if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName))
-  Dir = *DirEntry;
-else
-  Dir = nullptr;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
   } while (Dir);
 
   return false;
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1751,12 +1751,12 @@
 }
 
 OptionalFileEntryRef
-HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
+HeaderSearch::lookupModuleMapFile(DirectoryEntryRef Dir, bool IsFramework) {
   if (!HSOpts->ImplicitModuleMaps)
 return std::nullopt;
   // For frameworks, the preferred spelling is Modules/module.modulemap, but
   // module.map at the framework root is also accepted.
-  SmallString<128> ModuleMapFileName(Dir->getName());
+  SmallString<128> ModuleMapFileName(Dir.getName());
   if (IsFramework)
 llvm::sys::path::append(ModuleMapFileName, "Modules");
   llvm::sys::path::append(ModuleMapFileName, "module.modulemap");
@@ -1764,7 +1764,7 @@
 return *F;
 
   // Continue to allow module.map
-  ModuleMapFileName = Dir->getName();
+  ModuleMapFileName = Dir.getName();
   llvm::sys::path::append(ModuleMapFileName, "module.map");
   if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
 return *F;
@@ -1772,7 +1772,7 @@
   // For frameworks, allow to have a private module map with a preferred
   // spelling when a public module map is absent.
   if (IsFramework) {
-ModuleMapFileName = Dir->getName();
+ModuleMapFileName = Dir.getName();
 llvm::sys::path::append(ModuleMapFileName, "Modules",
  

[PATCH] D150253: [RISCV] Add Zvfhmin extension for clang.

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



Comment at: clang/include/clang/Basic/riscv_vector.td:2219
+  def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
+  let RequiredFeatures = ["ZvfhminOrZvfh"] in
+def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {

eopXD wrote:
> I think using `ZvfhminOrZvfh` is not accurate here. By the v-spec:
> 
> > When the Zvfhmin extension is implemented, the vfwcvt.f.f.v and 
> > vfncvt.f.f.w instructions become defined when SEW=16. 
> > The Zvfh extension depends on the Zve32f and Zfhmin extensions.
> 
> I think making it `let RequiredFeatures = ["Zvfhmin"]` would be clearer.
Note that the spec says Zfhmin(no v) not Zvfhmin. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

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


[PATCH] D112932: Use llvm.is_fpclass to implement FP classification functions

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



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2185-2187
+  auto TestV = llvm::ConstantInt::get(CGF->Int32Ty, Test);
+  Function *F = CGF->CGM.getIntrinsic(Intrinsic::is_fpclass, V->getType());
+  return CGF->Builder.CreateCall(F, {V, TestV});

Might as well put this in IRBuilder 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112932

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


[PATCH] D151904: [clang-repl][CUDA] Add an unit test for interactive CUDA

2023-06-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/unittests/Interpreter/InteractiveCudaTest.cpp:92
+  std::unique_ptr Interp = createInterpreter();
+  auto Err = Interp->LoadDynamicLibrary("libcudart.so");
+  if (Err) { // CUDA runtime is not installed/usable, cannot continue testing

argentite wrote:
> tra wrote:
> > This could be a bit of a problem.
> > 
> > There may be multiple CUDA SDK versions that may be installed on a system 
> > at any given time and the libcudart.so you pick here may not be the one you 
> > want.
> > E.g it may be from a recent CUDA version which is not supported by NVIDIA 
> > drivers yet. 
> > 
> > I think you may need a way to let the user override CUDA SDK (or 
> > libcudart.so) location explicitly. I guess they could do that via 
> > LD_LIBRARY_PATH, but for the CUDA compilation in general, knowing CUDA SDK 
> > path is essential, as it does affect various compilation options set by the 
> > driver.
> > 
> Yes, this probably would be an issue. It is currently possible to override 
> the CUDA path with a command line argument in clang-repl. But I am not sure 
> what we can do inside a test.
To me it looks like CUDA location should be detected/set at the configuration 
time and then propagated to the individual tests that need that info.
CMake has cuda detection mechanisms that could be used for that purpose.
They are a bit of a pain to use in practice (I'm still not sure what's the 
reliable way to do it), but it's as close to the 'standard' way of doing it as 
we have at the moment.
I believe libc and mlir subtrees in LLVM are already using this mechanism. E.g 
https://github.com/llvm/llvm-project/blob/main/libc/utils/gpu/loader/CMakeLists.txt#L16


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151904

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


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

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



Comment at: clang/lib/Sema/TreeTransform.h:11940-11943
-  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
-  if (Callee.isInvalid())
-return ExprError();
-

rsmith wrote:
> Fznamznon wrote:
> > cor3ntin wrote:
> > > I don't understand why we would not need to transform the callee. do we 
> > > do that elsewhere?
> > For example, the code above for call and subscript operators never 
> > transforms the callee.
> > This `TransFormExpr` call  seems to be a no-op for overloaded operator call 
> > case, and the result never ends up in the resulting ast.
> > 
> To me it looks like we need to transform the callee in order to transform the 
> declarations in the `UnresolvedLookupExpr`, if the operator has such 
> functions. For example, in:
> 
> ```
> 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); }
> ```
> 
> ... we need to transform the `UnresolvedLookupExpr` for the `t + t` to map 
> from the `operator+` declaration in the `A::f` template to the instantiated 
> `operator+` declaration in `A::f`.
> 
> But I think this patch is going in the right direction. We don't *actually* 
> want to transform the callee; all we want to do is to transform the function 
> or list of functions contained in the callee to form an `UnresolvedSet` of 
> candidates found during the template parse. Building and then throwing away a 
> `DeclRefExpr` or `UnresolvedLookupExpr` denoting that function or set of 
> functions is both a waste of time and (as demonstrated by the bug being 
> addressed here) problematic.
> 
> Instead of calling `TransformExpr` on the callee, we should be calling 
> `TransformOverloadExprDecls` if the callee is an `UnresolvedLookupExpr` or 
> `TransformDecl` if it's a `DeclRefExpr`, and I think 
> `RebuildCXXOperatorCallExpr` should be changed to take an `UnresolvedSet` and 
> a `RequiresADL` flag, and it looks like we can then remove the `OrigCallee` 
> parameter, if we pass in some extra source locations.
Thank you for the feedback @rsmith , I appreciate it very much.
I tried the described approach, and it fixes the original bug I was trying to 
resolve as well as makes the mentioned example work correctly whereas my 
original change broke it. Apparently, we don't have test like that in 
check-clang set. I'm going to polish the resulting code a bit and put up to 
review tomorrow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151553

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


[PATCH] D151869: [RISCV] Support more builtin for zvfhmin.

2023-06-01 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added a comment.

I think the topic of this patch is not accurate. The compiler already support 
these intrinsics with `zvfh` specified. Implementing `zvfhmin` is relaxing the 
implementation and let come the intrinsics available when only `zvfhmin` and 
not `zvfm` is specified. So I think we can adjust the patch description a bit.

I think you may relax the extension specified, which is currently `zvfh`, to 
using `zvfhmin`, under the existing test cases under 
`clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated` to verify your 
implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151869

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


[PATCH] D150253: [RISCV] Add Zvfhmin extension for clang.

2023-06-01 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2050
   Diag(Loc, diag::err_riscv_type_requires_extension, FD)
-  << Ty << "zvfh";
+  << Ty << "zvfh or zvfhmin";
 if (Ty->isRVVType(/* Bitwidth */ 32, /* IsFloat */ true) &&

We can remove `!TI.hasFeature("experimental-zvfh")` since `zvfh` will imply 
`zvfhmin`.



Comment at: clang/lib/Sema/Sema.cpp:2050
   Diag(Loc, diag::err_riscv_type_requires_extension, FD)
-  << Ty << "zvfh";
+  << Ty << "zvfh or zvfhmin";
 if (Ty->isRVVType(/* Bitwidth */ 32, /* IsFloat */ true) &&

eopXD wrote:
> We can remove `!TI.hasFeature("experimental-zvfh")` since `zvfh` will imply 
> `zvfhmin`.
`"zvfh or zvfhmin"` -> `"zvfhmin"`



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin-error.c:20
+
+// CHECK-ZVFHMIN-ERR: no matching function for call to '__riscv_vfadd'
+

eopXD wrote:
> If `zvfhmin` is not specified, should the compiler emit semantic error when 
> encountering `vfloat16*_t` types?
Sorry I missed the test case below. Please ignore this comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

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


[PATCH] D151854: [clang] Use `FileEntryRef` in modular header search (part 1/2)

2023-06-01 Thread Jan Svoboda 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 rGb092f417db21: [clang] Use `FileEntryRef` in modular header 
search (part 1/2) (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151854

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8799,7 +8799,8 @@
 
   ASTUnit  = *cxtu::getASTUnit(TU);
   HeaderSearch  = Unit.getPreprocessor().getHeaderSearchInfo();
-  ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE);
+  // TODO: Make CXFile a FileEntryRef.
+  ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE->getLastRef());
 
   return Header.getModule();
 }
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -409,29 +409,27 @@
   return Known;
 }
 
-ModuleMap::KnownHeader
-ModuleMap::findHeaderInUmbrellaDirs(const FileEntry *File,
-SmallVectorImpl ) {
+ModuleMap::KnownHeader ModuleMap::findHeaderInUmbrellaDirs(
+FileEntryRef File, SmallVectorImpl ) {
   if (UmbrellaDirs.empty())
 return {};
 
-  const DirectoryEntry *Dir = File->getDir();
-  assert(Dir && "file in no directory");
+  OptionalDirectoryEntryRef Dir = File.getDir();
 
   // Note: as an egregious but useful hack we use the real path here, because
   // frameworks moving from top-level frameworks to embedded frameworks tend
   // to be symlinked from the top-level location to the embedded location,
   // and we need to resolve lookups as if we had found the embedded location.
-  StringRef DirName = SourceMgr.getFileManager().getCanonicalName(Dir);
+  StringRef DirName = SourceMgr.getFileManager().getCanonicalName(*Dir);
 
   // Keep walking up the directory hierarchy, looking for a directory with
   // an umbrella header.
   do {
-auto KnownDir = UmbrellaDirs.find(Dir);
+auto KnownDir = UmbrellaDirs.find(*Dir);
 if (KnownDir != UmbrellaDirs.end())
   return KnownHeader(KnownDir->second, NormalHeader);
 
-IntermediateDirs.push_back(Dir);
+IntermediateDirs.push_back(*Dir);
 
 // Retrieve our parent path.
 DirName = llvm::sys::path::parent_path(DirName);
@@ -439,10 +437,7 @@
   break;
 
 // Resolve the parent path to a directory entry.
-if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName))
-  Dir = *DirEntry;
-else
-  Dir = nullptr;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
   } while (Dir);
   return {};
 }
@@ -582,7 +577,7 @@
   return false;
 }
 
-ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File,
+ModuleMap::KnownHeader ModuleMap::findModuleForHeader(FileEntryRef File,
   bool AllowTextual,
   bool AllowExcluded) {
   auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader {
@@ -612,10 +607,10 @@
 }
 
 ModuleMap::KnownHeader
-ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) {
+ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
   assert(!Headers.count(File) && "already have a module for this header");
 
-  SmallVector SkippedDirs;
+  SmallVector SkippedDirs;
   KnownHeader H = findHeaderInUmbrellaDirs(File, SkippedDirs);
   if (H) {
 Module *Result = H.getModule();
@@ -635,11 +630,11 @@
   // the actual header is located.
   bool Explicit = UmbrellaModule->InferExplicitSubmodules;
 
-  for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) {
+  for (DirectoryEntryRef SkippedDir : llvm::reverse(SkippedDirs)) {
 // Find or create the module that corresponds to this directory name.
 SmallString<32> NameBuf;
 StringRef Name = sanitizeFilenameAsIdentifier(
-llvm::sys::path::stem(SkippedDir->getName()), NameBuf);
+llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
 Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
 Explicit).first;
 InferredModuleAllowedBy[Result] = UmbrellaModuleMap;
@@ -657,7 +652,7 @@
   // Infer a submodule with the same name as this header file.
   SmallString<32> NameBuf;
   StringRef Name = sanitizeFilenameAsIdentifier(
- llvm::sys::path::stem(File->getName()), NameBuf);
+ llvm::sys::path::stem(File.getName()), NameBuf);
   Result = 

[PATCH] D112932: Use llvm.is_fpclass to implement FP classification functions

2023-06-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D112932#4005339 , @sepavloff wrote:

> Remove __builtin_isfpclass

I am interested in adding a __builtin_isfpclass, just in a separate patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112932

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


[clang] b092f41 - [clang] Use `FileEntryRef` in modular header search (part 1/2)

2023-06-01 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-06-01T10:38:07-07:00
New Revision: b092f417db211b5316bc29bc651eaaa86ce1

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

LOG: [clang] Use `FileEntryRef` in modular header search (part 1/2)

This patch removes some deprecated uses of `{File,Directory}Entry::getName()`. 
No functional change indended.

Depends on D151853.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 947fb8308908e..131dbdcc20007 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -659,7 +659,7 @@ class HeaderSearch {
   ///
   /// \param File The header that we wish to map to a module.
   /// \param AllowTextual Whether we want to find textual headers too.
-  ModuleMap::KnownHeader findModuleForHeader(const FileEntry *File,
+  ModuleMap::KnownHeader findModuleForHeader(FileEntryRef File,
  bool AllowTextual = false,
  bool AllowExcluded = false) const;
 
@@ -670,7 +670,7 @@ class HeaderSearch {
   ///
   /// \ref findModuleForHeader should typically be used instead of this.
   ArrayRef
-  findAllModulesForHeader(const FileEntry *File) const;
+  findAllModulesForHeader(FileEntryRef File) const;
 
   /// Like \ref findAllModulesForHeader, but do not attempt to infer module
   /// ownership from umbrella headers if we've not already done so.
@@ -760,8 +760,7 @@ class HeaderSearch {
   ///
   /// \return \c true if the file can be used, \c false if we are not 
permitted to
   /// find this file due to requirements from \p RequestingModule.
-  bool findUsableModuleForHeader(const FileEntry *File,
- const DirectoryEntry *Root,
+  bool findUsableModuleForHeader(FileEntryRef File, const DirectoryEntry *Root,
  Module *RequestingModule,
  ModuleMap::KnownHeader *SuggestedModule,
  bool IsSystemHeaderDir);
@@ -772,7 +771,7 @@ class HeaderSearch {
   /// \return \c true if the file can be used, \c false if we are not 
permitted to
   /// find this file due to requirements from \p RequestingModule.
   bool findUsableModuleForFrameworkHeader(
-  const FileEntry *File, StringRef FrameworkName, Module *RequestingModule,
+  FileEntryRef File, StringRef FrameworkName, Module *RequestingModule,
   ModuleMap::KnownHeader *SuggestedModule, bool IsSystemFramework);
 
   /// Look up the file with the specified name and determine its owning

diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 55797a31bbf83..83c227b38e1bb 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -364,17 +364,17 @@ class ModuleMap {
   ///
   /// \param IntermediateDirs On success, contains the set of directories
   /// searched before finding \p File.
-  KnownHeader findHeaderInUmbrellaDirs(const FileEntry *File,
-SmallVectorImpl );
+  KnownHeader findHeaderInUmbrellaDirs(
+  FileEntryRef File, SmallVectorImpl );
 
   /// Given that \p File is not in the Headers map, look it up within
   /// umbrella directories and find or create a module for it.
-  KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File);
+  KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File);
 
   /// A convenience method to determine if \p File is (possibly nested)
   /// in an umbrella directory.
-  bool isHeaderInUmbrellaDirs(const FileEntry *File) {
-SmallVector IntermediateDirs;
+  bool isHeaderInUmbrellaDirs(FileEntryRef File) {
+SmallVector IntermediateDirs;
 return static_cast(findHeaderInUmbrellaDirs(File, IntermediateDirs));
   }
 
@@ -437,8 +437,7 @@ class ModuleMap {
   /// \returns The module KnownHeader, which provides the module that owns the
   /// given header file.  The KnownHeader is default constructed to indicate
   /// that no module owns this header file.
-  KnownHeader findModuleForHeader(const FileEntry *File,
-  bool AllowTextual = false,
+  KnownHeader findModuleForHeader(FileEntryRef File, bool AllowTextual = false,
   bool AllowExcluded = false);
 
   /// Retrieve all the modules that contain the given header file. Note that
@@ -448,7 +447,7 @@ class ModuleMap {
   ///

[PATCH] D150253: [RISCV] Add Zvfhmin extension for clang.

2023-06-01 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added a comment.

Thank you for the patch. Few comments here.




Comment at: clang/include/clang/Basic/riscv_vector.td:2219
+  def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
+  let RequiredFeatures = ["ZvfhminOrZvfh"] in
+def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {

I think using `ZvfhminOrZvfh` is not accurate here. By the v-spec:

> When the Zvfhmin extension is implemented, the vfwcvt.f.f.v and vfncvt.f.f.w 
> instructions become defined when SEW=16. 
> The Zvfh extension depends on the Zve32f and Zfhmin extensions.

I think making it `let RequiredFeatures = ["Zvfhmin"]` would be clearer.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:199
+  bool HasZvfh = TI.hasFeature("experimental-zvfh");
+  bool HasZvfhminOrZvfh = TI.hasFeature("experimental-zvfhmin") || HasZvfh;
 

I think `HasZvfhmin` is a more accurate naming.



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin-error.c:20
+
+// CHECK-ZVFHMIN-ERR: no matching function for call to '__riscv_vfadd'
+

If `zvfhmin` is not specified, should the compiler emit semantic error when 
encountering `vfloat16*_t` types?



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c:15
+//
+vfloat16m1_t test_vfncvt_f_f_w_f16m1(vfloat32m2_t src, size_t vl) {
+  return __riscv_vfncvt_f(src, vl);

This test case is already covered.

https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt.c#L356


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

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


[PATCH] D151904: [clang-repl][CUDA] Add an unit test for interactive CUDA

2023-06-01 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite added inline comments.



Comment at: clang/unittests/Interpreter/InteractiveCudaTest.cpp:92
+  std::unique_ptr Interp = createInterpreter();
+  auto Err = Interp->LoadDynamicLibrary("libcudart.so");
+  if (Err) { // CUDA runtime is not installed/usable, cannot continue testing

tra wrote:
> This could be a bit of a problem.
> 
> There may be multiple CUDA SDK versions that may be installed on a system at 
> any given time and the libcudart.so you pick here may not be the one you want.
> E.g it may be from a recent CUDA version which is not supported by NVIDIA 
> drivers yet. 
> 
> I think you may need a way to let the user override CUDA SDK (or 
> libcudart.so) location explicitly. I guess they could do that via 
> LD_LIBRARY_PATH, but for the CUDA compilation in general, knowing CUDA SDK 
> path is essential, as it does affect various compilation options set by the 
> driver.
> 
Yes, this probably would be an issue. It is currently possible to override the 
CUDA path with a command line argument in clang-repl. But I am not sure what we 
can do inside a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151904

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


[PATCH] D151904: [clang-repl][CUDA] Add an unit test for interactive CUDA

2023-06-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/unittests/Interpreter/InteractiveCudaTest.cpp:92
+  std::unique_ptr Interp = createInterpreter();
+  auto Err = Interp->LoadDynamicLibrary("libcudart.so");
+  if (Err) { // CUDA runtime is not installed/usable, cannot continue testing

This could be a bit of a problem.

There may be multiple CUDA SDK versions that may be installed on a system at 
any given time and the libcudart.so you pick here may not be the one you want.
E.g it may be from a recent CUDA version which is not supported by NVIDIA 
drivers yet. 

I think you may need a way to let the user override CUDA SDK (or libcudart.so) 
location explicitly. I guess they could do that via LD_LIBRARY_PATH, but for 
the CUDA compilation in general, knowing CUDA SDK path is essential, as it does 
affect various compilation options set by the driver.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151904

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


[PATCH] D112932: Use llvm.is_fpclass to implement FP classification functions

2023-06-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D112932#4043545 , @arsenm wrote:

> This change itself LGTM but I think it should wait until after we get more 
> optimizations in to go back to fcmp, and after the release branch

I think these optimizations are mostly in a good state. I still have some 
outstanding is.fpclass codegen patches (e.g. D143201 
 and related)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112932

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


[PATCH] D151854: [clang] Use `FileEntryRef` in modular header search (part 1/2)

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 527490.
jansvoboda11 added a comment.

Remove optionality from one argument


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151854

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8799,7 +8799,8 @@
 
   ASTUnit  = *cxtu::getASTUnit(TU);
   HeaderSearch  = Unit.getPreprocessor().getHeaderSearchInfo();
-  ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE);
+  // TODO: Make CXFile a FileEntryRef.
+  ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE->getLastRef());
 
   return Header.getModule();
 }
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -409,29 +409,27 @@
   return Known;
 }
 
-ModuleMap::KnownHeader
-ModuleMap::findHeaderInUmbrellaDirs(const FileEntry *File,
-SmallVectorImpl ) {
+ModuleMap::KnownHeader ModuleMap::findHeaderInUmbrellaDirs(
+FileEntryRef File, SmallVectorImpl ) {
   if (UmbrellaDirs.empty())
 return {};
 
-  const DirectoryEntry *Dir = File->getDir();
-  assert(Dir && "file in no directory");
+  OptionalDirectoryEntryRef Dir = File.getDir();
 
   // Note: as an egregious but useful hack we use the real path here, because
   // frameworks moving from top-level frameworks to embedded frameworks tend
   // to be symlinked from the top-level location to the embedded location,
   // and we need to resolve lookups as if we had found the embedded location.
-  StringRef DirName = SourceMgr.getFileManager().getCanonicalName(Dir);
+  StringRef DirName = SourceMgr.getFileManager().getCanonicalName(*Dir);
 
   // Keep walking up the directory hierarchy, looking for a directory with
   // an umbrella header.
   do {
-auto KnownDir = UmbrellaDirs.find(Dir);
+auto KnownDir = UmbrellaDirs.find(*Dir);
 if (KnownDir != UmbrellaDirs.end())
   return KnownHeader(KnownDir->second, NormalHeader);
 
-IntermediateDirs.push_back(Dir);
+IntermediateDirs.push_back(*Dir);
 
 // Retrieve our parent path.
 DirName = llvm::sys::path::parent_path(DirName);
@@ -439,10 +437,7 @@
   break;
 
 // Resolve the parent path to a directory entry.
-if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName))
-  Dir = *DirEntry;
-else
-  Dir = nullptr;
+Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
   } while (Dir);
   return {};
 }
@@ -582,7 +577,7 @@
   return false;
 }
 
-ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File,
+ModuleMap::KnownHeader ModuleMap::findModuleForHeader(FileEntryRef File,
   bool AllowTextual,
   bool AllowExcluded) {
   auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader {
@@ -612,10 +607,10 @@
 }
 
 ModuleMap::KnownHeader
-ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) {
+ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
   assert(!Headers.count(File) && "already have a module for this header");
 
-  SmallVector SkippedDirs;
+  SmallVector SkippedDirs;
   KnownHeader H = findHeaderInUmbrellaDirs(File, SkippedDirs);
   if (H) {
 Module *Result = H.getModule();
@@ -635,11 +630,11 @@
   // the actual header is located.
   bool Explicit = UmbrellaModule->InferExplicitSubmodules;
 
-  for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) {
+  for (DirectoryEntryRef SkippedDir : llvm::reverse(SkippedDirs)) {
 // Find or create the module that corresponds to this directory name.
 SmallString<32> NameBuf;
 StringRef Name = sanitizeFilenameAsIdentifier(
-llvm::sys::path::stem(SkippedDir->getName()), NameBuf);
+llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
 Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
 Explicit).first;
 InferredModuleAllowedBy[Result] = UmbrellaModuleMap;
@@ -657,7 +652,7 @@
   // Infer a submodule with the same name as this header file.
   SmallString<32> NameBuf;
   StringRef Name = sanitizeFilenameAsIdentifier(
- llvm::sys::path::stem(File->getName()), NameBuf);
+ llvm::sys::path::stem(File.getName()), NameBuf);
   Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
   Explicit).first;
   InferredModuleAllowedBy[Result] = 

[PATCH] D151854: [clang] Use `FileEntryRef` in modular header search (part 1/2)

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Lex/HeaderSearch.h:763
   /// find this file due to requirements from \p RequestingModule.
-  bool findUsableModuleForHeader(const FileEntry *File,
+  bool findUsableModuleForHeader(OptionalFileEntryRef File,
  const DirectoryEntry *Root,

jansvoboda11 wrote:
> benlangmuir wrote:
> > This should probably be non-Optional. I can't find any calls to this API 
> > that can pass null, they all pass something that is already being 
> > dereferenced.
> You're right, thanks. Fixed in the committed version.
*In the new revision, rather.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151854

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


[PATCH] D151854: [clang] Use `FileEntryRef` in modular header search (part 1/2)

2023-06-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Lex/HeaderSearch.h:763
   /// find this file due to requirements from \p RequestingModule.
-  bool findUsableModuleForHeader(const FileEntry *File,
+  bool findUsableModuleForHeader(OptionalFileEntryRef File,
  const DirectoryEntry *Root,

benlangmuir wrote:
> This should probably be non-Optional. I can't find any calls to this API that 
> can pass null, they all pass something that is already being dereferenced.
You're right, thanks. Fixed in the committed version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151854

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


[PATCH] D151761: clang-format: Add AlignConsecutiveShortCaseLabels

2023-06-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:790
+
+**AlignConsecutiveShortCaseLabels** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 17` :ref:`¶ `
+  Style of aligning consecutive short case labels.

galenelias wrote:
> MyDeveloperDay wrote:
> > Did you generate this by hand or run the dump_format_style.py function? 
> > Format.h and the rst look out of sync
> This was generated from dump_format_style.py.  What looks out of sync?  My 
> guess is the confusing thing is all the styles which use 
> `AlignConsecutiveStyle` get the same documentation pasted for them which 
> specifically references `AlignConsecutiveMacros` and makes it look like it's 
> for the wrong option.
that doesn't feel right to me.. not saying its not dump_format_style.py but it 
shouldn't do that in my view


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151761

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


[PATCH] D151867: [Clang][RISCV] Make generic clz/ctz builtins defined for zero on RISCV targets.

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

Doesn't this make codegen worse on when those extensions aren't supported?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151867

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


[PATCH] D151904: [clang-repl][CUDA] Add an unit test for interactive CUDA

2023-06-01 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite created this revision.
argentite added a reviewer: v.g.vassilev.
Herald added subscribers: mattd, carlosgalvezp, yaxunl.
Herald added a project: All.
argentite requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This tests interactive CUDA support in clang interpreter and should pass
in case CUDA runtime is not available or no GPUs are available.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151904

Files:
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InteractiveCudaTest.cpp

Index: clang/unittests/Interpreter/InteractiveCudaTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/InteractiveCudaTest.cpp
@@ -0,0 +1,142 @@
+//===- unittests/Interpreter/CudaTest.cpp --- Interactive CUDA tests --===//
+//
+// 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
+//
+//===--===//
+//
+// Unit tests for interactive CUDA in Clang interpreter
+//
+//===--===//
+
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+
+#include "llvm/Support/TargetSelect.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+std::string MakeResourcesPath() {
+  using namespace llvm;
+#ifdef LLVM_BINARY_DIR
+  StringRef Dir = LLVM_BINARY_DIR;
+#else
+  // Dir is bin/ or lib/, depending on where BinaryPath is.
+  void *MainAddr = (void *)(intptr_t)MakeResourcesPath;
+  std::string BinaryPath =
+  llvm::sys::fs::getMainExecutable(/*Argv0=*/nullptr, MainAddr);
+
+  // build/tools/clang/unittests/Interpreter/Executable -> build/
+  StringRef Dir = sys::path::parent_path(BinaryPath);
+
+  Dir = sys::path::parent_path(Dir);
+  Dir = sys::path::parent_path(Dir);
+  Dir = sys::path::parent_path(Dir);
+  Dir = sys::path::parent_path(Dir);
+#endif // LLVM_BINARY_DIR
+  SmallString<128> P(Dir);
+  sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
+CLANG_VERSION_MAJOR_STRING);
+  return P.str().str();
+}
+
+static std::unique_ptr
+createInterpreter(const std::vector  = {}) {
+  static bool firstrun = true;
+  if (firstrun) {
+llvm::InitializeAllTargetInfos();
+llvm::InitializeAllTargets();
+llvm::InitializeAllTargetMCs();
+llvm::InitializeAllAsmPrinters();
+
+firstrun = false;
+  }
+
+  clang::IncrementalCompilerBuilder CB;
+
+  // Help find cuda's runtime headers.
+  std::string ResourceDir = MakeResourcesPath();
+
+  std::vector Args = {"-resource-dir", ResourceDir.c_str(), "-std=c++20"};
+  Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end());
+  CB.SetCompilerArgs(Args);
+
+  // Create the device code compiler
+  std::unique_ptr DeviceCI;
+  CB.SetOffloadArch("sm_35");
+  DeviceCI = cantFail(CB.CreateCudaDevice());
+
+  std::unique_ptr CI;
+  CI = cantFail(CB.CreateCudaHost());
+
+  auto Interp = cantFail(
+  clang::Interpreter::createWithCUDA(std::move(CI), std::move(DeviceCI)));
+
+  return Interp;
+}
+
+enum {
+  // Defined in CUDA Runtime API
+  cudaErrorNoDevice = 100,
+};
+
+TEST(InteractiveCudaTest, Sanity) {
+  std::unique_ptr Interp = createInterpreter();
+  auto Err = Interp->LoadDynamicLibrary("libcudart.so");
+  if (Err) { // CUDA runtime is not installed/usable, cannot continue testing
+consumeError(std::move(Err));
+return;
+  }
+
+  // Check if we have any GPU for test
+  int CudaError = 0;
+  auto GpuCheckCommand = std::string(R"(
+int device_id = -1;
+int *error = (int *))" + std::to_string((uintptr_t)) +
+ R"(;
+*error = cudaGetDevice(_id);
+  )");
+  cantFail(Interp->ParseAndExecute(GpuCheckCommand));
+  if (CudaError == cudaErrorNoDevice) {
+// No GPU is available on this machine, cannot continue testing
+return;
+  }
+  ASSERT_EQ(CudaError, 0);
+
+  int HostSum = 0;
+  auto Command1 = std::string(R"(
+__host__ __device__ inline int sum(int a, int b){ return a + b; }
+__global__ void kernel(int * output){ *output = sum(40,2); }
+int *hostsum = (int *) )") +
+  std::to_string((uintptr_t)) +
+  R"(;
+*hostsum = sum(41,1);)";
+  cantFail(Interp->ParseAndExecute(Command1));
+
+  int DeviceSum = 0;
+  auto Command2 = std::string(R"(
+int *devicesum = (int *))" +
+  std::to_string((uintptr_t)) +
+  R"(;
+int *deviceVar;
+*error |= cudaMalloc((void **) , sizeof(int));
+kernel<<<1,1>>>(deviceVar);
+*error |= cudaGetLastError();
+*error |= cudaMemcpy(devicesum, deviceVar, sizeof(int), 

[clang] 82b5a93 - Revert "[Fuchsia] Add llvm-debuginfod to toolchain"

2023-06-01 Thread Haowei Wu via cfe-commits

Author: Haowei Wu
Date: 2023-06-01T10:20:17-07:00
New Revision: 82b5a934b8e535d531b204af13775a820010c9be

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

LOG: Revert "[Fuchsia] Add llvm-debuginfod to toolchain"

This reverts commit 731f9ac6e53611dabb51c52bfc8011c2aab7790b.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 78c123f191305..8f5aa21be6fb8 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -296,7 +296,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-ar
   llvm-cov
   llvm-cxxfilt
-  llvm-debuginfod
   llvm-debuginfod-find
   llvm-dlltool
   ${LLVM_DRIVER_TARGET}



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


  1   2   3   >