Feature request: C intrinsics for overflow detection

LLVM has the llvm.*.with.overflow.* intrinsics. Can these be exposed
to C code? I imagine this would be straightforward, aside from the
obligatory bikeshedding about exactly what the interface should be.

This would eliminate a lot of nasty hacks used to check for overflow,
especially for multiplication overflow. I currently write this stuff
in inline x86 assembler -- ugh! And maybe gcc would go along if clang
paved the way :slight_smile:

--Andy

You mean something like the __builtin_[u]add[ll]_overflow intrinsics?

– Steve

They are exposed:
http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins

… but that’s not indexed by Google. Maybe this is the problem?
http://clang.llvm.org/robots.txt:

User-agent: *
Disallow:

See: http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins

David

Is this what you are looking for:

http://llvm.org/releases/3.4/tools/clang/docs/LanguageExtensions.html#checked-arithmetic-builtins

Tobias

That's exactly what I'm looking for, and it's also probably why I
couldn't find it. I did try. Thanks!

As promised: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61129

--Andy

They are exposed:

http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins

... but that's not indexed by Google. Maybe this is the problem?
http://clang.llvm.org/robots.txt:
User-agent: *
Disallow:

That's an 'allow everything' robots.txt. The results are there; try
searching for: "__builtin_uadd_overflow" clang

The problem is that searching for things like "clang overflow
detection" returns a bunch of results that look like they would have
suggested using the intrinsics if they existed, so I assumed that they
didn't.

Yeah, I was pretty sure I was crazy. I guess LanguageExtensions.html is
just ranked very, very poorly.

    They are exposed:
    http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins

    ... but that's not indexed by Google. Maybe this is the problem?
    http://clang.llvm.org/robots.txt:
    User-agent: *
    Disallow:

That's an 'allow everything' robots.txt. The results are there; try searching for: "__builtin_uadd_overflow" clang

I've found Bing yields *far* better results for compiler-related technical searches. Definitely worth changing habits and checking out for a few days:

   http://www.bing.com/search?q=builtin_uadd_overflow (54 results)

   https://www.google.com/#q=builtin_uadd_overflow (0 results)

I'm not sure why but Google search seems to expect an exact match for many of the constructs one encounters in C and C++ so you rarely get pertinent results. I was talking with a Google search engineer and they said their focus is on the most popular consumer searches so perhaps that's the reason.

Cheers
Alp.

For me, at least, none of them were clang-related. Not sure if Bing has learned from your previous searches. Many of them were about overflowing sewage. There were some stack overflow questions that eventually led to the right place if you followed enough links.

However, DuckDuckGo provides very good results for this query:

https://duckduckgo.com/?q=builtin_uadd_overflow

The second hit is the mailing list discussion on adding the builtins, the third is the clang 3.5 documentation and the fifth is the clang 3.4 documentation. If you add the two leading underscores, then the clang links move to positions 1 and 2.

DDG also indexes a few domain-specific search engines and suggests a few for this search that might have results with a higher signal-to-noise ratio.

David