[cfe-dev] RFC: range attribute

Xi Wang xi.wang at gmail.com
Wed Aug 22 13:23:15 PDT 2012


Hi,

User-supplied range information would be useful for both static analyzers and optimizers.  For static analyzers, the information can be used to reduce false positives if the developer knows the physical limit of some variables.  For the backend, the information can provide more precise value ranges for optimizations.

How about a new range attribute that allows developers to annotate range information?

Here's a prototype implementation that adds the range attribute to clang and emits range metadata.

  https://github.com/xiw/clang/compare/range

Here's an example.

  struct A {
      int x;
      int y __attribute__((range(100, 200)));
  };

  int z __attribute__((range(250, 500)));

  int foo(struct A *a)
  {
      return a->y + z;
  }

// CHECK: load i32* %y, align 4, !range !0
// CHECK: load i32* @z, align 4, !range !1

// CHECK: !0 = metadata !{i32 100, i32 201}
// CHECK: !1 = metadata !{i32 250, i32 501}

One bummer is that !range can only be attached to load instructions, and thus the patch doesn't support range attributes on function return values (or parameters).  Maybe we can generate some module metadata instead?

- xi



More information about the cfe-dev mailing list