castToDeclContext/castFromDeclContext are only required to be included in the class of decls that directly derive from DeclContext.
Their subclasses don't need them.
castToDeclContext/castFromDeclContext are not meant to be used directly; they are used indirectly by cast/dyn_cast.
All Decl <-> DeclContext casting should be done through cast/dyn_cast.
DeclContext had its "casting machinery" inside the class definition so that if a new declaration context Decl appeared, the necessary changes
would be in one place. Since, now, only DeclNodes.def needs to be modified, move things out-of-line and simplify the DeclContext class.
-In DeclNodes.def, only mark as DeclContexts the top classes that directly derive from DeclContext. If the Decl has subclasses,
it should be marked with DECL_CONTEXT_BASE.
-Use DeclNodes.def to automate the DeclContext::classof and DeclContext::CastTo definitions.
Chris Lattner [Sun, 15 Feb 2009 22:43:40 +0000 (22:43 +0000)]
Refactor the deprecated and unavailable checks into a new
DiagnoseUseOfDeprecatedDecl method. This ensures that they
are treated consistently. This gets us 'unavailable' support
on a few new types of decls, and makes sure we consistently
silence deprecated when the caller is also deprecated.
Chris Lattner [Sun, 15 Feb 2009 21:32:34 +0000 (21:32 +0000)]
fix a fixme in -emit-html output: highlight the entire range of a macro
instantiation, which highlights the arguments of a function like macro
as well as its identifier.
Chris Lattner [Sun, 15 Feb 2009 21:06:39 +0000 (21:06 +0000)]
fix PR3579: __LINE__ expands to the presumed location of the
*end* of a macro instantiation, not the start of it. This is
really all about bug-for-bug compatibility with GCC, but not
doing this breaks the FreeBSD kernel.
Chris Lattner [Sun, 15 Feb 2009 21:06:15 +0000 (21:06 +0000)]
fix PR3579: __LINE__ expands to the presumed location of the
*end* of a macro instantiation, not the start of it. This is
really all about bug-for-bug compatibility with GCC, but not
doing this breaks the FreeBSD kernel.
Chris Lattner [Sun, 15 Feb 2009 20:52:18 +0000 (20:52 +0000)]
track "just a little more" location information for macro instantiations.
Now instead of just tracking the expansion history, also track the full
range of the macro that got replaced. For object-like macros, this doesn't
change anything. For _Pragma and function-like macros, this means we track
the locations of the ')'.
This is required for PR3579 because apparently GCC uses the line of the ')'
of a function-like macro as the location to expand __LINE__ to.
Fixed a bad ir-gen bug which caused a dejagnu test to fail.
Now we are pretty close to be in sync with objc's classic
abi when it comes to passing dejagnu objc executable tests.
Fixed a problem caused by foreward @class use
which consequently caused a Seg fault. during meta-data
generation. It also addresses an issue related to
late binding of newly synthesize ivars (when we support it).
Douglas Gregor [Sat, 14 Feb 2009 18:57:46 +0000 (18:57 +0000)]
Add hook to add attributes to function declarations that we know
about, whether they are builtins or not. Use this to add the
appropriate "format" attribute to NSLog, NSLogv, asprintf, and
vasprintf, and to translate builtin attributes (from Builtins.def)
into actual attributes on the function declaration.
Use the "printf" format attribute on function declarations to
determine whether we should do format string checking, rather than
looking at an ad hoc list of builtins and "known" function names.
Be a bit more careful about when we consider a function a "builtin" in
C++.
Ted Kremenek [Sat, 14 Feb 2009 17:08:39 +0000 (17:08 +0000)]
Patch by Ben Laurie:
ConstraintManager:
- constify getSymVal()
BasicConstraintManager:
- Pull out logic that would be common to ConstraintManagers of a similar nature
and put them in a parent class called 'SimpleConstraintManager'.
RangeConstraintManager:
- Added a new prototype ConstraintManager to track ranges of variables! This
ConstraintManager keeps tracks of ranges of concrete integers that a symbolic
integer may have.
AnalysisConsumer:
- Add driver option to use RangeConstraintManager with GRExprEngine-based
analyses.
Chris Lattner [Sat, 14 Feb 2009 08:09:34 +0000 (08:09 +0000)]
add parser and type checking support for attribute((objc_exception)).
We don't have "zero cost" exceptions for ObjC yet, so there is no codegen
support required.
Chris Lattner [Sat, 14 Feb 2009 07:37:35 +0000 (07:37 +0000)]
Several related changes:
1) implement parser and sema support for reading and verifying attribute(warnunusedresult).
2) rename hasLocalSideEffect to isUnusedResultAWarning, inverting the sense
of its result.
3) extend isUnusedResultAWarning to directly return the loc and range
info that should be reported to the user. Make it substantially more
precise in some cases than what was previously reported.
4) teach isUnusedResultAWarning about CallExpr to decls that are
pure/const/warnunusedresult, fixing a fixme.
5) change warn_attribute_wrong_decl_type to not pass in english strings, instead,
pass in integers and use %select.
Ted Kremenek [Sat, 14 Feb 2009 03:16:10 +0000 (03:16 +0000)]
Added GRStateManager::scanReachableSymbols(), a method which scans the reachable
symbols from an SVal.
- Fixed a bug in EnvironmentManager::RemoveDeadBindings() where it did not mark
live all the symbols reachable from a live block-level expression.
- Fixed a bug in the retain/release checker where it did not stop tracking
symbols that 'escaped' via compound literals being assigned to something the
BasicStoreManager didn't reason about.
Daniel Dunbar [Sat, 14 Feb 2009 02:09:24 +0000 (02:09 +0000)]
x86_64 ABI: Pass simple types directly when possible. This is
important for both keeping the generated LLVM simple and for ensuring
that integer types are passed/promoted correctly.
Douglas Gregor [Sat, 14 Feb 2009 01:52:53 +0000 (01:52 +0000)]
Make it possible for builtins to expression FILE* arguments, so that
we can define builtins such as fprintf, vfprintf, and
__builtin___fprintf_chk. Give a nice error message when we need to
implicitly declare a function like fprintf.
Ted Kremenek [Sat, 14 Feb 2009 01:43:44 +0000 (01:43 +0000)]
Static analyzer:
- Added a new 'node builder' class called GRStmtNodeBuilderRef (name may
change). This is essentially a smart reference to a GRStmtNodeBuilder object
that keeps track of the current context (predecessor node, GRExprEngine
object, etc.) The idea is to gradually simplify the interface between
GRExprEngine and GRTransferFuncs using this new builder (i.e., passing 1
argument instead of 5). It also handles some of the "auto-transition" for node
creation, simplifying some of the logic in GRExprEngine itself.
- Used GRStmtBuilderRef to replace GRTransferFuncs::EvalStore with
GRTransferFuncs::EvalBind. The new EvalBind method will be used at any
arbitrary places where a binding between a location and value takes place.
Moreover, GRTransferFuncs no longer has the responsibility to request
StoreManager to do the binding; this is now in GRExprEngine::EvalBind. All
GRTransferFuncs::EvalBind does is checker-specific logic (which can be a
no-op).
Douglas Gregor [Sat, 14 Feb 2009 00:32:47 +0000 (00:32 +0000)]
Extend builtin "attribute" syntax to include a notation for
printf-like functions, both builtin functions and those in the
C library. The function-call checker now queries this attribute do
determine if we have a printf-like function, rather than scanning
through the list of "known functions IDs". However, there are 5
functions they are not yet "builtins", so the function-call checker
handles them specifically still:
- fprintf and vfprintf: the builtins mechanism cannot (yet)
express FILE* arguments, so these can't be encoded.
- NSLog: the builtins mechanism cannot (yet) express NSString*
arguments, so this (and NSLogv) can't be encoded.
- asprintf and vasprintf: these aren't part of the C99 standard
library, so we really shouldn't be defining them as builtins in
the general case (and we don't seem to have the machinery to make
them builtins only on certain targets and depending on whether
extensions are enabled).
Douglas Gregor [Fri, 13 Feb 2009 23:20:09 +0000 (23:20 +0000)]
Implicitly declare certain C library functions (malloc, strcpy, memmove,
etc.) when we perform name lookup on them. This ensures that we
produce the correct signature for these functions, which has two
practical impacts:
1) When we're supporting the "implicit function declaration" feature
of C99, these functions will be implicitly declared with the right
signature rather than as a function returning "int" with no
prototype. See PR3541 for the reason why this is important (hint:
GCC always predeclares these functions).
2) If users attempt to redeclare one of these library functions with
an incompatible signature, we produce a hard error.
This patch does a little bit of work to give reasonable error
messages. For example, when we hit case #1 we complain that we're
implicitly declaring this function with a specific signature, and then
we give a note that asks the user to include the appropriate header
(e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In
case #2, we show the type of the implicit builtin that was incorrectly
declared, so the user can see the problem. We could do better here:
for example, when displaying this latter error message we say
something like:
'strcpy' was implicitly declared here with type 'char *(char *, char
const *)'
but we should really print out a fake code line showing the
declaration, like this:
'strcpy' was implicitly declared here as:
char *strcpy(char *, char const *)
This would also be good for printing built-in candidates with C++
operator overloading.
The set of C library functions supported by this patch includes all
functions from the C99 specification's <stdlib.h> and <string.h> that
(a) are predefined by GCC and (b) have signatures that could cause
codegen issues if they are treated as functions with no prototype
returning and int. Future work could extend this set of functions to
other C library functions that we know about.
Chris Lattner [Fri, 13 Feb 2009 22:13:02 +0000 (22:13 +0000)]
improve wording in a diagnostic to make it clear that we never intend to support
the vla-in-structure extension that GCC does. PR3562
Also wrap some long lines.
Daniel Dunbar [Fri, 13 Feb 2009 21:18:01 +0000 (21:18 +0000)]
Pull MayDeferGeneration out of EmitGlobal.
- Fix emission of static functions with constructor attribute while I
was here.
<rdar://problem/6140899> [codegen] "static" and attribute-constructor interact poorly
Chris Lattner [Fri, 13 Feb 2009 19:33:24 +0000 (19:33 +0000)]
Fix rdar://6562329, a static analyzer crash Ted noticed on
wine sources. This was happening because HighlightMacros was
calling EnterMainFile multiple times on the same preprocessor
object and getting an assert due to the new #line stuff (the
file in question was bison output with #line directives).
The fix for this is to not reenter the file. Instead,
relex the tokens in raw mode, swizzle them a bit and repreprocess
the token stream. An added bonus of this is that rewrite macros
will now hilight the macro definition as well as its uses. Woo.
Douglas Gregor [Fri, 13 Feb 2009 19:06:18 +0000 (19:06 +0000)]
Remove DeclGroupOwningRef, since we intend for declarations to be owned
by DeclContexts (always) rather than by statements.
DeclContext currently goes out of its way to avoid destroying any
Decls that might be owned by a DeclGroupOwningRef. However, in an
error-recovery situation, a failure in a declaration statement can
cause all of the decls in a DeclGroupOwningRef to be destroyed after
they've already be added into the DeclContext. Hence, DeclContext is
left with already-destroyed declarations, and bad things happen. This
problem was causing failures that showed up as assertions on x86 Linux
in test/Parser/objc-forcollection-neg-2.m.