<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Can't test for __builtin_offsetof"
href="https://llvm.org/bugs/show_bug.cgi?id=31178">31178</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Can't test for __builtin_offsetof
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sitsofe@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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:
<a href="http://clang.llvm.org/docs/LanguageExtensions.html#has-builtin">http://clang.llvm.org/docs/LanguageExtensions.html#has-builtin</a> 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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>