@@ -175,14 +175,58 @@ static void validateWarningControlArgs(DiagnosticEngine &diags,
175175 }
176176}
177177
178+ // / Validates only *generate* profiling flags and their mutual conflicts.
179+ static void validateProfilingGenerateArgs (DiagnosticEngine &diags,
180+ const ArgList &args) {
181+ const Arg *ProfileGenerate = args.getLastArg (options::OPT_profile_generate);
182+ const Arg *IRProfileGenerate =
183+ args.getLastArg (options::OPT_ir_profile_generate);
184+ const Arg *CSProfileGenerate =
185+ args.getLastArg (options::OPT_cs_profile_generate);
186+ const Arg *CSProfileGenerateEQ =
187+ args.getLastArg (options::OPT_cs_profile_generate_EQ);
188+
189+ // If both CS Profile forms were specified, report a clear conflict.
190+ if (CSProfileGenerate && CSProfileGenerateEQ) {
191+ diags.diagnose (SourceLoc (), diag::error_conflicting_options,
192+ " -cs-profile-generate" , " -cs-profile-generate=" );
193+ CSProfileGenerateEQ = nullptr ;
194+ }
195+
196+ llvm::SmallVector<std::pair<const Arg *, const char *>, 3 > gens;
197+ if (ProfileGenerate)
198+ gens.push_back ({ProfileGenerate, " -profile-generate" });
199+ if (IRProfileGenerate)
200+ gens.push_back ({IRProfileGenerate, " -ir-profile-generate" });
201+ if (CSProfileGenerate)
202+ gens.push_back ({CSProfileGenerate, " -cs-profile-generate" });
203+ else if (CSProfileGenerateEQ)
204+ gens.push_back ({CSProfileGenerateEQ, " -cs-profile-generate=" });
205+
206+ // Emit pairwise conflicts if more than one generate-mode was selected
207+ for (size_t i = 0 ; i + 1 < gens.size (); ++i) {
208+ for (size_t j = i + 1 ; j < gens.size (); ++j) {
209+ diags.diagnose (SourceLoc (), diag::error_conflicting_options,
210+ gens[i].second , gens[j].second );
211+ }
212+ }
213+ }
214+
178215static void validateProfilingArgs (DiagnosticEngine &diags,
179216 const ArgList &args) {
217+ validateProfilingGenerateArgs (diags, args);
180218 const Arg *ProfileGenerate = args.getLastArg (options::OPT_profile_generate);
181219 const Arg *ProfileUse = args.getLastArg (options::OPT_profile_use);
220+ const Arg *IRProfileGenerate =
221+ args.getLastArg (options::OPT_ir_profile_generate);
182222 if (ProfileGenerate && ProfileUse) {
183223 diags.diagnose (SourceLoc (), diag::error_conflicting_options,
184224 " -profile-generate" , " -profile-use" );
185225 }
226+ if (IRProfileGenerate && ProfileUse) {
227+ diags.diagnose (SourceLoc (), diag::error_conflicting_options,
228+ " -ir-profile-generate" , " -profile-use" );
229+ }
186230
187231 // Check if the profdata is missing
188232 if (ProfileUse && !llvm::sys::fs::exists (ProfileUse->getValue ())) {
0 commit comments