2009-04-21 13:40:52 +08:00
|
|
|
//===--- InitPreprocessor.cpp - PP initialization code. ---------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2009-04-21 13:40:52 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the clang::InitializePreprocessor function.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
2010-01-20 14:13:02 +08:00
|
|
|
#include "clang/Basic/MacroBuilder.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2017-08-05 02:16:31 +08:00
|
|
|
#include "clang/Basic/SyncScope.h"
|
2009-04-21 13:40:52 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2009-12-03 00:32:41 +08:00
|
|
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
2010-01-14 02:51:17 +08:00
|
|
|
#include "clang/Frontend/FrontendOptions.h"
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "clang/Frontend/Utils.h"
|
2011-12-09 09:33:57 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2009-04-21 13:40:52 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2012-10-25 01:01:35 +08:00
|
|
|
#include "clang/Lex/PreprocessorOptions.h"
|
2012-10-23 07:59:45 +08:00
|
|
|
#include "clang/Serialization/ASTReader.h"
|
2010-01-10 00:17:37 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2019-10-22 01:58:14 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2009-11-03 05:48:09 +08:00
|
|
|
using namespace clang;
|
2009-04-21 13:40:52 +08:00
|
|
|
|
2013-08-29 04:35:38 +08:00
|
|
|
static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
|
|
|
|
while (!MacroBody.empty() && isWhitespace(MacroBody.back()))
|
|
|
|
MacroBody = MacroBody.drop_back();
|
|
|
|
return !MacroBody.empty() && MacroBody.back() == '\\';
|
|
|
|
}
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Append a #define line to Buf for Macro. Macro should be of the form XXX,
|
|
|
|
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
|
|
|
|
// "#define XXX Y z W". To get a #define with no value, use "XXX=".
|
2011-07-23 18:55:15 +08:00
|
|
|
static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2011-07-23 18:55:15 +08:00
|
|
|
std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
|
|
|
|
StringRef MacroName = MacroPair.first;
|
|
|
|
StringRef MacroBody = MacroPair.second;
|
2010-01-10 08:46:21 +08:00
|
|
|
if (MacroName.size() != Macro.size()) {
|
2009-04-21 13:40:52 +08:00
|
|
|
// Per GCC -D semantics, the macro ends at \n if it exists.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef::size_type End = MacroBody.find_first_of("\n\r");
|
|
|
|
if (End != StringRef::npos)
|
2010-01-10 08:46:21 +08:00
|
|
|
Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
|
2010-01-09 17:27:11 +08:00
|
|
|
<< MacroName;
|
2013-08-29 04:35:38 +08:00
|
|
|
MacroBody = MacroBody.substr(0, End);
|
|
|
|
// We handle macro bodies which end in a backslash by appending an extra
|
|
|
|
// backslash+newline. This makes sure we don't accidentally treat the
|
|
|
|
// backslash as a line continuation marker.
|
|
|
|
if (MacroBodyEndsInBackslash(MacroBody))
|
|
|
|
Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n");
|
|
|
|
else
|
|
|
|
Builder.defineMacro(MacroName, MacroBody);
|
2009-04-21 13:40:52 +08:00
|
|
|
} else {
|
|
|
|
// Push "macroname 1".
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro(Macro);
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
2009-05-16 00:08:43 +08:00
|
|
|
}
|
|
|
|
|
2012-06-14 06:07:09 +08:00
|
|
|
/// AddImplicitInclude - Add an implicit \#include of the specified file to the
|
2009-04-21 13:40:52 +08:00
|
|
|
/// predefines buffer.
|
2014-08-12 16:25:57 +08:00
|
|
|
/// As these includes are generated by -include arguments the header search
|
|
|
|
/// logic is going to search relatively to the current working directory.
|
|
|
|
static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) {
|
|
|
|
Builder.append(Twine("#include \"") + File + "\"");
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2014-08-12 16:25:57 +08:00
|
|
|
static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
|
|
|
|
Builder.append(Twine("#__include_macros \"") + File + "\"");
|
2009-04-21 13:40:52 +08:00
|
|
|
// Marker token to stop the __include_macros fetch loop.
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.append("##"); // ##?
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Add an implicit \#include using the original file used to generate
|
2012-10-23 07:59:45 +08:00
|
|
|
/// a PCH file.
|
|
|
|
static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP,
|
2015-07-17 09:19:54 +08:00
|
|
|
const PCHContainerReader &PCHContainerRdr,
|
2012-10-23 07:59:45 +08:00
|
|
|
StringRef ImplicitIncludePCH) {
|
2020-01-29 03:23:46 +08:00
|
|
|
std::string OriginalFile = ASTReader::getOriginalSourceFile(
|
|
|
|
std::string(ImplicitIncludePCH), PP.getFileManager(), PCHContainerRdr,
|
|
|
|
PP.getDiagnostics());
|
2012-10-23 07:59:45 +08:00
|
|
|
if (OriginalFile.empty())
|
|
|
|
return;
|
|
|
|
|
2014-08-12 16:25:57 +08:00
|
|
|
AddImplicitInclude(Builder, OriginalFile);
|
2012-10-23 07:59:45 +08:00
|
|
|
}
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
/// PickFP - This is used to pick a value based on the FP semantics of the
|
|
|
|
/// specified FP model.
|
|
|
|
template <typename T>
|
2017-09-13 23:23:19 +08:00
|
|
|
static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
|
2009-05-23 11:50:01 +08:00
|
|
|
T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
|
|
|
|
T IEEEQuadVal) {
|
2017-09-13 23:23:19 +08:00
|
|
|
if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
|
|
|
|
return IEEEHalfVal;
|
2016-12-14 19:57:17 +08:00
|
|
|
if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
|
2009-04-21 13:40:52 +08:00
|
|
|
return IEEESingleVal;
|
2016-12-14 19:57:17 +08:00
|
|
|
if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
|
2009-04-21 13:40:52 +08:00
|
|
|
return IEEEDoubleVal;
|
2016-12-14 19:57:17 +08:00
|
|
|
if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
|
2009-04-21 13:40:52 +08:00
|
|
|
return X87DoubleExtendedVal;
|
2016-12-14 19:57:17 +08:00
|
|
|
if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
|
2009-05-23 11:50:01 +08:00
|
|
|
return PPCDoubleDoubleVal;
|
2016-12-14 19:57:17 +08:00
|
|
|
assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
|
2009-05-23 11:50:01 +08:00
|
|
|
return IEEEQuadVal;
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
|
2012-11-10 08:20:38 +08:00
|
|
|
const llvm::fltSemantics *Sem, StringRef Ext) {
|
2009-04-21 13:40:52 +08:00
|
|
|
const char *DenormMin, *Epsilon, *Max, *Min;
|
2017-09-13 23:23:19 +08:00
|
|
|
DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45",
|
|
|
|
"4.9406564584124654e-324", "3.64519953188247460253e-4951",
|
2012-11-10 08:20:38 +08:00
|
|
|
"4.94065645841246544176568792868221e-324",
|
|
|
|
"6.47517511943802511092443895822764655e-4966");
|
2017-09-13 23:23:19 +08:00
|
|
|
int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33);
|
|
|
|
int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36);
|
|
|
|
Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7",
|
|
|
|
"2.2204460492503131e-16", "1.08420217248550443401e-19",
|
2012-11-10 08:20:38 +08:00
|
|
|
"4.94065645841246544176568792868221e-324",
|
|
|
|
"1.92592994438723585305597794258492732e-34");
|
2017-09-13 23:23:19 +08:00
|
|
|
int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113);
|
2019-05-31 09:21:36 +08:00
|
|
|
int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931);
|
2017-09-13 23:23:19 +08:00
|
|
|
int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932);
|
2019-05-31 09:21:36 +08:00
|
|
|
int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381);
|
|
|
|
int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384);
|
2017-09-13 23:23:19 +08:00
|
|
|
Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308",
|
2012-11-10 08:20:38 +08:00
|
|
|
"3.36210314311209350626e-4932",
|
|
|
|
"2.00416836000897277799610805135016e-292",
|
|
|
|
"3.36210314311209350626267781732175260e-4932");
|
2017-09-13 23:23:19 +08:00
|
|
|
Max = PickFP(Sem, "6.5504e+4", "3.40282347e+38", "1.7976931348623157e+308",
|
2012-11-10 08:20:38 +08:00
|
|
|
"1.18973149535723176502e+4932",
|
|
|
|
"1.79769313486231580793728971405301e+308",
|
|
|
|
"1.18973149535723176508575932662800702e+4932");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<32> DefPrefix;
|
2010-01-20 14:09:53 +08:00
|
|
|
DefPrefix = "__";
|
|
|
|
DefPrefix += Prefix;
|
|
|
|
DefPrefix += "_";
|
2010-01-10 00:17:37 +08:00
|
|
|
|
2012-11-10 08:20:38 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext);
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "HAS_DENORM__");
|
2011-07-23 18:55:15 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits));
|
2015-02-23 17:12:31 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "DECIMAL_DIG__", Twine(DecimalDigits));
|
2012-11-10 08:20:38 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext);
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "HAS_INFINITY__");
|
|
|
|
Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__");
|
2011-07-23 18:55:15 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits));
|
2010-01-10 01:43:21 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp));
|
|
|
|
Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp));
|
2012-11-10 08:20:38 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext);
|
2010-01-10 01:43:21 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")");
|
|
|
|
Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")");
|
2012-11-10 08:20:38 +08:00
|
|
|
Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext);
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
|
|
|
|
/// named MacroName with the max value for a type with width 'TypeWidth' a
|
|
|
|
/// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
|
2014-06-25 09:31:33 +08:00
|
|
|
static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef ValSuffix, bool isSigned,
|
2011-02-24 14:54:56 +08:00
|
|
|
MacroBuilder &Builder) {
|
|
|
|
llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
|
|
|
|
: llvm::APInt::getMaxValue(TypeWidth);
|
|
|
|
Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2009-11-06 05:21:32 +08:00
|
|
|
/// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
|
|
|
|
/// the width, suffix, and signedness of the given type
|
2014-06-25 09:31:33 +08:00
|
|
|
static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
|
2010-01-10 00:17:37 +08:00
|
|
|
const TargetInfo &TI, MacroBuilder &Builder) {
|
2017-12-08 07:04:11 +08:00
|
|
|
DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
|
2010-01-10 00:17:37 +08:00
|
|
|
TI.isTypeSigned(Ty), Builder);
|
2009-11-06 05:21:32 +08:00
|
|
|
}
|
|
|
|
|
2014-07-15 19:30:00 +08:00
|
|
|
static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty,
|
|
|
|
const TargetInfo &TI, MacroBuilder &Builder) {
|
|
|
|
bool IsSigned = TI.isTypeSigned(Ty);
|
|
|
|
StringRef FmtModifier = TI.getTypeFormatModifier(Ty);
|
|
|
|
for (const char *Fmt = IsSigned ? "di" : "ouxX"; *Fmt; ++Fmt) {
|
2014-07-15 20:18:40 +08:00
|
|
|
Builder.defineMacro(Prefix + "_FMT" + Twine(*Fmt) + "__",
|
|
|
|
Twine("\"") + FmtModifier + Twine(*Fmt) + "\"");
|
2014-07-15 19:30:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty,
|
2010-01-10 00:17:37 +08:00
|
|
|
MacroBuilder &Builder) {
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty,
|
2010-01-10 00:17:37 +08:00
|
|
|
const TargetInfo &TI, MacroBuilder &Builder) {
|
2011-07-23 18:55:15 +08:00
|
|
|
Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty)));
|
2009-11-18 21:52:57 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
|
2010-05-28 08:27:15 +08:00
|
|
|
const TargetInfo &TI, MacroBuilder &Builder) {
|
|
|
|
Builder.defineMacro(MacroName,
|
2011-07-23 18:55:15 +08:00
|
|
|
Twine(BitWidth / TI.getCharWidth()));
|
2010-05-28 08:27:15 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 09:31:33 +08:00
|
|
|
static void DefineExactWidthIntType(TargetInfo::IntType Ty,
|
|
|
|
const TargetInfo &TI,
|
|
|
|
MacroBuilder &Builder) {
|
2009-11-17 00:36:33 +08:00
|
|
|
int TypeWidth = TI.getTypeWidth(Ty);
|
2014-06-25 09:31:33 +08:00
|
|
|
bool IsSigned = TI.isTypeSigned(Ty);
|
2010-06-30 14:30:56 +08:00
|
|
|
|
|
|
|
// Use the target specified int64 type, when appropriate, so that [u]int64_t
|
|
|
|
// ends up being defined in terms of the correct type.
|
|
|
|
if (TypeWidth == 64)
|
2014-07-15 19:51:38 +08:00
|
|
|
Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
|
2010-06-30 14:30:56 +08:00
|
|
|
|
2014-07-09 00:07:36 +08:00
|
|
|
const char *Prefix = IsSigned ? "__INT" : "__UINT";
|
2014-06-25 09:31:33 +08:00
|
|
|
|
|
|
|
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
|
2009-11-17 00:36:33 +08:00
|
|
|
|
2014-07-18 04:12:32 +08:00
|
|
|
StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty));
|
2014-07-18 03:47:34 +08:00
|
|
|
Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
|
2014-06-25 09:31:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
|
|
|
|
const TargetInfo &TI,
|
|
|
|
MacroBuilder &Builder) {
|
|
|
|
int TypeWidth = TI.getTypeWidth(Ty);
|
|
|
|
bool IsSigned = TI.isTypeSigned(Ty);
|
|
|
|
|
|
|
|
// Use the target specified int64 type, when appropriate, so that [u]int64_t
|
|
|
|
// ends up being defined in terms of the correct type.
|
|
|
|
if (TypeWidth == 64)
|
2014-07-15 19:51:38 +08:00
|
|
|
Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2014-07-09 00:07:36 +08:00
|
|
|
const char *Prefix = IsSigned ? "__INT" : "__UINT";
|
2014-06-25 09:31:33 +08:00
|
|
|
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
|
|
|
|
const TargetInfo &TI,
|
|
|
|
MacroBuilder &Builder) {
|
|
|
|
TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
|
|
|
|
if (Ty == TargetInfo::NoInt)
|
|
|
|
return;
|
|
|
|
|
2014-07-09 00:07:36 +08:00
|
|
|
const char *Prefix = IsSigned ? "__INT_LEAST" : "__UINT_LEAST";
|
2014-06-25 09:31:33 +08:00
|
|
|
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
|
|
|
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
|
2014-06-25 09:31:33 +08:00
|
|
|
}
|
2017-12-08 07:04:11 +08:00
|
|
|
|
|
|
|
static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
|
|
|
|
const TargetInfo &TI, MacroBuilder &Builder) {
|
|
|
|
// stdint.h currently defines the fast int types as equivalent to the least
|
|
|
|
// types.
|
|
|
|
TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
|
|
|
|
if (Ty == TargetInfo::NoInt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *Prefix = IsSigned ? "__INT_FAST" : "__UINT_FAST";
|
|
|
|
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
|
|
|
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
|
|
|
|
|
|
|
|
DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
|
|
|
|
/// the specified properties.
|
|
|
|
static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
|
|
|
|
unsigned InlineWidth) {
|
|
|
|
// Fully-aligned, power-of-2 sizes no larger than the inline
|
|
|
|
// width will be inlined as lock-free operations.
|
|
|
|
if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 &&
|
|
|
|
TypeWidth <= InlineWidth)
|
|
|
|
return "2"; // "always lock free"
|
|
|
|
// We cannot be certain what operations the lib calls might be
|
|
|
|
// able to implement as lock-free on future processors.
|
|
|
|
return "1"; // "sometimes lock free"
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Add definitions required for a smooth interaction between
|
2017-12-08 07:04:11 +08:00
|
|
|
/// Objective-C++ automated reference counting and libstdc++ (4.2).
|
|
|
|
static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts,
|
|
|
|
MacroBuilder &Builder) {
|
|
|
|
Builder.defineMacro("_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR");
|
|
|
|
|
|
|
|
std::string Result;
|
|
|
|
{
|
|
|
|
// Provide specializations for the __is_scalar type trait so that
|
|
|
|
// lifetime-qualified objects are not considered "scalar" types, which
|
|
|
|
// libstdc++ uses as an indicator of the presence of trivial copy, assign,
|
|
|
|
// default-construct, and destruct semantics (none of which hold for
|
|
|
|
// lifetime-qualified objects in ARC).
|
|
|
|
llvm::raw_string_ostream Out(Result);
|
|
|
|
|
|
|
|
Out << "namespace std {\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "struct __true_type;\n"
|
|
|
|
<< "struct __false_type;\n"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
Out << "template<typename _Tp> struct __is_scalar;\n"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
if (LangOpts.ObjCAutoRefCount) {
|
|
|
|
Out << "template<typename _Tp>\n"
|
|
|
|
<< "struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n"
|
|
|
|
<< " enum { __value = 0 };\n"
|
|
|
|
<< " typedef __false_type __type;\n"
|
|
|
|
<< "};\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LangOpts.ObjCWeak) {
|
|
|
|
Out << "template<typename _Tp>\n"
|
|
|
|
<< "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n"
|
|
|
|
<< " enum { __value = 0 };\n"
|
|
|
|
<< " typedef __false_type __type;\n"
|
|
|
|
<< "};\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LangOpts.ObjCAutoRefCount) {
|
|
|
|
Out << "template<typename _Tp>\n"
|
|
|
|
<< "struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))"
|
|
|
|
<< " _Tp> {\n"
|
|
|
|
<< " enum { __value = 0 };\n"
|
|
|
|
<< " typedef __false_type __type;\n"
|
|
|
|
<< "};\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
Out << "}\n";
|
|
|
|
}
|
|
|
|
Builder.append(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
|
|
|
|
const LangOptions &LangOpts,
|
|
|
|
const FrontendOptions &FEOpts,
|
|
|
|
MacroBuilder &Builder) {
|
2020-02-19 08:13:23 +08:00
|
|
|
// C++ [cpp.predefined]p1:
|
|
|
|
// The following macro names shall be defined by the implementation:
|
|
|
|
|
|
|
|
// -- __STDC__
|
|
|
|
// [C++] Whether __STDC__ is predefined and if so, what its value is,
|
|
|
|
// are implementation-defined.
|
|
|
|
// (Removed in C++20.)
|
2017-12-08 07:04:11 +08:00
|
|
|
if (!LangOpts.MSVCCompat && !LangOpts.TraditionalCPP)
|
|
|
|
Builder.defineMacro("__STDC__");
|
2020-02-19 08:13:23 +08:00
|
|
|
// -- __STDC_HOSTED__
|
|
|
|
// The integer literal 1 if the implementation is a hosted
|
|
|
|
// implementation or the integer literal 0 if it is not.
|
2017-12-08 07:04:11 +08:00
|
|
|
if (LangOpts.Freestanding)
|
|
|
|
Builder.defineMacro("__STDC_HOSTED__", "0");
|
|
|
|
else
|
|
|
|
Builder.defineMacro("__STDC_HOSTED__");
|
|
|
|
|
2020-02-19 08:13:23 +08:00
|
|
|
// -- __STDC_VERSION__
|
|
|
|
// [C++] Whether __STDC_VERSION__ is predefined and if so, what its
|
|
|
|
// value is, are implementation-defined.
|
|
|
|
// (Removed in C++20.)
|
2017-12-08 07:04:11 +08:00
|
|
|
if (!LangOpts.CPlusPlus) {
|
|
|
|
if (LangOpts.C17)
|
|
|
|
Builder.defineMacro("__STDC_VERSION__", "201710L");
|
|
|
|
else if (LangOpts.C11)
|
|
|
|
Builder.defineMacro("__STDC_VERSION__", "201112L");
|
|
|
|
else if (LangOpts.C99)
|
|
|
|
Builder.defineMacro("__STDC_VERSION__", "199901L");
|
|
|
|
else if (!LangOpts.GNUMode && LangOpts.Digraphs)
|
|
|
|
Builder.defineMacro("__STDC_VERSION__", "199409L");
|
|
|
|
} else {
|
2020-02-19 08:13:23 +08:00
|
|
|
// -- __cplusplus
|
|
|
|
// [C++20] The integer literal 202002L.
|
2020-04-22 03:37:19 +08:00
|
|
|
if (LangOpts.CPlusPlus20)
|
2020-02-19 08:13:23 +08:00
|
|
|
Builder.defineMacro("__cplusplus", "202002L");
|
|
|
|
// [C++17] The integer literal 201703L.
|
2017-12-08 07:04:11 +08:00
|
|
|
else if (LangOpts.CPlusPlus17)
|
|
|
|
Builder.defineMacro("__cplusplus", "201703L");
|
2020-02-19 08:13:23 +08:00
|
|
|
// [C++14] The name __cplusplus is defined to the value 201402L when
|
|
|
|
// compiling a C++ translation unit.
|
2017-12-08 07:04:11 +08:00
|
|
|
else if (LangOpts.CPlusPlus14)
|
|
|
|
Builder.defineMacro("__cplusplus", "201402L");
|
2020-02-19 08:13:23 +08:00
|
|
|
// [C++11] The name __cplusplus is defined to the value 201103L when
|
|
|
|
// compiling a C++ translation unit.
|
2017-12-08 07:04:11 +08:00
|
|
|
else if (LangOpts.CPlusPlus11)
|
|
|
|
Builder.defineMacro("__cplusplus", "201103L");
|
2020-02-19 08:13:23 +08:00
|
|
|
// [C++03] The name __cplusplus is defined to the value 199711L when
|
|
|
|
// compiling a C++ translation unit.
|
2017-12-08 07:04:11 +08:00
|
|
|
else
|
|
|
|
Builder.defineMacro("__cplusplus", "199711L");
|
|
|
|
|
2020-02-19 08:13:23 +08:00
|
|
|
// -- __STDCPP_DEFAULT_NEW_ALIGNMENT__
|
|
|
|
// [C++17] An integer literal of type std::size_t whose value is the
|
|
|
|
// alignment guaranteed by a call to operator new(std::size_t)
|
2017-12-08 07:04:11 +08:00
|
|
|
//
|
|
|
|
// We provide this in all language modes, since it seems generally useful.
|
|
|
|
Builder.defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__",
|
|
|
|
Twine(TI.getNewAlign() / TI.getCharWidth()) +
|
|
|
|
TI.getTypeConstantSuffix(TI.getSizeType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// In C11 these are environment macros. In C++11 they are only defined
|
|
|
|
// as part of <cuchar>. To prevent breakage when mixing C and C++
|
|
|
|
// code, define these macros unconditionally. We can define them
|
|
|
|
// unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit
|
|
|
|
// and 32-bit character literals.
|
|
|
|
Builder.defineMacro("__STDC_UTF_16__", "1");
|
|
|
|
Builder.defineMacro("__STDC_UTF_32__", "1");
|
|
|
|
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LangOpts.ObjC)
|
2017-12-08 07:04:11 +08:00
|
|
|
Builder.defineMacro("__OBJC__");
|
|
|
|
|
|
|
|
// OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros.
|
|
|
|
if (LangOpts.OpenCL) {
|
2018-04-12 22:17:04 +08:00
|
|
|
if (LangOpts.CPlusPlus) {
|
|
|
|
if (LangOpts.OpenCLCPlusPlusVersion == 100)
|
|
|
|
Builder.defineMacro("__OPENCL_CPP_VERSION__", "100");
|
|
|
|
else
|
2019-07-18 18:02:35 +08:00
|
|
|
llvm_unreachable("Unsupported C++ version for OpenCL");
|
2018-04-12 22:17:04 +08:00
|
|
|
Builder.defineMacro("__CL_CPP_VERSION_1_0__", "100");
|
|
|
|
} else {
|
|
|
|
// OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
|
|
|
|
// language standard with which the program is compiled. __OPENCL_VERSION__
|
|
|
|
// is for the OpenCL version supported by the OpenCL device, which is not
|
|
|
|
// necessarily the language standard with which the program is compiled.
|
|
|
|
// A shared OpenCL header file requires a macro to indicate the language
|
|
|
|
// standard. As a workaround, __OPENCL_C_VERSION__ is defined for
|
|
|
|
// OpenCL v1.0 and v1.1.
|
|
|
|
switch (LangOpts.OpenCLVersion) {
|
|
|
|
case 100:
|
|
|
|
Builder.defineMacro("__OPENCL_C_VERSION__", "100");
|
|
|
|
break;
|
|
|
|
case 110:
|
|
|
|
Builder.defineMacro("__OPENCL_C_VERSION__", "110");
|
|
|
|
break;
|
|
|
|
case 120:
|
|
|
|
Builder.defineMacro("__OPENCL_C_VERSION__", "120");
|
|
|
|
break;
|
|
|
|
case 200:
|
|
|
|
Builder.defineMacro("__OPENCL_C_VERSION__", "200");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported OpenCL version");
|
|
|
|
}
|
2019-08-12 18:44:07 +08:00
|
|
|
}
|
|
|
|
Builder.defineMacro("CL_VERSION_1_0", "100");
|
|
|
|
Builder.defineMacro("CL_VERSION_1_1", "110");
|
|
|
|
Builder.defineMacro("CL_VERSION_1_2", "120");
|
|
|
|
Builder.defineMacro("CL_VERSION_2_0", "200");
|
2018-04-12 22:17:04 +08:00
|
|
|
|
2019-08-12 18:44:07 +08:00
|
|
|
if (TI.isLittleEndian())
|
|
|
|
Builder.defineMacro("__ENDIAN_LITTLE__");
|
2018-04-12 22:17:04 +08:00
|
|
|
|
2019-08-12 18:44:07 +08:00
|
|
|
if (LangOpts.FastRelaxedMath)
|
|
|
|
Builder.defineMacro("__FAST_RELAXED_MATH__");
|
2017-12-08 07:04:11 +08:00
|
|
|
}
|
2019-07-26 23:21:01 +08:00
|
|
|
|
|
|
|
if (LangOpts.SYCL) {
|
|
|
|
// SYCL Version is set to a value when building SYCL applications
|
|
|
|
if (LangOpts.SYCLVersion == 2017)
|
|
|
|
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
|
|
|
|
}
|
|
|
|
|
2017-12-08 07:04:11 +08:00
|
|
|
// Not "standard" per se, but available even with the -undef flag.
|
|
|
|
if (LangOpts.AsmPreprocessor)
|
|
|
|
Builder.defineMacro("__ASSEMBLER__");
|
2018-04-25 09:10:37 +08:00
|
|
|
if (LangOpts.CUDA && !LangOpts.HIP)
|
2017-12-08 07:04:11 +08:00
|
|
|
Builder.defineMacro("__CUDA__");
|
2018-04-25 21:33:19 +08:00
|
|
|
if (LangOpts.HIP) {
|
2018-04-25 09:10:37 +08:00
|
|
|
Builder.defineMacro("__HIP__");
|
2018-04-25 21:33:19 +08:00
|
|
|
Builder.defineMacro("__HIPCC__");
|
|
|
|
if (LangOpts.CUDAIsDevice)
|
|
|
|
Builder.defineMacro("__HIP_DEVICE_COMPILE__");
|
|
|
|
}
|
2017-12-08 07:04:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Initialize the predefined C++ language feature test macros defined in
|
|
|
|
/// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
|
|
|
|
static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
|
|
|
|
MacroBuilder &Builder) {
|
|
|
|
// C++98 features.
|
|
|
|
if (LangOpts.RTTI)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_rtti", "199711L");
|
2014-11-13 05:16:38 +08:00
|
|
|
if (LangOpts.CXXExceptions)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_exceptions", "199711L");
|
2014-11-13 05:16:38 +08:00
|
|
|
|
2013-11-28 06:58:16 +08:00
|
|
|
// C++11 features.
|
|
|
|
if (LangOpts.CPlusPlus11) {
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_unicode_characters", "200704L");
|
|
|
|
Builder.defineMacro("__cpp_raw_strings", "200710L");
|
|
|
|
Builder.defineMacro("__cpp_unicode_literals", "200710L");
|
|
|
|
Builder.defineMacro("__cpp_user_defined_literals", "200809L");
|
|
|
|
Builder.defineMacro("__cpp_lambdas", "200907L");
|
2013-11-28 06:58:16 +08:00
|
|
|
Builder.defineMacro("__cpp_constexpr",
|
2020-04-22 03:37:19 +08:00
|
|
|
LangOpts.CPlusPlus20 ? "201907L" :
|
2018-06-14 08:40:20 +08:00
|
|
|
LangOpts.CPlusPlus17 ? "201603L" :
|
|
|
|
LangOpts.CPlusPlus14 ? "201304L" : "200704");
|
2019-12-20 04:57:04 +08:00
|
|
|
Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L");
|
2016-09-29 04:26:06 +08:00
|
|
|
Builder.defineMacro("__cpp_range_based_for",
|
2018-06-14 08:40:20 +08:00
|
|
|
LangOpts.CPlusPlus17 ? "201603L" : "200907");
|
2016-09-29 03:44:50 +08:00
|
|
|
Builder.defineMacro("__cpp_static_assert",
|
2018-06-14 08:40:20 +08:00
|
|
|
LangOpts.CPlusPlus17 ? "201411L" : "200410");
|
|
|
|
Builder.defineMacro("__cpp_decltype", "200707L");
|
|
|
|
Builder.defineMacro("__cpp_attributes", "200809L");
|
|
|
|
Builder.defineMacro("__cpp_rvalue_references", "200610L");
|
|
|
|
Builder.defineMacro("__cpp_variadic_templates", "200704L");
|
|
|
|
Builder.defineMacro("__cpp_initializer_lists", "200806L");
|
|
|
|
Builder.defineMacro("__cpp_delegating_constructors", "200604L");
|
|
|
|
Builder.defineMacro("__cpp_nsdmi", "200809L");
|
|
|
|
Builder.defineMacro("__cpp_inheriting_constructors", "201511L");
|
|
|
|
Builder.defineMacro("__cpp_ref_qualifiers", "200710L");
|
|
|
|
Builder.defineMacro("__cpp_alias_templates", "200704L");
|
2013-11-28 06:58:16 +08:00
|
|
|
}
|
2017-08-11 11:39:40 +08:00
|
|
|
if (LangOpts.ThreadsafeStatics)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_threadsafe_static_init", "200806L");
|
2013-11-28 06:58:16 +08:00
|
|
|
|
|
|
|
// C++14 features.
|
2014-08-19 23:55:55 +08:00
|
|
|
if (LangOpts.CPlusPlus14) {
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_binary_literals", "201304L");
|
|
|
|
Builder.defineMacro("__cpp_digit_separators", "201309L");
|
2019-12-20 07:18:59 +08:00
|
|
|
Builder.defineMacro("__cpp_init_captures",
|
2020-04-22 03:37:19 +08:00
|
|
|
LangOpts.CPlusPlus20 ? "201803L" : "201304L");
|
2019-12-20 04:57:04 +08:00
|
|
|
Builder.defineMacro("__cpp_generic_lambdas",
|
2020-04-22 03:37:19 +08:00
|
|
|
LangOpts.CPlusPlus20 ? "201707L" : "201304L");
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_decltype_auto", "201304L");
|
|
|
|
Builder.defineMacro("__cpp_return_type_deduction", "201304L");
|
|
|
|
Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L");
|
|
|
|
Builder.defineMacro("__cpp_variable_templates", "201304L");
|
2013-11-28 06:58:16 +08:00
|
|
|
}
|
2014-11-13 05:16:38 +08:00
|
|
|
if (LangOpts.SizedDeallocation)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_sized_deallocation", "201309L");
|
2016-09-29 03:44:50 +08:00
|
|
|
|
|
|
|
// C++17 features.
|
2017-12-05 04:27:34 +08:00
|
|
|
if (LangOpts.CPlusPlus17) {
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_hex_float", "201603L");
|
|
|
|
Builder.defineMacro("__cpp_inline_variables", "201606L");
|
|
|
|
Builder.defineMacro("__cpp_noexcept_function_type", "201510L");
|
|
|
|
Builder.defineMacro("__cpp_capture_star_this", "201603L");
|
|
|
|
Builder.defineMacro("__cpp_if_constexpr", "201606L");
|
2019-12-20 04:57:04 +08:00
|
|
|
Builder.defineMacro("__cpp_deduction_guides", "201703L"); // (not latest)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_template_auto", "201606L"); // (old name)
|
|
|
|
Builder.defineMacro("__cpp_namespace_attributes", "201411L");
|
|
|
|
Builder.defineMacro("__cpp_enumerator_attributes", "201411L");
|
|
|
|
Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
|
|
|
|
Builder.defineMacro("__cpp_variadic_using", "201611L");
|
|
|
|
Builder.defineMacro("__cpp_aggregate_bases", "201603L");
|
|
|
|
Builder.defineMacro("__cpp_structured_bindings", "201606L");
|
2019-12-20 04:57:04 +08:00
|
|
|
Builder.defineMacro("__cpp_nontype_template_args",
|
|
|
|
"201411L"); // (not latest)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_fold_expressions", "201603L");
|
|
|
|
Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
|
|
|
|
Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");
|
2016-09-29 03:44:50 +08:00
|
|
|
}
|
2018-08-04 07:12:37 +08:00
|
|
|
if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable)
|
2018-06-14 08:40:20 +08:00
|
|
|
Builder.defineMacro("__cpp_aligned_new", "201606L");
|
|
|
|
if (LangOpts.RelaxedTemplateTemplateArgs)
|
|
|
|
Builder.defineMacro("__cpp_template_template_args", "201611L");
|
2016-09-29 03:44:50 +08:00
|
|
|
|
2018-11-15 05:04:34 +08:00
|
|
|
// C++20 features.
|
2020-04-22 03:37:19 +08:00
|
|
|
if (LangOpts.CPlusPlus20) {
|
2019-12-20 04:57:04 +08:00
|
|
|
//Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
|
2020-01-24 06:43:22 +08:00
|
|
|
Builder.defineMacro("__cpp_concepts", "201907L");
|
2019-05-09 11:59:21 +08:00
|
|
|
Builder.defineMacro("__cpp_conditional_explicit", "201806L");
|
2019-12-20 04:57:04 +08:00
|
|
|
//Builder.defineMacro("__cpp_consteval", "201811L");
|
2019-10-03 08:39:37 +08:00
|
|
|
Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
|
2019-09-05 04:30:37 +08:00
|
|
|
Builder.defineMacro("__cpp_constinit", "201907L");
|
2019-12-20 04:57:04 +08:00
|
|
|
//Builder.defineMacro("__cpp_coroutines", "201902L");
|
|
|
|
Builder.defineMacro("__cpp_designated_initializers", "201707L");
|
2019-12-16 14:20:06 +08:00
|
|
|
Builder.defineMacro("__cpp_impl_three_way_comparison", "201907L");
|
2019-12-20 04:57:04 +08:00
|
|
|
//Builder.defineMacro("__cpp_modules", "201907L");
|
|
|
|
//Builder.defineMacro("__cpp_using_enum", "201907L");
|
2019-09-05 04:30:37 +08:00
|
|
|
}
|
2018-11-15 05:04:34 +08:00
|
|
|
if (LangOpts.Char8)
|
|
|
|
Builder.defineMacro("__cpp_char8_t", "201811L");
|
2019-01-12 01:09:22 +08:00
|
|
|
Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
|
2018-11-15 05:04:34 +08:00
|
|
|
|
2016-09-29 03:44:50 +08:00
|
|
|
// TS features.
|
2019-02-24 05:06:26 +08:00
|
|
|
if (LangOpts.Coroutines)
|
2017-05-25 22:58:46 +08:00
|
|
|
Builder.defineMacro("__cpp_coroutines", "201703L");
|
2013-11-28 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
static void InitializePredefinedMacros(const TargetInfo &TI,
|
|
|
|
const LangOptions &LangOpts,
|
2010-01-14 02:51:17 +08:00
|
|
|
const FrontendOptions &FEOpts,
|
2019-10-15 04:15:01 +08:00
|
|
|
const PreprocessorOptions &PPOpts,
|
2010-01-10 00:17:37 +08:00
|
|
|
MacroBuilder &Builder) {
|
2009-04-21 13:40:52 +08:00
|
|
|
// Compiler version introspection macros.
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__llvm__"); // LLVM Backend
|
|
|
|
Builder.defineMacro("__clang__"); // Clang Frontend
|
2010-04-30 10:51:06 +08:00
|
|
|
#define TOSTR2(X) #X
|
|
|
|
#define TOSTR(X) TOSTR2(X)
|
|
|
|
Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
|
|
|
|
Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
|
|
|
|
Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
|
Simplify Clang's version number configuration in CMake.
Currently, the Clang version is computed as follows:
1. LLVM defines major, minor, and patch versions, all statically set. Today,
these are 4, 0, and 0, respectively.
2. The static version numbers are combined into PACKAGE_VERSION along with a
suffix, so the result today looks like "4.0.0svn".
3. Clang extracts CLANG_VERSION from PACKAGE_VERSION using a regexp. The regexp
allows the patch level to omitted, and drops any non-digit trailing values.
Today, this result looks like "4.0.0".
4. CLANG_VERSION is then split further into CLANG_VERSION_MAJOR and
CLANG_VERSION_MINOR. Today, these resolve to 4 and 0, respectively.
5. If CLANG_VERSION matches a regexp with three version components, then
CLANG_VERSION_PATCHLEVEL is extracted and the CLANG_HAS_VERSION_PATCHLEVEL
variable is set to 1. Today, these values are 0 and 1, respectively.
6. The CLANG_VERSION_* variables (and CLANG_HAS_VERSION_PATCHLEVEL) are
configured into [llvm/tools/clang/]include/clang/Basic/Version.inc
verbatim by CMake.
7. In [llvm/tools/clang/]include/clang/Basic/Version.h, macros are defined
conditionally, based on CLANG_HAS_VERSION_PATCHLEVEL, to compute
CLANG_VERSION_STRING as either a two- or three-level version number. Today,
this value is "4.0.0", because despite the patchlevel being 0, it was
matched by regexp and is thus "HAS"ed by the preprocessor. This string is
then used wherever Clang's "version" is needed [*].
[*] Including, notably, by compiler-rt, for computing its installation path.
This change collapses steps 2-5 by defaulting Clang to use LLVM's (non-string)
version components for the Clang version (see [*] for why not PACKAGE_VERSION),
and collapses steps 6 and 7 by simply writing CLANG_VERSION_STRING into
Version.inc. The Clang version today always uses the patchlevel form, so the
collapsed Version.inc does not have logic for a version without a patch level.
Historically speaking, this technique began with the VER file in r82085 (which
survives in the form of the regexp in #3). The major, minor, and patchlevel
versions were introduced by r106863 (which remains in #4-6). The VER file itself
was deleted in favor of the LLVM version number in r106914. On the LLVM side,
the individual LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, and PACKAGE_VERSION
weren't introduced for nearly two more years, until r150405.
llvm-svn: 281666
2016-09-16 06:12:26 +08:00
|
|
|
#undef TOSTR
|
|
|
|
#undef TOSTR2
|
2017-12-08 07:04:11 +08:00
|
|
|
Builder.defineMacro("__clang_version__",
|
2012-10-09 02:49:39 +08:00
|
|
|
"\"" CLANG_VERSION_STRING " "
|
|
|
|
+ getClangFullRepositoryVersion() + "\"");
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
|
|
|
|
if (LangOpts.GNUCVersion != 0) {
|
|
|
|
// Major, minor, patch, are given two decimal places each, so 4.2.1 becomes
|
|
|
|
// 40201.
|
|
|
|
unsigned GNUCMajor = LangOpts.GNUCVersion / 100 / 100;
|
|
|
|
unsigned GNUCMinor = LangOpts.GNUCVersion / 100 % 100;
|
|
|
|
unsigned GNUCPatch = LangOpts.GNUCVersion % 100;
|
|
|
|
Builder.defineMacro("__GNUC__", Twine(GNUCMajor));
|
|
|
|
Builder.defineMacro("__GNUC_MINOR__", Twine(GNUCMinor));
|
|
|
|
Builder.defineMacro("__GNUC_PATCHLEVEL__", Twine(GNUCPatch));
|
2012-03-11 06:21:14 +08:00
|
|
|
Builder.defineMacro("__GXX_ABI_VERSION", "1002");
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
|
|
|
|
if (LangOpts.CPlusPlus) {
|
|
|
|
Builder.defineMacro("__GNUG__", Twine(GNUCMajor));
|
|
|
|
Builder.defineMacro("__GXX_WEAK__");
|
|
|
|
}
|
2012-03-11 06:21:14 +08:00
|
|
|
}
|
2011-03-31 08:53:51 +08:00
|
|
|
|
2012-01-17 01:27:18 +08:00
|
|
|
// Define macros for the C11 / C++11 memory orderings
|
|
|
|
Builder.defineMacro("__ATOMIC_RELAXED", "0");
|
|
|
|
Builder.defineMacro("__ATOMIC_CONSUME", "1");
|
|
|
|
Builder.defineMacro("__ATOMIC_ACQUIRE", "2");
|
|
|
|
Builder.defineMacro("__ATOMIC_RELEASE", "3");
|
|
|
|
Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
|
|
|
|
Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
|
|
|
|
|
2017-08-05 02:16:31 +08:00
|
|
|
// Define macros for the OpenCL memory scope.
|
2017-08-16 12:15:28 +08:00
|
|
|
// The values should match AtomicScopeOpenCLModel::ID enum.
|
2017-08-16 00:02:49 +08:00
|
|
|
static_assert(
|
|
|
|
static_cast<unsigned>(AtomicScopeOpenCLModel::WorkGroup) == 1 &&
|
|
|
|
static_cast<unsigned>(AtomicScopeOpenCLModel::Device) == 2 &&
|
|
|
|
static_cast<unsigned>(AtomicScopeOpenCLModel::AllSVMDevices) == 3 &&
|
|
|
|
static_cast<unsigned>(AtomicScopeOpenCLModel::SubGroup) == 4,
|
|
|
|
"Invalid OpenCL memory scope enum definition");
|
2017-08-05 02:16:31 +08:00
|
|
|
Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0");
|
|
|
|
Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1");
|
|
|
|
Builder.defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2");
|
|
|
|
Builder.defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3");
|
|
|
|
Builder.defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4");
|
|
|
|
|
2012-02-19 00:12:34 +08:00
|
|
|
// Support for #pragma redefine_extname (Sun compatibility)
|
|
|
|
Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
|
|
|
|
|
2019-07-16 01:47:22 +08:00
|
|
|
// Previously this macro was set to a string aiming to achieve compatibility
|
|
|
|
// with GCC 4.2.1. Now, just return the full Clang version
|
|
|
|
Builder.defineMacro("__VERSION__", "\"" +
|
2019-07-13 14:27:35 +08:00
|
|
|
Twine(getClangFullCPPVersion()) + "\"");
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Initialize language-specific preprocessor defines.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Standard conforming mode?
|
2014-07-01 04:36:33 +08:00
|
|
|
if (!LangOpts.GNUMode && !LangOpts.MSVCCompat)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__STRICT_ANSI__");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LangOpts.ObjC) {
|
2012-06-20 14:18:46 +08:00
|
|
|
if (LangOpts.ObjCRuntime.isNonFragile()) {
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__OBJC2__");
|
2017-12-08 07:04:11 +08:00
|
|
|
|
2011-09-12 23:17:19 +08:00
|
|
|
if (LangOpts.ObjCExceptions)
|
|
|
|
Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2011-09-14 01:21:33 +08:00
|
|
|
if (LangOpts.getGC() != LangOptions::NonGC)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__OBJC_GC__");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
if (LangOpts.ObjCRuntime.isNeXTFamily())
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__NEXT_RUNTIME__");
|
2012-06-19 08:37:39 +08:00
|
|
|
|
2018-05-22 18:13:06 +08:00
|
|
|
if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::GNUstep) {
|
|
|
|
auto version = LangOpts.ObjCRuntime.getVersion();
|
|
|
|
std::string versionString = "1";
|
|
|
|
// Don't rely on the tuple argument, because we can be asked to target
|
|
|
|
// later ABIs than we actually support, so clamp these values to those
|
|
|
|
// currently supported
|
|
|
|
if (version >= VersionTuple(2, 0))
|
|
|
|
Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__", "20");
|
|
|
|
else
|
|
|
|
Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__",
|
|
|
|
"1" + Twine(std::min(8U, version.getMinor().getValueOr(0))));
|
|
|
|
}
|
|
|
|
|
2013-09-17 00:31:49 +08:00
|
|
|
if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
|
|
|
|
VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
|
|
|
|
|
|
|
|
unsigned minor = 0;
|
|
|
|
if (tuple.getMinor().hasValue())
|
|
|
|
minor = tuple.getMinor().getValue();
|
|
|
|
|
|
|
|
unsigned subminor = 0;
|
|
|
|
if (tuple.getSubminor().hasValue())
|
|
|
|
subminor = tuple.getSubminor().getValue();
|
|
|
|
|
|
|
|
Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
|
|
|
|
Twine(tuple.getMajor() * 10000 + minor * 100 +
|
|
|
|
subminor));
|
|
|
|
}
|
|
|
|
|
2012-06-19 08:37:39 +08:00
|
|
|
Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))");
|
|
|
|
Builder.defineMacro("IBOutletCollection(ClassName)",
|
|
|
|
"__attribute__((iboutletcollection(ClassName)))");
|
|
|
|
Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
|
2014-08-09 07:46:25 +08:00
|
|
|
Builder.defineMacro("IBInspectable", "");
|
|
|
|
Builder.defineMacro("IB_DESIGNABLE", "");
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2017-01-21 00:48:25 +08:00
|
|
|
// Define a macro that describes the Objective-C boolean type even for C
|
|
|
|
// and C++ since BOOL can be used from non Objective-C code.
|
|
|
|
Builder.defineMacro("__OBJC_BOOL_IS_BOOL",
|
|
|
|
Twine(TI.useSignedCharForObjCBool() ? "0" : "1"));
|
|
|
|
|
2013-11-28 06:58:16 +08:00
|
|
|
if (LangOpts.CPlusPlus)
|
|
|
|
InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// darwin_constant_cfstrings controls this. This is also dependent
|
|
|
|
// on other things like the runtime I believe. This is set even for C code.
|
2011-07-06 00:00:59 +08:00
|
|
|
if (!LangOpts.NoConstantCFStrings)
|
|
|
|
Builder.defineMacro("__CONSTANT_CFSTRINGS__");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LangOpts.ObjC)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("OBJC_NEW_PROPERTIES");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
|
|
|
if (LangOpts.PascalStrings)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__PASCAL_STRINGS__");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
|
|
|
if (LangOpts.Blocks) {
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
|
|
|
|
Builder.defineMacro("__BLOCKS__");
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-10-28 04:02:19 +08:00
|
|
|
if (!LangOpts.MSVCCompat && LangOpts.Exceptions)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__EXCEPTIONS");
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
if (LangOpts.GNUCVersion && LangOpts.RTTI)
|
2010-05-28 08:27:15 +08:00
|
|
|
Builder.defineMacro("__GXX_RTTI");
|
2017-11-29 15:25:12 +08:00
|
|
|
|
2010-02-11 02:49:11 +08:00
|
|
|
if (LangOpts.SjLjExceptions)
|
|
|
|
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
|
2017-11-29 15:25:12 +08:00
|
|
|
else if (LangOpts.SEHExceptions)
|
|
|
|
Builder.defineMacro("__SEH__");
|
|
|
|
else if (LangOpts.DWARFExceptions &&
|
|
|
|
(TI.getTriple().isThumb() || TI.getTriple().isARM()))
|
|
|
|
Builder.defineMacro("__ARM_DWARF_EH__");
|
2009-10-01 21:33:33 +08:00
|
|
|
|
2011-04-24 03:48:40 +08:00
|
|
|
if (LangOpts.Deprecated)
|
|
|
|
Builder.defineMacro("__DEPRECATED");
|
|
|
|
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__private_extern__", "extern");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-18 01:15:52 +08:00
|
|
|
if (LangOpts.MicrosoftExt) {
|
2012-09-06 01:30:57 +08:00
|
|
|
if (LangOpts.WChar) {
|
|
|
|
// wchar_t supported as a keyword.
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("_WCHAR_T_DEFINED");
|
|
|
|
Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
|
2012-09-06 01:30:57 +08:00
|
|
|
}
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
if (LangOpts.Optimize)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__OPTIMIZE__");
|
2009-04-21 13:40:52 +08:00
|
|
|
if (LangOpts.OptimizeSize)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__OPTIMIZE_SIZE__");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-03 10:46:46 +08:00
|
|
|
if (LangOpts.FastMath)
|
|
|
|
Builder.defineMacro("__FAST_MATH__");
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Initialize target-specific preprocessor defines.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-08-09 00:09:12 +08:00
|
|
|
// __BYTE_ORDER__ was added in GCC 4.6. It's analogous
|
|
|
|
// to the macro __BYTE_ORDER (no trailing underscores)
|
|
|
|
// from glibc's <endian.h> header.
|
2012-07-28 02:34:31 +08:00
|
|
|
// We don't support the PDP-11 as a target, but include
|
|
|
|
// the define so it can still be compared against.
|
|
|
|
Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234");
|
|
|
|
Builder.defineMacro("__ORDER_BIG_ENDIAN__", "4321");
|
|
|
|
Builder.defineMacro("__ORDER_PDP_ENDIAN__", "3412");
|
2014-03-10 20:06:29 +08:00
|
|
|
if (TI.isBigEndian()) {
|
2012-07-28 02:34:31 +08:00
|
|
|
Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__");
|
2014-03-10 20:06:29 +08:00
|
|
|
Builder.defineMacro("__BIG_ENDIAN__");
|
|
|
|
} else {
|
2012-07-28 02:34:31 +08:00
|
|
|
Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__");
|
2014-03-10 20:06:29 +08:00
|
|
|
Builder.defineMacro("__LITTLE_ENDIAN__");
|
|
|
|
}
|
2012-08-11 03:12:37 +08:00
|
|
|
|
|
|
|
if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64
|
|
|
|
&& TI.getIntWidth() == 32) {
|
|
|
|
Builder.defineMacro("_LP64");
|
|
|
|
Builder.defineMacro("__LP64__");
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:58:10 +08:00
|
|
|
if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
|
|
|
|
&& TI.getIntWidth() == 32) {
|
|
|
|
Builder.defineMacro("_ILP32");
|
|
|
|
Builder.defineMacro("__ILP32__");
|
|
|
|
}
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Define type sizing macros based on the target properties.
|
|
|
|
assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
|
2016-09-23 20:23:44 +08:00
|
|
|
Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
|
2010-01-10 00:17:37 +08:00
|
|
|
|
2013-09-05 19:23:21 +08:00
|
|
|
DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
|
|
|
|
DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
|
|
|
|
DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
|
|
|
|
DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
|
|
|
|
DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
|
2017-12-05 17:13:18 +08:00
|
|
|
DefineTypeSize("__WINT_MAX__", TI.getWIntType(), TI, Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
|
2013-03-28 16:36:54 +08:00
|
|
|
DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
|
|
|
|
DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
|
|
|
|
DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
|
|
|
|
DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2010-05-28 08:27:15 +08:00
|
|
|
DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_PTRDIFF_T__",
|
|
|
|
TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_SIZE_T__",
|
|
|
|
TI.getTypeWidth(TI.getSizeType()), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_WCHAR_T__",
|
|
|
|
TI.getTypeWidth(TI.getWCharType()), TI, Builder);
|
|
|
|
DefineTypeSizeof("__SIZEOF_WINT_T__",
|
|
|
|
TI.getTypeWidth(TI.getWIntType()), TI, Builder);
|
2015-02-12 19:36:56 +08:00
|
|
|
if (TI.hasInt128Type())
|
2012-11-29 13:41:51 +08:00
|
|
|
DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
|
2010-05-28 08:27:15 +08:00
|
|
|
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
|
2014-07-16 05:58:11 +08:00
|
|
|
Builder.defineMacro("__INTMAX_C_SUFFIX__",
|
2014-07-18 04:12:32 +08:00
|
|
|
TI.getTypeConstantSuffix(TI.getIntMaxType()));
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
|
2014-07-16 05:58:11 +08:00
|
|
|
Builder.defineMacro("__UINTMAX_C_SUFFIX__",
|
2014-07-18 04:12:32 +08:00
|
|
|
TI.getTypeConstantSuffix(TI.getUIntMaxType()));
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder);
|
|
|
|
DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
|
|
|
|
DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
|
|
|
|
DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
|
2014-07-15 19:30:00 +08:00
|
|
|
DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
|
|
|
|
DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
|
|
|
|
DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
|
|
|
|
DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
|
|
|
|
DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
|
|
|
|
DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
|
2014-07-18 02:31:20 +08:00
|
|
|
DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
|
2010-05-28 08:27:15 +08:00
|
|
|
DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
|
|
|
|
DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
|
2010-01-10 00:17:37 +08:00
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
DefineTypeWidth("__UINTMAX_WIDTH__", TI.getUIntMaxType(), TI, Builder);
|
|
|
|
DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
|
|
|
|
DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
|
|
|
|
DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2019-02-21 04:27:33 +08:00
|
|
|
if (TI.hasFloat16Type())
|
|
|
|
DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
|
2012-11-10 08:20:38 +08:00
|
|
|
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
|
|
|
|
DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
|
|
|
|
DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
|
|
|
// Define a __POINTER_WIDTH__ macro for stdint.h.
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__POINTER_WIDTH__",
|
2011-07-23 18:55:15 +08:00
|
|
|
Twine((int)TI.getPointerWidth(0)));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2015-02-06 09:25:07 +08:00
|
|
|
// Define __BIGGEST_ALIGNMENT__ to be compatible with gcc.
|
|
|
|
Builder.defineMacro("__BIGGEST_ALIGNMENT__",
|
|
|
|
Twine(TI.getSuitableAlign() / TI.getCharWidth()) );
|
|
|
|
|
2009-06-05 15:05:05 +08:00
|
|
|
if (!LangOpts.CharIsSigned)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__CHAR_UNSIGNED__");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
2012-05-04 19:23:40 +08:00
|
|
|
if (!TargetInfo::isTypeSigned(TI.getWCharType()))
|
|
|
|
Builder.defineMacro("__WCHAR_UNSIGNED__");
|
|
|
|
|
2011-04-21 13:45:45 +08:00
|
|
|
if (!TargetInfo::isTypeSigned(TI.getWIntType()))
|
|
|
|
Builder.defineMacro("__WINT_UNSIGNED__");
|
|
|
|
|
2009-11-12 16:08:27 +08:00
|
|
|
// Define exact-width integer types for stdint.h
|
2014-07-18 03:47:34 +08:00
|
|
|
DefineExactWidthIntType(TargetInfo::SignedChar, TI, Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 16:08:27 +08:00
|
|
|
if (TI.getShortWidth() > TI.getCharWidth())
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder);
|
|
|
|
|
2009-11-12 16:08:27 +08:00
|
|
|
if (TI.getIntWidth() > TI.getShortWidth())
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder);
|
|
|
|
|
2009-11-12 16:08:27 +08:00
|
|
|
if (TI.getLongWidth() > TI.getIntWidth())
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder);
|
|
|
|
|
2009-11-12 16:08:27 +08:00
|
|
|
if (TI.getLongLongWidth() > TI.getLongWidth())
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
|
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder);
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
if (TI.getShortWidth() > TI.getCharWidth()) {
|
|
|
|
DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder);
|
|
|
|
}
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
if (TI.getIntWidth() > TI.getShortWidth()) {
|
|
|
|
DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder);
|
|
|
|
}
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
if (TI.getLongWidth() > TI.getIntWidth()) {
|
|
|
|
DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder);
|
|
|
|
}
|
2014-06-25 09:31:33 +08:00
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
if (TI.getLongLongWidth() > TI.getLongWidth()) {
|
|
|
|
DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder);
|
|
|
|
DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder);
|
2014-06-25 09:31:33 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 03:24:06 +08:00
|
|
|
DefineLeastWidthIntType(8, true, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(8, false, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(16, true, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(16, false, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(32, true, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(32, false, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(64, true, TI, Builder);
|
|
|
|
DefineLeastWidthIntType(64, false, TI, Builder);
|
|
|
|
|
|
|
|
DefineFastIntType(8, true, TI, Builder);
|
|
|
|
DefineFastIntType(8, false, TI, Builder);
|
|
|
|
DefineFastIntType(16, true, TI, Builder);
|
|
|
|
DefineFastIntType(16, false, TI, Builder);
|
|
|
|
DefineFastIntType(32, true, TI, Builder);
|
|
|
|
DefineFastIntType(32, false, TI, Builder);
|
|
|
|
DefineFastIntType(64, true, TI, Builder);
|
|
|
|
DefineFastIntType(64, false, TI, Builder);
|
|
|
|
|
2016-03-05 03:00:41 +08:00
|
|
|
char UserLabelPrefix[2] = {TI.getDataLayout().getGlobalPrefix(), 0};
|
|
|
|
Builder.defineMacro("__USER_LABEL_PREFIX__", UserLabelPrefix);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-07-19 11:52:53 +08:00
|
|
|
if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
|
|
|
|
Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
|
|
|
|
else
|
|
|
|
Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
if (LangOpts.GNUCVersion) {
|
2015-05-14 06:07:22 +08:00
|
|
|
if (LangOpts.GNUInline || LangOpts.CPlusPlus)
|
2014-07-11 02:44:24 +08:00
|
|
|
Builder.defineMacro("__GNUC_GNU_INLINE__");
|
|
|
|
else
|
|
|
|
Builder.defineMacro("__GNUC_STDC_INLINE__");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
2014-07-11 02:44:24 +08:00
|
|
|
// The value written by __atomic_test_and_set.
|
|
|
|
// FIXME: This is target-dependent.
|
|
|
|
Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1");
|
Add __CLANG_ATOMIC_<TYPE>_LOCK_FREE macros for use in MSVC compatibility mode.
Summary:
Libc++ currently implements the `ATOMIC_<TYPE>_LOCK_FREE` macros using the `__GCC_ATOMIC_<TYPE>_LOCK_FREE` macros. However these are not available when MSVC compatibility is enabled even though C11 `_Atomic` is. This prevents libc++ from correctly implementing `ATOMIC_<TYPE>_LOCK_FREE`.
This patch adds an alternative spelling `__CLANG_ATOMIC_<TYPE>_LOCK_FREE` that is enabled with `-fms-compatibility`.
Reviewers: rsmith, aaron.ballman, majnemer, zturner, compnerd, jfb, rnk
Reviewed By: rsmith
Subscribers: BillyONeal, smeenai, jfb, cfe-commits, dschuff
Differential Revision: https://reviews.llvm.org/D32265
llvm-svn: 300914
2017-04-21 06:53:57 +08:00
|
|
|
}
|
Implement the missing pieces needed to support libstdc++4.7's <atomic>:
__atomic_test_and_set, __atomic_clear, plus a pile of undocumented __GCC_*
predefined macros.
Implement library fallback for __atomic_is_lock_free and
__c11_atomic_is_lock_free, and implement __atomic_always_lock_free.
Contrary to their documentation, GCC's __atomic_fetch_add family don't
multiply the operand by sizeof(T) when operating on a pointer type.
libstdc++ relies on this quirk. Remove this handling for all but the
__c11_atomic_fetch_add and __c11_atomic_fetch_sub builtins.
Contrary to their documentation, __atomic_test_and_set and __atomic_clear
take a first argument of type 'volatile void *', not 'void *' or 'bool *',
and __atomic_is_lock_free and __atomic_always_lock_free have an argument
of type 'const volatile void *', not 'void *'.
With this change, libstdc++4.7's <atomic> passes libc++'s atomic test suite,
except for a couple of libstdc++ bugs and some cases where libc++'s test
suite tests for properties which implementations have latitude to vary.
llvm-svn: 154640
2012-04-13 08:45:38 +08:00
|
|
|
|
Add __CLANG_ATOMIC_<TYPE>_LOCK_FREE macros for use in MSVC compatibility mode.
Summary:
Libc++ currently implements the `ATOMIC_<TYPE>_LOCK_FREE` macros using the `__GCC_ATOMIC_<TYPE>_LOCK_FREE` macros. However these are not available when MSVC compatibility is enabled even though C11 `_Atomic` is. This prevents libc++ from correctly implementing `ATOMIC_<TYPE>_LOCK_FREE`.
This patch adds an alternative spelling `__CLANG_ATOMIC_<TYPE>_LOCK_FREE` that is enabled with `-fms-compatibility`.
Reviewers: rsmith, aaron.ballman, majnemer, zturner, compnerd, jfb, rnk
Reviewed By: rsmith
Subscribers: BillyONeal, smeenai, jfb, cfe-commits, dschuff
Differential Revision: https://reviews.llvm.org/D32265
llvm-svn: 300914
2017-04-21 06:53:57 +08:00
|
|
|
auto addLockFreeMacros = [&](const llvm::Twine &Prefix) {
|
2016-03-24 08:20:44 +08:00
|
|
|
// Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
|
2014-07-11 02:44:24 +08:00
|
|
|
unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth();
|
Add __CLANG_ATOMIC_<TYPE>_LOCK_FREE macros for use in MSVC compatibility mode.
Summary:
Libc++ currently implements the `ATOMIC_<TYPE>_LOCK_FREE` macros using the `__GCC_ATOMIC_<TYPE>_LOCK_FREE` macros. However these are not available when MSVC compatibility is enabled even though C11 `_Atomic` is. This prevents libc++ from correctly implementing `ATOMIC_<TYPE>_LOCK_FREE`.
This patch adds an alternative spelling `__CLANG_ATOMIC_<TYPE>_LOCK_FREE` that is enabled with `-fms-compatibility`.
Reviewers: rsmith, aaron.ballman, majnemer, zturner, compnerd, jfb, rnk
Reviewed By: rsmith
Subscribers: BillyONeal, smeenai, jfb, cfe-commits, dschuff
Differential Revision: https://reviews.llvm.org/D32265
llvm-svn: 300914
2017-04-21 06:53:57 +08:00
|
|
|
#define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
|
|
|
|
Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE", \
|
|
|
|
getLockFreeValue(TI.get##Type##Width(), \
|
|
|
|
TI.get##Type##Align(), \
|
|
|
|
InlineWidthBits));
|
2014-07-11 02:44:24 +08:00
|
|
|
DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(CHAR, Char);
|
2018-05-01 13:02:45 +08:00
|
|
|
if (LangOpts.Char8)
|
|
|
|
DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
|
2014-07-11 02:44:24 +08:00
|
|
|
DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(SHORT, Short);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(INT, Int);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(LONG, Long);
|
|
|
|
DEFINE_LOCK_FREE_MACRO(LLONG, LongLong);
|
Add __CLANG_ATOMIC_<TYPE>_LOCK_FREE macros for use in MSVC compatibility mode.
Summary:
Libc++ currently implements the `ATOMIC_<TYPE>_LOCK_FREE` macros using the `__GCC_ATOMIC_<TYPE>_LOCK_FREE` macros. However these are not available when MSVC compatibility is enabled even though C11 `_Atomic` is. This prevents libc++ from correctly implementing `ATOMIC_<TYPE>_LOCK_FREE`.
This patch adds an alternative spelling `__CLANG_ATOMIC_<TYPE>_LOCK_FREE` that is enabled with `-fms-compatibility`.
Reviewers: rsmith, aaron.ballman, majnemer, zturner, compnerd, jfb, rnk
Reviewed By: rsmith
Subscribers: BillyONeal, smeenai, jfb, cfe-commits, dschuff
Differential Revision: https://reviews.llvm.org/D32265
llvm-svn: 300914
2017-04-21 06:53:57 +08:00
|
|
|
Builder.defineMacro(Prefix + "POINTER_LOCK_FREE",
|
2014-07-11 02:44:24 +08:00
|
|
|
getLockFreeValue(TI.getPointerWidth(0),
|
2017-02-24 09:16:34 +08:00
|
|
|
TI.getPointerAlign(0),
|
2014-07-11 02:44:24 +08:00
|
|
|
InlineWidthBits));
|
Implement the missing pieces needed to support libstdc++4.7's <atomic>:
__atomic_test_and_set, __atomic_clear, plus a pile of undocumented __GCC_*
predefined macros.
Implement library fallback for __atomic_is_lock_free and
__c11_atomic_is_lock_free, and implement __atomic_always_lock_free.
Contrary to their documentation, GCC's __atomic_fetch_add family don't
multiply the operand by sizeof(T) when operating on a pointer type.
libstdc++ relies on this quirk. Remove this handling for all but the
__c11_atomic_fetch_add and __c11_atomic_fetch_sub builtins.
Contrary to their documentation, __atomic_test_and_set and __atomic_clear
take a first argument of type 'volatile void *', not 'void *' or 'bool *',
and __atomic_is_lock_free and __atomic_always_lock_free have an argument
of type 'const volatile void *', not 'void *'.
With this change, libstdc++4.7's <atomic> passes libc++'s atomic test suite,
except for a couple of libstdc++ bugs and some cases where libc++'s test
suite tests for properties which implementations have latitude to vary.
llvm-svn: 154640
2012-04-13 08:45:38 +08:00
|
|
|
#undef DEFINE_LOCK_FREE_MACRO
|
Add __CLANG_ATOMIC_<TYPE>_LOCK_FREE macros for use in MSVC compatibility mode.
Summary:
Libc++ currently implements the `ATOMIC_<TYPE>_LOCK_FREE` macros using the `__GCC_ATOMIC_<TYPE>_LOCK_FREE` macros. However these are not available when MSVC compatibility is enabled even though C11 `_Atomic` is. This prevents libc++ from correctly implementing `ATOMIC_<TYPE>_LOCK_FREE`.
This patch adds an alternative spelling `__CLANG_ATOMIC_<TYPE>_LOCK_FREE` that is enabled with `-fms-compatibility`.
Reviewers: rsmith, aaron.ballman, majnemer, zturner, compnerd, jfb, rnk
Reviewed By: rsmith
Subscribers: BillyONeal, smeenai, jfb, cfe-commits, dschuff
Differential Revision: https://reviews.llvm.org/D32265
llvm-svn: 300914
2017-04-21 06:53:57 +08:00
|
|
|
};
|
|
|
|
addLockFreeMacros("__CLANG_ATOMIC_");
|
Add -fgnuc-version= to control __GNUC__ and other GCC macros
I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __GNUG__, __GXX_RTTI__, and
a number of other macros for GCC compatibility. This is undesirable and
causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. This change adds -fgnuc-version= to be
that option.
My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.
This overlaps a bit with the "GNUMode" language option from -std=gnu*.
The gnu language mode tends to enable non-conforming behaviors that we'd
rather not enable by default, but the we want to set things like
__GXX_RTTI__ by default, so I've kept these separate.
Helps address PR42817
Reviewed By: hans, nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D68055
llvm-svn: 374449
2019-10-11 05:04:25 +08:00
|
|
|
if (LangOpts.GNUCVersion)
|
Add __CLANG_ATOMIC_<TYPE>_LOCK_FREE macros for use in MSVC compatibility mode.
Summary:
Libc++ currently implements the `ATOMIC_<TYPE>_LOCK_FREE` macros using the `__GCC_ATOMIC_<TYPE>_LOCK_FREE` macros. However these are not available when MSVC compatibility is enabled even though C11 `_Atomic` is. This prevents libc++ from correctly implementing `ATOMIC_<TYPE>_LOCK_FREE`.
This patch adds an alternative spelling `__CLANG_ATOMIC_<TYPE>_LOCK_FREE` that is enabled with `-fms-compatibility`.
Reviewers: rsmith, aaron.ballman, majnemer, zturner, compnerd, jfb, rnk
Reviewed By: rsmith
Subscribers: BillyONeal, smeenai, jfb, cfe-commits, dschuff
Differential Revision: https://reviews.llvm.org/D32265
llvm-svn: 300914
2017-04-21 06:53:57 +08:00
|
|
|
addLockFreeMacros("__GCC_ATOMIC_");
|
Implement the missing pieces needed to support libstdc++4.7's <atomic>:
__atomic_test_and_set, __atomic_clear, plus a pile of undocumented __GCC_*
predefined macros.
Implement library fallback for __atomic_is_lock_free and
__c11_atomic_is_lock_free, and implement __atomic_always_lock_free.
Contrary to their documentation, GCC's __atomic_fetch_add family don't
multiply the operand by sizeof(T) when operating on a pointer type.
libstdc++ relies on this quirk. Remove this handling for all but the
__c11_atomic_fetch_add and __c11_atomic_fetch_sub builtins.
Contrary to their documentation, __atomic_test_and_set and __atomic_clear
take a first argument of type 'volatile void *', not 'void *' or 'bool *',
and __atomic_is_lock_free and __atomic_always_lock_free have an argument
of type 'const volatile void *', not 'void *'.
With this change, libstdc++4.7's <atomic> passes libc++'s atomic test suite,
except for a couple of libstdc++ bugs and some cases where libc++'s test
suite tests for properties which implementations have latitude to vary.
llvm-svn: 154640
2012-04-13 08:45:38 +08:00
|
|
|
|
2012-03-09 23:39:08 +08:00
|
|
|
if (LangOpts.NoInlineDefine)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__NO_INLINE__");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
|
|
|
if (unsigned PICLevel = LangOpts.PICLevel) {
|
2011-07-23 18:55:15 +08:00
|
|
|
Builder.defineMacro("__PIC__", Twine(PICLevel));
|
|
|
|
Builder.defineMacro("__pic__", Twine(PICLevel));
|
2016-06-23 23:07:32 +08:00
|
|
|
if (LangOpts.PIE) {
|
|
|
|
Builder.defineMacro("__PIE__", Twine(PICLevel));
|
|
|
|
Builder.defineMacro("__pie__", Twine(PICLevel));
|
|
|
|
}
|
Teach Clang about PIE compilations. This is the first step of PR12380.
First, this patch cleans up the parsing of the PIC and PIE family of
options in the driver. The existing logic failed to claim arguments all
over the place resulting in kludges that marked the options as unused.
Instead actually walk all of the arguments and claim them properly.
We now treat -f{,no-}{pic,PIC,pie,PIE} as a single set, accepting the
last one on the commandline. Previously there were lots of ordering bugs
that could creep in due to the nature of the parsing. Let me know if
folks would like weird things such as "-fPIE -fno-pic" to turn on PIE,
but disable full PIC. This doesn't make any sense to me, but we could in
theory support it.
Options that seem to have intentional "trump" status (-static, -mkernel,
etc) continue to do so and are commented as such.
Next, a -pie-level flag is threaded into the frontend, rigged to
a language option, and handled preprocessor, setting up the appropriate
defines. We'll now have the correct defines when compiling with -fpie.
The one place outside of the preprocessor that was inspecting the PIC
level (as opposed to the relocation model, which is set and handled
separately, yay!) is in the GNU ObjC runtime. I changed it to exactly
preserve existing behavior. If folks want to change its behavior in the
face of PIE, they can do that in a separate patch.
Essentially the only functionality changed here is the preprocessor
defines and bug-fixes to the argument management.
Tests have been updated and extended to test all of this a bit more
thoroughly.
llvm-svn: 154291
2012-04-09 00:40:35 +08:00
|
|
|
}
|
2009-04-21 13:40:52 +08:00
|
|
|
|
|
|
|
// Macros to control C99 numerics and <float.h>
|
2011-12-28 23:47:06 +08:00
|
|
|
Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__FLT_RADIX__", "2");
|
2015-02-23 17:12:31 +08:00
|
|
|
Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
|
2009-06-28 15:36:13 +08:00
|
|
|
|
2011-09-14 01:21:33 +08:00
|
|
|
if (LangOpts.getStackProtector() == LangOptions::SSPOn)
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.defineMacro("__SSP__");
|
2014-02-11 09:35:14 +08:00
|
|
|
else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
|
|
|
|
Builder.defineMacro("__SSP_STRONG__", "2");
|
2011-09-14 01:21:33 +08:00
|
|
|
else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
|
2014-02-11 09:35:14 +08:00
|
|
|
Builder.defineMacro("__SSP_ALL__", "3");
|
2009-06-28 15:36:13 +08:00
|
|
|
|
2019-10-15 04:15:01 +08:00
|
|
|
if (PPOpts.SetUpStaticAnalyzer)
|
2019-09-24 11:21:22 +08:00
|
|
|
Builder.defineMacro("__clang_analyzer__");
|
|
|
|
|
2010-12-04 09:51:23 +08:00
|
|
|
if (LangOpts.FastRelaxedMath)
|
|
|
|
Builder.defineMacro("__FAST_RELAXED_MATH__");
|
|
|
|
|
Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously. Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references. The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)
If you like, you can enable this feature with
-Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.
This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC. Unlike __weak, this is being enabled immediately. Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.
As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers. I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.
rdar://9674298
llvm-svn: 251041
2015-10-23 02:38:17 +08:00
|
|
|
if (FEOpts.ProgramAction == frontend::RewriteObjC ||
|
|
|
|
LangOpts.getGC() != LangOptions::NonGC) {
|
|
|
|
Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
|
|
|
|
Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
|
2015-11-11 07:00:25 +08:00
|
|
|
Builder.defineMacro("__autoreleasing", "");
|
|
|
|
Builder.defineMacro("__unsafe_unretained", "");
|
2018-10-31 04:31:30 +08:00
|
|
|
} else if (LangOpts.ObjC) {
|
2011-06-24 08:08:59 +08:00
|
|
|
Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
|
|
|
|
Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
|
2011-06-16 08:03:19 +08:00
|
|
|
Builder.defineMacro("__autoreleasing",
|
2011-06-24 08:08:59 +08:00
|
|
|
"__attribute__((objc_ownership(autoreleasing)))");
|
2011-06-16 08:03:19 +08:00
|
|
|
Builder.defineMacro("__unsafe_unretained",
|
2011-06-24 08:08:59 +08:00
|
|
|
"__attribute__((objc_ownership(none)))");
|
2011-06-16 08:03:19 +08:00
|
|
|
}
|
|
|
|
|
2015-06-25 06:02:16 +08:00
|
|
|
// On Darwin, there are __double_underscored variants of the type
|
|
|
|
// nullability qualifiers.
|
|
|
|
if (TI.getTriple().isOSDarwin()) {
|
|
|
|
Builder.defineMacro("__nonnull", "_Nonnull");
|
|
|
|
Builder.defineMacro("__null_unspecified", "_Null_unspecified");
|
|
|
|
Builder.defineMacro("__nullable", "_Nullable");
|
|
|
|
}
|
|
|
|
|
2017-12-08 03:04:10 +08:00
|
|
|
// Add a macro to differentiate between regular iOS/tvOS/watchOS targets and
|
|
|
|
// the corresponding simulator targets.
|
|
|
|
if (TI.getTriple().isOSDarwin() && TI.getTriple().isSimulatorEnvironment())
|
|
|
|
Builder.defineMacro("__APPLE_EMBEDDED_SIMULATOR__", "1");
|
|
|
|
|
2013-01-15 14:45:29 +08:00
|
|
|
// OpenMP definition
|
2016-05-27 12:13:39 +08:00
|
|
|
// OpenMP 2.2:
|
|
|
|
// In implementations that support a preprocessor, the _OPENMP
|
|
|
|
// macro name is defined to have the decimal value yyyymm where
|
|
|
|
// yyyy and mm are the year and the month designations of the
|
|
|
|
// version of the OpenMP API that the implementation support.
|
2018-05-22 00:40:32 +08:00
|
|
|
if (!LangOpts.OpenMPSimd) {
|
|
|
|
switch (LangOpts.OpenMP) {
|
|
|
|
case 0:
|
|
|
|
break;
|
2019-08-07 22:39:17 +08:00
|
|
|
case 31:
|
|
|
|
Builder.defineMacro("_OPENMP", "201107");
|
|
|
|
break;
|
2018-05-22 00:40:32 +08:00
|
|
|
case 40:
|
|
|
|
Builder.defineMacro("_OPENMP", "201307");
|
|
|
|
break;
|
2019-08-07 22:02:11 +08:00
|
|
|
case 50:
|
|
|
|
Builder.defineMacro("_OPENMP", "201811");
|
|
|
|
break;
|
2018-05-22 00:40:32 +08:00
|
|
|
default:
|
2019-08-07 22:39:17 +08:00
|
|
|
// Default version is OpenMP 4.5
|
|
|
|
Builder.defineMacro("_OPENMP", "201511");
|
2018-05-22 00:40:32 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-01-15 14:45:29 +08:00
|
|
|
}
|
|
|
|
|
2014-12-04 05:53:36 +08:00
|
|
|
// CUDA device path compilaton
|
2018-04-25 21:33:19 +08:00
|
|
|
if (LangOpts.CUDAIsDevice && !LangOpts.HIP) {
|
2014-12-04 05:53:36 +08:00
|
|
|
// The CUDA_ARCH value is set for the GPU target specified in the NVPTX
|
|
|
|
// backend's target defines.
|
|
|
|
Builder.defineMacro("__CUDA_ARCH__");
|
|
|
|
}
|
|
|
|
|
2016-05-24 04:19:56 +08:00
|
|
|
// We need to communicate this to our CUDA header wrapper, which in turn
|
|
|
|
// informs the proper CUDA headers of this choice.
|
|
|
|
if (LangOpts.CUDADeviceApproxTranscendentals || LangOpts.FastMath) {
|
|
|
|
Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
|
|
|
|
}
|
|
|
|
|
2019-02-25 19:48:48 +08:00
|
|
|
// Define a macro indicating that the source file is being compiled with a
|
|
|
|
// SYCL device compiler which doesn't produce host binary.
|
|
|
|
if (LangOpts.SYCLIsDevice) {
|
|
|
|
Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
|
|
|
|
}
|
|
|
|
|
2016-05-17 01:06:34 +08:00
|
|
|
// OpenCL definitions.
|
|
|
|
if (LangOpts.OpenCL) {
|
2019-02-08 01:32:37 +08:00
|
|
|
#define OPENCLEXT(Ext) \
|
|
|
|
if (TI.getSupportedOpenCLOpts().isSupported(#Ext, LangOpts)) \
|
|
|
|
Builder.defineMacro(#Ext);
|
2016-05-17 01:06:34 +08:00
|
|
|
#include "clang/Basic/OpenCLExtensions.def"
|
2017-12-04 23:01:08 +08:00
|
|
|
|
2019-05-09 18:25:45 +08:00
|
|
|
if (TI.getTriple().isSPIR())
|
2017-12-04 23:01:08 +08:00
|
|
|
Builder.defineMacro("__IMAGE_SUPPORT__");
|
2016-05-17 01:06:34 +08:00
|
|
|
}
|
|
|
|
|
2016-07-21 15:44:41 +08:00
|
|
|
if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
|
2016-11-01 04:25:52 +08:00
|
|
|
// For each extended integer type, g++ defines a macro mapping the
|
|
|
|
// index of the type (0 in this case) in some list of extended types
|
|
|
|
// to the type.
|
2016-07-21 15:44:41 +08:00
|
|
|
Builder.defineMacro("__GLIBCXX_TYPE_INT_N_0", "__int128");
|
|
|
|
Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
|
|
|
|
}
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Get other target #defines.
|
2010-01-10 01:55:51 +08:00
|
|
|
TI.getTargetDefines(LangOpts, Builder);
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// InitializePreprocessor - Initialize the preprocessor getting it and the
|
|
|
|
/// environment ready to process a single file. This returns true on error.
|
|
|
|
///
|
2015-06-21 02:53:08 +08:00
|
|
|
void clang::InitializePreprocessor(
|
|
|
|
Preprocessor &PP, const PreprocessorOptions &InitOpts,
|
2015-07-17 09:19:54 +08:00
|
|
|
const PCHContainerReader &PCHContainerRdr,
|
2015-06-21 02:53:08 +08:00
|
|
|
const FrontendOptions &FEOpts) {
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &LangOpts = PP.getLangOpts();
|
2010-01-10 00:17:37 +08:00
|
|
|
std::string PredefineBuffer;
|
|
|
|
PredefineBuffer.reserve(4080);
|
|
|
|
llvm::raw_string_ostream Predefines(PredefineBuffer);
|
|
|
|
MacroBuilder Builder(Predefines);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-04-27 06:08:10 +08:00
|
|
|
// Emit line markers for various builtin sections of the file. We don't do
|
|
|
|
// this in asm preprocessor mode, because "# 4" is not a line marker directive
|
|
|
|
// in this mode.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!PP.getLangOpts().AsmPreprocessor)
|
2010-04-27 06:08:10 +08:00
|
|
|
Builder.append("# 1 \"<built-in>\" 3");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Install things like __POWERPC__, __GNUC__, etc into the macro table.
|
2011-06-16 07:02:42 +08:00
|
|
|
if (InitOpts.UsePredefines) {
|
2018-08-31 04:43:39 +08:00
|
|
|
// FIXME: This will create multiple definitions for most of the predefined
|
|
|
|
// macros. This is not the right way to handle this.
|
2019-12-10 21:52:58 +08:00
|
|
|
if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) &&
|
|
|
|
PP.getAuxTargetInfo())
|
2018-08-31 04:43:39 +08:00
|
|
|
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
|
2019-10-15 04:15:01 +08:00
|
|
|
PP.getPreprocessorOpts(), Builder);
|
2018-08-31 04:43:39 +08:00
|
|
|
|
2019-10-15 04:15:01 +08:00
|
|
|
InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts,
|
|
|
|
PP.getPreprocessorOpts(), Builder);
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
// Install definitions to make Objective-C++ ARC work well with various
|
|
|
|
// C++ Standard Library implementations.
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LangOpts.ObjC && LangOpts.CPlusPlus &&
|
Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously. Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references. The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)
If you like, you can enable this feature with
-Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.
This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC. Unlike __weak, this is being enabled immediately. Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.
As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers. I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.
rdar://9674298
llvm-svn: 251041
2015-10-23 02:38:17 +08:00
|
|
|
(LangOpts.ObjCAutoRefCount || LangOpts.ObjCWeak)) {
|
2011-06-16 07:02:42 +08:00
|
|
|
switch (InitOpts.ObjCXXARCStandardLibrary) {
|
|
|
|
case ARCXX_nolib:
|
Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously. Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references. The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)
If you like, you can enable this feature with
-Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.
This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC. Unlike __weak, this is being enabled immediately. Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.
As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers. I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.
rdar://9674298
llvm-svn: 251041
2015-10-23 02:38:17 +08:00
|
|
|
case ARCXX_libcxx:
|
2011-06-16 07:02:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ARCXX_libstdcxx:
|
|
|
|
AddObjCXXARCLibstdcxxDefines(LangOpts, Builder);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 07:04:11 +08:00
|
|
|
|
2011-06-07 14:07:12 +08:00
|
|
|
// Even with predefines off, some macros are still predefined.
|
|
|
|
// These should all be defined in the preprocessor according to the
|
|
|
|
// current language configuration.
|
2012-03-11 15:00:24 +08:00
|
|
|
InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
|
2011-06-07 14:07:12 +08:00
|
|
|
FEOpts, Builder);
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Add on the predefines from the driver. Wrap in a #line directive to report
|
|
|
|
// that they come from the command line.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!PP.getLangOpts().AsmPreprocessor)
|
2010-04-27 06:08:10 +08:00
|
|
|
Builder.append("# 1 \"<command line>\" 1");
|
2009-04-21 13:40:52 +08:00
|
|
|
|
|
|
|
// Process #define's and #undef's in the order they are given.
|
2009-11-17 13:52:41 +08:00
|
|
|
for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
|
|
|
|
if (InitOpts.Macros[i].second) // isUndef
|
2010-01-10 01:43:21 +08:00
|
|
|
Builder.undefineMacro(InitOpts.Macros[i].first);
|
2009-04-21 14:00:24 +08:00
|
|
|
else
|
2010-01-10 00:17:37 +08:00
|
|
|
DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
|
2010-01-10 08:46:21 +08:00
|
|
|
PP.getDiagnostics());
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|
|
|
|
|
2016-03-24 02:00:22 +08:00
|
|
|
// Exit the command line and go back to <built-in> (2 is LC_LEAVE).
|
|
|
|
if (!PP.getLangOpts().AsmPreprocessor)
|
|
|
|
Builder.append("# 1 \"<built-in>\" 2");
|
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// If -imacros are specified, include them now. These are processed before
|
|
|
|
// any -include directives.
|
2009-11-17 13:52:41 +08:00
|
|
|
for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
|
2014-08-12 16:25:57 +08:00
|
|
|
AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
|
2009-04-21 13:40:52 +08:00
|
|
|
|
2013-02-06 00:36:52 +08:00
|
|
|
// Process -include-pch/-include-pth directives.
|
|
|
|
if (!InitOpts.ImplicitPCHInclude.empty())
|
2015-07-17 09:19:54 +08:00
|
|
|
AddImplicitIncludePCH(Builder, PP, PCHContainerRdr,
|
2015-06-21 02:53:08 +08:00
|
|
|
InitOpts.ImplicitPCHInclude);
|
2013-02-06 00:36:52 +08:00
|
|
|
|
2009-04-21 13:40:52 +08:00
|
|
|
// Process -include directives.
|
2009-11-17 13:52:41 +08:00
|
|
|
for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
|
|
|
|
const std::string &Path = InitOpts.Includes[i];
|
2014-08-12 16:25:57 +08:00
|
|
|
AddImplicitInclude(Builder, Path);
|
2009-06-15 17:57:52 +08:00
|
|
|
}
|
2009-04-21 13:40:52 +08:00
|
|
|
|
Introduce basic support for loading a precompiled preamble while
reparsing an ASTUnit. When saving a preamble, create a buffer larger
than the actual file we're working with but fill everything from the
end of the preamble to the end of the file with spaces (so the lexer
will quickly skip them). When we load the file, create a buffer of the
same size, filling it with the file and then spaces. Then, instruct
the lexer to start lexing after the preamble, therefore continuing the
parse from the spot where the preamble left off.
It's now possible to perform a simple preamble build + parse (+
reparse) with ASTUnit. However, one has to disable a bunch of checking
in the PCH reader to do so. That part isn't committed; it will likely
be handled with some other kind of flag (e.g., -fno-validate-pch).
As part of this, fix some issues with null termination of the memory
buffers created for the preamble; we were trying to explicitly
NULL-terminate them, even though they were also getting implicitly
NULL terminated, leading to excess warnings about NULL characters in
source files.
llvm-svn: 109445
2010-07-27 05:36:20 +08:00
|
|
|
// Instruct the preprocessor to skip the preamble.
|
|
|
|
PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
|
|
|
|
InitOpts.PrecompiledPreambleBytes.second);
|
2017-12-08 07:04:11 +08:00
|
|
|
|
2010-01-10 00:17:37 +08:00
|
|
|
// Copy PredefinedBuffer into the Preprocessor.
|
|
|
|
PP.setPredefines(Predefines.str());
|
2009-04-21 13:40:52 +08:00
|
|
|
}
|