Ericsson / clang

Cross Translation Unit analysis capability for Clang Static Analyzer. (Fork of official clang at http://llvm.org/git/clang)
http://clang.llvm.org/
Other
15 stars 10 forks source link

Fix infinite recursion in macro expansion #591

Closed bruntib closed 5 years ago

bruntib commented 5 years ago

define f(y) x define x f(x)

This example results a preprocessor error since "x" in the first line was not defined earlier. However, the macro expression printer goes to an infinite recursion on this example.

dkrupp commented 5 years ago

Can one of the admins verify this patch?

bruntib commented 5 years ago

Me too, I'd require the author to check this fix. For example I don't know if there is a better identification of tokens besides their names. @Szelethus

Szelethus commented 5 years ago

Thank you so much for taking care of this!

Instead of gathering strings, we'd be better off with storing const IdentifierInfos. You can see taht the main loop that iterates over the macro expansion's tokens has an if (Tok.is(tok::identifieer)) statement, meaning that the code it guards ensures that

Szelethus commented 5 years ago

Also, please include a test if it's feasible. Does check-clang-analysis run cleanly?

martong commented 5 years ago

Can one of the admins verify this patch?

run tests

martong commented 5 years ago

@bruntib

Can one of the admins verify this patch?

This is just a message from Jenkins, Dani is still on the ski slopes I think :D

Szelethus commented 5 years ago

Well, I'm not listed as a reviewer, but this LGTM. Thanks!

bruntib commented 5 years ago

@Szelethus thanks for the review comments. At the time of creating this pull request, you were not a collaborator to this repository, and I couldn't add you. I meant you as the author of the macro feature.

@martong I run the tests with make check-clang. I haven't created test for this specific recursive case. The goal for now is to include this fix in our internal test frameworks which is scheduled at 21:00.

martong commented 5 years ago

@bruntib @Szelethus just added you to the collaborators