[PATCH] D26054: Use `getFileLoc()` instead of `getSpellingLoc()` in the ASTImporter

Rafael Stahl via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 09:28:49 PDT 2018


r.stahl added a comment.
Herald added a subscriber: martong.

I encountered an issue caused by this change.

In the scenario as shown below the call to getFileLoc causes the startLoc of the BinaryOp to be after the endLoc, because the LHS (`s->a`) is located in the marco argument while the RHS (`0`) is located at the beginning of the marco. See below: `BinaryOperator 0x12f45b8 <col:13, col:5>`

This is an issue because the diagnostics machinery asserts on correctly ordered sourceranges. Namely:

`llvm/tools/clang/lib/Frontend/TextDiagnostic.cpp:1015: void highlightRange(const clang::CharSourceRange&, unsigned int, clang::FileID, const {anonymous}::SourceColumnMap&, std::__cxx11::string&, const clang::SourceManager&, const clang::LangOptions&): Assertion 'StartColNo <= EndColNo && "Invalid range!"' failed.`

I have tested the solution proposed by @a.sidorin and it works for my tests and the regression tests still pass.

code:

  01|#include <stdint.h>
  02|
  03|
  04|#define CLR_BIT(reg)     (reg = 0)
  05|
  06|
  07|struct S
  08|{
  09|    int a;
  10|};
  11|
  12|int foo()
  13|{
  14|    struct S *s = 0x80008000;
  15|    CLR_BIT(s->a);
  16|}

original:

  `-FunctionDecl 0xd29850 <line:12:1, line:16:1> line:12:5 foo 'int ()'
    `-CompoundStmt 0xd312d8 <line:13:1, line:16:1>
      |-DeclStmt 0xd311e0 <line:14:5, col:29>
      | `-VarDecl 0xd299e0 <col:5, col:19> col:15 used s 'struct S *' cinit
      |   `-ImplicitCastExpr 0xd29a60 <col:19> 'struct S *' <IntegralToPointer>
      |     `-IntegerLiteral 0xd29a40 <col:19> 'unsigned int' 2147516416
      `-ParenExpr 0xd312b8 <line:4:26, col:34> 'int'
        `-BinaryOperator 0xd31290 <line:15:13, line:4:33> 'int' '='
          |-MemberExpr 0xd31238 <line:15:13, col:16> 'int' lvalue ->a 0xd297b8
          | `-ImplicitCastExpr 0xd31220 <col:13> 'struct S *' <LValueToRValue>
          |   `-DeclRefExpr 0xd311f8 <col:13> 'struct S *' lvalue Var 0xd299e0 's' 'struct S *'
          `-IntegerLiteral 0xd31270 <line:4:33> 'int' 0

imported:

  `-FunctionDecl 0x12f4218 prev 0x12f3fa0 <line:12:1, line:16:1> line:12:5 used foo 'int ()'
    `-CompoundStmt 0x12f4600 <line:13:1, line:16:1>
      |-DeclStmt 0x12f4508 <line:14:5, col:29>
      | `-VarDecl 0x12f4470 <col:5, col:19> col:15 used s 'struct S *' cinit
      |   `-ImplicitCastExpr 0x12f44f0 <col:19> 'struct S *' <IntegralToPointer>
      |     `-IntegerLiteral 0x12f44d0 <col:19> 'unsigned int' 2147516416
      `-ParenExpr 0x12f45e0 <line:15:5> 'int'
        `-BinaryOperator 0x12f45b8 <col:13, col:5> 'int' '='
          |-MemberExpr 0x12f4560 <col:13, col:16> 'int' lvalue ->a 0x12f4378
          | `-ImplicitCastExpr 0x12f4548 <col:13> 'struct S *' <LValueToRValue>
          |   `-DeclRefExpr 0x12f4520 <col:13> 'struct S *' lvalue Var 0x12f4470 's' 'struct S *'
          `-IntegerLiteral 0x12f4598 <col:5> 'int' 0


https://reviews.llvm.org/D26054





More information about the cfe-commits mailing list