[clang] 6538362 - [clang][AVR] Set '-fno-use-cxa-atexit' to default
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 29 18:27:26 PST 2022
Author: Ben Shi
Date: 2022-01-30T02:26:19Z
New Revision: 653836251ac41775e3d376e9ee28efd2ea0232b2
URL: https://github.com/llvm/llvm-project/commit/653836251ac41775e3d376e9ee28efd2ea0232b2
DIFF: https://github.com/llvm/llvm-project/commit/653836251ac41775e3d376e9ee28efd2ea0232b2.diff
LOG: [clang][AVR] Set '-fno-use-cxa-atexit' to default
AVR is baremetal environment, so the avr-libc does not support
'__cxa_atexit()'.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D118445
Added:
Modified:
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-toolchain.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3b5389ee3670..8a0150218a7a 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -8304,12 +8304,14 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
// Check if global/static variable is defined in address space
// 1~6 (__flash, __flash1, __flash2, __flash3, __flash4, __flash5)
// but not constant.
- LangAS AS = D->getType().getAddressSpace();
- if (isTargetAddressSpace(AS) && 1 <= toTargetAddressSpace(AS) &&
- toTargetAddressSpace(AS) <= 6 && !D->getType().isConstQualified())
- CGM.getDiags().Report(D->getLocation(),
- diag::err_verify_nonconst_addrspace)
- << "__flash*";
+ if (D) {
+ LangAS AS = D->getType().getAddressSpace();
+ if (isTargetAddressSpace(AS) && 1 <= toTargetAddressSpace(AS) &&
+ toTargetAddressSpace(AS) <= 6 && !D->getType().isConstQualified())
+ CGM.getDiags().Report(D->getLocation(),
+ diag::err_verify_nonconst_addrspace)
+ << "__flash*";
+ }
return TargetCodeGenInfo::getGlobalVarAddressSpace(CGM, D);
}
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index a66cae8b4d6b..2cf16cf9fdb4 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -379,6 +379,11 @@ void AVRToolChain::addClangTargetOptions(
if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
options::OPT_fno_use_init_array, false))
CC1Args.push_back("-fno-use-init-array");
+ // Use `-fno-use-cxa-atexit` as default, since avr-libc does not support
+ // `__cxa_atexit()`.
+ if (!DriverArgs.hasFlag(options::OPT_fuse_cxa_atexit,
+ options::OPT_fno_use_cxa_atexit, false))
+ CC1Args.push_back("-fno-use-cxa-atexit");
}
Tool *AVRToolChain::buildLinker() const {
diff --git a/clang/test/Driver/avr-toolchain.c b/clang/test/Driver/avr-toolchain.c
index 6bb7a00b6a3b..50f62c34ff9e 100644
--- a/clang/test/Driver/avr-toolchain.c
+++ b/clang/test/Driver/avr-toolchain.c
@@ -25,7 +25,12 @@
// CHECK3-SAME: {{^}} "[[SYSROOT]]/usr/avr/include"
// RUN: %clang %s -### -target avr 2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
+// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array" "-fno-use-cxa-atexit"
+
+// RUN: %clang %s -### -target avr -fuse-init-array -fuse-cxa-atexit 2>&1 | FileCheck -check-prefix=CHECK4 %s
+// CHECK4: clang{{.*}} "-cc1" "-triple" "avr"
+// CHECK4-NOT: "-fno-use-init-array"
+// CHECK4-NOT: "-fno-use-cxa-atexit"
// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 -nostdinc | FileCheck --check-prefix=NOSTDINC %s
// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 -nostdlibinc | FileCheck --check-prefix=NOSTDINC %s
More information about the cfe-commits
mailing list