Skip to content

CUDA frontend: preprocessor expands macros inside /* */ comments #88

@Zaneham

Description

@Zaneham

@
The preprocessor walks straight through /* */ comments doing macro substitution, which it should not be doing. Comments are meant to be opaque to expansion: a macro name that appears inside a comment in the source should stay as literal text, and the comment itself should be stripped (or whitespace-replaced) before any expansion happens.

The way this currently bites is that any macro whose own definition has a trailing /* ... */ comment will, when expanded inside another comment, drag its trailing */ into the outer comment and close it early. Everything after the early close gets parsed as code, usually as a torrent of E020 "expected ;" errors that look completely unrelated to comments. Took a while to spot in the soft-float runtime because the macros and the comments referencing them are several headers apart.

Repro: runtime/soft_fp.c includes runtime/soft_fp_internal.h which defines #define SFP_MANT_BITS 23 /* explicit mantissa bits */ and then has a doc-comment further down that references SFP_MANT_BITS. Run barracuda --pp -I runtime runtime/soft_fp.c | sed -n /SFP_MANT_BITS/p and youll see the macro expanded inside the doc-comment, trailing comment and all. Fix is to teach the preprocessor to skip comment regions during expansion the same way it already does during directive parsing.
@

Metadata

Metadata

Assignees

No one assigned

    Labels

    CUDACUDA frontend and CUDA-specific behaviourbugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions