-
Notifications
You must be signed in to change notification settings - Fork 80
Closed
Labels
work itemThis labels issues that are not exactly bugs but are about improvements.This labels issues that are not exactly bugs but are about improvements.
Description
We cannot allow static variables to have types with free type variables. The storage for static variables in generic functions persists and could be used with different generic type instantiations. This creates a soundness issue.
Here is an example of how things can go wrong:
#include <stdbool.h>
#include <stdio.h>
_For_any(T) _Ptr<T> get_set(int isSetter, _Ptr<T> val) {
static _Ptr<T> capture;
if (isSetter) {
capture = val;
return 0;
}
else
return capture;
}
int main(int argc, _Array_ptr<_Nt_array_ptr<char>> argv : count(argc)) {
short j = 0;
short i = 1;
get_set<short>(true, &i);
_Ptr<double> p = get_set<double>(false, 0);
*p = 3.141516; // corrupt memory
printf(" j = %d", j);
}
When compiled by the Checked C clang compiler on Windows x64,, the store through p overwrites j. Here is the output.
D:\checkedc1\llvm\tools\clang\test\CheckedC>a.exe
j = 9214
abeln
Metadata
Metadata
Assignees
Labels
work itemThis labels issues that are not exactly bugs but are about improvements.This labels issues that are not exactly bugs but are about improvements.