[PATCH] Added comprehensive macro arg usage logic to Use-Nullptr Transform

Edwin Vane edwin.vane at intel.com
Fri May 3 10:09:27 PDT 2013


  Small suggestions addressed. Thank you.

  As for Lexer::makeFileCharRange(), it is accomplishing something different using the same mechanisms as I'm using here, hence the similarity. Perhaps there's some refactoring that could be done to get functions like Lexer::getImmediateMacroName() (which I based much of my understanding on), Lexer::makeFileCharRange(), and numerous SourceManager functions to avoid repeated code. I do see similar tasks happening:

    if macro arg expansion:
      do something
    else
      do something else

  Generally this is all done in digging out of (or in to, depending how you look at it) macro expansions. Whereas makeFileCharRange() is attempting to produce a SourceRange with file locations, the new functionality in this patch is trying to answer this question: given a NullTo(Member)Pointer cast that expands from a macro arg, do all uses of that arg result in NullTo(Member)Pointer casts. The three steps to accomplish this are described in allArgUsesValid():

    # Get the SourceLocation of the arg and the macro to which that arg is given.
    # Find the first ancestor of the cast that doesn't expand from the macro found in step 1. This is just to limit our search through the AST in step 3.
    # Look at all descendants of node from step 2. Any that have source locations matching the arg from step 1 must have a NullTo(Member)Pointer cast somewhere along the descendant chain. This is taken to suffice as "all uses of the arg result in NullTo(Member)Pointer casts".

http://llvm-reviews.chandlerc.com/D732



More information about the cfe-commits mailing list