r230914 - DebugInfo: Give externally defined types a size and alignment where

Adrian Prantl aprantl at apple.com
Sun Mar 1 17:32:34 PST 2015


We don’t actually need it to emit the debug info, but I’m using the type size to assert that perform a couple of sanity assertions for multi-piece debug values that helped catch a lot of bugs so far. We could also disable these assertion for types with zero size to allow for sizeless forward-declared types, but since the size field is there anyway, we might as well use it for something good.

-- adrian

> On Mar 1, 2015, at 3:24 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> Hey Adrian - what's the reason we need the type's size for optimized debug info output?
> 
> On Mar 1, 2015 2:11 PM, "Peter Collingbourne" <peter at pcc.me.uk <mailto:peter at pcc.me.uk>> wrote:
> Author: pcc
> Date: Sun Mar  1 16:07:04 2015
> New Revision: 230914
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=230914&view=rev <http://llvm.org/viewvc/llvm-project?rev=230914&view=rev>
> Log:
> DebugInfo: Give externally defined types a size and alignment where
> possible. Fixes PR22736.
> 
> Modified:
>     cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>     cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=230914&r1=230913&r2=230914&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=230914&r1=230913&r2=230914&view=diff>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sun Mar  1 16:07:04 2015
> @@ -647,11 +647,19 @@ CGDebugInfo::getOrCreateRecordFwdDecl(co
>    unsigned Line = getLineNumber(RD->getLocation());
>    StringRef RDName = getClassName(RD);
> 
> +  uint64_t Size = 0;
> +  uint64_t Align = 0;
> +
> +  const RecordDecl *D = RD->getDefinition();
> +  if (D && D->isCompleteDefinition()) {
> +    Size = CGM.getContext().getTypeSize(Ty);
> +    Align = CGM.getContext().getTypeAlign(Ty);
> +  }
> 
>    // Create the type.
>    SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
>    llvm::DICompositeType RetTy = DBuilder.createReplaceableCompositeType(
> -      getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, 0, 0,
> +      getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align,
>        llvm::DIDescriptor::FlagFwdDecl, FullName);
>    ReplaceMap.emplace_back(
>        std::piecewise_construct, std::make_tuple(Ty),
> 
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp?rev=230914&r1=230913&r2=230914&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp?rev=230914&r1=230913&r2=230914&view=diff>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp Sun Mar  1 16:07:04 2015
> @@ -99,3 +99,11 @@ template <>
>  struct k<int>;
>  template struct k<int>;
>  // CHECK-NOT: ; [ DW_TAG_structure_type ] [k<int>]
> +
> +template <typename T>
> +struct l {
> +  int x;
> +};
> +extern template class l<int>;
> +l<int> li;
> +// CHECK: [ DW_TAG_structure_type ] [l<int>] {{.*}}size {{[^0]}}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu <mailto:cfe-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits <http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150301/4f37be94/attachment.html>


More information about the cfe-commits mailing list