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

Type variable insertion bug when converting icecast #315

Closed john-h-kastner closed 3 years ago

john-h-kastner commented 3 years ago

An issue encountered by aravind while evaluating 3c on icecast.

#!/usr/bin/env bash
CCCDIR=/home/machiry/projects/CheckedC/checkedc-clang
CCONVBIN=/home/machiry/projects/CheckedC/checkedc-clang/llvm/cmake-build-debug/bin/cconv-standalone
wget http://downloads.xiph.org/releases/icecast/icecast-2.4.4.tar.gz
tar -xvzf icecast-2.4.4.tar.gz
cd icecast-2.4.4
./configure
bear make
python ${CCCDIR}/clang/tools/cconv-standalone/utils/cc_conv/convert_project.py --includeDir ${CCCDIR}/llvm/projects/checkedc-wrapper/checkedc/include -p '${CCONVBIN}'  -pr `pwd`

The conversion gives an assertion error:

lib/CConv/ProgramInfo.cpp:936: void ProgramInfo::setTypeParamBinding(clang::CallExpr*, unsigned int, ConstraintVariable*, clang::ASTContext*): Assertion `"Attempting to overwrite type param binding in ProgramInfo." && CallMap.find(TypeVarIdx) == CallMap.end()' failed.

I 've found a minimal example that gives the same crash.

#define buz foo(i); foo(j);

_Itype_for_any(T) void foo(void *x  : itype(_Ptr<T>));

void test() {
  int *i = 0;
  int *j = 0;
  buz
}

I'm not sure that this is exactly the same issue that's showing up in icecast, but the root of the problems should be the same. The type variable insertion code doesn't do a good job handling any possible macros around polymorphic functions.

john-h-kastner commented 3 years ago

Another aspect to this issue. Consider the same example with only one call to foo in the macro.

#define buz foo(i);

_Itype_for_any(T) void foo(void *x  : itype(_Ptr<T>));

void test() {
  int *i = 0;
  buz
}

This runs without error, but inserting the type variable fails silently because the function call is in a macro. This is an error when converting with -addcr because generic functions are required to have argument lists when called in a checked scope.