[LifetimeSafety] Support C compound literals
LifetimeSafety does not fully model C compound literals yet.
Minimal repro:
int *bad(void) {
int *p = &(int){12};
return p; // should warn
}
https://godbolt.org/z/6oPvfr9bn
In C, compound literal has automatic storage duration, so this should behave roughly like returning the address of an unnamed local variable.
Expected: warn that the returned pointer refers to storage that does not live long enough.
This should remain OK however:
int ok(void) {
int *p = &(int){12};
*p = 100;
return *p;
}
@llvm/issue-subscribers-clang-temporal-safety
Author: NeKon69
Minimal repro:
int *bad(void) {
int *p = &(int){12};
return p; // should warn
}
https://godbolt.org/z/6oPvfr9bn
In C, compound literal has automatic storage duration, so this should behave roughly like returning the address of an unnamed local variable.
Expected: warn that the returned pointer refers to storage that does not live long enough.
This should remain OK however:
int ok(void) {
int *p = &(int){12};
*p = 100;
return *p;
}
This appears to be much harder than I initially anticipated as these are not modeled on the CFG level. So this might actually take a while..
I don't plan on working on this for the foreseeable future, there are too much blockers that I encountered while looking for a way to solve this issue.