https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87454

            Bug ID: 87454
           Summary: Maybe implement -fsanitize=implicit-integer-truncation
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org,
                    marxin at gcc dot gnu.org, mpolacek at gcc dot gnu.org
  Target Milestone: ---

It's new in LLVM 7.0.0:

  -  ``-fsanitize=implicit-integer-truncation``: Implicit conversion from
     integer of larger bit width to smaller bit width, if that results in data
     loss. That is, if the demoted value, after casting back to the original
     width, is not equal to the original value before the downcast.
     Issues caught by this sanitizer are not undefined behavior,
     but are often unintentional.

Example:

unsigned char store = 0;

bool consume(unsigned int val);

void test(unsigned long val) {
  if (consume(val)) // the value may have been silently truncated.
    store = store + 768; // before addition, 'store' was promoted to int.
  (void)consume((unsigned int)val); // OK, the truncation is explicit.
}

Reply via email to