Skip to content

Omod missing cast in Ceval.ml #565

Description

@bagnalla

CompCert 3.16 master branch
gcc 13.3.0
clang 18.1.3

int main() {
  switch (-1 % 7u) {
    case -1 % 7u:
      return 0;
    default:
      return 1;
  }
}
$ ccomp omod-missing-cast.c && ./a.out; echo $?
1
$ gcc omod-missing-cast.c && ./a.out; echo $?
0
$ clang omod-missing-cast.c && ./a.out; echo $?
0

My understanding is this:

  • Case label -1 % 7u is computed by the constant expression evaluator in cparser/Ceval.ml.
  • Since the RHS is unsigned, the whole operation is unsigned, so the LHS should be promoted to unsigned.
  • The Omod case in Ceval.ml:binop doesn't perform this cast so the LHS value is not normalized to 32-bit unsigned before the operation.

Is this intended? If not, proposed fix is to replace in the Omod case

begin match v1, v2 with

with

begin match cast env tyop v1, cast env tyop v2 with

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