correctcomputation / checkedc-clang

This is the primary development repository for 3C, a tool for automatically converting legacy C code to the Checked C extension of C, which aims to enforce spatial memory safety. This repository is a fork of Checked C's.
14 stars 5 forks source link

Global array degrades to pointer if unused #167

Closed dopelsunce closed 4 years ago

dopelsunce commented 4 years ago

Hi, nice tool! Not sure if my configuration is correct, but I encountered this issue.

int a[10];

Gets translated to the following if a is in the external scope and not used in the code:

_Ptr<int> a;

But I expect a to keep its size, regardless of whether it is used:

int a _Checked[10];

Similarly, int a[] = { 1 }; gets translated to _Ptr<int> a = { 1 };. The latter triggers a compiler error:

test1.checked.c:1:20: error: initializing '_Ptr<int>' with an expression of incompatible type 'int'
_Ptr<int> arr =  { 1 };
                   ^

I'm using the BigRefactor branch, with -alltypes enabled.

sroy4899 commented 4 years ago

Can you paste the exact command you're using? On my machine, when I run the tool with the flag -alltypes on the following code:

int a[10]; 
int b[] = {1};

it converts to:

int a _Checked[10]; 
int b _Checked[1] =  {1};

Running without -alltypes enabled results in no conversion occurring.

dopelsunce commented 4 years ago

Never mind, I invoked cconv-standalone from the wrong path so I was using the old version checked into the master branch. I was able to get the same results as yours after fixing the path.

Thanks!