summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaCast.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Sema: Check value dependent casts when possibleDavid Majnemer2014-12-161-4/+2
| | | | | | | | | | We know that const_cast<char *>((void)Something) is ill-formed, even if 'Something' is dependent because you can't cast from void to a pointer type. This fixes PR21845. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224299 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenCL] Implemented restrictions for pointer conversions specified in ↵Anastasia Stulova2014-11-261-2/+2
| | | | | | | | | | | | | | OpenCL v2.0. OpenCL v2.0 s6.5.5 restricts conversion of pointers to different address spaces: - the named address spaces (__global, __local, and __private) => __generic - implicitly converted; - __generic => named - with an explicit cast; - named <=> named - disallowed; - __constant <=> any other - disallowed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222834 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement -Wcast-qual, fixing #13772.Roman Divacky2014-11-211-4/+40
| | | | | | | Many thanks to dblaikie for his advices and suggestions! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222568 91177308-0d34-0410-b5e6-96231b3b80d8
* PR20227: materialize a temporary when dynamic_casting a class prvalue to aRichard Smith2014-07-081-1/+9
| | | | | | | reference type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212551 91177308-0d34-0410-b5e6-96231b3b80d8
* Hide the concept of diagnostic levels from lex, parse and semaAlp Toker2014-06-151-6/+3
| | | | | | | | | | | | | | | | The compilation pipeline doesn't actually need to know about the high-level concept of diagnostic mappings, and hiding the final computed level presents several simplifications and other potential benefits. The only exceptions are opportunistic checks to see whether expensive code paths can be avoided for diagnostics that are guaranteed to be ignored at a certain SourceLocation. This commit formalizes that invariant by introducing and using DiagnosticsEngine::isIgnored() in place of individual level checks throughout lex, parse and sema. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211005 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactoring. Remove Owned method from Sema.Nikola Smiljanic2014-05-291-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209812 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactoring. Remove release and take methods from ActionResult. Rename ↵Nikola Smiljanic2014-05-291-20/+20
| | | | | | takeAs to getAs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209800 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Use 'nullptr'. Sema edition.Craig Topper2014-05-261-5/+5
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209613 91177308-0d34-0410-b5e6-96231b3b80d8
* Objective-C ARC. Add support for toll-free bridge Fariborz Jahanian2014-05-101-0/+5
| | | | | | | | type ,and bridge attribute, checking with static_cast. // rdar://16756639 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208474 91177308-0d34-0410-b5e6-96231b3b80d8
* AST: Mangle reference temporaries reliablyDavid Majnemer2014-05-011-2/+1
| | | | | | | | | | | | | | | Summary: Previously, we would generate a single name for all reference temporaries and allow LLVM to rename them for us. Instead, number the reference temporaries as we build them in Sema. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3554 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207776 91177308-0d34-0410-b5e6-96231b3b80d8
* Objective-C. Improve diagnosis of bridging types.Fariborz Jahanian2014-04-291-4/+0
| | | | | | | // rdar://16737117 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207542 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix diagnostics for C-style cast to function type.Logan Chien2014-04-131-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | If the C-style type cast is applied to the overloaded function and the destination type is function type, then Clang will crash with assertion failure. For example, void foo(int); void foo(int, int); void bar() { typedef void (ft)(int); ft p = (ft)foo; } In this case, the overloaded function foo will be cast to a function type, which should be considered as an error. But, unfortunately, since the function resolution is using canonical type, the matched function will be returned, and result in SEGV. This patch fixes this issue by removing the assertion and add some error diagnostics as the one in static_cast. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206133 91177308-0d34-0410-b5e6-96231b3b80d8
* MS ABI: Tweak pointer-to-member mangling/inheritance model selectionDavid Majnemer2014-02-061-0/+4
| | | | | | | | | | | | | Properly determine the inheritance model when dealing with nullptr: - If a nullptr template argument is being checked against pointer-to-member parameter, nail down an inheritance model. N.B. We will chose an inheritance model even if we won't ultimately choose the template to instantiate! Cooky, right? - Null pointer-to-datamembers have a virtual base table offset of -1, not zero. Previously, we chose an offset of 0. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200920 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "Revert r199416, "MS ABI: Improve selection of an inheritance model""David Majnemer2014-01-171-0/+8
| | | | | | | | | | | This reverts commit r199475 (which reverted r199416) with fixes for the breakages. We wouldn't lock an inheritance model if we saw a pointer-to-member formed as a result of the address-of operator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199482 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r199416, "MS ABI: Improve selection of an inheritance model"NAKAMURA Takumi2014-01-171-8/+0
| | | | | | | | | | | | It broke tests for targeting x86_64-pc-win32: Clang Tools :: clang-modernize/LoopConvert/array.cpp Clang :: CodeGenCXX/2010-05-10-Var-DbgInfo.cpp Clang :: CodeGenCXX/member-call-parens.cpp Clang :: CodeGenCXX/ptr-to-datamember.cpp Clang :: SemaTemplate/instantiate-function-1.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199475 91177308-0d34-0410-b5e6-96231b3b80d8
* MS ABI: Improve selection of an inheritance modelDavid Majnemer2014-01-161-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | The MSVC ABI is rather finicky about the exact representation of it's pointer-to-member representation. The exact position of when and where it will go with one representation versus another appears to be when it desires the pointer-to-member to be complete. To properly implement this in clang, do several things: - Give up on tracking the polymorphic nature of the class. It isn't useful to Sema and is only pertinent when choosing CodeGen-time details like whether the field-offset can be 0 instead of -1. - Insist on locking-in the inheritance model when we ask our pointer-to-member type to be complete. From there, grab the underlying CXXRecordDecl and try to make *that* complete. Once we've done this, we can calculate it's inheritance model and apply it using an attribute. N.B. My first bullet point is a lie. We will eventually care about the specifics of whether or not a CXXRecordDecl is or is not polymorphic because MSVC compatible mangling of such things depends on it. However, I believe we will handle this in a rather different way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199416 91177308-0d34-0410-b5e6-96231b3b80d8
* Sema: Fix crash during member pointer conversion involving incomplete classesDavid Majnemer2014-01-161-1/+2
| | | | | | | | | | | | | | We would attempt to determine the inheritance relationship between classes 'A' and 'B' during static_cast if we tried to convert from 'int A::*' to 'int B::*'. However, the question "does A derive from B" is not meaningful when 'A' isn't defined. Handle this case by requiring that 'A' be defined. This fixes PR18506. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199374 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenCL] Disallow casts between address spaces.Joey Gouly2014-01-141-0/+15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199208 91177308-0d34-0410-b5e6-96231b3b80d8
* ObjectiveC. Allow toll free bridge cast warnings outsideFariborz Jahanian2013-11-211-0/+5
| | | | | | | | ARC and in objectiveC/ObjectiveC++ MRR mode as well. // rdar://15454846 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195288 91177308-0d34-0410-b5e6-96231b3b80d8
* Allow dynamic_cast to void* even with -fno-rtti.Eli Friedman2013-09-241-2/+4
| | | | | | PR17346. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191340 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix crash with cast of value-dependent expr.Eli Friedman2013-09-191-2/+5
| | | | | | | | | We don't really need to perform semantic analysis on the dependent expression anyway, so just call the cast dependent. <rdar://problem/15012610> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190981 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix missing source location in CXXTemporaryObjectExpr nodes.Enea Zaffanella2013-09-071-1/+1
| | | | | | | | | | For clarity, renamed (get/set)ParenRange as (get/set)ParenOrBraceRange in CXXConstructExpr nodes. Added testcase. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190239 91177308-0d34-0410-b5e6-96231b3b80d8
* Properly track l-paren of a CXXFucntionalCastExpr.Eli Friedman2013-08-151-2/+2
| | | | | | | | | | In addition to storing more useful information in the AST, this fixes a semantic check in template instantiation which checks whether the l-paren location is valid. Fixes PR16903. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188495 91177308-0d34-0410-b5e6-96231b3b80d8
* Check dynamic_cast is not used with -fno-rtti, unless it is a noop or can be ↵Arnaud A. de Grandmaison2013-08-011-0/+7
| | | | | | resolved statically. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187564 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't build expressions for invalid casts.Eli Friedman2013-07-261-8/+21
| | | | | | | | | | This matches how we normally perform semantic analysis for other sorts of invalid expressions: it means we don't have to reason about invalid sub-expressions. Fixes PR16680. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187276 91177308-0d34-0410-b5e6-96231b3b80d8
* Use SmallVectorImpl::reverse_iterator instead of SmallVector to avoid ↵Craig Topper2013-07-081-2/+2
| | | | | | specifying the vector size. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185784 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't use unnamed local enums as template arguments.Joerg Sonnenberger2013-06-261-2/+2
| | | | | | | Fixes -Werror bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185023 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove dead code.Eli Friedman2013-06-201-5/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184453 91177308-0d34-0410-b5e6-96231b3b80d8
* Silence 'set but not used' warning when building in release mode using gcc.Andy Gibbs2013-06-191-0/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184299 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix handling of const_cast from prvalue to rvalue reference: such a cast isRichard Smith2013-06-141-11/+46
| | | | | | | | only permitted if the source object is of class type, and should materialize a temporary for the reference to bind to. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184017 91177308-0d34-0410-b5e6-96231b3b80d8
* Disallow reinterpret_cast from pointer to bool on WindowsHans Wennborg2013-06-061-2/+4
| | | | | | | | | | | | This became allowed by accident in r131201, but triggers an assert. That patch added an exception to allow conversion from pointers to narrow integral types for MSVC compatibility. However, a pointer can already be converted to bool in a civilized manner; allowing conversion via reinterpret_cast is a bad idea. Fixes PR16222. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183394 91177308-0d34-0410-b5e6-96231b3b80d8
* Split off casts to void* for -Wint-to-pointer-cast to subgroup ↵Ted Kremenek2013-05-291-2/+12
| | | | | | | | | | | | | -Wint-to-void-pointer-cast. This change is motivated from user feedback that some APIs use void* as an opaque "context" object that may not really be a pointer. Such users want an ability to turn off the warning for casts to void* while preserving the warning for other cases. Implements <rdar://problem/14016721>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182884 91177308-0d34-0410-b5e6-96231b3b80d8
* Grab-bag of bit-field fixes:John McCall2013-05-061-1/+11
| | | | | | | | | | | | | | - References to ObjC bit-field ivars are bit-field lvalues; fixes rdar://13794269, which got me started down this. - Introduce Expr::refersToBitField, switch a couple users to it where semantically important, and comment the difference between this and the existing API. - Discourage Expr::getBitField by making it a bit longer and less general-sounding. - Lock down on const_casts of bit-field gl-values until we hear back from the committee as to whether they're allowed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181252 91177308-0d34-0410-b5e6-96231b3b80d8
* ArrayRef'ize InitializationSequence constructor and ↵Dmitri Gribenko2013-05-031-2/+2
| | | | | | | | | InitializationSequence::Diagnose() Patch by Robert Wilhelm. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181022 91177308-0d34-0410-b5e6-96231b3b80d8
* Provide a fixit to static_cast for reinterpret_casts within a class hierarchy.Jordan Rose2013-03-281-6/+7
| | | | | | | | | The suggestion was already in the text of the note; this just adds the actual fixit and the appropriate test cases. Patch by Alexander Zinenko! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178274 91177308-0d34-0410-b5e6-96231b3b80d8
* Make the -Wreinterpret-base-class logic safe against invalidJohn McCall2013-03-271-6/+15
| | | | | | | declarations at any point. Patch by Alexander Zinenko, and report by Richard Smith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178098 91177308-0d34-0410-b5e6-96231b3b80d8
* Warn about attempts to reinterpret_cast between two types that areJohn McCall2013-03-221-2/+87
| | | | | | | | hierarchy-related at a possibly nonzero offset. Patch by Alexander Zinenko! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177698 91177308-0d34-0410-b5e6-96231b3b80d8
* objective-C arg: provide fixit support whenFariborz Jahanian2013-02-221-4/+8
| | | | | | | | c++'s named cast need be replaced for bridge casting. // rdar://12788838 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175923 91177308-0d34-0410-b5e6-96231b3b80d8
* Diagnose loads of 'half' l-values in OpenCL.John McCall2013-02-121-6/+0
| | | | | | Patch by Joey Gouly! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174928 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a new LangOpt NativeHalfType. This option allows for native half/fp16Joey Gouly2013-01-231-0/+15
| | | | | | | | | | operations (as opposed to storage only half/fp16). Also add some semantic checks for OpenCL half types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173254 91177308-0d34-0410-b5e6-96231b3b80d8
* s/CPlusPlus0x/CPlusPlus11/gRichard Smith2013-01-021-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171367 91177308-0d34-0410-b5e6-96231b3b80d8
* objc: DOn't complain if a (SEL) expression is typecastFariborz Jahanian2012-12-131-0/+2
| | | | | | | to (SEL). Fixes // rdar://12859590 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170058 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-3/+3
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169237 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement GCC's -Wint-to-pointer-cast.David Blaikie2012-10-161-0/+20
| | | | | | | | | | | | This implementation doesn't warn on anything that GCC doesn't warn on with the exception of templates specializations (GCC doesn't warn, Clang does). The specific skipped cases (boolean, constant expressions, enums) are open for debate/adjustment if anyone wants to demonstrate that GCC is being overly conservative here. The only really obvious false positive I found was in the Clang regression suite's MPI test - apparently MPI uses specific flag values in pointer constants. (eg: #define FOO (void*)~0) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166039 91177308-0d34-0410-b5e6-96231b3b80d8
* Now that ASTMultiPtr is nothing more than a array reference, make it a ↵Benjamin Kramer2012-08-231-2/+1
| | | | | | | | MutableArrayRef. This required changing all get() calls to data() and using the simpler constructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162501 91177308-0d34-0410-b5e6-96231b3b80d8
* Rip out remnants of move semantic emulation and smart pointers in Sema.Benjamin Kramer2012-08-231-3/+3
| | | | | | | These were nops for quite a while and only lead to confusion. ASTMultiPtr now behaves like a proper dumb array reference. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162475 91177308-0d34-0410-b5e6-96231b3b80d8
* c: implement gcc's -Wbad-function-cast which warnsFariborz Jahanian2012-08-171-1/+38
| | | | | | | | on unsafe cast of a c-function call. This is a C-only option. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162109 91177308-0d34-0410-b5e6-96231b3b80d8
* objective-C: deprecate casts of ObjC's SELFariborz Jahanian2012-08-161-1/+19
| | | | | | | | expressions except to void, void * and their qualified versions. // rdar://12107381 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162036 91177308-0d34-0410-b5e6-96231b3b80d8
* Add correct parenthesis range to CXXConstructExprs insideDaniel Jasper2012-07-161-0/+3
| | | | | | CXXFunctionalCastExprs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160252 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix Sema and IRGen for atomic compound assignment so it has the right ↵Eli Friedman2012-06-161-5/+1
| | | | | | | | | | semantics when promotions are involved. (As far as I can tell, this only affects some edge cases.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158591 91177308-0d34-0410-b5e6-96231b3b80d8