Skip to content

Commit 92dd321

Browse files
committed
Rollback of rL355585.
Introduces memory leak in FunctionTest.GetPointerAlignment that breaks sanitizer buildbots: ``` ================================================================= ==2453==ERROR: LeakSanitizer: detected memory leaks Direct leak of 128 byte(s) in 1 object(s) allocated from: #0 0x610428 in operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:105 llvm#1 0x16936bc in llvm::User::operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/IR/User.cpp:151:19 llvm#2 0x7c3fe9 in Create /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/IR/Function.h:144:12 llvm#3 0x7c3fe9 in (anonymous namespace)::FunctionTest_GetPointerAlignment_Test::TestBody() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/unittests/IR/FunctionTest.cpp:136 llvm#4 0x1a836a0 in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc llvm#5 0x1a836a0 in testing::Test::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2474 llvm#6 0x1a85c55 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 llvm#7 0x1a870d0 in testing::TestCase::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 llvm#8 0x1aa5b84 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 llvm#9 0x1aa4d30 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc llvm#10 0x1aa4d30 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4257 llvm#11 0x1a6b656 in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 llvm#12 0x1a6b656 in main /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50 llvm#13 0x7f5af37a22e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) Indirect leak of 40 byte(s) in 1 object(s) allocated from: #0 0x610428 in operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:105 llvm#1 0x151be6b in make_unique<llvm::ValueSymbolTable> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/ADT/STLExtras.h:1349:29 llvm#2 0x151be6b in llvm::Function::Function(llvm::FunctionType*, llvm::GlobalValue::LinkageTypes, unsigned int, llvm::Twine const&, llvm::Module*) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/IR/Function.cpp:241 llvm#3 0x7c4006 in Create /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/IR/Function.h:144:16 llvm#4 0x7c4006 in (anonymous namespace)::FunctionTest_GetPointerAlignment_Test::TestBody() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/unittests/IR/FunctionTest.cpp:136 llvm#5 0x1a836a0 in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc llvm#6 0x1a836a0 in testing::Test::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2474 llvm#7 0x1a85c55 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 llvm#8 0x1a870d0 in testing::TestCase::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 llvm#9 0x1aa5b84 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 llvm#10 0x1aa4d30 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc llvm#11 0x1aa4d30 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4257 llvm#12 0x1a6b656 in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 llvm#13 0x1a6b656 in main /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50 llvm#14 0x7f5af37a22e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) SUMMARY: AddressSanitizer: 168 byte(s) leaked in 2 allocation(s). ``` See http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/11358/steps/check-llvm%20asan/logs/stdio for more information. Also introduces use-of-uninitialized-value in ConstantsTest.FoldGlobalVariablePtr: ``` ==7070==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x14e703c in User /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/User.h:79:5 llvm#1 0x14e703c in Constant /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/Constant.h:44 llvm#2 0x14e703c in llvm::GlobalValue::GlobalValue(llvm::Type*, llvm::Value::ValueTy, llvm::Use*, unsigned int, llvm::GlobalValue::LinkageTypes, llvm::Twine const&, unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/GlobalValue.h:78 llvm#3 0x14e5467 in GlobalObject /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/GlobalObject.h:34:9 llvm#4 0x14e5467 in llvm::GlobalVariable::GlobalVariable(llvm::Type*, bool, llvm::GlobalValue::LinkageTypes, llvm::Constant*, llvm::Twine const&, llvm::GlobalValue::ThreadLocalMode, unsigned int, bool) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/Globals.cpp:314 llvm#5 0x6938f1 in llvm::(anonymous namespace)::ConstantsTest_FoldGlobalVariablePtr_Test::TestBody() /b/sanitizer-x86_64-linux-fast/build/llvm/unittests/IR/ConstantsTest.cpp:565:18 llvm#6 0x1a240a1 in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc llvm#7 0x1a240a1 in testing::Test::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:2474 llvm#8 0x1a26d26 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 llvm#9 0x1a2815f in testing::TestCase::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 llvm#10 0x1a43de8 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 llvm#11 0x1a42c47 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc llvm#12 0x1a42c47 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:4257 llvm#13 0x1a0dfba in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 llvm#14 0x1a0dfba in main /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50 llvm#15 0x7f2081c412e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) llvm#16 0x4dff49 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/unittests/IR/IRTests+0x4dff49) SUMMARY: MemorySanitizer: use-of-uninitialized-value /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/User.h:79:5 in User ``` See http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/30222/steps/check-llvm%20msan/logs/stdio for more information. llvm-svn: 355616
1 parent 2f94dce commit 92dd321

File tree

13 files changed

+25
-279
lines changed

13 files changed

+25
-279
lines changed

clang/lib/Basic/Targets/ARM.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,25 @@ void ARMTargetInfo::setABIAAPCS() {
4040
// so set preferred for small types to 32.
4141
if (T.isOSBinFormatMachO()) {
4242
resetDataLayout(BigEndian
43-
? "E-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
44-
: "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
43+
? "E-m:o-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
44+
: "e-m:o-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64");
4545
} else if (T.isOSWindows()) {
4646
assert(!BigEndian && "Windows on ARM does not support big endian");
4747
resetDataLayout("e"
4848
"-m:w"
4949
"-p:32:32"
50-
"-Fi8"
5150
"-i64:64"
5251
"-v128:64:128"
5352
"-a:0:32"
5453
"-n32"
5554
"-S64");
5655
} else if (T.isOSNaCl()) {
5756
assert(!BigEndian && "NaCl on ARM does not support big endian");
58-
resetDataLayout("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S128");
57+
resetDataLayout("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S128");
5958
} else {
6059
resetDataLayout(BigEndian
61-
? "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
62-
: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
60+
? "E-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
61+
: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64");
6362
}
6463

6564
// FIXME: Enumerated types are variable width in straight AAPCS.
@@ -88,17 +87,17 @@ void ARMTargetInfo::setABIAPCS(bool IsAAPCS16) {
8887

8988
if (T.isOSBinFormatMachO() && IsAAPCS16) {
9089
assert(!BigEndian && "AAPCS16 does not support big-endian");
91-
resetDataLayout("e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128");
90+
resetDataLayout("e-m:o-p:32:32-i64:64-a:0:32-n32-S128");
9291
} else if (T.isOSBinFormatMachO())
9392
resetDataLayout(
9493
BigEndian
95-
? "E-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
96-
: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32");
94+
? "E-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
95+
: "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32");
9796
else
9897
resetDataLayout(
9998
BigEndian
100-
? "E-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
101-
: "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32");
99+
? "E-m:e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
100+
: "e-m:e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32");
102101

103102
// FIXME: Override "preferred align" for double and long long.
104103
}
@@ -1056,7 +1055,7 @@ CygwinARMTargetInfo::CygwinARMTargetInfo(const llvm::Triple &Triple,
10561055
this->WCharType = TargetInfo::UnsignedShort;
10571056
TLSSupported = false;
10581057
DoubleAlign = LongLongAlign = 64;
1059-
resetDataLayout("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
1058+
resetDataLayout("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64");
10601059
}
10611060

10621061
void CygwinARMTargetInfo::getTargetDefines(const LangOptions &Opts,

clang/test/CodeGen/armv7k-abi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Make sure 64 and 128 bit types are naturally aligned by the v7k ABI:
66

7-
// CHECK: target datalayout = "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128"
7+
// CHECK: target datalayout = "e-m:o-p:32:32-i64:64-a:0:32-n32-S128"
88

99
typedef struct {
1010
float arr[4];

clang/test/CodeGen/target-data.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
// RUN: %clang_cc1 -triple arm-nacl -o - -emit-llvm %s | \
9898
// RUN: FileCheck %s -check-prefix=ARM-NACL
99-
// ARM-NACL: target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S128"
99+
// ARM-NACL: target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S128"
100100

101101
// RUN: %clang_cc1 -triple mipsel-nacl -o - -emit-llvm %s | \
102102
// RUN: FileCheck %s -check-prefix=MIPS-NACL
@@ -165,19 +165,19 @@
165165

166166
// RUN: %clang_cc1 -triple thumb-unknown-gnueabi -o - -emit-llvm %s | \
167167
// RUN: FileCheck %s -check-prefix=THUMB
168-
// THUMB: target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
168+
// THUMB: target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
169169

170170
// RUN: %clang_cc1 -triple arm-unknown-gnueabi -o - -emit-llvm %s | \
171171
// RUN: FileCheck %s -check-prefix=ARM
172-
// ARM: target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
172+
// ARM: target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
173173

174174
// RUN: %clang_cc1 -triple thumb-unknown -o - -emit-llvm -target-abi apcs-gnu \
175175
// RUN: %s | FileCheck %s -check-prefix=THUMB-GNU
176-
// THUMB-GNU: target datalayout = "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
176+
// THUMB-GNU: target datalayout = "e-m:e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
177177

178178
// RUN: %clang_cc1 -triple arm-unknown -o - -emit-llvm -target-abi apcs-gnu \
179179
// RUN: %s | FileCheck %s -check-prefix=ARM-GNU
180-
// ARM-GNU: target datalayout = "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
180+
// ARM-GNU: target datalayout = "e-m:e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
181181

182182
// RUN: %clang_cc1 -triple arc-unknown-unknown -o - -emit-llvm %s | \
183183
// RUN: FileCheck %s -check-prefix=ARC

llvm/docs/LangRef.rst

-8
Original file line numberDiff line numberDiff line change
@@ -2004,14 +2004,6 @@ as follows:
20042004
targets.
20052005
``a:<abi>:<pref>``
20062006
This specifies the alignment for an object of aggregate type.
2007-
``F<type><abi>``
2008-
This specifies the alignment for function pointers.
2009-
The options for ``<type>`` are:
2010-
2011-
* ``i``: The alignment of function pointers is independent of the alignment
2012-
of functions, and is a multiple of ``<abi>``.
2013-
* ``n``: The alignment of function pointers is a multiple of the explicit
2014-
alignment specified on the function, and is a multiple of ``<abi>``.
20152007
``m:<mangling>``
20162008
If present, specifies that llvm names are mangled in the output. Symbols
20172009
prefixed with the mangling escape character ``\01`` are passed through

llvm/include/llvm/IR/DataLayout.h

-23
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ struct PointerAlignElem {
108108
/// generating LLVM IR is required to generate the right target data for the
109109
/// target being codegen'd to.
110110
class DataLayout {
111-
public:
112-
enum class FunctionPtrAlignType {
113-
/// The function pointer alignment is independent of the function alignment.
114-
Independent,
115-
/// The function pointer alignment is a multiple of the function alignment.
116-
MultipleOfFunctionAlign,
117-
};
118111
private:
119112
/// Defaults to false.
120113
bool BigEndian;
@@ -123,9 +116,6 @@ class DataLayout {
123116
unsigned StackNaturalAlign;
124117
unsigned ProgramAddrSpace;
125118

126-
unsigned FunctionPtrAlign;
127-
FunctionPtrAlignType TheFunctionPtrAlignType;
128-
129119
enum ManglingModeT {
130120
MM_None,
131121
MM_ELF,
@@ -209,8 +199,6 @@ class DataLayout {
209199
BigEndian = DL.isBigEndian();
210200
AllocaAddrSpace = DL.AllocaAddrSpace;
211201
StackNaturalAlign = DL.StackNaturalAlign;
212-
FunctionPtrAlign = DL.FunctionPtrAlign;
213-
TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType;
214202
ProgramAddrSpace = DL.ProgramAddrSpace;
215203
ManglingMode = DL.ManglingMode;
216204
LegalIntWidths = DL.LegalIntWidths;
@@ -268,17 +256,6 @@ class DataLayout {
268256
unsigned getStackAlignment() const { return StackNaturalAlign; }
269257
unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
270258

271-
/// Returns the alignment of function pointers, which may or may not be
272-
/// related to the alignment of functions.
273-
/// \see getFunctionPtrAlignType
274-
unsigned getFunctionPtrAlign() const { return FunctionPtrAlign; }
275-
276-
/// Return the type of function pointer alignment.
277-
/// \see getFunctionPtrAlign
278-
FunctionPtrAlignType getFunctionPtrAlignType() const {
279-
return TheFunctionPtrAlignType;
280-
}
281-
282259
unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
283260

284261
bool hasMicrosoftFastStdCallMangling() const {

llvm/lib/IR/ConstantFold.cpp

+4-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "llvm/IR/GlobalAlias.h"
2727
#include "llvm/IR/GlobalVariable.h"
2828
#include "llvm/IR/Instructions.h"
29-
#include "llvm/IR/Module.h"
3029
#include "llvm/IR/Operator.h"
3130
#include "llvm/IR/PatternMatch.h"
3231
#include "llvm/Support/ErrorHandling.h"
@@ -1077,29 +1076,10 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
10771076
isa<GlobalValue>(CE1->getOperand(0))) {
10781077
GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
10791078

1080-
unsigned GVAlign;
1081-
1082-
if (Module *TheModule = GV->getParent()) {
1083-
GVAlign = GV->getPointerAlignment(TheModule->getDataLayout());
1084-
1085-
// If the function alignment is not specified then assume that it
1086-
// is 4.
1087-
// This is dangerous; on x86, the alignment of the pointer
1088-
// corresponds to the alignment of the function, but might be less
1089-
// than 4 if it isn't explicitly specified.
1090-
// However, a fix for this behaviour was reverted because it
1091-
// increased code size (see https://reviews.llvm.org/D55115)
1092-
// FIXME: This code should be deleted once existing targets have
1093-
// appropriate defaults
1094-
if (GVAlign == 0U && isa<Function>(GV))
1095-
GVAlign = 4U;
1096-
} else if (isa<Function>(GV)) {
1097-
// Without a datalayout we have to assume the worst case: that the
1098-
// function pointer isn't aligned at all.
1099-
GVAlign = 0U;
1100-
} else {
1101-
GVAlign = GV->getAlignment();
1102-
}
1079+
// Functions are at least 4-byte aligned.
1080+
unsigned GVAlign = GV->getAlignment();
1081+
if (isa<Function>(GV))
1082+
GVAlign = std::max(GVAlign, 4U);
11031083

11041084
if (GVAlign > 1) {
11051085
unsigned DstWidth = CI2->getType()->getBitWidth();

llvm/lib/IR/DataLayout.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ void DataLayout::reset(StringRef Desc) {
184184
AllocaAddrSpace = 0;
185185
StackNaturalAlign = 0;
186186
ProgramAddrSpace = 0;
187-
FunctionPtrAlign = 0;
188-
TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
189187
ManglingMode = MM_None;
190188
NonIntegralAddressSpaces.clear();
191189

@@ -381,22 +379,6 @@ void DataLayout::parseSpecifier(StringRef Desc) {
381379
StackNaturalAlign = inBytes(getInt(Tok));
382380
break;
383381
}
384-
case 'F': {
385-
switch (Tok.front()) {
386-
case 'i':
387-
TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
388-
break;
389-
case 'n':
390-
TheFunctionPtrAlignType = FunctionPtrAlignType::MultipleOfFunctionAlign;
391-
break;
392-
default:
393-
report_fatal_error("Unknown function pointer alignment type in "
394-
"datalayout string");
395-
}
396-
Tok = Tok.substr(1);
397-
FunctionPtrAlign = inBytes(getInt(Tok));
398-
break;
399-
}
400382
case 'P': { // Function address space.
401383
ProgramAddrSpace = getAddrSpace(Tok);
402384
break;
@@ -450,8 +432,6 @@ bool DataLayout::operator==(const DataLayout &Other) const {
450432
AllocaAddrSpace == Other.AllocaAddrSpace &&
451433
StackNaturalAlign == Other.StackNaturalAlign &&
452434
ProgramAddrSpace == Other.ProgramAddrSpace &&
453-
FunctionPtrAlign == Other.FunctionPtrAlign &&
454-
TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
455435
ManglingMode == Other.ManglingMode &&
456436
LegalIntWidths == Other.LegalIntWidths &&
457437
Alignments == Other.Alignments && Pointers == Other.Pointers;

llvm/lib/IR/Value.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,10 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const {
648648

649649
unsigned Align = 0;
650650
if (auto *GO = dyn_cast<GlobalObject>(this)) {
651-
if (isa<Function>(GO)) {
652-
switch (DL.getFunctionPtrAlignType()) {
653-
case DataLayout::FunctionPtrAlignType::Independent:
654-
return DL.getFunctionPtrAlign();
655-
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
656-
return std::max(DL.getFunctionPtrAlign(), GO->getAlignment());
657-
}
658-
}
651+
// Don't make any assumptions about function pointer alignment. Some
652+
// targets use the LSBs to store additional information.
653+
if (isa<Function>(GO))
654+
return 0;
659655
Align = GO->getAlignment();
660656
if (Align == 0) {
661657
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {

llvm/lib/Target/ARM/ARMTargetMachine.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ static std::string computeDataLayout(const Triple &TT, StringRef CPU,
141141
// Pointers are 32 bits and aligned to 32 bits.
142142
Ret += "-p:32:32";
143143

144-
// Function pointers are aligned to 8 bits (because the LSB stores the
145-
// ARM/Thumb state).
146-
Ret += "-Fi8";
147-
148144
// ABIs other than APCS have 64 bit integers with natural alignment.
149145
if (ABI != ARMBaseTargetMachine::ARM_ABI_APCS)
150146
Ret += "-i64:64";

llvm/unittests/IR/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ add_llvm_unittest(IRTests
1313
CFGBuilder.cpp
1414
ConstantRangeTest.cpp
1515
ConstantsTest.cpp
16-
DataLayoutTest.cpp
1716
DebugInfoTest.cpp
1817
DebugTypeODRUniquingTest.cpp
1918
DominatorTreeTest.cpp

llvm/unittests/IR/ConstantsTest.cpp

-101
Original file line numberDiff line numberDiff line change
@@ -475,106 +475,5 @@ TEST(ConstantsTest, BitcastToGEP) {
475475
ASSERT_EQ(cast<ConstantExpr>(C)->getOpcode(), Instruction::BitCast);
476476
}
477477

478-
bool foldFuncPtrAndConstToNull(LLVMContext &Context, Module *TheModule,
479-
uint64_t AndValue, unsigned FunctionAlign = 0) {
480-
Type *VoidType(Type::getVoidTy(Context));
481-
FunctionType *FuncType(FunctionType::get(VoidType, false));
482-
Function *Func(Function::Create(
483-
FuncType, GlobalValue::ExternalLinkage, "", TheModule));
484-
485-
if (FunctionAlign) Func->setAlignment(FunctionAlign);
486-
487-
IntegerType *ConstantIntType(Type::getInt32Ty(Context));
488-
ConstantInt *TheConstant(ConstantInt::get(ConstantIntType, AndValue));
489-
490-
Constant *TheConstantExpr(
491-
ConstantExpr::getPtrToInt(Func, ConstantIntType));
492-
493-
return ConstantExpr::get(Instruction::And, TheConstantExpr,
494-
TheConstant)->isNullValue();
495-
}
496-
497-
TEST(ConstantsTest, FoldFunctionPtrAlignUnknownAnd2) {
498-
LLVMContext Context;
499-
Module TheModule("TestModule", Context);
500-
// When the DataLayout doesn't specify a function pointer alignment we
501-
// assume in this case that it is 4 byte aligned. This is a bug but we can't
502-
// fix it directly because it causes a code size regression on X86.
503-
// FIXME: This test should be changed once existing targets have
504-
// appropriate defaults. See associated FIXME in ConstantFoldBinaryInstruction
505-
ASSERT_TRUE(foldFuncPtrAndConstToNull(Context, &TheModule, 2));
506-
}
507-
508-
TEST(ConstantsTest, DontFoldFunctionPtrAlignUnknownAnd4) {
509-
LLVMContext Context;
510-
Module TheModule("TestModule", Context);
511-
ASSERT_FALSE(foldFuncPtrAndConstToNull(Context, &TheModule, 4));
512-
}
513-
514-
TEST(ConstantsTest, FoldFunctionPtrAlign4) {
515-
LLVMContext Context;
516-
Module TheModule("TestModule", Context);
517-
const char* AlignmentStrings[] = { "Fi32", "Fn32" };
518-
519-
for (unsigned AndValue = 1; AndValue <= 2; ++AndValue) {
520-
for (const char *AlignmentString : AlignmentStrings) {
521-
TheModule.setDataLayout(AlignmentString);
522-
ASSERT_TRUE(foldFuncPtrAndConstToNull(Context, &TheModule, AndValue));
523-
}
524-
}
525-
}
526-
527-
TEST(ConstantsTest, DontFoldFunctionPtrAlign1) {
528-
LLVMContext Context;
529-
Module TheModule("TestModule", Context);
530-
const char* AlignmentStrings[] = { "Fi8", "Fn8" };
531-
532-
for (const char* AlignmentString : AlignmentStrings) {
533-
TheModule.setDataLayout(AlignmentString);
534-
ASSERT_FALSE(foldFuncPtrAndConstToNull(Context, &TheModule, 2));
535-
}
536-
}
537-
538-
TEST(ConstantsTest, FoldFunctionAlign4PtrAlignMultiple) {
539-
LLVMContext Context;
540-
Module TheModule("TestModule", Context);
541-
TheModule.setDataLayout("Fn8");
542-
ASSERT_TRUE(foldFuncPtrAndConstToNull(Context, &TheModule, 2, 4));
543-
}
544-
545-
TEST(ConstantsTest, DontFoldFunctionAlign4PtrAlignIndependent) {
546-
LLVMContext Context;
547-
Module TheModule("TestModule", Context);
548-
TheModule.setDataLayout("Fi8");
549-
ASSERT_FALSE(foldFuncPtrAndConstToNull(Context, &TheModule, 2, 4));
550-
}
551-
552-
TEST(ConstantsTest, DontFoldFunctionPtrIfNoModule) {
553-
LLVMContext Context;
554-
// Even though the function is explicitly 4 byte aligned, in the absence of a
555-
// DataLayout we can't assume that the function pointer is aligned.
556-
ASSERT_FALSE(foldFuncPtrAndConstToNull(Context, nullptr, 2, 4));
557-
}
558-
559-
TEST(ConstantsTest, FoldGlobalVariablePtr) {
560-
LLVMContext Context;
561-
562-
563-
IntegerType *IntType(Type::getInt32Ty(Context));
564-
565-
std::unique_ptr<GlobalVariable> Global(
566-
new GlobalVariable(IntType, true, GlobalValue::ExternalLinkage));
567-
568-
Global->setAlignment(4);
569-
570-
ConstantInt *TheConstant(ConstantInt::get(IntType, 2));
571-
572-
Constant *TheConstantExpr(
573-
ConstantExpr::getPtrToInt(Global.get(), IntType));
574-
575-
ASSERT_TRUE(ConstantExpr::get( \
576-
Instruction::And, TheConstantExpr, TheConstant)->isNullValue());
577-
}
578-
579478
} // end anonymous namespace
580479
} // end namespace llvm

0 commit comments

Comments
 (0)