Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Better cycle detection #298

Closed
jyn514 opened this issue Feb 26, 2020 · 1 comment · Fixed by #310
Closed

Better cycle detection #298

jyn514 opened this issue Feb 26, 2020 · 1 comment · Fixed by #310
Labels
preprocessor Issue in the preprocessor (probably cycle detection)

Comments

@jyn514
Copy link
Owner

jyn514 commented Feb 26, 2020

See http://port70.net/~nsz/c/c11/n1570.html#6.10.3.4, especially

2 If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file's preprocessing tokens), it is not replaced. Furthermore, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later (re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced.

Examples of cycles that should be detected:

// from real code in <signal.h> !!
#define sa_handler   __sa_handler.sa_handler
#define sa_sigaction __sa_handler.sa_sigaction
int main() {
    struct sigaction handler;
    handler.sa_handler = 0;
}

See also #5

@jyn514
Copy link
Owner Author

jyn514 commented Feb 26, 2020

Proposed algorithm:

In https://github.com/jyn514/rcc/blob/master/src/lex/cpp.rs#L523, instead of always adding a token to self.pending, decide whether or not the token should undergo further replacement. If not, add a CppToken::NoReplacement to self.pending; otherwise add CppToken::Token

jyn514 added a commit that referenced this issue Feb 29, 2020
jyn514 added a commit that referenced this issue Feb 29, 2020
@jyn514 jyn514 added the preprocessor Issue in the preprocessor (probably cycle detection) label Mar 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
preprocessor Issue in the preprocessor (probably cycle detection)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant