diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp --- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -73,68 +73,12 @@ getRISCFeaturesFromMcpu(D, Triple, Args, A, A->getValue(), Features); // Handle features corresponding to "-ffixed-X" options - if (Args.hasArg(options::OPT_ffixed_x1)) - Features.push_back("+reserve-x1"); - if (Args.hasArg(options::OPT_ffixed_x2)) - Features.push_back("+reserve-x2"); - if (Args.hasArg(options::OPT_ffixed_x3)) - Features.push_back("+reserve-x3"); - if (Args.hasArg(options::OPT_ffixed_x4)) - Features.push_back("+reserve-x4"); - if (Args.hasArg(options::OPT_ffixed_x5)) - Features.push_back("+reserve-x5"); - if (Args.hasArg(options::OPT_ffixed_x6)) - Features.push_back("+reserve-x6"); - if (Args.hasArg(options::OPT_ffixed_x7)) - Features.push_back("+reserve-x7"); - if (Args.hasArg(options::OPT_ffixed_x8)) - Features.push_back("+reserve-x8"); - if (Args.hasArg(options::OPT_ffixed_x9)) - Features.push_back("+reserve-x9"); - if (Args.hasArg(options::OPT_ffixed_x10)) - Features.push_back("+reserve-x10"); - if (Args.hasArg(options::OPT_ffixed_x11)) - Features.push_back("+reserve-x11"); - if (Args.hasArg(options::OPT_ffixed_x12)) - Features.push_back("+reserve-x12"); - if (Args.hasArg(options::OPT_ffixed_x13)) - Features.push_back("+reserve-x13"); - if (Args.hasArg(options::OPT_ffixed_x14)) - Features.push_back("+reserve-x14"); - if (Args.hasArg(options::OPT_ffixed_x15)) - Features.push_back("+reserve-x15"); - if (Args.hasArg(options::OPT_ffixed_x16)) - Features.push_back("+reserve-x16"); - if (Args.hasArg(options::OPT_ffixed_x17)) - Features.push_back("+reserve-x17"); - if (Args.hasArg(options::OPT_ffixed_x18)) - Features.push_back("+reserve-x18"); - if (Args.hasArg(options::OPT_ffixed_x19)) - Features.push_back("+reserve-x19"); - if (Args.hasArg(options::OPT_ffixed_x20)) - Features.push_back("+reserve-x20"); - if (Args.hasArg(options::OPT_ffixed_x21)) - Features.push_back("+reserve-x21"); - if (Args.hasArg(options::OPT_ffixed_x22)) - Features.push_back("+reserve-x22"); - if (Args.hasArg(options::OPT_ffixed_x23)) - Features.push_back("+reserve-x23"); - if (Args.hasArg(options::OPT_ffixed_x24)) - Features.push_back("+reserve-x24"); - if (Args.hasArg(options::OPT_ffixed_x25)) - Features.push_back("+reserve-x25"); - if (Args.hasArg(options::OPT_ffixed_x26)) - Features.push_back("+reserve-x26"); - if (Args.hasArg(options::OPT_ffixed_x27)) - Features.push_back("+reserve-x27"); - if (Args.hasArg(options::OPT_ffixed_x28)) - Features.push_back("+reserve-x28"); - if (Args.hasArg(options::OPT_ffixed_x29)) - Features.push_back("+reserve-x29"); - if (Args.hasArg(options::OPT_ffixed_x30)) - Features.push_back("+reserve-x30"); - if (Args.hasArg(options::OPT_ffixed_x31)) - Features.push_back("+reserve-x31"); +#define HAS_FFIXED_X(I) \ + (if (Args.hasArg(options::OPT_ffixed_x(I))) \ + Features.push_back("+reserve-x(I)")) + + for (int i = 1; i <= 31; ++i) + HAS_FFIXED_X(i); // -mrelax is default, unless -mno-relax is specified. if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))