[PATCH] D143509: Move the BySpelling map to IncludeStructure.

2023-02-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Headers.h:164
+  llvm::StringMap>
+  buildMainFileIncludesBySpelling() const {
+llvm::StringMap> BySpelling;

instead of building this on-demand, what about building it as we're collecting 
directives around 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/Headers.cpp#L52
 ?

afterwards we can just have a lookup function exposed here, that returns an 
`ArrayRef` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143509

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


[PATCH] D140795: [Flang] Add user option -funderscoring/-fnounderscoring to control trailing underscore added to external names

2023-02-09 Thread Valentin Clement via Phabricator via cfe-commits
clementval added inline comments.



Comment at: flang/test/Fir/external-mangling.fir:36
+
+// CHECK-NOUNDER: func @foo
+// CHECK-NOUNDER: %{{.*}} = fir.address_of(@a) : !fir.ref>

You should check at least the character after it because here the check line 
would also succeed with an underscore. 



Comment at: flang/test/Fir/external-mangling.fir:39-40
+// CHECK-NOUNDER: %{{.*}} = fir.address_of(@__BLNK__) : 
!fir.ref>
+// CHECK-NOUNDER: fir.call @bar
+// CHECK-NOUNDER: fir.call @bar2
+// CHECK-NOUNDER: fir.global common @a(dense<0> : vector<4xi8>) : 
!fir.array<4xi8>

Same here. 



Comment at: flang/test/Fir/external-mangling.fir:85-88
+// CHECK-NOUNDER: func @callee
+// CHECK-NOUNDER: fir.call @callee
+// CHECK-NOUNDER: func @caller
+// CHECK-NOUNDER: fir.call @callee

Same here. 


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

https://reviews.llvm.org/D140795

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


[clang] 2929683 - [clang][codegen] Fix emission of consteval constructor of derived type

2023-02-09 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-02-09T04:43:48-05:00
New Revision: 2929683eef27e6b3ac95325d955cd39bc2e416c0

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

LOG: [clang][codegen] Fix emission of consteval constructor of derived type

For simple derived type ConstantEmitter returns a struct of the same
size but different type which is then stored field-by-field into memory
via pointer to derived type. In case base type has more fields than derived,
the incorrect GEP is emitted. So, just cast pointer to derived type to
appropriate type with enough fields.

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

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGExprAgg.cpp
clang/test/CodeGenCXX/cxx20-consteval-crash.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 35c3fa5780368..4d52dbb27a90e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -64,6 +64,9 @@ Bug Fixes
   driver mode and emit an error which suggests using ``/TC`` or ``/TP``
   ``clang-cl`` options instead. This fixes
   `Issue 59307 `_.
+- Fix crash when evaluating consteval constructor of derived class whose base
+  has more than one field. This fixes
+  `Issue 60166 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 34e535a78dd6e..b7fe7fefec2f9 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@ class AggExprEmitter : public StmtVisitor {
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a 
diff erent type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }

diff  --git a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp 
b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
index 44513599ad916..ebd7eafaf7156 100644
--- a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@ int foo() {
 }
 } // namespace Issue55065
 
+namespace GH60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.GH60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace GH60166



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


[PATCH] D142534: [clang][codegen] Fix emission of consteval constructor of derived type

2023-02-09 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2929683eef27: [clang][codegen] Fix emission of consteval 
constructor of derived type (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142534

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@
 }
 } // namespace Issue55065
 
+namespace GH60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.GH60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace GH60166
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a different type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -64,6 +64,9 @@
   driver mode and emit an error which suggests using ``/TC`` or ``/TP``
   ``clang-cl`` options instead. This fixes
   `Issue 59307 `_.
+- Fix crash when evaluating consteval constructor of derived class whose base
+  has more than one field. This fixes
+  `Issue 60166 `_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@
 }
 } // namespace Issue55065
 
+namespace GH60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.GH60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace GH60166
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a different type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===

[PATCH] D143632: [clang] Handle __declspec() attributes in using

2023-02-09 Thread Tobias Hieta via Phabricator via cfe-commits
thieta created this revision.
thieta added reviewers: aaron.ballman, rsmith, tbaeder, saudi.
Herald added a project: All.
thieta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes so that declspec attributes are forwarded
to the alias declaration.

Before this patch this would assert:

class Test { int a; };
using AlignedTest = __declspec(align(16)) const Test;
static_assert(alignof(AlignedTest) == 16, "error");

But afterwards it behaves the same as MSVC does and doesn't
assert.

Fixes: llvm/llvm-project#60513


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143632

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/SemaCXX/using-declspec.cpp


Index: clang/test/SemaCXX/using-declspec.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-declspec.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+struct Test { int a; };
+using AlignedTest = __declspec(align(16)) const Test;
+static_assert(alignof(AlignedTest) == 16, "error");
\ No newline at end of file
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -56,6 +56,15 @@
   if (OwnedType)
 *OwnedType = DS.isTypeSpecOwned() ? DS.getRepAsDecl() : nullptr;
 
+  // Move declspec attributes to ParsedAttributes
+  llvm::SmallVector ToBeMoved;
+  for (ParsedAttr &AL : DS.getAttributes())
+if (AL.isDeclspecAttribute())
+  ToBeMoved.push_back(&AL);
+
+  for (ParsedAttr *AL : ToBeMoved)
+Attrs->takeOneFrom(DS.getAttributes(), AL);
+
   // Parse the abstract-declarator, if present.
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), Context);
   ParseDeclarator(DeclaratorInfo);


Index: clang/test/SemaCXX/using-declspec.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-declspec.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+struct Test { int a; };
+using AlignedTest = __declspec(align(16)) const Test;
+static_assert(alignof(AlignedTest) == 16, "error");
\ No newline at end of file
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -56,6 +56,15 @@
   if (OwnedType)
 *OwnedType = DS.isTypeSpecOwned() ? DS.getRepAsDecl() : nullptr;
 
+  // Move declspec attributes to ParsedAttributes
+  llvm::SmallVector ToBeMoved;
+  for (ParsedAttr &AL : DS.getAttributes())
+if (AL.isDeclspecAttribute())
+  ToBeMoved.push_back(&AL);
+
+  for (ParsedAttr *AL : ToBeMoved)
+Attrs->takeOneFrom(DS.getAttributes(), AL);
+
   // Parse the abstract-declarator, if present.
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), Context);
   ParseDeclarator(DeclaratorInfo);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f28c28e - Simplify test from change D73904

2023-02-09 Thread Michael Platings via cfe-commits

Author: Michael Platings
Date: 2023-02-09T10:05:01Z
New Revision: f28c28e6645723c01c73478a9d18f0bf0551767a

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

LOG: Simplify test from change D73904

This part of the test can break if multilib is enabled, and isn't
important to testing the change with which is was added.

The relevant part of the test is
ARM-EABI: "-lclang_rt.builtins-arm"
which remains.

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

Added: 


Modified: 
clang/test/Driver/arm-compiler-rt.c

Removed: 




diff  --git a/clang/test/Driver/arm-compiler-rt.c 
b/clang/test/Driver/arm-compiler-rt.c
index a8ea38a7da3c5..a101396862c58 100644
--- a/clang/test/Driver/arm-compiler-rt.c
+++ b/clang/test/Driver/arm-compiler-rt.c
@@ -2,7 +2,6 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-EABI
-// ARM-EABI: 
"-L{{.*[/\\]}}Inputs/resource_dir_with_arch_subdir{{/|}}lib{{/|}}baremetal"
 // ARM-EABI: "-lclang_rt.builtins-arm"
 
 // RUN: %clang -target arm-linux-gnueabi \



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


[PATCH] D143590: [NFC] Simplify test from change D73904

2023-02-09 Thread Michael Platings via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf28c28e66457: Simplify test from change D73904 (authored by 
michaelplatings).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143590

Files:
  clang/test/Driver/arm-compiler-rt.c


Index: clang/test/Driver/arm-compiler-rt.c
===
--- clang/test/Driver/arm-compiler-rt.c
+++ clang/test/Driver/arm-compiler-rt.c
@@ -2,7 +2,6 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-EABI
-// ARM-EABI: 
"-L{{.*[/\\]}}Inputs/resource_dir_with_arch_subdir{{/|}}lib{{/|}}baremetal"
 // ARM-EABI: "-lclang_rt.builtins-arm"
 
 // RUN: %clang -target arm-linux-gnueabi \


Index: clang/test/Driver/arm-compiler-rt.c
===
--- clang/test/Driver/arm-compiler-rt.c
+++ clang/test/Driver/arm-compiler-rt.c
@@ -2,7 +2,6 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-EABI
-// ARM-EABI: "-L{{.*[/\\]}}Inputs/resource_dir_with_arch_subdir{{/|}}lib{{/|}}baremetal"
 // ARM-EABI: "-lclang_rt.builtins-arm"
 
 // RUN: %clang -target arm-linux-gnueabi \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138254: [llvm] Fix the build on OpenBSD by removing LLVM_VERSION_SUFFIX from created shared library names

2023-02-09 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

@brad is this something you still need for OpenBSD?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138254

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


[PATCH] D142094: [Clang][Doc] Add release note for changes of the RVV intrinsics

2023-02-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD abandoned this revision.
eopXD added a comment.

This was cherry-picked into the release branch of LLVM 16. Closing the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142094

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


[PATCH] D143634: [ModuleUtils] Assert correct linkage and visibility of structors' COMDAT key

2023-02-09 Thread Marco Elver via Phabricator via cfe-commits
melver created this revision.
melver added reviewers: MaskRay, vitalybuka, fmayer, pcc.
Herald added subscribers: luke, Enna1, kosarev, frasercrmck, kerbowa, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, jvesely.
Herald added a project: All.
melver requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead.
Herald added projects: clang, LLVM.

Currently structors of various sanitizers have internal linkage, even
with a COMDAT set. This means that semantics is not the same with LTO,
because LTO uses linkage to deduplicate and not the COMDAT. The result
is that a target built with LTO currently has numerous duplicate
redundant constructors and destructors generated by the sanitizers.

This can be fixed by marking the structor as having external linkage.
However, care must be taken to also set hidden visibility, otherwise a
DSO may not call its own structor but another, which is usually wrong.

To allow the caller full flexibility over precise linkage and
visibility, we can't just set it for the caller.

Add an assertion that checks the various rules.

Along the way, we now have to fix up ASan, HWASan, and SanCov to emit
the right linkage.

See also: https://maskray.me/blog/2021-07-25-comdat-and-section-group#grp_comdat


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143634

Files:
  clang/test/CodeGen/asan-destructor-kind.cpp
  clang/test/CodeGen/asan-no-globals-no-comdat.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
  llvm/lib/Transforms/Utils/ModuleUtils.cpp
  llvm/test/CodeGen/AArch64/pacbti-llvm-generated-funcs-1.ll
  llvm/test/DebugInfo/AArch64/asan-stack-vars.mir
  llvm/test/DebugInfo/COFF/asan-module-ctor.ll
  llvm/test/DebugInfo/COFF/asan-module-without-functions.ll
  llvm/test/DebugInfo/Generic/incorrect-variable-debugloc.ll
  llvm/test/DebugInfo/X86/dbg_value_direct.ll
  
llvm/test/Instrumentation/AddressSanitizer/AMDGPU/asan_do_not_instrument_lds.ll
  llvm/test/Instrumentation/AddressSanitizer/basic.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/kcfi-offset.ll
  llvm/test/Instrumentation/AddressSanitizer/kcfi.ll
  llvm/test/Instrumentation/AddressSanitizer/module-flags.ll
  llvm/test/Instrumentation/AddressSanitizer/no-global-ctors.ll
  llvm/test/Instrumentation/AddressSanitizer/no-globals.ll
  llvm/test/Instrumentation/AddressSanitizer/no_global_dtors.ll
  llvm/test/Instrumentation/AddressSanitizer/program-addrspace.ll
  llvm/test/Instrumentation/AddressSanitizer/version-mismatch-check.ll
  llvm/test/Instrumentation/HWAddressSanitizer/RISCV/basic.ll
  llvm/test/Instrumentation/HWAddressSanitizer/RISCV/with-calls.ll
  llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
  llvm/test/Instrumentation/HWAddressSanitizer/with-calls.ll
  llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
  
llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-8bit-counters.ll
  llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
  llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll

Index: llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll
@@ -73,7 +73,7 @@
   ret void
 }
 
-; ELF-LABEL: define internal void @sancov.module_ctor_trace_pc_guard() #2 comdat {
+; ELF-LABEL: define hidden void @sancov.module_ctor_trace_pc_guard() #2 comdat {
 ; MACHO-LABEL: define internal void @sancov.module_ctor_trace_pc_guard() #2 {
 
 ; CHECK: attributes #2 = { nounwind }
Index: llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
@@ -2,9 +2,11 @@
 
 ; Module ctors should have stable names across modules, not something like
 ; @sancov.module_ctor.3 that may cause duplicate ctors after linked together.
+; They should also have external linkage, so that LTO doesn't end up producing
+; duplicate ctors either.
 
-; CHECK: define internal void @sancov.module_ctor_trace_pc_guard() #[[#]] comdat {
-; CHECK: define internal void @sancov.module_ctor_bool_flag() #[[#]] comdat {
+; CHECK: define hidden void @sancov.module_ctor_trace_pc_guard() #[[#]] comdat {
+; CHECK: define hidden void @sancov.module_ctor_bool_flag() #[[#]] comdat {
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:6

[PATCH] D143634: [ModuleUtils] Assert correct linkage and visibility of structors' COMDAT key

2023-02-09 Thread Marco Elver via Phabricator via cfe-commits
melver added a comment.

This is currently more an RFC - there might be other side-effects not yet 
accounted for, so please review carefully.

Although I have been able to reproduce the issue with an LTO and ASan build 
quite easily. If this is a common usecase for us, we might potentially save a 
good amount of .text size because of the 1000s of redundant structors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143634

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


[clang] 0b704d9 - [Support] Emulate SIGPIPE handling in raw_fd_ostream write for Windows

2023-02-09 Thread Andrew Ng via cfe-commits

Author: Andrew Ng
Date: 2023-02-09T10:39:09Z
New Revision: 0b704d9db7e15723922ee29c6f245d108a09c214

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

LOG: [Support] Emulate SIGPIPE handling in raw_fd_ostream write for Windows

Prevent errors and crash dumps for broken pipes on Windows.

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

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
llvm/include/llvm/Support/ExitCodes.h
llvm/include/llvm/Support/Signals.h
llvm/lib/Support/Windows/Signals.inc
llvm/lib/Support/raw_ostream.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 6c0ff3d30e643..7d43b4094b7d7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1873,14 +1873,12 @@ int Driver::ExecuteCompilation(
 C.CleanupFileMap(C.getFailureResultFiles(), JA, true);
 }
 
-#if LLVM_ON_UNIX
-// llvm/lib/Support/Unix/Signals.inc will exit with a special return code
+// llvm/lib/Support/*/Signals.inc will exit with a special return code
 // for SIGPIPE. Do not print diagnostics for this case.
 if (CommandRes == EX_IOERR) {
   Res = CommandRes;
   continue;
 }
-#endif
 
 // Print extra information about abnormal failures, if possible.
 //

diff  --git a/llvm/include/llvm/Support/ExitCodes.h 
b/llvm/include/llvm/Support/ExitCodes.h
index b9041f5557d52..4eb5dedc688bc 100644
--- a/llvm/include/llvm/Support/ExitCodes.h
+++ b/llvm/include/llvm/Support/ExitCodes.h
@@ -20,9 +20,9 @@
 
 #if HAVE_SYSEXITS_H
 #include 
-#elif __MVS__
-//  does not exist on z/OS. The only value used in LLVM is
-// EX_IOERR, which is used to signal a special error condition (broken pipe).
+#elif __MVS__ || defined(_WIN32)
+//  does not exist on z/OS and Windows. The only value used in LLVM
+// is EX_IOERR, which is used to signal a special error condition (broken 
pipe).
 // Define the macro with its usual value from BSD systems, which is chosen to
 // not clash with more standard exit codes like 1.
 #define EX_IOERR 74

diff  --git a/llvm/include/llvm/Support/Signals.h 
b/llvm/include/llvm/Support/Signals.h
index 937e0572d4a72..70749ce30184a 100644
--- a/llvm/include/llvm/Support/Signals.h
+++ b/llvm/include/llvm/Support/Signals.h
@@ -102,14 +102,17 @@ namespace sys {
   /// functions.  A null handler pointer disables the current installed
   /// function.  Note also that the handler may be executed on a
   /// 
diff erent thread on some platforms.
-  ///
-  /// This is a no-op on Windows.
   void SetOneShotPipeSignalFunction(void (*Handler)());
 
-  /// On Unix systems, this function exits with an "IO error" exit code.
-  /// This is a no-op on Windows.
+  /// On Unix systems and Windows, this function exits with an "IO error" exit
+  /// code.
   void DefaultOneShotPipeSignalHandler();
 
+#ifdef _WIN32
+  /// Windows does not support signals and this handler must be called 
manually.
+  void CallOneShotPipeSignalHandler();
+#endif
+
   /// This function does the following:
   /// - clean up any temporary files registered with RemoveFileOnSignal()
   /// - dump the callstack from the exception context

diff  --git a/llvm/lib/Support/Windows/Signals.inc 
b/llvm/lib/Support/Windows/Signals.inc
index ba93afe0803b4..4bf699f2bccf0 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -10,6 +10,7 @@
 //
 
//===--===//
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -204,6 +205,9 @@ static bool RegisteredUnhandledExceptionFilter = false;
 static bool CleanupExecuted = false;
 static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL;
 
+/// The function to call on "SIGPIPE" (one-time use only).
+static std::atomic OneShotPipeSignalFunction(nullptr);
+
 // Windows creates a new thread to execute the console handler when an event
 // (such as CTRL/C) occurs.  This causes concurrency issues with the above
 // globals which this critical section addresses.
@@ -575,11 +579,16 @@ void llvm::sys::SetInfoSignalFunction(void (*Handler)()) {
 }
 
 void llvm::sys::SetOneShotPipeSignalFunction(void (*Handler)()) {
-  // Unimplemented.
+  OneShotPipeSignalFunction.exchange(Handler);
 }
 
 void llvm::sys::DefaultOneShotPipeSignalHandler() {
-  // Unimplemented.
+  llvm::sys::Process::Exit(EX_IOERR, /*NoCleanup=*/true);
+}
+
+void llvm::sys::CallOneShotPipeSignalHandler() {
+  if (auto OldOneShotPipeFunction = 
OneShotPipeSignalFunction.exchange(nullptr))
+OldOneShotPipeFunction();
 }
 
 /// Add a functi

[PATCH] D142224: [Support] Emulate SIGPIPE handling in raw_fd_ostream write for Windows

2023-02-09 Thread Andrew Ng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b704d9db7e1: [Support] Emulate SIGPIPE handling in 
raw_fd_ostream write for Windows (authored by andrewng).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142224

Files:
  clang/lib/Driver/Driver.cpp
  llvm/include/llvm/Support/ExitCodes.h
  llvm/include/llvm/Support/Signals.h
  llvm/lib/Support/Windows/Signals.inc
  llvm/lib/Support/raw_ostream.cpp

Index: llvm/lib/Support/raw_ostream.cpp
===
--- llvm/lib/Support/raw_ostream.cpp
+++ llvm/lib/Support/raw_ostream.cpp
@@ -56,6 +56,7 @@
 
 #ifdef _WIN32
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/Windows/WindowsSupport.h"
 #endif
 
@@ -775,6 +776,15 @@
   )
 continue;
 
+#ifdef _WIN32
+  // Windows equivalents of SIGPIPE/EPIPE.
+  DWORD WinLastError = GetLastError();
+  if (WinLastError == ERROR_BROKEN_PIPE ||
+  (WinLastError == ERROR_NO_DATA && errno == EINVAL)) {
+llvm::sys::CallOneShotPipeSignalHandler();
+errno = EPIPE;
+  }
+#endif
   // Otherwise it's a non-recoverable error. Note it and quit.
   error_detected(std::error_code(errno, std::generic_category()));
   break;
Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -10,6 +10,7 @@
 //
 //===--===//
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -204,6 +205,9 @@
 static bool CleanupExecuted = false;
 static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL;
 
+/// The function to call on "SIGPIPE" (one-time use only).
+static std::atomic OneShotPipeSignalFunction(nullptr);
+
 // Windows creates a new thread to execute the console handler when an event
 // (such as CTRL/C) occurs.  This causes concurrency issues with the above
 // globals which this critical section addresses.
@@ -575,11 +579,16 @@
 }
 
 void llvm::sys::SetOneShotPipeSignalFunction(void (*Handler)()) {
-  // Unimplemented.
+  OneShotPipeSignalFunction.exchange(Handler);
 }
 
 void llvm::sys::DefaultOneShotPipeSignalHandler() {
-  // Unimplemented.
+  llvm::sys::Process::Exit(EX_IOERR, /*NoCleanup=*/true);
+}
+
+void llvm::sys::CallOneShotPipeSignalHandler() {
+  if (auto OldOneShotPipeFunction = OneShotPipeSignalFunction.exchange(nullptr))
+OldOneShotPipeFunction();
 }
 
 /// Add a function to be called when a signal is delivered to the process. The
@@ -816,7 +825,15 @@
 }
 
 void sys::CleanupOnSignal(uintptr_t Context) {
-  LLVMUnhandledExceptionFilter((LPEXCEPTION_POINTERS)Context);
+  LPEXCEPTION_POINTERS EP = (LPEXCEPTION_POINTERS)Context;
+  // Broken pipe is not a crash.
+  //
+  // 0xE000 is combined with the return code in the exception raised in
+  // CrashRecoveryContext::HandleExit().
+  int RetCode = (int)EP->ExceptionRecord->ExceptionCode;
+  if (RetCode == (0xE000 | EX_IOERR))
+return;
+  LLVMUnhandledExceptionFilter(EP);
 }
 
 static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
Index: llvm/include/llvm/Support/Signals.h
===
--- llvm/include/llvm/Support/Signals.h
+++ llvm/include/llvm/Support/Signals.h
@@ -102,14 +102,17 @@
   /// functions.  A null handler pointer disables the current installed
   /// function.  Note also that the handler may be executed on a
   /// different thread on some platforms.
-  ///
-  /// This is a no-op on Windows.
   void SetOneShotPipeSignalFunction(void (*Handler)());
 
-  /// On Unix systems, this function exits with an "IO error" exit code.
-  /// This is a no-op on Windows.
+  /// On Unix systems and Windows, this function exits with an "IO error" exit
+  /// code.
   void DefaultOneShotPipeSignalHandler();
 
+#ifdef _WIN32
+  /// Windows does not support signals and this handler must be called manually.
+  void CallOneShotPipeSignalHandler();
+#endif
+
   /// This function does the following:
   /// - clean up any temporary files registered with RemoveFileOnSignal()
   /// - dump the callstack from the exception context
Index: llvm/include/llvm/Support/ExitCodes.h
===
--- llvm/include/llvm/Support/ExitCodes.h
+++ llvm/include/llvm/Support/ExitCodes.h
@@ -20,9 +20,9 @@
 
 #if HAVE_SYSEXITS_H
 #include 
-#elif __MVS__
-//  does not exist on z/OS. The only value used in LLVM is
-// EX_IOERR, which is used to signal a special error condition (broken pipe).

[PATCH] D143142: [clang][lex] Enable Lexer to grow its buffer

2023-02-09 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:211
+  L->BufferOffset =
+  StrData - InputFile.getBufferStart(); // FIXME: this is wrong
+  L->BufferSize = L->BufferOffset + TokLen;

Is that an outdated comment? If not maybe elaborate why this is wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143142

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


[PATCH] D143635: [clangd] Refactor new include cleaner functionality into a separate class.

2023-02-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143635

Files:
  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/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -342,7 +342,9 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  std::vector MacroReferences = collectMacroReferences(AST); 
+  CachedIncludeCleaner IncludeCleaner(AST, MacroReferences);
+  EXPECT_THAT(IncludeCleaner.computeUnusedIncludesExperimental(),
   ElementsAre(Pointee(writtenInclusion("";
 }
 
@@ -379,8 +381,10 @@
   computeUnusedIncludes(AST),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
+  std::vector MacroReferences = collectMacroReferences(AST); 
+  CachedIncludeCleaner IncludeCleaner(AST, MacroReferences);
   EXPECT_THAT(
-  computeUnusedIncludesExperimental(AST),
+  IncludeCleaner.computeUnusedIncludesExperimental(),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
 }
@@ -413,8 +417,10 @@
   TU.Code = MainFile.str();
   ParsedAST AST = TU.build();
 
+  std::vector MacroReferences = collectMacroReferences(AST); 
+  CachedIncludeCleaner IncludeCleaner(AST, MacroReferences);
   std::vector> MissingIncludes =
-  computeMissingIncludes(AST);
+  IncludeCleaner.computeMissingIncludes();
 
   std::pair b{"\"b.h\"", 86};
   std::pair d{"\"dir/d.h\"", 97};
@@ -591,7 +597,10 @@
   ReferencedFiles.User.contains(AST.getSourceManager().getMainFileID()));
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
   EXPECT_THAT(computeUnusedIncludes(AST), IsEmpty());
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST), IsEmpty());
+
+  std::vector MacroReferences = collectMacroReferences(AST); 
+  CachedIncludeCleaner IncludeCleaner(AST, MacroReferences);
+  EXPECT_THAT(IncludeCleaner.computeUnusedIncludesExperimental(), IsEmpty());
 }
 
 TEST(IncludeCleaner, RecursiveInclusion) {
@@ -620,7 +629,10 @@
 
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
   EXPECT_THAT(computeUnusedIncludes(AST), IsEmpty());
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST), IsEmpty());
+
+  std::vector MacroReferences = clang::clangd::collectMacroReferences(AST); 
+  CachedIncludeCleaner IncludeCleaner(AST, MacroReferences);
+  EXPECT_THAT(IncludeCleaner.computeUnusedIncludesExperimental(), IsEmpty());
 }
 
 TEST(IncludeCleaner, IWYUPragmaExport) {
@@ -645,7 +657,9 @@
   // FIXME: This is not correct: foo.h is unused but is not diagnosed as such
   // because we ignore headers with IWYU export pragmas for now.
   EXPECT_THAT(computeUnusedIncludes(AST), IsEmpty());
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST), IsEmpty());
+  std::vector MacroReferences = collectMacroReferences(AST); 
+  CachedIncludeCleaner IncludeCleaner(AST, MacroReferences);
+  EXPECT_THAT(IncludeCleaner.computeUnusedIncludesExperimental(), IsEmpty());
 }
 
 TEST(IncludeCleaner, NoDiagsForObjC) {
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -168,6 +168,9 @@
   std::unique_ptr Resolver;
 };
 
+std::vector
+collectMacroReferences(ParsedAST &AST);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -341,6 +341,27 @@
 
 } // namespace
 
+std::vector
+collectMacroReferences(ParsedAST &AST) {
+  const auto &SM = AST.getSourceManager();
+  //  FIXME: !!this is a hacky way to collect macro references.
+  std::vector Macros;
+  auto &PP = AST.getPreprocessor();
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = locateMacroAt(Tok, PP);
+if (!Macro)
+  continue;
+if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  Macros.push_back(
+  {Tok.location(),
+   include_cleaner::Macro{/*Name=*/

[PATCH] D143587: [Docs] Multilib design

2023-02-09 Thread Amilendra Kodithuwakku via Phabricator via cfe-commits
amilendra added a comment.

Thanks for the design docs. At a high-level this gives a good summary on what 
you intend the multilib feature to do. Couple of suggestions.




Comment at: clang/docs/Multilib.rst:86-89
+   a match.
+   If more than one variant matches then a toolchain may opt to either use only
+   the *last* matching multilib variant, or may use all matching variants,
+   thereby layering them.

Would it be possible to give more details on how the toolchain makes this 
choice?



Comment at: clang/docs/Multilib.rst:97
+
+Multilib via configuration file shall be considered an experimental feature
+until LLVM 18, at which point ``-print-multi-selection-flags-experimental``

Would it be worth to also add a flag to activate/deactivate the multilib 
feature for the duration that it is experimental?
IIUC, a similar mechanism was used before switching to a new pass manager.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

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


[PATCH] D143587: [Docs] Multilib design

2023-02-09 Thread Amilendra Kodithuwakku via Phabricator via cfe-commits
amilendra added inline comments.



Comment at: clang/docs/Multilib.rst:89
+   the *last* matching multilib variant, or may use all matching variants,
+   thereby layering them.
+#. Generate ``-isystem`` and ``-L`` arguments. Iterate in reverse order over

What would be the effect of layering? Does this mean multiple choices for 
`--sysroot``, ``-isystem`` and ``-L`` will be used?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Config.h:91
 
+  enum class MissingIncludesPolicy {
+/// Diagnose missing includes.

rather than duplicating, what about renaming `UnusedIncludesPolicy` to 
`IncludesPolicy` and use it for both `UnusedIncludes` and `MissingIncludes` 
options below?



Comment at: clang-tools-extra/clangd/ConfigFragment.h:224
 
-/// Controls how clangd will correct "unnecessary #include directives.
+/// Controls how clangd will correct "unnecessary" #include directives.
 /// clangd can warn if a header is `#include`d but not used, and suggest

nit: i'd rather drop the quotes completely to match your description of 
MissingIncludes below.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:238
 
+/// Controls how clangd handles missing #include directives.
+/// clangd can warn if a header for a symbol is not `#include`d (missing),





Comment at: clang-tools-extra/clangd/ConfigFragment.h:239-240
+/// Controls how clangd handles missing #include directives.
+/// clangd can warn if a header for a symbol is not `#include`d (missing),
+/// and suggest adding it.
+///





Comment at: clang-tools-extra/clangd/ConfigFragment.h:242
+///
+/// Strict means a header is missing if it is not *directly #include'd.
+/// The file might still compile if the header is included transitively.





Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:516
+
+  std::vector Macros =
+  collectMacroReferences(AST);





Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:547
+convertIncludes(const SourceManager &SM,
+std::vector MainFileIncludes) {
+  include_cleaner::Includes Includes;

you can just pass an `llvm::ArrayRef` to prevent a copy



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:550
+  for (const Inclusion &Inc : MainFileIncludes) {
+llvm::ErrorOr ResolvedOrError =
+SM.getFileManager().getFile(Inc.Resolved);

you can re-write this as:
```
include_cleaner::Include TransformedInc;
TransformedInc.Spelled = Inc.Written.trim("\"<>");
TransformedInc.HashLocation = SM.getComposedLoc(SM.getMainFileID(), 
Inc.HashOffset); // we should actually convert this from a SourceLocation to 
offset in include_cleaner::Include as well
TransformedInc.Line = Inc.HashLine;
TransformedInc.Angled = WrittenRef.starts_with("<");
if(auto FE = SM.getFileManager().getFile(Inc.Resolved))
  TransformedInc.Resolved = *FE;
Includes.add(std::move(TransformedInc));
```



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:570
+computeMissingIncludes(ParsedAST &AST) {
+  std::vector Macros =
+  collectMacroReferences(AST);

nit: `auto Macros = ..`



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:572
+  collectMacroReferences(AST);
+  std::vector MainFileIncludes =
+  AST.getIncludeStructure().MainFileIncludes;

no need for copying to vector here, `const auto& MainFileIncludes = ...`



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:577
+  convertIncludes(AST.getSourceManager(), MainFileIncludes);
+  std::string FileName =
+  AST.getSourceManager()

you can use `AST.tuPath()`



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:582
+  .str();
+  if (FileName.find("foo") != std::string::npos) {
+vlog("Include cleaner includes: {0}", IncludeCleanerIncludes.all().size());

looks like debugging artifact?



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:593
+  llvm::ArrayRef Providers) {
+bool Satisfied = false;
+for (const include_cleaner::Header &H : Providers) {

nit: you can check whether `Ref.RT` is `Explicit` at the top, and bail out 
early.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:597
+  H.physical() == MainFile) {
+Satisfied = true;
+  }

nit: you can just `break` after satisfying the include (same below)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:605
+Ref.RT == include_cleaner::RefType::Explicit) {
+  std::string SpelledHeader = include_cleaner::spellHeader(
+  Providers.front(), AST.getPreprocessor().getHeaderSearchInfo(),

clangd has some header spelling customizations. so we should actually be doing 
this through 
`URI::includeSpelling(URI::create(getCanonicalPath(Providers.front().physical(),
 SM)))` first, and fall back to `spellHeader` if it fails for physical header 
providers to make sure we're consistent.

this is used by $E

[PATCH] D143587: [Docs] Multilib design

2023-02-09 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 496072.
michaelplatings added a comment.

Made changes requested by @amilendra


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

Files:
  clang/docs/Multilib.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -100,6 +100,7 @@
CodeOwners
InternalsManual
DriverInternals
+   Multilib
OffloadingDesign
PCHInternals
ItaniumMangleAbiTags
Index: clang/docs/Multilib.rst
===
--- /dev/null
+++ clang/docs/Multilib.rst
@@ -0,0 +1,202 @@
+
+Multilib
+
+
+Introduction
+
+
+This document describes how multilib is implemented in Clang.
+
+What is multilib and why might you care?
+If you're :doc:`cross compiling` then you can't use native
+system headers and libraries. To address this, you can use a combination of
+``--sysroot``, ``-isystem`` and ``-L`` options to point clang at suitable
+directories for your target.
+However, when there are many possible directories to choose from, it's not
+necessarily obvious which one to pick.
+Multilib allows a toolchain designer to imbue the toolchain with the ability to
+pick a suitable directory automatically, based on the options the user provides
+to clang. For example, if the user specifies
+``--target=arm-none-eabi -mcpu=cortex-m4`` the toolchain can choose a directory
+containing headers and libraries suitable for Armv7E-M, because it knows that's
+a suitable architecture for Arm Cortex-M4.
+Multilib can also choose between libraries for the same architecture based on
+other options. For example if the user specifies ``-fno-exceptions`` then a
+toolchain could select libraries built without exception support, thereby
+reducing the size of the resulting binary.
+
+Design
+==
+
+Clang supports GCC's ``-print-multi-lib`` and ``-print-multi-directory``
+options. These are described in
+`GCC Developer Options `_.
+
+There are two ways to configure multilib in Clang: hard-coded or via a
+configuration file.
+
+Hard-coded Multilib
+===
+
+The available libraries can be hard-coded in clang. Typically this is done
+using the ``MultilibBuilder`` interface. There are many examples of this in
+``Gnu.cpp``.
+The remainder of this document will not focus on this type of multilib.
+
+Multilib via configuration file
+===
+
+Some clang toolchains support loading multilib configuration from a
+``multilib.yaml`` configuration file.
+
+A ``multilib.yaml`` configuration file specifies which multilib variants are
+available, their relative location, what compilation options were used to build
+them, and the criteria by which they are selected.
+
+Multilib processing
+===
+
+Clang goes through the following steps to use multilib from a configuration
+file:
+#. Convert command line arguments to flags. Clang can accept the same
+   information via different arguments - for example,
+   ``--target=arm-none-eabi -march=armv7-m`` and
+   ``--target=armv7m-none-eabi`` are equivalent. Clang can also accept many
+   independent pieces of information within a single flag - for example
+   ``-march=armv8.1m.main+fp+mve`` specifies the architecture and two
+   extensions in a single command line argument.
+   To make it easier for the multilib system, clang converts the command line
+   arguments into a standard set of simpler "flags". In many cases these flags
+   will look like a command line argument with the leading ``-`` stripped off,
+   but where a suitable form for the flag doesn't exist in command line
+   arguments then its form will be different. For example, an Arm architecture
+   extension is represented like ``march=+mve`` since there's no way to specify
+   it in isolation in a command line argument.
+   To see what flags are emitted for a given set of command line arguments, use
+   the ``-print-multi-selection-flags-experimental`` command line argument
+   along with the rest of the arguments you want to use.
+#. Load ``multilib.yaml`` from sysroot.
+#. Generate additional flags. ``multilib.yaml`` contains a ``flagMap`` section,
+   which specifies how to generate additional flags based on the flags derived
+   from command line arguments. Flags are matched using regular expressions.
+   These regular expressions shall use the POSIX extended regular expression
+   syntax.
+#. Match flags against multilib variants. If the generated flags are a superset
+   of the flags specified for a multilib variant then the variant is considered
+   a match.
+   If more than one variant matches then a toolchain may opt to either use only
+   the *last* matching multilib variant, or may use all matching v

[PATCH] D143587: [Docs] Multilib design

2023-02-09 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings marked 3 inline comments as done.
michaelplatings added inline comments.



Comment at: clang/docs/Multilib.rst:86-89
+   a match.
+   If more than one variant matches then a toolchain may opt to either use only
+   the *last* matching multilib variant, or may use all matching variants,
+   thereby layering them.

amilendra wrote:
> Would it be possible to give more details on how the toolchain makes this 
> choice?
Added below: "This decision is hard-coded per ToolChain subclass"



Comment at: clang/docs/Multilib.rst:89
+   the *last* matching multilib variant, or may use all matching variants,
+   thereby layering them.
+#. Generate ``-isystem`` and ``-L`` arguments. Iterate in reverse order over

amilendra wrote:
> What would be the effect of layering? Does this mean multiple choices for 
> `--sysroot``, ``-isystem`` and ``-L`` will be used?
Added a section below on multilib layering



Comment at: clang/docs/Multilib.rst:97
+
+Multilib via configuration file shall be considered an experimental feature
+until LLVM 18, at which point ``-print-multi-selection-flags-experimental``

amilendra wrote:
> Would it be worth to also add a flag to activate/deactivate the multilib 
> feature for the duration that it is experimental?
> IIUC, a similar mechanism was used before switching to a new pass manager.
I think no because the feature is implicitly disabled by a lack of 
multilib.yaml. I added some text explaining what's necessary to enable the 
feature which hopefully makes that clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

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


[PATCH] D143638: [clangd] Move function body to out-of-line: unnamed class method incorrect moving

2023-02-09 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin created this revision.
denis-fatkulin added reviewers: kadircet, sammccall.
Herald added a subscriber: arphaman.
Herald added a project: All.
denis-fatkulin requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The refactoring !!Move function body to out-of-line!! produces incorrect code 
for methods of unnamed classes.
For this simple example

  // foo.h
  struct Foo {
struct {
  void f^oo() {}
} Bar;
  };

the refactoring generates code:

  // foo.cpp
  void Foo::(unnamed struct at D:\test\foo.h:2:3)foo() {}

Outplace definition for methods of unnamed classes is meaningless. The patch 
disables it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143638

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,23 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -397,6 +397,14 @@
 if (auto *MD = llvm::dyn_cast(Source)) {
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes.
+  const auto *Parent = MD->getParent();
+  while (Parent) {
+if (Parent->getName().empty())
+  return false;
+Parent = llvm::dyn_cast_or_null(Parent->getParent());
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,23 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -397,6 +397,14 @@
 if (auto *MD = llvm::dyn_cast(Source)) {
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes.
+  const auto *Parent = MD->getParent();
+  while (Parent) {
+if (Parent->getName().empty())
+  return false;
+Parent = llvm::dyn_cast_or_null(Parent->getParent());
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127910: [Clang][AArch64][SME] Add vector load/store (ld1/st1) intrinsics

2023-02-09 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Thanks a lot for making all the changes @bryanpkc - it's looking really good 
now! I just have a few minor comments/suggestions and then I think it looks 
good to go.




Comment at: clang/include/clang/Basic/arm_sme.td:22
+let TargetGuard = "sme" in {
+  def SVLD1_HOR_ZA8 : MInst<"svld1_hor_za8", "vimiPQ", "c", [IsLoad, 
IsOverloadNone, IsStreaming, IsSharedZA], MemEltTyDefault, 
"aarch64_sme_ld1b_horiz", [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_15>]>;
+  def SVLD1_HOR_ZA16 : MInst<"svld1_hor_za16", "vimiPQ", "s", [IsLoad, 
IsOverloadNone, IsStreaming, IsSharedZA], MemEltTyDefault, 
"aarch64_sme_ld1h_horiz", [ImmCheck<0, ImmCheck0_1>, ImmCheck<2, ImmCheck0_7>]>;

This is just a suggestion, but you could reduce the lines of code here if you 
want by creating a multiclass that creates both the horizontal and vertical 
variants for each size, i.e. something like

  multiclass MyMultiClass<..> {
def NAME # _H : MInst<...>
def NAME # _V : MInst<...>
  }

  defm SVLD1_ZA8 : MyMultiClass<...>;

or whatever naming scheme you prefer, and same for the stores. Feel free to 
ignore this suggestion though if it doesn't help you!



Comment at: clang/lib/Basic/Targets/AArch64.cpp:438
 
+  if (HasSME)
+Builder.defineMacro("__ARM_FEATURE_SME", "1");

bryanpkc wrote:
> david-arm wrote:
> > Can you remove this please? We can't really set this macro until the SME 
> > ABI and ACLE is feature complete.
> OK. Could you educate me what else is needed for SME ABI and ACLE to be 
> feature-complete? How can I help?
It should have complete support for the SME ABI and ACLE in terms of supporting 
the C/C++ level attributes as described here  - 
https://arm-software.github.io/acle/main/acle.html#sme-language-extensions-and-intrinsics.
 For example, the compiler should support cases where a normal function calls a 
`arm_streaming` function and sets up the state correctly, etc. You can see 
@sdesmalen's patch to add the clang-side attributes here D127762. There should 
also be full support for all of the SME ACLE builtins.



Comment at: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp:3
+
+// RUN: %clang_cc1 -D__ARM_FEATURE_SME -triple aarch64-none-linux-gnu 
-target-feature +sve -target-feature +sme -fsyntax-only -verify 
-verify-ignore-unexpected=error %s
+// RUN: %clang_cc1 -D__ARM_FEATURE_SME -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only 
-verify -verify-ignore-unexpected=error %s

I think you can remove the `-target-feature +sve` flags from the RUN lines 
because `+sme` should imply that.



Comment at: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp:16
+__attribute__((arm_streaming))
+void test_range_0_0(svbool_t pg, void *ptr) {
+  // expected-error-re@+1 {{argument value 0 is outside the valid range [0, 
0]}}

These tests are great! Thanks for doing this. Could you also add the `_vnum` 
variants too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

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


[PATCH] D127910: [Clang][AArch64][SME] Add vector load/store (ld1/st1) intrinsics

2023-02-09 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/lib/Headers/CMakeLists.txt:332
+  # Generate arm_sme.h
+  clang_generate_header(-gen-arm-sme-header arm_sme.td arm_sme.h)
   # Generate arm_bf16.h

The ACLE specification is still in a draft (ALP) state, which means there may 
still be subject to significant changes. To avoid users from using this 
implementation with the expectation that their code is compliant going forward, 
it would be good to rename the header file to something that makes it very 
clear this feature is not yet ready to use. I'm thinking of something like 
`arm_sme_draft_spec_subject_to_change.h`. When the specification goes out of 
draft, we can rename it to `arm_sme.h`. Could you rename the file for now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

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


[PATCH] D143640: [Tooling/Inclusion] Support overload symbols in the stdlib.

2023-02-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143640

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Testing/TestAST.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
@@ -62,6 +63,9 @@
   ElementsAre(stdlib::Header::named(""),
   stdlib::Header::named(""),
   stdlib::Header::named("")));
+  // Ambiguous symbol, we return the first one which always map to 
+  EXPECT_THAT(stdlib::Symbol::named("std::", "move")->headers(),
+  ElementsAre(stdlib::Header::named("")));
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
@@ -94,7 +98,6 @@
 struct vector { class nested {}; };
 
 class secret {};
-
 } // inl
 
 inline namespace __1 {
@@ -144,6 +147,73 @@
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
+TEST(StdlibTest, RecognizerAmbiguousSymbol) {
+  struct {
+llvm::StringRef Code;
+llvm::StringRef QName;
+
+llvm::StringRef ExpectedHeader;
+  } TestCases[] = {
+  {
+  R"cpp(
+namespace std {
+ template 
+ constexpr OutputIt move(InputIt first, InputIt last, OutputIt dest);
+})cpp",
+  "std::move",
+  "",
+  },
+  {
+  R"cpp(
+namespace std {
+  template constexpr T move(T&& t) noexcept;
+})cpp",
+  "std::move",
+  "",
+  },
+  {
+  R"cpp(
+namespace std {
+  template
+  ForwardIt remove(ForwardIt first, ForwardIt last, const T& value);
+})cpp",
+  "std::remove",
+  "",
+  },
+  {
+  "namespace std { int remove(const char*); }",
+  "std::remove",
+  "",
+  },
+  };
+
+  struct DeclCapturer : RecursiveASTVisitor {
+llvm::StringRef TargetQName;
+const NamedDecl *Out = nullptr;
+
+DeclCapturer(llvm::StringRef TargetQName) : TargetQName(TargetQName) {}
+bool VisitNamedDecl(const NamedDecl *ND) {
+  if (auto *TD = ND->getDescribedTemplate())
+ND = TD;
+  if (ND->getQualifiedNameAsString() == TargetQName) {
+EXPECT_TRUE(Out == nullptr || Out == ND->getCanonicalDecl())
+<< "Found multiple matches for " << TargetQName;
+Out = cast(ND->getCanonicalDecl());
+  }
+  return true;
+}
+  };
+  stdlib::Recognizer Recognizer;
+  for (auto &T : TestCases) {
+TestAST AST(T.Code);
+DeclCapturer V(T.QName);
+V.TraverseDecl(AST.context().getTranslationUnitDecl());
+ASSERT_TRUE(V.Out);
+EXPECT_THAT(Recognizer(V.Out)->headers(),
+ElementsAre(stdlib::Header::named(T.ExpectedHeader)));
+  }
+}
+
 } // namespace
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
@@ -35,11 +36,24 @@
 const char *Data;  // std::vector
 unsigned ScopeLen; // ~
 unsigned NameLen;  //  ~~
+SymbolName() = default;
+SymbolName(const char *Data, unsigned ScopeLen, unsigned NameLen,
+   bool Ambiguous, unsigned ParameterCount)
+: Data(Data), ScopeLen(ScopeLen), NameLen(NameLen),
+  Ambiguous(Ambiguous), ParameterCount(ParameterCount) {}
+
 StringRef scope() const { return StringRef(Data, ScopeLen); }
 StringRef name() const { return StringRef(Data + ScopeLen, NameLen); }
 StringRef qualifiedName() const {
   return StringRef(Data, ScopeLen + NameLen);
 }
+
+// True if symbol is ambiguous, which cannot be distinguish by the
+// fully qualified name, e.g. std::move.
+bool Ambiguous : 1;
+// Extra symbol information for disambiguati

[clang-tools-extra] 2706919 - [clang-tidy][doc] Improve clang-tidy documentation

2023-02-09 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-02-09T12:19:36Z
New Revision: 2706919f91977f3859ad625d4fb624fb04857e4f

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

LOG: [clang-tidy][doc] Improve clang-tidy documentation

- Specify that the .clang-tidy file is in YAML format.
- Document the options that may be used in the .clang-tidy file,
- Add missing documentation for existing options (User).
- Fix spurious newline after the dash that comes after every
  command-line option. This was inconsistent with single-line
  descriptions, which lacked a newline. The description is now
  aligned with the dash and the corresponding command-line option,
  more visually pleasing.

This enables documenting upcoming global clang-tidy
configuration options.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/docs/clang-tidy/index.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 765b8483561ea..ff673e78a2836 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -31,6 +31,10 @@
 using namespace clang::tooling;
 using namespace llvm;
 
+static cl::desc desc(StringRef description) {
+  return cl::desc(description.ltrim());
+}
+
 static cl::OptionCategory ClangTidyCategory("clang-tidy options");
 
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
@@ -38,13 +42,37 @@ static cl::extrahelp ClangTidyHelp(R"(
 Configuration files:
   clang-tidy attempts to read configuration for each source file from a
   .clang-tidy file located in the closest parent directory of the source
-  file. If InheritParentConfig is true in a config file, the configuration file
-  in the parent directory (if any exists) will be taken and current config file
-  will be applied on top of the parent one. If any configuration options have
-  a corresponding command-line option, command-line option takes precedence.
-  The effective configuration can be inspected using -dump-config:
-
-$ clang-tidy -dump-config
+  file. The .clang-tidy file is specified in YAML format. If any configuration
+  options have a corresponding command-line option, command-line option takes
+  precedence.
+
+  The following configuration options may be used in a .clang-tidy file:
+
+  CheckOptions - List of key-value pairs defining 
check-specific
+ options. Example:
+   CheckOptions:
+ some-check.SomeOption: 'some value'
+  Checks   - Same as '--checks'.
+  ExtraArgs- Same as '--extra-args'.
+  ExtraArgsBefore  - Same as '--extra-args-before'.
+  FormatStyle  - Same as '--format-style'.
+  HeaderFilterRegex- Same as '--header-filter-regex'.
+  InheritParentConfig  - If this option is true in a config file, the
+ configuration file in the parent directory
+ (if any exists) will be taken and the current
+ config file will be applied on top of the
+ parent one.
+  SystemHeaders- Same as '--system-headers'.
+  UseColor - Same as '--use-color'.
+  User - Specifies the name or e-mail of the user
+ running clang-tidy. This option is used, for
+ example, to place the correct user name in
+ TODO() comments in the relevant check.
+  WarningsAsErrors - Same as '--warnings-as-errors'.
+
+  The effective configuration can be inspected using --dump-config:
+
+$ clang-tidy --dump-config
 ---
 Checks:  '-*,some-check'
 WarningsAsErrors:''
@@ -62,7 +90,7 @@ const char DefaultChecks[] = // Enable these checks by 
default:
 "clang-diagnostic-*,"//   * compiler diagnostics
 "clang-analyzer-*";  //   * Static Analyzer checks
 
-static cl::opt Checks("checks", cl::desc(R"(
+static cl::opt Checks("checks", desc(R"(
 Comma-separated list of globs with optional '-'
 prefix. Globs are processed in order of
 appearance in the list. Globs without '-'
@@ -75,7 +103,7 @@ file, if any.
 )"),
cl::init(""), cl::cat(ClangTidyCategory));
 
-static cl::opt WarningsAsErrors("warnings-as-errors", cl::desc(R"(
+static cl::opt WarningsAsErrors("warnings-as-errors", desc(R"(
 Upgrades warnings to errors. Same format as
 '-checks'.
 This option's

[PATCH] D141144: [clang-tidy][doc] Improve clang-tidy documentation

2023-02-09 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2706919f9197: [clang-tidy][doc] Improve clang-tidy 
documentation (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141144

Files:
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/clang-tidy/index.rst

Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -122,8 +122,7 @@
 
   clang-tidy options:
 
---checks=  -
- Comma-separated list of globs with optional '-'
+--checks=  - Comma-separated list of globs with optional '-'
  prefix. Globs are processed in order of
  appearance in the list. Globs without '-'
  prefix add checks with matching names to the
@@ -132,21 +131,18 @@
  checks. This option's value is appended to the
  value of the 'Checks' option in .clang-tidy
  file, if any.
---config=  -
- Specifies a configuration in YAML/JSON format:
+--config=  - Specifies a configuration in YAML/JSON format:
-config="{Checks: '*',
- CheckOptions: {x, y}}"
+ CheckOptions: {x: y}}"
  When the value is empty, clang-tidy will
  attempt to find a file named .clang-tidy for
  each source file in its parent directories.
---config-file= - 
-Specify the path of .clang-tidy or custom config file:
-  e.g. --config-file=/some/path/myTidyConfigFile
-This option internally works exactly the same way as
+--config-file= - Specify the path of .clang-tidy or custom config file:
+ e.g. --config-file=/some/path/myTidyConfigFile
+ This option internally works exactly the same way as
   --config option after reading specified config file.
-Use either --config-file or --config, not both.
---dump-config  -
- Dumps configuration in the YAML format to
+ Use either --config-file or --config, not both.
+--dump-config  - Dumps configuration in the YAML format to
  stdout. This option can be used along with a
  file name (and '--' if the file is outside of a
  project with configured compilation database).
@@ -154,38 +150,29 @@
  printed.
  Use along with -checks=* to include
  configuration of all checks.
---enable-check-profile -
- Enable per-check timing profiles, and print a
+--enable-check-profile - Enable per-check timing profiles, and print a
  report to stderr.
---explain-config   -
- For each enabled check explains, where it is
+--explain-config   - For each enabled check explains, where it is
  enabled, i.e. in clang-tidy binary, command
  line or a specific configuration file.
---export-fixes=  -
- YAML file to store suggested fixes in. The
+--export-fixes=  - YAML file to store suggested fixes in. The
  stored fixes can be applied to the input source
  code with clang-apply-replacements.
---extra-arg=   - Additional argument to append to the compiler command line.
- Can be used several times.
---extra-arg-before=- Additional argument to prepend to the compiler command line.
- Can be used several times.
---fix  -
- Apply suggested fixes. Without -fix-errors
+--extra-arg=   - Additional argument to append to the compiler command line
+--ext

[PATCH] D143501: [clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-09 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 496089.
Michael137 added a comment.

- Reword commit
- Use different debuginfo kind in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/debug-info-preferred-names.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/CodeGen/debug-info-preferred-names.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-preferred-names.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - -debugger-tuning=lldb | FileCheck --check-prefixes=COMMON,LLDB %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - -debugger-tuning=gdb | FileCheck --check-prefixes=COMMON,GDB %s
+
+template
+class Qux {};
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+int main() {
+/* Trivial cases */
+
+Bar b;
+// COMMON: !DIDerivedType(tag: DW_TAG_typedef, name: "Bar"
+
+Foo f1;
+// COMMON: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+
+/* Alias template case */
+
+Bar> f2;
+// GDB:!DIDerivedType(tag: DW_TAG_typedef, name: "Bar >"
+// LLDB:   !DIDerivedType(tag: DW_TAG_typedef, name: "Bar >"
+
+/* Nested cases */
+
+Foo> f3; 
+// GDB:!DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+// LLDB:   !DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+
+Qux> f4;
+// GDB:!DICompositeType(tag: DW_TAG_class_type, name: "Qux >"
+// LLDB:   !DICompositeType(tag: DW_TAG_class_type, name: "Qux >"
+
+return 0;
+}
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -789,6 +789,11 @@
   std::memcpy(Data + A.size(), B.data(), B.size());
 return StringRef(Data, A.size() + B.size());
   }
+
+  /// Returns the QualType of the typedef that the PreferredNameAttr
+  /// of 'orig' refers to, if any such attribute exists. Returns 'orig'
+  /// otherwise.
+  QualType maybeGetPreferredNameType(QualType orig) const;
 };
 
 /// A scoped helper to set the current debug location to the specified
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -250,7 +250,7 @@
 
   PP.SuppressInlineNamespace = false;
   PP.PrintCanonicalTypes = true;
-  PP.UsePreferredNames = false;
+  PP.UsePreferredNames = CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB;
   PP.AlwaysIncludeTypeForTemplateArgument = true;

[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:218
+  if (!D) // global scope.
+return getMappingPerLang(L)->NamespaceSymbols->lookup("");
   auto It = NamespaceCache.find(D);

oh i actually missed the behaviour change here in the previous version of the 
code and it seems very subtle.
can we change this function to take in a `DeclContext*` instead and terminate 
traversal inside the callsite at `TUDecl` and only treat `TUDecl` as global 
scope here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143319: [clangd] Support iwyu pragma: no_include

2023-02-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks a lot for the patch!

we're migrating IWYU related functionality in clangd to make use of 
include-cleaner library nowadays. so can you actually move the IWYU no_include 
pragma handling logic into 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/include-cleaner/lib/Record.cpp?
This won't have affect on clangd regarding the particular problem you're facing 
immediately, but we're going to merge the logic inside include-cleaner and 
clangd soon and such discrepancies should disappear then.

in the meanwhile regarding the particular problem you're facing for 
experimental symbols. sorry for shutting down D142836 
, but that actually made us re-evaluate the 
approach of hand-curated lists and we've decided to introduce such mappings. so 
if you can revamp D142836  and put 
`TsStdSymbolMap.inc` in 
https://github.com/llvm/llvm-project/tree/main/clang/lib/Tooling/Inclusions/Stdlib/StdTsSymbolMap.inc
 we can land it and make sure it work as intended inside clangd, even before we 
merge the IWYU pragma handling logic. Happy to do that myself if you don't feel 
like doing it, sorry for creating some confusion here :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143319

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


[PATCH] D143375: clang-tidy: Count template constructors in modernize-use-default-member-init

2023-02-09 Thread Marco Falke via Phabricator via cfe-commits
MarcoFalke updated this revision to Diff 496094.
MarcoFalke added a comment.

Simplify patch and remove test case failing on Windows, but passing on Linux


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

https://reviews.llvm.org/D143375

Files:
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -60,6 +60,12 @@
 int i;
 };
 
+struct TwoConstructorsTpl {
+  TwoConstructorsTpl() : i{7} {}
+  template  TwoConstructorsTpl(T, int) : i(8) {}
+  int i;
+};
+
 struct PositiveNotDefaultOOLInt {
   PositiveNotDefaultOOLInt(int);
   int i;
@@ -237,6 +243,14 @@
 NegativeTemplate nti;
 NegativeTemplate ntd;
 
+template  struct PositiveTemplate {
+  PositiveTemplate() : i(9) {}
+  // CHECK-FIXES: PositiveTemplate()  {}
+  int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer 
for 'i'
+  // CHECK-FIXES: int i{9};
+};
+
 struct NegativeDefaultMember {
   NegativeDefaultMember() {}
   int i = 2;
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -246,8 +246,12 @@
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
   const auto *ClassDecl = cast(Field->getParent());
-  if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
-return !Ctor->isCopyOrMoveConstructor();
+  if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) {
+if (const auto *FTD = dyn_cast(D))
+  D = FTD->getTemplatedDecl();
+if (const auto *Ctor = dyn_cast(D))
+  return !Ctor->isCopyOrMoveConstructor();
+return false;
   }) > 1)
 return;
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -60,6 +60,12 @@
 int i;
 };
 
+struct TwoConstructorsTpl {
+  TwoConstructorsTpl() : i{7} {}
+  template  TwoConstructorsTpl(T, int) : i(8) {}
+  int i;
+};
+
 struct PositiveNotDefaultOOLInt {
   PositiveNotDefaultOOLInt(int);
   int i;
@@ -237,6 +243,14 @@
 NegativeTemplate nti;
 NegativeTemplate ntd;
 
+template  struct PositiveTemplate {
+  PositiveTemplate() : i(9) {}
+  // CHECK-FIXES: PositiveTemplate()  {}
+  int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
+  // CHECK-FIXES: int i{9};
+};
+
 struct NegativeDefaultMember {
   NegativeDefaultMember() {}
   int i = 2;
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -246,8 +246,12 @@
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
   const auto *ClassDecl = cast(Field->getParent());
-  if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
-return !Ctor->isCopyOrMoveConstructor();
+  if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) {
+if (const auto *FTD = dyn_cast(D))
+  D = FTD->getTemplatedDecl();
+if (const auto *Ctor = dyn_cast(D))
+  return !Ctor->isCopyOrMoveConstructor();
+return false;
   }) > 1)
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-02-09 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10980
+/// Construct a SPIR-V target extension type for the given OpenCL image type.
+static llvm::Type *getSPIRVType(llvm::LLVMContext &Ctx, StringRef BaseType,
+StringRef OpenCLName,

There probably can be more types


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141008

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


[PATCH] D143632: [clang] Handle __declspec() attributes in using

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: erichkeane.
aaron.ballman added a comment.

Please be sure to add a release note for the fix.




Comment at: clang/lib/Parse/ParseDecl.cpp:61-63
+  for (ParsedAttr &AL : DS.getAttributes())
+if (AL.isDeclspecAttribute())
+  ToBeMoved.push_back(&AL);

How about using an algorithm for this (would need to be reformatted for 80 col)?



Comment at: clang/lib/Parse/ParseDecl.cpp:65-66
+
+  for (ParsedAttr *AL : ToBeMoved)
+Attrs->takeOneFrom(DS.getAttributes(), AL);
+

Similar here, but this one might be less of a win in terms of readability.



Comment at: clang/test/SemaCXX/using-declspec.cpp:4
+
+struct Test { int a; };
+using AlignedTest = __declspec(align(16)) const Test;

Because we're touching `ParseTypeName()` and that is called in a lot of 
contexts, I think we should have extra testing in non-alias declaration cases 
and verify that MSVC behaves the same way. e.g., (search for `ParseTypeName()`, 
see where we parse type names, devise some test cases)
```
// I don't think the align attribute has a declaration to move onto in this 
case...
auto func() -> __declspec(align(16)) int;
// So I *think* the alignment of the return type isn't changed?
static_assert(alignof(decltype(func())) == alignof(int));

// Same here, no declaration to shift to
int i = (__declspec(align(16))int)12;

// But there is a declaration here!
typedef __declspec(align(16)) int Foo;
static_assert(alignof(Foo) == 16);
```
(There are possibly other interesting tests to consider.)

I suspect we should be issuing some "attribute ignored" diagnostics for the 
cases where the attribute has no effect (even if MSVC does not warn).



Comment at: clang/test/SemaCXX/using-declspec.cpp:7
+static_assert(alignof(AlignedTest) == 16, "error");
\ No newline at end of file


Please add a newline to the end of the file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143632

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 496102.
hokein added a comment.

address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang-tools-extra/clangd/unittests/StdLibTests.cpp
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -65,13 +65,24 @@
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
-  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+}
 
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
-  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
+TEST(StdlibTest, CCompat) {
+  EXPECT_THAT(
+  stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX)->headers(),
+  ElementsAre(stdlib::Header::named(""),
+  stdlib::Header::named("")));
+  EXPECT_THAT(
+  stdlib::Symbol::named("std::", "int16_t", stdlib::Lang::CXX)->headers(),
+  ElementsAre(stdlib::Header::named("")));
+
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+  EXPECT_THAT(
+  stdlib::Symbol::named("", "int16_t", stdlib::Lang::C)->headers(),
+  ElementsAre(stdlib::Header::named("", stdlib::Lang::C)));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "int16_t", stdlib::Lang::C));
 }
 
 TEST(StdlibTest, Recognizer) {
@@ -127,9 +138,9 @@
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
-  EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
-  EXPECT_EQ(Recognizer(CDivT),
-stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
+  auto DivT = stdlib::Symbol::named("", "div_t", stdlib::Lang::CXX);
+  EXPECT_TRUE(DivT);
+  EXPECT_EQ(Recognizer(CDivT), DivT);
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -39,6 +39,7 @@
 import datetime
 import os
 import sys
+import re
 
 
 CODE_PREFIX = """\
@@ -170,6 +171,69 @@
   return headers
 
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  header = symbol.headers[0]
+  if header not in c_compat_headers:
+return []
+  if any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+return []
+
+  # Introduce two more entries, both in the global namespace, one using the
+  # C++-compat header and another using the C header.
+  results = []
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+  c_header = "<" + header[2:-1] +  ".h>" #  => 
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
+
+
 def main():
   args = ParseArg()
   if args.symbols == 'cpp':
@@ -192,6 +256,7 @@
   # Zombie symbols that were available from the Standard Library, but are
   # removed in the following standard

[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:218
+  if (!D) // global scope.
+return getMappingPerLang(L)->NamespaceSymbols->lookup("");
   auto It = NamespaceCache.find(D);

kadircet wrote:
> oh i actually missed the behaviour change here in the previous version of the 
> code and it seems very subtle.
> can we change this function to take in a `DeclContext*` instead and terminate 
> traversal inside the callsite at `TUDecl` and only treat `TUDecl` as global 
> scope here?
Modified this code per the suggestion, hope it is clearer now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D136864: [Clang] Create opaque type for AArch64 SVE2p1/SME2 svcount_t.

2023-02-09 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 496103.
sdesmalen added a comment.

Rebased patch to use target("aarch64.svcount")
Changed debug info for svcount to only print the first 2 bytes (rather than 
vscale x 2 bytes)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136864

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/AST/ast-dump-aarch64-sve-types.c
  clang/test/CodeGen/aarch64-debug-sve-vector-types.c
  clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
  clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
  clang/test/CodeGenCXX/aarch64-sve-typeinfo.cpp
  clang/unittests/AST/SizelessTypesTest.cpp

Index: clang/unittests/AST/SizelessTypesTest.cpp
===
--- clang/unittests/AST/SizelessTypesTest.cpp
+++ clang/unittests/AST/SizelessTypesTest.cpp
@@ -45,6 +45,7 @@
   ASSERT_TRUE(Ctx.SveBFloat16Ty->isSizelessBuiltinType());
 
   ASSERT_TRUE(Ctx.SveBoolTy->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveCountTy->isSizelessBuiltinType());
 
   ASSERT_FALSE(Ctx.VoidTy->isSizelessBuiltinType());
   ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessBuiltinType());
@@ -55,6 +56,12 @@
   Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessBuiltinType());
   ASSERT_FALSE(
   Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessBuiltinType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveCountTy)->isSizelessBuiltinType());
+  ASSERT_FALSE(
+  Ctx.getLValueReferenceType(Ctx.SveCountTy)->isSizelessBuiltinType());
+  ASSERT_FALSE(
+  Ctx.getRValueReferenceType(Ctx.SveCountTy)->isSizelessBuiltinType());
 }
 
 TEST_F(SizelessTypeTester, TestSizeless) {
@@ -75,6 +82,7 @@
   ASSERT_TRUE(Ctx.SveBFloat16Ty->isSizelessType());
 
   ASSERT_TRUE(Ctx.SveBoolTy->isSizelessType());
+  ASSERT_TRUE(Ctx.SveCountTy->isSizelessType());
 
   ASSERT_FALSE(Ctx.VoidTy->isSizelessType());
   ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessType());
@@ -83,4 +91,8 @@
   ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessType());
   ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
   ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveCountTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveCountTy)->isSizelessType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveCountTy)->isSizelessType());
 }
Index: clang/test/CodeGenCXX/aarch64-sve-typeinfo.cpp
===
--- clang/test/CodeGenCXX/aarch64-sve-typeinfo.cpp
+++ clang/test/CodeGenCXX/aarch64-sve-typeinfo.cpp
@@ -22,6 +22,7 @@
 auto &bf16 = typeid(__SVBFloat16_t);
 
 auto &b8 = typeid(__SVBool_t);
+auto &c8 = typeid(__SVCount_t);
 
 // CHECK-DAG: @_ZTSu10__SVInt8_t = {{.*}} c"u10__SVInt8_t\00"
 // CHECK-DAG: @_ZTIu10__SVInt8_t = {{.*}} @_ZTVN10__cxxabiv123__fundamental_type_infoE, {{.*}} @_ZTSu10__SVInt8_t
@@ -61,3 +62,6 @@
 
 // CHECK-DAG: @_ZTSu10__SVBool_t = {{.*}} c"u10__SVBool_t\00"
 // CHECK-DAG: @_ZTIu10__SVBool_t = {{.*}} @_ZTVN10__cxxabiv123__fundamental_type_infoE, {{.*}} @_ZTSu10__SVBool_t
+
+// CHECK-DAG: @_ZTSu11__SVCount_t = {{.*}} c"u11__SVCount_t\00"
+// CHECK-DAG: @_ZTIu11__SVCount_t = {{.*}} @_ZTVN10__cxxabiv123__fundamental_type_infoE, {{.*}} @_ZTSu11__SVCount_t
Index: clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
===
--- clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
+++ clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
@@ -31,6 +31,8 @@
 void f12(S<__SVBFloat16_t>) {}
 // CHECK: _Z3f131SIu10__SVBool_tE
 void f13(S<__SVBool_t>) {}
+// CHECK: _Z3f141SIu11__SVCount_tE
+void f14(S<__SVCount_t>) {}
 
 // The tuple types don't use the internal name for mangling.
 
Index: clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
===
--- clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
+++ clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
@@ -20,5 +20,17 @@
   return ret ;
 }
 
+__SVCount_t funcB1(__SVCount_t in)
+{
+  __SVCount_t ret ;
+  asm volatile (
+"mov %[ret].b, %[in].b \n"
+: [ret] "=w" (ret)
+: [in] "w" (in)
+:);
+
+  return ret ;
+}
+
 // CHECK: funcB1
 // CHECK-ERROR: fatal error: error in backend: Cannot select
Index: clang/test/CodeGen/aarch64-debug-sve-vector-types.c
===
--- clang/test/CodeGen/aarch64-debug-sve-vector-types.c
+++ clang/test/CodeGen/aarch64-debug-sve-vector-types.c
@@ -9,6 +9,12 @@
   // CHECK-DAG: ![[REALELTS1_64]] = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_constu, 1, DW_OP_bregx, 46, 0, DW_OP_mul, 

[PATCH] D143375: clang-tidy: Count template constructors in modernize-use-default-member-init

2023-02-09 Thread Marco Falke via Phabricator via cfe-commits
MarcoFalke updated this revision to Diff 496104.
MarcoFalke edited the summary of this revision.
MarcoFalke added a comment.

Remove both test cases that pass on current `main` on Linux, but fail on 
Windows. Seems unrelated to add/fix them here.


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

https://reviews.llvm.org/D143375

Files:
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -60,6 +60,12 @@
 int i;
 };
 
+struct TwoConstructorsTpl {
+  TwoConstructorsTpl() : i{7} {}
+  template  TwoConstructorsTpl(T, int) : i(8) {}
+  int i;
+};
+
 struct PositiveNotDefaultOOLInt {
   PositiveNotDefaultOOLInt(int);
   int i;
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -246,8 +246,12 @@
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
   const auto *ClassDecl = cast(Field->getParent());
-  if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
-return !Ctor->isCopyOrMoveConstructor();
+  if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) {
+if (const auto *FTD = dyn_cast(D))
+  D = FTD->getTemplatedDecl();
+if (const auto *Ctor = dyn_cast(D))
+  return !Ctor->isCopyOrMoveConstructor();
+return false;
   }) > 1)
 return;
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -60,6 +60,12 @@
 int i;
 };
 
+struct TwoConstructorsTpl {
+  TwoConstructorsTpl() : i{7} {}
+  template  TwoConstructorsTpl(T, int) : i(8) {}
+  int i;
+};
+
 struct PositiveNotDefaultOOLInt {
   PositiveNotDefaultOOLInt(int);
   int i;
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -246,8 +246,12 @@
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
   const auto *ClassDecl = cast(Field->getParent());
-  if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
-return !Ctor->isCopyOrMoveConstructor();
+  if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) {
+if (const auto *FTD = dyn_cast(D))
+  D = FTD->getTemplatedDecl();
+if (const auto *Ctor = dyn_cast(D))
+  return !Ctor->isCopyOrMoveConstructor();
+return false;
   }) > 1)
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.

thanks, lgtm again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143638: [clangd] Move function body to out-of-line: unnamed class method incorrect moving

2023-02-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:395
 
 // Bail out in templated classes, as it is hard to spell the class name, 
i.e
 // if the template parameter is unnamed.

could you move this comment closer to the `isTempated` if statement below?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:401
+
+  // The refactoring is meaningless for unnamed classes.
+  const auto *Parent = MD->getParent();

not just classes, but also for cases with unnamed namespaces.

could you change this to look like:
```
for(DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
  if (auto *ND = llvm::dyn_cast(DC)) {
 if(ND->getDeclName().isEmpty())
return false;
  }
}
```



Comment at: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp:97
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {

can you also have a test inside an unnamed namespace?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143638

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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D140756#4100387 , @aaron.ballman 
wrote:

> @diseraluca -- do you need this cherry picked into Clang 16 or are you fine 
> if this goes into Clang 17 instead?

I'll go with the assumption this is fine going into Clang 17 and not needing to 
be cherry-picked. I'll take care of that and the missed release note when I 
have a spare moment. (Thanks @vedgy for noticing these changes are needed!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140756

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


[clang] c812ab7 - [include-mapping] Add C-compatibility symbol entries.

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

Author: Haojian Wu
Date: 2023-02-09T15:34:41+01:00
New Revision: c812ab731243f9d5fe1764eb995809a22409ca71

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

LOG: [include-mapping] Add C-compatibility symbol entries.

Extending the python generator:
- to generate C-compatibility symbols
- to generate macros

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/StdLibTests.cpp
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
clang/tools/include-mapping/cppreference_parser.py
clang/tools/include-mapping/gen_std.py
clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/StdLibTests.cpp 
b/clang-tools-extra/clangd/unittests/StdLibTests.cpp
index f70de71edfc3d..ef47141bade15 100644
--- a/clang-tools-extra/clangd/unittests/StdLibTests.cpp
+++ b/clang-tools-extra/clangd/unittests/StdLibTests.cpp
@@ -34,7 +34,7 @@ TEST(StdLibTests, getStdlibUmbrellaHeader) {
   auto CXX = getStdlibUmbrellaHeader(LO).str();
   EXPECT_THAT(CXX, HasSubstr("#include "));
   EXPECT_THAT(CXX, HasSubstr("#include "));
-  EXPECT_THAT(CXX, Not(HasSubstr("#include ")));
+  EXPECT_THAT(CXX, Not(HasSubstr("#include ")));
 
   LO.CPlusPlus = false;
   auto C = getStdlibUmbrellaHeader(LO).str();

diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index 830cbd5873bc6..9d45d84a429be 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -108,7 +108,7 @@ class Recognizer {
 
 private:
   using NSSymbolMap = llvm::DenseMap;
-  NSSymbolMap *namespaceSymbols(const NamespaceDecl *D);
+  NSSymbolMap *namespaceSymbols(const DeclContext *DC, Lang L);
   llvm::DenseMap NamespaceCache;
 };
 

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 55d87b98eb653..0340a9151424d 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -213,21 +213,14 @@ llvm::SmallVector Symbol::headers() const {
 
 Recognizer::Recognizer() { ensureInitialized(); }
 
-NSSymbolMap *Recognizer::namespaceSymbols(const NamespaceDecl *D) {
-  if (!D)
-return nullptr;
-  Lang Language;
-  if (D->getLangOpts().CPlusPlus)
-Language = Lang::CXX;
-  else if (D->getLangOpts().C11)
-Language = Lang::C;
-  else
-return nullptr;
+NSSymbolMap *Recognizer::namespaceSymbols(const DeclContext *DC, Lang L) {
+  if (DC->isTranslationUnit()) // global scope.
+return getMappingPerLang(L)->NamespaceSymbols->lookup("");
 
-  auto It = NamespaceCache.find(D);
+  auto It = NamespaceCache.find(DC);
   if (It != NamespaceCache.end())
 return It->second;
-
+  const NamespaceDecl *D = llvm::cast(DC);
   NSSymbolMap *Result = [&]() -> NSSymbolMap * {
 if (D->isAnonymousNamespace())
   return nullptr;
@@ -237,24 +230,35 @@ NSSymbolMap *Recognizer::namespaceSymbols(const 
NamespaceDecl *D) {
  ND = llvm::dyn_cast_or_null(ND->getParent()))
   if (!ND->isInlineNamespace() && !ND->isAnonymousNamespace())
 Scope = ND->getName().str() + "::" + Scope;
-return getMappingPerLang(Language)->NamespaceSymbols->lookup(Scope);
+return getMappingPerLang(L)->NamespaceSymbols->lookup(Scope);
   }();
   NamespaceCache.try_emplace(D, Result);
   return Result;
 }
 
 std::optional Recognizer::operator()(const Decl *D) {
+  Lang L;
+  if (D->getLangOpts().CPlusPlus) {
+L = Lang::CXX;
+  } else if (D->getLangOpts().C11) {
+L = Lang::C;
+  } else {
+return std::nullopt; // not a supported language.
+  }
+
   // If D is std::vector::iterator, `vector` is the outer symbol to look up.
   // We keep all the candidate DCs as some may turn out to be anon enums.
   // Do this resolution lazily as we may turn out not to have a std namespace.
   llvm::SmallVector IntermediateDecl;
   const DeclContext *DC = D->getDeclContext();
-  while (DC && !DC->isNamespace()) {
+  if (!DC) // The passed D is a TranslationUnitDecl!
+return std::nullopt;
+  while (!DC->isNamespace() && !DC->isTranslationUnit()) {
 if (NamedDecl::classofKind(DC->getDeclKind()))
   IntermediateDecl.push_back(DC);
 DC = DC->getParent();
   }
-  NSSymbolMap *Symbols = namespaceSymbols(cast_or_null(DC));
+  NSSymbolMap *Symbols = namespaceSymbols(DC, L);
   if (!Symbols)
 return std::nullopt;
 
@@ -277,7 +281,7 @@ std::optional Recognizer::operator()(const Decl *D) 
{
   auto It = Symbols->find(

[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-09 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc812ab731243: [include-mapping] Add C-compatibility symbol 
entries. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang-tools-extra/clangd/unittests/StdLibTests.cpp
  clang/include/clang/Tooling/Inclusions/StandardLibrary.h
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py
  clang/unittests/Tooling/StandardLibraryTest.cpp

Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -65,13 +65,24 @@
 
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
-  EXPECT_FALSE(stdlib::Header::named(""));
-  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
-  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::CXX));
+  EXPECT_FALSE(stdlib::Header::named("", stdlib::Lang::CXX));
+}
 
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t"));
-  EXPECT_FALSE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX));
-  EXPECT_TRUE(stdlib::Symbol::named("", "int16_t", stdlib::Lang::C));
+TEST(StdlibTest, CCompat) {
+  EXPECT_THAT(
+  stdlib::Symbol::named("", "int16_t", stdlib::Lang::CXX)->headers(),
+  ElementsAre(stdlib::Header::named(""),
+  stdlib::Header::named("")));
+  EXPECT_THAT(
+  stdlib::Symbol::named("std::", "int16_t", stdlib::Lang::CXX)->headers(),
+  ElementsAre(stdlib::Header::named("")));
+
+  EXPECT_TRUE(stdlib::Header::named("", stdlib::Lang::C));
+  EXPECT_THAT(
+  stdlib::Symbol::named("", "int16_t", stdlib::Lang::C)->headers(),
+  ElementsAre(stdlib::Header::named("", stdlib::Lang::C)));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "int16_t", stdlib::Lang::C));
 }
 
 TEST(StdlibTest, Recognizer) {
@@ -127,9 +138,9 @@
   EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector"));
   EXPECT_EQ(Recognizer(Clock),
 stdlib::Symbol::named("std::chrono::", "system_clock"));
-  EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t"));
-  EXPECT_EQ(Recognizer(CDivT),
-stdlib::Symbol::named("", "div_t", stdlib::Lang::C));
+  auto DivT = stdlib::Symbol::named("", "div_t", stdlib::Lang::CXX);
+  EXPECT_TRUE(DivT);
+  EXPECT_EQ(Recognizer(CDivT), DivT);
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -39,6 +39,7 @@
 import datetime
 import os
 import sys
+import re
 
 
 CODE_PREFIX = """\
@@ -170,6 +171,69 @@
   return headers
 
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  header = symbol.headers[0]
+  if header not in c_compat_headers:
+return []
+  if any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+return []
+
+  # Introduce two more entries, both in the global namespace, one using the
+  # C++-compat header and another using the C header.
+  results = []
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+  c_header = "<" + header[2:-1] +  ".h>" #  => 
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
+
+
 def main():
   args = ParseArg()
   if args.symbols == 'cpp':
@@ -192,6 +256,7 @@
   # Zombie symbols 

[clang] de4321c - [libclang] Tweaks for clang_CXXMethod_isExplicit

2023-02-09 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-02-09T09:55:11-05:00
New Revision: de4321cf2cf28f2bae7fc0f1897957e73b726f89

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

LOG: [libclang] Tweaks for clang_CXXMethod_isExplicit

This adds a release note that was accidentally dropped, and moves the
symbol from LLVM 16 to LLVM 17 in the module map.

Amends 0a51bc731bcc2c27e4fe97957a83642d93d989be

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/tools/libclang/libclang.map

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d52dbb27a90e..4fef5f883655b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -213,6 +213,10 @@ clang-extdef-mapping
 libclang
 
 
+- Introduced the new function ``clang_CXXMethod_isExplicit``,
+  which identifies whether a constructor or conversion function cursor
+  was marked with the explicit identifier.
+
 Static Analyzer
 ---
 

diff  --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 4a607338a9f64..efb1c3cc4e691 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -416,6 +416,9 @@ LLVM_16 {
 clang_disposeAPISet;
 clang_getSymbolGraphForCursor;
 clang_getSymbolGraphForUSR;
+};
+
+LLVM_17 {
 clang_CXXMethod_isExplicit;
 };
 



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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D140756#4115363 , @aaron.ballman 
wrote:

> In D140756#4100387 , @aaron.ballman 
> wrote:
>
>> @diseraluca -- do you need this cherry picked into Clang 16 or are you fine 
>> if this goes into Clang 17 instead?
>
> I'll go with the assumption this is fine going into Clang 17 and not needing 
> to be cherry-picked. I'll take care of that and the missed release note when 
> I have a spare moment. (Thanks @vedgy for noticing these changes are needed!)

The spare moment came sooner than expected, I've made the changes in 
de4321cf2cf28f2bae7fc0f1897957e73b726f89 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140756

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


[PATCH] D143287: [Clang][X86] Change X86 cast intrinsics to use __builtin_nondeterministic_value

2023-02-09 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito updated this revision to Diff 496129.
ManuelJBrito retitled this revision from "[Clang][x86] Change x86 cast 
intrinsics to use __builtin_nondeterministic_value" to "[Clang][X86] Change X86 
cast intrinsics to use __builtin_nondeterministic_value".
ManuelJBrito added a comment.

Match freeze(poison) operand in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143287

Files:
  clang/lib/Headers/avx512fintrin.h
  clang/lib/Headers/avx512fp16intrin.h
  clang/lib/Headers/avxintrin.h
  clang/test/CodeGen/X86/avx-builtins.c
  clang/test/CodeGen/X86/avx-cast-builtins.c
  clang/test/CodeGen/X86/avx512f-builtins.c
  clang/test/CodeGen/X86/avx512fp16-builtins.c

Index: clang/test/CodeGen/X86/avx512fp16-builtins.c
===
--- clang/test/CodeGen/X86/avx512fp16-builtins.c
+++ clang/test/CodeGen/X86/avx512fp16-builtins.c
@@ -326,19 +326,22 @@
 
 __m256h test_mm256_castph128_ph256(__m128h __a) {
   // CHECK-LABEL: test_mm256_castph128_ph256
-  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> %{{.*}}, <16 x i32> 
+  // CHECK: [[A:%.*]] = freeze <8 x half> poison 
+  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> [[A]], <16 x i32> 
   return _mm256_castph128_ph256(__a);
 }
 
 __m512h test_mm512_castph128_ph512(__m128h __a) {
   // CHECK-LABEL: test_mm512_castph128_ph512
-  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> %{{.*}}, <32 x i32> 
+  // CHECK: [[A:%.*]] = freeze <8 x half> poison 
+  // CHECK: shufflevector <8 x half> %{{.*}}, <8 x half> [[A]], <32 x i32> 
   return _mm512_castph128_ph512(__a);
 }
 
 __m512h test_mm512_castph256_ph512(__m256h __a) {
   // CHECK-LABEL: test_mm512_castph256_ph512
-  // CHECK: shufflevector <16 x half> %{{.*}}, <16 x half> %{{.*}}, <32 x i32> 
+  // CHECK: [[A:%.*]] = freeze <16 x half> poison 
+  // CHECK: shufflevector <16 x half> %{{.*}}, <16 x half> [[A]], <32 x i32> 
   return _mm512_castph256_ph512(__a);
 }
 
Index: clang/test/CodeGen/X86/avx512f-builtins.c
===
--- clang/test/CodeGen/X86/avx512f-builtins.c
+++ clang/test/CodeGen/X86/avx512f-builtins.c
@@ -8987,13 +8987,15 @@
 
 __m512 test_mm512_castps128_ps512(__m128 __A) {
   // CHECK-LABEL: @test_mm512_castps128_ps512
-  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <16 x i32> 
+  // CHECK: [[A:%.*]] = freeze <4 x float> poison 
+  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> [[A]], <16 x i32> 
   return _mm512_castps128_ps512(__A); 
 }
 
 __m512d test_mm512_castpd128_pd512(__m128d __A) {
   // CHECK-LABEL: @test_mm512_castpd128_pd512
-  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <8 x i32> 
+  // CHECK: [[A:%.*]] = freeze <2 x double> poison 
+  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> [[A]], <8 x i32> 
   return _mm512_castpd128_pd512(__A); 
 }
 
@@ -9086,7 +9088,8 @@
 __m512d test_mm512_castpd256_pd512(__m256d a)
 {
   // CHECK-LABEL: @test_mm512_castpd256_pd512
-  // CHECK: shufflevector <4 x double> {{.*}} 
+  // CHECK: [[A:%.*]] = freeze <4 x double> poison 
+  // CHECK: shufflevector <4 x double> {{.*}}, <4 x double> [[A]], 
   return _mm512_castpd256_pd512(a);
 }
 
@@ -9112,13 +9115,15 @@
 }
 __m512i test_mm512_castsi128_si512(__m128i __A) {
   // CHECK-LABEL: @test_mm512_castsi128_si512
-  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <8 x i32> 
+  // CHECK: [[A:%.*]] = freeze <2 x i64> poison 
+  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> [[A]], <8 x i32> 
   return _mm512_castsi128_si512(__A); 
 }
 
 __m512i test_mm512_castsi256_si512(__m256i __A) {
   // CHECK-LABEL: @test_mm512_castsi256_si512
-  // CHECK: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <8 x i32> 
+  // CHECK: [[A:%.*]] = freeze <4 x i64> poison 
+  // CHECK: shufflevector <4 x i64> %{{.*}}, <4 x i64> [[A]], <8 x i32> 
   return _mm512_castsi256_si512(__A); 
 }
 
Index: clang/test/CodeGen/X86/avx-cast-builtins.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/avx-cast-builtins.c
@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 %s -O3 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +avx -target-feature +avx512f  -target-feature +avx512fp16 -S -o - | FileCheck %s
+
+
+#include 
+
+__m256d test_mm256_castpd128_pd256(__m128d A) {
+  // CHECK-LABEL: test_mm256_castpd128_pd256
+  // CHECK: # %bb.0:
+  // CHECK-NEXT:vmovaps %xmm0, %xmm0
+  // CHECK-NEXT:ret{{[l|q]}}
+  return _mm256_castpd128_pd256(A);
+}
+
+__m256 test_mm256_castps128_ps256(__m128 A) {
+  // CHECK-LABEL: test_mm256_castps128_ps256
+  // CHECK: # %bb.0:
+  // CHECK-NEXT:vmovaps %xmm0, %xmm0
+  // CHECK-NEXT:ret{{[l|q]}}
+  return _mm256_castps128_ps256(A);
+}
+
+__m256i test_mm256_castsi128_si256(__m128i A) {
+  

[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-09 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.

LG.


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

https://reviews.llvm.org/D141910

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


[PATCH] D143587: [Docs] Multilib design

2023-02-09 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

Thanks very much for writing this. Will be worth updating the RFC with a link 
as I think that this is an approachable place to comment on the format and 
selection model without the implementation detail. I'm happy with what has been 
written so far. My suggestions are mostly additions rather than modifications.

Could be worth adding a design principles section at the end, this may help 
someone looking back rationalise the choices made. For example I think that it 
is an important decision to expand the command-line options in clang prior to 
multi-lib selection to avoid another implementation of the complex architecture 
feature selection code in multilib.

May be worth a quick description of how we might model some awkward cases like 
position independent and non-position independent code. This is analagous to 
soft and softfp.

  Position independence is an awkward case to model, which may be worth showing 
as an example.
  * if my incoming flags include position independent code [PIC] then I need to 
select the [PIC] libraries, which implies that we want a [PIC] flag.
  * if my incoming flags do not include position independent code then I can 
use [PIC] libraries, but I would prefer to use not PIC if it were available.
  If we did have separate PIC and non PIC choices then I think this would need 
two features [PIC] and [non-PIC] with incoming non-position independent code 
having both [PIC, non-PIC] so it could match both, but position indendent code 
would only have [PIC]. Presumably we'd need the [non-PIC] variant sorted after.




Comment at: clang/docs/Multilib.rst:102
+There are two options permitted:
+#. Use only the *last* matching multilib variant.
+#. Use all matching variants, thereby layering them.

May be worth indicating that this is to support compatibility with existing 
clang multilib, we expect most implementations to use all matching variants.



Comment at: clang/docs/Multilib.rst:105
+
+This decision is hard-coded per ToolChain subclass.
+

Considering the BareMetal ToolChain is used by RISC-V, Arm and AArch64 is there 
scope for a different choice per toolchain. I guess that we could put a 
predicate function for the ToolChain that could change due to architecture.



Comment at: clang/docs/Multilib.rst:122
+``-fno-exceptions`` multilib variant need only contain C++ libraries.
+
+Stability

Although it can be worked out by looking at the example, which I think is your 
intention from the comment. It may be worth a section on Syntax that extracts 
some of these.
```
Syntax of multilib.yaml
===
```
Some suggestions/questions:
* Does the file have to contain both variants: and flagmap: are either of them 
optional?
* Do variants have to come before flagmap, or is order not important.
* Will be worth highlighting that the order of the variants may be significant 
depending on the toolchain.
* Each variant is made up of dir: (path added to sysroot?), flags: [comma 
separated list of flags] and printArgs: [comma separated list of command line 
options for -print-multi-lib and -print-multi-directory, but not important for 
multilib selection]
* Each flagmap is made up of a POSIX extended syntax regex: that matches a 
flag, and (one of?) matchFlags/noMatchFlags which either adds or removes 
respecively a [comma separated list of flags] 



Comment at: clang/docs/Multilib.rst:169
+# considered a match.
+flags: [V6]
+# If a user invokes clang with -print-multi-lib then the arguments it

Although very Arm specific. I'd use [V6M] here as ArmV6 (pre-cortex so no 
explicit profile) is very different to ArmV6-m. Also in regex section below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 496132.
ahatanak marked 4 inline comments as done.
ahatanak added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGNonTrivialStruct.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGValue.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h

Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -3164,7 +3164,8 @@
 
 Address getIndirectAddress() const {
   assert(isIndirect());
-  return Address(Value, ElementType, CharUnits::fromQuantity(Alignment));
+  return Address(Value, ElementType, CharUnits::fromQuantity(Alignment),
+ KnownNonNull);
 }
   };
 
@@ -3771,8 +3772,13 @@
   /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
   /// variable length type, this is not possible.
   ///
-  LValue EmitLValue(const Expr *E);
+  LValue EmitLValue(const Expr *E,
+KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
 
+private:
+  LValue EmitLValueHelper(const Expr *E, KnownNonNull_t IsKnownNonNull);
+
+public:
   /// Same as EmitLValue but additionally we generate checking code to
   /// guard against undefined behavior.  This is only suitable when we know
   /// that the address will be used to access the object.
@@ -4783,9 +4789,10 @@
   /// into the address of a local variable.  In such a case, it's quite
   /// reasonable to just ignore the returned alignment when it isn't from an
   /// explicit source.
-  Address EmitPointerWithAlignment(const Expr *Addr,
-   LValueBaseInfo *BaseInfo = nullptr,
-   TBAAAccessInfo *TBAAInfo = nullptr);
+  Address
+  EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo = nullptr,
+   TBAAAccessInfo *TBAAInfo = nullptr,
+   KnownNonNull_t IsKnownNonNull = NotKnownNonNull);
 
   /// If \p E references a parameter with pass_object_size info or a constant
   /// array size modifier, emit the object size divided by the size of \p EltTy.
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1104,8 +1104,9 @@
 auto AI = CurFn->arg_begin();
 if (CurFnInfo->getReturnInfo().isSRetAfterThis())
   ++AI;
-ReturnValue = Address(&*AI, ConvertType(RetTy),
-  CurFnInfo->getReturnInfo().getIndirectAlign());
+ReturnValue =
+Address(&*AI, ConvertType(RetTy),
+CurFnInfo->getReturnInfo().getIndirectAlign(), KnownNonNull);
 if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
   ReturnValuePointer =
   CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
@@ -1125,8 +1126,8 @@
 cast(Addr)->getResultElementType();
 ReturnValuePointer = Address(Addr, Ty, getPointerAlign());
 Addr = Builder.CreateAlignedLoad(Ty, Addr, getPointerAlign(), "agg.result");
-ReturnValue =
-Address(Addr, ConvertType(RetTy), CGM.getNaturalTypeAlignment(RetTy));
+ReturnValue = Address(Addr, ConvertType(RetTy),
+  CGM.getNaturalTypeAlignment(RetTy), KnownNonNull);
   } else {
 ReturnValue = CreateIRTemp(RetTy, "retval");
 
Index: clang/lib/CodeGen/CGValue.h
===
--- clang/lib/CodeGen/CGValue.h
+++ clang/lib/CodeGen/CGValue.h
@@ -225,6 +225,8 @@
   // this lvalue.
   bool Nontemporal : 1;
 
+  bool IsKnownNonNull : 1l;
+
   LValueBaseInfo BaseInfo;
   TBAAAccessInfo TBAAInfo;
 
@@ -333,24 +335,35 @@
   LValueBaseInfo getBaseInfo() const { return BaseInfo; }
   void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
 
+  KnownNonNull_t isKnownNonNull() const {
+return (KnownNonNull_t)IsKnownNonNull;
+  }
+  LValue setKnownNonNull() {
+IsKnownNonNull = true;
+return *this;
+  }
+
   // simple lvalue
   llvm::Value *getPointer(CodeGenFunction &CGF) const {
 assert(isSimple());
 return V;
   }
   Address getAddress(CodeGenFunction &CGF) const {
-return Address(getPointer(CGF), ElementType, getAlignment());
+return Address(getPointer(CGF), ElementType, getAlignment(),
+   (KnownNonNull_t)isKnownNonNull());
   }
   void setAddress(Address address) {
 assert(isSimple());
 V = address.getPointer();

[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/Address.h:65
   : Pointer(Pointer), ElementType(ElementType) {
 if (Alignment.isZero())
   return;

efriedma wrote:
> Do you need to do something with IsKnownNonNull in the `Alignment.isZero()` 
> case?
We can probably get away with not doing anything here because currently the 
alignment is zero only when `Address::invalid` is called.



Comment at: clang/lib/CodeGen/Address.h:67
   return;
-// Currently the max supported alignment is much less than 1 << 63 and is
+// Currently the max supported alignment is much less than 1 << 32 and is
 // guaranteed to be a power of 2, so we can store the log of the alignment

efriedma wrote:
> This comment isn't right.  The max alignment is, as far as I can tell, 1<<32 
> exactly.  (But there's something weird going on with very large values... 
> somehow `int a[1LL<<32] __attribute((aligned(1ULL<<32))) = {};` ignores the 
> alignment.)
The following function generated by tablegen (and a few others directly or 
indirectly calling the function) returns a 32-bit int, but it should be 
returning a 64-bit int.

https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/ClangAttrEmitter.cpp#L532



Comment at: clang/lib/CodeGen/CGBuilder.h:164
+return Addr.withPointer(CreateAddrSpaceCast(Addr.getPointer(), Ty, Name),
+Addr.isKnownNonNull());
   }

efriedma wrote:
> Do address-space casts preserve non-null?
I think we can preserve non-null here. We just can't assume that `KnownNonNull` 
indicates the pointer is non-zero when the address space isn't the default 
address space.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D143501: [clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-09 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py:61
 
 if self.expectedCompilerVersion(['>', '16.0']):
+string_type = "std::string"

Michael137 wrote:
> aprantl wrote:
> > Out of curiosity: How does this function work when building the testsuite 
> > with a compiler that isn't Clang?
> > I vaguely recall there was someone in the community running a bot that 
> > built the LLDB testsuite against GCC.
> Good point, this should also check for the compiler really. I assume because 
> GCC isn't at that version yet it just works on that GCC buildbot
> 
> Will change in a different patch since there's other tests with this condition
Addressed here: https://reviews.llvm.org/D143656


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly under Sema

2023-02-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: craig.topper, aaron.ballman, kito-cheng, asb.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

Before this commit, vector float 16 types (e.g. `vfloat16m1_t`) of RVV
is only defined when extension `zvfh` is defined. However this
generate inaccurate diagnostics like:

  error: unknown type name 'vfloat16m1_t'

This commit improves the compiler by guarding type check correctly
under semantic analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143657

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/RISCVVTypes.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-float16-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -368,14 +368,13 @@
   }
 }
   }
-  OS << "#if defined(__riscv_zvfh)\n";
+
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float16, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n";
 
   OS << "#if (__riscv_v_elen_fp >= 32)\n";
   for (int Log2LMUL : Log2LMULs) {
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat16m1_t foo() {  /* expected-error {{Vector type 'vfloat16m1_t' (aka '__rvv_float16m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -223,9 +223,6 @@
 continue;
 
   // Check requirement.
-  if (BaseType == BasicType::Float16 && !HasZvfh)
-continue;
-
   if (BaseType == BasicType::Float32 && !HasVectorFloat32)
 continue;
 
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -2046,6 +2046,14 @@
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
+if (Ty->isVectorFloat16Type() &&
+!Context.getTargetInfo().hasVectorFloat16Support()) {
+  Diag(Loc, diag::err_require_vector_float16_support) << Ty;
+  if (Ty->isVectorFloat16Type() && Ty->isRVVFloat16Type()) {
+Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zvfh";
+  }
+}
+
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
   llvm::StringMap CallerFeatureMap;
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -100,6 +100,8 @@
 
   bool hasBitIntType() const override { return true; }
 
+  bool hasVectorFloat16Support() const override { return hasFeature("zvfh"); }
+
   bool useFP16ConversionIntrinsics() const override {
 return false;
   }
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -664,6 +664,10 @@
   /// Determine whether constrained floating point is supported on this target.
   virtual bool hasStrictFP() const { return HasStrictFP; }
 
+  /// Determine whether vector half float (float16) type is supported on this
+  /// target.
+  virtual bool hasVectorFloat16Support() const { return false; }
+
   /// Return the alignment that is the largest alignment ever used for any
   /// scalar/SIMD data type on the target machine you are compiling for
   /// (including types with an ex

[clang] 7f85c56 - [Clang][AIX][p]Enable -p Functionality

2023-02-09 Thread Michael Francis via cfe-commits

Author: Michael Francis
Date: 2023-02-09T16:13:51Z
New Revision: 7f85c560b43bd1b2ebf77cc443281b474b5e19c6

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

LOG: [Clang][AIX][p]Enable -p Functionality

This patch enables `-p` functionality into Clang on AIX and Linux
To create parity with GCC.

The purpose of the `-p` flag is similar to that of `-pg`, but the
results are analyzed with the `prof` tool as opposed to the `gprof` tool.
More details can be found in this RFC post:
https://discourse.llvm.org/t/rfc-add-p-driver-support-to-clang/66013?u=francii

On AIX, compiling with `-p` links against `mcrt0.o`
and produces a mon.out file analyzed with the `prof` tool,
while `-pg` links against `gcrt0.o` and produces a `gmon.out`file
analyzed with the `gprof` tool. The differences are therefore
only a concern when linking, so calling `-p` will push `-pg` to cc1.

An AIX test for `-p` already exists, and I recently
another test was added here:
https://github.com/llvm/llvm-project/commit/dc9846ce988b9ddfcbc42cd462d5d94b634b3161
As such, there is no AIX test case attached to this patch.

Reviewed By: daltenty

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6e7cdf131d937..9766a087eb6d9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4179,6 +4179,7 @@ def pedantic_errors : Flag<["-", "--"], 
"pedantic-errors">, Group>;
 def pedantic : Flag<["-", "--"], "pedantic">, Group, 
Flags<[CC1Option,FlangOption,FC1Option]>,
   HelpText<"Warn on language extensions">, 
MarshallingInfoFlag>;
+def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">;
 def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
@@ -4225,7 +4226,6 @@ defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
   NegFlag, BothFlags<[CC1Option]>>;
-def p : Flag<["-"], "p">;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;

diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index f62b566c3946e..15560e1c81bca 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -271,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e7ba912403d83..3aff071d75394 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6331,7 +6331,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
-if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
+if (TC.getTriple().isOSAIX()) {
+  CmdArgs.push_back("-pg");
+} else if (!TC.getTriple().isOSOpenBSD()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }

diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 8f0125c272a69..38ac440aabdc6 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \



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


[PATCH] D137753: [Clang][AIX][p]Enable -p Functionality

2023-02-09 Thread Michael Francis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f85c560b43b: [Clang][AIX][p]Enable -p Functionality 
(authored by francii).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137753

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-ld.c


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6331,7 +6331,9 @@
 }
   }
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
-if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
+if (TC.getTriple().isOSAIX()) {
+  CmdArgs.push_back("-pg");
+} else if (!TC.getTriple().isOSOpenBSD()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -271,7 +271,7 @@
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4179,6 +4179,7 @@
   MarshallingInfoFlag>;
 def pedantic : Flag<["-", "--"], "pedantic">, Group, 
Flags<[CC1Option,FlangOption,FC1Option]>,
   HelpText<"Warn on language extensions">, 
MarshallingInfoFlag>;
+def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">;
 def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
@@ -4225,7 +4226,6 @@
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
   NegFlag, BothFlags<[CC1Option]>>;
-def p : Flag<["-"], "p">;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6331,7 +6331,9 @@
 }
   }
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
-if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
+if (TC.getTriple().isOSAIX()) {
+  CmdArgs.push_back("-pg");
+} else if (!TC.getTriple().isOSOpenBSD()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -2

[clang] ec094d2 - [z/OS][pg] Throw error when using -pg on z/OS

2023-02-09 Thread Michael Francis via cfe-commits

Author: Michael Francis
Date: 2023-02-09T16:14:29Z
New Revision: ec094d259ecfdd82b951f644bc9a28e487e53c60

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

LOG: [z/OS][pg] Throw error when using -pg on z/OS

Throw an error when trying to compile with `-pg` on z/OS,
as the platform does not support `gprof`.

Reviewed By: cebowleratibm, MaskRay

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

Added: 
clang/test/Driver/zos-profiling-error.c

Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3aff071d75394..58d6215670ad6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6338,6 +6338,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   << A->getAsString(Args) << TripleStr;
 }
   }
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
+if (TC.getTriple().isOSzOS()) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << TripleStr;
+}
+  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))

diff  --git a/clang/test/Driver/zos-profiling-error.c 
b/clang/test/Driver/zos-profiling-error.c
new file mode 100644
index 0..e969dc31a245a
--- /dev/null
+++ b/clang/test/Driver/zos-profiling-error.c
@@ -0,0 +1,2 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'



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


[PATCH] D137756: [z/OS][pg] Throw error when using -pg on z/OS

2023-02-09 Thread Michael Francis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec094d259ecf: [z/OS][pg] Throw error when using -pg on z/OS 
(authored by francii).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137756

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/zos-profiling-error.c


Index: clang/test/Driver/zos-profiling-error.c
===
--- /dev/null
+++ clang/test/Driver/zos-profiling-error.c
@@ -0,0 +1,2 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6338,6 +6338,12 @@
   << A->getAsString(Args) << TripleStr;
 }
   }
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
+if (TC.getTriple().isOSzOS()) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << TripleStr;
+}
+  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))


Index: clang/test/Driver/zos-profiling-error.c
===
--- /dev/null
+++ clang/test/Driver/zos-profiling-error.c
@@ -0,0 +1,2 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6338,6 +6338,12 @@
   << A->getAsString(Args) << TripleStr;
 }
   }
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
+if (TC.getTriple().isOSzOS()) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << TripleStr;
+}
+  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-02-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:1723
+  Addr =
+  Addr.withPointer(Builder.CreateThreadLocalAddress(GV), KnownNonNull);
 

`KnownNonNull` is being passed here because the address of a load must be 
non-null. Do we have to check that the function doesn't have 
`null_pointer_is_valid` here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly with semantic analysis

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

Are you going to do f32, f64, and i64 as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143657

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


[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly with semantic analysis

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

In D143657#4115721 , @craig.topper 
wrote:

> Are you going to do f32, f64, and i64 as well?

Yes, going to add them once this commit lands.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143657

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


[PATCH] D143663: [clangd] Show used symbols on hover.

2023-02-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143663

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h

Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -21,9 +21,11 @@
 #include "Config.h"
 #include "Headers.h"
 #include "ParsedAST.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/CanonicalIncludes.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/StringSet.h"
@@ -38,6 +40,11 @@
   llvm::DenseSet Stdlib;
 };
 
+struct UsedSymbol {
+  std::string Name;
+  SourceLocation Location;
+};
+
 class CachedIncludeCleaner {
 
 public:
@@ -50,6 +57,7 @@
   void run();
   std::vector> computeMissingIncludes();
   std::vector computeUnusedIncludesExperimental();
+  llvm::DenseSet computeUsedSymbols(const Inclusion &Inclusion);
 
 private:
   ParsedAST &AST;
@@ -143,4 +151,29 @@
 } // namespace clangd
 } // namespace clang
 
+namespace llvm {
+template <> struct llvm::DenseMapInfo {
+  static clang::clangd::UsedSymbol getEmptyKey() {
+constexpr clang::SourceLocation::UIntTy Zero = 0;
+return clang::clangd::UsedSymbol{
+"", clang::SourceLocation::getFromRawEncoding(~Zero)};
+  }
+
+  static clang::clangd::UsedSymbol getTombstoneKey() {
+constexpr clang::SourceLocation::UIntTy Zero = 0;
+return clang::clangd::UsedSymbol{
+"", clang::SourceLocation::getFromRawEncoding(~Zero - 1)};
+  }
+
+  static unsigned getHashValue(clang::clangd::UsedSymbol Sym) {
+return std::hash{}(Sym.Name);
+  }
+
+  static bool isEqual(clang::clangd::UsedSymbol LHS,
+  clang::clangd::UsedSymbol RHS) {
+return LHS.Name == RHS.Name;
+  }
+};
+} // namespace llvm
+
 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INCLUDECLEANER_H
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -27,6 +27,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -212,6 +213,56 @@
   return getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
 }
 
+// TODO(bakalova) Add unit test
+llvm::DenseSet
+CachedIncludeCleaner::computeUsedSymbols(const Inclusion &Inclusion) {
+  if (Refs.empty()) {
+run();
+  }
+  llvm::DenseSet UsedSymbols;
+  // TODO(bakalova) Avoid double loop by adding a cache by header?
+  for (unsigned I = 0; I < Refs.size(); ++I) {
+include_cleaner::SymbolReference Ref{Refs[I]};
+std::string Name;
+SourceLocation Location{Ref.RefLocation};
+// TODO(bakalova) Name is not enough. Can I get more context? Check other hovers to see how
+// they get more stuff (from a Decl?)
+switch(Ref.Target.kind()) {
+   case include_cleaner::Symbol::Declaration:
+Name = cast(Ref.Target.declaration())
+.getDeclName()
+.getAsString();   
+break;
+  case include_cleaner::Symbol::Macro:
+Name = Ref.Target.macro().Name->getName(); 
+break;
+}
+llvm::SmallVector Providers = ProviderRefs[I];
+for (const include_cleaner::Header &H : Providers) {
+  switch (H.kind()) {
+  case include_cleaner::Header::Physical:
+if (H.physical()->tryGetRealPathName().contains(
+llvm::StringRef(Inclusion.Written).trim("\"<>"))) {
+  UsedSymbols.insert({Name, Location});
+}
+break;
+  case include_cleaner::Header::Standard:
+if (Inclusion.Written == H.standard().name()) {
+  UsedSymbols.insert({Name, Location});
+}
+break;
+  // TODO(bakalova) does the verbatim thing include quotes or not?
+  case include_cleaner::Header::Verbatim:
+if (Inclusion.Written == H.verbatim()) {
+  UsedSymbols.insert({Name, Location});
+}
+break;
+  }
+}
+  }
+  return UsedSymbols;
+}
+
 include_cleaner::Includes
 CachedIncludeCleaner::convertIncludes(const SourceManager &SM,
   std::vector MainFileIncludes) {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang

[PATCH] D143142: [clang][lex] Enable Lexer to grow its buffer

2023-02-09 Thread Sunho Kim via Phabricator via cfe-commits
sunho added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:211
+  L->BufferOffset =
+  StrData - InputFile.getBufferStart(); // FIXME: this is wrong
+  L->BufferSize = L->BufferOffset + TokLen;

v.g.vassilev wrote:
> Is that an outdated comment? If not maybe elaborate why this is wrong.
It's indeed outdated comment. I'll remove it.



Comment at: clang/lib/Lex/Lexer.cpp:1203
 if (L && !L->isLexingRawMode())
-  L->Diag(CP-2, diag::trigraph_ignored);
+  L->Diag(CP - 2 - L->getBuffer().data(), diag::trigraph_ignored);
 return 0;

shafik wrote:
> I wonder do we really need to do these pointer gymnastics, maybe making this 
> a member function would eliminate the need for it.
Yes, we can change it to offset here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143142

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


[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly with semantic analysis

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

Forward declaration (snippet below) is still allowed after this commit.

  #include 
  
  vfloat16m1_t foo();

I see the same behavior under 
https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/x86_64-no-x87.cpp.
  If I add type check under `SemaDecl.cpp::Sema::ActOnFunctionDeclarator`, the 
compiler will emit repeating warning for the same function. Currently I don't 
know what is the best fix for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143657

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


[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly with semantic analysis

2023-02-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 496160.
eopXD added a comment.

Update code: rename error for vector support, remove dead code under 
SemaRISCVVectorLoopup.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143657

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/RISCVVTypes.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-float16-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -368,14 +368,13 @@
   }
 }
   }
-  OS << "#if defined(__riscv_zvfh)\n";
+
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float16, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n";
 
   OS << "#if (__riscv_v_elen_fp >= 32)\n";
   for (int Log2LMUL : Log2LMULs) {
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat16m1_t foo() {  /* expected-error {{Vector type 'vfloat16m1_t' (aka '__rvv_float16m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -171,7 +171,6 @@
   const TargetInfo &TI = Context.getTargetInfo();
   bool HasVectorFloat32 = TI.hasFeature("zve32f");
   bool HasVectorFloat64 = TI.hasFeature("zve64d");
-  bool HasZvfh = TI.hasFeature("experimental-zvfh");
   bool HasRV64 = TI.hasFeature("64bit");
   bool HasFullMultiply = TI.hasFeature("v");
 
@@ -223,9 +222,6 @@
 continue;
 
   // Check requirement.
-  if (BaseType == BasicType::Float16 && !HasZvfh)
-continue;
-
   if (BaseType == BasicType::Float32 && !HasVectorFloat32)
 continue;
 
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -2046,6 +2046,14 @@
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
+if (Ty->isVectorFloat16Type() &&
+!Context.getTargetInfo().hasVectorFloat16Support()) {
+  Diag(Loc, diag::err_require_vector_support) << Ty;
+  if (Ty->isVectorFloat16Type() && Ty->isRVVFloat16Type()) {
+Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zvfh";
+  }
+}
+
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
   llvm::StringMap CallerFeatureMap;
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -100,6 +100,8 @@
 
   bool hasBitIntType() const override { return true; }
 
+  bool hasVectorFloat16Support() const override { return hasFeature("zvfh"); }
+
   bool useFP16ConversionIntrinsics() const override {
 return false;
   }
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -664,6 +664,10 @@
   /// Determine whether constrained floating point is supported on this target.
   virtual bool hasStrictFP() const { return HasStrictFP; }
 
+  /// Determine whether vector half float (float16) type is supported on this
+  /// target.
+  virtual bool hasVectorFloat16Support() const { return false; }
+
   /// Return the alignment that is the largest alignment ever used for any
   /// scalar/SIMD data type on the target machine you are compiling for
   /// (including types with an extended alignment requirement).
Index: clang/include/clang/Basic/RISCVVTypes.def
===
--- clang/include/clang/Basic/RISCVVTypes.def
+++ clang/include/clang/Basic/RISCVVTypes.def
@@ -60,6 +60,10 @@
   RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, t

[PATCH] D143613: [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

2023-02-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM, but would be nice to have a test for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143613

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


[PATCH] D143664: [SanitizerBinaryMetadata] Support ignore list

2023-02-09 Thread Marco Elver via Phabricator via cfe-commits
melver created this revision.
melver added reviewers: dvyukov, vitalybuka.
Herald added subscribers: Enna1, ormris, hiraditya.
Herald added a project: All.
melver requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

For large projects it will be required to opt out entire subdirectories.
In the absence of fine-grained control over the flags passed via the
build system, introduce -fexperimental-sanitize-metadata-ignorelist=.

The format is identical to other sanitizer ignore lists, and its effect
will be to simply not instrument either functions or entire modules
based on the rules in the ignore list file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143664

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/sanitize-metadata-ignorelist.c
  clang/test/Driver/fsanitize-metadata-ignorelist.c
  llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
  llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp

Index: llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
===
--- llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -38,13 +38,16 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
 #include 
 #include 
+#include 
 
 using namespace llvm;
 
@@ -121,9 +124,11 @@
 
 class SanitizerBinaryMetadata {
 public:
-  SanitizerBinaryMetadata(Module &M, SanitizerBinaryMetadataOptions Opts)
+  SanitizerBinaryMetadata(Module &M, SanitizerBinaryMetadataOptions Opts,
+  std::unique_ptr Ignorelist)
   : Mod(M), Options(transformOptionsFromCl(std::move(Opts))),
-TargetTriple(M.getTargetTriple()), IRB(M.getContext()) {
+Ignorelist(std::move(Ignorelist)), TargetTriple(M.getTargetTriple()),
+IRB(M.getContext()) {
 // FIXME: Make it work with other formats.
 assert(TargetTriple.isOSBinFormatELF() && "ELF only");
   }
@@ -168,6 +173,7 @@
 
   Module &Mod;
   const SanitizerBinaryMetadataOptions Options;
+  std::unique_ptr Ignorelist;
   const Triple TargetTriple;
   IRBuilder<> IRB;
   BumpPtrAllocator Alloc;
@@ -243,6 +249,8 @@
 return;
   if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
 return;
+  if (Ignorelist && Ignorelist->inSection("metadata", "fun", F.getName()))
+return;
   // Don't touch available_externally functions, their actual body is elsewhere.
   if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage)
 return;
@@ -455,12 +463,20 @@
 } // namespace
 
 SanitizerBinaryMetadataPass::SanitizerBinaryMetadataPass(
-SanitizerBinaryMetadataOptions Opts)
-: Options(std::move(Opts)) {}
+SanitizerBinaryMetadataOptions Opts, ArrayRef IgnorelistFiles)
+: Options(std::move(Opts)), IgnorelistFiles(std::move(IgnorelistFiles)) {}
 
 PreservedAnalyses
 SanitizerBinaryMetadataPass::run(Module &M, AnalysisManager &AM) {
-  SanitizerBinaryMetadata Pass(M, Options);
+  std::unique_ptr Ignorelist;
+  if (!IgnorelistFiles.empty()) {
+Ignorelist = SpecialCaseList::createOrDie(IgnorelistFiles,
+  *vfs::getRealFileSystem());
+if (Ignorelist->inSection("metadata", "src", M.getSourceFileName()))
+  return PreservedAnalyses::all();
+  }
+
+  SanitizerBinaryMetadata Pass(M, Options, std::move(Ignorelist));
   if (Pass.run())
 return PreservedAnalyses::none();
   return PreservedAnalyses::all();
Index: llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
===
--- llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
+++ llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
@@ -12,6 +12,7 @@
 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERBINARYMETADATA_H
 #define LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERBINARYMETADATA_H
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
@@ -50,12 +51,14 @@
 : public PassInfoMixin {
 public:
   explicit SanitizerBinaryMetadataPass(
-  SanitizerBinaryMetadataOptions Opts = {});
+  SanitizerBinaryMetadataOptions Opts = {},
+  ArrayRef IgnorelistFiles = {});
   PreservedAnalyses run(Module &M, ModuleAnalysisM

[PATCH] D143665: [Clang][RISCV] Guard vector int64, float32, float64 with semantic analysis

2023-02-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: craig.topper, aaron.ballman, kito-cheng, asb.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

Depends on D143657 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143665

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/RISCVVTypes.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -376,23 +376,19 @@
   printType(*T);
   }
 
-  OS << "#if (__riscv_v_elen_fp >= 32)\n";
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float32, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n";
 
-  OS << "#if (__riscv_v_elen_fp >= 64)\n";
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float64, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n\n";
 
   OS << "#define __riscv_v_intrinsic_overloading 1\n";
 
Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +zve32x -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vint64m1_t foo() {  /* expected-error {{Vector type 'vint64m1_t' (aka '__rvv_int64m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/test/Sema/riscv-vector-float64-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float64-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +zve64f -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat64m1_t foo() {  /* expected-error {{Vector type 'vfloat64m1_t' (aka '__rvv_float64m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/test/Sema/riscv-vector-float32-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float32-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +zve32x -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat32m1_t foo() {  /* expected-error {{Vector type 'vfloat32m1_t' (aka '__rvv_float32m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -169,8 +169,6 @@
 
 void RISCVIntrinsicManagerImpl::InitIntrinsicList() {
   const TargetInfo &TI = Context.getTargetInfo();
-  bool HasVectorFloat32 = TI.hasFeature("zve32f");
-  bool HasVectorFloat64 = TI.hasFeature("zve64d");
   bool HasRV64 = TI.hasFeature("64bit");
   bool HasFullMultiply = TI.hasFeature("v");
 
@@ -222,12 +220,6 @@
 continue;
 
   // Check requirement.
-  if (BaseType == BasicType::Float32 && !HasVectorFloat32)
-continue;
-
-  if (BaseType == BasicType::Float64 && !HasVectorFloat64)
-   

[PATCH] D143666: [Clang] Fix clang_rt tests when LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is ON

2023-02-09 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings created this revision.
michaelplatings added a reviewer: phosek.
Herald added a project: All.
michaelplatings requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If clang is part of a toolchain that can locate clang_rt libraries
outside its resource directory and these are built with
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON then the tests would fail because
the library names don't have the arch suffix. This change makes the arch
suffix optional.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143666

Files:
  clang/test/Driver/arm-compiler-rt.c
  clang/test/Driver/print-libgcc-file-name-clangrt.c

Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -4,13 +4,13 @@
 // RUN: --target=x86_64-pc-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-X8664 %s
-// CHECK-CLANGRT-X8664: libclang_rt.builtins-x86_64.a
+// CHECK-CLANGRT-X8664: libclang_rt.builtins{{(-x86_64)?}}.a
 
 // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
 // RUN: --target=i386-pc-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
-// CHECK-CLANGRT-I386: libclang_rt.builtins-i386.a
+// CHECK-CLANGRT-I386: libclang_rt.builtins{{(-i386)?}}.a
 
 // Check whether alternate arch values map to the correct library.
 //
@@ -23,7 +23,7 @@
 // RUN: --target=arm-linux-gnueabi \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM %s
-// CHECK-CLANGRT-ARM: libclang_rt.builtins-arm.a
+// CHECK-CLANGRT-ARM: libclang_rt.builtins{{(-arm)?}}.a
 
 // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
 // RUN: --target=arm-linux-androideabi \
@@ -35,19 +35,19 @@
 // RUN: --target=arm-linux-gnueabihf \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARMHF %s
-// CHECK-CLANGRT-ARMHF: libclang_rt.builtins-armhf.a
+// CHECK-CLANGRT-ARMHF: libclang_rt.builtins{{(-armhf)?}}.a
 
 // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
 // RUN: --target=arm-linux-gnueabi -mfloat-abi=hard \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-ABI %s
-// CHECK-CLANGRT-ARM-ABI: libclang_rt.builtins-armhf.a
+// CHECK-CLANGRT-ARM-ABI: libclang_rt.builtins{{(-armhf)?}}.a
 
 // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
 // RUN: --target=armv7m-none-eabi \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
-// CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+// CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins{{(-armv7m)?}}.a
 
 // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
 // RUN: --target=armv7m-vendor-none-eabi \
Index: clang/test/Driver/arm-compiler-rt.c
===
--- clang/test/Driver/arm-compiler-rt.c
+++ clang/test/Driver/arm-compiler-rt.c
@@ -2,47 +2,47 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-EABI
-// ARM-EABI: "-lclang_rt.builtins-arm"
+// ARM-EABI: "-lclang_rt.builtins{{(-arm)?}}"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI
-// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins{{(-arm)?}}.a"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI-ABI
-// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins{{(-armhf)?}}.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF
-// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins{{(-armhf)?}}.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=soft -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF-ABI
-// 

[PATCH] D143613: [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

2023-02-09 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 496173.
benlangmuir added a comment.

Add a test


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

https://reviews.llvm.org/D143613

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/line-directive.c


Index: clang/test/ClangScanDeps/line-directive.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/line-directive.c
@@ -0,0 +1,34 @@
+// Check that we get the right file dependencies and not the declared paths 
from
+// line directives.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -mode preprocess-dependency-directives -format experimental-full > 
%t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  "file-deps": [
+// CHECK-NEXT:   "[[PREFIX]]/tu.c"
+// CHECK-NEXT:   "[[PREFIX]]/header.h"
+// CHECK-NEXT: ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c"
+}]
+
+//--- other.h
+
+//--- other.c
+
+//--- header.h
+#line 100 "other.h"
+
+//--- tu.c
+#include "header.h"
+#line 100 "other.c"
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -301,11 +301,12 @@
   assert(Inserted && "duplicate module mapping");
 }
 
-void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
-   FileChangeReason Reason,
-   SrcMgr::CharacteristicKind FileType,
-   FileID PrevFID) {
-  if (Reason != PPCallbacks::EnterFile)
+void ModuleDepCollectorPP::LexedFileChanged(FileID FID,
+LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind 
FileType,
+FileID PrevFID,
+SourceLocation Loc) {
+  if (Reason != LexedFileChangeReason::EnterFile)
 return;
 
   // This has to be delayed as the context hash can change at the start of
@@ -320,8 +321,7 @@
   // Dependency generation really does want to go all the way to the
   // file entry for a source location to find out what is depended on.
   // We do not want #line markers to affect dependency generation!
-  if (std::optional Filename =
-  SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc
+  if (std::optional Filename = SM.getNonBuiltinFilenameForID(FID))
 MDC.addFileDep(llvm::sys::path::remove_leading_dotslash(*Filename));
 }
 
Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
===
--- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -126,9 +126,9 @@
 public:
   ModuleDepCollectorPP(ModuleDepCollector &MDC) : MDC(MDC) {}
 
-  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
-   SrcMgr::CharacteristicKind FileType,
-   FileID PrevFID) override;
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override;
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange,


Index: clang/test/ClangScanDeps/line-directive.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/line-directive.c
@@ -0,0 +1,34 @@
+// Check that we get the right file dependencies and not the declared paths from
+// line directives.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -mode preprocess-dependency-directives -format experimental-full > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  "file-deps": [
+// CHECK-NEXT:   "[[PREFIX]]/tu.c"
+// CHECK-NEXT:   "[[PREFIX]]/header.h"
+// CHECK-NEXT: ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c"
+}]
+
+//--- other.h
+
+//--- other.c
+
+//--- header.h
+#line 100 "other.h"
+
+//--- tu.c
+#include "header.h"
+#line 100 "other.c"
Index: clang/lib

[PATCH] D143613: [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

2023-02-09 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

In D143613#4115857 , @jansvoboda11 
wrote:

> LGTM, but would be nice to have a test for this.

Oh, I didn't realize we didn't have one already.  Added.


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

https://reviews.llvm.org/D143613

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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-02-09 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

In D140756#4115381 , @aaron.ballman 
wrote:

> The spare moment came sooner than expected, I've made the changes in 
> de4321cf2cf28f2bae7fc0f1897957e73b726f89 
> .

Isn't the `global:` label needed in the new `LLVM_17` block/tag?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140756

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


[PATCH] D140915: [clangd] Fix getQueryScopes for using-directive with inline namespace

2023-02-09 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

Thanks for reviewing!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140915

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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D140756#4115963 , @vedgy wrote:

> In D140756#4115381 , @aaron.ballman 
> wrote:
>
>> The spare moment came sooner than expected, I've made the changes in 
>> de4321cf2cf28f2bae7fc0f1897957e73b726f89 
>> .
>
> Isn't the `global:` label needed in the new `LLVM_17` block/tag?

I thought that was the default already, but I see the others do it explicitly, 
so I will as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140756

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


[PATCH] D143613: [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

2023-02-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D143613#4115935 , @benlangmuir 
wrote:

> In D143613#4115857 , @jansvoboda11 
> wrote:
>
>> LGTM, but would be nice to have a test for this.
>
> Oh, I didn't realize we didn't have one already.  Added.

Thanks!


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

https://reviews.llvm.org/D143613

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

__clang_hip_math.hip is annoying...

We'll need to remove the `MandatoryFirst` inliner in 
`ModuleInlinerWrapperPass`, although not sure if @mtrofin has any issues with 
that or not

This isn't quite what I had initially thought, but this might be better. (I was 
thinking that we sort the calls in the inliner to visit alwaysinline calls 
first, but that might cause more compile time issues since we have to update 
the call graph after visiting all the calls in a function, but we might be 
visiting every function twice if we first batch process the alwaysinline calls 
then all other calls)




Comment at: llvm/lib/Passes/PassBuilderPipelines.cpp:1082
 
+  MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
+

I think we want to insert lifetime intrinsics when optimizing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[clang-tools-extra] ce87b03 - [clangd] Fix getQueryScopes for using-directive with inline namespace

2023-02-09 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2023-02-09T20:53:33+01:00
New Revision: ce87b031437071f011026bb850a2fb2e5f9a72b4

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

LOG: [clangd] Fix getQueryScopes for using-directive with inline namespace

For example, in the following code

```

using namespace std::string_literals;

int main() {
strin^ // Completes `string` instead of `std::string`
}
```

The using declaration would make completion drop the std namespace, even though 
it shouldn't.

printNamespaceScope() skips inline namespaces, so to fix this use
printQualifiedName() instead

See https://github.com/clangd/clangd/issues/1451

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 708e6f140af3d..04494f9cda5b4 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -313,7 +313,7 @@ struct ScoredBundleGreater {
 struct CodeCompletionBuilder {
   CodeCompletionBuilder(ASTContext *ASTCtx, const CompletionCandidate &C,
 CodeCompletionString *SemaCCS,
-llvm::ArrayRef QueryScopes,
+llvm::ArrayRef AccessibleScopes,
 const IncludeInserter &Includes,
 llvm::StringRef FileName,
 CodeCompletionContext::Kind ContextKind,
@@ -367,7 +367,7 @@ struct CodeCompletionBuilder {
   // avoids unneeded qualifiers in cases like with `using ns::X`.
   if (Completion.RequiredQualifier.empty() && !C.SemaResult) {
 llvm::StringRef ShortestQualifier = C.IndexResult->Scope;
-for (llvm::StringRef Scope : QueryScopes) {
+for (llvm::StringRef Scope : AccessibleScopes) {
   llvm::StringRef Qualifier = C.IndexResult->Scope;
   if (Qualifier.consume_front(Scope) &&
   Qualifier.size() < ShortestQualifier.size())
@@ -646,40 +646,70 @@ struct SpecifiedScope {
   //
   // Examples of unqualified completion:
   //
-  //   "vec^"   => {""}
-  //   "using namespace std; vec^"  => {"", "std::"}
-  //   "using namespace std; namespace ns { vec^ }" => {"ns::", "std::", ""}
+  //   "vec^"=> {""}
+  //   "using namespace std; vec^"   => {"", "std::"}
+  //   "namespace ns {inline namespace ni { struct Foo {}}}
+  //using namespace ns::ni; Fo^ "=> {"", "ns::ni::"}
+  //   "using namespace std; namespace ns { vec^ }"  => {"ns::", "std::", ""}
   //
   // "" for global namespace, "ns::" for normal namespace.
   std::vector AccessibleScopes;
+  // This is an overestimate of AccessibleScopes, e.g. it ignores inline
+  // namespaces, to fetch more relevant symbols from index.
+  std::vector QueryScopes;
   // The full scope qualifier as typed by the user (without the leading "::").
   // Set if the qualifier is not fully resolved by Sema.
   std::optional UnresolvedQualifier;
 
-  // Construct scopes being queried in indexes. The results are deduplicated.
-  // This method format the scopes to match the index request representation.
-  std::vector scopesForIndexQuery() {
+  std::optional EnclosingNamespace;
+
+  bool AllowAllScopes = false;
+
+  // Scopes that are accessible from current context. Used for dropping
+  // unnecessary namespecifiers.
+  std::vector scopesForQualification() {
 std::set Results;
 for (llvm::StringRef AS : AccessibleScopes)
   Results.insert(
   (AS + (UnresolvedQualifier ? *UnresolvedQualifier : "")).str());
 return {Results.begin(), Results.end()};
   }
+
+  // Construct scopes being queried in indexes. The results are deduplicated.
+  // This method formats the scopes to match the index request representation.
+  std::vector scopesForIndexQuery() {
+// The enclosing namespace must be first, it gets a quality boost.
+std::vector EnclosingAtFront;
+if (EnclosingNamespace.has_value())
+  EnclosingAtFront.push_back(*EnclosingNamespace);
+std::set Deduplicated;
+for (llvm::StringRef S : QueryScopes)
+  if (S != EnclosingNamespace)
+Deduplicated.insert((S + UnresolvedQualifier.value_or("")).str());
+
+EnclosingAtFront.reserve(EnclosingAtFront.size() + Deduplicated.size());
+llvm::copy(Deduplicated, std::back_inserter(EnclosingAtFront));
+
+return EnclosingAtFront;
+  }
 };
 
 // Get all scopes that will be queried in indexes and whether symbols from
 // any scope is allowed. The first scope in the list is the preferre

[PATCH] D140915: [clangd] Fix getQueryScopes for using-directive with inline namespace

2023-02-09 Thread Tom Praschan 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 rGce87b0314370: [clangd] Fix getQueryScopes for 
using-directive with inline namespace (authored by tom-anders).

Changed prior to commit:
  https://reviews.llvm.org/D140915?vs=494074&id=496182#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140915

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -465,6 +465,18 @@
   Not(Contains(AllOf(qualifier(""), named("foo");
 }
 
+// https://github.com/clangd/clangd/issues/1451
+TEST(CompletionTest, QualificationWithInlineNamespace) {
+  auto Results = completions(R"cpp(
+namespace a { inline namespace b {} }
+using namespace a::b;
+void f() { Foo^ }
+  )cpp",
+ {cls("a::Foo")});
+  EXPECT_THAT(Results.Completions,
+  UnorderedElementsAre(AllOf(qualifier("a::"), named("Foo";
+}
+
 TEST(CompletionTest, InjectedTypename) {
   // These are suppressed when accessed as a member...
   EXPECT_THAT(completions("struct X{}; void foo(){ X().^ }").Completions,
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -313,7 +313,7 @@
 struct CodeCompletionBuilder {
   CodeCompletionBuilder(ASTContext *ASTCtx, const CompletionCandidate &C,
 CodeCompletionString *SemaCCS,
-llvm::ArrayRef QueryScopes,
+llvm::ArrayRef AccessibleScopes,
 const IncludeInserter &Includes,
 llvm::StringRef FileName,
 CodeCompletionContext::Kind ContextKind,
@@ -367,7 +367,7 @@
   // avoids unneeded qualifiers in cases like with `using ns::X`.
   if (Completion.RequiredQualifier.empty() && !C.SemaResult) {
 llvm::StringRef ShortestQualifier = C.IndexResult->Scope;
-for (llvm::StringRef Scope : QueryScopes) {
+for (llvm::StringRef Scope : AccessibleScopes) {
   llvm::StringRef Qualifier = C.IndexResult->Scope;
   if (Qualifier.consume_front(Scope) &&
   Qualifier.size() < ShortestQualifier.size())
@@ -646,40 +646,70 @@
   //
   // Examples of unqualified completion:
   //
-  //   "vec^"   => {""}
-  //   "using namespace std; vec^"  => {"", "std::"}
-  //   "using namespace std; namespace ns { vec^ }" => {"ns::", "std::", ""}
+  //   "vec^"=> {""}
+  //   "using namespace std; vec^"   => {"", "std::"}
+  //   "namespace ns {inline namespace ni { struct Foo {}}}
+  //using namespace ns::ni; Fo^ "=> {"", "ns::ni::"}
+  //   "using namespace std; namespace ns { vec^ }"  => {"ns::", "std::", ""}
   //
   // "" for global namespace, "ns::" for normal namespace.
   std::vector AccessibleScopes;
+  // This is an overestimate of AccessibleScopes, e.g. it ignores inline
+  // namespaces, to fetch more relevant symbols from index.
+  std::vector QueryScopes;
   // The full scope qualifier as typed by the user (without the leading "::").
   // Set if the qualifier is not fully resolved by Sema.
   std::optional UnresolvedQualifier;
 
-  // Construct scopes being queried in indexes. The results are deduplicated.
-  // This method format the scopes to match the index request representation.
-  std::vector scopesForIndexQuery() {
+  std::optional EnclosingNamespace;
+
+  bool AllowAllScopes = false;
+
+  // Scopes that are accessible from current context. Used for dropping
+  // unnecessary namespecifiers.
+  std::vector scopesForQualification() {
 std::set Results;
 for (llvm::StringRef AS : AccessibleScopes)
   Results.insert(
   (AS + (UnresolvedQualifier ? *UnresolvedQualifier : "")).str());
 return {Results.begin(), Results.end()};
   }
+
+  // Construct scopes being queried in indexes. The results are deduplicated.
+  // This method formats the scopes to match the index request representation.
+  std::vector scopesForIndexQuery() {
+// The enclosing namespace must be first, it gets a quality boost.
+std::vector EnclosingAtFront;
+if (EnclosingNamespace.has_value())
+  EnclosingAtFront.push_back(*EnclosingNamespace);
+std::set Deduplicated;
+for (llvm::StringRef S : QueryScopes)
+  if (S != EnclosingNamespace)
+Deduplicated.insert((S + UnresolvedQualifier.value_

[PATCH] D143657: [Clang][RISCV] Guard vector float16 type correctly with semantic analysis

2023-02-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 496183.
eopXD added a comment.

Update code: check for `experimental-zvfh` instead of `zvfh`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143657

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/RISCVVTypes.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-float16-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -368,14 +368,13 @@
   }
 }
   }
-  OS << "#if defined(__riscv_zvfh)\n";
+
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float16, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n";
 
   OS << "#if (__riscv_v_elen_fp >= 32)\n";
   for (int Log2LMUL : Log2LMULs) {
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat16m1_t foo() {  /* expected-error {{Vector type 'vfloat16m1_t' (aka '__rvv_float16m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -171,7 +171,6 @@
   const TargetInfo &TI = Context.getTargetInfo();
   bool HasVectorFloat32 = TI.hasFeature("zve32f");
   bool HasVectorFloat64 = TI.hasFeature("zve64d");
-  bool HasZvfh = TI.hasFeature("experimental-zvfh");
   bool HasRV64 = TI.hasFeature("64bit");
   bool HasFullMultiply = TI.hasFeature("v");
 
@@ -223,9 +222,6 @@
 continue;
 
   // Check requirement.
-  if (BaseType == BasicType::Float16 && !HasZvfh)
-continue;
-
   if (BaseType == BasicType::Float32 && !HasVectorFloat32)
 continue;
 
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -2046,6 +2046,14 @@
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
+if (Ty->isVectorFloat16Type() &&
+!Context.getTargetInfo().hasVectorFloat16Support()) {
+  Diag(Loc, diag::err_require_vector_support) << Ty;
+  if (Ty->isVectorFloat16Type() && Ty->isRVVFloat16Type()) {
+Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zvfh";
+  }
+}
+
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
   llvm::StringMap CallerFeatureMap;
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -100,6 +100,10 @@
 
   bool hasBitIntType() const override { return true; }
 
+  bool hasVectorFloat16Support() const override {
+return hasFeature("experimental-zvfh");
+  }
+
   bool useFP16ConversionIntrinsics() const override {
 return false;
   }
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -664,6 +664,10 @@
   /// Determine whether constrained floating point is supported on this target.
   virtual bool hasStrictFP() const { return HasStrictFP; }
 
+  /// Determine whether vector half float (float16) type is supported on this
+  /// target.
+  virtual bool hasVectorFloat16Support() const { return false; }
+
   /// Return the alignment that is the largest alignment ever used for any
   /// scalar/SIMD data type on the target machine you are compiling for
   /// (including types with an extended alignment requirement).
Index: clang/include/clang/Basic/RISCVVTypes.def
===
--- clang/include/clang/Basic/RISCVVTypes.def
+++ clang/include/clang/Basic/RISCVVTypes.def
@@ -60,6 +60,10 @@
   RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true)
 #endif

[PATCH] D143665: [Clang][RISCV] Guard vector int64, float32, float64 with semantic analysis

2023-02-09 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 496185.
eopXD added a comment.

Bump CI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143665

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/RISCVVTypes.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -376,23 +376,19 @@
   printType(*T);
   }
 
-  OS << "#if (__riscv_v_elen_fp >= 32)\n";
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float32, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n";
 
-  OS << "#if (__riscv_v_elen_fp >= 64)\n";
   for (int Log2LMUL : Log2LMULs) {
 auto T = TypeCache.computeType(BasicType::Float64, Log2LMUL,
PrototypeDescriptor::Vector);
 if (T)
   printType(*T);
   }
-  OS << "#endif\n\n";
 
   OS << "#define __riscv_v_intrinsic_overloading 1\n";
 
Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +zve32x -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vint64m1_t foo() {  /* expected-error {{Vector type 'vint64m1_t' (aka '__rvv_int64m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/test/Sema/riscv-vector-float64-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float64-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +zve64f -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat64m1_t foo() {  /* expected-error {{Vector type 'vfloat64m1_t' (aka '__rvv_float64m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/test/Sema/riscv-vector-float32-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-float32-check.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +zve32x -target-feature +zfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vfloat32m1_t foo() {  /* expected-error {{Vector type 'vfloat32m1_t' (aka '__rvv_float32m1_t') is not supported in the current target}} */ /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -169,8 +169,6 @@
 
 void RISCVIntrinsicManagerImpl::InitIntrinsicList() {
   const TargetInfo &TI = Context.getTargetInfo();
-  bool HasVectorFloat32 = TI.hasFeature("zve32f");
-  bool HasVectorFloat64 = TI.hasFeature("zve64d");
   bool HasRV64 = TI.hasFeature("64bit");
   bool HasFullMultiply = TI.hasFeature("v");
 
@@ -222,12 +220,6 @@
 continue;
 
   // Check requirement.
-  if (BaseType == BasicType::Float32 && !HasVectorFloat32)
-continue;
-
-  if (BaseType == BasicType::Float64 && !HasVectorFloat64)
-continue;
-
   if (((Record.RequiredExtensions & RVV_REQ_RV64) == RVV_REQ_RV64) &&
   !HasRV64)
 continue;
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -2046,12 +2046,30 @@
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
-if (Ty->isVectorFloat16Type() &&
-!Context.getTargetInfo().hasVecto

[PATCH] D143439: [RISCV] Add vendor-defined XTheadBb (basic bit-manipulation) extension

2023-02-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:318
+if (Subtarget.is64Bit())
+  setOperationAction({ISD::CTLZ, ISD::CTLZ_ZERO_UNDEF}, MVT::i32, Custom);
+  }

philipp.tomsich wrote:
> craig.topper wrote:
> > without these two lines to promote i32, I suppose we would get zext i32 to 
> > i64, ff1, addi? Is the sequence used for ctlzw better than that?
> The sequences will have an identical critical-path (and require the same 
> number of temporaries).
> I read your comment as a recommendation to simplify the overall 
> implementation (by removing the special case here and in the 
> pattern-matching).
Yes that would be my recommendation if there's no reason to prefer one over the 
other.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143439

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


[clang] 4c84c13 - [libclang] Add "global:" to the module map explicitly; NFC intended

2023-02-09 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-02-09T14:01:54-05:00
New Revision: 4c84c1314716392061215aac7f299493bdf3cc93

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

LOG: [libclang] Add "global:" to the module map explicitly; NFC intended

Added: 


Modified: 
clang/tools/libclang/libclang.map

Removed: 




diff  --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index efb1c3cc4e691..80b244e0fa907 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -419,6 +419,7 @@ LLVM_16 {
 };
 
 LLVM_17 {
+  global:
 clang_CXXMethod_isExplicit;
 };
 



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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D140756#4115979 , @aaron.ballman 
wrote:

> In D140756#4115963 , @vedgy wrote:
>
>> In D140756#4115381 , 
>> @aaron.ballman wrote:
>>
>>> The spare moment came sooner than expected, I've made the changes in 
>>> de4321cf2cf28f2bae7fc0f1897957e73b726f89 
>>> .
>>
>> Isn't the `global:` label needed in the new `LLVM_17` block/tag?
>
> I thought that was the default already, but I see the others do it 
> explicitly, so I will as well.

Added in 4c84c1314716392061215aac7f299493bdf3cc93 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140756

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

In D143624#4115986 , @aeubanks wrote:

> __clang_hip_math.hip is annoying...
>
> We'll need to remove the `MandatoryFirst` inliner in 
> `ModuleInlinerWrapperPass`, although not sure if @mtrofin has any issues with 
> that or not
>
> This isn't quite what I had initially thought, but this might be better. (I 
> was thinking that we sort the calls in the inliner to visit alwaysinline 
> calls first, but that might cause more compile time issues since we have to 
> update the call graph after visiting all the calls in a function, but we 
> might be visiting every function twice if we first batch process the 
> alwaysinline calls then all other calls)

I think that doesn't actually do the same thing as this, since the `Calls` 
vector is populated by visiting the functions in the current SCC. What we're 
trying to do with this patch is to ensure that all always-inline calls globally 
are processed first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D143634: [ModuleUtils] Assert correct linkage and visibility of structors' COMDAT key

2023-02-09 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

I've always considered that this should be fixed by extending the 
resolution-based LTO API to also include resolutions for comdats.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143634

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


[PATCH] D143670: Stop claiming we support [[carries_dependency]]

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: clang-language-wg, erichkeane, rsmith, 
hubert.reinterpretcast.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

The `[[carries_dependency]]` attribute was added to the standard in C++11, but 
implementations have (uniformly, as best I can tell) been ignoring this 
attribute for the past decade. In Clang, we would parse the attribute and 
otherwise do nothing useful with it (no additional analyses, no communication 
of the attribute to the backend, etc). As far as I know, we have no future 
plans to implement the semantics of the attribute. However, 
`__has_cpp_attribute(carries_dependency)` returns a nonzero value which 
suggests we actually do support the attribute and do useful things with it, 
especially because we documented that it might improve performance.

This removes all support for `[[carries_dependency]]` and treats it as an 
unknown attribute instead (the same as we do for other standard attributes we 
don't support, like `[[no_unique_address]]` on some targets). We now return 
zero from `__has_cpp_attribute(carries_dependency)`, which matches the behavior 
of GCC.

I can find no evidence of user code that should be impacted by this. All uses 
of the GNU version of the attribute were in compiler test suites: 
https://sourcegraph.com/search?q=context:global+__attribute__%28%28carries_dependency%29%29+-file:.*test.*+-file:clang&patternType=standard&sm=1&groupBy=repo
 All uses of the C++ version of the attribute are also in compiler 
implementations or documentation: 
https://sourcegraph.com/search?q=context:global+%5B%5Bcarries_dependency%5D%5D+-file:.*test.*+-file:clang&patternType=standard&sm=1&groupBy=repo

Incidentally, this also helps people in WG21 build a case for deprecating and 
removing this attribute in a future revision of C++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143670

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p2.cpp
  clang/test/CodeCompletion/attr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Parser/cxx11-stmt-attributes.cpp
  clang/test/Parser/stmt-attributes.c
  clang/test/Preprocessor/has_attribute.cpp
  clang/test/SemaCXX/attr-cxx0x.cpp

Index: clang/test/SemaCXX/attr-cxx0x.cpp
===
--- clang/test/SemaCXX/attr-cxx0x.cpp
+++ clang/test/SemaCXX/attr-cxx0x.cpp
@@ -46,7 +46,7 @@
 
 static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-error{{invalid application of 'alignof' to a function type}}
 
-[[__carries_dependency__]]
+[[__carries_dependency__]] // expected-warning {{unknown attribute '__carries_dependency__' ignored}}
 void func(void);
 
 alignas(4) auto PR19252 = 0;
Index: clang/test/Preprocessor/has_attribute.cpp
===
--- clang/test/Preprocessor/has_attribute.cpp
+++ clang/test/Preprocessor/has_attribute.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
+#define NOT_SUPPORTED(x) x: __has_cpp_attribute(x)
 
 // CHECK: clang::fallthrough: 201603L
 CXX11(clang::fallthrough)
@@ -35,7 +36,7 @@
 // Test for standard attributes as listed in C++2a [cpp.cond] paragraph 6.
 
 CXX11(assert)
-CXX11(carries_dependency)
+NOT_SUPPORTED(carries_dependency)
 CXX11(deprecated)
 CXX11(ensures)
 CXX11(expects)
@@ -47,7 +48,7 @@
 CXX11(noreturn)
 CXX11(unlikely)
 // FIXME(201806L) CHECK: assert: 0
-// CHECK: carries_dependency: 200809L
+// CHECK: carries_dependency: 0
 // CHECK: deprecated: 201309L
 // FIXME(201806L) CHECK: ensures: 0
 // FIXME(201806L) CHECK: expects: 0
Index: clang/test/Parser/stmt-attributes.c
===
--- clang/test/Parser/stmt-attributes.c
+++ clang/test/Parser/stmt-attributes.c
@@ -41,7 +41,7 @@
   __attribute__((unused)) switch (i) { // expected-error {{'unused' attribute cannot be applied to a statement}}
   __attribute__((uuid)) case 0:// expected-warning {{unknown attribute 'uuid' ignored}}
   __attribute__((visibility(""))) default: // expected-error {{'visibility' attribute cannot be applied to a statement}}
-__attribute__((carries_dependency)) break; // expected-error {{'carries_dependency' attribute cannot be applied to a statement}}
+__attribute__((nonnull)) break; // expected-error {{'nonnull' attr

[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

In D143624#4116080 , @aemerson wrote:

> In D143624#4115986 , @aeubanks 
> wrote:
>
>> __clang_hip_math.hip is annoying...
>>
>> We'll need to remove the `MandatoryFirst` inliner in 
>> `ModuleInlinerWrapperPass`, although not sure if @mtrofin has any issues 
>> with that or not
>>
>> This isn't quite what I had initially thought, but this might be better. (I 
>> was thinking that we sort the calls in the inliner to visit alwaysinline 
>> calls first, but that might cause more compile time issues since we have to 
>> update the call graph after visiting all the calls in a function, but we 
>> might be visiting every function twice if we first batch process the 
>> alwaysinline calls then all other calls)
>
> I think that doesn't actually do the same thing as this, since the `Calls` 
> vector is populated by visiting the functions in the current SCC. What we're 
> trying to do with this patch is to ensure that all always-inline calls 
> globally are processed first.

That's true, but the legacy pass manager where the inliner explosion didn't 
happen in your case didn't process always-inline calls before other calls. So I 
don't think it's necessary to process alwaysinline calls globally first to fix 
your case. However, given that we still do two more rounds of inlining in the 
inliner pipeline after the alwaysinliner pass you added and your case still 
doesn't blow up, this solution does seem robust.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D143670: Stop claiming we support [[carries_dependency]]

2023-02-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

Thanks for doing this Aaron.
Did you look in libc++ if they used it anywhere? (I assume they don't)




Comment at: clang/docs/ReleaseNotes.rst:131
+- Clang no longer claims to support the ``[[carries_dependency]]`` attribute.
+  We have not implemented any semantics for this attribute in the past decade,
+  have no plans to implement any in the future, and so returning nonzero from




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143670

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


[PATCH] D143670: Stop claiming we support [[carries_dependency]]

2023-02-09 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D143670#4116118 , @cor3ntin wrote:

> Thanks for doing this Aaron.
> Did you look in libc++ if they used it anywhere? (I assume they don't)

I'm not aware of any uses, and I would be quite surprised if it was used 
anywhere given that apparently nobody properly implemented it. IIUC this 
attribute is supposed to improve performance in some way, and we normally 
require a benchmark to show that some change actually does that if it claims to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143670

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


[PATCH] D143613: [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

2023-02-09 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8711120e8bcf: [clang][deps] Migrate ModuleDepCollector to 
LexedFileChanged NFCI (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143613

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/line-directive.c


Index: clang/test/ClangScanDeps/line-directive.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/line-directive.c
@@ -0,0 +1,34 @@
+// Check that we get the right file dependencies and not the declared paths 
from
+// line directives.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -mode preprocess-dependency-directives -format experimental-full > 
%t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  "file-deps": [
+// CHECK-NEXT:   "[[PREFIX]]/tu.c"
+// CHECK-NEXT:   "[[PREFIX]]/header.h"
+// CHECK-NEXT: ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c"
+}]
+
+//--- other.h
+
+//--- other.c
+
+//--- header.h
+#line 100 "other.h"
+
+//--- tu.c
+#include "header.h"
+#line 100 "other.c"
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -301,11 +301,12 @@
   assert(Inserted && "duplicate module mapping");
 }
 
-void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
-   FileChangeReason Reason,
-   SrcMgr::CharacteristicKind FileType,
-   FileID PrevFID) {
-  if (Reason != PPCallbacks::EnterFile)
+void ModuleDepCollectorPP::LexedFileChanged(FileID FID,
+LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind 
FileType,
+FileID PrevFID,
+SourceLocation Loc) {
+  if (Reason != LexedFileChangeReason::EnterFile)
 return;
 
   // This has to be delayed as the context hash can change at the start of
@@ -320,8 +321,7 @@
   // Dependency generation really does want to go all the way to the
   // file entry for a source location to find out what is depended on.
   // We do not want #line markers to affect dependency generation!
-  if (std::optional Filename =
-  SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc
+  if (std::optional Filename = SM.getNonBuiltinFilenameForID(FID))
 MDC.addFileDep(llvm::sys::path::remove_leading_dotslash(*Filename));
 }
 
Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
===
--- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -126,9 +126,9 @@
 public:
   ModuleDepCollectorPP(ModuleDepCollector &MDC) : MDC(MDC) {}
 
-  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
-   SrcMgr::CharacteristicKind FileType,
-   FileID PrevFID) override;
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override;
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange,


Index: clang/test/ClangScanDeps/line-directive.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/line-directive.c
@@ -0,0 +1,34 @@
+// Check that we get the right file dependencies and not the declared paths from
+// line directives.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -mode preprocess-dependency-directives -format experimental-full > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  "file-deps": [
+// CHECK-NEXT:   "[[PREFIX]]/tu.c"
+// CHECK-NEXT:   "[[PREFIX]]/header.h"
+// CHECK-NEXT: ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c"
+

[clang] 8711120 - [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

2023-02-09 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2023-02-09T11:42:03-08:00
New Revision: 8711120e8bcf891f3c316e20869493e93472f200

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

LOG: [clang][deps] Migrate ModuleDepCollector to LexedFileChanged NFCI

LexedFileChanged has the semantics we want of ignoring #line/etc. It's
also consistent with other dep collectors like DependencyFileGenerator.

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

Added: 
clang/test/ClangScanDeps/line-directive.c

Modified: 
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 6e4cec25961de..3e1b71e6b8a48 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -126,9 +126,9 @@ class ModuleDepCollectorPP final : public PPCallbacks {
 public:
   ModuleDepCollectorPP(ModuleDepCollector &MDC) : MDC(MDC) {}
 
-  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
-   SrcMgr::CharacteristicKind FileType,
-   FileID PrevFID) override;
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override;
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange,

diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 4ff9e606677a8..94ece9eb4c685 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -301,11 +301,12 @@ void ModuleDepCollector::associateWithContextHash(const 
CompilerInvocation &CI,
   assert(Inserted && "duplicate module mapping");
 }
 
-void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
-   FileChangeReason Reason,
-   SrcMgr::CharacteristicKind FileType,
-   FileID PrevFID) {
-  if (Reason != PPCallbacks::EnterFile)
+void ModuleDepCollectorPP::LexedFileChanged(FileID FID,
+LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind 
FileType,
+FileID PrevFID,
+SourceLocation Loc) {
+  if (Reason != LexedFileChangeReason::EnterFile)
 return;
 
   // This has to be delayed as the context hash can change at the start of
@@ -320,8 +321,7 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
   // Dependency generation really does want to go all the way to the
   // file entry for a source location to find out what is depended on.
   // We do not want #line markers to affect dependency generation!
-  if (std::optional Filename =
-  SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc
+  if (std::optional Filename = SM.getNonBuiltinFilenameForID(FID))
 MDC.addFileDep(llvm::sys::path::remove_leading_dotslash(*Filename));
 }
 

diff  --git a/clang/test/ClangScanDeps/line-directive.c 
b/clang/test/ClangScanDeps/line-directive.c
new file mode 100644
index 0..4bf532167a935
--- /dev/null
+++ b/clang/test/ClangScanDeps/line-directive.c
@@ -0,0 +1,34 @@
+// Check that we get the right file dependencies and not the declared paths 
from
+// line directives.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -mode preprocess-dependency-directives -format experimental-full > 
%t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  "file-deps": [
+// CHECK-NEXT:   "[[PREFIX]]/tu.c"
+// CHECK-NEXT:   "[[PREFIX]]/header.h"
+// CHECK-NEXT: ]
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c"
+}]
+
+//--- other.h
+
+//--- other.c
+
+//--- header.h
+#line 100 "other.h"
+
+//--- tu.c
+#include "header.h"
+#line 100 "other.c"



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


[PATCH] D143501: [clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D143501#4110302 , @Michael137 
wrote:

> The alternative would be attaching the preferred name as a new attribute or 
> an existing attribute like `DW_AT_description`.

I'd recommend a possible long-term solution would be simplified template names 
(so we don't have to worry about encoding this in the `DW_AT_name` anyway) and 
a "DW_AT_LLVM_preferred_name" or similar attribute on a type that refers to the 
typedef that is the preferred name. This would generalize further than only 
appearing in template names - the type of a variable inside a template would 
also gain the beneficial naming (eg: `template void f1(T t) { }` - 
as it stands, the type of the variable `t` must be `std::basic_stringhttps://reviews.llvm.org/D143501/new/

https://reviews.llvm.org/D143501

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin added a comment.

In D143624#4115986 , @aeubanks wrote:

> __clang_hip_math.hip is annoying...
>
> We'll need to remove the `MandatoryFirst` inliner in 
> `ModuleInlinerWrapperPass`, although not sure if @mtrofin has any issues with 
> that or not

IIRC we had at a point a mandatory , whole-module pass. The idea wast that 
let's not have N inliners, and that AlwaysInliner had some limitations, and for 
similar reasons @aemerson  pointed out, it'd make sense to first perform the 
mandatory inlines (D91567 ). In D94825 
 we went away from that. I don't remember why. 
@aeubanks? (it's referencing a patch you started)

> This isn't quite what I had initially thought, but this might be better. (I 
> was thinking that we sort the calls in the inliner to visit alwaysinline 
> calls first, but that might cause more compile time issues since we have to 
> update the call graph after visiting all the calls in a function, but we 
> might be visiting every function twice if we first batch process the 
> alwaysinline calls then all other calls)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

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

In D143546#4114341 , @owenpan wrote:

> In D143546#4113721 , @rymiel wrote:
>
>> In D143546#4112077 , @owenpan 
>> wrote:
>>
>>> As this one is an invalid-code-generation bug, I wanted it fixed ASAP.
>>
>> Do you intend to backport it to the 16 release branch then?
>
> I don't know but will go with whatever you, @MyDeveloperDay and 
> @HazardyKnusperkeks prefer.

I'd vote in favor, letting a code breaking bug knowingly in the most current 
(or to come? I don't follow that.) version would be let's say not nice.




Comment at: clang/lib/Format/TokenAnnotator.cpp:3884
   if (Style.isCpp()) {
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;

owenpan wrote:
> rsmith wrote:
> > owenpan wrote:
> > > HazardyKnusperkeks wrote:
> > > > Add a comment what that is? Without the bug report I'd not know what 
> > > > that sequence would be.
> > > I could do that, but the github issue is linked in the summary above and 
> > > will be in the commit message. In general, I don't like unnecessary 
> > > comments littered in the source. They can become outdated, out of place, 
> > > misleading, and even wrong. How about giving an example as shown above?
> > Does `clang-format` have any formatting modes where it would leave out 
> > spaces around `+` or `-`? The same issue arises with things like `0xe + n`, 
> > where removing the space between the `0xe` and the `+` results in a token 
> > splice.
> No. I was aware of them and had made sure clang-format already handled them 
> correctly.
> I could do that, but the github issue is linked in the summary above and will 
> be in the commit message. In general, I don't like unnecessary comments 
> littered in the source. They can become outdated, out of place, misleading, 
> and even wrong. How about giving an example as shown above?

If you do a `git blame` you can come to the commit and thus to the bug, but if 
you are just reading, at least I don't blame all the lines. There I think a 
comment is nice, and your proposal is a really nice one.
But I've accepted the patch as is, and so the decision is yours. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[PATCH] D143501: [clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-09 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

> I'd recommend a possible long-term solution would be simplified template 
> names (so we don't have to worry about encoding this in the `DW_AT_name` 
> anyway) and a "DW_AT_LLVM_preferred_name" or similar attribute on a type that 
> refers to the typedef that is the preferred name. This would generalize 
> further than only appearing in template names - the type of a variable inside 
> a template would also gain the beneficial naming (eg: `template 
> void f1(T t) { }` - as it stands, the type of the variable `t` must be 
> `std::basic_string `std::basic_string debugger could helpfully render the type by its preferred alias instead)

That could be a neat solution. I probably asked this before, but what's the 
timeline with switching it on by default (if such plan is in the works at all)?

> Alternatively, I suppose, the DWARF emission could just look at the preferred 
> name and use that as the `DW_AT_type` in all cases anyway? Avoids needing a 
> new attribute, etc, though would be a bit quirky in its own way.

This is how I first thought of implementing it, but ran into some circular 
dependency quirks and started working on this patch instead. Could take a 
second stab at doing so if that's the preference. Would be nice to not have 
this behind a tuning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143592: [flang][driver] Rename `flang-new -flang-experimental-exec` to `flang`

2023-02-09 Thread Brad Richardson via Phabricator via cfe-commits
everythingfunctional updated this revision to Diff 496213.
everythingfunctional added a comment.

rebase to get fix for build/test failure


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

https://reviews.llvm.org/D143592

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/test/Driver/flang/flang.f90
  clang/test/Driver/flang/flang_ucase.F90
  clang/test/Driver/flang/multiple-inputs-mixed.f90
  clang/test/Driver/flang/multiple-inputs.f90
  flang/docs/FlangDriver.md
  flang/docs/ImplementingASemanticCheck.md
  flang/docs/Overview.md
  flang/examples/FlangOmpReport/FlangOmpReport.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/color-diagnostics-forwarding.f90
  flang/test/Driver/convert.f90
  flang/test/Driver/disable-ext-name-interop.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-version.f90
  flang/test/Driver/escaped-backslash.f90
  flang/test/Driver/fdefault.f90
  flang/test/Driver/flarge-sizes.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/intrinsic-module-path.f90
  flang/test/Driver/linker-flags.f90
  flang/test/Driver/macro-def-undef.F90
  flang/test/Driver/missing-input.f90
  flang/test/Driver/multiple-input-files.f90
  flang/test/Driver/predefined-macros-compiler-version.F90
  flang/test/Driver/std2018-wrong.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/use-module-error.f90
  flang/test/Driver/use-module.f90
  flang/test/Lower/Intrinsics/command_argument_count.f90
  flang/test/Lower/Intrinsics/exit.f90
  flang/test/Lower/Intrinsics/get_command_argument.f90
  flang/test/Lower/Intrinsics/get_environment_variable.f90
  flang/test/Lower/Intrinsics/move_alloc.f90
  flang/test/Lower/OpenACC/Todo/acc-declare.f90
  flang/test/Lower/OpenACC/Todo/acc-routine.f90
  flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90
  flang/test/Lower/OpenMP/Todo/omp-declare-target.f90
  flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90
  flang/test/lit.cfg.py
  flang/tools/f18/CMakeLists.txt
  flang/tools/f18/flang-to-external-fc.in
  flang/tools/flang-driver/CMakeLists.txt
  flang/tools/flang-driver/driver.cpp

Index: flang/tools/flang-driver/driver.cpp
===
--- flang/tools/flang-driver/driver.cpp
+++ flang/tools/flang-driver/driver.cpp
@@ -88,14 +88,15 @@
   llvm::InitLLVM x(argc, argv);
   llvm::SmallVector args(argv, argv + argc);
 
-  clang::driver::ParsedClangName targetandMode("flang", "--driver-mode=flang");
+  clang::driver::ParsedClangName targetandMode =
+  clang::driver::ToolChain::getTargetAndModeFromProgramName(argv[0]);
   std::string driverPath = getExecutablePath(args[0]);
 
   llvm::BumpPtrAllocator a;
   llvm::StringSaver saver(a);
   ExpandResponseFiles(saver, args);
 
-  // Check if flang-new is in the frontend mode
+  // Check if flang is in the frontend mode
   auto firstArg = std::find_if(args.begin() + 1, args.end(),
[](const char *a) { return a != nullptr; });
   if (firstArg != args.end()) {
@@ -104,7 +105,7 @@
<< "Valid tools include '-fc1'.\n";
   return 1;
 }
-// Call flang-new frontend
+// Call flang frontend
 if (llvm::StringRef(args[1]).startswith("-fc1")) {
   return executeFC1Tool(args);
 }
Index: flang/tools/flang-driver/CMakeLists.txt
===
--- flang/tools/flang-driver/CMakeLists.txt
+++ flang/tools/flang-driver/CMakeLists.txt
@@ -11,7 +11,7 @@
   TargetParser
 )
 
-add_flang_tool(flang-new
+add_flang_tool(flang
   driver.cpp
   fc1_main.cpp
 
@@ -24,13 +24,13 @@
   Fortran_main
 )
 
-target_link_libraries(flang-new
+target_link_libraries(flang
   PRIVATE
   flangFrontend
   flangFrontendTool
 )
 
-clang_target_link_libraries(flang-new
+clang_target_link_libraries(flang
   PRIVATE
   clangDriver
   clangBasic
@@ -38,9 +38,9 @@
 
 option(FLANG_PLUGIN_SUPPORT "Build Flang with plugin support." ON)
 
-# Enable support for plugins, which need access to symbols from flang-new
+# Enable support for plugins, which need access to symbols from flang
 if(FLANG_PLUGIN_SUPPORT)
-  export_executable_symbols_for_plugins(flang-new)
+  export_executable_symbols_for_plugins(flang)
 endif()
 
-install(TARGETS flang-new DESTINATION "${CMAKE_INSTALL_BINDIR}")
+install(TARGETS flang DESTINATION "${CMAKE_INSTALL_BINDIR}")
Index: flang/tools/f18/flang-to-external-fc.in
===
--- flang/tools/f18/flang-to-external-fc.in
+++ flang/tools/f18/flang-to-external-fc.in
@@ -205,7 +205,7 @@
 

[PATCH] D143418: [libclang] Add API to set preferred temp dir path

2023-02-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: jkorous.
aaron.ballman added a comment.

In D143418#4111990 , @vedgy wrote:

> I hoped to avoid applying an unrelated `git clang-format`'s include 
> reordering, but the CI fails because of that. Will apply it along with 
> changes requested during code review.

FWIW, you can ignore any CI failure related to formatting. It's an (annoying) 
bug that it gets reported as a failure. Our coding style guide prefers matching 
the surrounding style when it conflicts with the usual coding style, so it's 
not uncommon to have these kind of fake failures.

From the previous review (https://reviews.llvm.org/D139774):

> After thinking some more, I'd like to revisit this decision. You agree that 
> the general solution setTempDirPath() is an ultimate goal. But the rejection 
> of tampering with the return value of system_temp_directory() means that 
> overriding the temporary path will likely never be perfectly reliable.

Just to make sure we're on the same page, the reason we don't want to change 
`system_temp_directory()` is because that API is expected to get you the system 
temp directory, so an override in that function would break expectations. 
Instead, we want callers of that API to decide whether they really want the 
system temp directory or whether they want some other directory that perhaps 
the user provides. That keeps a clean separation of concerns -- the system APIs 
get you the system information and the things that wish to put files elsewhere 
can still do so.

> So how about a more sincere general solution: setPreferredTempDirPath()? The 
> documentation would say that libclang tries its best to place temporary files 
> into the specified directory, but some might end up in the system temporary 
> directory instead.

I don't think those semantics are reasonable. "Tries its best" is fine for 
things that are heuristic based, like deciding when to do an analysis cut 
point, but is too non-deterministic for something like "where do files get 
placed". I think it's reasonable that we either:

1. expose an option to say "I prefer preambles to be put in this directory" for 
libclang, or
2. expose an option to say "I prefer using this directory over the temp 
directory for all files" for libclang,

I thought we agreed that #2 is too high of risk because it requires auditing 
libclang for all the places it decides to put something into the temp 
directory, and so we were going with #1 and doing it as part of the cindex 
constructor so that users cannot run into the surprise issues (multithreading, 
files changing location mid-run) with an independent setter.

> Such an API would be consistent with an existing libclang function:

That is interesting to note, but I'm not certain that was a good decision as it 
still has the same concerns. In the original review for that 
(https://reviews.llvm.org/D40527), it was observed that libclang is not 
thread-safe, which is accurate (Clang itself is not particularly thread-safe 
but there have been occasional efforts to drive us in that direction or at 
least not drive us away from it), but it didn't discuss the fact that this 
design potentially leads to files in different locations mid-run. It also 
didn't get nearly as much review discussion as this API, so there's that. CC 
@arphaman and @jkorous in case they want to weigh in on the new API, since 
they've worked in this area.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143418

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

In D143624#4116114 , @aeubanks wrote:

> In D143624#4116080 , @aemerson 
> wrote:
>
>> In D143624#4115986 , @aeubanks 
>> wrote:
>>
>>> __clang_hip_math.hip is annoying...
>>>
>>> We'll need to remove the `MandatoryFirst` inliner in 
>>> `ModuleInlinerWrapperPass`, although not sure if @mtrofin has any issues 
>>> with that or not
>>>
>>> This isn't quite what I had initially thought, but this might be better. (I 
>>> was thinking that we sort the calls in the inliner to visit alwaysinline 
>>> calls first, but that might cause more compile time issues since we have to 
>>> update the call graph after visiting all the calls in a function, but we 
>>> might be visiting every function twice if we first batch process the 
>>> alwaysinline calls then all other calls)
>>
>> I think that doesn't actually do the same thing as this, since the `Calls` 
>> vector is populated by visiting the functions in the current SCC. What we're 
>> trying to do with this patch is to ensure that all always-inline calls 
>> globally are processed first.
>
> That's true, but the legacy pass manager where the inliner explosion didn't 
> happen in your case didn't process always-inline calls before other calls. So 
> I don't think it's necessary to process alwaysinline calls globally first to 
> fix your case. However, given that we still do two more rounds of inlining in 
> the inliner pipeline after the alwaysinliner pass you added and your case 
> still doesn't blow up, this solution does seem robust.

Sure, the exponential compile time case is actually just a side benefit here. 
The motivating reason for this change is actually to improve code size when 
building codebases that make heavy use of always_inline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

In D143624#4116171 , @mtrofin wrote:

> In D143624#4115986 , @aeubanks 
> wrote:
>
>> __clang_hip_math.hip is annoying...
>>
>> We'll need to remove the `MandatoryFirst` inliner in 
>> `ModuleInlinerWrapperPass`, although not sure if @mtrofin has any issues 
>> with that or not
>
> IIRC we had at a point a mandatory , whole-module pass. The idea wast that 
> let's not have N inliners, and that AlwaysInliner had some limitations, and 
> for similar reasons @aemerson  pointed out, it'd make sense to first perform 
> the mandatory inlines (D91567 ). In D94825 
>  we went away from that. I don't remember 
> why. @aeubanks? (it's referencing a patch you started)
>
>> This isn't quite what I had initially thought, but this might be better. (I 
>> was thinking that we sort the calls in the inliner to visit alwaysinline 
>> calls first, but that might cause more compile time issues since we have to 
>> update the call graph after visiting all the calls in a function, but we 
>> might be visiting every function twice if we first batch process the 
>> alwaysinline calls then all other calls)

Without knowing that there were inliner explosion issues, I still think it 
makes more sense to not visit all functions twice. e.g. it helps with cache 
locality when compiling if you don't visit functions on two separate walks of 
the call graph.

But if this solves the issue then I think this patch is good. Getting rid of 
the mandatory inline advisor is a nice cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-02-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

In D143624#4116318 , @aemerson wrote:

> Sure, the exponential compile time case is actually just a side benefit here. 
> The motivating reason for this change is actually to improve code size when 
> building codebases that make heavy use of always_inline.

Ah I didn't see that part of the commit message. Mentioning code size more 
explicitly in the message would be good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D143546#4114341 , @owenpan wrote:

> In D143546#4113721 , @rymiel wrote:
>
>> In D143546#4112077 , @owenpan 
>> wrote:
>>
>>> As this one is an invalid-code-generation bug, I wanted it fixed ASAP.
>>
>> Do you intend to backport it to the 16 release branch then?
>
> I don't know but will go with whatever you, @MyDeveloperDay and 
> @HazardyKnusperkeks prefer.

honestly, I trust your judgement @ownpan. I'm ok either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


[clang] b4e35c6 - [clang-format] Insert a space between a numeric UDL and a dot

2023-02-09 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-02-09T13:34:57-08:00
New Revision: b4e35c63711b4bde10b83607d04dab4bfdb86482

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

LOG: [clang-format] Insert a space between a numeric UDL and a dot

Fixes #60576.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 2186d68ab430b..2bafa48b53363 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3893,6 +3893,9 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 return true;
 
   if (Style.isCpp()) {
+// Space between UDL and dot: auto b = 4s .count();
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;
 // Space between import .
 // or import .;
 if (Left.is(Keywords.kw_import) && Right.isOneOf(tok::less, tok::ellipsis))

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b00c597b69a1d..69736ee497930 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25407,6 +25407,11 @@ TEST_F(FormatTest, InsertNewlineAtEOF) {
   verifyFormat("int i;\n", "int i;", Style);
 }
 
+TEST_F(FormatTest, SpaceAfterUDL) {
+  verifyFormat("auto c = (4s).count();");
+  verifyFormat("auto x = 5s .count() == 5;");
+}
+
 } // namespace
 } // namespace format
 } // namespace clang



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


[PATCH] D143546: [clang-format] Insert a space between a numeric UDL and a dot

2023-02-09 Thread Owen Pan 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 rGb4e35c63711b: [clang-format] Insert a space between a 
numeric UDL and a dot (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D143546?vs=495707&id=496226#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143546

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25407,6 +25407,11 @@
   verifyFormat("int i;\n", "int i;", Style);
 }
 
+TEST_F(FormatTest, SpaceAfterUDL) {
+  verifyFormat("auto c = (4s).count();");
+  verifyFormat("auto x = 5s .count() == 5;");
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3893,6 +3893,9 @@
 return true;
 
   if (Style.isCpp()) {
+// Space between UDL and dot: auto b = 4s .count();
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;
 // Space between import .
 // or import .;
 if (Left.is(Keywords.kw_import) && Right.isOneOf(tok::less, tok::ellipsis))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25407,6 +25407,11 @@
   verifyFormat("int i;\n", "int i;", Style);
 }
 
+TEST_F(FormatTest, SpaceAfterUDL) {
+  verifyFormat("auto c = (4s).count();");
+  verifyFormat("auto x = 5s .count() == 5;");
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3893,6 +3893,9 @@
 return true;
 
   if (Style.isCpp()) {
+// Space between UDL and dot: auto b = 4s .count();
+if (Right.is(tok::period) && Left.is(tok::numeric_constant))
+  return true;
 // Space between import .
 // or import .;
 if (Left.is(Keywords.kw_import) && Right.isOneOf(tok::less, tok::ellipsis))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >