summaryrefslogtreecommitdiff
path: root/include/llvm/Support/Casting.h
Commit message (Collapse)AuthorAge
* Fix a regression I introduced back in r178147.Rafael Espindola2013-07-18
| | | | | | | | | | | We don't want cast and dyn_cast to work on temporaries. They don't extend lifetime like a direct bind to a reference would, so they can introduce hard to find bugs. I added tests to make sure we don't regress this. Thanks to Eli Friedman for noticing this and for his suggestions on how to test it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186559 91177308-0d34-0410-b5e6-96231b3b80d8
* Cleanup the simplify_type implementation.Rafael Espindola2013-03-27
| | | | | | | | | | | | | | | | | | | | As far as simplify_type is concerned, there are 3 kinds of smart pointers: * const correct: A 'const MyPtr<int> &' produces a 'const int*'. A 'MyPtr<int> &' produces a 'int *'. * always const: Even a 'MyPtr<int> &' produces a 'const int*'. * no const: Even a 'const MyPtr<int> &' produces a 'int*'. This patch then does the following: * Removes the unused specializations. Since they are unused, it is hard to know which kind should be implemented. * Make sure we don't drop const. * Fix the default forwarding so that const correct pointer only need one specialization. * Simplifies the existing specializations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178147 91177308-0d34-0410-b5e6-96231b3b80d8
* Limit cast machinery to preserve const and not accept temporariesDavid Blaikie2013-02-21
| | | | | | | | | | | | | | | | | | | | | | | After cleaning up the following type hierarchies: * TypeLoc: r175462 * SVal: r175594 * CFGElement: r175462 * ProgramPoint: r175812 that all invoked undefined behavior by causing a derived copy construction of a base object through an invalid cast (thus supporting code that relied on casting temporaries that were direct base objects) Clang/LLVM is now clean of casts of temporaries. So here's some fun SFINAE machinery (courtesy of Eli Friedman, with some porting back from C++11 to LLVM's traits by me) to cause compile-time failures if llvm::cast & friends are ever passed an rvalue. This should avoid a repeat of anything even remotely like PR14321/r168124. Thanks to Jordan Rose for the help with the various Static Analyzer related hierarchies that needed cleaning up, Eli for the SFINAE, Richard Smith, John McCall, Ted Kremenek, and Anna Zaks for their input/reviews/patience along the way. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175819 91177308-0d34-0410-b5e6-96231b3b80d8
* Casting.h: Automatically handle isa<Base>(Derived).Sean Silva2012-10-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Additionally, all such cases are handled with no dynamic check. All `classof()` of the form class Foo { [...] static bool classof(const Bar *) { return true; } [...] } where Foo is an ancestor of Bar are no longer necessary. Don't write them! Note: The exact test is `is_base_of<Foo, Bar>`, which is non-strict, so that Foo is considered an ancestor of itself. This leads to the following rule of thumb for LLVM-style RTTI: The argument type of `classof()` should be a strict ancestor. For more information about implementing LLVM-style RTTI, see docs/HowToSetUpLLVMStyleRTTI.rst git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165765 91177308-0d34-0410-b5e6-96231b3b80d8
* Casting: assert that pointer arguments to isa<> are non-null.Jordan Rose2012-09-22
| | | | | | | | This silences several analyzer warnings within LLVM, and provides a slightly nicer crash experience when someone calls isa<>, cast<>, or dyn_cast<> with a null pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164439 91177308-0d34-0410-b5e6-96231b3b80d8
* PR7952: Make isa<> use the same logic as cast<>, so that they both workEli Friedman2011-05-21
| | | | | | | | consistently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131803 91177308-0d34-0410-b5e6-96231b3b80d8
* fix doc comment bug, noticed by JochenChris Lattner2011-04-09
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129186 91177308-0d34-0410-b5e6-96231b3b80d8
* restrict dyn_cast_or_null to pointer types, just like cast_or_null; ↵Gabor Greif2010-09-18
| | | | | | re-commit of r114279, backed out in r114280 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114282 91177308-0d34-0410-b5e6-96231b3b80d8
* back out r114279 as some darwin buildbots get errors compiling clang:Gabor Greif2010-09-18
| | | | | | svn merge -c -114279 llvm/include/llvm/Support/Casting.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114280 91177308-0d34-0410-b5e6-96231b3b80d8
* restrict dyn_cast_or_null to pointer types, just like cast_or_nullGabor Greif2010-09-18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114279 91177308-0d34-0410-b5e6-96231b3b80d8
* remove testing cruft, this can be found in unittests/Support/Casting.cpp nowGabor Greif2010-07-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108868 91177308-0d34-0410-b5e6-96231b3b80d8
* Switch isa_impl from a function template to a class template with aDouglas Gregor2010-03-30
| | | | | | | | static inline member function doit(). This enables the use of partial specialization to override the last stage of the "isa" check. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99898 91177308-0d34-0410-b5e6-96231b3b80d8
* use a c-style cast instead of reinterpret-cast, as sometimes theChris Lattner2010-02-08
| | | | | | | | | cast needs to adjust for a vtable pointer when going from base to derived type (when the base doesn't have a vtable but the derived type does). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95585 91177308-0d34-0410-b5e6-96231b3b80d8
* Convert debug messages to use dbgs(). Generally this meansDavid Greene2009-12-23
| | | | | | | s/errs/dbgs/g except for certain special cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92016 91177308-0d34-0410-b5e6-96231b3b80d8
* convert LoopInfo.h and GraphWriter.h to use raw_ostreamChris Lattner2009-08-23
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79836 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r78424.Argyrios Kyrtzidis2009-08-14
| | | | | | | In order for the changes in r78424 to work properly, cast_retty<X,Y> should return an object instead of a reference, and it's not clear that this approach has real advantages. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79023 91177308-0d34-0410-b5e6-96231b3b80d8
* Modifications to dyn_cast/cast to make them work for objects too, instead of ↵Argyrios Kyrtzidis2009-08-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | only pointers. The use case is if you have a wrapper class: class Base { void *Ptr; public: Base() : Ptr(0) { } operator bool() const { return Ptr; } ..... } and sub-wrappers that have exactly the same size: class Sub : public Base { public: .... static bool classof(const Base*); } and in the code you would do: void f(Base b) { Sub sub = dyn_cast<Sub>(b); if (sub) { .... } } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78424 91177308-0d34-0410-b5e6-96231b3b80d8
* Roll back rev 59890, since Chris says this can never happen.Scott Michel2008-11-23
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59914 91177308-0d34-0410-b5e6-96231b3b80d8
* Check for NULL before traversing the isa<> type hierarchy checking with aScott Michel2008-11-22
| | | | | | | | | | | NULL-based reference. Note: Encountered this a few times on Tiger + gcc 4.0.1. Might just be a platform-specific compiler issue, but it's good defensive programming in any case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59890 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove uses of "llvm/Support/Debug.h" from LLVM include files, whichDan Gohman2008-07-07
| | | | | | | all happened be unnecessary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53182 91177308-0d34-0410-b5e6-96231b3b80d8
* merge of r49785 (from branches/ggreif/use-diet): pass V to dyn_cast by const ↵Gabor Greif2008-04-16
| | | | | | reference, this avoids copy-constructing and destructing all the time. especially important if these constructors are not accessible git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49787 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't attribute in file headers anymore. See llvmdev for theChris Lattner2007-12-29
| | | | | | | | discussion of this change. Boy are my fingers tired. ;-) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45411 91177308-0d34-0410-b5e6-96231b3b80d8
* Changed llvm_ostream et all to OStream. llvm_cerr, llvm_cout, llvm_null, areBill Wendling2006-12-07
| | | | | | | now cerr, cout, and NullStream resp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32298 91177308-0d34-0410-b5e6-96231b3b80d8
* Used llvm_ostream instead of std::ostream objects. This will reduce useBill Wendling2006-11-17
| | | | | | | of the icky <iostream> class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31818 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a #include <cassert> for situations where Casting.h is used standalone.Reid Spencer2006-05-13
| | | | | | | Patch contributed by Vladimir Prus. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28280 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove trailing whitespaceMisha Brukman2005-04-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21411 91177308-0d34-0410-b5e6-96231b3b80d8
* Changes For Bug 352Reid Spencer2004-09-01
| | | | | | | | | Move include/Config and include/Support into include/llvm/Config, include/llvm/ADT and include/llvm/Support. From here on out, all LLVM public header files must be under include/llvm/. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16137 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixes for PR114: Thanks to Reid Spencer!Chris Lattner2003-11-16
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10029 91177308-0d34-0410-b5e6-96231b3b80d8
* Put all LLVM code into the llvm namespace, as per bug 109.Brian Gaeke2003-11-11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9903 91177308-0d34-0410-b5e6-96231b3b80d8
* Added LLVM notice.John Criswell2003-10-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9300 91177308-0d34-0410-b5e6-96231b3b80d8
* Standardize header file commentsChris Lattner2003-09-30
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8782 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix spelloChris Lattner2003-09-10
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8432 91177308-0d34-0410-b5e6-96231b3b80d8
* Spell `incompatible' correctly.Misha Brukman2003-08-27
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8163 91177308-0d34-0410-b5e6-96231b3b80d8
* Merged in autoconf branch. This provides configuration via the autoconfJohn Criswell2003-06-30
| | | | | | | system. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7014 91177308-0d34-0410-b5e6-96231b3b80d8
* dyn_cast_or_null should work just the same as dyn_cast doesChris Lattner2003-05-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6394 91177308-0d34-0410-b5e6-96231b3b80d8
* Allow dyn_cast to operate on things that aren't OBVIOUSLY a pointer type.Chris Lattner2003-04-23
| | | | | | | These things can be converted to a pointer, like ilist_iterators git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5861 91177308-0d34-0410-b5e6-96231b3b80d8
* Add missing typename's that GCC3.1 is whining about.Chris Lattner2002-07-24
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3051 91177308-0d34-0410-b5e6-96231b3b80d8
* MEGAPATCH checkin.Chris Lattner2002-06-25
| | | | | | | For details, See: docs/2002-06-25-MegaPatchInfo.txt git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2779 91177308-0d34-0410-b5e6-96231b3b80d8
* Pull casting operators out of Value.hChris Lattner2002-04-08
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2166 91177308-0d34-0410-b5e6-96231b3b80d8