[cfe-commits] r112977 - in /cfe/trunk: include/clang/Lex/Token.h lib/Lex/Preprocessor.cpp lib/Parse/ParseObjc.cpp

Chris Lattner clattner at apple.com
Fri Sep 3 10:47:14 PDT 2010


On Sep 3, 2010, at 10:33 AM, Fariborz Jahanian wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=112977&view=rev
> Log:
> Use getSpelling to get original text of the
> c++ operator token. (radar 8328250).

Thanks Fariborz, one gotcha here:

>   switch (Tok.getKind()) {
>   default:
>     return 0;
> +  case tok::ampamp:
> +  case tok::ampequal:
> +  case tok::amp:
> +  case tok::pipe:
> +  case tok::tilde:
> +  case tok::exclaim:
> +  case tok::exclaimequal:
> +  case tok::pipepipe:
> +  case tok::pipeequal:
> +  case tok::caret:
> +  case tok::caretequal: {
> +    llvm::StringRef ThisTok = PP.getSpelling(Tok);

PP.getSpelling(Tok) returns an std::string, which will be destroyed at the end of the statement.  This causes the StringRef (which is basically a pointer + length) to dangle.  There are a couple of different ways to fix this, but the simplest is to declare ThisTok as an std::string.

-Chris

> +    if (isalpha(ThisTok[0])) {
> +      IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data());
> +      Tok.setKind(tok::identifier);
> +      SelectorLoc = ConsumeToken();
> +      return II;
> +    }
> +    return 0; 
> +  }
> +      
>   case tok::identifier:
>   case tok::kw_asm:
>   case tok::kw_auto:
> 
> 
> _______________________________________________
> 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