|
4 | 4 | #include "driver/cl_options.h"
|
5 | 5 | #include "driver/timetrace.h"
|
6 | 6 | #include "driver/tool.h"
|
| 7 | +#include "gen/irstate.h" |
7 | 8 | #include "llvm/Support/FileSystem.h"
|
8 | 9 | #include "llvm/Support/Path.h"
|
9 | 10 | #include "llvm/Support/Program.h"
|
| 11 | +#include "llvm/MC/MCSubtargetInfo.h" |
| 12 | +#include "llvm/Target/TargetMachine.h" |
10 | 13 |
|
11 | 14 | namespace {
|
12 | 15 | const char *getPathToImportc_h(const Loc &loc) {
|
@@ -119,6 +122,27 @@ FileName runCPreprocessor(FileName csrcfile, const Loc &loc,
|
119 | 122 | args.push_back("/PD"); // print all macro definitions
|
120 | 123 | args.push_back("/Zc:preprocessor"); // use the new conforming preprocessor
|
121 | 124 | } else {
|
| 125 | + // propagate the target to the preprocessor |
| 126 | + args.push_back("-target"); |
| 127 | + args.push_back(triple.getTriple()); |
| 128 | + |
| 129 | +#if LDC_LLVM_VER >= 1800 // getAllProcessorFeatures was introduced in this version |
| 130 | + // propagate all enabled/disabled features to the preprocessor |
| 131 | + const auto &subTarget = gTargetMachine->getMCSubtargetInfo(); |
| 132 | + const auto &featureBits = subTarget->getFeatureBits(); |
| 133 | + llvm::SmallString<64> featureString; |
| 134 | + for (const auto &feature : subTarget->getAllProcessorFeatures()) { |
| 135 | + args.push_back("-Xclang"); |
| 136 | + args.push_back("-target-feature"); |
| 137 | + args.push_back("-Xclang"); |
| 138 | + |
| 139 | + featureString += featureBits.test(feature.Value) ? '+' : '-'; |
| 140 | + featureString += feature.Key; |
| 141 | + args.push_back(featureString.str().str()); |
| 142 | + featureString.clear(); |
| 143 | + } |
| 144 | +#endif |
| 145 | + |
122 | 146 | // print macro definitions (clang-cl doesn't support /PD - use clang's
|
123 | 147 | // -dD)
|
124 | 148 | args.push_back("-Xclang");
|
|
0 commit comments