diff options
author | Anders Carlsson <andersca@mac.com> | 2008-01-29 15:56:48 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-01-29 15:56:48 +0000 |
commit | 5a1deb8d9c0722beae28d693fa137bbb942bd11f (patch) | |
tree | 6e1ad85c4c4c2057d736bea1684fd64196a77562 /CodeGen/CGExprScalar.cpp | |
parent | 12fe558612303cb2188c321a77a21f7df23b6ae8 (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/CGExprScalar.cpp')
-rw-r--r-- | CodeGen/CGExprScalar.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index 652729ac27..e1771e80f8 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -213,7 +213,8 @@ public: Value *VisitUnaryExtension(const UnaryOperator *E) { return Visit(E->getSubExpr()); } - + Value *VisitUnaryOffsetOf(const UnaryOperator *E); + // Binary Operators. Value *EmitMul(const BinOpInfo &Ops) { return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul"); @@ -628,6 +629,16 @@ Value *ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *E) { return llvm::Constant::getNullValue(ConvertType(E->getType())); } +Value *ScalarExprEmitter::VisitUnaryOffsetOf(const UnaryOperator *E) +{ + int64_t Val = E->evaluateOffsetOf(CGF.getContext()); + + assert(E->getType()->isIntegerType() && "Result type must be an integer!"); + + uint32_t ResultWidth = static_cast<uint32_t>( + CGF.getContext().getTypeSize(E->getType(), SourceLocation())); + return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val)); +} //===----------------------------------------------------------------------===// // Binary Operators |