Created
September 21, 2013 03:20
-
-
Save jedbrown/6646889 to your computer and use it in GitHub Desktop.
Clang 3.3 bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdarg.h> | |
// This function is not actually called, but it must exist in a different compilation unit | |
int X_rank(int *rank); | |
static int ErrorHandlerX(int comm,int line,const char *fun,const char *file,const char *dir,int n,int p,const char *mess) | |
{ | |
int rank; | |
if (comm != 0) X_rank(&rank); | |
if (p) { // p==0 so this branch is not taken, but it must exist | |
printf("%s!\n",mess); | |
} | |
printf("%s() line %d in %s%s\n",fun,line,dir,file); | |
return(n); | |
} | |
// must not be static, must have all arguments, must be variadic | |
int ErrorX(int comm,int line,const char *func,const char *file,const char *dir,int n,int p,const char *mess,...) | |
{ | |
va_list args; | |
char buf[1000]; | |
const char *lbuf = 0; | |
// None of these branches should be taken | |
if (!func) func = "User provided function"; | |
if (!file) file = "NOT THE FILE NAME"; | |
if (!dir) dir = " "; | |
if (comm == 10) comm = 11; | |
if (mess) { | |
strcpy(buf,mess); | |
lbuf = mess; | |
} | |
va_start(args,mess); | |
va_end(args); | |
return ErrorHandlerX(comm,line,func,file,dir,n,p,lbuf); | |
} | |
int main() | |
{ | |
ErrorX(0,__LINE__,__func__,__FILE__,"/dir/",75,0,"Irrelevant Message"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = clang | |
CFLAGS = -Wall -Wextra -pedantic -std=c99 -O1 -g # -O1 or higher needed | |
a.out : a.o xrank.o | |
$(CC) -o $@ $^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int X_rank(int *rank) { | |
*rank = 0; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment