This is an archive of the discontinued LLVM Phabricator instance.

[clang][CodeGen] Fix global variables initialized with an inheriting constructor.
ClosedPublic

Authored by efriedma on Jun 30 2023, 3:46 PM.

Details

Summary

For inheriting constructors which have to be emitted inline, we use CodeGenFunction::EmitInlinedInheritingCXXConstructorCall to emit the required code. This code uses EmitParmDecl to emit the "this" argument of the call. EmitParmDecl then helpfully calls llvm::Value::setName to name the parameter... which renames the global variable to "this".

To fix the issue, skip the setName call on globals.

The renaming still has slightly weird results in other cases (it renames all local variables initialized with an inlined inheriting constructor to "this"), but the result isn't actually wrong in those cases, so I'm just going to leave it for now.

Fixes https://github.com/llvm/llvm-project/issues/63618

Diff Detail

Event Timeline

efriedma created this revision.Jun 30 2023, 3:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 3:46 PM
efriedma requested review of this revision.Jun 30 2023, 3:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 3:46 PM
rsmith accepted this revision.Jun 30 2023, 3:57 PM

Wow, what an amazing bug :)

clang/lib/CodeGen/CGDecl.cpp
2459

Is it feasible to only set the name if the value doesn't already have a name, or do we give values bad names often enough that it's better to overwrite an existing name here?

This revision is now accepted and ready to land.Jun 30 2023, 3:57 PM
efriedma added inline comments.Jul 2 2023, 11:10 AM
clang/lib/CodeGen/CGDecl.cpp
2459

Outside the EmitInlinedInheritingCXXConstructorCall case, the arguments are generally either llvm::Argument, or llvm::Instruction generated by calling convention code. It might make sense to just make the calling convention code name the values itself (it already names some of the values it generates).

But I'll stick with the conservative fix here, and leave that for a followup.

This revision was landed with ongoing or failed builds.Jul 2 2023, 2:25 PM
This revision was automatically updated to reflect the committed changes.