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

2023-09-05 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fbd1323e7bf: [Sema] Make C++ functional-style cast warn 
about dropped qualifiers (-Wcast… (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159133

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


Index: clang/test/Sema/warn-cast-qual.c
===
--- clang/test/Sema/warn-cast-qual.c
+++ clang/test/Sema/warn-cast-qual.c
@@ -36,6 +36,39 @@
   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 *fcharptr2 = CharPtr(charptr); // no warning
+#endif
 }
 
 void bar_0(void) {
@@ -48,6 +81,12 @@
 
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
+
+#ifdef __cplusplus
+  using IntPtr = int *;
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+#endif
 }
 
 void bar_1(void) {
@@ -61,4 +100,10 @@
 
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
   *(int *)() = 0; // no warning
+
+#ifdef __cplusplus
+  using IntPtr = int *;
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+  *(IntPtr()) = 0; // no warning
+#endif
 }
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -3374,6 +3374,9 @@
   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));
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -165,6 +165,7 @@
   (`#64871: `_).
   Also clang no longer emits false positive 

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

2023-08-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 554818.
krisb added a comment.

Add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159133

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


Index: clang/test/Sema/warn-cast-qual.c
===
--- clang/test/Sema/warn-cast-qual.c
+++ clang/test/Sema/warn-cast-qual.c
@@ -36,6 +36,39 @@
   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 *fcharptr2 = CharPtr(charptr); // no warning
+#endif
 }
 
 void bar_0(void) {
@@ -48,6 +81,12 @@
 
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
+
+#ifdef __cplusplus
+  using IntPtr = int *;
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+#endif
 }
 
 void bar_1(void) {
@@ -61,4 +100,10 @@
 
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
   *(int *)() = 0; // no warning
+
+#ifdef __cplusplus
+  using IntPtr = int *;
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+  *(IntPtr()) = 0; // no warning
+#endif
 }
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -3374,6 +3374,9 @@
   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));
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -155,6 +155,7 @@
   (`#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 

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

2023-08-29 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: lebedev.ri, rnk, alexfh.
Herald added a subscriber: StephenFan.
Herald added a project: All.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159133

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-cast-qual.c


Index: clang/test/Sema/warn-cast-qual.c
===
--- clang/test/Sema/warn-cast-qual.c
+++ clang/test/Sema/warn-cast-qual.c
@@ -36,6 +36,39 @@
   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 *fcharptr2 = CharPtr(charptr); // no warning
+#endif
 }
 
 void bar_0(void) {
@@ -48,6 +81,12 @@
 
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
+
+#ifdef __cplusplus
+  using IntPtr = int *;
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+#endif
 }
 
 void bar_1(void) {
@@ -61,4 +100,10 @@
 
   *(int *)() = 0; // expected-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
   *(int *)() = 0; // no warning
+
+#ifdef __cplusplus
+  using IntPtr = int *;
+  *(IntPtr()) = 0; // expected-warning {{cast from 'const int *' to 'int 
*' drops const qualifier}}
+  *(IntPtr()) = 0; // no warning
+#endif
 }
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -3374,6 +3374,9 @@
   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));


Index: clang/test/Sema/warn-cast-qual.c

[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (5/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 504608.
krisb marked an inline comment as done.
krisb added a comment.

Apply review comments and rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006

Files:
  clang/test/CodeGen/debug-info-codeview-unnamed.c
  clang/test/CodeGen/debug-info-unused-types.c
  clang/test/CodeGen/debug-info-unused-types.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp
  clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
  clang/test/CodeGenCXX/debug-lambda-this.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/DebugInfo/Generic/inlined-local-type.ll
  llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
  llvm/test/DebugInfo/Generic/lexical-block-types.ll
  llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/set.ll

Index: llvm/test/DebugInfo/X86/set.ll
===
--- llvm/test/DebugInfo/X86/set.ll
+++ llvm/test/DebugInfo/X86/set.ll
@@ -68,11 +68,11 @@
 !llvm.module.flags = !{!18, !19, !20}
 
 !0 = !{!"versions- cm3: d5.10.0 llvm: 9.0"}
-!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
+!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
 !2 = !DIFile(filename: "Main.m3", directory: "/home/cm3/settest/src")
 !3 = !{!4}
 !4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", scope: !5, file: !2, line: 11, size: 8, align: 8, elements: !9)
-!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
+!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !3)
 !6 = !DISubroutineType(types: !7)
 !7 = !{null}
 !8 = !{}
Index: llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
===
--- llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
+++ llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
@@ -38,7 +38,7 @@
 define void @invalid_retained_nodes_list() !dbg !10 { ret void }
 !10 = distinct !DISubprogram(retainedNodes: !0)
 
-; CHECK: invalid retained nodes, expected DILocalVariable, DILabel or DIImportedEntity
+; CHECK: invalid retained nodes, expected DILocalVariable, DILabel, DIImportedEntity or DIType
 define void @invalid_retained_nodes_expected() !dbg !11 { ret void }
 !11 = distinct !DISubprogram(retainedNodes: !{!0})
 
Index: llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
@@ -0,0 +1,160 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s  \
+; RUN:  | llvm-dwarfdump --show-children --name=foo - \
+; RUN:  | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s
+
+; The test ensures that AsmPrinter doesn't crashed compiling this.
+; It also demostrates misplacement for a local type (see PR55680 for details).
+
+; The test compiled from:
+
+; template
+; struct A {
+;   A(T ) : a(in) {}
+;   T a;
+; };
+;
+; __attribute__((always_inline))
+; void foo() {
+;   struct B { int i; };
+;   B objB;
+;   A objA(objB);
+; }
+;
+; int main() {
+;   foo();
+; }
+
+; Concrete out-of-line tree of foo().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_abstract_origin {{.*}} "_Z3foov"
+;
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objB"
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objA"
+
+; FIXME: 'struct B' should be in the abstract tree below, not here.
+; CHECK:   DW_TAG_structure_type
+; CHECK: DW_AT_name	("B")
+; CHECK: DW_TAG_member
+; CHECK: NULL
+
+; CHECK:   NULL
+
+; Abstract tree of foo().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_name	("foo")
+; CHECK:   DW_AT_inline	(DW_INL_inlined)
+
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_name	("objB")
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_name	("objA")
+
+; CHECK:   NULL
+
+; CHECK: DW_TAG_inlined_subroutine
+; CHECK:   DW_AT_abstract_origin {{.*}} "_Z3foov"
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objB"
+; CHECK:   DW_TAG_variable
+; CHECK: 

[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (5/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked 2 inline comments as done.
krisb added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:698
+  // an inlined function: if a local variable has a templated type with
+  // a function-local type as a template parameter. See PR55680 for details.
+  if (!Scope->isAbstractScope() && !Scope->getInlinedAt()) {

jmmartinez wrote:
> I cannot find the link to PR55680. Would you mind sharing it?
> 
> You could also reference `local-type-as-template-parameter.ll`, your test 
> depicts the issue very clearly.
> I cannot find the link to PR55680. Would you mind sharing it?
> 
> You could also reference `local-type-as-template-parameter.ll`, your test 
> depicts the issue very clearly.

Here is the link to the issue https://github.com/llvm/llvm-project/issues/55680.
Mentioned the test in the comment. Thank you!



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:712-714
+  assert(!getAbstractScopeDIEs().count(DS) &&
+ "Abstract DIE for this scope exists!");
+  getAbstractScopeDIEs()[DS] = ScopeDIE;

jmmartinez wrote:
> NIT: You could use `insert/try_emplace` instead of using `count` and 
> `operator[]`. The assertion would become something like:
> ```
> auto Inserted = getAbstractScopeDIEs().try_emplace(DS, ScopeDIE);
> assert(Inserted.second && "Abstract DIE for this scope exists!");
> return ScopeDIE;
> ```
I'd slightly prefer to keep the original code as it looks a bit more readable 
to me (in your example, there should be another line to void out unused 
`Inserted` variable, otherwise it'd cause a warning). 
Additional `count()` call in the `assert()` doesn't seem too expensive to me, 
but if you still think `try_emplace()` is better, I'll change to it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006

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


[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 504605.
krisb added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144004

Files:
  clang/test/CodeGenCXX/debug-info-namespace.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/test/CodeGen/Generic/DbgValueAggregate.ll
  llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/fission-inline.ll
  llvm/test/DebugInfo/X86/fission-local-import.ll
  llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
  llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
  llvm/test/DebugInfo/X86/namelist2.ll
  llvm/test/DebugInfo/omit-empty.ll
  llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Index: llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
===
--- llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
+++ llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
@@ -5,15 +5,13 @@
 ; RUN: opt -module-summary %p/Inputs/debuginfo-cu-import.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
 
-; Don't import enums, macros, retainedTypes or globals lists.
-; Only import local scope imported entities.
+; Don't import enums, macros, retainedTypes, globals or imports lists.
 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
 ; CHECK-NOT: DICompileUnit{{.*}} enums:
 ; CHECK-NOT: DICompileUnit{{.*}} macros:
 ; CHECK-NOT: DICompileUnit{{.*}} retainedTypes:
 ; CHECK-NOT: DICompileUnit{{.*}} globals:
-; CHECK: DICompileUnit{{.*}} imports: ![[IMP:[0-9]+]]
-; CHECK: ![[IMP]] = !{!{{[0-9]+}}}
+; CHECK-NOT: DICompileUnit{{.*}} imports:
 
 ; ModuleID = 'debuginfo-cu-import.c'
 source_filename = "debuginfo-cu-import.c"
@@ -50,14 +48,14 @@
 !8 = !{!9}
 !9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
 !10 = !DIGlobalVariable(name: "version", scope: !4, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true)
-!11 = !{!12, !16}
+!11 = !{!12}
 !12 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, entity: !13, file: !1, line: 8)
 !13 = distinct !DISubprogram(name: "a", linkageName: "_ZN1A1aEv", scope: !4, file: !1, line: 7, type: !14, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null}
 !16 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !17, entity: !19, file: !1, line: 8)
 !17 = distinct !DILexicalBlock(scope: !18, file: !1, line: 9, column: 8)
-!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
+!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !33)
 !19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 10, column: 8)
 !20 = distinct !DISubprogram(name: "d", linkageName: "_ZN1A1dEv", scope: !4, file: !1, line: 10, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !21 = !{!22}
@@ -72,4 +70,4 @@
 !30 = !DILocation(line: 7, column: 12, scope: !13)
 !31 = distinct !DISubprogram(name: "b", linkageName: "_ZN1A1bEv", scope: !4, file: !1, line: 8, type: !14, isLocal: true, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !32 = !DILocation(line: 8, column: 24, scope: !31)
-
+!33 = !{!16}
Index: llvm/test/DebugInfo/omit-empty.ll
===
--- llvm/test/DebugInfo/omit-empty.ll
+++ llvm/test/DebugInfo/omit-empty.ll
@@ -6,15 +6,15 @@
 !llvm.dbg.cu = !{!0, !5}
 !llvm.module.flags = !{!3, !4}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "LLVM", isOptimized: false, 

[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-03-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 504602.
krisb added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143984

Files:
  clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenObjC/debug-info-category.m
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/IR/DIBuilder.cpp

Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -57,23 +57,11 @@
 }
 
 void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
-  MDTuple *Temp = SP->getRetainedNodes().get();
-  if (!Temp || !Temp->isTemporary())
-return;
-
-  SmallVector RetainedNodes;
-
-  auto PV = PreservedVariables.find(SP);
-  if (PV != PreservedVariables.end())
-RetainedNodes.append(PV->second.begin(), PV->second.end());
-
-  auto PL = PreservedLabels.find(SP);
-  if (PL != PreservedLabels.end())
-RetainedNodes.append(PL->second.begin(), PL->second.end());
-
-  DINodeArray Node = getOrCreateArray(RetainedNodes);
-
-  TempMDTuple(Temp)->replaceAllUsesWith(Node.get());
+  auto PN = SubprogramTrackedNodes.find(SP);
+  if (PN != SubprogramTrackedNodes.end())
+SP->replaceRetainedNodes(
+MDTuple::get(VMContext, SmallVector(PN->second.begin(),
+PN->second.end(;
 }
 
 void DIBuilder::finalize() {
@@ -772,26 +760,20 @@
 
 static DILocalVariable *createLocalVariable(
 LLVMContext ,
-DenseMap> ,
-DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
+SmallVectorImpl ,
+DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
-  // FIXME: Why getNonCompileUnitScope()?
-  // FIXME: Why is "!Context" okay here?
   // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
   // the only valid scopes)?
-  DIScope *Context = getNonCompileUnitScope(Scope);
-
-  auto *Node = DILocalVariable::get(
-  VMContext, cast_or_null(Context), Name, File, LineNo, Ty,
-  ArgNo, Flags, AlignInBits, Annotations);
+  auto *Scope = cast(Context);
+  auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
+ArgNo, Flags, AlignInBits, Annotations);
   if (AlwaysPreserve) {
 // The optimizer may remove local variables. If there is an interest
 // to preserve variable info in such situation then stash it in a
 // named mdnode.
-DISubprogram *Fn = getDISubprogram(Scope);
-assert(Fn && "Missing subprogram for local variable");
-PreservedVariables[Fn].emplace_back(Node);
+PreservedNodes.emplace_back(Node);
   }
   return Node;
 }
@@ -801,9 +783,11 @@
DIType *Ty, bool AlwaysPreserve,
DINode::DIFlags Flags,
uint32_t AlignInBits) {
-  return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
- /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
- Flags, AlignInBits);
+  assert(Scope && isa(Scope) &&
+ "Unexpected scope for a local variable.");
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
+  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
 }
 
 DILocalVariable *DIBuilder::createParameterVariable(
@@ -811,25 +795,23 @@
 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
 DINodeArray Annotations) {
   assert(ArgNo && "Expected non-zero argument number for parameter");
-  return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
- File, LineNo, Ty, AlwaysPreserve, Flags,
- /*AlignInBits=*/0, Annotations);
+  assert(Scope && isa(Scope) &&
+ "Unexpected scope for a local variable.");
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
+  File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
 }
 
-DILabel *DIBuilder::createLabel(DIScope *Scope, StringRef Name, DIFile *File,
-unsigned LineNo, bool AlwaysPreserve) {
-  DIScope *Context = getNonCompileUnitScope(Scope);
-
-  auto *Node = DILabel::get(VMContext, cast_or_null(Context),
-Name, File, LineNo);
+DILabel *DIBuilder::createLabel(DIScope *Context, StringRef Name, DIFile *File,
+ unsigned LineNo, 

[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-03-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked an inline comment as done.
krisb added inline comments.



Comment at: llvm/include/llvm/IR/DIBuilder.h:76
 
-/// Each subprogram's preserved labels.
-DenseMap> PreservedLabels;
+SmallVectorImpl &
+getSubprogramNodesTrackingVector(const DIScope *S) {

aprantl wrote:
> Do you need a writeable copy, or could you get by with returning an 
> `ArrayRef`?
It should return smth suitable to emplace new elements, so, right, we need a 
writable reference here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143984

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


[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-03-02 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Friendly ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143984

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


[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-02-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll:17-36
+; CHECK:   DW_TAG_subprogram
+; CHECK: DW_AT_name("foo")
+; CHECK: DW_TAG_imported_declaration
+; CHECK: NULL
+
+; CHECK:   DW_TAG_base_type
+; CHECK: DW_AT_name("int")

jmmartinez wrote:
> I'd be tempted to match the offset of the abstract subprogram and of the 
> imported declaration too.
> At least for me, it makes clear the intention of the test without running it.
> 
> What do you think ?
Good point, thank  you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144004

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


[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-02-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 499848.
krisb marked 2 inline comments as done.
krisb added a comment.

Apply review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144004

Files:
  clang/test/CodeGenCXX/debug-info-namespace.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/test/CodeGen/Generic/DbgValueAggregate.ll
  llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/fission-inline.ll
  llvm/test/DebugInfo/X86/fission-local-import.ll
  llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
  llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
  llvm/test/DebugInfo/X86/namelist2.ll
  llvm/test/DebugInfo/omit-empty.ll
  llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Index: llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
===
--- llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
+++ llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
@@ -5,15 +5,13 @@
 ; RUN: opt -module-summary %p/Inputs/debuginfo-cu-import.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
 
-; Don't import enums, macros, retainedTypes or globals lists.
-; Only import local scope imported entities.
+; Don't import enums, macros, retainedTypes, globals or imports lists.
 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
 ; CHECK-NOT: DICompileUnit{{.*}} enums:
 ; CHECK-NOT: DICompileUnit{{.*}} macros:
 ; CHECK-NOT: DICompileUnit{{.*}} retainedTypes:
 ; CHECK-NOT: DICompileUnit{{.*}} globals:
-; CHECK: DICompileUnit{{.*}} imports: ![[IMP:[0-9]+]]
-; CHECK: ![[IMP]] = !{!{{[0-9]+}}}
+; CHECK-NOT: DICompileUnit{{.*}} imports:
 
 ; ModuleID = 'debuginfo-cu-import.c'
 source_filename = "debuginfo-cu-import.c"
@@ -50,14 +48,14 @@
 !8 = !{!9}
 !9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
 !10 = !DIGlobalVariable(name: "version", scope: !4, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true)
-!11 = !{!12, !16}
+!11 = !{!12}
 !12 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, entity: !13, file: !1, line: 8)
 !13 = distinct !DISubprogram(name: "a", linkageName: "_ZN1A1aEv", scope: !4, file: !1, line: 7, type: !14, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null}
 !16 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !17, entity: !19, file: !1, line: 8)
 !17 = distinct !DILexicalBlock(scope: !18, file: !1, line: 9, column: 8)
-!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
+!18 = distinct !DISubprogram(name: "c", linkageName: "_ZN1A1cEv", scope: !4, file: !1, line: 9, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !33)
 !19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 10, column: 8)
 !20 = distinct !DISubprogram(name: "d", linkageName: "_ZN1A1dEv", scope: !4, file: !1, line: 10, type: !14, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !21 = !{!22}
@@ -72,4 +70,4 @@
 !30 = !DILocation(line: 7, column: 12, scope: !13)
 !31 = distinct !DISubprogram(name: "b", linkageName: "_ZN1A1bEv", scope: !4, file: !1, line: 8, type: !14, isLocal: true, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !5)
 !32 = !DILocation(line: 8, column: 24, scope: !31)
-
+!33 = !{!16}
Index: llvm/test/DebugInfo/omit-empty.ll
===
--- llvm/test/DebugInfo/omit-empty.ll
+++ llvm/test/DebugInfo/omit-empty.ll
@@ -6,15 +6,15 @@
 !llvm.dbg.cu = !{!0, !5}
 !llvm.module.flags = !{!3, !4}
 
-!0 = distinct !DICompileUnit(language: 

[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-02-22 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@jmmartinez thank you for looking at this!




Comment at: llvm/lib/IR/DIBuilder.cpp:789
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
+  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);

jmmartinez wrote:
> I'll be tempted to move the call to `getSubprogramNodesTrackingVector(Scope)` 
> into `createLocalVariable`. It seems that every time `createLocalVariable` is 
> called, `getSubprogramNodesTrackingVector(Scope)` is passed as value for 
> `PreservedNodes`.
> 
> (I've just started reviewing so I may be missing some other modifications)
That's right, but the problem is in the fact that `createLocalVariable()` is 
static while `getSubprogramNodesTrackingVector()` is a DIBuilder's member. To 
move the call inside `createLocalVariable()` we need either to make it a member 
of DIBuilder or to pass DIBuilder object to it. None of these options looks 
much better to me, honestly. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143984

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2023-02-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb abandoned this revision.
krisb added a comment.

Abandon in favor of 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (5/7)

2023-02-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
krisb edited the summary of this revision.
krisb added reviewers: dblaikie, jmmartinez.
krisb added projects: LLVM, debug-info.
krisb published this revision for review.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144006

Files:
  clang/test/CodeGen/debug-info-codeview-unnamed.c
  clang/test/CodeGen/debug-info-unused-types.c
  clang/test/CodeGen/debug-info-unused-types.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp
  clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
  clang/test/CodeGenCXX/debug-lambda-this.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/DebugInfo/Generic/inlined-local-type.ll
  llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
  llvm/test/DebugInfo/Generic/lexical-block-types.ll
  llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/set.ll

Index: llvm/test/DebugInfo/X86/set.ll
===
--- llvm/test/DebugInfo/X86/set.ll
+++ llvm/test/DebugInfo/X86/set.ll
@@ -68,11 +68,11 @@
 !llvm.module.flags = !{!18, !19, !20}
 
 !0 = !{!"versions- cm3: d5.10.0 llvm: 9.0"}
-!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
+!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
 !2 = !DIFile(filename: "Main.m3", directory: "/home/cm3/settest/src")
 !3 = !{!4}
 !4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", scope: !5, file: !2, line: 11, size: 8, align: 8, elements: !9)
-!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
+!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !3)
 !6 = !DISubroutineType(types: !7)
 !7 = !{null}
 !8 = !{}
Index: llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
===
--- llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
+++ llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
@@ -38,7 +38,7 @@
 define void @invalid_retained_nodes_list() !dbg !10 { ret void }
 !10 = distinct !DISubprogram(retainedNodes: !0)
 
-; CHECK: invalid retained nodes, expected DILocalVariable, DILabel or DIImportedEntity
+; CHECK: invalid retained nodes, expected DILocalVariable, DILabel, DIImportedEntity or DIType
 define void @invalid_retained_nodes_expected() !dbg !11 { ret void }
 !11 = distinct !DISubprogram(retainedNodes: !{!0})
 
Index: llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
@@ -0,0 +1,160 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s  \
+; RUN:  | llvm-dwarfdump --show-children --name=foo - \
+; RUN:  | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s
+
+; The test ensures that AsmPrinter doesn't crashed compiling this.
+; It also demostrates misplacement for a local type (see PR55680 for details).
+
+; The test compiled from:
+
+; template
+; struct A {
+;   A(T ) : a(in) {}
+;   T a;
+; };
+;
+; __attribute__((always_inline))
+; void foo() {
+;   struct B { int i; };
+;   B objB;
+;   A objA(objB);
+; }
+;
+; int main() {
+;   foo();
+; }
+
+; Concrete out-of-line tree of foo().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_abstract_origin {{.*}} "_Z3foov"
+;
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_abstract_origin {{.*}} "objB"
+; CHECK:   DW_TAG_variable
+; CHECK: 

[PATCH] D144004: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-02-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
Herald added subscribers: ormris, steven_wu, hiraditya.
Herald added a reviewer: sscalpone.
Herald added a project: All.
krisb edited the summary of this revision.
krisb added reviewers: dblaikie, jmmartinez, ellis.
krisb added projects: LLVM, debug-info.
krisb published this revision for review.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Fixed PR51501 (tests from D112337 ).

This patch proposes two changes that get squashed to this single patch due to
their close dependencies:

1. Reuse of DISubprogram's 'retainedNodes' to track other function-local 
entities together with local variables and labels (this patch cares about 
function-local import while D144006  and 
D144008  use the same approach for local 
types and static variables). So, effectively this patch moves ownership of 
tracking local import from DICompileUnit's 'imports' field to DISubprogram's 
'retainedNodes' and adjusts DWARF emitter for the new layout. The old layout is 
considered unsupported (DwarfDebug would assert on such debug metadata).

  DICompileUnit's 'imports' field is supposed to track global imported 
declarations as it does before.

  This addresses various FIXMEs and simplifies the next part of the patch.

2. Postpone emission of function-local imported entities from 
`DwarfDebug::endFunctionImpl()` to `DwarfDebug::endModule()`. While in 
`DwarfDebug::endFunctionImpl()` we do not have all the information about a 
parent subprogram or a referring subprogram (whether a subprogram inlined or 
not), so we can't guarantee we emit an imported entity correctly and place it 
in a proper subprogram tree. So now, we just gather needed details about the 
import itself and its parent entity (either a Subprogram or a LexicalBlock) 
during processing in `DwarfDebug::endFunctionImpl()`, but all the real work is 
done in `DwarfDebug::endModule()` when we have all the required information to 
make proper emission.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144004

Files:
  clang/test/CodeGenCXX/debug-info-namespace.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/test/CodeGen/Generic/DbgValueAggregate.ll
  llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/fission-inline.ll
  llvm/test/DebugInfo/X86/fission-local-import.ll
  llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
  llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
  llvm/test/DebugInfo/X86/namelist2.ll
  llvm/test/DebugInfo/omit-empty.ll
  llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Index: llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
===
--- llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
+++ llvm/test/ThinLTO/X86/debuginfo-cu-import.ll
@@ -5,15 +5,13 @@
 ; RUN: opt -module-summary %p/Inputs/debuginfo-cu-import.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
 
-; Don't import enums, macros, retainedTypes or globals lists.
-; Only import local scope imported entities.
+; Don't import enums, macros, retainedTypes, globals or imports lists.
 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
 ; CHECK-NOT: DICompileUnit{{.*}} enums:
 ; CHECK-NOT: DICompileUnit{{.*}} macros:
 ; CHECK-NOT: DICompileUnit{{.*}} retainedTypes:
 ; CHECK-NOT: DICompileUnit{{.*}} globals:
-; CHECK: DICompileUnit{{.*}} imports: ![[IMP:[0-9]+]]
-; CHECK: ![[IMP]] = !{!{{[0-9]+}}}
+; CHECK-NOT: DICompileUnit{{.*}} imports:
 
 ; ModuleID = 'debuginfo-cu-import.c'
 source_filename = "debuginfo-cu-import.c"
@@ -50,14 +48,14 @@
 !8 = !{!9}
 !9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
 !10 = !DIGlobalVariable(name: "version", scope: !4, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true)
-!11 = !{!12, 

[PATCH] D143984: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-02-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
krisb edited the summary of this revision.
krisb added reviewers: dblaikie, jmmartinez.
krisb added projects: LLVM, debug-info.
krisb published this revision for review.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Currently, `retainedNodes` tracks function-local variables and labels.
To support function-local import, types and static variables (which are globals
in LLVM IR), subsequent patches use the same field. So this patch makes
preliminary refactoring of the code tracking local entities to apply future
functional changes lucidly and cleanly.

No functional changes intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143984

Files:
  clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenObjC/debug-info-category.m
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/IR/DIBuilder.cpp

Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -57,23 +57,11 @@
 }
 
 void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
-  MDTuple *Temp = SP->getRetainedNodes().get();
-  if (!Temp || !Temp->isTemporary())
-return;
-
-  SmallVector RetainedNodes;
-
-  auto PV = PreservedVariables.find(SP);
-  if (PV != PreservedVariables.end())
-RetainedNodes.append(PV->second.begin(), PV->second.end());
-
-  auto PL = PreservedLabels.find(SP);
-  if (PL != PreservedLabels.end())
-RetainedNodes.append(PL->second.begin(), PL->second.end());
-
-  DINodeArray Node = getOrCreateArray(RetainedNodes);
-
-  TempMDTuple(Temp)->replaceAllUsesWith(Node.get());
+  auto PN = SubprogramTrackedNodes.find(SP);
+  if (PN != SubprogramTrackedNodes.end())
+SP->replaceRetainedNodes(
+MDTuple::get(VMContext, SmallVector(PN->second.begin(),
+PN->second.end(;
 }
 
 void DIBuilder::finalize() {
@@ -772,26 +760,20 @@
 
 static DILocalVariable *createLocalVariable(
 LLVMContext ,
-DenseMap> ,
-DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
+SmallVectorImpl ,
+DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
-  // FIXME: Why getNonCompileUnitScope()?
-  // FIXME: Why is "!Context" okay here?
   // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
   // the only valid scopes)?
-  DIScope *Context = getNonCompileUnitScope(Scope);
-
-  auto *Node = DILocalVariable::get(
-  VMContext, cast_or_null(Context), Name, File, LineNo, Ty,
-  ArgNo, Flags, AlignInBits, Annotations);
+  auto *Scope = cast(Context);
+  auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
+ArgNo, Flags, AlignInBits, Annotations);
   if (AlwaysPreserve) {
 // The optimizer may remove local variables. If there is an interest
 // to preserve variable info in such situation then stash it in a
 // named mdnode.
-DISubprogram *Fn = getDISubprogram(Scope);
-assert(Fn && "Missing subprogram for local variable");
-PreservedVariables[Fn].emplace_back(Node);
+PreservedNodes.emplace_back(Node);
   }
   return Node;
 }
@@ -801,9 +783,11 @@
DIType *Ty, bool AlwaysPreserve,
DINode::DIFlags Flags,
uint32_t AlignInBits) {
-  return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
- /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
- Flags, AlignInBits);
+  assert(Scope && isa(Scope) &&
+ "Unexpected scope for a local variable.");
+  return createLocalVariable(
+  VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
+  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
 }
 
 DILocalVariable *DIBuilder::createParameterVariable(
@@ -811,25 +795,23 @@
 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
 DINodeArray Annotations) {
   assert(ArgNo && "Expected non-zero argument number for parameter");
-  return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
- File, LineNo, Ty, AlwaysPreserve, Flags,
- /*AlignInBits=*/0, 

[PATCH] D137067: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-11-03 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ecb2b8ef6be: [DebugInfo][Metadata] Make AllEnumTypes 
holding TrackingMDNodeRef (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137067

Files:
  clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   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 @@
   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;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 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;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ 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;
+}


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   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 @@
   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;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 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;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ 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,

[PATCH] D137067: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-10-31 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D137067#3896524 , @dblaikie wrote:

> Test case can be simplified a bit further:

Thank you!

> but otherwise I'm OK with this - I don't /fully/ understand it, but it sounds 
> plausible enough. (if you have time, I wouldn't mind hearing more about why 
> this requires local types (`Struct3`) and two similar functions to tickle the 
> issue)

The test is just a simplified code sample where the issue was original faced. 
I'm not sure we specifically need local types or two particular functions, but 
artificially reproducing the same conditions may be tricky.
Basically, the issue happens only when collisions take place twice:

- first time when a record's temporary debug metadata being replaced by a 
unique, and
- second time when tempopary's enum user being re-uniquefied.

I haven't studied deeply why the collisions happen in this particular test, 
since if collisions /may/ happen, we should handle this case correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137067

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


[PATCH] D137067: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-10-31 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 472079.
krisb added a comment.

Apply review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137067

Files:
  clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   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 @@
   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;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 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;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ 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;
+}


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   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 @@
   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;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 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;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ 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]] = 

[PATCH] D137067: [DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef

2022-10-31 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: ellis, aprantl, dblaikie.
Herald added a subscriber: hiraditya.
Herald added a project: All.
krisb requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

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.

Once resolved the temporary, we may 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-uniqueing it, which may return a new pointer in a case of 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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137067

Files:
  clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   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 @@
   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;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -48,7 +48,7 @@
 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;
Index: clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-enum-metadata-collision.cpp
@@ -0,0 +1,30 @@
+// 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();
+};
+template  struct Struct2 {
+  void function1() { (void)Struct1::enumValue1; }
+};
+void function2() {
+  struct Struct3 {};
+  Struct2 variable1;
+  variable1.function1();
+}
+void function3() {
+  struct Struct3 {};
+  Struct2 variable1;
+  variable1.function1();
+}


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -84,7 +84,9 @@
   }
 
   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 @@
   getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
   IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr,
   nullptr, UniqueIdentifier);
-  AllEnumTypes.push_back(CTy);
+  AllEnumTypes.emplace_back(CTy);
   

[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-24 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D125693#3653631 , @dblaikie wrote:

> In D125693#3648942 , @krisb wrote:
>
>> In D125693#3644029 , @dblaikie 
>> wrote:
>>
>>> In D125693#3641742 , @krisb wrote:
>>>
 @dblaikie, could you please take a look at this and/or D113741 
 ? Do you see any ways to proceed?
>>>
>>> My concern with this direction is that anything that adds lists to the IR 
>>> metadata makes it difficult for that data to be dropped when it becomes 
>>> unused (the type graph, apart from the "retained types" on the CU, is 
>>> structured so that if a variable, say, gets optimized away, or a function 
>>> gets optimized away and its parameters along with it, the types get dropped 
>>> too - similarly with function descriptions, they aren't in a list (they 
>>> used to be) and are instead referenced from the `llvm::Function` ensuring 
>>> that if the function is optimized away entirely, the debug info for that 
>>> goes away too). Admittedly function-local things are handled somewhat 
>>> differently, for instance there is a list on the `DISubprogram` of the 
>>> local variables to ensure they are retained through optimizations so name 
>>> lookup does the right things at function-scope. So /maybe/ it's OK to move 
>>> in that direction here, but it might look more like that, add these other 
>>> function-local things to the `DISubprogram`-scoped list (rename the list to 
>>> generalize over more than just variables), rather than adding per-scope 
>>> lists?
>>
>> Initially, I made the dedicated per-scope list of local static 
>> vars/imports/types to make possible to remove unused entities if their 
>> parent scope gets optimized out. This doesn't fully resolve your concern 
>> about local types that might be emitted even if they are not used, but this 
>> makes the things a bit better. Moreover, such local entities as well as 
>> variables/labels are not going to be emitted to a final DWARF if their scope 
>> was optimized away. Currently, to emit any local entity we need its scope to 
>> have LexicalScope defined. If there are no DILocations in such a scope (so 
>> that it may be considered as optimized out), it will not have LexicalScope 
>> defined for it, thus no variables/labels/other local things will be emitted 
>> for it. So, if we are not going to change this design in a near future, it 
>> might be worse to consider switching local variables/labels to per-scope 
>> list as well.
>>
>> What about merging variables/labels/other entities to a single list, I fully 
>> support this idea (it would require some additional checks in the backend, 
>> but would look more consistent).
>
> Ah, fair point about implicitly dropping some debug info if it's in a dead 
> scope. & yeah, maybe moving the existing optimized local variables list into 
> a per-scope list might be a nice improvement regardless.

Well, this isn't as good as I thought. We are skipping optimized scopes and 
entities belong to them iff the scope is concrete (either inline or 
out-of-line). But we never skip abstract scopes; instead we create 
LexicalScope's just before constructing an abstract tree (see 
`DwarfDebug::ensureAbstractEntityIsCreated()`) if there are some retained nodes 
in them (currently, local variables or labels).

I was a bit confused by assert in `DwarfDebug::endFunctionImpl()`:

  assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes
 && "ensureAbstractEntityIsCreated inserted abstract scopes");

It checks that `DwarfDebug::ensureAbstractEntityIsCreated()` doesn't create any 
scopes, but this check is for subprogram scopes only, it doesn't guard against 
creation of lexical block scope. And we do create LexicalScope's for 
DILexicalBlock if there is a retained node belong to it. I tried to restore the 
same behavior with per-scope retained nodes approach, but it significantly 
affects compile time (22.6% geomean on CTMark). 
So, I agree with your first suggestion to reuse retainedNodes field of 
DISuprogram to track other local entities. 
I'll update this patch soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D125693#3644029 , @dblaikie wrote:

> In D125693#3641742 , @krisb wrote:
>
>> @dblaikie, could you please take a look at this and/or D113741 
>> ? Do you see any ways to proceed?
>
> My concern with this direction is that anything that adds lists to the IR 
> metadata makes it difficult for that data to be dropped when it becomes 
> unused (the type graph, apart from the "retained types" on the CU, is 
> structured so that if a variable, say, gets optimized away, or a function 
> gets optimized away and its parameters along with it, the types get dropped 
> too - similarly with function descriptions, they aren't in a list (they used 
> to be) and are instead referenced from the `llvm::Function` ensuring that if 
> the function is optimized away entirely, the debug info for that goes away 
> too). Admittedly function-local things are handled somewhat differently, for 
> instance there is a list on the `DISubprogram` of the local variables to 
> ensure they are retained through optimizations so name lookup does the right 
> things at function-scope. So /maybe/ it's OK to move in that direction here, 
> but it might look more like that, add these other function-local things to 
> the `DISubprogram`-scoped list (rename the list to generalize over more than 
> just variables), rather than adding per-scope lists?

Initially, I made the dedicated per-scope list of local static 
vars/imports/types to make possible to remove unused entities if their parent 
scope gets optimized out. This doesn't fully resolve your concern about local 
types that might be emitted even if they are not used, but this makes the 
things a bit better. Moreover, such local entities as well as variables/labels 
are not going to be emitted to a final DWARF if their scope was optimized away. 
Currently, to emit any local entity we need its scope to have LexicalScope 
defined. If there are no DILocations in such a scope (so that it may be 
considered as optimized out), it will not have LexicalScope defined for it, 
thus no variables/labels/other local things will be emitted for it. So, if we 
are not going to change this design in a near future, it might be worse to 
consider switching local variables/labels to per-scope list as well.

What about merging variables/labels/other entities to a single list, I fully 
support this idea (it would require some additional checks in the backend, but 
would look more consistent).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-11 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@dblaikie, could you please take a look at this and/or D113741 
? Do you see any ways to proceed?




Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

ellis wrote:
> krisb wrote:
> > ellis wrote:
> > > krisb wrote:
> > > > ellis wrote:
> > > > > I asked the same question in D113741, but why is this test changed?
> > > > Normally, we emit function-local entities iff a parent function has 
> > > > location information. This is done the same way for local variables, 
> > > > labels, parameters, imported entities, and, //now,// for static locals 
> > > > as well.
> > > > Before this change static locals behaved more like global variables and 
> > > > get emitted doesn't matter its parent function. This patch makes them 
> > > > handled more like local variables.
> > > > 
> > > > I believe either the call or the 'ret' (or, likely, both) had had 
> > > > DILocation attached originally, but it has been removed to simplify the 
> > > > test.
> > > I just checked and the `llvm.instrprof.increment` intrinsic does not have 
> > > debug info attached. I think you're right that I removed debug info from 
> > > the `ret` instruction to simplify the test.
> > > 
> > > This is a special case where a global and its debug info is synthesized.
> > > https://github.com/llvm/llvm-project/blob/23c2bedfd93cfacc62009425c464e659a34e92e6/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L976-L1001
> > > 
> > > So I don't understand why this added debug info is necessary. Does the 
> > > test fail otherwise?
> > Right, the test would fail w/o the added DILocation, because `__profc_foo` 
> > variable (which is function-local 'global' technically) would not be 
> > emitted. 
> > With this patch we emit function-local entities if and only if the parent 
> > function has LexicalScope defined (see createAndAddScopeChildren() and its 
> > call from constructSubprogramScopeDIE()), otherwise we skip emitting all 
> > function's children (including function-local 'globals').
> Got it, thanks for explaining!
> 
> I'm ok with this because `llvm.instrprof.increment` should probably be next 
> to some instruction with debug info.
Thank you for checking this is okay!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

ellis wrote:
> krisb wrote:
> > ellis wrote:
> > > I asked the same question in D113741, but why is this test changed?
> > Normally, we emit function-local entities iff a parent function has 
> > location information. This is done the same way for local variables, 
> > labels, parameters, imported entities, and, //now,// for static locals as 
> > well.
> > Before this change static locals behaved more like global variables and get 
> > emitted doesn't matter its parent function. This patch makes them handled 
> > more like local variables.
> > 
> > I believe either the call or the 'ret' (or, likely, both) had had 
> > DILocation attached originally, but it has been removed to simplify the 
> > test.
> I just checked and the `llvm.instrprof.increment` intrinsic does not have 
> debug info attached. I think you're right that I removed debug info from the 
> `ret` instruction to simplify the test.
> 
> This is a special case where a global and its debug info is synthesized.
> https://github.com/llvm/llvm-project/blob/23c2bedfd93cfacc62009425c464e659a34e92e6/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L976-L1001
> 
> So I don't understand why this added debug info is necessary. Does the test 
> fail otherwise?
Right, the test would fail w/o the added DILocation, because `__profc_foo` 
variable (which is function-local 'global' technically) would not be emitted. 
With this patch we emit function-local entities if and only if the parent 
function has LexicalScope defined (see createAndAddScopeChildren() and its call 
from constructSubprogramScopeDIE()), otherwise we skip emitting all function's 
children (including function-local 'globals').


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

ellis wrote:
> I asked the same question in D113741, but why is this test changed?
Normally, we emit function-local entities iff a parent function has location 
information. This is done the same way for local variables, labels, parameters, 
imported entities, and, //now,// for static locals as well.
Before this change static locals behaved more like global variables and get 
emitted doesn't matter its parent function. This patch makes them handled more 
like local variables.

I believe either the call or the 'ret' (or, likely, both) had had DILocation 
attached originally, but it has been removed to simplify the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-06-29 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo][WIP] Support types, imports and static locals declared in a lexical block (3/5)

2022-06-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Tested the whole patchset with various combinations of

- opt levels (O0, O2 , O3 
, ThinLTO, FullLTO),
- debug info options (-fdebug-types-section, -gline-tables-only, 
-fno-eliminate-unused-debug-types -gsplit-dwarf, -fsplit-dwarf-inlining),
- and some additional checks / asserts (like additional verification of 
abstract / concrete out-of-line tree to be sure local entities are not 
duplicated, do not go to the wrong tree)

on clang bootstrapping build. No issues so far (except PR55680, which caused 
not by this and related patches).

This still doesn't guarantee that the patch accounts all the corner cases and 
no issues would be exposed later, but seems good to start with. 
Removing [WIP] status.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-06-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 434541.
krisb marked an inline comment as done.
krisb added a comment.

Applied review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125695

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-local-types.cpp

Index: clang/test/CodeGenCXX/debug-info-local-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-local-types.cpp
@@ -0,0 +1,101 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=CHECK,LIMITED
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=unused-types -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=UNUSED_TYPES
+
+void test() {
+  {
+struct S { int a; };
+class C { int b; };
+S s;
+{
+  C c;
+}
+  }
+
+  {
+typedef char Char;
+using Int = int;
+Char c;
+{
+  Int i;
+}
+  }
+
+  {
+enum E { a, b, c };
+enum class T { aa, bb, cc };
+E e = E::a;
+{
+  T t = T::aa;
+}
+  }
+
+  {
+union U { int i; char c; };
+U u = { 256 };
+  }
+}
+
+// LIMITED: distinct !DICompileUnit
+// LIMITED-NOT: retainedTypes:
+
+// CHECK: !DILocalVariable(name: "s", scope: [[LBSCOPE_1:![0-9]+]]
+// CHECK-SAME:type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE_1]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[STRUCT]], [[CLASS:![0-9]+]]}
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", scope: [[LBSCOPE_1]]
+// CHECK: [[CLASS]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", scope: [[LBSCOPE_1]]
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_11:![0-9]+]]
+// CHECK-SAME:type: [[CLASS]]
+// CHECK: [[LBSCOPE_11]] = distinct !DILexicalBlock(scope: [[LBSCOPE_1]]
+//
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_2:![0-9]+]]
+// CHECK-SAME:type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[LBSCOPE_2]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[TYPEDEF]], [[USING:![0-9]+]]}
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Char", scope: [[LBSCOPE_2]]
+// CHECK: [[USING]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Int", scope: [[LBSCOPE_2]]
+// CHECK: !DILocalVariable(name: "i", scope: [[LBSCOPE_21:![0-9]+]]
+// CHECK-SAME:type: [[USING]]
+// CHECK: [[LBSCOPE_21]] = distinct !DILexicalBlock(scope: [[LBSCOPE_2]]
+//
+// CHECK: !DILocalVariable(name: "e", scope: [[LBSCOPE_3:![0-9]+]]
+// CHECK-SAME:type: [[ENUM:![0-9]+]]
+// CHECK: [[LBSCOPE_3]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB3_DECLS:![0-9]+]]
+// CHECK: [[LB3_DECLS]] = !{[[ENUM]], [[ENUM_CLASS:![0-9]+]]}
+// CHECK: [[ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E", scope: [[LBSCOPE_3]]
+// CHECK: [[ENUM_CLASS]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "T", scope: [[LBSCOPE_3]]
+// CHECK: !DILocalVariable(name: "t", scope: [[LBSCOPE_31:![0-9]+]]
+// CHECK-SAME:type: [[ENUM_CLASS]]
+// CHECK: [[LBSCOPE_31]] = distinct !DILexicalBlock(scope: [[LBSCOPE_3]]
+//
+// CHECK: !DILocalVariable(name: "u", scope: [[LBSCOPE_4:![0-9]+]]
+// CHECK-SAME:type: [[UNION:![0-9]+]]
+// CHECK: [[LBSCOPE_4]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB4_DECLS:![0-9]+]]
+// CHECK: [[LB4_DECLS]] = !{[[UNION]]}
+// CHECK: [[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", scope: [[LBSCOPE_4]]
+
+void test_unused() {
+  {
+struct X {};
+typedef int Y; // typedef doesn't go to retainedTypes.
+enum Z { z };
+  }
+}
+
+// UNUSED_TYPES: distinct !DICompileUnit
+// UNUSED_TYPES-SAME: retainedTypes: [[RETAINED_TYPES:![0-9]+]]
+//
+// struct, class, char, int, enum, enum class, union, unused struct, unused enum, ::F
+// UNUSED_TYPES: [[RETAINED_TYPES]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, [[UNUSED_STRUCT:![0-9]+]], [[UNUSED_ENUM:![0-9]+]], !{{.*}}}
+// UNUSED_TYPES: [[UNUSED_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[UNUSED_LB:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB]] = distinct !DILexicalBlock({{.*}}, localDecls: [[UNUSED_LB_DECLS:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB_DECLS]] = !{[[UNUSED_STRUCT]], [[UNUSED_ENUM]]}
+// UNUSED_TYPES: [[UNUSED_ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Z", scope: [[UNUSED_LB]]
+
+void test_lambda() {
+  auto t = []() { struct F {}; return F(); };
+  auto v = t();
+}
+
+// TODO: ::F doesn't have its scope 

[PATCH] D125693: [DebugInfo][WIP] Support types, imports and static locals declared in a lexical block (3/5)

2022-05-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Thank you, @asavonic for your comments!

I've added some more details about the issues this is going to fix, hope it'll 
help to review the patchset.

In D125693#3523278 , @asavonic wrote:

> Thanks a lot for the patch! It would be great to get this issue finally 
> fixed. I assume that this is the main patch, other patches in the stack seem 
> like just preparation/adjustments needed for this one to work.

Correct. The first two patches were extracted to just make this one a bit 
smaller and easier to review.




Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1382
+  assert((!GV->getScope() || !isa(GV->getScope())) &&
+ "Unexpected function-local declaration!");
   if (Processed.insert(GV).second)

asavonic wrote:
> So here we discard LLVM IR metadata that have local declarations tied to a 
> CU, right? This will break compatibility with old LLVM IR. Can we do some 
> upgrade to convert this "old style" metadata the way we expect it now? Does 
> it make sense to support both variants?
Good question. I haven't thought about backward compatibility, not even sure we 
have some requirements for this. The easiest option seems to increase debug 
metadata version and drop debug info if it isn't compatible with this one as it 
done in AutoUpgrade. This prevents producing incorrect DWARF for ill-formed 
metadata.

Upgrading "old style" metadata would be a bit tricky. Current implementation 
assumes that all the local declarations (excluding regular local vars and 
labels) are referenced by parent's localDecls field, including types. Before 
this patchset there were no ways to find types except by references from their 
uses. So, to find all the function-local types we may need to iterate over all 
instructions and parse all debug metadata, which likely increases compile time. 
Not sure this trade-off is a worth one.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


[PATCH] D124982: [clang][OpenMP][DebugInfo] Debug support for variables in containing scope of OMP constructs

2022-05-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:689
   auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
+  insertDIE(Scope->getScopeNode(), ScopeDIE);
   if (Scope->isAbstractScope())

In case of compiling optimized code with inlining enabled, the `Scope` may be 
either a scope of an inlined instance (which may appear multiple times), an 
abstract scope or a concrete out-of-line scope. All of them will match a single 
ScopeNode, so this will override the map's value multiple times and `getDIE()` 
will likely return something that one may not expect.
I've been working on patches that make possible for local types, imports and 
static variables to be scoped in a lexical block, see D125693 for 
backend-related changes. May be you could find something useful there (see 
`DwarfCompileUnit::getOrCreateLexicalBlockDIE()` and 
`DwarfCompileUnit::getOrCreateContextDIE()`) or could help to review the 
patches.


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

https://reviews.llvm.org/D124982

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


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

2022-05-16 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb abandoned this revision.
krisb added a comment.
Herald added a project: All.

Split on two: D125694  and D125695 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-05-16 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: dblaikie, aprantl, probinson.
Herald added a project: All.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a part from D113743  split to make it 
easier to test and review.

It also enables lexical blocks as a scope for types and type-like entities
only if -debugger-tunning=gdb. lldb can't (yet) handle lexical block scoped
types (see D115277  for details), other 
debuggers were not verified (yet).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125695

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-local-types.cpp

Index: clang/test/CodeGenCXX/debug-info-local-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-local-types.cpp
@@ -0,0 +1,101 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=CHECK,LIMITED
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=unused-types -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=UNUSED_TYPES
+
+void test() {
+  {
+struct S { int a; };
+class C { int b; };
+S s;
+{
+  C c;
+}
+  }
+
+  {
+typedef char Char;
+using Int = int;
+Char c;
+{
+  Int i;
+}
+  }
+
+  {
+enum E { a, b, c };
+enum class T { aa, bb, cc };
+E e = E::a;
+{
+  T t = T::aa;
+}
+  }
+
+  {
+union U { int i; char c; };
+U u = { 256 };
+  }
+}
+
+// LIMITED: distinct !DICompileUnit
+// LIMITED-NOT: retainedTypes:
+
+// CHECK: !DILocalVariable(name: "s", scope: [[LBSCOPE_1:![0-9]+]]
+// CHECK-SAME:type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE_1]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[STRUCT]], [[CLASS:![0-9]+]]}
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", scope: [[LBSCOPE_1]]
+// CHECK: [[CLASS]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", scope: [[LBSCOPE_1]]
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_11:![0-9]+]]
+// CHECK-SAME:type: [[CLASS]]
+// CHECK: [[LBSCOPE_11]] = distinct !DILexicalBlock(scope: [[LBSCOPE_1]]
+//
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_2:![0-9]+]]
+// CHECK-SAME:type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[LBSCOPE_2]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[TYPEDEF]], [[USING:![0-9]+]]}
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Char", scope: [[LBSCOPE_2]]
+// CHECK: [[USING]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Int", scope: [[LBSCOPE_2]]
+// CHECK: !DILocalVariable(name: "i", scope: [[LBSCOPE_21:![0-9]+]]
+// CHECK-SAME:type: [[USING]]
+// CHECK: [[LBSCOPE_21]] = distinct !DILexicalBlock(scope: [[LBSCOPE_2]]
+//
+// CHECK: !DILocalVariable(name: "e", scope: [[LBSCOPE_3:![0-9]+]]
+// CHECK-SAME:type: [[ENUM:![0-9]+]]
+// CHECK: [[LBSCOPE_3]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB3_DECLS:![0-9]+]]
+// CHECK: [[LB3_DECLS]] = !{[[ENUM]], [[ENUM_CLASS:![0-9]+]]}
+// CHECK: [[ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E", scope: [[LBSCOPE_3]]
+// CHECK: [[ENUM_CLASS]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "T", scope: [[LBSCOPE_3]]
+// CHECK: !DILocalVariable(name: "t", scope: [[LBSCOPE_31:![0-9]+]]
+// CHECK-SAME:type: [[ENUM_CLASS]]
+// CHECK: [[LBSCOPE_31]] = distinct !DILexicalBlock(scope: [[LBSCOPE_3]]
+//
+// CHECK: !DILocalVariable(name: "u", scope: [[LBSCOPE_4:![0-9]+]]
+// CHECK-SAME:type: [[UNION:![0-9]+]]
+// CHECK: [[LBSCOPE_4]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB4_DECLS:![0-9]+]]
+// CHECK: [[LB4_DECLS]] = !{[[UNION]]}
+// CHECK: [[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", scope: [[LBSCOPE_4]]
+
+void test_unused() {
+  {
+struct X {};
+typedef int Y; // typedef doesn't go to retainedTypes.
+enum Z { z };
+  }
+}
+
+// UNUSED_TYPES: distinct !DICompileUnit
+// UNUSED_TYPES-SAME: retainedTypes: [[RETAINED_TYPES:![0-9]+]]
+//
+// struct, class, char, int, enum, enum class, union, unused struct, unused enum, ::F
+// UNUSED_TYPES: [[RETAINED_TYPES]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, [[UNUSED_STRUCT:![0-9]+]], [[UNUSED_ENUM:![0-9]+]], !{{.*}}}
+// UNUSED_TYPES: [[UNUSED_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[UNUSED_LB:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB]] = distinct 

[PATCH] D125694: [clang][DebugInfo] Allow function-local statics to be scoped within a lexical block (4/5)

2022-05-16 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: dblaikie, aprantl, probinson.
Herald added a project: All.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a part from D113743  split to make it 
easier to test and review.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125694

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-locals.cpp


Index: clang/test/CodeGenCXX/debug-info-static-locals.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-static-locals.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+
+// Test that static local variables emitted in correct scopes.
+
+void test() {
+  static int bar = 2;
+  {
+static int bar = 1;
+{
+  static int bar = 0;
+}
+  }
+}
+
+// CHECK: [[FS_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: 
[[FS_GV:![0-9]+]]
+// CHECK: [[FS_GV]] = distinct !DIGlobalVariable(name: "bar", scope: 
[[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "test"
+// CHECK-SAME:localDecls: [[FS_DECLS:![0-9]+]]
+// CHECK: [[FS_DECLS]] = !{[[FS_GVE]]}
+// CHECK: [[LB1_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: 
[[LB1_GV:![0-9]+]]
+// CHECK: [[LB1_GV]] = distinct !DIGlobalVariable(name: "bar", scope: 
[[LB1SCOPE:![0-9]+]]
+// CHECK: [[LB1SCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK-SAME:localDecls: 
[[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[LB1_GVE]]}
+// CHECK: [[LB2_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: 
[[LB2_GV:![0-9]+]]
+// CHECK: [[LB2_GV]] = distinct !DIGlobalVariable(name: "bar", scope: 
[[LB2SCOPE:![0-9]+]]
+// CHECK: [[LB2SCOPE]] = distinct !DILexicalBlock(scope: [[LB1SCOPE]]
+// CHECK-SAME:localDecls: 
[[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[LB2_GVE]]}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3746,6 +3746,14 @@
 TemplateParameters = nullptr;
   }
 
+  // Get context for static locals (that are technically globals) the same way
+  // we do for "local" locals -- by using current lexical block.
+  if (VD->isStaticLocal()) {
+assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack 
empty!");
+VDContext = LexicalBlockStack.back();
+return;
+  }
+
   // Since we emit declarations (DW_AT_members) for static members, place the
   // definition of those static members in the namespace they were declared in
   // in the source code (the lexical decl context).


Index: clang/test/CodeGenCXX/debug-info-static-locals.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-static-locals.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+// Test that static local variables emitted in correct scopes.
+
+void test() {
+  static int bar = 2;
+  {
+static int bar = 1;
+{
+  static int bar = 0;
+}
+  }
+}
+
+// CHECK: [[FS_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[FS_GV:![0-9]+]]
+// CHECK: [[FS_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "test"
+// CHECK-SAME:localDecls: [[FS_DECLS:![0-9]+]]
+// CHECK: [[FS_DECLS]] = !{[[FS_GVE]]}
+// CHECK: [[LB1_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[LB1_GV:![0-9]+]]
+// CHECK: [[LB1_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[LB1SCOPE:![0-9]+]]
+// CHECK: [[LB1SCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK-SAME:localDecls: [[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[LB1_GVE]]}
+// CHECK: [[LB2_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[LB2_GV:![0-9]+]]
+// CHECK: [[LB2_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[LB2SCOPE:![0-9]+]]
+// CHECK: [[LB2SCOPE]] = distinct !DILexicalBlock(scope: [[LB1SCOPE]]
+// CHECK-SAME:localDecls: [[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[LB2_GVE]]}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3746,6 +3746,14 @@
 TemplateParameters = nullptr;
   }
 
+  // Get context for static locals (that are technically globals) the same way
+  // we do for "local" locals -- by using current lexical block.
+  if (VD->isStaticLocal()) {
+assert(!LexicalBlockStack.empty() && "Region stack 

[PATCH] D125693: [DebugInfo][WIP] Support types, imports and static locals declared in a lexical block (3/5)

2022-05-16 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Mark this and D125691  as WIP since I'm still 
testing the approach on various combinations of debug info and optimization 
options (O0, O3 , thinlto, 
split-dwarf, split-dwarf-inlining, gline-tables-only, etc.).
Except of the testing purpose itself I'm also trying to catch the issue 
reported by David here https://reviews.llvm.org/D113741#3437182 for previous 
implementation (while I hope this approach wouldn't trigger the issue, it'd be 
good to catch and fix it anyway).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125693

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


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

2022-03-21 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGafbe54f2feb0: [clang] Fix wrong -Wunused-local-typedef 
warning within a template function (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

Files:
  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


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -238,5 +238,22 @@
   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"
Index: clang/test/Modules/odr_hash.cpp
===
--- clang/test/Modules/odr_hash.cpp
+++ clang/test/Modules/odr_hash.cpp
@@ -4372,6 +4372,8 @@
 G* S::Foo(const G* asdf, int*) {}
 #else
 S s;
+// expected-error@first.h:* {{'ParameterTest::S::Foo' has different 
definitions in different modules; definition in module 'FirstModule' first 
difference is 1st parameter with name ''}}
+// expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with 
name 'asdf'}}
 #endif
 }  // ParameterTest
 
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -193,7 +193,7 @@
 // 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 @@
 // 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'
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -974,6 +974,7 @@
 SemaRef.inferGslPointerAttribute(Typedef);
 
   Typedef->setAccess(D->getAccess());
+  Typedef->setReferenced(D->isReferenced());
 
   return Typedef;
 }


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -238,5 +238,22 @@
   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"
Index: clang/test/Modules/odr_hash.cpp
===
--- clang/test/Modules/odr_hash.cpp
+++ clang/test/Modules/odr_hash.cpp
@@ -4372,6 +4372,8 @@
 G* S::Foo(const G* asdf, int*) {}
 #else
 S s;
+// expected-error@first.h:* 

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

2022-03-14 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/test/SemaCXX/warn-unused-local-typedef.cpp:246
+  typedef int Int; // no-diag
+  typedef char Char; // expected-warning {{unused typedef 'Char'}}
+  Int m;

krisb wrote:
> Quuxplusone wrote:
> > I haven't tried to understand the main point of this PR, but FWIW, have you 
> > seen https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61596 ? This looks 
> > suspiciously like that exact case. (I just filed its dup 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104792 the other day.)
> This patch prevents clang from warning on used typedefs (`Int` case), if 
> those typedefs are defined within a local class of a templated function or a 
> member function of a templated class.
> For `Char` case, which is unused in this example, the patch changes nothing.
> 
> Regarding https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104792, those typedefs 
> seem well known, so could we just make clang skipping any checks for those 
> particular names?
> Alternatively, we would likely need to stop warning on any typedefs defined 
> within a function-local class (but those warnings may still be useful like in 
> the test from this patch).
@Quuxplusone if you do not have objections for this patch, I'd land it now. 
It'll make things a bit better and do not prevent us from relaxing conditions 
for the warning further.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


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

2022-03-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/test/SemaCXX/warn-unused-local-typedef.cpp:246
+  typedef int Int; // no-diag
+  typedef char Char; // expected-warning {{unused typedef 'Char'}}
+  Int m;

Quuxplusone wrote:
> I haven't tried to understand the main point of this PR, but FWIW, have you 
> seen https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61596 ? This looks 
> suspiciously like that exact case. (I just filed its dup 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104792 the other day.)
This patch prevents clang from warning on used typedefs (`Int` case), if those 
typedefs are defined within a local class of a templated function or a member 
function of a templated class.
For `Char` case, which is unused in this example, the patch changes nothing.

Regarding https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104792, those typedefs 
seem well known, so could we just make clang skipping any checks for those 
particular names?
Alternatively, we would likely need to stop warning on any typedefs defined 
within a function-local class (but those warnings may still be useful like in 
the test from this patch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


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

2022-03-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.
Herald added a project: All.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


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

2022-03-01 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@tra thank you for looking at this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120499

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


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

2022-03-01 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57aaab3b17f0: [NVPTX] Fix nvvm.match.sync*.i64 intrinsics 
return type (i64 - i32) (authored by krisb).

Changed prior to commit:
  https://reviews.llvm.org/D120499?vs=411416=412018#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120499

Files:
  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

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
 
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
-  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
-  %v1 = extractvalue {i64, i1} %r1, 0
-  %p1 = extractvalue {i64, i1} %r1, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
-  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
-  %v2 = extractvalue {i64, i1} %r2, 0
-  %p2 = extractvalue {i64, i1} %r2, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
-  %r3 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
-  %v3 = extractvalue {i64, i1} %r3, 0
-  %p3 = extractvalue {i64, i1} %r3, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 4, 3;
-  %r4 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 3, i64 4)
-  %v4 = extractvalue {i64, i1} %r4, 0
-  %p4 = extractvalue {i64, i1} %r4, 1
-
-  %vsum1 = add i64 %v1, %v2
-  %vsum2 = add i64 %v3, %v4
-  %vsum3 = add i64 %vsum1, %vsum2
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  

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

2022-02-25 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 411416.
krisb added a comment.

Fix a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120499

Files:
  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

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
 
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
-  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
-  %v1 = extractvalue {i64, i1} %r1, 0
-  %p1 = extractvalue {i64, i1} %r1, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
-  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
-  %v2 = extractvalue {i64, i1} %r2, 0
-  %p2 = extractvalue {i64, i1} %r2, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
-  %r3 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
-  %v3 = extractvalue {i64, i1} %r3, 0
-  %p3 = extractvalue {i64, i1} %r3, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 4, 3;
-  %r4 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 3, i64 4)
-  %v4 = extractvalue {i64, i1} %r4, 0
-  %p4 = extractvalue {i64, i1} %r4, 1
-
-  %vsum1 = add i64 %v1, %v2
-  %vsum2 = add i64 %v3, %v4
-  %vsum3 = add i64 %vsum1, %vsum2
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
+  %r3 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
+  %v3 = extractvalue {i32, i1} %r3, 0
+  %p3 = extractvalue {i32, i1} %r3, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 

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

2022-02-25 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 411341.
krisb added a comment.

Add SM_70 requirement for 'match' builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120499

Files:
  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

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
 
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
-  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
-  %v1 = extractvalue {i64, i1} %r1, 0
-  %p1 = extractvalue {i64, i1} %r1, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
-  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
-  %v2 = extractvalue {i64, i1} %r2, 0
-  %p2 = extractvalue {i64, i1} %r2, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
-  %r3 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
-  %v3 = extractvalue {i64, i1} %r3, 0
-  %p3 = extractvalue {i64, i1} %r3, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 4, 3;
-  %r4 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 3, i64 4)
-  %v4 = extractvalue {i64, i1} %r4, 0
-  %p4 = extractvalue {i64, i1} %r4, 1
-
-  %vsum1 = add i64 %v1, %v2
-  %vsum2 = add i64 %v3, %v4
-  %vsum3 = add i64 %vsum1, %vsum2
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
+  %r3 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
+  %v3 = extractvalue {i32, i1} %r3, 0
+  %p3 = extractvalue {i32, i1} %r3, 1
+
+  ; CHECK:  

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

2022-02-24 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D113743#3343481 , @dblaikie wrote:

> In D113743#3177437 , @krisb wrote:
>
>> In D113743#3175301 , @dblaikie 
>> wrote:
>>
>>> Not super surprising that lldb might not be able to deal with DWARF in this 
>>> shape - is LLDB support important to you/something you plan to work on for 
>>> this DWARF? Otherwise we might need to opt-out of this functionality when 
>>> tuning for LLDB, for instance. Unless LLDB-invested folks are interested in 
>>> doing the integration work (& even then, maybe disabling it for LLDB tuning 
>>> until that's fixed). @aprantl @JDevlieghere
>>
>> Thank you for the suggestion!
>> I implemented a small workaround that makes lldb behaves like if the types 
>> have subprogram scope (see https://reviews.llvm.org/D115277), not sure I'll 
>> be able to do something better any time soon.
>> So, if D115277  isn't acceptable, and 
>> nobody volunteers to implement this properly, the only way to proceed is to 
>> turn this functionality off for lldb.
>
> Thanks for having a go at a fix/workaround here.
>
> I think we'll still need to hear from Apple folks (@aprantl @JDevlieghere 
> @shafik ) - I'm not sure what their backwards compatibility (new 
> clang-produced binaries being debugged with an old lldb) requirements are. If 
> they need some backcompat there, then I guess they/we/you would still need to 
> disable this DWARF fidelity improvement when tuning for lldb. Hopefully that 
> can be avoided, but I don't know.

Thank you!

FYI. I'm going to split this patch into two: one for local statics and one for 
types and other. The part for static variables seems clean and safe so we can 
let it go once backend will be ready for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


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

2022-02-24 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added a reviewer: tra.
Herald added subscribers: asavonic, hiraditya.
krisb requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert.
Herald added projects: clang, LLVM.

NVVM IR specification defines them with i32 return type [0]:

  The following intrinsics synchronize a subset of threads in a warp and then
  broadcast and compare a value across threads in the subset.
  
  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 spec [1]:

  9.7.12.8. Parallel Synchronization and Communication Instructions: match.sync
  ...
  Syntax
  match.any.sync.type  d, a, membermask;
  match.all.sync.type  d[|p], a, membermask;
  
  Description
  ...
  Destination d is a 32-bit mask where bit position in mask corresponds
  to thread’s laneid.

So it doesn't make sense to define them with any other return type.

Additionally, ptxas doesn't accept intructions, produced by NVPTX
backend. Here is the ptxas output for `llvm/test/CodeGen/NVPTX/match.ll`:

  ptxas match.ptx, line 44; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 45; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 46; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 47; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 98; error   : Arguments mismatch for instruction 'match'

After this patch, it compiles with no issues.

[0] https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html#unique_341827171
[1] 
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-match-sync


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120499

Files:
  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

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	

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

2022-02-24 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 411137.
krisb added a comment.

Rebase on top of 'main'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

Index: clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+void foo() {
+  static int bar = 1;
+  {
+struct X {};
+typedef char Y;
+static int bar = 0;
+// The following basic block is intended, in order to check the case where
+// types "X", "Y" are defined in a different scope than where they are used.
+// They should have the scope they are defined at as their parent scope.
+{
+  X a;
+  Y b;
+}
+  }
+}
+
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "foo"
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBSCOPE:![0-9]+]]
+// CHECK: [[LBSCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "a", scope: [[LBSCOPE2:![0-9]+]], {{.*}} type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE2]] = distinct !DILexicalBlock(scope: [[LBSCOPE]]
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "b", scope: [[LBSCOPE2]], {{.*}} type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBSCOPE]]
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -103,17 +103,21 @@
 llvm_unreachable("Declaration should not be in declstmts!");
   case Decl::Record:// struct/union/class X;
   case Decl::CXXRecord: // struct/union/class X; [C++]
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getRecordType(cast()));
+}
 return;
   case Decl::Enum:  // enum X;
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getEnumType(cast()));
+}
 return;
-  case Decl::Function: // void X();
   case Decl::EnumConstant: // enum ? { X = ? }
+  case Decl::Function: // void X();
   case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
   case Decl::Label:// __label__ x;
   case Decl::Import:
@@ -132,11 +136,11 @@
 
   case Decl::NamespaceAlias:
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitNamespaceAlias(cast(D));
+  DI->EmitNamespaceAlias(cast(D));
 return;
   case Decl::Using:  // using X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitUsingDecl(cast(D));
+  DI->EmitUsingDecl(cast(D));
 return;
   case Decl::UsingEnum: // using enum X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
@@ -172,8 +176,10 @@
   case Decl::Typedef:  // typedef int X;
   case Decl::TypeAlias: {  // using X = int; [C++0x]
 QualType Ty = cast(D).getUnderlyingType();
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   DI->EmitAndRetainType(Ty);
+}
 if (Ty->isVariablyModifiedType())
   EmitVariablyModifiedType(Ty);
 return;
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -138,6 +138,11 @@
 
   /// Keep track of our current nested lexical block.
   std::vector> LexicalBlockStack;
+
+  /// Map of AST declaration to its lexical block scope.
+  llvm::DenseMap>
+  LexicalBlockMap;
+
   llvm::DenseMap RegionMap;
   /// Keep track of LexicalBlockStack counter at the beginning of a
   /// function. This is used to pop unbalanced regions at the end of a
@@ -542,6 +547,12 @@
   /// Emit an Objective-C interface type standalone debug info.
   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
 
+  /// Map AST declaration to its lexical block scope if available.
+  void recordDeclarationLexicalScope(const Decl );
+
+  /// Get lexical scope of AST declaration.
+  llvm::DIScope *getDeclarationLexicalScope(const Decl *D);
+
   /// Emit standalone debug info for a type.
   llvm::DIType 

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

2022-02-21 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


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

2021-12-10 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@rtrieu, thank you for looking at this! Do you have any comments about the rest 
of the patch? Do you think it makes sense?




Comment at: clang/test/Modules/odr_hash.cpp:4288
 S s;
+// expected-error@first.h:* {{'ParameterTest::S::Foo' has different 
definitions in different modules; definition in module 'FirstModule' first 
difference is 1st parameter with name ''}}
+// expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with 
name 'asdf'}}

rtrieu wrote:
> krisb wrote:
> > I'm not sure what was the original intent of this test (i.e. whether it 
> > intentionally tests the fact that there is no error on an uninstantiated 
> > static member function). As well as it doesn't clear to me what is the role 
> > of the unused typedef here, but it starts triggering the error because of 
> > redecls() call on isReferenced() added by this patch.
> I've checked out the ODR Hashing versus the other cases.   The new error is 
> in line with the other behavior.  Having this new error is okay.
Thank you for checking this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


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

2021-12-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D113743#3175301 , @dblaikie wrote:

> Not super surprising that lldb might not be able to deal with DWARF in this 
> shape - is LLDB support important to you/something you plan to work on for 
> this DWARF? Otherwise we might need to opt-out of this functionality when 
> tuning for LLDB, for instance. Unless LLDB-invested folks are interested in 
> doing the integration work (& even then, maybe disabling it for LLDB tuning 
> until that's fixed). @aprantl @JDevlieghere

Thank you for the suggestion!
I implemented a small workaround that makes lldb behaves like if the types have 
subprogram scope (see https://reviews.llvm.org/D115277), not sure I'll be able 
to do something better any time soon.
So, if D115277  isn't acceptable, and nobody 
volunteers to implement this properly, the only way to proceed is to turn this 
functionality off for lldb.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


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

2021-12-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D113743#3173981 , @JDevlieghere 
wrote:

> Hey Kristina, this broke TestSetData.py on GreenDragon: 
> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/39089/
>
> Since the bot has been red for several hours I went ahead and reverted your 
> change in 4cb79294e8df8c91ae15264d1014361815d34a53 
> .

Thank you for taking care of this!
I'm looking at the issue, but it's been taking more time than I expected.

This doesn't seem like a flaw of the patch, but likely is a lack of support of 
records/typedefs scoped within a bracketed block from lldb side.
I see lldb couldn't handle cases like

  int foo(int a) {
{
  typedef int Int;
  Int local = a;
  return local;
}
  }

which produces the same error as for TestSetData.py:

  Process 2487354 stopped
  * thread #1, name = 'a.out', stop reason = step over
  frame #0: 0x0040111d a.out`foo(a=1) at test_lldb.cpp:5:12
 2{
 3  typedef int Int;
 4  Int local = a;
  -> 5  return local;
 6}
 7  }
 8  
  (lldb) p local
  error: expression failed to parse:
  error: :45:31: no member named 'local' in namespace 
'$__lldb_local_vars'
  using $__lldb_local_vars::local;
^
  error: :1:1: use of undeclared identifier 'local'
  local
  ^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


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

2021-12-06 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe403f4fdc883: [clang][DebugInfo] Allow function-local 
statics and types to be scoped within a… (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

Index: clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+void foo() {
+  static int bar = 1;
+  {
+struct X {};
+typedef char Y;
+static int bar = 0;
+// The following basic block is intended, in order to check the case where
+// types "X", "Y" are defined in a different scope than where they are used.
+// They should have the scope they are defined at as their parent scope.
+{
+  X a;
+  Y b;
+}
+  }
+}
+
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "foo"
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBSCOPE:![0-9]+]]
+// CHECK: [[LBSCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "a", scope: [[LBSCOPE2:![0-9]+]], {{.*}} type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE2]] = distinct !DILexicalBlock(scope: [[LBSCOPE]]
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "b", scope: [[LBSCOPE2]], {{.*}} type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBSCOPE]]
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -103,17 +103,21 @@
 llvm_unreachable("Declaration should not be in declstmts!");
   case Decl::Record:// struct/union/class X;
   case Decl::CXXRecord: // struct/union/class X; [C++]
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getRecordType(cast()));
+}
 return;
   case Decl::Enum:  // enum X;
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getEnumType(cast()));
+}
 return;
-  case Decl::Function: // void X();
   case Decl::EnumConstant: // enum ? { X = ? }
+  case Decl::Function: // void X();
   case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
   case Decl::Label:// __label__ x;
   case Decl::Import:
@@ -132,11 +136,11 @@
 
   case Decl::NamespaceAlias:
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitNamespaceAlias(cast(D));
+  DI->EmitNamespaceAlias(cast(D));
 return;
   case Decl::Using:  // using X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitUsingDecl(cast(D));
+  DI->EmitUsingDecl(cast(D));
 return;
   case Decl::UsingEnum: // using enum X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
@@ -172,8 +176,10 @@
   case Decl::Typedef:  // typedef int X;
   case Decl::TypeAlias: {  // using X = int; [C++0x]
 QualType Ty = cast(D).getUnderlyingType();
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   DI->EmitAndRetainType(Ty);
+}
 if (Ty->isVariablyModifiedType())
   EmitVariablyModifiedType(Ty);
 return;
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -139,6 +139,11 @@
 
   /// Keep track of our current nested lexical block.
   std::vector> LexicalBlockStack;
+
+  /// Map of AST declaration to its lexical block scope.
+  llvm::DenseMap>
+  LexicalBlockMap;
+
   llvm::DenseMap RegionMap;
   /// Keep track of LexicalBlockStack counter at the beginning of a
   /// function. This is used to pop unbalanced regions at the end of a
@@ -543,6 +548,12 @@
   /// Emit an Objective-C interface type standalone debug info.
   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
 
+  /// Map AST declaration to its lexical block scope if available.
+  void recordDeclarationLexicalScope(const Decl );
+
+  /// Get lexical scope of AST declaration.
+  

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

2021-12-02 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


[PATCH] D114446: [clang] Fix wrong -Wunused-local-typedef warning if use is a dependent qialified identifier

2021-12-02 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 391312.
krisb added a comment.

Simplified diagnostic condition in 
TemplateDeclInstantiator::InstantiateTypedefNameDecl().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114446

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/warn-unused-local-typedef.cpp


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -255,5 +255,20 @@
 }
 } // TypedefInLocalClassOfTemplateClassMember
 
+namespace TypedefInDependentQualifiedIdentifier {
+struct A { void f() const {} };
+
+template 
+void handler(const T ) {
+   using a_type_t = A; // no-diag
+  using b_type_t = A; // expected-warning {{unused type alias 'b_type_t'}}
+   item.a_type_t::f();
+}
+
+void foo() {
+   handler(A());
+}
+} // TypedefInDependentQualifiedIdentifier
+
 // This should not disable any warnings:
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -955,6 +955,10 @@
   Typedef->setAccess(D->getAccess());
   Typedef->setReferenced(D->isReferenced());
 
+  // Diagnose unused local typedefs.
+  if (!Typedef->isInvalidDecl() && (!RD || RD->isLocalClass()))
+SemaRef.DiagnoseUnusedDecl(Typedef);
+
   return Typedef;
 }
 
@@ -1907,8 +1911,6 @@
 LocalInstantiations.perform();
   }
 
-  SemaRef.DiagnoseUnusedNestedTypedefs(Record);
-
   if (IsInjectedClassName)
 assert(Record->isInjectedClassName() && "Broken injected-class-name");
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1794,16 +1794,19 @@
 
   // Except for labels, we only care about unused decls that are local to
   // functions.
-  bool WithinFunction = D->getDeclContext()->isFunctionOrMethod();
-  if (const auto *R = dyn_cast(D->getDeclContext()))
-// For dependent types, the diagnostic is deferred.
-WithinFunction =
-WithinFunction || (R->isLocalClass() && !R->isDependentType());
+  auto *Context = D->getDeclContext();
+  bool WithinFunction = Context->isFunctionOrMethod();
+  if (const auto *R = dyn_cast(Context))
+WithinFunction = WithinFunction || R->isLocalClass();
   if (!WithinFunction)
 return false;
 
-  if (isa(D))
+  if (const auto *TD = dyn_cast(D)) {
+// Defer warnings for typedefs within a dependent context.
+if (Context->isDependentContext())
+  return false;
 return true;
+  }
 
   // White-list anything that isn't a local variable.
   if (!isa(D) || isa(D) || isa(D))


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -255,5 +255,20 @@
 }
 } // TypedefInLocalClassOfTemplateClassMember
 
+namespace TypedefInDependentQualifiedIdentifier {
+struct A { void f() const {} };
+
+template 
+void handler(const T ) {
+	using a_type_t = A; // no-diag
+  using b_type_t = A; // expected-warning {{unused type alias 'b_type_t'}}
+	item.a_type_t::f();
+}
+
+void foo() {
+	handler(A());
+}
+} // TypedefInDependentQualifiedIdentifier
+
 // This should not disable any warnings:
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -955,6 +955,10 @@
   Typedef->setAccess(D->getAccess());
   Typedef->setReferenced(D->isReferenced());
 
+  // Diagnose unused local typedefs.
+  if (!Typedef->isInvalidDecl() && (!RD || RD->isLocalClass()))
+SemaRef.DiagnoseUnusedDecl(Typedef);
+
   return Typedef;
 }
 
@@ -1907,8 +1911,6 @@
 LocalInstantiations.perform();
   }
 
-  SemaRef.DiagnoseUnusedNestedTypedefs(Record);
-
   if (IsInjectedClassName)
 assert(Record->isInjectedClassName() && "Broken injected-class-name");
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1794,16 +1794,19 @@
 
   // Except for labels, we only care about unused decls that are local to
   // functions.
-  bool WithinFunction = D->getDeclContext()->isFunctionOrMethod();
-  if (const auto *R = dyn_cast(D->getDeclContext()))
-// For dependent types, the diagnostic is deferred.
-WithinFunction =
-

[PATCH] D108301: [MSP430][Clang] Update hard-coded MCU data

2021-12-02 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:223-224
+  MCUData LoadedMCUData;
+  if (const Arg *MCUArg = Args.getLastArg(options::OPT_mmcu_EQ))
+LoadedMCUData = getMCUData(MCUArg->getValue());
+

It might be worth moving this under `hwmult` option check, so we do not need to 
load MCU data again if the option is properly specificed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108301

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


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

2021-11-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


[PATCH] D114446: [clang] Fix wrong -Wunused-local-typedef warning if use is a dependent qialified identifier

2021-11-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: thakis, rtrieu, rsmith.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Attempt to fix Tom Smeding's example from 
https://bugs.llvm.org/show_bug.cgi?id=24883.

Given the case like this one:

  struct A {
void f() const {}
  };
  
  template 
  void handler(const T ) {
using a_type_t = A;
item.a_type_t::f();
  }
  
  int main() {
handler(A());
  }

there is no way to know whether the typedef is used or not before
the templated context is instantiated.

Having this the patch proposes deffering all the diagnostics for
typedefs defined within a dependent context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114446

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/warn-unused-local-typedef.cpp


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -255,5 +255,20 @@
 }
 } // TypedefInLocalClassOfTemplateClassMember
 
+namespace TypedefInDependentQualifiedIdentifier {
+struct A { void f() const {} };
+
+template 
+void handler(const T ) {
+   using a_type_t = A; // no-diag
+  using b_type_t = A; // expected-warning {{unused type alias 'b_type_t'}}
+   item.a_type_t::f();
+}
+
+void foo() {
+   handler(A());
+}
+} // TypedefInDependentQualifiedIdentifier
+
 // This should not disable any warnings:
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -955,6 +955,14 @@
   Typedef->setAccess(D->getAccess());
   Typedef->setReferenced(D->isReferenced());
 
+  // Diagnose unused local typedefs here since diagnostics for typedefs
+  // in a dependent context were deffered).
+  bool ShouldDiagnoseUnused = Typedef->getDeclContext()->isFunctionOrMethod();
+  if (const auto *R = dyn_cast(Typedef->getDeclContext()))
+ShouldDiagnoseUnused = ShouldDiagnoseUnused || R->isLocalClass();
+  if (!Typedef->isInvalidDecl() && ShouldDiagnoseUnused)
+SemaRef.DiagnoseUnusedDecl(Typedef);
+
   return Typedef;
 }
 
@@ -1907,8 +1915,6 @@
 LocalInstantiations.perform();
   }
 
-  SemaRef.DiagnoseUnusedNestedTypedefs(Record);
-
   if (IsInjectedClassName)
 assert(Record->isInjectedClassName() && "Broken injected-class-name");
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1794,16 +1794,19 @@
 
   // Except for labels, we only care about unused decls that are local to
   // functions.
-  bool WithinFunction = D->getDeclContext()->isFunctionOrMethod();
-  if (const auto *R = dyn_cast(D->getDeclContext()))
-// For dependent types, the diagnostic is deferred.
-WithinFunction =
-WithinFunction || (R->isLocalClass() && !R->isDependentType());
+  auto *Context = D->getDeclContext();
+  bool WithinFunction = Context->isFunctionOrMethod();
+  if (const auto *R = dyn_cast(Context))
+WithinFunction = WithinFunction || R->isLocalClass();
   if (!WithinFunction)
 return false;
 
-  if (isa(D))
+  if (const auto *TD = dyn_cast(D)) {
+// Defer warnings for typedefs within a dependent context.
+if (Context->isDependentContext())
+  return false;
 return true;
+  }
 
   // White-list anything that isn't a local variable.
   if (!isa(D) || isa(D) || isa(D))


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -255,5 +255,20 @@
 }
 } // TypedefInLocalClassOfTemplateClassMember
 
+namespace TypedefInDependentQualifiedIdentifier {
+struct A { void f() const {} };
+
+template 
+void handler(const T ) {
+	using a_type_t = A; // no-diag
+  using b_type_t = A; // expected-warning {{unused type alias 'b_type_t'}}
+	item.a_type_t::f();
+}
+
+void foo() {
+	handler(A());
+}
+} // TypedefInDependentQualifiedIdentifier
+
 // This should not disable any warnings:
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -955,6 +955,14 @@
   Typedef->setAccess(D->getAccess());
   Typedef->setReferenced(D->isReferenced());
 
+  // Diagnose unused local typedefs here since diagnostics for typedefs
+  // in a dependent context were deffered).
+  bool 

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

2021-11-22 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/test/Modules/odr_hash.cpp:4288
 S s;
+// expected-error@first.h:* {{'ParameterTest::S::Foo' has different 
definitions in different modules; definition in module 'FirstModule' first 
difference is 1st parameter with name ''}}
+// expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with 
name 'asdf'}}

I'm not sure what was the original intent of this test (i.e. whether it 
intentionally tests the fact that there is no error on an uninstantiated static 
member function). As well as it doesn't clear to me what is the role of the 
unused typedef here, but it starts triggering the error because of redecls() 
call on isReferenced() added by this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


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

2021-11-22 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: thakis, rtrieu, rsmith.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Partially fixes PR24883.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114382

Files:
  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


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -238,5 +238,22 @@
   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"
Index: clang/test/Modules/odr_hash.cpp
===
--- clang/test/Modules/odr_hash.cpp
+++ clang/test/Modules/odr_hash.cpp
@@ -4285,6 +4285,8 @@
 G* S::Foo(const G* asdf, int*) {}
 #else
 S s;
+// expected-error@first.h:* {{'ParameterTest::S::Foo' has different 
definitions in different modules; definition in module 'FirstModule' first 
difference is 1st parameter with name ''}}
+// expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with 
name 'asdf'}}
 #endif
 }  // ParameterTest
 
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -193,7 +193,7 @@
 // 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 @@
 // 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'
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -953,6 +953,7 @@
 SemaRef.inferGslPointerAttribute(Typedef);
 
   Typedef->setAccess(D->getAccess());
+  Typedef->setReferenced(D->isReferenced());
 
   return Typedef;
 }


Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -238,5 +238,22 @@
   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"
Index: clang/test/Modules/odr_hash.cpp
===
--- clang/test/Modules/odr_hash.cpp
+++ clang/test/Modules/odr_hash.cpp
@@ -4285,6 +4285,8 @@
 G* S::Foo(const G* asdf, int*) {}
 #else
 S 

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

2021-11-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@aprantl thank you for taking a look at this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


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

2021-11-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 387956.
krisb marked an inline comment as done.
krisb added a comment.

Applied the comment & silence clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

Index: clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+void foo() {
+  static int bar = 1;
+  {
+struct X {};
+typedef char Y;
+static int bar = 0;
+// The following basic block is intended, in order to check the case where
+// types "X", "Y" are defined in a different scope than where they are used.
+// They should have the scope they are defined at as their parent scope.
+{
+  X a;
+  Y b;
+}
+  }
+}
+
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "foo"
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBSCOPE:![0-9]+]]
+// CHECK: [[LBSCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "a", scope: [[LBSCOPE2:![0-9]+]], {{.*}} type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE2]] = distinct !DILexicalBlock(scope: [[LBSCOPE]]
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "b", scope: [[LBSCOPE2]], {{.*}} type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBSCOPE]]
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -103,17 +103,21 @@
 llvm_unreachable("Declaration should not be in declstmts!");
   case Decl::Record:// struct/union/class X;
   case Decl::CXXRecord: // struct/union/class X; [C++]
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getRecordType(cast()));
+}
 return;
   case Decl::Enum:  // enum X;
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getEnumType(cast()));
+}
 return;
-  case Decl::Function: // void X();
   case Decl::EnumConstant: // enum ? { X = ? }
+  case Decl::Function: // void X();
   case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
   case Decl::Label:// __label__ x;
   case Decl::Import:
@@ -132,11 +136,11 @@
 
   case Decl::NamespaceAlias:
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitNamespaceAlias(cast(D));
+  DI->EmitNamespaceAlias(cast(D));
 return;
   case Decl::Using:  // using X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitUsingDecl(cast(D));
+  DI->EmitUsingDecl(cast(D));
 return;
   case Decl::UsingEnum: // using enum X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
@@ -172,8 +176,10 @@
   case Decl::Typedef:  // typedef int X;
   case Decl::TypeAlias: {  // using X = int; [C++0x]
 QualType Ty = cast(D).getUnderlyingType();
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   DI->EmitAndRetainType(Ty);
+}
 if (Ty->isVariablyModifiedType())
   EmitVariablyModifiedType(Ty);
 return;
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -139,6 +139,11 @@
 
   /// Keep track of our current nested lexical block.
   std::vector> LexicalBlockStack;
+
+  /// Map of AST declaration to its lexical block scope.
+  llvm::DenseMap>
+  LexicalBlockMap;
+
   llvm::DenseMap RegionMap;
   /// Keep track of LexicalBlockStack counter at the beginning of a
   /// function. This is used to pop unbalanced regions at the end of a
@@ -543,6 +548,12 @@
   /// Emit an Objective-C interface type standalone debug info.
   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
 
+  /// Map AST declaration to its lexical block scope if available.
+  void recordDeclarationLexicalScope(const Decl );
+
+  /// Get lexical scope of AST declaration.
+  llvm::DIScope *getDeclarationLexicalScope(const Decl *D);
+
   

[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-11-15 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb abandoned this revision.
krisb added a comment.

Abandon in favor of https://reviews.llvm.org/D113741.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109703

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


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

2021-11-12 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: dblaikie, aprantl, probinson.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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, clangs 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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113743

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

Index: clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+void foo() {
+  static int bar = 1;
+  {
+struct X {};
+typedef char Y;
+static int bar = 0;
+// The following basic block is intended, in order to check the case where
+// types "X", "Y" are defined in a different scope than where they are used.
+// They should have the scope they are defined at as their parent scope.
+{
+  X a;
+  Y b;
+}
+  }
+}
+
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "foo"
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBSCOPE:![0-9]+]]
+// CHECK: [[LBSCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "a", scope: [[LBSCOPE2:![0-9]+]], {{.*}} type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE2]] = distinct !DILexicalBlock(scope: [[LBSCOPE]]
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "b", scope: [[LBSCOPE2]], {{.*}} type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBSCOPE]]
+
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -103,17 +103,21 @@
 llvm_unreachable("Declaration should not be in declstmts!");
   case Decl::Record:// struct/union/class X;
   case Decl::CXXRecord: // struct/union/class X; [C++]
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getRecordType(cast()));
+}
 return;
   case Decl::Enum:  // enum X;
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getEnumType(cast()));
+}
 return;
-  case Decl::Function: // void X();
   case Decl::EnumConstant: // enum ? { X = ? }
+  case Decl::Function: // void X();
   case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
   case Decl::Label:// __label__ x;
   case Decl::Import:
@@ -132,11 +136,11 @@
 
   case Decl::NamespaceAlias:
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitNamespaceAlias(cast(D));
+  DI->EmitNamespaceAlias(cast(D));
 return;
   case Decl::Using:  // using X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitUsingDecl(cast(D));
+  DI->EmitUsingDecl(cast(D));
 return;
   case Decl::UsingEnum: // using enum X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
@@ -172,8 +176,10 @@
   case Decl::Typedef:  // typedef int X;
   case Decl::TypeAlias: {  // using X = int; [C++0x]
 QualType Ty = cast(D).getUnderlyingType();
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   DI->EmitAndRetainType(Ty);
+}
 if (Ty->isVariablyModifiedType())
   EmitVariablyModifiedType(Ty);
 return;

[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@ellis I'd appreciate if you go ahead and fix the issues with inlined 
functions. Sorry for interrupting you in D108492 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109703

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


[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@dblaikie yeah, the problem(s) seemed easier and smaller :(

Basically, we have two issues with local scopes here:
(1) function-scoped entities like static variables, type definitions/typedefs, 
etc have incorrect (empty) parent DIE if the function containing them was 
inlined. We do not consider abstract SP as a possible parent DIE and try to 
create a new DIE for a function that doesn't exist. @ellis is working on this 
issue in [0] (for static vars) and [1] (for imported declarations).
(2) the same entities (static local vars, typedefs, etc) that should be scoped 
within a lexical block have a subprogram scope (in debug metadata) and parent 
DIE (in DWARF) instead. This is the issue I'm trying to fix in this patch, but 
for static variables only.

As a side effect, this patch fixes the issue with inlined functions for static 
vars (1) as well. But it seems the issues are not related and can be fixed 
separately.
And as now I've realized that static locals is not the only problem, this patch 
should implement a more generic solution to cover other entities. So, please, 
consider it as a WIP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109703

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


[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

In D109703#2998155 , @ellis wrote:

> I've added this to the added test case.
>
>   !18 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, 
> entity: !19, line: 122)
>   !19 = !DIGlobalVariable(name: "imported_static_var", scope: !6, file: !5, 
> line: 3, type: !10, isLocal: false, isDefinition: true)

Thank you for pointing to this! Just in case, do you have a C++ example, that 
reproduces the issue with imported static local declaration? I'm asking, cause 
in your example `DW_TAG_imported_declaration` has CU as a scope, while 
`DIGlobalVariable` is function-scoped. This looks a bit strange. I mean, 
`constructImportedEntityDIE()` called from `DwarfDebug::beginModule()` skips 
all local-scoped entities, and unless I'm missing something static locals 
shouldn't go here. Another call for  `constructImportedEntityDIE()` is from 
`DwarfCompileUnit::createScopeChildrenDIE` where I'd not expect any issue with 
parents.

But it seems imported declarations are broken not just for static locals, but 
for all inlined entities, for example

  namespace ns {
  inline __attribute__((always_inline))
  int foo() {
int a = 42; 
return a;
  }
  }
  
  int main() {
using ns::foo;
return foo();
  }

produces (with or w/o this patch) imported declaration for `foo()` that refers 
to an empty subprogram:

  x002a:   DW_TAG_namespace
  DW_AT_name  ("ns")
  
  0x002f: DW_TAG_subprogram
DW_AT_name  ("foo")
DW_AT_inline  (DW_INL_inlined)
  
  0x003f:   DW_TAG_variable
  DW_AT_name  ("a")
  
  0x004a:   NULL
  
  0x004b: DW_TAG_subprogram
  
  0x004c: NULL
  
  0x0054:   DW_TAG_subprogram
  DW_AT_name  ("main")
  
  0x006d: DW_TAG_imported_declaration
DW_AT_import  (0x004b)

while it should point to `0x002f`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109703

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


[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-13 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: dblaikie, probinson.
Herald added a subscriber: hiraditya.
krisb requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This fixes https://bugs.llvm.org/show_bug.cgi?id=44695 (and likely
https://bugs.llvm.org/show_bug.cgi?id=30637).

On clang side we need to place static locals defined within a bracketed
block into a correct scope. Since getContextDescriptor() does no access lexical
blocks, just pick the innermost lexical scope early.

On llvm side the patch proposes to delay emission of static locals until their
parent scopes are created (just like normal local variables).
In case of inlined function, static locals are created only for abstract
entities (as per suggestions from https://bugs.llvm.org/show_bug.cgi?id=30637).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109703

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-static.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/Generic/static-locals.ll
  llvm/test/DebugInfo/X86/gnu-public-names.ll

Index: llvm/test/DebugInfo/X86/gnu-public-names.ll
===
--- llvm/test/DebugInfo/X86/gnu-public-names.ll
+++ llvm/test/DebugInfo/X86/gnu-public-names.ll
@@ -137,19 +137,6 @@
 ; CHECK-NOT: {{DW_TAG|NULL}}
 ; CHECK: DW_AT_name {{.*}} "global_namespace_function"
 
-; CHECK: DW_TAG_subprogram
-; CHECK-NOT: {{DW_TAG|NULL}}
-; CHECK:   DW_AT_name {{.*}} "f3"
-; CHECK-NOT: {{DW_TAG|NULL}}
-; CHECK: [[F3_Z:.*]]:   DW_TAG_variable
-; CHECK-NOT: DW_TAG
-; CHECK: DW_AT_name {{.*}} "z"
-; CHECK-NOT: {{DW_TAG|NULL}}
-; CHECK: DW_AT_location
-; CHECK-NOT: {{DW_TAG|NULL}}
-; CHECK:   NULL
-; CHECK-NOT: {{DW_TAG|NULL}}
-
 ; CHECK: [[ANON:.*]]: DW_TAG_namespace
 ; CHECK-NOT:   DW_AT_name
 ; CHECK: [[ANON_I:.*]]: DW_TAG_variable
@@ -237,6 +224,19 @@
 ; CHECK: DW_AT_linkage_name
 ; CHECK-NOT: {{DW_TAG|NULL}}
 ; CHECK: DW_AT_name {{.*}} "global_function"
+; CHECK-NOT: {{DW_TAG|NULL}}
+
+; CHECK: DW_TAG_subprogram
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK:   DW_AT_name {{.*}} "f3"
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK: [[F3_Z:.*]]:   DW_TAG_variable
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_name {{.*}} "z"
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK: DW_AT_location
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK:   NULL
 
 ; CHECK-LABEL: .debug_gnu_pubnames contents:
 ; CHECK-NEXT: length = {{.*}}, version = 0x0002, unit_offset = 0x, unit_size = {{.*}}
@@ -250,8 +250,8 @@
 ; comes out naturally from LLVM's implementation, so I'm OK with it for now. If
 ; it's demonstrated that this is a major size concern or degrades debug info
 ; consumer behavior, feel free to change it.
-; CHECK-NEXT:  [[F3_Z]] STATIC VARIABLE "f3::z"
 ; CHECK-NEXT:  [[ANON]] EXTERNAL TYPE "(anonymous namespace)"
+; CHECK-NEXT:  [[F3_Z]] STATIC VARIABLE "f3::z"
 ; CHECK-NEXT:  [[OUTER_ANON]] EXTERNAL TYPE "outer::(anonymous namespace)"
 ; CHECK-NEXT:  [[ANON_INNER_B]] STATIC VARIABLE "(anonymous namespace)::inner::b"
 ; CHECK-NEXT:  [[OUTER]] EXTERNAL TYPE "outer"
Index: llvm/test/DebugInfo/Generic/static-locals.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/Generic/static-locals.ll
@@ -0,0 +1,204 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s \
+; RUN:   | llvm-dwarfdump -debug-info -  \
+; RUN:   | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s
+
+; Generated from:
+
+; static int global = 42;
+;
+; inline __attribute__((always_inline))
+; int inlined() {
+;   static int inlined_a = 1;
+;   if (global > 100) {
+; static int inlined_b = 2;
+; return inlined_b;
+;   }
+;   {
+; static int inlined_c = 3;
+; inlined_a = inlined_c;
+;   }
+;   return inlined_a;
+; }
+;
+; int foo() {
+;   static int a = 1;
+;   if (global < 100) {
+; static int b = 2;
+; return b;
+;   }
+;   {
+; static int c = 3;
+; a = c;
+;   }
+;   return a;
+; }
+;
+; int far() {
+;   return inlined();
+; }
+
+; CHECK: DW_TAG_compile_unit
+; CHECK: DW_TAG_variable
+; CHECK: DW_AT_name	("global")
+; CHECK: DW_TAG_base_type
+
+; foo().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_name	("foo")
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_name	("a")
+; CHECK:   DW_TAG_lexical_block
+; CHECK: DW_TAG_variable
+; CHECK:   DW_AT_name	("b")
+; CHECK: NULL
+; CHECK:   DW_TAG_lexical_block
+; CHECK: DW_TAG_variable
+; CHECK:   DW_AT_name	("c")
+; CHECK:   NULL
+; CHECK: NULL
+
+; inlined().
+; CHECK: DW_TAG_subprogram
+; CHECK:   DW_AT_name  ("inlined")
+; CHECK:   DW_AT_inline  (DW_INL_inlined)
+; CHECK:   DW_TAG_variable
+; CHECK: DW_AT_name	("inlined_a")
+; CHECK:   DW_TAG_lexical_block
+; CHECK: DW_TAG_variable
+; CHECK:   DW_AT_name	("inlined_b")
+; CHECK: NULL
+; 

[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-08-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb accepted this revision.
krisb added a comment.
This revision is now accepted and ready to land.

@aorlov, thank you! LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-05-03 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:3080
+// For instance this marked as unavailable:
+//class __attribute((unavailable)) UnavailableClass;`
+auto RemoveAccessCheckingDiagnostics = [, this]() {

aorlov wrote:
> krisb wrote:
> > Basically, if `__attribute((unavailable))` should trigger the error for any 
> > use of an unavailable class, we have it already broken.
> > For example, for this code clang-12 doesn't produce any diagnostics:
> > ```
> > class __attribute((unavailable)) X {
> >   template  class __attribute((unavailable)) Y {};
> > };
> > class __attribute((unavailable)) A { 
> > class __attribute((unavailable)) C {}; 
> > };
> > template <> class X::Y {};
> > ```
> > So, I don't see much sense in inventing something new to workaround only 
> > the cases that come with this patch. It's better to either fix it globally 
> > or leave it broken atm with the corresponding FIXME.
> Anyway, I tried to remove the access diagnostics only. Who knows which 
> diagnostics may be needed. Or you strongly prefer using 
> `SuppressAccessChecks` instead?
Basically, I'd prefer consistency. Having two different ways of doing (almost) 
the same things doesn't look good to me. But I'm not sure about 
`SuppressAccessChecks` as turns all kinds of diagnostics off. Did you consider 
a possibility to improve `SuppressAccessChecks` to disable only a particular 
(specified) type of diagnostics? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-04-28 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Thank you! It looks more consistent now.




Comment at: clang/lib/Parse/ParseDecl.cpp:3080
+// For instance this marked as unavailable:
+//class __attribute((unavailable)) UnavailableClass;`
+auto RemoveAccessCheckingDiagnostics = [, this]() {

Basically, if `__attribute((unavailable))` should trigger the error for any use 
of an unavailable class, we have it already broken.
For example, for this code clang-12 doesn't produce any diagnostics:
```
class __attribute((unavailable)) X {
  template  class __attribute((unavailable)) Y {};
};
class __attribute((unavailable)) A { 
class __attribute((unavailable)) C {}; 
};
template <> class X::Y {};
```
So, I don't see much sense in inventing something new to workaround only the 
cases that come with this patch. It's better to either fix it globally or leave 
it broken atm with the corresponding FIXME.



Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:54
+  template <> void func2>() {
+  } template <> void func3() {
+  }

Formatting seems broken here and below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-04-08 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Do we still need the following tests:

- clang/test/CXX/temp/temp.spec/temp.explicit/p11.cpp
- clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp

?




Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:105
+template  void func10(A::B, int x) {}
+template  void func11(A::C, A::D, int) {}
+template  void func12() {}

aorlov wrote:
> krisb wrote:
> > Before this patch clang diagnosed cases like 
> > 
> > ```
> > class A { class C {}; };
> > template  void func(A::C) {}
> > ```
> > Why is it no longer the case?
> > 
> Your example generates an error `error: 'C' is a private member of 'A'` on 
> latest clang.
> This patch is intended to implement a proposal [[ 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0692r1.html | 
> p0692r1]] and consider this example as valid.
> Did I understand your question correctly?
It doesn't seem the aforementioned example falls under any of the cases from 
P0692R1 unless I misinterpreted its wordings.
It's a primary template, right?
Consider also the following example for which clang issues the error in both 
cases (before and after the patch):
```
class A { class C {}; };
template  A::C func();
```
I'm also wondering about something like:
```
class A { class C {}; };
template  T func() {}
template <> A::C func();
```



Comment at: clang/test/CXX/temp/temp.spec/part.spec.cpp:3
+
+// C++20 [temp.class.spec] 17.6.5/10:
+//   The usual access checking rules do not apply to non-dependent names used

It seems this test checks more than just partial specialization cases.
Could you please align the comments with what the test actually tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-04-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:3001
 DS.getStorageClassSpec() == clang::DeclSpec::SCS_typedef &&
-!DS.hasTypeSpecifier() && GetLookAheadToken(1).is(tok::less))
+!DS.hasTypeSpecifier() && NextToken().is(tok::less))
   Tok.setKind(tok::identifier);

It seems to be a change unrelated to the patch.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:1414
 
   // C++03 [temp.explicit] 14.7.2/8:
   //   The usual access checking rules do not apply to names used to specify

The comment needs to be updated.



Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:95
+// expected-error@+1 {{is a protected member of}}
+template  class A::B func4() { A::B x; } template 
 void func5() {
+  // expected-error@+2 {{is a private member of}}

Formatting issue here.



Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:105
+template  void func10(A::B, int x) {}
+template  void func11(A::C, A::D, int) {}
+template  void func12() {}

Before this patch clang diagnosed cases like 

```
class A { class C {}; };
template  void func(A::C) {}
```
Why is it no longer the case?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


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

2020-09-07 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG04ea680a8ccc: [cmake] Fix build of attribute plugin example 
on Windows (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86091

Files:
  clang/examples/Attribute/CMakeLists.txt


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ 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


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ 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


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

2020-08-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added a reviewer: john.brawn.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
krisb requested review of this revision.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86091

Files:
  clang/examples/Attribute/CMakeLists.txt


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ 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


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ 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


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

2020-07-28 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad4ab81dccaa: [clang][cmake] Force CMAKE_LINKER for 
multistage build in case of… (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873

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


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   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 )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -753,6 +753,14 @@
 -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


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   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 )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -753,6 +753,14 @@
 -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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-07-27 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked an inline comment as done.
krisb added a comment.

@phosek thank you for reviewing this!




Comment at: clang/CMakeLists.txt:751
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME)
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)

phosek wrote:
> krisb wrote:
> > phosek wrote:
> > > I don't understand the second part of this condition, can you elaborate? 
> > > Why not set `CMAKE_LINKER` to `lld-link.exe` even if 
> > > `BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows"`?
> > The only reason that stopped me from adding `BOOTSTRAP_CMAKE_SYSTEM_NAME 
> > STREQUAL "Windows"` case here is that there is no way to keep it working in 
> > the future (or, at least, I don't know one). Moreover, the build which sets 
> > BOOTSTRAP_CMAKE_SYSTEM_NAME equal to "Windows" is currently broken.
> > Since the same issue is exposed if to build LLVM with 
> > `clang/cmake/caches/DistributionExample.cmake` on Windows, I included only 
> > the changes that contribute to making this configuration buildable. I 
> > wanted to avoid making the impression that some other configurations are 
> > supported (because they are not) and also avoid adding any dead code that 
> > nobody would use and that would easily be broken.
> > 
> I'd prefer to use `WIN32 OR BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows"` 
> here even if we don't support cross-compilation to Windows now as I hope it's 
> something we're going to support in the future and this will be one less 
> thing we need to address. Alternatively, please at least leave a `TODO` so 
> it's easier to find later. 
Okay, I made the condition to be `(WIN32 AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) 
OR BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows"` to avoid setting 
`CMAKE_LINKER` in case of cross-compiling with Windows host and non-Windows 
target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873



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


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

2020-07-27 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 280835.
krisb added a comment.

Addressed the review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873

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


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   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 )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -757,6 +757,14 @@
 -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


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   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 )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -757,6 +757,14 @@
 -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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-07-21 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873



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


[PATCH] D81676: [MSP430] Align the toolchain definition with the TI's msp430-gcc v9.2.0

2020-07-14 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb accepted this revision.
krisb added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: dang.

Sorry for the delays in response, busy days.
LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81676



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


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

2020-07-14 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked an inline comment as done.
krisb added inline comments.



Comment at: clang/CMakeLists.txt:751
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME)
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)

phosek wrote:
> I don't understand the second part of this condition, can you elaborate? Why 
> not set `CMAKE_LINKER` to `lld-link.exe` even if `BOOTSTRAP_CMAKE_SYSTEM_NAME 
> STREQUAL "Windows"`?
The only reason that stopped me from adding `BOOTSTRAP_CMAKE_SYSTEM_NAME 
STREQUAL "Windows"` case here is that there is no way to keep it working in the 
future (or, at least, I don't know one). Moreover, the build which sets 
BOOTSTRAP_CMAKE_SYSTEM_NAME equal to "Windows" is currently broken.
Since the same issue is exposed if to build LLVM with 
`clang/cmake/caches/DistributionExample.cmake` on Windows, I included only the 
changes that contribute to making this configuration buildable. I wanted to 
avoid making the impression that some other configurations are supported 
(because they are not) and also avoid adding any dead code that nobody would 
use and that would easily be broken.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873



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


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

2020-07-14 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 277806.
krisb edited the summary of this revision.
krisb added a comment.

Changed MSVC -> WIN32 check and simplified the warning fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873

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


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   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 )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -745,6 +745,14 @@
 -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)
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG 
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -261,7 +261,12 @@
   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 )
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -745,6 +745,14 @@
 -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)
+  set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81676: [MSP430] Align the toolchain definition with the TI's msp430-gcc v9.2.0

2020-07-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Thank you!
LGTM, except some minor nits below.




Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:154
 
+  SmallString<128> MultilibInclude(GCCInstallation.getInstallPath());
+  llvm::sys::path::append(MultilibInclude, "include");

I'd guard this by `if (GCCInstallation.isValid())` to avoid adding include 
directories with relative paths if `GCCInstallation.getInstallPath()` is empty.



Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:239
+  Arg *SspFlag = Args.getLastArg(
+  options::OPT_fno_stack_protector, options::OPT_fstack_protector,
+  options::OPT_fstack_protector_all, options::OPT_fstack_protector_strong);

Is the check for `fno-stack-protector` necessary here? Looks as the checks for 
'positive' options should be enough to do the trick.



Comment at: clang/test/Driver/msp430-toolchain.c:5
+
+// Test for include paths (cannot use -###)
+

This way looks okay to me, but I believe you should be able to check cc1 
command (though -###) for `-internal-isystem`, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81676



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


[PATCH] D81676: [MSP430] Align the toolchain definition with the TI's msp430-gcc v8.3.1

2020-06-22 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:155
   SmallString<128> Dir(computeSysRoot());
   llvm::sys::path::append(Dir, "include");
   addSystemInclude(DriverArgs, CC1Args, Dir.str());

Seems the driver stops adding `msp430-elf/include` to the default include 
search paths, instead it adds `$sysroot/include` (or `$gcc-toolchain/include`). 
As I can see the latter isn't among the default include paths used by TI gcc. 
So, shouldn't we change here to `llvm::sys::path::append(Dir, "msp430-elf", 
"include");` as well?



Comment at: clang/lib/Driver/ToolChains/MSP430.cpp:239
+ArgStringList ) {
+  if (!Args.hasArg(options::OPT_T)) {
+if (Args.hasArg(options::OPT_msim)) {

What about an early exit here?



Comment at: clang/test/Driver/msp430-toolchain.c:12
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" 2>&1 
\
-// RUN:   | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "msp430"
+// RUN:   | FileCheck -check-prefix=DEFAULT-NEG %s
+// DEFAULT-POS: clang{{.*}} "-cc1" "-triple" "msp430"

How about using a single run line with just 
`--check-prefixes=DEFAULT-POS,DEFAULT-NEG`?



Comment at: clang/test/Driver/msp430-toolchain.c:37
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" \
+// RUN:   -o /tmp/test.elf -r -t -z muldefs -mrelax 2>&1 | FileCheck 
-check-prefix=MISC-FLAGS-1-NEG %s
+// MISC-FLAGS-1-POS: "{{.*}}msp430-elf-ld"

Same here about `--check-prefixes`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81676



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


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

2020-06-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873



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


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

2020-05-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: phosek, thakis, russell.gallop.
Herald added subscribers: llvm-commits, cfe-commits, mgorny.
Herald added projects: clang, LLVM.

(I'm trying to get a bootstrap self-build on Windows, where lld is used as a
linker for the stage2.)

I assume BOOTSTRAP_LLVM_ENABLE_LLD works the same way as LLVM_ENABLE_LLD,
but enables to use just-built lld for the next stage.

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 cmake invokes a linker directly and requires CMAKE_LINKER
option to be specified otherwise it defaults CMAKE_LINKER to be link.exe.
Passing CMAKE_LINKER is easy for 1-stage builds, but it's notquite handy
to do for multistage builds, because it's not possible to know for sure
where to find just-built lld.

This patch allows BOOTSTRAP_LLVM_ENABLE_LLD to set CMAKE_LINKER in the case
of building for host Windows. It also skips adding '-fuse-ld=lld' to make
lld-link not warning about 'unknown argument'. The latter part is taken
from https://reviews.llvm.org/D69030 with additional checks that
CMAKE_LINKER doesn't contain a path to another compiler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80873

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


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -264,7 +264,15 @@
   set(LLVM_USE_LINKER "lld")
 endif()
 
-if( LLVM_USE_LINKER )
+# cmake defaults to invoke a linker directly on Windows, so skip adding
+# '-fuse-ld' flag in this case.
+if( LINKER_IS_LLD_LINK AND ( NOT CMAKE_LINKER OR CMAKE_LINKER MATCHES 
"lld-link" ))
+  set(IS_FUSE_LD_FLAG_NEEDED FALSE)
+else()
+  set(IS_FUSE_LD_FLAG_NEEDED TRUE)
+endif()
+
+if( LLVM_USE_LINKER AND IS_FUSE_LD_FLAG_NEEDED )
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} 
-fuse-ld=${LLVM_USE_LINKER}")
   check_cxx_source_compiles("int main() { return 0; }" 
CXX_SUPPORTS_CUSTOM_LINKER)
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -745,6 +745,14 @@
 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
 -DCMAKE_ASM_COMPILER_ID=Clang)
 
+  # cmake requires CMAKE_LINKER to be specified in case of MSVC or it defaults
+  # the linker to be link.exe.
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME)
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG 
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -264,7 +264,15 @@
   set(LLVM_USE_LINKER "lld")
 endif()
 
-if( LLVM_USE_LINKER )
+# cmake defaults to invoke a linker directly on Windows, so skip adding
+# '-fuse-ld' flag in this case.
+if( LINKER_IS_LLD_LINK AND ( NOT CMAKE_LINKER OR CMAKE_LINKER MATCHES "lld-link" ))
+  set(IS_FUSE_LD_FLAG_NEEDED FALSE)
+else()
+  set(IS_FUSE_LD_FLAG_NEEDED TRUE)
+endif()
+
+if( LLVM_USE_LINKER AND IS_FUSE_LD_FLAG_NEEDED )
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}")
   check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER)
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -745,6 +745,14 @@
 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
 -DCMAKE_ASM_COMPILER_ID=Clang)
 
+  # cmake requires CMAKE_LINKER to be specified in case of MSVC or it defaults
+  # the linker to be link.exe.
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME)
+  set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)
+endif()
+  endif()
+
   if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
 set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
 set(${CLANG_STAGE}_TABLEGEN
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-09-11 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@dnsampaio, many thanks for committing this!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66018



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-09-11 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 219670.
krisb added a comment.

Rebased


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c

Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,8 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" "+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -45,14 +46,36 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes -mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
+//
+// Check +crypto for M and R profiles:
+//
+// RUN: %clang -target arm-arm-none-eabi -march=armv8-r+crypto   -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8-m.base+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8-m.main+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-m23+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// CHECK-NOCRYPTO5: warning: ignoring extension 'crypto' because the {{.*}} architecture does not support it
+// CHECK-NOCRYPTO5-NOT: "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -477,23 +477,26 @@
   Features.push_back("-crc");
   }
 
-  // For Arch >= ARMv8.0:  crypto = sha2 + aes
+  // For Arch >= 

[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-09-02 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 218388.
krisb marked an inline comment as done.
krisb added a comment.

Applied the comment: enable 'sha2' and 'aes' only for armv8 A profile, report 
warning and disable 'crypto' for other archs. Add more tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c

Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,8 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" "+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -45,14 +46,36 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+nocrypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes -mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
+//
+// Check +crypto for M and R profiles:
+//
+// RUN: %clang -target arm-arm-none-eabi -march=armv8-r+crypto   -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8-m.base+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8-m.main+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-m23+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
+// CHECK-NOCRYPTO5: warning: ignoring extension 'crypto' because the {{.*}} architecture does not support it
+// CHECK-NOCRYPTO5-NOT: "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- 

[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

I see. But this doesn't seem like a valid case, does it? Shouldn't we somehow 
diagnose it to not to silently ignore user-specified options?


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked an inline comment as done.
krisb added a comment.

@dnsampaio thanks for reviewing this! Could I ask you to commit the patch 
(since I don't have commit access yet)?


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-30 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 218076.
krisb edited the summary of this revision.
krisb added a comment.

Added 'CPU.empty()' check back.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c


Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,8 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -45,14 +46,27 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" 
"-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -479,21 +479,20 @@
 
   // For Arch >= ARMv8.0:  crypto = sha2 + aes
   // FIXME: this needs reimplementation after the TargetParser rewrite
-  if (ArchName.find_lower("armv8a") != StringRef::npos ||
-  ArchName.find_lower("armv8.1a") != StringRef::npos ||
-  ArchName.find_lower("armv8.2a") != StringRef::npos ||
-  ArchName.find_lower("armv8.3a") != StringRef::npos ||
-  ArchName.find_lower("armv8.4a") != StringRef::npos) {
-if (ArchName.find_lower("+crypto") != StringRef::npos) {
-  if (ArchName.find_lower("+nosha2") == StringRef::npos)
+  StringRef ArchSuffix = arm::getLLVMArchSuffixForARM(
+  arm::getARMTargetCPU(CPUName, ArchName, Triple), ArchName, Triple);
+
+  if (llvm::ARM::parseArchVersion(ArchSuffix) >= 8) {
+auto CryptoIt =
+llvm::find_if(llvm::reverse(Features),
+  [](const 

[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-29 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked 2 inline comments as done.
krisb added a comment.

@dnsampaio, thanks! This is definitely better. I also added ARMV8_5A as a test 
case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-29 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 217819.
krisb added a comment.

Applied the comment & rebased.
Also changed the patch to take into account only the latest 'crypto' in the 
Features vector, to avoid enabling 'sha2' and 'aes' when 'crypto' was finally 
disabled.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c


Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,8 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -45,14 +46,27 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" 
"-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -479,21 +479,20 @@
 
   // For Arch >= ARMv8.0:  crypto = sha2 + aes
   // FIXME: this needs reimplementation after the TargetParser rewrite
-  if (ArchName.find_lower("armv8a") != StringRef::npos ||
-  ArchName.find_lower("armv8.1a") != StringRef::npos ||
-  ArchName.find_lower("armv8.2a") != StringRef::npos ||
-  ArchName.find_lower("armv8.3a") != StringRef::npos ||
-  ArchName.find_lower("armv8.4a") != StringRef::npos) {
-if (ArchName.find_lower("+crypto") != StringRef::npos) {
-  if (ArchName.find_lower("+nosha2") == StringRef::npos)
+  StringRef ArchSuffix = arm::getLLVMArchSuffixForARM(
+  arm::getARMTargetCPU(CPUName, ArchName, Triple), ArchName, Triple);
+
+  if 

[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-15 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@dnsampaio, thanks, this looks better.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-15 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 215394.
krisb added a comment.

Applied the comment.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c


Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,7 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -47,12 +47,24 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" 
"-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -479,21 +479,22 @@
 
   // For Arch >= ARMv8.0:  crypto = sha2 + aes
   // FIXME: this needs reimplementation after the TargetParser rewrite
-  if (ArchName.find_lower("armv8a") != StringRef::npos ||
-  ArchName.find_lower("armv8.1a") != StringRef::npos ||
-  ArchName.find_lower("armv8.2a") != StringRef::npos ||
-  ArchName.find_lower("armv8.3a") != StringRef::npos ||
-  ArchName.find_lower("armv8.4a") != StringRef::npos) {
-if (ArchName.find_lower("+crypto") != StringRef::npos) {
-  if (ArchName.find_lower("+nosha2") == StringRef::npos)
+  llvm::ARM::ArchKind ArchKind = arm::getLLVMArchKindForARM(
+  arm::getARMTargetCPU(CPUName, ArchName, Triple),
+  arm::getARMArch(ArchName, Triple), Triple);
+
+  if (ArchKind == llvm::ARM::ArchKind::ARMV8A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_1A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_2A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_3A ||
+  ArchKind == llvm::ARM::ArchKind::ARMV8_4A) {
+if (find(Features, "+crypto") != Features.end()) {
+  if (ArchName.find_lower("+nosha2") == StringRef::npos &&
+  CPUName.find_lower("+nosha2") == StringRef::npos)
 Features.push_back("+sha2");
-  if (ArchName.find_lower("+noaes") == StringRef::npos)
+  if (ArchName.find_lower("+noaes") == StringRef::npos &&
+  CPUName.find_lower("+noaes") == StringRef::npos)
 

[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-09 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.
krisb added reviewers: SjoerdMeijer, ostannard, labrinea, dnsampaio.

'+crypto' means '+aes' and '+sha2' for arch >= ARMv8 when
they were not disabled explicitly.
Currenlty, this situation is correclty handled only in case of '-march'
option, but the feature may also be specified though '-mcpu' and '-mfpu':

  $ clang -mcpu=cortex-a57 -mfpu=crypto-neon-fp-armv8

becomes

  $ clang -cc1 -triple armv8--- -target-cpu cortex-a57
  -target-feature -sha2 -target-feature -aes -target-feature +crypto

which is quite unexpected.
This exposed by https://reviews.llvm.org/D63936 that makes 'aes' and
'sha2' features disabled by default.

So, while handling 'crypto' feature we need to take into accout:

- a cpu name, as it provides the information about architecture (if no

'-march' options specified),

- features, specified by '-mcpu' and '-mfpu'.


Repository:
  rC Clang

https://reviews.llvm.org/D66018

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c


Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,7 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -47,12 +47,24 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" 
"-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -479,21 +479,24 @@
 
   // For Arch >= ARMv8.0:  crypto = sha2 + aes
   // FIXME: this needs reimplementation after the TargetParser rewrite
-  if (ArchName.find_lower("armv8a") != StringRef::npos ||
-  ArchName.find_lower("armv8.1a") != StringRef::npos ||
-  ArchName.find_lower("armv8.2a") != StringRef::npos ||
-  ArchName.find_lower("armv8.3a") != StringRef::npos ||
-  ArchName.find_lower("armv8.4a") != StringRef::npos) {
-if (ArchName.find_lower("+crypto") != StringRef::npos) {
-  if (ArchName.find_lower("+nosha2") == StringRef::npos)
+  llvm::ARM::ArchKind ArchKind =
+  

[PATCH] D56925: Do not use frame pointer by default for MSP430

2019-01-25 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added inline comments.



Comment at: test/CodeGen/msp430-fp-elim.c:16
+{
+   asm volatile ("calla r4");
+}

This test as it is will fail after integrated assembler will be turned on by 
default (see https://reviews.llvm.org/D56787).  Since `calla` instruction isn't 
supported yet, the assembler will report an error of 'invalid instruction 
mnemonic'.
So, please, choose another instruction from ones that are already supported. Or 
turn -integrated-as off.


Repository:
  rC Clang

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

https://reviews.llvm.org/D56925



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


[PATCH] D57012: Merge similar target diagnostics for interrupt attribute into one. NFC

2019-01-23 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@aaron.ballman yes and yes. Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D57012



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


[PATCH] D57012: Merge similar target diagnostics for interrupt attribute into one. NFC

2019-01-22 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@aaron.ballman Thanks! Could I ask you to commit the patch? I don't have commit 
access yet.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57012



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


[PATCH] D57012: Merge similar target diagnostics for interrupt attribute into one. NFC

2019-01-22 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 182852.
krisb added a comment.

Applied the comment.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57012

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5541,14 +5541,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 1;
 return;
   }
 
@@ -5616,14 +5616,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MIPS*/ 0 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MIPS*/ 0 << 1;
 return;
   }
 
@@ -5770,12 +5770,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_riscv_interrupt_attribute) << 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+  << /*RISC-V*/ 2 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_riscv_interrupt_attribute) << 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+  << /*RISC-V*/ 2 << 1;
 return;
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -261,22 +261,14 @@
 def warn_arm_interrupt_calling_convention : Warning<
"call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
InGroup;
-def warn_mips_interrupt_attribute : Warning<
-   "MIPS 'interrupt' attribute only applies to functions that have "
-   "%select{no parameters|a 'void' return type}0">,
+def warn_interrupt_attribute_invalid : Warning<
+   "%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to "
+   "functions that have %select{no parameters|a 'void' return type}1">,
InGroup;
 def warn_riscv_repeated_interrupt_attribute : Warning<
   "repeated RISC-V 'interrupt' attribute">, InGroup;
 def note_riscv_repeated_interrupt_attribute : Note<
   "repeated RISC-V 'interrupt' attribute is here">;
-def warn_riscv_interrupt_attribute : Warning<
-   "RISC-V 'interrupt' attribute only applies to functions that have "
-   "%select{no parameters|a 'void' return type}0">,
-   InGroup;
-def warn_msp430_interrupt_attribute : Warning<
-   "MSP430 'interrupt' attribute only applies to functions that have "
-   "%select{no parameters|a 'void' return type}0">,
-   InGroup;
 def warn_unused_parameter : Warning<"unused parameter %0">,
   InGroup, DefaultIgnore;
 def warn_unused_variable : Warning<"unused variable %0">,


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5541,14 +5541,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 1;
 return;
   }
 
@@ -5616,14 +5616,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MIPS*/ 0 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MIPS*/ 0 << 1;
 return;
   }
 
@@ -5770,12 +5770,14 @@
   }
 
   if (hasFunctionProto(D) && 

[PATCH] D57015: [MSP430] Ajust f32/f64 alignment according to MSP430 EABI

2019-01-21 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added a reviewer: asl.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D57015

Files:
  lib/Basic/Targets/MSP430.h
  test/CodeGen/msp430-align.c
  test/Preprocessor/init.c


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -5158,7 +5158,7 @@
 // MSP430:#define __SIZE_MAX__ 65535U
 // MSP430:#define __SIZE_TYPE__ unsigned int
 // MSP430:#define __SIZE_WIDTH__ 16
-// MSP430-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
+// MSP430-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 2U
 // MSP430:#define __UINT16_C_SUFFIX__ U
 // MSP430:#define __UINT16_MAX__ 65535U
 // MSP430:#define __UINT16_TYPE__ unsigned short
Index: test/CodeGen/msp430-align.c
===
--- /dev/null
+++ test/CodeGen/msp430-align.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple msp430-elf -emit-llvm %s -o - | FileCheck %s
+
+// MSP430 target prefers chars to be aligned to 8 bit and other types to 16 
bit.
+
+// CHECK: @c ={{.*}}global i8 1, align 1
+// CHECK: @s ={{.*}}global i16 266, align 2
+// CHECK: @i ={{.*}}global i16 266, align 2
+// CHECK: @l ={{.*}}global i32 16909060, align 2
+// CHECK: @ll ={{.*}}global i64 283686952306183, align 2
+// CHECK: @f ={{.*}}global float 1.00e+00, align 2
+// CHECK: @d ={{.*}}global double 1.00e+00, align 2
+// CHECK: @ld ={{.*}}global double 1.00e+00, align 2
+// CHECK: @p ={{.*}}global i8* @c, align 2
+
+char c = 1;
+short s = 266;
+int i = 266;
+long l = 16909060;
+long long ll = 283686952306183;
+float f = 1.0f;
+double d = 1.0;
+long double ld = 1.0;
+char *p = 
Index: lib/Basic/Targets/MSP430.h
===
--- lib/Basic/Targets/MSP430.h
+++ lib/Basic/Targets/MSP430.h
@@ -33,6 +33,10 @@
 LongWidth = 32;
 LongLongWidth = 64;
 LongAlign = LongLongAlign = 16;
+FloatWidth = 32;
+FloatAlign = 16;
+DoubleWidth = LongDoubleWidth = 64;
+DoubleAlign = LongDoubleAlign = 16;
 PointerWidth = 16;
 PointerAlign = 16;
 SuitableAlign = 16;
@@ -51,6 +55,8 @@
 return None;
   }
 
+  bool allowsLargerPreferedTypeAlignment() const override { return false; }
+
   bool hasFeature(StringRef Feature) const override {
 return Feature == "msp430";
   }


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -5158,7 +5158,7 @@
 // MSP430:#define __SIZE_MAX__ 65535U
 // MSP430:#define __SIZE_TYPE__ unsigned int
 // MSP430:#define __SIZE_WIDTH__ 16
-// MSP430-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
+// MSP430-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 2U
 // MSP430:#define __UINT16_C_SUFFIX__ U
 // MSP430:#define __UINT16_MAX__ 65535U
 // MSP430:#define __UINT16_TYPE__ unsigned short
Index: test/CodeGen/msp430-align.c
===
--- /dev/null
+++ test/CodeGen/msp430-align.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple msp430-elf -emit-llvm %s -o - | FileCheck %s
+
+// MSP430 target prefers chars to be aligned to 8 bit and other types to 16 bit.
+
+// CHECK: @c ={{.*}}global i8 1, align 1
+// CHECK: @s ={{.*}}global i16 266, align 2
+// CHECK: @i ={{.*}}global i16 266, align 2
+// CHECK: @l ={{.*}}global i32 16909060, align 2
+// CHECK: @ll ={{.*}}global i64 283686952306183, align 2
+// CHECK: @f ={{.*}}global float 1.00e+00, align 2
+// CHECK: @d ={{.*}}global double 1.00e+00, align 2
+// CHECK: @ld ={{.*}}global double 1.00e+00, align 2
+// CHECK: @p ={{.*}}global i8* @c, align 2
+
+char c = 1;
+short s = 266;
+int i = 266;
+long l = 16909060;
+long long ll = 283686952306183;
+float f = 1.0f;
+double d = 1.0;
+long double ld = 1.0;
+char *p = 
Index: lib/Basic/Targets/MSP430.h
===
--- lib/Basic/Targets/MSP430.h
+++ lib/Basic/Targets/MSP430.h
@@ -33,6 +33,10 @@
 LongWidth = 32;
 LongLongWidth = 64;
 LongAlign = LongLongAlign = 16;
+FloatWidth = 32;
+FloatAlign = 16;
+DoubleWidth = LongDoubleWidth = 64;
+DoubleAlign = LongDoubleAlign = 16;
 PointerWidth = 16;
 PointerAlign = 16;
 SuitableAlign = 16;
@@ -51,6 +55,8 @@
 return None;
   }
 
+  bool allowsLargerPreferedTypeAlignment() const override { return false; }
+
   bool hasFeature(StringRef Feature) const override {
 return Feature == "msp430";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57012: Merge similar target diagnostics for interrupt attribute into one. NFC

2019-01-21 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: asl, aaron.ballman.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D57012

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5541,14 +5541,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 1;
 return;
   }
 
@@ -5616,14 +5616,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*Mips*/ 0 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*Mips*/ 0 << 1;
 return;
   }
 
@@ -5770,12 +5770,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_riscv_interrupt_attribute) << 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+  << /*RISC-V*/ 2 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_riscv_interrupt_attribute) << 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+  << /*RISC-V*/ 2 << 1;
 return;
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -261,22 +261,14 @@
 def warn_arm_interrupt_calling_convention : Warning<
"call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
InGroup;
-def warn_mips_interrupt_attribute : Warning<
-   "MIPS 'interrupt' attribute only applies to functions that have "
-   "%select{no parameters|a 'void' return type}0">,
+def warn_interrupt_attribute_invalid : Warning<
+   "%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to "
+   "functions that have %select{no parameters|a 'void' return type}1">,
InGroup;
 def warn_riscv_repeated_interrupt_attribute : Warning<
   "repeated RISC-V 'interrupt' attribute">, InGroup;
 def note_riscv_repeated_interrupt_attribute : Note<
   "repeated RISC-V 'interrupt' attribute is here">;
-def warn_riscv_interrupt_attribute : Warning<
-   "RISC-V 'interrupt' attribute only applies to functions that have "
-   "%select{no parameters|a 'void' return type}0">,
-   InGroup;
-def warn_msp430_interrupt_attribute : Warning<
-   "MSP430 'interrupt' attribute only applies to functions that have "
-   "%select{no parameters|a 'void' return type}0">,
-   InGroup;
 def warn_unused_parameter : Warning<"unused parameter %0">,
   InGroup, DefaultIgnore;
 def warn_unused_variable : Warning<"unused variable %0">,


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5541,14 +5541,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_msp430_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*MSP430*/ 1 << 1;
 return;
   }
 
@@ -5616,14 +5616,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 0;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*Mips*/ 0 << 0;
 return;
   }
 
   if (!getFunctionOrMethodResultType(D)->isVoidType()) {
-S.Diag(D->getLocation(), diag::warn_mips_interrupt_attribute)
-<< 1;
+S.Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+<< /*Mips*/ 0 << 1;
 return;
   }
 
@@ -5770,12 +5770,14 @@
   }
 
   if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
-

  1   2   >