[llvm-bugs] [Bug 31178] New: Can't test for __builtin_offsetof
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Nov 27 22:35:53 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=31178
Bug ID: 31178
Summary: Can't test for __builtin_offsetof
Product: clang
Version: 3.9
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: sitsofe at yahoo.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
Description of the problem:
It's not possible to test for __builtin_offsetof using __has_builtin.
Steps to reproduce:
1. Create check_offsetof.c:
#include <stdio.h>
#include <stddef.h>
#ifndef __has_builtin // Optional of course.
#define __has_builtin(x) 0 // Compatibility with non-clang compilers.
#endif
struct my_struct {
long long a;
int b;
};
int main(void) {
#if __has_builtin(__builtin_offsetof)
printf("Has __builtin_offsetof\n");
#else
printf("Does NOT have __builtin_offsetof\n");
#endif
printf("__builtin_offsetof(struct my_struct, b): %lu\n",
__builtin_offsetof(struct my_struct, b));
return 0;
}
2. Compile with
clang check_offsetof.c -o check_offsetof
3. Run
./check_offsetof
Expected result:
Compilation error at 2 or output like
Has __builtin_offsetof
__builtin_offsetof(struct my_struct, b): 8
Actual result:
Output like
Does NOT have __builtin_offsetof
__builtin_offsetof(struct my_struct, b): 8
Additional information:
http://clang.llvm.org/docs/LanguageExtensions.html#has-builtin suggests it
should be possible to use __has_builtin to test for a builtin and this works
for things like __builtin_trap just not __builtin_offsetof.
Version information:
clang version 3.9.0 (branches/release_39 280336)
Target: x86_64-unknown-linux-gnu
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161128/afde0b43/attachment.html>
More information about the llvm-bugs
mailing list