-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.miscompilation
Description
The following program demonstrates this issue:
#include<stdio.h>
int main(){
static const char X[]="main";
printf("%i\n",__func__=="main");
printf("%i\n",X=="main");
}
Clang prints 1 then 0 with this program, when it should print 0 then 0.
The identifier __func__ shall be implicitly declared by the translator as if, immediately following
the opening brace of each function definition, the declarationstatic const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.
Section 6.4.2.2 "Predefined identifiers" Paragraph 1 ISO/IEC 9899:2024
Unlike C++, C doesn't say that __func__ can share addresses with string literals so __func__=="main"
should be zero for the same reason that X=="main"
is zero.
dtcxzyw
Metadata
Metadata
Assignees
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.miscompilation