Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang preprocessor crashes when using -E -CC option on MFC code. #10525

Closed
llvmbot opened this issue Jun 19, 2011 · 7 comments
Closed

clang preprocessor crashes when using -E -CC option on MFC code. #10525

llvmbot opened this issue Jun 19, 2011 · 7 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Member

llvmbot commented Jun 19, 2011

Bugzilla Link 10153
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @akyrtzi,@ismail

Extended Description

If you are trying to get the preprocessed output file of a MFC file using the -E -CC options, clang will crash.

Here is a reduction:
test.cpp:
#define A text//\

clang -E -CC test.cpp

@llvmbot
Copy link
Member Author

llvmbot commented Aug 17, 2011

*** Bug llvm/llvm-bugzilla-archive#10683 has been marked as a duplicate of this bug. ***

@llvmbot
Copy link
Member Author

llvmbot commented Aug 18, 2011

It has nothing to do with MFC though. Any file containing "//" with an empty line afterwards will cause a crash.

@llvmbot
Copy link
Member Author

llvmbot commented Aug 22, 2011

This code:
// \
int a; //dead line

Will be preprocessed as:
// int a; //dead line

Thus the second line is lost.

@akyrtzi
Copy link
Contributor

akyrtzi commented Dec 21, 2011

Fixed in r147091.

@llvmbot
Copy link
Member Author

llvmbot commented Aug 5, 2015

The bug is active in clang 3.6.2. This code:

int main(int argc, char* argv[]) {
//
int a; //dead line
int b;
return 0;
}

is preprocessed as:

int main(int argc, char* argv[]) {

int b;
return 0;

}

@llvmbot
Copy link
Member Author

llvmbot commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#10683

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Endilll
Copy link
Contributor

Endilll commented May 22, 2023

Crash was indeed fixed in Clang 3.1: https://godbolt.org/z/cGrxoe5fn

As for the last example:

int main(int argc, char* argv[]) {
	// \
	int a; //dead line
	int b;
	return 0;
}

per N4944.lex.phases, backslashes are processed during the second phase, whereas comments are processed during the third phase. Which means int a; //dead line becomes a part of the previous line // before compiler recognizes comments to skip over them. There's no implementation divergence on this, save for MSVC /C (preserve comments) mode: https://godbolt.org/z/PYYhhdjKb

@Endilll Endilll closed this as completed May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants