[PATCH] D141811: [clang-format] Allow trailing return types in macros

2023-01-18 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

I suppose this means `auto a = (b) -> c;` is also technically broken, actually, 
and there's no easy fix for that.

I did have an idea for adding an additional pass taking place somewhere in 
`TokenAnnotator::calculateFormattingInformation`, which would detect trailing 
return types using a bit more context, as a potential fix for 
https://github.com/llvm/llvm-project/issues/41495. I suppose I could make that 
theoretically replace all of this AutoFound logic. I should actually try to see 
if my idea would work at all though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141811

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


[PATCH] D141908: [C++20][Modules] Handle defaulted and deleted functions in header units.

2023-01-18 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 490383.
iains added a comment.

rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141908

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/module/module.import/p6.cpp


Index: clang/test/CXX/module/module.import/p6.cpp
===
--- clang/test/CXX/module/module.import/p6.cpp
+++ clang/test/CXX/module/module.import/p6.cpp
@@ -28,3 +28,11 @@
 static const int value = 43; 
 };
 
+void deleted_fn_ok (void) = delete;
+
+struct S {
+   ~S() noexcept(false) = default;
+private:
+  S(S&);
+};
+S::S(S&) = default;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15254,9 +15254,15 @@
   }
 
   // C++ [module.import/6] external definitions are not permitted in header
-  // units.
+  // units.  Deleted and Defaulted functions are implicitly inline (but the
+  // inline state is not set at this point, so check the BodyKind explicitly).
+  // FIXME: Consider an alternate location for the test where the inlined()
+  // state is complete.
   if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
-  FD->getFormalLinkage() == Linkage::ExternalLinkage && !FD->isInlined()) {
+  FD->getFormalLinkage() == Linkage::ExternalLinkage &&
+  !FD->isInvalidDecl() && BodyKind != FnBodyKind::Delete &&
+  BodyKind != FnBodyKind::Default && !FD->isInlined()) {
+assert(FD->isThisDeclarationADefinition());
 Diag(FD->getLocation(), diag::err_extern_def_in_header_unit);
 FD->setInvalidDecl();
   }


Index: clang/test/CXX/module/module.import/p6.cpp
===
--- clang/test/CXX/module/module.import/p6.cpp
+++ clang/test/CXX/module/module.import/p6.cpp
@@ -28,3 +28,11 @@
 static const int value = 43; 
 };
 
+void deleted_fn_ok (void) = delete;
+
+struct S {
+   ~S() noexcept(false) = default;
+private:
+  S(S&);
+};
+S::S(S&) = default;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15254,9 +15254,15 @@
   }
 
   // C++ [module.import/6] external definitions are not permitted in header
-  // units.
+  // units.  Deleted and Defaulted functions are implicitly inline (but the
+  // inline state is not set at this point, so check the BodyKind explicitly).
+  // FIXME: Consider an alternate location for the test where the inlined()
+  // state is complete.
   if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
-  FD->getFormalLinkage() == Linkage::ExternalLinkage && !FD->isInlined()) {
+  FD->getFormalLinkage() == Linkage::ExternalLinkage &&
+  !FD->isInvalidDecl() && BodyKind != FnBodyKind::Delete &&
+  BodyKind != FnBodyKind::Default && !FD->isInlined()) {
+assert(FD->isThisDeclarationADefinition());
 Diag(FD->getLocation(), diag::err_extern_def_in_header_unit);
 FD->setInvalidDecl();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141811: [clang-format] Allow trailing return types in macros

2023-01-18 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel planned changes to this revision.
rymiel added a comment.

In D141811#4055485 , 
@HazardyKnusperkeks wrote:

> What about `decltype(auto)`?

Turns out this is a problem even without this patch:

`decltype(auto) a = (b) -> c;`

I'm sure this could somehow be valid c++ syntax, but it does have to be at the 
top scope. I suppose I could fix it in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141811

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


[PATCH] D142046: [BPF][clang] Ignore stack protector options for BPF target

2023-01-18 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@compnerd  could you also take a look at this patch?

First, some background about this patch. The reason of this patch is due to:

  
https://lore.kernel.org/bpf/CAOFdcFPnHEc2qd-=c+hdk4ntjjfbhsf4r-g7pdjtrbat6mu...@mail.gmail.com/

Further the following link has details about hardened gentoo and modified clang 
default flags:

  https://wiki.gentoo.org/wiki/Hardened_Gentoo

Unfortunately, we don't want -fstack-protector for bpf target as bpf kernel 
verifier will do stack verification.
This patch tries to ignore -fstack-protector. NVPTX arch has the same need of 
ignoring -fstack-protector.
This patch presented a different message than NVPTX. This patch:

  clang-16: warning: ignoring '-fstack-protector' option as it is not currently 
supported for target 'bpf' [-Woption-ignored]

NVPTX

  clang-16: warning: argument unused during compilation: '-fstack-protector' 
[-Wunused-command-line-argument]

Does clang community has a preference for the above two formats?

Let us say we do implement this patch and merged into clang, then using gentoo 
clang compiler, we will hit
the warning:

  clang-16: warning: ignoring '-fstack-protector' option as it is not currently 
supported for target 'bpf' [-Woption-ignored]

I suspect gentoo community might complain. I don't think we should add 
-Wno-option-ignored since this may cause
unintended issues with compiler command line arguments. 
Without -Wno-option-ignored, gentoo community might wants to append 
-fno-stack-protector to disable stack-protector,
but with the current implementation, we might actually trigger another warning.

So we have to two choices here for bpf target:

  (1). ignore any stack-protector option and do not issue any warning, or
  (2). append -fno-stack-protector by clang to compilation flags.

We can document this behavior in related clang (and kernel) docs.

WDYT?

WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142046

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


[PATCH] D142075: [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target offloading for NVPTX

2023-01-18 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 490375.
tianshilei1992 added a comment.

fix comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142075

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/OpenMP/float16_sema.cpp


Index: clang/test/OpenMP/float16_sema.cpp
===
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -943,9 +943,13 @@
 
   // CUDA host and device may have different _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
+  // When we compile for OpenMP target offloading on NVPTX, f16 suffix
+  // should also be supported.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  // TODO: AMDGPU might also support it in the future.
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;


Index: clang/test/OpenMP/float16_sema.cpp
===
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -943,9 +943,13 @@
 
   // CUDA host and device may have different _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
+  // When we compile for OpenMP target offloading on NVPTX, f16 suffix
+  // should also be supported.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  // TODO: AMDGPU might also support it in the future.
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-01-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: JDevlieghere, aprantl.
dblaikie added a comment.

In D141451#4063582 , @nickdesaulniers 
wrote:

> In D141451#4063519 , @dblaikie 
> wrote:
>
>> In D141451#4063504 , 
>> @nickdesaulniers wrote:
>>
>>> In D141451#4063335 , @dblaikie 
>>> wrote:
>>>
 In D141451#4063151 , 
 @nickdesaulniers wrote:

> In D141451#4045658 , @efriedma 
> wrote:
>
>> clang has a "LocTrackingOnly" setting for debug info, which emits 
>> DILocation info into the IR, but emits a marker into the DICompileUnit 
>> to skip emitting the .debug_info in the backend.  We currently use it 
>> for -Rpass.  We don't do this by default, I think to save compile time.
>
> Specifically `emissionKind: NoDebug`, example:
>
> `!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: 
> "clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
> 7b433e026498cf4176931b2407baece1d5060e16)", isOptimized: true, 
> runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, 
> nameTableKind: None)`
>
> Though should the frontend be setting codegen options when parsing? Would 
> the idea be to try to re-set `OPT_debug_info_kind_EQ` when clang 
> codegen's IR for a function with such an attribute?

 Probably turn on `emissionKind: NoDebug` whenever the warning is enabled?
>>>
>>> So this warning is default enabled, IIRC.
>>
>> Then it might be a broader question about whether this extra info is 
>> acceptable to turn on by default, and if not, maybe an extra flag would be 
>> needed to say "give me extra info in this diagnostic", basically (or a 
>> separate warning flag that's off by default) - some perf metrics might help 
>> indicate whether the extra info is cheap enough.
>
> The implementation as it stands is zero cost in the sense that if 
> `__attribute__((warning("")))` or `__attribute__((error("")))` aren't used in 
> the source code, there is ZERO cost in IR.  Additional metadata is only 
> created when inlining occurs (which might not happen if optimizations weren't 
> enabled) where callsites to such functions exist (unlikely), and if the call 
> site is optimized away, the metadata should be deleted (at least, I imagine 
> that's how metadata works in LLVM.  I should actually verify that's the case, 
> then probably add such verification as a test to this patch, perhaps.
>
>> I'm still a bit confused/not following about the "Let me see if I can create 
>> DILocation without line or column values." - why do you want to create that?
>
> You're the one that asked  if if I 
> can reuse existing metadata nodes, specifically:
>
>>> It'd be nice not to invent a new way of tracking inlining separate from the 
>>> way debug info does this

Right - I was thinking more, as above, about directly using the existing 
metadata generation (if it's too expensive to enable by default, then possibly 
under an off-by-default warning or other flag) that the inliner already knows 
how to read and write, rather than creating new/different metadata handling.

Perhaps there's already logic for enabling this for remarks 
(CompilerInvocation.cpp:~2019).

Though it's possibly a path forward to generate new DILocations in the absence 
of any - it's not the top of my list reach for here, but that's just my 2c. 
Perhaps other folks have other ideas.

It's possible that this approach might be able to fill a gap we sometimes have 
in debug info, though - where a call site lacks a DILocation and that makes 
creating the inline debug info difficult/impossible at the moment (there's a 
whole long history of this issue, the assertions and verifier checks we've 
implemented to detect it, and the bugs (frontend missing opportunities to emit 
useful DILocations) it has found/lead to being fixed, though - so I'm somewhat 
hesitant to make us more permissive on constructing debug info inlining for 
call sites without DILocations). (@aprantl @JDevlieghere perhaps you folks have 
thoughts on this?)

> So I could emit DILocation and DISubprogram metadata rather than the custom 
> metadata nodes as I'm doing in this diff.  I just wouldn't be able to 
> synthesize line or column info for the callsites, since the frontend may not 
> have ever produced it in the first place.  Such an approach would be emitting 
> `DILocation`+`DISubprogram` from the backend, not the frontend; the backend 
> doesn't have line+column info unless debugging was enabled in the first place 
> (which it probably wasn't).
>
> I don't want to pessimistically emit these always from the frontend with 
> precise line+column info. That would be so pessimistic for the common case 
> 

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

2023-01-18 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

This broke our mac builds with errors like:

  ld64.lld: error: undefined symbol: CFRunLoopRun
  >>> referenced by 
tools/clang/tools/clang-stat-cache/CMakeFiles/clang-stat-cache.dir/clang-stat-cache.cpp.o:(symbol
 main+0x11be)

(and many more symbols)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D71734: [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches.

2023-01-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai marked an inline comment as done.
vsapsai added a comment.

In D71734#4061228 , @ChuanqiXu wrote:

> LGTM generally. It'd better to mention this in the `Potentially Breaking 
> Changes` section of ReleaseNotes.

Thanks for all your efforts during the review! Mentioned the change in the 
release notes.




Comment at: clang/lib/AST/Decl.cpp:4714
   setIsRandomized(false);
+  RecordDeclBits.ODRHash = 0;
 }

ChuanqiXu wrote:
> nit: setODRHash(0) may be more consistent with above style.
You are right, changed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Kazu Hirata via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
kazu marked 2 inline comments as done.
Closed by commit rG83d56fb17a4d: Drop the ZeroBehavior parameter from 
countLeadingZeros and the like (NFC) (authored by kazu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

Files:
  llvm/include/llvm/Support/MathExtras.h
  llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Index: mlir/lib/Bytecode/Reader/BytecodeReader.cpp
===
--- mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -281,8 +281,7 @@
 // here because we only care about the first byte, and so that be actually
 // get ctz intrinsic calls when possible (the `uint8_t` overload uses a loop
 // implementation).
-uint32_t numBytes =
-llvm::countTrailingZeros(result, llvm::ZB_Undefined);
+uint32_t numBytes = llvm::countTrailingZeros(result);
 assert(numBytes > 0 && numBytes <= 7 &&
"unexpected number of trailing zeros in varint encoding");
 
Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -259,8 +259,7 @@
 if (I < B.size())
   BitsUsed |= B[I];
   if (BitsUsed != 0xff)
-return (MinByte + I) * 8 +
-   countTrailingZeros(uint8_t(~BitsUsed), ZB_Undefined);
+return (MinByte + I) * 8 + countTrailingZeros(uint8_t(~BitsUsed));
 }
   } else {
 // Find a free (Size/8) byte region in each member of Used.
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -172,7 +172,7 @@
 
   BSI.AlignLog2 = 0;
   if (Mask != 0)
-BSI.AlignLog2 = countTrailingZeros(Mask, ZB_Undefined);
+BSI.AlignLog2 = countTrailingZeros(Mask);
 
   // Build the compressed bitset while normalizing the offsets against the
   // computed alignment.
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -180,7 +180,7 @@
   // or ADDIW. If there are trailing zeros, try generating a sign extended
   // constant with no trailing zeros and use a final SLLI to restore them.
   if ((Val & 0xfff) != 0 && (Val & 1) == 0 && Res.size() >= 2) {
-unsigned TrailingZeros = countTrailingZeros((uint64_t)Val, ZB_Undefined);
+unsigned TrailingZeros = countTrailingZeros((uint64_t)Val);
 int64_t ShiftedVal = Val >> TrailingZeros;
 // If we can use C.LI+C.SLLI instead of LUI+ADDI(W) prefer that since
 // its more compressible. But only if LUI+ADDI(W) isn't fusable.
@@ -202,7 +202,7 @@
   if (Val > 0 && Res.size() > 2) {
 assert(ActiveFeatures[RISCV::Feature64Bit] &&
"Expected RV32 to only need 2 instructions");
-unsigned LeadingZeros = countLeadingZeros((uint64_t)Val, ZB_Undefined);
+unsigned LeadingZeros = countLeadingZeros((uint64_t)Val);
 uint64_t ShiftedVal = (uint64_t)Val << LeadingZeros;
 // Fill in the bits that will be shifted out with 1s. An example where this
 // helps is trailing one masks with 32 or more ones. This will generate
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -2451,8 +2451,7 @@
   unsigned PsInputBits = Info->getPSInputAddr() & Info->getPSInputEnable();
   if ((PsInputBits & 0x7F) == 0 ||
   ((PsInputBits & 0xF) == 0 && (PsInputBits >> 11 & 1)))
-Info->markPSInputEnabled(
-countTrailingZeros(Info->getPSInputAddr(), ZB_Undefined));
+Info->markPSInputEnabled(countTrailingZeros(Info->getPSInputAddr()));
 }
   } else if (IsKernel) {
 assert(Info->hasWorkGroupIDX() && Info->hasWorkItemIDX());
Index: llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
@@ -701,8 +701,7 @@
   if ((PsInputBits & 0x7F) == 0 ||
   ((PsInputBits & 0xF) == 0 &&
(PsInputBits >> 11 & 1)))
-Info->markPSInputEnabled(
-  

[PATCH] D142077: [Clang][SemaCXX][Coroutines] Fix misleading diagnostics with -Wunsequenced

2023-01-18 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno created this revision.
bruno added reviewers: ChuanqiXu, nridge, sammccall.
Herald added subscribers: hoy, modimo, wenlei.
Herald added a project: All.
bruno requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

D115187  exposed CoroutineSuspendExpr's 
operand, which makes some nodes to show up twice during the traversal, 
confusing the check for unsequenced operations. Skip the operand since it's 
already handled as part of the common expression and get rid of the misleading 
warnings.

https://github.com/llvm/llvm-project/issues/56768


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142077

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/warn-unsequenced-coro.cpp

Index: clang/test/SemaCXX/warn-unsequenced-coro.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsequenced-coro.cpp
@@ -0,0 +1,144 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify -std=c++20 -Wno-unused -Wno-uninitialized -Wunsequenced %s
+
+// expected-no-diagnostics
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+namespace std {
+
+template struct remove_reference   { typedef T type; };
+template struct remove_reference  { typedef T type; };
+template struct remove_reference { typedef T type; };
+
+template
+typename remove_reference::type &(T &) noexcept;
+
+template 
+struct coroutine_traits { using promise_type = typename Ret::promise_type; };
+
+template 
+struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  static coroutine_handle from_promise(Promise );
+};
+template <>
+struct coroutine_handle {
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+  static coroutine_handle from_address(void *);
+};
+
+struct suspend_always {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
+struct suspend_never {
+  bool await_ready() noexcept { return true; }
+  void await_suspend(coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
+struct input_iterator_tag {};
+struct forward_iterator_tag : public input_iterator_tag {};
+
+} // namespace std
+
+using namespace std;
+
+template
+struct Task {
+struct promise_type {
+Task get_return_object() noexcept;
+suspend_always initial_suspend() noexcept;
+suspend_always final_suspend() noexcept;
+void return_value(T);
+void unhandled_exception();
+auto yield_value(Task) noexcept { return final_suspend(); }
+};
+bool await_ready() noexcept { return false; }
+void await_suspend(coroutine_handle<>) noexcept {}
+T await_resume();
+};
+
+template<>
+struct Task {
+struct promise_type {
+Task get_return_object() noexcept;
+suspend_always initial_suspend() noexcept;
+suspend_always final_suspend() noexcept;
+void return_void() noexcept;
+void unhandled_exception() noexcept;
+auto yield_value(Task) noexcept { return final_suspend(); }
+};
+bool await_ready() noexcept { return false; }
+void await_suspend(coroutine_handle<>) noexcept {}
+void await_resume() noexcept {}
+};
+
+template 
+class generator
+{
+  struct Promise
+  {
+auto get_return_object() { return generator{*this}; }
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() noexcept { return suspend_always{}; }
+void unhandled_exception() {}
+void return_void() {}
+
+auto yield_value(T value)
+{
+  value_ = std::move(value);
+  return suspend_always{};
+}
+
+T value_;
+  };
+
+  using Handle = coroutine_handle;
+
+  struct sentinel{};
+  struct iterator
+  {
+using iterator_category = input_iterator_tag;
+using value_type = T;
+using difference_type = ptrdiff_t;
+using reference = T &;
+using const_reference = const T &;
+using pointer = T *;
+
+iterator ++()
+{
+  h_.resume();
+  return *this;
+}
+const_reference *() const { return h_.promise().value_; }
+bool operator!=(sentinel) { return !h_.done(); }
+
+Handle h_;
+  };
+
+  explicit generator(Promise ) : h_(Handle::from_promise(p)) {}
+  Handle h_;
+public:
+  using promise_type = Promise;
+  auto begin() { return iterator{h_}; }
+  auto end() { return sentinel{}; }
+};
+
+Task c(int i) {
+  co_await (i = 0, std::suspend_always{});
+}
+
+generator range(int start, int end)
+{
+  while (start < end)
+co_yield start++;
+}
+
+Task go(int const& val);
+Task go1(int x) {
+  co_return co_await go(++x);
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15176,6 +15176,23 @@
 Base::VisitStmt(E);
   }
 
+  void 

[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Kazu Hirata via Phabricator via cfe-commits
kazu marked an inline comment as done.
kazu added inline comments.



Comment at: llvm/include/llvm/Support/MathExtras.h:225
 ///
 /// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are
 ///   valid arguments.

jrtc27 wrote:
> A bunch of functions still have this documentation, but these are now the 
> only possible values, so this seems redundant
I've adjusted the redundant comments on two functions - `findFirstSet` and 
`findLastSet`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Kazu Hirata via Phabricator via cfe-commits
kazu updated this revision to Diff 490363.
kazu added a comment.

I've adjusted comments for findFirstSet and findLastSet to reflect the
fact that ZeroBehavior now takes only two values -- ZB_Undefined and
ZB_Max.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

Files:
  llvm/include/llvm/Support/MathExtras.h
  llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Index: mlir/lib/Bytecode/Reader/BytecodeReader.cpp
===
--- mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -281,8 +281,7 @@
 // here because we only care about the first byte, and so that be actually
 // get ctz intrinsic calls when possible (the `uint8_t` overload uses a loop
 // implementation).
-uint32_t numBytes =
-llvm::countTrailingZeros(result, llvm::ZB_Undefined);
+uint32_t numBytes = llvm::countTrailingZeros(result);
 assert(numBytes > 0 && numBytes <= 7 &&
"unexpected number of trailing zeros in varint encoding");
 
Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -259,8 +259,7 @@
 if (I < B.size())
   BitsUsed |= B[I];
   if (BitsUsed != 0xff)
-return (MinByte + I) * 8 +
-   countTrailingZeros(uint8_t(~BitsUsed), ZB_Undefined);
+return (MinByte + I) * 8 + countTrailingZeros(uint8_t(~BitsUsed));
 }
   } else {
 // Find a free (Size/8) byte region in each member of Used.
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -172,7 +172,7 @@
 
   BSI.AlignLog2 = 0;
   if (Mask != 0)
-BSI.AlignLog2 = countTrailingZeros(Mask, ZB_Undefined);
+BSI.AlignLog2 = countTrailingZeros(Mask);
 
   // Build the compressed bitset while normalizing the offsets against the
   // computed alignment.
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -180,7 +180,7 @@
   // or ADDIW. If there are trailing zeros, try generating a sign extended
   // constant with no trailing zeros and use a final SLLI to restore them.
   if ((Val & 0xfff) != 0 && (Val & 1) == 0 && Res.size() >= 2) {
-unsigned TrailingZeros = countTrailingZeros((uint64_t)Val, ZB_Undefined);
+unsigned TrailingZeros = countTrailingZeros((uint64_t)Val);
 int64_t ShiftedVal = Val >> TrailingZeros;
 // If we can use C.LI+C.SLLI instead of LUI+ADDI(W) prefer that since
 // its more compressible. But only if LUI+ADDI(W) isn't fusable.
@@ -202,7 +202,7 @@
   if (Val > 0 && Res.size() > 2) {
 assert(ActiveFeatures[RISCV::Feature64Bit] &&
"Expected RV32 to only need 2 instructions");
-unsigned LeadingZeros = countLeadingZeros((uint64_t)Val, ZB_Undefined);
+unsigned LeadingZeros = countLeadingZeros((uint64_t)Val);
 uint64_t ShiftedVal = (uint64_t)Val << LeadingZeros;
 // Fill in the bits that will be shifted out with 1s. An example where this
 // helps is trailing one masks with 32 or more ones. This will generate
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -2451,8 +2451,7 @@
   unsigned PsInputBits = Info->getPSInputAddr() & Info->getPSInputEnable();
   if ((PsInputBits & 0x7F) == 0 ||
   ((PsInputBits & 0xF) == 0 && (PsInputBits >> 11 & 1)))
-Info->markPSInputEnabled(
-countTrailingZeros(Info->getPSInputAddr(), ZB_Undefined));
+Info->markPSInputEnabled(countTrailingZeros(Info->getPSInputAddr()));
 }
   } else if (IsKernel) {
 assert(Info->hasWorkGroupIDX() && Info->hasWorkItemIDX());
Index: llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
@@ -701,8 +701,7 @@
   if ((PsInputBits & 0x7F) == 0 ||
   ((PsInputBits & 0xF) == 0 &&
(PsInputBits >> 11 & 1)))
-Info->markPSInputEnabled(
-  countTrailingZeros(Info->getPSInputAddr(), ZB_Undefined));
+

[PATCH] D142075: [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target offloading for NVPTX

2023-01-18 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

Seems reasonable, maybe update the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142075

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

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

In D141798#4064142 , @MaskRay wrote:

> `ZB_Max` is the strange mode that should be dropped, perhaps also 
> `ZB_Undefined`.
>
> In D141798#4064114 , @arsenm wrote:
>
>>> If you care about compilation speed, you should build LLVM with an 
>>> appropriate -march= to take advantage of lzcnt and tzcnt.
>>
>> I think this is bad reasoning, nobody really uses -march
>
> I agree. The reason should be clarified that the lzcnt performance here 
> really doesn't matter.
> Note: 
> https://stackoverflow.com/questions/21390165/why-does-breaking-the-output-dependency-of-lzcnt-matter
>  lzcnt/tzcnt have false dependencies on older (pre-Skylake) Intel processors. 
> But this doesn't really matter for LLVM, at least the minor issue does not 
> justify keeping the weird mode `ZB_Undefined`.

I'm not sure the false dependency issue is relevant here. Without -march, 
compilers will emit BSR/BSF and possibly a cmov to handle the zero behavior. 
Both BSR/BSF always have a false dependency because the behavior for 0 input is 
to keep the old value of the output register. Knowing we can use lzcnt/tzcnt is 
always better than BSR/BSF.

If we know zero doesn't matter, without march, gcc and recent clang will always 
emit BSF using the encoding for TZCNT. On CPUs without TZCNT this encoding is 
treated as BSF. This allows us to use TZCNT at runtime if the CPU is modern 
even without -march being passed. We can't do the same for BSF/LZCNT because 
their outputs are inverted from each other.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141954: Forbid implicit conversion of constraint expression to bool

2023-01-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:377-380
+  SubstitutedExpression = ImplicitCastExpr::Create(
+  S.Context, SubstitutedExpression.get()->getType(),
+  CK_LValueToRValue, SubstitutedExpression.get(),
+  /*BasePath=*/nullptr, VK_PRValue, FPOptionsOverride());

tahonermann wrote:
> erichkeane wrote:
> > tahonermann wrote:
> > > `ImplicitCastExpr::Create()` has the following assertion. I wonder if we 
> > > need to guard against this here.
> > >   clang/lib/AST/Expr.cpp:
> > >   2073   assert((Kind != CK_LValueToRValue ||
> > >   2074   !(T->isNullPtrType() || T->getAsCXXRecordDecl())) &&
> > >   2075  "invalid type for lvalue-to-rvalue conversion");
> > > 
> > > Or perhaps it would be better to call `Sema::DefaultLvalueConversion()` 
> > > here?
> > I don't think we want all the baggage that DefaultLvalueConversion gets us, 
> > including diagnostics/etc.  That assert IS concerning though... I presume 
> > we can come up with something to hit that. 
> > 
> > It DOES look like that DefeaultLValue conversion replaces the nullptrtypes 
> > with a NullToPointer cast, so perhaps I should do that, and doesn't do 
> > anything with a record type.
> I'm surprised the additional checks for `nullptr` aren't tripping that 
> assert; it looks to me like it should. Any ideas?
I moved the creation of this AFTER 'CheckConstraintExpression', which will fail 
unless the type is 'bool' already.  SO the expression here cannot be a nullptr 
or struct type.  Before I moved it and wrote the new tests (NullTy and 
StructTy), it actually did hit the assert you mentioned.


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

https://reviews.llvm.org/D141954

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


[PATCH] D142075: [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target offloading for NVPTX

2023-01-18 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, jhuber6, yaxunl, rjmccall, tra.
Herald added subscribers: mattd, gchakrabarti, asavonic, guansong.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Fix #58087.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142075

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/OpenMP/float16_sema.cpp


Index: clang/test/OpenMP/float16_sema.cpp
===
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -944,8 +944,9 @@
   // CUDA host and device may have different _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;


Index: clang/test/OpenMP/float16_sema.cpp
===
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -944,8 +944,9 @@
   // CUDA host and device may have different _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

`ZB_Max` is the strange mode that should be dropped, perhaps also 
`ZB_Undefined`.

In D141798#4064114 , @arsenm wrote:

>> If you care about compilation speed, you should build LLVM with an 
>> appropriate -march= to take advantage of lzcnt and tzcnt.
>
> I think this is bad reasoning, nobody really uses -march

I agree. The reason should be clarified that the lzcnt performance here really 
doesn't matter.
Note: 
https://stackoverflow.com/questions/21390165/why-does-breaking-the-output-dependency-of-lzcnt-matter
 lzcnt/tzcnt have false dependencies on older (pre-Skylake) Intel processors. 
But this doesn't really matter for LLVM, at least the minor issue does not 
justify keeping the weird mode `ZB_Undefined`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-18 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski added a comment.

Are those failures on Linux? I only developed this change on macOS, but the 
automated tests passed...

Admittedly I'm not sure what should happen when building for macOS from Linux 
(is there any use case where that works and does anything useful? I'm not 
sure).  I was under the impression that the Darwin driver applied to Darwin 
hosts, not targets, but if that's not true, it would attempt to run xcrun. If 
xcrun isn't found, no error occurs but the sysroot remains unset.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/include/llvm/Support/MathExtras.h:225
 ///
 /// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are
 ///   valid arguments.

A bunch of functions still have this documentation, but these are now the only 
possible values, so this seems redundant


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141992: [NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls

2023-01-18 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

It passes on the previous windows CI. It looks like the assertion for 
`sizeof(...)` is indeed not a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141992

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

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

> If you care about compilation speed, you should build LLVM

with an appropriate -march= to take advantage of lzcnt and tzcnt.

I think this is bad reasoning, nobody really uses -march


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[clang] f252333 - [-Wunsafe-buffer-usage][NFC] Fix Fixables filtering

2023-01-18 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2023-01-18T18:54:48-08:00
New Revision: f252333b978c6b5a04d1cea3d92de16490969ff5

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

LOG: [-Wunsafe-buffer-usage][NFC] Fix Fixables filtering

We have WIP Fixables for local variables and this central part of the machinery
was dropping Fixables attached to local variables instead of keeping those and
dropping everything else.
We are in the process of rewriting our patches for emitting fixits after we
discovered a conceptual problem in our design.
That is why there's currently no tests that would've detected the issue but
that will change very shortly.

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index ec2a09e89989..2f1417487967 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -662,7 +662,7 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
   for (auto it = FixablesForUnsafeVars.byVar.cbegin();
it != FixablesForUnsafeVars.byVar.cend();) {
 // FIXME: Support ParmVarDecl as well.
-if (it->first->isLocalVarDecl() || Tracker.hasUnclaimedUses(it->first)) {
+if (!it->first->isLocalVarDecl() || Tracker.hasUnclaimedUses(it->first)) {
   it = FixablesForUnsafeVars.byVar.erase(it);
 } else {
   ++it;



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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks oodles of tests for me: http://45.33.8.238/macm1/52994/step_7.txt

Is anyone else seeing this?

Also, independently of that, shouldn't this check that the _host_ os is macOS 
as well? Doesn't the current code try to run `xcrun` if I do `clang 
--target=arm64-apple-macos -x c -c /dev/null` on Linux? (Or am I misreading 
that?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 accepted this revision.
barannikov88 added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/include/llvm/Support/MathExtras.h:212
 /// Only unsigned integral types are allowed.
-///
-/// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are
-///   valid arguments.
-template  T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
-  if (ZB == ZB_Max && Val == 0)
+template  T findFirstSet(T Val) {
+  if (Val == 0)

kazu wrote:
> craig.topper wrote:
> > Note, x86 does not have an efficient instruction for find first set with 
> > zero returning -1. It will require a cmov to handle zero.
> The new iteration of the patch leaves findFirstSet and findLastSet untouched.
(optional) ZB could be made a template argument and constexpr-ifed.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141992: [NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls

2023-01-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks for the fast revert!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141992

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


[PATCH] D141992: [NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls

2023-01-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Also fails on 64-bit windows fwiw: http://45.33.8.238/win/73344/step_4.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141992

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


[PATCH] D141992: [NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls

2023-01-18 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:2313
 void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
+  static_assert(sizeof(OMPDeclareMapperDecl) == 120,
+"You need to update the serializer after you change the fields 
"

thakis wrote:
> How can this work? This includes an ArrayRef 
> (http://llvm-cs.pcc.me.uk/tools/clang/include/clang/AST/DeclOpenMP.h#221) 
> which contains a pointer and a size_t. That alone will be 16 bytes on 64-bit 
> builds and 8 bytes on 32-bit builds.
You're right that I forgot the case for 32-bit machine. I've reverted the 
patch. And I need to look for better solutions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141992

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


[clang] 38a2f08 - Revert "[NFC] [Serialization] Add static assert for the size of the decls to"

2023-01-18 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-19T10:37:48+08:00
New Revision: 38a2f089b48103922e3ff6c363032704ce52c08e

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

LOG: Revert "[NFC] [Serialization] Add static assert for the size of the decls 
to"

This reverts commit c79635cce845d66897970cd7f8d7c77b0a3c0286. Since I
forgot the case for 32-bit machine.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index d4e4fa48e5da3..8a5f75573095b 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1389,8 +1389,6 @@ class DeclContextLookupResult {
 class DeclContext {
   /// For makeDeclVisibleInContextImpl
   friend class ASTDeclReader;
-  /// For checking the new bits in the Serialization part.
-  friend class ASTDeclWriter;
   /// For reconcileExternalVisibleStorage, CreateStoredDeclsMap,
   /// hasNeedToReconcileExternalVisibleStorage
   friend class ExternalASTSource;

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 1813529373ff2..43a74cdb5a5b7 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5899,11 +5899,6 @@ void ASTRecordWriter::AddCXXCtorInitializers(
 }
 
 void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
-  static_assert(sizeof(decltype(D->data())) == 104 &&
-sizeof(CXXRecordDecl::LambdaDefinitionData) == 144,
-"You need to update the serializer after you change the fields 
"
-"of Decls.");
-
   auto  = D->data();
   Record->push_back(Data.IsLambda);
 

diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 1b44ac9d59caf..ca59dd69f4fd5 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -300,9 +300,6 @@ void ASTDeclWriter::Visit(Decl *D) {
 }
 
 void ASTDeclWriter::VisitDecl(Decl *D) {
-  static_assert(sizeof(Decl) == 40, "You need to update the serializer after "
-"you change the fields of Decls.");
-
   Record.AddDeclRef(cast_or_null(D->getDeclContext()));
   if (D->getDeclContext() != D->getLexicalDeclContext())
 Record.AddDeclRef(cast_or_null(D->getLexicalDeclContext()));
@@ -342,10 +339,6 @@ void ASTDeclWriter::VisitDecl(Decl *D) {
 }
 
 void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
-  static_assert(sizeof(PragmaCommentDecl) == 40,
-"You need to update the serializer after you change the fields 
"
-"of Decls.");
-
   StringRef Arg = D->getArg();
   Record.push_back(Arg.size());
   VisitDecl(D);
@@ -357,10 +350,6 @@ void 
ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
 
 void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
 PragmaDetectMismatchDecl *D) {
-  static_assert(sizeof(PragmaDetectMismatchDecl) == 48,
-"You need to update the serializer after you change the fields 
"
-"of Decls.");
-
   StringRef Name = D->getName();
   StringRef Value = D->getValue();
   Record.push_back(Name.size() + 1 + Value.size());
@@ -376,10 +365,6 @@ void 
ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
 }
 
 void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
-  static_assert(sizeof(NamedDecl) == 48,
-"You need to update the serializer after you change the fields 
"
-"of Decls.");
-
   VisitDecl(D);
   Record.AddDeclarationName(D->getDeclName());
   Record.push_back(needsAnonymousDeclarationNumber(D)
@@ -388,20 +373,12 @@ void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
 }
 
 void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
-  static_assert(sizeof(TypeDecl) == 64,
-"You need to update the serializer after you change the fields 
"
-"of Decls.");
-
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
 }
 
 void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
-  static_assert(sizeof(TypedefNameDecl) == 88,
-"You need to update the serializer after you change the fields 
"
-"of Decls.");
-
   VisitRedeclarable(D);
   VisitTypeDecl(D);
   Record.AddTypeSourceInfo(D->getTypeSourceInfo());
@@ -412,10 +389,6 @@ void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl 
*D) {
 }
 
 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
-  static_assert(sizeof(TypedefDecl) == 88,
-"You need to update the serializer after you change the fields 
"
-   

[PATCH] D71734: [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches.

2023-01-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 490354.
vsapsai added a comment.

`setODRHash(0)` for consistency, mention the change in Potentially Breaking 
Changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/ODRDiagsEmitter.h
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/compare-record.c

Index: clang/test/Modules/compare-record.c
===
--- /dev/null
+++ clang/test/Modules/compare-record.c
@@ -0,0 +1,418 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Build first header file
+// RUN: echo "#define FIRST" >> %t/include/first.h
+// RUN: cat %t/test.c>> %t/include/first.h
+// RUN: echo "#undef FIRST"  >> %t/include/first.h
+
+// Build second header file
+// RUN: echo "#define SECOND" >> %t/include/second.h
+// RUN: cat %t/test.c >> %t/include/second.h
+// RUN: echo "#undef SECOND"  >> %t/include/second.h
+
+// Test that each header can compile
+// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/first.h -fblocks -fobjc-arc
+// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/second.h -fblocks -fobjc-arc
+
+// Run test
+// RUN: %clang_cc1 -I%t/include -verify %t/test.c -fblocks -fobjc-arc \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Run tests for nested structs
+// DEFINE: %{filename} = test-nested-struct.c
+// DEFINE: %{macro_flag} = -DCASE1=1
+// DEFINE: %{command} = %clang_cc1 -I%t/include -verify %t/%{filename} -fblocks -fobjc-arc \
+// DEFINE: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache \
+// DEFINE: %{macro_flag} -emit-llvm -o %t/%{filename}.bc
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE2=1
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE3=1
+// RUN: %{command}
+
+// Test that we don't accept different structs and unions with the same name
+// from multiple modules but detect mismatches and provide actionable
+// diagnostic.
+
+//--- include/first-empty.h
+//--- include/module.modulemap
+module First {
+  module Empty {
+header "first-empty.h"
+  }
+  module Hidden {
+header "first.h"
+header "first-nested-struct.h"
+export *
+  }
+}
+module Second {
+  header "second.h"
+  header "second-nested-struct.h"
+  export *
+}
+
+//--- test.c
+#if !defined(FIRST) && !defined(SECOND)
+# include "first-empty.h"
+# include "second.h"
+#endif
+
+#if defined(FIRST)
+struct CompareForwardDeclaration1;
+struct CompareForwardDeclaration2 {};
+#elif defined(SECOND)
+struct CompareForwardDeclaration1 {};
+struct CompareForwardDeclaration2;
+#else
+struct CompareForwardDeclaration1 *compareForwardDeclaration1;
+struct CompareForwardDeclaration2 *compareForwardDeclaration2;
+#endif
+
+#if defined(FIRST)
+struct CompareMatchingFields {
+  int matchingFieldName;
+};
+
+struct CompareFieldPresence1 {
+  int fieldPresence1;
+};
+struct CompareFieldPresence2 {};
+
+struct CompareFieldName {
+  int fieldNameA;
+};
+
+struct CompareFieldOrder {
+  int fieldOrderX;
+  int fieldOrderY;
+};
+#elif defined(SECOND)
+struct CompareMatchingFields {
+  int matchingFieldName;
+};
+
+struct CompareFieldPresence1 {
+};
+struct CompareFieldPresence2 {
+  int fieldPresence2;
+};
+
+struct CompareFieldName {
+  int fieldNameB;
+};
+
+struct CompareFieldOrder {
+  int fieldOrderY;
+  int fieldOrderX;
+};
+#else
+struct CompareMatchingFields compareMatchingFields;
+struct CompareFieldPresence1 compareFieldPresence1;
+// expected-error@first.h:* {{'CompareFieldPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found field}}
+// expected-note@second.h:* {{but in 'Second' found end of class}}
+struct CompareFieldPresence2 compareFieldPresence2;
+// expected-error@second.h:* {{'CompareFieldPresence2::fieldPresence2' from module 'Second' is not present in definition of 'struct CompareFieldPresence2' in module 'First.Hidden'}}
+// expected-note@first.h:* {{definition has no member 'fieldPresence2'}}
+struct CompareFieldName compareFieldName;
+// expected-error@second.h:* {{'CompareFieldName::fieldNameB' from module 'Second' is not present in definition of 'struct CompareFieldName' in module 'First.Hidden'}}
+// expected-note@first.h:* {{definition has no member 'fieldNameB'}}
+struct CompareFieldOrder compareFieldOrder;
+// expected-error@first.h:* {{'CompareFieldOrder' has different definitions in different modules; first difference is definition in module 

[PATCH] D141992: [NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls

2023-01-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:2313
 void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
+  static_assert(sizeof(OMPDeclareMapperDecl) == 120,
+"You need to update the serializer after you change the fields 
"

How can this work? This includes an ArrayRef 
(http://llvm-cs.pcc.me.uk/tools/clang/include/clang/AST/DeclOpenMP.h#221) which 
contains a pointer and a size_t. That alone will be 16 bytes on 64-bit builds 
and 8 bytes on 32-bit builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141992

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


[PATCH] D141798: Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)

2023-01-18 Thread Kazu Hirata via Phabricator via cfe-commits
kazu marked an inline comment as done.
kazu added a comment.

Please take a look.  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141798: Remove ZeroBehavior of countLeadingZeros and the like (NFC)

2023-01-18 Thread Kazu Hirata via Phabricator via cfe-commits
kazu marked an inline comment as done.
kazu added a comment.

In D141798#4055050 , @barannikov88 
wrote:

> It would be nice to have comments reflecting the new behavior in the case of 
> 0 / max value.

I've added comments to all four functions -- 
count{Leading,Trailing}{Zeros,Ones}.




Comment at: llvm/include/llvm/Support/MathExtras.h:212
 /// Only unsigned integral types are allowed.
-///
-/// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are
-///   valid arguments.
-template  T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
-  if (ZB == ZB_Max && Val == 0)
+template  T findFirstSet(T Val) {
+  if (Val == 0)

craig.topper wrote:
> Note, x86 does not have an efficient instruction for find first set with zero 
> returning -1. It will require a cmov to handle zero.
The new iteration of the patch leaves findFirstSet and findLastSet untouched.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

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


[PATCH] D141798: Remove ZeroBehavior of countLeadingZeros and the like (NFC)

2023-01-18 Thread Kazu Hirata via Phabricator via cfe-commits
kazu updated this revision to Diff 490348.
kazu added a comment.

Updated the patch to leave findFirstSet and findLastSet untouched.

Added a comment about the behavior on 0/max input.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141798

Files:
  llvm/include/llvm/Support/MathExtras.h
  llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Index: mlir/lib/Bytecode/Reader/BytecodeReader.cpp
===
--- mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -281,8 +281,7 @@
 // here because we only care about the first byte, and so that be actually
 // get ctz intrinsic calls when possible (the `uint8_t` overload uses a loop
 // implementation).
-uint32_t numBytes =
-llvm::countTrailingZeros(result, llvm::ZB_Undefined);
+uint32_t numBytes = llvm::countTrailingZeros(result);
 assert(numBytes > 0 && numBytes <= 7 &&
"unexpected number of trailing zeros in varint encoding");
 
Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -259,8 +259,7 @@
 if (I < B.size())
   BitsUsed |= B[I];
   if (BitsUsed != 0xff)
-return (MinByte + I) * 8 +
-   countTrailingZeros(uint8_t(~BitsUsed), ZB_Undefined);
+return (MinByte + I) * 8 + countTrailingZeros(uint8_t(~BitsUsed));
 }
   } else {
 // Find a free (Size/8) byte region in each member of Used.
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -172,7 +172,7 @@
 
   BSI.AlignLog2 = 0;
   if (Mask != 0)
-BSI.AlignLog2 = countTrailingZeros(Mask, ZB_Undefined);
+BSI.AlignLog2 = countTrailingZeros(Mask);
 
   // Build the compressed bitset while normalizing the offsets against the
   // computed alignment.
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -180,7 +180,7 @@
   // or ADDIW. If there are trailing zeros, try generating a sign extended
   // constant with no trailing zeros and use a final SLLI to restore them.
   if ((Val & 0xfff) != 0 && (Val & 1) == 0 && Res.size() >= 2) {
-unsigned TrailingZeros = countTrailingZeros((uint64_t)Val, ZB_Undefined);
+unsigned TrailingZeros = countTrailingZeros((uint64_t)Val);
 int64_t ShiftedVal = Val >> TrailingZeros;
 // If we can use C.LI+C.SLLI instead of LUI+ADDI(W) prefer that since
 // its more compressible. But only if LUI+ADDI(W) isn't fusable.
@@ -202,7 +202,7 @@
   if (Val > 0 && Res.size() > 2) {
 assert(ActiveFeatures[RISCV::Feature64Bit] &&
"Expected RV32 to only need 2 instructions");
-unsigned LeadingZeros = countLeadingZeros((uint64_t)Val, ZB_Undefined);
+unsigned LeadingZeros = countLeadingZeros((uint64_t)Val);
 uint64_t ShiftedVal = (uint64_t)Val << LeadingZeros;
 // Fill in the bits that will be shifted out with 1s. An example where this
 // helps is trailing one masks with 32 or more ones. This will generate
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -2451,8 +2451,7 @@
   unsigned PsInputBits = Info->getPSInputAddr() & Info->getPSInputEnable();
   if ((PsInputBits & 0x7F) == 0 ||
   ((PsInputBits & 0xF) == 0 && (PsInputBits >> 11 & 1)))
-Info->markPSInputEnabled(
-countTrailingZeros(Info->getPSInputAddr(), ZB_Undefined));
+Info->markPSInputEnabled(countTrailingZeros(Info->getPSInputAddr()));
 }
   } else if (IsKernel) {
 assert(Info->hasWorkGroupIDX() && Info->hasWorkItemIDX());
Index: llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp
@@ -701,8 +701,7 @@
   if ((PsInputBits & 0x7F) == 0 ||
   ((PsInputBits & 0xF) == 0 &&
(PsInputBits >> 11 & 1)))
-Info->markPSInputEnabled(
-  countTrailingZeros(Info->getPSInputAddr(), ZB_Undefined));
+

[PATCH] D141992: [NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls

2023-01-18 Thread Chuanqi Xu 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 rGc79635cce845: [NFC] [Serialization] Add static assert for 
the size of the decls to (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141992

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp

Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -300,6 +300,9 @@
 }
 
 void ASTDeclWriter::VisitDecl(Decl *D) {
+  static_assert(sizeof(Decl) == 40, "You need to update the serializer after "
+"you change the fields of Decls.");
+
   Record.AddDeclRef(cast_or_null(D->getDeclContext()));
   if (D->getDeclContext() != D->getLexicalDeclContext())
 Record.AddDeclRef(cast_or_null(D->getLexicalDeclContext()));
@@ -339,6 +342,10 @@
 }
 
 void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
+  static_assert(sizeof(PragmaCommentDecl) == 40,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   StringRef Arg = D->getArg();
   Record.push_back(Arg.size());
   VisitDecl(D);
@@ -350,6 +357,10 @@
 
 void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
 PragmaDetectMismatchDecl *D) {
+  static_assert(sizeof(PragmaDetectMismatchDecl) == 48,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   StringRef Name = D->getName();
   StringRef Value = D->getValue();
   Record.push_back(Name.size() + 1 + Value.size());
@@ -365,6 +376,10 @@
 }
 
 void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
+  static_assert(sizeof(NamedDecl) == 48,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitDecl(D);
   Record.AddDeclarationName(D->getDeclName());
   Record.push_back(needsAnonymousDeclarationNumber(D)
@@ -373,12 +388,20 @@
 }
 
 void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
+  static_assert(sizeof(TypeDecl) == 64,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
 }
 
 void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
+  static_assert(sizeof(TypedefNameDecl) == 88,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitRedeclarable(D);
   VisitTypeDecl(D);
   Record.AddTypeSourceInfo(D->getTypeSourceInfo());
@@ -389,6 +412,10 @@
 }
 
 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
+  static_assert(sizeof(TypedefDecl) == 88,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitTypedefNameDecl(D);
   if (D->getDeclContext() == D->getLexicalDeclContext() &&
   !D->hasAttrs() &&
@@ -405,12 +432,20 @@
 }
 
 void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
+  static_assert(sizeof(TypeAliasDecl) == 96,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitTypedefNameDecl(D);
   Record.AddDeclRef(D->getDescribedAliasTemplate());
   Code = serialization::DECL_TYPEALIAS;
 }
 
 void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
+  static_assert(DeclContext::NumTagDeclBits == 10 && sizeof(TagDecl) == 128,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitRedeclarable(D);
   VisitTypeDecl(D);
   Record.push_back(D->getIdentifierNamespace());
@@ -435,6 +470,10 @@
 }
 
 void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
+  static_assert(DeclContext::NumEnumDeclBits == 20 && sizeof(EnumDecl) == 160,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitTagDecl(D);
   Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
   if (!D->getIntegerTypeSourceInfo())
@@ -478,6 +517,11 @@
 }
 
 void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
+  static_assert(DeclContext::NumRecordDeclBits == 15 &&
+sizeof(RecordDecl) == 128,
+"You need to update the serializer after you change the fields "
+"of Decls.");
+
   VisitTagDecl(D);
   Record.push_back(D->hasFlexibleArrayMember());
   Record.push_back(D->isAnonymousStructOrUnion());
@@ -513,11 +557,19 @@
 }
 
 void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
+  static_assert(sizeof(ValueDecl) == 

[clang] c79635c - [NFC] [Serialization] Add static assert for the size of the decls to

2023-01-18 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-19T10:20:29+08:00
New Revision: c79635cce845d66897970cd7f8d7c77b0a3c0286

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

LOG: [NFC] [Serialization] Add static assert for the size of the decls to
mention developers to remember to touch the serializer after them
modified the field of decls

It is easy for the developers to forget to touch the serializer after
they add new field to decls. Then if the existing tests fail to catch
such cases, it may be a bug report from users some day. And it is
time-consuming to solve such bugs.

To mitigate the problem, I add the static_asserts in the serializer. So
that the developers can understand they need to modify the serializer
after they saw the static assertion failure. Although this can't solve
all the problems, I feel the current status can be much better.

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 8a5f75573095b..d4e4fa48e5da3 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1389,6 +1389,8 @@ class DeclContextLookupResult {
 class DeclContext {
   /// For makeDeclVisibleInContextImpl
   friend class ASTDeclReader;
+  /// For checking the new bits in the Serialization part.
+  friend class ASTDeclWriter;
   /// For reconcileExternalVisibleStorage, CreateStoredDeclsMap,
   /// hasNeedToReconcileExternalVisibleStorage
   friend class ExternalASTSource;

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 43a74cdb5a5b7..1813529373ff2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5899,6 +5899,11 @@ void ASTRecordWriter::AddCXXCtorInitializers(
 }
 
 void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
+  static_assert(sizeof(decltype(D->data())) == 104 &&
+sizeof(CXXRecordDecl::LambdaDefinitionData) == 144,
+"You need to update the serializer after you change the fields 
"
+"of Decls.");
+
   auto  = D->data();
   Record->push_back(Data.IsLambda);
 

diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index ca59dd69f4fd5..1b44ac9d59caf 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -300,6 +300,9 @@ void ASTDeclWriter::Visit(Decl *D) {
 }
 
 void ASTDeclWriter::VisitDecl(Decl *D) {
+  static_assert(sizeof(Decl) == 40, "You need to update the serializer after "
+"you change the fields of Decls.");
+
   Record.AddDeclRef(cast_or_null(D->getDeclContext()));
   if (D->getDeclContext() != D->getLexicalDeclContext())
 Record.AddDeclRef(cast_or_null(D->getLexicalDeclContext()));
@@ -339,6 +342,10 @@ void ASTDeclWriter::VisitDecl(Decl *D) {
 }
 
 void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
+  static_assert(sizeof(PragmaCommentDecl) == 40,
+"You need to update the serializer after you change the fields 
"
+"of Decls.");
+
   StringRef Arg = D->getArg();
   Record.push_back(Arg.size());
   VisitDecl(D);
@@ -350,6 +357,10 @@ void 
ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
 
 void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
 PragmaDetectMismatchDecl *D) {
+  static_assert(sizeof(PragmaDetectMismatchDecl) == 48,
+"You need to update the serializer after you change the fields 
"
+"of Decls.");
+
   StringRef Name = D->getName();
   StringRef Value = D->getValue();
   Record.push_back(Name.size() + 1 + Value.size());
@@ -365,6 +376,10 @@ void 
ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
 }
 
 void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
+  static_assert(sizeof(NamedDecl) == 48,
+"You need to update the serializer after you change the fields 
"
+"of Decls.");
+
   VisitDecl(D);
   Record.AddDeclarationName(D->getDeclName());
   Record.push_back(needsAnonymousDeclarationNumber(D)
@@ -373,12 +388,20 @@ void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
 }
 
 void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
+  static_assert(sizeof(TypeDecl) == 64,
+"You need to update the serializer after you change the fields 
"
+"of Decls.");
+
   VisitNamedDecl(D);
   Record.AddSourceLocation(D->getBeginLoc());
   Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
 }
 
 void 

[PATCH] D135488: [codegen] Add StackFrameLayoutAnalysisPass

2023-01-18 Thread Paul Kirth 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 rG557a5bc336ff: [codegen] Add StackFrameLayoutAnalysisPass 
(authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135488

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/Frontend/stack-layout-remark.c
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/InitializePasses.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/ARM/O3-pipeline.ll
  llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
  llvm/test/CodeGen/Generic/llc-start-stop.ll
  llvm/test/CodeGen/LoongArch/O0-pipeline.ll
  llvm/test/CodeGen/LoongArch/opt-pipeline.ll
  llvm/test/CodeGen/M68k/pipeline.ll
  llvm/test/CodeGen/PowerPC/O0-pipeline.ll
  llvm/test/CodeGen/PowerPC/O3-pipeline.ll
  llvm/test/CodeGen/RISCV/O0-pipeline.ll
  llvm/test/CodeGen/RISCV/O3-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll

Index: llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
@@ -0,0 +1,315 @@
+; Test remark output for stack-frame-layout
+
+; ensure basic output works
+; RUN: llc -mcpu=corei7 -O1 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s
+
+; check additional slots are displayed when stack is not optimized
+; RUN: llc -mcpu=corei7 -O0 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NO_COLORING
+
+; check more complex cases
+; RUN: llc %s -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=DEBUG
+
+; check output without debug info
+; RUN: opt %s -passes=strip -S | llc  -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=STRIPPED
+
+target triple = "x86_64-unknown-linux-gnu"
+
+@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
+declare i32 @printf(ptr, ...)
+
+; CHECK: Function: stackSizeWarning
+; CHECK: Offset: [SP-88], Type: Variable, Align: 16, Size: 80
+; CHECK:buffer @ frame-diags.c:30
+; NO_COLORING: Offset: [SP-168], Type: Variable, Align: 16, Size: 80
+; CHECK:buffer2 @ frame-diags.c:33
+define void @stackSizeWarning() {
+entry:
+  %buffer = alloca [80 x i8], align 16
+  %buffer2 = alloca [80 x i8], align 16
+  call void @llvm.dbg.declare(metadata ptr %buffer, metadata !25, metadata !DIExpression()), !dbg !39
+  call void @llvm.dbg.declare(metadata ptr %buffer2, metadata !31, metadata !DIExpression()), !dbg !40
+  ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+; BOTH: Function: cleanup_array
+; BOTH-Next:  Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: a @ dot.c:13
+; STRIPPED-NOT: a @ dot.c:13
+; BOTH:  Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+define void @cleanup_array(ptr %0) #1 {
+  %2 = alloca ptr, align 8
+  store ptr %0, ptr %2, align 8
+  call void @llvm.dbg.declare(metadata ptr %2, metadata !41, metadata !DIExpression()), !dbg !46
+  ret void
+}
+
+; BOTH: Function: cleanup_result
+; BOTH:  Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: res @ dot.c:21
+; STRIPPED-NOT: res @ dot.c:21
+; BOTH:  Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+define void @cleanup_result(ptr %0) #1 {
+  %2 = alloca ptr, align 8
+  store ptr %0, ptr %2, align 8
+  call void @llvm.dbg.declare(metadata ptr %2, metadata !47, metadata !DIExpression()), !dbg !51
+  ret void
+}
+
+; BOTH: Function: do_work
+; BOTH:  Offset: [SP+12], Type: Variable, Align: 8, Size: 4
+; DEBUG: out @ dot.c:32
+; STRIPPED-NOT: out @ dot.c:32
+; BOTH:  Offset: [SP+8], Type: Variable, Align: 4, Size: 4
+; BOTH:  Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: A @ dot.c:32
+; STRIPPED-NOT: A @ dot.c:32
+; BOTH:  Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+; BOTH:  Offset: [SP-12], Type: Variable, Align: 8, Size: 4
+; DEBUG: AB @ dot.c:38
+; STRIPPED-NOT: AB @ dot.c:38
+; BOTH:  Offset: [SP-16], Type: Variable, Align: 4, Size: 4
+; DEBUG: i @ dot.c:55
+; STRIPPED-NOT: i @ dot.c:55
+; BOTH:  Offset: [SP-20], Type: Variable, Align: 8, Size: 4
+; DEBUG: B @ dot.c:32
+; STRIPPED-NOT: B @ dot.c:32
+; BOTH:  Offset: [SP-24], 

[clang] 557a5bc - [codegen] Add StackFrameLayoutAnalysisPass

2023-01-18 Thread Paul Kirth via cfe-commits

Author: Paul Kirth
Date: 2023-01-19T01:51:14Z
New Revision: 557a5bc336ffb9b03c53d4d13fd8f0bc9418ec96

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

LOG: [codegen] Add StackFrameLayoutAnalysisPass

Issue #58168 describes the difficulty diagnosing stack size issues
identified by -Wframe-larger-than. For simple code, its easy to
understand the stack layout and where space is being allocated, but in
more complex programs, where code may be heavily inlined, unrolled, and
have duplicated code paths, it is no longer easy to manually inspect the
source program and understand where stack space can be attributed.

This patch implements a machine function pass that emits remarks with a
textual representation of stack slots, and also outputs any available
debug information to map source variables to those slots.

The new behavior can be used by adding `-Rpass-analysis=stack-frame-layout`
to the compiler invocation. Like other remarks the diagnostic
information can be saved to a file in a machine readable format by
adding -fsave-optimzation-record.

Fixes: #58168

Reviewed By: nickdesaulniers, thegameg

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

Added: 
clang/test/Frontend/stack-layout-remark.c
llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
llvm/test/CodeGen/ARM/O3-pipeline.ll
llvm/test/CodeGen/Generic/llc-start-stop.ll
llvm/test/CodeGen/LoongArch/O0-pipeline.ll
llvm/test/CodeGen/LoongArch/opt-pipeline.ll
llvm/test/CodeGen/M68k/pipeline.ll
llvm/test/CodeGen/PowerPC/O0-pipeline.ll
llvm/test/CodeGen/PowerPC/O3-pipeline.ll
llvm/test/CodeGen/RISCV/O0-pipeline.ll
llvm/test/CodeGen/RISCV/O3-pipeline.ll
llvm/test/CodeGen/X86/O0-pipeline.ll
llvm/test/CodeGen/X86/opt-pipeline.ll

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 288904b023863..21960ab69ceab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -547,6 +547,11 @@ New Compiler Flags
   `Standard C++ Modules 
`_
   for more information.
 
+- Added ``-Rpass-analysis=stack-frame-layout`` which will emit new diagnostic
+  information about the layout of stack frames through the remarks
+  infrastructure. Since it uses remarks the diagnostic information is available
+  both on the CLI, and in a machine readable format.
+
 Deprecated Compiler Flags
 -
 - ``-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang``

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d754fdb594c02..6c997c37cc5cd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1269,7 +1269,25 @@ def OpenMP : DiagGroup<"openmp", [
 // Backend warnings.
 def BackendInlineAsm : DiagGroup<"inline-asm">;
 def BackendSourceMgr : DiagGroup<"source-mgr">;
-def BackendFrameLargerThan : DiagGroup<"frame-larger-than">;
+def BackendFrameLargerThan : DiagGroup<"frame-larger-than">{
+ code Documentation = [{
+More fine grained information about the stack layout is available by adding the
+`-Rpass-analysis=stack-frame-layout` command-line flag to the compiler
+invocation.
+
+The diagnostic information can be saved to a file in a machine readable format,
+like YAML by adding the `-foptimization-record-file=` command-line flag.
+
+Results can be filtered by function name by passing 
+`-mllvm -filter-print-funcs=foo`, where `foo` is the target function's name.
+
+   .. code-block: console
+  clang -c a.cpp -Rpass-analysis=stack-frame-layout -mllvm 
-filter-print-funcs=foo
+
+   .. code-block: console
+  clang -c a.cpp -Rpass-analysis=stack-frame-layout 
-foptimization-record-file=
+}];
+}
 // Compatibility flag name from old versions of Clang.
 def : DiagGroup<"frame-larger-than=", [BackendFrameLargerThan]>;
 def BackendPlugin : DiagGroup<"backend-plugin">;

diff  --git a/clang/test/Frontend/stack-layout-remark.c 
b/clang/test/Frontend/stack-layout-remark.c
new file mode 100644
index 0..b0ed03c80f24a
--- /dev/null
+++ 

[PATCH] D140179: [WIP][-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-01-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/include/clang/Basic/Diagnostic.h:1040-1043
+  // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one
+  // translation unit. Each region is represented by a pair of start and end
+  // locations.
+  SmallVector, 8> 
SafeBufferOptOutMap;

Ok, now I no longer see why this data should live in DiagnosticEngine. It's 
mostly about analysis, right? The pragma simply makes our analysis produce 
different results, regardless of whether these results are used for producing 
diagnostics or something else. Maybe let's keep it all in Preprocessor?



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:543
 #define GADGET(x)  
\
-x ## Gadget::matcher().bind(#x),
+allOf(x ## Gadget::matcher().bind(#x), notInSafeBufferOptOut()),
 #include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"

This prevents safe fixable gadgets from being found in the opt-out zone. I 
think this clause should only apply to warning gadgets.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:551-555
+allOf(declStmt().bind("any_ds"), notInSafeBufferOptOut())
+// We match all DREs regardless of whether they are in safe-buffer
+// opt-out region. Because an unclaimed DRE 'd', regardless of where 
it is,
+// should prevent a Fixable associated to the same variable as 'd'
+// from being emitting.

I think we should match all DeclStmts as well, because otherwise we may be 
unable to find the variable to fix.


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

https://reviews.llvm.org/D140179

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


[PATCH] D142065: [SVE] Fix incorrect lowering of predicate permute builtins.

2023-01-18 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added reviewers: david-arm, CarolineConcatto, peterwaller-arm.
paulwalker-arm added a comment.

This is bug fix based on something spotted when reviewing D141469 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142065

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


[PATCH] D142065: [SVE] Fix incorrect lowering of predicate permute builtins.

2023-01-18 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm created this revision.
Herald added subscribers: psnobl, hiraditya, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: All.
paulwalker-arm requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

When lowering predicate permute builtins we incorrectly assume only
the typically "active" bits for the specified element type play a
role with all other bits zero'd.  This is not the case because all
bits are significant, with the element type specifying how they
are grouped:

  b8  - permute using a block size of 1 bit
  b16 - permute using a block size of 2 bits
  b32 - permute using a block size of 4 bits
  b64 - permute using a block size of 8 bits

The affected builtins are svrev, svtrn1, svtrn2, svuzp1, svuzp2,
svzip1 and svzip2.

This patch adds new intrinsics to support these operations and
changes the builtin lowering code to emit them.  The b8 case remains
unchanged because for that operation the existing intrinsics work
as required and their support for other predicate types has been
maintained as useful if only as a way to test the correctness of
their matching ISD nodes that code generation relies on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142065

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rev.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_trn2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_uzp2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip1.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_zip2.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve-intrinsics-perm-select.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-perm-select.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-perm-select.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-perm-select.ll
@@ -942,8 +942,8 @@
 ; REV
 ;
 
-define  @rev_b8(  %a) {
-; CHECK-LABEL: rev_b8:
+define  @rev_nxv16i1( %a) {
+; CHECK-LABEL: rev_nxv16i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:rev p0.b, p0.b
 ; CHECK-NEXT:ret
@@ -951,8 +951,8 @@
   ret  %res
 }
 
-define  @rev_b16( %a) {
-; CHECK-LABEL: rev_b16:
+define  @rev_nxv8i1( %a) {
+; CHECK-LABEL: rev_nxv8i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:rev p0.h, p0.h
 ; CHECK-NEXT:ret
@@ -960,8 +960,8 @@
   ret  %res
 }
 
-define  @rev_b32( %a) {
-; CHECK-LABEL: rev_b32:
+define  @rev_nxv4i1( %a) {
+; CHECK-LABEL: rev_nxv4i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:rev p0.s, p0.s
 ; CHECK-NEXT:ret
@@ -969,8 +969,8 @@
   ret  %res
 }
 
-define  @rev_b64( %a) {
-; CHECK-LABEL: rev_b64:
+define  @rev_nxv2i1( %a) {
+; CHECK-LABEL: rev_nxv2i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:rev p0.d, p0.d
 ; CHECK-NEXT:ret
@@ -978,7 +978,34 @@
   ret  %res
 }
 
-define  @rev_i8(  %a) {
+define  @rev_b16( %a) {
+; CHECK-LABEL: rev_b16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rev p0.h, p0.h
+; CHECK-NEXT:ret
+  %res = call  @llvm.aarch64.sve.rev.b16( %a)
+  ret  %res
+}
+
+define  @rev_b32( %a) {
+; CHECK-LABEL: rev_b32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rev p0.s, p0.s
+; CHECK-NEXT:ret
+  %res = call  @llvm.aarch64.sve.rev.b32( %a)
+  ret  %res
+}
+
+define  @rev_b64( %a) {
+; CHECK-LABEL: rev_b64:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rev p0.d, p0.d
+; CHECK-NEXT:ret
+  %res = call  @llvm.aarch64.sve.rev.b64( %a)
+  ret  %res
+}
+
+define  @rev_i8( %a) {
 ; CHECK-LABEL: rev_i8:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:rev z0.b, z0.b
@@ -1354,8 +1381,8 @@
 ; TRN1
 ;
 
-define  @trn1_b8( %a,  %b) {
-; CHECK-LABEL: trn1_b8:
+define  @trn1_nxv16i1( %a,  %b) {
+; CHECK-LABEL: trn1_nxv16i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:trn1 p0.b, p0.b, p1.b
 ; CHECK-NEXT:ret
@@ -1364,8 +1391,8 @@
   ret  %out
 }
 
-define  @trn1_b16( %a,  %b) {
-; CHECK-LABEL: trn1_b16:
+define  @trn1_nxv8i1( %a,  %b) {
+; CHECK-LABEL: trn1_nxv8i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:trn1 p0.h, p0.h, p1.h
 ; CHECK-NEXT:ret
@@ -1374,8 +1401,8 @@
   ret  %out
 }
 
-define  @trn1_b32( %a,  %b) {
-; CHECK-LABEL: trn1_b32:
+define  @trn1_nxv4i1( %a,  %b) {
+; CHECK-LABEL: trn1_nxv4i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:trn1 p0.s, p0.s, p1.s
 ; CHECK-NEXT:ret
@@ -1384,8 +1411,8 @@
   ret  %out
 }
 
-define  @trn1_b64( %a,  %b) {
-; CHECK-LABEL: trn1_b64:
+define  @trn1_nxv2i1( %a,  %b) {
+; CHECK-LABEL: trn1_nxv2i1:
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:trn1 p0.d, p0.d, p1.d
 ; CHECK-NEXT:ret
@@ -1394,6 +1421,36 @@
   ret  %out
 }
 
+define  @trn1_b16( %a,  %b) {
+; CHECK-LABEL: trn1_b16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:

[PATCH] D141968: [NFC] Consolidate llvm::CodeGenOpt::Level handling

2023-01-18 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/include/llvm/Support/CodeGen.h:57
+  /// Code generation optimization level.
+  enum Level : IDType {
+None = 0,  ///< -O0

scott.linder wrote:
> barannikov88 wrote:
> > arsenm wrote:
> > > scott.linder wrote:
> > > > This is ABI breaking, so maybe we don't want/need to define the 
> > > > underlying type?
> > > This isn't in the C API, and this isn't for a release branch so I don't 
> > > think it matters
> > Why did you need to restrict the underlying type?
> > 
> There is no strict need, it just:
> 
> * Avoids potential UB (casting an out-of-range value to an enumeration type 
> //without a fixed underlying type// is undefined); in practice there is 
> plenty of UB in LLVM, and a bug here wouldn't be a particularly pernicious 
> kind of UB anyway.
> * Means users of the type might pack better (and we won't run out of 255 opt 
> levels anytime soon).
> 
> I originally intended to change this to an `enum class` rather than a `class` 
> in a `namespace`, but that is slightly more disruptive and should probably be 
> done for every other enumeration defined here at the same time.
Thanks for the explanation.
> Means users of the type might pack better (and we won't run out of 255 opt 
> levels anytime soon).
The downside is that `int` is usually more efficient.
> Avoids potential UB [...]
cppreference [[ https://en.cppreference.com/w/cpp/language/enum | says ]]
```
Values of unscoped enumeration type are implicitly-convertible to integral 
types. If the underlying type is not fixed, the value is convertible to the 
first type from the following list able to hold their entire value range: int, 
unsigned int, ...
```
so casting to int should be safe.
Anyways, this is just a nit, feel free to ignore.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141968

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


[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:22399-22412
 bool Sema::isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const {
   assert(LangOpts.OpenMP && "Expected OpenMP mode.");
   const Expr *Ref = DSAStack->getDeclareMapperVarRef();
   if (const auto *DRE = cast_or_null(Ref)) {
 if (VD->getCanonicalDecl() == DRE->getDecl()->getCanonicalDecl())
   return true;
 if (VD->isUsableInConstantExpressions(Context))

This input to this function is the VD variable I've been talking about. If you 
print it all out it's just a simple VarDecl:

if you do `VD->dump()`;
```
VarDecl 0x55b57f81dec8  col:52 implicit 
used it 'int'
```

if you do `VD->getType()->dump()`:
```
BuiltinType 0x55b57f6d2560 'int'
```


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

https://reviews.llvm.org/D141871

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Joseph Huber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
jhuber6 marked 3 inline comments as done.
Closed by commit rG0660397e6809: [CUDA] Allow targeting NVPTX directly without 
a host toolchain (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D140158?vs=490317=490329#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c

Index: clang/test/Driver/cuda-cross-compiling.c
===
--- /dev/null
+++ clang/test/Driver/cuda-cross-compiling.c
@@ -0,0 +1,68 @@
+// Tests the driver when targeting the NVPTX architecture directly without a
+// host toolchain to perform CUDA mappings.
+
+// REQUIRES: nvptx-registered-target
+
+//
+// Test the generated phases when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=PHASES %s
+
+//  PHASES: 0: input, "[[INPUT:.+]]", c
+// PHASES-NEXT: 1: preprocessor, {0}, cpp-output
+// PHASES-NEXT: 2: compiler, {1}, ir
+// PHASES-NEXT: 3: backend, {2}, assembler
+// PHASES-NEXT: 4: assembler, {3}, object
+// PHASES-NEXT: 5: linker, {4}, image
+
+//
+// Test the generated bindings when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=BINDINGS %s
+
+//  BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that the '.o' files are converted to '.cubin' if produced internally.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=ARGS %s
+
+//  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that we emit '.o' files if compiled with '-c'
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -c -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=OBJECT %s
+
+//  OBJECT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// OBJECT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[OBJ:.+]].o" "[[PTX]].s" "-c"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that we copy input '.o' files to '.cubin' files when linking.
+//
+// RUN: touch %t.o
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINK %s
+
+// LINK: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "{{.*}}.cubin"
+
+//
+// Test the generated arguments default to a value with no architecture. 
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DEFAULT %s
+
+//  DEFAULT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_35" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// DEFAULT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_35" "--output-file" "[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// DEFAULT-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_35" {{.*}} "[[CUBIN]].cubin"
Index: clang/lib/Driver/ToolChains/Cuda.h
===
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -95,6 +95,19 @@
 
 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
 // assembly into a single output file.
+class LLVM_LIBRARY_VISIBILITY FatBinary : public Tool {
+public:
+  FatBinary(const ToolChain ) : Tool("NVPTX::Linker", "fatbinary", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+};
+
+// Runs nvlink, which links GPU object files ("cubin" files) into a single file.
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
 public:
   Linker(const 

[clang] 0660397 - [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-01-18T18:18:25-06:00
New Revision: 0660397e68096a64279b19f913e7de2c283e524f

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

LOG: [CUDA] Allow targeting NVPTX directly without a host toolchain

Currently, the NVPTX compilation toolchain can only be invoked either
through CUDA or OpenMP via `--offload-device-only`. This is because we
cannot build a CUDA toolchain without an accompanying host toolchain for
the offloading. When using `--target=nvptx64-nvidia-cuda` this results
in generating calls to the GNU assembler and linker, leading to errors.

This patch abstracts the portions of the CUDA toolchain that are
independent of the host toolchain or offloading kind into a new base
class called `NVPTXToolChain`. We still need to read the host's triple
to build the CUDA installation, so if not present we just assume it will
match the host's system for now, or the user can provide the path
explicitly.

This should allow the compiler driver to create NVPTX device images
directly from C/C++ code.

Reviewed By: tra

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

Added: 
clang/test/Driver/cuda-cross-compiling.c

Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e20aad49b0cd..12f8c326 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6039,6 +6039,9 @@ const ToolChain ::getToolChain(const ArgList ,
 case llvm::Triple::Solaris:
   TC = std::make_unique(*this, Target, Args);
   break;
+case llvm::Triple::CUDA:
+  TC = std::make_unique(*this, Target, Args);
+  break;
 case llvm::Triple::AMDHSA:
   TC = std::make_unique(*this, Target, Args);
   break;
@@ -6158,11 +6161,6 @@ const ToolChain ::getToolChain(const ArgList 
,
 }
   }
 
-  // Intentionally omitted from the switch above: llvm::Triple::CUDA.  CUDA
-  // compiles always need two toolchains, the CUDA toolchain and the host
-  // toolchain.  So the only valid way to create a CUDA toolchain is via
-  // CreateOffloadingDeviceToolChains.
-
   return *TC;
 }
 

diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index b5e45ae4e0bf..484c8c070264 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -369,18 +369,20 @@ void NVPTX::Assembler::ConstructJob(Compilation , const 
JobAction ,
 const ArgList ,
 const char *LinkingOutput) const {
   const auto  =
-  static_cast(getToolChain());
+  static_cast(getToolChain());
   assert(TC.getTriple().isNVPTX() && "Wrong platform");
 
   StringRef GPUArchName;
-  // If this is an OpenMP action we need to extract the device architecture
-  // from the -march=arch option. This option may come from -Xopenmp-target
-  // flag or the default value.
-  if (JA.isDeviceOffloading(Action::OFK_OpenMP)) {
+  // If this is a CUDA action we need to extract the device architecture
+  // from the Job's associated architecture, otherwise use the -march=arch
+  // option. This option may come from -Xopenmp-target flag or the default
+  // value.
+  if (JA.isDeviceOffloading(Action::OFK_Cuda)) {
+GPUArchName = JA.getOffloadingArch();
+  } else {
 GPUArchName = Args.getLastArgValue(options::OPT_march_EQ);
 assert(!GPUArchName.empty() && "Must have an architecture passed in.");
-  } else
-GPUArchName = JA.getOffloadingArch();
+  }
 
   // Obtain architecture from the action.
   CudaArch gpu_arch = StringToCudaArch(GPUArchName);
@@ -442,8 +444,22 @@ void NVPTX::Assembler::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
   CmdArgs.push_back("--output-file");
   const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output));
-  if (std::string(OutputFileName) != std::string(Output.getFilename()))
+
+  // If we are invoking `nvlink` internally we need to output a `.cubin` file.
+  // Checking if the output is a temporary is the cleanest way to determine
+  // this. Putting this logic in `getInputFilename` isn't an option because it
+  // relies on the compilation.
+  // FIXME: This should hopefully be removed if NVIDIA updates their tooling.
+  if (Output.isFilename() &&
+  llvm::find(C.getTempFiles(), Output.getFilename()) !=
+  C.getTempFiles().end()) {
+SmallString<256> Filename(Output.getFilename());
+llvm::sys::path::replace_extension(Filename, "cubin");
+OutputFileName = Args.MakeArgString(Filename);
+  }
+  if (Output.isFilename() && OutputFileName != 

[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

doru1004 wrote:
> doru1004 wrote:
> > ABataev wrote:
> > > doru1004 wrote:
> > > > doru1004 wrote:
> > > > > ABataev wrote:
> > > > > > doru1004 wrote:
> > > > > > > ABataev wrote:
> > > > > > > > doru1004 wrote:
> > > > > > > > > ABataev wrote:
> > > > > > > > > > Do you really need to store the variable in the stack, is 
> > > > > > > > > > not it enough just to check that the type of this variable 
> > > > > > > > > > is BuiltinType::OMPIterator?
> > > > > > > > > I'm happy to replace this if you think it will work. Is there 
> > > > > > > > > an example somewhere in the code where I can get from the 
> > > > > > > > > VarDecl to the build in type you mention?
> > > > > > > > You have already a check 
> > > > > > > > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> > > > > > > >  you can you something similar for the variable
> > > > > > > This didn't work and I had to revert to using the stack!
> > > > > > Why?
> > > > > I checked the output of the check and it was false when it should 
> > > > > have been true! If you check the latest test that I added it 
> > > > > showcases the source code and in the case of OpenMP 5.2 you can see 
> > > > > that the message "only variable 'vvec' is allowed in map clauses of 
> > > > > this 'omp declare mapper' directive" doesn't appear when a legal 
> > > > > iteration variable is used.
> > > > > If I used the check you suggested then the error message appears.
> > > > > In the example you pasted the check is performed on a `Expr *`. In 
> > > > > the case here, we only have VD which is a VarDecl.
> > > > I am not sure how I can force it to have that type when it just 
> > > > doesn't. Do you have any suggestions?
> > > Did not get it. It still shall be of type builtintype::OMPIterator.
> > The VD that we are checking for this builtin is coming from somewhere else 
> > in the code, it is passed into the `Sema::DiagnoseUseOfDecl(` function. 
> > It's not a VarDecl that is under the control of anything added in this 
> > patch.
> This implementation is in line with the current checks for the declaration of 
> the mapper variable. You store the declaration onto the stack so that you can 
> compare it with the incoming VarDecl passed to the diagnose function.
Some debug printouts regarding VD:

> VD->dump();
```
VarDecl 0x55b57f81dec8  col:52 implicit 
used it 'int'
```

This is the type of the variable if you do `VD->getType()->dump()`:
```
BuiltinType 0x55b57f6d2560 'int'
```


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

https://reviews.llvm.org/D141871

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


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

2023-01-18 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D136651#4063818 , @friss wrote:

> In D136651#4063632 , @lebedev.ri 
> wrote:
>
>> In D136651#4063597 , @friss wrote:
>>
>>> In D136651#4060071 , @lebedev.ri 
>>> wrote:
>>>
 Docs still missing.
>>>
>>> Sorry @lebedev.ri I missed your earlier comment about this. What format of 
>>> doc would you like to see? A more elaborate comment in the tool's source or 
>>> something else?
>>
>> Right now it's impossible to discover that tool unless you already know it 
>> exists (or it's mentioned in some xcode doc, i guess)
>> It should have it's own description in it's `--help`, and ideally an `.rst` 
>> documentation page in `docs`.
>
> I have no issue adding a more detailed help text. The documentation page 
> seems somewhat overkill, but I guess I could be convinced otherwise. You need 
> a fairly special build environment for this to make a difference and I'm not 
> sure it's broadly applicable. You also need good build system integration to 
> make it practical.

... and all of that knowledge seems to be missing from the current docs, which 
is why i'm asking in the first place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


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

2023-01-18 Thread Frederic Riss via Phabricator via cfe-commits
friss added a comment.

In D136651#4063632 , @lebedev.ri 
wrote:

> In D136651#4063597 , @friss wrote:
>
>> In D136651#4060071 , @lebedev.ri 
>> wrote:
>>
>>> Docs still missing.
>>
>> Sorry @lebedev.ri I missed your earlier comment about this. What format of 
>> doc would you like to see? A more elaborate comment in the tool's source or 
>> something else?
>
> Right now it's impossible to discover that tool unless you already know it 
> exists (or it's mentioned in some xcode doc, i guess)
> It should have it's own description in it's `--help`, and ideally an `.rst` 
> documentation page in `docs`.

I have no issue adding a more detailed help text. The documentation page seems 
somewhat overkill, but I guess I could be convinced otherwise. You need a 
fairly special build environment for this to make a difference and I'm not sure 
it's broadly applicable. You also need good build system integration to make it 
practical.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D136497: [Clang] support for outputs along indirect edges of asm goto

2023-01-18 Thread Bill Wendling via Phabricator via cfe-commits
void added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:199
+  guaranteed (and necessary to support outputs along indirect edges, which is
+  now supported as of this release).
+

Is it worth it to mention that this change makes Clang's behavior with regards 
to your example here consistent with GCC's behavior?



Comment at: clang/lib/CodeGen/CGStmt.cpp:2814
+  // A 2D vector, indexed by indirect destination, then ResultReg.
+  std::vector> CBRRegResults;
   if (IsGCCAsmGoto) {

It seems as if you really want a map indexed by the `BasicBlock*`. So something 
like this:

```
DenseMap> // 4 should be enough for 
anyone.
```

That way you can iterate over `CBR->getIndirectDests()` instead of having to 
use an iterator.



Comment at: clang/lib/CodeGen/CGStmt.cpp:2868
+  // CBRRegResults rather than RegResults.
+  if (IsGCCAsmGoto && CBRRegResults.size()) {
+for (unsigned i = 0, e = CBR->getNumIndirectDests(); i != e; ++i) {

Could probably use `!CBRRegResults.empty()` instead of `.size()`. The first 
should be `O(1)` (granted `.size()` probably should be too, but `.empty()` is 
more explicit anyway).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136497

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


[PATCH] D141968: [NFC] Consolidate llvm::CodeGenOpt::Level handling

2023-01-18 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: llvm/include/llvm/Support/CodeGen.h:57
+  /// Code generation optimization level.
+  enum Level : IDType {
+None = 0,  ///< -O0

barannikov88 wrote:
> arsenm wrote:
> > scott.linder wrote:
> > > This is ABI breaking, so maybe we don't want/need to define the 
> > > underlying type?
> > This isn't in the C API, and this isn't for a release branch so I don't 
> > think it matters
> Why did you need to restrict the underlying type?
> 
There is no strict need, it just:

* Avoids potential UB (casting an out-of-range value to an enumeration type 
//without a fixed underlying type// is undefined); in practice there is plenty 
of UB in LLVM, and a bug here wouldn't be a particularly pernicious kind of UB 
anyway.
* Means users of the type might pack better (and we won't run out of 255 opt 
levels anytime soon).

I originally intended to change this to an `enum class` rather than a `class` 
in a `namespace`, but that is slightly more disruptive and should probably be 
done for every other enumeration defined here at the same time.



Comment at: llvm/include/llvm/Support/CodeGen.h:67
+  inline std::optional getLevel(IDType ID) {
+if (ID < 0 || ID > 3)
+  return std::nullopt;

barannikov88 wrote:
> As I can see, clients do not check for nullopt. Either add checks or replace 
> this check with an assertion and drop std::optional (in this case 
> `parseLevel` should be updated accordingly).
> 
> 
Good catch! I was working off of the old behavior of `llvm::Optional` and 
assuming the new `std::optional` was guaranteed to `assert` on dereference as 
well. I think the right interface is to expose the `optional`, so for the 
callsites which currently do the equivalent of asserting I will just carry over 
an explicit assert to the new version.

I posted to 
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716/26
 to discuss the issue more generally, as at least some of the patches which 
moved code from `llvm::Optional` to `std::optional` accidentally dropped 
assertions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141968

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


[PATCH] D137113: [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

2023-01-18 Thread Bill Wendling via Phabricator via cfe-commits
void accepted this revision.
void added a comment.

Still LGTM :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137113

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


[PATCH] D135488: [codegen] Add StackFrameLayoutAnalysisPass

2023-01-18 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 490323.
paulkirth added a comment.
Herald added a subscriber: luke.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135488

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/Frontend/stack-layout-remark.c
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/InitializePasses.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/ARM/O3-pipeline.ll
  llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
  llvm/test/CodeGen/Generic/llc-start-stop.ll
  llvm/test/CodeGen/LoongArch/O0-pipeline.ll
  llvm/test/CodeGen/LoongArch/opt-pipeline.ll
  llvm/test/CodeGen/M68k/pipeline.ll
  llvm/test/CodeGen/PowerPC/O0-pipeline.ll
  llvm/test/CodeGen/PowerPC/O3-pipeline.ll
  llvm/test/CodeGen/RISCV/O0-pipeline.ll
  llvm/test/CodeGen/RISCV/O3-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll

Index: llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
@@ -0,0 +1,315 @@
+; Test remark output for stack-frame-layout
+
+; ensure basic output works
+; RUN: llc -mcpu=corei7 -O1 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s
+
+; check additional slots are displayed when stack is not optimized
+; RUN: llc -mcpu=corei7 -O0 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NO_COLORING
+
+; check more complex cases
+; RUN: llc %s -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=DEBUG
+
+; check output without debug info
+; RUN: opt %s -passes=strip -S | llc  -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=STRIPPED
+
+target triple = "x86_64-unknown-linux-gnu"
+
+@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
+declare i32 @printf(ptr, ...)
+
+; CHECK: Function: stackSizeWarning
+; CHECK: Offset: [SP-88], Type: Variable, Align: 16, Size: 80
+; CHECK:buffer @ frame-diags.c:30
+; NO_COLORING: Offset: [SP-168], Type: Variable, Align: 16, Size: 80
+; CHECK:buffer2 @ frame-diags.c:33
+define void @stackSizeWarning() {
+entry:
+  %buffer = alloca [80 x i8], align 16
+  %buffer2 = alloca [80 x i8], align 16
+  call void @llvm.dbg.declare(metadata ptr %buffer, metadata !25, metadata !DIExpression()), !dbg !39
+  call void @llvm.dbg.declare(metadata ptr %buffer2, metadata !31, metadata !DIExpression()), !dbg !40
+  ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+; BOTH: Function: cleanup_array
+; BOTH-Next:  Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: a @ dot.c:13
+; STRIPPED-NOT: a @ dot.c:13
+; BOTH:  Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+define void @cleanup_array(ptr %0) #1 {
+  %2 = alloca ptr, align 8
+  store ptr %0, ptr %2, align 8
+  call void @llvm.dbg.declare(metadata ptr %2, metadata !41, metadata !DIExpression()), !dbg !46
+  ret void
+}
+
+; BOTH: Function: cleanup_result
+; BOTH:  Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: res @ dot.c:21
+; STRIPPED-NOT: res @ dot.c:21
+; BOTH:  Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+define void @cleanup_result(ptr %0) #1 {
+  %2 = alloca ptr, align 8
+  store ptr %0, ptr %2, align 8
+  call void @llvm.dbg.declare(metadata ptr %2, metadata !47, metadata !DIExpression()), !dbg !51
+  ret void
+}
+
+; BOTH: Function: do_work
+; BOTH:  Offset: [SP+12], Type: Variable, Align: 8, Size: 4
+; DEBUG: out @ dot.c:32
+; STRIPPED-NOT: out @ dot.c:32
+; BOTH:  Offset: [SP+8], Type: Variable, Align: 4, Size: 4
+; BOTH:  Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: A @ dot.c:32
+; STRIPPED-NOT: A @ dot.c:32
+; BOTH:  Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+; BOTH:  Offset: [SP-12], Type: Variable, Align: 8, Size: 4
+; DEBUG: AB @ dot.c:38
+; STRIPPED-NOT: AB @ dot.c:38
+; BOTH:  Offset: [SP-16], Type: Variable, Align: 4, Size: 4
+; DEBUG: i @ dot.c:55
+; STRIPPED-NOT: i @ dot.c:55
+; BOTH:  Offset: [SP-20], Type: Variable, Align: 8, Size: 4
+; DEBUG: B @ dot.c:32
+; STRIPPED-NOT: B @ dot.c:32
+; BOTH:  Offset: [SP-24], Type: Variable, Align: 4, Size: 4
+; DEBUG: len @ dot.c:37
+; STRIPPED-NOT: len @ dot.c:37
+; BOTH:  Offset: 

[PATCH] D141968: [NFC] Consolidate llvm::CodeGenOpt::Level handling

2023-01-18 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 490321.
scott.linder marked 2 inline comments as done.
scott.linder added a comment.

- Fix return type of `getID`
- Fix mistakenly updated option help text
- Add back in missing `assert`s


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141968

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  flang/lib/Frontend/FrontendActions.cpp
  llvm/include/llvm/Support/CodeGen.h
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/lto/lto.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp

Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
@@ -138,20 +138,6 @@
   return createModuleFromMemoryBuffer(MB, Context);
 }
 
-CodeGenOpt::Level getCGOptLevel(unsigned OptLevel) {
-  switch (OptLevel) {
-  case 0:
-return CodeGenOpt::None;
-  case 1:
-return CodeGenOpt::Less;
-  case 2:
-return CodeGenOpt::Default;
-  case 3:
-return CodeGenOpt::Aggressive;
-  }
-  llvm_unreachable("Invalid optimization level");
-}
-
 OptimizationLevel getOptLevel(unsigned OptLevel) {
   switch (OptLevel) {
   case 0:
@@ -169,7 +155,10 @@
 Expected>
 createTargetMachine(Module , std::string CPU, unsigned OptLevel) {
   Triple TT(M.getTargetTriple());
-  CodeGenOpt::Level CGOptLevel = getCGOptLevel(OptLevel);
+  std::optional CGOptLevelOrNone =
+  CodeGenOpt::getLevel(OptLevel);
+  assert(CGOptLevelOrNone);
+  CodeGenOpt::Level CGOptLevel = *CGOptLevelOrNone;
 
   std::string Msg;
   const Target *T = TargetRegistry::lookupTarget(M.getTargetTriple(), Msg);
Index: llvm/tools/lto/lto.cpp
===
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -528,20 +528,10 @@
 if (OptLevel < '0' || OptLevel > '3')
   report_fatal_error("Optimization level must be between 0 and 3");
 CodeGen->setOptLevel(OptLevel - '0');
-switch (OptLevel) {
-case '0':
-  CodeGen->setCodeGenOptLevel(CodeGenOpt::None);
-  break;
-case '1':
-  CodeGen->setCodeGenOptLevel(CodeGenOpt::Less);
-  break;
-case '2':
-  CodeGen->setCodeGenOptLevel(CodeGenOpt::Default);
-  break;
-case '3':
-  CodeGen->setCodeGenOptLevel(CodeGenOpt::Aggressive);
-  break;
-}
+std::optional CGOptLevelOrNone =
+CodeGenOpt::getLevel(OptLevel - '0');
+assert(CGOptLevelOrNone);
+CodeGen->setCodeGenOptLevel(*CGOptLevelOrNone);
   }
   return wrap(CodeGen);
 }
Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -306,20 +306,9 @@
   Conf.Freestanding = EnableFreestanding;
   for (auto  : PassPlugins)
 Conf.PassPlugins.push_back(PluginFN);
-  switch (CGOptLevel) {
-  case '0':
-Conf.CGOptLevel = CodeGenOpt::None;
-break;
-  case '1':
-Conf.CGOptLevel = CodeGenOpt::Less;
-break;
-  case '2':
-Conf.CGOptLevel = CodeGenOpt::Default;
-break;
-  case '3':
-Conf.CGOptLevel = CodeGenOpt::Aggressive;
-break;
-  default:
+  if (auto Level = CodeGenOpt::parseLevel(CGOptLevel)) {
+Conf.CGOptLevel = *Level;
+  } else {
 llvm::errs() << "invalid cg optimization level: " << CGOptLevel << '\n';
 return 1;
   }
Index: llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
===
--- llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
+++ llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
@@ -42,7 +42,7 @@
 OptLevel("O",
  cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
   "(default = '-O2')"),
- cl::Prefix, cl::init(' '));
+ cl::Prefix, cl::init('2'));
 
 static cl::opt
 TargetTriple("mtriple", cl::desc("Override target triple for module"));
@@ -144,16 +144,12 @@
   std::string CPUStr = codegen::getCPUStr(),
   FeaturesStr = codegen::getFeaturesStr();
 
-  CodeGenOpt::Level OLvl = CodeGenOpt::Default;
-  switch (OptLevel) {
-  default:
+  CodeGenOpt::Level OLvl;
+  if (auto Level = CodeGenOpt::parseLevel(OptLevel)) {
+OLvl = *Level;
+  } else {
 errs() << argv[0] << ": invalid optimization level.\n";
 return 1;
-  case ' ': break;
-  case '0': OLvl = CodeGenOpt::None; break;
-  case '1': OLvl = CodeGenOpt::Less; break;
-  case '2': OLvl = CodeGenOpt::Default; break;
-  case '3': OLvl = 

[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked 3 inline comments as done.
jhuber6 added a comment.

In D140158#4063720 , @tra wrote:

> LGTM with few minor nits and questions.
>
> In D140158#4063689 , @jhuber6 wrote:
>
>> Addressing some comments. I don't know if there's a cleaner way to mess 
>> around with the `.cubin` nonsense. I liked symbolic links but that doesn't 
>> work on Windows.
>
> Can we do a copy or rename instead. That could be more portable.

I do a copy in this patch already. The problem is that if it's an internal 
link, e.g. `clang --target=nvptx64-nvidia-cuda foo.c bar.c`, then there will be 
no file to copy. The symbol link got around this by linking the files so once 
the `.o` was written the contents would automatically appear in the `.cubin`. 
The other approach is to detect this and use the correct names which is what 
this patch does, albeit a little jankily.




Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:518-521
+const InputInfo ,
+const InputInfoList ,
+const ArgList ,
+const char *LinkingOutput) const {

tra wrote:
> Nit: Looks like there are tabs.
I think that's just the diff showing that it was indented, there's no tabs in 
the file.



Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:448-450
+  // If we are invoking `nvlink` internally we need to output a `.cubin` file.
+  // Checking if the output is a temporary is the cleanest way to determine
+  // this. Putting this logic in `getInputFIlename` isn't an option because it

tra wrote:
> jhuber6 wrote:
> > tra wrote:
> > > Can't say that I like this approach. It heavily relies on "happens to 
> > > work".
> > > 
> > > Perhaps a better way to deal with this is to create the temporary GPU 
> > > object file name with ".cubin" extension to start with.
> > > 
> > > 
> > > 
> > As far as I know, the files are created independently of the tool-chains so 
> > I'm not sure if we'd be able to check there. The current way is to use 
> > `getInputFilename` but that doesn't have access to the compilation. As far 
> > as I can come up with there's the following solutions
> > 
> > - Do this and check the temp files
> > - Create a symbolic link if the file is empty (Doesn't work on Windows)
> > - Make a random global that's true if the Linker tool was built at some 
> > point
> Naming is hard. :-(
> 
> OK, let's add a FIXME to this comment and hope to get it fixed when NVIDIA's 
> tools become less obsessive about file extensions. I'll file a bug with them 
> to get the ball rolling on their end.
I would like that. it's a very simple check if you actually know how ELF 
headers work... Also while you're at it, ask for how they set their machine 
flags in Nvidia so we can display the arch via `llvm-readelf`.

I'll add some FIXME's.



Comment at: clang/lib/Driver/ToolChains/Cuda.h:196-197
+
+   void AddCudaIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 

tra wrote:
> jhuber6 wrote:
> > tra wrote:
> > > Nit: it's hard to tell whether the whitespace additions are spaces or 
> > > tabs. They show up as ">" to me which suggests it may be tabs. Just in 
> > > case it is indeed the case, please make sure to un-tabify the changes.
> > I think it's because the original file was formatted incorrectly, so all my 
> > new changes are formatted correctly. I'm somewhat more tempted to just 
> > clang-format it upstream and rebase it.
> Clang-formatting the file(s) and submitting that change separately before the 
> patch SGTM.
Already did :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 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.

LGTM with few minor nits and questions.

In D140158#4063689 , @jhuber6 wrote:

> Addressing some comments. I don't know if there's a cleaner way to mess 
> around with the `.cubin` nonsense. I liked symbolic links but that doesn't 
> work on Windows.

Can we do a copy or rename instead. That could be more portable.




Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:518-521
+const InputInfo ,
+const InputInfoList ,
+const ArgList ,
+const char *LinkingOutput) const {

Nit: Looks like there are tabs.



Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:448-450
+  // If we are invoking `nvlink` internally we need to output a `.cubin` file.
+  // Checking if the output is a temporary is the cleanest way to determine
+  // this. Putting this logic in `getInputFIlename` isn't an option because it

jhuber6 wrote:
> tra wrote:
> > Can't say that I like this approach. It heavily relies on "happens to work".
> > 
> > Perhaps a better way to deal with this is to create the temporary GPU 
> > object file name with ".cubin" extension to start with.
> > 
> > 
> > 
> As far as I know, the files are created independently of the tool-chains so 
> I'm not sure if we'd be able to check there. The current way is to use 
> `getInputFilename` but that doesn't have access to the compilation. As far as 
> I can come up with there's the following solutions
> 
> - Do this and check the temp files
> - Create a symbolic link if the file is empty (Doesn't work on Windows)
> - Make a random global that's true if the Linker tool was built at some point
Naming is hard. :-(

OK, let's add a FIXME to this comment and hope to get it fixed when NVIDIA's 
tools become less obsessive about file extensions. I'll file a bug with them to 
get the ball rolling on their end.



Comment at: clang/lib/Driver/ToolChains/Cuda.h:196-197
+
+   void AddCudaIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 

jhuber6 wrote:
> tra wrote:
> > Nit: it's hard to tell whether the whitespace additions are spaces or tabs. 
> > They show up as ">" to me which suggests it may be tabs. Just in case it is 
> > indeed the case, please make sure to un-tabify the changes.
> I think it's because the original file was formatted incorrectly, so all my 
> new changes are formatted correctly. I'm somewhat more tempted to just 
> clang-format it upstream and rebase it.
Clang-formatting the file(s) and submitting that change separately before the 
patch SGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

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


[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

doru1004 wrote:
> ABataev wrote:
> > doru1004 wrote:
> > > doru1004 wrote:
> > > > ABataev wrote:
> > > > > doru1004 wrote:
> > > > > > ABataev wrote:
> > > > > > > doru1004 wrote:
> > > > > > > > ABataev wrote:
> > > > > > > > > Do you really need to store the variable in the stack, is not 
> > > > > > > > > it enough just to check that the type of this variable is 
> > > > > > > > > BuiltinType::OMPIterator?
> > > > > > > > I'm happy to replace this if you think it will work. Is there 
> > > > > > > > an example somewhere in the code where I can get from the 
> > > > > > > > VarDecl to the build in type you mention?
> > > > > > > You have already a check 
> > > > > > > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> > > > > > >  you can you something similar for the variable
> > > > > > This didn't work and I had to revert to using the stack!
> > > > > Why?
> > > > I checked the output of the check and it was false when it should have 
> > > > been true! If you check the latest test that I added it showcases the 
> > > > source code and in the case of OpenMP 5.2 you can see that the message 
> > > > "only variable 'vvec' is allowed in map clauses of this 'omp declare 
> > > > mapper' directive" doesn't appear when a legal iteration variable is 
> > > > used.
> > > > If I used the check you suggested then the error message appears.
> > > > In the example you pasted the check is performed on a `Expr *`. In the 
> > > > case here, we only have VD which is a VarDecl.
> > > I am not sure how I can force it to have that type when it just doesn't. 
> > > Do you have any suggestions?
> > Did not get it. It still shall be of type builtintype::OMPIterator.
> The VD that we are checking for this builtin is coming from somewhere else in 
> the code, it is passed into the `Sema::DiagnoseUseOfDecl(` function. It's not 
> a VarDecl that is under the control of anything added in this patch.
This implementation is in line with the current checks for the declaration of 
the mapper variable. You store the declaration onto the stack so that you can 
compare it with the incoming VarDecl passed to the diagnose function.


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

https://reviews.llvm.org/D141871

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 490317.
jhuber6 added a comment.

Addressing some comments. I don't know if there's a cleaner way to mess around 
with the `.cubin` nonsense. I liked symbolic links but that doesn't work on 
Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c

Index: clang/test/Driver/cuda-cross-compiling.c
===
--- /dev/null
+++ clang/test/Driver/cuda-cross-compiling.c
@@ -0,0 +1,68 @@
+// Tests the driver when targeting the NVPTX architecture directly without a
+// host toolchain to perform CUDA mappings.
+
+// REQUIRES: nvptx-registered-target
+
+//
+// Test the generated phases when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=PHASES %s
+
+//  PHASES: 0: input, "[[INPUT:.+]]", c
+// PHASES-NEXT: 1: preprocessor, {0}, cpp-output
+// PHASES-NEXT: 2: compiler, {1}, ir
+// PHASES-NEXT: 3: backend, {2}, assembler
+// PHASES-NEXT: 4: assembler, {3}, object
+// PHASES-NEXT: 5: linker, {4}, image
+
+//
+// Test the generated bindings when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=BINDINGS %s
+
+//  BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that the '.o' files are converted to '.cubin' if produced internally.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=ARGS %s
+
+//  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that we emit '.o' files if compiled with '-c'
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -c -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=OBJECT %s
+
+//  OBJECT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// OBJECT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[OBJ:.+]].o" "[[PTX]].s" "-c"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that we copy input '.o' files to '.cubin' files when linking.
+//
+// RUN: touch %t.o
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINK %s
+
+// LINK: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "{{.*}}.cubin"
+
+//
+// Test the generated arguments default to a value with no architecture. 
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DEFAULT %s
+
+//  DEFAULT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_35" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// DEFAULT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_35" "--output-file" "[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// DEFAULT-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_35" {{.*}} "[[CUBIN]].cubin"
Index: clang/lib/Driver/ToolChains/Cuda.h
===
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -95,6 +95,19 @@
 
 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
 // assembly into a single output file.
+class LLVM_LIBRARY_VISIBILITY FatBinary : public Tool {
+public:
+  FatBinary(const ToolChain ) : Tool("NVPTX::Linker", "fatbinary", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+};
+
+// Runs nvlink, which links GPU object files ("cubin" files) into a single file.
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
 public:
   Linker(const ToolChain ) : Tool("NVPTX::Linker", "fatbinary", TC) {}
@@ -116,7 +129,48 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY 

[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

ABataev wrote:
> doru1004 wrote:
> > doru1004 wrote:
> > > ABataev wrote:
> > > > doru1004 wrote:
> > > > > ABataev wrote:
> > > > > > doru1004 wrote:
> > > > > > > ABataev wrote:
> > > > > > > > Do you really need to store the variable in the stack, is not 
> > > > > > > > it enough just to check that the type of this variable is 
> > > > > > > > BuiltinType::OMPIterator?
> > > > > > > I'm happy to replace this if you think it will work. Is there an 
> > > > > > > example somewhere in the code where I can get from the VarDecl to 
> > > > > > > the build in type you mention?
> > > > > > You have already a check 
> > > > > > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> > > > > >  you can you something similar for the variable
> > > > > This didn't work and I had to revert to using the stack!
> > > > Why?
> > > I checked the output of the check and it was false when it should have 
> > > been true! If you check the latest test that I added it showcases the 
> > > source code and in the case of OpenMP 5.2 you can see that the message 
> > > "only variable 'vvec' is allowed in map clauses of this 'omp declare 
> > > mapper' directive" doesn't appear when a legal iteration variable is used.
> > > If I used the check you suggested then the error message appears.
> > > In the example you pasted the check is performed on a `Expr *`. In the 
> > > case here, we only have VD which is a VarDecl.
> > I am not sure how I can force it to have that type when it just doesn't. Do 
> > you have any suggestions?
> Did not get it. It still shall be of type builtintype::OMPIterator.
The VD that we are checking for this builtin is coming from somewhere else in 
the code, it is passed into the `Sema::DiagnoseUseOfDecl(` function. It's not a 
VarDecl that is under the control of anything added in this patch.


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

https://reviews.llvm.org/D141871

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


[clang] debfa43 - [Clang][NFC] Clang-format CUDA toolchain file

2023-01-18 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-01-18T17:15:03-06:00
New Revision: debfa43117f458cd75e3d0a7b37f7622c7c67d40

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

LOG: [Clang][NFC] Clang-format CUDA toolchain file

Summary:
This file is not formatted, which makes further changes to it more
difficult. Format it.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index f2e575cd10592..b5e45ae4e0bfe 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -445,10 +445,10 @@ void NVPTX::Assembler::ConstructJob(Compilation , const 
JobAction ,
   if (std::string(OutputFileName) != std::string(Output.getFilename()))
 C.addTempFile(OutputFileName);
   CmdArgs.push_back(OutputFileName);
-  for (const auto& II : Inputs)
+  for (const auto  : Inputs)
 CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
 
-  for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
+  for (const auto  : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
 CmdArgs.push_back(Args.MakeArgString(A));
 
   bool Relocatable = false;
@@ -458,8 +458,8 @@ void NVPTX::Assembler::ConstructJob(Compilation , const 
JobAction ,
options::OPT_fnoopenmp_relocatable_target,
/*Default=*/true);
   else if (JA.isOffloading(Action::OFK_Cuda))
-Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
-   options::OPT_fno_gpu_rdc, /*Default=*/false);
+Relocatable = Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
+   /*Default=*/false);
 
   if (Relocatable)
 CmdArgs.push_back("-c");
@@ -513,7 +513,7 @@ void NVPTX::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
 CmdArgs.push_back("-g");
 
-  for (const auto& II : Inputs) {
+  for (const auto  : Inputs) {
 auto *A = II.getAction();
 assert(A->getInputs().size() == 1 &&
"Device offload action is expected to have a single input");
@@ -535,7 +535,7 @@ void NVPTX::Linker::ConstructJob(Compilation , const 
JobAction ,
",file=" + getToolChain().getInputFilename(II)));
   }
 
-  for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_fatbinary))
+  for (const auto  : Args.getAllArgValues(options::OPT_Xcuda_fatbinary))
 CmdArgs.push_back(Args.MakeArgString(A));
 
   const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary"));
@@ -619,8 +619,7 @@ std::string CudaToolChain::getInputFilename(const InputInfo 
) const {
 }
 
 void CudaToolChain::addClangTargetOptions(
-const llvm::opt::ArgList ,
-llvm::opt::ArgStringList ,
+const llvm::opt::ArgList , llvm::opt::ArgStringList ,
 Action::OffloadKind DeviceOffloadingKind) const {
   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
 
@@ -781,7 +780,8 @@ CudaToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList ,
 
   if (!BoundArch.empty()) {
 DAL->eraseArg(options::OPT_march_EQ);
-DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), 
BoundArch);
+DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
+  BoundArch);
   }
   return DAL;
 }

diff  --git a/clang/lib/Driver/ToolChains/Cuda.h 
b/clang/lib/Driver/ToolChains/Cuda.h
index 8ee99d4a3786b..e34a6dd43c5d0 100644
--- a/clang/lib/Driver/ToolChains/Cuda.h
+++ b/clang/lib/Driver/ToolChains/Cuda.h
@@ -82,29 +82,29 @@ namespace NVPTX {
 
 // Run ptxas, the NVPTX assembler.
 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
- public:
-   Assembler(const ToolChain ) : Tool("NVPTX::Assembler", "ptxas", TC) {}
+public:
+  Assembler(const ToolChain ) : Tool("NVPTX::Assembler", "ptxas", TC) {}
 
-   bool hasIntegratedCPP() const override { return false; }
+  bool hasIntegratedCPP() const override { return false; }
 
-   void ConstructJob(Compilation , const JobAction ,
- const InputInfo , const InputInfoList ,
- const llvm::opt::ArgList ,
- const char *LinkingOutput) const override;
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
 };
 
 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
 // assembly into a single output file.
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
- public:
-   Linker(const ToolChain ) : Tool("NVPTX::Linker", "fatbinary", TC) {}

[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

doru1004 wrote:
> ABataev wrote:
> > doru1004 wrote:
> > > ABataev wrote:
> > > > doru1004 wrote:
> > > > > ABataev wrote:
> > > > > > Do you really need to store the variable in the stack, is not it 
> > > > > > enough just to check that the type of this variable is 
> > > > > > BuiltinType::OMPIterator?
> > > > > I'm happy to replace this if you think it will work. Is there an 
> > > > > example somewhere in the code where I can get from the VarDecl to the 
> > > > > build in type you mention?
> > > > You have already a check 
> > > > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> > > >  you can you something similar for the variable
> > > This didn't work and I had to revert to using the stack!
> > Why?
> I checked the output of the check and it was false when it should have been 
> true! If you check the latest test that I added it showcases the source code 
> and in the case of OpenMP 5.2 you can see that the message "only variable 
> 'vvec' is allowed in map clauses of this 'omp declare mapper' directive" 
> doesn't appear when a legal iteration variable is used.
> If I used the check you suggested then the error message appears.
> In the example you pasted the check is performed on a `Expr *`. In the case 
> here, we only have VD which is a VarDecl.
I am not sure how I can force it to have that type when it just doesn't. Do you 
have any suggestions?


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

https://reviews.llvm.org/D141871

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


[PATCH] D141744: [Clang] Add lifetimebound attribute to std::move/std::forward

2023-01-18 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 490313.
alexander-shaposhnikov added a comment.

@aaron.ballman - thanks for the review, I've updated the release notes. 
Regarding LanguageExtensions.rst - somehow I  don't see any appropriate 
sections in  LanguageExtensions.rst (either about our builtin std::move and 
friends or [[clang::lifetimebound]]) - didn't change that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141744

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-lifetimebound.cpp
  clang/test/SemaCXX/builtin-std-move.cpp
  clang/test/SemaCXX/builtins.cpp

Index: clang/test/SemaCXX/builtins.cpp
===
--- clang/test/SemaCXX/builtins.cpp
+++ clang/test/SemaCXX/builtins.cpp
@@ -40,7 +40,7 @@
   struct U { int n : 5; } u;
   int *pbf = __builtin_addressof(u.n); // expected-error {{address of bit-field requested}}
 
-  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
+  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}} expected-warning {{temporary whose address is used as value of local variable 'ptmp' will be destroyed at the end of the full-expression}}
 }
 
 namespace function_start {
Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- clang/test/SemaCXX/builtin-std-move.cpp
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -85,7 +85,7 @@
 
 A _rval_as_lval() {
   std::forward(A()); // expected-warning {{const attribute}}
-  return std::forward(A()); // expected-note {{instantiation of}}
+  return std::forward(A()); // expected-note {{instantiation of}} expected-warning {{returning reference}}
 }
 
 struct B {};
Index: clang/test/SemaCXX/attr-lifetimebound.cpp
===
--- clang/test/SemaCXX/attr-lifetimebound.cpp
+++ clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -113,3 +113,77 @@
   std::map m;
   const std::string  = findOrDefault(m, "foo"s, "bar"s); // expected-warning {{temporary bound to local reference 'v'}}
 }
+
+// definitions for std::move, std::forward et al.
+namespace std {
+inline namespace foo {
+
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+
+template  constexpr typename remove_reference::type &(T &) {
+return static_cast::type>(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type ) {
+return static_cast(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type &) {
+return static_cast(t);
+}
+
+template  constexpr const T _const(T ) { return x; }
+
+template  struct PickRef {
+using type = typename remove_reference::type &;
+};
+template  struct PickRef {
+using type = typename remove_reference::type &&;
+};
+
+template 
+auto move_if_noexcept(T ) ->
+typename PickRef(t)))>::type {
+return static_cast<
+typename PickRef(t)))>::type>(t);
+}
+
+template  T *addressof(T ) {
+return reinterpret_cast(
+_cast(reinterpret_cast(arg)));
+}
+
+} // namespace foo
+} // namespace std
+
+namespace move_forward_et_al_examples {
+  struct S {
+S () [[clang::lifetimebound]] { return *this; }
+  };
+
+  S & = std::move(S{}); // expected-warning {{temporary bound to local reference 'Move' will be destroyed at the end of the full-expression}}
+  S MoveOk = std::move(S{});
+
+  S & = std::forward(S{}); // expected-warning {{temporary bound to local reference 'Forward' will be destroyed at the end of the full-expression}}
+  S ForwardOk = std::forward(S{});
+
+  const S  = std::as_const(S{}.self()); // expected-warning {{temporary bound to local reference 'Const' will be destroyed at the end of the full-expression}}
+  const S ConstOk = std::as_const(S{}.self());
+
+  S & = std::move_if_noexcept(S{}.self()); // expected-warning {{temporary bound to local reference 'MoveIfNoExcept' will be destroyed at the end of the full-expression}}
+  S MoveIfNoExceptOk = std::move_if_noexcept(S{}.self());
+
+  S *AddressOf = std::addressof(S{}.self()); // expected-warning {{temporary whose address is used as value of local variable 'AddressOf' will be destroyed at the end of the full-expression}}
+  S X;
+  S *AddressOfOk = std::addressof(X);
+} // namespace move_forward_et_al_examples
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16182,6 +16182,24 @@
 default:
   break;
 }
+
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case 

[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

doru1004 wrote:
> ABataev wrote:
> > doru1004 wrote:
> > > ABataev wrote:
> > > > doru1004 wrote:
> > > > > ABataev wrote:
> > > > > > Do you really need to store the variable in the stack, is not it 
> > > > > > enough just to check that the type of this variable is 
> > > > > > BuiltinType::OMPIterator?
> > > > > I'm happy to replace this if you think it will work. Is there an 
> > > > > example somewhere in the code where I can get from the VarDecl to the 
> > > > > build in type you mention?
> > > > You have already a check 
> > > > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> > > >  you can you something similar for the variable
> > > This didn't work and I had to revert to using the stack!
> > Why?
> I checked the output of the check and it was false when it should have been 
> true! If you check the latest test that I added it showcases the source code 
> and in the case of OpenMP 5.2 you can see that the message "only variable 
> 'vvec' is allowed in map clauses of this 'omp declare mapper' directive" 
> doesn't appear when a legal iteration variable is used.
> If I used the check you suggested then the error message appears.
> In the example you pasted the check is performed on a `Expr *`. In the case 
> here, we only have VD which is a VarDecl.
Did not get it. It still shall be of type builtintype::OMPIterator.


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

https://reviews.llvm.org/D141871

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


[PATCH] D141356: [-Wunsafe-buffer-usage] Group diagnostics by variable

2023-01-18 Thread Jan Korous 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 rG237ca436adf4: [-Wunsafe-buffer-usage] Group diagnostics by 
variable (authored by jkorous).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D141356?vs=489936=490308#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141356

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/unsafe-buffer-usage-diag-type.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -1,4 +1,10 @@
-// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fblocks -include %s -verify %s
+// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage -fblocks -include %s -verify %s
+
+// RUN: %clang -x c++ -fsyntax-only -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s
+// RUN: %clang_cc1 -std=c++11 -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s
+// RUN: %clang_cc1 -std=c++20 -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s
+// CHECK-NOT: [-Wunsafe-buffer-usage]
+
 #ifndef INCLUDED
 #define INCLUDED
 #pragma clang system_header
@@ -18,41 +24,50 @@
 
 #else
 
-void testIncrement(char *p) {
-  ++p; // expected-warning{{unchecked operation on raw buffer in expression}}
-  p++; // expected-warning{{unchecked operation on raw buffer in expression}}
-  --p; // expected-warning{{unchecked operation on raw buffer in expression}}
-  p--; // expected-warning{{unchecked operation on raw buffer in expression}}
+void testIncrement(char *p) { // expected-warning{{'p' is an unsafe pointer used for buffer access}}
+  ++p; // expected-note{{used in pointer arithmetic here}}
+  p++; // expected-note{{used in pointer arithmetic here}}
+  --p; // expected-note{{used in pointer arithmetic here}}
+  p--; // expected-note{{used in pointer arithmetic here}}
 }
 
 void * voidPtrCall(void);
 char * charPtrCall(void);
 
 void testArraySubscripts(int *p, int **pp) {
-  foo(p[1], // expected-warning{{unchecked operation on raw buffer in expression}}
-  pp[1][1], // expected-warning2{{unchecked operation on raw buffer in expression}}
-  1[1[pp]], // expected-warning2{{unchecked operation on raw buffer in expression}}
-  1[pp][1]  // expected-warning2{{unchecked operation on raw buffer in expression}}
+// expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
+// expected-warning@-2{{'pp' is an unsafe pointer used for buffer access}}
+  foo(p[1], // expected-note{{used in buffer access here}}
+  pp[1][1], // expected-note{{used in buffer access here}}
+// expected-warning@-1{{unsafe buffer access}}
+  1[1[pp]], // expected-note{{used in buffer access here}}
+// expected-warning@-1{{unsafe buffer access}}
+  1[pp][1]  // expected-note{{used in buffer access here}}
+// expected-warning@-1{{unsafe buffer access}}
   );
 
-  if (p[3]) {   // expected-warning{{unchecked operation on raw buffer in expression}}
+  if (p[3]) {   // expected-note{{used in buffer access here}}
 void * q = p;
 
-foo(((int*)q)[10]); // expected-warning{{unchecked operation on raw buffer in expression}}
+foo(((int*)q)[10]); // expected-warning{{unsafe buffer access}}
   }
 
-  foo(((int*)voidPtrCall())[3], // expected-warning{{unchecked operation on raw buffer in expression}}
-  3[(int*)voidPtrCall()],   // expected-warning{{unchecked operation on raw buffer in expression}}
-  charPtrCall()[3], // expected-warning{{unchecked operation on raw buffer in expression}}
-  3[charPtrCall()]  // expected-warning{{unchecked operation on raw buffer in expression}}
+  foo(((int*)voidPtrCall())[3], // expected-warning{{unsafe buffer access}}
+  3[(int*)voidPtrCall()],   // expected-warning{{unsafe buffer access}}
+  charPtrCall()[3], // expected-warning{{unsafe buffer access}}
+  3[charPtrCall()]  // expected-warning{{unsafe buffer access}}
   );
 
-  int a[10], b[10][10];
+int a[10];  // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}}
+int b[10][10];  // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}}
 
-  foo(a[1], 1[a], // expected-warning2{{unchecked operation on 

[clang] 237ca43 - [-Wunsafe-buffer-usage] Group diagnostics by variable

2023-01-18 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2023-01-18T15:00:22-08:00
New Revision: 237ca436adf48c72821afd9fa6e031ec1d4a0420

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

LOG: [-Wunsafe-buffer-usage] Group diagnostics by variable

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

Added: 
clang/test/SemaCXX/unsafe-buffer-usage-diag-type.cpp

Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 6a4930f40bdff..e3f87cd0f3660 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -31,7 +31,8 @@ class UnsafeBufferUsageHandler {
   using FixItList = llvm::SmallVectorImpl;
 
   /// Invoked when an unsafe operation over raw pointers is found.
-  virtual void handleUnsafeOperation(const Stmt *Operation) = 0;
+  virtual void handleUnsafeOperation(const Stmt *Operation,
+ bool IsRelatedToDecl) = 0;
 
   /// Invoked when a fix is suggested against a variable.
   virtual void handleFixableVariable(const VarDecl *Variable,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 02a6c2c4214e8..2ba52728e9485 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11778,12 +11778,16 @@ def err_loongarch_builtin_requires_la64 : Error<
   "this builtin requires target: loongarch64">;
 
 // Unsafe buffer usage diagnostics.
-def warn_unsafe_buffer_expression : Warning<
-  "unchecked operation on raw buffer in expression">,
-  InGroup, DefaultIgnore;
 def warn_unsafe_buffer_variable : Warning<
-  "variable %0 participates in unchecked buffer operations">,
+  "%0 is an %select{unsafe pointer used for buffer access|unsafe buffer that "
+  "does not perform bounds checks}1">,
+  InGroup, DefaultIgnore;
+def warn_unsafe_buffer_operation : Warning<
+  "%select{unsafe pointer operation|unsafe pointer arithmetic|"
+  "unsafe buffer access}0">,
   InGroup, DefaultIgnore;
+def note_unsafe_buffer_operation : Note<
+  "used%select{| in pointer arithmetic| in buffer access}0 here">;
 def err_loongarch_builtin_requires_la32 : Error<
   "this builtin requires target: loongarch32">;
 } // end of sema component.

diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index c75eaba820c42..ec2a09e89989b 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -680,17 +680,16 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
   // FIXME Detect overlapping FixIts.
 
   for (const auto  : UnsafeOps.noVar) {
-Handler.handleUnsafeOperation(G->getBaseStmt());
+Handler.handleUnsafeOperation(G->getBaseStmt(), /*IsRelatedToDecl=*/false);
   }
 
   for (const auto &[VD, WarningGadgets] : UnsafeOps.byVar) {
 auto FixItsIt = FixItsForVariable.find(VD);
-if (FixItsIt != FixItsForVariable.end()) {
-  Handler.handleFixableVariable(VD, std::move(FixItsIt->second));
-} else {
-  for (const auto  : WarningGadgets) {
-Handler.handleUnsafeOperation(G->getBaseStmt());
-  }
+Handler.handleFixableVariable(VD, FixItsIt != FixItsForVariable.end()
+  ? std::move(FixItsIt->second)
+  : FixItList{});
+for (const auto  : WarningGadgets) {
+  Handler.handleUnsafeOperation(G->getBaseStmt(), 
/*IsRelatedToDecl=*/true);
 }
   }
 }

diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 08cf45e5865c0..4530154ac9447 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2153,12 +2153,15 @@ class UnsafeBufferUsageReporter : public 
UnsafeBufferUsageHandler {
 public:
   UnsafeBufferUsageReporter(Sema ) : S(S) {}
 
-  void handleUnsafeOperation(const Stmt *Operation) override {
+  void handleUnsafeOperation(const Stmt *Operation,
+ bool IsRelatedToDecl) override {
 SourceLocation Loc;
 SourceRange Range;
+unsigned MsgParam = 0;
 if (const auto *ASE = dyn_cast(Operation)) {
   Loc = ASE->getBase()->getExprLoc();
   Range = ASE->getBase()->getSourceRange();
+  MsgParam = 2;
 } else if (const auto *BO = 

[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-18 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1764
+  the ``external_source_symbol`` attribute with
+  ``__has_attribute(external_source_symbol_with_usr)``.
+

aaron.ballman wrote:
> erichkeane wrote:
> > arphaman wrote:
> > > aaron.ballman wrote:
> > > > erichkeane wrote:
> > > > > I don't think we can do this.  __has_attribute needs to take the 
> > > > > actual name of the attribute.
> > > > +1
> > > `__has_attribute(external_source_symbol)` already works but it wouldn't 
> > > help here as it doesn't tell whether the attribute supports USR or not. 
> > > Are you saying I should come up with a totally new attribute that accepts 
> > > USR? That was originally why I had the `__has_feature` check.
> > The typical way of doing this in the standard is to have 
> > __has_c_attribute/__has_cpp_attribute return a larger non-zero value for 
> > the normal attribute.
> > 
> > I suspect we should extend `__has_attribute` to do something similar (that 
> > is, allowing Feature Test Macros' for it).  Aaron, WDYT?
> > The typical way of doing this in the standard is to have 
> > has_c_attribute/has_cpp_attribute return a larger non-zero value for the 
> > normal attribute.
> 
> Which we expose for the CXX11 and C2X spellings in Attr.td, but don't expose 
> for the `Clang` spelling (easy enough to change).
> 
> > I suspect we should extend __has_attribute to do something similar (that 
> > is, allowing Feature Test Macros' for it). Aaron, WDYT?
> 
> +1, if we don't already do that. This should be handled entirely within 
> Attr.td and ClangAttrEmitter.cpp for a generic solution.
sounds good, I will look into that and will update this patch.


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

https://reviews.llvm.org/D141324

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


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

2023-01-18 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D136651#4063597 , @friss wrote:

> In D136651#4060071 , @lebedev.ri 
> wrote:
>
>> Docs still missing.
>
> Sorry @lebedev.ri I missed your earlier comment about this. What format of 
> doc would you like to see? A more elaborate comment in the tool's source or 
> something else?

Right now it's impossible to discover that tool unless you already know it 
exists (or it's mentioned in some xcode doc, i guess)
It should have it's own description in it's `--help`, and ideally an `.rst` 
documentation page in `docs`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

ABataev wrote:
> doru1004 wrote:
> > ABataev wrote:
> > > doru1004 wrote:
> > > > ABataev wrote:
> > > > > Do you really need to store the variable in the stack, is not it 
> > > > > enough just to check that the type of this variable is 
> > > > > BuiltinType::OMPIterator?
> > > > I'm happy to replace this if you think it will work. Is there an 
> > > > example somewhere in the code where I can get from the VarDecl to the 
> > > > build in type you mention?
> > > You have already a check 
> > > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> > >  you can you something similar for the variable
> > This didn't work and I had to revert to using the stack!
> Why?
I checked the output of the check and it was false when it should have been 
true! If you check the latest test that I added it showcases the source code 
and in the case of OpenMP 5.2 you can see that the message "only variable 
'vvec' is allowed in map clauses of this 'omp declare mapper' directive" 
doesn't appear when a legal iteration variable is used.
If I used the check you suggested then the error message appears.
In the example you pasted the check is performed on a `Expr *`. In the case 
here, we only have VD which is a VarDecl.


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

https://reviews.llvm.org/D141871

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


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

2023-01-18 Thread Frederic Riss via Phabricator via cfe-commits
friss added a subscriber: lebedev.ri.
friss added a comment.

In D136651#4060071 , @lebedev.ri 
wrote:

> Docs still missing.

Sorry @lebedev.ri I missed your earlier comment about this. What format of doc 
would you like to see? A more elaborate comment in the tool's source or 
something else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-01-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D141451#4063519 , @dblaikie wrote:

> In D141451#4063504 , 
> @nickdesaulniers wrote:
>
>> In D141451#4063335 , @dblaikie 
>> wrote:
>>
>>> In D141451#4063151 , 
>>> @nickdesaulniers wrote:
>>>
 In D141451#4045658 , @efriedma 
 wrote:

> clang has a "LocTrackingOnly" setting for debug info, which emits 
> DILocation info into the IR, but emits a marker into the DICompileUnit to 
> skip emitting the .debug_info in the backend.  We currently use it for 
> -Rpass.  We don't do this by default, I think to save compile time.

 Specifically `emissionKind: NoDebug`, example:

 `!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: 
 "clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
 7b433e026498cf4176931b2407baece1d5060e16)", isOptimized: true, 
 runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, 
 nameTableKind: None)`

 Though should the frontend be setting codegen options when parsing? Would 
 the idea be to try to re-set `OPT_debug_info_kind_EQ` when clang codegen's 
 IR for a function with such an attribute?
>>>
>>> Probably turn on `emissionKind: NoDebug` whenever the warning is enabled?
>>
>> So this warning is default enabled, IIRC.
>
> Then it might be a broader question about whether this extra info is 
> acceptable to turn on by default, and if not, maybe an extra flag would be 
> needed to say "give me extra info in this diagnostic", basically (or a 
> separate warning flag that's off by default) - some perf metrics might help 
> indicate whether the extra info is cheap enough.

The implementation as it stands is zero cost in the sense that if 
`__attribute__((warning("")))` or `__attribute__((error("")))` aren't used in 
the source code, there is ZERO cost in IR.  Additional metadata is only created 
when inlining occurs (which might not happen if optimizations weren't enabled) 
where callsites to such functions exist (unlikely), and if the call site is 
optimized away, the metadata should be deleted (at least, I imagine that's how 
metadata works in LLVM.  I should actually verify that's the case, then 
probably add such verification as a test to this patch, perhaps.

> I'm still a bit confused/not following about the "Let me see if I can create 
> DILocation without line or column values." - why do you want to create that?

You're the one that asked  if if I 
can reuse existing metadata nodes, specifically:

>> It'd be nice not to invent a new way of tracking inlining separate from the 
>> way debug info does this

So I could emit DILocation and DISubprogram metadata rather than the custom 
metadata nodes as I'm doing in this diff.  I just wouldn't be able to 
synthesize line or column info for the callsites, since the frontend may not 
have ever produced it in the first place.  Such an approach would be emitting 
`DILocation`+`DISubprogram` from the backend, not the frontend; the backend 
doesn't have line+column info unless debugging was enabled in the first place 
(which it probably wasn't).

I don't want to pessimistically emit these always from the frontend with 
precise line+column info. That would be so pessimistic for the common case 
where you probably never encounter functions with such attributes in a given TU.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


Re: [clang] a033dbb - [Clang] Give Clang the ability to use a shared stat cache

2023-01-18 Thread Roman Lebedev via cfe-commits
Looks like my comments on the review got completely ignored and not
even acknowledged.

On Thu, Jan 19, 2023 at 1:35 AM Fred Riss via cfe-commits
 wrote:
>
>
> Author: Fred Riss
> Date: 2023-01-18T14:31:27-08:00
> New Revision: a033dbbe5c43247b60869b008e67ed86ed230eaa
>
> URL: 
> https://github.com/llvm/llvm-project/commit/a033dbbe5c43247b60869b008e67ed86ed230eaa
> DIFF: 
> https://github.com/llvm/llvm-project/commit/a033dbbe5c43247b60869b008e67ed86ed230eaa.diff
>
> LOG: [Clang] Give Clang the ability to use a shared stat cache
>
> Every Clang instance uses an internal FileSystemStatCache to avoid
> stating the same content multiple times. However, different instances
> of Clang will contend for filesystem access for their initial stats
> during HeaderSearch or module validation.
>
> On some workloads, the time spent in the kernel in these concurrent
> stat calls has been measured to be over 20% of the overall compilation
> time. This is extremly wassteful when most of the stat calls target
> mostly immutable content like a SDK.
>
> This commit introduces a new tool `clang-stat-cache` able to generate
> an OnDiskHashmap containing the stat data for a given filesystem
> hierarchy.
>
> The driver part of this has been modeled after -ivfsoverlay given
> the similarities with what it influences. It introduces a new
> -ivfsstatcache driver option to instruct Clang to use a stat cache
> generated by `clang-stat-cache`. These stat caches are inserted at
> the bottom of the VFS stack (right above the real filesystem).
>
> Differential Revision: https://reviews.llvm.org/D136651
>
> Added:
> clang/test/Driver/vfsstatcache.c
> clang/test/clang-stat-cache/cache-effects.c
> clang/test/clang-stat-cache/errors.test
> clang/tools/clang-stat-cache/CMakeLists.txt
> clang/tools/clang-stat-cache/clang-stat-cache.cpp
> llvm/include/llvm/Support/StatCacheFileSystem.h
> llvm/lib/Support/StatCacheFileSystem.cpp
>
> Modified:
> clang/include/clang/Basic/DiagnosticFrontendKinds.td
> clang/include/clang/Driver/Options.td
> clang/include/clang/Frontend/CompilerInvocation.h
> clang/include/clang/Lex/HeaderSearchOptions.h
> clang/lib/Frontend/ASTUnit.cpp
> clang/lib/Frontend/CompilerInvocation.cpp
> clang/test/CMakeLists.txt
> clang/tools/CMakeLists.txt
> llvm/lib/Support/CMakeLists.txt
> llvm/unittests/Support/VirtualFileSystemTest.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
> b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
> index d0f672ae5a1bd..e106858688ac7 100644
> --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
> +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
> @@ -256,6 +256,11 @@ def err_test_module_file_extension_version : Error<
>"test module file extension '%0' has
> diff erent version (%1.%2) than expected "
>"(%3.%4)">;
>
> +def err_missing_vfs_stat_cache_file : Error<
> +  "stat cache file '%0' not found">, DefaultFatal;
> +def err_invalid_vfs_stat_cache : Error<
> +  "invalid stat cache file '%0'">, DefaultFatal;
> +
>  def err_missing_vfs_overlay_file : Error<
>"virtual filesystem overlay file '%0' not found">, DefaultFatal;
>  def err_invalid_vfs_overlay : Error<
>
> diff  --git a/clang/include/clang/Driver/Options.td 
> b/clang/include/clang/Driver/Options.td
> index ba49b335cf287..9334e6319d57b 100644
> --- a/clang/include/clang/Driver/Options.td
> +++ b/clang/include/clang/Driver/Options.td
> @@ -3357,6 +3357,8 @@ def iwithsysroot : JoinedOrSeparate<["-"], 
> "iwithsysroot">, Group
>HelpText<"Add directory to SYSTEM include search path, "
> "absolute paths are relative to -isysroot">, 
> MetaVarName<"">,
>Flags<[CC1Option]>;
> +def ivfsstatcache : JoinedOrSeparate<["-"], "ivfsstatcache">, 
> Group, Flags<[CC1Option]>,
> +  HelpText<"Use the stat data cached in file instead of doing filesystem 
> syscalls. See clang-stat-cache utility.">;
>  def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, 
> Group, Flags<[CC1Option]>,
>HelpText<"Overlay the virtual filesystem described by file over the real 
> file system">;
>  def imultilib : Separate<["-"], "imultilib">, Group;
>
> diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
> b/clang/include/clang/Frontend/CompilerInvocation.h
> index 254f048ed3c7e..9cc6aa5c4d8a1 100644
> --- a/clang/include/clang/Frontend/CompilerInvocation.h
> +++ b/clang/include/clang/Frontend/CompilerInvocation.h
> @@ -296,6 +296,7 @@ IntrusiveRefCntPtr 
> createVFSFromCompilerInvocation(
>
>  IntrusiveRefCntPtr
>  createVFSFromOverlayFiles(ArrayRef VFSOverlayFiles,
> +  ArrayRef VFSStatCacheFiles,
>DiagnosticsEngine ,
>IntrusiveRefCntPtr BaseFS);
>
>
> diff  --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
> 

[PATCH] D141954: Forbid implicit conversion of constraint expression to bool

2023-01-18 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:377-380
+  SubstitutedExpression = ImplicitCastExpr::Create(
+  S.Context, SubstitutedExpression.get()->getType(),
+  CK_LValueToRValue, SubstitutedExpression.get(),
+  /*BasePath=*/nullptr, VK_PRValue, FPOptionsOverride());

erichkeane wrote:
> tahonermann wrote:
> > `ImplicitCastExpr::Create()` has the following assertion. I wonder if we 
> > need to guard against this here.
> >   clang/lib/AST/Expr.cpp:
> >   2073   assert((Kind != CK_LValueToRValue ||
> >   2074   !(T->isNullPtrType() || T->getAsCXXRecordDecl())) &&
> >   2075  "invalid type for lvalue-to-rvalue conversion");
> > 
> > Or perhaps it would be better to call `Sema::DefaultLvalueConversion()` 
> > here?
> I don't think we want all the baggage that DefaultLvalueConversion gets us, 
> including diagnostics/etc.  That assert IS concerning though... I presume we 
> can come up with something to hit that. 
> 
> It DOES look like that DefeaultLValue conversion replaces the nullptrtypes 
> with a NullToPointer cast, so perhaps I should do that, and doesn't do 
> anything with a record type.
I'm surprised the additional checks for `nullptr` aren't tripping that assert; 
it looks to me like it should. Any ideas?


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

https://reviews.llvm.org/D141954

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


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

2023-01-18 Thread Frederic Riss 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 rGa033dbbe5c43: [Clang] Give Clang the ability to use a shared 
stat cache (authored by friss).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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

Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -14,9 +14,11 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/StatCacheFileSystem.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 
@@ -3228,3 +3230,306 @@
 "  DummyFileSystem (RecursiveContents)\n",
 Output);
 }
+
+class StatCacheFileSystemTest : public ::testing::Test {
+public:
+  void SetUp() override {}
+
+  template 
+  void createStatCacheFileSystem(
+  StringRef OutputFile, StringRef BaseDir, bool IsCaseSensitive,
+  IntrusiveRefCntPtr ,
+  StringCollection ,
+  IntrusiveRefCntPtr Lower = new ErrorDummyFileSystem(),
+  uint64_t ValidityToken = 0) {
+sys::fs::file_status s;
+status(BaseDir, s);
+vfs::StatCacheFileSystem::StatCacheWriter Generator(
+BaseDir, s, IsCaseSensitive, ValidityToken);
+std::error_code ErrorCode;
+
+Result.reset();
+
+// Base path should be present in the stat cache.
+Filenames.push_back(std::string(BaseDir));
+
+for (sys::fs::recursive_directory_iterator I(BaseDir, ErrorCode), E;
+ I != E && !ErrorCode; I.increment(ErrorCode)) {
+  Filenames.push_back(I->path());
+  StringRef Path(Filenames.back().c_str());
+  status(Path, s);
+  Generator.addEntry(Path, s);
+}
+
+{
+  raw_fd_ostream StatCacheFile(OutputFile, ErrorCode);
+  ASSERT_FALSE(ErrorCode);
+  Generator.writeStatCache(StatCacheFile);
+}
+
+loadCacheFile(OutputFile, ValidityToken, Lower, Result);
+  }
+
+  void loadCacheFile(StringRef OutputFile, uint64_t ExpectedValidityToken,
+ IntrusiveRefCntPtr Lower,
+ IntrusiveRefCntPtr ) {
+auto ErrorOrBuffer = MemoryBuffer::getFile(OutputFile);
+EXPECT_TRUE(ErrorOrBuffer);
+StringRef CacheBaseDir;
+bool IsCaseSensitive;
+bool VersionMatch;
+uint64_t FileValidityToken;
+auto E = vfs::StatCacheFileSystem::validateCacheFile(
+(*ErrorOrBuffer)->getMemBufferRef(), CacheBaseDir, IsCaseSensitive,
+VersionMatch, FileValidityToken);
+ASSERT_FALSE(E);
+EXPECT_TRUE(VersionMatch);
+EXPECT_EQ(FileValidityToken, ExpectedValidityToken);
+auto ExpectedCache =
+vfs::StatCacheFileSystem::create(std::move(*ErrorOrBuffer), Lower);
+ASSERT_FALSE(ExpectedCache.takeError());
+Result = *ExpectedCache;
+  }
+
+  template 
+  void
+  compareStatCacheToRealFS(IntrusiveRefCntPtr CacheFS,
+   const StringCollection ) {
+IntrusiveRefCntPtr RealFS = vfs::getRealFileSystem();
+
+for (auto  : Files) {
+  auto ErrorOrStatus1 = RealFS->status(File);
+  auto ErrorOrStatus2 = CacheFS->status(File);
+
+  EXPECT_EQ((bool)ErrorOrStatus1, (bool)ErrorOrStatus2);
+  if (!ErrorOrStatus1 || !ErrorOrStatus2)
+continue;
+
+  vfs::Status s1 = *ErrorOrStatus1, s2 = *ErrorOrStatus2;
+  EXPECT_EQ(s1.getName(), s2.getName());
+  EXPECT_EQ(s1.getType(), s2.getType());
+  EXPECT_EQ(s1.getPermissions(), s2.getPermissions());
+  EXPECT_EQ(s1.getLastModificationTime(), s2.getLastModificationTime());
+  EXPECT_EQ(s1.getUniqueID(), s2.getUniqueID());
+  EXPECT_EQ(s1.getUser(), s2.getUser());
+  EXPECT_EQ(s1.getGroup(), s2.getGroup());
+  EXPECT_EQ(s1.getSize(), s2.getSize());
+}
+  }
+};
+
+TEST_F(StatCacheFileSystemTest, Basic) {
+  TempDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
+  TempDir _a(TestDirectory.path("a"));
+  TempFile _ab(TestDirectory.path("a/b"));
+  

[clang] a033dbb - [Clang] Give Clang the ability to use a shared stat cache

2023-01-18 Thread Fred Riss via cfe-commits

Author: Fred Riss
Date: 2023-01-18T14:31:27-08:00
New Revision: a033dbbe5c43247b60869b008e67ed86ed230eaa

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

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

Every Clang instance uses an internal FileSystemStatCache to avoid
stating the same content multiple times. However, different instances
of Clang will contend for filesystem access for their initial stats
during HeaderSearch or module validation.

On some workloads, the time spent in the kernel in these concurrent
stat calls has been measured to be over 20% of the overall compilation
time. This is extremly wassteful when most of the stat calls target
mostly immutable content like a SDK.

This commit introduces a new tool `clang-stat-cache` able to generate
an OnDiskHashmap containing the stat data for a given filesystem
hierarchy.

The driver part of this has been modeled after -ivfsoverlay given
the similarities with what it influences. It introduces a new
-ivfsstatcache driver option to instruct Clang to use a stat cache
generated by `clang-stat-cache`. These stat caches are inserted at
the bottom of the VFS stack (right above the real filesystem).

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

Added: 
clang/test/Driver/vfsstatcache.c
clang/test/clang-stat-cache/cache-effects.c
clang/test/clang-stat-cache/errors.test
clang/tools/clang-stat-cache/CMakeLists.txt
clang/tools/clang-stat-cache/clang-stat-cache.cpp
llvm/include/llvm/Support/StatCacheFileSystem.h
llvm/lib/Support/StatCacheFileSystem.cpp

Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/CompilerInvocation.h
clang/include/clang/Lex/HeaderSearchOptions.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CMakeLists.txt
clang/tools/CMakeLists.txt
llvm/lib/Support/CMakeLists.txt
llvm/unittests/Support/VirtualFileSystemTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index d0f672ae5a1bd..e106858688ac7 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -256,6 +256,11 @@ def err_test_module_file_extension_version : Error<
   "test module file extension '%0' has 
diff erent version (%1.%2) than expected "
   "(%3.%4)">;
 
+def err_missing_vfs_stat_cache_file : Error<
+  "stat cache file '%0' not found">, DefaultFatal;
+def err_invalid_vfs_stat_cache : Error<
+  "invalid stat cache file '%0'">, DefaultFatal;
+
 def err_missing_vfs_overlay_file : Error<
   "virtual filesystem overlay file '%0' not found">, DefaultFatal;
 def err_invalid_vfs_overlay : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ba49b335cf287..9334e6319d57b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3357,6 +3357,8 @@ def iwithsysroot : JoinedOrSeparate<["-"], 
"iwithsysroot">, Group
   HelpText<"Add directory to SYSTEM include search path, "
"absolute paths are relative to -isysroot">, 
MetaVarName<"">,
   Flags<[CC1Option]>;
+def ivfsstatcache : JoinedOrSeparate<["-"], "ivfsstatcache">, 
Group, Flags<[CC1Option]>,
+  HelpText<"Use the stat data cached in file instead of doing filesystem 
syscalls. See clang-stat-cache utility.">;
 def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, 
Group, Flags<[CC1Option]>,
   HelpText<"Overlay the virtual filesystem described by file over the real 
file system">;
 def imultilib : Separate<["-"], "imultilib">, Group;

diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 254f048ed3c7e..9cc6aa5c4d8a1 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -296,6 +296,7 @@ IntrusiveRefCntPtr 
createVFSFromCompilerInvocation(
 
 IntrusiveRefCntPtr
 createVFSFromOverlayFiles(ArrayRef VFSOverlayFiles,
+  ArrayRef VFSStatCacheFiles,
   DiagnosticsEngine ,
   IntrusiveRefCntPtr BaseFS);
 

diff  --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
b/clang/include/clang/Lex/HeaderSearchOptions.h
index 6436a9b3bde20..548f7d4493de4 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -181,6 +181,9 @@ class HeaderSearchOptions {
   /// of computing the module hash.
   llvm::SmallSetVector ModulesIgnoreMacros;
 
+  /// The set of user-provided stat cache files.
+  

[PATCH] D141340: [-Wunsafe-buffer-usage] Use relevant source locations for warnings

2023-01-18 Thread Jan Korous 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 rG39a63fc7fe98: [-Wunsafe-buffer-usage] Use relevant source 
locations for warnings (authored by jkorous).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141340

Files:
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -Wno-everything -Wunsafe-buffer-usage -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s
+
+void foo(int i) {
+  int * ptr;
+
+
+  ptr++;
+  // CHECK-DAG: {7:3-7:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr--;
+  // CHECK-DAG: {9:3-9:6}{{.*}}[-Wunsafe-buffer-usage]
+  ++ptr;
+  // CHECK-DAG: {11:5-11:8}{{.*}}[-Wunsafe-buffer-usage]
+  --ptr;
+  // CHECK-DAG: {13:5-13:8}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr + 1;
+  // CHECK-DAG: {17:3-17:6}{{.*}}[-Wunsafe-buffer-usage]
+  2 + ptr;
+  // CHECK-DAG: {19:7-19:10}{{.*}}[-Wunsafe-buffer-usage]
+  ptr + i;
+  // CHECK-DAG: {21:3-21:6}{{.*}}[-Wunsafe-buffer-usage]
+  i + ptr;
+  // CHECK-DAG: {23:7-23:10}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr - 3;
+  // CHECK-DAG: {27:3-27:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr - i;
+  // CHECK-DAG: {29:3-29:6}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr += 4;
+  // CHECK-DAG: {33:3-33:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr += i;
+  // CHECK-DAG: {35:3-35:6}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr -= 5;
+  // CHECK-DAG: {39:3-39:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr -= i;
+  // CHECK-DAG: {41:3-41:6}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr[5];
+  // CHECK-DAG: {45:3-45:6}{{.*}}[-Wunsafe-buffer-usage]
+  5[ptr];
+  // CHECK-DAG: {47:5-47:8}{{.*}}[-Wunsafe-buffer-usage]
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -16,8 +16,10 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/OperationKinds.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtCXX.h"
@@ -2152,8 +2154,35 @@
   UnsafeBufferUsageReporter(Sema ) : S(S) {}
 
   void handleUnsafeOperation(const Stmt *Operation) override {
-S.Diag(Operation->getBeginLoc(), diag::warn_unsafe_buffer_expression)
-<< Operation->getSourceRange();
+SourceLocation Loc;
+SourceRange Range;
+if (const auto *ASE = dyn_cast(Operation)) {
+  Loc = ASE->getBase()->getExprLoc();
+  Range = ASE->getBase()->getSourceRange();
+} else if (const auto *BO = dyn_cast(Operation)) {
+  BinaryOperator::Opcode Op = BO->getOpcode();
+  if (Op == BO_Add || Op == BO_AddAssign || Op == BO_Sub ||
+  Op == BO_SubAssign) {
+if (BO->getRHS()->getType()->isIntegerType()) {
+  Loc = BO->getLHS()->getExprLoc();
+  Range = BO->getLHS()->getSourceRange();
+} else {
+  Loc = BO->getRHS()->getExprLoc();
+  Range = BO->getRHS()->getSourceRange();
+}
+  }
+} else if (const auto *UO = dyn_cast(Operation)) {
+  UnaryOperator::Opcode Op = UO->getOpcode();
+  if (Op == UO_PreInc || Op == UO_PreDec || Op == UO_PostInc ||
+  Op == UO_PostDec) {
+Loc = UO->getSubExpr()->getExprLoc();
+Range = UO->getSubExpr()->getSourceRange();
+  }
+} else {
+  Loc = Operation->getBeginLoc();
+  Range = Operation->getSourceRange();
+}
+S.Diag(Loc, diag::warn_unsafe_buffer_expression) << Range;
   }
 
   void handleFixableVariable(const VarDecl *Variable,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 39a63fc - [-Wunsafe-buffer-usage] Use relevant source locations for warnings

2023-01-18 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2023-01-18T14:18:54-08:00
New Revision: 39a63fc7fe9824313764a9da8565a705d3024b1a

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

LOG: [-Wunsafe-buffer-usage] Use relevant source locations for warnings

This way we highlight a particular unsafe subexpression by providing more 
accurate
source location than begin of an entire statement.

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

Added: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp

Modified: 
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 




diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 3a0f566588c41..08cf45e5865c0 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -16,8 +16,10 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/OperationKinds.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtCXX.h"
@@ -2152,8 +2154,35 @@ class UnsafeBufferUsageReporter : public 
UnsafeBufferUsageHandler {
   UnsafeBufferUsageReporter(Sema ) : S(S) {}
 
   void handleUnsafeOperation(const Stmt *Operation) override {
-S.Diag(Operation->getBeginLoc(), diag::warn_unsafe_buffer_expression)
-<< Operation->getSourceRange();
+SourceLocation Loc;
+SourceRange Range;
+if (const auto *ASE = dyn_cast(Operation)) {
+  Loc = ASE->getBase()->getExprLoc();
+  Range = ASE->getBase()->getSourceRange();
+} else if (const auto *BO = dyn_cast(Operation)) {
+  BinaryOperator::Opcode Op = BO->getOpcode();
+  if (Op == BO_Add || Op == BO_AddAssign || Op == BO_Sub ||
+  Op == BO_SubAssign) {
+if (BO->getRHS()->getType()->isIntegerType()) {
+  Loc = BO->getLHS()->getExprLoc();
+  Range = BO->getLHS()->getSourceRange();
+} else {
+  Loc = BO->getRHS()->getExprLoc();
+  Range = BO->getRHS()->getSourceRange();
+}
+  }
+} else if (const auto *UO = dyn_cast(Operation)) {
+  UnaryOperator::Opcode Op = UO->getOpcode();
+  if (Op == UO_PreInc || Op == UO_PreDec || Op == UO_PostInc ||
+  Op == UO_PostDec) {
+Loc = UO->getSubExpr()->getExprLoc();
+Range = UO->getSubExpr()->getSourceRange();
+  }
+} else {
+  Loc = Operation->getBeginLoc();
+  Range = Operation->getSourceRange();
+}
+S.Diag(Loc, diag::warn_unsafe_buffer_expression) << Range;
   }
 
   void handleFixableVariable(const VarDecl *Variable,

diff  --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp
new file mode 100644
index 0..35928cc6890ba
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-source-ranges.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -Wno-everything -Wunsafe-buffer-usage 
-fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s
+
+void foo(int i) {
+  int * ptr;
+
+
+  ptr++;
+  // CHECK-DAG: {7:3-7:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr--;
+  // CHECK-DAG: {9:3-9:6}{{.*}}[-Wunsafe-buffer-usage]
+  ++ptr;
+  // CHECK-DAG: {11:5-11:8}{{.*}}[-Wunsafe-buffer-usage]
+  --ptr;
+  // CHECK-DAG: {13:5-13:8}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr + 1;
+  // CHECK-DAG: {17:3-17:6}{{.*}}[-Wunsafe-buffer-usage]
+  2 + ptr;
+  // CHECK-DAG: {19:7-19:10}{{.*}}[-Wunsafe-buffer-usage]
+  ptr + i;
+  // CHECK-DAG: {21:3-21:6}{{.*}}[-Wunsafe-buffer-usage]
+  i + ptr;
+  // CHECK-DAG: {23:7-23:10}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr - 3;
+  // CHECK-DAG: {27:3-27:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr - i;
+  // CHECK-DAG: {29:3-29:6}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr += 4;
+  // CHECK-DAG: {33:3-33:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr += i;
+  // CHECK-DAG: {35:3-35:6}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr -= 5;
+  // CHECK-DAG: {39:3-39:6}{{.*}}[-Wunsafe-buffer-usage]
+  ptr -= i;
+  // CHECK-DAG: {41:3-41:6}{{.*}}[-Wunsafe-buffer-usage]
+
+
+  ptr[5];
+  // CHECK-DAG: {45:3-45:6}{{.*}}[-Wunsafe-buffer-usage]
+  5[ptr];
+  // CHECK-DAG: {47:5-47:8}{{.*}}[-Wunsafe-buffer-usage]
+}



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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-01-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D141451#4063504 , @nickdesaulniers 
wrote:

> In D141451#4063335 , @dblaikie 
> wrote:
>
>> In D141451#4063151 , 
>> @nickdesaulniers wrote:
>>
>>> In D141451#4045658 , @efriedma 
>>> wrote:
>>>
 clang has a "LocTrackingOnly" setting for debug info, which emits 
 DILocation info into the IR, but emits a marker into the DICompileUnit to 
 skip emitting the .debug_info in the backend.  We currently use it for 
 -Rpass.  We don't do this by default, I think to save compile time.
>>>
>>> Specifically `emissionKind: NoDebug`, example:
>>>
>>> `!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: 
>>> "clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
>>> 7b433e026498cf4176931b2407baece1d5060e16)", isOptimized: true, 
>>> runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, 
>>> nameTableKind: None)`
>>>
>>> Though should the frontend be setting codegen options when parsing? Would 
>>> the idea be to try to re-set `OPT_debug_info_kind_EQ` when clang codegen's 
>>> IR for a function with such an attribute?
>>
>> Probably turn on `emissionKind: NoDebug` whenever the warning is enabled?
>
> So this warning is default enabled, IIRC.

Then it might be a broader question about whether this extra info is acceptable 
to turn on by default, and if not, maybe an extra flag would be needed to say 
"give me extra info in this diagnostic", basically (or a separate warning flag 
that's off by default) - some perf metrics might help indicate whether the 
extra info is cheap enough.

> I guess I need to check for `-Wno-attribute-warning`.  If 
> `-Wno-attribute-warning` is //not// set and `-g` (or friends) is not set, 
> then I should set `emissionKind` to `NoDebug` (I think).

Generally you shouldn't be checking the raw flags like this for a feature like 
this - I'd expect something in Clang that checks to see if the warning is 
enabled, rather than whether certain flag spellings are used, etc. Though what 
goes in the driver V frontend, etc complicates things (if the decision is made 
in the frontend, once warning flags are parsed and there's a diagnostic engine 
you can query for warning enablement, then it'd need to override the debug info 
level rather than the command line handling in the driver)

>>> ---
>>>
>>> In D141451#4045214 , @dblaikie 
>>> wrote:
>>>
 It'd be nice not to invent a new way of tracking inlining separate from 
 the way debug info does this - duplicate systems with separate 
 opportunities for bugs, etc. Any chance we can reuse the debug info 
 inlining descriptions for this?
>>>
>>> So it looks like we have:
>>>
>>> `!28 = !DILocation(line: 14, column: 3, scope: !8, inlinedAt: !29)`
>>>
>>> Let me see if I can create DILocation without line or column values.
>>
>> Not sure I follow - why would you want to drop line/column info? Isn't that 
>> relevant to the inlining stack - you might have multiple calls in the same 
>> function & it'd be good to know which one the diagnostic is referring to.
>>
>>>   The DISubprogram and DILocation should form a similar chain, even if 
>>> significantly more complicated to "unwind."
>
> Not dropping it, more like without `-g` (or friends) it never existed in the 
> first place.  If you look at my change to 
> `llvm/lib/Transforms/Utils/InlineFunction.cpp` (in this patch), I'm basically 
> synthesizing metadata during inlining.  If we don't have Debug Info related 
> metadata because the program wasn't compiled with `-g` (or w/e), then the 
> DILocation for the callsites was never produced by the frontend in the first 
> place.  This patch doesn't intentionally drop anything, it's more like the 
> anything might never have existed in the first place.
>
> So this warning could "be improved" if you recompiled with `-g`; I don't 
> think there's really precedent for that and expect it's perhaps 
> controversial.  Hence my custom metadate nodes rather than the existing 
> DILocation.

I'm still a bit confused/not following about the "Let me see if I can create 
DILocation without line or column values." - why do you want to create that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


[PATCH] D141424: [clang][Sema] Fix uninitialized `SourceLocation` for types with multiple attributes and macros.

2023-01-18 Thread Volodymyr Sapsai 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 rG304d7307aee1: [clang][Sema] Fix uninitialized 
`SourceLocation` for types with multiple… (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141424

Files:
  clang/lib/Sema/SemaType.cpp
  clang/unittests/AST/SourceLocationTest.cpp

Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -438,6 +438,47 @@
   loc(unaryTransformType(;
 }
 
+TEST(PointerTypeLoc, StarLoc) {
+  llvm::Annotations Example(R"c(
+int $star^*var;
+  )c");
+
+  auto AST = tooling::buildASTFromCode(Example.code());
+  SourceManager  = AST->getSourceManager();
+  auto  = AST->getASTContext();
+
+  auto *VD = selectFirst("vd", match(varDecl(hasName("var")).bind("vd"), Ctx));
+  ASSERT_NE(VD, nullptr);
+
+  auto TL =
+  VD->getTypeSourceInfo()->getTypeLoc().castAs();
+  ASSERT_EQ(SM.getFileOffset(TL.getStarLoc()), Example.point("star"));
+}
+
+TEST(PointerTypeLoc, StarLocBehindSugar) {
+  llvm::Annotations Example(R"c(
+#define NODEREF __attribute__((noderef))
+char $1st^* NODEREF _Nonnull $2nd^* var;
+  )c");
+
+  auto AST = tooling::buildASTFromCode(Example.code());
+  SourceManager  = AST->getSourceManager();
+  auto  = AST->getASTContext();
+
+  auto *VD = selectFirst("vd", match(varDecl(hasName("var")).bind("vd"), Ctx));
+  ASSERT_NE(VD, nullptr);
+
+  auto TL = VD->getTypeSourceInfo()->getTypeLoc().castAs();
+  EXPECT_EQ(SM.getFileOffset(TL.getStarLoc()), Example.point("2nd"));
+
+  // Cast intermediate TypeLoc to make sure the structure matches expectations.
+  auto InnerPtrTL = TL.getPointeeLoc().castAs()
+.getNextTypeLoc().castAs()
+.getNextTypeLoc().castAs()
+.getNextTypeLoc().castAs();
+  EXPECT_EQ(SM.getFileOffset(InnerPtrTL.getStarLoc()), Example.point("1st"));
+}
+
 TEST(CXXFunctionalCastExpr, SourceRange) {
   RangeVerifier Verifier;
   Verifier.expectRange(2, 10, 2, 14);
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -6515,29 +6515,42 @@
   CurrTL = ATL.getValueLoc().getUnqualifiedLoc();
 }
 
-while (MacroQualifiedTypeLoc TL = CurrTL.getAs()) {
-  TL.setExpansionLoc(
-  State.getExpansionLocForMacroQualifiedType(TL.getTypePtr()));
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
-}
+bool HasDesugaredTypeLoc = true;
+while (HasDesugaredTypeLoc) {
+  switch (CurrTL.getTypeLocClass()) {
+  case TypeLoc::MacroQualified: {
+auto TL = CurrTL.castAs();
+TL.setExpansionLoc(
+State.getExpansionLocForMacroQualifiedType(TL.getTypePtr()));
+CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-while (AttributedTypeLoc TL = CurrTL.getAs()) {
-  fillAttributedTypeLoc(TL, State);
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
-}
+  case TypeLoc::Attributed: {
+auto TL = CurrTL.castAs();
+fillAttributedTypeLoc(TL, State);
+CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-while (BTFTagAttributedTypeLoc TL = CurrTL.getAs())
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+  case TypeLoc::Adjusted:
+  case TypeLoc::BTFTagAttributed: {
+CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-while (DependentAddressSpaceTypeLoc TL =
-   CurrTL.getAs()) {
-  fillDependentAddressSpaceTypeLoc(TL, D.getTypeObject(i).getAttrs());
-  CurrTL = TL.getPointeeTypeLoc().getUnqualifiedLoc();
-}
+  case TypeLoc::DependentAddressSpace: {
+auto TL = CurrTL.castAs();
+fillDependentAddressSpaceTypeLoc(TL, D.getTypeObject(i).getAttrs());
+CurrTL = TL.getPointeeTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-// FIXME: Ordering here?
-while (AdjustedTypeLoc TL = CurrTL.getAs())
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+  default:
+HasDesugaredTypeLoc = false;
+break;
+  }
+}
 
 DeclaratorLocFiller(S.Context, State, D.getTypeObject(i)).Visit(CurrTL);
 CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 304d730 - [clang][Sema] Fix uninitialized `SourceLocation` for types with multiple attributes and macros.

2023-01-18 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-01-18T16:15:53-06:00
New Revision: 304d7307aee15b6eb88d198ae94b595f4e09f485

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

LOG: [clang][Sema] Fix uninitialized `SourceLocation` for types with multiple 
attributes and macros.

Some `TypeLoc`s are considered "sugar" and we go past them in
`GetTypeSourceInfoForDeclarator`. The problem is that we peel off only
the same kind of `TypeLoc` at the time which makes it impossible to
handle mixed sequences like
`AttributedTypeLoc - MacroQualifiedTypeLoc - AttributedTypeLoc - PointerTypeLoc`

In this situation, as shown in the added test, we don't get to
`PointerTypeLoc` and don't set its starLoc leaving it uninitialized.

Address FIXME and peel off "sugar" `TypeLoc`s regardless of their order.

rdar://102149264

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

Added: 


Modified: 
clang/lib/Sema/SemaType.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index eb61a5fe4fbae..ac00e87944845 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -6515,29 +6515,42 @@ GetTypeSourceInfoForDeclarator(TypeProcessingState 
,
   CurrTL = ATL.getValueLoc().getUnqualifiedLoc();
 }
 
-while (MacroQualifiedTypeLoc TL = CurrTL.getAs()) {
-  TL.setExpansionLoc(
-  State.getExpansionLocForMacroQualifiedType(TL.getTypePtr()));
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
-}
+bool HasDesugaredTypeLoc = true;
+while (HasDesugaredTypeLoc) {
+  switch (CurrTL.getTypeLocClass()) {
+  case TypeLoc::MacroQualified: {
+auto TL = CurrTL.castAs();
+TL.setExpansionLoc(
+State.getExpansionLocForMacroQualifiedType(TL.getTypePtr()));
+CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-while (AttributedTypeLoc TL = CurrTL.getAs()) {
-  fillAttributedTypeLoc(TL, State);
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
-}
+  case TypeLoc::Attributed: {
+auto TL = CurrTL.castAs();
+fillAttributedTypeLoc(TL, State);
+CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-while (BTFTagAttributedTypeLoc TL = 
CurrTL.getAs())
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+  case TypeLoc::Adjusted:
+  case TypeLoc::BTFTagAttributed: {
+CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-while (DependentAddressSpaceTypeLoc TL =
-   CurrTL.getAs()) {
-  fillDependentAddressSpaceTypeLoc(TL, D.getTypeObject(i).getAttrs());
-  CurrTL = TL.getPointeeTypeLoc().getUnqualifiedLoc();
-}
+  case TypeLoc::DependentAddressSpace: {
+auto TL = CurrTL.castAs();
+fillDependentAddressSpaceTypeLoc(TL, D.getTypeObject(i).getAttrs());
+CurrTL = TL.getPointeeTypeLoc().getUnqualifiedLoc();
+break;
+  }
 
-// FIXME: Ordering here?
-while (AdjustedTypeLoc TL = CurrTL.getAs())
-  CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();
+  default:
+HasDesugaredTypeLoc = false;
+break;
+  }
+}
 
 DeclaratorLocFiller(S.Context, State, D.getTypeObject(i)).Visit(CurrTL);
 CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();

diff  --git a/clang/unittests/AST/SourceLocationTest.cpp 
b/clang/unittests/AST/SourceLocationTest.cpp
index 43b7149bd1183..ca9e9a2161974 100644
--- a/clang/unittests/AST/SourceLocationTest.cpp
+++ b/clang/unittests/AST/SourceLocationTest.cpp
@@ -438,6 +438,47 @@ TEST(UnaryTransformTypeLoc, ParensRange) {
   loc(unaryTransformType(;
 }
 
+TEST(PointerTypeLoc, StarLoc) {
+  llvm::Annotations Example(R"c(
+int $star^*var;
+  )c");
+
+  auto AST = tooling::buildASTFromCode(Example.code());
+  SourceManager  = AST->getSourceManager();
+  auto  = AST->getASTContext();
+
+  auto *VD = selectFirst("vd", 
match(varDecl(hasName("var")).bind("vd"), Ctx));
+  ASSERT_NE(VD, nullptr);
+
+  auto TL =
+  VD->getTypeSourceInfo()->getTypeLoc().castAs();
+  ASSERT_EQ(SM.getFileOffset(TL.getStarLoc()), Example.point("star"));
+}
+
+TEST(PointerTypeLoc, StarLocBehindSugar) {
+  llvm::Annotations Example(R"c(
+#define NODEREF __attribute__((noderef))
+char $1st^* NODEREF _Nonnull $2nd^* var;
+  )c");
+
+  auto AST = tooling::buildASTFromCode(Example.code());
+  SourceManager  = AST->getSourceManager();
+  auto  = AST->getASTContext();
+
+  auto *VD = selectFirst("vd", 
match(varDecl(hasName("var")).bind("vd"), Ctx));
+  ASSERT_NE(VD, nullptr);
+
+  auto TL = VD->getTypeSourceInfo()->getTypeLoc().castAs();
+  EXPECT_EQ(SM.getFileOffset(TL.getStarLoc()), Example.point("2nd"));

[PATCH] D141424: [clang][Sema] Fix uninitialized `SourceLocation` for types with multiple attributes and macros.

2023-01-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141424

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-01-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D141451#4063335 , @dblaikie wrote:

> In D141451#4063151 , 
> @nickdesaulniers wrote:
>
>> In D141451#4045658 , @efriedma 
>> wrote:
>>
>>> clang has a "LocTrackingOnly" setting for debug info, which emits 
>>> DILocation info into the IR, but emits a marker into the DICompileUnit to 
>>> skip emitting the .debug_info in the backend.  We currently use it for 
>>> -Rpass.  We don't do this by default, I think to save compile time.
>>
>> Specifically `emissionKind: NoDebug`, example:
>>
>> `!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: 
>> "clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
>> 7b433e026498cf4176931b2407baece1d5060e16)", isOptimized: true, 
>> runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, 
>> nameTableKind: None)`
>>
>> Though should the frontend be setting codegen options when parsing? Would 
>> the idea be to try to re-set `OPT_debug_info_kind_EQ` when clang codegen's 
>> IR for a function with such an attribute?
>
> Probably turn on `emissionKind: NoDebug` whenever the warning is enabled?

So this warning is default enabled, IIRC. I guess I need to check for 
`-Wno-attribute-warning`.  If `-Wno-attribute-warning` is //not// set and `-g` 
(or friends) is not set, then I should set `emissionKind` to `NoDebug` (I 
think).

>> ---
>>
>> In D141451#4045214 , @dblaikie 
>> wrote:
>>
>>> It'd be nice not to invent a new way of tracking inlining separate from the 
>>> way debug info does this - duplicate systems with separate opportunities 
>>> for bugs, etc. Any chance we can reuse the debug info inlining descriptions 
>>> for this?
>>
>> So it looks like we have:
>>
>> `!28 = !DILocation(line: 14, column: 3, scope: !8, inlinedAt: !29)`
>>
>> Let me see if I can create DILocation without line or column values.
>
> Not sure I follow - why would you want to drop line/column info? Isn't that 
> relevant to the inlining stack - you might have multiple calls in the same 
> function & it'd be good to know which one the diagnostic is referring to.
>
>>   The DISubprogram and DILocation should form a similar chain, even if 
>> significantly more complicated to "unwind."

Not dropping it, more like without `-g` (or friends) it never existed in the 
first place.  If you look at my change to 
`llvm/lib/Transforms/Utils/InlineFunction.cpp` (in this patch), I'm basically 
synthesizing metadata during inlining.  If we don't have Debug Info related 
metadata because the program wasn't compiled with `-g` (or w/e), then the 
DILocation for the callsites was never produced by the frontend in the first 
place.  This patch doesn't intentionally drop anything, it's more like the 
anything might never have existed in the first place.

So this warning could "be improved" if you recompiled with `-g`; I don't think 
there's really precedent for that and expect it's perhaps controversial.  Hence 
my custom metadate nodes rather than the existing DILocation.




Comment at: llvm/lib/Transforms/Utils/InlineFunction.cpp:2467-2468
+
+const Function *Callee = CI->getCalledFunction();
+if (Callee && (Callee->hasFnAttribute("dontcall-error") ||
+   Callee->hasFnAttribute("dontcall-warn"))) {

nickdesaulniers wrote:
> nickdesaulniers wrote:
> > arsenm wrote:
> > > Misses constexpr casts and aliases
> > The base feature doesn't work with aliases (or ConstantExpr), in GCC or 
> > Clang.  I should perhaps fix that first...
> Perhaps I should use Call.getCalledOperand()->stripPointerCasts() for 
> constantexpr case.
I've added support for ConstantExpr to the base feature in D142058.  I should 
still fix this in this PR and add a test case, so not yet marking this thread 
as done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


[PATCH] D140875: [clangd] prototype: Implement unused include warnings with include-cleaner library.

2023-01-18 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 490287.
hokein added a comment.

update the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140875

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp

Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -150,7 +150,7 @@
   RecordPragma(const CompilerInstance , PragmaIncludes *Out)
   : SM(CI.getSourceManager()),
 HeaderInfo(CI.getPreprocessor().getHeaderSearchInfo()), Out(Out),
-UniqueStrings(Arena) {}
+UniqueStrings(Out->Arena) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -176,7 +176,6 @@
   std::unique(It.getSecond().begin(), It.getSecond().end()),
   It.getSecond().end());
 }
-Out->Arena = std::move(Arena);
   }
 
   void InclusionDirective(SourceLocation HashLoc, const Token ,
@@ -307,7 +306,6 @@
   const SourceManager 
   HeaderSearch 
   PragmaIncludes *Out;
-  llvm::BumpPtrAllocator Arena;
   /// Intern table for strings. Contents are on the arena.
   llvm::StringSaver UniqueStrings;
 
@@ -336,6 +334,27 @@
   std::vector KeepStack;
 };
 
+PragmaIncludes::PragmaIncludes(const PragmaIncludes & In) {
+  *this = In;
+}
+
+PragmaIncludes ::operator=(const PragmaIncludes ) {
+  ShouldKeep = In.ShouldKeep;
+  NonSelfContainedFiles = In.NonSelfContainedFiles;
+  Arena.Reset();
+  llvm::UniqueStringSaver Strings(Arena);
+  IWYUPublic.clear();
+  for (const auto& It : In.IWYUPublic)
+IWYUPublic.try_emplace(It.first, Strings.save(It.second));
+  IWYUExportBy.clear();
+  for (const auto& UIDAndExporters : In.IWYUExportBy) {
+const auto& [UID, Exporters] = UIDAndExporters;
+for (StringRef ExporterHeader : Exporters)
+   IWYUExportBy.try_emplace(UID).first->second.push_back(ExporterHeader);
+  }
+  return *this;
+ }
+
 void PragmaIncludes::record(const CompilerInstance ) {
   auto Record = std::make_unique(CI, this);
   CI.getPreprocessor().addCommentHandler(Record.get());
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
@@ -48,6 +48,13 @@
 /// defines the symbol.
 class PragmaIncludes {
 public:
+  PragmaIncludes() = default;
+  PragmaIncludes(PragmaIncludes &&) = default;
+  PragmaIncludes =(PragmaIncludes &&) = default;
+
+  PragmaIncludes(const PragmaIncludes &);
+  PragmaIncludes =(const PragmaIncludes &);
+
   /// Installs an analysing PPCallback and CommentHandler and populates results
   /// to the structure.
   void record(const CompilerInstance );
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -343,6 +343,8 @@
 
   auto Unused = computeUnusedIncludes(AST);
   EXPECT_THAT(Unused, ElementsAre(Pointee(writtenInclusion("";
+  EXPECT_THAT(computeUnusedIncludesNew(AST),
+  ElementsAre(Pointee(writtenInclusion("";
 }
 
 TEST(IncludeCleaner, GetUnusedHeaders) {
@@ -379,6 +381,10 @@
 UnusedIncludes.push_back(Include->Written);
   EXPECT_THAT(UnusedIncludes,
   UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\""));
+  EXPECT_THAT(
+  computeUnusedIncludesNew(AST),
+  UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
+   Pointee(writtenInclusion("\"dir/unused.h\"";
 }
 
 TEST(IncludeCleaner, VirtualBuffers) {
@@ -533,6 +539,9 @@
 // IWYU pragma: private, include "public.h"
 void foo() {}
   )cpp");
+  Config Cfg;
+  Cfg.Diagnostics.UnusedIncludes = Config::Experiment;
+  WithContextValue Ctx(Config::Key, std::move(Cfg));
   ParsedAST AST = TU.build();
 
   auto ReferencedFiles = findReferencedFiles(
@@ -547,6 +556,7 @@
   ReferencedFiles.User.contains(AST.getSourceManager().getMainFileID()));
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
   

[PATCH] D131052: [CMake] Allow setting the location of host tools with LLVM_NATIVE_TOOL_DIR

2023-01-18 Thread Martin Storsjö 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 rGd3da9067d143: [CMake] Allow setting the location of host 
tools with LLVM_NATIVE_TOOL_DIR (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131052

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/pseudo/include/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/TableGen.cmake
  llvm/tools/llvm-config/CMakeLists.txt
  mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt

Index: mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
===
--- mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
+++ mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
@@ -14,23 +14,13 @@
   MLIRParser
   )
 
-set(MLIR_LINALG_ODS_YAML_GEN mlir-linalg-ods-yaml-gen CACHE
-  STRING "Native mlir-linalg-ods-yaml-gen executable. Saves building one when cross-compiling.")
+setup_host_tool(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN MLIR_LINALG_ODS_YAML_GEN_EXE MLIR_LINALG_ODS_YAML_GEN_TARGET)
 
-set(MLIR_LINALG_ODS_YAML_GEN_EXE ${MLIR_LINALG_ODS_YAML_GEN} PARENT_SCOPE)
-set(MLIR_LINALG_ODS_YAML_GEN_TARGET mlir-linalg-ods-yaml-gen PARENT_SCOPE)
+if(NOT ${MLIR_LINALG_ODS_YAML_GEN_EXE} STREQUAL "mlir-linalg-ods-yaml-gen")
+  add_custom_target(mlir-linalg-ods-yaml-gen-host DEPENDS ${MLIR_LINALG_ODS_YAML_GEN_EXE})
 
-if(LLVM_USE_HOST_TOOLS)
-  if (${MLIR_LINALG_ODS_YAML_GEN} STREQUAL "mlir-linalg-ods-yaml-gen")
-build_native_tool(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN_EXE DEPENDS mlir-linalg-ods-yaml-gen)
-set(MLIR_LINALG_ODS_YAML_GEN_EXE ${MLIR_LINALG_ODS_YAML_GEN_EXE} PARENT_SCOPE)
-
-add_custom_target(mlir-linalg-ods-yaml-gen-host DEPENDS ${MLIR_LINALG_ODS_YAML_GEN_EXE})
-set(MLIR_LINALG_ODS_YAML_GEN_TARGET mlir-linalg-ods-yaml-gen-host DEPENDS PARENT_SCOPE)
-
-if(NOT LLVM_BUILD_UTILS)
-  set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES EXCLUDE_FROM_ALL ON)
-endif()
+  if(NOT LLVM_BUILD_UTILS)
+set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES EXCLUDE_FROM_ALL ON)
   endif()
 endif()
 
Index: llvm/tools/llvm-config/CMakeLists.txt
===
--- llvm/tools/llvm-config/CMakeLists.txt
+++ llvm/tools/llvm-config/CMakeLists.txt
@@ -91,10 +91,18 @@
 # Add the dependency on the generation step.
 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
 
-if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
-  build_native_tool(llvm-config LLVM_CONFIG_PATH)
-  set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
+if(CMAKE_CROSSCOMPILING)
+  if (LLVM_NATIVE_TOOL_DIR AND NOT LLVM_CONFIG_PATH)
+if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/llvm-config${LLVM_HOST_EXECUTABLE_SUFFIX}")
+  set(LLVM_CONFIG_PATH "${LLVM_NATIVE_TOOL_DIR}/llvm-config${LLVM_HOST_EXECUTABLE_SUFFIX}")
+endif()
+  endif()
 
-  add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
-  add_dependencies(llvm-config NativeLLVMConfig)
+  if (NOT LLVM_CONFIG_PATH)
+build_native_tool(llvm-config LLVM_CONFIG_PATH)
+set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
+
+add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
+add_dependencies(llvm-config NativeLLVMConfig)
+  endif()
 endif()
Index: llvm/cmake/modules/TableGen.cmake
===
--- llvm/cmake/modules/TableGen.cmake
+++ llvm/cmake/modules/TableGen.cmake
@@ -156,7 +156,13 @@
 ${ADD_TABLEGEN_UNPARSED_ARGUMENTS})
   set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
 
-  set(${project}_TABLEGEN "${target}" CACHE
+  set(${project}_TABLEGEN_DEFAULT "${target}")
+  if (LLVM_NATIVE_TOOL_DIR)
+if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/${target}${LLVM_HOST_EXECUTABLE_SUFFIX}")
+  set(${project}_TABLEGEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${target}${LLVM_HOST_EXECUTABLE_SUFFIX}")
+endif()
+  endif()
+  set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE
   STRING "Native TableGen executable. Saves building one when cross-compiling.")
 
   # Effective tblgen executable to be used:
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2397,3 +2397,31 @@
 endif()
   endif()
 endfunction()
+
+function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
+  set(${setting_name}_DEFAULT "${tool_name}")
+
+  if(LLVM_USE_HOST_TOOLS AND LLVM_NATIVE_TOOL_DIR)
+if(EXISTS "${LLVM_NATIVE_TOOL_DIR}/${tool_name}${LLVM_HOST_EXECUTABLE_SUFFIX}")
+  set(${setting_name}_DEFAULT 

[clang-tools-extra] d3da906 - [CMake] Allow setting the location of host tools with LLVM_NATIVE_TOOL_DIR

2023-01-18 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-01-18T23:56:15+02:00
New Revision: d3da9067d143f3d4ce59b6d9ab4606a8ef1dc937

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

LOG: [CMake] Allow setting the location of host tools with LLVM_NATIVE_TOOL_DIR

This avoids having to specify the location of all individual tools.
In current builds, one may want to specify LLVM_TABLEGEN, CLANG_TABLEGEN,
LLDB_TABLEGEN, LLVM_CONFIG_PATH, CLANG_PSEUDO_GEN and
CLANG_TIDY_CONFUSABLE_CHARS_GEN; specifying just the base directory
containing all of them is much more convenient.

Factorize the code for setting up use of a tool that is used during
the build (which either is newly built in the same build, or
built in a separate nested cmake build - when cross compiling or
when e.g. optimized tablegen is requested - or used from an existing
prebuilt binary).

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/pseudo/include/CMakeLists.txt
llvm/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/TableGen.cmake
llvm/tools/llvm-config/CMakeLists.txt
mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 1387f551d6b12..a72362906e0b8 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -3,19 +3,7 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-set(CLANG_TIDY_CONFUSABLE_CHARS_GEN "clang-tidy-confusable-chars-gen" CACHE
-  STRING "Host clang-tidy-confusable-chars-gen executable. Saves building if 
cross-compiling.")
-
-if(NOT CLANG_TIDY_CONFUSABLE_CHARS_GEN STREQUAL 
"clang-tidy-confusable-chars-gen")
-  set(clang_tidy_confusable_chars_gen ${CLANG_TIDY_CONFUSABLE_CHARS_GEN})
-  set(clang_tidy_confusable_chars_gen_target 
${CLANG_TIDY_CONFUSABLE_CHARS_GEN})
-elseif(LLVM_USE_HOST_TOOLS)
-  build_native_tool(clang-tidy-confusable-chars-gen 
clang_tidy_confusable_chars_gen)
-  set(clang_tidy_confusable_chars_gen_target 
"${clang_tidy_confusable_chars_gen}")
-else()
-  set(clang_tidy_confusable_chars_gen 
$)
-  set(clang_tidy_confusable_chars_gen_target clang-tidy-confusable-chars-gen)
-endif()
+setup_host_tool(clang-tidy-confusable-chars-gen 
CLANG_TIDY_CONFUSABLE_CHARS_GEN clang_tidy_confusable_chars_gen 
clang_tidy_confusable_chars_gen_target)
 
 add_subdirectory(ConfusableTable)
 

diff  --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index ce2f97db78ad9..2334cfa12e337 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -1,21 +1,7 @@
 # The cxx.bnf grammar file
 set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
-set(CLANG_PSEUDO_GEN "clang-pseudo-gen" CACHE
-  STRING "Host clang-pseudo-gen executable. Saves building if 
cross-compiling.")
-
-if(NOT CLANG_PSEUDO_GEN STREQUAL "clang-pseudo-gen")
-  set(pseudo_gen ${CLANG_PSEUDO_GEN})
-  set(pseudo_gen_target ${CLANG_PSEUDO_GEN})
-elseif(LLVM_USE_HOST_TOOLS)
-  # The NATIVE executable *must* depend on the current target, otherwise the
-  # native one won't get rebuilt when the pseudo-gen sources change.
-  build_native_tool(clang-pseudo-gen pseudo_gen DEPENDS clang-pseudo-gen)
-  set(pseudo_gen_target "${pseudo_gen}")
-else()
-  set(pseudo_gen $)
-  set(pseudo_gen_target clang-pseudo-gen)
-endif()
+setup_host_tool(clang-pseudo-gen CLANG_PSEUDO_GEN pseudo_gen pseudo_gen_target)
 
 # Generate inc files.
 set(cxx_symbols_inc ${CMAKE_CURRENT_BINARY_DIR}/CXXSymbols.inc)

diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index fb486bdfcb2fc..28ed35f8b8025 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -665,6 +665,7 @@ set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING 
"Default options for lit")
 if( WIN32 AND NOT CYGWIN )
   set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
 endif()
+set(LLVM_NATIVE_TOOL_DIR "" CACHE PATH "Path to a directory containing 
prebuilt matching native tools (such as llvm-tblgen)")
 
 set(LLVM_INTEGRATED_CRT_ALLOC "" CACHE PATH "Replace the Windows CRT allocator 
with any of {rpmalloc|mimalloc|snmalloc}. Only works with /MT enabled.")
 if(LLVM_INTEGRATED_CRT_ALLOC)

diff  --git a/llvm/cmake/modules/AddLLVM.cmake 
b/llvm/cmake/modules/AddLLVM.cmake
index 368f0d1c2a32c..38b0f18fcb4f0 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2397,3 +2397,31 @@ function(find_first_existing_vc_file path out_var)
 endif()
   endif()
 endfunction()
+
+function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
+  

[PATCH] D141868: [Clang] [Sema] Removed a fix-it for system headers

2023-01-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:10923-10927
+for (std::vector::iterator HI = Cand->Fix.Hints.begin(),
+  HE = Cand->Fix.Hints.end();
+ HI != HE; ++HI)
+FDiag << *HI;
+  }

NoQ wrote:
> Since you're reformatting anyway, maybe use a range-based for-loop?
(or `for_each`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141868

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


[PATCH] D141954: Forbid implicit conversion of constraint expression to bool

2023-01-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 490278.
erichkeane added a comment.

Added tests suggested by Tom, also moved the cast creation after checking of 
the return type, so that we end up not hitting hte assert that Tom came up 
with.  Added 2 tests that show the two conditions (that DID repro as a crash).


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

https://reviews.llvm.org/D141954

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaConcept.cpp
  
clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp

Index: clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++20 -x c++ -Wno-constant-logical-operand -verify %s
+
+template concept C =
+sizeof(T) == 4 && !true;  // requires atomic constraints sizeof(T) == 4 and !true
+
+template concept C2 = sizeof(T); // expected-error{{atomic constraint must be of type 'bool' (found }}
+
+template struct S {
+  constexpr operator bool() const { return true; }
+};
+
+// expected-error@+3{{atomic constraint must be of type 'bool' (found 'S')}}
+// expected-note@#FINST{{while checking constraint satisfaction}}
+// expected-note@#FINST{{in instantiation of function template specialization}}
+template requires (S{})
+void f(T);
+void f(int);
+
+// Ensure this applies to operator && as well.
+// expected-error@+3{{atomic constraint must be of type 'bool' (found 'S')}}
+// expected-note@#F2INST{{while checking constraint satisfaction}}
+// expected-note@#F2INST{{in instantiation of function template specialization}}
+template requires (S{} && true)
+void f2(T);
+void f2(int);
+
+template requires requires {
+  requires S{};
+  // expected-error@-1{{atomic constraint must be of type 'bool' (found 'S')}}
+  // expected-note@-2{{while checking the satisfaction}}
+  // expected-note@-3{{in instantiation of requirement}}
+  // expected-note@-4{{while checking the satisfaction}}
+  // expected-note@-6{{while substituting template arguments}}
+  // expected-note@#F3INST{{while checking constraint satisfaction}}
+  // expected-note@#F3INST{{in instantiation of function template specialization}}
+  //
+}
+void f3(T);
+void f3(int);
+
+// Doesn't diagnose, since this is no longer a compound requirement.
+template requires (bool(1 && 2))
+void f4(T);
+void f4(int);
+
+void g() {
+  f(0); // #FINST
+  f2(0); // #F2INST
+  f3(0); // #F3INST
+  f4(0);
+}
+
+template
+auto Nullptr = nullptr;
+
+template concept NullTy = Nullptr;
+// expected-error@-1{{atomic constraint must be of type 'bool' (found }}
+// expected-note@+1{{while checking the satisfaction}}
+static_assert(NullTy);
+
+template
+auto Struct = S{};
+
+template concept StructTy = Struct;
+// expected-error@-1{{atomic constraint must be of type 'bool' (found 'S')}}
+// expected-note@+1{{while checking the satisfaction}}
+static_assert(StructTy);
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -329,14 +329,7 @@
   Sema::SFINAETrap Trap(S);
   SubstitutedExpression =
   S.SubstConstraintExpr(const_cast(AtomicExpr), MLTAL);
-  // Substitution might have stripped off a contextual conversion to
-  // bool if this is the operand of an '&&' or '||'. For example, we
-  // might lose an lvalue-to-rvalue conversion here. If so, put it back
-  // before we try to evaluate.
-  if (SubstitutedExpression.isUsable() &&
-  !SubstitutedExpression.isInvalid())
-SubstitutedExpression =
-S.PerformContextuallyConvertToBool(SubstitutedExpression.get());
+
   if (SubstitutedExpression.isInvalid() || Trap.hasErrorOccurred()) {
 // C++2a [temp.constr.atomic]p1
 //   ...If substitution results in an invalid type or expression, the
@@ -373,6 +366,23 @@
 if (!S.CheckConstraintExpression(SubstitutedExpression.get()))
   return ExprError();
 
+// [temp.constr.atomic]p3: To determine if an atomic constraint is
+// satisfied, the parameter mapping and template arguments are first
+// substituted into its expression.  If substitution results in an
+// invalid type or expression, the constraint is not satisfied.
+// Otherwise, the lvalue-to-rvalue conversion is performed if necessary,
+// and E shall be a constant expression of type bool.
+//
+// Perform the L to R Value conversion if necessary. We do so for all
+// non-PRValue categories, else we fail to extend the lifetime of
+// temporaries, and that fails the constant expression check.
+if 

[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

doru1004 wrote:
> ABataev wrote:
> > doru1004 wrote:
> > > ABataev wrote:
> > > > Do you really need to store the variable in the stack, is not it enough 
> > > > just to check that the type of this variable is 
> > > > BuiltinType::OMPIterator?
> > > I'm happy to replace this if you think it will work. Is there an example 
> > > somewhere in the code where I can get from the VarDecl to the build in 
> > > type you mention?
> > You have already a check 
> > IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator),
> >  you can you something similar for the variable
> This didn't work and I had to revert to using the stack!
Why?


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

https://reviews.llvm.org/D141871

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


[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1166-1168
+return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
+  return IteratorVD == VD->getCanonicalDecl();
+});

ABataev wrote:
> doru1004 wrote:
> > ABataev wrote:
> > > Do you really need to store the variable in the stack, is not it enough 
> > > just to check that the type of this variable is BuiltinType::OMPIterator?
> > I'm happy to replace this if you think it will work. Is there an example 
> > somewhere in the code where I can get from the VarDecl to the build in type 
> > you mention?
> You have already a check 
> IteratorModifier->getType()->isSpecificBuiltinType(BuiltinType::OMPIterator), 
> you can you something similar for the variable
This didn't work and I had to revert to using the stack!


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

https://reviews.llvm.org/D141871

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


[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 490277.

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

https://reviews.llvm.org/D141871

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/declare_mapper_messages.c
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_map_messages.cpp

Index: clang/test/OpenMP/target_map_messages.cpp
===
--- clang/test/OpenMP/target_map_messages.cpp
+++ clang/test/OpenMP/target_map_messages.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -verify=expected,lt50,lt51,omp,lt51-omp -fopenmp -fno-openmp-extensions -fopenmp-version=45 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge50,lt51,omp,lt51-omp -fopenmp -fno-openmp-extensions -fopenmp-version=50 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge50,ge51,omp,ge51-omp -fopenmp -fno-openmp-extensions -fopenmp-version=51 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,ge50,ge51,ge52,omp,ge52-omp -fopenmp -fno-openmp-extensions -fopenmp-version=52 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
 // RUN: %clang_cc1 -DCCODE -verify -fopenmp -fno-openmp-extensions -ferror-limit 300 -x c %s -Wno-openmp -Wuninitialized
 
 // -fopenmp-simd, -fno-openmp-extensions
@@ -158,23 +159,28 @@
 // expected-error@+1 {{use of undeclared identifier 'present'}}
 #pragma omp target map(present)
 {}
+// ge52-omp-error@+3 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c,f)
 {}
+// ge52-omp-error@+3 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c[1:2],f)
 {}
+// ge52-omp-error@+3 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c,f[1:2])
 {}
+// ge52-omp-error@+4 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // expected-error@+3 {{section length is unspecified and cannot be inferred because subscripted value is not an array}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c[:],f)
 {}
+// ge52-omp-error@+4 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // expected-error@+3 {{section length is unspecified and cannot be inferred because subscripted value is not an array}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
@@ -191,11 +197,15 @@
 // lt51-error@+1 2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(present, present, tofrom: a)
 {}
+// ge52-omp-error@+5 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
+// ge52-omp-error@+4 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ompx-error@+3 {{same map type modifier has been specified more than once}}
 // ge51-omp-error@+2 2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 2 {{incorrect map type modifier, expected one of: 

[PATCH] D136913: [HLSL] support RWByteAddressBuffer.

2023-01-18 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 490274.
python3kgae added a comment.

Rebase and update test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136913

Files:
  clang/include/clang/Sema/HLSLExternalSemaSource.h
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/AST/HLSL/RWByteAddressBuffer.hlsl
  clang/test/SemaHLSL/BuiltIns/RWByteAddressBuffer.hlsl

Index: clang/test/SemaHLSL/BuiltIns/RWByteAddressBuffer.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BuiltIns/RWByteAddressBuffer.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify %s
+
+typedef vector float3;
+
+RWByteAddressBuffer Buffer;
+
+[numthreads(1,1,1)]
+void main() {
+  (void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::RWByteAddressBuffer'}}
+  // expected-note@* {{implicitly declared private here}}
+  Buffer.Load(0);
+}
Index: clang/test/AST/HLSL/RWByteAddressBuffer.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/RWByteAddressBuffer.hlsl
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s
+
+RWByteAddressBuffer U;
+typedef unsigned int uint;
+typedef vector float2;
+
+// CHECK:CXXRecordDecl 0x{{[0-9a-f]+}} <>  implicit referenced  class RWByteAddressBuffer definition
+// CHECK:FinalAttr 0x{{[0-9a-f]+}} <> Implicit final
+// CHECK-NEXT:HLSLResourceAttr 0x{{[0-9a-f]+}} <> Implicit UAV RawBuffer
+// CHECK-NEXT:-FieldDecl 0x[[HDL:[0-9a-f]+]] <>  implicit referenced h 'void *'
+// CHECK-NEXT:CXXConstructorDecl 0x{{[0-9a-f]+}} <>  used RWByteAddressBuffer 'void ()' inline
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} <>
+// CHECK-NEXT:BinaryOperator 0x{{[0-9a-f]+}} <> 'void *' lvalue '='
+// CHECK-NEXT:MemberExpr 0x{{[0-9a-f]+}} <> 'void *' lvalue .h 0x[[HDL]]
+// CHECK-NEXT:-CXXThisExpr 0x{{[0-9a-f]+}} <> 'hlsl::RWByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT:CallExpr 0x{{[0-9a-f]+}} <> 'void *'
+// CHECK-NEXT:-DeclRefExpr 0x{{[0-9a-f]+}} <> 'void *(unsigned char) throw()' Function 0x{{[0-9a-f]+}} '__builtin_hlsl_create_handle' 'void *(unsigned char) throw()'
+// CHECK-NEXT:-IntegerLiteral 0x{{[0-9a-f]+}} <> 'unsigned char' 1
+// CHECK-NEXT:FunctionTemplateDecl 0x{{[0-9a-f]+}} <>  Load
+// CHECK-NEXT:TemplateTypeParmDecl 0x{{[0-9a-f]+}} <>  class depth 0 index 0 T
+// CHECK-NEXT:CXXMethodDecl 0x{{[0-9a-f]+}} <>  Load 'T (unsigned int)'
+// CHECK-NEXT:ParmVarDecl 0x[[LOAD_PARAM:[0-9a-f]+]] <>  ByteAddress 'unsigned int'
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} <>
+// CHECK-NEXT:ReturnStmt 0x{{[0-9a-f]+}} <>
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}} <> 'T' 
+// CHECK-NEXT:UnaryOperator 0x{{[0-9a-f]+}} <> 'T' lvalue prefix '*' cannot overflow
+// CHECK-NEXT:CStyleCastExpr 0x{{[0-9a-f]+}} <> 'T *' lvalue 
+// CHECK-NEXT:inaryOperator 0x{{[0-9a-f]+}} <> 'unsigned char *' '+'
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}} <> 'unsigned char *' 
+// CHECK-NEXT:CStyleCastExpr 0x{{[0-9a-f]+}} <> 'unsigned char *' lvalue 
+// CHECK-NEXT:MemberExpr 0x{{[0-9a-f]+}} <> 'void *' lvalue ->h 0x[[HDL]]
+// CHECK-NEXT:CXXThisExpr 0x{{[0-9a-f]+}} <> 'hlsl::RWByteAddressBuffer *' implicit this
+// CHECK-NEXT:DeclRefExpr 0x{{[0-9a-f]+}} <> 'unsigned int' ParmVar 0x[[LOAD_PARAM]] 'ByteAddress' 'unsigned int'
+
+// CHECK:CXXMethodDecl 0x[[LOAD_F:[0-9a-f]+]] <>  used Load 'float (unsigned int)'
+// CHECK-NEXT:TemplateArgument type 'float'
+// CHECK-NEXT:BuiltinType 0x{{[0-9a-f]+}} 'float'
+
+// CHECK:CXXMethodDecl 0x[[LOAD_F2:[0-9a-f]+]] <>  used Load 'float (unsigned int) __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:TemplateArgument type 'float __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:ExtVectorType 0x{{[0-9a-f]+}} 'float __attribute__((ext_vector_type(2)))' 2
+// CHECK-NEXT:BuiltinType 0x{{[0-9a-f]+}} 'float'
+
+// CHECK:CXXMethodDecl 0x[[LOAD_S:[0-9a-f]+]] <>  used Load 'S (unsigned int)'
+// CHECK-NEXT:TemplateArgument type 'S'
+// CHECK-NEXT:-RecordType 0x{{[0-9a-f]+}} 'S'
+// CHECK-NEXT:CXXRecord 0x[[RECORD:[0-9a-f]+]] 'S'
+
+// CHECK:VarDecl 0x[[BUF:[0-9a-f]+]] <{{.+}}:1, col:21> col:21 used U 'RWByteAddressBuffer':'hlsl::RWByteAddressBuffer'
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:{{[0-9]+}}:7 foo 'float (uint)'
+// CHECK-NEXT:ParmVarDecl 0x[[FOO_PARAM:[0-9a-f]+]]  col:16 used i 'uint':'unsigned int'
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:ReturnStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:CXXMemberCallExpr 0x{{[0-9a-f]+}}  'float':'float'
+// CHECK-NEXT:MemberExpr 0x{{[0-9a-f]+}}  '' .Load 0x[[LOAD_F]]
+// CHECK-NEXT:DeclRefExpr 0x{{[0-9a-f]+}}  'RWByteAddressBuffer':'hlsl::RWByteAddressBuffer' lvalue Var 0x[[BUF]] 'U' 'RWByteAddressBuffer':'hlsl::RWByteAddressBuffer'
+// CHECK-NEXT:ImplicitCastExpr 

[PATCH] D141441: [clang] Add ElaboratedType sugaring for types on implicit special members

2023-01-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

This makes sense to me, and it looks like the memory impact from the extra type 
nodes should be relatively small.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141441

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1764
+  the ``external_source_symbol`` attribute with
+  ``__has_attribute(external_source_symbol_with_usr)``.
+

erichkeane wrote:
> arphaman wrote:
> > aaron.ballman wrote:
> > > erichkeane wrote:
> > > > I don't think we can do this.  __has_attribute needs to take the actual 
> > > > name of the attribute.
> > > +1
> > `__has_attribute(external_source_symbol)` already works but it wouldn't 
> > help here as it doesn't tell whether the attribute supports USR or not. Are 
> > you saying I should come up with a totally new attribute that accepts USR? 
> > That was originally why I had the `__has_feature` check.
> The typical way of doing this in the standard is to have 
> __has_c_attribute/__has_cpp_attribute return a larger non-zero value for the 
> normal attribute.
> 
> I suspect we should extend `__has_attribute` to do something similar (that 
> is, allowing Feature Test Macros' for it).  Aaron, WDYT?
> The typical way of doing this in the standard is to have 
> has_c_attribute/has_cpp_attribute return a larger non-zero value for the 
> normal attribute.

Which we expose for the CXX11 and C2X spellings in Attr.td, but don't expose 
for the `Clang` spelling (easy enough to change).

> I suspect we should extend __has_attribute to do something similar (that is, 
> allowing Feature Test Macros' for it). Aaron, WDYT?

+1, if we don't already do that. This should be handled entirely within Attr.td 
and ClangAttrEmitter.cpp for a generic solution.


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

https://reviews.llvm.org/D141324

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1764
+  the ``external_source_symbol`` attribute with
+  ``__has_attribute(external_source_symbol_with_usr)``.
+

arphaman wrote:
> aaron.ballman wrote:
> > erichkeane wrote:
> > > I don't think we can do this.  __has_attribute needs to take the actual 
> > > name of the attribute.
> > +1
> `__has_attribute(external_source_symbol)` already works but it wouldn't help 
> here as it doesn't tell whether the attribute supports USR or not. Are you 
> saying I should come up with a totally new attribute that accepts USR? That 
> was originally why I had the `__has_feature` check.
The typical way of doing this in the standard is to have 
__has_c_attribute/__has_cpp_attribute return a larger non-zero value for the 
normal attribute.

I suspect we should extend `__has_attribute` to do something similar (that is, 
allowing Feature Test Macros' for it).  Aaron, WDYT?


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

https://reviews.llvm.org/D141324

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-18 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1764
+  the ``external_source_symbol`` attribute with
+  ``__has_attribute(external_source_symbol_with_usr)``.
+

aaron.ballman wrote:
> erichkeane wrote:
> > I don't think we can do this.  __has_attribute needs to take the actual 
> > name of the attribute.
> +1
`__has_attribute(external_source_symbol)` already works but it wouldn't help 
here as it doesn't tell whether the attribute supports USR or not. Are you 
saying I should come up with a totally new attribute that accepts USR? That was 
originally why I had the `__has_feature` check.


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

https://reviews.llvm.org/D141324

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


[PATCH] D141954: Forbid implicit conversion of constraint expression to bool

2023-01-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:377-380
+  SubstitutedExpression = ImplicitCastExpr::Create(
+  S.Context, SubstitutedExpression.get()->getType(),
+  CK_LValueToRValue, SubstitutedExpression.get(),
+  /*BasePath=*/nullptr, VK_PRValue, FPOptionsOverride());

tahonermann wrote:
> `ImplicitCastExpr::Create()` has the following assertion. I wonder if we need 
> to guard against this here.
>   clang/lib/AST/Expr.cpp:
>   2073   assert((Kind != CK_LValueToRValue ||
>   2074   !(T->isNullPtrType() || T->getAsCXXRecordDecl())) &&
>   2075  "invalid type for lvalue-to-rvalue conversion");
> 
> Or perhaps it would be better to call `Sema::DefaultLvalueConversion()` here?
I don't think we want all the baggage that DefaultLvalueConversion gets us, 
including diagnostics/etc.  That assert IS concerning though... I presume we 
can come up with something to hit that. 

It DOES look like that DefeaultLValue conversion replaces the nullptrtypes with 
a NullToPointer cast, so perhaps I should do that, and doesn't do anything with 
a record type.



Comment at: clang/lib/Sema/SemaConcept.cpp:383
 if (!S.CheckConstraintExpression(SubstitutedExpression.get()))
-  return ExprError();
+  return ExprError(); // convert to bool here?
 

tahonermann wrote:
> This comment appears to be unnecessary.
Woops!  I thought that wasn't mine :D  



Comment at: 
clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp:3-4
+
+template concept C =
+sizeof(T) == 4 && !true;  // requires atomic constraints sizeof(T) == 4 
and !true
+

tahonermann wrote:
> I'm not sure what this is intending to exercise. `C` isn't used elsewhere; 
> this just appears to validate that a well-formed concept declaration is 
> accepted (even if it is one that will always evaluate as false). I suggest 
> modifying it to drop `== 4 && !true` and then validate that a diagnostic is 
> issued (which might require a use of the concept).
This is exactly out of the standard, which is why I copied it.  however, a test 
for the diagnostic version seems like a good idea.


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

https://reviews.llvm.org/D141954

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-01-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D141451#4063151 , @nickdesaulniers 
wrote:

> In D141451#4045658 , @efriedma 
> wrote:
>
>> clang has a "LocTrackingOnly" setting for debug info, which emits DILocation 
>> info into the IR, but emits a marker into the DICompileUnit to skip emitting 
>> the .debug_info in the backend.  We currently use it for -Rpass.  We don't 
>> do this by default, I think to save compile time.
>
> Specifically `emissionKind: NoDebug`, example:
>
> `!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: 
> "clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
> 7b433e026498cf4176931b2407baece1d5060e16)", isOptimized: true, 
> runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, 
> nameTableKind: None)`
>
> Though should the frontend be setting codegen options when parsing? Would the 
> idea be to try to re-set `OPT_debug_info_kind_EQ` when clang codegen's IR for 
> a function with such an attribute?

Probably turn on `emissionKind: NoDebug` whenever the warning is enabled?

> ---
>
> In D141451#4045214 , @dblaikie 
> wrote:
>
>> It'd be nice not to invent a new way of tracking inlining separate from the 
>> way debug info does this - duplicate systems with separate opportunities for 
>> bugs, etc. Any chance we can reuse the debug info inlining descriptions for 
>> this?
>
> So it looks like we have:
>
> `!28 = !DILocation(line: 14, column: 3, scope: !8, inlinedAt: !29)`
>
> Let me see if I can create DILocation without line or column values.

Not sure I follow - why would you want to drop line/column info? Isn't that 
relevant to the inlining stack - you might have multiple calls in the same 
function & it'd be good to know which one the diagnostic is referring to.

>   The DISubprogram and DILocation should form a similar chain, even if 
> significantly more complicated to "unwind."




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1764
+  the ``external_source_symbol`` attribute with
+  ``__has_attribute(external_source_symbol_with_usr)``.
+

erichkeane wrote:
> I don't think we can do this.  __has_attribute needs to take the actual name 
> of the attribute.
+1



Comment at: clang/lib/Basic/Attributes.cpp:30-32
+  // Special case additions of new clauses to existing attributes.
+  if (Name == "external_source_symbol_with_usr")
+return 1;

This is handled automagically for you in Attr.td, but under the correct 
attribute name instead of an invented name.


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

https://reviews.llvm.org/D141324

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1755
+  String that specifies a unified symbol resolution (USR) value for this
+  declaration. USR string uniquely identifies this particular declaration, and
+  is typically used when constructing an index of a codebase.





Comment at: clang/include/clang/Basic/AttrDocs.td:1762
+  When not specified, Clang's indexer will use the Clang USR for this symbol.
+  User can query to see if Clang supports the use of the ``USR`` clause in
+  the ``external_source_symbol`` attribute with





Comment at: clang/include/clang/Basic/AttrDocs.td:1764
+  the ``external_source_symbol`` attribute with
+  ``__has_attribute(external_source_symbol_with_usr)``.
+

I don't think we can do this.  __has_attribute needs to take the actual name of 
the attribute.


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

https://reviews.llvm.org/D141324

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked an inline comment as done.
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Cuda.h:196-197
+
+   void AddCudaIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 

tra wrote:
> Nit: it's hard to tell whether the whitespace additions are spaces or tabs. 
> They show up as ">" to me which suggests it may be tabs. Just in case it is 
> indeed the case, please make sure to un-tabify the changes.
I think it's because the original file was formatted incorrectly, so all my new 
changes are formatted correctly. I'm somewhat more tempted to just clang-format 
it upstream and rebase it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:448-450
+  // If we are invoking `nvlink` internally we need to output a `.cubin` file.
+  // Checking if the output is a temporary is the cleanest way to determine
+  // this. Putting this logic in `getInputFIlename` isn't an option because it

tra wrote:
> Can't say that I like this approach. It heavily relies on "happens to work".
> 
> Perhaps a better way to deal with this is to create the temporary GPU object 
> file name with ".cubin" extension to start with.
> 
> 
> 
As far as I know, the files are created independently of the tool-chains so I'm 
not sure if we'd be able to check there. The current way is to use 
`getInputFilename` but that doesn't have access to the compilation. As far as I 
can come up with there's the following solutions

- Do this and check the temp files
- Create a symbolic link if the file is empty (Doesn't work on Windows)
- Make a random global that's true if the Linker tool was built at some point



Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:469
 
-  bool Relocatable = false;
+  bool Relocatable = true;
   if (JA.isOffloading(Action::OFK_OpenMP))

tra wrote:
> Nit: I'd add an `else { Relocatable = false; // comment on what use cases use 
> relocatable compilation by default. }` and leave it uninitialized here. At 
> the very least it may be worth a comment. Silently defaulting to `true` makes 
> me ask "what other compilation modes we may have?" and stand-alone 
> compilation targeting NVPTX is hard to infer here from the surrounding 
> details.
> 
> 
Works for me.



Comment at: clang/test/Driver/cuda-cross-compiling.c:37-38
+//  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// ARGS-NEXT: ptxas" "-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// ARGS-NEXT: nvlink" "-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+

tra wrote:
> This may fail on windows where ptxas/nvlink will be `ptxas.exe` `nvlink.exe`. 
> I think we typically use something like `fatbinary{{.*}}"` in other tests.
Good point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

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


[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-01-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The Clang bits LGTM, though you should add a release note about the new 
functionality so users know about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141785

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2023-01-18 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

LGTM overall, with few nits.




Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:448-450
+  // If we are invoking `nvlink` internally we need to output a `.cubin` file.
+  // Checking if the output is a temporary is the cleanest way to determine
+  // this. Putting this logic in `getInputFIlename` isn't an option because it

Can't say that I like this approach. It heavily relies on "happens to work".

Perhaps a better way to deal with this is to create the temporary GPU object 
file name with ".cubin" extension to start with.






Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:450
+  // Checking if the output is a temporary is the cleanest way to determine
+  // this. Putting this logic in `getInputFIlename` isn't an option because it
+  // relies on the compilation.

typo: getInputFilename



Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:469
 
-  bool Relocatable = false;
+  bool Relocatable = true;
   if (JA.isOffloading(Action::OFK_OpenMP))

Nit: I'd add an `else { Relocatable = false; // comment on what use cases use 
relocatable compilation by default. }` and leave it uninitialized here. At the 
very least it may be worth a comment. Silently defaulting to `true` makes me 
ask "what other compilation modes we may have?" and stand-alone compilation 
targeting NVPTX is hard to infer here from the surrounding details.





Comment at: clang/lib/Driver/ToolChains/Cuda.h:196-197
+
+   void AddCudaIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 

Nit: it's hard to tell whether the whitespace additions are spaces or tabs. 
They show up as ">" to me which suggests it may be tabs. Just in case it is 
indeed the case, please make sure to un-tabify the changes.



Comment at: clang/test/Driver/cuda-cross-compiling.c:37-38
+//  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// ARGS-NEXT: ptxas" "-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// ARGS-NEXT: nvlink" "-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+

This may fail on windows where ptxas/nvlink will be `ptxas.exe` `nvlink.exe`. I 
think we typically use something like `fatbinary{{.*}}"` in other tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140158

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


  1   2   3   >