Open
Description
When a function prototype in a header file occurs in both branches of an #ifdef
conditional, it is only rewritten to the correct checked type in one branch even if both branches are expanded by at different times when the header is included in different files.
In the example below, only the #else
branch is rewritten. Since a.c
takes the #if
branch, it sees an unchecked prototype, causing a compiler error.
This pattern is used by yacr2
in the ptrdist
benchmark.
Example:
a.c:
#define FOO
#include "test.h"
int *fn(void) {
return 0;
}
void testa() {
int *a = fn();
}
b.c:
include "test.h"
void testb() {
int *a = fn();
}
test.h:
#ifdef FOO
int *fn(void);
#else
int *fn(void);
#endif
Conversion with 3c --output-postfix=checked a.c b.c test.h
a.checked.c:
#define FOO
#include "test.h"
_Ptr<int> fn(void) {
return 0;
}
void testa() {
_Ptr<int> a = fn();
}
b.checked.c:
include "test.h"
void testb() {
_Ptr<int> a = fn();
}
test.checked.h:
#ifdef FOO
int *fn(void);
#else
_Ptr<int> fn(void);
#endif