This is an archive of the discontinued LLVM Phabricator instance.

[clang][DebugInfo] Emit debuginfo for non-constant case value
ClosedPublic

Authored by yonghong-song on Sep 27 2022, 12:04 AM.

Details

Summary

Currently, clang does not emit debuginfo for the switch stmt
case value if it is an enum value. For example,

$ cat test.c
enum { AA = 1, BB = 2 };
int func1(int a) {
  switch(a) {
  case AA: return 10; 
  case BB: return 11; 
  default: break;
  }   
  return 0;
}
$ llvm-dwarfdump test.o | grep AA
$

Note that gcc does emit debuginfo for the same test case.

This patch added such a support with similar implementation
to CodeGenFunction::EmitDeclRefExprDbgValue(). With this patch,

$ clang -g -c test.c
$ llvm-dwarfdump test.o | grep AA
                DW_AT_name    ("AA")
$   

Diff Detail

Event Timeline

yonghong-song created this revision.Sep 27 2022, 12:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 12:04 AM
yonghong-song requested review of this revision.Sep 27 2022, 12:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 12:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dblaikie accepted this revision.Sep 27 2022, 10:39 AM

SGTM - could you also add some CHECKs in the test that show the enumeration was added to the enumerators list on the CU (& you can probably test with just one enumerator - don't need two in each test for instance)

& I'm not quite following - what's the difference between the two cases being tested? Oh, I guess the second has implicit conversions in the case parameters? Fair enough, maybe would benefit from some comments.

This revision is now accepted and ready to land.Sep 27 2022, 10:39 AM

SGTM - could you also add some CHECKs in the test that show the enumeration was added to the enumerators list on the CU (& you can probably test with just one enumerator - don't need two in each test for instance)

Okay, will do.

& I'm not quite following - what's the difference between the two cases being tested? Oh, I guess the second has implicit conversions in the case parameters? Fair enough, maybe would benefit from some comments.

Yes, the first is without implicit conversion and the second is with implicit conversion. I will add some comments to clarify it in the test.

  • simplify test case, add more CHECK's and add comments to explain the test.
This revision was landed with ongoing or failed builds.Sep 28 2022, 12:11 PM
This revision was automatically updated to reflect the committed changes.