Skip to content

Commit df827a7

Browse files
author
Simon Dardis
committedFeb 21, 2017
[mips] Define macros related to -mabicalls in the preprocessor
Summary: Historically, NetBSD, FreeBSD and OpenBSD have defined the macro ABICALLS in the preprocessor when -mabicalls is in effect. Mainline GCC later defined __mips_abicalls when -mabicalls is in effect. This patch teaches the preprocessor to define these macros when appropriate. NetBSD does not require the ABICALLS macro. This resolves PR/31694. Thanks to Sean Bruno for highlighting this issue! Reviewers: slthakur, seanbruno Reviewed By: seanbruno Subscribers: joerg, brad, emaste, seanbruno, cfe-commits Differential Revision: https://reviews.llvm.org/D29032 llvm-svn: 295728
1 parent 78ef645 commit df827a7

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
 

‎clang/lib/Basic/Targets.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -7464,6 +7464,8 @@ class MipsTargetInfo : public TargetInfo {
74647464
bool IsMicromips;
74657465
bool IsNan2008;
74667466
bool IsSingleFloat;
7467+
bool IsNoABICalls;
7468+
bool CanUseBSDABICalls;
74677469
enum MipsFloatABI {
74687470
HardFloat, SoftFloat
74697471
} FloatABI;
@@ -7479,8 +7481,9 @@ class MipsTargetInfo : public TargetInfo {
74797481
public:
74807482
MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
74817483
: TargetInfo(Triple), IsMips16(false), IsMicromips(false),
7482-
IsNan2008(false), IsSingleFloat(false), FloatABI(HardFloat),
7483-
DspRev(NoDSP), HasMSA(false), HasFP64(false) {
7484+
IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
7485+
CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
7486+
HasMSA(false), HasFP64(false) {
74847487
TheCXXABI.set(TargetCXXABI::GenericMIPS);
74857488

74867489
setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -7489,6 +7492,9 @@ class MipsTargetInfo : public TargetInfo {
74897492
: "n64");
74907493

74917494
CPU = ABI == "o32" ? "mips32r2" : "mips64r2";
7495+
7496+
CanUseBSDABICalls = Triple.getOS() == llvm::Triple::FreeBSD ||
7497+
Triple.getOS() == llvm::Triple::OpenBSD;
74927498
}
74937499

74947500
bool isNaN2008Default() const {
@@ -7669,6 +7675,12 @@ class MipsTargetInfo : public TargetInfo {
76697675
} else
76707676
llvm_unreachable("Invalid ABI.");
76717677

7678+
if (!IsNoABICalls) {
7679+
Builder.defineMacro("__mips_abicalls");
7680+
if (CanUseBSDABICalls)
7681+
Builder.defineMacro("__ABICALLS__");
7682+
}
7683+
76727684
Builder.defineMacro("__REGISTER_PREFIX__", "");
76737685

76747686
switch (FloatABI) {
@@ -7883,6 +7895,8 @@ class MipsTargetInfo : public TargetInfo {
78837895
IsNan2008 = true;
78847896
else if (Feature == "-nan2008")
78857897
IsNan2008 = false;
7898+
else if (Feature == "+noabicalls")
7899+
IsNoABICalls = true;
78867900
}
78877901

78887902
setDataLayout();

‎clang/test/Preprocessor/init.c

+45
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,7 @@
30403040
// MIPS32BE:#define __llvm__ 1
30413041
// MIPS32BE:#define __mips 32
30423042
// MIPS32BE:#define __mips__ 1
3043+
// MIPS32BE:#define __mips_abicalls 1
30433044
// MIPS32BE:#define __mips_fpr 32
30443045
// MIPS32BE:#define __mips_hard_float 1
30453046
// MIPS32BE:#define __mips_o32 1
@@ -3246,6 +3247,7 @@
32463247
// MIPS32EL:#define __llvm__ 1
32473248
// MIPS32EL:#define __mips 32
32483249
// MIPS32EL:#define __mips__ 1
3250+
// MIPS32EL:#define __mips_abicalls 1
32493251
// MIPS32EL:#define __mips_fpr 32
32503252
// MIPS32EL:#define __mips_hard_float 1
32513253
// MIPS32EL:#define __mips_o32 1
@@ -3555,6 +3557,7 @@
35553557
// MIPSN32BE: #define __mips64 1
35563558
// MIPSN32BE: #define __mips64__ 1
35573559
// MIPSN32BE: #define __mips__ 1
3560+
// MIPSN32BE: #define __mips_abicalls 1
35583561
// MIPSN32BE: #define __mips_fpr 64
35593562
// MIPSN32BE: #define __mips_hard_float 1
35603563
// MIPSN32BE: #define __mips_isa_rev 2
@@ -3861,6 +3864,7 @@
38613864
// MIPSN32EL: #define __mips64 1
38623865
// MIPSN32EL: #define __mips64__ 1
38633866
// MIPSN32EL: #define __mips__ 1
3867+
// MIPSN32EL: #define __mips_abicalls 1
38643868
// MIPSN32EL: #define __mips_fpr 64
38653869
// MIPSN32EL: #define __mips_hard_float 1
38663870
// MIPSN32EL: #define __mips_isa_rev 2
@@ -4073,6 +4077,7 @@
40734077
// MIPS64BE:#define __mips64 1
40744078
// MIPS64BE:#define __mips64__ 1
40754079
// MIPS64BE:#define __mips__ 1
4080+
// MIPS64BE:#define __mips_abicalls 1
40764081
// MIPS64BE:#define __mips_fpr 64
40774082
// MIPS64BE:#define __mips_hard_float 1
40784083
// MIPS64BE:#define __mips_n64 1
@@ -4282,6 +4287,7 @@
42824287
// MIPS64EL:#define __mips64 1
42834288
// MIPS64EL:#define __mips64__ 1
42844289
// MIPS64EL:#define __mips__ 1
4290+
// MIPS64EL:#define __mips_abicalls 1
42854291
// MIPS64EL:#define __mips_fpr 64
42864292
// MIPS64EL:#define __mips_hard_float 1
42874293
// MIPS64EL:#define __mips_n64 1
@@ -4513,6 +4519,45 @@
45134519
// MIPS-XXR6:#define __mips_fpr 64
45144520
// MIPS-XXR6:#define __mips_nan2008 1
45154521
//
4522+
// RUN: %clang_cc1 -target-cpu mips32 \
4523+
// RUN: -E -dM -triple=mips-unknown-netbsd -mrelocation-model pic < /dev/null \
4524+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ABICALLS-NETBSD %s
4525+
// MIPS-ABICALLS-NETBSD-NOT: #define __ABICALLS__ 1
4526+
// MIPS-ABICALLS-NETBSD: #define __mips_abicalls 1
4527+
//
4528+
// RUN: %clang_cc1 -target-cpu mips64 \
4529+
// RUN: -E -dM -triple=mips64-unknown-netbsd -mrelocation-model pic < \
4530+
// RUN: /dev/null | FileCheck -match-full-lines \
4531+
// RUN: -check-prefix MIPS-ABICALLS-NETBSD64 %s
4532+
// MIPS-ABICALLS-NETBSD64-NOT: #define __ABICALLS__ 1
4533+
// MIPS-ABICALLS-NETBSD64: #define __mips_abicalls 1
4534+
//
4535+
// RUN: %clang_cc1 -target-cpu mips32 \
4536+
// RUN: -E -dM -triple=mips-unknown-freebsd -mrelocation-model pic < /dev/null \
4537+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ABICALLS-FREEBSD %s
4538+
// MIPS-ABICALLS-FREEBSD: #define __ABICALLS__ 1
4539+
// MIPS-ABICALLS-FREEBSD: #define __mips_abicalls 1
4540+
//
4541+
// RUN: %clang_cc1 -target-cpu mips64 \
4542+
// RUN: -E -dM -triple=mips64-unknown-freebsd -mrelocation-model pic < \
4543+
// RUN: /dev/null | FileCheck -match-full-lines \
4544+
// RUN: -check-prefix MIPS-ABICALLS-FREEBSD64 %s
4545+
// MIPS-ABICALLS-FREEBSD64: #define __ABICALLS__ 1
4546+
// MIPS-ABICALLS-FREEBSD64: #define __mips_abicalls 1
4547+
//
4548+
// RUN: %clang_cc1 -target-cpu mips32 \
4549+
// RUN: -E -dM -triple=mips-unknown-openbsd -mrelocation-model pic < /dev/null \
4550+
// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ABICALLS-OPENBSD %s
4551+
// MIPS-ABICALLS-OPENBSD: #define __ABICALLS__ 1
4552+
// MIPS-ABICALLS-OPENBSD: #define __mips_abicalls 1
4553+
//
4554+
// RUN: %clang_cc1 -target-cpu mips64 \
4555+
// RUN: -E -dM -triple=mips64-unknown-openbsd -mrelocation-model pic < \
4556+
// RUN: /dev/null | FileCheck -match-full-lines \
4557+
// RUN: -check-prefix MIPS-ABICALLS-OPENBSD64 %s
4558+
// MIPS-ABICALLS-OPENBSD64: #define __ABICALLS__ 1
4559+
// MIPS-ABICALLS-OPENBSD64: #define __mips_abicalls 1
4560+
//
45164561
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=msp430-none-none < /dev/null | FileCheck -match-full-lines -check-prefix MSP430 %s
45174562
// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=msp430-none-none < /dev/null | FileCheck -match-full-lines -check-prefix MSP430 -check-prefix MSP430-CXX %s
45184563
//

0 commit comments

Comments
 (0)
Please sign in to comment.