From bfe5a44dde6243818898e7cfada316d762c59742 Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 16 Jan 2019 18:53:05 +0000 Subject: [Fixed Point Arithmetic] Add APFixedPoint to APValue This adds APFixedPoint to the union of values that can be represented with an APValue. Differential Revision: https://reviews.llvm.org/D56746 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351368 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index c9475840ae..5cd3e8565a 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1873,6 +1873,9 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const APValue &Value, return ConstantLValueEmitter(*this, Value, DestType).tryEmit(); case APValue::Int: return llvm::ConstantInt::get(CGM.getLLVMContext(), Value.getInt()); + case APValue::FixedPoint: + return llvm::ConstantInt::get(CGM.getLLVMContext(), + Value.getFixedPoint().getValue()); case APValue::ComplexInt: { llvm::Constant *Complex[2]; -- cgit v1.2.3 From 324f918438715b4a0d024af5930628c1674f4fcd Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 19 Jan 2019 08:50:56 +0000 Subject: Update the file headers across all of the LLVM projects in the monorepo to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 5cd3e8565a..09a035679b 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1,9 +1,8 @@ //===--- CGExprConstant.cpp - Emit LLVM Code from Constant Expressions ----===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // -- cgit v1.2.3 From 12ab032c299151930251e64b550bc1eaf7770e46 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 22 Jan 2019 00:11:17 +0000 Subject: [CodeGen] Always use string computed in Sema for PredefinedExpr We can't use any other string, anyway, because its type wouldn't match the type of the PredefinedExpr. With this change, we don't compute a "nice" name for the __func__ global when it's used in the initializer for a constant. This doesn't seem like a great loss, and I'm not sure how to fix it without either storing more information in the AST, or somehow threading through the information from ExprConstant.cpp. This could break some situations involving BlockDecl; currently, CodeGenFunction::EmitPredefinedLValue has some logic to intentionally emit a string different from what Sema computed. This code skips that logic... but that logic can't work correctly in general anyway. (For example, sizeof(__func__) returns the wrong result.) Hopefully this doesn't affect practical code. Fixes https://bugs.llvm.org/show_bug.cgi?id=40313 . Differential Revision: https://reviews.llvm.org/D56821 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351766 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 09a035679b..48ab2522e8 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1788,17 +1788,7 @@ ConstantLValueEmitter::VisitObjCStringLiteral(const ObjCStringLiteral *E) { ConstantLValue ConstantLValueEmitter::VisitPredefinedExpr(const PredefinedExpr *E) { - if (auto CGF = Emitter.CGF) { - LValue Res = CGF->EmitPredefinedLValue(E); - return cast(Res.getAddress()); - } - - auto kind = E->getIdentKind(); - if (kind == PredefinedExpr::PrettyFunction) { - return CGM.GetAddrOfConstantCString("top level", ".tmp"); - } - - return CGM.GetAddrOfConstantCString("", ".tmp"); + return CGM.GetAddrOfConstantStringFromLiteral(E->getFunctionName()); } ConstantLValue -- cgit v1.2.3 From 4e215e73ed6b499f3ccf23263c96cd188e0eda2c Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 8 Feb 2019 21:18:46 +0000 Subject: [Sema] Make string literal init an rvalue. This allows substantially simplifying the expression evaluation code, because we don't have to special-case lvalues which are actually string literal initialization. This currently throws away an optimization where we would avoid creating an array APValue for string literal initialization. If we really want to optimize this case, we should fix APValue so it can store simple arrays more efficiently, like llvm::ConstantDataArray. This shouldn't affect the memory usage for other string literals. (Not sure if this is a blocker; I don't think string literal init is common enough for this to be a serious issue, but I could be wrong.) The change to test/CodeGenObjC/encode-test.m is a weird side-effect of these changes: we currently don't constant-evaluate arrays in C, so the strlen call shouldn't be folded, but lvalue string init managed to get around that check. I this this is fine. Fixes https://bugs.llvm.org/show_bug.cgi?id=40430 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353569 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 48ab2522e8..8dbfab8345 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1649,16 +1649,6 @@ private: llvm::Constant *ConstantLValueEmitter::tryEmit() { const APValue::LValueBase &base = Value.getLValueBase(); - // Certain special array initializers are represented in APValue - // as l-values referring to the base expression which generates the - // array. This happens with e.g. string literals. These should - // probably just get their own representation kind in APValue. - if (DestType->isArrayType()) { - assert(!hasNonZeroOffset() && "offset on array initializer"); - auto expr = const_cast(base.get()); - return ConstExprEmitter(Emitter).Visit(expr, DestType); - } - // Otherwise, the destination type should be a pointer or reference // type, but it might also be a cast thereof. // -- cgit v1.2.3 From c15c1c3a2e19df41895228622417a3ac43ae0176 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 8 Feb 2019 21:36:04 +0000 Subject: [CodeGen][NFC] Update comments in CGExprConstant.cpp. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353571 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 8dbfab8345..62cc12c7de 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -700,10 +700,12 @@ EmitArrayConstant(CodeGenModule &CGM, const ConstantArrayType *DestType, return llvm::ConstantStruct::get(SType, Elements); } -/// This class only needs to handle two cases: -/// 1) Literals (this is used by APValue emission to emit literals). -/// 2) Arrays, structs and unions (outside C++11 mode, we don't currently -/// constant fold these types). +// This class only needs to handle arrays, structs and unions. Outside C++11 +// mode, we don't currently constant fold those types. All other types are +// handled by constant folding. +// +// Constant folding is currently missing support for a few features supported +// here: CK_ToUnion, CK_ReinterpretMemberPointer, and DesignatedInitUpdateExpr. class ConstExprEmitter : public StmtVisitor { CodeGenModule &CGM; @@ -1076,6 +1078,7 @@ public: } llvm::Constant *VisitStringLiteral(StringLiteral *E, QualType T) { + // This is a string literal initializing an array in an initializer. return CGM.GetConstantArrayFromStringLiteral(E); } @@ -1649,7 +1652,7 @@ private: llvm::Constant *ConstantLValueEmitter::tryEmit() { const APValue::LValueBase &base = Value.getLValueBase(); - // Otherwise, the destination type should be a pointer or reference + // The destination type should be a pointer or reference // type, but it might also be a cast thereof. // // FIXME: the chain of casts required should be reflected in the APValue. -- cgit v1.2.3 From ad9a67e1f7dae24e41d70541d09019900ec029cd Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 6 Mar 2019 00:28:43 +0000 Subject: [Fixed Point Arithmetic] Fixed Point and Integer Conversions This patch includes the necessary code for converting between a fixed point type and integer. This also includes constant expression evaluation for conversions with these types. Differential Revision: https://reviews.llvm.org/D56900 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355462 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 62cc12c7de..64ad582c58 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -876,6 +876,8 @@ public: case CK_FloatingCast: case CK_FixedPointCast: case CK_FixedPointToBoolean: + case CK_FixedPointToIntegral: + case CK_IntegralToFixedPoint: case CK_ZeroToOCLOpaqueType: return nullptr; } -- cgit v1.2.3 From 4874bff565a9f92c41a1efad0b3d633371b5930c Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Fri, 8 Mar 2019 04:45:37 +0000 Subject: [ObjC] Emit a boxed expression as a compile-time constant if the expression inside the parentheses is a valid UTF-8 string literal. Previously clang emitted an expression like @("abc") as a message send to stringWithUTF8String. This commit makes clang emit the boxed expression as a compile-time constant instead. This commit also has the effect of silencing the nullable-to-nonnull conversion warning clang started emitting after r317727, which originally motivated this commit (see https://oleb.net/2018/@keypath). rdar://problem/42684601 Differential Revision: https://reviews.llvm.org/D58729 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355662 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 64ad582c58..102d21e519 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1613,6 +1613,7 @@ private: ConstantLValue VisitConstantExpr(const ConstantExpr *E); ConstantLValue VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); ConstantLValue VisitStringLiteral(const StringLiteral *E); + ConstantLValue VisitObjCBoxedExpr(const ObjCBoxedExpr *E); ConstantLValue VisitObjCEncodeExpr(const ObjCEncodeExpr *E); ConstantLValue VisitObjCStringLiteral(const ObjCStringLiteral *E); ConstantLValue VisitPredefinedExpr(const PredefinedExpr *E); @@ -1775,10 +1776,24 @@ ConstantLValueEmitter::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) { return CGM.GetAddrOfConstantStringFromObjCEncode(E); } +static ConstantLValue emitConstantObjCStringLiteral(const StringLiteral *S, + QualType T, + CodeGenModule &CGM) { + auto C = CGM.getObjCRuntime().GenerateConstantString(S); + return C.getElementBitCast(CGM.getTypes().ConvertTypeForMem(T)); +} + ConstantLValue ConstantLValueEmitter::VisitObjCStringLiteral(const ObjCStringLiteral *E) { - auto C = CGM.getObjCRuntime().GenerateConstantString(E->getString()); - return C.getElementBitCast(CGM.getTypes().ConvertTypeForMem(E->getType())); + return emitConstantObjCStringLiteral(E->getString(), E->getType(), CGM); +} + +ConstantLValue +ConstantLValueEmitter::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) { + assert(E->isExpressibleAsConstantInitializer() && + "this boxed expression can't be emitted as a compile-time constant"); + auto *SL = cast(E->getSubExpr()->IgnoreParenCasts()); + return emitConstantObjCStringLiteral(SL, E->getType(), CGM); } ConstantLValue -- cgit v1.2.3 From 64aa9a1dd1600e10da95a2a42d79e95ed0e53d7c Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Tue, 19 Mar 2019 06:14:14 +0000 Subject: Refactor cast<>'s in if conditionals, which can only assert on failure. Summary: This patch refactors several instances of cast<> used in if conditionals. Since cast<> asserts on failure, the else branch can never be taken. In some cases, the fix is to replace cast<> with dyn_cast<>. While others required the removal of the conditional and some minor refactoring. A discussion can be seen here: http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190318/265044.html Differential Revision: https://reviews.llvm.org/D59529 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356441 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 102d21e519..0772dcccc5 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1698,31 +1698,20 @@ ConstantLValueEmitter::tryEmitAbsolute(llvm::Type *destTy) { auto offset = getOffset(); // If we're producing a pointer, this is easy. - if (auto destPtrTy = cast(destTy)) { - if (Value.isNullPointer()) { - // FIXME: integer offsets from non-zero null pointers. - return CGM.getNullPointer(destPtrTy, DestType); - } - - // Convert the integer to a pointer-sized integer before converting it - // to a pointer. - // FIXME: signedness depends on the original integer type. - auto intptrTy = CGM.getDataLayout().getIntPtrType(destPtrTy); - llvm::Constant *C = offset; - C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy, - /*isSigned*/ false); - C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy); - return C; - } - - // Otherwise, we're basically returning an integer constant. - - // FIXME: this does the wrong thing with ptrtoint of a null pointer, - // but since we don't know the original pointer type, there's not much - // we can do about it. - - auto C = getOffset(); - C = llvm::ConstantExpr::getIntegerCast(C, destTy, /*isSigned*/ false); + auto destPtrTy = cast(destTy); + if (Value.isNullPointer()) { + // FIXME: integer offsets from non-zero null pointers. + return CGM.getNullPointer(destPtrTy, DestType); + } + + // Convert the integer to a pointer-sized integer before converting it + // to a pointer. + // FIXME: signedness depends on the original integer type. + auto intptrTy = CGM.getDataLayout().getIntPtrType(destPtrTy); + llvm::Constant *C = offset; + C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy, + /*isSigned*/ false); + C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy); return C; } -- cgit v1.2.3 From 329eb5c6baeca0a1bd6b1a5bd55e41de786f39fa Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 24 Apr 2019 14:43:05 +0000 Subject: Use llvm::stable_sort git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359098 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 0772dcccc5..4c0256fe38 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -459,7 +459,7 @@ bool ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD, CharUnits BaseOffset = Layout.getBaseClassOffset(BD); Bases.push_back(BaseInfo(BD, BaseOffset, BaseNo)); } - std::stable_sort(Bases.begin(), Bases.end()); + llvm::stable_sort(Bases); for (unsigned I = 0, N = Bases.size(); I != N; ++I) { BaseInfo &Base = Bases[I]; -- cgit v1.2.3