CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

"Switch constants must all be same type as switch value!" #125

Closed trasz closed 7 years ago

trasz commented 7 years ago

Trying to build nginx with the new LLVM fails like this:

src/http/ngx_http_script.c:753:50: warning: binary expression on capability and non-capability types: '__uintcap_t' and 'unsigned long'. Provenance will be inherited from left-hand side [-Wcheri-capability-misuse]
          + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~
Switch constants must all be same type as switch value!
  switch i64 %84, label %sw.epilog [
    i64 0, label %sw.bb
    i256 2, label %sw.bb
    i256 4, label %sw.bb
    i256 6, label %sw.bb
    i64 1, label %sw.bb51
    i256 3, label %sw.bb51
    i256 5, label %sw.bb51
    i256 7, label %sw.bb51
  ], !dbg !3817
fatal error: error in backend: Broken function found, compilation aborted!
clang-5.0: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 5.0.0 (https://github.com/CTSRD-CHERI/clang.git 13f7cc38d2bc821f3f7e0162fd9e586dbb3fb703) (https://github.com/CTSRD-CHERI/llvm.git 926e17c1b5d5110aef32be6b0c7c98054a08c448)

https://gist.github.com/trasz/d0dde7c94685b412f8dba56783a35822

brooksdavis commented 7 years ago

Probably not very related to the crash, but you will want to fix the warning. It's rather bizarre that they are using uintptr_t for a length, but I'd probably just cast it to size_t. It is conceivable that the problem is related to their overuse of uintptr_t.

davidchisnall commented 7 years ago

This looks as if it's coming from this source code:

        switch (code->op) {

        case ngx_http_script_file_plain:
        case ngx_http_script_file_dir:
        case ngx_http_script_file_exists:
        case ngx_http_script_file_exec:
             goto false_value;

        case ngx_http_script_file_not_plain:
        case ngx_http_script_file_not_dir:
        case ngx_http_script_file_not_exists:
        case ngx_http_script_file_not_exec:
             goto true_value;
        }

I can't manage to turn this into a reduced test case.

davidchisnall commented 7 years ago

It appears that after updating, there is a trivial reproducer for this:

int x(__intcap_t y)
{
    switch (y)
    {
        case 1: return 4;
    }
    return 1;
}

This is a simplified version of a test in the clang test suite, so I'm not sure why it's not working.

trasz commented 7 years ago

I'm still seeing this problem, with:

clang version 5.0.0 (https://github.com/CTSRD-CHERI/clang.git 55e094b2ebad134d775654e0989215476dd4a1ff) (https://github.com/CTSRD-CHERI/llvm.git 926e17c1b5d5110aef32be6b0c7c98054a08c448)