Skip to content

Commit 55c0948

Browse files
authored
[clang] add option to suppress conflicting type errors on function decls (#4908)
This optionally supresses the check of C standard introduced in rG385e7df to unblock qualifications Resolves: rdar://96080355
1 parent 594816a commit 55c0948

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32,
455455

456456
VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
457457

458+
LANGOPT(IgnoreConflictingTypes, 1, 0, "Suppress conflicting type errors from mismatching declarations")
459+
458460
#undef LANGOPT
459461
#undef COMPATIBLE_LANGOPT
460462
#undef BENIGN_LANGOPT

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6966,3 +6966,7 @@ def target_profile : DXCJoinedOrSeparate<"T">, MetaVarName<"<profile>">,
69666966
"lib_6_3, lib_6_4, lib_6_5, lib_6_6, lib_6_7, lib_6_x,"
69676967
"ms_6_5, ms_6_6, ms_6_7,"
69686968
"as_6_5, as_6_6, as_6_7">;
6969+
6970+
def fsuppress_conflicting_types: Flag<["-"], "fsuppress-conflicting-types">, Group<f_Group>,
6971+
MarshallingInfoFlag<LangOpts<"IgnoreConflictingTypes">>,
6972+
HelpText<"Ignore errors from conflicting types in function declarations">, Flags<[CC1Option]>;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6228,6 +6228,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job,
62286228
Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
62296229
Args.AddLastArg(CmdArgs, options::OPT_malign_double);
62306230
Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
6231+
Args.AddLastArg(CmdArgs, options::OPT_fsuppress_conflicting_types);
62316232

62326233
if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
62336234
CmdArgs.push_back("-ftrapv-handler");

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3910,7 +3910,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
39103910
// we need to cover here is that the number of arguments agree as the
39113911
// default argument promotion rules were already checked by
39123912
// ASTContext::typesAreCompatible().
3913-
if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn &&
3913+
if (!getLangOpts().IgnoreConflictingTypes && Old->hasPrototype() &&
3914+
!New->hasWrittenPrototype() && NewDeclIsDefn &&
39143915
Old->getNumParams() != New->getNumParams()) {
39153916
if (Old->hasInheritedPrototype())
39163917
Old = Old->getCanonicalDecl();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -fsuppress-conflicting-types -verify %s
2+
3+
void blapp(int);
4+
void blapp() {}
5+
6+
void foo(int);
7+
void foo();
8+
void foo() {}
9+
10+
// Maintain preexisting released clang behavior that catches conflicting type errors.
11+
void yarp(int, ...); // expected-note {{previous}}
12+
void yarp(); // expected-error {{conflicting types for 'yarp'}}
13+
14+
void blarg(int, ...); // expected-note {{previous}}
15+
void blarg() {} // expected-error {{conflicting types for 'blarg'}}

0 commit comments

Comments
 (0)