Skip to content

Commit f586021

Browse files
openeuler-ci-botgitee-org
authored andcommitted
!116 [Driver] Handle -mabi=lp64 and invalid -std for GNU compatibility
From: @polaris_jiang Reviewed-by: @liyunfei33, @cf-zhao Signed-off-by: @cf-zhao
2 parents 76fece9 + 10b2b33 commit f586021

File tree

9 files changed

+53
-0
lines changed

9 files changed

+53
-0
lines changed

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ set(CLANG_BASIC_OPTIONS)
22
if(LLVM_ENABLE_AUTOTUNER)
33
list(APPEND CLANG_BASIC_OPTIONS "-DENABLE_AUTOTUNER")
44
endif()
5+
if(BUILD_FOR_OPENEULER)
6+
list(APPEND CLANG_BASIC_OPTIONS "-DBUILD_FOR_OPENEULER")
7+
endif()
58

69
macro(clang_diag_gen component)
710
clang_tablegen(Diagnostic${component}Kinds.inc

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ def err_target_unknown_cpu : Error<"unknown target CPU '%0'">;
316316
def note_valid_options : Note<"valid target CPU values are: %0">;
317317
def err_target_unsupported_cpu_for_micromips : Error<
318318
"micromips is not supported for target CPU '%0'">;
319+
#ifdef BUILD_FOR_OPENEULER
320+
def warning_target_default_abi : Warning<
321+
"'%0' is the default abi for this target.">, InGroup<IgnoredOptimizationArgument>;
322+
def warning_not_valid_std : Warning<"'%0' is not valid for '%1'.">,
323+
InGroup<IgnoredOptimizationArgument>;
324+
#endif
319325
def err_target_unknown_abi : Error<"unknown target ABI '%0'">;
320326
def err_target_unsupported_abi : Error<"ABI '%0' is not supported on CPU '%1'">;
321327
def err_target_unsupported_abi_for_triple : Error<

clang/include/clang/Basic/TargetInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,11 @@ class TargetInfo : public TransferrableTargetInfo,
13201320
return false;
13211321
}
13221322

1323+
#if defined(BUILD_FOR_OPENEULER)
1324+
/// Check whether this ABI Name is the default one for GNU/GCC Compatibility
1325+
virtual bool isDefaultABI(const std::string &Name) {return false;}
1326+
#endif
1327+
13231328
/// Use the specified unit for FP math.
13241329
///
13251330
/// \return False on error (invalid unit name).

clang/lib/Basic/Targets.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,17 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
805805

806806
// Set the target ABI if specified.
807807
if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
808+
#if defined(BUILD_FOR_OPENEULER)
809+
if (Diags.getDiagnosticOptions().GccCompatible && Target->isDefaultABI(Opts->ABI)) {
810+
Diags.Report(diag::warning_target_default_abi) << Opts->ABI;
811+
} else {
812+
Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
813+
return nullptr;
814+
}
815+
#else
808816
Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
809817
return nullptr;
818+
#endif
810819
}
811820

812821
// Set the fp math unit.

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ bool AArch64TargetInfo::setABI(const std::string &Name) {
206206
return true;
207207
}
208208

209+
#if defined(BUILD_FOR_OPENEULER)
210+
bool AArch64TargetInfo::isDefaultABI(const std::string &Name) {
211+
return Name == "lp64";
212+
}
213+
#endif
214+
209215
bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
210216
BranchProtectionInfo &BPI,
211217
StringRef &Err) const {

clang/lib/Basic/Targets/AArch64.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
9494

9595
StringRef getABI() const override;
9696
bool setABI(const std::string &Name) override;
97+
#if defined(BUILD_FOR_OPENEULER)
98+
bool isDefaultABI(const std::string &Name) override;
99+
#endif
97100

98101
bool validateBranchProtection(StringRef Spec, StringRef Arch,
99102
BranchProtectionInfo &BPI,

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,8 +3622,19 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
36223622
// compatible.
36233623
const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
36243624
if (!IsInputCompatibleWithStandard(IK, Std)) {
3625+
#if defined(BUILD_FOR_OPENEULER)
3626+
if (Args.hasArg(OPT_fgcc_compatible)) {
3627+
LangStd = LangStandard::lang_unspecified;
3628+
Diags.Report(diag::warning_not_valid_std)
3629+
<< A->getAsString(Args) << GetInputKindName(IK);
3630+
} else {
3631+
Diags.Report(diag::err_drv_argument_not_allowed_with)
3632+
<< A->getAsString(Args) << GetInputKindName(IK);
3633+
}
3634+
#else
36253635
Diags.Report(diag::err_drv_argument_not_allowed_with)
36263636
<< A->getAsString(Args) << GetInputKindName(IK);
3637+
#endif
36273638
}
36283639
}
36293640
}

clang/test/Driver/arm-abi-lp64.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// REQUIRES: build_for_openeuler
2+
// RUN: not %clang -fgcc-compatible -mabi=lp64 -target aarch64 %s 2>&1 | FileCheck --check-prefix=CHECK-MABI-WARN %s
3+
// CHECK-MABI-WARN: warning: 'lp64' is the default abi for this target.
4+
// RUN: not %clang -mabi=lp64 -target aarch64 %s 2>&1 | FileCheck --check-prefix=CHECK-MABI-ERROR %s
5+
// CHECK-MABI-ERROR: error: unknown target ABI 'lp64'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// REQUIRES: build_for_openeuler
2+
// RUN: not %clang -fgcc-compatible -std=c++11 %s 2>&1 | FileCheck --check-prefix=CHECK-WARN-STD %s
3+
// CHECK-WARN-STD: warning: '-std=c++11' is not valid for 'C'
4+
// RUN: not %clang -std=c++11 %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR-STD %s
5+
// CHECK-ERROR-STD: error: invalid argument '-std=c++11' not allowed with 'C'

0 commit comments

Comments
 (0)