@@ -165,12 +165,59 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
165165 Features.push_back (" -relax" );
166166 }
167167
168+ // If -mstrict-align, -mno-strict-align, -mscalar-strict-align, or
169+ // -mno-scalar-strict-align is passed, use it. Otherwise, the
170+ // unaligned-scalar-mem is enabled if the CPU supports it or the target is
171+ // Android.
172+ if (const Arg *A = Args.getLastArg (
173+ options::OPT_mno_strict_align, options::OPT_mscalar_strict_align,
174+ options::OPT_mstrict_align, options::OPT_mno_scalar_strict_align)) {
175+ if (A->getOption ().matches (options::OPT_mno_strict_align) ||
176+ A->getOption ().matches (options::OPT_mno_scalar_strict_align)) {
177+ Features.push_back (" +unaligned-scalar-mem" );
178+ } else {
179+ Features.push_back (" -unaligned-scalar-mem" );
180+ }
181+ } else if (CPUFastScalarUnaligned || Triple.isAndroid ()) {
182+ Features.push_back (" +unaligned-scalar-mem" );
183+ }
184+
185+ // If -mstrict-align, -mno-strict-align, -mvector-strict-align, or
186+ // -mno-vector-strict-align is passed, use it. Otherwise, the
187+ // unaligned-vector-mem is enabled if the CPU supports it or the target is
188+ // Android.
189+ if (const Arg *A = Args.getLastArg (
190+ options::OPT_mno_strict_align, options::OPT_mvector_strict_align,
191+ options::OPT_mstrict_align, options::OPT_mno_vector_strict_align)) {
192+ if (A->getOption ().matches (options::OPT_mno_strict_align) ||
193+ A->getOption ().matches (options::OPT_mno_vector_strict_align)) {
194+ Features.push_back (" +unaligned-vector-mem" );
195+ } else {
196+ Features.push_back (" -unaligned-vector-mem" );
197+ }
198+ } else if (CPUFastVectorUnaligned || Triple.isAndroid ()) {
199+ Features.push_back (" +unaligned-vector-mem" );
200+ }
201+
202+ // Now add any that the user explicitly requested on the command line,
203+ // which may override the defaults.
204+ handleTargetFeaturesGroup (D, Triple, Args, Features,
205+ options::OPT_m_riscv_Features_Group);
206+
168207 if (Arg *A = Args.getLastArg (options::OPT_mabi_EQ)) {
169208 bool IsPureCapability = isCheriPurecapABIName (A->getValue ());
170209 if (IsPureCapability) {
171- if (llvm::find (Features, " +xcheri" ) == Features.end ()) {
172- D.Diag (diag::err_riscv_invalid_abi) << A->getValue ()
173- << " pure capability ABI requires xcheri extension to be specified" ;
210+ auto ISAInfo = llvm::RISCVISAInfo::parseFeatures (
211+ Triple.isArch32Bit () ? 32 : 64 ,
212+ std::vector<std::string>(Features.begin (), Features.end ()));
213+ if (!ISAInfo) {
214+ handleAllErrors (ISAInfo.takeError (), [&](llvm::StringError &ErrMsg) {
215+ D.Diag (diag::err_invalid_feature_combination) << ErrMsg.getMessage ();
216+ });
217+ } else if (!(*ISAInfo)->hasExtension (" xcheri" )) {
218+ D.Diag (diag::err_riscv_invalid_abi)
219+ << A->getValue ()
220+ << " pure capability ABI requires xcheri extension to be specified" ;
174221 return ;
175222 }
176223 Features.push_back (" +cap-mode" );
0 commit comments