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

Error on converting function with Nt_array_ptr itype #179

Closed dopelsunce closed 4 years ago

dopelsunce commented 4 years ago

Given test.c which is already converted:

void bar(char *a: itype(_Nt_array_ptr<char>)) {
    _Nt_array_ptr<char> b = a;
}
cconv-standalone test.c

Output:

/home/yahui/work/checkedc-musl/test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
1 error generated.
Error while processing /home/yahui/work/checkedc-musl/test.c.
/home/yahui/work/checkedc-musl/test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
1 error generated.
Error while processing /home/yahui/work/checkedc-musl/test.c.
/home/yahui/work/checkedc-musl/test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
void bar(char* a : itype(_Nt_array_ptr<char>)) {
    _Nt_array_ptr<char> b = ((void *)0) = a;
}
1 error generated.
Error while processing /home/yahui/work/checkedc-musl/test.c.

I expect no errors because test.c is valid Checked C code.

Here is the full output with --dump-intermediate option:

/home/yahui/work/checkedc-musl/test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
1 error generated.
Error while processing /home/yahui/work/checkedc-musl/test.c.
CONSTRAINTS: 
ENVIRONMENT: 

Constraint Variables
/home/yahui/work/checkedc-musl/test.c:1:6=>[ ( {  } ) bar ( { NTARR  } ) ]
/home/yahui/work/checkedc-musl/test.c:1:16=>[ { NTARR  } ]
/home/yahui/work/checkedc-musl/test.c:2:25=>[ { NTARR  } ]
External Function Definitions
Func Name:bar => [ ( {  } ) bar ( { NTARR  } ) ]

Static Function Definitions
Writing json output to:constraint_output.json_initial_constraints.json
Writing json output to:constraint_output.json_final_output.json
/home/yahui/work/checkedc-musl/test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
1 error generated.
Error while processing /home/yahui/work/checkedc-musl/test.c.
/home/yahui/work/checkedc-musl/test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
void bar(char* a : itype(_Nt_array_ptr<char>)) {
    _Nt_array_ptr<char> b = ((void *)0) = a;
}
1 error generated.
Error while processing /home/yahui/work/checkedc-musl/test.c.

I noticed the tool runs without errors if I replace nt_array_ptr with array_ptr:

void foo(char *a: itype(_Array_ptr<char>)) {
    _Array_ptr<char> b = a;
}
dopelsunce commented 4 years ago

It looks like a bug in the compiler. Compiling the above code with clang from the BigRefactor branch gives the same error:

test.c:2:25: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
    _Nt_array_ptr<char> b = a;
                        ^   ~
1 error generated.

But the code compiles under clang from microsoft:master branch. So I guess this was fixed upstream?

mwhicks1 commented 4 years ago

Did you try this with the mainline Checked C clang ? The code you typed in at the top is straight Checked C, so the porting tool shouldn't do anythnig.

dopelsunce commented 4 years ago

Yes, the mainline checked-c clang compiles it without any error. The clang from plum-umd/BigRefactor branch emits the above error.

Not familiar with the porting tool. It seems it invoked clang in the conversion process.

mwhicks1 commented 4 years ago

@Machiry Can we update our clang to match Microsoft's ?

Machiry commented 4 years ago

@mwhicks1 Will try to do by this weekend. Meanwhile, @dopelsunce Can you try to use: BigRefactor_Merging, it has all the changes from Microsoft's clang.

dopelsunce commented 4 years ago

@Machiry I tried the latest Bigfactor_Merging and still got this error.

mwhicks1 commented 4 years ago

@dopelsunce It might be that you have not properly re-built clang in this branch. I had the problem that when I switched to it and rebuilt, CLion did not properly rebuild clang. I had to clear all my previous work and build everything from scratch.

Machiry commented 4 years ago

@dopelsunce Can you please check with BigRefactor_master. The BigRefactor_Merging had issues which are now fixed. Also, as Mike suggested, please rebuild clang along with the tool.

Btw for faster Checked C builds, while building try to use ninja and restrict the targets (to X86) to build, specifically,

cmake -G Ninja -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_RTTI=ON -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" <llvm_folder>
dopelsunce commented 4 years ago

I tried BigRefactor_master and I did not observe this error. Thanks!