Skip to content

u'...' character constants are converted to unsigned int instead of being promoted to int #623

Open

Description

@alpaylan

A u'...' constant has type char16_t (unsigned short in CompCert). In an expression it should be promoted to
int (C11 6.3.1.1p2), but CompCert treats it as unsigned int:

#include <stdio.h>
int main(void) {
  printf("%d\n", u'0' < -1);              /* expected 0 */
  printf("%lld\n", (long long)-u'A');     /* expected -65 */
  return 0;
}
$ ccomp t.c && ./a.out
1
4294967231
$ ccomp -interp -quiet t.c
1
4294967231
$ gcc -std=c11 t.c && ./a.out      # gcc 15.2.0
0
-65
$ clang -std=c11 t.c && ./a.out    # clang 21.1.8
0
-65

Tested on master (2685140), x86-64.

Found by differential testing with Ephyra: generated C programs, CompCert
against gcc and clang.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions