[clang] 2fbd132 - [Sema] Make C++ functional-style cast warn about dropped qualifiers (-Wcast-qual)

2023-09-05 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2023-09-05T12:48:38+02:00
New Revision: 2fbd1323e7bf6ec204867774db8aa9b7dc976da5

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

LOG: [Sema] Make C++ functional-style cast warn about dropped qualifiers 
(-Wcast-qual)

Functional-style cast (i.e. a simple-type-specifier or typename-specifier
followed by a parenthesize single expression [expr.type.conv]) is equivalent
to the C-style cast, so that makes sense they have identical behavior
including warnings.

This also matches GCC https://godbolt.org/z/b8Ma9Thjb.

Reviewed By: rnk, aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCast.cpp
clang/test/Sema/warn-cast-qual.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 84681ec9554d21..b2b68cc2aeb5f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -165,6 +165,7 @@ Improvements to Clang's diagnostics
   (`#64871: `_).
   Also clang no longer emits false positive warnings about the output length of
   ``%g`` format specifier.
+- Clang now emits ``-Wcast-qual`` for functional-style cast expressions.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index d4648b2d16eaac..98b5879456e217 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -3374,6 +3374,9 @@ ExprResult 
Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo,
   if (auto *ConstructExpr = dyn_cast(SubExpr))
 ConstructExpr->setParenOrBraceRange(SourceRange(LPLoc, RPLoc));
 
+  // -Wcast-qual
+  DiagnoseCastQual(Op.Self, Op.SrcExpr, Op.DestType);
+
   return Op.complete(CXXFunctionalCastExpr::Create(
   Context, Op.ResultType, Op.ValueKind, CastTypeInfo, Op.Kind,
   Op.SrcExpr.get(), , CurFPFeatureOverrides(), LPLoc, RPLoc));

diff  --git a/clang/test/Sema/warn-cast-qual.c 
b/clang/test/Sema/warn-cast-qual.c
index 104f9a3faf47c8..ec140180ffa12f 100644
--- a/clang/test/Sema/warn-cast-qual.c
+++ b/clang/test/Sema/warn-cast-qual.c
@@ -36,6 +36,39 @@ void foo(void) {
   char *charptr = (char *)constcharptr; // expected-warning {{cast from 'const 
char *' to 'char *' drops const qualifier}}
   const char *constcharptr2 = (char *)constcharptr; // expected-warning {{cast 
from 'const char *' to 'char *' drops const qualifier}}
   const char *charptr2 = (char *)charptr; // no warning
+
+#ifdef __cplusplus
+  using CharPtr = char *;
+  using CharPtrPtr = char **;
+  using ConstCharPtrPtr = const char **;
+  using CharPtrConstPtr = char *const *;
+
+  char *fy = CharPtr(ptr); // expected-warning {{cast from 'const char *' 
to 'char *' drops const qualifier}}
+  char **fy1 = CharPtrPtr(ptrptr); // expected-warning {{cast from 'const 
char *const *' to 'char **' drops const qualifier}}
+  const char **fy2 = ConstCharPtrPtr(ptrptr);  // expected-warning {{cast from 
'const char *const *' to 'const char **' drops const qualifier}}
+  char *const *fy3 = CharPtrConstPtr(ptrptr);  // expected-warning {{cast from 
'const char *const' to 'char *const' drops const qualifier}}
+  const char **fy4 = ConstCharPtrPtr(ptrcptr); // expected-warning {{cast from 
'char *const *' to 'const char **' drops const qualifier}}
+
+  using ConstVoidPtr = const void *;
+  char *fz = CharPtr(uintptr_t(ConstVoidPtr(ptr)));// no warning
+  char *fz1 = CharPtr(ConstVoidPtr(ptr));  // expected-warning {{cast from 
'const void *' to 'char *' drops const qualifier}}
+
+  char *fvol2 = CharPtr(vol); // expected-warning {{cast from 'volatile char 
*' to 'char *' drops volatile qualifier}}
+  char *fvolc2 = CharPtr(volc); // expected-warning {{cast from 'const 
volatile char *' to 'char *' drops const and volatile qualifiers}}
+
+  using ConstIntPtrPtr = const int **;
+  using VolitileIntPtrPtr = volatile int **;
+  const int **fintptrptrc = ConstIntPtrPtr(intptrptr); // expected-warning 
{{cast from 'int **' to 'ConstIntPtrPtr' (aka 'const int **') must have all 
intermediate pointers const qualified}}
+  volatile int **fintptrptrv = VolitileIntPtrPtr(intptrptr); // 
expected-warning {{cast from 'int **' to 'VolitileIntPtrPtr' (aka 'volatile int 
**') must have all intermediate pointers const qualified}}
+
+  using ConstIntPtr = const int *;
+  const int *fintptrc = ConstIntPtr(intptr);// no warning
+
+  char **fcharptrptr = CharPtrPtr(charptrptrc); // expected-warning {{cast 
from 'const char *' to 'char *' drops const qualifier}}
+
+  char *fcharptr = CharPtr(constcharptr); // expected-warning {{cast from 
'const char *' to 'char *' drops const qualifier}}
+  const char 

[clang] 4ecb2b8 - [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-11-03 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2022-11-03T10:28:38+02:00
New Revision: 4ecb2b8ef6be69b55d46ac274f3b7a7103219f98

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

LOG: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

Having AllEnumtypes to be a vector of TrackingMDNodeRef makes it possible
to reflect changes in metadata in the vector if they took place before DIBuilder
being finalized.

Otherwise, we end up with heap-use-after-free because AllEnumTypes contains
metadata that no longer valid.

Consider a case where we have a class containing a definition of a enum,
so this enum has the class as a scope. For some reason (doesn't matter for
the current issue), we create a temporary debug metadata for this class, and
then resolve it while finalizing CGDebugInfo.

In the case of collision during uniqifying the temporary, we then need
to replace its uses with a new pointer. If a temporary's user is unique
(this is the enum mentioned above), we may need re-uniquefying it,
which may return a new pointer in the case of another collision.
If so, the pointer we stored in AllEnumTypes vector become dangling.
Making AllEnumTypes hodling TrackingMDNodeRef should solve this problem
(see debug-info-enum-metadata-collision.cpp test for details).

Reviewed By: dblaikie

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

Added: 
clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp

Modified: 
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp 
b/clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
new file mode 100644
index 0..dd27acd0a77c5
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-debug-info-kind=constructor %s -o - | FileCheck %s
+
+// Test that clang doesn't crash while resolving temporary debug metadata of
+// a record with collisions in the record's enum users.
+
+// CHECK:  !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME:  scope: [[SCOPE:![0-9]+]]
+// CHECK-SAME:  elements: [[ELEMENTS:![0-9]+]]
+// CHECK:  [[SCOPE]] = !DICompositeType(tag: DW_TAG_structure_type
+// CHECK-SAME:  name: "Struct1"
+// CHECK:  [[ELEMENTS]] = !{[[ELEMENT:![0-9]+]]}
+// CHECK:  [[ELEMENT]] = !DIEnumerator(name: "enumValue1"
+
+template  struct Struct1 {
+  enum { enumValue1 };
+  Struct1();
+};
+void function2() {
+  struct Struct3 {};
+  int i = Struct1::enumValue1;
+}
+void function3() {
+  struct Struct3 {};
+  int i = Struct1::enumValue1;
+}

diff  --git a/llvm/include/llvm/IR/DIBuilder.h 
b/llvm/include/llvm/IR/DIBuilder.h
index dfb65ce341296..61fa4d8f3b9fd 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@ namespace llvm {
 Function *LabelFn;   ///< llvm.dbg.label
 Function *AddrFn;///< llvm.dbg.addr
 
-SmallVector AllEnumTypes;
+SmallVector AllEnumTypes;
 /// Track the RetainTypes, since they can be updated later on.
 SmallVector AllRetainTypes;
 SmallVector AllSubprograms;

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index fada07ac383ae..76d7ade09a88c 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@ void DIBuilder::finalize() {
   }
 
   if (!AllEnumTypes.empty())
-CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
+CUNode->replaceEnumTypes(MDTuple::get(
+VMContext, SmallVector(AllEnumTypes.begin(),
+   AllEnumTypes.end(;
 
   SmallVector RetainValues;
   // Declarations and definitions of the same type may be retained. Some
@@ -556,7 +558,7 @@ DICompositeType *DIBuilder::createEnumerationType(
   getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 
0,
   IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, 
nullptr,
   nullptr, UniqueIdentifier);
-  AllEnumTypes.push_back(CTy);
+  AllEnumTypes.emplace_back(CTy);
   trackIfUnresolved(CTy);
   return CTy;
 }



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


[clang] afbe54f - [clang] Fix wrong -Wunused-local-typedef warning within a template function

2022-03-21 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2022-03-21T13:21:25+02:00
New Revision: afbe54f2feb0ed3a4d4c03c6107fcdffd21a8394

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

LOG: [clang] Fix wrong -Wunused-local-typedef warning within a template function

Partially fixes PR24883.

The patch sets Reference bit while instantiating a typedef if it
previously was found referenced.

Reviewed By: thakis

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
clang/test/Modules/odr_hash.cpp
clang/test/SemaCXX/warn-unused-local-typedef.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index ec993914595f3..8c7f5a4f19658 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -974,6 +974,7 @@ Decl 
*TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
 SemaRef.inferGslPointerAttribute(Typedef);
 
   Typedef->setAccess(D->getAccess());
+  Typedef->setReferenced(D->isReferenced());
 
   return Typedef;
 }

diff  --git 
a/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp 
b/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
index 35ec1cbfd8f7e..88138bf343da5 100644
--- a/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -193,7 +193,7 @@ int test(float &, short &) {
 // CHECK-NEXT: | | |-ParmVarDecl [[ADDR_43:0x[a-z0-9]*]]  
col:12 used __t 'float &'
 // CHECK-NEXT: | | `-CompoundStmt [[ADDR_44:0x[a-z0-9]*]] 
 // CHECK-NEXT: | |   |-DeclStmt [[ADDR_45:0x[a-z0-9]*]] 
-// CHECK-NEXT: | |   | `-TypedefDecl [[ADDR_46:0x[a-z0-9]*]]  
col:48 _Up 'typename remove_reference::type':'float'
+// CHECK-NEXT: | |   | `-TypedefDecl [[ADDR_46:0x[a-z0-9]*]]  
col:48 referenced _Up 'typename remove_reference::type':'float'
 // CHECK-NEXT: | |   |   `-ElaboratedType [[ADDR_47:0x[a-z0-9]*]] 'typename 
remove_reference::type' sugar
 // CHECK-NEXT: | |   | `-TypedefType [[ADDR_48:0x[a-z0-9]*]] 
'remove_reference::type' sugar
 // CHECK-NEXT: | |   |   |-Typedef [[ADDR_10]] 'type'
@@ -211,7 +211,7 @@ int test(float &, short &) {
 // CHECK-NEXT: |   |-ParmVarDecl [[ADDR_53:0x[a-z0-9]*]]  
col:12 used __t 'short &'
 // CHECK-NEXT: |   `-CompoundStmt [[ADDR_54:0x[a-z0-9]*]] 
 // CHECK-NEXT: | |-DeclStmt [[ADDR_55:0x[a-z0-9]*]] 
-// CHECK-NEXT: | | `-TypedefDecl [[ADDR_56:0x[a-z0-9]*]]  
col:48 _Up 'typename remove_reference::type':'short'
+// CHECK-NEXT: | | `-TypedefDecl [[ADDR_56:0x[a-z0-9]*]]  
col:48 referenced _Up 'typename remove_reference::type':'short'
 // CHECK-NEXT: | |   `-ElaboratedType [[ADDR_57:0x[a-z0-9]*]] 'typename 
remove_reference::type' sugar
 // CHECK-NEXT: | | `-TypedefType [[ADDR_58:0x[a-z0-9]*]] 
'remove_reference::type' sugar
 // CHECK-NEXT: | |   |-Typedef [[ADDR_18]] 'type'

diff  --git a/clang/test/Modules/odr_hash.cpp b/clang/test/Modules/odr_hash.cpp
index fe51915074239..81899943bc64c 100644
--- a/clang/test/Modules/odr_hash.cpp
+++ b/clang/test/Modules/odr_hash.cpp
@@ -4372,6 +4372,8 @@ template
 G* S::Foo(const G* asdf, int*) {}
 #else
 S s;
+// expected-error@first.h:* {{'ParameterTest::S::Foo' has 
diff erent definitions in 
diff erent modules; definition in module 'FirstModule' first 
diff erence is 1st parameter with name ''}}
+// expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with 
name 'asdf'}}
 #endif
 }  // ParameterTest
 

diff  --git a/clang/test/SemaCXX/warn-unused-local-typedef.cpp 
b/clang/test/SemaCXX/warn-unused-local-typedef.cpp
index 554ea37eeb282..e7130a24f2db2 100644
--- a/clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ b/clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -238,5 +238,22 @@ void placement_new_and_delete() {
   a->~A_t2();
 }
 
+namespace TypedefInLocalClassOfAMemberOfTemplateClass {
+template struct A {
+  void foo() {
+struct Inner {
+  typedef int Int; // no-diag
+  typedef char Char; // expected-warning {{unused typedef 'Char'}}
+  Int m;
+} b;
+  }
+};
+
+void foo() {
+  A x;
+  x.foo();
+}
+} // TypedefInLocalClassOfTemplateClassMember
+
 // This should not disable any warnings:
 #pragma clang diagnostic ignored "-Wunused-local-typedef"



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


[clang] 57aaab3 - [NVPTX] Fix nvvm.match.sync*.i64 intrinsics return type (i64 -> i32)

2022-03-01 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2022-03-01T12:26:16+02:00
New Revision: 57aaab3b17f02a0904b823278035afe555f6f99a

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

LOG: [NVPTX] Fix nvvm.match.sync*.i64 intrinsics return type (i64 -> i32)

NVVM IR specification defines them with i32 return type:

  declare i32 @llvm.nvvm.match.any.sync.i64(i32 %membermask, i64 %value)
  declare {i32, i1} @llvm.nvvm.match.all.sync.i64(i32 %membermask, i64 %value)
  ...
  The i32 return value is a 32-bit mask where bit position in mask corresponds
  to thread’s laneid.

as well as PTX ISA:

  9.7.12.8. Parallel Synchronization and Communication Instructions: match.sync

  match.any.sync.type  d, a, membermask;
  match.all.sync.type  d[|p], a, membermask;
  ...
  Destination d is a 32-bit mask where bit position in mask corresponds
  to thread’s laneid.

Additionally, ptxas doesn't accept intructions, produced by NVPTX backend.
After this patch, it compiles with no issues.

Reviewed By: tra

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/lib/Headers/__clang_cuda_intrinsics.h
clang/test/CodeGen/builtins-nvptx-ptx60.cu
llvm/include/llvm/IR/IntrinsicsNVVM.td
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
llvm/test/CodeGen/NVPTX/match.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 6b94dd8573008..1279d83f1f61f 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -473,11 +473,11 @@ TARGET_BUILTIN(__nvvm_vote_uni_sync, "bUib", "", PTX60)
 TARGET_BUILTIN(__nvvm_vote_ballot_sync, "UiUib", "", PTX60)
 
 // Match
-TARGET_BUILTIN(__nvvm_match_any_sync_i32, "UiUiUi", "", PTX60)
-TARGET_BUILTIN(__nvvm_match_any_sync_i64, "WiUiWi", "", PTX60)
+TARGET_BUILTIN(__nvvm_match_any_sync_i32, "UiUiUi", "", AND(SM_70,PTX60))
+TARGET_BUILTIN(__nvvm_match_any_sync_i64, "UiUiWi", "", AND(SM_70,PTX60))
 // These return a pair {value, predicate}, which requires custom lowering.
-TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", PTX60)
-TARGET_BUILTIN(__nvvm_match_all_sync_i64p, "WiUiWii*", "", PTX60)
+TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", AND(SM_70,PTX60))
+TARGET_BUILTIN(__nvvm_match_all_sync_i64p, "UiUiWii*", "", AND(SM_70,PTX60))
 
 // Redux
 TARGET_BUILTIN(__nvvm_redux_sync_add, "iii", "", AND(SM_80,PTX70))

diff  --git a/clang/lib/Headers/__clang_cuda_intrinsics.h 
b/clang/lib/Headers/__clang_cuda_intrinsics.h
index e0875bbcbf4ae..eee2930ece85a 100644
--- a/clang/lib/Headers/__clang_cuda_intrinsics.h
+++ b/clang/lib/Headers/__clang_cuda_intrinsics.h
@@ -234,7 +234,7 @@ inline __device__ unsigned int __match32_any_sync(unsigned 
int mask,
   return __nvvm_match_any_sync_i32(mask, value);
 }
 
-inline __device__ unsigned long long
+inline __device__ unsigned int
 __match64_any_sync(unsigned int mask, unsigned long long value) {
   return __nvvm_match_any_sync_i64(mask, value);
 }
@@ -244,7 +244,7 @@ __match32_all_sync(unsigned int mask, unsigned int value, 
int *pred) {
   return __nvvm_match_all_sync_i32p(mask, value, pred);
 }
 
-inline __device__ unsigned long long
+inline __device__ unsigned int
 __match64_all_sync(unsigned int mask, unsigned long long value, int *pred) {
   return __nvvm_match_all_sync_i64p(mask, value, pred);
 }

diff  --git a/clang/test/CodeGen/builtins-nvptx-ptx60.cu 
b/clang/test/CodeGen/builtins-nvptx-ptx60.cu
index 36d17e629eb82..afbe0a45b091b 100644
--- a/clang/test/CodeGen/builtins-nvptx-ptx60.cu
+++ b/clang/test/CodeGen/builtins-nvptx-ptx60.cu
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple nvptx64-unknown-unknown -target-cpu sm_60 \
+// RUN: %clang_cc1 -triple nvptx64-unknown-unknown -target-cpu sm_70 \
 // RUN:-fcuda-is-device -target-feature +ptx60 \
 // RUN:-S -emit-llvm -o - -x cuda %s \
 // RUN:   | FileCheck -check-prefix=CHECK %s
@@ -10,7 +10,7 @@
 // RUN:-fcuda-is-device -target-feature +ptx70 \
 // RUN:-S -emit-llvm -o - -x cuda %s \
 // RUN:   | FileCheck -check-prefix=CHECK %s
-// RUN: %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_60 \
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_70 \
 // RUN:   -fcuda-is-device -S -o /dev/null -x cuda -verify %s
 
 #define __device__ __attribute__((device))
@@ -89,16 +89,16 @@ __device__ void nvvm_sync(unsigned mask, int i, float f, 
int a, int b,
   //
 
   // CHECK: call i32 @llvm.nvvm.match.any.sync.i32(i32
-  // expected-error@+1 {{'__nvvm_match_any_sync_i32' needs target feature 
ptx60}}
+  // expected-error-re@+1 {{'__nvvm_match_any_sync_i32' needs target feature 
(sm_70{{.*}}),(ptx60{{.*}})}}
   

[clang] e403f4f - [clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block

2021-12-06 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2021-12-06T12:19:09+02:00
New Revision: e403f4fdc88322201040f2bee7b328e8a78e2f7f

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

LOG: [clang][DebugInfo] Allow function-local statics and types to be scoped 
within a lexical block

This is almost a reincarnation of https://reviews.llvm.org/D15977 originally
implemented by Amjad Aboud. It was discussed on llvm-dev [0], committed
with its backend counterpart [1], but finally reverted [2].

This patch makes clang to emit debug info for function-local static variables,
records (classes, structs and unions) and typdefs correctly scoped if
those function-local entites defined within a lexical (bracketed) block.

Before this patch, clang emits all those entities directly scoped in
DISubprogram no matter where they were really defined, causing
debug info loss (reported several times in [3], [4], [5]).

[0] https://lists.llvm.org/pipermail/llvm-dev/2015-November/092551.html
[1] https://reviews.llvm.org/rG30e7a8f694a19553f64b3a3a5de81ce317b9ec2f
[2] https://reviews.llvm.org/rGdc4531e552af6c880a69d226d3666756198fbdc8
[3] https://bugs.llvm.org/show_bug.cgi?id=19238
[4] https://bugs.llvm.org/show_bug.cgi?id=23164
[5] https://bugs.llvm.org/show_bug.cgi?id=44695

Reviewed By: dblaikie

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

Added: 
clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGDecl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index af651e6f44b7c..75eec22e4e4e5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -227,6 +227,20 @@ llvm::DIScope *CGDebugInfo::getContextDescriptor(const 
Decl *Context,
   return Default;
 }
 
+void CGDebugInfo::recordDeclarationLexicalScope(const Decl ) {
+  assert(LexicalBlockMap.find() == LexicalBlockMap.end() &&
+ "D is already mapped to a lexical block scope");
+  if (!LexicalBlockStack.empty())
+LexicalBlockMap.insert({, LexicalBlockStack.back()});
+}
+
+llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl *D) {
+  auto I = LexicalBlockMap.find(D);
+  if (I != LexicalBlockMap.end())
+return I->second;
+  return getDeclContextDescriptor(cast(D));
+}
+
 PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   PrintingPolicy PP = CGM.getContext().getPrintingPolicy();
 
@@ -1346,13 +1360,13 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType 
*Ty,
   // declared.
   SourceLocation Loc = Ty->getDecl()->getLocation();
 
+  llvm::DIScope *TDContext = getDeclarationLexicalScope(Ty->getDecl());
   uint32_t Align = getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext());
   // Typedefs are derived from some other type.
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(Ty->getDecl());
   return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
 getOrCreateFile(Loc), getLineNumber(Loc),
-getDeclContextDescriptor(Ty->getDecl()), Align,
-Annotations);
+TDContext, Align, Annotations);
 }
 
 static unsigned getDwarfCC(CallingConv CC) {
@@ -3251,7 +3265,7 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType 
*Ty) {
 // entered into the ReplaceMap: finalize() will replace the first
 // FwdDecl with the second and then replace the second with
 // complete type.
-llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
+llvm::DIScope *EDContext = getDeclarationLexicalScope(ED);
 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
 llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
@@ -3294,7 +3308,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const 
EnumType *Ty) {
 
   llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
   unsigned Line = getLineNumber(ED->getLocation());
-  llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
+  llvm::DIScope *EnumContext = getDeclarationLexicalScope(ED);
   llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
   return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
 Line, Size, Align, EltArray, ClassTy,
@@ -3597,7 +3611,7 @@ llvm::DICompositeType 
*CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
 Line = getLineNumber(Loc);
   }
 
-  llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
+  llvm::DIScope *RDContext = getDeclarationLexicalScope(RD);
 
   // If we ended up creating the type during the context 

[libunwind] f042fd4 - [libunwind][cmake] Add an option to enable/disable tests

2021-02-13 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2021-02-13T12:49:48+02:00
New Revision: f042fd46b527bea97dfa1e09558700173b70405e

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

LOG: [libunwind][cmake] Add an option to enable/disable tests

Reviewed By: ldionne, compnerd

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

Added: 


Modified: 
libunwind/CMakeLists.txt

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 05131bd77b39..140700030aff 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -63,6 +63,7 @@ option(LIBUNWIND_ENABLE_THREADS "Build libunwind with 
threading support." ON)
 option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread 
functions." OFF)
 option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." 
${LLVM_INCLUDE_DOCS})
+option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." 
${LLVM_INCLUDE_TESTS})
 option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
 option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. 
Requires locking dl_iterate_phdr." OFF)
 option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for 
.cfi_remember_state." OFF)
@@ -344,6 +345,6 @@ if (LIBUNWIND_INCLUDE_DOCS)
   add_subdirectory(docs)
 endif()
 
-if (EXISTS ${LLVM_CMAKE_PATH})
+if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_PATH})
   add_subdirectory(test)
 endif()



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


[clang] 04ea680 - [cmake] Fix build of attribute plugin example on Windows

2020-09-07 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2020-09-07T10:04:32+02:00
New Revision: 04ea680a8ccc4f9a4d7333cd712333960348c35b

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

LOG: [cmake] Fix build of attribute plugin example on Windows

Seems '${cmake_2_8_12_PRIVATE}' was removed a long time ago, so it should
be just PRIVATE keyword here.

Reviewed By: john.brawn

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

Added: 


Modified: 
clang/examples/Attribute/CMakeLists.txt

Removed: 




diff  --git a/clang/examples/Attribute/CMakeLists.txt 
b/clang/examples/Attribute/CMakeLists.txt
index ed02f5e5992f..42f04f5039bc 100644
--- a/clang/examples/Attribute/CMakeLists.txt
+++ b/clang/examples/Attribute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
-  target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
+  target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
 clangFrontend



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


[clang] ad4ab81 - [clang][cmake] Force CMAKE_LINKER for multistage build in case of BOOTSTRAP_LLVM_ENABLE_LLD and MSVC

2020-07-28 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2020-07-28T10:11:52+02:00
New Revision: ad4ab81dccaa72d9b5137433a0923d325ff76135

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

LOG: [clang][cmake] Force CMAKE_LINKER for multistage build in case of 
BOOTSTRAP_LLVM_ENABLE_LLD and MSVC

The issue with LLVM_ENABLE_LLD is that it just passes -fuse-ld=lld
to compiler/linker options which makes sense only for those platforms
where cmake invokes a compiler driver for linking. On Windows (MSVC) cmake
invokes the linker directly and requires CMAKE_LINKER to be specified
otherwise it defaults CMAKE_LINKER to be link.exe.

This patch allows BOOTSTRAP_LLVM_ENABLE_LLD to set CMAKE_LINKER in two cases:
* if building for host Windows,
* if crosscompiling for target Windows.

It also skips adding '-fuse-ld=lld' to make lld-link not warning
about 'unknown argument'.

This fixes build with `clang/cmake/caches/DistributionExample.cmake`
on Windows.

Reviewed By: phosek

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

Added: 


Modified: 
clang/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 1a6a20a271f3..0f08538495fc 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -753,6 +753,14 @@ if (CLANG_ENABLE_BOOTSTRAP)
 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
 -DCMAKE_ASM_COMPILER_ID=Clang)
 
+  # cmake requires CMAKE_LINKER to be specified if the compiler is MSVC-like,
+  # otherwise it defaults the linker to be link.exe.
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if((WIN32 AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) OR 
BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows")
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX})
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG 
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN

diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 62dd0ef79cf4..89f7016a7db4 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@ if( LLVM_ENABLE_LLD )
   if ( LLVM_USE_LINKER )
 message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at 
the same time")
   endif()
-  set(LLVM_USE_LINKER "lld")
+  # In case of MSVC cmake always invokes the linker directly, so the linker
+  # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld
+  # compiler option.
+  if ( NOT MSVC )
+set(LLVM_USE_LINKER "lld")
+  endif()
 endif()
 
 if( LLVM_USE_LINKER )



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