[PATCH] D119351: Update all LLVM documentation mentioning runtimes in LLVM_ENABLE_PROJECTS

2022-02-09 Thread Rafael Auler via Phabricator via cfe-commits
rafauler added a comment.

BOLT modifications LGTM, thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119351

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


[PATCH] D58216: Support attribute used in member funcs of class templates II

2019-03-08 Thread Rafael Auler via Phabricator via cfe-commits
rafauler added a comment.

I definitely understand how the diagnostic can be confusing. However, it's the 
same diagnostic gcc provides too, so gcc users wouldn't be surprised. But 
you're right this can be improved by at least mentioning the attribute used in 
the diagnostic message. There's no bug report to this yet, it would be nice to 
file it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58216



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


[PATCH] D58216: Support attribute used in member funcs of class templates II

2019-03-06 Thread Rafael Auler via Phabricator via cfe-commits
rafauler added a comment.

I'm not an expert in swift either. I'll wait for @davezarzycki input on what's 
happening, but I suspect the code base is indeed incompatible with gcc due to 
the nature of the error they experienced.  This testcase is creduce-d from what 
I observed in swift.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58216



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


[PATCH] D58216: Support attribute used in member funcs of class templates II

2019-03-06 Thread Rafael Auler via Phabricator via cfe-commits
rafauler added a subscriber: davezarzycki.
rafauler added a comment.

Both approaches make sense to me. I'll re-land the previous patch in favor of 
gcc compatibility, since the semantics of attribute used in member functions of 
class templates were first implemented in gcc.

@davezarzycki  Heads up that this will land again. Can you change the code in 
swift to use the attribute used in the declaration of the specialization, not 
in the declaration of the template? (that is, if you really need the attribute, 
of course).


Repository:
  rC Clang

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

https://reviews.llvm.org/D58216



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


[PATCH] D58216: Support attribute used in member funcs of class templates II

2019-02-13 Thread Rafael Auler via Phabricator via cfe-commits
rafauler created this revision.
rafauler added reviewers: rsmith, ldionne, aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: clang.

As PR17480 describes, clang does not support the used attribute
for member functions of class templates. This means that if the member
function is not used, its definition is never instantiated. This patch
changes clang to emit the definition if it has the used attribute.

This is a second attempt after the revert of D56928 
. The original diff
broke the swift toolchain because its source contained the attribute
used in a member function that was later explictly specialized. A
check for C++14 [temp.expl.spec]p6 was mistakenly firing here: D56928 

set the point of instantiation of member functions with attribute used
at the same point of instantiation of its containing class template.
When a explicit specialization was done, Clang was complaining that a
explicit specialization cannot occur after the use recorded to be at
the instantiation of the class template. The problem is that the use
was not real, but induced by the attribute used.  To avoid running
into this check, I no longer pass a valid SourceLocation to
MarkFunctionReferenced. The goal is to cause the function to be
instantiated at the end of the TU, but without a valid point of
instantiation, making this use not interfere anymore with the check
for C++14 [temp.expl.spec]p6.

Test Plan: Kept the original testcase and added another one to cover the
swift runtime issue. Also tested this diff in the swift build and
verified it is working.


Repository:
  rC Clang

https://reviews.llvm.org/D58216

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
  test/SemaTemplate/attr-used-member-function-implicit-instantiation.cpp


Index: test/SemaTemplate/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/SemaTemplate/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Check that __attribute__((used)) in member functions of templated classes
+// does not break explicit specializations of those functions
+
+// expected-no-diagnostics
+template 
+struct a {
+  void verify() __attribute__((__used__));
+};
+using b = a;
+template<> void b::verify() {}
Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template 
+struct S {
+  int __attribute__((used)) f() {
+return 0;
+  }
+};
+
+void test() {
+  // Check that InstantiateUsedMemberDefinition::S::f() is defined
+  // as a result of the S class template implicit instantiation
+  // CHECK: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+  S inst;
+}
+} // namespace InstantiateUsedMemberDefinition
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,11 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr())
+SemaRef.MarkFunctionReferenced(SourceLocation(), Method);
+
   return Method;
 }
 


Index: test/SemaTemplate/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/SemaTemplate/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Check that __attribute__((used)) in member functions of templated classes
+// does not break explicit specializations of those functions
+
+// expected-no-diagnostics
+template 
+struct a {
+  void verify() __attribute__((__used__));
+};
+using b = a;
+template<> void b::verify() {}
Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template 
+struct S {
+  int __attribute__((used)) f() {
+return 0;
+  }
+};
+
+void test() {
+  // Check that InstantiateUsedMemberDe

[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-31 Thread Rafael Auler via Phabricator via cfe-commits
rafauler added a comment.

Hi davezarzycki, thanks for reporting this! This is not expected, I'll revert 
this diff for now. Sorry for this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D56928



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


[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-31 Thread Rafael Auler via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC352740: Support attribute used in member funcs of class 
templates (authored by rafauler, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D56928?vs=184467&id=184470#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D56928

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template 
+struct S {
+  int __attribute__((used)) f() {
+return 0;
+  }
+};
+
+void test() {
+  // Check that InstantiateUsedMemberDefinition::S::f() is defined
+  // as a result of the S class template implicit instantiation
+  // CHECK: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+  S inst;
+}
+} // namespace InstantiateUsedMemberDefinition
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,20 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (const auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (const MemberSpecializationInfo *MSInfo =
+  A->getMemberSpecializationInfo())
+Loc = MSInfo->getPointOfInstantiation();
+  else if (const auto *Spec = dyn_cast(A))
+Loc = Spec->getPointOfInstantiation();
+  SemaRef.MarkFunctionReferenced(Loc, Method);
+}
+  }
+
   return Method;
 }
 


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template 
+struct S {
+  int __attribute__((used)) f() {
+return 0;
+  }
+};
+
+void test() {
+  // Check that InstantiateUsedMemberDefinition::S::f() is defined
+  // as a result of the S class template implicit instantiation
+  // CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+  S inst;
+}
+} // namespace InstantiateUsedMemberDefinition
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,20 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (const auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (const MemberSpecializationInfo *MSInfo =
+  A->getMemberSpecializationInfo())
+Loc = MSInfo->getPointOfInstantiation();
+  else if (const auto *Spec = dyn_cast(A))
+Loc = Spec->getPointOfInstantiation();
+  SemaRef.MarkFunctionReferenced(Loc, Method);
+}
+  }
+
   return Method;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-31 Thread Rafael Auler via Phabricator via cfe-commits
rafauler updated this revision to Diff 184467.
rafauler added a comment.

Thanks for reviewing!


Repository:
  rC Clang

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

https://reviews.llvm.org/D56928

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template 
+struct S {
+  int __attribute__((used)) f() {
+return 0;
+  }
+};
+
+void test() {
+  // Check that InstantiateUsedMemberDefinition::S::f() is defined
+  // as a result of the S class template implicit instantiation
+  // CHECK: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+  S inst;
+}
+} // namespace InstantiateUsedMemberDefinition
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,20 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (const auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (const MemberSpecializationInfo *MSInfo =
+  A->getMemberSpecializationInfo())
+Loc = MSInfo->getPointOfInstantiation();
+  else if (const auto *Spec = dyn_cast(A))
+Loc = Spec->getPointOfInstantiation();
+  SemaRef.MarkFunctionReferenced(Loc, Method);
+}
+  }
+
   return Method;
 }
 


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template 
+struct S {
+  int __attribute__((used)) f() {
+return 0;
+  }
+};
+
+void test() {
+  // Check that InstantiateUsedMemberDefinition::S::f() is defined
+  // as a result of the S class template implicit instantiation
+  // CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+  S inst;
+}
+} // namespace InstantiateUsedMemberDefinition
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,20 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (const auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (const MemberSpecializationInfo *MSInfo =
+  A->getMemberSpecializationInfo())
+Loc = MSInfo->getPointOfInstantiation();
+  else if (const auto *Spec = dyn_cast(A))
+Loc = Spec->getPointOfInstantiation();
+  SemaRef.MarkFunctionReferenced(Loc, Method);
+}
+  }
+
   return Method;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-29 Thread Rafael Auler via Phabricator via cfe-commits
rafauler updated this revision to Diff 184029.
rafauler added a comment.

Rebase + Aaron's suggestions. Thanks for the suggestions!


Repository:
  rC Clang

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

https://reviews.llvm.org/D56928

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int __attribute__((used)) f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,22 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (const auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (const MemberSpecializationInfo *MSInfo =
+  A->getMemberSpecializationInfo()) {
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (const auto *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+  SemaRef.MarkFunctionReferenced(Loc, Method);
+}
+  }
+
   return Method;
 }
 


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int __attribute__((used)) f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2175,6 +2175,22 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (const auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (const MemberSpecializationInfo *MSInfo =
+  A->getMemberSpecializationInfo()) {
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (const auto *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+  SemaRef.MarkFunctionReferenced(Loc, Method);
+}
+  }
+
   return Method;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-25 Thread Rafael Auler via Phabricator via cfe-commits
rafauler updated this revision to Diff 183657.
rafauler added a comment.

No problem, thanks for your suggestions!


Repository:
  rC Clang

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

https://reviews.llvm.org/D56928

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,20 @@
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int __attribute__((used)) f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2176,6 +2176,22 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (MemberSpecializationInfo *MSInfo = A->getMemberSpecializationInfo()) 
{
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+
+  SemaRef.MarkFunctionReferenced(Loc, Method, /*MightBeOdrUse=*/true);
+}
+  }
+
   return Method;
 }
 


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,20 @@
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int __attribute__((used)) f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2176,6 +2176,22 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (MemberSpecializationInfo *MSInfo = A->getMemberSpecializationInfo()) {
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+
+  SemaRef.MarkFunctionReferenced(Loc, Method, /*MightBeOdrUse=*/true);
+}
+  }
+
   return Method;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-18 Thread Rafael Auler via Phabricator via cfe-commits
rafauler updated this revision to Diff 182581.
rafauler added a comment.

Removing facebook tags


Repository:
  rC Clang

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

https://reviews.llvm.org/D56928

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+#define USED __attribute__((used))
+
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int USED f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK-DAG: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2176,6 +2176,22 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (MemberSpecializationInfo *MSInfo = A->getMemberSpecializationInfo()) 
{
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+
+  SemaRef.MarkFunctionReferenced(Loc, Method, /*MightBeOdrUse=*/true);
+}
+  }
+
   return Method;
 }
 


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+#define USED __attribute__((used))
+
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int USED f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK-DAG: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2176,6 +2176,22 @@
 Owner->addDecl(Method);
   }
 
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (MemberSpecializationInfo *MSInfo = A->getMemberSpecializationInfo()) {
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+
+  SemaRef.MarkFunctionReferenced(Loc, Method, /*MightBeOdrUse=*/true);
+}
+  }
+
   return Method;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56928: Support attribute used in member funcs of class templates

2019-01-18 Thread Rafael Auler via Phabricator via cfe-commits
rafauler created this revision.
rafauler added reviewers: rsmith, ldionne.

As PR17480 describes, clang does not support the used attribute
for member functions of class templates. This means that if the member
function is not used, its definition is never instantiated. This patch
changes clang to emit the definition if it has the used attribute.

Test Plan: Added a testcase


Repository:
  rC Clang

https://reviews.llvm.org/D56928

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+#define USED __attribute__((used))
+
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int USED f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK-DAG: define linkonce_odr i32 
@_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2176,6 +2176,24 @@
 Owner->addDecl(Method);
   }
 
+  // facebook begin T10336705
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (MemberSpecializationInfo *MSInfo = A->getMemberSpecializationInfo()) 
{
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+
+  SemaRef.MarkFunctionReferenced(Loc, Method, /*MightBeOdrUse=*/true);
+}
+  }
+  // end facebook
+
   return Method;
 }
 


Index: test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
===
--- /dev/null
+++ test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s \
+// RUN:  | FileCheck %s
+
+#define USED __attribute__((used))
+
+namespace InstantiateUsedMemberDefinition {
+  template  struct S {
+int USED f() {
+  return 0;
+}
+  };
+
+  void test() {
+// Check that InstantiateUsedMemberDefinition::S::f() is defined
+// as a result of the S class template implicit instantiation
+// CHECK-DAG: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+S inst;
+  }
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2176,6 +2176,24 @@
 Owner->addDecl(Method);
   }
 
+  // facebook begin T10336705
+  // PR17480: Honor the used attribute to instantiate member function
+  // definitions
+  if (Method->hasAttr()) {
+if (auto *A = dyn_cast(Owner)) {
+  SourceLocation Loc;
+  if (MemberSpecializationInfo *MSInfo = A->getMemberSpecializationInfo()) {
+Loc = MSInfo->getPointOfInstantiation();
+  } else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(A)) {
+Loc = Spec->getPointOfInstantiation();
+  }
+
+  SemaRef.MarkFunctionReferenced(Loc, Method, /*MightBeOdrUse=*/true);
+}
+  }
+  // end facebook
+
   return Method;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits