[cfe-commits] r132612 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ include/clang/Sema/ include/clang/Serialization/ lib/AST/ lib/CodeGen/ lib/Parse/ lib/Sema/ lib/Serialization/ lib/StaticAnalyzer/Core/ test/Parser/ tools/libclang/
Peter Collingbourne
peter at pcc.me.uk
Wed Jun 8 08:21:06 PDT 2011
On Wed, Jun 08, 2011 at 02:58:26PM +0200, Dimitry Andric wrote:
> > +ExprResult Sema::ActOnAsTypeExpr(Expr *expr, ParsedType destty,
> > + SourceLocation BuiltinLoc,
> > + SourceLocation RParenLoc) {
> > + ExprValueKind VK = VK_RValue;
> > + ExprObjectKind OK = OK_Ordinary;
> > + QualType DstTy = GetTypeFromParser(destty);
> > + QualType SrcTy = expr->getType();
> > + if (Context.getTypeSize(DstTy) != Context.getTypeSize(SrcTy))
> > + return ExprError(Diag(BuiltinLoc,
> > + diag::err_invalid_astype_of_different_size)
> > +<< DstTy.getAsString().c_str()
> > +<< SrcTy.getAsString().c_str()
> > +<< expr->getSourceRange());
> > + return Owned(new (Context) AsTypeExpr(expr, DstTy, VK, OK, BuiltinLoc, RParenLoc));
> > +}
> > +
>
> For me, this leads to a failure when testing a self-hosted clang:
...
> Because I'm using FreeBSD CURRENT, which poisons freed memory, the most
> likely reason is that the strings returned by
> DstTy.getAsString().c_str() and SrcTy.getAsString().c_str() are already
> destroyed at the moment the diagnostics are printed. Would it make
> sense to convert them to StringRefs, or something else?
>
> Btw, it doesn't seem possible to directly output std::string to a
> DiagnosticBuilder, was there any particular reason for that?
Hi Dmitry,
We can output QualTypes directly to the diagnostic builder, and
this is the approach followed in the rest of the code. I modified
this diagnostic to use QualTypes in r132750.
Thanks,
--
Peter
More information about the cfe-commits
mailing list