diff options
| author | John McCall <rjmccall@apple.com> | 2010-03-15 10:54:44 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-03-15 10:54:44 +0000 |
| commit | c33dec36642bb47c2451f3d33f8cf75f3c99f57c (patch) | |
| tree | c1e8a4837896c3a700c087c59a52e051ac549cdf /clang/lib | |
| parent | 3e11ebebc83643747f15bcafa28b3b7e232f6cc1 (diff) | |
| download | bcm5719-llvm-c33dec36642bb47c2451f3d33f8cf75f3c99f57c.tar.gz bcm5719-llvm-c33dec36642bb47c2451f3d33f8cf75f3c99f57c.zip | |
Add support for -Wwrite-strings. Patch by Mike M! Fixes PR 4804.
llvm-svn: 98541
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 2 |
3 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 64a42bc0ec4..5798f2f7100 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -474,6 +474,8 @@ static void LangOptsToArgs(const LangOptions &Opts, Res.push_back("-fcatch-undefined-behavior"); if (Opts.WritableStrings) Res.push_back("-fwritable-strings"); + if (Opts.ConstStrings) + Res.push_back("-Wwrite-strings"); if (!Opts.LaxVectorConversions) Res.push_back("-fno-lax-vector-conversions"); if (Opts.AltiVec) @@ -1162,6 +1164,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); Opts.Microsoft = Args.hasArg(OPT_fms_extensions); Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); + Opts.ConstStrings = Args.hasArg(OPT_Wwrite_strings); if (Args.hasArg(OPT_fno_lax_vector_conversions)) Opts.LaxVectorConversions = 0; if (Args.hasArg(OPT_fno_threadsafe_statics)) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index cd049a27c1b..a39ba2f7d06 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -370,7 +370,7 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { if (Literal.Pascal) StrTy = Context.UnsignedCharTy; // A C++ string literal has a const-qualified element type (C++ 2.13.4p1). - if (getLangOptions().CPlusPlus) + if (getLangOptions().CPlusPlus || getLangOptions().ConstStrings ) StrTy.addConst(); // Get an array type for the string, according to C99 6.4.5. This includes diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index c60455d8456..c98ba435c78 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -106,7 +106,7 @@ Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, // which is an array type. StrTy = Context.CharTy; // A C++ string literal has a const-qualified element type (C++ 2.13.4p1). - if (getLangOptions().CPlusPlus) + if (getLangOptions().CPlusPlus || getLangOptions().ConstStrings) StrTy.addConst(); StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1), ArrayType::Normal, 0); |

