Skip to content

[Clang] ensure mangled names are valid identifiers before being suggested in ifunc/alias attributes notes #118170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

a-tarasyuk
Copy link
Member

Fixes #112205


Commit that introduced this feature - 9306ef9

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Nov 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 30, 2024

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #112205


Commit that introduced this feature - 9306ef9


Full diff: https://github.com/llvm/llvm-project/pull/118170.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+1)
  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-1)
  • (modified) clang/test/CodeGen/alias.cpp (+3)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e44aefa90ab386..5c24471bbf7c93 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -763,6 +763,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 7189a4689e8156..d3d5c0743a520b 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 a468c31d369ed0..43be6b99ce8491 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

@a-tarasyuk a-tarasyuk merged commit 071da92 into llvm:main Dec 2, 2024
12 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 2, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-win running on sie-win-worker while building clang at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/8786

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: ClangScanDeps/modules-full.cpp' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
rm -rf Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir
# executed command: rm -rf 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir'
# RUN: at line 2
rm -rf Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb
# executed command: rm -rf 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb'
# RUN: at line 3
mkdir -p Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir
# executed command: mkdir -p 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir'
# RUN: at line 4
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input.cpp
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input.cpp'
# RUN: at line 5
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input2.cpp
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input2.cpp'
# RUN: at line 6
mkdir Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs
# executed command: mkdir 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs'
# RUN: at line 7
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header.h Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header.h
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header.h' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header.h'
# RUN: at line 8
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header2.h Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header2.h
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header2.h' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header2.h'
# RUN: at line 9
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/module.modulemap Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/module.modulemap
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/module.modulemap' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/module.modulemap'
# RUN: at line 10
sed -e "s|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g" Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb.json > Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb
# executed command: sed -e 's|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g' 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb.json'
# RUN: at line 11
sed -e "s|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g" Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb_clangcl.json > Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp_clangcl.cdb
# executed command: sed -e 's|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g' 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb_clangcl.json'
# RUN: at line 13
z:\b\llvm-clang-x86_64-sie-win\build\bin\clang-scan-deps.exe -compilation-database Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb -j 4 -format experimental-full    -mode preprocess-dependency-directives > Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.result
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\clang-scan-deps.exe' -compilation-database 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb' -j 4 -format experimental-full -mode preprocess-dependency-directives
# .---redirected output from 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.result'
# | {
# |   "modules": [
# |     {
# |       "clang-module-deps": [
# |         {
# |           "context-hash": "4C2VZJ6M2KPDHCCSBB14A8H2D",
# |           "module-name": "header2"
# |         }
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang++] Assertion `Name.isIdentifier() && "Name is not a simple identifier"' failed.
4 participants