appleseedlab / maki

A tool for analyzing syntactic and semantic properties of C Preprocessor macros in C programs
9 stars 3 forks source link

Maki outputs an incorrect definition location range for macros using line continuation #69

Closed SilverMight closed 3 weeks ago

SilverMight commented 1 month ago

Given a source file containing a macro definition utilization a line continuation character like this:

#define STRING_LITERAL \
"String literal"

int main() {
    char * a = STRING_LITERAL;
}

Maki will output a definition like this:

  {
    "Kind": "Definition",
    "Name": "STRING_LITERAL",
    "IsObjectLike": true,
    "IsDefinitionLocationValid": true,
    "Body": "\"String literal\"",
    "IsDefinedAtGlobalScope": true,
    "DefinitionLocation": "/home/silvermight/maki/newlinefail.c:1:9",
    "EndDefinitionLocation": "/home/silvermight/maki/newlinefail.c:1:24"
  },

With the EndDefinitionLocation ending at the line continuation character, and not the actual end of the macro (the end of the string literal on the next line).

This causes issues translating some codebases that use this heavily, i.e SQLite3 and Python.

PappasBrent commented 1 month ago

I'm looking into this now, but if this turns out to be an issue with Clang then we could fix this with MerC by just checking if the EndDefinitionLocation points to a backslash-newline, and if so, then just adding the next line to the macro definition.