[PATCH] clang does not emit DW_TAG_enumerator and DW_TAG_enumeration_type for unnamed enum types

David Blaikie dblaikie at gmail.com
Thu Nov 28 17:27:25 PST 2013


Will this cause us to emit all enumerations, even those that are not
referenced? That might be too bloaty/expensive.

(& please check the test cases it tools/clang/tests/CodeGen* to use as
a basis for writing test cases for your change/fix)

On Thu, Nov 28, 2013 at 6:13 AM, jyoti allur
<jyoti.yalamanchili at gmail.com> wrote:
> Hi echristo,
>
> //global-used-types.c
>
> /*
>  Contributed by Dodji Seketeli <dodji at redhat.com>
>  { dg-options "-g -dA -fno-merge-debug-strings" }
>  { dg-do compile }
>  { dg-final { scan-assembler-times "0x.* DW_TAG_enumeration_type" 1 } }
>  { dg-final { scan-assembler-times "DW_TAG_enumerator" 3 } }
>  { dg-final { scan-assembler "\"a\"" } } //check emission of enum members
>  { dg-final { scan-assembler "\"b\"" } } //check emission of enum members
>
>  */
>
> enum { a, b };
>
> int v = a;
> char s[b];
>
> clang does not seem to emit DW_TAG_enumerator and DW_TAG_enumeration_type for unnamed enum types.
> I have made a patch for the same. Let me know if this is good for commit. Need help adding a testcase for it in Debuginfo.
>
> http://llvm-reviews.chandlerc.com/D2286
>
> Files:
>   llvm/tools/clang/lib/CodeGen/CodeGenModule.h
>   llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp
>   llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
>   llvm/tools/clang/lib/CodeGen/CGDebugInfo.h
>
> Index: llvm/tools/clang/lib/CodeGen/CodeGenModule.h
> ===================================================================
> --- llvm/tools/clang/lib/CodeGen/CodeGenModule.h
> +++ llvm/tools/clang/lib/CodeGen/CodeGenModule.h
> @@ -1036,6 +1036,7 @@
>    void SetFunctionAttributes(GlobalDecl GD,
>                               llvm::Function *F,
>                               bool IsIncompleteFunction);
> +  void EmitEnumType(EnumDecl *GlobalEnum );
>
>    void EmitGlobalDefinition(GlobalDecl D);
>
> Index: llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp
> ===================================================================
> --- llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp
> +++ llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp
> @@ -2926,6 +2926,11 @@
>      EmitGlobal(cast<VarDecl>(D));
>      break;
>
> +  case Decl::Enum:
> +    //Handle Enum Case
> +    EmitEnumType(cast<EnumDecl>(D));
> +    break;
> +
>    // Indirect fields from global anonymous structs and unions can be
>    // ignored; only the actual variable requires IR gen support.
>    case Decl::IndirectField:
> @@ -3197,3 +3202,10 @@
>
>    return llvm::ConstantStruct::getAnon(Fields);
>  }
> +
> +void CodeGenModule::EmitEnumType(EnumDecl *GlobalEnum ) {
> +
> +  if (CGDebugInfo *DI = getModuleDebugInfo())
> +    DI->EmitEnumerator(GlobalEnum);
> +}
> +
> Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
> ===================================================================
> --- llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
> +++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
> @@ -3275,3 +3275,12 @@
>
>    DBuilder.finalize();
>  }
> +
> +void CGDebugInfo::EmitEnumerator(const EnumDecl *EnumD) {
> +
> +  ASTContext &Context = CGM.getContext();
> +  QualType T = Context.getEnumType(EnumD);
> +  if (const EnumType *Enum = T->getAs<EnumType>())
> +    CreateEnumType(Enum);
> +}
> +
> Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.h
> ===================================================================
> --- llvm/tools/clang/lib/CodeGen/CGDebugInfo.h
> +++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.h
> @@ -267,6 +267,9 @@
>    /// EmitGlobalVariable - Emit global variable's debug info.
>    void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
>
> +  /// EmitEnumerator - Emit enumerators debug info.
> +  void EmitEnumerator(const EnumDecl *EnumD);
> +
>    /// \brief - Emit C++ using directive.
>    void EmitUsingDirective(const UsingDirectiveDecl &UD);
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list