[cfe-commits] r130781 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp test/SemaCXX/warn-non-pod-memset.cpp
Nico Weber
thakis at chromium.org
Tue May 3 13:14:14 PDT 2011
Cool!
Can the warning mention "overwrites vtable" somehow? I think this is
not immediately obvious from the diagnostic.
On Tue, May 3, 2011 at 1:05 PM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Tue May 3 15:05:22 2011
> New Revision: 130781
>
> URL: http://llvm.org/viewvc/llvm-project?rev=130781&view=rev
> Log:
> Separate the -Wnon-pod-memset warnings into two separate warnings:
> - a default-on warning for pointers to dynamic classes (= classes with vtables)
> - a default-off warning for other non-POD types
>
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/SemaCXX/warn-non-pod-memset.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=130781&r1=130780&r2=130781&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 3 15:05:22 2011
> @@ -261,6 +261,9 @@
> def err_types_compatible_p_in_cplusplus : Error<
> "__builtin_types_compatible_p is not valid in C++">;
> def warn_builtin_unknown : Warning<"use of unknown builtin %0">, DefaultError;
> +def warn_dyn_class_memset : Warning<
> + "destination for this memset call is a pointer to a dynamic class %0">,
> + InGroup<DiagGroup<"non-pod-memset">>;
> def warn_non_pod_memset : Warning<
> "destination for this memset call is a pointer to a non-POD type %0">,
> InGroup<DiagGroup<"non-pod-memset">>, DefaultIgnore;
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=130781&r1=130780&r2=130781&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue May 3 15:05:22 2011
> @@ -1799,6 +1799,17 @@
>
> //===--- CHECK: Standard memory functions ---------------------------------===//
>
> +/// \brief Determine whether the given type is a dynamic class type (e.g.,
> +/// whether it has a vtable).
> +static bool isDynamicClassType(QualType T) {
> + if (CXXRecordDecl *Record = T->getAsCXXRecordDecl())
> + if (CXXRecordDecl *Definition = Record->getDefinition())
> + if (Definition->isDynamicClass())
> + return true;
> +
> + return false;
> +}
> +
> /// \brief Check for dangerous or invalid arguments to memset().
> ///
> /// This issues warnings on known problematic or dangerous or unspecified
> @@ -1814,27 +1825,26 @@
>
> const Expr *Dest = Call->getArg(0)->IgnoreParenImpCasts();
>
> - // The type checking for this warning is moderately expensive, only do it
> - // when enabled.
> - if (getDiagnostics().getDiagnosticLevel(diag::warn_non_pod_memset,
> - Dest->getExprLoc()) ==
> - Diagnostic::Ignored)
> - return;
> -
> QualType DestTy = Dest->getType();
> if (const PointerType *DestPtrTy = DestTy->getAs<PointerType>()) {
> QualType PointeeTy = DestPtrTy->getPointeeType();
> if (PointeeTy->isVoidType())
> return;
>
> + unsigned DiagID = 0;
> + // Always complain about dynamic classes.
> + if (isDynamicClassType(PointeeTy))
> + DiagID = diag::warn_dyn_class_memset;
> // Check the C++11 POD definition regardless of language mode; it is more
> - // relaxed than earlier definitions and we don't want spurrious warnings.
> - if (PointeeTy->isCXX11PODType())
> + // relaxed than earlier definitions and we don't want spurious warnings.
> + else if (!PointeeTy->isCXX11PODType())
> + DiagID = diag::warn_non_pod_memset;
> + else
> return;
>
> DiagRuntimeBehavior(
> Dest->getExprLoc(), Dest,
> - PDiag(diag::warn_non_pod_memset)
> + PDiag(DiagID)
> << PointeeTy << Call->getCallee()->getSourceRange());
>
> SourceRange ArgRange = Call->getArg(0)->getSourceRange();
>
> Modified: cfe/trunk/test/SemaCXX/warn-non-pod-memset.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-non-pod-memset.cpp?rev=130781&r1=130780&r2=130781&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/warn-non-pod-memset.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-non-pod-memset.cpp Tue May 3 15:05:22 2011
> @@ -30,13 +30,13 @@
> // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
> // expected-note {{explicitly cast the pointer to silence this warning}}
> memset(&x3, 0, sizeof x3); // \
> - // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
> + // expected-warning {{destination for this memset call is a pointer to a dynamic class}} \
> // expected-note {{explicitly cast the pointer to silence this warning}}
> memset(&x4, 0, sizeof x4); // \
> // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
> // expected-note {{explicitly cast the pointer to silence this warning}}
> memset(&x5, 0, sizeof x5); // \
> - // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
> + // expected-warning {{destination for this memset call is a pointer to a dynamic class}} \
> // expected-note {{explicitly cast the pointer to silence this warning}}
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list