[clang] Introduce paged vector (PR #66430)

2023-09-18 Thread David Blaikie via cfe-commits


@@ -0,0 +1,301 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+//
+// Pages are allocated in SLAB_SIZE chunks, using the BumpPtrAllocator.
+template 
+class PagedVector {
+  static_assert(PAGE_SIZE > 0, "PAGE_SIZE must be greater than 0. Most likely "
+   "you want it to be greater than 16.");
+  // The actual number of element in the vector which can be accessed.
+  std::size_t Size = 0;
+
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector PageToDataIdx;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The order of
+  // the elements however depends on the order of access of the pages.
+  uintptr_t Allocator = 0;
+
+  constexpr static T *invalidPage() { return reinterpret_cast(SIZE_MAX); }
+
+public:
+  // Default constructor. We build our own allocator.
+  PagedVector()
+  : Allocator(reinterpret_cast(new BumpPtrAllocator) | 0x1) {}
+  PagedVector(BumpPtrAllocator *A)
+  : Allocator(reinterpret_cast(A)) {}
+
+  ~PagedVector() {
+// If we own the allocator, delete it.
+if (Allocator & 0x1) {
+  delete getAllocator();
+}
+  }
+
+  // Get the allocator.
+  BumpPtrAllocator *getAllocator() const {
+return reinterpret_cast(Allocator & ~0x1);
+  }
+  // Lookup an element at position Index.
+  T [](std::size_t Index) const { return at(Index); }
+
+  // Lookup an element at position i.
+  // If the associated page is not filled, it will be filled with default
+  // constructed elements. If the associated page is filled, return the 
element.
+  T (std::size_t Index) const {
+assert(Index < Size);
+assert(Index / PAGE_SIZE < PageToDataIdx.size());
+auto * = PageToDataIdx[Index / PAGE_SIZE];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == invalidPage()) {
+  PagePtr = getAllocator()->template Allocate(PAGE_SIZE);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  for (std::size_t I = 0; I < PAGE_SIZE; ++I) {
+new (PagePtr + I) T();
+  }
+}
+// Dereference the element in the page.
+return *((Index % PAGE_SIZE) + PagePtr);
+  }
+
+  // Return the capacity of the vector. I.e. the maximum size it can be 
expanded
+  // to with the expand method without allocating more pages.
+  std::size_t capacity() const { return PageToDataIdx.size() * PAGE_SIZE; }
+
+  // Return the size of the vector. I.e. the maximum index that can be
+  // accessed, i.e. the maximum value which was used as argument of the
+  // expand method.
+  std::size_t size() const { return Size; }
+
+  // Expands the vector to the given NewSize number of elements.
+  // If the vector was smaller, allocates new pages as needed.
+  // It should be called only with NewSize >= Size.
+  void expand(std::size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// one would have to invalidate contents which is expensive and
+// while giving the false hope that the resize is cheap.
+if (NewSize <= Size) {
+  return;
+}
+// If the capacity is enough, just update the size and continue
+// with the currently allocated pages.
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+// The number of pages to allocate. The Remainder is calculated
+// for the case in which the NewSize is not a multiple of PAGE_SIZE.
+// In that case we need one more page.
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if 

[clang] 2993243 - Fix misdiagnosed writability for __attribute__((section()))

2023-08-16 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-08-17T05:35:40Z
New Revision: 2993243c45abdb4f2bc3979336d054be165b1134

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

LOG: Fix misdiagnosed writability for __attribute__((section()))

This didn't actually misclassify the resulting IR variable, but caused a
false-positive error about mismatched section flags.

Follow-up to D156726, issue identified by @eddyz87, thanks!

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/attr-section.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0ad807cca36c7b..3c2c7575ed9980 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14363,8 +14363,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 bool MSVCEnv =
 Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
 std::optional Reason;
-if (var->hasInit() && HasConstInit && !(Reason =
-var->getType().isNonConstantStorage(Context, true, false))) {
+if (HasConstInit &&
+!(Reason = var->getType().isNonConstantStorage(Context, true, false))) 
{
   Stack = 
 } else {
   SectionFlags |= ASTContext::PSF_Write;

diff  --git a/clang/test/Sema/attr-section.c b/clang/test/Sema/attr-section.c
index 1f058c24f980fd..2f9ac2f1ce9442 100644
--- a/clang/test/Sema/attr-section.c
+++ b/clang/test/Sema/attr-section.c
@@ -28,6 +28,9 @@ extern int a __attribute__((section("foo,zed"))); // 
expected-warning {{section
 int c;
 int c __attribute__((section("seg1,sec1")));
 
+const int with_init __attribute__((section("init_mix,x"))) = 1;
+const int no_init __attribute__((section("init_mix,x")));
+
 // Also OK.
 struct r_debug {};
 extern struct r_debug _r_debug;



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


[clang] 19f2b68 - Make globals with mutable members non-constant, even in custom sections

2023-08-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-08-14T22:25:42Z
New Revision: 19f2b68095fe727e40079b7c6380b36b6462e691

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

LOG: Make globals with mutable members non-constant, even in custom sections

Turned out we were making overly simple assumptions about which sections (& 
section flags) would be used when emitting a global into a custom section. This 
lead to sections with read-only flags being used for globals of struct types 
with mutable members.

Fixed by porting the codegen function with the more nuanced handling/checking 
for mutable members out of codegen for use in the sema code that does this 
initial checking/mapping to section flags.

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

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/Targets/AMDGPU.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/sections.cpp
clang/test/SemaCXX/attr-section.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 82a68e332765e8..ed424ffb748014 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -817,6 +817,26 @@ class QualType {
   /// Determine whether this type is const-qualified.
   bool isConstQualified() const;
 
+  enum class NonConstantStorageReason {
+MutableField,
+NonConstNonReferenceType,
+NonTrivialCtor,
+NonTrivialDtor,
+  };
+  /// Determine whether instances of this type can be placed in immutable
+  /// storage.
+  /// If ExcludeCtor is true, the duration when the object's constructor runs
+  /// will not be considered. The caller will need to verify that the object is
+  /// not written to during its construction. ExcludeDtor works similarly.
+  std::optional
+  isNonConstantStorage(const ASTContext , bool ExcludeCtor,
+   bool ExcludeDtor);
+
+  bool isConstantStorage(const ASTContext , bool ExcludeCtor,
+ bool ExcludeDtor) {
+return !isNonConstantStorage(Ctx, ExcludeCtor, ExcludeDtor);
+  }
+
   /// Determine whether this particular QualType instance has the
   /// "restrict" qualifier set, without looking through typedefs that may have
   /// added "restrict" at a 
diff erent level.

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 990f223f755490..6f8386cd10922f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -446,6 +446,7 @@ def IgnoredQualifiers : DiagGroup<"ignored-qualifiers", 
[IgnoredReferenceQualifi
 def : DiagGroup<"import">;
 def GNUIncludeNext : DiagGroup<"gnu-include-next">;
 def IncompatibleMSStruct : DiagGroup<"incompatible-ms-struct">;
+def IncompatibleMSPragmaSection : DiagGroup<"incompatible-ms-pragma-section">;
 def IncompatiblePointerTypesDiscardsQualifiers
   : DiagGroup<"incompatible-pointer-types-discards-qualifiers">;
 def IncompatibleFunctionPointerTypes

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 95f8f0247d4b78..935fad819b82a4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -996,6 +996,9 @@ def warn_cxx_ms_struct :
 def err_pragma_pack_identifer_not_supported : Error<
   "specifying an identifier within `#pragma pack` is not supported on this 
target">;
 def err_section_conflict : Error<"%0 causes a section type conflict with %1">;
+def warn_section_msvc_compat : Warning<"`#pragma const_seg` for section %1 
will"
+  " not apply to %0 due to the presence of a %select{mutable 
field||non-trivial constructor|non-trivial destructor}2">,
+  InGroup;
 def err_no_base_classes : Error<"invalid use of '__super', %0 has no base 
classes">;
 def err_invalid_super_scope : Error<"invalid use of '__super', "
   "this keyword can only be used inside class or member function scope">;

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index b3fd6fc3d823e2..e023cb46b9bb85 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -112,6 +112,25 @@ bool QualType::isConstant(QualType T, const ASTContext 
) {
   return T.getAddressSpace() == LangAS::opencl_constant;
 }
 
+std::optional
+QualType::isNonConstantStorage(const ASTContext , bool ExcludeCtor,
+bool 

Re: [clang] 3b34d69 - Revert "For #64088: mark vtable as used if we might emit a reference to it."

2023-08-06 Thread David Blaikie via cfe-commits
Ping on this - please always include details on the reason for a revert.

On Tue, Aug 1, 2023 at 10:09 AM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This revert reintroduces a wrong-code bug, can you explain what the
> purpose of the revert is?
>
> On Fri, 28 Jul 2023 at 03:50, Dmitry Chernenkov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Dmitry Chernenkov
>> Date: 2023-07-28T10:49:53Z
>> New Revision: 3b34d69ac7a643742364be3591b324ddd14ef9aa
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/3b34d69ac7a643742364be3591b324ddd14ef9aa
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/3b34d69ac7a643742364be3591b324ddd14ef9aa.diff
>>
>> LOG: Revert "For #64088: mark vtable as used if we might emit a reference
>> to it."
>>
>> This reverts commit b6847edfc235829b37dd6d734ef5bbfa0a58b6fc.
>>
>> Added:
>>
>>
>> Modified:
>> clang/lib/Sema/SemaCast.cpp
>> clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
>> index b338d601db7397..d65ecf52c52310 100644
>> --- a/clang/lib/Sema/SemaCast.cpp
>> +++ b/clang/lib/Sema/SemaCast.cpp
>> @@ -935,14 +935,6 @@ void CastOperation::CheckDynamicCast() {
>><< isClangCL;
>>}
>>
>> -  // For a dynamic_cast to a final type, IR generation might emit a
>> reference
>> -  // to the vtable.
>> -  if (DestRecord) {
>> -auto *DestDecl = DestRecord->getAsCXXRecordDecl();
>> -if (DestDecl->isEffectivelyFinal())
>> -  Self.MarkVTableUsed(OpRange.getBegin(), DestDecl);
>> -  }
>> -
>>// Done. Everything else is run-time checks.
>>Kind = CK_Dynamic;
>>  }
>>
>> diff  --git a/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> b/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> index bd283e85101b4b..676aa975a72686 100644
>> --- a/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> +++ b/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> @@ -76,12 +76,3 @@ H *exact_multi(A *a) {
>>// CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null,
>> %[[LABEL_FAILED]] ]
>>return dynamic_cast(a);
>>  }
>> -
>> -namespace GH64088 {
>> -  // Ensure we mark the B vtable as used here, because we're going to
>> emit a
>> -  // reference to it.
>> -  // CHECK: define {{.*}} @_ZN7GH640881BD0
>> -  struct A { virtual ~A(); };
>> -  struct B final : A { virtual ~B() = default; };
>> -  B *cast(A *p) { return dynamic_cast(p); }
>> -}
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3a100ea - Fix test to not write temporary files, use -fsyntax-only instead

2023-07-31 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-07-31T19:01:44Z
New Revision: 3a100ea901ed79d6a06a5f018be2b4d3bbca51e8

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

LOG: Fix test to not write temporary files, use -fsyntax-only instead

Added: 


Modified: 
clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c

Removed: 




diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
index de9e4a26badb63..f5149bf4ce8fda 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
@@ -1,16 +1,16 @@
 // REQUIRES: powerpc-registered-target
 
-// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 \
+// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
 // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_SI
-// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 \
+// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
 // RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_F
-// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 \
+// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
 // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_SLL
-// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 \
+// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
 // RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_D
-// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 \
+// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
 // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_UNALIGNED_UI
-// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 \
+// RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
 // RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify
 
 #include 



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


[clang] b43df5b - PseudoObjectExpr: Prefer ArrayRef over iterator_range when iterating with pointers

2023-07-18 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-07-18T23:43:41Z
New Revision: b43df5bfe7e7ef358e135b515b0651ec51f635d8

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

LOG: PseudoObjectExpr: Prefer ArrayRef over iterator_range when iterating with 
pointers

Simpler to use ArrayRef directly here rather than a more
generic/customizable range helper like iterator_range

Added: 


Modified: 
clang/include/clang/AST/Expr.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 661a8a7175ca88..7a886f546ed937 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6356,11 +6356,11 @@ class PseudoObjectExpr final
 return getSubExprsBuffer() + getNumSubExprs();
   }
 
-  llvm::iterator_range semantics() {
-return llvm::make_range(semantics_begin(), semantics_end());
+  ArrayRef semantics() {
+return ArrayRef(semantics_begin(), semantics_end());
   }
-  llvm::iterator_range semantics() const {
-return llvm::make_range(semantics_begin(), semantics_end());
+  ArrayRef semantics() const {
+return ArrayRef(semantics_begin(), semantics_end());
   }
 
   Expr *getSemanticExpr(unsigned index) {



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


[clang] 793c5b1 - Fix for release notes (follow-up to D149182/a8b0c6fa)

2023-05-08 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-05-09T00:40:11Z
New Revision: 793c5b12b9a70e363be40c5da2e26d7151fbbf41

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

LOG: Fix for release notes (follow-up to D149182/a8b0c6fa)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aa9a8a60e586..fcc6fb7df0c8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -111,12 +111,6 @@ Resolutions to C++ Defect Reports
 - Implemented `DR2397 `_ which allows ``auto`` 
specifier for pointers
   and reference to arrays.
 
-Warnings
-
-- Address a false positive in ``-Wpacked`` when applied to a non-pod type using
-  Clang ABI >= 15 (fixes 
`#62353`_,
-  fallout from the non-POD packing ABI fix in LLVM 15)
-
 C Language Changes
 --
 - Support for outputs from asm goto statements along indirect edges has been
@@ -267,6 +261,11 @@ Improvements to Clang's diagnostics
   (`#62247: `_).
 - Clang now diagnoses shadowing of lambda's template parameter by a capture.
   (`#61105: `_).
+- Address a false positive in ``-Wpacked`` when applied to a non-pod type using
+  Clang ABI >= 15.
+  (`#62353: `_,
+  fallout from the non-POD packing ABI fix in LLVM 15).
+
 
 Bug Fixes in This Version
 -



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


[clang] a8b0c6f - Remove -Wpacked false positive for non-pod types where the layout isn't directly changed

2023-05-08 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-05-09T00:13:45Z
New Revision: a8b0c6fa28acced71db33e80bd0b51d00422035b

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

LOG: Remove -Wpacked false positive for non-pod types where the layout isn't 
directly changed

The packed attribute can still be useful in this case if the struct is
then placed inside another packed struct - the non-pod element type's
packed attribute declares that it's OK to misalign this element inside
the packed structure. (otherwise the non-pod element is not packed/its
alignment is preserved, as per D117616/2771233)

Fixes PR62353

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/CodeGenCXX/warn-padded-packed.cpp
clang/test/Layout/aix-Wpacked-expecting-diagnostics.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4f8165bbc8ee5..aa9a8a60e586d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -111,6 +111,12 @@ Resolutions to C++ Defect Reports
 - Implemented `DR2397 `_ which allows ``auto`` 
specifier for pointers
   and reference to arrays.
 
+Warnings
+
+- Address a false positive in ``-Wpacked`` when applied to a non-pod type using
+  Clang ABI >= 15 (fixes 
`#62353`_,
+  fallout from the non-POD packing ABI fix in LLVM 15)
+
 C Language Changes
 --
 - Support for outputs from asm goto statements along indirect edges has been

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 641e9d62149e9..aca50912dceac 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2198,11 +2198,19 @@ void ItaniumRecordLayoutBuilder::FinishLayout(const 
NamedDecl *D) {
   << (InBits ? 1 : 0); // (byte|bit)
 }
 
+const auto *CXXRD = dyn_cast(RD);
+
 // Warn if we packed it unnecessarily, when the unpacked alignment is not
 // greater than the one after packing, the size in bits doesn't change and
 // the offset of each field is identical.
+// Unless the type is non-POD (for Clang ABI > 15), where the packed
+// attribute on such a type does allow the type to be packed into other
+// structures that use the packed attribute.
 if (Packed && UnpackedAlignment <= Alignment &&
-UnpackedSizeInBits == getSizeInBits() && !HasPackedField)
+UnpackedSizeInBits == getSizeInBits() && !HasPackedField &&
+(!CXXRD || CXXRD->isPOD() ||
+ Context.getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver15))
   Diag(D->getLocation(), diag::warn_unnecessary_packed)
   << Context.getTypeDeclType(RD);
   }

diff  --git a/clang/test/CodeGenCXX/warn-padded-packed.cpp 
b/clang/test/CodeGenCXX/warn-padded-packed.cpp
index cf4890e40005d..c51a6c9443f6e 100644
--- a/clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ b/clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify %s 
-emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
 
 struct S1 {
   char c;
@@ -154,7 +155,7 @@ struct S28 {
   char c1;
   short s1;
   char c2;
-  S28_non_pod p1; // expected-warning {{not packing field 'p1' as it is 
non-POD for the purposes of layout}}
+  S28_non_pod p1; // top-warning {{not packing field 'p1' as it is non-POD for 
the purposes of layout}}
 } __attribute__((packed));
 
 struct S29_non_pod_align_1 {
@@ -167,6 +168,16 @@ struct S29 {
 } __attribute__((packed)); // no warning
 static_assert(alignof(S29) == 1, "");
 
+struct S30 {
+protected:
+ short s;
+} __attribute__((packed)); // no warning
+struct S30_use { // abi15-warning {{packed attribute is unnecessary for 
'S30_use'}}
+  char c;
+  S30 u;
+} __attribute__((packed));
+static_assert(sizeof(S30_use) == 3, "");
+
 // The warnings are emitted when the layout of the structs is computed, so we 
have to use them.
 void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*,
S14*, S15*, S16*, S17*, S18*, S19*, S20*, S21*, S22*, S23*, S24*, S25*,

diff  --git a/clang/test/Layout/aix-Wpacked-expecting-diagnostics.cpp 
b/clang/test/Layout/aix-Wpacked-expecting-diagnostics.cpp
index 37982fcb74b96..1576b8561cb56 100644
--- a/clang/test/Layout/aix-Wpacked-expecting-diagnostics.cpp
+++ b/clang/test/Layout/aix-Wpacked-expecting-diagnostics.cpp
@@ -6,6 +6,8 @@
 

[clang] e5144d9 - Fix a few clang-tidy warnings (container empty checks, function decl/def param naming)

2023-04-04 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-04-05T01:06:41Z
New Revision: e5144d9d2dd26a67f576d2f5772b3cf0486245f4

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

LOG: Fix a few clang-tidy warnings (container empty checks, function decl/def 
param naming)

Added: 


Modified: 
clang/lib/Basic/Targets/X86.h
clang/lib/Sema/SemaChecking.cpp
llvm/lib/Target/X86/X86ExpandPseudo.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86LowerAMXType.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 9a563db496dcd..6cefda7fa49f6 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -206,9 +206,9 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
 return RegName.equals("esp") || RegName.equals("rsp");
   }
 
-  bool validateCpuSupports(StringRef Name) const override;
+  bool validateCpuSupports(StringRef FeatureStr) const override;
 
-  bool validateCpuIs(StringRef Name) const override;
+  bool validateCpuIs(StringRef FeatureStr) const override;
 
   bool validateCPUSpecificCPUDispatch(StringRef Name) const override;
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index af67552cba39b..16f29be4947fb 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4594,7 +4594,7 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo 
,
 std::string FeatureStr = OF.str();
 FeatureStr[0] = std::toupper(FeatureStr[0]);
 // Combine strings.
-FeatureStrs += FeatureStrs == "" ? "" : ", ";
+FeatureStrs += FeatureStrs.empty() ? "" : ", ";
 FeatureStrs += "'";
 FeatureStrs += FeatureStr;
 FeatureStrs += "'";
@@ -9506,13 +9506,13 @@ void CheckFormatHandler::HandlePosition(const char 
*startPos,
getSpecifierRange(startPos, posLen));
 }
 
-void
-CheckFormatHandler::HandleInvalidPosition(const char *startPos, unsigned 
posLen,
- analyze_format_string::PositionContext p) 
{
-  EmitFormatDiagnostic(S.PDiag(diag::warn_format_invalid_positional_specifier)
- << (unsigned) p,
-   getLocationOfByte(startPos), /*IsStringLocation*/true,
-   getSpecifierRange(startPos, posLen));
+void CheckFormatHandler::HandleInvalidPosition(
+const char *startSpecifier, unsigned specifierLen,
+analyze_format_string::PositionContext p) {
+  EmitFormatDiagnostic(
+  S.PDiag(diag::warn_format_invalid_positional_specifier) << (unsigned)p,
+  getLocationOfByte(startSpecifier), /*IsStringLocation*/ true,
+  getSpecifierRange(startSpecifier, specifierLen));
 }
 
 void CheckFormatHandler::HandleZeroPosition(const char *startPos,
@@ -9557,7 +9557,7 @@ void CheckFormatHandler::DoneProcessing() {
 
 void UncoveredArgHandler::Diagnose(Sema , bool IsFunctionCall,
const Expr *ArgExpr) {
-  assert(hasUncoveredArg() && DiagnosticExprs.size() > 0 &&
+  assert(hasUncoveredArg() && !DiagnosticExprs.empty() &&
  "Invalid state");
 
   if (!ArgExpr)
@@ -16620,14 +16620,13 @@ static bool findRetainCycleOwner(Sema , Expr *e, 
RetainCycleOwner ) {
 namespace {
 
   struct FindCaptureVisitor : EvaluatedExprVisitor {
-ASTContext 
 VarDecl *Variable;
 Expr *Capturer = nullptr;
 bool VarWillBeReased = false;
 
 FindCaptureVisitor(ASTContext , VarDecl *variable)
 : EvaluatedExprVisitor(Context),
-  Context(Context), Variable(variable) {}
+  Variable(variable) {}
 
 void VisitDeclRefExpr(DeclRefExpr *ref) {
   if (ref->getDecl() == Variable && !Capturer)

diff  --git a/llvm/lib/Target/X86/X86ExpandPseudo.cpp 
b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
index 21ad08fb5f0af..085fa9280b0ea 100644
--- a/llvm/lib/Target/X86/X86ExpandPseudo.cpp
+++ b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
@@ -49,7 +49,7 @@ class X86ExpandPseudo : public MachineFunctionPass {
   const X86MachineFunctionInfo *X86FI = nullptr;
   const X86FrameLowering *X86FL = nullptr;
 
-  bool runOnMachineFunction(MachineFunction ) override;
+  bool runOnMachineFunction(MachineFunction ) override;
 
   MachineFunctionProperties getRequiredProperties() const override {
 return MachineFunctionProperties().set(
@@ -77,7 +77,7 @@ class X86ExpandPseudo : public MachineFunctionPass {
   /// placed into separate block guarded by check for al register(for SystemV
   /// abi).
   void ExpandVastartSaveXmmRegs(
-  MachineBasicBlock *MBB,
+  MachineBasicBlock *EntryBlk,
   MachineBasicBlock::iterator VAStartPseudoInstr) const;
 };
 char X86ExpandPseudo::ID = 0;

diff  --git 

[clang] e9c9db3 - PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-04-03 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-04-04T04:45:32Z
New Revision: e9c9db34a9b04706937e9dd764d1d97ca84337b6

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

LOG: PR58819: Correct linkage and mangling of lambdas in inline static member 
initializers

https://llvm.org/pr58819 - clang is giving an externally visible lambda in a 
static data member internal linkage and the wrong linkage name.

Looks like we should be classifying this case the same as a non-static data 
member, so far as I can tell from the ABI docs and template examples (seems 
like the non-template inline-defined case should be the same).

This is a change in ABI, but not sure it qualifies as an ABI break as far as 
Apple and Sony are concerned - do you folks want this change? (it should fix 
the example in the bug where a static member in such a lambda ends up 
bifurcated, and I don't /think/ it'll break existing code since the symbol was 
previously internal anyway)

Looks like GCC has got this mangling slightly wrong (so we'd still end up with 
GCC+Clang bifurcation of the local static in the lambda, function address 
inequality, etc) in that they miss the variable name in the mangling in the 
non-template case. GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107741

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

Added: 


Modified: 
clang/lib/Sema/SemaLambda.cpp
clang/test/CodeGenCXX/mangle-lambdas.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c633a5080996b..a809968b66032 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -283,12 +283,14 @@ Sema::getCurrentMangleNumberContext(const DeclContext 
*DC) {
 Normal,
 DefaultArgument,
 DataMember,
-StaticDataMember,
 InlineVariable,
-VariableTemplate,
+TemplatedVariable,
 Concept
   } Kind = Normal;
 
+  bool IsInNonspecializedTemplate =
+  inTemplateInstantiation() || CurContext->isDependentContext();
+
   // Default arguments of member function parameters that appear in a class
   // definition, as well as the initializers of data members, receive special
   // treatment. Identify them.
@@ -299,15 +301,15 @@ Sema::getCurrentMangleNumberContext(const DeclContext 
*DC) {
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
+Kind = TemplatedVariable;
   else if (Var->getDescribedVarTemplate())
-Kind = VariableTemplate;
+Kind = TemplatedVariable;
   else if (auto *VTS = dyn_cast(Var)) {
 if (!VTS->isExplicitSpecialization())
-  Kind = VariableTemplate;
+  Kind = TemplatedVariable;
   }
 } else if (isa(ManglingContextDecl)) {
   Kind = DataMember;
@@ -319,12 +321,9 @@ Sema::getCurrentMangleNumberContext(const DeclContext *DC) 
{
   // Itanium ABI [5.1.7]:
   //   In the following contexts [...] the one-definition rule requires closure
   //   types in 
diff erent translation units to "correspond":
-  bool IsInNonspecializedTemplate =
-  inTemplateInstantiation() || CurContext->isDependentContext();
   switch (Kind) {
   case Normal: {
-//  -- the bodies of non-exported nonspecialized template functions
-//  -- the bodies of inline functions
+//  -- the bodies of inline or templated functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
@@ -341,21 +340,13 @@ Sema::getCurrentMangleNumberContext(const DeclContext 
*DC) {
 // however the ManglingContextDecl is important for the purposes of
 // re-forming the template argument list of the lambda for constraint
 // evaluation.
-  case StaticDataMember:
-//  -- the initializers of nonspecialized static members of template 
classes
-if (!IsInNonspecializedTemplate)
-  return std::make_tuple(nullptr, ManglingContextDecl);
-// Fall through to get the current context.
-[[fallthrough]];
-
   case DataMember:
-//  -- the in-class initializers of class members
+//  -- default member initializers
   case DefaultArgument:
 //  -- default arguments appearing in class definitions
   case InlineVariable:
-//  -- the initializers of inline variables
-  case VariableTemplate:
-//  -- the initializers of templated variables
+  case TemplatedVariable:
+//  -- the initializers of inline or 

[clang] 58ec6e0 - [NFC] [clang] Forward forwarding reference

2023-02-27 Thread David Blaikie via cfe-commits

Author: Chris Cotter
Date: 2023-02-28T01:27:21Z
New Revision: 58ec6e09abe8083709802833572bca931b2d15d9

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

LOG: [NFC] [clang] Forward forwarding reference

Update function bodies to forward forwarding references.
I spotted this while authoring a clang-tidy tool for CppCoreGuideline F.19

Reviewed By: dblaikie

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

Added: 
clang/unittests/AST/ASTExprTest.cpp

Modified: 
clang/include/clang/AST/IgnoreExpr.h
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/AST/IgnoreExpr.h 
b/clang/include/clang/AST/IgnoreExpr.h
index a7e9b07bef6c4..f8d2d6c7d00c0 100644
--- a/clang/include/clang/AST/IgnoreExpr.h
+++ b/clang/include/clang/AST/IgnoreExpr.h
@@ -23,7 +23,8 @@ namespace detail {
 inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
 template 
 Expr *IgnoreExprNodesImpl(Expr *E, FnTy &, FnTys &&... Fns) {
-  return IgnoreExprNodesImpl(Fn(E), std::forward(Fns)...);
+  return IgnoreExprNodesImpl(std::forward(Fn)(E),
+ std::forward(Fns)...);
 }
 } // namespace detail
 

diff  --git a/clang/unittests/AST/ASTExprTest.cpp 
b/clang/unittests/AST/ASTExprTest.cpp
new file mode 100644
index 0..ec75492ccff8e
--- /dev/null
+++ b/clang/unittests/AST/ASTExprTest.cpp
@@ -0,0 +1,58 @@
+//===- unittests/AST/ASTExprTest.cpp --- AST Expr tests 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file contains tests for AST Expr related methods.
+//
+//===--===//
+
+#include "ASTPrint.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/IgnoreExpr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+TEST(ASTExpr, IgnoreExprCallbackForwarded) {
+  constexpr char Code[] = "";
+  auto AST = tooling::buildASTFromCodeWithArgs(Code, /*Args=*/{"-std=c++20"});
+  ASTContext  = AST->getASTContext();
+
+  auto createIntLiteral = [&](uint32_t Value) -> IntegerLiteral * {
+const int numBits = 32;
+return IntegerLiteral::Create(Ctx, llvm::APInt(numBits, Value),
+  Ctx.UnsignedIntTy, {});
+  };
+
+  struct IgnoreParens {
+Expr *operator()(Expr *E) & { return nullptr; }
+Expr *operator()(Expr *E) && {
+  if (auto *PE = dyn_cast(E)) {
+return PE->getSubExpr();
+  }
+  return E;
+}
+  };
+
+  {
+auto *IntExpr = createIntLiteral(10);
+ParenExpr *PE =
+new (Ctx) ParenExpr(SourceLocation{}, SourceLocation{}, IntExpr);
+EXPECT_EQ(IntExpr, IgnoreExprNodes(PE, IgnoreParens{}));
+  }
+
+  {
+IgnoreParens CB{};
+auto *IntExpr = createIntLiteral(10);
+ParenExpr *PE =
+new (Ctx) ParenExpr(SourceLocation{}, SourceLocation{}, IntExpr);
+EXPECT_EQ(nullptr, IgnoreExprNodes(PE, CB));
+  }
+}

diff  --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index 13b945df3b589..b664b64070328 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_unittest(ASTTests
   ASTContextParentMapTest.cpp
+  ASTExprTest.cpp
   ASTImporterFixtures.cpp
   ASTImporterTest.cpp
   ASTImporterObjCTest.cpp



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


[clang] d8a1a55 - DebugInfo: Disable ctor homing for types with only deleted (non copy/move) ctors

2023-02-27 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-02-28T01:25:22Z
New Revision: d8a1a559f3009a31c517f864156db91d2ae3012c

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

LOG: DebugInfo: Disable ctor homing for types with only deleted (non copy/move) 
ctors

Such a type is never going to have a ctor home, and may be used for type
punning or other ways of creating objects.

May be a more generally acceptable solution in some cases compared to
attributing with [[clang::standalone_debug]].

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4dab595ada76b..126b239042ee1 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2489,9 +2489,18 @@ static bool canUseCtorHoming(const CXXRecordDecl *RD) {
   if (isClassOrMethodDLLImport(RD))
 return false;
 
-  return !RD->isLambda() && !RD->isAggregate() &&
- !RD->hasTrivialDefaultConstructor() &&
- !RD->hasConstexprNonCopyMoveConstructor();
+  if (RD->isLambda() || RD->isAggregate() ||
+  RD->hasTrivialDefaultConstructor() ||
+  RD->hasConstexprNonCopyMoveConstructor())
+return false;
+
+  for (const CXXConstructorDecl *Ctor : RD->ctors()) {
+if (Ctor->isCopyOrMoveConstructor())
+  continue;
+if (!Ctor->isDeleted())
+  return true;
+  }
+  return false;
 }
 
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index ac53cace075cd..18adfdeed0480 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -68,6 +68,21 @@ class K {
 };
 void f(K k) {}
 
+// CHECK-DAG: !DICompositeType({{.*}}name: 
"DeletedCtors",{{.*}}DIFlagTypePassBy
+struct NonTrivial {
+  NonTrivial();
+};
+struct DeletedCtors {
+  DeletedCtors() = delete;
+  DeletedCtors(const DeletedCtors &) = default;
+  void f1();
+  NonTrivial t;
+};
+
+const NonTrivial (const DeletedCtors ) {
+  return D.t;
+}
+
 // Test that we don't use constructor homing on lambdas.
 // CHECK-DAG: ![[L:.*]] ={{.*}}!DISubprogram({{.*}}name: "L"
 // CHECK-DAG: !DICompositeType({{.*}}scope: ![[L]], {{.*}}DIFlagTypePassByValue
@@ -89,3 +104,4 @@ VTableAndCtor::VTableAndCtor() {
 }
 
 // ITANIUM-DAG: !DICompositeType({{.*}}name: "VTableAndCtor", {{.*}}flags: 
DIFlagFwdDecl
+



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


Re: [clang] 931d04b - [ADT] Make StringRef::compare like std::string_view::compare

2023-01-16 Thread David Blaikie via cfe-commits
Nice!

On Sun, Jan 15, 2023 at 12:10 PM Benjamin Kramer via cfe-commits
 wrote:
>
>
> Author: Benjamin Kramer
> Date: 2023-01-15T20:59:21+01:00
> New Revision: 931d04be2fc8f3f0505b43e64297f75d526cb42a
>
> URL: 
> https://github.com/llvm/llvm-project/commit/931d04be2fc8f3f0505b43e64297f75d526cb42a
> DIFF: 
> https://github.com/llvm/llvm-project/commit/931d04be2fc8f3f0505b43e64297f75d526cb42a.diff
>
> LOG: [ADT] Make StringRef::compare like std::string_view::compare
>
> string_view has a slightly weaker contract, which only specifies whether
> the value is bigger or smaller than 0. Adapt users accordingly and just
> forward to the standard function (that also compiles down to memcmp)
>
> Added:
>
>
> Modified:
> clang/lib/AST/DeclarationName.cpp
> clang/lib/Analysis/PathDiagnostic.cpp
> clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
> clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
> lld/COFF/Writer.cpp
> llvm/include/llvm/ADT/SmallString.h
> llvm/include/llvm/ADT/StringRef.h
> llvm/include/llvm/ProfileData/SampleProf.h
> llvm/lib/Transforms/IPO/MergeFunctions.cpp
> llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
> llvm/unittests/ADT/SmallStringTest.cpp
> llvm/unittests/ADT/StringRefTest.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/AST/DeclarationName.cpp 
> b/clang/lib/AST/DeclarationName.cpp
> index b2232ddfced32..c1219041a466b 100644
> --- a/clang/lib/AST/DeclarationName.cpp
> +++ b/clang/lib/AST/DeclarationName.cpp
> @@ -72,15 +72,9 @@ int DeclarationName::compare(DeclarationName LHS, 
> DeclarationName RHS) {
>  }
>  unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
>  for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
> -  switch (LHSSelector.getNameForSlot(I).compare(
> -  RHSSelector.getNameForSlot(I))) {
> -  case -1:
> -return -1;
> -  case 1:
> -return 1;
> -  default:
> -break;
> -  }
> +  if (int Compare = LHSSelector.getNameForSlot(I).compare(
> +  RHSSelector.getNameForSlot(I)))
> +return Compare;
>  }
>
>  return compareInt(LN, RN);
>
> diff  --git a/clang/lib/Analysis/PathDiagnostic.cpp 
> b/clang/lib/Analysis/PathDiagnostic.cpp
> index 9e1215fe3d01d..ac1306fd80711 100644
> --- a/clang/lib/Analysis/PathDiagnostic.cpp
> +++ b/clang/lib/Analysis/PathDiagnostic.cpp
> @@ -342,7 +342,7 @@ static bool compareCrossTUSourceLocs(FullSourceLoc XL, 
> FullSourceLoc YL) {
>  return XFE && !YFE;
>int NameCmp = XFE->getName().compare(YFE->getName());
>if (NameCmp != 0)
> -return NameCmp == -1;
> +return NameCmp < 0;
>// Last resort: Compare raw file IDs that are possibly expansions.
>return XL.getFileID() < YL.getFileID();
>  }
>
> diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
> b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
> index b38d18d3691d9..12b948a65261f 100644
> --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
> +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
> @@ -2146,7 +2146,7 @@ void CStringChecker::evalStrcmpCommon(CheckerContext 
> , const CallExpr *CE,
>  DefinedSVal zeroVal = svalBuilder.makeIntVal(0, CE->getType());
>  // Constrain strcmp's result range based on the result of StringRef's
>  // comparison methods.
> -BinaryOperatorKind op = (compareRes == 1) ? BO_GT : BO_LT;
> +BinaryOperatorKind op = (compareRes > 0) ? BO_GT : BO_LT;
>  SVal compareWithZero =
>svalBuilder.evalBinOp(state, op, resultVal, zeroVal,
>svalBuilder.getConditionType());
>
> diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
> b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
> index 1fb4c83052c4a..1daa58f20fd5b 100644
> --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
> +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
> @@ -1272,8 +1272,8 @@ linkAndWrapDeviceFiles(SmallVectorImpl 
> ,
>  // We sort the entries before bundling so they appear in a deterministic
>  // order in the final binary.
>  llvm::sort(Input, [](OffloadingImage , OffloadingImage ) {
> -  return A.StringData["triple"].compare(B.StringData["triple"]) == 1 ||
> - A.StringData["arch"].compare(B.StringData["arch"]) == 1 ||
> +  return A.StringData["triple"] > B.StringData["triple"] ||
> + A.StringData["arch"] > B.StringData["arch"] ||
>   A.TheOffloadKind < B.TheOffloadKind;
>  });
>  auto BundledImagesOrErr = bundleLinkedOutput(Input, Args, Kind);
>
> diff  --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
> index 09cca5667a470..b02ad01bdef74 100644
> --- a/lld/COFF/Writer.cpp
> +++ b/lld/COFF/Writer.cpp
> @@ -188,7 +188,7 @@ class PartialSectionKey {
>
>bool operator<(const PartialSectionKey ) const {
> 

[clang] 7a91e00 - Ensure clang test doesn't write out to the source directory

2022-12-16 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-12-16T23:39:28Z
New Revision: 7a91e00d915c638bfb4864826bc445211e0e41d7

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

LOG: Ensure clang test doesn't write out to the source directory

Added: 


Modified: 
clang/test/Misc/warn-not-error-Xfoo.c

Removed: 




diff  --git a/clang/test/Misc/warn-not-error-Xfoo.c 
b/clang/test/Misc/warn-not-error-Xfoo.c
index 49a594d4c2f29..54d97c618cddf 100644
--- a/clang/test/Misc/warn-not-error-Xfoo.c
+++ b/clang/test/Misc/warn-not-error-Xfoo.c
@@ -1,5 +1,5 @@
-// RUN: %clang -c -Xfoo %s 2>&1 | FileCheck 
--check-prefix=CHECK_STANDALONE_FOO %s
-// RUN: %clang -c -Xfoo=bar %s 2>&1 | FileCheck 
--check-prefix=CHECK_JOINED_FOO %s
+// RUN: %clang -c %s -o /dev/null -Xfoo < %s 2>&1 | FileCheck 
--check-prefix=CHECK_STANDALONE_FOO %s
+// RUN: %clang -c %s -o /dev/null -Xfoo=bar 2>&1 | FileCheck 
--check-prefix=CHECK_JOINED_FOO %s
 
 // This test ensures that we only warn on -X and -X
 // in case it is used downstream. If we error, we can't ignore it and some



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


[clang] be931f8 - clang/test/CodeCompletion: Simplify/fix some `touch` commands

2022-12-16 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-12-16T23:18:11Z
New Revision: be931f89451b650e081daf875213c19f658caf25

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

LOG: clang/test/CodeCompletion: Simplify/fix some `touch` commands

These were inconsistent (one `touch` line listed all the files in a
single `touch` invocation, but the other listed them as separate
commands with `&&`) and incorrect (one `&&` was missing, causing `touch`
to try to touch a file called `touch` in the cwd, which might not be
accessible/relevant to test execution)

So make them consistent and simpler by using the "list all the files on
a line in a single `touch` invocation" reducing the visual
noise/clutter/etc.

Added: 


Modified: 
clang/test/CodeCompletion/included-files.cpp

Removed: 




diff  --git a/clang/test/CodeCompletion/included-files.cpp 
b/clang/test/CodeCompletion/included-files.cpp
index d8a4c3872a78c..9ad3e28b21231 100644
--- a/clang/test/CodeCompletion/included-files.cpp
+++ b/clang/test/CodeCompletion/included-files.cpp
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t && mkdir %t && cp %s %t/main.cc && mkdir %t/a && mkdir 
%t/QtCore && mkdir %t/Headers %t/Some.framework %t/Some.framework/Headers
-// RUN: touch %t/foo.h && touch %t/foo.hxx touch %t/foo.cc && touch 
%t/a/foosys %t/a/foosys.h && touch %t/QtCore/foosys %t/QtCore/foo.h
+// RUN: touch %t/foo.h %t/foo.hxx %t/foo.cc %t/a/foosys %t/a/foosys.h 
%t/QtCore/foosys %t/QtCore/foo.h
 // RUN: touch %t/Headers/foosys %t/Headers/foo.h 
%t/Some.framework/Headers/foosys %t/Some.framework/Headers/foo.h
 
 // Quoted string shows header-ish files from CWD, and all from system.



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


[clang] c73876d - Reapply "DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions""

2022-12-12 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-12-12T22:36:23Z
New Revision: c73876db4f2dfd2c38d5720f62509e57f23b2059

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

LOG: Reapply "DebugInfo: Add/support new DW_LANG codes for recent C and C++ 
versions""

This may be a breaking change for consumers if they're trying to detect
if code is C or C++, since it'll start using new codes that they may not
be ready to recognize, in which case they may fall back to non-C
handling.

This caused regressions due to PS4 having a different default for C
language version than other targets. Those tests were adapted to be
relaxed about which C version is used.

This reapplies commit 3c312e48f325c1b1ee11404ee6cfa08ee00037b0
Which was reverted by commit 6ab6085c77ef9bcdabf842342f63fba4291791a4.

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

Added: 
clang/test/CodeGen/debug-info-programming-language.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-preprocessed-file.i
clang/test/CodeGenCXX/debug-info-programming-language.cpp
clang/test/PCH/debug-info-pch-container-path.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 2a67f58d22ced..3e370fb17b1d8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -526,7 +526,8 @@ void CGDebugInfo::CreateCompileUnit() {
 
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
-  std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
+  auto  = CGM.getCodeGenOpts();
+  std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
 
@@ -562,11 +563,11 @@ void CGDebugInfo::CreateCompileUnit() {
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
-CGM.getCodeGenOpts().DwarfVersion >= 5))
+else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+else if (LO.CPlusPlus14)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
-CGM.getCodeGenOpts().DwarfVersion >= 5))
+else if (LO.CPlusPlus11)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
@@ -577,6 +578,8 @@ void CGDebugInfo::CreateCompileUnit() {
 LangTag = llvm::dwarf::DW_LANG_OpenCL;
   } else if (LO.RenderScript) {
 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
+  } else if (LO.C11) {
+LangTag = llvm::dwarf::DW_LANG_C11;
   } else if (LO.C99) {
 LangTag = llvm::dwarf::DW_LANG_C99;
   } else {

diff  --git a/clang/test/CodeGen/debug-info-preprocessed-file.i 
b/clang/test/CodeGen/debug-info-preprocessed-file.i
index d231b45d67c2e..23fd26525e3bf 100644
--- a/clang/test/CodeGen/debug-info-preprocessed-file.i
+++ b/clang/test/CodeGen/debug-info-preprocessed-file.i
@@ -7,5 +7,5 @@
 # 1 "preprocessed-input.c" 2
 
 // RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s
-// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] 
+// CHECK: !DICompileUnit(language: DW_LANG_C{{.*}}, file: ![[FILE:[0-9]+]]
 // CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c"

diff  --git a/clang/test/CodeGen/debug-info-programming-language.c 
b/clang/test/CodeGen/debug-info-programming-language.c
new file mode 100644
index 0..f81bab610d51e
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-programming-language.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x c -std=c11 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-C11 %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x c -std=c17 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-C17 %s
+
+// CHECK-C11: !DICompileUnit(language: DW_LANG_C11
+// Update this check once support for DW_LANG_C17 is broadly supported/known in
+// consumers. Maybe we'll skip this and go to the DWARFv6 language+version
+// encoding that avoids the risk of regression when describing a language
+// version newer than what the consumer is aware of.
+// CHECK-C17: !DICompileUnit(language: DW_LANG_C11
+
+void f1(void) { }

diff  --git a/clang/test/CodeGenCXX/debug-info-programming-language.cpp 
b/clang/test/CodeGenCXX/debug-info-programming-language.cpp
index 06873a7b5752a..69532661947a8 100644
--- a/clang/test/CodeGenCXX/debug-info-programming-language.cpp

[clang] 6ab6085 - Revert "DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions"

2022-12-06 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-12-06T22:52:47Z
New Revision: 6ab6085c77ef9bcdabf842342f63fba4291791a4

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

LOG: Revert "DebugInfo: Add/support new DW_LANG codes for recent C and C++ 
versions"

Some buildbots are failing in Clang and LLDB tests. (I guess the LLDB
failure is due to the explicit C language tests in DwarfUnit.cpp that
need to be updated - not sure what the Clang failures are about, they
seem to be still emitting C99 when we're expecting C11 and I checked
those tests pass... maybe systems with a different C language version
default?)

This reverts commit 3c312e48f325c1b1ee11404ee6cfa08ee00037b0.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-preprocessed-file.i
clang/test/CodeGenCXX/debug-info-programming-language.cpp
clang/test/PCH/debug-info-pch-container-path.c

Removed: 
clang/test/CodeGen/debug-info-programming-language.c



diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3e370fb17b1d8..2a67f58d22ced 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -526,8 +526,7 @@ void CGDebugInfo::CreateCompileUnit() {
 
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
-  auto  = CGM.getCodeGenOpts();
-  std::string MainFileName = CGO.MainFileName;
+  std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
 
@@ -563,11 +562,11 @@ void CGDebugInfo::CreateCompileUnit() {
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
-else if (LO.CPlusPlus14)
+else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+CGM.getCodeGenOpts().DwarfVersion >= 5))
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
+else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+CGM.getCodeGenOpts().DwarfVersion >= 5))
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
@@ -578,8 +577,6 @@ void CGDebugInfo::CreateCompileUnit() {
 LangTag = llvm::dwarf::DW_LANG_OpenCL;
   } else if (LO.RenderScript) {
 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
-  } else if (LO.C11) {
-LangTag = llvm::dwarf::DW_LANG_C11;
   } else if (LO.C99) {
 LangTag = llvm::dwarf::DW_LANG_C99;
   } else {

diff  --git a/clang/test/CodeGen/debug-info-preprocessed-file.i 
b/clang/test/CodeGen/debug-info-preprocessed-file.i
index d58cfe0124949..d231b45d67c2e 100644
--- a/clang/test/CodeGen/debug-info-preprocessed-file.i
+++ b/clang/test/CodeGen/debug-info-preprocessed-file.i
@@ -7,5 +7,5 @@
 # 1 "preprocessed-input.c" 2
 
 // RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s
-// CHECK: !DICompileUnit(language: DW_LANG_C11, file: ![[FILE:[0-9]+]]
+// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] 
 // CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c"

diff  --git a/clang/test/CodeGen/debug-info-programming-language.c 
b/clang/test/CodeGen/debug-info-programming-language.c
deleted file mode 100644
index f81bab610d51e..0
--- a/clang/test/CodeGen/debug-info-programming-language.c
+++ /dev/null
@@ -1,15 +0,0 @@
-// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
-// RUN:   -x c -std=c11 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN:   | FileCheck --check-prefix=CHECK-C11 %s
-// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
-// RUN:   -x c -std=c17 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN:   | FileCheck --check-prefix=CHECK-C17 %s
-
-// CHECK-C11: !DICompileUnit(language: DW_LANG_C11
-// Update this check once support for DW_LANG_C17 is broadly supported/known in
-// consumers. Maybe we'll skip this and go to the DWARFv6 language+version
-// encoding that avoids the risk of regression when describing a language
-// version newer than what the consumer is aware of.
-// CHECK-C17: !DICompileUnit(language: DW_LANG_C11
-
-void f1(void) { }

diff  --git a/clang/test/CodeGenCXX/debug-info-programming-language.cpp 
b/clang/test/CodeGenCXX/debug-info-programming-language.cpp
index 69532661947a8..06873a7b5752a 100644
--- a/clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ b/clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -4,12 +4,6 @@
 // RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
 

[clang] 3c312e4 - DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions

2022-12-06 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-12-06T21:11:08Z
New Revision: 3c312e48f325c1b1ee11404ee6cfa08ee00037b0

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

LOG: DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions

This may be a breaking change for consumers if they're trying to detect
if code is C or C++, since it'll start using new codes that they may not
be ready to recognize, in which case they may fall back to non-C
handling.

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

Added: 
clang/test/CodeGen/debug-info-programming-language.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-preprocessed-file.i
clang/test/CodeGenCXX/debug-info-programming-language.cpp
clang/test/PCH/debug-info-pch-container-path.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 2a67f58d22ced..3e370fb17b1d8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -526,7 +526,8 @@ void CGDebugInfo::CreateCompileUnit() {
 
   // Get absolute path name.
   SourceManager  = CGM.getContext().getSourceManager();
-  std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
+  auto  = CGM.getCodeGenOpts();
+  std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
 
@@ -562,11 +563,11 @@ void CGDebugInfo::CreateCompileUnit() {
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
-CGM.getCodeGenOpts().DwarfVersion >= 5))
+else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+else if (LO.CPlusPlus14)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
-CGM.getCodeGenOpts().DwarfVersion >= 5))
+else if (LO.CPlusPlus11)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
@@ -577,6 +578,8 @@ void CGDebugInfo::CreateCompileUnit() {
 LangTag = llvm::dwarf::DW_LANG_OpenCL;
   } else if (LO.RenderScript) {
 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
+  } else if (LO.C11) {
+LangTag = llvm::dwarf::DW_LANG_C11;
   } else if (LO.C99) {
 LangTag = llvm::dwarf::DW_LANG_C99;
   } else {

diff  --git a/clang/test/CodeGen/debug-info-preprocessed-file.i 
b/clang/test/CodeGen/debug-info-preprocessed-file.i
index d231b45d67c2e..d58cfe0124949 100644
--- a/clang/test/CodeGen/debug-info-preprocessed-file.i
+++ b/clang/test/CodeGen/debug-info-preprocessed-file.i
@@ -7,5 +7,5 @@
 # 1 "preprocessed-input.c" 2
 
 // RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s
-// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] 
+// CHECK: !DICompileUnit(language: DW_LANG_C11, file: ![[FILE:[0-9]+]]
 // CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c"

diff  --git a/clang/test/CodeGen/debug-info-programming-language.c 
b/clang/test/CodeGen/debug-info-programming-language.c
new file mode 100644
index 0..f81bab610d51e
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-programming-language.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x c -std=c11 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-C11 %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x c -std=c17 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-C17 %s
+
+// CHECK-C11: !DICompileUnit(language: DW_LANG_C11
+// Update this check once support for DW_LANG_C17 is broadly supported/known in
+// consumers. Maybe we'll skip this and go to the DWARFv6 language+version
+// encoding that avoids the risk of regression when describing a language
+// version newer than what the consumer is aware of.
+// CHECK-C17: !DICompileUnit(language: DW_LANG_C11
+
+void f1(void) { }

diff  --git a/clang/test/CodeGenCXX/debug-info-programming-language.cpp 
b/clang/test/CodeGenCXX/debug-info-programming-language.cpp
index 06873a7b5752a..69532661947a8 100644
--- a/clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ b/clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -4,6 +4,12 @@
 // RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
 // RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 

Re: [clang] a446827 - [NFC][Clang][Driver][AMDGPU] Avoid temporary copies of std::string by using Twine and StringRef

2022-12-05 Thread David Blaikie via cfe-commits
On Mon, Dec 5, 2022 at 5:27 AM Juan Manuel MARTINEZ CAAMAÑO via
cfe-commits  wrote:
>
>
> Author: Juan Manuel MARTINEZ CAAMAÑO
> Date: 2022-12-05T07:27:10-06:00
> New Revision: a446827249bdeb2f27e55a9f4942bd7425ecb0ff
>
> URL: 
> https://github.com/llvm/llvm-project/commit/a446827249bdeb2f27e55a9f4942bd7425ecb0ff
> DIFF: 
> https://github.com/llvm/llvm-project/commit/a446827249bdeb2f27e55a9f4942bd7425ecb0ff.diff
>
> LOG: [NFC][Clang][Driver][AMDGPU] Avoid temporary copies of std::string by 
> using Twine and StringRef
>
> Reviewed By: tra
>
> Differential Revision: https://reviews.llvm.org/D139023
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/AMDGPU.cpp
> clang/lib/Driver/ToolChains/HIPAMD.cpp
> clang/lib/Driver/ToolChains/ROCm.h
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
> b/clang/lib/Driver/ToolChains/AMDGPU.cpp
> index f3ac7d2ab735..ff77969bbec5 100644
> --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
> +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
> @@ -854,7 +854,7 @@ void ROCMToolChain::addClangTargetOptions(
>const StringRef GpuArch = getGPUArch(DriverArgs);
>auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
>const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
> -  std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
> +  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
>auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
>getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
>if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
> @@ -946,7 +946,7 @@ ROCMToolChain::getCommonDeviceLibNames(const 
> llvm::opt::ArgList ,
>auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
>const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
>
> -  std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
> +  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
>auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
>getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
>if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
>
> diff  --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
> b/clang/lib/Driver/ToolChains/HIPAMD.cpp
> index c64421d259ce..a555fe5830e0 100644
> --- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
> +++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
> @@ -237,7 +237,7 @@ void HIPAMDToolChain::addClangTargetOptions(
>DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);
>if (!MaxThreadsPerBlock.empty()) {
>  std::string ArgStr =
> -std::string("--gpu-max-threads-per-block=") + 
> MaxThreadsPerBlock.str();
> +(Twine("--gpu-max-threads-per-block=") + MaxThreadsPerBlock).str();
>  CC1Args.push_back(DriverArgs.MakeArgStringRef(ArgStr));
>}
>
> @@ -344,7 +344,7 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList 
> ) const {
>ArgStringList LibraryPaths;
>
>// Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
> -  for (auto Path : RocmInstallation.getRocmDeviceLibPathArg())
> +  for (StringRef Path : RocmInstallation.getRocmDeviceLibPathArg())
>  LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
>
>addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH");
> @@ -354,7 +354,7 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList 
> ) const {
>if (!BCLibArgs.empty()) {
>  llvm::for_each(BCLibArgs, [&](StringRef BCName) {
>StringRef FullName;
> -  for (std::string LibraryPath : LibraryPaths) {
> +  for (StringRef LibraryPath : LibraryPaths) {
>  SmallString<128> Path(LibraryPath);
>  llvm::sys::path::append(Path, BCName);
>  FullName = Path;
> @@ -387,15 +387,15 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList 
> ) const {
>  getDriver().Diag(DiagID);
>  return {};
>} else
> -BCLibs.push_back({AsanRTL.str(), /*ShouldInternalize=*/false});
> +BCLibs.emplace_back(AsanRTL, /*ShouldInternalize=*/false);
>  }
>
>  // Add the HIP specific bitcode library.
>  BCLibs.push_back(RocmInstallation.getHIPPath());
>
>  // Add common device libraries like ocml etc.
> -for (auto N : getCommonDeviceLibNames(DriverArgs, GpuArch.str()))
> -  BCLibs.push_back(StringRef(N));
> +for (StringRef N : getCommonDeviceLibNames(DriverArgs, GpuArch.str()))
> +  BCLibs.emplace_back(N);
>
>  // Add instrument lib.
>  auto InstLib =
>
> diff  --git a/clang/lib/Driver/ToolChains/ROCm.h 
> b/clang/lib/Driver/ToolChains/ROCm.h
> index b16deecdebec..600c8b39f4b3 100644
> --- a/clang/lib/Driver/ToolChains/ROCm.h
> +++ b/clang/lib/Driver/ToolChains/ROCm.h
> @@ -252,8 +252,11 @@ class RocmInstallationDetector {
>}
>
>/// Get libdevice file for given architecture
> -  std::string 

[clang] 2cea4c2 - Do not suggest taking the address of a const pointer to get void*

2022-11-23 Thread David Blaikie via cfe-commits

Author: Alexey Kreshchuk
Date: 2022-11-23T18:43:06Z
New Revision: 2cea4c239570c37f46ad0003b3d41d9473aca60f

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

LOG: Do not suggest taking the address of a const pointer to get void*

It's more likely the user needs a const cast, but probably not sure
enough that we should suggest that either - so err on the side of
caution and offer no suggestion.

Fixes pr58958

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/Sema/SemaFixItUtils.cpp
clang/test/FixIt/fixit-function-call.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaFixItUtils.cpp 
b/clang/lib/Sema/SemaFixItUtils.cpp
index 2910a56f866bb..2c85a53194301 100644
--- a/clang/lib/Sema/SemaFixItUtils.cpp
+++ b/clang/lib/Sema/SemaFixItUtils.cpp
@@ -124,7 +124,7 @@ bool ConversionFixItGenerator::tryToFixConversion(const 
Expr *FullExpr,
 
   // Check if the pointer to the argument needs to be passed:
   //   (type -> type *) or (type & -> type *).
-  if (isa(ToQTy)) {
+  if (const auto *ToPtrTy = dyn_cast(ToQTy)) {
 bool CanConvert = false;
 OverloadFixItKind FixKind = OFIK_TakeAddress;
 
@@ -132,6 +132,10 @@ bool ConversionFixItGenerator::tryToFixConversion(const 
Expr *FullExpr,
 if (!Expr->isLValue() || Expr->getObjectKind() != OK_Ordinary)
   return false;
 
+// Do no take address of const pointer to get void*
+if (isa(FromQTy) && ToPtrTy->isVoidPointerType())
+  return false;
+
 CanConvert = CompareTypes(S.Context.getPointerType(FromQTy), ToQTy, S,
   Begin, VK_PRValue);
 if (CanConvert) {

diff  --git a/clang/test/FixIt/fixit-function-call.cpp 
b/clang/test/FixIt/fixit-function-call.cpp
index 273e4a41ec8dd..88f636ea5859d 100644
--- a/clang/test/FixIt/fixit-function-call.cpp
+++ b/clang/test/FixIt/fixit-function-call.cpp
@@ -115,4 +115,25 @@ void dbcaller(A *ptra, B *ptrb, C , B ) {
   u(c);
 }
 
+void accept_void(void*);
+
+void issue58958(const char* a, volatile char * v, const volatile char * cv) {
+// CHECK: no matching function for call to 'accept_void'
+// CHECK-NOT: take the address of the argument with &
+accept_void(a);
+// CHECK: no matching function for call to 'accept_void'
+// CHECK-NOT: take the address of the argument with &
+accept_void(v);
+// CHECK: no matching function for call to 'accept_void'
+// CHECK-NOT: take the address of the argument with &
+accept_void(cv);
+char b;
+// CHECK: no matching function for call to 'accept_void'
+// CHECK: take the address of the argument with &
+accept_void(b);
+// CHECK-NOT: no matching function for call to 'accept_void'
+// CHECK-NOT: take the address of the argument with &
+accept_void();
+}
+
 // CHECK: errors generated



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


[clang] 9df8ba6 - pr59000: Clarify packed-non-pod warning that it's pod-for-the-purposes-of-layout

2022-11-21 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-11-22T00:02:09Z
New Revision: 9df8ba631d4612eb8f930c9fe7c6cf39e5deb3af

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

LOG: pr59000: Clarify packed-non-pod warning that it's 
pod-for-the-purposes-of-layout

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/test/CodeGenCXX/warn-padded-packed.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 15bd9d7c0e49a..6a2d15ef77c6a 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -960,8 +960,11 @@ def warn_padded_struct_size : Warning<
   InGroup, DefaultIgnore;
 def warn_unnecessary_packed : Warning<
   "packed attribute is unnecessary for %0">, InGroup, DefaultIgnore;
-def warn_unpacked_field : Warning<
-  "not packing field %0 as it is non-POD">, InGroup, 
DefaultIgnore;
+def warn_unpacked_field
+: Warning<
+  "not packing field %0 as it is non-POD for the purposes of layout">,
+  InGroup,
+  DefaultIgnore;
 
 // -Wunaligned-access
 def warn_unaligned_access : Warning<

diff  --git a/clang/test/CodeGenCXX/warn-padded-packed.cpp 
b/clang/test/CodeGenCXX/warn-padded-packed.cpp
index 60cf5e4a691f7..cf4890e40005d 100644
--- a/clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ b/clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -154,7 +154,7 @@ struct S28 {
   char c1;
   short s1;
   char c2;
-  S28_non_pod p1; // expected-warning {{not packing field 'p1' as it is 
non-POD}}
+  S28_non_pod p1; // expected-warning {{not packing field 'p1' as it is 
non-POD for the purposes of layout}}
 } __attribute__((packed));
 
 struct S29_non_pod_align_1 {



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


[clang] a72d8d7 - Update lambda mangling test to C++17

2022-11-17 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-11-18T00:24:40Z
New Revision: a72d8d704178118b254d9ff84a78afb18813b888

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

LOG: Update lambda mangling test to C++17

add some side effects so some (I guess guaranteed?) constant folding
doesn't happen, keeping the test testing the things it was testing..

The test passes with 14, 17, and 20 - so let's just leave the version
off so it might be able to be updated/used in C++20 when the default
changes to C++20 in the future.

Added: 


Modified: 
clang/test/CodeGenCXX/mangle-lambdas.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/mangle-lambdas.cpp 
b/clang/test/CodeGenCXX/mangle-lambdas.cpp
index 93362876e1742..c10f7add32933 100644
--- a/clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ b/clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -1,9 +1,11 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o 
- %s -w | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s -w | 
FileCheck %s
+
+void side_effect();
 
 // CHECK-LABEL: define linkonce_odr void @_Z11inline_funci
 inline void inline_func(int n) {
   // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE_clEv
-  int i = []{ return 1; }();
+  int i = []{ return side_effect(), 1; }();
 
   // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE0_clEv
   int j = [=] { return n + i; }();
@@ -14,7 +16,7 @@ inline void inline_func(int n) {
   // CHECK: call noundef i32 @_ZZ11inline_funciENKUliE_clEi
   int l = [=] (int x) -> int { return x + i; }(n);
 
-  int inner(int i = []{ return 17; }());
+  int inner(int i = []{ return side_effect(), 17; }());
   // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE2_clEv
   // CHECK-NEXT: call noundef i32 @_Z5inneri
   inner();
@@ -48,14 +50,14 @@ int *use_var_template = var_template();
 void use_var_template_substitution(decltype(var_template), 
decltype(var_template)) {}
 
 struct S {
-  void f(int = []{return 1;}()
- + []{return 2;}(),
- int = []{return 3;}());
+  void f(int = []{return side_effect(), 1;}()
+ + []{return side_effect(), 2;}(),
+ int = []{return side_effect(), 3;}());
   void g(int, int);
 };
 
-void S::g(int i = []{return 1;}(),
-  int j = []{return 2; }()) {}
+void S::g(int i = []{return side_effect(), 1;}(),
+  int j = []{return side_effect(), 2; }()) {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6test_S1S
 void test_S(S s) {
@@ -128,16 +130,16 @@ struct StaticMembers {
 template int accept_lambda(T);
 
 template
-T StaticMembers::x = []{return 1;}() + []{return 2;}();
+T StaticMembers::x = []{return side_effect(), 1;}() + []{return 
side_effect(), 2;}();
 
 template
-T StaticMembers::y = []{return 3;}();
+T StaticMembers::y = []{return side_effect(), 3;}();
 
 template
-T StaticMembers::z = accept_lambda([]{return 4;});
+T StaticMembers::z = accept_lambda([]{return side_effect(), 4;});
 
 template
-int (*StaticMembers::f)() = []{return 5;};
+int (*StaticMembers::f)() = (side_effect(), []{return side_effect(), 5;});
 
 // CHECK-LABEL: define internal void @__cxx_global_var_init
 // CHECK: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
@@ -169,7 +171,7 @@ template int (*StaticMembers::f)();
 // CHECK: call noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"
 // CHECK-LABEL: define internal noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"
 // CHECK: ret i32 42
-template<> double StaticMembers::z = []{return 42; }();
+template<> double StaticMembers::z = []{return side_effect(), 42; }();
 
 template
 void func_template(T = []{ return T(); }());
@@ -212,7 +214,7 @@ int k = testVarargsLambdaNumbering();
 
 
 template
-void ft1(int = [](int p = [] { return 42; } ()) {
+void ft1(int = [](int p = [] { return side_effect(), 42; } ()) {
  return p;
} ());
 void test_ft1() {
@@ -225,7 +227,7 @@ void test_ft1() {
 
 struct c1 {
   template
-  void mft1(int = [](int p = [] { return 42; } ()) {
+  void mft1(int = [](int p = [] { return side_effect(), 42; } ()) {
 return p;
   } ());
 };
@@ -239,10 +241,10 @@ void test_c1_mft1() {
 
 template
 struct ct1 {
-  void mf1(int = [](int p = [] { return 42; } ()) {
+  void mf1(int = [](int p = [] { return side_effect(), 42; } ()) {
return p;
  } ());
-  friend void ff(ct1, int = [](int p = [] { return 0; }()) { return p; }()) {}
+  friend void ff(ct1, int = [](int p = [] { return side_effect(), 0; }()) { 
return p; }()) {}
 };
 void test_ct1_mft1() {
   // CHECK: call noundef i32 @_ZZZN3ct1IiE3mf1EiEd_NKUliE_clEiEd_NKUlvE_clEv
@@ -259,7 +261,7 @@ void test_ct1_mft1() {
 
 template
 void ft2() {
-  [](int p = [] { return 42; } ()) { return p; } ();
+  [](int p = 

Re: [clang] a88ebd4 - Revert "[clang] Instantiate NTTPs and template default arguments with sugar"

2022-10-31 Thread David Blaikie via cfe-commits
Please include some details about the reason for a revert in the
revert commit message in addition to the precanned revision/subject
quoting

On Wed, Oct 26, 2022 at 1:16 AM Matheus Izvekov via cfe-commits
 wrote:
>
>
> Author: Matheus Izvekov
> Date: 2022-10-26T10:14:27+02:00
> New Revision: a88ebd405da67b4cebf094c5a56f9aed97875423
>
> URL: 
> https://github.com/llvm/llvm-project/commit/a88ebd405da67b4cebf094c5a56f9aed97875423
> DIFF: 
> https://github.com/llvm/llvm-project/commit/a88ebd405da67b4cebf094c5a56f9aed97875423.diff
>
> LOG: Revert "[clang] Instantiate NTTPs and template default arguments with 
> sugar"
>
> This reverts commit 2560c1266993af6e6c15900ce673c6db23132f8b.
>
> Added:
>
>
> Modified:
> clang/include/clang/Sema/Sema.h
> clang/lib/Sema/SemaTemplate.cpp
> clang/lib/Sema/SemaTemplateDeduction.cpp
> clang/test/AST/ast-dump-template-decls.cpp
> clang/test/CXX/drs/dr3xx.cpp
> clang/test/CXX/expr/expr.const/p3-0x.cpp
> clang/test/Misc/diag-template-diffing.cpp
> clang/test/SemaTemplate/instantiation-default-1.cpp
> clang/test/SemaTemplate/make_integer_seq.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/Sema/Sema.h 
> b/clang/include/clang/Sema/Sema.h
> index 37ad78f3d7969..d0757f874303f 100644
> --- a/clang/include/clang/Sema/Sema.h
> +++ b/clang/include/clang/Sema/Sema.h
> @@ -8199,11 +8199,14 @@ class Sema final {
>  SourceLocation TemplateLoc,
>  Declarator );
>
> -  TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(
> -  TemplateDecl *Template, SourceLocation TemplateLoc,
> -  SourceLocation RAngleLoc, Decl *Param,
> -  ArrayRef SugaredConverted,
> -  ArrayRef CanonicalConverted, bool );
> +  TemplateArgumentLoc
> +  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
> +  SourceLocation TemplateLoc,
> +  SourceLocation RAngleLoc,
> +  Decl *Param,
> +  SmallVectorImpl
> +,
> +  bool );
>
>/// Specifies the context in which a particular template
>/// argument is being checked.
>
> diff  --git a/clang/lib/Sema/SemaTemplate.cpp 
> b/clang/lib/Sema/SemaTemplate.cpp
> index 37eaa2a5795aa..73c681035b161 100644
> --- a/clang/lib/Sema/SemaTemplate.cpp
> +++ b/clang/lib/Sema/SemaTemplate.cpp
> @@ -5261,25 +5261,27 @@ bool Sema::CheckTemplateTypeArgument(
>  /// \param Converted the list of template arguments provided for template
>  /// parameters that precede \p Param in the template parameter list.
>  /// \returns the substituted template argument, or NULL if an error occurred.
> -static TypeSourceInfo *SubstDefaultTemplateArgument(
> -Sema , TemplateDecl *Template, SourceLocation TemplateLoc,
> -SourceLocation RAngleLoc, TemplateTypeParmDecl *Param,
> -ArrayRef SugaredConverted,
> -ArrayRef CanonicalConverted) {
> +static TypeSourceInfo *
> +SubstDefaultTemplateArgument(Sema ,
> + TemplateDecl *Template,
> + SourceLocation TemplateLoc,
> + SourceLocation RAngleLoc,
> + TemplateTypeParmDecl *Param,
> + SmallVectorImpl ) {
>TypeSourceInfo *ArgType = Param->getDefaultArgumentInfo();
>
>// If the argument type is dependent, instantiate it now based
>// on the previously-computed template arguments.
>if (ArgType->getType()->isInstantiationDependentType()) {
> -Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc, Param, Template,
> - SugaredConverted,
> +Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc,
> + Param, Template, Converted,
>   SourceRange(TemplateLoc, RAngleLoc));
>  if (Inst.isInvalid())
>return nullptr;
>
>  // Only substitute for the innermost template argument list.
> -MultiLevelTemplateArgumentList TemplateArgLists(Template, 
> SugaredConverted,
> -/*Final=*/true);
> +MultiLevelTemplateArgumentList TemplateArgLists(Template, Converted,
> +/*Final=*/false);
>  for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
>TemplateArgLists.addOuterTemplateArguments(None);
>
> @@ -5318,20 +5320,22 @@ static TypeSourceInfo *SubstDefaultTemplateArgument(
>  /// parameters that precede \p Param in the template parameter list.
>  ///
>  /// \returns the substituted template argument, or NULL if an error occurred.
> -static ExprResult SubstDefaultTemplateArgument(
> -Sema , 

[clang] 97c1b00 - Follow-up to Itanium ABI POD patchnotes

2022-10-28 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-28T22:29:50Z
New Revision: 97c1b0094ad6f628927223b53300c9296ae72f44

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

LOG: Follow-up to Itanium ABI POD patchnotes

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7f02e843f39d..bd4c0bf7fa0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -618,9 +618,9 @@ ABI Changes in Clang
   You can switch back to the old ABI behavior with the flag:
   ``-fclang-abi-compat=15.0``.
 - GCC allows POD types to have defaulted special members. Clang historically
-  classified such types as non-POD. Clang now matches the gcc behavior (except
-  on Darwin and PS4). You can switch back to the old ABI behavior with the 
flag:
-  ``-fclang-abi-compat=15.0``.
+  classified such types as non-POD (for the purposes of Itanium ABI). Clang now
+  matches the gcc behavior (except on Darwin and PS4). You can switch back to
+  the old ABI behavior with the flag: ``-fclang-abi-compat=15.0``.
 
 OpenMP Support in Clang
 ---



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


Re: [Diffusion] rGe4ec6ce8a75c: Clang: Add release note for defaulted-special-members-POD GCC ABI fix

2022-10-28 Thread David Blaikie via cfe-commits
Posted, awaiting approval.

On Fri, Oct 28, 2022 at 5:23 AM Aaron Ballman  wrote:
>
> Also, please be sure to post something to
> https://discourse.llvm.org/c/announce/46 with the potentially-breaking
> tag applied to it.
>
> ~Aaron
>
> On Thu, Oct 27, 2022 at 8:19 PM Hubert Tong via Phabricator via
> cfe-commits  wrote:
> >
> > hubert.reinterpretcast added inline comments.
> >
> > BRANCHES
> >   main
> >
> > /clang/docs/ReleaseNotes.rst:612-613 Shouldn't the usage of POD here be 
> > clarified to say that we mean "POD for the purposes of Itanium ABI layout"?
> >
> > Users:
> >   dblaikie (Author)
> >
> > https://reviews.llvm.org/rGe4ec6ce8a75c
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e4ec6ce - Clang: Add release note for defaulted-special-members-POD GCC ABI fix

2022-10-27 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-27T20:41:22Z
New Revision: e4ec6ce8a75c208b49b163c81cda90dc7373c791

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

LOG: Clang: Add release note for defaulted-special-members-POD GCC ABI fix

Follow-up to 7846d590033e8d661198f4c00f56f46a4993c526

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9d4738b64bd8..bc27c82b3621 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -609,6 +609,10 @@ ABI Changes in Clang
   such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
   You can switch back to the old ABI behavior with the flag:
   ``-fclang-abi-compat=15.0``.
+- GCC allows POD types to have defaulted special members. Clang historically
+  classified such types as non-POD. Clang now matches the gcc behavior (except
+  on Darwin and PS4). You can switch back to the old ABI behavior with the 
flag:
+  ``-fclang-abi-compat=15.0``.
 
 OpenMP Support in Clang
 ---



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


[clang] ec273d3 - Add a warning for not packing non-POD members in packed structs

2022-10-26 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-26T22:18:51Z
New Revision: ec273d3e3a8c3bcb2cf98f893f28bee5bf9b30af

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

LOG: Add a warning for not packing non-POD members in packed structs

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/CodeGenCXX/warn-padded-packed.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index c4f5204425495..af7aec65bf6c8 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -934,6 +934,8 @@ def warn_padded_struct_size : Warning<
   InGroup, DefaultIgnore;
 def warn_unnecessary_packed : Warning<
   "packed attribute is unnecessary for %0">, InGroup, DefaultIgnore;
+def warn_unpacked_field : Warning<
+  "not packing field %0 as it is non-POD">, InGroup, 
DefaultIgnore;
 
 // -Wunaligned-access
 def warn_unaligned_access : Warning<

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2e22f89266a4a..006e5afcd43be 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -562,7 +562,8 @@ def UnderalignedExceptionObject : 
DiagGroup<"underaligned-exception-object">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
 def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
-def Packed : DiagGroup<"packed">;
+def PackedNonPod : DiagGroup<"packed-non-pod">;
+def Packed : DiagGroup<"packed", [PackedNonPod]>;
 def Padded : DiagGroup<"padded">;
 def UnalignedAccess : DiagGroup<"unaligned-access">;
 

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index a897d4c832300..93ade76364b42 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1890,12 +1890,6 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
   LastBitfieldStorageUnitSize = 0;
 
   llvm::Triple Target = Context.getTargetInfo().getTriple();
-  bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
- FieldClass->hasAttr() ||
- Context.getLangOpts().getClangABICompat() <=
- LangOptions::ClangABI::Ver15 ||
- Target.isPS() || Target.isOSDarwin())) ||
- D->hasAttr();
 
   AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
@@ -1976,6 +1970,13 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 }
   }
 
+  bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ FieldClass->hasAttr() ||
+ Context.getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver15 ||
+ Target.isPS() || Target.isOSDarwin())) ||
+ D->hasAttr();
+
   // When used as part of a typedef, or together with a 'packed' attribute, the
   // 'aligned' attribute can be used to decrease alignment. In that case, it
   // overrides any computed alignment we have, and there is no need to upgrade
@@ -2026,28 +2027,34 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
   // The align if the field is not packed. This is to check if the attribute
   // was unnecessary (-Wpacked).
-  CharUnits UnpackedFieldAlign =
-  !DefaultsToAIXPowerAlignment ? FieldAlign : PreferredAlign;
+  CharUnits UnpackedFieldAlign = FieldAlign; 
+  CharUnits PackedFieldAlign = CharUnits::One();
   CharUnits UnpackedFieldOffset = FieldOffset;
   CharUnits OriginalFieldAlign = UnpackedFieldAlign;
 
-  if (FieldPacked) {
-FieldAlign = CharUnits::One();
-PreferredAlign = CharUnits::One();
-  }
   CharUnits MaxAlignmentInChars =
   Context.toCharUnitsFromBits(D->getMaxAlignment());
-  FieldAlign = std::max(FieldAlign, MaxAlignmentInChars);
+  PackedFieldAlign = std::max(PackedFieldAlign, MaxAlignmentInChars);
   PreferredAlign = std::max(PreferredAlign, MaxAlignmentInChars);
   UnpackedFieldAlign = std::max(UnpackedFieldAlign, MaxAlignmentInChars);
 
   // The maximum field alignment overrides the aligned attribute.
   if (!MaxFieldAlignment.isZero()) {
-FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
+PackedFieldAlign = 

[clang] 7846d59 - Extend the C++03 definition of POD to include defaulted functions

2022-10-26 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-26T22:00:49Z
New Revision: 7846d590033e8d661198f4c00f56f46a4993c526

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

LOG: Extend the C++03 definition of POD to include defaulted functions

The AST/conditionally-trivial-smfs tests look a bit questionable, but
are consistent with GCC's POD-ness, at least as far as packing is
concerned: https://godbolt.org/z/36nqPMbKM
(questionable because it looks like the type would be non-copyable, so
how could it be pod? But the calling convention/pass by value seems to
work correctly (local testing verifies that this behavior is preserved
even with this patch: https://godbolt.org/z/3Pa89zsv6 ))

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/DeclCXX.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/test/AST/conditionally-trivial-smfs.cpp
clang/test/SemaCXX/class-layout.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index cfa98329ce24a..a7903855222f6 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -229,6 +229,7 @@ class LangOptions : public LangOptionsBase {
 /// This causes clang to:
 ///   - Reverse the implementation for DR692, DR1395 and DR1432.
 ///   - pack non-POD members of packed structs.
+///   - consider classes with defaulted special member functions non-pod.
 Ver15,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9b9439e2c34f6..2c50b19763665 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1566,6 +1566,14 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
 
   virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
 
+  /// Controls whether explicitly defaulted (`= default`) special member
+  /// functions disqualify something from being POD-for-the-purposes-of-layout.
+  /// Historically, Clang didn't consider these acceptable for POD, but GCC
+  /// does. So in newer Clang ABIs they are acceptable for POD to be compatible
+  /// with GCC/Itanium ABI, and remains disqualifying for targets that need
+  /// Clang backwards compatibility rather than GCC/Itanium ABI compatibility.
+  virtual bool areDefaultedSMFStillPOD(const LangOptions&) const;
+
   /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
   /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
   virtual bool hasSjLjLowering() const {

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index b92210996fdb6..16b21397309d3 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -36,6 +36,7 @@
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
@@ -768,12 +769,16 @@ void CXXRecordDecl::addedMember(Decl *D) {
 // Note that we have a user-declared constructor.
 data().UserDeclaredConstructor = true;
 
-// C++ [class]p4:
-//   A POD-struct is an aggregate class [...]
-// Since the POD bit is meant to be C++03 POD-ness, clear it even if
-// the type is technically an aggregate in C++0x since it wouldn't be
-// in 03.
-data().PlainOldData = false;
+const TargetInfo  = getASTContext().getTargetInfo();
+if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
+!TI.areDefaultedSMFStillPOD(getLangOpts())) {
+  // C++ [class]p4:
+  //   A POD-struct is an aggregate class [...]
+  // Since the POD bit is meant to be C++03 POD-ness, clear it even if
+  // the type is technically an aggregate in C++0x since it wouldn't be
+  // in 03.
+  data().PlainOldData = false;
+}
   }
 
   if (Constructor->isDefaultConstructor()) {
@@ -881,18 +886,24 @@ void CXXRecordDecl::addedMember(Decl *D) {
   if (!Method->isImplicit()) {
 data().UserDeclaredSpecialMembers |= SMKind;
 
-// C++03 [class]p4:
-//   A POD-struct is an aggregate class that has [...] no user-defined
-//   copy assignment operator and no user-defined destructor.
-//
-// Since the POD bit is meant to be C++03 POD-ness, and in C++03,
-// aggregates could not have any constructors, clear it even for an
-

[clang] 5b773dc - Fix incorrect check for running out of source locations.

2022-10-18 Thread David Blaikie via cfe-commits

Author: Paul Pluzhnikov
Date: 2022-10-18T20:48:00Z
New Revision: 5b773dcd2de0c4844814266a90dac14c349b8f18

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

LOG: Fix incorrect check for running out of source locations.

When CurrentLoadedOffset is less than TotalSize, current code will
trigger unsigned overflow and will not return an "allocation failed"
indicator.

Google ref: b/248613299

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 6aae581be8001..20bb594106713 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -454,8 +454,10 @@ SourceManager::AllocateLoadedSLocEntries(unsigned 
NumSLocEntries,
  SourceLocation::UIntTy TotalSize) {
   assert(ExternalSLocEntries && "Don't have an external sloc source");
   // Make sure we're not about to run out of source locations.
-  if (CurrentLoadedOffset - TotalSize < NextLocalOffset)
+  if (CurrentLoadedOffset < TotalSize ||
+  CurrentLoadedOffset - TotalSize < NextLocalOffset) {
 return std::make_pair(0, 0);
+  }
   LoadedSLocEntryTable.resize(LoadedSLocEntryTable.size() + NumSLocEntries);
   SLocEntryLoaded.resize(LoadedSLocEntryTable.size());
   CurrentLoadedOffset -= TotalSize;



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


Re: [clang] 0674f2e - [NFC] Fix warning on no return after switch.

2022-10-17 Thread David Blaikie via cfe-commits
On Mon, Oct 17, 2022 at 5:52 PM stan li  wrote:
>
> Thanks for the suggestion.
>
>
>
> Updated llvm_unreachable.
>
>
>
> The static_cast not only check the switch cases all covered, also make sure 2 
> enums not out of sync.


Ah, OK  - thanks for explaining!

>
>
>
>
>
>
>
> Sent from Mail for Windows
>
>
>
> From: David Blaikie
> Sent: Monday, October 17, 2022 5:42 PM
> To: Xiang Li; Xiang Li
> Cc: cfe-commits@lists.llvm.org
> Subject: Re: [clang] 0674f2e - [NFC] Fix warning on no return after switch.
>
>
>
> Also the static_assert is probably not needed - Clang builds with
> -Wswitch-enum, which will warn if a switch over an enum doesn't cover
> all the enumerators. We have lots of other switches over enums that
> depend on this warning to detect code that needs to be updated when an
> enum is modified.
>
> On Mon, Oct 17, 2022 at 5:40 PM David Blaikie  wrote:
> >
> > If the switch is exhaustive (covers all the enumerators in an
> > enumeration), we usually use an llvm_unreachable at the end, rather
> > than a return. Could you change this to an llvm_unreachable?
> >
> > On Mon, Oct 17, 2022 at 3:52 PM Xiang Li via cfe-commits
> >  wrote:
> > >
> > >
> > > Author: Xiang Li
> > > Date: 2022-10-17T15:52:23-07:00
> > > New Revision: 0674f2ec96422131abde0c042fbf2c11267db210
> > >
> > > URL: 
> > > https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210
> > > DIFF: 
> > > https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210.diff
> > >
> > > LOG: [NFC] Fix warning on no return after switch.
> > >
> > > Added:
> > >
> > >
> > > Modified:
> > > clang/lib/CodeGen/CGHLSLRuntime.cpp
> > >
> > > Removed:
> > >
> > >
> > >
> > > 
> > > diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
> > > b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > > index 7a80dedb8133..6f32136b49de 100644
> > > --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > > +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > > @@ -270,6 +270,7 @@ 
> > > castResourceShapeToResourceKind(HLSLResourceAttr::ResourceKind RK) {
> > >static_cast(
> > >HLSLResourceAttr::ResourceKind::FeedbackTexture2DArray) ==
> > >(static_cast(llvm::hlsl::ResourceKind::NumEntries) - 2));
> > > +  return llvm::hlsl::ResourceKind::Invalid;
> > >  }
> > >
> > >  void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, 
> > > GlobalVariable *GV) {
> > >
> > >
> > >
> > > ___
> > > cfe-commits mailing list
> > > cfe-commits@lists.llvm.org
> > > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] 0674f2e - [NFC] Fix warning on no return after switch.

2022-10-17 Thread David Blaikie via cfe-commits
Also the static_assert is probably not needed - Clang builds with
-Wswitch-enum, which will warn if a switch over an enum doesn't cover
all the enumerators. We have lots of other switches over enums that
depend on this warning to detect code that needs to be updated when an
enum is modified.

On Mon, Oct 17, 2022 at 5:40 PM David Blaikie  wrote:
>
> If the switch is exhaustive (covers all the enumerators in an
> enumeration), we usually use an llvm_unreachable at the end, rather
> than a return. Could you change this to an llvm_unreachable?
>
> On Mon, Oct 17, 2022 at 3:52 PM Xiang Li via cfe-commits
>  wrote:
> >
> >
> > Author: Xiang Li
> > Date: 2022-10-17T15:52:23-07:00
> > New Revision: 0674f2ec96422131abde0c042fbf2c11267db210
> >
> > URL: 
> > https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210
> > DIFF: 
> > https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210.diff
> >
> > LOG: [NFC] Fix warning on no return after switch.
> >
> > Added:
> >
> >
> > Modified:
> > clang/lib/CodeGen/CGHLSLRuntime.cpp
> >
> > Removed:
> >
> >
> >
> > 
> > diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
> > b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > index 7a80dedb8133..6f32136b49de 100644
> > --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > @@ -270,6 +270,7 @@ 
> > castResourceShapeToResourceKind(HLSLResourceAttr::ResourceKind RK) {
> >static_cast(
> >HLSLResourceAttr::ResourceKind::FeedbackTexture2DArray) ==
> >(static_cast(llvm::hlsl::ResourceKind::NumEntries) - 2));
> > +  return llvm::hlsl::ResourceKind::Invalid;
> >  }
> >
> >  void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable 
> > *GV) {
> >
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] 0674f2e - [NFC] Fix warning on no return after switch.

2022-10-17 Thread David Blaikie via cfe-commits
If the switch is exhaustive (covers all the enumerators in an
enumeration), we usually use an llvm_unreachable at the end, rather
than a return. Could you change this to an llvm_unreachable?

On Mon, Oct 17, 2022 at 3:52 PM Xiang Li via cfe-commits
 wrote:
>
>
> Author: Xiang Li
> Date: 2022-10-17T15:52:23-07:00
> New Revision: 0674f2ec96422131abde0c042fbf2c11267db210
>
> URL: 
> https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210
> DIFF: 
> https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210.diff
>
> LOG: [NFC] Fix warning on no return after switch.
>
> Added:
>
>
> Modified:
> clang/lib/CodeGen/CGHLSLRuntime.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
> b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> index 7a80dedb8133..6f32136b49de 100644
> --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
> +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> @@ -270,6 +270,7 @@ 
> castResourceShapeToResourceKind(HLSLResourceAttr::ResourceKind RK) {
>static_cast(
>HLSLResourceAttr::ResourceKind::FeedbackTexture2DArray) ==
>(static_cast(llvm::hlsl::ResourceKind::NumEntries) - 2));
> +  return llvm::hlsl::ResourceKind::Invalid;
>  }
>
>  void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable 
> *GV) {
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 037f856 - Itanium ABI: Pack non-pod members of packed types

2022-10-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-14T19:32:57Z
New Revision: 037f856681268c793c660389b4d6407367e68190

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

LOG: Itanium ABI: Pack non-pod members of packed types

Seems there's a narrow case - where a packed type doesn't pack its base
subobjects (only fields), but when packing a field of the derived type,
GCC does pack the resulting total object - effectively packing the base
subobject.

So ensure that this non-pod type (owing to it having a base class) that
is packed, gets packed when placed in /another/ type that is also
packed.

This is a (smallish?) ABI fix to a regression introduced by D117616 -
but that regression/ABI break hasn't been released in LLVM as-yet (it's
been reverted on the release branch from the last two LLVM releases - I
probably should've just reverted the whole patch while we hashed out
this and other issues) so this change isn't itself an ABI break, as far
as LLVM releases are concerned (for folks releasing their own copies of
LLVM from ToT/without the LLVM release branch, and didn't opt into the
clang-abi-compat 14 or below (soon to be 15 or below, I guess I should
say) then this would be an ABI break against clang from the last 9
months or so)

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

Added: 


Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/SemaCXX/class-layout.cpp

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index dea7450613cc3..a897d4c832300 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1891,6 +1891,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
   llvm::Triple Target = Context.getTargetInfo().getTriple();
   bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ FieldClass->hasAttr() ||
  Context.getLangOpts().getClangABICompat() <=
  LangOptions::ClangABI::Ver15 ||
  Target.isPS() || Target.isOSDarwin())) ||

diff  --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index df63141fc36dd..f3106ec422dff 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -642,3 +642,17 @@ struct t2 {
 _Static_assert(_Alignof(t1) == 1, "");
 _Static_assert(_Alignof(t2) == 1, "");
 } // namespace non_pod_packed
+
+namespace non_pod_packed_packed {
+struct B {
+  int b;
+};
+struct  FromB : B {
+} __attribute__((packed));
+struct C {
+  char a[3];
+  FromB b;
+} __attribute__((packed));
+_Static_assert(__builtin_offsetof(C, b) == 3, "");
+}
+



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


[clang] 9363071 - Move GCC-compatible pod-packing change to v16/old behavior available at v15 and below

2022-10-13 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-13T21:13:19Z
New Revision: 9363071303ec59bc9e0d9b989f08390b37e3f5e4

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

LOG: Move GCC-compatible pod-packing change to v16/old behavior available at 
v15 and below

Change matches D126334/e59f648d698e since this change got punted from
v15 too.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/SemaCXX/class-layout.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b036764803007..2a81877f27b71 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -524,6 +524,12 @@ OpenCL C Language Changes in Clang
 ABI Changes in Clang
 
 
+- GCC doesn't pack non-POD members in packed structs unless the packed
+  attribute is also specified on the member. Clang historically did perform
+  such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
+  You can switch back to the old ABI behavior with the flag:
+  ``-fclang-abi-compat=15.0``.
+
 OpenMP Support in Clang
 ---
 

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 4cac4c221d8b5..cfa98329ce24a 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -220,7 +220,6 @@ class LangOptions : public LangOptionsBase {
 /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
 /// This causes clang to:
 ///   - mangle dependent nested names incorrectly.
-///   - pack non-POD members of packed structs.
 ///   - make trivial only those defaulted copy constructors with a
 /// parameter-type-list equivalent to the parameter-type-list of an
 /// implicit declaration.
@@ -229,6 +228,7 @@ class LangOptions : public LangOptionsBase {
 /// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
 /// This causes clang to:
 ///   - Reverse the implementation for DR692, DR1395 and DR1432.
+///   - pack non-POD members of packed structs.
 Ver15,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 6f3ede2ce42a7..dea7450613cc3 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1892,7 +1892,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
   llvm::Triple Target = Context.getTargetInfo().getTriple();
   bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
  Context.getLangOpts().getClangABICompat() <=
- LangOptions::ClangABI::Ver14 ||
+ LangOptions::ClangABI::Ver15 ||
  Target.isPS() || Target.isOSDarwin())) ||
  D->hasAttr();
 

diff  --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index f81e526d0e2ad..df63141fc36dd 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
 // RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
 // expected-no-diagnostics
 
 #define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -621,7 +621,7 @@ struct t2 {
   char c2;
   t1 v1;
 } __attribute__((packed));
-#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15
 

Re: [clang-tools-extra] 5d2d527 - [clangd] Avoid scanning up to end of file on each comment!

2022-10-10 Thread David Blaikie via cfe-commits
On Mon, Oct 10, 2022 at 11:13 AM Sam McCall  wrote:
>
> On Mon, 10 Oct 2022, 19:57 David Blaikie,  wrote:
>>
>> Could the underlying API be made more robust to handle StringRefs
>> rather than null terminated char* in the first place? (like
>> SourceManager::getCharacterData could return StringRef? Presumably at
>> some layer it already knows how long the file is - the underlying
>> MemoryBuffer, in this case)
>
> Maybe...
>
> You could return a StringRef(Pos, EOF) efficiently.
> However it's not a great fit for many of the existing (>150) callers:
>  - that are looking for the *endpoint* of some text

Yeah, I figured that was more what the API was about for better/worse.
I guess it's not worth having two entry points, a lower-level one that
returns StringRef and then the existing one that calls that and
returns the data pointer from the StringRef...

>  - which want to run the lexer (the returned char* is implicitly 
> null-terminated, StringRef would obscure that guarantee)

I guess by implication the lexer needs something null terminated? Be
nice if that wasn't the case too...

>  - the function is marked as "this is very hot", though I doubt it matters 
> that much

*nod* At least something to be careful about.

> It also leads to some unnatural code at callsites such as this, because "from 
> the start of this entity until the end of the file" is an unnatural range to 
> have, it would probably be easy to mistake for "from the start to the end of 
> this entity".

Yeah. :/

> I think what this function does is too low-level to make safe and obvious, 
> and unfortunately it's hard to build high-level things on top of it.

Yeah :/

> (e.g. StringRef getTextRange(SourceRange) would be great to have, but 
> actually you it needs to run the lexer and assert nontrivial invariants due 
> to design decisions elsewhere in clang)
>
>>
>> On Thu, Oct 6, 2022 at 2:39 AM Sam McCall via cfe-commits
>>  wrote:
>> >
>> >
>> > Author: Sam McCall
>> > Date: 2022-10-06T11:38:55+02:00
>> > New Revision: 5d2d527c32da2081b814ef8b446bc3e037f74b0a
>> >
>> > URL: 
>> > https://github.com/llvm/llvm-project/commit/5d2d527c32da2081b814ef8b446bc3e037f74b0a
>> > DIFF: 
>> > https://github.com/llvm/llvm-project/commit/5d2d527c32da2081b814ef8b446bc3e037f74b0a.diff
>> >
>> > LOG: [clangd] Avoid scanning up to end of file on each comment!
>> >
>> > Assigning char* (pointing at comment start) to StringRef was causing us
>> > to scan the rest of the source file looking for the null terminator.
>> >
>> > This seems to be eating about 8% of our *total* CPU!
>> >
>> > While fixing this, factor out the common bits from the two places we're
>> > parsing IWYU pragmas.
>> >
>> > Differential Revision: https://reviews.llvm.org/D135314
>> >
>> > Added:
>> >
>> >
>> > Modified:
>> > clang-tools-extra/clangd/Headers.cpp
>> > clang-tools-extra/clangd/Headers.h
>> > clang-tools-extra/clangd/index/CanonicalIncludes.cpp
>> > clang-tools-extra/clangd/unittests/HeadersTests.cpp
>> >
>> > Removed:
>> >
>> >
>> >
>> > 
>> > diff  --git a/clang-tools-extra/clangd/Headers.cpp 
>> > b/clang-tools-extra/clangd/Headers.cpp
>> > index 5231a47487bc7..52b954e921620 100644
>> > --- a/clang-tools-extra/clangd/Headers.cpp
>> > +++ b/clang-tools-extra/clangd/Headers.cpp
>> > @@ -22,9 +22,17 @@
>> >  namespace clang {
>> >  namespace clangd {
>> >
>> > -const char IWYUPragmaKeep[] = "// IWYU pragma: keep";
>> > -const char IWYUPragmaExport[] = "// IWYU pragma: export";
>> > -const char IWYUPragmaBeginExports[] = "// IWYU pragma: begin_exports";
>> > +llvm::Optional parseIWYUPragma(const char *Text) {
>> > +  // This gets called for every comment seen in the preamble, so it's 
>> > quite hot.
>> > +  constexpr llvm::StringLiteral IWYUPragma = "// IWYU pragma: ";
>> > +  if (strncmp(Text, IWYUPragma.data(), IWYUPragma.size()))
>> > +return llvm::None;
>> > +  Text += IWYUPragma.size();
>> > +  const char *End = Text;
>> > +  while (*End != 0 && *End != '\n')
>> > +++End;
>> > +  return StringRef(Text, End - Text);
>> > +}
>> >
>> >  class IncludeStructure::RecordHeaders : public PPCallbacks,
>> >  public CommentHandler {
>> > @@ -129,10 +137,10 @@ class IncludeStructure::RecordHeaders : public 
>> > PPCallbacks,
>> >}
>> >
>> >bool HandleComment(Preprocessor , SourceRange Range) override {
>> > -bool Err = false;
>> > -llvm::StringRef Text = SM.getCharacterData(Range.getBegin(), );
>> > -if (Err)
>> > +auto Pragma = parseIWYUPragma(SM.getCharacterData(Range.getBegin()));
>> > +if (!Pragma)
>> >return false;
>> > +
>> >  if (inMainFile()) {
>> >// Given:
>> >//
>> > @@ -150,8 +158,7 @@ class IncludeStructure::RecordHeaders : public 
>> > PPCallbacks,
>> >// will know that the next inclusion is behind the IWYU pragma.
>> >// FIXME: Support "IWYU pragma: 

Re: [clang-tools-extra] 5d2d527 - [clangd] Avoid scanning up to end of file on each comment!

2022-10-10 Thread David Blaikie via cfe-commits
Could the underlying API be made more robust to handle StringRefs
rather than null terminated char* in the first place? (like
SourceManager::getCharacterData could return StringRef? Presumably at
some layer it already knows how long the file is - the underlying
MemoryBuffer, in this case)

On Thu, Oct 6, 2022 at 2:39 AM Sam McCall via cfe-commits
 wrote:
>
>
> Author: Sam McCall
> Date: 2022-10-06T11:38:55+02:00
> New Revision: 5d2d527c32da2081b814ef8b446bc3e037f74b0a
>
> URL: 
> https://github.com/llvm/llvm-project/commit/5d2d527c32da2081b814ef8b446bc3e037f74b0a
> DIFF: 
> https://github.com/llvm/llvm-project/commit/5d2d527c32da2081b814ef8b446bc3e037f74b0a.diff
>
> LOG: [clangd] Avoid scanning up to end of file on each comment!
>
> Assigning char* (pointing at comment start) to StringRef was causing us
> to scan the rest of the source file looking for the null terminator.
>
> This seems to be eating about 8% of our *total* CPU!
>
> While fixing this, factor out the common bits from the two places we're
> parsing IWYU pragmas.
>
> Differential Revision: https://reviews.llvm.org/D135314
>
> Added:
>
>
> Modified:
> clang-tools-extra/clangd/Headers.cpp
> clang-tools-extra/clangd/Headers.h
> clang-tools-extra/clangd/index/CanonicalIncludes.cpp
> clang-tools-extra/clangd/unittests/HeadersTests.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang-tools-extra/clangd/Headers.cpp 
> b/clang-tools-extra/clangd/Headers.cpp
> index 5231a47487bc7..52b954e921620 100644
> --- a/clang-tools-extra/clangd/Headers.cpp
> +++ b/clang-tools-extra/clangd/Headers.cpp
> @@ -22,9 +22,17 @@
>  namespace clang {
>  namespace clangd {
>
> -const char IWYUPragmaKeep[] = "// IWYU pragma: keep";
> -const char IWYUPragmaExport[] = "// IWYU pragma: export";
> -const char IWYUPragmaBeginExports[] = "// IWYU pragma: begin_exports";
> +llvm::Optional parseIWYUPragma(const char *Text) {
> +  // This gets called for every comment seen in the preamble, so it's quite 
> hot.
> +  constexpr llvm::StringLiteral IWYUPragma = "// IWYU pragma: ";
> +  if (strncmp(Text, IWYUPragma.data(), IWYUPragma.size()))
> +return llvm::None;
> +  Text += IWYUPragma.size();
> +  const char *End = Text;
> +  while (*End != 0 && *End != '\n')
> +++End;
> +  return StringRef(Text, End - Text);
> +}
>
>  class IncludeStructure::RecordHeaders : public PPCallbacks,
>  public CommentHandler {
> @@ -129,10 +137,10 @@ class IncludeStructure::RecordHeaders : public 
> PPCallbacks,
>}
>
>bool HandleComment(Preprocessor , SourceRange Range) override {
> -bool Err = false;
> -llvm::StringRef Text = SM.getCharacterData(Range.getBegin(), );
> -if (Err)
> +auto Pragma = parseIWYUPragma(SM.getCharacterData(Range.getBegin()));
> +if (!Pragma)
>return false;
> +
>  if (inMainFile()) {
>// Given:
>//
> @@ -150,8 +158,7 @@ class IncludeStructure::RecordHeaders : public 
> PPCallbacks,
>// will know that the next inclusion is behind the IWYU pragma.
>// FIXME: Support "IWYU pragma: begin_exports" and "IWYU pragma:
>// end_exports".
> -  if (!Text.startswith(IWYUPragmaExport) &&
> -  !Text.startswith(IWYUPragmaKeep))
> +  if (!Pragma->startswith("export") && !Pragma->startswith("keep"))
>  return false;
>unsigned Offset = SM.getFileOffset(Range.getBegin());
>LastPragmaKeepInMainFileLine =
> @@ -161,8 +168,7 @@ class IncludeStructure::RecordHeaders : public 
> PPCallbacks,
>// does not support them properly yet, so they will be not marked as
>// unused.
>// FIXME: Once IncludeCleaner supports export pragmas, remove this.
> -  if (!Text.startswith(IWYUPragmaExport) &&
> -  !Text.startswith(IWYUPragmaBeginExports))
> +  if (!Pragma->startswith("export") && 
> !Pragma->startswith("begin_exports"))
>  return false;
>Out->HasIWYUExport.insert(
>*Out->getID(SM.getFileEntryForID(SM.getFileID(Range.getBegin();
>
> diff  --git a/clang-tools-extra/clangd/Headers.h 
> b/clang-tools-extra/clangd/Headers.h
> index ff3f063168325..ba72ad397bf8f 100644
> --- a/clang-tools-extra/clangd/Headers.h
> +++ b/clang-tools-extra/clangd/Headers.h
> @@ -35,6 +35,12 @@ namespace clangd {
>  /// Returns true if \p Include is literal include like "path" or .
>  bool isLiteralInclude(llvm::StringRef Include);
>
> +/// If Text begins an Include-What-You-Use directive, returns it.
> +/// Given "// IWYU pragma: keep", returns "keep".
> +/// Input is a null-terminated char* as provided by SM.getCharacterData().
> +/// (This should not be StringRef as we do *not* want to scan for its 
> length).
> +llvm::Optional parseIWYUPragma(const char *Text);
> +
>  /// Represents a header file to be #include'd.
>  struct HeaderFile {
>std::string File;
>
> diff  --git 

[clang] b61860e - Use inheriting ctors for OSTargetInfo

2022-10-05 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-05T20:22:19Z
New Revision: b61860e63e34d955a9841389583978af93c2b97a

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

LOG: Use inheriting ctors for OSTargetInfo

(& remove PSPTargetInfo because it's unused - it had the wrong ctor in
it anyway, so wouldn't've been able to be instantiated - must've
happened due to bitrot over the years)

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index c75f7d9fbafeb..2d1a33ad9c0bc 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -50,8 +50,7 @@ class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  CloudABITargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Ananas target
@@ -66,8 +65,7 @@ class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  AnanasTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 void getDarwinDefines(MacroBuilder , const LangOptions ,
@@ -280,8 +278,7 @@ class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  KFreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Haiku Target
@@ -336,8 +333,7 @@ class LLVM_LIBRARY_VISIBILITY HurdTargetInfo : public 
OSTargetInfo {
   Builder.defineMacro("_GNU_SOURCE");
   }
 public:
-  HurdTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Minix Target
@@ -360,8 +356,7 @@ class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  MinixTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Linux target
@@ -499,23 +494,6 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public 
OSTargetInfo {
   }
 };
 
-// PSP Target
-template 
-class LLVM_LIBRARY_VISIBILITY PSPTargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const override {
-// PSP defines; list based on the output of the pspdev gcc toolchain.
-Builder.defineMacro("PSP");
-Builder.defineMacro("_PSP");
-Builder.defineMacro("__psp__");
-Builder.defineMacro("__ELF__");
-  }
-
-public:
-  PSPTargetInfo(const llvm::Triple ) : OSTargetInfo(Triple) {}
-};
-
 // PS3 PPU Target
 template 
 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public OSTargetInfo {
@@ -595,8 +573,7 @@ class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public 
PSOSTargetInfo {
   }
 
 public:
-  PS4OSTargetInfo(const llvm::Triple , const TargetOptions )
-  : PSOSTargetInfo(Triple, Opts) {}
+  using PSOSTargetInfo::PSOSTargetInfo;
 };
 
 // PS5 Target
@@ -612,8 +589,7 @@ class LLVM_LIBRARY_VISIBILITY PS5OSTargetInfo : public 
PSOSTargetInfo {
   }
 
 public:
-  PS5OSTargetInfo(const llvm::Triple , const TargetOptions )
-  : PSOSTargetInfo(Triple, Opts) {}
+  using PSOSTargetInfo::PSOSTargetInfo;
 };
 
 // RTEMS Target
@@ -986,8 +962,7 @@ class LLVM_LIBRARY_VISIBILITY WASITargetInfo
   }
 
 public:
-  explicit WASITargetInfo(const llvm::Triple , const TargetOptions 
)
-  : WebAssemblyOSTargetInfo(Triple, Opts) {}
+  using WebAssemblyOSTargetInfo::WebAssemblyOSTargetInfo;
 };
 
 // Emscripten target



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


[clang] 4769976 - MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for pod/aggregate passing

2022-10-04 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-04T20:19:17Z
New Revision: 4769976c49be468d7629d513080e6959a25adcfe

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

LOG: MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for 
pod/aggregate passing

Details posted here: https://reviews.llvm.org/D119051#3747201

3 cases that were inconsistent with the MSABI without this patch applied:
  https://godbolt.org/z/GY48qxh3G - field with protected member
  https://godbolt.org/z/Mb1PYhjrP - non-static data member initializer
  https://godbolt.org/z/sGvxcEPjo - defaulted copy constructor

I'm not sure what's suitable/sufficient testing for this - I did verify
the three cases above. Though if it helps to add them as explicit tests,
I can do that too.

Also, I was wondering if the other use of isTrivialForAArch64MSVC in
isPermittedToBeHomogenousAggregate could be another source of bugs - I
tried changing the function to unconditionally call
isTrivialFor(AArch64)MSVC without testing AArch64 first, but no tests
fail, so it looks like this is undertested in any case. But I had
trouble figuring out how to exercise this functionality properly to add
test coverage and then compare that to MSVC itself... - I got very
confused/turned around trying to test this, so I've given up enough to
send what I have out for review, but happy to look further into this
with help.

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

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 76aeb7bb7b76..1034066b472e 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1086,8 +1086,8 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl GD) 
const {
   return isDeletingDtor(GD);
 }
 
-static bool isTrivialForAArch64MSVC(const CXXRecordDecl *RD) {
-  // For AArch64, we use the C++14 definition of an aggregate, so we also
+static bool isTrivialForMSVC(const CXXRecordDecl *RD) {
+  // We use the C++14 definition of an aggregate, so we also
   // check for:
   //   No private or protected non static data members.
   //   No base classes
@@ -1115,15 +1115,7 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
   if (!RD)
 return false;
 
-  // Normally, the C++ concept of "is trivially copyable" is used to determine
-  // if a struct can be returned directly. However, as MSVC and the language
-  // have evolved, the definition of "trivially copyable" has changed, while 
the
-  // ABI must remain stable. AArch64 uses the C++14 concept of an "aggregate",
-  // while other ISAs use the older concept of "plain old data".
-  bool isTrivialForABI = RD->isPOD();
-  bool isAArch64 = CGM.getTarget().getTriple().isAArch64();
-  if (isAArch64)
-isTrivialForABI = RD->canPassInRegisters() && isTrivialForAArch64MSVC(RD);
+  bool isTrivialForABI = RD->canPassInRegisters() && isTrivialForMSVC(RD);
 
   // MSVC always returns structs indirectly from C++ instance methods.
   bool isIndirectReturn = !isTrivialForABI || FI.isInstanceMethod();
@@ -1137,7 +1129,7 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
 
 // On AArch64, use the `inreg` attribute if the object is considered to not
 // be trivially copyable, or if this is an instance method struct return.
-FI.getReturnInfo().setInReg(isAArch64);
+FI.getReturnInfo().setInReg(CGM.getTarget().getTriple().isAArch64());
 
 return true;
   }

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
index d6ee0684e36f..08c9faf6fd77 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix 
WIN32 %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck 
-check-prefix WOA %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck 
-check-prefix WIN64 %s
-// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 
-triple=aarch64-windows-msvc -mconstructor-aliases -fno-rtti | FileCheck 
-check-prefix WOA64 %s
+// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - 

[clang] 2e1c1d6 - MSVC AArch64 ABI: Homogeneous aggregates

2022-10-04 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-04T20:17:29Z
New Revision: 2e1c1d6d72879cafc339ad035b1b5a6d1c8cc130

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

LOG: MSVC AArch64 ABI: Homogeneous aggregates

Fixes:
Protected members, HFA: https://godbolt.org/z/zqdK7vdKc
Private members, HFA: https://godbolt.org/z/zqdK7vdKc
Non-empty base, HFA: https://godbolt.org/z/PKTz59Wev
User-provided ctor, HFA: https://godbolt.org/z/sfrTddcW6

Existing correct cases:
Empty base class, NonHFA: https://godbolt.org/z/4veY9MWP3
 - correct by accident of not allowing bases at all (see non-empty base
   case/fix above for counterexample)
Polymorphic: NonHFA: https://godbolt.org/z/4veY9MWP3
Trivial copy assignment, HFA: https://godbolt.org/z/Tdecj836P
Non-trivial copy assignment, NonHFA: https://godbolt.org/z/7c4bE9Whq
Non-trivial default ctor, NonHFA: https://godbolt.org/z/Tsq1EE7b7
 - correct by accident of disallowing all user-provided ctors (see
   user-provided non-default ctor example above for counterexample)
Trivial dtor, HFA: https://godbolt.org/z/nae999aqz
Non-trivial dtor, NonHFA: https://godbolt.org/z/69oMcshb1
Empty field, NonHFA: https://godbolt.org/z/8PTxsKKMK
 - true due to checking for the absence of padding (see comment in code)

After a bunch of testing, this fixes a bunch of cases that were
incorrect. Some of the tests verify the nuances of the existing
behavior/code checks that were already present.

This was mostly motivated by cleanup from/in D133817 which itself was
motivated by D119051.

By removing the incorrect use of isTrivialForAArch64MSVC here & adding
more nuance to the homogeneous testing we can more safely/confidently
make changes to the isTrivialFor(AArch64)MSVC to more properly align
with its usage anyway.

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

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/homogeneous-aggregates.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 539f0a6eb8cb8..76aeb7bb7b76f 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4476,10 +4476,45 @@ MicrosoftCXXABI::LoadVTablePtr(CodeGenFunction , 
Address This,
 }
 
 bool MicrosoftCXXABI::isPermittedToBeHomogeneousAggregate(
-const CXXRecordDecl *CXXRD) const {
-  // MSVC Windows on Arm64 considers a type not HFA if it is not an
-  // aggregate according to the C++14 spec. This is not consistent with the
-  // AAPCS64, but is defacto spec on that platform.
-  return !CGM.getTarget().getTriple().isAArch64() ||
- isTrivialForAArch64MSVC(CXXRD);
+const CXXRecordDecl *RD) const {
+  // All aggregates are permitted to be HFA on non-ARM platforms, which mostly
+  // affects vectorcall on x64/x86.
+  if (!CGM.getTarget().getTriple().isAArch64())
+return true;
+  // MSVC Windows on Arm64 has its own rules for determining if a type is HFA
+  // that are inconsistent with the AAPCS64 ABI. The following are our best
+  // determination of those rules so far, based on observation of MSVC's
+  // behavior.
+  if (RD->isEmpty())
+return false;
+  if (RD->isPolymorphic())
+return false;
+  if (RD->hasNonTrivialCopyAssignment())
+return false;
+  if (RD->hasNonTrivialDestructor())
+return false;
+  if (RD->hasNonTrivialDefaultConstructor())
+return false;
+  // These two are somewhat redundant given the caller
+  // (ABIInfo::isHomogeneousAggregate) checks the bases and fields, but that
+  // caller doesn't consider empty bases/fields to be non-homogenous, but it
+  // looks like Microsoft's AArch64 ABI does care about these empty types &
+  // anything containing/derived from one is non-homogeneous.
+  // Instead we could add another CXXABI entry point to query this property and
+  // have ABIInfo::isHomogeneousAggregate use that property.
+  // I don't think any other of the features listed above could be true of a
+  // base/field while not true of the outer struct. For example, if you have a
+  // base/field that has an non-trivial copy assignment/dtor/default ctor, then
+  // the outer struct's corresponding operation must be non-trivial.
+  for (const CXXBaseSpecifier  : RD->bases()) {
+if (const CXXRecordDecl *FRD = B.getType()->getAsCXXRecordDecl()) {
+  if (!isPermittedToBeHomogeneousAggregate(FRD))
+return false;
+}
+  }
+  // empty fields seem to be caught by the ABIInfo::isHomogeneousAggregate
+  // checking for padding - but maybe there are ways to end up with an empty
+  // field without padding? Not that I know of, so don't check fields here &
+  // rely on the padding check.
+  return true;
 }

diff  --git a/clang/test/CodeGenCXX/homogeneous-aggregates.cpp 

[clang] 1651289 - [clang] fix generation of .debug_aranges with LTO

2022-10-04 Thread David Blaikie via cfe-commits

Author: Azat Khuzhin
Date: 2022-10-04T20:03:36Z
New Revision: 16512898956857b13e566165ba9a195be81d325f

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

LOG: [clang] fix generation of .debug_aranges with LTO

Right now in case of LTO the section is not emited:

$ cat test.c
void __attribute__((optnone)) bar()
{
}
void __attribute__((optnone)) foo()
{
bar();
}
int main()
{
foo();
}

$ clang -flto=thin -gdwarf-aranges -g -O3 test.c
$ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
0

$ clang -gdwarf-aranges -g -O3 test.c
$ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
2

Fix this by passing explicitly --plugin-opt=-generate-arange-section.

Suggested-by: OCHyams 

Reviewed By: dblaikie, MaskRay

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

Added: 
clang/test/Driver/debug-options-aranges.c

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4bc16710e194..d81faa365228 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -509,6 +509,14 @@ void tools::addLTOOptions(const ToolChain , 
const ArgList ,
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 

diff  --git a/clang/test/Driver/debug-options-aranges.c 
b/clang/test/Driver/debug-options-aranges.c
new file mode 100644
index ..4dc098b7d185
--- /dev/null
+++ b/clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,6 @@
+// REQUIRES: lld
+
+/// Check that the linker plugin will get -generate-arange-section.
+// RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section



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


[clang] 4cd7529 - [clang][DebugInfo] Emit access specifiers for typedefs

2022-09-22 Thread David Blaikie via cfe-commits

Author: Jonathan Camilleri
Date: 2022-09-22T17:08:41Z
New Revision: 4cd7529e4caa00fa7ba27d9de18adea3c702ad8f

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

LOG: [clang][DebugInfo] Emit access specifiers for typedefs

The accessibility level of a typedef or using declaration in a
struct or class was being lost when producing debug information.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 73cb80816fae7..a5cc5930728aa 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1283,6 +1283,33 @@ llvm::DIType *CGDebugInfo::CreateType(const 
TemplateSpecializationType *Ty,
 getDeclContextDescriptor(AliasDecl));
 }
 
+/// Convert an AccessSpecifier into the corresponding DINode flag.
+/// As an optimization, return 0 if the access specifier equals the
+/// default for the containing type.
+static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access,
+   const RecordDecl *RD) {
+  AccessSpecifier Default = clang::AS_none;
+  if (RD && RD->isClass())
+Default = clang::AS_private;
+  else if (RD && (RD->isStruct() || RD->isUnion()))
+Default = clang::AS_public;
+
+  if (Access == Default)
+return llvm::DINode::FlagZero;
+
+  switch (Access) {
+  case clang::AS_private:
+return llvm::DINode::FlagPrivate;
+  case clang::AS_protected:
+return llvm::DINode::FlagProtected;
+  case clang::AS_public:
+return llvm::DINode::FlagPublic;
+  case clang::AS_none:
+return llvm::DINode::FlagZero;
+  }
+  llvm_unreachable("unexpected access enumerator");
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
   llvm::DIFile *Unit) {
   llvm::DIType *Underlying =
@@ -1298,10 +1325,16 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType 
*Ty,
   uint32_t Align = getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext());
   // Typedefs are derived from some other type.
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(Ty->getDecl());
+
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  const DeclContext *DC = Ty->getDecl()->getDeclContext();
+  if (isa(DC))
+Flags = getAccessFlag(Ty->getDecl()->getAccess(), cast(DC));
+
   return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
 getOrCreateFile(Loc), getLineNumber(Loc),
 getDeclContextDescriptor(Ty->getDecl()), Align,
-Annotations);
+Flags, Annotations);
 }
 
 static unsigned getDwarfCC(CallingConv CC) {
@@ -1395,33 +1428,6 @@ llvm::DIType *CGDebugInfo::CreateType(const FunctionType 
*Ty,
   return F;
 }
 
-/// Convert an AccessSpecifier into the corresponding DINode flag.
-/// As an optimization, return 0 if the access specifier equals the
-/// default for the containing type.
-static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access,
-   const RecordDecl *RD) {
-  AccessSpecifier Default = clang::AS_none;
-  if (RD && RD->isClass())
-Default = clang::AS_private;
-  else if (RD && (RD->isStruct() || RD->isUnion()))
-Default = clang::AS_public;
-
-  if (Access == Default)
-return llvm::DINode::FlagZero;
-
-  switch (Access) {
-  case clang::AS_private:
-return llvm::DINode::FlagPrivate;
-  case clang::AS_protected:
-return llvm::DINode::FlagProtected;
-  case clang::AS_public:
-return llvm::DINode::FlagPublic;
-  case clang::AS_none:
-return llvm::DINode::FlagZero;
-  }
-  llvm_unreachable("unexpected access enumerator");
-}
-
 llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl,
   llvm::DIScope *RecordTy,
   const RecordDecl *RD) {

diff  --git a/clang/test/CodeGenCXX/debug-info-access.cpp 
b/clang/test/CodeGenCXX/debug-info-access.cpp
index cd5328be0a85c..9f2c044843d0f 100644
--- a/clang/test/CodeGenCXX/debug-info-access.cpp
+++ b/clang/test/CodeGenCXX/debug-info-access.cpp
@@ -9,7 +9,6 @@ struct A {
   static int pub_default_static;
 };
 
-
 // CHECK: !DIDerivedType(tag: DW_TAG_inheritance,{{.*}} baseType: 
![[A]],{{.*}} flags: DIFlagPublic, extraData: i32 0)
 class B : public A {
 public:
@@ -17,9 +16,17 @@ class B : public A {
   void pub();
   // CHECK-DAG: !DIDerivedType(tag: DW_TAG_member, name: 

[clang] 6bf6730 - [clang] fix generation of .debug_aranges with LTO

2022-09-13 Thread David Blaikie via cfe-commits

Author: Azat Khuzhin
Date: 2022-09-13T22:33:56Z
New Revision: 6bf6730ac55e064edf46915ebba02e9c716f48e8

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

LOG: [clang] fix generation of .debug_aranges with LTO

Right now in case of LTO the section is not emited:

$ cat test.c
void __attribute__((optnone)) bar()
{
}
void __attribute__((optnone)) foo()
{
bar();
}
int main()
{
foo();
}

$ clang -flto=thin -gdwarf-aranges -g -O3 test.c
$ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
0

$ clang -gdwarf-aranges -g -O3 test.c
$ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
2

Fix this by passing explicitly -mllvm -generate-arange-section.

P.S. although this looks like a hack, since none of -mllvm was passed to
the lld before.

Signed-off-by: Azat Khuzhin 
Suggested-by: OCHyams 

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 22025d95e7c8f..c61fcfc946b89 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -506,6 +506,19 @@ void tools::addLTOOptions(const ToolChain , 
const ArgList ,
 Suffix,
 Plugin);
 CmdArgs.push_back(Args.MakeArgString(Plugin));
+  } else {
+// NOTE:
+// - it is not possible to use lld for PS4
+// - addLTOOptions() is not used for PS5
+// Hence no need to handle SCE (like in Clang.cpp::renderDebugOptions()).
+//
+// But note, this solution is far from perfect, better to encode it into IR
+// metadata, but this may not be worth it, since it looks like aranges is
+// on the way out.
+if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+  CmdArgs.push_back(Args.MakeArgString("-mllvm"));
+  CmdArgs.push_back(Args.MakeArgString("-generate-arange-section"));
+}
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to

diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 04004716aa501..2da192d098e24 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -246,7 +246,11 @@
 // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
-// RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck 
-check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | 
FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 
| FileCheck -check-prefix=LDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck -check-prefix=LDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -fuse-ld=lld -flto 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LLDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -fuse-ld=lld -flto=thin 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LLDGARANGE %s
 //
 // RUN: %clang -### -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 
\
 // RUN:| FileCheck -check-prefix=FDTS %s
@@ -371,6 +375,8 @@
 // NORNGBSE-NOT: -fdebug-ranges-base-address
 //
 // GARANGE-DAG: -generate-arange-section
+// LDGARANGE-NOT: {{".*lld.*"}} {{.*}} "-generate-arange-section"
+// LLDGARANGE: {{".*lld.*"}} {{.*}} "-generate-arange-section"
 //
 // FDTS: "-mllvm" "-generate-type-units"
 // FDTSE: error: unsupported option '-fdebug-types-section' for target 
'x86_64-apple-darwin'



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


Re: [clang] b7a7aee - [clang] Qualify auto in range-based for loops (NFC)

2022-09-12 Thread David Blaikie via cfe-commits
On Sat, Sep 10, 2022 at 3:01 PM Kazu Hirata  wrote:
>
> Thank you Aaron and David for your inputs.
>
> First and foremost, I apologize if I made your job harder by increasing the 
> number of commits you have to peel to get to the real author.
>
> I hear that we are moving toward github pull requests.  A casual search tells 
> me that there are some add-ons to integrate clang-tidy into the code review 
> platform, so I am hoping we can use something like that to get each patch 
> right first time.
>
> Going forward, I'll take git churn and the difficulty of backsliding as big 
> factors in doing future clenaups.  For example, it's probably a good idea to 
> delete a function that hasn't been used for many years (excluding dump 
> functions and such).  Library standardization (like the recent removal of 
> llvm::array_lengthof in favor of std::size) is less good in terms of git 
> churn, but it's very unlikely for somebody to re-introduce 
> llvm::array_lengthof.

I think API deprecations (where the API can be completely removed
eventually, and marked as deprecated/all in-tree usage removed within
O(weeks/months)) especially for cases like the core/support libraries
with relatively many uses, and relatively small APIs are great - if we
get into the territory of naming convention cleanup, that gets more
debatable because there's wide APIs with many naming violations and
then we need more community discussion about what direction we're
going (there are multiple lingering naming conventions, some
discussions about moving to different ones in the future, so maybe
churn to meet the current letter of the style guide would be better
spent after changing the style guide with those directions in mind,
etc).

For stylistic things like range-based-for conversion, const auto*, etc
- yeah, there's some wriggle room depending on how uncontentious the
conversion is, I think.

(there's also some way to mark certain changes as ignorable by git?
Maybe using that more frequently would help lower the cost of these
sort of changes - broader discussion on discourse about ways to
enable/lower the cost of these sort of changes would probably be good
- I think as much as we can make these sort of changes cheaper/less
problematic, to make them more encouraged, is a really good thing to
do)

>
> Thanks,
>
> Kazu Hirata
>
>
> On Fri, Sep 9, 2022 at 5:27 AM Aaron Ballman  wrote:
>>
>> On Thu, Sep 8, 2022 at 12:37 PM David Blaikie  wrote:
>> >
>> > Mixed feelings here - Kazu's made a lot of cleanup/stylistic changes
>> > across the LLVM project for a while now, most, at least I think, are
>> > quite welcome (things like switching to range-based-for, std
>> > algorithms over llvm ones, llvm algorithms over manually written
>> > loops, etc). But yeah, there's some threshold below which the churn
>> > might not be worth the benefit - especially if the change doesn't come
>> > along with tooling to enforce the invariant is maintained in the
>> > future (if it's easy to make mistakes like this one - we'll regress it
>> > and need to do cleanup again in the future)
>>
>> Thanks for speaking up, because I also waffled a bit on whether I
>> called this out or not. :-)
>>
>> > Also, for this particular one, I wonder if in some cases this sort of
>> > automatic transformation isn't ideal - if something is a pointer, but
>> > that's an implementation detail, rather than an intentional feature of
>> > an API (eg: the pointer-ness might be hidden behind a typedef and used
>> > as an opaque handle, without any dereferencing, etc)
>>
>> Agreed.
>>
>> > I think it'd be really good to have some discussion on discourse about
>> > if/how some of these cleanups could be formed into a way to
>> > enforce/encourage the invariant to be maintained going forward -
>> > clang-tidy (assuming that's the basis for the tooling Kazu's using to
>> > make these changes in the first place) integration into the LLVM build
>> > in some way, etc.
>>
>> I think that's a good idea! We want to encourage cleanups, but we
>> don't want to encourage churn, and I think it's somewhat subjective
>> where to draw that line. Having some more community awareness around
>> that would be beneficial. I'm especially interested in how we balance
>> between making incremental style improvements to the project and
>> keeping our git blame logs useful. I'm seeing a lot more git blames
>> that require several steps to get to an interesting commit because of
>> the number of NFCs and reverts/recommits. Unfortunately, the tooling
>> around viewing git blames of large files (like Clang tends to have)
>> makes these sorts of commits surprisingly painful when you do have to
>> dig to see where changes came from. (So I find myself having far less
>> concern when TransGCAttrs.cpp (~350LoC) gets a cleanup like this
>> compared to SemaExpr.cpp (~21kLoC), which suggests to me we should
>> maybe strongly consider splitting more of these massive files up so
>> that churn is less painful.)
>>
>> > & yeah, 

Re: [clang] 0e5813b - [clang][NFC] silences warnings

2022-09-08 Thread David Blaikie via cfe-commits
On Fri, Aug 26, 2022 at 2:10 PM Christopher Di Bella via cfe-commits
 wrote:
>
>
> Author: Abraham Corea Diaz
> Date: 2022-08-26T21:09:39Z
> New Revision: 0e5813b88e50576940070003e093d696390a6959
>
> URL: 
> https://github.com/llvm/llvm-project/commit/0e5813b88e50576940070003e093d696390a6959
> DIFF: 
> https://github.com/llvm/llvm-project/commit/0e5813b88e50576940070003e093d696390a6959.diff
>
> LOG: [clang][NFC] silences warnings
>
> * removes unused data member `OS` from `SARIFDiagnostic`
> * flags `Filename` variable as currently unused
>
> This is a follow-up to D131632.
>
> Added:
>
>
> Modified:
> clang/include/clang/Frontend/SARIFDiagnostic.h
> clang/lib/Frontend/SARIFDiagnostic.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/Frontend/SARIFDiagnostic.h 
> b/clang/include/clang/Frontend/SARIFDiagnostic.h
> index bd0f1df9aa58..ec1d0b8e6a7c 100644
> --- a/clang/include/clang/Frontend/SARIFDiagnostic.h
> +++ b/clang/include/clang/Frontend/SARIFDiagnostic.h
> @@ -55,8 +55,6 @@ class SARIFDiagnostic : public DiagnosticRenderer {
>StringRef ModuleName) override;
>
>  private:
> -  raw_ostream 
> -
>// Shared between SARIFDiagnosticPrinter and this renderer.
>SarifDocumentWriter *Writer;
>
>
> diff  --git a/clang/lib/Frontend/SARIFDiagnostic.cpp 
> b/clang/lib/Frontend/SARIFDiagnostic.cpp
> index 2bcbd5cf34f2..f0f32a179825 100644
> --- a/clang/lib/Frontend/SARIFDiagnostic.cpp
> +++ b/clang/lib/Frontend/SARIFDiagnostic.cpp
> @@ -33,7 +33,7 @@ namespace clang {
>  SARIFDiagnostic::SARIFDiagnostic(raw_ostream , const LangOptions 
> ,
>   DiagnosticOptions *DiagOpts,
>   SarifDocumentWriter *Writer)
> -: DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), Writer(Writer) {}
> +: DiagnosticRenderer(LangOpts, DiagOpts), Writer(Writer) {}
>
>  // FIXME(llvm-project/issues/57323): Refactor Diagnostic classes.
>  void SARIFDiagnostic::emitDiagnosticMessage(
> @@ -71,7 +71,8 @@ SarifResult SARIFDiagnostic::addLocationToResult(
>  FileID FID = Loc.getFileID();
>  if (FID.isValid()) {
>if (const FileEntry *FE = Loc.getFileEntry()) {
> -emitFilename(FE->getName(), Loc.getManager());
> +[[gnu::unused]] llvm::StringRef Filename =

Does this not cause warnings on an MSVC build for an unknown
attribute? (there's a whole issue with unknown attributes and how to
diagnose them)

I think it's probably best in general to leave the variable out until it's used.

> +emitFilename(FE->getName(), Loc.getManager());
>  // FIXME(llvm-project/issues/57366): File-only locations
>}
>  }
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] b7a7aee - [clang] Qualify auto in range-based for loops (NFC)

2022-09-08 Thread David Blaikie via cfe-commits
Mixed feelings here - Kazu's made a lot of cleanup/stylistic changes
across the LLVM project for a while now, most, at least I think, are
quite welcome (things like switching to range-based-for, std
algorithms over llvm ones, llvm algorithms over manually written
loops, etc). But yeah, there's some threshold below which the churn
might not be worth the benefit - especially if the change doesn't come
along with tooling to enforce the invariant is maintained in the
future (if it's easy to make mistakes like this one - we'll regress it
and need to do cleanup again in the future)

Also, for this particular one, I wonder if in some cases this sort of
automatic transformation isn't ideal - if something is a pointer, but
that's an implementation detail, rather than an intentional feature of
an API (eg: the pointer-ness might be hidden behind a typedef and used
as an opaque handle, without any dereferencing, etc)

I think it'd be really good to have some discussion on discourse about
if/how some of these cleanups could be formed into a way to
enforce/encourage the invariant to be maintained going forward -
clang-tidy (assuming that's the basis for the tooling Kazu's using to
make these changes in the first place) integration into the LLVM build
in some way, etc.

& yeah, adding the `const` too if/when that's relevant would've
improved the quality/value/justification for a cleanup change like
this.

On Sun, Sep 4, 2022 at 5:58 AM Aaron Ballman via cfe-commits
 wrote:
>
> FWIW, sweeping NFC changes like this cause a fair amount of code churn
> (which makes tools like git blame a bit harder to use) for a
> relatively small improvement to code readability, which is why our
> developer policy asks that you "Avoid committing formatting- or
> whitespace-only changes outside of code you plan to make subsequent
> changes to." In the future, I'd caution against doing such large-scale
> sweeping NFC changes outside of areas you're actively working on
> unless there's some wider discussion with the community first. That
> said, all of your changes are all improvements, so thank you for them!
>
> Some of the changes you made would have ideally made it more clear
> when the deduced type is a pointer to a const object instead of hiding
> the qualifier behind the deduction. I've pointed out a couple such
> places below, but don't feel obligated to go back and change anything
> unless you're going to be touching other code in the area.
>
> ~Aaron
>
>
> On Sun, Sep 4, 2022 at 2:27 AM Kazu Hirata via cfe-commits
>  wrote:
> >
> >
> > Author: Kazu Hirata
> > Date: 2022-09-03T23:27:27-07:00
> > New Revision: b7a7aeee90cffefd0f73b8d9f44ab4d1d5123d05
> >
> > URL: 
> > https://github.com/llvm/llvm-project/commit/b7a7aeee90cffefd0f73b8d9f44ab4d1d5123d05
> > DIFF: 
> > https://github.com/llvm/llvm-project/commit/b7a7aeee90cffefd0f73b8d9f44ab4d1d5123d05.diff
> >
> > LOG: [clang] Qualify auto in range-based for loops (NFC)
> >
> > Added:
> >
> >
> > Modified:
> > clang/lib/ARCMigrate/ObjCMT.cpp
> > clang/lib/ARCMigrate/TransGCAttrs.cpp
> > clang/lib/AST/ASTContext.cpp
> > clang/lib/AST/ASTImporter.cpp
> > clang/lib/AST/Decl.cpp
> > clang/lib/AST/DeclObjC.cpp
> > clang/lib/AST/ODRHash.cpp
> > clang/lib/AST/OpenMPClause.cpp
> > clang/lib/AST/StmtProfile.cpp
> > clang/lib/AST/Type.cpp
> > clang/lib/Analysis/CFG.cpp
> > clang/lib/Analysis/ThreadSafetyCommon.cpp
> > clang/lib/CodeGen/CGBlocks.cpp
> > clang/lib/CodeGen/CGCall.cpp
> > clang/lib/CodeGen/CGClass.cpp
> > clang/lib/CodeGen/CGDebugInfo.cpp
> > clang/lib/CodeGen/CGDeclCXX.cpp
> > clang/lib/CodeGen/CGExpr.cpp
> > clang/lib/CodeGen/CGObjCGNU.cpp
> > clang/lib/CodeGen/CGObjCMac.cpp
> > clang/lib/CodeGen/CodeGenFunction.cpp
> > clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
> > clang/lib/CodeGen/SwiftCallingConv.cpp
> > clang/lib/Driver/Compilation.cpp
> > clang/lib/Driver/Driver.cpp
> > clang/lib/Driver/ToolChains/Clang.cpp
> > clang/lib/Driver/ToolChains/CommonArgs.cpp
> > clang/lib/Driver/ToolChains/Gnu.cpp
> > clang/lib/Driver/ToolChains/HIPAMD.cpp
> > clang/lib/Format/Format.cpp
> > clang/lib/Frontend/FrontendActions.cpp
> > clang/lib/Index/USRGeneration.cpp
> > clang/lib/Sema/IdentifierResolver.cpp
> > clang/lib/Sema/Sema.cpp
> > clang/lib/Sema/SemaCodeComplete.cpp
> > clang/lib/Sema/SemaDecl.cpp
> > clang/lib/Sema/SemaDeclAttr.cpp
> > clang/lib/Sema/SemaDeclCXX.cpp
> > clang/lib/Sema/SemaDeclObjC.cpp
> > clang/lib/Sema/SemaExpr.cpp
> > clang/lib/Sema/SemaExprCXX.cpp
> > clang/lib/Sema/SemaInit.cpp
> > clang/lib/Sema/SemaLambda.cpp
> > clang/lib/Sema/SemaLookup.cpp
> > clang/lib/Sema/SemaObjCProperty.cpp
> > clang/lib/Sema/SemaOpenMP.cpp
> > clang/lib/Sema/SemaOverload.cpp
> > clang/lib/Sema/SemaTemplateDeduction.cpp
> > clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
> > 

Re: [clang] acaf6b9 - [NFC] Add [[maybe_unused]] to avoid warning in gcc9

2022-08-23 Thread David Blaikie via cfe-commits
Thanks for the link - fair enough. We'll see how ubiquitous the
constexpr-creating-sort-of-unused-variables situation is. If it comes
up a lot we might want to disable the warning for GCC 9.

On Mon, Aug 22, 2022 at 7:58 PM chuanqi.xcq  wrote:
>
> Hi David,
>
>   This is the reproduce link from godbolt: https://godbolt.org/z/nEc7WYKnq. 
> It is weird that it requries `-Wunused-but-set-parameter` instead of 
> `-Wunused-parameter`. The bug exists in all versions of GCC9. And it gets 
> fixed in GCC10 and later. Personally, I feel it looks better to suppress the 
> warning for GCC9.
>
> Thanks,
> Chuanqi
>
> --
> From:David Blaikie 
> Send Time:2022年8月23日(星期二) 07:22
> To:Chuanqi Xu ; Chuanqi Xu 
> Cc:cfe-commits 
> Subject:Re: [clang] acaf6b9 - [NFC] Add [[maybe_unused]] to avoid warning in 
> gcc9
>
> Seems like a bug in the GCC9 warning - any chance we can disable it?
> (is it fixed in later versions of GCC?)
>
> I can't seem to reproduce this with godbolt at least with basic
> examples - it'd be good to know how bad the thing is we're working
> around so we know if we want to keep working around it, or suppress
> the warning for certainly compiler versions entirely.
>
> On Thu, Aug 18, 2022 at 11:43 PM Chuanqi Xu via cfe-commits
>  wrote:
> >
> >
> > Author: Chuanqi Xu
> > Date: 2022-08-19T14:43:22+08:00
> > New Revision: acaf6b9dc07de3c12c8a1a55fd8674bca547a917
> >
> > URL: 
> > https://github.com/llvm/llvm-project/commit/acaf6b9dc07de3c12c8a1a55fd8674bca547a917
> > DIFF: 
> > https://github.com/llvm/llvm-project/commit/acaf6b9dc07de3c12c8a1a55fd8674bca547a917.diff
> >
> > LOG: [NFC] Add [[maybe_unused]] to avoid warning in gcc9
> >
> > GCC9 may issue warning for the 'unused' parameters in if constexpr.
> > This commit try to fix it by adding the [[maybe_unused]] attribute.
> >
> > Added:
> >
> >
> > Modified:
> > clang/include/clang/AST/RecursiveASTVisitor.h
> >
> > Removed:
> >
> >
> >
> > 
> > diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
> > b/clang/include/clang/AST/RecursiveASTVisitor.h
> > index 91baad51b26e..bd7fadb87c5f 100644
> > --- a/clang/include/clang/AST/RecursiveASTVisitor.h
> > +++ b/clang/include/clang/AST/RecursiveASTVisitor.h
> > @@ -73,7 +73,8 @@ struct has_same_member_pointer_type > (U::*)(P...)>
> >  /// are pointers to the same non-static member function.
> >  template 
> >  LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto
> > -isSameMethod(FirstMethodPtrTy FirstMethodPtr, SecondMethodPtrTy 
> > SecondMethodPtr)
> > +isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr,
> > + [[maybe_unused]] SecondMethodPtrTy SecondMethodPtr)
> >  -> bool {
> >if constexpr (has_same_member_pointer_type >   SecondMethodPtrTy>::value)
> >
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] acaf6b9 - [NFC] Add [[maybe_unused]] to avoid warning in gcc9

2022-08-22 Thread David Blaikie via cfe-commits
Seems like a bug in the GCC9 warning - any chance we can disable it?
(is it fixed in later versions of GCC?)

I can't seem to reproduce this with godbolt at least with basic
examples - it'd be good to know how bad the thing is we're working
around so we know if we want to keep working around it, or suppress
the warning for certainly compiler versions entirely.

On Thu, Aug 18, 2022 at 11:43 PM Chuanqi Xu via cfe-commits
 wrote:
>
>
> Author: Chuanqi Xu
> Date: 2022-08-19T14:43:22+08:00
> New Revision: acaf6b9dc07de3c12c8a1a55fd8674bca547a917
>
> URL: 
> https://github.com/llvm/llvm-project/commit/acaf6b9dc07de3c12c8a1a55fd8674bca547a917
> DIFF: 
> https://github.com/llvm/llvm-project/commit/acaf6b9dc07de3c12c8a1a55fd8674bca547a917.diff
>
> LOG: [NFC] Add [[maybe_unused]] to avoid warning in gcc9
>
> GCC9 may issue warning for the 'unused' parameters in if constexpr.
> This commit try to fix it by adding the [[maybe_unused]] attribute.
>
> Added:
>
>
> Modified:
> clang/include/clang/AST/RecursiveASTVisitor.h
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
> b/clang/include/clang/AST/RecursiveASTVisitor.h
> index 91baad51b26e..bd7fadb87c5f 100644
> --- a/clang/include/clang/AST/RecursiveASTVisitor.h
> +++ b/clang/include/clang/AST/RecursiveASTVisitor.h
> @@ -73,7 +73,8 @@ struct has_same_member_pointer_type (U::*)(P...)>
>  /// are pointers to the same non-static member function.
>  template 
>  LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto
> -isSameMethod(FirstMethodPtrTy FirstMethodPtr, SecondMethodPtrTy 
> SecondMethodPtr)
> +isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr,
> + [[maybe_unused]] SecondMethodPtrTy SecondMethodPtr)
>  -> bool {
>if constexpr (has_same_member_pointer_type   SecondMethodPtrTy>::value)
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d4e0fe6 - Simplify RAV isSameMethod with constexpr if

2022-08-18 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-08-19T04:00:21Z
New Revision: d4e0fe62b1aa090527c0cc289cdf3eef0370f064

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

LOG: Simplify RAV isSameMethod with constexpr if

Owing to the large number of instantiations of this function, this small
change has a small but meaningful difference on the total size of
(especially a debug) build of clang at -O0:
```
FILE SIZEVM SIZE
 --  --
  +0.9% +96.9Ki  +0.9% +96.9Ki.data.rel.ro
  +0.7% +96.7Ki  +0.7% +96.7Ki.rela.dyn
  +0.0% +18.3Ki  +0.0% +18.3Ki.rodata
  +0.0%+324  [ = ]   0[2 Others]
  -0.2%-392  -0.2%-392.gnu.version
  -0.0%-441  [ = ]   0.debug_abbrev
  -0.1%-980  -0.1%-980.gnu.hash
  -0.2% -1.53Ki  -0.2% -1.53Ki.hash
  -0.2% -4.59Ki  -0.2% -4.59Ki.dynsym
  -0.1% -10.5Ki  [ = ]   0.debug_rnglists
  -0.6% -59.0Ki  -0.6% -59.0Ki.dynstr
  -0.2%  -191Ki  [ = ]   0.debug_str_offsets
  -3.0%  -233Ki  -3.0%  -233Ki.eh_frame_hdr
  -0.7%  -244Ki  [ = ]   0.debug_addr
  -2.9%  -699Ki  [ = ]   0.symtab
  -0.6%  -884Ki  [ = ]   0.debug_line
  -3.0%  -932Ki  -3.0%  -932Ki.eh_frame
  -1.0% -1.48Mi  -1.0% -1.48Mi.text
  -0.6% -2.75Mi  [ = ]   0.debug_info
  -7.3% -8.61Mi  [ = ]   0.strtab
  -7.3% -17.2Mi  [ = ]   0.debug_str
  -2.4% -33.0Mi  -0.9% -2.47MiTOTAL
```

If anyone's got other ideas for how to reduce this further - it's not
especially important, I just came across it while investigating a debug
info size regression, but thought it was interesting enough to poke
around at.

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 6c6d5402d5d12..91baad51b26ea 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -69,30 +69,16 @@ template 
 struct has_same_member_pointer_type
 : std::true_type {};
 
-template  struct is_same_method_impl {
-  template 
-  static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
-   SecondMethodPtrTy SecondMethodPtr) {
-return false;
-  }
-};
-
-template <> struct is_same_method_impl {
-  template 
-  static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
-   SecondMethodPtrTy SecondMethodPtr) {
-return FirstMethodPtr == SecondMethodPtr;
-  }
-};
-
 /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
 /// are pointers to the same non-static member function.
 template 
-bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
-  SecondMethodPtrTy SecondMethodPtr) {
-  return is_same_method_impl::value>::isSameMethod(FirstMethodPtr, 
SecondMethodPtr);
+LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto
+isSameMethod(FirstMethodPtrTy FirstMethodPtr, SecondMethodPtrTy 
SecondMethodPtr)
+-> bool {
+  if constexpr (has_same_member_pointer_type::value)
+return FirstMethodPtr == SecondMethodPtr;
+  return false;
 }
 
 } // end namespace detail



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


[clang] 06c70e9 - DebugInfo: Remove auto return type representation support

2022-08-16 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-08-17T00:35:05Z
New Revision: 06c70e9b998ca289630ee1629ec09b6dd51b29b9

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

LOG: DebugInfo: Remove auto return type representation support

Seems this complicated lldb sufficiently for some cases that it hasn't
been worth supporting/fixing there - and it so far hasn't provided any
new use cases/value for debug info consumers, so let's remove it until
someone has a use case for it.

(side note: the original implementation of this still had a bug (I
should've caught it in review) that we still didn't produce
auto-returning function declarations in types where the function wasn't
instantiatied (that requires a fix to remove the `if
getContainedAutoType` condition in
`CGDebugInfo::CollectCXXMemberFunctions` - without that, auto returning
functions were still being handled the same as member function templates
and special member functions - never added to the member list, only
attached to the type via the declaration chain from the definition)

Further discussion about this in D123319

This reverts commit 5ff992bca208a0e37ca6338fc735aec6aa848b72: [DEBUG-INFO] 
Change how we handle auto return types for lambda operator() to be consistent 
with gcc

This reverts commit c83602fdf51b2692e3bacb06bf861f20f74e987f: [DWARF5][clang]: 
Added support for DebugInfo generation for auto return type for C++ member 
functions.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/test/CodeGenCXX/debug-info-auto-return.cpp

Removed: 
clang/test/CodeGenCXX/no_auto_return_lambda.cpp



diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0469de766d78c..3d78a13d30aa8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -883,10 +883,6 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
   return DBuilder.createBasicType(BTName, Size, Encoding);
 }
 
-llvm::DIType *CGDebugInfo::CreateType(const AutoType *Ty) {
-  return DBuilder.createUnspecifiedType("auto");
-}
-
 llvm::DIType *CGDebugInfo::CreateType(const BitIntType *Ty) {
 
   StringRef Name = Ty->isUnsigned() ? "unsigned _BitInt" : "_BitInt";
@@ -1647,18 +1643,16 @@ void CGDebugInfo::CollectRecordFields(
 
 llvm::DISubroutineType *
 CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
-   llvm::DIFile *Unit, bool decl) {
-  const auto *Func = Method->getType()->castAs();
+   llvm::DIFile *Unit) {
+  const FunctionProtoType *Func = 
Method->getType()->getAs();
   if (Method->isStatic())
 return cast_or_null(
 getOrCreateType(QualType(Func, 0), Unit));
-  return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit, 
decl);
+  return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit);
 }
 
-llvm::DISubroutineType *
-CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
-   const FunctionProtoType *Func,
-   llvm::DIFile *Unit, bool decl) {
+llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
+QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile *Unit) {
   FunctionProtoType::ExtProtoInfo EPI = Func->getExtProtoInfo();
   Qualifiers  = EPI.TypeQuals;
   Qc.removeConst();
@@ -1681,20 +1675,9 @@ CGDebugInfo::getOrCreateInstanceMethodType(QualType 
ThisPtr,
   assert(Args.size() && "Invalid number of arguments!");
 
   SmallVector Elts;
+
   // First element is always return type. For 'void' functions it is NULL.
-  QualType temp = Func->getReturnType();
-  if (temp->getTypeClass() == Type::Auto && decl) {
-const AutoType *AT = cast(temp);
-
-// It may be tricky in some cases to link the specification back the lambda
-// call operator and so we skip emitting "auto" for lambdas. This is
-// consistent with gcc as well.
-if (AT->isDeduced() && ThisPtr->getPointeeCXXRecordDecl()->isLambda())
-  Elts.push_back(getOrCreateType(AT->getDeducedType(), Unit));
-else
-  Elts.push_back(CreateType(AT));
-  } else
-Elts.push_back(Args[0]);
+  Elts.push_back(Args[0]);
 
   // "this" pointer is always first argument.
   const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
@@ -1747,7 +1730,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
   isa(Method) || isa(Method);
 
   StringRef MethodName = getFunctionName(Method);
-  llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit, true);
+  llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
 
   // Since a single ctor/dtor corresponds 

[clang] 4bb192b - DebugInfo: Test vtable homing overriding ctor homing only on itanium since msvc ABI doesn't home vtables

2022-07-27 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-07-28T00:45:00Z
New Revision: 4bb192b846854ab1dc49a2e4b2a2717a4e3a9b1e

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

LOG: DebugInfo: Test vtable homing overriding ctor homing only on itanium since 
msvc ABI doesn't home vtables

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index d17e3a142ad7..ac53cace075c 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -debug-info-kind=constructor -emit-llvm %s -o - | FileCheck 
%s
+// RUN: %clang_cc1 -debug-info-kind=constructor -triple x86_64-linux-gnu 
-emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s
 
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"A"{{.*}}DIFlagTypePassByValue
 struct A {
@@ -87,4 +88,4 @@ struct VTableAndCtor {
 VTableAndCtor::VTableAndCtor() {
 }
 
-// CHECK-DAG: !DICompositeType({{.*}}name: "VTableAndCtor", {{.*}}flags: 
DIFlagFwdDecl
+// ITANIUM-DAG: !DICompositeType({{.*}}name: "VTableAndCtor", {{.*}}flags: 
DIFlagFwdDecl



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


Re: [clang] 4821508 - Revert "DebugInfo: Fully integrate ctor type homing into 'limited' debug info"

2022-07-27 Thread David Blaikie via cfe-commits
Excuse the delay - yeah, pulled out the fix in
4e719e0f16933a8945a4e85db39fdad5afbede36

On Fri, Jul 1, 2022 at 7:21 AM Robinson, Paul  wrote:
>
> Hi Dave,
>
> The original commit message included
> Also fix a bug I found along the way that was causing ctor type homing
> to kick in even when something could be vtable homed
>
> Is it reasonable to fix that without removing ctor homing in general?
> Or would that cause too much test churn, as you're planning to recommit
> this patch anyway?
> --paulr
>
> > -Original Message-
> > From: cfe-commits  On Behalf Of David
> > Blaikie via cfe-commits
> > Sent: Friday, June 24, 2022 1:08 PM
> > To: cfe-commits@lists.llvm.org
> > Subject: [clang] 4821508 - Revert "DebugInfo: Fully integrate ctor type
> > homing into 'limited' debug info"
> >
> >
> > Author: David Blaikie
> > Date: 2022-06-24T17:07:47Z
> > New Revision: 4821508d4db75a535d02b8938f81fac6de66cc26
> >
> > URL: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> > project/commit/4821508d4db75a535d02b8938f81fac6de66cc26__;!!JmoZiZGBv3RvKR
> > Sx!7pmjZG0ponrxAVY0dOSOTgWfvxMgERh3TNpn2zRGr7NTuooxwQKHzTroRX39LtKaKCXGoQD
> > n3Ri4BOhJymrwDVc8Rzk$
> > DIFF: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> > project/commit/4821508d4db75a535d02b8938f81fac6de66cc26.diff__;!!JmoZiZGBv
> > 3RvKRSx!7pmjZG0ponrxAVY0dOSOTgWfvxMgERh3TNpn2zRGr7NTuooxwQKHzTroRX39LtKaKC
> > XGoQDn3Ri4BOhJymrwKAIx5Rg$
> >
> > LOG: Revert "DebugInfo: Fully integrate ctor type homing into 'limited'
> > debug info"
> >
> > Reverting to simplify some Google-internal rollout issues. Will recommit
> > in a week or two.
> >
> > This reverts commit 517bbc64dbe493644eff8d55fd9566435e930520.
> >
> > Added:
> > clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
> >
> > Modified:
> > clang/docs/UsersManual.rst
> > clang/include/clang/Basic/CodeGenOptions.h
> > clang/include/clang/Basic/DebugInfoOptions.h
> > clang/include/clang/Driver/Options.td
> > clang/lib/CodeGen/CGDebugInfo.cpp
> > clang/lib/Driver/ToolChains/Clang.cpp
> > clang/lib/Frontend/CompilerInvocation.cpp
> > clang/test/CodeGen/attr-cpuspecific-renaming.cpp
> > clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
> > clang/test/CodeGenCXX/debug-info-class.cpp
> > clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
> > clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
> > clang/test/CodeGenCXX/debug-lambda-this.cpp
> > clang/test/CodeGenCXX/ibm128-declarations.cpp
> > clang/test/CodeGenCXX/standalone-debug-attribute.cpp
> > clang/test/Driver/cl-options.c
> > clang/test/Driver/clang-g-opts.c
> > clang/test/Driver/cuda-dwarf-2.cu
> > clang/test/Driver/debug-options-as.c
> > clang/test/Driver/debug-options.c
> > clang/test/Driver/integrated-as.s
> > clang/test/Driver/myriad-toolchain.c
> > clang/test/Driver/openmp-offload-gpu.c
> > clang/test/Driver/split-debug.c
> > clang/test/OpenMP/debug_private.c
> > clang/test/OpenMP/debug_task_shared.c
> > clang/test/OpenMP/debug_threadprivate_copyin.c
> >
> > Removed:
> >
> >
> >
> > ##
> > ##
> > diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
> > index ccb5fed1cb370..e12dc72407b13 100644
> > --- a/clang/docs/UsersManual.rst
> > +++ b/clang/docs/UsersManual.rst
> > @@ -2672,6 +2672,19 @@ below. If multiple flags are present, the last one
> > is used.
> > **-fno-standalone-debug** option can be used to get to turn on the
> > vtable-based optimization described above.
> >
> > +.. option:: -fuse-ctor-homing
> > +
> > +   This optimization is similar to the optimizations that are enabled as
> > part
> > +   of -fno-standalone-debug. Here, Clang only emits type info for a
> > +   non-trivial, non-aggregate C++ class in the modules that contain a
> > +   definition of one of its constructors. This relies on the additional
> > +   assumption that all classes that are not trivially constructible have
> > a
> > +   non-trivial constructor that is used somewhere. The negation,
> > +   -fno-use-ctor-homing, ensures that constructor homing is not used.
> > +
> > +   This flag is not enabled by default, and needs to be used with -cc1 or
> > +   -Xclang.
> > +
> >  .. option:: -g
> >
>

[clang] 4e719e0 - DebugInfo: Prefer vtable homing over ctor homing.

2022-07-27 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-07-28T00:07:35Z
New Revision: 4e719e0f16933a8945a4e85db39fdad5afbede36

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

LOG: DebugInfo: Prefer vtable homing over ctor homing.

Vtables will be emitted in fewer places than ctors (every ctor
references the vtable, so at worst it's the same places - but at best
the type has a non-inline key function and the vtable is emitted in one
place)

Pulling this fix out of 517bbc64dbe493644eff8d55fd9566435e930520 which
was reverted in 4821508d4db75a535d02b8938f81fac6de66cc26

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 94c48316add7..6821fc97e504 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3351,7 +3351,7 @@ void CGDebugInfo::completeTemplateDefinition(
 }
 
 void CGDebugInfo::completeUnusedClass(const CXXRecordDecl ) {
-  if (DebugKind <= codegenoptions::DebugLineTablesOnly)
+  if (DebugKind <= codegenoptions::DebugLineTablesOnly || D.isDynamicClass())
 return;
 
   completeClassData();

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index 835e6d481622..d17e3a142ad7 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -77,3 +77,14 @@ void L() {
 // Check that types are being added to retained types list.
 // CHECK-DAG: !DICompileUnit{{.*}}retainedTypes: ![[RETAINED:[0-9]+]]
 // CHECK-DAG: ![[RETAINED]] = {{.*}}![[C]]
+
+
+struct VTableAndCtor {
+  virtual void f1();
+  VTableAndCtor();
+};
+
+VTableAndCtor::VTableAndCtor() {
+}
+
+// CHECK-DAG: !DICompositeType({{.*}}name: "VTableAndCtor", {{.*}}flags: 
DIFlagFwdDecl



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


[clang] 4821508 - Revert "DebugInfo: Fully integrate ctor type homing into 'limited' debug info"

2022-06-24 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-06-24T17:07:47Z
New Revision: 4821508d4db75a535d02b8938f81fac6de66cc26

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

LOG: Revert "DebugInfo: Fully integrate ctor type homing into 'limited' debug 
info"

Reverting to simplify some Google-internal rollout issues. Will recommit
in a week or two.

This reverts commit 517bbc64dbe493644eff8d55fd9566435e930520.

Added: 
clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DebugInfoOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/attr-cpuspecific-renaming.cpp
clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
clang/test/CodeGenCXX/debug-info-class.cpp
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
clang/test/CodeGenCXX/ibm128-declarations.cpp
clang/test/CodeGenCXX/standalone-debug-attribute.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
clang/test/OpenMP/debug_private.c
clang/test/OpenMP/debug_task_shared.c
clang/test/OpenMP/debug_threadprivate_copyin.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index ccb5fed1cb370..e12dc72407b13 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2672,6 +2672,19 @@ below. If multiple flags are present, the last one is 
used.
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
+.. option:: -fuse-ctor-homing
+
+   This optimization is similar to the optimizations that are enabled as part
+   of -fno-standalone-debug. Here, Clang only emits type info for a
+   non-trivial, non-aggregate C++ class in the modules that contain a
+   definition of one of its constructors. This relies on the additional
+   assumption that all classes that are not trivially constructible have a
+   non-trivial constructor that is used somewhere. The negation,
+   -fno-use-ctor-homing, ensures that constructor homing is not used.
+
+   This flag is not enabled by default, and needs to be used with -cc1 or
+   -Xclang.
+
 .. option:: -g
 
   Generate complete debug info.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 5f5218c87a605..23d76c308d847 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -468,7 +468,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if type and variable info should be emitted.
   bool hasReducedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::LimitedDebugInfo;
+return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
   }
 
   /// Check if maybe unused type info should be emitted.

diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index 98210cc3cfa13..a99a2b5903d7e 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -34,6 +34,12 @@ enum DebugInfoKind {
   /// (-gline-tables-only).
   DebugLineTablesOnly,
 
+  /// Limit generated debug info for classes to reduce size. This emits class
+  /// type info only where the constructor is emitted, if it is a class that
+  /// has a constructor.
+  /// FIXME: Consider combining this with LimitedDebugInfo.
+  DebugInfoConstructor,
+
   /// Limit generated debug info to reduce size (-fno-standalone-debug). This
   /// emits forward decls for types that could be replaced with forward decls 
in
   /// the source code. For dynamic C++ classes type info is only emitted into

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e998612d32e2e..81d1d53cea9b1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5246,6 +5246,11 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
 def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
   HelpText<"Disable implicit builtin knowledge of math functions">,
   MarshallingInfoFlag>;
+def fno_use_ctor_homing: Flag<["-"], "fno-use-ctor-homing">,
+HelpText<"Don't 

[clang] 517bbc6 - DebugInfo: Fully integrate ctor type homing into 'limited' debug info

2022-06-23 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-06-23T20:15:00Z
New Revision: 517bbc64dbe493644eff8d55fd9566435e930520

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

LOG: DebugInfo: Fully integrate ctor type homing into 'limited' debug info

Simplify debug info back to just "limited" or "full" by rolling the ctor
type homing fully into the "limited" debug info.

Also fix a bug I found along the way that was causing ctor type homing
to kick in even when something could be vtable homed (where vtable
homing is stronger/more effective than ctor homing) - fixing at the same
time as it keeps the tests (that were testing only "limited non ctor"
homing and now test ctor homing) passing.

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DebugInfoOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/attr-cpuspecific-renaming.cpp
clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
clang/test/CodeGenCXX/debug-info-class.cpp
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
clang/test/CodeGenCXX/ibm128-declarations.cpp
clang/test/CodeGenCXX/standalone-debug-attribute.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
clang/test/OpenMP/debug_private.c
clang/test/OpenMP/debug_task_shared.c
clang/test/OpenMP/debug_threadprivate_copyin.c

Removed: 
clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp



diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e12dc72407b13..ccb5fed1cb370 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2672,19 +2672,6 @@ below. If multiple flags are present, the last one is 
used.
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
-.. option:: -fuse-ctor-homing
-
-   This optimization is similar to the optimizations that are enabled as part
-   of -fno-standalone-debug. Here, Clang only emits type info for a
-   non-trivial, non-aggregate C++ class in the modules that contain a
-   definition of one of its constructors. This relies on the additional
-   assumption that all classes that are not trivially constructible have a
-   non-trivial constructor that is used somewhere. The negation,
-   -fno-use-ctor-homing, ensures that constructor homing is not used.
-
-   This flag is not enabled by default, and needs to be used with -cc1 or
-   -Xclang.
-
 .. option:: -g
 
   Generate complete debug info.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 23d76c308d847..5f5218c87a605 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -468,7 +468,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if type and variable info should be emitted.
   bool hasReducedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
+return getDebugInfo() >= codegenoptions::LimitedDebugInfo;
   }
 
   /// Check if maybe unused type info should be emitted.

diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index a99a2b5903d7e..98210cc3cfa13 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -34,12 +34,6 @@ enum DebugInfoKind {
   /// (-gline-tables-only).
   DebugLineTablesOnly,
 
-  /// Limit generated debug info for classes to reduce size. This emits class
-  /// type info only where the constructor is emitted, if it is a class that
-  /// has a constructor.
-  /// FIXME: Consider combining this with LimitedDebugInfo.
-  DebugInfoConstructor,
-
   /// Limit generated debug info to reduce size (-fno-standalone-debug). This
   /// emits forward decls for types that could be replaced with forward decls 
in
   /// the source code. For dynamic C++ classes type info is only emitted into

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5410b5d3e617f..3036668390cad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5234,11 +5234,6 @@ def 

Re: [clang] d4bcb45 - [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible

2022-06-13 Thread David Blaikie via cfe-commits
Please include details of what changed between one commit and a recommit of
a patch - helpful for reviewers checking what's changed since the last
commit, double-checking that the patch fully addresses the issues, etc.

On Sun, Jun 12, 2022 at 2:24 PM Jez Ng via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Jez Ng
> Date: 2022-06-12T17:24:19-04:00
> New Revision: d4bcb45db78dc7ca371224cb01bea8dcb14e0698
>
> URL:
> https://github.com/llvm/llvm-project/commit/d4bcb45db78dc7ca371224cb01bea8dcb14e0698
> DIFF:
> https://github.com/llvm/llvm-project/commit/d4bcb45db78dc7ca371224cb01bea8dcb14e0698.diff
>
> LOG: [MC][re-land] Omit DWARF unwind info if compact unwind is present
> where eligible
>
> This reverts commit d941d597837d9e1405086f008c9bd6a71e7263c9.
>
> Differential Revision: https://reviews.llvm.org/D122258
>
> Added:
> clang/test/Driver/femit-dwarf-unwind.c
> clang/test/Driver/femit-dwarf-unwind.s
> llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
> llvm/test/MC/X86/compact-unwind-mode-dwarf.s
>
> Modified:
> clang/include/clang/Basic/CodeGenOptions.def
> clang/include/clang/Driver/Options.td
> clang/lib/CodeGen/BackendUtil.cpp
> clang/lib/Driver/ToolChains/Clang.cpp
> clang/tools/driver/cc1as_main.cpp
> llvm/include/llvm/MC/MCContext.h
> llvm/include/llvm/MC/MCTargetOptions.h
> llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
> llvm/lib/CodeGen/LLVMTargetMachine.cpp
> llvm/lib/CodeGen/MachineModuleInfo.cpp
> llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
> llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
> llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
> llvm/lib/MC/MCContext.cpp
> llvm/lib/MC/MCDwarf.cpp
> llvm/lib/MC/MCObjectFileInfo.cpp
> llvm/lib/MC/MCTargetOptions.cpp
> llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
> llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/CodeGenOptions.def
> b/clang/include/clang/Basic/CodeGenOptions.def
> index d8f667dc387bb..8e89106993c26 100644
> --- a/clang/include/clang/Basic/CodeGenOptions.def
> +++ b/clang/include/clang/Basic/CodeGenOptions.def
> @@ -114,6 +114,10 @@ CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when
> -fstack-size-section is enabl
>  CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when
> -fforce-dwarf-frame is
>///< enabled.
>
> +///< Set when -femit-dwarf-unwind is passed.
> +ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
> +llvm::EmitDwarfUnwindType::Default)
> +
>  ///< Set when -fxray-always-emit-customevents is enabled.
>  CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)
>
>
> diff  --git a/clang/include/clang/Driver/Options.td
> b/clang/include/clang/Driver/Options.td
> index 95840760f7746..002cd6cc8cb17 100644
> --- a/clang/include/clang/Driver/Options.td
> +++ b/clang/include/clang/Driver/Options.td
> @@ -3044,6 +3044,13 @@ def fmacro_prefix_map_EQ
>  defm force_dwarf_frame : BoolFOption<"force-dwarf-frame",
>CodeGenOpts<"ForceDwarfFrameSection">, DefaultFalse,
>PosFlag,
> NegFlag>;
> +def femit_dwarf_unwind_EQ : Joined<["-"], "femit-dwarf-unwind=">,
> +  Group, Flags<[CC1Option, CC1AsOption]>,
> +  HelpText<"When to emit DWARF unwind (EH frame) info">,
> +  Values<"always,no-compact-unwind,default">,
> +  NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,
> +  NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
> +  MarshallingInfoEnum, "Default">;
>  def g_Flag : Flag<["-"], "g">, Group,
>HelpText<"Generate source-level debug information">;
>  def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
>
> diff  --git a/clang/lib/CodeGen/BackendUtil.cpp
> b/clang/lib/CodeGen/BackendUtil.cpp
> index 0de15b1e48078..4b294c254e476 100644
> --- a/clang/lib/CodeGen/BackendUtil.cpp
> +++ b/clang/lib/CodeGen/BackendUtil.cpp
> @@ -453,6 +453,7 @@ static bool initTargetOptions(DiagnosticsEngine ,
>}
>
>Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
> +  Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
>Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
>Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
>Options.MCOptions.MCUseDwarfDirectory =
>
> diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp
> b/clang/lib/Driver/ToolChains/Clang.cpp
> index ceac142653ebe..62e891ce38c49 100644
> --- a/clang/lib/Driver/ToolChains/Clang.cpp
> +++ b/clang/lib/Driver/ToolChains/Clang.cpp
> @@ -2518,6 +2518,8 @@ static void
> CollectArgsForIntegratedAssembler(Compilation ,
> DefaultIncrementalLinkerCompatible))
>  CmdArgs.push_back("-mincremental-linker-compatible");
>
> +  Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);
> +
>// If you add more args here, also add them to the block below that

Re: [clang] d941d59 - Revert "[MC] Omit DWARF unwind info if compact unwind is present where eligible"

2022-06-13 Thread David Blaikie via cfe-commits
Please include details about the reason for a revert in the revert commit
message - helpful for folks following along/looking to see if a given
revert addresses an issue they're seeing, etc.

On Sun, Jun 12, 2022 at 7:47 AM Jez Ng via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Jez Ng
> Date: 2022-06-12T10:47:08-04:00
> New Revision: d941d597837d9e1405086f008c9bd6a71e7263c9
>
> URL:
> https://github.com/llvm/llvm-project/commit/d941d597837d9e1405086f008c9bd6a71e7263c9
> DIFF:
> https://github.com/llvm/llvm-project/commit/d941d597837d9e1405086f008c9bd6a71e7263c9.diff
>
> LOG: Revert "[MC] Omit DWARF unwind info if compact unwind is present
> where eligible"
>
> This reverts commit ef501bf85d8c869248e51371f0e74bcec0e7b229.
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/CodeGenOptions.def
> clang/include/clang/Driver/Options.td
> clang/lib/CodeGen/BackendUtil.cpp
> clang/lib/Driver/ToolChains/Clang.cpp
> clang/tools/driver/cc1as_main.cpp
> llvm/include/llvm/MC/MCContext.h
> llvm/include/llvm/MC/MCTargetOptions.h
> llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
> llvm/lib/CodeGen/LLVMTargetMachine.cpp
> llvm/lib/CodeGen/MachineModuleInfo.cpp
> llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
> llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
> llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
> llvm/lib/MC/MCContext.cpp
> llvm/lib/MC/MCDwarf.cpp
> llvm/lib/MC/MCObjectFileInfo.cpp
> llvm/lib/MC/MCTargetOptions.cpp
> llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
> llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
>
> Removed:
> clang/test/Driver/femit-dwarf-unwind.c
> clang/test/Driver/femit-dwarf-unwind.s
> llvm/test/MC/MachO/emit-dwarf-unwind.s
> llvm/test/MC/X86/compact-unwind-mode-dwarf.s
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/CodeGenOptions.def
> b/clang/include/clang/Basic/CodeGenOptions.def
> index 8e89106993c26..d8f667dc387bb 100644
> --- a/clang/include/clang/Basic/CodeGenOptions.def
> +++ b/clang/include/clang/Basic/CodeGenOptions.def
> @@ -114,10 +114,6 @@ CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when
> -fstack-size-section is enabl
>  CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when
> -fforce-dwarf-frame is
>///< enabled.
>
> -///< Set when -femit-dwarf-unwind is passed.
> -ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
> -llvm::EmitDwarfUnwindType::Default)
> -
>  ///< Set when -fxray-always-emit-customevents is enabled.
>  CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)
>
>
> diff  --git a/clang/include/clang/Driver/Options.td
> b/clang/include/clang/Driver/Options.td
> index 002cd6cc8cb17..95840760f7746 100644
> --- a/clang/include/clang/Driver/Options.td
> +++ b/clang/include/clang/Driver/Options.td
> @@ -3044,13 +3044,6 @@ def fmacro_prefix_map_EQ
>  defm force_dwarf_frame : BoolFOption<"force-dwarf-frame",
>CodeGenOpts<"ForceDwarfFrameSection">, DefaultFalse,
>PosFlag,
> NegFlag>;
> -def femit_dwarf_unwind_EQ : Joined<["-"], "femit-dwarf-unwind=">,
> -  Group, Flags<[CC1Option, CC1AsOption]>,
> -  HelpText<"When to emit DWARF unwind (EH frame) info">,
> -  Values<"always,no-compact-unwind,default">,
> -  NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,
> -  NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
> -  MarshallingInfoEnum, "Default">;
>  def g_Flag : Flag<["-"], "g">, Group,
>HelpText<"Generate source-level debug information">;
>  def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
>
> diff  --git a/clang/lib/CodeGen/BackendUtil.cpp
> b/clang/lib/CodeGen/BackendUtil.cpp
> index 4b294c254e476..0de15b1e48078 100644
> --- a/clang/lib/CodeGen/BackendUtil.cpp
> +++ b/clang/lib/CodeGen/BackendUtil.cpp
> @@ -453,7 +453,6 @@ static bool initTargetOptions(DiagnosticsEngine ,
>}
>
>Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
> -  Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
>Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
>Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
>Options.MCOptions.MCUseDwarfDirectory =
>
> diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp
> b/clang/lib/Driver/ToolChains/Clang.cpp
> index 62e891ce38c49..ceac142653ebe 100644
> --- a/clang/lib/Driver/ToolChains/Clang.cpp
> +++ b/clang/lib/Driver/ToolChains/Clang.cpp
> @@ -2518,8 +2518,6 @@ static void
> CollectArgsForIntegratedAssembler(Compilation ,
> DefaultIncrementalLinkerCompatible))
>  CmdArgs.push_back("-mincremental-linker-compatible");
>
> -  Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);
> -
>// If you add more args here, also add them to the block below that
>// starts with "// If CollectArgsForIntegratedAssembler() isn't called
> below".
>
> @@ 

Re: [clang] f13019f - [clang] Use any_of and none_of (NFC)

2022-06-13 Thread David Blaikie via cfe-commits
On Sun, Jun 12, 2022 at 10:17 AM Kazu Hirata via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Kazu Hirata
> Date: 2022-06-12T10:17:12-07:00
> New Revision: f13019f8367a417075e70effb13dcf58024090b2
>
> URL:
> https://github.com/llvm/llvm-project/commit/f13019f8367a417075e70effb13dcf58024090b2
> DIFF:
> https://github.com/llvm/llvm-project/commit/f13019f8367a417075e70effb13dcf58024090b2.diff
>
> LOG: [clang] Use any_of and none_of (NFC)
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/Attr.td
> clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
> clang/lib/Sema/SemaDeclCXX.cpp
> clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/Attr.td
> b/clang/include/clang/Basic/Attr.td
> index d1f407259cb6e..16384969f68e4 100644
> --- a/clang/include/clang/Basic/Attr.td
> +++ b/clang/include/clang/Basic/Attr.td
> @@ -1926,9 +1926,9 @@ def NonNull : InheritableParamAttr {
>  bool isNonNull(unsigned IdxAST) const {
>if (!args_size())
>  return true;
> -  return args_end() != std::find_if(
> -  args_begin(), args_end(),
> -  [=](const ParamIdx ) { return Idx.getASTIndex() == IdxAST;
> });
> +  return llvm::any_of(args(), [=](const ParamIdx ) {
> +return Idx.getASTIndex() == IdxAST;
> +  });
>

Generally, I think for locally scoped lambdas (lambdas that don't escape
their scope) we should prefer/default to default reference capture (`[&]`)
- it simplifies changes in the future. Would that be OK for these sort of
cleanups?


>  }
>}];
>// FIXME: We should merge duplicates into a single nonnull attribute.
>
> diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
> b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
> index a7b0a1ac98a78..bffa66c2d9448 100644
> --- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
> +++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
> @@ -199,11 +199,11 @@ struct LocationFileChecker {
>  // Try to reduce the include name the same way we tried to include it.
>  bool IsQuoted = false;
>  if (auto IncludeName = getRelativeIncludeName(CI, FileName,
> ))
> -  if (llvm::find_if(KnownFiles,
> -[, ](const auto ) {
> -  return KnownFile.first.equals(*IncludeName) &&
> - KnownFile.second == IsQuoted;
> -}) != KnownFiles.end()) {
> +  if (llvm::any_of(KnownFiles,
> +   [, ](const auto ) {
> + return KnownFile.first.equals(*IncludeName) &&
> +KnownFile.second == IsQuoted;
> +   })) {
>  KnownFileEntries.insert(File);
>  return true;
>}
>
> diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp
> b/clang/lib/Sema/SemaDeclCXX.cpp
> index 569b226da9233..214332e53c0f0 100644
> --- a/clang/lib/Sema/SemaDeclCXX.cpp
> +++ b/clang/lib/Sema/SemaDeclCXX.cpp
> @@ -8617,10 +8617,10 @@ bool
> Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
>  int(1)))
>return true;
>
> -if (llvm::find_if(RD->friends(), [&](const FriendDecl *F) {
> +if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
>return FD->getCanonicalDecl() ==
>   F->getFriendDecl()->getCanonicalDecl();
> -}) == RD->friends().end()) {
> +})) {
>Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
><< int(DCK) << int(0) << RD;
>Diag(RD->getCanonicalDecl()->getLocation(), diag::note_declared_at);
>
> diff  --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
> b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
> index 528284ca89858..9ee6ef4f9519f 100644
> --- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
> +++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
> @@ -480,9 +480,7 @@ static void isOptionContainedIn(const
> CmdLineOptionList ,
>  return Opt.OptionName == SuppliedOption;
>};
>
> -  const auto *OptionIt = llvm::find_if(OptionList, SameOptName);
> -
> -  if (OptionIt == OptionList.end()) {
> +  if (llvm::none_of(OptionList, SameOptName)) {
>  Diags.Report(diag::err_analyzer_checker_option_unknown)
>  << SuppliedChecker << SuppliedOption;
>  return;
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] cb08f4a - Support warn_unused_result on typedefs

2022-06-02 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-06-02T20:57:31Z
New Revision: cb08f4aa4467cf562b62e542725f5351c5482495

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

LOG: Support warn_unused_result on typedefs

While it's not as robust as using the attribute on enums/classes (the
type information may be lost through a function pointer, a declaration
or use of the underlying type without using the typedef, etc) but I
think there's still value in being able to attribute a typedef and have
all return types written with that typedef pick up the
warn_unused_result behavior.

Specifically I'd like to be able to annotate LLVMErrorRef (a wrapper for
llvm::Error used in the C API - the underlying type is a raw pointer, so
it can't be attributed itself) to reduce the chance of unhandled errors.

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttributeCommonInfo.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Expr.cpp
clang/lib/Basic/Attributes.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/Sema/c2x-nodiscard.c
clang/test/Sema/unused-expr.c
clang/test/SemaCXX/warn-unused-result.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fed29b03a8b14..4644323501272 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2944,7 +2944,7 @@ def WarnUnusedResult : InheritableAttr {
C2x<"", "nodiscard", 201904>,
CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];
-  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike]>;
+  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike, 
TypedefName]>;
   let Args = [StringArgument<"Message", 1>];
   let Documentation = [WarnUnusedResultsDocs];
   let AdditionalMembers = [{

diff  --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 9eff0966e458a..afa8a893e921a 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -146,6 +146,7 @@ class AttributeCommonInfo {
   bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; }
 
   bool isGNUScope() const;
+  bool isClangScope() const;
 
   bool isAlignasAttribute() const {
 // FIXME: Use a better mechanism to determine this.
@@ -164,6 +165,8 @@ class AttributeCommonInfo {
 return isCXX11Attribute() || isC2xAttribute();
   }
 
+  bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; }
+
   bool isKeywordAttribute() const {
 return SyntaxUsed == AS_Keyword || SyntaxUsed == 
AS_ContextSensitiveKeyword;
   }

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 469f79a867524..0e6573241b55e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8734,6 +8734,10 @@ def warn_unused_result : Warning<
 def warn_unused_result_msg : Warning<
   "ignoring return value of function declared with %0 attribute: %1">,
   InGroup;
+def warn_unused_result_typedef_unsupported_spelling : Warning<
+  "'[[%select{nodiscard|gnu::warn_unused_result}0]]' attribute ignored when "
+  "applied to a typedef; consider using '__attribute__((warn_unused_result))' "
+  "or '[[clang::warn_unused_result]]' instead">, InGroup;
 def warn_unused_volatile : Warning<
   "expression result unused; assign into a variable to force a volatile load">,
   InGroup>;

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index c3dfae5cba061..79d092acccec9 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1522,6 +1522,11 @@ const Attr *CallExpr::getUnusedResultAttr(const 
ASTContext ) const {
 if (const auto *A = TD->getAttr())
   return A;
 
+  for (const auto *TD = getCallReturnType(Ctx)->getAs(); TD;
+   TD = TD->desugar()->getAs())
+if (const auto *A = TD->getDecl()->getAttr())
+  return A;
+
   // Otherwise, see if the callee is marked nodiscard and return that attribute
   // instead.
   const Decl *D = getCalleeDecl();

diff  --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 62eea9c590825..bd27dc13a92f0 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -85,6 +85,10 @@ bool AttributeCommonInfo::isGNUScope() const {
   return ScopeName && (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__"));
 }
 
+bool 

Re: Call for an assistance pushing patch review forward

2022-05-30 Thread David Blaikie via cfe-commits
Beyond that it may be useful to look at who's been contributing to the
code you're trying to change and consider cc'ing them on the review.
(if they can't help, maybe they can point you to someone who can)

On Fri, May 27, 2022 at 2:23 PM stryku_t via cfe-commits
 wrote:
>
> Hi Paul,
>
> Thank you for the tips.
> Pinging is indeed mentioned in the docs, but I didn't want to piss everyone 
> off, so after two pings I thought that I'm doing something wrong. From now on 
> I'll ping once a week in such situations.
>
> Got review comments now, so we're back on track. Gonna implement changes over 
> the weekend.
>
> Thanks,
> Mateusz Janek
>
> czw., 26 maj 2022 o 22:51 Robinson, Paul  napisał(a):
>>
>> Hi Mateusz,
>>
>>
>>
>> I wouldn’t worry too much about the failed build.  I took a peek and it 
>> looks like the failures are mostly in places very unrelated to your patch.  
>> If your own testing shows no problems, it’s very likely you’re fine.
>>
>>
>>
>> Regarding lack of response, this is unfortunately more common than it should 
>> be.  Our recommended practice—and I’m surprised we don’t say anything on the 
>> website—is to add a “ping” comment to your review, maybe once a week.  This 
>> can “bump” it up in someone’s to-be-reviewed list; if nothing else, there’s 
>> another email to the list that will hopefully catch someone’s attention.
>>
>>
>>
>> Good luck,
>>
>> --paulr
>>
>>
>>
>> From: cfe-commits  On Behalf Of stryku_t 
>> via cfe-commits
>> Sent: Thursday, May 26, 2022 4:20 PM
>> To: cfe-commits@lists.llvm.org
>> Subject: Call for an assistance pushing patch review forward
>>
>>
>>
>> Hi,
>>
>> Some time ago I submitted a Clang patch for review: 
>> https://reviews.llvm.org/D123532
>>
>> It's been some time and I can't make progress with it.
>> I'm aware that there is failed build. But, as I mentioned in one of the 
>> comments, I can't reproduce it locally.
>> Tried to reach out to the people mentioned in the review, but I struggle 
>> getting answers.
>> At this point I'm not sure if I'm doing something wrong or people are just 
>> busy. Should tag different people? Different project? Am I expected to 
>> figure out failed builds on my own before someone will review the changes?
>>
>> Could someone from the community please assist me how for move forward with 
>> this patch? Also, I'd be grateful if there's someone who can hint me how to 
>> reproduce failed builds locally or using some CI server.
>>
>> Thanks in advance!
>>
>> Best regards,
>> Mateusz Janek
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e59f648 - Move GCC-compatible pod-packing change to v15/old behavior available at v14 and below

2022-05-24 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-05-25T03:03:27Z
New Revision: e59f648d698efe58b96e9b6224449b2b8cfa872a

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

LOG: Move GCC-compatible pod-packing change to v15/old behavior available at 
v14 and below

Since this didn't make it into the v14 release - anyone requesting the
v14 ABI shouldn't get this GCC-compatible change that isn't backwards
compatible with v14 Clang.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/SemaCXX/class-layout.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7a54a3368547..a457a8fb2efe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -431,7 +431,7 @@ ABI Changes in Clang
   attribute is also specified on the member. Clang historically did perform
   such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
   You can switch back to the old ABI behavior with the flag:
-  ``-fclang-abi-compat=13.0``.
+  ``-fclang-abi-compat=14.0``.
 
 OpenMP Support in Clang
 ---

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index d442b4d96e76..6e7763a4a2b4 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -214,12 +214,9 @@ class LangOptions : public LangOptionsBase {
 /// global-scope inline variables incorrectly.
 Ver12,
 
-/// Attempt to be ABI-compatible with code generated by Clang 13.0.x.
-/// This causes clang to not pack non-POD members of packed structs.
-Ver13,
-
 /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
 /// This causes clang to mangle dependent nested names incorrectly.
+/// This causes clang to pack non-POD members of packed structs.
 Ver14,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 202823da7baa..8827e956fc2f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1890,7 +1890,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
   llvm::Triple Target = Context.getTargetInfo().getTriple();
   bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
  Context.getLangOpts().getClangABICompat() <=
- LangOptions::ClangABI::Ver13 ||
+ LangOptions::ClangABI::Ver14 ||
  Target.isPS4() || Target.isOSDarwin())) ||
  D->hasAttr();
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 88125dad8a92..32b084dfedec 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3516,8 +3516,6 @@ void CompilerInvocation::GenerateLangArgs(const 
LangOptions ,
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "11.0", SA);
   else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver12)
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "12.0", SA);
-  else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver13)
-GenerateArg(Args, OPT_fclang_abi_compat_EQ, "13.0", SA);
   else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver14)
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "14.0", SA);
 
@@ -4010,8 +4008,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions , 
ArgList ,
 Opts.setClangABICompat(LangOptions::ClangABI::Ver11);
   else if (Major <= 12)
 Opts.setClangABICompat(LangOptions::ClangABI::Ver12);
-  else if (Major <= 13)
-Opts.setClangABICompat(LangOptions::ClangABI::Ver13);
   else if (Major <= 14)
 Opts.setClangABICompat(LangOptions::ClangABI::Ver14);
 } else if (Ver != "latest") {

diff  --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 79fa67707110..940966950d8b 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=13
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s 

Re: [clang] 7aa1fa0 - Reland "[dwarf] Emit a DIGlobalVariable for constant strings."

2022-05-23 Thread David Blaikie via cfe-commits
(when recommitting a patch it can be helpful to mention the revisions
of the previous commit/revert, the reason for the revert and what's
different in this version of the patch that addresses that issue (or
how was the issue otherwise addressed))

On Wed, May 18, 2022 at 1:59 PM Mitch Phillips via cfe-commits
 wrote:
>
>
> Author: Mitch Phillips
> Date: 2022-05-18T13:56:45-07:00
> New Revision: 7aa1fa0a0a07f7949d2d77c099aab43cf9b75a91
>
> URL: 
> https://github.com/llvm/llvm-project/commit/7aa1fa0a0a07f7949d2d77c099aab43cf9b75a91
> DIFF: 
> https://github.com/llvm/llvm-project/commit/7aa1fa0a0a07f7949d2d77c099aab43cf9b75a91.diff
>
> LOG: Reland "[dwarf] Emit a DIGlobalVariable for constant strings."
>
> An upcoming patch will extend llvm-symbolizer to provide the source line
> information for global variables. The goal is to move AddressSanitizer
> off of internal debug info for symbolization onto the DWARF standard
> (and doing a clean-up in the process). Currently, ASan reports the line
> information for constant strings if a memory safety bug happens around
> them. We want to keep this behaviour, so we need to emit debuginfo for
> these variables as well.
>
> Reviewed By: dblaikie, rnk, aprantl
>
> Differential Revision: https://reviews.llvm.org/D123534
>
> Added:
> clang/test/CodeGen/debug-info-variables.c
> llvm/test/DebugInfo/COFF/global-no-strings.ll
>
> Modified:
> clang/lib/CodeGen/CGDebugInfo.cpp
> clang/lib/CodeGen/CGDebugInfo.h
> clang/lib/CodeGen/CodeGenModule.cpp
> clang/test/VFS/external-names.c
> llvm/lib/AsmParser/LLParser.cpp
> llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
> llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>
> Removed:
> llvm/test/Assembler/invalid-diglobalvariable-missing-name.ll
>
>
> 
> diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
> b/clang/lib/CodeGen/CGDebugInfo.cpp
> index 3d73bfb8ce79..753427029441 100644
> --- a/clang/lib/CodeGen/CGDebugInfo.cpp
> +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
> @@ -5132,7 +5132,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
> Qualified) const {
>  return Name;
>codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
>CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
> -
> +
>if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
>  TemplateNamesKind = codegenoptions::DebugTemplateNamesKind::Full;
>
> @@ -5459,6 +5459,21 @@ void CGDebugInfo::EmitGlobalAlias(const 
> llvm::GlobalValue *GV,
>ImportedDeclCache[GD.getCanonicalDecl().getDecl()].reset(ImportDI);
>  }
>
> +void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
> +const StringLiteral *S) {
> +  SourceLocation Loc = S->getStrTokenLoc(0);
> +  PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
> +  if (!PLoc.isValid())
> +return;
> +
> +  llvm::DIFile *File = getOrCreateFile(Loc);
> +  llvm::DIGlobalVariableExpression *Debug =
> +  DBuilder.createGlobalVariableExpression(
> +  nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
> +  getLineNumber(Loc), getOrCreateType(S->getType(), File), true);
> +  GV->addDebugInfo(Debug);
> +}
> +
>  llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
>if (!LexicalBlockStack.empty())
>  return LexicalBlockStack.back();
>
> diff  --git a/clang/lib/CodeGen/CGDebugInfo.h 
> b/clang/lib/CodeGen/CGDebugInfo.h
> index 8984f3eb1d7a..38e3fa5b2fa9 100644
> --- a/clang/lib/CodeGen/CGDebugInfo.h
> +++ b/clang/lib/CodeGen/CGDebugInfo.h
> @@ -533,6 +533,14 @@ class CGDebugInfo {
>/// Emit an @import declaration.
>void EmitImportDecl(const ImportDecl );
>
> +  /// DebugInfo isn't attached to string literals by default. While certain
> +  /// aspects of debuginfo aren't useful for string literals (like a name), 
> it's
> +  /// nice to be able to symbolize the line and column information. This is
> +  /// especially useful for sanitizers, as it allows symbolization of
> +  /// heap-buffer-overflows on constant strings.
> +  void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
> + const StringLiteral *S);
> +
>/// Emit C++ namespace alias.
>llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl );
>
>
> diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
> b/clang/lib/CodeGen/CodeGenModule.cpp
> index f8bf210dc0e2..703cf4edf5f5 100644
> --- a/clang/lib/CodeGen/CodeGenModule.cpp
> +++ b/clang/lib/CodeGen/CodeGenModule.cpp
> @@ -5670,6 +5670,11 @@ 
> CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
>}
>
>auto GV = GenerateStringLiteral(C, LT, *this, GlobalVariableName, 
> Alignment);
> +
> +  CGDebugInfo *DI = getModuleDebugInfo();
> +  if (DI && getCodeGenOpts().hasReducedDebugInfo())
> +DI->AddStringLiteralDebugInfo(GV, S);
> +
>if (Entry)
>  *Entry = 

[clang] 0b903ef - Re-add release notes for GCC ABI compatibility for non-POD in packed structs

2022-05-21 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-05-22T01:15:34Z
New Revision: 0b903ef6aa0976a60d3f448837f3c43adaf09cc1

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

LOG: Re-add release notes for GCC ABI compatibility for non-POD in packed 
structs

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5d1b12504f787..a889c74a55239 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,6 +424,12 @@ OpenCL C Language Changes in Clang
 ABI Changes in Clang
 
 
+- GCC doesn't pack non-POD members in packed structs unless the packed
+  attribute is also specified on the member. Clang historically did perform
+  such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
+  You can switch back to the old ABI behavior with the flag:
+  ``-fclang-abi-compat=13.0``.
+
 OpenMP Support in Clang
 ---
 



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


[clang] 1cee3d9 - DebugInfo: Consider the type of NTTP when simplifying template names

2022-04-07 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-04-08T00:00:46Z
New Revision: 1cee3d9db77b2c62a03efe1cce45f627dcbe6457

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

LOG: DebugInfo: Consider the type of NTTP when simplifying template names

Since the NTTP may need to be cast to the type when rebuilding the name,
check that the type can be rebuilt when determining whether a template
name can be simplified.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-simple-template-names.cpp

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 63b89f258a8ac..c18dbccf82936 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5167,7 +5167,8 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
 // harder to parse back into a large integer, etc - so punting on
 // this for now. Re-parsing the integers back into APInt is 
probably
 // feasible some day.
-return TA.getAsIntegral().getBitWidth() <= 64;
+return TA.getAsIntegral().getBitWidth() <= 64 &&
+   IsReconstitutableType(TA.getIntegralType());
   case TemplateArgument::Type:
 return IsReconstitutableType(TA.getAsType());
   default:

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 190d121937a03..98faa0fc6f0bb 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -31,6 +31,10 @@ struct t4 {
 };
   
 t4 v1;
+enum { UnnamedEnum1 };
+template
+void f4() {
+}
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "t3<(anonymous 
namespace)::LocalEnum, ((anonymous namespace)::LocalEnum)0>"
 void f() {
   // Basic examples of simplifiable/rebuildable names
@@ -122,4 +126,7 @@ void f() {
   int fnrt() __attribute__((noreturn));
   f1();
   // CHECK: !DISubprogram(name: "f1",
+  
+  f4();
+  // CHECK: !DISubprogram(name: "f4<((unnamed enum at {{.*}}))0>"
 }

diff  --git 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
index 9bc14f8ce6577..b68d4e8c04b94 100644
--- 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
+++ 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
@@ -179,6 +179,10 @@ struct t12 {
   t11 v1;
 };
 
+template
+void f10() {
+}
+
 int main() {
   struct { } A;
   auto L = []{};
@@ -327,6 +331,7 @@ int main() {
   f1();
   int fnrt() __attribute__((noreturn));
   f1();
+  f10();
 }
 void t8::mem() {
   struct t7 { };



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


[clang] 6b30623 - DebugInfo: Make the simplified template names prefix more unique

2022-04-06 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-04-06T18:25:46Z
New Revision: 6b306233f78876a1d197ed6e1f05785505de7c63

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

LOG: DebugInfo: Make the simplified template names prefix more unique

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/test/DebugInfo/X86/tu-to-non-tu.ll
llvm/test/ThinLTO/X86/debuginfo-compositetype-import.ll
llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names-fail.s
llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a37dc81c4bb8f..eeabae09c2cab 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5199,7 +5199,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
 TemplateNamesKind == codegenoptions::DebugTemplateNamesKind::Mangled;
 // check if it's a template
 if (Mangled)
-  OS << "_STN";
+  OS << "_STN|";
 
 OS << ND->getDeclName();
 std::string EncodedOriginalName;

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 5bf1b54b97708..190d121937a03 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -35,20 +35,20 @@ t4 v1;
 void f() {
   // Basic examples of simplifiable/rebuildable names
   f1<>();
-  // CHECK: !DISubprogram(name: "_STNf1|<>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<>",
   // SIMPLE: !DISubprogram(name: "f1",
   // FULL: !DISubprogram(name: "f1<>",
   f1();
-  // CHECK: !DISubprogram(name: "_STNf1|",
+  // CHECK: !DISubprogram(name: "_STN|f1|",
   f1();
-  // CHECK: !DISubprogram(name: "_STNf1|",
+  // CHECK: !DISubprogram(name: "_STN|f1|",
   f2();
-  // CHECK: !DISubprogram(name: "_STNf2|",
+  // CHECK: !DISubprogram(name: "_STN|f2|",
 
   // Check that even though the nested name can't be rebuilt, it'll carry its
   // full name and the outer name can be rebuilt from that.
   f1>();
-  // CHECK: !DISubprogram(name: "_STNf1| >",
+  // CHECK: !DISubprogram(name: "_STN|f1| >",
 
   // Vector array types are encoded in DWARF but the decoding in llvm-dwarfdump
   // isn't implemented yet.
@@ -109,7 +109,7 @@ void f() {
   // worry about seeing conversion operators as parameters to other templates.
 
   f3();
-  // CHECK: !DISubprogram(name: "_STNf3|",
+  // CHECK: !DISubprogram(name: "_STN|f3|",
   
   f1<_BitInt(3)>();
   // CHECK: !DISubprogram(name: "f1<_BitInt(3)>",

diff  --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp 
b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 7d097bbff6d82..420df9b4e14a9 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1509,7 +1509,7 @@ Error 
MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
 // DICompositeType flag specifying whether template parameters are
 // required on declarations of this type.
 StringRef NameStr = Name->getString();
-if (!NameStr.contains('<') || NameStr.startswith("_STN"))
+if (!NameStr.contains('<') || NameStr.startswith("_STN|"))
   TemplateParams = getMDOrNull(Record[14]);
   }
 } else {

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp 
b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 1dbe22dcd1c58..265096c7e3fba 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -291,7 +291,7 @@ struct DWARFTypePrinter {
   }
   Word = true;
   StringRef Name = NamePtr;
-  static constexpr StringRef MangledPrefix = "_STN";
+  static constexpr StringRef MangledPrefix = "_STN|";
   if (Name.startswith(MangledPrefix)) {
 Name = Name.drop_front(MangledPrefix.size());
 auto Separator = Name.find('|');

diff  --git a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll 
b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
index c204c67e9b652..119c4884900a9 100644
--- a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
+++ b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
@@ -66,7 +66,7 @@
 ; };
 ; ref_templ_non_tu_simple v3;
 ; 
-; // Modify templ_non_tu's name to be mangled ('_STN' name '|' args)
+; // Modify templ_non_tu's name to be mangled ('_STN|' name '|' args)
 ; template <>
 ; struct templ_non_tu {
 ;   virtual void f1();
@@ -117,7 +117,7 @@
 ; CHECK: DW_AT_name {{.*}}"ref_templ_non_tu"
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name {{.*}}"_STNtempl_non_tu|"
+; CHECK: DW_AT_name 

[clang] bb3980a - DebugInfo: Don't use enumerators in template names for debug info as they are not canonical

2022-04-05 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-04-05T17:16:42Z
New Revision: bb3980ae9fa7e19540080285f2bf2d960ea802fc

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

LOG: DebugInfo: Don't use enumerators in template names for debug info as they 
are not canonical

Since enumerators may not be available in every translation unit they
can't be reliably used to name entities. (this also makes simplified
template name roundtripping infeasible - since the expected name could
only be rebuilt if the enumeration definition could be found (or only if
it couldn't be found, depending on the context of the original name))

Added: 


Modified: 
clang/include/clang/AST/PrettyPrinter.h
clang/lib/AST/TemplateBase.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s
llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s

Removed: 




diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 54cb57227f7a0..cb25b2750dd43 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -74,7 +74,8 @@ struct PrintingPolicy {
 SuppressImplicitBase(false), FullyQualifiedName(false),
 PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
 UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false),
-CleanUglifiedParameters(false), EntireContentsOfLargeArray(true) {}
+CleanUglifiedParameters(false), EntireContentsOfLargeArray(true),
+UseEnumerators(true) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -290,6 +291,10 @@ struct PrintingPolicy {
   /// template parameters, no matter how many elements there are.
   unsigned EntireContentsOfLargeArray : 1;
 
+  /// Whether to print enumerator non-type template parameters with a matching
+  /// enumerator name or via cast of an integer.
+  unsigned UseEnumerators : 1;
+
   /// Callbacks to use to allow the behavior of printing to be customized.
   const PrintingCallbacks *Callbacks = nullptr;
 };

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 3418401517c84..229a8db21ab63 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -59,15 +59,17 @@ static void printIntegral(const TemplateArgument , 
raw_ostream ,
   const Type *T = TemplArg.getIntegralType().getTypePtr();
   const llvm::APSInt  = TemplArg.getAsIntegral();
 
-  if (const EnumType *ET = T->getAs()) {
-for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
-  // In Sema::CheckTemplateArugment, enum template arguments value are
-  // extended to the size of the integer underlying the enum type.  This
-  // may create a size 
diff erence between the enum value and template
-  // argument value, requiring isSameValue here instead of operator==.
-  if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
-ECD->printQualifiedName(Out, Policy);
-return;
+  if (Policy.UseEnumerators) {
+if (const EnumType *ET = T->getAs()) {
+  for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) {
+// In Sema::CheckTemplateArugment, enum template arguments value are
+// extended to the size of the integer underlying the enum type.  This
+// may create a size 
diff erence between the enum value and template
+// argument value, requiring isSameValue here instead of operator==.
+if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
+  ECD->printQualifiedName(Out, Policy);
+  return;
+}
   }
 }
   }

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index beb640375dfba..a37dc81c4bb8f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -248,6 +248,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   PP.PrintCanonicalTypes = true;
   PP.UsePreferredNames = false;
   PP.AlwaysIncludeTypeForTemplateArgument = true;
+  PP.UseEnumerators = false;
 
   // Apply -fdebug-prefix-map.
   PP.Callbacks = 

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 00c4361e11ef4..5bf1b54b97708 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -31,7 +31,7 @@ struct t4 {
 };
   
 t4 v1;
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "t3<(anonymous 

Re: [clang] abe997b - [CMake][Fuchsia] Switch to lld on Apple platforms

2022-03-28 Thread David Blaikie via cfe-commits
Neat!

On Tue, Mar 22, 2022 at 1:07 AM Petr Hosek via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Petr Hosek
> Date: 2022-03-22T01:06:30-07:00
> New Revision: abe997bb2dd61188784954ae866352740629985d
>
> URL:
> https://github.com/llvm/llvm-project/commit/abe997bb2dd61188784954ae866352740629985d
> DIFF:
> https://github.com/llvm/llvm-project/commit/abe997bb2dd61188784954ae866352740629985d.diff
>
> LOG: [CMake][Fuchsia] Switch to lld on Apple platforms
>
> lld Mach-O backend supports all our use cases now.
>
> Differential Revision: https://reviews.llvm.org/D122047
>
> Added:
>
>
> Modified:
> clang/cmake/caches/Fuchsia-stage2.cmake
> clang/cmake/caches/Fuchsia.cmake
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake
> b/clang/cmake/caches/Fuchsia-stage2.cmake
> index d64229bd572eb..df15aa65cc9d2 100644
> --- a/clang/cmake/caches/Fuchsia-stage2.cmake
> +++ b/clang/cmake/caches/Fuchsia-stage2.cmake
> @@ -9,10 +9,7 @@ set(LLVM_ENABLE_RUNTIMES
> "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
>
>  set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
>  set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
> -if(NOT APPLE)
> -  # TODO: Remove this once we switch to ld64.lld.
> -  set(LLVM_ENABLE_LLD ON CACHE BOOL "")
> -endif()
> +set(LLVM_ENABLE_LLD ON CACHE BOOL "")
>  set(LLVM_ENABLE_LTO ON CACHE BOOL "")
>  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
>  set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
> @@ -31,11 +28,8 @@ if(WIN32)
>  endif()
>
>  set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
> -if(NOT APPLE)
> -  # TODO: Remove this once we switch to ld64.lld.
> -  set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
> -  set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
> -endif()
> +set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
> +set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
>  set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
>  set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
>  set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
>
> diff  --git a/clang/cmake/caches/Fuchsia.cmake
> b/clang/cmake/caches/Fuchsia.cmake
> index 8e9e44d5917ed..bf2ea1802963d 100644
> --- a/clang/cmake/caches/Fuchsia.cmake
> +++ b/clang/cmake/caches/Fuchsia.cmake
> @@ -22,11 +22,8 @@ if(WIN32)
>  endif()
>
>  set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
> -if(NOT APPLE)
> -  # TODO: Remove this once we switch to ld64.lld.
> -  set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
> -  set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
> -endif()
> +set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
> +set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
>  set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
>  set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
>  set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
> @@ -112,11 +109,8 @@ if(UNIX)
>set(BOOTSTRAP_CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread" CACHE STRING "")
>  endif()
>
> +set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
>  set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")
> -if(NOT APPLE)
> -  # TODO: Remove this once we switch to ld64.lld.
> -  set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
> -endif()
>
>  set(CLANG_BOOTSTRAP_TARGETS
>check-all
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 34b9b1e - Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"

2022-03-25 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-03-25T23:53:19Z
New Revision: 34b9b1ea4874b109b998d59a837f81f2f730001c

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

LOG: Disable -Wmissing-prototypes for internal linkage functions that aren't 
explicitly marked "static"

Some functions can end up non-externally visible despite not being
declared "static" or in an unnamed namespace in C++ - such as by having
parameters that are of non-external types.

Such functions aren't mistakenly intended to be defining some function
that needs a declaration. They could be maybe more legible (except for
the operator new example) with an explicit static, but that's a
stylistic thing outside what should be addressed by a warning.

This reapplies 275c56226d7fbd6a4d554807374f78d323aa0c1c - once we figure
out what to do about the change in behavior for -Wnon-c-typedef-for-linkage
(this reverts the revert commit 85ee1d3ca1d06b6bd3477515b8d0c72c8df7c069)

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/anonymous-struct.cpp
clang/test/SemaCXX/warn-missing-prototypes.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5c262063a6aef..4051ab29fb26f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14233,6 +14233,11 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
   if (FD->isDeleted())
 return false;
 
+  // Don't warn on implicitly local functions (such as having local-typed
+  // parameters).
+  if (!FD->isExternallyVisible())
+return false;
+
   for (const FunctionDecl *Prev = FD->getPreviousDecl();
Prev; Prev = Prev->getPreviousDecl()) {
 // Ignore any declarations that occur in function or method

diff  --git a/clang/test/SemaCXX/anonymous-struct.cpp 
b/clang/test/SemaCXX/anonymous-struct.cpp
index 0a5395e15780b..7cf05ee3c49ae 100644
--- a/clang/test/SemaCXX/anonymous-struct.cpp
+++ b/clang/test/SemaCXX/anonymous-struct.cpp
@@ -183,3 +183,9 @@ namespace BuiltinName {
 void memcpy(); // expected-note {{due to this member}}
   } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+namespace inline_defined_static_member {
+typedef struct { // expected-warning {{anonymous non-C-compatible type}}
+  static void f() { // expected-note {{due to this member}}
+  }
+} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
+}

diff  --git a/clang/test/SemaCXX/warn-missing-prototypes.cpp 
b/clang/test/SemaCXX/warn-missing-prototypes.cpp
index e8637e5a90eab..2880514ee02b7 100644
--- a/clang/test/SemaCXX/warn-missing-prototypes.cpp
+++ b/clang/test/SemaCXX/warn-missing-prototypes.cpp
@@ -44,3 +44,16 @@ void j() = delete;
 extern void k() {} // expected-warning {{no previous prototype for function 
'k'}}
 // expected-note@-1{{declare 'static' if the function is not intended to be 
used outside of this translation unit}}
 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{.*}}-[[@LINE-2]]:{{.*}}}:"{{.*}}"
+
+namespace {
+struct anon { };
+}
+
+// No warning because this has internal linkage despite not being declared
+// explicitly 'static', owing to the internal linkage parameter.
+void l(anon) {
+}
+
+void *operator new(decltype(sizeof(3)) size, const anon &) throw() {
+  return nullptr;
+}



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


[clang] 7b498be - DebugInfo: Classify noreturn function types as non-reconstructible

2022-03-24 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-03-24T18:53:14Z
New Revision: 7b498beef03ae07bb98796461a957af836074b92

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

LOG: DebugInfo: Classify noreturn function types as non-reconstructible

This information isn't preserved in the DWARF description of function
types (though probably should be - it's preserved on the function
declarations/definitions themselves through the DW_AT_noreturn attribute
- but we should move or also include that in the subroutine type itself
too - but for now, with it not being there, the DWARF is lossy and
can't be reconstructed)

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-simple-template-names.cpp

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 75ce74b31846f..beb640375dfba 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5078,6 +5078,7 @@ struct ReconstitutableType : public 
RecursiveASTVisitor {
   bool VisitFunctionProtoType(FunctionProtoType *FT) {
 // noexcept is not encoded in DWARF, so the reversi
 Reconstitutable &= !isNoexceptExceptionSpec(FT->getExceptionSpecType());
+Reconstitutable &= !FT->getNoReturnAttr();
 return Reconstitutable;
   }
   bool VisitRecordType(RecordType *RT) {

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 3d8e69abed99b..00c4361e11ef4 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -116,4 +116,10 @@ void f() {
 
   f1();
   // CHECK: !DISubprogram(name: "f1",
+
+  // Add a parameter just so this 
diff ers from other attributed function types
+  // that don't mangle 
diff erently.
+  int fnrt() __attribute__((noreturn));
+  f1();
+  // CHECK: !DISubprogram(name: "f1",
 }

diff  --git 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
index 5ecc3bc7fc144..5b1afcb29cc7f 100644
--- 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
+++ 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
@@ -325,6 +325,8 @@ int main() {
   f1::*>();
   void fcc() __attribute__((swiftcall));
   f1();
+  int fnrt() __attribute__((noreturn));
+  f1();
 }
 void t8::mem() {
   struct t7 { };



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


[clang] 85ee1d3 - Revert "Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static""

2022-03-09 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-03-09T21:12:56Z
New Revision: 85ee1d3ca1d06b6bd3477515b8d0c72c8df7c069

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

LOG: Revert "Disable -Wmissing-prototypes for internal linkage functions that 
aren't explicitly marked "static""

Regresses:
typedef struct {
  static void  f() {
  }
} a_t;

Causing this to error instead of warn, because the linkage is computed
earlier/too early perhaps. I'll send out a review to see if there's some
other path forward or if this is an acceptable regression, etc.

This reverts commit 275c56226d7fbd6a4d554807374f78d323aa0c1c.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/warn-missing-prototypes.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b88d9f2f847fd..fa086ae0f6126 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14210,9 +14210,6 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
   if (!FD->isGlobal())
 return false;
 
-  if (!FD->isExternallyVisible())
-return false;
-
   // Don't warn about C++ member functions.
   if (isa(FD))
 return false;

diff  --git a/clang/test/SemaCXX/warn-missing-prototypes.cpp 
b/clang/test/SemaCXX/warn-missing-prototypes.cpp
index 2880514ee02b7..e8637e5a90eab 100644
--- a/clang/test/SemaCXX/warn-missing-prototypes.cpp
+++ b/clang/test/SemaCXX/warn-missing-prototypes.cpp
@@ -44,16 +44,3 @@ void j() = delete;
 extern void k() {} // expected-warning {{no previous prototype for function 
'k'}}
 // expected-note@-1{{declare 'static' if the function is not intended to be 
used outside of this translation unit}}
 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{.*}}-[[@LINE-2]]:{{.*}}}:"{{.*}}"
-
-namespace {
-struct anon { };
-}
-
-// No warning because this has internal linkage despite not being declared
-// explicitly 'static', owing to the internal linkage parameter.
-void l(anon) {
-}
-
-void *operator new(decltype(sizeof(3)) size, const anon &) throw() {
-  return nullptr;
-}



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


[clang] c0a6433 - Simplify OpenMP Lambda use

2022-03-07 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-03-07T18:23:20Z
New Revision: c0a6433f2b5120d79f03431e9bf61b4da1184412

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

LOG: Simplify OpenMP Lambda use

* Use default ref capture for non-escaping lambdas (this makes
  maintenance easier by allowing new uses, removing uses, having
  conditional uses (such as in assertions) not require updates to an
  explicit capture list)
* Simplify addPrivate API not to take a lambda, since it calls it
  unconditionally/immediately anyway - most callers are simply passing
  in a named value or short expression anyway and the lambda syntax just
  adds noise/overhead

Reviewed By: ABataev

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 399b2f63e8443..3089cdc4e4a92 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -370,8 +370,7 @@ class CGOpenMPInnerExprInfo final : public 
CGOpenMPInlinedRegionInfo {
   /*RefersToEnclosingVariableOrCapture=*/false,
   VD->getType().getNonReferenceType(), VK_LValue,
   C.getLocation());
-  PrivScope.addPrivate(
-  VD, [, ]() { return CGF.EmitLValue().getAddress(CGF); });
+  PrivScope.addPrivate(VD, CGF.EmitLValue().getAddress(CGF));
 }
 (void)PrivScope.Privatize();
   }
@@ -634,10 +633,8 @@ static void 
emitInitWithReductionInitializer(CodeGenFunction ,
 const auto *RHSDRE =
 cast(cast(RHS)->getSubExpr());
 CodeGenFunction::OMPPrivateScope PrivateScope(CGF);
-PrivateScope.addPrivate(cast(LHSDRE->getDecl()),
-[=]() { return Private; });
-PrivateScope.addPrivate(cast(RHSDRE->getDecl()),
-[=]() { return Original; });
+PrivateScope.addPrivate(cast(LHSDRE->getDecl()), Private);
+PrivateScope.addPrivate(cast(RHSDRE->getDecl()), Original);
 (void)PrivateScope.Privatize();
 RValue Func = RValue::get(Reduction.second);
 CodeGenFunction::OpaqueValueMapping Map(CGF, OVE, Func);
@@ -1141,15 +1138,13 @@ emitCombinerOrInitializer(CodeGenModule , QualType 
Ty,
 Out->getLocation());
   CodeGenFunction::OMPPrivateScope Scope(CGF);
   Address AddrIn = CGF.GetAddrOfLocalVar();
-  Scope.addPrivate(In, [, AddrIn, PtrTy]() {
-return CGF.EmitLoadOfPointerLValue(AddrIn, PtrTy->castAs())
-.getAddress(CGF);
-  });
+  Scope.addPrivate(
+  In, CGF.EmitLoadOfPointerLValue(AddrIn, PtrTy->castAs())
+  .getAddress(CGF));
   Address AddrOut = CGF.GetAddrOfLocalVar();
-  Scope.addPrivate(Out, [, AddrOut, PtrTy]() {
-return CGF.EmitLoadOfPointerLValue(AddrOut, PtrTy->castAs())
-.getAddress(CGF);
-  });
+  Scope.addPrivate(
+  Out, CGF.EmitLoadOfPointerLValue(AddrOut, PtrTy->castAs())
+   .getAddress(CGF));
   (void)Scope.Privatize();
   if (!IsCombiner && Out->hasInit() &&
   !CGF.isTrivialInitializer(Out->getInit())) {
@@ -3938,8 +3933,7 @@ static void emitPrivatesInit(CodeGenFunction ,
   Address SrcElement) {
   // Clean up any temporaries needed by the initialization.
   CodeGenFunction::OMPPrivateScope InitScope(CGF);
-  InitScope.addPrivate(
-  Elem, [SrcElement]() -> Address { return SrcElement; });
+  InitScope.addPrivate(Elem, SrcElement);
   (void)InitScope.Privatize();
   // Emit initialization for single element.
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(
@@ -3951,9 +3945,7 @@ static void emitPrivatesInit(CodeGenFunction ,
   }
 } else {
   CodeGenFunction::OMPPrivateScope InitScope(CGF);
-  InitScope.addPrivate(Elem, [SharedRefLValue, ]() -> Address {
-return SharedRefLValue.getAddress(CGF);
-  });
+  InitScope.addPrivate(Elem, SharedRefLValue.getAddress(CGF));
   (void)InitScope.Privatize();
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );
   CGF.EmitExprAsInit(Init, VD, PrivateLValue,
@@ -4099,14 +4091,11 @@ class OMPIteratorGeneratorScope final
 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
   Uppers.push_back(CGF.EmitScalarExpr(E->getHelper(I).Upper));
   const auto *VD = cast(E->getIteratorDecl(I));
-  addPrivate(VD, [, VD]() {
-return CGF.CreateMemTemp(VD->getType(), VD->getName());
-  });
+  

Re: [clang] 1d1b089 - Fix more unused lambda capture warnings, NFC

2022-03-06 Thread David Blaikie via cfe-commits
On Mon, Feb 28, 2022 at 10:12 AM Reid Kleckner  wrote:

> I agree, but clearly this person chose a particular style, and I wasn't
> trying to revise their code style, just to fix some the Bazel build, which
> uses -Werror.
>

Oh, wow, yeah, this file/corner of the codebase is deep into lambdas, wow.
Sent https://reviews.llvm.org/D121077 for the broader change (both the
capture lists and at least one function that seemed to not really benefit
from taking a lambda - maybe other functions could have similar cleanup)


> The way that `assert` can affect a lambda's capture list seems like a
> particularly good argument for having a project wide style recommendation
> to never use explicit capture lists.
>

Yeah, not sure it's worth words in the style guide unless it's especially
contentious (the presence of code like this might argue that it is - but
hopefully even in this case only pointing it out will be enough) but maybe.

- Dave


>
> On Mon, Feb 28, 2022 at 9:45 AM David Blaikie  wrote:
>
>> FWIW, I think it's probably simpler/more maintainable to default capture
>> by reference ("[&]") if a lambda doesn't escape its scope (if it's never
>> type erased/put in a std::function or equivalent). Avoids assert/non-assert
>> unused issues, having to maintain/update the list when the code changes and
>> makes a capture live/dead/etc.
>>
>> On Wed, Feb 23, 2022 at 2:09 PM Reid Kleckner via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Reid Kleckner
>>> Date: 2022-02-23T14:07:04-08:00
>>> New Revision: 1d1b089c5d503e2fc8697887411730105f66c774
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/1d1b089c5d503e2fc8697887411730105f66c774
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/1d1b089c5d503e2fc8697887411730105f66c774.diff
>>>
>>> LOG: Fix more unused lambda capture warnings, NFC
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/lib/CodeGen/CGOpenMPRuntime.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
>>> b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
>>> index b4033da890c4..3f4a78ddbf3c 100644
>>> --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
>>> +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
>>> @@ -10358,8 +10358,8 @@ void CGOpenMPRuntime::emitTargetCall(
>>>llvm::Value *MapTypesArray = nullptr;
>>>llvm::Value *MapNamesArray = nullptr;
>>>// Generate code for the host fallback function.
>>> -  auto & = [this, OutlinedFn, , ,
>>> RequiresOuterTask,
>>> -, OffloadingMandatory](CodeGenFunction )
>>> {
>>> +  auto & = [this, , OutlinedFn, ,
>>> RequiresOuterTask, ,
>>> +OffloadingMandatory](CodeGenFunction ) {
>>>  if (OffloadingMandatory) {
>>>CGF.Builder.CreateUnreachable();
>>>  } else {
>>> @@ -10371,9 +10371,8 @@ void CGOpenMPRuntime::emitTargetCall(
>>>  }
>>>};
>>>// Fill up the pointer arrays and transfer execution to the device.
>>> -  auto & = [this, Device, OutlinedFn, OutlinedFnID, ,
>>> ,
>>> -, , ,
>>> RequiresOuterTask,
>>> -, SizeEmitter,
>>> +  auto & = [this, Device, OutlinedFnID, , ,
>>> +, , SizeEmitter,
>>>  FallbackGen](CodeGenFunction , PrePostActionTy
>>> &) {
>>>  if (Device.getInt() == OMPC_DEVICE_ancestor) {
>>>// Reverse offloading is not supported, so just execute on the
>>> host.
>>> @@ -10392,6 +10391,7 @@ void CGOpenMPRuntime::emitTargetCall(
>>>
>>>  // From this point on, we need to have an ID of the target region
>>> defined.
>>>  assert(OutlinedFnID && "Invalid outlined function ID!");
>>> +(void)OutlinedFnID;
>>>
>>>  // Emit device ID if any.
>>>  llvm::Value *DeviceID;
>>> @@ -10529,8 +10529,7 @@ void CGOpenMPRuntime::emitTargetCall(
>>>};
>>>
>>>// Notify that the host version must be executed.
>>> -  auto & = [this, , OutlinedFn, , ,
>>> RequiresOuterTask,
>>> -FallbackGen](CodeGenFunction , PrePostActionTy
>>> &) {
>>> +  auto & = [FallbackGen](CodeGenFunction , PrePostActionTy
>>> &) {
>>>  FallbackGen(CGF);
>>>};
>>>
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] 1d1b089 - Fix more unused lambda capture warnings, NFC

2022-02-28 Thread David Blaikie via cfe-commits
FWIW, I think it's probably simpler/more maintainable to default capture by
reference ("[&]") if a lambda doesn't escape its scope (if it's never type
erased/put in a std::function or equivalent). Avoids assert/non-assert
unused issues, having to maintain/update the list when the code changes and
makes a capture live/dead/etc.

On Wed, Feb 23, 2022 at 2:09 PM Reid Kleckner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Reid Kleckner
> Date: 2022-02-23T14:07:04-08:00
> New Revision: 1d1b089c5d503e2fc8697887411730105f66c774
>
> URL:
> https://github.com/llvm/llvm-project/commit/1d1b089c5d503e2fc8697887411730105f66c774
> DIFF:
> https://github.com/llvm/llvm-project/commit/1d1b089c5d503e2fc8697887411730105f66c774.diff
>
> LOG: Fix more unused lambda capture warnings, NFC
>
> Added:
>
>
> Modified:
> clang/lib/CodeGen/CGOpenMPRuntime.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> index b4033da890c4..3f4a78ddbf3c 100644
> --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> @@ -10358,8 +10358,8 @@ void CGOpenMPRuntime::emitTargetCall(
>llvm::Value *MapTypesArray = nullptr;
>llvm::Value *MapNamesArray = nullptr;
>// Generate code for the host fallback function.
> -  auto & = [this, OutlinedFn, , ,
> RequiresOuterTask,
> -, OffloadingMandatory](CodeGenFunction ) {
> +  auto & = [this, , OutlinedFn, ,
> RequiresOuterTask, ,
> +OffloadingMandatory](CodeGenFunction ) {
>  if (OffloadingMandatory) {
>CGF.Builder.CreateUnreachable();
>  } else {
> @@ -10371,9 +10371,8 @@ void CGOpenMPRuntime::emitTargetCall(
>  }
>};
>// Fill up the pointer arrays and transfer execution to the device.
> -  auto & = [this, Device, OutlinedFn, OutlinedFnID, ,
> ,
> -, , ,
> RequiresOuterTask,
> -, SizeEmitter,
> +  auto & = [this, Device, OutlinedFnID, , ,
> +, , SizeEmitter,
>  FallbackGen](CodeGenFunction , PrePostActionTy &)
> {
>  if (Device.getInt() == OMPC_DEVICE_ancestor) {
>// Reverse offloading is not supported, so just execute on the host.
> @@ -10392,6 +10391,7 @@ void CGOpenMPRuntime::emitTargetCall(
>
>  // From this point on, we need to have an ID of the target region
> defined.
>  assert(OutlinedFnID && "Invalid outlined function ID!");
> +(void)OutlinedFnID;
>
>  // Emit device ID if any.
>  llvm::Value *DeviceID;
> @@ -10529,8 +10529,7 @@ void CGOpenMPRuntime::emitTargetCall(
>};
>
>// Notify that the host version must be executed.
> -  auto & = [this, , OutlinedFn, , ,
> RequiresOuterTask,
> -FallbackGen](CodeGenFunction , PrePostActionTy &)
> {
> +  auto & = [FallbackGen](CodeGenFunction , PrePostActionTy &)
> {
>  FallbackGen(CGF);
>};
>
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ea3266 - DebugInfo: Don't simplify template names using _BitInt(N)

2022-02-15 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-02-15T11:58:40-08:00
New Revision: 1ea326634b582f5574e0b22b85e5b0c631b30dcf

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

LOG: DebugInfo: Don't simplify template names using _BitInt(N)

_BitInt(N) only encodes the byte size in DWARF, not the bit size, so
can't be reconstituted.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-simple-template-names.cpp

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index d8ba5592ad478..91a8f278de5c4 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5032,6 +5032,15 @@ struct ReconstitutableType : public 
RecursiveASTVisitor {
 Reconstitutable = false;
 return false;
   }
+  bool VisitType(Type *T) {
+// _BitInt(N) isn't reconstitutable because the bit width isn't encoded in
+// the DWARF, only the byte width.
+if (T->isBitIntType()) {
+  Reconstitutable = false;
+  return false;
+}
+return true;
+  }
   bool TraverseEnumType(EnumType *ET) {
 // Unnamed enums can't be reconstituted due to a lack of column info we
 // produce in the DWARF, so we can't get Clang's full name back.

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 06e83ea6f59eb..d20c9478c363d 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -105,4 +105,10 @@ void f() {
 
   f3();
   // CHECK: !DISubprogram(name: "_STNf3|",
+  
+  f1<_BitInt(3)>();
+  // CHECK: !DISubprogram(name: "f1<_BitInt(3)>",
+
+  f1();
+  // CHECK: !DISubprogram(name: "f1",
 }

diff  --git 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
index 898b27ec0e479..ee429ef3b5798 100644
--- 
a/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
+++ 
b/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp
@@ -316,6 +316,8 @@ int main() {
   f1();
   operator_not_really();
   t12 v4;
+  f1<_BitInt(3)>();
+  f1();
 }
 void t8::mem() {
   struct t7 { };



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


[clang] 26c5cf8 - Fix Windows build that fails if a class has a member with the same naem

2022-02-10 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-02-10T15:27:31-08:00
New Revision: 26c5cf8fa031f5143fd180fdc8d9dbc26a88e89e

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

LOG: Fix Windows build that fails if a class has a member with the same naem

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index cca5576aac07..eb3f104f7eb9 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5000,10 +5000,10 @@ static bool 
ReferencesAnonymousEntity(ArrayRef Args) {
 case TemplateArgument::Type: {
   struct ReferencesAnonymous
   : public RecursiveASTVisitor {
-bool ReferencesAnonymous = false;
+bool RefAnon = false;
 bool VisitRecordType(RecordType *RT) {
   if (ReferencesAnonymousEntity(RT)) {
-ReferencesAnonymous = true;
+RefAnon = true;
 return false;
   }
   return true;
@@ -5011,7 +5011,7 @@ static bool 
ReferencesAnonymousEntity(ArrayRef Args) {
   };
   ReferencesAnonymous RT;
   RT.TraverseType(TA.getAsType());
-  if (RT.ReferencesAnonymous)
+  if (RT.RefAnon)
 return true;
   break;
 }



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


[clang] 275c562 - Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"

2022-01-31 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-31T17:34:51-08:00
New Revision: 275c56226d7fbd6a4d554807374f78d323aa0c1c

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

LOG: Disable -Wmissing-prototypes for internal linkage functions that aren't 
explicitly marked "static"

Some functions can end up non-externally visible despite not being
declared "static" or in an unnamed namespace in C++ - such as by having
parameters that are of non-external types.

Such functions aren't mistakenly intended to be defining some function
that needs a declaration. They could be maybe more legible (except for
the `operator new` example) with an explicit static, but that's a
stylistic thing outside what should be addressed by a warning.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/warn-missing-prototypes.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e747ffc6f2ac1..cbd9df4d6a7b7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14196,6 +14196,9 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
   if (!FD->isGlobal())
 return false;
 
+  if (!FD->isExternallyVisible())
+return false;
+
   // Don't warn about C++ member functions.
   if (isa(FD))
 return false;

diff  --git a/clang/test/SemaCXX/warn-missing-prototypes.cpp 
b/clang/test/SemaCXX/warn-missing-prototypes.cpp
index e8637e5a90eab..2880514ee02b7 100644
--- a/clang/test/SemaCXX/warn-missing-prototypes.cpp
+++ b/clang/test/SemaCXX/warn-missing-prototypes.cpp
@@ -44,3 +44,16 @@ void j() = delete;
 extern void k() {} // expected-warning {{no previous prototype for function 
'k'}}
 // expected-note@-1{{declare 'static' if the function is not intended to be 
used outside of this translation unit}}
 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{.*}}-[[@LINE-2]]:{{.*}}}:"{{.*}}"
+
+namespace {
+struct anon { };
+}
+
+// No warning because this has internal linkage despite not being declared
+// explicitly 'static', owing to the internal linkage parameter.
+void l(anon) {
+}
+
+void *operator new(decltype(sizeof(3)) size, const anon &) throw() {
+  return nullptr;
+}



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


[clang] 2771233 - GCC ABI Compatibility: Preserve alignment of non-pod members in packed structs

2022-01-28 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-28T11:04:20-08:00
New Revision: 277123376ce08c98b07c154bf83e4092a5d4d3c6

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

LOG: GCC ABI Compatibility: Preserve alignment of non-pod members in packed 
structs

This matches GCC: https://godbolt.org/z/sM5q95PGY

I realize this is an API break for clang+clang - so I'm totally open to
discussing how we should deal with that. If Apple wants to keep the
Clang layout indefinitely, if we want to put a flag on this so non-Apple
folks can opt out of this fix/new behavior.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/SemaCXX/class-layout.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6a9b046a1427d..45e80785e462a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -236,6 +236,12 @@ ABI Changes in Clang
   is still in the process of being stabilized, so this type should not yet be
   used in interfaces that require ABI stability.
 
+- GCC doesn't pack non-POD members in packed structs unless the packed
+  attribute is also specified on the member. Clang historically did perform
+  such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
+  You can switch back to the old ABI behavior with the flag:
+  ``-fclang-abi-compat=13.0``.
+
 OpenMP Support in Clang
 ---
 

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 09afa641acf9b..50c7f038fc6be 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -181,6 +181,10 @@ class LangOptions : public LangOptionsBase {
 /// global-scope inline variables incorrectly.
 Ver12,
 
+/// Attempt to be ABI-compatible with code generated by Clang 13.0.x.
+/// This causes clang to not pack non-POD members of packed structs.
+Ver13,
+
 /// Conform to the underlying platform's C and C++ ABIs as closely
 /// as we can.
 Latest

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 61a30ead165ef..709e05716a562 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1887,7 +1887,12 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
   UnfilledBitsInLastUnit = 0;
   LastBitfieldStorageUnitSize = 0;
 
-  bool FieldPacked = Packed || D->hasAttr();
+  llvm::Triple Target = Context.getTargetInfo().getTriple();
+  bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
+ Context.getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver13 ||
+ Target.isPS4() || Target.isOSDarwin())) ||
+ D->hasAttr();
 
   AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 7f1ce3da7e7eb..553a0b31c0ab3 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3560,6 +3560,8 @@ void CompilerInvocation::GenerateLangArgs(const 
LangOptions ,
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "11.0", SA);
   else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver12)
 GenerateArg(Args, OPT_fclang_abi_compat_EQ, "12.0", SA);
+  else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver13)
+GenerateArg(Args, OPT_fclang_abi_compat_EQ, "13.0", SA);
 
   if (Opts.getSignReturnAddressScope() ==
   LangOptions::SignReturnAddressScopeKind::All)
@@ -4062,6 +4064,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions , 
ArgList ,
 Opts.setClangABICompat(LangOptions::ClangABI::Ver11);
   else if (Major <= 12)
 Opts.setClangABICompat(LangOptions::ClangABI::Ver12);
+  else if (Major <= 13)
+Opts.setClangABICompat(LangOptions::ClangABI::Ver13);
 } else if (Ver != "latest") {
   Diags.Report(diag::err_drv_invalid_value)
   << A->getAsString(Args) << A->getValue();

diff  --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 5403bd6e6a6f6..79fa677071109 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only 

[clang] 9c62728 - Default to DWARFv4 on Windows

2022-01-26 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-26T18:01:07-08:00
New Revision: 9c6272861032f511a23784ce0c5cc8f6ac2f625b

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

LOG: Default to DWARFv4 on Windows

Added: 


Modified: 
clang/lib/Driver/ToolChains/MSVC.h
clang/test/CodeGen/dwarf-version.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/MSVC.h 
b/clang/lib/Driver/ToolChains/MSVC.h
index 8f033de09bf64..c842773996eda 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -69,6 +69,10 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public 
ToolChain {
 return llvm::DebuggerKind::Default;
   }
 
+  unsigned GetDefaultDwarfVersion() const override {
+return 4;
+  }
+
   enum class SubDirectoryType {
 Bin,
 Include,

diff  --git a/clang/test/CodeGen/dwarf-version.c 
b/clang/test/CodeGen/dwarf-version.c
index b329556ae0d9d..47025e241d13c 100644
--- a/clang/test/CodeGen/dwarf-version.c
+++ b/clang/test/CodeGen/dwarf-version.c
@@ -28,10 +28,10 @@
 // RUN: | FileCheck %s --check-prefixes=NODWARF,CODEVIEW
 // Explicitly request DWARF.
 // RUN: %clang -target i686-pc-windows-msvc -gdwarf -S -emit-llvm -o - %s \
-// RUN: | FileCheck %s --check-prefixes=VER5,NOCODEVIEW
+// RUN: | FileCheck %s --check-prefixes=VER4,NOCODEVIEW
 // Explicitly request both.
 // RUN: %clang -target i686-pc-windows-msvc -gdwarf -gcodeview -S -emit-llvm 
-o - %s \
-// RUN: | FileCheck %s --check-prefixes=VER5,CODEVIEW
+// RUN: | FileCheck %s --check-prefixes=VER4,CODEVIEW
 // RUN: %clang -target powerpc-ibm-aix-xcoff -g -S -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefix=VER3
 // RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-2 -S -emit-llvm -o - %s | 
\



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


[clang] 87e68ca - Improve relnotes for the DWARFv5 default change

2022-01-25 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-25T09:56:07-08:00
New Revision: 87e68cae50d7ca28975ca6fb456cf0ab2ac915a1

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

LOG: Improve relnotes for the DWARFv5 default change

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5cd2896de54d..2272d7197ac5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -256,9 +256,9 @@ DWARF Support in Clang
 --
 
 - The default DWARF version has increased from DWARFv4 to DWARFv5.  You can opt
-  back in to the old behavior with -gdwarf-4. Some platforms (Darwin, Android,
-  and SCE for instance) already opt out of this version bump as is suitable for
-  the platform
+  back in to the old behavior with ``-gdwarf-4`` or 
``-fdebug-default-version=4``.
+  Some platforms (Darwin, Android, and SCE for instance) already opt out of 
this
+  version bump as is suitable for the platform
 
 Arm and AArch64 Support in Clang
 



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


Re: [clang] d3b26de - Clang: Change the default DWARF version to 5

2022-01-24 Thread David Blaikie via cfe-commits
Oh, sorry, I see you are zmodem... yay for getting used to more usernames -
thanks for the workaround :)

On Mon, Jan 24, 2022 at 3:05 PM David Blaikie  wrote:

> Looks like that got addressed/worked around with
> https://github.com/llvm/llvm-project/commit/38e16e1cebb891ad47b85727bf46f7dac6d7da94
>
> I'll look into it further once I've cleaned up other live fallout.
>
> On Mon, Jan 24, 2022 at 10:01 AM Hans Wennborg  wrote:
>
>> For me, this broke some tests of the profiling runtime:
>>
>> $ ninja check-profile
>> ...
>> Failed Tests (2):
>>   Profile-i386 :: Linux/instrprof-debug-info-correlate.c
>>   Profile-x86_64 :: Linux/instrprof-debug-info-correlate.c
>>
>> Annoyingly, I can't find any buildbots where this fails, but I'm not
>> really sure which ones test this runtime.
>>
>> It also reproduces on Chromium's builders, e.g.
>>
>> https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8824141369391584977/+/u/package_clang/stdout
>>
>> Filed https://github.com/llvm/llvm-project/issues/53387
>>
>>
>> On Mon, Jan 24, 2022 at 5:50 AM David Blaikie via cfe-commits
>>  wrote:
>> >
>> >
>> > Author: David Blaikie
>> > Date: 2022-01-23T20:49:57-08:00
>> > New Revision: d3b26dea16108c427b19b5480c9edc76edf8f5b4
>> >
>> > URL:
>> https://github.com/llvm/llvm-project/commit/d3b26dea16108c427b19b5480c9edc76edf8f5b4
>> > DIFF:
>> https://github.com/llvm/llvm-project/commit/d3b26dea16108c427b19b5480c9edc76edf8f5b4.diff
>> >
>> > LOG: Clang: Change the default DWARF version to 5
>> >
>> > (except on platforms that already opt in to specific versions - SCE,
>> > Android, and Darwin using DWARFv4 explicitly, for instance)
>> >
>> > Added:
>> >
>> >
>> > Modified:
>> > clang/docs/ReleaseNotes.rst
>> > clang/include/clang/Driver/ToolChain.h
>> > clang/lib/Driver/ToolChains/Linux.h
>> > clang/test/CodeGen/debug-info-extern-call.c
>> > clang/test/CodeGen/dwarf-version.c
>> > clang/test/Driver/cl-options.c
>> > clang/test/Driver/clang-g-opts.c
>> > clang/test/Driver/ve-toolchain.c
>> > clang/test/Driver/ve-toolchain.cpp
>> >
>> > Removed:
>> >
>> >
>> >
>> >
>> 
>> > diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
>> > index 2eec63901932e..4fe037741256f 100644
>> > --- a/clang/docs/ReleaseNotes.rst
>> > +++ b/clang/docs/ReleaseNotes.rst
>> > @@ -252,6 +252,14 @@ X86 Support in Clang
>> >
>> >  - Support for ``AVX512-FP16`` instructions has been added.
>> >
>> > +DWARF Support in Clang
>> > +--
>> > +
>> > +- The default DWARF version has increased from DWARFv4 to DWARFv5.
>> You can opt
>> > +  back in to the old behavior with -gdwarf-4. Some platforms (Darwin,
>> Android,
>> > +  and SCE for instance) already opt out of this version bump as is
>> suitable for
>> > +  the platform
>> > +
>> >  Arm and AArch64 Support in Clang
>> >  
>> >
>> >
>> > diff  --git a/clang/include/clang/Driver/ToolChain.h
>> b/clang/include/clang/Driver/ToolChain.h
>> > index eb95806a2f75d..37011de6bd6d7 100644
>> > --- a/clang/include/clang/Driver/ToolChain.h
>> > +++ b/clang/include/clang/Driver/ToolChain.h
>> > @@ -510,7 +510,7 @@ class ToolChain {
>> >
>> >// Return the DWARF version to emit, in the absence of arguments
>> >// to the contrary.
>> > -  virtual unsigned GetDefaultDwarfVersion() const { return 4; }
>> > +  virtual unsigned GetDefaultDwarfVersion() const { return 5; }
>> >
>> >// Some toolchains may have
>> > diff erent restrictions on the DWARF version and
>> >// may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even
>> when host
>> >
>> > diff  --git a/clang/lib/Driver/ToolChains/Linux.h
>> b/clang/lib/Driver/ToolChains/Linux.h
>> > index a5ec33bd44f10..a5648d79d655f 100644
>> > --- a/clang/lib/Driver/ToolChains/Linux.h
>> > +++ b/clang/lib/Driver/ToolChains/Linux.h
>> > @@ -40,6 +40,7 @@ class LLVM_LIBRARY_VISIBILITY Linux : public
>> Generic_ELF {
>> >void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
>> >  

Re: [clang] d3b26de - Clang: Change the default DWARF version to 5

2022-01-24 Thread David Blaikie via cfe-commits
Looks like that got addressed/worked around with
https://github.com/llvm/llvm-project/commit/38e16e1cebb891ad47b85727bf46f7dac6d7da94

I'll look into it further once I've cleaned up other live fallout.

On Mon, Jan 24, 2022 at 10:01 AM Hans Wennborg  wrote:

> For me, this broke some tests of the profiling runtime:
>
> $ ninja check-profile
> ...
> Failed Tests (2):
>   Profile-i386 :: Linux/instrprof-debug-info-correlate.c
>   Profile-x86_64 :: Linux/instrprof-debug-info-correlate.c
>
> Annoyingly, I can't find any buildbots where this fails, but I'm not
> really sure which ones test this runtime.
>
> It also reproduces on Chromium's builders, e.g.
>
> https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8824141369391584977/+/u/package_clang/stdout
>
> Filed https://github.com/llvm/llvm-project/issues/53387
>
>
> On Mon, Jan 24, 2022 at 5:50 AM David Blaikie via cfe-commits
>  wrote:
> >
> >
> > Author: David Blaikie
> > Date: 2022-01-23T20:49:57-08:00
> > New Revision: d3b26dea16108c427b19b5480c9edc76edf8f5b4
> >
> > URL:
> https://github.com/llvm/llvm-project/commit/d3b26dea16108c427b19b5480c9edc76edf8f5b4
> > DIFF:
> https://github.com/llvm/llvm-project/commit/d3b26dea16108c427b19b5480c9edc76edf8f5b4.diff
> >
> > LOG: Clang: Change the default DWARF version to 5
> >
> > (except on platforms that already opt in to specific versions - SCE,
> > Android, and Darwin using DWARFv4 explicitly, for instance)
> >
> > Added:
> >
> >
> > Modified:
> > clang/docs/ReleaseNotes.rst
> > clang/include/clang/Driver/ToolChain.h
> > clang/lib/Driver/ToolChains/Linux.h
> > clang/test/CodeGen/debug-info-extern-call.c
> > clang/test/CodeGen/dwarf-version.c
> > clang/test/Driver/cl-options.c
> > clang/test/Driver/clang-g-opts.c
> > clang/test/Driver/ve-toolchain.c
> > clang/test/Driver/ve-toolchain.cpp
> >
> > Removed:
> >
> >
> >
> >
> 
> > diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
> > index 2eec63901932e..4fe037741256f 100644
> > --- a/clang/docs/ReleaseNotes.rst
> > +++ b/clang/docs/ReleaseNotes.rst
> > @@ -252,6 +252,14 @@ X86 Support in Clang
> >
> >  - Support for ``AVX512-FP16`` instructions has been added.
> >
> > +DWARF Support in Clang
> > +--
> > +
> > +- The default DWARF version has increased from DWARFv4 to DWARFv5.  You
> can opt
> > +  back in to the old behavior with -gdwarf-4. Some platforms (Darwin,
> Android,
> > +  and SCE for instance) already opt out of this version bump as is
> suitable for
> > +  the platform
> > +
> >  Arm and AArch64 Support in Clang
> >  
> >
> >
> > diff  --git a/clang/include/clang/Driver/ToolChain.h
> b/clang/include/clang/Driver/ToolChain.h
> > index eb95806a2f75d..37011de6bd6d7 100644
> > --- a/clang/include/clang/Driver/ToolChain.h
> > +++ b/clang/include/clang/Driver/ToolChain.h
> > @@ -510,7 +510,7 @@ class ToolChain {
> >
> >// Return the DWARF version to emit, in the absence of arguments
> >// to the contrary.
> > -  virtual unsigned GetDefaultDwarfVersion() const { return 4; }
> > +  virtual unsigned GetDefaultDwarfVersion() const { return 5; }
> >
> >// Some toolchains may have
> > diff erent restrictions on the DWARF version and
> >// may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even
> when host
> >
> > diff  --git a/clang/lib/Driver/ToolChains/Linux.h
> b/clang/lib/Driver/ToolChains/Linux.h
> > index a5ec33bd44f10..a5648d79d655f 100644
> > --- a/clang/lib/Driver/ToolChains/Linux.h
> > +++ b/clang/lib/Driver/ToolChains/Linux.h
> > @@ -40,6 +40,7 @@ class LLVM_LIBRARY_VISIBILITY Linux : public
> Generic_ELF {
> >void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
> > llvm::opt::ArgStringList ) const
> override;
> >RuntimeLibType GetDefaultRuntimeLibType() const override;
> > +  unsigned GetDefaultDwarfVersion() const override;
> >CXXStdlibType GetDefaultCXXStdlibType() const override;
> >bool
> >IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList ) const
> override;
> >
> > diff  --git a/clang/test/CodeGen/debug-info-extern-call.c
> b/clang/test/CodeGen/debug-info-extern-call.c
> > index 7cf90550ac00a..fad52d0df0b3f 100644
> > --- a/clang/test/CodeGen/debug-info-extern-call.c
> >

[clang] 90abe18 - Add missing function implementation from DWARF default change

2022-01-23 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-23T21:10:16-08:00
New Revision: 90abe181da7c61d982e4873c97fd12bc06fefe09

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

LOG: Add missing function implementation from DWARF default change

Fix for d3b26dea16108c427b19b5480c9edc76edf8f5b4

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index e413640abad3..af74b108e04e 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -324,6 +324,12 @@ ToolChain::RuntimeLibType 
Linux::GetDefaultRuntimeLibType() const {
   return Generic_ELF::GetDefaultRuntimeLibType();
 }
 
+unsigned Linux::GetDefaultDwarfVersion() const {
+  if (getTriple().isAndroid())
+return 4;
+  return ToolChain::GetDefaultDwarfVersion();
+}
+
 ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const {
   if (getTriple().isAndroid())
 return ToolChain::CST_Libcxx;



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


[clang] d3b26de - Clang: Change the default DWARF version to 5

2022-01-23 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-23T20:49:57-08:00
New Revision: d3b26dea16108c427b19b5480c9edc76edf8f5b4

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

LOG: Clang: Change the default DWARF version to 5

(except on platforms that already opt in to specific versions - SCE,
Android, and Darwin using DWARFv4 explicitly, for instance)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChains/Linux.h
clang/test/CodeGen/debug-info-extern-call.c
clang/test/CodeGen/dwarf-version.c
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/ve-toolchain.c
clang/test/Driver/ve-toolchain.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2eec63901932e..4fe037741256f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -252,6 +252,14 @@ X86 Support in Clang
 
 - Support for ``AVX512-FP16`` instructions has been added.
 
+DWARF Support in Clang
+--
+
+- The default DWARF version has increased from DWARFv4 to DWARFv5.  You can opt
+  back in to the old behavior with -gdwarf-4. Some platforms (Darwin, Android,
+  and SCE for instance) already opt out of this version bump as is suitable for
+  the platform
+
 Arm and AArch64 Support in Clang
 
 

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index eb95806a2f75d..37011de6bd6d7 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -510,7 +510,7 @@ class ToolChain {
 
   // Return the DWARF version to emit, in the absence of arguments
   // to the contrary.
-  virtual unsigned GetDefaultDwarfVersion() const { return 4; }
+  virtual unsigned GetDefaultDwarfVersion() const { return 5; }
 
   // Some toolchains may have 
diff erent restrictions on the DWARF version and
   // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when 
host

diff  --git a/clang/lib/Driver/ToolChains/Linux.h 
b/clang/lib/Driver/ToolChains/Linux.h
index a5ec33bd44f10..a5648d79d655f 100644
--- a/clang/lib/Driver/ToolChains/Linux.h
+++ b/clang/lib/Driver/ToolChains/Linux.h
@@ -40,6 +40,7 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
   void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
   RuntimeLibType GetDefaultRuntimeLibType() const override;
+  unsigned GetDefaultDwarfVersion() const override;
   CXXStdlibType GetDefaultCXXStdlibType() const override;
   bool
   IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList ) const 
override;

diff  --git a/clang/test/CodeGen/debug-info-extern-call.c 
b/clang/test/CodeGen/debug-info-extern-call.c
index 7cf90550ac00a..fad52d0df0b3f 100644
--- a/clang/test/CodeGen/debug-info-extern-call.c
+++ b/clang/test/CodeGen/debug-info-extern-call.c
@@ -12,13 +12,13 @@
 // decls so that the dwarf generator can describe information needed for tail
 // call frame reconstrution.
 //
-// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -ggdb -S -emit-llvm %s -o 
- \
+// RUN: %clang -gdwarf-4 -O2 -target x86_64-none-linux-gnu -ggdb -S -emit-llvm 
%s -o - \
 // RUN:   | FileCheck %s -check-prefix=DECLS-FOR-EXTERN
 //
 // Do not emit a subprogram for extern decls when entry values are disabled and
 // the tuning is not set to gdb.
 //
-// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o 
- \
+// RUN: %clang -gdwarf-4 -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm 
%s -o - \
 // RUN:   | FileCheck %s -check-prefix=NO-DECLS-FOR-EXTERN
 
 // DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: !{{[0-9]+}}

diff  --git a/clang/test/CodeGen/dwarf-version.c 
b/clang/test/CodeGen/dwarf-version.c
index 6d131c470d5b3..b329556ae0d9d 100644
--- a/clang/test/CodeGen/dwarf-version.c
+++ b/clang/test/CodeGen/dwarf-version.c
@@ -2,8 +2,8 @@
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-3 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER3
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-4 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-5 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
-// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER4
-// RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
+// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
+// RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 
 // The -isysroot is 

[clang] baa9b7c - unique_ptrify the ModuleManager's VisitState linked list

2022-01-19 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-19T09:57:46-08:00
New Revision: baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810

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

LOG: unique_ptrify the ModuleManager's VisitState linked list

Added: 


Modified: 
clang/include/clang/Serialization/ModuleManager.h
clang/lib/Serialization/ModuleManager.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ModuleManager.h 
b/clang/include/clang/Serialization/ModuleManager.h
index 7081eedad4b49..4305bae5ee958 100644
--- a/clang/include/clang/Serialization/ModuleManager.h
+++ b/clang/include/clang/Serialization/ModuleManager.h
@@ -105,10 +105,6 @@ class ModuleManager {
   Stack.reserve(N);
 }
 
-~VisitState() {
-  delete NextState;
-}
-
 /// The stack used when marking the imports of a particular module
 /// as not-to-be-visited.
 SmallVector Stack;
@@ -121,14 +117,14 @@ class ModuleManager {
 unsigned NextVisitNumber = 1;
 
 /// The next visit state.
-VisitState *NextState = nullptr;
+std::unique_ptr NextState;
   };
 
   /// The first visit() state in the chain.
-  VisitState *FirstVisitState = nullptr;
+  std::unique_ptr FirstVisitState;
 
-  VisitState *allocateVisitState();
-  void returnVisitState(VisitState *State);
+  std::unique_ptr allocateVisitState();
+  void returnVisitState(std::unique_ptr State);
 
 public:
   using ModuleIterator = llvm::pointee_iterator<
@@ -142,7 +138,6 @@ class ModuleManager {
   explicit ModuleManager(FileManager , InMemoryModuleCache 
,
  const PCHContainerReader ,
  const HeaderSearch );
-  ~ModuleManager();
 
   /// Forward iterator to traverse all loaded modules.
   ModuleIterator begin() { return Chain.begin(); }

diff  --git a/clang/lib/Serialization/ModuleManager.cpp 
b/clang/lib/Serialization/ModuleManager.cpp
index f4882c7be3f7d..4fd217cf7a6ea 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -304,23 +304,22 @@ ModuleManager::addInMemoryBuffer(StringRef FileName,
   InMemoryBuffers[Entry] = std::move(Buffer);
 }
 
-ModuleManager::VisitState *ModuleManager::allocateVisitState() {
+std::unique_ptr ModuleManager::allocateVisitState() 
{
   // Fast path: if we have a cached state, use it.
   if (FirstVisitState) {
-VisitState *Result = FirstVisitState;
-FirstVisitState = FirstVisitState->NextState;
-Result->NextState = nullptr;
+auto Result = std::move(FirstVisitState);
+FirstVisitState = std::move(Result->NextState);
 return Result;
   }
 
   // Allocate and return a new state.
-  return new VisitState(size());
+  return std::make_unique(size());
 }
 
-void ModuleManager::returnVisitState(VisitState *State) {
+void ModuleManager::returnVisitState(std::unique_ptr State) {
   assert(State->NextState == nullptr && "Visited state is in list?");
-  State->NextState = FirstVisitState;
-  FirstVisitState = State;
+  State->NextState = std::move(FirstVisitState);
+  FirstVisitState = std::move(State);
 }
 
 void ModuleManager::setGlobalIndex(GlobalModuleIndex *Index) {
@@ -351,8 +350,6 @@ ModuleManager::ModuleManager(FileManager ,
 : FileMgr(FileMgr), ModuleCache(),
   PCHContainerRdr(PCHContainerRdr), HeaderSearchInfo(HeaderSearchInfo) {}
 
-ModuleManager::~ModuleManager() { delete FirstVisitState; }
-
 void ModuleManager::visit(llvm::function_ref Visitor,
   llvm::SmallPtrSetImpl *ModuleFilesHit) 
{
   // If the visitation order vector is the wrong size, recompute the order.
@@ -396,11 +393,10 @@ void 
ModuleManager::visit(llvm::function_ref Visitor,
 
 assert(VisitOrder.size() == N && "Visitation order is wrong?");
 
-delete FirstVisitState;
 FirstVisitState = nullptr;
   }
 
-  VisitState *State = allocateVisitState();
+  auto State = allocateVisitState();
   unsigned VisitNumber = State->NextVisitNumber++;
 
   // If the caller has provided us with a hit-set that came from the global
@@ -452,7 +448,7 @@ void 
ModuleManager::visit(llvm::function_ref Visitor,
 } while (true);
   }
 
-  returnVisitState(State);
+  returnVisitState(std::move(State));
 }
 
 bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,



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


[clang] e1e74f6 - -Wmissing-prototypes: Don't warn in named namespaces nested in anonymous namespaces

2022-01-04 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-01-04T10:08:23-08:00
New Revision: e1e74f6cd6ce41ce8303a5a91f29736808fccc36

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

LOG: -Wmissing-prototypes: Don't warn in named namespaces nested in anonymous 
namespaces

Added: 


Modified: 
clang/lib/AST/Decl.cpp
clang/test/SemaCXX/warn-missing-prototypes.cpp

Removed: 




diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index e63560f1b6fea..3ef08cab96750 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3251,7 +3251,6 @@ bool FunctionDecl::isGlobal() const {
 if (const auto *Namespace = cast(DC)) {
   if (!Namespace->getDeclName())
 return false;
-  break;
 }
   }
 

diff  --git a/clang/test/SemaCXX/warn-missing-prototypes.cpp 
b/clang/test/SemaCXX/warn-missing-prototypes.cpp
index bb71aa8b142d1..e8637e5a90eab 100644
--- a/clang/test/SemaCXX/warn-missing-prototypes.cpp
+++ b/clang/test/SemaCXX/warn-missing-prototypes.cpp
@@ -13,6 +13,10 @@ namespace NS {
 namespace {
   // Don't warn about functions in anonymous namespaces.
   void f() { }
+  // Even if they're in nested namespaces within an anonymous namespace.
+  namespace NS {
+void f() { }
+  }
 }
 
 struct A {



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


Re: [clang] ea22fdd - [Clang][DebugInfo] Cease turning instruction-referencing off by default

2021-12-22 Thread David Blaikie via cfe-commits
On Wed, Dec 22, 2021 at 11:47 AM Jeremy Morse 
wrote:

> On Wed, Dec 22, 2021 at 4:34 PM David Blaikie via cfe-commits
>  wrote:
> > Is there a way to turn this off now, if it's broken for some user/use
> case? I guess using an -mllvm flag, instead of an -Xclang flag?
>
> Yup, that should be achieved by "-mllvm
> -experimental-debug-variable-locations=false", there's a test for that
> in llvm/test/DebugInfo/X86/instr-ref-flag.ll.
>

Fair enough - probably would've been good to have that flag in this commit
message (hopefully some folks can find it here in the email thread) - and I
think I probably would've left the clang flag in (& changed its default) to
"ship" the feature (though, as you said on the other thread - LTO wouldn't
be affected by that flag flip, so would also have to make the change down
in LLVM too - sort of nice that they happened separately, really, to create
an incremental rollout)

Ah well - sounds alright, thanks for the details!


>
> > Generally I think for a significant change like this the process would
> be to add it under a flag, off by default, encourage people to test it by
> opting in via the flag, eventually change the default for the flag (letting
> people know they can opt-out using the flag if they see problems & to
> report them to you so they can be fixed & hopefully they can stop opting
> out) & then remove the flag when it's stable. Reverting a patch to disable
> a newly-on-by-default feature is a bit heavyweight and it can be nice to
> have a flag to control it while it's getting more exposure/experience.
>
> Indeed, I'd hoped this was largely achieved with
> https://lists.llvm.org/pipermail/llvm-dev/2021-July/151965.html , I
> guess what's missing is better communicating in how to opt out now,
> alas. It's unfortunate that people bisecting back are going to find
> this commit; I couldn't think of another way of rectifying things
> without pushing up several reverts and the re-applies at the same time
> though.
>
> --
> Thanks,
> Jeremy
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] ea22fdd - [Clang][DebugInfo] Cease turning instruction-referencing off by default

2021-12-22 Thread David Blaikie via cfe-commits
Is there a way to turn this off now, if it's broken for some user/use case?
I guess using an -mllvm flag, instead of an -Xclang flag?

Generally I think for a significant change like this the process would be
to add it under a flag, off by default, encourage people to test it by
opting in via the flag, eventually change the default for the flag (letting
people know they can opt-out using the flag if they see problems & to
report them to you so they can be fixed & hopefully they can stop opting
out) & then remove the flag when it's stable. Reverting a patch to disable
a newly-on-by-default feature is a bit heavyweight and it can be nice to
have a flag to control it while it's getting more exposure/experience.

On Wed, Dec 22, 2021 at 11:31 AM Jeremy Morse via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Jeremy Morse
> Date: 2021-12-22T16:30:05Z
> New Revision: ea22fdd120aeb1bbb9ea96670d70193dc02b2c5f
>
> URL:
> https://github.com/llvm/llvm-project/commit/ea22fdd120aeb1bbb9ea96670d70193dc02b2c5f
> DIFF:
> https://github.com/llvm/llvm-project/commit/ea22fdd120aeb1bbb9ea96670d70193dc02b2c5f.diff
>
> LOG: [Clang][DebugInfo] Cease turning instruction-referencing off by
> default
>
> Over in D114631 I turned this debug-info feature on by default, for x86_64
> only. I'd previously stripped out the clang cc1 option that controlled it
> in 651122fc4ac, unfortunately that turned out to not be completely
> effective, and the two things deleted in this patch continued to keep it
> off-by-default.  Oooff.
>
> As a follow-up, this patch removes the last few things to do with
> ValueTrackingVariableLocations from clang, which was the original purpose
> of D114631. In an ideal world, if this patch causes you trouble you'd
> revert 3c045070882f instead, which was where this behaviour was supposed
> to start being the default, although that might not be practical any more.
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/CodeGenOptions.def
> clang/lib/CodeGen/BackendUtil.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/CodeGenOptions.def
> b/clang/include/clang/Basic/CodeGenOptions.def
> index 94b3003a9c33c..723302f108e20 100644
> --- a/clang/include/clang/Basic/CodeGenOptions.def
> +++ b/clang/include/clang/Basic/CodeGenOptions.def
> @@ -368,9 +368,6 @@ ENUM_CODEGENOPT(DebuggerTuning, llvm::DebuggerKind, 3,
>  /// emitted.
>  VALUE_CODEGENOPT(DwarfVersion, 3, 0)
>
> -/// Whether to use experimental new variable location tracking.
> -CODEGENOPT(ValueTrackingVariableLocations, 1, 0)
> -
>  /// Whether we should emit CodeView debug information. It's possible to
> emit
>  /// CodeView and DWARF into the same object.
>  CODEGENOPT(EmitCodeView, 1, 0)
>
> diff  --git a/clang/lib/CodeGen/BackendUtil.cpp
> b/clang/lib/CodeGen/BackendUtil.cpp
> index 5e16d3525b383..bacac0a20d4d5 100644
> --- a/clang/lib/CodeGen/BackendUtil.cpp
> +++ b/clang/lib/CodeGen/BackendUtil.cpp
> @@ -603,8 +603,6 @@ static bool initTargetOptions(DiagnosticsEngine ,
>Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
>Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
>Options.EnableAIXExtendedAltivecABI =
> CodeGenOpts.EnableAIXExtendedAltivecABI;
> -  Options.ValueTrackingVariableLocations =
> -  CodeGenOpts.ValueTrackingVariableLocations;
>Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;
>Options.LoopAlignment = CodeGenOpts.LoopAlignment;
>
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] b8e03be - [PS4][DWARF] Explicitly set default DWARF version to 4

2021-12-06 Thread David Blaikie via cfe-commits
Guess this is untestable right now, since it's overriding with the same
value? Maybe worth adding an explicit test for the PS4 default - so that
the test would fail /if/ the generic (non-PS4) default was changed (which
we'll hopefully change in the near future)?

On Tue, Nov 30, 2021 at 8:59 AM Paul Robinson via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Paul Robinson
> Date: 2021-11-30T08:58:40-08:00
> New Revision: b8e03be88dc87303f7401ea7b9906947ac67a6db
>
> URL:
> https://github.com/llvm/llvm-project/commit/b8e03be88dc87303f7401ea7b9906947ac67a6db
> DIFF:
> https://github.com/llvm/llvm-project/commit/b8e03be88dc87303f7401ea7b9906947ac67a6db.diff
>
> LOG: [PS4][DWARF] Explicitly set default DWARF version to 4
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/PS4CPU.h
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.h
> b/clang/lib/Driver/ToolChains/PS4CPU.h
> index 82f9523f84fb8..4bedabaf267c0 100644
> --- a/clang/lib/Driver/ToolChains/PS4CPU.h
> +++ b/clang/lib/Driver/ToolChains/PS4CPU.h
> @@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PS4CPU : public
> Generic_ELF {
>  return LangOptions::SSPStrong;
>}
>
> +  unsigned GetDefaultDwarfVersion() const override { return 4; }
>llvm::DebuggerKind getDefaultDebuggerTuning() const override {
>  return llvm::DebuggerKind::SCE;
>}
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 50fdd7d - Add more test coverage for D77598

2021-11-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-14T21:09:11-08:00
New Revision: 50fdd7df827137c8465abafa82a6bae7c87096c5

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

LOG: Add more test coverage for D77598

Add coverage to demonstrate why including the type of template
parameters is necessary to disambiguate function template
specializations.

Test courtesy of Richard Smith

Added: 


Modified: 
clang/test/AST/ast-dump-templates.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-templates.cpp 
b/clang/test/AST/ast-dump-templates.cpp
index b08bc76ed179..3d26eb917c12 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -93,3 +93,14 @@ void test() {
 // CHECK1: {{^}}template<> struct foo<1, 0 + 0L> {
 template struct foo<1, 0 + 0L>;
 }
+
+namespace test5 {
+template void f() {}
+void (*p)() = f<0>;
+template void f() {}
+void (*q)() = f<>;
+// Not perfect - this code in the dump would be ambiguous, but it's the best we
+// can do to 
diff erentiate these two implicit specializations.
+// CHECK1: template<> void f<0L>()
+// CHECK1: template<> void f<0U>()
+}



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


[clang] b2589e3 - ast-print: Avoid extra whitespace before function opening brace

2021-11-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-14T20:45:16-08:00
New Revision: b2589e326ba4407d8314938a4f7498086e2203ea

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

LOG: ast-print: Avoid extra whitespace before function opening brace

Added: 


Modified: 
clang/include/clang/AST/Stmt.h
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/StmtPrinter.cpp
clang/test/AST/ast-dump-templates.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 73cbff537847..a32126d23d31 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1216,6 +1216,11 @@ class alignas(void *) Stmt {
const PrintingPolicy , unsigned Indentation = 0,
StringRef NewlineSymbol = "\n",
const ASTContext *Context = nullptr) const;
+  void printPrettyControlled(raw_ostream , PrinterHelper *Helper,
+ const PrintingPolicy ,
+ unsigned Indentation = 0,
+ StringRef NewlineSymbol = "\n",
+ const ASTContext *Context = nullptr) const;
 
   /// Pretty-prints in JSON format.
   void printJson(raw_ostream , PrinterHelper *Helper,

diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 5c6781c26ed7..044eb8f8f8e5 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -782,11 +782,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   Out << ";\n";
 }
 Indentation -= Policy.Indentation;
-  } else
-Out << ' ';
+  }
 
   if (D->getBody())
-D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation, "\n",
+D->getBody()->printPrettyControlled(Out, nullptr, SubPolicy, 
Indentation, "\n",
   );
 } else {
   if (!Policy.TerseOutput && isa(*D))

diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 12af5bfa2013..fc267d7006a1 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2595,6 +2595,14 @@ void Stmt::printPretty(raw_ostream , PrinterHelper 
*Helper,
   P.Visit(const_cast(this));
 }
 
+void Stmt::printPrettyControlled(raw_ostream , PrinterHelper *Helper,
+ const PrintingPolicy ,
+ unsigned Indentation, StringRef NL,
+ const ASTContext *Context) const {
+  StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
+  P.PrintControlledStmt(const_cast(this));
+}
+
 void Stmt::printJson(raw_ostream , PrinterHelper *Helper,
  const PrintingPolicy , bool AddQuotes) const {
   std::string Buf;

diff  --git a/clang/test/AST/ast-dump-templates.cpp 
b/clang/test/AST/ast-dump-templates.cpp
index dcecdca58c75..b08bc76ed179 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -79,6 +79,8 @@ struct foo {
 // type/unsigned argument (see
 // TemplateParameterList::shouldIncludeTypeForArgument)
 // CHECK1: {{^}}template<> struct foo<0, 0L> {
+// CHECK1: {{^}}void test(){{ }}{
+// CHECK1: {{^}}foo<0, 0 + 0L>::fn();
 void test() {
   foo<0, 0 + 0L>::fn();
 }



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


[clang] 604446a - ast-dump: Add missing identation of class template specializations

2021-11-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-14T20:45:16-08:00
New Revision: 604446aa6b41461e2691c9f4253e9ef70a5d68e4

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

LOG: ast-dump: Add missing identation of class template specializations

Added: 


Modified: 
clang/lib/AST/DeclPrinter.cpp
clang/test/AST/ast-dump-templates.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 884b8e730905..5c6781c26ed7 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1185,6 +1185,7 @@ void 
DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 if (D->isThisDeclarationADefinition())
   Out << ";";
 Out << "\n";
+Indent();
 Visit(I);
   }
   }

diff  --git a/clang/test/AST/ast-dump-templates.cpp 
b/clang/test/AST/ast-dump-templates.cpp
index cb2994edcc67..dcecdca58c75 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -78,7 +78,7 @@ struct foo {
 // includes the type for the auto argument and omits it for the fixed
 // type/unsigned argument (see
 // TemplateParameterList::shouldIncludeTypeForArgument)
-// CHECK1: template<> struct foo<0, 0L> {
+// CHECK1: {{^}}template<> struct foo<0, 0L> {
 void test() {
   foo<0, 0 + 0L>::fn();
 }
@@ -88,6 +88,6 @@ void test() {
 // powered by the shouldIncludeTypeForArgument functionality.
 // Not sure if this it's intentional that these two specializations are 
rendered
 // 
diff erently in this way.
-// CHECK1: template<> struct foo<1, 0 + 0L> {
+// CHECK1: {{^}}template<> struct foo<1, 0 + 0L> {
 template struct foo<1, 0 + 0L>;
 }



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


[clang] 400eb59 - Add test for a case in D77598

2021-11-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-14T20:45:16-08:00
New Revision: 400eb59adf43b29af3117c163cf770e6d6e514f7

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

LOG: Add test for a case in D77598

This covers the DeclPrinter::VisitCXXRecordDecl caller - though also
demonstrates some possible inconsistency in template specialization
printing.

Added: 


Modified: 
clang/test/AST/ast-dump-templates.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-templates.cpp 
b/clang/test/AST/ast-dump-templates.cpp
index ab4a7356028e1..cb2994edcc67e 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -67,3 +67,27 @@ namespace test3 {
   template A(T) -> A;
   // CHECK1: template  A(T) -> A;
 }
+
+namespace test4 {
+template 
+struct foo {
+  static void fn();
+};
+
+// Prints using an "integral" template argument. Test that this correctly
+// includes the type for the auto argument and omits it for the fixed
+// type/unsigned argument (see
+// TemplateParameterList::shouldIncludeTypeForArgument)
+// CHECK1: template<> struct foo<0, 0L> {
+void test() {
+  foo<0, 0 + 0L>::fn();
+}
+
+// Prints using an "expression" template argument. This renders based on the 
way
+// the user wrote the arguments (including that + expression) - so it's not
+// powered by the shouldIncludeTypeForArgument functionality.
+// Not sure if this it's intentional that these two specializations are 
rendered
+// 
diff erently in this way.
+// CHECK1: template<> struct foo<1, 0 + 0L> {
+template struct foo<1, 0 + 0L>;
+}



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


[clang] 5de3690 - Follow-up to D77598: Simplify API by passing template parameters only when used/to imply "TemplOverloaded/overloadable"

2021-11-14 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-14T13:35:22-08:00
New Revision: 5de369056dee2c4de81625cb05a5c212a0bdc053

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

LOG: Follow-up to D77598: Simplify API by passing template parameters only when 
used/to imply "TemplOverloaded/overloadable"

These arguments were redundant, and other parts of D77598 did rely on
the presence/absence of template parameters to imply whether types
should be included for the argument (like
clang::printTemplateArgumentList) so do that here too.

Added: 


Modified: 
clang/lib/AST/DeclPrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 38f2d10cdc90..884b8e730905 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -112,11 +112,9 @@ namespace {
 void printTemplateParameters(const TemplateParameterList *Params,
  bool OmitTemplateKW = false);
 void printTemplateArguments(llvm::ArrayRef Args,
-const TemplateParameterList *Params,
-bool TemplOverloaded);
+const TemplateParameterList *Params);
 void printTemplateArguments(llvm::ArrayRef Args,
-const TemplateParameterList *Params,
-bool TemplOverloaded);
+const TemplateParameterList *Params);
 void prettyPrintAttributes(Decl *D);
 void prettyPrintPragmas(Decl *D);
 void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
@@ -652,16 +650,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
 llvm::raw_string_ostream POut(Proto);
 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
 const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten();
-const TemplateParameterList *TPL = D->getTemplateSpecializationInfo()
-   ->getTemplate()
-   ->getTemplateParameters();
 if (TArgAsWritten && !Policy.PrintCanonicalTypes)
-  TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), TPL,
- /*TemplOverloaded*/ true);
+  TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), nullptr);
 else if (const TemplateArgumentList *TArgs =
  D->getTemplateSpecializationArgs())
-  TArgPrinter.printTemplateArguments(TArgs->asArray(), TPL,
- /*TemplOverloaded*/ true);
+  TArgPrinter.printTemplateArguments(TArgs->asArray(), nullptr);
   }
 
   QualType Ty = D->getType();
@@ -1002,8 +995,7 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
   dyn_cast(TSI->getType()))
 Args = TST->template_arguments();
   printTemplateArguments(
-  Args, S->getSpecializedTemplate()->getTemplateParameters(),
-  /*TemplOverloaded*/ false);
+  Args, S->getSpecializedTemplate()->getTemplateParameters());
 }
   }
 
@@ -1096,13 +1088,12 @@ void DeclPrinter::printTemplateParameters(const 
TemplateParameterList *Params,
 }
 
 void DeclPrinter::printTemplateArguments(ArrayRef Args,
- const TemplateParameterList *Params,
- bool TemplOverloaded) {
+ const TemplateParameterList *Params) {
   Out << "<";
   for (size_t I = 0, E = Args.size(); I < E; ++I) {
 if (I)
   Out << ", ";
-if (TemplOverloaded || !Params)
+if (!Params)
   Args[I].print(Policy, Out, /*IncludeType*/ true);
 else
   Args[I].print(Policy, Out,
@@ -1113,13 +1104,12 @@ void 
DeclPrinter::printTemplateArguments(ArrayRef Args,
 }
 
 void DeclPrinter::printTemplateArguments(ArrayRef Args,
- const TemplateParameterList *Params,
- bool TemplOverloaded) {
+ const TemplateParameterList *Params) {
   Out << "<";
   for (size_t I = 0, E = Args.size(); I < E; ++I) {
 if (I)
   Out << ", ";
-if (TemplOverloaded)
+if (!Params)
   Args[I].getArgument().print(Policy, Out, /*IncludeType*/ true);
 else
   Args[I].getArgument().print(



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


[clang] 6512098 - DebugInfo/Printing: Improve name of policy for including types for template arguments

2021-11-11 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-11T21:59:27-08:00
New Revision: 6512098877c3a230bbd38bc81b14a4e5844739ff

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

LOG: DebugInfo/Printing: Improve name of policy for including types for 
template arguments

Feedback from Richard Smith that the policy should be named closer to
the context its used in.

Added: 


Modified: 
clang/include/clang/AST/PrettyPrinter.h
clang/lib/AST/DeclTemplate.cpp
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 38d122db0749..f6816e938f2a 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -75,7 +75,7 @@ struct PrintingPolicy {
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
 PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
-UsePreferredNames(true), UseIntegerTypeSuffixesAlways(false) {}
+UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -280,7 +280,7 @@ struct PrintingPolicy {
 
   /// Whether to use type suffixes (eg: 1U) on integral non-type template
   /// parameters.
-  unsigned UseIntegerTypeSuffixesAlways : 1;
+  unsigned AlwaysIncludeTypeForTemplateArgument : 1;
 
   /// Callbacks to use to allow the behavior of printing to be customized.
   const PrintingCallbacks *Callbacks = nullptr;

diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 10f7155fcb96..223f06b9db1c 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -204,7 +204,7 @@ bool TemplateParameterList::hasAssociatedConstraints() 
const {
 bool TemplateParameterList::shouldIncludeTypeForArgument(
 const PrintingPolicy , const TemplateParameterList *TPL,
 unsigned Idx) {
-  if (!TPL || Idx >= TPL->size() || Policy.UseIntegerTypeSuffixesAlways)
+  if (!TPL || Idx >= TPL->size() || 
Policy.AlwaysIncludeTypeForTemplateArgument)
 return true;
   const NamedDecl *TemplParam = TPL->getParam(Idx);
   if (const auto *ParamValueDecl =

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 1ce56f98e1f0..af651e6f44b7 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -247,7 +247,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   PP.SuppressInlineNamespace = false;
   PP.PrintCanonicalTypes = true;
   PP.UsePreferredNames = false;
-  PP.UseIntegerTypeSuffixesAlways = true;
+  PP.AlwaysIncludeTypeForTemplateArgument = true;
 
   // Apply -fdebug-prefix-map.
   PP.Callbacks = 



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


[clang] 8bf1244 - DebugInfo: workaround for context-sensitive use of non-type-template-parameter integer suffixes

2021-11-01 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-11-01T17:08:26-07:00
New Revision: 8bf12445383b2f3149a9d095bfbc0f6d5b00dfaa

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

LOG: DebugInfo: workaround for context-sensitive use of 
non-type-template-parameter integer suffixes

There's a nuanced check about when to use suffixes on these integer
non-type-template-parameters, but when rebuilding names for
-gsimple-template-names there isn't enough data in the DWARF to
determine when to use suffixes or not. So turn on suffixes always to
make it easy to match up names in llvm-dwarfdump --verify.

I /think/ if we correctly modelled auto non-type-template parameters
maybe we could put suffixes only on those. But there's also some logic
in Clang that puts the suffixes on overloaded functions - at least
that's what the parameter says (see D77598 and printTemplateArguments
"TemplOverloaded" parameter) - but I think maybe it's for anything that
/can/ be overloaded, not necessarily only the things that are overloaded
(the argument value is hardcoded at the various callsites, doesn't seem
to depend on overload resolution/searching for overloaded functions). So
maybe with "auto" modeled more accurately, and differentiating between
function templates (always using type suffixes there) and class/variable
templates (only using the suffix for "auto" types) we could correctly
use integer type suffixes only in the minimal set of cases.

But that seems all too much fuss, so let's just put integer type
suffixes everywhere always in the debug info of integer non-type
template parameters in template names.

(more context:
* https://reviews.llvm.org/D77598#inline-1057607
* https://groups.google.com/g/llvm-dev/c/ekLMllbLIZg/m/-dhJ0hO1AAAJ )

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

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/PrettyPrinter.h
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CodeGenCXX/debug-info-template.cpp
clang/test/Modules/lsv-debuginfo.cpp
libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 2408f50c074b..d33babef958e 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -203,7 +203,8 @@ class TemplateParameterList final
   void print(raw_ostream , const ASTContext ,
  const PrintingPolicy , bool OmitTemplateKW = false) const;
 
-  static bool shouldIncludeTypeForArgument(const TemplateParameterList *TPL,
+  static bool shouldIncludeTypeForArgument(const PrintingPolicy ,
+   const TemplateParameterList *TPL,
unsigned Idx);
 };
 

diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 8cab7f189559..38d122db0749 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -75,7 +75,7 @@ struct PrintingPolicy {
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
 PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
-UsePreferredNames(true) {}
+UsePreferredNames(true), UseIntegerTypeSuffixesAlways(false) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -273,8 +273,15 @@ struct PrintingPolicy {
   /// written. When a template argument is unnamed, printing it results in
   /// invalid C++ code.
   unsigned PrintInjectedClassNameWithArguments : 1;
+
+  /// Whether to use C++ template preferred_name attributes when printing
+  /// templates.
   unsigned UsePreferredNames : 1;
 
+  /// Whether to use type suffixes (eg: 1U) on integral non-type template
+  /// parameters.
+  unsigned UseIntegerTypeSuffixesAlways : 1;
+
   /// Callbacks to use to allow the behavior of printing to be customized.
   const PrintingCallbacks *Callbacks = nullptr;
 };

diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index f2d7a792567d..7f3d3c5a9ec3 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1105,9 +1105,9 @@ void 
DeclPrinter::printTemplateArguments(ArrayRef Args,
 if (TemplOverloaded || !Params)
   Args[I].print(Policy, Out, /*IncludeType*/ true);
 else
-  Args[I].print(
-  Policy, Out,
-  

Re: r307232 - [modules ts] Do not emit strong function definitions from the module interface unit in every user.

2021-11-01 Thread David Blaikie via cfe-commits
Ping

On Tue, Sep 21, 2021 at 7:58 PM David Blaikie  wrote:

> Ping
>
> On Sun, Sep 5, 2021 at 11:28 AM David Blaikie  wrote:
>
>> Hey Richard - was just going back over some of the modular codegen code
>> (due to a discussion on the EWG mailing list about file extensions that
>> ended up touching on the nature of how modules are built) - and I came
>> across this code & had the same question I see I wrote up here already but
>> got lost in the *-commits mail.
>>
>> Wondering if you've got some thoughts on why this choice was implemented
>> for C++20 modules - not homing inline functions/variables, only the extern
>> linkage ones for correctness?
>>
>> On Sun, Jul 16, 2017 at 8:26 PM David Blaikie  wrote:
>>
>>> Looks good - does this support available_externally definitions of
>>> strong external linkage functions in the users of a module? (is that
>>> tested?) Should it?
>>>
>>> Also should we consider having two flags for modular codegen - one for
>>> correctness (external function definitions), one for linkage size
>>> optimization (inline functions). Given the current data on optimized builds
>>> with inline functions (that it hurts object size to emit
>>> weak+available_externally definitions rather than linkonce_odr because so
>>> many definitions are optimized away entirely, that the bytes for the weak
>>> definition are wasted/unnecessary) - or at least something to keep in
>>> mind/run numbers on in the future for more generic codebases than Google's
>>> protobuf-heavy (& only protobuf modularized) code.
>>>
>>> On Wed, Jul 5, 2017 at 5:30 PM Richard Smith via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: rsmith
 Date: Wed Jul  5 17:30:00 2017
 New Revision: 307232

 URL: http://llvm.org/viewvc/llvm-project?rev=307232=rev
 Log:
 [modules ts] Do not emit strong function definitions from the module
 interface unit in every user.

 Added:
 cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/
 cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/
 cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
 cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm
 cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
 Modified:
 cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

 Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=307232=307231=307232=diff

 ==
 --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
 +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Wed Jul  5 17:30:00
 2017
 @@ -2233,8 +2233,18 @@ void ASTRecordWriter::AddFunctionDefinit
Writer->ClearSwitchCaseIDs();

assert(FD->doesThisDeclarationHaveABody());
 -  bool ModulesCodegen = Writer->Context->getLangOpts().ModulesCodegen
 &&
 -Writer->WritingModule &&
 !FD->isDependentContext();
 +  bool ModulesCodegen = false;
 +  if (Writer->WritingModule && !FD->isDependentContext()) {
 +// Under -fmodules-codegen, codegen is performed for all defined
 functions.
 +// When building a C++ Modules TS module interface unit, a strong
 definition
 +// in the module interface is provided by the compilation of that
 module
 +// interface unit, not by its users. (Inline functions are still
 emitted
 +// in module users.)
 +ModulesCodegen =
 +Writer->Context->getLangOpts().ModulesCodegen ||
 +(Writer->WritingModule->Kind == Module::ModuleInterfaceUnit &&
 + Writer->Context->GetGVALinkageForFunction(FD) ==
 GVA_StrongExternal);
 +  }
Record->push_back(ModulesCodegen);
if (ModulesCodegen)
  Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));

 Added: cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp?rev=307232=auto

 ==
 --- cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
 (added)
 +++ cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp Wed
 Jul  5 17:30:00 2017
 @@ -0,0 +1,23 @@
 +// RUN: %clang_cc1 -fmodules-ts %S/module.cppm -triple
 %itanium_abi_triple -emit-module-interface -o %t
 +// RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple
 -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused
 --implicit-check-not=global_module
 +
 +module Module;
 +
 +void use() {
 +  // CHECK: define linkonce_odr {{.*}}@_Z20used_inline_exportedv
 +  used_inline_exported();

Re: [clang] 2bd8493 - Improve type printing of const arrays to normalize array-of-const and const-array

2021-10-21 Thread David Blaikie via cfe-commits
On Thu, Oct 14, 2021 at 2:25 PM David Blaikie  wrote:

> On Tue, Oct 12, 2021 at 7:35 PM David Blaikie  wrote:
>
>> On Mon, Oct 11, 2021 at 2:46 PM Richard Smith 
>> wrote:
>>
>>> On Wed, 15 Sept 2021 at 13:52, David Blaikie  wrote:
>>>
>>>> On Tue, Sep 14, 2021 at 10:04 AM Richard Smith 
>>>> wrote:
>>>>
>>>>> On Mon, 13 Sept 2021 at 19:24, David Blaikie via cfe-commits <
>>>>> cfe-commits@lists.llvm.org> wrote:
>>>>>
>>>>>>
>>>>>> Author: David Blaikie
>>>>>> Date: 2021-09-13T19:17:05-07:00
>>>>>> New Revision: 2bd84938470bf2e337801faafb8a67710f46429d
>>>>>>
>>>>>> URL:
>>>>>> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d
>>>>>> DIFF:
>>>>>> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d.diff
>>>>>>
>>>>>> LOG: Improve type printing of const arrays to normalize
>>>>>> array-of-const and const-array
>>>>>>
>>>>>> Since these map to the same effective type - render them the same/in
>>>>>> the
>>>>>> more legible way (const x[n]).
>>>>>>
>>>>>
>>>>> Nice!
>>>>>
>>>>>
>>>>>> Added:
>>>>>>
>>>>>>
>>>>>> Modified:
>>>>>> clang/lib/AST/TypePrinter.cpp
>>>>>> clang/test/ARCMT/cxx-checking.mm
>>>>>> clang/test/AST/ast-dump-APValue-arithmetic.cpp
>>>>>> clang/test/AST/ast-dump-APValue-array.cpp
>>>>>> clang/test/CXX/basic/basic.types/p10.cpp
>>>>>> clang/test/Sema/assign.c
>>>>>> clang/test/Sema/typedef-retain.c
>>>>>> clang/test/SemaCXX/reinterpret-cast.cpp
>>>>>> clang/test/SemaCXX/static-assert-cxx17.cpp
>>>>>>
>>>>>> Removed:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> 
>>>>>> diff  --git a/clang/lib/AST/TypePrinter.cpp
>>>>>> b/clang/lib/AST/TypePrinter.cpp
>>>>>> index aef1e4f3f4953..251db97c7db08 100644
>>>>>> --- a/clang/lib/AST/TypePrinter.cpp
>>>>>> +++ b/clang/lib/AST/TypePrinter.cpp
>>>>>> @@ -200,11 +200,12 @@ bool TypePrinter::canPrefixQualifiers(const
>>>>>> Type *T,
>>>>>>// type expands to a simple string.
>>>>>>bool CanPrefixQualifiers = false;
>>>>>>NeedARCStrongQualifier = false;
>>>>>> -  Type::TypeClass TC = T->getTypeClass();
>>>>>> +  const Type *UnderlyingType = T;
>>>>>>if (const auto *AT = dyn_cast(T))
>>>>>> -TC = AT->desugar()->getTypeClass();
>>>>>> +UnderlyingType = AT->desugar().getTypePtr();
>>>>>>if (const auto *Subst = dyn_cast(T))
>>>>>> -TC = Subst->getReplacementType()->getTypeClass();
>>>>>> +UnderlyingType = Subst->getReplacementType().getTypePtr();
>>>>>> +  Type::TypeClass TC = UnderlyingType->getTypeClass();
>>>>>>
>>>>>>switch (TC) {
>>>>>>  case Type::Auto:
>>>>>> @@ -243,6 +244,9 @@ bool TypePrinter::canPrefixQualifiers(const Type
>>>>>> *T,
>>>>>>
>>>>>>  case Type::ConstantArray:
>>>>>>  case Type::IncompleteArray:
>>>>>> +  return canPrefixQualifiers(
>>>>>> +
>>>>>> cast(UnderlyingType)->getElementType().getTypePtr(),
>>>>>> +  NeedARCStrongQualifier);
>>>>>>  case Type::VariableArray:
>>>>>>  case Type::DependentSizedArray:
>>>>>>
>>>>>
>>>>> Can we give these two cases the same treatment?
>>>>>
>>>>
>>>> Handled the DependentSizedArray in
>>>> https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00
>>>>
>>>> But per the comment in that commit I wasn't able to reproduce the
>>>> problem with a vari

[clang] 8c13680 - PR18733: Remove -Wweak-template-vtables

2021-10-21 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-10-21T14:50:20-07:00
New Revision: 8c136805242014b6ad9ff1afcac9d7f4a18bec3f

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

LOG: PR18733: Remove -Wweak-template-vtables

It isn't really pulling its weight and I think splitting it out from
-Wweak-vtables was the wrong call: I think it was just a bug in the
original warning, which was trying to not diagnose template
instantiations, implicit or explicit.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/warn-weak-vtables.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 13f8fc3de03c..7cee98c8a64c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1643,10 +1643,6 @@ def warn_weak_vtable : Warning<
   "%0 has no out-of-line virtual method definitions; its vtable will be "
   "emitted in every translation unit">,
   InGroup>, DefaultIgnore;
-def warn_weak_template_vtable : Warning<
-  "explicit template instantiation %0 will emit a vtable in every "
-  "translation unit">,
-  InGroup>, DefaultIgnore;
 
 def ext_using_undefined_std : ExtWarn<
   "using directive refers to implicitly-defined namespace 'std'">;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 2d1fd1b14040..03f7a95d0800 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/TypeOrdering.h"
 #include "clang/Basic/AttributeCommonInfo.h"
 #include "clang/Basic/PartialDiagnostic.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/Preprocessor.h"
@@ -17647,16 +17648,12 @@ bool Sema::DefineUsedVTables() {
 // no key function or the key function is inlined. Don't warn in C++ ABIs
 // that lack key functions, since the user won't be able to make one.
 if (Context.getTargetInfo().getCXXABI().hasKeyFunctions() &&
-Class->isExternallyVisible() && ClassTSK != TSK_ImplicitInstantiation) 
{
+Class->isExternallyVisible() && ClassTSK != TSK_ImplicitInstantiation 
&&
+ClassTSK != TSK_ExplicitInstantiationDefinition) {
   const FunctionDecl *KeyFunctionDef = nullptr;
   if (!KeyFunction || (KeyFunction->hasBody(KeyFunctionDef) &&
-   KeyFunctionDef->isInlined())) {
-Diag(Class->getLocation(),
- ClassTSK == TSK_ExplicitInstantiationDefinition
- ? diag::warn_weak_template_vtable
- : diag::warn_weak_vtable)
-<< Class;
-  }
+   KeyFunctionDef->isInlined()))
+Diag(Class->getLocation(), diag::warn_weak_vtable) << Class;
 }
   }
   VTableUses.clear();

diff  --git a/clang/test/SemaCXX/warn-weak-vtables.cpp 
b/clang/test/SemaCXX/warn-weak-vtables.cpp
index e678f9e461ef..9355af50310d 100644
--- a/clang/test/SemaCXX/warn-weak-vtables.cpp
+++ b/clang/test/SemaCXX/warn-weak-vtables.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -triple %itanium_abi_triple 
-Wweak-vtables -Wweak-template-vtables
+// RUN: %clang_cc1 %s -fsyntax-only -verify -triple %itanium_abi_triple 
-Wweak-vtables
 //
 // Check that this warning is disabled on MS ABI targets which don't have key
 // functions.
-// RUN: %clang_cc1 %s -fsyntax-only -triple %ms_abi_triple -Werror 
-Wweak-vtables -Wweak-template-vtables
+// RUN: %clang_cc1 %s -fsyntax-only -triple %ms_abi_triple -Werror 
-Wweak-vtables
 
 struct A { // expected-warning {{'A' has no out-of-line virtual method 
definitions; its vtable will be emitted in every translation unit}}
   virtual void f() { } 
@@ -63,7 +63,7 @@ template struct TemplVirt {
   virtual void f();
 };
 
-template class TemplVirt; // expected-warning{{explicit template 
instantiation 'TemplVirt' will emit a vtable in every translation unit}}
+template class TemplVirt;
 
 template<> struct TemplVirt {
   virtual void f();



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


Re: [clang] 2bd8493 - Improve type printing of const arrays to normalize array-of-const and const-array

2021-10-14 Thread David Blaikie via cfe-commits
On Tue, Oct 12, 2021 at 7:35 PM David Blaikie  wrote:

> On Mon, Oct 11, 2021 at 2:46 PM Richard Smith 
> wrote:
>
>> On Wed, 15 Sept 2021 at 13:52, David Blaikie  wrote:
>>
>>> On Tue, Sep 14, 2021 at 10:04 AM Richard Smith 
>>> wrote:
>>>
>>>> On Mon, 13 Sept 2021 at 19:24, David Blaikie via cfe-commits <
>>>> cfe-commits@lists.llvm.org> wrote:
>>>>
>>>>>
>>>>> Author: David Blaikie
>>>>> Date: 2021-09-13T19:17:05-07:00
>>>>> New Revision: 2bd84938470bf2e337801faafb8a67710f46429d
>>>>>
>>>>> URL:
>>>>> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d
>>>>> DIFF:
>>>>> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d.diff
>>>>>
>>>>> LOG: Improve type printing of const arrays to normalize array-of-const
>>>>> and const-array
>>>>>
>>>>> Since these map to the same effective type - render them the same/in
>>>>> the
>>>>> more legible way (const x[n]).
>>>>>
>>>>
>>>> Nice!
>>>>
>>>>
>>>>> Added:
>>>>>
>>>>>
>>>>> Modified:
>>>>> clang/lib/AST/TypePrinter.cpp
>>>>> clang/test/ARCMT/cxx-checking.mm
>>>>> clang/test/AST/ast-dump-APValue-arithmetic.cpp
>>>>> clang/test/AST/ast-dump-APValue-array.cpp
>>>>> clang/test/CXX/basic/basic.types/p10.cpp
>>>>> clang/test/Sema/assign.c
>>>>> clang/test/Sema/typedef-retain.c
>>>>> clang/test/SemaCXX/reinterpret-cast.cpp
>>>>> clang/test/SemaCXX/static-assert-cxx17.cpp
>>>>>
>>>>> Removed:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> 
>>>>> diff  --git a/clang/lib/AST/TypePrinter.cpp
>>>>> b/clang/lib/AST/TypePrinter.cpp
>>>>> index aef1e4f3f4953..251db97c7db08 100644
>>>>> --- a/clang/lib/AST/TypePrinter.cpp
>>>>> +++ b/clang/lib/AST/TypePrinter.cpp
>>>>> @@ -200,11 +200,12 @@ bool TypePrinter::canPrefixQualifiers(const Type
>>>>> *T,
>>>>>// type expands to a simple string.
>>>>>bool CanPrefixQualifiers = false;
>>>>>NeedARCStrongQualifier = false;
>>>>> -  Type::TypeClass TC = T->getTypeClass();
>>>>> +  const Type *UnderlyingType = T;
>>>>>if (const auto *AT = dyn_cast(T))
>>>>> -TC = AT->desugar()->getTypeClass();
>>>>> +UnderlyingType = AT->desugar().getTypePtr();
>>>>>if (const auto *Subst = dyn_cast(T))
>>>>> -TC = Subst->getReplacementType()->getTypeClass();
>>>>> +UnderlyingType = Subst->getReplacementType().getTypePtr();
>>>>> +  Type::TypeClass TC = UnderlyingType->getTypeClass();
>>>>>
>>>>>switch (TC) {
>>>>>  case Type::Auto:
>>>>> @@ -243,6 +244,9 @@ bool TypePrinter::canPrefixQualifiers(const Type
>>>>> *T,
>>>>>
>>>>>  case Type::ConstantArray:
>>>>>  case Type::IncompleteArray:
>>>>> +  return canPrefixQualifiers(
>>>>> +
>>>>> cast(UnderlyingType)->getElementType().getTypePtr(),
>>>>> +  NeedARCStrongQualifier);
>>>>>  case Type::VariableArray:
>>>>>  case Type::DependentSizedArray:
>>>>>
>>>>
>>>> Can we give these two cases the same treatment?
>>>>
>>>
>>> Handled the DependentSizedArray in
>>> https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00
>>>
>>> But per the comment in that commit I wasn't able to reproduce the
>>> problem with a variable array - though we could include it in the handling
>>> on principle/for consistency, even without a test/etc. Perhaps there's a
>>> way to test/provoke the behavior you might know that I couldn't figure out?
>>>
>>> Details from the commit:
>>>
>>> The VariableArray case I couldn't figure out how to test/provoke -
>>> you
>>>
>>> can't w

Re: [clang] 2bd8493 - Improve type printing of const arrays to normalize array-of-const and const-array

2021-10-12 Thread David Blaikie via cfe-commits
On Mon, Oct 11, 2021 at 2:46 PM Richard Smith  wrote:

> On Wed, 15 Sept 2021 at 13:52, David Blaikie  wrote:
>
>> On Tue, Sep 14, 2021 at 10:04 AM Richard Smith 
>> wrote:
>>
>>> On Mon, 13 Sept 2021 at 19:24, David Blaikie via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>>>
>>>> Author: David Blaikie
>>>> Date: 2021-09-13T19:17:05-07:00
>>>> New Revision: 2bd84938470bf2e337801faafb8a67710f46429d
>>>>
>>>> URL:
>>>> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d
>>>> DIFF:
>>>> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d.diff
>>>>
>>>> LOG: Improve type printing of const arrays to normalize array-of-const
>>>> and const-array
>>>>
>>>> Since these map to the same effective type - render them the same/in the
>>>> more legible way (const x[n]).
>>>>
>>>
>>> Nice!
>>>
>>>
>>>> Added:
>>>>
>>>>
>>>> Modified:
>>>> clang/lib/AST/TypePrinter.cpp
>>>> clang/test/ARCMT/cxx-checking.mm
>>>> clang/test/AST/ast-dump-APValue-arithmetic.cpp
>>>> clang/test/AST/ast-dump-APValue-array.cpp
>>>> clang/test/CXX/basic/basic.types/p10.cpp
>>>> clang/test/Sema/assign.c
>>>> clang/test/Sema/typedef-retain.c
>>>> clang/test/SemaCXX/reinterpret-cast.cpp
>>>> clang/test/SemaCXX/static-assert-cxx17.cpp
>>>>
>>>> Removed:
>>>>
>>>>
>>>>
>>>>
>>>> 
>>>> diff  --git a/clang/lib/AST/TypePrinter.cpp
>>>> b/clang/lib/AST/TypePrinter.cpp
>>>> index aef1e4f3f4953..251db97c7db08 100644
>>>> --- a/clang/lib/AST/TypePrinter.cpp
>>>> +++ b/clang/lib/AST/TypePrinter.cpp
>>>> @@ -200,11 +200,12 @@ bool TypePrinter::canPrefixQualifiers(const Type
>>>> *T,
>>>>// type expands to a simple string.
>>>>bool CanPrefixQualifiers = false;
>>>>NeedARCStrongQualifier = false;
>>>> -  Type::TypeClass TC = T->getTypeClass();
>>>> +  const Type *UnderlyingType = T;
>>>>if (const auto *AT = dyn_cast(T))
>>>> -TC = AT->desugar()->getTypeClass();
>>>> +UnderlyingType = AT->desugar().getTypePtr();
>>>>if (const auto *Subst = dyn_cast(T))
>>>> -TC = Subst->getReplacementType()->getTypeClass();
>>>> +UnderlyingType = Subst->getReplacementType().getTypePtr();
>>>> +  Type::TypeClass TC = UnderlyingType->getTypeClass();
>>>>
>>>>switch (TC) {
>>>>  case Type::Auto:
>>>> @@ -243,6 +244,9 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,
>>>>
>>>>  case Type::ConstantArray:
>>>>  case Type::IncompleteArray:
>>>> +  return canPrefixQualifiers(
>>>> +
>>>> cast(UnderlyingType)->getElementType().getTypePtr(),
>>>> +  NeedARCStrongQualifier);
>>>>  case Type::VariableArray:
>>>>  case Type::DependentSizedArray:
>>>>
>>>
>>> Can we give these two cases the same treatment?
>>>
>>
>> Handled the DependentSizedArray in
>> https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00
>>
>> But per the comment in that commit I wasn't able to reproduce the problem
>> with a variable array - though we could include it in the handling on
>> principle/for consistency, even without a test/etc. Perhaps there's a way
>> to test/provoke the behavior you might know that I couldn't figure out?
>>
>> Details from the commit:
>>
>> The VariableArray case I couldn't figure out how to test/provoke -
>> you
>>
>> can't write/form a variable array in any context other than a local
>>
>> variable that I know of, and in that case `const int x[n]` is the
>>
>> normalized form already (array-of-const) and you can't use typedefs
>>
>> (since you can't typedef int[n] with variable 'n') to force the
>>
>> const-array AST that would produce the undesirable type printing "int
>>
>> const [n]".
>>
>
> C has a fairly surprising rule here -- you 

[clang] 3909327 - Improve printing of const variable sized arrays

2021-10-12 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-10-12T19:04:53-07:00
New Revision: 39093279f2ede4af9048b89d048d7fe9182a50f8

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

LOG: Improve printing of const variable sized arrays

Follow-on from 40acc0adad59ac39e9a7a02fcd93161298500c00 with help from
Richard Smith on how to provoke this particular case.

Added: 
clang/test/Sema/vla.cpp

Modified: 
clang/lib/AST/TypePrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 3c7a6b8b9e95..e573037db10e 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -242,6 +242,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,
 T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType();
   break;
 
+case Type::VariableArray:
 case Type::DependentSizedArray:
   NeedARCStrongQualifier = true;
   LLVM_FALLTHROUGH;
@@ -251,9 +252,6 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,
   return canPrefixQualifiers(
   cast(UnderlyingType)->getElementType().getTypePtr(),
   NeedARCStrongQualifier);
-case Type::VariableArray:
-  NeedARCStrongQualifier = true;
-  LLVM_FALLTHROUGH;
 
 case Type::Adjusted:
 case Type::Decayed:

diff  --git a/clang/test/Sema/vla.cpp b/clang/test/Sema/vla.cpp
new file mode 100644
index ..b4416a07cf0e
--- /dev/null
+++ b/clang/test/Sema/vla.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void f1(int n) {
+  typedef int x[n];
+  const x y; // expected-error {{default initialization of an object of const 
type 'const x' (aka 'const int [n]')}}
+}



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


<    1   2   3   4   5   6   7   8   9   10   >