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

3c does not rewrite vector types correctly #381

Open Machiry opened 3 years ago

Machiry commented 3 years ago

Steps:

git clone git@github.com:randy408/libspng.git libspng

./3c -alltypes -dump-intermediate -extra-arg-before=-DSPNG_STATIC -base-dir="<path_to_repo>/libspng" <path_to_repo>/libspng/spng.c --

Error:

clang/lib/3C/ConstraintResolver.cpp:586: CSetBkeyPair ConstraintResolver::getExprConstraintVars(clang::Expr*): Assertion `"InitlistExpr of type other than array or pointer in " "getExprConstraintVars" && ILE->getType()->isPointerType()' failed.
 #0 0x000055a6094530eb llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/r3x/griller/3c/checkedc-clang/llvm/lib/Support/Unix/Signals.inc:533:0
 #1 0x000055a60945317e PrintStackTraceSignalHandler(void*) /home/r3x/griller/3c/checkedc-clang/llvm/lib/Support/Unix/Signals.inc:594:0
 #2 0x000055a609451058 llvm::sys::RunSignalHandlers() /home/r3x/griller/3c/checkedc-clang/llvm/lib/Support/Signals.cpp:68:0
 #3 0x000055a609452aa2 SignalHandler(int) /home/r3x/griller/3c/checkedc-clang/llvm/lib/Support/Unix/Signals.inc:385:0
 #4 0x00007f8beb509980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007f8bea3befb7 raise /build/glibc-S9d2JN/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007f8bea3c0921 abort /build/glibc-S9d2JN/glibc-2.27/stdlib/abort.c:81:0

The target function _mm_setzero_si64 is: in: cmake-build-debug/lib/clang/9.0.0/include/mmintrin.h

static __inline__ __m64 __DEFAULT_FN_ATTRS
_mm_setzero_si64(void)
{
    return __extension__ (__m64){ 0LL };
}

The function is returning vector type but we do not handle vector types (which should be handled in the same way as record types).

mwhicks1 commented 3 years ago

Where is the vector type? Are vector types actually supported by the Checked C clang compiler (e.g., could it compile this libspng with no changes) ?

Machiry commented 3 years ago

Yes, compilation with clang works fine with original libspng. At AST level, what we see is a vector type for the return type of _mm_setzero_si64 and we do not handle them. We only look for structtype and these vector types should also be handled as structure types.

These are mmx types (x86 SIMD instructions operate on these types)

aaronjeline commented 3 years ago

633 Fixes the crash but does not address rewriting vector types

mattmccutchen-cci commented 2 years ago

633 Fixes the crash but does not address rewriting vector types

I attempted to update the issue title to reflect this. I haven't verified the current state myself.