aboutsummaryrefslogtreecommitdiff
path: root/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-01-29 15:56:48 +0000
committerAnders Carlsson <andersca@mac.com>2008-01-29 15:56:48 +0000
commit5a1deb8d9c0722beae28d693fa137bbb942bd11f (patch)
tree6e1ad85c4c4c2057d736bea1684fd64196a77562 /CodeGen/CGExprConstant.cpp
parent12fe558612303cb2188c321a77a21f7df23b6ae8 (diff)
Implement __builtin_offsetof.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CGExprConstant.cpp')
-rw-r--r--CodeGen/CGExprConstant.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/CodeGen/CGExprConstant.cpp b/CodeGen/CGExprConstant.cpp
index 3b1c62bb16..e03db991c4 100644
--- a/CodeGen/CGExprConstant.cpp
+++ b/CodeGen/CGExprConstant.cpp
@@ -235,6 +235,15 @@ public:
llvm::Constant *VisitUnaryAddrOf(const UnaryOperator *E) {
return EmitLValue(E->getSubExpr());
}
+ llvm::Constant *VisitUnaryOffsetOf(const UnaryOperator *E) {
+ int64_t Val = E->evaluateOffsetOf(CGM.getContext());
+
+ assert(E->getType()->isIntegerType() && "Result type must be an integer!");
+
+ uint32_t ResultWidth = static_cast<uint32_t>(
+ CGM.getContext().getTypeSize(E->getType(), SourceLocation()));
+ return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
+ }
// Binary operators
llvm::Constant *VisitBinOr(const BinaryOperator *E) {