Skip to content

Macro expander fails on preprocessor directives inside block comment in bh #615

Open
@mattmccutchen-cci

Description

@mattmccutchen-cci

bh (in Olden) has a block comment containing preprocessor directives:

/********
#define global extern
#include "defs.h"
#include "code.h"
#include "mem-ref.h"
*********/

The preprocessor removes the entire block comment, but then the macro expander adds back the directives as it normally does: it's not smart enough to realize that they were commented out. This causes a verification failure because the #include directives point to files that do not exist in the current version of bh: presumably that's why they had been commented out!

A possible workaround is to have the macro expander use the -C option to clang -E to preserve comments. It still won't know any better than to think that the directives are real directives that it should force to be preserved, but the preprocessor will keep the /* ... */ around them, so it won't matter. This is starting to illustrate the design fragility of the macro expander: while adding -C sets off a chain of events that leads to the desired end result in this case, it equally well might break other edge cases. Fortunately, the built-in verification ensures that we are notified of any problem right away rather than silently getting wrong results, so maybe I can just test the change on the benchmark workflow and we'll be satisfied if that passes.

Other benefits of adding -C:

  • It will preserve the /**/ comments that we added to some benchmarks to work around correctcomputation/C3#10, so we'll no longer have to patch those comments using sed in the analyse-conv makefile.
  • In general, keeping comments probably makes things nicer for the user if they have to read the macro-expanded code for troubleshooting and by keeping irrelevant comment removals out of the diffs the user has to review during the proposed textual merge workflow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions