Compilers claim support for builtin but compilation fails

nvcc and nvc++ (as well as pgcc and pgc++) return true for __has_builtin(__builthin_expect_with_probability), but if used in code results in undefined reference to __builtin_expect_with_probability’`.

Simple test case:

#if defined(__has_builtin)
#  if __has_builtin(__builtin_expect_with_probability)
#    define FOO_EXPECT(expr, value, probability) __builtin_expect_with_probability((expr), (value), (probability))
#  endif
#endif
#if !defined(FOO_EXPECT)
#  define FOO_EXPECT(expr, value, probability) (expr)
#endif

int main(int argc, char** argv) {
  return FOO_EXPECT(argc & 1, 1, 0.75);
}

This is with 20.7-0 on x86_64.

Sorry for not mentioning which builtin in the title; if I add it I just get a pop-up that says the title doesn’t look like a complete sentence…

Thanks. I was able to reproduce the error here and have added an issue report (TPR#28843). In looking through the compiler source, I do see that we handle this builtin, so it’s unclear what’s wrong with this case. We’ll need a compiler engineer to investigate.

-Mat

1 Like