summaryrefslogtreecommitdiffstats
path: root/clang/test/PCH/exprs.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-04-28 22:16:22 +0000
committerDouglas Gregor <dgregor@apple.com>2010-04-28 22:16:22 +0000
commit882211c1da17254908e6b36d6e5d4e425f224347 (patch)
treef2f975514865d2ed37eac79a5e787fe5803a6432 /clang/test/PCH/exprs.h
parent0dec1e0d56c3bbccf7d61323fb2939f475ad9a0b (diff)
downloadbcm5719-llvm-882211c1da17254908e6b36d6e5d4e425f224347.tar.gz
bcm5719-llvm-882211c1da17254908e6b36d6e5d4e425f224347.zip
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini. This change introduces a new expression node type, OffsetOfExpr, that describes __builtin_offsetof. Previously, __builtin_offsetof was implemented using a unary operator whose subexpression involved various synthesized array-subscript and member-reference expressions, which was ugly and made it very hard to instantiate as a template. OffsetOfExpr represents the AST more faithfully, with proper type source information and a more compact representation. OffsetOfExpr also has support for dependent __builtin_offsetof expressions; it can be value-dependent, but will never be type-dependent (like sizeof or alignof). This commit introduces template instantiation for __builtin_offsetof as well. There are two major caveats to this patch: 1) CodeGen cannot handle the case where __builtin_offsetof is not a constant expression, so it produces an error. So, to avoid regressing in C, we retain the old UnaryOperator-based __builtin_offsetof implementation in C while using the shiny new OffsetOfExpr implementation in C++. The old implementation can go away once we have proper CodeGen support for this case, which we expect won't cause much trouble in C++. 2) __builtin_offsetof doesn't work well with non-POD class types, particularly when the designated field is found within a base class. I will address this in a subsequent patch. Fixes PR5880 and a bunch of assertions when building Boost.Python tests. llvm-svn: 102542
Diffstat (limited to 'clang/test/PCH/exprs.h')
-rw-r--r--clang/test/PCH/exprs.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/test/PCH/exprs.h b/clang/test/PCH/exprs.h
index 7012422aad3..5af8c7c1a90 100644
--- a/clang/test/PCH/exprs.h
+++ b/clang/test/PCH/exprs.h
@@ -25,6 +25,19 @@ typedef typeof('a') char_literal;
// UnaryOperator
typedef typeof(-Enumerator) negate_enum;
+// OffsetOfExpr
+struct X {
+ int member;
+};
+struct Y {
+ struct X array[5];
+};
+struct Z {
+ struct Y y;
+};
+typedef typeof(__builtin_offsetof(struct Z, y.array[1 + 2].member))
+ offsetof_type;
+
// SizeOfAlignOfExpr
typedef typeof(sizeof(int)) typeof_sizeof;
typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
OpenPOWER on IntegriCloud