[cfe-commits] Proposed fix to SourceManager.cpp

Dean Sturtevant dsturtevant at google.com
Mon Oct 4 17:16:18 PDT 2010


Anyone willing to take this one on?
- Dean

On Thu, Sep 30, 2010 at 5:25 PM, Dean Sturtevant <dsturtevant at google.com> wrote:
> Certain methods in SourceManager.ccp were not respecting an "Invalid"
> pointer being passed in. Here is a proposed fix, built & tested.
> Please consider patching this in.
> - Dean Sturtevant
>
> --- llvm/tools/clang/lib/Basic/SourceManager.cpp     2010-09-02
> 00:41:19.000000000 -0700
> +++ llvm/tools/clang/lib/Basic/SourceManager.cpp    2010-09-29
> 16:41:00.000000000 -0700
> @@ -796,16 +796,25 @@
>  return FilePos-LineStart+1;
>  }
>
> +// isInvalid - Return the result of calling loc.isInvalid(), and
> +// if Invalid is not null, set its value to same.
> +static bool isInvalid(SourceLocation Loc, bool *Invalid) {
> +  bool MyInvalid = Loc.isInvalid();
> +  if (Invalid)
> +    *Invalid = MyInvalid;
> +  return MyInvalid;
> +}
> +
>  unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc,
>                                                bool *Invalid) const {
> -  if (Loc.isInvalid()) return 0;
> +  if (isInvalid(Loc, Invalid)) return 0;
>  std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
>  return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
>  }
>
>  unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc,
>                                                     bool *Invalid) const {
> -  if (Loc.isInvalid()) return 0;
> +  if (isInvalid(Loc, Invalid)) return 0;
>  std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
>  return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
>  }
> @@ -974,13 +983,13 @@
>
>  unsigned SourceManager::getInstantiationLineNumber(SourceLocation Loc,
>                                                   bool *Invalid) const {
> -  if (Loc.isInvalid()) return 0;
> +  if (isInvalid(Loc, Invalid)) return 0;
>  std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
>  return getLineNumber(LocInfo.first, LocInfo.second);
>  }
>  unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,
>                                              bool *Invalid) const {
> -  if (Loc.isInvalid()) return 0;
> +  if (isInvalid(Loc, Invalid)) return 0;
>  std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
>  return getLineNumber(LocInfo.first, LocInfo.second);
>  }
> @@ -1021,7 +1030,7 @@
>  /// for normal clients.
>  const char *SourceManager::getBufferName(SourceLocation Loc,
>                                         bool *Invalid) const {
> -  if (Loc.isInvalid()) return "<invalid loc>";
> +  if (isInvalid(Loc, Invalid)) return "<invalid loc>";
>
>  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
>  }
>




More information about the cfe-commits mailing list