[PATCH] D109703: [DebugInfo] Fix scope for local static variables

Ellis Hoag via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 22 15:27:28 PDT 2021


ellis added a comment.

In D109703#2998350 <https://reviews.llvm.org/D109703#2998350>, @krisb wrote:

> But it seems imported declarations are broken not just for static locals, but for all inlined entities, for example
>
>   namespace ns {
>   inline __attribute__((always_inline))
>   int foo() {
>     int a = 42; 
>     return a;
>   }
>   }
>   
>   int main() {
>     using ns::foo;
>     return foo();
>   }
>
> produces (with or w/o this patch) imported declaration for `foo()` that refers to an empty subprogram:
>
>   x0000002a:   DW_TAG_namespace
>                   DW_AT_name  ("ns")
>   
>   0x0000002f:     DW_TAG_subprogram
>                     DW_AT_name  ("foo")
>                     DW_AT_inline  (DW_INL_inlined)
>   
>   0x0000003f:       DW_TAG_variable
>                       DW_AT_name  ("a")
>   
>   0x0000004a:       NULL
>   
>   0x0000004b:     DW_TAG_subprogram
>   
>   0x0000004c:     NULL
>   
>   0x00000054:   DW_TAG_subprogram
>                   DW_AT_name  ("main")
>   
>   0x0000006d:     DW_TAG_imported_declaration
>                     DW_AT_import  (0x0000004b)
>
> while it should point to `0x0000002f`.

I've looked into this and realized that clang correctly emits a `DW_TAG_inlined_subroutine` for foo so the variables here are actually ok. The `DW_TAG_imported_declaration` tag is incorrect though, and I have a fix in https://reviews.llvm.org/D110294.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109703



More information about the cfe-commits mailing list