Git Product home page Git Product logo

Comments (2)

xavierleroy avatar xavierleroy commented on June 18, 2024

This is one aspect where CompCert sticks to the ISO C standard.

A pointer value with static pointer type can be "casted" to a large enough integer type, but any arithmetic operation over the resulting pointer value with integer type is undefined. The only safe operation that can be done over such a value is casting it back to a pointer type. You can check this aspect of the CompCert C formal semantics using the reference interpreter (ccomp -interp).

Evaluation of compile-time constant expressions, in global initializers and elsewhere, is done essentially like the reference interpreter, following the formal semantics. Hence, the initializer above is reported as a compile-time error, because it corresponds to undefined run-time behavior.

GCC and Clang are more lenient, probably because they have an execution model in mind that is more lenient than the ISO C standard concerning arithmetic on pointer values having static integer type. I don't think CompCert can go this way, though, because it would break abstraction properties of pointer values that are necessary for correct compilation.

from compcert.

 avatar commented on June 18, 2024

Thank you very much for the explanation.

Indeed, in the original code, such operations seem reasonable for GCC/Clang because they reference offsets inside array variables, e.g.:

unsigned long a[10];
unsigned long b = {(unsigned long)a+1}; // or +3, +5, +7...

It seems such accesses are voluntarily misaligned, but always inside the bounds of the array, so in practice there is no overflow here, but it deviates from the standard nevertheless.

from compcert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.