[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-27 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 updated this revision to Diff 500715.
0xdc03 edited the summary of this revision.
0xdc03 added a comment.

- Update to address reviewer comments
- Add release note
- Redo notes to match reviewer comments
- Make the fix-it highlight the whole attribute
- Update tests to check new diagnostics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/alias.cpp
  clang/test/CodeGen/attr-ifunc.c
  clang/test/CodeGen/attr-ifunc.cpp
  clang/test/Sema/attr-alias-elf.c

Index: clang/test/Sema/attr-alias-elf.c
===
--- clang/test/Sema/attr-alias-elf.c
+++ clang/test/Sema/attr-alias-elf.c
@@ -5,9 +5,10 @@
 }
 
 void f2(void) __attribute__((alias("g2"))); // expected-error {{alias must point to a defined variable or function}}
-
+// expected-note@-1 {{must refer to the mangled name}}
 
 void f3(void) __attribute__((alias("g3"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to the mangled name}}
 void g3(void);
 
 
@@ -46,11 +47,14 @@
 int b1 = 42;
 
 extern int a2 __attribute__((alias("b2"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to the mangled name}}
 
 extern int a3 __attribute__((alias("b3"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to the mangled name}}
 extern int b3;
 
 extern int a4 __attribute__((alias("b4"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to the mangled name}}
 typedef int b4;
 
 void test2_bar() {}
Index: clang/test/CodeGen/attr-ifunc.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-ifunc.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+
+void *f1_ifunc(void) { return nullptr; }
+void f1(void) __attribute__((ifunc("f1_ifunc")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to the mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+
+void *f6_resolver_resolver(void) { return 0; }
+void *f6_resolver(void) __attribute__((ifunc("f6_resolver_resolver")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to the mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+void f6(void) __attribute__((ifunc("f6_resolver")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to the mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+
+__attribute__((unused, ifunc("resolver"), deprecated("hahahaha, isn't C great?")))
+void func();
+// expected-error@-2 {{ifunc must point to a defined function}}
+// expected-note@-3 {{must refer to the mangled name}}
+
Index: clang/test/CodeGen/attr-ifunc.c
===
--- clang/test/CodeGen/attr-ifunc.c
+++ clang/test/CodeGen/attr-ifunc.c
@@ -12,6 +12,7 @@
 void *f1_ifunc(void);
 void f1(void) __attribute__((ifunc("f1_ifunc")));
 // expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to the mangled name}}
 
 void *f2_a(void) __attribute__((alias("f2_b")));
 void *f2_b(void) __attribute__((ifunc("f2_a")));
Index: clang/test/CodeGen/alias.cpp
===
--- /dev/null
+++ clang/test/CodeGen/alias.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+
+void *f1_ifunc(void) { return nullptr; }
+void f1(void) __attribute__((alias("f1_ifunc")));
+// expected-error@-1 {{alias must point to a defined variable or function}}
+// expected-note@-2 {{must refer to the mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+
+void *f6_resolver_resolver(void) { return 0; }
+void *f6_resolver(void) __attribute__((alias("f6_resolver_resolver")));
+// expected-error@-1 {{alias must point to a defined variable or function}}
+// expected-note@-2 {{must refer to the mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+void f6(void) __attribute__((alias("f6_resolver")));
+// expected-error@-1 {{alias must point to a defined variable or function}}
+// expected-note@-2 {{must refer to the mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+
+__attribute__((unused, alias("resolver"), deprecated("hahahaha, isn't C great?")))
+void func();
+// expected-error@-2 {{alias must point to a defined variable or function}}
+// expected-note@-3 

[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-27 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

Okay, I have now modified the diagnostic to look something like (as per the 
discussion at 
https://discord.com/channels/636084430946959380/636732781086638081/1079356357024694363):

  ../../bug/ifunc-#59164.cpp:17:16: error: ifunc must point to a defined 
function
  __attribute__((ifunc("resolver")))
 ^
  ../../bug/ifunc-#59164.cpp:17:16: note: the name specified in an ifunc must 
refer to the mangled name
  ../../bug/ifunc-#59164.cpp:17:16: note: function by that name is mangled as 
"_ZL8resolverv"
  __attribute__((ifunc("resolver")))
 ^
 ifunc("_ZL8resolverv")
  ../../bug/ifunc-#59164.cpp:20:16: error: alias must point to a defined 
variable or function
  __attribute__((alias("resolver")))
 ^
  ../../bug/ifunc-#59164.cpp:20:16: note: the name specified in an alias must 
refer to the mangled name
  ../../bug/ifunc-#59164.cpp:20:16: note: function by that name is mangled as 
"_ZL8resolverv"
  __attribute__((alias("resolver")))
 ^
 alias("_ZL8resolverv")
  ../../bug/ifunc-#59164.cpp:23:24: error: ifunc must point to a defined 
function
  __attribute__((unused, ifunc("resolver"), deprecated("hahahaha, isn't C 
great?"))) void func();
 ^
  ../../bug/ifunc-#59164.cpp:23:24: note: the name specified in an ifunc must 
refer to the mangled name
  ../../bug/ifunc-#59164.cpp:23:24: note: function by that name is mangled as 
"_ZL8resolverv"
  __attribute__((unused, ifunc("resolver"), deprecated("hahahaha, isn't C 
great?"))) void func();
 ^
 ifunc("_ZL8resolverv")
  3 errors generated.

However, `clang/test/SemaCXX/externc-ifunc-resolver.cpp` still fails, and I am 
not entirely sure what to do with it. Should I update it to check the 
diagnostic? Also, it seems that the code I wrote prints "must refer to the 
mangled name" everywhere, even when the resolver or aliasee is not a function. 
Should I try to fix this? Or is it OK as it is?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-27 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

In D143803#4155266 , @erichkeane 
wrote:

> I think updating that test with this additional note is the right thing to do.

Will do, will also add checks for the fix-its.

> As far as that note, saying 'mangled name' is perhaps not correct there, 
> since what we really care is that it is the name-as-emitted to the linker. I 
> don't have an idea on exactly what to call it.  If we could come up with a 
> better phrase, it probably makes the diagnostic on the thing not being a 
> function.

First few that come to mind:

- ABI-mangled symbol
- Linked symbol
- Externally-visible name

It may also be worth splitting the diagnostic for `ifunc`s and `alias`es to be 
something like:

- `ifunc`: the function specified in an `ifunc` must refer to its 
- `alias`: the function or variable specified in an `alias` must refer to its 


I feel externally-visible name fits the best, though it doesn't really make 
sense with internal linkage.

> ALSO, it would be worth updating the error here to mention that it must point 
> to a defined function,  (where x,y,z are the things that it is 
> allowed to target).

Hmm, I do not really understand this point, could you please clarify it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-03-06 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 updated this revision to Diff 502660.
0xdc03 added a comment.

- Reword the diagnostic messages
- Refactor tests to match updated diagnostic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/alias.cpp
  clang/test/CodeGen/attr-ifunc.c
  clang/test/CodeGen/attr-ifunc.cpp
  clang/test/Sema/attr-alias-elf.c
  clang/test/SemaCXX/externc-ifunc-resolver.cpp

Index: clang/test/SemaCXX/externc-ifunc-resolver.cpp
===
--- clang/test/SemaCXX/externc-ifunc-resolver.cpp
+++ clang/test/SemaCXX/externc-ifunc-resolver.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm-only -triple x86_64-linux-gnu -verify %s
+// RUN: not %clang_cc1 -triple x86_64-linux -emit-llvm-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 extern "C" {
 __attribute__((used)) static void *resolve_foo() { return 0; }
@@ -12,5 +13,10 @@
 // some way to improve this diagnostic (likely by diagnosing when we decide
 // this case suppresses alias creation).
 __attribute__((ifunc("resolve_foo"))) void foo(); // expected-error{{ifunc must point to a defined function}}
+// expected-note@-1 {{must refer to its mangled name}}
+// expected-note@-2 {{function by that name is mangled as}}
+// expected-note@-3 {{function by that name is mangled as}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:36}:"ifunc(\"_ZL11resolve_foov\")"
+// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:16-[[@LINE-5]]:36}:"ifunc(\"_ZN2NSL11resolve_fooEv\")"
 }
 
Index: clang/test/Sema/attr-alias-elf.c
===
--- clang/test/Sema/attr-alias-elf.c
+++ clang/test/Sema/attr-alias-elf.c
@@ -5,9 +5,10 @@
 }
 
 void f2(void) __attribute__((alias("g2"))); // expected-error {{alias must point to a defined variable or function}}
-
+// expected-note@-1 {{must refer to its mangled name}}
 
 void f3(void) __attribute__((alias("g3"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to its mangled name}}
 void g3(void);
 
 
@@ -46,11 +47,14 @@
 int b1 = 42;
 
 extern int a2 __attribute__((alias("b2"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to its mangled name}}
 
 extern int a3 __attribute__((alias("b3"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to its mangled name}}
 extern int b3;
 
 extern int a4 __attribute__((alias("b4"))); // expected-error {{alias must point to a defined variable or function}}
+// expected-note@-1 {{must refer to its mangled name}}
 typedef int b4;
 
 void test2_bar() {}
Index: clang/test/CodeGen/attr-ifunc.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-ifunc.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+// RUN: not %clang_cc1 -triple x86_64-linux -emit-llvm-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void *f1_ifunc(void) { return nullptr; }
+void f1(void) __attribute__((ifunc("f1_ifunc")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to its mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:30-[[@LINE-4]]:47}:"ifunc(\"_Z8f1_ifuncv\")"
+
+void *f6_resolver_resolver(void) { return 0; }
+void *f6_resolver(void) __attribute__((ifunc("f6_resolver_resolver")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to its mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:40-[[@LINE-4]]:69}:"ifunc(\"_Z20f6_resolver_resolverv\")"
+void f6(void) __attribute__((ifunc("f6_resolver")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to its mangled name}}
+// expected-note@-3 {{function by that name is mangled as}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:30-[[@LINE-4]]:50}:"ifunc(\"_Z11f6_resolverv\")"
+
+__attribute__((unused, ifunc("resolver"), deprecated("hahahaha, isn't C great?")))
+void func();
+// expected-error@-2 {{ifunc must point to a defined function}}
+// expected-note@-3 {{must refer to its mangled name}}
+
Index: clang/test/CodeGen/attr-ifunc.c
===
--- clang/test/CodeGen/attr-ifunc.c
+++ clang/test/CodeGen/attr-ifunc.c
@@ -12,6 +12,7 @@
 void *f1_ifunc(void);
 void f1(void) __attribute__((ifunc("f1_ifunc")));
 // expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{must refer to its mangled name}}

[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-03-06 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

Okay, I have now modified the diagnostic to look like this:

  ../bug/ifunc-#59164.cpp:17:16: error: ifunc must point to a defined function
  __attribute__((ifunc("resolver")))
 ^
  ../bug/ifunc-#59164.cpp:17:16: note: the function specified in an ifunc must 
refer to its mangled name
  ../bug/ifunc-#59164.cpp:17:16: note: function by that name is mangled as 
"_ZL8resolverv"
  __attribute__((ifunc("resolver")))
 ^
 ifunc("_ZL8resolverv")
  ../bug/ifunc-#59164.cpp:20:16: error: alias must point to a defined variable 
or function
  __attribute__((alias("resolver")))
 ^
  ../bug/ifunc-#59164.cpp:20:16: note: the function or variable specified in an 
alias must refer to its mangled name
  ../bug/ifunc-#59164.cpp:20:16: note: function by that name is mangled as 
"_ZL8resolverv"
  __attribute__((alias("resolver")))
 ^
 alias("_ZL8resolverv")
  ../bug/ifunc-#59164.cpp:23:24: error: ifunc must point to a defined function
  __attribute__((unused, ifunc("resolver"), deprecated("hahahaha, isn't C 
great?"))) void func();
 ^
  ../bug/ifunc-#59164.cpp:23:24: note: the function specified in an ifunc must 
refer to its mangled name
  ../bug/ifunc-#59164.cpp:23:24: note: function by that name is mangled as 
"_ZL8resolverv"
  __attribute__((unused, ifunc("resolver"), deprecated("hahahaha, isn't C 
great?"))) void func();
 ^
 ifunc("_ZL8resolverv")
  3 errors generated.

Honestly I think this is good enough, I don't really think its worth 
bikeshedding over ``. I would anyways expect a user of these 
features to know how mangling works, so :shrug: from me.

I have also added checks for the fix-its.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-03-06 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

In D143803#4171728 , @erichkeane 
wrote:

> Not thrilled about 'mangled name' still, but I can't think of anything better 
> after all this time, so LGTM.

Oh wow your reply was much faster than I expected 😅. If you can, please land 
this patch on my behalf as I do not have commit access, using "Dhruv Chawla 
"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-10 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 created this revision.
Herald added a subscriber: jeroen.dobbelaere.
Herald added a project: All.
0xdc03 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When an alias or ifunc attribute refers to a function name that is
mangled, a diagnostic is emitted to suggest the mangled name as a
replacement for the given function name for every matching name in the
current TU.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143803

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/alias.cpp
  clang/test/CodeGen/attr-ifunc.cpp


Index: clang/test/CodeGen/attr-ifunc.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-ifunc.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only 
%s
+
+void *f1_ifunc(void) { return nullptr; }
+void f1(void) __attribute__((ifunc("f1_ifunc")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{exists as a mangled name}}
+
+void *f6_resolver_resolver(void) { return 0; }
+void *f6_resolver(void) __attribute__((ifunc("f6_resolver_resolver")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{exists as a mangled name}}
+void f6(void) __attribute__((ifunc("f6_resolver")));
+// expected-error@-1 {{ifunc must point to a defined function}}
+// expected-note@-2 {{exists as a mangled name}}
Index: clang/test/CodeGen/alias.cpp
===
--- /dev/null
+++ clang/test/CodeGen/alias.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only 
%s
+
+void *f1_ifunc(void) { return nullptr; }
+void f1(void) __attribute__((alias("f1_ifunc")));
+// expected-error@-1 {{alias must point to a defined variable or function}}
+// expected-note@-2 {{exists as a mangled name}}
+
+void *f6_resolver_resolver(void) { return 0; }
+void *f6_resolver(void) __attribute__((alias("f6_resolver_resolver")));
+// expected-error@-1 {{alias must point to a defined variable or function}}
+// expected-note@-2 {{exists as a mangled name}}
+void f6(void) __attribute__((alias("f6_resolver")));
+// expected-error@-1 {{alias must point to a defined variable or function}}
+// expected-note@-2 {{exists as a mangled name}}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -341,7 +341,8 @@
 static bool checkAliasedGlobal(DiagnosticsEngine &Diags,
SourceLocation Location, bool IsIFunc,
const llvm::GlobalValue *Alias,
-   const llvm::GlobalValue *&GV) {
+   const llvm::GlobalValue *&GV,
+   const llvm::MapVector 
&MangledDeclNames) {
   GV = getAliasedGlobal(Alias);
   if (!GV) {
 Diags.Report(Location, diag::err_cyclic_alias) << IsIFunc;
@@ -350,6 +351,16 @@
 
   if (GV->isDeclaration()) {
 Diags.Report(Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
+// Provide a note if the given function is not found and exists as a
+// mangled name
+for (const auto &[Decl, Name] : MangledDeclNames) {
+  if (const auto *ND = dyn_cast(Decl.getDecl())) {
+if (ND->getName() == GV->getName()) {
+   Diags.Report(Location, diag::note_alias_requires_mangled_name)
+   << GV->getName() << Name;
+}
+  }
+}
 return false;
   }
 
@@ -390,7 +401,8 @@
 StringRef MangledName = getMangledName(GD);
 llvm::GlobalValue *Alias = GetGlobalValue(MangledName);
 const llvm::GlobalValue *GV = nullptr;
-if (!checkAliasedGlobal(Diags, Location, IsIFunc, Alias, GV)) {
+if (!checkAliasedGlobal(Diags, Location, IsIFunc, Alias, GV,
+MangledDeclNames)) {
   Error = true;
   continue;
 }
Index: clang/include/clang/Basic/DiagnosticFrontendKinds.td
===
--- clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -278,6 +278,8 @@
 def err_alias_to_undefined : Error<
   "%select{alias|ifunc}0 must point to a defined "
   "%select{variable or |}1function">;
+def note_alias_requires_mangled_name : Note<
+  "'%0' exists as a mangled name, did you mean to use '%1'?">;
 def warn_alias_to_weak_alias : Warning<
   "%select{alias|ifunc}2 will always resolve to %0 even if weak definition of "
   "%1 is overridden">,


Index: clang/test/CodeGen/attr-ifunc.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-ifunc.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_

[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-10 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

Note that as it stands currently, this patch cannot be committed because the 
test `clang/test/SemaCXX/externc-ifunc-resolver.cpp` fails to run. The contents 
of the test are as follows:

  // RUN: %clang_cc1 -emit-llvm-only -triple x86_64-linux-gnu -verify %s
  
  extern "C" {
  __attribute__((used)) static void *resolve_foo() { return 0; }
  namespace NS {
  __attribute__((used)) static void *resolve_foo() { return 0; }
  } // namespace NS
  
  // FIXME: This diagnostic is pretty confusing, the issue is that the existence
  // of the two functions suppresses the 'alias' creation, and thus the ifunc
  // resolution via the alias as well. In the future we should probably find
  // some way to improve this diagnostic (likely by diagnosing when we decide
  // this case suppresses alias creation).
  __attribute__((ifunc("resolve_foo"))) void foo(); // expected-error{{ifunc 
must point to a defined function}}
  }

The error that I get is as follows:

  Command Output (stderr):
  --
  + : 'RUN: at line 1'
  + /mnt/entschuldigung/LLVM/llvm-main/build-release/bin/clang -cc1 
-internal-isystem 
/mnt/entschuldigung/LLVM/llvm-main/build-release/lib/clang/17/include 
-nostdsysteminc -emit-llvm-only -triple x86_64-linux-gnu -verify 
/mnt/entschuldigung/LLVM/llvm-main/clang/test/SemaCXX/externc-ifunc-resolver.cpp
  error: 'note' diagnostics seen but not expected:
File 
/mnt/entschuldigung/LLVM/llvm-main/clang/test/SemaCXX/externc-ifunc-resolver.cpp
 Line 14: 'resolve_foo' exists as a mangled name, did you mean to use 
'_ZL11resolve_foov'?
File 
/mnt/entschuldigung/LLVM/llvm-main/clang/test/SemaCXX/externc-ifunc-resolver.cpp
 Line 14: 'resolve_foo' exists as a mangled name, did you mean to use 
'_ZN2NSL11resolve_fooEv'?
  2 errors generated.
  
  --

which confuses me because an `extern "C"` block is not supposed to mangle any 
names, right? Appreciate any inputs on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-18 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

nudge! at anyone who knows what to do here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-24 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

I will try to come up with a better diagnostic for this issue and will try and 
update the patch as soon as I can.

In D143803#4150423 , @aaron.ballman 
wrote:

> Btw, these changes should come with a release note as well.

Are all functional changes logged in the release notes? I am not really aware 
of how they work.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:345
+   const llvm::GlobalValue *&GV,
+   const llvm::MapVector 
&MangledDeclNames) {
   GV = getAliasedGlobal(Alias);

aaron.ballman wrote:
> Does clang-format do this? It looks far beyond the usual 80 col limit we use.
It is beyond the 80 column limit because I formatted it by hand. The linting 
part of `arc diff` did not complain so it seemed fine to me. I suppose I was 
supposed to use `git clang-format`, I was not aware of it. I will use that 
command from now on.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:359-360
+if (ND->getName() == GV->getName()) {
+   Diags.Report(Location, diag::note_alias_requires_mangled_name)
+   << GV->getName() << Name;
+}

aaron.ballman wrote:
> Should this come with a fix-it to switch the attribute to using the mangled 
> name instead?
I did consider it, however I have no idea how to implement that 😅 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D152522: [NFC][SetVector] Update some usages of SetVector to SmallSetVector

2023-06-09 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 created this revision.
0xdc03 added a reviewer: nikic.
Herald added subscribers: ChuanqiXu, StephenFan, haicheng, hiraditya, MatzeB.
Herald added a project: All.
0xdc03 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch is a continuation of D152497 . It 
updates usages of SetVector
that were found in llvm/ and clang/ which were originally specifying either
SmallPtrSet or SmallVector to just using SmallSetVector, as the overhead
of SetVector is reduced with D152497 .

This also helps clean up the code a fair bit, and gives a decent speed
boost at -O0 (~0.2%):
https://llvm-compile-time-tracker.com/compare.php?from=9ffdabecabcddde298ff313f5353f9e06590af62&to=97f1c0cde42ba85eaa67cbe89bec8fe45b801f21&stat=instructions%3Au


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152522

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  llvm/include/llvm/ADT/GenericCycleInfo.h
  llvm/include/llvm/CodeGen/LiveRangeEdit.h
  llvm/include/llvm/Transforms/Scalar/SROA.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -318,9 +318,7 @@
 
   /// This is a collection of subprogram MDNodes that are processed to
   /// create DIEs.
-  SetVector,
-SmallPtrSet>
-  ProcessedSPNodes;
+  SmallSetVector ProcessedSPNodes;
 
   /// If nonnull, stores the current machine function we're processing.
   const MachineFunction *CurFn = nullptr;
Index: llvm/lib/Analysis/InlineCost.cpp
===
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -2680,9 +2680,7 @@
   // basic blocks in a breadth-first order as we insert live successors. To
   // accomplish this, prioritizing for small iterations because we exit after
   // crossing our threshold, we use a small-size optimized SetVector.
-  typedef SetVector,
-SmallPtrSet>
-  BBSetVector;
+  typedef SmallSetVector BBSetVector;
   BBSetVector BBWorklist;
   BBWorklist.insert(&F.getEntryBlock());
 
Index: llvm/include/llvm/Transforms/Scalar/SROA.h
===
--- llvm/include/llvm/Transforms/Scalar/SROA.h
+++ llvm/include/llvm/Transforms/Scalar/SROA.h
@@ -105,7 +105,7 @@
   /// directly promoted. Finally, each time we rewrite a use of an alloca other
   /// the one being actively rewritten, we add it back onto the list if not
   /// already present to ensure it is re-visited.
-  SetVector> Worklist;
+  SmallSetVector Worklist;
 
   /// A collection of instructions to delete.
   /// We try to batch deletions to simplify code and make things a bit more
@@ -120,7 +120,7 @@
   ///
   /// Note that we have to be very careful to clear allocas out of this list in
   /// the event they are deleted.
-  SetVector> PostPromotionWorklist;
+  SmallSetVector PostPromotionWorklist;
 
   /// A collection of alloca instructions we can directly promote.
   std::vector PromotableAllocas;
@@ -130,7 +130,7 @@
   /// All of these PHIs have been checked for the safety of speculation and by
   /// being speculated will allow promoting allocas currently in the promotable
   /// queue.
-  SetVector> SpeculatablePHIs;
+  SmallSetVector SpeculatablePHIs;
 
   /// A worklist of select instructions to rewrite prior to promoting
   /// allocas.
Index: llvm/include/llvm/CodeGen/LiveRangeEdit.h
===
--- llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -97,8 +97,7 @@
   /// a load, eliminate the register by folding the def into the use.
   bool foldAsLoad(LiveInterval *LI, SmallVectorImpl &Dead);
 
-  using ToShrinkSet = SetVector,
-SmallPtrSet>;
+  using ToShrinkSet = SmallSetVector;
 
   /// Helper for eliminateDeadDefs.
   void eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink);
Index: llvm/include/llvm/ADT/GenericCycleInfo.h
===
--- llvm/include/llvm/ADT/GenericCycleInfo.h
+++ llvm/include/llvm/ADT/GenericCycleInfo.h
@@ -28,10 +28,10 @@
 #ifndef LLVM_ADT_GENERICCYCLEINFO_H
 #define LLVM_ADT_GENERICCYCLEINFO_H
 
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/GenericSSAContext.h"
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -64,7 +64,7 @@
   /// Basic blocks that are contained in the cycle, including entry blocks,
   /// and including blocks that ar

[PATCH] D152522: [NFC][SetVector] Update some usages of SetVector to SmallSetVector

2023-06-10 Thread Dhruv Chawla 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 rG8e580b7edd15: [NFC][SetVector] Update some usages of 
SetVector to SmallSetVector (authored by 0xdc03).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152522

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  llvm/include/llvm/ADT/GenericCycleInfo.h
  llvm/include/llvm/CodeGen/LiveRangeEdit.h
  llvm/include/llvm/Transforms/Scalar/SROA.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -318,9 +318,7 @@
 
   /// This is a collection of subprogram MDNodes that are processed to
   /// create DIEs.
-  SetVector,
-SmallPtrSet>
-  ProcessedSPNodes;
+  SmallSetVector ProcessedSPNodes;
 
   /// If nonnull, stores the current machine function we're processing.
   const MachineFunction *CurFn = nullptr;
Index: llvm/lib/Analysis/InlineCost.cpp
===
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -2680,9 +2680,7 @@
   // basic blocks in a breadth-first order as we insert live successors. To
   // accomplish this, prioritizing for small iterations because we exit after
   // crossing our threshold, we use a small-size optimized SetVector.
-  typedef SetVector,
-SmallPtrSet>
-  BBSetVector;
+  typedef SmallSetVector BBSetVector;
   BBSetVector BBWorklist;
   BBWorklist.insert(&F.getEntryBlock());
 
Index: llvm/include/llvm/Transforms/Scalar/SROA.h
===
--- llvm/include/llvm/Transforms/Scalar/SROA.h
+++ llvm/include/llvm/Transforms/Scalar/SROA.h
@@ -105,7 +105,7 @@
   /// directly promoted. Finally, each time we rewrite a use of an alloca other
   /// the one being actively rewritten, we add it back onto the list if not
   /// already present to ensure it is re-visited.
-  SetVector> Worklist;
+  SmallSetVector Worklist;
 
   /// A collection of instructions to delete.
   /// We try to batch deletions to simplify code and make things a bit more
@@ -120,7 +120,7 @@
   ///
   /// Note that we have to be very careful to clear allocas out of this list in
   /// the event they are deleted.
-  SetVector> PostPromotionWorklist;
+  SmallSetVector PostPromotionWorklist;
 
   /// A collection of alloca instructions we can directly promote.
   std::vector PromotableAllocas;
@@ -130,7 +130,7 @@
   /// All of these PHIs have been checked for the safety of speculation and by
   /// being speculated will allow promoting allocas currently in the promotable
   /// queue.
-  SetVector> SpeculatablePHIs;
+  SmallSetVector SpeculatablePHIs;
 
   /// A worklist of select instructions to rewrite prior to promoting
   /// allocas.
Index: llvm/include/llvm/CodeGen/LiveRangeEdit.h
===
--- llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -97,8 +97,7 @@
   /// a load, eliminate the register by folding the def into the use.
   bool foldAsLoad(LiveInterval *LI, SmallVectorImpl &Dead);
 
-  using ToShrinkSet = SetVector,
-SmallPtrSet>;
+  using ToShrinkSet = SmallSetVector;
 
   /// Helper for eliminateDeadDefs.
   void eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink);
Index: llvm/include/llvm/ADT/GenericCycleInfo.h
===
--- llvm/include/llvm/ADT/GenericCycleInfo.h
+++ llvm/include/llvm/ADT/GenericCycleInfo.h
@@ -28,10 +28,10 @@
 #ifndef LLVM_ADT_GENERICCYCLEINFO_H
 #define LLVM_ADT_GENERICCYCLEINFO_H
 
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/GenericSSAContext.h"
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -64,7 +64,7 @@
   /// Basic blocks that are contained in the cycle, including entry blocks,
   /// and including blocks that are part of a child cycle.
   using BlockSetVectorT = SetVector,
-SmallPtrSet>;
+DenseSet, 8>;
   BlockSetVectorT Blocks;
 
   /// Depth of the cycle in the tree. The root "cycle" is at depth 0.
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -1729,9 +1729,7 @@
 
 namespace {
   // Use SetVector since the diagnostic cares about the ordering of the Decl's.
-  using DeclSetVe