summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr T. <oleksandr.tarasiuk@outlook.com>2024-12-02 18:16:47 +0200
committerGitHub <noreply@github.com>2024-12-02 18:16:47 +0200
commit071da9261b7e94c2d2d4e9d3d4eba1f29115e8ae (patch)
tree8ceecc90b32c6dfaa400667633a15172b31a7e14
parent97f94af3560d3ae046f6c3d7ec74b03d1d2493d0 (diff)
[Clang] ensure mangled names are valid identifiers before being suggested in ifunc/alias attributes notes (#118170)
Fixes #112205 --- Commit that introduced this feature - https://github.com/llvm/llvm-project/commit/9306ef9750b7a319d59f6d3e4977e01e39b8f161
-rw-r--r--clang/docs/ReleaseNotes.rst1
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp3
-rw-r--r--clang/test/CodeGen/alias.cpp3
3 files changed, 6 insertions, 1 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 08887d5ba985..0bb2eb820cd7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -762,6 +762,7 @@ Bug Fixes to C++ Support
- Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105)
- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
+- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 7189a4689e81..d3d5c0743a52 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -602,7 +602,8 @@ static bool checkAliasedGlobal(
// mangled name.
for (const auto &[Decl, Name] : MangledDeclNames) {
if (const auto *ND = dyn_cast<NamedDecl>(Decl.getDecl())) {
- if (ND->getName() == GV->getName()) {
+ IdentifierInfo *II = ND->getIdentifier();
+ if (II && II->getName() == GV->getName()) {
Diags.Report(Location, diag::note_alias_mangled_name_alternative)
<< Name
<< FixItHint::CreateReplacement(
diff --git a/clang/test/CodeGen/alias.cpp b/clang/test/CodeGen/alias.cpp
index a468c31d369e..43be6b99ce84 100644
--- a/clang/test/CodeGen/alias.cpp
+++ b/clang/test/CodeGen/alias.cpp
@@ -26,6 +26,9 @@ __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 {{must refer to its mangled name}}
+
+void *operator new(unsigned long) __attribute__((alias("A"))); // expected-error {{alias must point to a defined variable or function}} \
+ // expected-note {{the function or variable specified in an alias must refer to its mangled name}}
#endif
// CHECK: @_ZN4libc4log2Ed ={{.*}} alias double (double), ptr @log2