Skip to content

3C inserts cast into unwritable inline function body that calls function pointer with itype #423

Open
@john-h-kastner

Description

@john-h-kastner

Running 3c stdlib_checked.h -- -O2 gives an error

In file included from /home/cc/checkedc/include/stdlib_checked.h:14:
In file included from /usr/include/stdlib.h:825:
/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:1:1: error: 3C internal error: 3C generated changes to this file even though it is not allowed to write to the file (https://github.com/correctcomputation/checkedc-clang/issues/387)
/* Perform binary search - inline version.
^
/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:1:1: note: use the -dump-unwritable-changes option to see the new version of the file
1 error generated.

This error is currently affecting the benchmark programs tested in our actions repository. -O2 makes gcc set __USE_EXTERN_INLINES which causes the definition for bsearch to be inlined in the stdlib.h. 3C then tries to insert a cast in the definition which triggers the unwritable change error.

The example below demonstrates the same error.

#define __USE_EXTERN_INLINES
#include <stdlib.h>
_Itype_for_any(T) void *bsearch(const void *key : itype(_Ptr<const T>),
                                const void *base : itype(_Array_ptr<const T>) byte_count(nmemb * size),
                                size_t nmemb, size_t size,
                                int ((*compar)(const void *, const void *)) :
                                  itype(_Ptr<int(_Ptr<const T>, _Ptr<const T>)>)
                                ) : itype(_Ptr<T>);

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions