From pichet2000 at gmail.com Mon Mar 14 01:07:19 2011 From: pichet2000 at gmail.com (Francois Pichet) Date: Mon, 14 Mar 2011 02:07:19 -0400 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing Message-ID: Hi, This patch implements "Late template parsing" in Microsoft mode. It solves the problem of Microsoft allowing names not yet declared in template code Like this: template void foo() { undeclared(); } void undeclared(){ } To do so, template function code and template explicit instantiations are lexed, the tokens saved and actually parsed at the end of the translation unit. This resolve a bunch of error when parsing Microsoft C++ template code with clang. Important point: I tested that this patch can self host clang (on Darwin) with -fms-extension enabled and it works: make CXXFLAGS=-fms-extensions cd tools/clang make test 100% pass -------------- next part -------------- A non-text attachment was scrubbed... Name: LateParsedMSTemplate.patch Type: application/octet-stream Size: 16649 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110314/dd6e3887/attachment-0001.obj From dgregor at apple.com Mon Mar 14 09:35:55 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 07:35:55 -0700 Subject: [cfe-commits] r127564 - /cfe/trunk/tools/libclang/CMakeLists.txt In-Reply-To: <87k4g3sgqj.fsf@wanadoo.es> References: <20110313042830.073B82A6C12C@llvm.org> <87k4g3sgqj.fsf@wanadoo.es> Message-ID: On Mar 12, 2011, at 9:59 PM, ?scar Fuentes wrote: > Francois Pichet writes: > >> You can reapply this patch but you need to remove all that: (in Index.h) >> #ifdef _CINDEX_LIB_ >> #define CINDEX_LINKAGE __declspec(dllexport) >> #else >> #define CINDEX_LINKAGE __declspec(dllimport) >> #endif >> >> just do >> #define CINDEX_LINKAGE >> >> You can't do dllexport and dllimport stuff for shared libs. > > I think you mean "You can't do dllexport and dllimport stuff for > *static* libs". > >> I was just about this checkin that but you reverted the patch:( > > I was not aware that libclang was being created as a dll on Windows, so > when my change forced it to be static, the problem you noticed came to > being. My intention is to reapply the patch but with the necessary > modifications for keep building libclang as a dll. Unless someone says > that static is preferable. libclang should be built as a DLL. I don't see any reason for it to be a static library. - Doug From ofv at wanadoo.es Mon Mar 14 09:32:16 2011 From: ofv at wanadoo.es (Oscar Fuentes) Date: Mon, 14 Mar 2011 14:32:16 -0000 Subject: [cfe-commits] r127579 - /cfe/trunk/tools/libclang/CMakeLists.txt Message-ID: <20110314143216.6A3882A6C12C@llvm.org> Author: ofv Date: Mon Mar 14 09:32:16 2011 New Revision: 127579 URL: http://llvm.org/viewvc/llvm-project?rev=127579&view=rev Log: Fix LIBCLANG_LINK_FLAGS for Darwin. The previous syntax created a list with the usual semicolon as separator, which breaks the link command. Modified: cfe/trunk/tools/libclang/CMakeLists.txt Modified: cfe/trunk/tools/libclang/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CMakeLists.txt?rev=127579&r1=127578&r2=127579&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CMakeLists.txt (original) +++ cfe/trunk/tools/libclang/CMakeLists.txt Mon Mar 14 09:32:16 2011 @@ -38,8 +38,8 @@ DEFINE_SYMBOL _CINDEX_LIB_) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(LIBCLANG_LINK_FLAGS "-Wl,-compatibility_version -Wl,1" - " -Wl,-dead_strip -Wl,-seg1addr -Wl,0xE0000000") + set(LIBCLANG_LINK_FLAGS + "-Wl,-compatibility_version -Wl,1 -Wl,-dead_strip -Wl,-seg1addr -Wl,0xE0000000") set_target_properties(libclang PROPERTIES LINK_FLAGS "${LIBCLANG_LINK_FLAGS}" From dgregor at apple.com Mon Mar 14 09:36:54 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 07:36:54 -0700 Subject: [cfe-commits] r127507 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseStmt.cpp test/SemaCXX/cxx0x-return-init-list.cpp In-Reply-To: <20110311231044.D03472A6C12C@llvm.org> References: <20110311231044.D03472A6C12C@llvm.org> Message-ID: Bill, Please pull this commit into the 2.9 release branch. Thanks! Doug On Mar 11, 2011, at 3:10 PM, Douglas Gregor wrote: > Author: dgregor > Date: Fri Mar 11 17:10:44 2011 > New Revision: 127507 > > URL: http://llvm.org/viewvc/llvm-project?rev=127507&view=rev > Log: > Implement a hack intended to allow Clang to parse libstdc++ 4.5's > headers, which use C++0x generalized initializer lists. Per PR7069, it > appears that the only use is as the return type of a function, so this > commit enables this extension just in that narrow case. If it's enough > for libstdc++ 4.5, or if it can be trivially extended to work with > libstdc++ 4.5, we'll keep it. Otherwise, or if this breaks anything, > we'll revert and wait for the real feature. > > > Added: > cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp > Modified: > cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td > cfe/trunk/lib/Parse/ParseStmt.cpp > > Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=127507&r1=127506&r2=127507&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Mar 11 17:10:44 2011 > @@ -178,6 +178,9 @@ > "reference qualifiers on functions are a C++0x extension">, InGroup; > def ext_inline_namespace : ExtWarn< > "inline namespaces are a C++0x feature">, InGroup; > +def ext_generalized_initializer_lists : ExtWarn< > + "generalized initializer lists are a C++0x extension unsupported in Clang">, > + InGroup; > def err_argument_required_after_attribute : Error< > "argument required after attribute">; > def err_missing_param : Error<"expected parameter declarator">; > > Modified: cfe/trunk/lib/Parse/ParseStmt.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=127507&r1=127506&r2=127507&view=diff > ============================================================================== > --- cfe/trunk/lib/Parse/ParseStmt.cpp (original) > +++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Mar 11 17:10:44 2011 > @@ -1267,7 +1267,16 @@ > return StmtError(); > } > > - R = ParseExpression(); > + // FIXME: This is a hack to allow something like C++0x's generalized > + // initializer lists, but only enough of this feature to allow Clang to > + // parse libstdc++ 4.5's headers. > + if (Tok.is(tok::l_brace) && getLang().CPlusPlus) { > + R = ParseInitializer(); > + if (R.isUsable() && !getLang().CPlusPlus0x) > + Diag(R.get()->getLocStart(), diag::ext_generalized_initializer_lists) > + << R.get()->getSourceRange(); > + } else > + R = ParseExpression(); > if (R.isInvalid()) { // Skip to the semicolon, but don't consume it. > SkipUntil(tok::semi, false, true); > return StmtError(); > > Added: cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp?rev=127507&view=auto > ============================================================================== > --- cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp (added) > +++ cfe/trunk/test/SemaCXX/cxx0x-return-init-list.cpp Fri Mar 11 17:10:44 2011 > @@ -0,0 +1,18 @@ > +// RUN: %clang_cc1 -fsyntax-only -verify %s > + > +// This test checks for a teeny tiny subset of the functionality in > +// the C++0x generalized initializer lists feature, which happens to > +// be used in libstdc++ 4.5. We accept only this syntax so that Clang > +// can handle the libstdc++ 4.5 headers. > + > +int test0(int i) { > + return { i }; // expected-warning{{generalized initializer lists are a C++0x extension unsupported in Clang}} > +} > + > +template > +T test1(U u) { > + return { u }; // expected-warning{{generalized initializer lists are a C++0x extension unsupported in Clang}} > +} > + > +template int test1(char); > +template long test1(int); > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From csdavec at swan.ac.uk Mon Mar 14 10:01:16 2011 From: csdavec at swan.ac.uk (David Chisnall) Date: Mon, 14 Mar 2011 15:01:16 -0000 Subject: [cfe-commits] r127580 - /cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Message-ID: <20110314150116.715802A6C12C@llvm.org> Author: theraven Date: Mon Mar 14 10:01:16 2011 New Revision: 127580 URL: http://llvm.org/viewvc/llvm-project?rev=127580&view=rev Log: Fix incorrect linkage specifiers for selectors. Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=127580&r1=127579&r2=127580&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Mar 14 10:01:16 2011 @@ -1720,7 +1720,7 @@ llvm::Constant *Idxs[] = {Zeros[0], llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]}; llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy, - true, llvm::GlobalValue::LinkOnceODRLinkage, + true, llvm::GlobalValue::InternalLinkage, llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2), MangleSelectorTypes(".objc_sel_ptr"+iter->first.first+"."+ iter->first.second)); @@ -1739,7 +1739,7 @@ llvm::Constant *Idxs[] = {Zeros[0], llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]}; llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy, - true, llvm::GlobalValue::LinkOnceODRLinkage, + true, llvm::GlobalValue::InternalLinkage, llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2), MangleSelectorTypes(std::string(".objc_sel_ptr")+iter->getKey().str())); // If selectors are defined as an opaque type, cast the pointer to this From dgregor at apple.com Mon Mar 14 10:07:10 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 08:07:10 -0700 Subject: [cfe-commits] r127580 - /cfe/trunk/lib/CodeGen/CGObjCGNU.cpp In-Reply-To: <20110314150116.715802A6C12C@llvm.org> References: <20110314150116.715802A6C12C@llvm.org> Message-ID: <24F2BA41-0ED6-42AC-9A22-B43362939709@apple.com> Bill, please merge this to the 2.9 release branch. Thanks! - Doug On Mar 14, 2011, at 8:01 AM, David Chisnall wrote: > Author: theraven > Date: Mon Mar 14 10:01:16 2011 > New Revision: 127580 > > URL: http://llvm.org/viewvc/llvm-project?rev=127580&view=rev > Log: > Fix incorrect linkage specifiers for selectors. > > > Modified: > cfe/trunk/lib/CodeGen/CGObjCGNU.cpp > > Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=127580&r1=127579&r2=127580&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Mar 14 10:01:16 2011 > @@ -1720,7 +1720,7 @@ > llvm::Constant *Idxs[] = {Zeros[0], > llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]}; > llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy, > - true, llvm::GlobalValue::LinkOnceODRLinkage, > + true, llvm::GlobalValue::InternalLinkage, > llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2), > MangleSelectorTypes(".objc_sel_ptr"+iter->first.first+"."+ > iter->first.second)); > @@ -1739,7 +1739,7 @@ > llvm::Constant *Idxs[] = {Zeros[0], > llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]}; > llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy, > - true, llvm::GlobalValue::LinkOnceODRLinkage, > + true, llvm::GlobalValue::InternalLinkage, > llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2), > MangleSelectorTypes(std::string(".objc_sel_ptr")+iter->getKey().str())); > // If selectors are defined as an opaque type, cast the pointer to this > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From dgregor at apple.com Mon Mar 14 10:30:54 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 08:30:54 -0700 Subject: [cfe-commits] r124753 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGenCXX/debug-info-template.cpp In-Reply-To: <20110202213849.B25D02A6C12C@llvm.org> References: <20110202213849.B25D02A6C12C@llvm.org> Message-ID: On Feb 2, 2011, at 1:38 PM, Devang Patel wrote: > Author: dpatel > Date: Wed Feb 2 15:38:49 2011 > New Revision: 124753 > > URL: http://llvm.org/viewvc/llvm-project?rev=124753&view=rev > Log: > Emit debug info for template type parameters. > > Modified: > cfe/trunk/lib/CodeGen/CGDebugInfo.cpp > cfe/trunk/test/CodeGenCXX/debug-info-template.cpp > > Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=124753&r1=124752&r2=124753&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Feb 2 15:38:49 2011 > @@ -953,9 +953,23 @@ > } > > CollectRecordFields(RD, Unit, EltTys); > + llvm::SmallVector TemplateParams; > if (CXXDecl) { > CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); > CollectCXXFriends(CXXDecl, Unit, EltTys, FwdDecl); > + if (ClassTemplateSpecializationDecl *TSpecial > + = dyn_cast(RD)) { > + const TemplateArgumentList &TAL = TSpecial->getTemplateArgs(); > + for (unsigned i = 0, e = TAL.size(); i != e; ++i) { > + const TemplateArgument &TA = TAL[i]; > + if (TA.getKind() == TemplateArgument::Type) { > + llvm::DIType TTy = getOrCreateType(TA.getAsType(), Unit); > + llvm::DITemplateTypeParameter TTP = > + DBuilder.CreateTemplateTypeParameter(TheCU, TTy.getName(), TTy); > + TemplateParams.push_back(TTP); > + } > + } > + } This is not going to work for class template partial specializations, and it doesn't give access to the parameter name itself. A better approach would be to determine the class template or class template partial specialization from which this class was instantiated/specialized (using ClassTemplateSpecializationDecl::getSpecializedTemplateOrPartial) and extracting it's TemplateParameterList. The template parameter list has the template parameters in order, including their names. For the template arguments that correspond to the template parameters, use ClassTemplateSpecializationDecl::getTemplateInstantiationArgs(). There's a 1-1 mapping between the template parameters and the instantiation arguments, so you can index the resulting TemplateArgumentList the same way you index the TemplateParameterList (to retrieve the substituted values). I suggest abstracting the generation of the template parameter information in some subroutine that takes a TemplateParameterList and a TemplateArgumentList, since you'll also want it for function template instantiations/specializations. - Doug From dgregor at apple.com Mon Mar 14 10:33:44 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 15:33:44 -0000 Subject: [cfe-commits] r127582 - /cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Message-ID: <20110314153344.A0E9A2A6C12C@llvm.org> Author: dgregor Date: Mon Mar 14 10:33:44 2011 New Revision: 127582 URL: http://llvm.org/viewvc/llvm-project?rev=127582&view=rev Log: Add include paths for Gentoo Linux, from Marcin Miros?aw! Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=127582&r1=127581&r2=127582&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original) +++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Mon Mar 14 10:33:44 2011 @@ -741,7 +741,19 @@ "i686-pc-linux-gnu", "", "", triple); AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", "x86_64-unknown-linux-gnu", "", "", triple); - // Gentoo x86 2010.0 stable + // Gentoo x86 gcc 4.5.2 + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4", + "i686-pc-linux-gnu", "", "", triple); + // Gentoo x86 gcc 4.4.5 + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4", + "i686-pc-linux-gnu", "", "", triple); + // Gentoo x86 gcc 4.4.4 + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/i686-pc-linux-gnu/4.4.4/include/g++-v4", + "i686-pc-linux-gnu", "", "", triple); + // Gentoo x86 2010.0 stable AddGnuCPlusPlusIncludePaths( "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4", "i686-pc-linux-gnu", "", "", triple); @@ -757,7 +769,15 @@ AddGnuCPlusPlusIncludePaths( "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", "i686-pc-linux-gnu", "", "", triple); + // Gentoo x86 llvm-gcc trunk + AddGnuCPlusPlusIncludePaths( + "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", + "i686-pc-linux-gnu", "", "", triple); + // Gentoo amd64 gcc 4.5.2 + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4", + "x86_64-pc-linux-gnu", "32", "", triple); // Gentoo amd64 gcc 4.4.5 AddGnuCPlusPlusIncludePaths( "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4", @@ -777,7 +797,7 @@ // Gentoo amd64 stable AddGnuCPlusPlusIncludePaths( "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", - "i686-pc-linux-gnu", "", "", triple); + "x86_64-pc-linux-gnu", "", "", triple); // Gentoo amd64 llvm-gcc trunk AddGnuCPlusPlusIncludePaths( From dgregor at apple.com Mon Mar 14 10:37:49 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 08:37:49 -0700 Subject: [cfe-commits] [PATCH] Ask for add support gcc-4.4.5 in gentoo In-Reply-To: <4D75F805.1020408@mejor.pl> References: <4D70E343.5090506@mejor.pl> <945B7297-8BEF-4114-89C2-1CFBB9B0D7AD@apple.com> <4D75F805.1020408@mejor.pl> Message-ID: <90D5E1FB-7949-4DD4-9A6E-FDCF20D02645@apple.com> On Mar 8, 2011, at 1:33 AM, Marcin Miros?aw wrote: > W dniu 06.03.2011 20:27, Douglas Gregor pisze: >> Can you submit a patch to cfe-commits with the change you need? > > Hello! > Here it is. This patch add paths to gcc which is available in Gentoo. > I hope it fix also two issues: > - missing declaration of include path for llvm-gcc at x86 arch > - compiler name in delcaration for gcc 4.1.2 at amd64 Committed in r127582, thanks! - Doug From dgregor at apple.com Mon Mar 14 10:39:50 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 15:39:50 -0000 Subject: [cfe-commits] r127583 - /cfe/trunk/lib/Driver/ToolChains.cpp Message-ID: <20110314153950.5B4842A6C12C@llvm.org> Author: dgregor Date: Mon Mar 14 10:39:50 2011 New Revision: 127583 URL: http://llvm.org/viewvc/llvm-project?rev=127583&view=rev Log: Support Ubuntu hardy and intrepid, from Thomas Gamper! Modified: cfe/trunk/lib/Driver/ToolChains.cpp Modified: cfe/trunk/lib/Driver/ToolChains.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=127583&r1=127582&r2=127583&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Mar 14 10:39:50 2011 @@ -1280,6 +1280,8 @@ Fedora13, Fedora14, OpenSuse11_3, + UbuntuHardy, + UbuntuIntrepid, UbuntuJaunty, UbuntuKarmic, UbuntuLucid, @@ -1300,7 +1302,8 @@ } static bool IsUbuntu(enum LinuxDistro Distro) { - return Distro == UbuntuLucid || Distro == UbuntuMaverick || + return Distro == UbuntuHardy || Distro == UbuntuIntrepid || + Distro == UbuntuLucid || Distro == UbuntuMaverick || Distro == UbuntuJaunty || Distro == UbuntuKarmic; } @@ -1329,6 +1332,10 @@ llvm::SmallVector Lines; Data.split(Lines, "\n"); for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) { + if (Lines[i] == "DISTRIB_CODENAME=hardy") + return UbuntuHardy; + if (Lines[i] == "DISTRIB_CODENAME=intrepid") + return UbuntuIntrepid; if (Lines[i] == "DISTRIB_CODENAME=maverick") return UbuntuMaverick; else if (Lines[i] == "DISTRIB_CODENAME=lucid") @@ -1444,7 +1451,8 @@ const char* GccVersions[] = {"4.5.2", "4.5.1", "4.5", "4.4.5", "4.4.4", "4.4.3", "4.4", "4.3.4", "4.3.3", "4.3.2", - "4.3"}; + "4.3", "4.2.4", "4.2.3", "4.2.2", "4.2.1", + "4.2"}; std::string Base = ""; for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) { std::string Suffix = GccTriple + "/" + GccVersions[i]; From dgregor at apple.com Mon Mar 14 10:44:00 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 08:44:00 -0700 Subject: [cfe-commits] [PATCH]Support Ubuntu Hardy & Intrepid In-Reply-To: <20110311182712.17573wkv24btqvlc@webmail.tuwien.ac.at> References: <20110311182712.17573wkv24btqvlc@webmail.tuwien.ac.at> Message-ID: <119294DA-C770-4F48-B28A-7E5AFF25EA39@apple.com> Committed in r127583, thanks! - Doug On Mar 11, 2011, at 9:27 AM, Thomas Gamper wrote: > > Hi! > > Today I did a bootstrap of clang' release2_9 branch on my Ubuntu 8.04 AMD64, I got working executables but clang was unable to find crtbeginS.o and friends during linking. Attached patch got clang working on my system, no hacks, just extensions to the existing infrastructure. > > Regards, > Thomas Gamper > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From fjahanian at apple.com Mon Mar 14 11:07:00 2011 From: fjahanian at apple.com (Fariborz Jahanian) Date: Mon, 14 Mar 2011 16:07:00 -0000 Subject: [cfe-commits] r127585 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp test/SemaObjC/block-type-safety.m Message-ID: <20110314160700.651852A6C12C@llvm.org> Author: fjahanian Date: Mon Mar 14 11:07:00 2011 New Revision: 127585 URL: http://llvm.org/viewvc/llvm-project?rev=127585&view=rev Log: Block return type of the initialized must be be more speciaclized than that of the initializer, when matching protocol qualifier list. // rdar:// 9118343. Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/test/SemaObjC/block-type-safety.m Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=127585&r1=127584&r2=127585&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Mar 14 11:07:00 2011 @@ -1333,7 +1333,8 @@ const ObjCObjectType *RHS); bool canAssignObjCInterfacesInBlockPointer( const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT); + const ObjCObjectPointerType *RHSOPT, + bool BlockReturnType); bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT); @@ -1341,7 +1342,7 @@ // Functions for calculating composite types QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, - bool Unqualified = false); + bool Unqualified = false, bool BlockReturnType = false); QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified = false); QualType mergeFunctionArgumentTypes(QualType, QualType, Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=127585&r1=127584&r2=127585&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Mon Mar 14 11:07:00 2011 @@ -4838,7 +4838,8 @@ /// not OK. For the return type, the opposite is not OK. bool ASTContext::canAssignObjCInterfacesInBlockPointer( const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT) { + const ObjCObjectPointerType *RHSOPT, + bool BlockReturnType) { if (RHSOPT->isObjCBuiltinType() || LHSOPT->isObjCIdType()) return true; @@ -4856,9 +4857,9 @@ if (LHS && RHS) { // We have 2 user-defined types. if (LHS != RHS) { if (LHS->getDecl()->isSuperClassOf(RHS->getDecl())) - return false; + return BlockReturnType; if (RHS->getDecl()->isSuperClassOf(LHS->getDecl())) - return true; + return !BlockReturnType; } else return true; @@ -5082,7 +5083,7 @@ bool UnqualifiedResult = Unqualified; if (!UnqualifiedResult) UnqualifiedResult = (!RHS.hasQualifiers() && LHS.hasQualifiers()); - retType = mergeTypes(RHS, LHS, true, UnqualifiedResult); + retType = mergeTypes(LHS, RHS, true, UnqualifiedResult, true); } else retType = mergeTypes(lbase->getResultType(), rbase->getResultType(), false, @@ -5222,7 +5223,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, bool OfBlockPointer, - bool Unqualified) { + bool Unqualified, bool BlockReturnType) { // C++ [expr]: If an expression initially has the type "reference to T", the // type is adjusted to "T" prior to any further analysis, the expression // designates the object or function denoted by the reference, and the @@ -5456,7 +5457,8 @@ if (OfBlockPointer) { if (canAssignObjCInterfacesInBlockPointer( LHS->getAs(), - RHS->getAs())) + RHS->getAs(), + BlockReturnType)) return LHS; return QualType(); } Modified: cfe/trunk/test/SemaObjC/block-type-safety.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-type-safety.m?rev=127585&r1=127584&r2=127585&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/block-type-safety.m (original) +++ cfe/trunk/test/SemaObjC/block-type-safety.m Mon Mar 14 11:07:00 2011 @@ -121,3 +121,20 @@ return 0; } +// rdar:// 9118343 + + at protocol NSCopying @end + + at interface NSAllArray + at end + + at interface NSAllArray (FooConformance) + at end + +int test5() { + NSAllArray *(^block)(id); + id (^genericBlock)(id); + genericBlock = block; + return 0; +} + From dgregor at apple.com Mon Mar 14 11:13:32 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 16:13:32 -0000 Subject: [cfe-commits] r127586 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/writable-strings-deprecated.cpp Message-ID: <20110314161332.591072A6C12C@llvm.org> Author: dgregor Date: Mon Mar 14 11:13:32 2011 New Revision: 127586 URL: http://llvm.org/viewvc/llvm-project?rev=127586&view=rev Log: -fwritable-strings should silence warnings about the deprecated string -literal to char* conversion. Make it so. Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/test/SemaCXX/writable-strings-deprecated.cpp Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127586&r1=127585&r2=127586&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Mar 14 11:13:32 2011 @@ -2273,7 +2273,8 @@ ImpCastExprToType(From, ToType.getNonLValueExprType(Context), CK_NoOp, VK); - if (SCS.DeprecatedStringLiteralToCharPtr) + if (SCS.DeprecatedStringLiteralToCharPtr && + !getLangOptions().WritableStrings) Diag(From->getLocStart(), diag::warn_deprecated_string_literal_conversion) << ToType.getNonReferenceType(); Modified: cfe/trunk/test/SemaCXX/writable-strings-deprecated.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/writable-strings-deprecated.cpp?rev=127586&r1=127585&r2=127586&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/writable-strings-deprecated.cpp (original) +++ cfe/trunk/test/SemaCXX/writable-strings-deprecated.cpp Mon Mar 14 11:13:32 2011 @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -Wno-deprecated-writable-strings -verify %s +// RUN: %clang_cc1 -fsyntax-only -fwritable-strings -verify %s // rdar://8827606 char *fun(void) From dgregor at apple.com Mon Mar 14 12:28:24 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 10:28:24 -0700 Subject: [cfe-commits] PATCH: Add support for C++ namespace-aware typo correcting In-Reply-To: References: <7E51FDB4-EF54-4C46-9BCD-A886845955E2@apple.com> Message-ID: On Mar 9, 2011, at 11:35 AM, Kaelyn Uhrain wrote: > I just finished up a new version of my patch earlier this week, which no longer uses the RecursiveASTVisitor (per chandlerc's suggestion). I've rebased the patch against the current SVN and have attached it for you to test. With the new version only the FixIt/typo.cpp and SemaObjC/synth-provisional-ivars.m tests are failing, and for those two I'm not entirely sure which parts of the behavior are correct/acceptable and which might be a bug in my changes. Definitely looking better! I don't have the time at the moment to re-run my performance tests, but I will comment on some aspects of your patch... Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp (revision 127346) +++ lib/Sema/SemaDecl.cpp (working copy) @@ -264,24 +264,24 @@ if (DeclarationName Corrected = CorrectTypo(Lookup, S, SS, 0, 0, CTC_Type)) { if (NamedDecl *Result = Lookup.getAsSingle()) { + std::string Suggestion = Result->getQualifiedNameAsString(); + // FIXME: Silly formatting rules make us have to quote strings ourselves + // to keep quoting consistent between strings and IdentiferInfos. + std::string QuotedSug = "'" + Suggestion + "'"; getQualifiedNameAsString() isn't necessarily what we want here, because it always produces the fully-qualified name. That means it will overqualify when we're already in a namespace, e.g., namespace N { namespace inner { class vector { /* ... */ }; } void f() { vector v; // will suggest N::inner::vector, when inner::vector would suffice } } A similar issue is inline namespaces. For example, if one has: namespace std { inline namespace __1 { class vector { /* ... */ }; } } void f() { vector v; // will suggest std::__1::vector, when std::vector would suffice } It would be preferable to add some kind of function that computes the minimum qualification needed to get from the specified context (e.g., CurContext, for unqualified name lookup) to the entity, since that's what the user would want to type. Incidentally, when testing this, I actually used template class vector { /* ... */ }; in my examples, and got incorrect Fix-Its and diagnostics: t.cpp:7:4: error: no template named 'vector'; did you mean 'vector'? vector v; // will suggest ... ^~~~~~ vector +void TypoCorrectionConsumer::CheckEditDistanceAndStore( + llvm::StringRef Name, DeclSpecPair DSPair, unsigned DistOffset) { + using namespace std; + // Compute an upper bound on the allowable edit distance, so that the // edit-distance algorithm can short-circuit. unsigned UpperBound = min(unsigned((Typo.size() + 2) / 3), BestEditDistance); @@ -2872,7 +2884,7 @@ // Compute the edit distance between the typo and the name of this // entity. If this edit distance is not worse than the best edit // distance we've seen so far, add it to the list of results. - unsigned ED = Typo.edit_distance(Name, true, UpperBound); + unsigned ED = Typo.edit_distance(Name, true, UpperBound) + DistOffset; if (ED == 0) return; The DistOffset should be added into the UpperBound, so that the edit_distance implementation can abort early if the resulting edit distance is going to be too high. + // Only consider entities that haven't already been found. + DeclContext *NDContext = ND->getDeclContext()->getPrimaryContext(); + iterator N = BestResults.find(ShortName); + if (N != BestResults.end()) { + for (DeclSpecList::iterator D = N->second.begin(), DEnd = N->second.end(); + D != DEnd; ++D) { + if (NDContext == D->first) return; + } + } Should we use a SmallPtrSet for this, so that we get faster lookup if the BestResults set happens to get large? +void ScanNamespaceForCorrections(DeclContext *DC, + TypoCorrectionConsumer &Consumer, + unsigned DistanceOffset, bool DownOnly) { + + if (DistanceOffset > Consumer.getBestEditDistance()) + return; + + DeclContext *ParentDC = DC->getLookupParent(); + + for (DC = DC->getPrimaryContext(); DC != NULL; DC = DC->getNextContext()) { + for (DeclContext::decl_iterator D = DC->decls_begin(), + DEnd = DC->decls_end(); D != DEnd; ++D) { + NamedDecl *ChildDecl = dyn_cast(D->getCanonicalDecl()); + NamespaceDecl *ChildND = dyn_cast_or_null(*D); + if (ChildDecl) + Consumer.FoundDecl(ChildDecl, NULL, false, DistanceOffset); + if (ChildND) + ScanNamespaceForCorrections(ChildND, Consumer, + DistanceOffset + 1, true); + } + } + + if (DownOnly || !ParentDC) return; + + ScanNamespaceForCorrections(ParentDC, Consumer, DistanceOffset, false); +} This will end up walking most of the translation unit. It's better than the RecursiveASTVisitor, since it won't walk into function bodies or the definitions of classes, but there's still some redundant work. I'll make a concrete suggestion at the end of this reply. + for (DeclSpecList::iterator DSI = I->second.begin(), + DSIEnd = I->second.end(); + DSI != DSIEnd; /* Increment in loop, */) { + // Perform name lookup on this name. + IdentifierInfo *Name = &Context.Idents.get(I->getKey()); + LookupPotentialTypoResult(*this, Res, Name, S, SS, + DSI->second ? DSI->first : MemberContext, + EnteringContext, CTC); Using DSI->first as the member context isn't quite what we want, because we don't want to turn an unqualified lookup into a member lookup. Rather, we want to turn an unqualified lookup into a qualified lookup. So, I suggest that you form a new nested-name-specifier (e.g., a new "SS") that provides the minimum qualification needed to get from the current context over to the result we found (this is related to my first comment). If that works, you could write the results back to SS, so that our caller can go ahead and use that nested-name-specifier for the rest of semantic analysis as if the user had written it explicitly. (Naturally, callers would need some updating to understand that this could happen). The key here is that, on successfully returning an alternative result from typo correction, the name-lookup state looks *exactly* as it would had the user typed the right thing. Incidentally, I think this is the source of the SemaObjC/synth-provisional-ivars.m failure, since we're allowing lookup into an Objective-C class even though one can never qualify the name of an entity in an Objective-C class. We shouldn't ever do qualifier checks in (Objective-)C, although it's happening here. Back to my comment about repeated work. The typo correction code for unqualified lookup makes a pass over all of the identifiers known in the translation unit, which includes all of the names of entities buried in namespaces. So, when we also go walk the AST to find all of the namespaces (and the members of those namespaces), so we end up hitting many of those identifiers a second time, and traversing most of the AST in the process (which is more expensive than just looking at the identifiers). So, here's a concrete recommendation: 1) Don't walk the namespaces at all; let the check against all of the identifiers in the translation unit winnow the list down to the best candidates based on name alone. We don't know which of these candidates is visible, or how to get there. 2) When we're performing lookup for each candidate (e.g., the calls to LookupPotentialTypoResult), first try unqualified lookup. If that fails, save the candidate in a separate "try qualified name lookup" set. 3) If none of the candidates can be found by unqualified lookup, start looking in each of the namespaces we know about to see if qualified name lookup would work to find each of the candidates. You'll likely need a side structure containing all of the (unique, canonicalized) NamespaceDecls in the translation unit to make this efficient. Implemented this way, there's no additional penalty for typo correction of visible names. Moreover, we skip the AST walk entirely, and only perform targeted lookups for names that we know exist (because they were in the identifier table). This also permits a few more optimizations: - We could (roughly) order namespaces based on their depth, so that we'll tend to visit the more top-level (and, therefore, more likely to have short qualifiers) namespaces first. If the qualifier for a namespace would be longer than the shortest qualifier we've found so far, we don't have to look in that namespace. - For a given namespace, we could look for all of the candidates in that namespace at the same time, improving locality (which is particularly import when those lookups hit the disk in the PCH case). Sorry for the long e-mail; you've got me thinking a lot about this :) - Doug From rjmccall at apple.com Mon Mar 14 12:36:15 2011 From: rjmccall at apple.com (John McCall) Date: Mon, 14 Mar 2011 10:36:15 -0700 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing In-Reply-To: References: Message-ID: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> On Mar 13, 2011, at 11:07 PM, Francois Pichet wrote: > This patch implements "Late template parsing" in Microsoft mode. > It solves the problem of Microsoft allowing names not yet declared in > template code. I haven't looked at the patch yet, but this defintely needs to be enabled by its own -cc1 language option; that option should then be enabled by windows targets, rather than tying this to -fms-extensions. John. From dgregor at apple.com Mon Mar 14 12:46:41 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 10:46:41 -0700 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing In-Reply-To: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> References: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> Message-ID: <045D8E3B-670A-4306-B5A1-EE9343BC5343@apple.com> On Mar 14, 2011, at 10:36 AM, John McCall wrote: > On Mar 13, 2011, at 11:07 PM, Francois Pichet wrote: >> This patch implements "Late template parsing" in Microsoft mode. >> It solves the problem of Microsoft allowing names not yet declared in >> template code. > > I haven't looked at the patch yet, but this defintely needs to be enabled > by its own -cc1 language option; that option should then be enabled by > windows targets, rather than tying this to -fms-extensions. Yes. -fdelayed-template-parsing seems a good name. - Doug From rafael.espindola at gmail.com Mon Mar 14 12:55:00 2011 From: rafael.espindola at gmail.com (Rafael Espindola) Date: Mon, 14 Mar 2011 17:55:00 -0000 Subject: [cfe-commits] r127594 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c Message-ID: <20110314175500.819F62A6C12C@llvm.org> Author: rafael Date: Mon Mar 14 12:55:00 2011 New Revision: 127594 URL: http://llvm.org/viewvc/llvm-project?rev=127594&view=rev Log: Fix link of libxul with LTO and the linker in xcode4. It is not clear if this is working around a bug in ld or if the new linker has a reasonable reason for wanting the string constant to be linker visible. Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/test/CodeGen/darwin-string-literals.c Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127594&r1=127593&r2=127594&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Mar 14 12:55:00 2011 @@ -1669,7 +1669,10 @@ // does make plain ascii ones writable. isConstant = true; } else { - Linkage = llvm::GlobalValue::PrivateLinkage; + // FIXME: With OS X ld 123.2 (xcode 4) and LTO we would get a linker error + // when using private linkage. It is not clear if this is a bug in ld + // or a reasonable new restriction. + Linkage = llvm::GlobalValue::InternalLinkage; isConstant = !Features.WritableStrings; } Modified: cfe/trunk/test/CodeGen/darwin-string-literals.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/darwin-string-literals.c?rev=127594&r1=127593&r2=127594&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/darwin-string-literals.c (original) +++ cfe/trunk/test/CodeGen/darwin-string-literals.c Mon Mar 14 12:55:00 2011 @@ -1,13 +1,13 @@ // RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix LSB %s // CHECK-LSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" -// CHECK-LSB: @.str1 = private unnamed_addr constant [8 x i8] c"string1\00" +// CHECK-LSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" // CHECK-LSB: @.str2 = internal unnamed_addr constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", align 2 // RUN: %clang_cc1 -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s // CHECK-MSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" -// CHECK-MSB: @.str1 = private unnamed_addr constant [8 x i8] c"string1\00" +// CHECK-MSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" // CHECK-MSB: @.str2 = internal unnamed_addr constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", align 2 const char *g0 = "string0"; From sebastian.redl at getdesigned.at Mon Mar 14 13:08:30 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 18:08:30 -0000 Subject: [cfe-commits] r127596 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaType.cpp test/CXX/except/except.spec/p15.cpp Message-ID: <20110314180830.7DC802A6C12D@llvm.org> Author: cornedbee Date: Mon Mar 14 13:08:30 2011 New Revision: 127596 URL: http://llvm.org/viewvc/llvm-project?rev=127596&view=rev Log: Make deallocation functions implicitly noexcept in C++0x. Added: cfe/trunk/test/CXX/except/except.spec/p15.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127596&r1=127595&r2=127596&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 14 13:08:30 2011 @@ -3733,7 +3733,7 @@ } bool isStatic = SC == SC_Static; - + // [class.free]p1: // Any allocation function for a class T is a static member // (even if not explicitly declared static). @@ -3746,7 +3746,7 @@ if (Name.getCXXOverloadedOperator() == OO_Delete || Name.getCXXOverloadedOperator() == OO_Array_Delete) isStatic = true; - + // This is a C++ method declaration. NewFD = CXXMethodDecl::Create(Context, cast(DC), D.getSourceRange().getBegin(), Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127596&r1=127595&r2=127596&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Mar 14 13:08:30 2011 @@ -1404,11 +1404,18 @@ /// DeclareGlobalNewDelete - Declare the global forms of operator new and /// delete. These are: /// @code +/// // C++03: /// void* operator new(std::size_t) throw(std::bad_alloc); /// void* operator new[](std::size_t) throw(std::bad_alloc); /// void operator delete(void *) throw(); /// void operator delete[](void *) throw(); +/// // C++0x: +/// void* operator new(std::size_t); +/// void* operator new[](std::size_t); +/// void operator delete(void *); +/// void operator delete[](void *); /// @endcode +/// C++0x operator delete is implicitly noexcept. /// Note that the placement and nothrow forms of new are *not* implicitly /// declared. Their use requires including \. void Sema::DeclareGlobalNewDelete() { @@ -1420,10 +1427,16 @@ // implicitly declared in global scope in each translation unit of a // program // + // C++03: // void* operator new(std::size_t) throw(std::bad_alloc); // void* operator new[](std::size_t) throw(std::bad_alloc); // void operator delete(void*) throw(); // void operator delete[](void*) throw(); + // C++0x: + // void* operator new(std::size_t); + // void* operator new[](std::size_t); + // void operator delete(void*); + // void operator delete[](void*); // // These implicit declarations introduce only the function names operator // new, operator new[], operator delete, operator delete[]. @@ -1432,7 +1445,9 @@ // "std" or "bad_alloc" as necessary to form the exception specification. // However, we do not make these implicit declarations visible to name // lookup. - if (!StdBadAlloc) { + // Note that the C++0x versions of operator delete are deallocation functions, + // and thus are implicitly noexcept. + if (!StdBadAlloc && !getLangOptions().CPlusPlus0x) { // The "std::bad_alloc" class has not yet been declared, so build it // implicitly. StdBadAlloc = CXXRecordDecl::Create(Context, TTK_Class, @@ -1495,18 +1510,21 @@ bool HasBadAllocExceptionSpec = (Name.getCXXOverloadedOperator() == OO_New || Name.getCXXOverloadedOperator() == OO_Array_New); - if (HasBadAllocExceptionSpec) { + if (HasBadAllocExceptionSpec && !getLangOptions().CPlusPlus0x) { assert(StdBadAlloc && "Must have std::bad_alloc declared"); BadAllocType = Context.getTypeDeclType(getStdBadAlloc()); } FunctionProtoType::ExtProtoInfo EPI; if (HasBadAllocExceptionSpec) { - EPI.ExceptionSpecType = EST_Dynamic; - EPI.NumExceptions = 1; - EPI.Exceptions = &BadAllocType; + if (!getLangOptions().CPlusPlus0x) { + EPI.ExceptionSpecType = EST_Dynamic; + EPI.NumExceptions = 1; + EPI.Exceptions = &BadAllocType; + } } else { - EPI.ExceptionSpecType = EST_DynamicNone; + EPI.ExceptionSpecType = getLangOptions().CPlusPlus0x ? + EST_BasicNoexcept : EST_DynamicNone; } QualType FnType = Context.getFunctionType(Return, &Argument, 1, EPI); Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127596&r1=127595&r2=127596&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Mar 14 13:08:30 2011 @@ -1494,9 +1494,19 @@ TypeProcessingState state(*this, D); + // In C++0x, deallocation functions (normal and array operator delete) + // are implicitly noexcept. + bool ImplicitlyNoexcept = false; + switch (D.getName().getKind()) { - case UnqualifiedId::IK_Identifier: case UnqualifiedId::IK_OperatorFunctionId: + if (getLangOptions().CPlusPlus0x) { + OverloadedOperatorKind OO = D.getName().OperatorFunctionId.Operator; + if (OO == OO_Delete || OO == OO_Array_Delete) + ImplicitlyNoexcept = true; + } + // Intentional fall-through. + case UnqualifiedId::IK_Identifier: case UnqualifiedId::IK_LiteralOperatorId: case UnqualifiedId::IK_TemplateId: T = ConvertDeclSpecToType(*this, state); @@ -1917,6 +1927,10 @@ else EPI.NoexceptExpr = NoexceptExpr; } + } else if (FTI.getExceptionSpecType() == EST_None && + ImplicitlyNoexcept && chunkIndex == 0) { + // Only the outermost chunk is marked noexcept, of course. + EPI.ExceptionSpecType = EST_BasicNoexcept; } T = Context.getFunctionType(T, ArgTys.data(), ArgTys.size(), EPI); Added: cfe/trunk/test/CXX/except/except.spec/p15.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p15.cpp?rev=127596&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p15.cpp (added) +++ cfe/trunk/test/CXX/except/except.spec/p15.cpp Mon Mar 14 13:08:30 2011 @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -std=c++0x -fexceptions -fcxx-exceptions -fsyntax-only -verify %s + +// Deallocation functions are implicitly noexcept. +// Thus, explicit specs aren't allowed to conflict. + +void f() { + // Force implicit declaration of delete. + delete new int; + delete[] new int[1]; +} + +void operator delete(void*) noexcept; +void operator delete[](void*) noexcept; + +// Same goes for explicit declarations. +void operator delete(void*, float); +void operator delete(void*, float) noexcept; + +void operator delete[](void*, float); +void operator delete[](void*, float) noexcept; + +// But explicit specs stay. +void operator delete(void*, double) throw(int); // expected-note {{previous}} +void operator delete(void*, double) noexcept; // expected-error {{does not match}} From clattner at apple.com Mon Mar 14 13:37:43 2011 From: clattner at apple.com (Chris Lattner) Date: Mon, 14 Mar 2011 11:37:43 -0700 Subject: [cfe-commits] r127594 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c In-Reply-To: <20110314175500.819F62A6C12C@llvm.org> References: <20110314175500.819F62A6C12C@llvm.org> Message-ID: <0637D520-A391-4215-A854-D1E0C89D0FC0@apple.com> On Mar 14, 2011, at 10:55 AM, Rafael Espindola wrote: > Author: rafael > Date: Mon Mar 14 12:55:00 2011 > New Revision: 127594 > > URL: http://llvm.org/viewvc/llvm-project?rev=127594&view=rev > Log: > Fix link of libxul with LTO and the linker in xcode4. It is not clear if this > is working around a bug in ld or if the new linker has a reasonable reason > for wanting the string constant to be linker visible. Hi Rafael, Private is probably the wrong answer, but I think that LinkerPrivate is the right answer. Does LinkerPrivate work for libxul? -Chris > > Modified: > cfe/trunk/lib/CodeGen/CodeGenModule.cpp > cfe/trunk/test/CodeGen/darwin-string-literals.c > > Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127594&r1=127593&r2=127594&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) > +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Mar 14 12:55:00 2011 > @@ -1669,7 +1669,10 @@ > // does make plain ascii ones writable. > isConstant = true; > } else { > - Linkage = llvm::GlobalValue::PrivateLinkage; > + // FIXME: With OS X ld 123.2 (xcode 4) and LTO we would get a linker error > + // when using private linkage. It is not clear if this is a bug in ld > + // or a reasonable new restriction. > + Linkage = llvm::GlobalValue::InternalLinkage; > isConstant = !Features.WritableStrings; > } > > > Modified: cfe/trunk/test/CodeGen/darwin-string-literals.c > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/darwin-string-literals.c?rev=127594&r1=127593&r2=127594&view=diff > ============================================================================== > --- cfe/trunk/test/CodeGen/darwin-string-literals.c (original) > +++ cfe/trunk/test/CodeGen/darwin-string-literals.c Mon Mar 14 12:55:00 2011 > @@ -1,13 +1,13 @@ > // RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix LSB %s > > // CHECK-LSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" > -// CHECK-LSB: @.str1 = private unnamed_addr constant [8 x i8] c"string1\00" > +// CHECK-LSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" > // CHECK-LSB: @.str2 = internal unnamed_addr constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", align 2 > > // RUN: %clang_cc1 -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s > > // CHECK-MSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" > -// CHECK-MSB: @.str1 = private unnamed_addr constant [8 x i8] c"string1\00" > +// CHECK-MSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" > // CHECK-MSB: @.str2 = internal unnamed_addr constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", align 2 > > const char *g0 = "string0"; > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From dgregor at apple.com Mon Mar 14 13:45:30 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 11:45:30 -0700 Subject: [cfe-commits] r127596 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaType.cpp test/CXX/except/except.spec/p15.cpp In-Reply-To: <20110314180830.7DC802A6C12D@llvm.org> References: <20110314180830.7DC802A6C12D@llvm.org> Message-ID: <20894183-43F6-4CC5-8D7E-8B57058560B1@apple.com> On Mar 14, 2011, at 11:08 AM, Sebastian Redl wrote: > Author: cornedbee > Date: Mon Mar 14 13:08:30 2011 > New Revision: 127596 > > URL: http://llvm.org/viewvc/llvm-project?rev=127596&view=rev > Log: > Make deallocation functions implicitly noexcept in C++0x. This is moderately terrifying, since throwing destructors (which were permitted in C++98/03) will now terminate(). We might want to put this under a flag, and even consider diagnosing the common cases (e.g., warn about a throw expression that occurs in a destructor). - Doug > Added: > cfe/trunk/test/CXX/except/except.spec/p15.cpp > Modified: > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaExprCXX.cpp > cfe/trunk/lib/Sema/SemaType.cpp > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127596&r1=127595&r2=127596&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 14 13:08:30 2011 > @@ -3733,7 +3733,7 @@ > } > > bool isStatic = SC == SC_Static; > - > + > // [class.free]p1: > // Any allocation function for a class T is a static member > // (even if not explicitly declared static). > @@ -3746,7 +3746,7 @@ > if (Name.getCXXOverloadedOperator() == OO_Delete || > Name.getCXXOverloadedOperator() == OO_Array_Delete) > isStatic = true; > - > + > // This is a C++ method declaration. > NewFD = CXXMethodDecl::Create(Context, cast(DC), > D.getSourceRange().getBegin(), > > Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127596&r1=127595&r2=127596&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) > +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Mar 14 13:08:30 2011 > @@ -1404,11 +1404,18 @@ > /// DeclareGlobalNewDelete - Declare the global forms of operator new and > /// delete. These are: > /// @code > +/// // C++03: > /// void* operator new(std::size_t) throw(std::bad_alloc); > /// void* operator new[](std::size_t) throw(std::bad_alloc); > /// void operator delete(void *) throw(); > /// void operator delete[](void *) throw(); > +/// // C++0x: > +/// void* operator new(std::size_t); > +/// void* operator new[](std::size_t); > +/// void operator delete(void *); > +/// void operator delete[](void *); > /// @endcode > +/// C++0x operator delete is implicitly noexcept. > /// Note that the placement and nothrow forms of new are *not* implicitly > /// declared. Their use requires including \. > void Sema::DeclareGlobalNewDelete() { > @@ -1420,10 +1427,16 @@ > // implicitly declared in global scope in each translation unit of a > // program > // > + // C++03: > // void* operator new(std::size_t) throw(std::bad_alloc); > // void* operator new[](std::size_t) throw(std::bad_alloc); > // void operator delete(void*) throw(); > // void operator delete[](void*) throw(); > + // C++0x: > + // void* operator new(std::size_t); > + // void* operator new[](std::size_t); > + // void operator delete(void*); > + // void operator delete[](void*); > // > // These implicit declarations introduce only the function names operator > // new, operator new[], operator delete, operator delete[]. > @@ -1432,7 +1445,9 @@ > // "std" or "bad_alloc" as necessary to form the exception specification. > // However, we do not make these implicit declarations visible to name > // lookup. > - if (!StdBadAlloc) { > + // Note that the C++0x versions of operator delete are deallocation functions, > + // and thus are implicitly noexcept. > + if (!StdBadAlloc && !getLangOptions().CPlusPlus0x) { > // The "std::bad_alloc" class has not yet been declared, so build it > // implicitly. > StdBadAlloc = CXXRecordDecl::Create(Context, TTK_Class, > @@ -1495,18 +1510,21 @@ > bool HasBadAllocExceptionSpec > = (Name.getCXXOverloadedOperator() == OO_New || > Name.getCXXOverloadedOperator() == OO_Array_New); > - if (HasBadAllocExceptionSpec) { > + if (HasBadAllocExceptionSpec && !getLangOptions().CPlusPlus0x) { > assert(StdBadAlloc && "Must have std::bad_alloc declared"); > BadAllocType = Context.getTypeDeclType(getStdBadAlloc()); > } > > FunctionProtoType::ExtProtoInfo EPI; > if (HasBadAllocExceptionSpec) { > - EPI.ExceptionSpecType = EST_Dynamic; > - EPI.NumExceptions = 1; > - EPI.Exceptions = &BadAllocType; > + if (!getLangOptions().CPlusPlus0x) { > + EPI.ExceptionSpecType = EST_Dynamic; > + EPI.NumExceptions = 1; > + EPI.Exceptions = &BadAllocType; > + } > } else { > - EPI.ExceptionSpecType = EST_DynamicNone; > + EPI.ExceptionSpecType = getLangOptions().CPlusPlus0x ? > + EST_BasicNoexcept : EST_DynamicNone; > } > > QualType FnType = Context.getFunctionType(Return, &Argument, 1, EPI); > > Modified: cfe/trunk/lib/Sema/SemaType.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127596&r1=127595&r2=127596&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaType.cpp (original) > +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Mar 14 13:08:30 2011 > @@ -1494,9 +1494,19 @@ > > TypeProcessingState state(*this, D); > > + // In C++0x, deallocation functions (normal and array operator delete) > + // are implicitly noexcept. > + bool ImplicitlyNoexcept = false; > + > switch (D.getName().getKind()) { > - case UnqualifiedId::IK_Identifier: > case UnqualifiedId::IK_OperatorFunctionId: > + if (getLangOptions().CPlusPlus0x) { > + OverloadedOperatorKind OO = D.getName().OperatorFunctionId.Operator; > + if (OO == OO_Delete || OO == OO_Array_Delete) > + ImplicitlyNoexcept = true; > + } > + // Intentional fall-through. > + case UnqualifiedId::IK_Identifier: > case UnqualifiedId::IK_LiteralOperatorId: > case UnqualifiedId::IK_TemplateId: > T = ConvertDeclSpecToType(*this, state); > @@ -1917,6 +1927,10 @@ > else > EPI.NoexceptExpr = NoexceptExpr; > } > + } else if (FTI.getExceptionSpecType() == EST_None && > + ImplicitlyNoexcept && chunkIndex == 0) { > + // Only the outermost chunk is marked noexcept, of course. > + EPI.ExceptionSpecType = EST_BasicNoexcept; > } > > T = Context.getFunctionType(T, ArgTys.data(), ArgTys.size(), EPI); > > Added: cfe/trunk/test/CXX/except/except.spec/p15.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p15.cpp?rev=127596&view=auto > ============================================================================== > --- cfe/trunk/test/CXX/except/except.spec/p15.cpp (added) > +++ cfe/trunk/test/CXX/except/except.spec/p15.cpp Mon Mar 14 13:08:30 2011 > @@ -0,0 +1,24 @@ > +// RUN: %clang_cc1 -std=c++0x -fexceptions -fcxx-exceptions -fsyntax-only -verify %s > + > +// Deallocation functions are implicitly noexcept. > +// Thus, explicit specs aren't allowed to conflict. > + > +void f() { > + // Force implicit declaration of delete. > + delete new int; > + delete[] new int[1]; > +} > + > +void operator delete(void*) noexcept; > +void operator delete[](void*) noexcept; > + > +// Same goes for explicit declarations. > +void operator delete(void*, float); > +void operator delete(void*, float) noexcept; > + > +void operator delete[](void*, float); > +void operator delete[](void*, float) noexcept; > + > +// But explicit specs stay. > +void operator delete(void*, double) throw(int); // expected-note {{previous}} > +void operator delete(void*, double) noexcept; // expected-error {{does not match}} > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From sebastian.redl at getdesigned.at Mon Mar 14 13:51:44 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 18:51:44 -0000 Subject: [cfe-commits] r127602 - /cfe/trunk/test/CXX/except/except.spec/p11.cpp Message-ID: <20110314185144.3BFC02A6C12C@llvm.org> Author: cornedbee Date: Mon Mar 14 13:51:44 2011 New Revision: 127602 URL: http://llvm.org/viewvc/llvm-project?rev=127602&view=rev Log: Add another, pretty trivial, exception spec test case. Added: cfe/trunk/test/CXX/except/except.spec/p11.cpp Added: cfe/trunk/test/CXX/except/except.spec/p11.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p11.cpp?rev=127602&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p11.cpp (added) +++ cfe/trunk/test/CXX/except/except.spec/p11.cpp Mon Mar 14 13:51:44 2011 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++0x -fexceptions -fcxx-exceptions -fsyntax-only -verify %s + +// This is the "let the user shoot himself in the foot" clause. +void f() noexcept { + throw 0; // no-error +} +void g() throw() { + throw 0; // no-error +} +void h() throw(int) { + throw 0.0; // no-error +} From sebastian.redl at getdesigned.at Mon Mar 14 13:51:50 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 18:51:50 -0000 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp Message-ID: <20110314185150.9056C2A6C12D@llvm.org> Author: cornedbee Date: Mon Mar 14 13:51:50 2011 New Revision: 127603 URL: http://llvm.org/viewvc/llvm-project?rev=127603&view=rev Log: Implement instantiation of noexcept spec and add a test case. Added: cfe/trunk/test/CXX/except/except.spec/template.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=127603&r1=127602&r2=127603&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Mar 14 13:51:50 2011 @@ -2161,14 +2161,20 @@ Exceptions.push_back(T); } + Expr *NoexceptExpr = 0; + if (Expr *OldNoexceptExpr = Proto->getNoexceptExpr()) { + ExprResult E = SemaRef.SubstExpr(OldNoexceptExpr, TemplateArgs); + if (E.isUsable()) + NoexceptExpr = E.take(); + } // Rebuild the function type FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo(); - // FIXME: Handle noexcept EPI.ExceptionSpecType = Proto->getExceptionSpecType(); EPI.NumExceptions = Exceptions.size(); EPI.Exceptions = Exceptions.data(); + EPI.NoexceptExpr = NoexceptExpr; EPI.ExtInfo = Proto->getExtInfo(); const FunctionProtoType *NewProto Added: cfe/trunk/test/CXX/except/except.spec/template.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/template.cpp?rev=127603&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/template.cpp (added) +++ cfe/trunk/test/CXX/except/except.spec/template.cpp Mon Mar 14 13:51:50 2011 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++0x -fexceptions -fcxx-exceptions -fsyntax-only -verify %s + +// We use pointer assignment compatibility to test instantiation. + +template void f1() throw(int); +template void f2() noexcept(N > 1); + +void (*t1)() throw(int) = &f1<0>; +void (*t2)() throw() = &f1<0>; // expected-error {{not superset}} + +void (*t3)() noexcept = &f2<2>; // no-error +void (*t4)() noexcept = &f2<0>; // expected-error {{not superset}} From dgregor at apple.com Mon Mar 14 13:59:15 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 11:59:15 -0700 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp In-Reply-To: <20110314185150.9056C2A6C12D@llvm.org> References: <20110314185150.9056C2A6C12D@llvm.org> Message-ID: On Mar 14, 2011, at 11:51 AM, Sebastian Redl wrote: > Author: cornedbee > Date: Mon Mar 14 13:51:50 2011 > New Revision: 127603 > > URL: http://llvm.org/viewvc/llvm-project?rev=127603&view=rev > Log: > Implement instantiation of noexcept spec and add a test case. Cool. I'm guessing that there's more work to be done to make noexcept instantiation be a SFINAE context, which IIRC it should be. - Doug > Added: > cfe/trunk/test/CXX/except/except.spec/template.cpp > Modified: > cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp > > Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=127603&r1=127602&r2=127603&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Mar 14 13:51:50 2011 > @@ -2161,14 +2161,20 @@ > > Exceptions.push_back(T); > } > + Expr *NoexceptExpr = 0; > + if (Expr *OldNoexceptExpr = Proto->getNoexceptExpr()) { > + ExprResult E = SemaRef.SubstExpr(OldNoexceptExpr, TemplateArgs); > + if (E.isUsable()) > + NoexceptExpr = E.take(); > + } > > // Rebuild the function type > > FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo(); > - // FIXME: Handle noexcept > EPI.ExceptionSpecType = Proto->getExceptionSpecType(); > EPI.NumExceptions = Exceptions.size(); > EPI.Exceptions = Exceptions.data(); > + EPI.NoexceptExpr = NoexceptExpr; > EPI.ExtInfo = Proto->getExtInfo(); > > const FunctionProtoType *NewProto > > Added: cfe/trunk/test/CXX/except/except.spec/template.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/template.cpp?rev=127603&view=auto > ============================================================================== > --- cfe/trunk/test/CXX/except/except.spec/template.cpp (added) > +++ cfe/trunk/test/CXX/except/except.spec/template.cpp Mon Mar 14 13:51:50 2011 > @@ -0,0 +1,12 @@ > +// RUN: %clang_cc1 -std=c++0x -fexceptions -fcxx-exceptions -fsyntax-only -verify %s > + > +// We use pointer assignment compatibility to test instantiation. > + > +template void f1() throw(int); > +template void f2() noexcept(N > 1); > + > +void (*t1)() throw(int) = &f1<0>; > +void (*t2)() throw() = &f1<0>; // expected-error {{not superset}} > + > +void (*t3)() noexcept = &f2<2>; // no-error > +void (*t4)() noexcept = &f2<0>; // expected-error {{not superset}} > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From sebastian.redl at getdesigned.at Mon Mar 14 14:22:17 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 20:22:17 +0100 Subject: [cfe-commits] r127596 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaType.cpp test/CXX/except/except.spec/p15.cpp In-Reply-To: <20894183-43F6-4CC5-8D7E-8B57058560B1@apple.com> References: <20110314180830.7DC802A6C12D@llvm.org> <20894183-43F6-4CC5-8D7E-8B57058560B1@apple.com> Message-ID: On 14.03.2011, at 19:45, Douglas Gregor wrote: > > On Mar 14, 2011, at 11:08 AM, Sebastian Redl wrote: > >> Author: cornedbee >> Date: Mon Mar 14 13:08:30 2011 >> New Revision: 127596 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127596&view=rev >> Log: >> Make deallocation functions implicitly noexcept in C++0x. > > This is moderately terrifying, since throwing destructors (which were permitted in C++98/03) will now terminate(). We might want to put this under a flag, and even consider diagnosing the common cases (e.g., warn about a throw expression that occurs in a destructor). It's not that bad. Unlike the proposal, the actual standard draft only makes deallocation functions (operator delete and delete[]) noexcept, not destructors. Sebastian From sebastian.redl at getdesigned.at Mon Mar 14 14:24:03 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 20:24:03 +0100 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp In-Reply-To: References: <20110314185150.9056C2A6C12D@llvm.org> Message-ID: On 14.03.2011, at 19:59, Douglas Gregor wrote: > > On Mar 14, 2011, at 11:51 AM, Sebastian Redl wrote: > >> Author: cornedbee >> Date: Mon Mar 14 13:51:50 2011 >> New Revision: 127603 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127603&view=rev >> Log: >> Implement instantiation of noexcept spec and add a test case. > > Cool. I'm guessing that there's more work to be done to make noexcept instantiation be a SFINAE context, which IIRC it should be. Strictly speaking, the dynamic spec instantiation should be as well. template void f() throw(typename T::type); I'll write a test and see what I can do. Sebastian From sebastian.redl at getdesigned.at Mon Mar 14 14:35:06 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 20:35:06 +0100 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp In-Reply-To: References: <20110314185150.9056C2A6C12D@llvm.org> Message-ID: <5AE819DB-C144-45FD-884E-1E8E02F2A92C@getdesigned.at> On 14.03.2011, at 20:24, Sebastian Redl wrote: > > On 14.03.2011, at 19:59, Douglas Gregor wrote: > >> >> On Mar 14, 2011, at 11:51 AM, Sebastian Redl wrote: >> >>> Author: cornedbee >>> Date: Mon Mar 14 13:51:50 2011 >>> New Revision: 127603 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=127603&view=rev >>> Log: >>> Implement instantiation of noexcept spec and add a test case. >> >> Cool. I'm guessing that there's more work to be done to make noexcept instantiation be a SFINAE context, which IIRC it should be. > > Strictly speaking, the dynamic spec instantiation should be as well. > > template > void f() throw(typename T::type); > > I'll write a test and see what I can do. OK, [temp.deduct]p7 contains a note that says that exception specs are not a SFINAE context. Apparently this is because "substitution occurs in all types and expressions that are used in the function type". Note that it is the function type, not the function, and as [except.spec]p13 tells us, "an exception-specification is not considered part of a function's type". So there. :-) Sebastian From kremenek at apple.com Mon Mar 14 14:50:34 2011 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 14 Mar 2011 19:50:34 -0000 Subject: [cfe-commits] r127604 - /cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Message-ID: <20110314195034.8A0492A6C12C@llvm.org> Author: kremenek Date: Mon Mar 14 14:50:34 2011 New Revision: 127604 URL: http://llvm.org/viewvc/llvm-project?rev=127604&view=rev Log: Incorporate source ranges for RangeBugReport when coelescing reports into equivalence classes. Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h?rev=127604&r1=127603&r2=127604&view=diff ============================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (original) +++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Mon Mar 14 14:50:34 2011 @@ -219,6 +219,18 @@ virtual std::pair getRanges() const { return std::make_pair(Ranges.begin(), Ranges.end()); } + + virtual void Profile(llvm::FoldingSetNodeID& hash) const { + BugReport::Profile(hash); + for (llvm::SmallVectorImpl::const_iterator I = + Ranges.begin(), E = Ranges.end(); I != E; ++I) { + const SourceRange range = *I; + if (!range.isValid()) + continue; + hash.AddInteger(range.getBegin().getRawEncoding()); + hash.AddInteger(range.getEnd().getRawEncoding()); + } + } }; class EnhancedBugReport : public RangedBugReport { From kremenek at apple.com Mon Mar 14 14:50:37 2011 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 14 Mar 2011 19:50:37 -0000 Subject: [cfe-commits] r127605 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp test/Analysis/variadic-method-types.m Message-ID: <20110314195037.88E842A6C12D@llvm.org> Author: kremenek Date: Mon Mar 14 14:50:37 2011 New Revision: 127605 URL: http://llvm.org/viewvc/llvm-project?rev=127605&view=rev Log: Tweak VariadicMethodTypeChecker to only create one ExplodedNode when issuing multiple warnings for the same message expression. Also add a test case showing that we correctly report multiple warnings for the same message expression. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp cfe/trunk/test/Analysis/variadic-method-types.m Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=127605&r1=127604&r2=127605&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Mon Mar 14 14:50:37 2011 @@ -502,10 +502,7 @@ bool VariadicMethodTypeChecker::isVariadicMessage(const ObjCMessage &msg) const { const ObjCMethodDecl *MD = msg.getMethodDecl(); - if (!MD) - return false; - - if (!MD->isVariadic()) + if (!MD || !MD->isVariadic()) return false; Selector S = msg.getSelector(); @@ -586,13 +583,19 @@ return; // Verify that all arguments have Objective-C types. + llvm::Optional errorNode; + for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) { QualType ArgTy = msg.getArgType(I); if (ArgTy->isObjCObjectPointerType()) continue; - ExplodedNode *N = C.generateNode(); - if (!N) + // Generate only one error node to use for all bug reports. + if (!errorNode.hasValue()) { + errorNode = C.generateNode(); + } + + if (!errorNode.getValue()) continue; llvm::SmallString<128> sbuf; @@ -607,7 +610,8 @@ << "' should be an Objective-C pointer type, not '" << ArgTy.getAsString() << "'"; - RangedBugReport *R = new RangedBugReport(*BT, os.str(), N); + RangedBugReport *R = new RangedBugReport(*BT, os.str(), + errorNode.getValue()); R->addRange(msg.getArgSourceRange(I)); C.EmitReport(R); } Modified: cfe/trunk/test/Analysis/variadic-method-types.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/variadic-method-types.m?rev=127605&r1=127604&r2=127605&view=diff ============================================================================== --- cfe/trunk/test/Analysis/variadic-method-types.m (original) +++ cfe/trunk/test/Analysis/variadic-method-types.m Mon Mar 14 14:50:37 2011 @@ -63,7 +63,7 @@ void f(id a, id

b, C* c, C

*d) { [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil]; - [NSArray arrayWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}} + [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}} [NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} [NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}} From kremenek at apple.com Mon Mar 14 14:55:29 2011 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 14 Mar 2011 12:55:29 -0700 Subject: [cfe-commits] r127572 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp lib/StaticAnalyzer/Checkers/Checkers.td test/Analysis/variadic-method-types.m In-Reply-To: <20110313203521.F31C22A6C12C@llvm.org> References: <20110313203521.F31C22A6C12C@llvm.org> Message-ID: Looks great to me! I went ahead and did a few tweaks so that only one ExplodedNode gets generated for multiple warnings at the same message expression, and in turn fixed a latent bug in BugReporter. Thanks for doing this! On Mar 13, 2011, at 1:35 PM, Anders Carlsson wrote: > Author: andersca > Date: Sun Mar 13 15:35:21 2011 > New Revision: 127572 > > URL: http://llvm.org/viewvc/llvm-project?rev=127572&view=rev > Log: > Add an Objective-C checker that checks that arguments passed to some variadic Objective-C methods are of Objective-C pointer types. > > Ted or Argiris, I'd appreciate a review! > > Added: > cfe/trunk/test/Analysis/variadic-method-types.m > Modified: > cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp > cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td > > Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=127572&r1=127571&r2=127572&view=diff > ============================================================================== > --- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original) > +++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Sun Mar 13 15:35:21 2011 > @@ -477,6 +477,143 @@ > } > > //===----------------------------------------------------------------------===// > +// Check for passing non-Objective-C types to variadic methods that expect > +// only Objective-C types. > +//===----------------------------------------------------------------------===// > + > +namespace { > +class VariadicMethodTypeChecker : public Checker { > + mutable Selector arrayWithObjectsS; > + mutable Selector dictionaryWithObjectsAndKeysS; > + mutable Selector setWithObjectsS; > + mutable Selector initWithObjectsS; > + mutable Selector initWithObjectsAndKeysS; > + mutable llvm::OwningPtr BT; > + > + bool isVariadicMessage(const ObjCMessage &msg) const; > + > +public: > + void checkPreObjCMessage(ObjCMessage msg, CheckerContext &C) const; > +}; > +} > + > +/// isVariadicMessage - Returns whether the given message is a variadic message, > +/// where all arguments must be Objective-C types. > +bool > +VariadicMethodTypeChecker::isVariadicMessage(const ObjCMessage &msg) const { > + const ObjCMethodDecl *MD = msg.getMethodDecl(); > + if (!MD) > + return false; > + > + if (!MD->isVariadic()) > + return false; > + > + Selector S = msg.getSelector(); > + > + if (msg.isInstanceMessage()) { > + // FIXME: Ideally we'd look at the receiver interface here, but that's not > + // useful for init, because alloc returns 'id'. In theory, this could lead > + // to false positives, for example if there existed a class that had an > + // initWithObjects: implementation that does accept non-Objective-C pointer > + // types, but the chance of that happening is pretty small compared to the > + // gains that this analysis gives. > + const ObjCInterfaceDecl *Class = MD->getClassInterface(); > + > + // -[NSArray initWithObjects:] > + if (isReceiverClassOrSuperclass(Class, "NSArray") && > + S == initWithObjectsS) > + return true; > + > + // -[NSDictionary initWithObjectsAndKeys:] > + if (isReceiverClassOrSuperclass(Class, "NSDictionary") && > + S == initWithObjectsAndKeysS) > + return true; > + > + // -[NSSet initWithObjects:] > + if (isReceiverClassOrSuperclass(Class, "NSSet") && > + S == initWithObjectsS) > + return true; > + } else { > + const ObjCInterfaceDecl *Class = msg.getReceiverInterface(); > + > + // -[NSArray arrayWithObjects:] > + if (isReceiverClassOrSuperclass(Class, "NSArray") && > + S == arrayWithObjectsS) > + return true; > + > + // -[NSDictionary dictionaryWithObjectsAndKeys:] > + if (isReceiverClassOrSuperclass(Class, "NSDictionary") && > + S == dictionaryWithObjectsAndKeysS) > + return true; > + > + // -[NSSet setWithObjects:] > + if (isReceiverClassOrSuperclass(Class, "NSSet") && > + S == setWithObjectsS) > + return true; > + } > + > + return false; > +} > + > +void VariadicMethodTypeChecker::checkPreObjCMessage(ObjCMessage msg, > + CheckerContext &C) const { > + if (!BT) { > + BT.reset(new APIMisuse("Arguments passed to variadic method aren't all " > + "Objective-C pointer types")); > + > + ASTContext &Ctx = C.getASTContext(); > + arrayWithObjectsS = GetUnarySelector("arrayWithObjects", Ctx); > + dictionaryWithObjectsAndKeysS = > + GetUnarySelector("dictionaryWithObjectsAndKeys", Ctx); > + setWithObjectsS = GetUnarySelector("setWithObjects", Ctx); > + > + initWithObjectsS = GetUnarySelector("initWithObjects", Ctx); > + initWithObjectsAndKeysS = GetUnarySelector("initWithObjectsAndKeys", Ctx); > + } > + > + if (!isVariadicMessage(msg)) > + return; > + > + // We are not interested in the selector arguments since they have > + // well-defined types, so the compiler will issue a warning for them. > + unsigned variadicArgsBegin = msg.getSelector().getNumArgs(); > + > + // We're not interested in the last argument since it has to be nil or the > + // compiler would have issued a warning for it elsewhere. > + unsigned variadicArgsEnd = msg.getNumArgs() - 1; > + > + if (variadicArgsEnd <= variadicArgsBegin) > + return; > + > + // Verify that all arguments have Objective-C types. > + for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) { > + QualType ArgTy = msg.getArgType(I); > + if (ArgTy->isObjCObjectPointerType()) > + continue; > + > + ExplodedNode *N = C.generateNode(); > + if (!N) > + continue; > + > + llvm::SmallString<128> sbuf; > + llvm::raw_svector_ostream os(sbuf); > + > + if (const char *TypeName = GetReceiverNameType(msg)) > + os << "Argument to '" << TypeName << "' method '"; > + else > + os << "Argument to method '"; > + > + os << msg.getSelector().getAsString() > + << "' should be an Objective-C pointer type, not '" > + << ArgTy.getAsString() << "'"; > + > + RangedBugReport *R = new RangedBugReport(*BT, os.str(), N); > + R->addRange(msg.getArgSourceRange(I)); > + C.EmitReport(R); > + } > +} > + > +//===----------------------------------------------------------------------===// > // Check registration. > //===----------------------------------------------------------------------===// > > @@ -495,3 +632,7 @@ > void ento::registerClassReleaseChecker(CheckerManager &mgr) { > mgr.registerChecker(); > } > + > +void ento::registerVariadicMethodTypeChecker(CheckerManager &mgr) { > + mgr.registerChecker(); > +} > > Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td?rev=127572&r1=127571&r2=127572&view=diff > ============================================================================== > --- cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td (original) > +++ cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td Sun Mar 13 15:35:21 2011 > @@ -60,6 +60,11 @@ > HelpText<"Check for sending 'retain', 'release', or 'autorelease' directly to a Class">, > DescFile<"BasicObjCFoundationChecks.cpp">; > > +def VariadicMethodTypeChecker : Checker<"VariadicMethodTypes">, > + HelpText<"Check for passing non-Objective-C types to variadic methods that expect" > + "only Objective-C types">, > + DescFile<"BasicObjCFoundationChecks.cpp">; > + > def NSAutoreleasePoolChecker : Checker<"NSAutoreleasePool">, > HelpText<"Warn for subpar uses of NSAutoreleasePool">, > DescFile<"NSAutoreleasePoolChecker.cpp">; > > Added: cfe/trunk/test/Analysis/variadic-method-types.m > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/variadic-method-types.m?rev=127572&view=auto > ============================================================================== > --- cfe/trunk/test/Analysis/variadic-method-types.m (added) > +++ cfe/trunk/test/Analysis/variadic-method-types.m Sun Mar 13 15:35:21 2011 > @@ -0,0 +1,77 @@ > +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,cocoa.VariadicMethodTypes -analyzer-store=basic -fblocks -verify %s > +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,cocoa.VariadicMethodTypes -analyzer-store=region -fblocks -verify %s > + > +//===----------------------------------------------------------------------===// > +// The following code is reduced using delta-debugging from > +// Foundation.h (Mac OS X). > +// > +// It includes the basic definitions for the test cases below. > +// Not directly including Foundation.h directly makes this test case > +// both svelte and portable to non-Mac platforms. > +//===----------------------------------------------------------------------===// > + > +#define nil (void*)0 > + > +typedef signed char BOOL; > +typedef struct _NSZone NSZone; > +typedef unsigned int NSUInteger; > + at protocol NSObject > +- (BOOL)isEqual:(id)object; > +- (oneway void)release; > +- (id)retain; > +- (id)autorelease; > + at end > + at protocol NSCopying > +- (id)copyWithZone:(NSZone *)zone; > + at end > + at protocol NSMutableCopying > +- (id)mutableCopyWithZone:(NSZone *)zone; > + at end > + at class NSCoder; > + at protocol NSCoding > +- (void)encodeWithCoder:(NSCoder *)aCoder; > + at end > + at interface NSObject {} > +- (id)init; > ++ (id)alloc; > + at end > +typedef struct {} NSFastEnumerationState; > + at protocol NSFastEnumeration > +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; > + at end > + at interface NSArray : NSObject > + at end > + at interface NSArray (NSArrayCreation) > ++ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1))); > +- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1))); > + at end > + at interface NSDictionary : NSObject > + at end > + at interface NSDictionary (NSDictionaryCreation) > ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1))); > +- (id)initWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1))); > + at end > + at interface NSSet : NSObject > + at end > + at interface NSSet (NSSetCreation) > ++ (id)setWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1))); > +- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1))); > + at end > + at protocol P; > + at class C; > + > +void f(id a, id

b, C* c, C

*d) { > + [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil]; > + > + [NSArray arrayWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}} > + [NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} > + [NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}} > + > + [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} > + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} > + [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} > +} > + > +int main() { > + f(nil, nil, nil, nil); > +} > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From dgregor at apple.com Mon Mar 14 15:17:32 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 13:17:32 -0700 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp In-Reply-To: <5AE819DB-C144-45FD-884E-1E8E02F2A92C@getdesigned.at> References: <20110314185150.9056C2A6C12D@llvm.org> <5AE819DB-C144-45FD-884E-1E8E02F2A92C@getdesigned.at> Message-ID: <362E1449-2448-448A-9D74-F9B8F38BAF31@apple.com> On Mar 14, 2011, at 12:35 PM, Sebastian Redl wrote: > > On 14.03.2011, at 20:24, Sebastian Redl wrote: > >> >> On 14.03.2011, at 19:59, Douglas Gregor wrote: >> >>> >>> On Mar 14, 2011, at 11:51 AM, Sebastian Redl wrote: >>> >>>> Author: cornedbee >>>> Date: Mon Mar 14 13:51:50 2011 >>>> New Revision: 127603 >>>> >>>> URL: http://llvm.org/viewvc/llvm-project?rev=127603&view=rev >>>> Log: >>>> Implement instantiation of noexcept spec and add a test case. >>> >>> Cool. I'm guessing that there's more work to be done to make noexcept instantiation be a SFINAE context, which IIRC it should be. >> >> Strictly speaking, the dynamic spec instantiation should be as well. >> >> template >> void f() throw(typename T::type); >> >> I'll write a test and see what I can do. > > OK, [temp.deduct]p7 contains a note that says that exception specs are not a SFINAE context. Apparently this is because "substitution occurs in all types and expressions that are used in the function type". Note that it is the function type, not the function, and as [except.spec]p13 tells us, "an exception-specification is not considered part of a function's type". > > So there. :-) Fine! Be that way! I think we *do* end up instantiating exception specifications at the wrong time still, but that's probably a separable issue. In particular, I think we're only supposed to instantiate the exception specifications once we've selected an overload in overload resolution - Doug From dgregor at apple.com Mon Mar 14 15:18:04 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 13:18:04 -0700 Subject: [cfe-commits] r127583 - /cfe/trunk/lib/Driver/ToolChains.cpp In-Reply-To: <20110314153950.5B4842A6C12C@llvm.org> References: <20110314153950.5B4842A6C12C@llvm.org> Message-ID: Bill, please pull this into the 2.9 branch. Thanks! - Doug On Mar 14, 2011, at 8:39 AM, Douglas Gregor wrote: > Author: dgregor > Date: Mon Mar 14 10:39:50 2011 > New Revision: 127583 > > URL: http://llvm.org/viewvc/llvm-project?rev=127583&view=rev > Log: > Support Ubuntu hardy and intrepid, from Thomas Gamper! > > Modified: > cfe/trunk/lib/Driver/ToolChains.cpp > > Modified: cfe/trunk/lib/Driver/ToolChains.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=127583&r1=127582&r2=127583&view=diff > ============================================================================== > --- cfe/trunk/lib/Driver/ToolChains.cpp (original) > +++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Mar 14 10:39:50 2011 > @@ -1280,6 +1280,8 @@ > Fedora13, > Fedora14, > OpenSuse11_3, > + UbuntuHardy, > + UbuntuIntrepid, > UbuntuJaunty, > UbuntuKarmic, > UbuntuLucid, > @@ -1300,7 +1302,8 @@ > } > > static bool IsUbuntu(enum LinuxDistro Distro) { > - return Distro == UbuntuLucid || Distro == UbuntuMaverick || > + return Distro == UbuntuHardy || Distro == UbuntuIntrepid || > + Distro == UbuntuLucid || Distro == UbuntuMaverick || > Distro == UbuntuJaunty || Distro == UbuntuKarmic; > } > > @@ -1329,6 +1332,10 @@ > llvm::SmallVector Lines; > Data.split(Lines, "\n"); > for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) { > + if (Lines[i] == "DISTRIB_CODENAME=hardy") > + return UbuntuHardy; > + if (Lines[i] == "DISTRIB_CODENAME=intrepid") > + return UbuntuIntrepid; > if (Lines[i] == "DISTRIB_CODENAME=maverick") > return UbuntuMaverick; > else if (Lines[i] == "DISTRIB_CODENAME=lucid") > @@ -1444,7 +1451,8 @@ > > const char* GccVersions[] = {"4.5.2", "4.5.1", "4.5", "4.4.5", "4.4.4", > "4.4.3", "4.4", "4.3.4", "4.3.3", "4.3.2", > - "4.3"}; > + "4.3", "4.2.4", "4.2.3", "4.2.2", "4.2.1", > + "4.2"}; > std::string Base = ""; > for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) { > std::string Suffix = GccTriple + "/" + GccVersions[i]; > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From dgregor at apple.com Mon Mar 14 15:18:18 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 13:18:18 -0700 Subject: [cfe-commits] r127582 - /cfe/trunk/lib/Frontend/InitHeaderSearch.cpp In-Reply-To: <20110314153344.A0E9A2A6C12C@llvm.org> References: <20110314153344.A0E9A2A6C12C@llvm.org> Message-ID: Bill, please pull this into the 2.9 branch. Thanks! - Doug On Mar 14, 2011, at 8:33 AM, Douglas Gregor wrote: > Author: dgregor > Date: Mon Mar 14 10:33:44 2011 > New Revision: 127582 > > URL: http://llvm.org/viewvc/llvm-project?rev=127582&view=rev > Log: > Add include paths for Gentoo Linux, from Marcin Miros?aw! > > Modified: > cfe/trunk/lib/Frontend/InitHeaderSearch.cpp > > Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=127582&r1=127581&r2=127582&view=diff > ============================================================================== > --- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original) > +++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Mon Mar 14 10:33:44 2011 > @@ -741,7 +741,19 @@ > "i686-pc-linux-gnu", "", "", triple); > AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", > "x86_64-unknown-linux-gnu", "", "", triple); > - // Gentoo x86 2010.0 stable > + // Gentoo x86 gcc 4.5.2 > + AddGnuCPlusPlusIncludePaths( > + "/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4", > + "i686-pc-linux-gnu", "", "", triple); > + // Gentoo x86 gcc 4.4.5 > + AddGnuCPlusPlusIncludePaths( > + "/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4", > + "i686-pc-linux-gnu", "", "", triple); > + // Gentoo x86 gcc 4.4.4 > + AddGnuCPlusPlusIncludePaths( > + "/usr/lib/gcc/i686-pc-linux-gnu/4.4.4/include/g++-v4", > + "i686-pc-linux-gnu", "", "", triple); > + // Gentoo x86 2010.0 stable > AddGnuCPlusPlusIncludePaths( > "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4", > "i686-pc-linux-gnu", "", "", triple); > @@ -757,7 +769,15 @@ > AddGnuCPlusPlusIncludePaths( > "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", > "i686-pc-linux-gnu", "", "", triple); > + // Gentoo x86 llvm-gcc trunk > + AddGnuCPlusPlusIncludePaths( > + "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", > + "i686-pc-linux-gnu", "", "", triple); > > + // Gentoo amd64 gcc 4.5.2 > + AddGnuCPlusPlusIncludePaths( > + "/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4", > + "x86_64-pc-linux-gnu", "32", "", triple); > // Gentoo amd64 gcc 4.4.5 > AddGnuCPlusPlusIncludePaths( > "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4", > @@ -777,7 +797,7 @@ > // Gentoo amd64 stable > AddGnuCPlusPlusIncludePaths( > "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", > - "i686-pc-linux-gnu", "", "", triple); > + "x86_64-pc-linux-gnu", "", "", triple); > > // Gentoo amd64 llvm-gcc trunk > AddGnuCPlusPlusIncludePaths( > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From sebastian.redl at getdesigned.at Mon Mar 14 15:21:55 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 21:21:55 +0100 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp In-Reply-To: <362E1449-2448-448A-9D74-F9B8F38BAF31@apple.com> References: <20110314185150.9056C2A6C12D@llvm.org> <5AE819DB-C144-45FD-884E-1E8E02F2A92C@getdesigned.at> <362E1449-2448-448A-9D74-F9B8F38BAF31@apple.com> Message-ID: <478DE9AF-406B-41D9-A979-6C778E260B4C@getdesigned.at> On 14.03.2011, at 21:17, Douglas Gregor wrote: > I think we *do* end up instantiating exception specifications at the wrong time still, but that's probably a separable issue. In particular, I think we're only supposed to instantiate the exception specifications once we've selected an overload in overload resolution Yes. I wrote a test case that was supposed to fail with ambiguity, but it failed to instantiate the prototypes. I so don't want to be the one to fix that ... Sebastian From dgregor at apple.com Mon Mar 14 15:28:18 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 13:28:18 -0700 Subject: [cfe-commits] r127603 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/except/except.spec/template.cpp In-Reply-To: <478DE9AF-406B-41D9-A979-6C778E260B4C@getdesigned.at> References: <20110314185150.9056C2A6C12D@llvm.org> <5AE819DB-C144-45FD-884E-1E8E02F2A92C@getdesigned.at> <362E1449-2448-448A-9D74-F9B8F38BAF31@apple.com> <478DE9AF-406B-41D9-A979-6C778E260B4C@getdesigned.at> Message-ID: <36B107D2-9E1C-4F27-A23D-EE987C672DA1@apple.com> On Mar 14, 2011, at 1:21 PM, Sebastian Redl wrote: > > On 14.03.2011, at 21:17, Douglas Gregor wrote: > >> I think we *do* end up instantiating exception specifications at the wrong time still, but that's probably a separable issue. In particular, I think we're only supposed to instantiate the exception specifications once we've selected an overload in overload resolution > > Yes. I wrote a test case that was supposed to fail with ambiguity, but it failed to instantiate the prototypes. If you have that test case around, could you put it in a PR? > I so don't want to be the one to fix that ... Yeah, it's messy. We probably need to stop relying on FunctionDecls while we're performing overload resolution for function template specializations, which probably means I should do it. Draw straws? ;) - Doug From echristo at apple.com Mon Mar 14 15:30:34 2011 From: echristo at apple.com (Eric Christopher) Date: Mon, 14 Mar 2011 20:30:34 -0000 Subject: [cfe-commits] r127616 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/arm-clear.c Message-ID: <20110314203034.D72C62A6C12C@llvm.org> Author: echristo Date: Mon Mar 14 15:30:34 2011 New Revision: 127616 URL: http://llvm.org/viewvc/llvm-project?rev=127616&view=rev Log: __clear_cache() is varargs and people will occasionally write it without arguments. Process only the arguments that people write, but process all of them. Fixes rdar://8900346 Added: cfe/trunk/test/CodeGen/arm-clear.c Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=127616&r1=127615&r2=127616&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original) +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Mar 14 15:30:34 2011 @@ -1116,13 +1116,16 @@ const CallExpr *E) { if (BuiltinID == ARM::BI__clear_cache) { const FunctionDecl *FD = E->getDirectCallee(); - Value *a = EmitScalarExpr(E->getArg(0)); - Value *b = EmitScalarExpr(E->getArg(1)); + // Oddly people write this call without args on occasion and gcc accepts + // it - it's also marked as varargs in the description file. + llvm::SmallVector Ops; + for (unsigned i = 0; i < E->getNumArgs(); i++) + Ops.push_back(EmitScalarExpr(E->getArg(i))); const llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); const llvm::FunctionType *FTy = cast(Ty); llvm::StringRef Name = FD->getName(); - return Builder.CreateCall2(CGM.CreateRuntimeFunction(FTy, Name), - a, b); + return Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), + Ops.begin(), Ops.end()); } llvm::SmallVector Ops; Added: cfe/trunk/test/CodeGen/arm-clear.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-clear.c?rev=127616&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/arm-clear.c (added) +++ cfe/trunk/test/CodeGen/arm-clear.c Mon Mar 14 15:30:34 2011 @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -w -o - %s | FileCheck %s + +void clear0(void *ptr) { + // CHECK: clear0 + // CHECK-NOT: load i8** + __clear_cache(); +} + +void clear1(void *ptr) { + // CHECK: clear1 + // CHECK: load i8** + // CHECK-NOT: load i8** + __clear_cache(ptr); +} + +void clear2(void *ptr, void *ptr2) { + // CHECK: clear2 + // CHECK: load i8** + // CHECK: load i8** + __clear_cache(ptr, ptr2); +} From sebastian.redl at getdesigned.at Mon Mar 14 15:33:21 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Mon, 14 Mar 2011 20:33:21 -0000 Subject: [cfe-commits] r127617 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp Message-ID: <20110314203321.1D6DD2A6C12C@llvm.org> Author: cornedbee Date: Mon Mar 14 15:33:20 2011 New Revision: 127617 URL: http://llvm.org/viewvc/llvm-project?rev=127617&view=rev Log: Code generation for noexcept. Added: cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp Modified: cfe/trunk/lib/CodeGen/CGException.cpp Modified: cfe/trunk/lib/CodeGen/CGException.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=127617&r1=127616&r2=127617&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGException.cpp (original) +++ cfe/trunk/lib/CodeGen/CGException.cpp Mon Mar 14 15:33:20 2011 @@ -449,19 +449,23 @@ if (Proto == 0) return; - // FIXME: What about noexcept? - if (!Proto->hasDynamicExceptionSpec()) - return; - - unsigned NumExceptions = Proto->getNumExceptions(); - EHFilterScope *Filter = EHStack.pushFilter(NumExceptions); - - for (unsigned I = 0; I != NumExceptions; ++I) { - QualType Ty = Proto->getExceptionType(I); - QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType(); - llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType, - /*ForEH=*/true); - Filter->setFilter(I, EHType); + ExceptionSpecificationType EST = Proto->getExceptionSpecType(); + if (isNoexceptExceptionSpec(EST)) { + if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) { + // noexcept functions are simple terminate scopes. + EHStack.pushTerminate(); + } + } else if (EST == EST_Dynamic || EST == EST_DynamicNone) { + unsigned NumExceptions = Proto->getNumExceptions(); + EHFilterScope *Filter = EHStack.pushFilter(NumExceptions); + + for (unsigned I = 0; I != NumExceptions; ++I) { + QualType Ty = Proto->getExceptionType(I); + QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType(); + llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType, + /*ForEH=*/true); + Filter->setFilter(I, EHType); + } } } @@ -476,10 +480,14 @@ if (Proto == 0) return; - if (!Proto->hasDynamicExceptionSpec()) - return; - - EHStack.popFilter(); + ExceptionSpecificationType EST = Proto->getExceptionSpecType(); + if (isNoexceptExceptionSpec(EST)) { + if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) { + EHStack.popTerminate(); + } + } else if (EST == EST_Dynamic || EST == EST_DynamicNone) { + EHStack.popFilter(); + } } void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) { Added: cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp?rev=127617&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp (added) +++ cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp Mon Mar 14 15:33:20 2011 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s + +void external(); + +void target() throw(int) +{ + // CHECK: invoke void @_Z8externalv() + external(); +} +// CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind +// CHECK: ehspec.unexpected: +// CHECK: call void @__cxa_call_unexpected(i8* %1) noreturn Added: cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp?rev=127617&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp (added) +++ cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp Mon Mar 14 15:33:20 2011 @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 %s -std=c++0x -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s + +void external(); + +void target() noexcept +{ + // CHECK: invoke void @_Z8externalv() + external(); +} +// CHECK: terminate.lpad: +// CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) nounwind +// CHECK-NEXT: call void @_ZSt9terminatev() noreturn nounwind +// CHECK-NEXT: unreachable + +void reverse() noexcept(false) +{ + // CHECK: call void @_Z8externalv() + external(); +} From pichet2000 at gmail.com Mon Mar 14 16:03:11 2011 From: pichet2000 at gmail.com (Francois Pichet) Date: Mon, 14 Mar 2011 17:03:11 -0400 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing In-Reply-To: <045D8E3B-670A-4306-B5A1-EE9343BC5343@apple.com> References: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> <045D8E3B-670A-4306-B5A1-EE9343BC5343@apple.com> Message-ID: On Mon, Mar 14, 2011 at 1:46 PM, Douglas Gregor wrote: > > On Mar 14, 2011, at 10:36 AM, John McCall wrote: > >> On Mar 13, 2011, at 11:07 PM, Francois Pichet wrote: >>> This patch implements "Late template parsing" in Microsoft mode. >>> It solves the problem of Microsoft allowing names not yet declared in >>> template code. >> >> I haven't looked at the patch yet, but this defintely needs to be enabled >> by its own -cc1 language option; ?that option should then be enabled by >> windows targets, rather than tying this to -fms-extensions. > > > Yes. -fdelayed-template-parsing seems a good name. > > ? ? ? ?- Doug > ok then i'll provide a new patch soon. I'll remove the *Microsoft* from all the structs and functions names to make the patch more generic. From dgregor at apple.com Mon Mar 14 16:04:22 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 14:04:22 -0700 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing In-Reply-To: References: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> <045D8E3B-670A-4306-B5A1-EE9343BC5343@apple.com> Message-ID: On Mar 14, 2011, at 2:03 PM, Francois Pichet wrote: > On Mon, Mar 14, 2011 at 1:46 PM, Douglas Gregor wrote: >> >> On Mar 14, 2011, at 10:36 AM, John McCall wrote: >> >>> On Mar 13, 2011, at 11:07 PM, Francois Pichet wrote: >>>> This patch implements "Late template parsing" in Microsoft mode. >>>> It solves the problem of Microsoft allowing names not yet declared in >>>> template code. >>> >>> I haven't looked at the patch yet, but this defintely needs to be enabled >>> by its own -cc1 language option; that option should then be enabled by >>> windows targets, rather than tying this to -fms-extensions. >> >> >> Yes. -fdelayed-template-parsing seems a good name. >> >> - Doug >> > > ok then i'll provide a new patch soon. I'll remove the *Microsoft* > from all the structs and functions names to make the patch more > generic. Thanks! - Doug From rafael.espindola at gmail.com Mon Mar 14 16:08:20 2011 From: rafael.espindola at gmail.com (Rafael Espindola) Date: Mon, 14 Mar 2011 21:08:20 -0000 Subject: [cfe-commits] r127622 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c Message-ID: <20110314210820.0F84F2A6C12C@llvm.org> Author: rafael Date: Mon Mar 14 16:08:19 2011 New Revision: 127622 URL: http://llvm.org/viewvc/llvm-project?rev=127622&view=rev Log: Switch from internal to linker_private linkage, it is sufficient to please the new linker. Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/test/CodeGen/darwin-string-literals.c Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127622&r1=127621&r2=127622&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Mar 14 16:08:19 2011 @@ -1672,7 +1672,7 @@ // FIXME: With OS X ld 123.2 (xcode 4) and LTO we would get a linker error // when using private linkage. It is not clear if this is a bug in ld // or a reasonable new restriction. - Linkage = llvm::GlobalValue::InternalLinkage; + Linkage = llvm::GlobalValue::LinkerPrivateLinkage; isConstant = !Features.WritableStrings; } Modified: cfe/trunk/test/CodeGen/darwin-string-literals.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/darwin-string-literals.c?rev=127622&r1=127621&r2=127622&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/darwin-string-literals.c (original) +++ cfe/trunk/test/CodeGen/darwin-string-literals.c Mon Mar 14 16:08:19 2011 @@ -1,13 +1,13 @@ // RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix LSB %s // CHECK-LSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" -// CHECK-LSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" +// CHECK-LSB: @.str1 = linker_private unnamed_addr constant [8 x i8] c"string1\00" // CHECK-LSB: @.str2 = internal unnamed_addr constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", align 2 // RUN: %clang_cc1 -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s // CHECK-MSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" -// CHECK-MSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" +// CHECK-MSB: @.str1 = linker_private unnamed_addr constant [8 x i8] c"string1\00" // CHECK-MSB: @.str2 = internal unnamed_addr constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", align 2 const char *g0 = "string0"; From rafael.espindola at gmail.com Mon Mar 14 16:15:14 2011 From: rafael.espindola at gmail.com (Rafael Avila de Espindola) Date: Mon, 14 Mar 2011 17:15:14 -0400 Subject: [cfe-commits] r127594 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c In-Reply-To: <0637D520-A391-4215-A854-D1E0C89D0FC0@apple.com> References: <20110314175500.819F62A6C12C@llvm.org> <0637D520-A391-4215-A854-D1E0C89D0FC0@apple.com> Message-ID: <4D7E8562.7000102@gmail.com> On 11-03-14 02:37 PM, Chris Lattner wrote: > > On Mar 14, 2011, at 10:55 AM, Rafael Espindola wrote: > >> Author: rafael Date: Mon Mar 14 12:55:00 2011 New Revision: 127594 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127594&view=rev Log: >> Fix link of libxul with LTO and the linker in xcode4. It is not >> clear if this is working around a bug in ld or if the new linker >> has a reasonable reason for wanting the string constant to be >> linker visible. > > Hi Rafael, > > Private is probably the wrong answer, but I think that LinkerPrivate > is the right answer. Does LinkerPrivate work for libxul? > It does, thanks! I have updated the file. > -Chris Cheers, Rafael From dgregor at apple.com Mon Mar 14 16:19:51 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 21:19:51 -0000 Subject: [cfe-commits] r127623 - in /cfe/trunk: include/clang/Sema/IdentifierResolver.h lib/Sema/IdentifierResolver.cpp lib/Sema/SemaDecl.cpp test/SemaCXX/goto.cpp Message-ID: <20110314211951.DA5752A6C12C@llvm.org> Author: dgregor Date: Mon Mar 14 16:19:51 2011 New Revision: 127623 URL: http://llvm.org/viewvc/llvm-project?rev=127623&view=rev Log: When synthesizing a label declaration based on a goto statement that cannot yet be resolved, be sure to push the new label declaration into the right place within the identifier chain. Otherwise, name lookup in C++ gets confused when searching for names that are lexically closer than the label. Fixes PR9463. Added: cfe/trunk/test/SemaCXX/goto.cpp Modified: cfe/trunk/include/clang/Sema/IdentifierResolver.h cfe/trunk/lib/Sema/IdentifierResolver.cpp cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/include/clang/Sema/IdentifierResolver.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/IdentifierResolver.h?rev=127623&r1=127622&r2=127623&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/IdentifierResolver.h (original) +++ cfe/trunk/include/clang/Sema/IdentifierResolver.h Mon Mar 14 16:19:51 2011 @@ -53,6 +53,11 @@ /// declaration was not found, returns false. bool ReplaceDecl(NamedDecl *Old, NamedDecl *New); + /// \brief Insert the given declaration at the given position in the list. + void InsertDecl(DeclsTy::iterator Pos, NamedDecl *D) { + Decls.insert(Pos, D); + } + private: DeclsTy Decls; }; @@ -166,6 +171,10 @@ /// (and, therefore, replaced). bool ReplaceDecl(NamedDecl *Old, NamedDecl *New); + /// \brief Insert the given declaration prior to the given iterator + /// position + void InsertDecl(iterator Pos, NamedDecl *D); + /// \brief Link the declaration into the chain of declarations for /// the given identifier. /// Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=127623&r1=127622&r2=127623&view=diff ============================================================================== --- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original) +++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Mon Mar 14 16:19:51 2011 @@ -168,6 +168,39 @@ IDI->AddDecl(D); } +void IdentifierResolver::InsertDecl(iterator Pos, NamedDecl *D) { + if (Pos == iterator()) { + // Simple case: insert at the beginning of the list (which is the + // end of the stored vector). + AddDecl(D); + return; + } + + DeclarationName Name = D->getDeclName(); + void *Ptr = Name.getFETokenInfo(); + + if (isDeclPtr(Ptr)) { + // There's only one element, and we want to insert before it in the list. + // Just create the storage for these identifiers and insert them in the + // opposite order we normally would. + assert(isDeclPtr(Ptr) && "Not a single declaration!"); + Name.setFETokenInfo(NULL); + IdDeclInfo *IDI = &(*IdDeclInfos)[Name]; + NamedDecl *PrevD = static_cast(Ptr); + IDI->AddDecl(D); + IDI->AddDecl(PrevD); + return; + } + + // General case: insert the declaration at the appropriate point in the + // list, which already has at least two elements. + IdDeclInfo *IDI = toIdDeclInfo(Ptr); + if (Pos.isIterator()) + IDI->InsertDecl(Pos.getIterator(), D); + else + IDI->InsertDecl(IDI->decls_begin(), D); +} + /// RemoveDecl - Unlink the decl from its shadowed decl chain. /// The decl must already be part of the decl chain. void IdentifierResolver::RemoveDecl(NamedDecl *D) { Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127623&r1=127622&r2=127623&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 14 16:19:51 2011 @@ -494,7 +494,20 @@ } S->AddDecl(D); - IdResolver.AddDecl(D); + + if (isa(D) && !cast(D)->isGnuLocal()) { + // Implicitly-generated labels may end up getting generated in an order that + // isn't strictly lexical, which breaks name lookup. Be careful to insert + // the label at the appropriate place in the identifier chain. + for (I = IdResolver.begin(D->getDeclName()); I != IEnd; ++I) { + if ((*I)->getLexicalDeclContext()->Encloses(CurContext)) + break; + } + + IdResolver.InsertDecl(I, D); + } else { + IdResolver.AddDecl(D); + } } bool Sema::isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S, Added: cfe/trunk/test/SemaCXX/goto.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/goto.cpp?rev=127623&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/goto.cpp (added) +++ cfe/trunk/test/SemaCXX/goto.cpp Mon Mar 14 16:19:51 2011 @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR9463 +double *end; +void f() { + { + int end = 0; + goto end; + end = 1; + } + + end: + return; +} + +void g() { + end = 1; // expected-error{{assigning to 'double *' from incompatible type 'int'}} +} From joerg at bec.de Mon Mar 14 16:20:47 2011 From: joerg at bec.de (Joerg Sonnenberger) Date: Mon, 14 Mar 2011 21:20:47 -0000 Subject: [cfe-commits] r127624 - /cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt Message-ID: <20110314212047.1B1962A6C12C@llvm.org> Author: joerg Date: Mon Mar 14 16:20:46 2011 New Revision: 127624 URL: http://llvm.org/viewvc/llvm-project?rev=127624&view=rev Log: Sort Modified: cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt Modified: cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt?rev=127624&r1=127623&r2=127624&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt Mon Mar 14 16:20:46 2011 @@ -8,19 +8,19 @@ BasicConstraintManager.cpp BasicStore.cpp BasicValueFactory.cpp + BlockCounter.cpp BugReporter.cpp BugReporterVisitors.cpp CFRefCount.cpp + CXXExprEngine.cpp CheckerContext.cpp CheckerHelpers.cpp CheckerManager.cpp + CoreEngine.cpp Environment.cpp ExplodedGraph.cpp ExprEngine.cpp FlatStore.cpp - BlockCounter.cpp - CXXExprEngine.cpp - CoreEngine.cpp GRState.cpp HTMLDiagnostics.cpp MemRegion.cpp From dgregor at apple.com Mon Mar 14 16:43:31 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 21:43:31 -0000 Subject: [cfe-commits] r127625 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/SemaObjC/auto-objective-c.m Message-ID: <20110314214331.1256E2A6C12C@llvm.org> Author: dgregor Date: Mon Mar 14 16:43:30 2011 New Revision: 127625 URL: http://llvm.org/viewvc/llvm-project?rev=127625&view=rev Log: Disable 'auto' type deduction in Objective-C. It likes 'id' a bit too much to be useful. Removed: cfe/trunk/test/SemaObjC/auto-objective-c.m Modified: cfe/trunk/lib/Parse/ParseDecl.cpp Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=127625&r1=127624&r2=127625&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Mar 14 16:43:30 2011 @@ -1249,7 +1249,7 @@ DiagID, getLang()); break; case tok::kw_auto: - if (getLang().CPlusPlus0x || getLang().ObjC2) { + if (getLang().CPlusPlus0x) { if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec, DiagID, getLang()); Removed: cfe/trunk/test/SemaObjC/auto-objective-c.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/auto-objective-c.m?rev=127624&view=auto ============================================================================== --- cfe/trunk/test/SemaObjC/auto-objective-c.m (original) +++ cfe/trunk/test/SemaObjC/auto-objective-c.m (removed) @@ -1,33 +0,0 @@ -// RUN: %clang_cc1 -x objective-c -fblocks -fsyntax-only -verify %s - - at interface I -{ - id pi; -} -- (id) Meth; - at end - -// Objective-C does not support trailing return types, so check we don't get -// the C++ diagnostic suggesting we forgot one. -auto noTrailingReturnType(); // expected-error {{'auto' not allowed in function return type}} - -typedef int (^P) (int x); - - at implementation I -- (id) Meth { - auto p = [pi Meth]; - return p; -} - -- (P) bfunc { - auto my_block = ^int (int x) {return x; }; - my_block(1); - return my_block; -} - at end - - -// rdar://9036633 -int main() { - auto int auto_i = 7; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}} -} From dgregor at apple.com Mon Mar 14 16:59:20 2011 From: dgregor at apple.com (Douglas Gregor) Date: Mon, 14 Mar 2011 14:59:20 -0700 Subject: [cfe-commits] [PATCH]Support Ubuntu Hardy & Intrepid In-Reply-To: <20110314225817.18994m16s8xg9w8p@webmail.tuwien.ac.at> References: <20110311182712.17573wkv24btqvlc@webmail.tuwien.ac.at> <119294DA-C770-4F48-B28A-7E5AFF25EA39@apple.com> <20110314225817.18994m16s8xg9w8p@webmail.tuwien.ac.at> Message-ID: <4CF0132C-A353-449B-8F75-03AE49A3B1EE@apple.com> I already forwarded it to our release manager for inclusion in 2.9. - Doug On Mar 14, 2011, at 2:58 PM, Thomas Gamper wrote: > Could it go into the release2_9 branch too? > > Thanks, > TOM > > > Quoting Douglas Gregor : > >> Committed in r127583, thanks! >> >> - Doug >> >> On Mar 11, 2011, at 9:27 AM, Thomas Gamper wrote: >> >>> >>> Hi! >>> >>> Today I did a bootstrap of clang' release2_9 branch on my Ubuntu 8.04 AMD64, I got working executables but clang was unable to find crtbeginS.o and friends during linking. Attached patch got clang working on my system, no hacks, just extensions to the existing infrastructure. >>> >>> Regards, >>> Thomas Gamper >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> cfe-commits at cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> >> > > From anton.yartsev at gmail.com Mon Mar 14 18:01:19 2011 From: anton.yartsev at gmail.com (Anton Yartsev) Date: Tue, 15 Mar 2011 02:01:19 +0300 Subject: [cfe-commits] [PATCH][Review request] correct initialization of AltiVec vectors In-Reply-To: <4D5BA715.70204@Gmail.com> References: <4CF32459.2000700@Gmail.com> <4D1BCEFC.8020303@Gmail.com> <87A3C667-726E-4C41-B463-8614B8B295D7@apple.com> <4D3F4468.1030000@Gmail.com> <400B9C54-D5E0-4B94-9A79-58997009DB9E@apple.com> <4D5BA715.70204@Gmail.com> Message-ID: <4D7E9E3F.1050201@Gmail.com> On 16.02.2011 13:29, Anton Yartsev wrote: > >> Index: lib/Sema/SemaCXXCast.cpp >> =================================================================== >> --- lib/Sema/SemaCXXCast.cpp (revision 124051) >> +++ lib/Sema/SemaCXXCast.cpp (working copy) >> @@ -1227,7 +1227,16 @@ >> >> // FIXME: Should this also apply to floating point types? >> bool srcIsScalar = SrcType->isIntegralType(Self.Context); >> bool destIsScalar = DestType->isIntegralType(Self.Context); >> - >> + >> + // Case of AltiVec vector initialization with a single literal >> + if (destIsVector >> +&& DestType->getAs()->getVectorKind() == >> + VectorType::AltiVecVector >> +&& (SrcType->isIntegerType() || SrcType->isFloatingType())) { >> + Kind = CK_VectorSplat; >> + return TC_Success; >> + } >> + >> // Check if this is a cast between a vector and something else. >> if (!(srcIsScalar&& destIsVector)&& !(srcIsVector&& >> destIsScalar)&& >> !(srcIsVector&& destIsVector)) >> >> What's your motivation for this change? This is along the >> reinterpret_cast path, and reinterpret_cast is meant only for >> conversions that take the same bits and interpret them in a different >> way. A vector splat isn't such a conversion. >> >> This change basically ends up taking something that used to work in a >> reinterpret_cast---say, reinterpreting an int as a vector of 4 >> chars---and introduces an conceptual ambiguity (it could also mean a >> vector splat), then resolves it to the vector splat. Is this really >> what you intended? >> > That was the wrong place for the code, moved to the right one > >> @@ -4885,18 +4893,45 @@ >> >> } >> if (PE->getNumExprs() == 1) { >> if (!PE->getExpr(0)->getType()->isVectorType()) >> - isAltiVecLiteral = true; >> + isVectorLiteral = true; >> } >> else >> - isAltiVecLiteral = true; >> + isVectorLiteral = true; >> } >> >> - // If this is an altivec initializer, '(' type ')' '(' init, ..., >> init ')' >> + // If this is a vector initializer, '(' type ')' '(' init, ..., >> init ')' >> // then handle it as such. >> - if (isAltiVecLiteral) { >> + if (isVectorLiteral) { >> llvm::SmallVector initExprs; >> - for (unsigned i = 0, e = PE->getNumExprs(); i != e; ++i) >> - initExprs.push_back(PE->getExpr(i)); >> + // '(...)' form of vector initialization in AltiVec: the number of >> + // initializers must be one or must match the size of the vector. >> + // If a single value is specified in the initializer then it >> will be >> + // replicated to all the components of the vector >> + if (Ty->getAs()->getVectorKind() == >> + VectorType::AltiVecVector) { >> + unsigned numElems = Ty->getAs()->getNumElements(); >> + // The number of initializers must be one or must match the >> size of the >> + // vector. If a single value is specified in the initializer >> then it will >> + // be replicated to all the components of the vector >> + if (PE->getNumExprs() == 1) { >> + QualType ElemTy = Ty->getAs()->getElementType(); >> + Expr *Literal = PE->getExpr(0); >> + ImpCastExprToType(Literal, ElemTy, >> + PrepareScalarCast(*this, Literal, ElemTy)); >> + return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, >> Literal); >> + } >> >> This looks good. One question: if we have a one-element vector, >> shouldn't this be handled as an initializer of that one-element >> vector rather than a splat? I expect that code generation will be >> roughly the same, but it would be cleaner to represent this as an >> initialization. > There are no one-element vector types in AltiVec. > > Initialization is cleaner, but it gives a little bit complicated > bitcode. Transforming the following code > > int main() { > vector int v = (vector int)(1); > return 0; > } > > with the solution using initialization we obtain > > define i32 @main() nounwind { > entry: > %retval = alloca i32, align 4 > %v = alloca <4 x i32>, align 16 > %.compoundliteral = alloca <4 x i32>, align 16 > store i32 0, i32* %retval > store <4 x i32> , <4 x i32>* > %.compoundliteral > %tmp = load <4 x i32>* %.compoundliteral > store <4 x i32> %tmp, <4 x i32>* %v, align 16 > ret i32 0 > } > > and with the solution using cast - > > define i32 @main() nounwind { > entry: > %retval = alloca i32, align 4 > %v = alloca <4 x i32>, align 16 > store i32 0, i32* %retval > store <4 x i32> , <4 x i32>* %v, align 16 > ret i32 0 > } > >> There seem to be a bunch of whitespace changes in the diff for >> test/CodeGen/builtins-ppc-altivec.c, which make it hard to see any >> actual changes. > This are not whitespace changes - the bitcode changed > > Attached are fixed patches performed one as cast and another as > initialization, please review and chose! > Ping! -- Anton From icicle at mail.cg.tuwien.ac.at Mon Mar 14 16:58:17 2011 From: icicle at mail.cg.tuwien.ac.at (Thomas Gamper) Date: Mon, 14 Mar 2011 22:58:17 +0100 Subject: [cfe-commits] [PATCH]Support Ubuntu Hardy & Intrepid In-Reply-To: <119294DA-C770-4F48-B28A-7E5AFF25EA39@apple.com> References: <20110311182712.17573wkv24btqvlc@webmail.tuwien.ac.at> <119294DA-C770-4F48-B28A-7E5AFF25EA39@apple.com> Message-ID: <20110314225817.18994m16s8xg9w8p@webmail.tuwien.ac.at> Could it go into the release2_9 branch too? Thanks, TOM Quoting Douglas Gregor : > Committed in r127583, thanks! > > - Doug > > On Mar 11, 2011, at 9:27 AM, Thomas Gamper wrote: > >> >> Hi! >> >> Today I did a bootstrap of clang' release2_9 branch on my Ubuntu >> 8.04 AMD64, I got working executables but clang was unable to find >> crtbeginS.o and friends during linking. Attached patch got clang >> working on my system, no hacks, just extensions to the existing >> infrastructure. >> >> Regards, >> Thomas Gamper >> >> _______________________________________________ >> cfe-commits mailing list >> cfe-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > From pichet2000 at gmail.com Mon Mar 14 18:19:08 2011 From: pichet2000 at gmail.com (Francois Pichet) Date: Mon, 14 Mar 2011 19:19:08 -0400 Subject: [cfe-commits] r127617 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp In-Reply-To: <20110314203321.1D6DD2A6C12C@llvm.org> References: <20110314203321.1D6DD2A6C12C@llvm.org> Message-ID: On Mon, Mar 14, 2011 at 4:33 PM, Sebastian Redl wrote: > Author: cornedbee > Date: Mon Mar 14 15:33:20 2011 > New Revision: 127617 > > URL: http://llvm.org/viewvc/llvm-project?rev=127617&view=rev > Log: > Code generation for noexcept. > > Added: > ? ?cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp > ? ?cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp Hi, these two tests fail on MSVC 2010. any idea why? here the log: 3> FAIL: Clang :: CXX/except/except.spec/p9-noexcept.cpp (174 of 368) 3> ******************** TEST 'Clang :: CXX/except/except.spec/p9-noexcept.cpp' FAILED ******************** 3> Script: 3> -- 3> C:/dev/llvm/llvm_trunk/bin/Release/clang.EXE -cc1 C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-noexcept.cpp -std=c++0x -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-noexcept.cpp 3> -- 3> Exit Code: 1 3> Command Output (stdout): 3> -- 3> Command 0: "C:/dev/llvm/llvm_trunk/bin/Release/clang.EXE" "-cc1" "C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-noexcept.cpp" "-std=c++0x" "-triple=x86_64-apple-darwin10" "-emit-llvm" "-o" "-" "-fcxx-exceptions" "-fexceptions" 3> Command 0 Result: 0 3> Command 0 Output: 3> 3> 3> Command 0 Stderr: 3> 3> 3> Command 1: "FileCheck" "C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-noexcept.cpp" 3> Command 1 Result: 1 3> Command 1 Output: 3> 3> 3> Command 1 Stderr: 3> C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-noexcept.cpp:10:11: error: expected string not found in input 3> // CHECK: terminate.lpad: 3> ^ 3> :7:2: note: scanning from here 3> to label %1 unwind label %2 3> ^ 3> :15:18: note: possible intended match here 3> call void @_ZSt9terminatev() noreturn nounwind 3> ^ 3> 3> 3> -- 3> 3> ******************** 3> FAIL: Clang :: CXX/except/except.spec/p9-dynamic.cpp (176 of 368) 3> ******************** TEST 'Clang :: CXX/except/except.spec/p9-dynamic.cpp' FAILED ******************** 3> Script: 3> -- 3> C:/dev/llvm/llvm_trunk/bin/Release/clang.EXE -cc1 C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-dynamic.cpp -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-dynamic.cpp 3> -- 3> Exit Code: 1 3> Command Output (stdout): 3> -- 3> Command 0: "C:/dev/llvm/llvm_trunk/bin/Release/clang.EXE" "-cc1" "C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-dynamic.cpp" "-triple=x86_64-apple-darwin10" "-emit-llvm" "-o" "-" "-fcxx-exceptions" "-fexceptions" 3> Command 0 Result: 0 3> Command 0 Output: 3> 3> 3> Command 0 Stderr: 3> 3> 3> Command 1: "FileCheck" "C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-dynamic.cpp" 3> Command 1 Result: 1 3> Command 1 Output: 3> 3> 3> Command 1 Stderr: 3> C:\dev\llvm\llvm_trunk\tools\clang\test\CXX\except\except.spec\p9-dynamic.cpp:10:11: error: expected string not found in input 3> // CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind 3> ^ 3> :10:2: note: scanning from here 3> to label %2 unwind label %3 3> ^ 3> :18:2: note: possible intended match here 3> %5 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %4, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind 3> ^ 3> 3> 3> -- 3> 3> ******************** 3> 3> Testing Time: 3.53s 3> ******************** 3> Failing Tests (2): 3> Clang :: CXX/except/except.spec/p9-dynamic.cpp 3> Clang :: CXX/except/except.spec/p9-noexcept.cpp From joerg at britannica.bec.de Mon Mar 14 18:19:06 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Tue, 15 Mar 2011 00:19:06 +0100 Subject: [cfe-commits] Inferring host triple from command name Message-ID: <20110314231906.GA1690@britannica.bec.de> Hi all, the attached patch allows inferring the host triple from the command name, making it easier to integrate in a cross-compiling toolchain. To use this, simply create a symlink from clang e.g. to x86_64-netbsd-clang and the latter will default to the x86_64--netbsd target. Joerg -------------- next part -------------- A non-text attachment was scrubbed... Name: driver-target.diff Type: text/x-diff Size: 2395 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110315/18cf72db/attachment.bin From stoklund at 2pi.dk Mon Mar 14 19:04:47 2011 From: stoklund at 2pi.dk (Jakob Stoklund Olesen) Date: Mon, 14 Mar 2011 17:04:47 -0700 Subject: [cfe-commits] r127617 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp In-Reply-To: <20110314203321.1D6DD2A6C12C@llvm.org> References: <20110314203321.1D6DD2A6C12C@llvm.org> Message-ID: <201031D7-35EC-4F00-ABEA-F9D1D76EBDA7@2pi.dk> On Mar 14, 2011, at 1:33 PM, Sebastian Redl wrote: > Author: cornedbee > Date: Mon Mar 14 15:33:20 2011 > New Revision: 127617 > > URL: http://llvm.org/viewvc/llvm-project?rev=127617&view=rev > Log: > Code generation for noexcept. > > Added: > cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp > cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp These tests are failing in a release (-Asserts) build: ******************** TEST 'Clang :: CXX/except/except.spec/p9-noexcept.cpp' FAILED ******************** Script: -- /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/clang-build/Release/bin/clang -cc1 /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/llvm/tools/clang/test/CXX/except/except.spec/p9-noexcept.cpp -std=c++0x -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/llvm/tools/clang/test/CXX/except/except.spec/p9-noexcept.cpp -- Exit Code: 1 Command Output (stderr): -- /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/llvm/tools/clang/test/CXX/except/except.spec/p9-noexcept.cpp:10:11: error: expected string not found in input // CHECK: terminate.lpad: ^ :7:2: note: scanning from here to label %1 unwind label %2 ^ :15:18: note: possible intended match here call void @_ZSt9terminatev() noreturn nounwind ^ -- ******************** PASS: Clang :: CXX/expr/expr.cast/p4.cpp (317 of 2936) FAIL: Clang :: CXX/except/except.spec/p9-dynamic.cpp (318 of 2936) ******************** TEST 'Clang :: CXX/except/except.spec/p9-dynamic.cpp' FAILED ******************** Script: -- /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/clang-build/Release/bin/clang -cc1 /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/llvm/tools/clang/test/CXX/except/except.spec/p9-dynamic.cpp -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/llvm/tools/clang/test/CXX/except/except.spec/p9-dynamic.cpp -- Exit Code: 1 Command Output (stderr): -- /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-R/llvm/tools/clang/test/CXX/except/except.spec/p9-dynamic.cpp:10:11: error: expected string not found in input // CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind ^ :10:2: note: scanning from here to label %2 unwind label %3 ^ :18:2: note: possible intended match here %5 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %4, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind ^ -- ******************** From echristo at apple.com Mon Mar 14 19:14:24 2011 From: echristo at apple.com (Eric Christopher) Date: Mon, 14 Mar 2011 17:14:24 -0700 Subject: [cfe-commits] Inferring host triple from command name In-Reply-To: <20110314231906.GA1690@britannica.bec.de> References: <20110314231906.GA1690@britannica.bec.de> Message-ID: <45E9532F-CD5D-4FA0-A770-009130371B3F@apple.com> On Mar 14, 2011, at 4:19 PM, Joerg Sonnenberger wrote: > Hi all, > the attached patch allows inferring the host triple from the command > name, making it easier to integrate in a cross-compiling toolchain. > To use this, simply create a symlink from clang e.g. to > x86_64-netbsd-clang and the latter will default to the x86_64--netbsd > target. > > Joerg That's kinda cool. I have no objections. -eric From stoklund at 2pi.dk Mon Mar 14 19:18:21 2011 From: stoklund at 2pi.dk (Jakob Stoklund Olesen) Date: Tue, 15 Mar 2011 00:18:21 -0000 Subject: [cfe-commits] r127635 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp Message-ID: <20110315001821.66DF12A6C12C@llvm.org> Author: stoklund Date: Mon Mar 14 19:18:21 2011 New Revision: 127635 URL: http://llvm.org/viewvc/llvm-project?rev=127635&view=rev Log: Revert r127617: "Code generation for noexcept." The tests fail in a -Asserts build. Removed: cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp Modified: cfe/trunk/lib/CodeGen/CGException.cpp Modified: cfe/trunk/lib/CodeGen/CGException.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=127635&r1=127634&r2=127635&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGException.cpp (original) +++ cfe/trunk/lib/CodeGen/CGException.cpp Mon Mar 14 19:18:21 2011 @@ -449,23 +449,19 @@ if (Proto == 0) return; - ExceptionSpecificationType EST = Proto->getExceptionSpecType(); - if (isNoexceptExceptionSpec(EST)) { - if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) { - // noexcept functions are simple terminate scopes. - EHStack.pushTerminate(); - } - } else if (EST == EST_Dynamic || EST == EST_DynamicNone) { - unsigned NumExceptions = Proto->getNumExceptions(); - EHFilterScope *Filter = EHStack.pushFilter(NumExceptions); - - for (unsigned I = 0; I != NumExceptions; ++I) { - QualType Ty = Proto->getExceptionType(I); - QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType(); - llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType, - /*ForEH=*/true); - Filter->setFilter(I, EHType); - } + // FIXME: What about noexcept? + if (!Proto->hasDynamicExceptionSpec()) + return; + + unsigned NumExceptions = Proto->getNumExceptions(); + EHFilterScope *Filter = EHStack.pushFilter(NumExceptions); + + for (unsigned I = 0; I != NumExceptions; ++I) { + QualType Ty = Proto->getExceptionType(I); + QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType(); + llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType, + /*ForEH=*/true); + Filter->setFilter(I, EHType); } } @@ -480,14 +476,10 @@ if (Proto == 0) return; - ExceptionSpecificationType EST = Proto->getExceptionSpecType(); - if (isNoexceptExceptionSpec(EST)) { - if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) { - EHStack.popTerminate(); - } - } else if (EST == EST_Dynamic || EST == EST_DynamicNone) { - EHStack.popFilter(); - } + if (!Proto->hasDynamicExceptionSpec()) + return; + + EHStack.popFilter(); } void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) { Removed: cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp?rev=127634&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp (original) +++ cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp (removed) @@ -1,12 +0,0 @@ -// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s - -void external(); - -void target() throw(int) -{ - // CHECK: invoke void @_Z8externalv() - external(); -} -// CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind -// CHECK: ehspec.unexpected: -// CHECK: call void @__cxa_call_unexpected(i8* %1) noreturn Removed: cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp?rev=127634&view=auto ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp (original) +++ cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp (removed) @@ -1,19 +0,0 @@ -// RUN: %clang_cc1 %s -std=c++0x -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s - -void external(); - -void target() noexcept -{ - // CHECK: invoke void @_Z8externalv() - external(); -} -// CHECK: terminate.lpad: -// CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) nounwind -// CHECK-NEXT: call void @_ZSt9terminatev() noreturn nounwind -// CHECK-NEXT: unreachable - -void reverse() noexcept(false) -{ - // CHECK: call void @_Z8externalv() - external(); -} From clattner at apple.com Mon Mar 14 19:50:28 2011 From: clattner at apple.com (Chris Lattner) Date: Mon, 14 Mar 2011 17:50:28 -0700 Subject: [cfe-commits] r127594 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c In-Reply-To: <4D7E8562.7000102@gmail.com> References: <20110314175500.819F62A6C12C@llvm.org> <0637D520-A391-4215-A854-D1E0C89D0FC0@apple.com> <4D7E8562.7000102@gmail.com> Message-ID: <4429C2B4-5275-44DA-A454-E4D65C2DA802@apple.com> On Mar 14, 2011, at 2:15 PM, Rafael Avila de Espindola wrote: >> >> Private is probably the wrong answer, but I think that LinkerPrivate >> is the right answer. Does LinkerPrivate work for libxul? >> > > It does, thanks! > I have updated the file. Thanks! From clattner at apple.com Mon Mar 14 19:51:18 2011 From: clattner at apple.com (Chris Lattner) Date: Mon, 14 Mar 2011 17:51:18 -0700 Subject: [cfe-commits] r127622 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c In-Reply-To: <20110314210820.0F84F2A6C12C@llvm.org> References: <20110314210820.0F84F2A6C12C@llvm.org> Message-ID: <2E2D9369-3492-40AE-B67D-BAC158AD098B@apple.com> Hi Bill, please pull this into 2.9. The patch will probably conflict with the change from private -> internal linkage. -Chris On Mar 14, 2011, at 2:08 PM, Rafael Espindola wrote: > Author: rafael > Date: Mon Mar 14 16:08:19 2011 > New Revision: 127622 > > URL: http://llvm.org/viewvc/llvm-project?rev=127622&view=rev > Log: > Switch from internal to linker_private linkage, it is sufficient to please the new linker. > > Modified: > cfe/trunk/lib/CodeGen/CodeGenModule.cpp > cfe/trunk/test/CodeGen/darwin-string-literals.c > > Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127622&r1=127621&r2=127622&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) > +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Mar 14 16:08:19 2011 > @@ -1672,7 +1672,7 @@ > // FIXME: With OS X ld 123.2 (xcode 4) and LTO we would get a linker error > // when using private linkage. It is not clear if this is a bug in ld > // or a reasonable new restriction. > - Linkage = llvm::GlobalValue::InternalLinkage; > + Linkage = llvm::GlobalValue::LinkerPrivateLinkage; > isConstant = !Features.WritableStrings; > } > > > Modified: cfe/trunk/test/CodeGen/darwin-string-literals.c > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/darwin-string-literals.c?rev=127622&r1=127621&r2=127622&view=diff > ============================================================================== > --- cfe/trunk/test/CodeGen/darwin-string-literals.c (original) > +++ cfe/trunk/test/CodeGen/darwin-string-literals.c Mon Mar 14 16:08:19 2011 > @@ -1,13 +1,13 @@ > // RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix LSB %s > > // CHECK-LSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" > -// CHECK-LSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" > +// CHECK-LSB: @.str1 = linker_private unnamed_addr constant [8 x i8] c"string1\00" > // CHECK-LSB: @.str2 = internal unnamed_addr constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", align 2 > > // RUN: %clang_cc1 -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s > > // CHECK-MSB: @.str = private unnamed_addr constant [8 x i8] c"string0\00" > -// CHECK-MSB: @.str1 = internal unnamed_addr constant [8 x i8] c"string1\00" > +// CHECK-MSB: @.str1 = linker_private unnamed_addr constant [8 x i8] c"string1\00" > // CHECK-MSB: @.str2 = internal unnamed_addr constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", align 2 > > const char *g0 = "string0"; > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From akyrtzi at gmail.com Mon Mar 14 19:47:44 2011 From: akyrtzi at gmail.com (Argyrios Kyrtzidis) Date: Tue, 15 Mar 2011 00:47:44 -0000 Subject: [cfe-commits] r127639 - /cfe/trunk/lib/Basic/FileManager.cpp Message-ID: <20110315004744.95F892A6C12C@llvm.org> Author: akirtzidis Date: Mon Mar 14 19:47:44 2011 New Revision: 127639 URL: http://llvm.org/viewvc/llvm-project?rev=127639&view=rev Log: Stop leaking file descriptors. After the open+fstat optimization, files were already opened for FileManager::getBufferForFile() and we closed them after reading them. The problem was that when -working-directory was passed, the code path that actually reuses & closes the already opened file descriptor was not followed. Modified: cfe/trunk/lib/Basic/FileManager.cpp Modified: cfe/trunk/lib/Basic/FileManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=127639&r1=127638&r2=127639&view=diff ============================================================================== --- cfe/trunk/lib/Basic/FileManager.cpp (original) +++ cfe/trunk/lib/Basic/FileManager.cpp Mon Mar 14 19:47:44 2011 @@ -466,21 +466,23 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) { llvm::OwningPtr Result; llvm::error_code ec; - if (FileSystemOpts.WorkingDir.empty()) { - const char *Filename = Entry->getName(); - // If the file is already open, use the open file descriptor. - if (Entry->FD != -1) { - ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result, - Entry->getSize()); - if (ErrorStr) - *ErrorStr = ec.message(); - - close(Entry->FD); - Entry->FD = -1; - return Result.take(); - } - // Otherwise, open the file. + const char *Filename = Entry->getName(); + // If the file is already open, use the open file descriptor. + if (Entry->FD != -1) { + ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result, + Entry->getSize()); + if (ErrorStr) + *ErrorStr = ec.message(); + + close(Entry->FD); + Entry->FD = -1; + return Result.take(); + } + + // Otherwise, open the file. + + if (FileSystemOpts.WorkingDir.empty()) { ec = llvm::MemoryBuffer::getFile(Filename, Result, Entry->getSize()); if (ec && ErrorStr) *ErrorStr = ec.message(); From kd at kendyck.com Mon Mar 14 20:09:02 2011 From: kd at kendyck.com (Ken Dyck) Date: Tue, 15 Mar 2011 01:09:02 -0000 Subject: [cfe-commits] r127641 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110315010902.C2DA82A6C12C@llvm.org> Author: kjdyck Date: Mon Mar 14 20:09:02 2011 New Revision: 127641 URL: http://llvm.org/viewvc/llvm-project?rev=127641&view=rev Log: Introduce a CharUnits FieldOffsetInChars variable in AppendField() to replace some uses of FieldOffsetInBytes. The remaining uses of FieldOffsetInBytes will be replaced once NextFieldOffsetInBytes is converted to CharUnits. No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127641&r1=127640&r2=127641&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Mon Mar 14 20:09:02 2011 @@ -77,7 +77,11 @@ bool ConstStructBuilder:: AppendField(const FieldDecl *Field, uint64_t FieldOffset, llvm::Constant *InitCst) { - uint64_t FieldOffsetInBytes = FieldOffset / 8; + + const ASTContext &Context = CGM.getContext(); + + CharUnits FieldOffsetInChars = Context.toCharUnitsFromBits(FieldOffset); + uint64_t FieldOffsetInBytes = FieldOffsetInChars.getQuantity(); assert(NextFieldOffsetInBytes <= FieldOffsetInBytes && "Field offset mismatch!"); @@ -100,9 +104,9 @@ if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) { // We need to append padding. AppendPadding( - CharUnits::fromQuantity(FieldOffsetInBytes - NextFieldOffsetInBytes)); + FieldOffsetInChars - CharUnits::fromQuantity(NextFieldOffsetInBytes)); - assert(NextFieldOffsetInBytes == FieldOffsetInBytes && + assert(NextFieldOffsetInBytes == FieldOffsetInChars.getQuantity() && "Did not add enough padding!"); AlignedNextFieldOffsetInBytes = NextFieldOffsetInBytes; From joerg at britannica.bec.de Mon Mar 14 20:29:17 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Tue, 15 Mar 2011 02:29:17 +0100 Subject: [cfe-commits] Inferring host triple from command name In-Reply-To: <20110314231906.GA1690@britannica.bec.de> References: <20110314231906.GA1690@britannica.bec.de> Message-ID: <20110315012917.GA24530@britannica.bec.de> On Tue, Mar 15, 2011 at 12:19:06AM +0100, Joerg Sonnenberger wrote: > the attached patch allows inferring the host triple from the command > name, making it easier to integrate in a cross-compiling toolchain. > To use this, simply create a symlink from clang e.g. to > x86_64-netbsd-clang and the latter will default to the x86_64--netbsd > target. Of course, both the rsplit and the TargetRegistry::lookup don't work as expected. Attached patch makes sure that a bare clang actually works. This still has the problem that e.g. x86_64-netbsd-clang-cpp doesn't work as expected (at least for me), since TargetRegistry::lookup happily accepts "x86_64-netbsd-clang" as triple. One option would be to move to a different separator (e.g. ::). Suggestions? Joerg -------------- next part -------------- A non-text attachment was scrubbed... Name: driver-target.diff Type: text/x-diff Size: 2619 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110315/86e49523/attachment.bin From geek4civic at gmail.com Mon Mar 14 21:32:36 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Tue, 15 Mar 2011 02:32:36 -0000 Subject: [cfe-commits] r127652 - /cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Message-ID: <20110315023236.A85DD2A6C12C@llvm.org> Author: chapuni Date: Mon Mar 14 21:32:36 2011 New Revision: 127652 URL: http://llvm.org/viewvc/llvm-project?rev=127652&view=rev Log: lib/Frontend/InitHeaderSearch.cpp: Introduce AddMinGW64CXXPaths(Base) for x86_64-w64-mingw32. Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=127652&r1=127651&r2=127652&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original) +++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Mon Mar 14 21:32:36 2011 @@ -76,6 +76,10 @@ llvm::StringRef Arch, llvm::StringRef Version); + /// AddMinGW64CXXPaths - Add the necessary paths to support + /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. + void AddMinGW64CXXPaths(llvm::StringRef Base); + /// AddDelimitedPaths - Add a list of paths delimited by the system PATH /// separator. The processing follows that of the CPATH variable for gcc. void AddDelimitedPaths(llvm::StringRef String); @@ -207,6 +211,15 @@ CXXSystem, true, false, false); } +void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base) { + AddPath(Base, + CXXSystem, true, false, false); + AddPath(Base + "/x86_64-w64-mingw32", + CXXSystem, true, false, false); + AddPath(Base + "/backward", + CXXSystem, true, false, false); +} + // FIXME: This probably should goto to some platform utils place. #ifdef _MSC_VER @@ -534,6 +547,10 @@ AddPath("/usr/include/w32api", System, true, false, false); break; case llvm::Triple::MinGW32: + // FIXME: We should be aware of i686-w64-mingw32. + if (triple.getArch() == llvm::Triple::x86_64) + AddPath("c:/mingw/x86_64-w64-mingw32/include", + System, true, false, false); AddPath("/mingw/include", System, true, false, false); AddPath("c:/mingw/include", System, true, false, false); break; @@ -571,18 +588,13 @@ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4"); break; case llvm::Triple::MinGW32: - // mingw-w64-20110207 - AddPath("c:/MinGW/include/c++/4.5.3", CXXSystem, true, false, false); - AddPath("c:/MinGW/include/c++/4.5.3/x86_64-w64-mingw32", CXXSystem, true, - false, false); - AddPath("c:/MinGW/include/c++/4.5.3/backward", CXXSystem, true, false, - false); - // mingw-w64-20101129 - AddPath("c:/MinGW/include/c++/4.5.2", CXXSystem, true, false, false); - AddPath("c:/MinGW/include/c++/4.5.2/x86_64-w64-mingw32", CXXSystem, true, - false, false); - AddPath("c:/MinGW/include/c++/4.5.2/backward", CXXSystem, true, false, - false); + // FIXME: We should be aware of i686-w64-mingw32. + if (triple.getArch() == llvm::Triple::x86_64) { + // mingw-w64-20110207 + AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.3"); + // mingw-w64-20101129 + AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.2"); + } // Try gcc 4.5.2 (MSYS) AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); // Try gcc 4.5.0 From geek4civic at gmail.com Mon Mar 14 21:32:43 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Tue, 15 Mar 2011 02:32:43 -0000 Subject: [cfe-commits] r127654 - /cfe/trunk/lib/Headers/mm_malloc.h Message-ID: <20110315023243.A43F62A6C12C@llvm.org> Author: chapuni Date: Mon Mar 14 21:32:43 2011 New Revision: 127654 URL: http://llvm.org/viewvc/llvm-project?rev=127654&view=rev Log: lib/Headers/mm_malloc.h: On Windows, we can expect _mm_malloc would be provided as macro by . Modified: cfe/trunk/lib/Headers/mm_malloc.h Modified: cfe/trunk/lib/Headers/mm_malloc.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/mm_malloc.h?rev=127654&r1=127653&r2=127654&view=diff ============================================================================== --- cfe/trunk/lib/Headers/mm_malloc.h (original) +++ cfe/trunk/lib/Headers/mm_malloc.h Mon Mar 14 21:32:43 2011 @@ -40,6 +40,7 @@ #endif #endif +#if !(defined(_WIN32) && defined(_mm_malloc)) static __inline__ void *__attribute__((__always_inline__, __nodebug__, __malloc__)) _mm_malloc(size_t size, size_t align) @@ -67,5 +68,6 @@ { free(p); } +#endif #endif /* __MM_MALLOC_H */ From geek4civic at gmail.com Mon Mar 14 21:32:50 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Tue, 15 Mar 2011 02:32:50 -0000 Subject: [cfe-commits] r127655 - /cfe/trunk/lib/Basic/Targets.cpp Message-ID: <20110315023250.650372A6C12D@llvm.org> Author: chapuni Date: Mon Mar 14 21:32:50 2011 New Revision: 127655 URL: http://llvm.org/viewvc/llvm-project?rev=127655&view=rev Log: lib/Basic/Targets.cpp: __declspec(attr) should be provided on mingw as macro, alias of __attribute__. On mingw without -fms-extensions, we can provide "as-is" __declspec. Modified: cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=127655&r1=127654&r2=127655&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Mon Mar 14 21:32:50 2011 @@ -1481,7 +1481,15 @@ Builder.defineMacro("_X86_"); Builder.defineMacro("__MSVCRT__"); Builder.defineMacro("__MINGW32__"); - Builder.defineMacro("__declspec", "__declspec"); + + // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). + // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. + if (Opts.Microsoft) + // Provide "as-is" __declspec. + Builder.defineMacro("__declspec", "__declspec"); + else + // Provide alias of __attribute__ like mingw32-gcc. + Builder.defineMacro("__declspec(a)", "__attribute__((a))"); } }; } // end anonymous namespace @@ -1631,7 +1639,15 @@ Builder.defineMacro("__MSVCRT__"); Builder.defineMacro("__MINGW32__"); Builder.defineMacro("__MINGW64__"); - Builder.defineMacro("__declspec", "__declspec"); + + // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). + // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. + if (Opts.Microsoft) + // Provide "as-is" __declspec. + Builder.defineMacro("__declspec", "__declspec"); + else + // Provide alias of __attribute__ like mingw32-gcc. + Builder.defineMacro("__declspec(a)", "__attribute__((a))"); } }; } // end anonymous namespace From geek4civic at gmail.com Mon Mar 14 21:40:20 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Tue, 15 Mar 2011 11:40:20 +0900 Subject: [cfe-commits] [PATCH] lib/Basic/Targets.cpp: __declspec(attr) should be provided on mingw as macro, alias of __attribute__. In-Reply-To: References: Message-ID: Committed in r127655, with adding a comment. On Tue, Mar 8, 2011 at 9:54 PM, NAKAMURA Takumi wrote: > --- > ?lib/Basic/Targets.cpp | ? 10 ++++++++-- > ?1 files changed, 8 insertions(+), 2 deletions(-) > > --- > On gcc on cygming, __declspec(attr) is always defined as > __attribute__((attr)) regardless of -fms-extensions. > (it seems gcc's cc1 would not understand __declspec) > I am dubious __declspec might be provided as keyword w/o > -fms-extensions, not sure. > Please give me any comments, thank you. > > ...Takumi > From geek4civic at gmail.com Mon Mar 14 21:41:17 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Tue, 15 Mar 2011 11:41:17 +0900 Subject: [cfe-commits] [PATCH] lib/Headers/mm_malloc.h: On Windows, we can expect _mm_malloc would be provided as macro by . In-Reply-To: References: Message-ID: Committed in r127654. ...Takumi On Tue, Mar 8, 2011 at 9:49 PM, NAKAMURA Takumi wrote: > --- > ?lib/Headers/mm_malloc.h | ? ?2 ++ > ?1 files changed, 2 insertions(+), 0 deletions(-) > From kremenek at apple.com Mon Mar 14 22:17:01 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 03:17:01 -0000 Subject: [cfe-commits] r127656 - in /cfe/trunk: include/clang/Analysis/Analyses/UninitializedValues.h lib/Analysis/CMakeLists.txt lib/Analysis/UninitializedValues.cpp test/Analysis/conditional-op-missing-lhs.c test/Analysis/uninit-vals.c test/Sema/uninit-variables.c Message-ID: <20110315031701.A29362A6C12C@llvm.org> Author: kremenek Date: Mon Mar 14 22:17:01 2011 New Revision: 127656 URL: http://llvm.org/viewvc/llvm-project?rev=127656&view=rev Log: Remove old UninitializedValues analysis. Removed: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h cfe/trunk/lib/Analysis/UninitializedValues.cpp cfe/trunk/test/Analysis/conditional-op-missing-lhs.c cfe/trunk/test/Analysis/uninit-vals.c Modified: cfe/trunk/lib/Analysis/CMakeLists.txt cfe/trunk/test/Sema/uninit-variables.c Removed: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h?rev=127655&view=auto ============================================================================== --- cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h (original) +++ cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h (removed) @@ -1,77 +0,0 @@ -//===- UninitializedValues.h - unintialized values analysis ----*- C++ --*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the interface for the Unintialized Values analysis, -// a flow-sensitive analysis that detects when variable values are unintialized. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_UNITVALS_H -#define LLVM_CLANG_UNITVALS_H - -#include "clang/Analysis/Support/BlkExprDeclBitVector.h" -#include "clang/Analysis/FlowSensitive/DataflowValues.h" - -namespace clang { - - class BlockVarDecl; - class Expr; - class DeclRefExpr; - class VarDecl; - -/// UninitializedValues_ValueTypes - Utility class to wrap type declarations -/// for dataflow values and dataflow analysis state for the -/// Unitialized Values analysis. -class UninitializedValues_ValueTypes { -public: - - struct ObserverTy; - - struct AnalysisDataTy : public StmtDeclBitVector_Types::AnalysisDataTy { - AnalysisDataTy() : Observer(NULL), FullUninitTaint(true) {} - virtual ~AnalysisDataTy() {} - - ObserverTy* Observer; - bool FullUninitTaint; - }; - - typedef StmtDeclBitVector_Types::ValTy ValTy; - - //===--------------------------------------------------------------------===// - // ObserverTy - Observer for querying DeclRefExprs that use an uninitalized - // value. - //===--------------------------------------------------------------------===// - - struct ObserverTy { - virtual ~ObserverTy(); - virtual void ObserveDeclRefExpr(ValTy& Val, AnalysisDataTy& AD, - DeclRefExpr* DR, VarDecl* VD) = 0; - }; -}; - -/// UninitializedValues - Objects of this class encapsulate dataflow analysis -/// information regarding what variable declarations in a function are -/// potentially unintialized. -class UninitializedValues : - public DataflowValues { -public: - typedef UninitializedValues_ValueTypes::ObserverTy ObserverTy; - - UninitializedValues(CFG &cfg) { getAnalysisData().setCFG(cfg); } - - /// IntializeValues - Create initial dataflow values and meta data for - /// a given CFG. This is intended to be called by the dataflow solver. - void InitializeValues(const CFG& cfg); -}; - - -void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags, - bool FullUninitTaint=false); -} // end namespace clang -#endif Modified: cfe/trunk/lib/Analysis/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CMakeLists.txt?rev=127656&r1=127655&r2=127656&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/CMakeLists.txt (original) +++ cfe/trunk/lib/Analysis/CMakeLists.txt Mon Mar 14 22:17:01 2011 @@ -12,7 +12,6 @@ PseudoConstantAnalysis.cpp ReachableCode.cpp ScanfFormatString.cpp - UninitializedValues.cpp UninitializedValuesV2.cpp ) Removed: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127655&view=auto ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp (removed) @@ -1,317 +0,0 @@ -//==- UninitializedValues.cpp - Find Uninitialized Values -------*- C++ --*-==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements Uninitialized Values analysis for source-level CFGs. -// -//===----------------------------------------------------------------------===// - -#include "clang/Analysis/Analyses/UninitializedValues.h" -#include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h" -#include "clang/Analysis/AnalysisDiagnostic.h" -#include "clang/AST/ASTContext.h" -#include "clang/Analysis/FlowSensitive/DataflowSolver.h" - -#include "llvm/ADT/SmallPtrSet.h" - -using namespace clang; - -//===----------------------------------------------------------------------===// -// Dataflow initialization logic. -//===----------------------------------------------------------------------===// - -namespace { - -class RegisterDecls - : public CFGRecStmtDeclVisitor { - - UninitializedValues::AnalysisDataTy& AD; -public: - RegisterDecls(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {} - - void VisitVarDecl(VarDecl* VD) { AD.Register(VD); } - CFG& getCFG() { return AD.getCFG(); } -}; - -} // end anonymous namespace - -void UninitializedValues::InitializeValues(const CFG& cfg) { - RegisterDecls R(getAnalysisData()); - cfg.VisitBlockStmts(R); -} - -//===----------------------------------------------------------------------===// -// Transfer functions. -//===----------------------------------------------------------------------===// - -namespace { -class TransferFuncs - : public CFGStmtVisitor { - - UninitializedValues::ValTy V; - UninitializedValues::AnalysisDataTy& AD; -public: - TransferFuncs(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {} - - UninitializedValues::ValTy& getVal() { return V; } - CFG& getCFG() { return AD.getCFG(); } - - void SetTopValue(UninitializedValues::ValTy& X) { - X.setDeclValues(AD); - X.resetBlkExprValues(AD); - } - - bool VisitDeclRefExpr(DeclRefExpr* DR); - bool VisitBinaryOperator(BinaryOperator* B); - bool VisitUnaryOperator(UnaryOperator* U); - bool VisitStmt(Stmt* S); - bool VisitCallExpr(CallExpr* C); - bool VisitDeclStmt(DeclStmt* D); - bool VisitAbstractConditionalOperator(AbstractConditionalOperator* C); - bool BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S); - - bool Visit(Stmt *S); - bool BlockStmt_VisitExpr(Expr* E); - - void VisitTerminator(CFGBlock* B) { } - - void setCurrentBlock(const CFGBlock *block) {} -}; - -static const bool Initialized = false; -static const bool Uninitialized = true; - -bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) { - - if (VarDecl* VD = dyn_cast(DR->getDecl())) - if (VD->isLocalVarDecl()) { - - if (AD.Observer) - AD.Observer->ObserveDeclRefExpr(V, AD, DR, VD); - - // Pseudo-hack to prevent cascade of warnings. If an accessed variable - // is uninitialized, then we are already going to flag a warning for - // this variable, which a "source" of uninitialized values. - // We can otherwise do a full "taint" of uninitialized values. The - // client has both options by toggling AD.FullUninitTaint. - - if (AD.FullUninitTaint) - return V(VD,AD); - } - - return Initialized; -} - -static VarDecl* FindBlockVarDecl(Expr* E) { - - // Blast through casts and parentheses to find any DeclRefExprs that - // refer to a block VarDecl. - - if (DeclRefExpr* DR = dyn_cast(E->IgnoreParenCasts())) - if (VarDecl* VD = dyn_cast(DR->getDecl())) - if (VD->isLocalVarDecl()) return VD; - - return NULL; -} - -bool TransferFuncs::VisitBinaryOperator(BinaryOperator* B) { - - if (VarDecl* VD = FindBlockVarDecl(B->getLHS())) - if (B->isAssignmentOp()) { - if (B->getOpcode() == BO_Assign) - return V(VD,AD) = Visit(B->getRHS()); - else // Handle +=, -=, *=, etc. We do want '&', not '&&'. - return V(VD,AD) = Visit(B->getLHS()) & Visit(B->getRHS()); - } - - return VisitStmt(B); -} - -bool TransferFuncs::VisitDeclStmt(DeclStmt* S) { - for (DeclStmt::decl_iterator I=S->decl_begin(), E=S->decl_end(); I!=E; ++I) { - VarDecl *VD = dyn_cast(*I); - if (VD && VD->isLocalVarDecl()) { - if (Stmt* I = VD->getInit()) { - // Visit the subexpression to check for uses of uninitialized values, - // even if we don't propagate that value. - bool isSubExprUninit = Visit(I); - V(VD,AD) = AD.FullUninitTaint ? isSubExprUninit : Initialized; - } - else { - // Special case for declarations of array types. For things like: - // - // char x[10]; - // - // we should treat "x" as being initialized, because the variable - // "x" really refers to the memory block. Clearly x[1] is - // uninitialized, but expressions like "(char *) x" really do refer to - // an initialized value. This simple dataflow analysis does not reason - // about the contents of arrays, although it could be potentially - // extended to do so if the array were of constant size. - if (VD->getType()->isArrayType()) - V(VD,AD) = Initialized; - else - V(VD,AD) = Uninitialized; - } - } - } - return Uninitialized; // Value is never consumed. -} - -bool TransferFuncs::VisitCallExpr(CallExpr* C) { - VisitChildren(C); - return Initialized; -} - -bool TransferFuncs::VisitUnaryOperator(UnaryOperator* U) { - switch (U->getOpcode()) { - case UO_AddrOf: { - VarDecl* VD = FindBlockVarDecl(U->getSubExpr()); - if (VD && VD->isLocalVarDecl()) - return V(VD,AD) = Initialized; - break; - } - - default: - break; - } - - return Visit(U->getSubExpr()); -} - -bool -TransferFuncs::BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) { - // This represents a use of the 'collection' - bool x = Visit(S->getCollection()); - - if (x == Uninitialized) - return Uninitialized; - - // This represents an initialization of the 'element' value. - Stmt* Element = S->getElement(); - VarDecl* VD = 0; - - if (DeclStmt* DS = dyn_cast(Element)) - VD = cast(DS->getSingleDecl()); - else { - Expr* ElemExpr = cast(Element)->IgnoreParens(); - - // Initialize the value of the reference variable. - if (DeclRefExpr* DR = dyn_cast(ElemExpr)) - VD = cast(DR->getDecl()); - else - return Visit(ElemExpr); - } - - V(VD,AD) = Initialized; - return Initialized; -} - - -bool TransferFuncs:: -VisitAbstractConditionalOperator(AbstractConditionalOperator* C) { - Visit(C->getCond()); - - bool rhsResult = Visit(C->getFalseExpr()); - // Handle the GNU extension for missing LHS. - if (isa(C)) - return Visit(C->getTrueExpr()) & rhsResult; // Yes: we want &, not &&. - else - return rhsResult; -} - -bool TransferFuncs::VisitStmt(Stmt* S) { - bool x = Initialized; - - // We don't stop at the first subexpression that is Uninitialized because - // evaluating some subexpressions may result in propogating "Uninitialized" - // or "Initialized" to variables referenced in the other subexpressions. - for (Stmt::child_range I = S->children(); I; ++I) - if (*I && Visit(*I) == Uninitialized) x = Uninitialized; - - return x; -} - -bool TransferFuncs::Visit(Stmt *S) { - if (AD.isTracked(static_cast(S))) return V(static_cast(S),AD); - else return static_cast*>(this)->Visit(S); -} - -bool TransferFuncs::BlockStmt_VisitExpr(Expr* E) { - bool x = static_cast*>(this)->Visit(E); - if (AD.isTracked(E)) V(E,AD) = x; - return x; -} - -} // end anonymous namespace - -//===----------------------------------------------------------------------===// -// Merge operator. -// -// In our transfer functions we take the approach that any -// combination of uninitialized values, e.g. -// Uninitialized + ___ = Uninitialized. -// -// Merges take the same approach, preferring soundness. At a confluence point, -// if any predecessor has a variable marked uninitialized, the value is -// uninitialized at the confluence point. -//===----------------------------------------------------------------------===// - -namespace { - typedef StmtDeclBitVector_Types::Union Merge; - typedef DataflowSolver Solver; -} - -//===----------------------------------------------------------------------===// -// Uninitialized values checker. Scan an AST and flag variable uses -//===----------------------------------------------------------------------===// - -UninitializedValues_ValueTypes::ObserverTy::~ObserverTy() {} - -namespace { -class UninitializedValuesChecker - : public UninitializedValues::ObserverTy { - - ASTContext &Ctx; - Diagnostic &Diags; - llvm::SmallPtrSet AlreadyWarned; - -public: - UninitializedValuesChecker(ASTContext &ctx, Diagnostic &diags) - : Ctx(ctx), Diags(diags) {} - - virtual void ObserveDeclRefExpr(UninitializedValues::ValTy& V, - UninitializedValues::AnalysisDataTy& AD, - DeclRefExpr* DR, VarDecl* VD) { - - assert ( AD.isTracked(VD) && "Unknown VarDecl."); - - if (V(VD,AD) == Uninitialized) - if (AlreadyWarned.insert(VD)) - Diags.Report(Ctx.getFullLoc(DR->getSourceRange().getBegin()), - diag::warn_uninit_val); - } -}; -} // end anonymous namespace - -namespace clang { -void CheckUninitializedValues(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags, - bool FullUninitTaint) { - - // Compute the uninitialized values information. - UninitializedValues U(cfg); - U.getAnalysisData().FullUninitTaint = FullUninitTaint; - Solver S(U); - S.runOnCFG(cfg); - - // Scan for DeclRefExprs that use uninitialized values. - UninitializedValuesChecker Observer(Ctx,Diags); - U.getAnalysisData().Observer = &Observer; - S.runOnAllBlocks(cfg); -} -} // end namespace clang Removed: cfe/trunk/test/Analysis/conditional-op-missing-lhs.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/conditional-op-missing-lhs.c?rev=127655&view=auto ============================================================================== --- cfe/trunk/test/Analysis/conditional-op-missing-lhs.c (original) +++ cfe/trunk/test/Analysis/conditional-op-missing-lhs.c (removed) @@ -1,28 +0,0 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=deadcode.DeadStores -warn-uninit-values -verify %s -// FIXME: The current UninitializedValuesChecker will go away; replace it and re-enable test. -// XFAIL: * - -void f1() -{ - int i; - - int j = i ? : 1; // expected-warning{{use of uninitialized variable}} //expected-warning{{Value stored to 'j' during its initialization is never read}} -} - -void *f2(int *i) -{ - return i ? : 0; -} - -void *f3(int *i) -{ - int a; - - return &a ? : i; -} - -void f4() -{ - char c[1 ? : 2]; -} - Removed: cfe/trunk/test/Analysis/uninit-vals.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals.c?rev=127655&view=auto ============================================================================== --- cfe/trunk/test/Analysis/uninit-vals.c (original) +++ cfe/trunk/test/Analysis/uninit-vals.c (removed) @@ -1,55 +0,0 @@ -// RUN: %clang_cc1 -analyze -warn-uninit-values -verify %s -// FIXME: The current UninitializedValuesChecker will go away; replace it and re-enable test. -// XFAIL: * - -int f1() { - int x; - return x; // expected-warning {{use of uninitialized variable}} -} - -int f2(int x) { - int y; - int z = x + y; // expected-warning {{use of uninitialized variable}} - return z; -} - - -int f3(int x) { - int y; - return x ? 1 : y; // expected-warning {{use of uninitialized variable}} -} - -int f4(int x) { - int y; - if (x) y = 1; - return y; // expected-warning {{use of uninitialized variable}} -} - -void f5() { - int a; - a = 30; // no-warning -} - -void f6(int i) { - int x; - for (i = 0 ; i < 10; i++) - printf("%d",x++); // expected-warning {{use of uninitialized variable}} \ - // expected-warning{{implicitly declaring C library function 'printf' with type 'int (const char *, ...)'}} \ - // expected-note{{please include the header or explicitly provide a declaration for 'printf'}} -} - -void f7(int i) { - int x = i; - int y; - for (i = 0; i < 10; i++ ) { - printf("%d",x++); // no-warning - x += y; // expected-warning {{use of uninitialized variable}} - } -} - -int f8(int j) { - int x = 1, y = x + 1; - if (y) // no-warning - return x; - return y; -} Modified: cfe/trunk/test/Sema/uninit-variables.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=127656&r1=127655&r2=127656&view=diff ============================================================================== --- cfe/trunk/test/Sema/uninit-variables.c (original) +++ cfe/trunk/test/Sema/uninit-variables.c Mon Mar 14 22:17:01 2011 @@ -260,3 +260,71 @@ return ((r < 0) || ((r == 0) && (x < y))); } +int test39(int x) { + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + int z = x + y; // expected-warning {{variable 'y' is possibly uninitialized when used here}} + return z; +} + + +int test40(int x) { + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + return x ? 1 : y; // expected-warning {{variable 'y' is possibly uninitialized when used here}} +} + +int test41(int x) { + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + if (x) y = 1; // no-warning + return y; // expected-warning {{variable 'y' is possibly uninitialized when used here}} +} + +void test42() { + int a; + a = 30; // no-warning +} + +void test43_aux(int x); +void test43(int i) { + int x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + for (i = 0 ; i < 10; i++) + test43_aux(x++); // expected-warning {{variable 'x' is possibly uninitialized when used here}} +} + +void test44(int i) { + int x = i; + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + for (i = 0; i < 10; i++ ) { + test43_aux(x++); // no-warning + x += y; // expected-warning {{variable 'y' is possibly uninitialized when used here}} + } +} + +int test45(int j) { + int x = 1, y = x + 1; + if (y) // no-warning + return x; + return y; +} + +void test46() +{ + int i; // expected-note {{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}} + int j = i ? : 1; // expected-warning {{variable 'i' is possibly uninitialized when used here}} +} + +void *test47(int *i) +{ + return i ? : 0; // no-warning +} + +void *test49(int *i) +{ + int a; + return &a ? : i; // no-warning +} + +void test50() +{ + char c[1 ? : 2]; // no-warning +} + From kremenek at apple.com Mon Mar 14 22:17:07 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 03:17:07 -0000 Subject: [cfe-commits] r127657 - in /cfe/trunk: include/clang/Analysis/Analyses/UninitializedValues.h include/clang/Analysis/Analyses/UninitializedValuesV2.h lib/Analysis/CMakeLists.txt lib/Analysis/UninitializedValues.cpp lib/Analysis/UninitializedValuesV2.cpp lib/Sema/AnalysisBasedWarnings.cpp Message-ID: <20110315031708.0A3532A6C12D@llvm.org> Author: kremenek Date: Mon Mar 14 22:17:07 2011 New Revision: 127657 URL: http://llvm.org/viewvc/llvm-project?rev=127657&view=rev Log: Rename UninitializedValuesV2 to UninitializedValues. Added: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h - copied, changed from r127656, cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h cfe/trunk/lib/Analysis/UninitializedValues.cpp - copied, changed from r127656, cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp Removed: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp Modified: cfe/trunk/lib/Analysis/CMakeLists.txt cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Copied: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h (from r127656, cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h?p2=cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h&p1=cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h&r1=127656&r2=127657&rev=127657&view=diff ============================================================================== --- cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h (original) +++ cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h Mon Mar 14 22:17:07 2011 @@ -1,4 +1,4 @@ -//= UninitializedValuesV2.h - Finding uses of uninitialized values --*- C++ -*-= +//= UninitializedValues.h - Finding uses of uninitialized values --*- C++ -*-==// // // The LLVM Compiler Infrastructure // Removed: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h?rev=127656&view=auto ============================================================================== --- cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h (original) +++ cfe/trunk/include/clang/Analysis/Analyses/UninitializedValuesV2.h (removed) @@ -1,40 +0,0 @@ -//= UninitializedValuesV2.h - Finding uses of uninitialized values --*- C++ -*-= -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines APIs for invoking and reported uninitialized values -// warnings. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_UNINIT_VALS_H -#define LLVM_CLANG_UNINIT_VALS_H - -namespace clang { - -class AnalysisContext; -class CFG; -class DeclContext; -class Expr; -class VarDecl; - -class UninitVariablesHandler { -public: - UninitVariablesHandler() {} - virtual ~UninitVariablesHandler(); - - virtual void handleUseOfUninitVariable(const Expr *ex, - const VarDecl *vd) {} -}; - -void runUninitializedVariablesAnalysis(const DeclContext &dc, const CFG &cfg, - AnalysisContext &ac, - UninitVariablesHandler &handler); - -} -#endif Modified: cfe/trunk/lib/Analysis/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CMakeLists.txt?rev=127657&r1=127656&r2=127657&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/CMakeLists.txt (original) +++ cfe/trunk/lib/Analysis/CMakeLists.txt Mon Mar 14 22:17:07 2011 @@ -12,7 +12,7 @@ PseudoConstantAnalysis.cpp ReachableCode.cpp ScanfFormatString.cpp - UninitializedValuesV2.cpp + UninitializedValues.cpp ) add_dependencies(clangAnalysis ClangAttrClasses ClangAttrList Copied: cfe/trunk/lib/Analysis/UninitializedValues.cpp (from r127656, cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?p2=cfe/trunk/lib/Analysis/UninitializedValues.cpp&p1=cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp&r1=127656&r2=127657&rev=127657&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 14 22:17:07 2011 @@ -1,4 +1,4 @@ -//==- UninitializedValuesV2.cpp - Find Uninitialized Values -----*- C++ --*-==// +//==- UninitializedValues.cpp - Find Uninitialized Values -------*- C++ --*-==// // // The LLVM Compiler Infrastructure // @@ -20,7 +20,7 @@ #include "clang/Analysis/CFG.h" #include "clang/Analysis/AnalysisContext.h" #include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h" -#include "clang/Analysis/Analyses/UninitializedValuesV2.h" +#include "clang/Analysis/Analyses/UninitializedValues.h" #include "clang/Analysis/Support/SaveAndRestore.h" using namespace clang; Removed: cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp?rev=127656&view=auto ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp (removed) @@ -1,611 +0,0 @@ -//==- UninitializedValuesV2.cpp - Find Uninitialized Values -----*- C++ --*-==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements uninitialized values analysis for source-level CFGs. -// -//===----------------------------------------------------------------------===// - -#include -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/BitVector.h" -#include "llvm/ADT/DenseMap.h" -#include "clang/AST/Decl.h" -#include "clang/Analysis/CFG.h" -#include "clang/Analysis/AnalysisContext.h" -#include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h" -#include "clang/Analysis/Analyses/UninitializedValuesV2.h" -#include "clang/Analysis/Support/SaveAndRestore.h" - -using namespace clang; - -static bool isTrackedVar(const VarDecl *vd, const DeclContext *dc) { - return vd->isLocalVarDecl() && !vd->hasGlobalStorage() && - vd->getType()->isScalarType() && - vd->getDeclContext() == dc; -} - -//------------------------------------------------------------------------====// -// DeclToBit: a mapping from Decls we track to bitvector indices. -//====------------------------------------------------------------------------// - -namespace { -class DeclToBit { - llvm::DenseMap map; -public: - DeclToBit() {} - - /// Compute the actual mapping from declarations to bits. - void computeMap(const DeclContext &dc); - - /// Return the number of declarations in the map. - unsigned size() const { return map.size(); } - - /// Returns the bit vector index for a given declaration. - llvm::Optional getBitVectorIndex(const VarDecl *d); -}; -} - -void DeclToBit::computeMap(const DeclContext &dc) { - unsigned count = 0; - DeclContext::specific_decl_iterator I(dc.decls_begin()), - E(dc.decls_end()); - for ( ; I != E; ++I) { - const VarDecl *vd = *I; - if (isTrackedVar(vd, &dc)) - map[vd] = count++; - } -} - -llvm::Optional DeclToBit::getBitVectorIndex(const VarDecl *d) { - llvm::DenseMap::iterator I = map.find(d); - if (I == map.end()) - return llvm::Optional(); - return I->second; -} - -//------------------------------------------------------------------------====// -// CFGBlockValues: dataflow values for CFG blocks. -//====------------------------------------------------------------------------// - -typedef std::pair BVPair; - -namespace { -class CFGBlockValues { - const CFG &cfg; - BVPair *vals; - llvm::BitVector scratch; - DeclToBit declToBit; - - llvm::BitVector &lazyCreate(llvm::BitVector *&bv); -public: - CFGBlockValues(const CFG &cfg); - ~CFGBlockValues(); - - void computeSetOfDeclarations(const DeclContext &dc); - llvm::BitVector &getBitVector(const CFGBlock *block, - const CFGBlock *dstBlock); - - BVPair &getBitVectors(const CFGBlock *block, bool shouldLazyCreate); - - void mergeIntoScratch(llvm::BitVector const &source, bool isFirst); - bool updateBitVectorWithScratch(const CFGBlock *block); - bool updateBitVectors(const CFGBlock *block, const BVPair &newVals); - - bool hasNoDeclarations() const { - return declToBit.size() == 0; - } - - void resetScratch(); - llvm::BitVector &getScratch() { return scratch; } - - llvm::BitVector::reference operator[](const VarDecl *vd); -}; -} - -CFGBlockValues::CFGBlockValues(const CFG &c) : cfg(c), vals(0) { - unsigned n = cfg.getNumBlockIDs(); - if (!n) - return; - vals = new std::pair[n]; - memset(vals, 0, sizeof(*vals) * n); -} - -CFGBlockValues::~CFGBlockValues() { - unsigned n = cfg.getNumBlockIDs(); - if (n == 0) - return; - for (unsigned i = 0; i < n; ++i) { - delete vals[i].first; - delete vals[i].second; - } - delete [] vals; -} - -void CFGBlockValues::computeSetOfDeclarations(const DeclContext &dc) { - declToBit.computeMap(dc); - scratch.resize(declToBit.size()); -} - -llvm::BitVector &CFGBlockValues::lazyCreate(llvm::BitVector *&bv) { - if (!bv) - bv = new llvm::BitVector(declToBit.size()); - return *bv; -} - -/// This function pattern matches for a '&&' or '||' that appears at -/// the beginning of a CFGBlock that also (1) has a terminator and -/// (2) has no other elements. If such an expression is found, it is returned. -static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) { - if (block->empty()) - return 0; - - const CFGStmt *cstmt = block->front().getAs(); - BinaryOperator *b = llvm::dyn_cast_or_null(cstmt->getStmt()); - - if (!b || !b->isLogicalOp()) - return 0; - - if (block->pred_size() == 2 && - ((block->succ_size() == 2 && block->getTerminatorCondition() == b) || - block->size() == 1)) - return b; - - return 0; -} - -llvm::BitVector &CFGBlockValues::getBitVector(const CFGBlock *block, - const CFGBlock *dstBlock) { - unsigned idx = block->getBlockID(); - if (dstBlock && getLogicalOperatorInChain(block)) { - if (*block->succ_begin() == dstBlock) - return lazyCreate(vals[idx].first); - assert(*(block->succ_begin()+1) == dstBlock); - return lazyCreate(vals[idx].second); - } - - assert(vals[idx].second == 0); - return lazyCreate(vals[idx].first); -} - -BVPair &CFGBlockValues::getBitVectors(const clang::CFGBlock *block, - bool shouldLazyCreate) { - unsigned idx = block->getBlockID(); - lazyCreate(vals[idx].first); - if (shouldLazyCreate) - lazyCreate(vals[idx].second); - return vals[idx]; -} - -void CFGBlockValues::mergeIntoScratch(llvm::BitVector const &source, - bool isFirst) { - if (isFirst) - scratch = source; - else - scratch |= source; -} -#if 0 -static void printVector(const CFGBlock *block, llvm::BitVector &bv, - unsigned num) { - - llvm::errs() << block->getBlockID() << " :"; - for (unsigned i = 0; i < bv.size(); ++i) { - llvm::errs() << ' ' << bv[i]; - } - llvm::errs() << " : " << num << '\n'; -} -#endif - -bool CFGBlockValues::updateBitVectorWithScratch(const CFGBlock *block) { - llvm::BitVector &dst = getBitVector(block, 0); - bool changed = (dst != scratch); - if (changed) - dst = scratch; -#if 0 - printVector(block, scratch, 0); -#endif - return changed; -} - -bool CFGBlockValues::updateBitVectors(const CFGBlock *block, - const BVPair &newVals) { - BVPair &vals = getBitVectors(block, true); - bool changed = *newVals.first != *vals.first || - *newVals.second != *vals.second; - *vals.first = *newVals.first; - *vals.second = *newVals.second; -#if 0 - printVector(block, *vals.first, 1); - printVector(block, *vals.second, 2); -#endif - return changed; -} - -void CFGBlockValues::resetScratch() { - scratch.reset(); -} - -llvm::BitVector::reference CFGBlockValues::operator[](const VarDecl *vd) { - const llvm::Optional &idx = declToBit.getBitVectorIndex(vd); - assert(idx.hasValue()); - return scratch[idx.getValue()]; -} - -//------------------------------------------------------------------------====// -// Worklist: worklist for dataflow analysis. -//====------------------------------------------------------------------------// - -namespace { -class DataflowWorklist { - llvm::SmallVector worklist; - llvm::BitVector enqueuedBlocks; -public: - DataflowWorklist(const CFG &cfg) : enqueuedBlocks(cfg.getNumBlockIDs()) {} - - void enqueue(const CFGBlock *block); - void enqueueSuccessors(const CFGBlock *block); - const CFGBlock *dequeue(); - -}; -} - -void DataflowWorklist::enqueue(const CFGBlock *block) { - if (!block) - return; - unsigned idx = block->getBlockID(); - if (enqueuedBlocks[idx]) - return; - worklist.push_back(block); - enqueuedBlocks[idx] = true; -} - -void DataflowWorklist::enqueueSuccessors(const clang::CFGBlock *block) { - for (CFGBlock::const_succ_iterator I = block->succ_begin(), - E = block->succ_end(); I != E; ++I) { - enqueue(*I); - } -} - -const CFGBlock *DataflowWorklist::dequeue() { - if (worklist.empty()) - return 0; - const CFGBlock *b = worklist.back(); - worklist.pop_back(); - enqueuedBlocks[b->getBlockID()] = false; - return b; -} - -//------------------------------------------------------------------------====// -// Transfer function for uninitialized values analysis. -//====------------------------------------------------------------------------// - -static const bool Initialized = false; -static const bool Uninitialized = true; - -namespace { -class FindVarResult { - const VarDecl *vd; - const DeclRefExpr *dr; -public: - FindVarResult(VarDecl *vd, DeclRefExpr *dr) : vd(vd), dr(dr) {} - - const DeclRefExpr *getDeclRefExpr() const { return dr; } - const VarDecl *getDecl() const { return vd; } -}; - -class TransferFunctions : public CFGRecStmtVisitor { - CFGBlockValues &vals; - const CFG &cfg; - AnalysisContext ∾ - UninitVariablesHandler *handler; - const DeclRefExpr *currentDR; - const Expr *currentVoidCast; - const bool flagBlockUses; -public: - TransferFunctions(CFGBlockValues &vals, const CFG &cfg, - AnalysisContext &ac, - UninitVariablesHandler *handler, - bool flagBlockUses) - : vals(vals), cfg(cfg), ac(ac), handler(handler), currentDR(0), - currentVoidCast(0), flagBlockUses(flagBlockUses) {} - - const CFG &getCFG() { return cfg; } - void reportUninit(const DeclRefExpr *ex, const VarDecl *vd); - - void VisitBlockExpr(BlockExpr *be); - void VisitDeclStmt(DeclStmt *ds); - void VisitDeclRefExpr(DeclRefExpr *dr); - void VisitUnaryOperator(UnaryOperator *uo); - void VisitBinaryOperator(BinaryOperator *bo); - void VisitCastExpr(CastExpr *ce); - void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *se); - void BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt *fs); - - bool isTrackedVar(const VarDecl *vd) { - return ::isTrackedVar(vd, cast(ac.getDecl())); - } - - FindVarResult findBlockVarDecl(Expr *ex); -}; -} - -void TransferFunctions::reportUninit(const DeclRefExpr *ex, - const VarDecl *vd) { - if (handler) handler->handleUseOfUninitVariable(ex, vd); -} - -FindVarResult TransferFunctions::findBlockVarDecl(Expr* ex) { - if (DeclRefExpr* dr = dyn_cast(ex->IgnoreParenCasts())) - if (VarDecl *vd = dyn_cast(dr->getDecl())) - if (isTrackedVar(vd)) - return FindVarResult(vd, dr); - return FindVarResult(0, 0); -} - -void TransferFunctions::BlockStmt_VisitObjCForCollectionStmt( - ObjCForCollectionStmt *fs) { - - Visit(fs->getCollection()); - - // This represents an initialization of the 'element' value. - Stmt *element = fs->getElement(); - const VarDecl* vd = 0; - - if (DeclStmt* ds = dyn_cast(element)) { - vd = cast(ds->getSingleDecl()); - if (!isTrackedVar(vd)) - vd = 0; - } - else { - // Initialize the value of the reference variable. - const FindVarResult &res = findBlockVarDecl(cast(element)); - vd = res.getDecl(); - if (!vd) { - Visit(element); - return; - } - } - - if (vd) - vals[vd] = Initialized; -} - -void TransferFunctions::VisitBlockExpr(BlockExpr *be) { - if (!flagBlockUses || !handler) - return; - AnalysisContext::referenced_decls_iterator i, e; - llvm::tie(i, e) = ac.getReferencedBlockVars(be->getBlockDecl()); - for ( ; i != e; ++i) { - const VarDecl *vd = *i; - if (vd->getAttr() || !vd->hasLocalStorage() || - !isTrackedVar(vd)) - continue; - if (vals[vd] == Uninitialized) - handler->handleUseOfUninitVariable(be, vd); - } -} - -void TransferFunctions::VisitDeclStmt(DeclStmt *ds) { - for (DeclStmt::decl_iterator DI = ds->decl_begin(), DE = ds->decl_end(); - DI != DE; ++DI) { - if (VarDecl *vd = dyn_cast(*DI)) { - if (isTrackedVar(vd)) { - vals[vd] = Uninitialized; - if (Stmt *init = vd->getInit()) { - Visit(init); - vals[vd] = Initialized; - } - } - else if (Stmt *init = vd->getInit()) { - Visit(init); - } - } - } -} - -void TransferFunctions::VisitDeclRefExpr(DeclRefExpr *dr) { - // We assume that DeclRefExprs wrapped in an lvalue-to-rvalue cast - // cannot be block-level expressions. Therefore, we determine if - // a DeclRefExpr is involved in a "load" by comparing it to the current - // DeclRefExpr found when analyzing the last lvalue-to-rvalue CastExpr. - // If a DeclRefExpr is not involved in a load, we are essentially computing - // its address, either for assignment to a reference or via the '&' operator. - // In such cases, treat the variable as being initialized, since this - // analysis isn't powerful enough to do alias tracking. - if (dr != currentDR) - if (const VarDecl *vd = dyn_cast(dr->getDecl())) - if (isTrackedVar(vd)) - vals[vd] = Initialized; -} - -void TransferFunctions::VisitBinaryOperator(clang::BinaryOperator *bo) { - if (bo->isAssignmentOp()) { - const FindVarResult &res = findBlockVarDecl(bo->getLHS()); - if (const VarDecl* vd = res.getDecl()) { - // We assume that DeclRefExprs wrapped in a BinaryOperator "assignment" - // cannot be block-level expressions. Therefore, we determine if - // a DeclRefExpr is involved in a "load" by comparing it to the current - // DeclRefExpr found when analyzing the last lvalue-to-rvalue CastExpr. - SaveAndRestore lastDR(currentDR, - res.getDeclRefExpr()); - Visit(bo->getRHS()); - Visit(bo->getLHS()); - - llvm::BitVector::reference bit = vals[vd]; - if (bit == Uninitialized) { - if (bo->getOpcode() != BO_Assign) - reportUninit(res.getDeclRefExpr(), vd); - bit = Initialized; - } - return; - } - } - Visit(bo->getRHS()); - Visit(bo->getLHS()); -} - -void TransferFunctions::VisitUnaryOperator(clang::UnaryOperator *uo) { - switch (uo->getOpcode()) { - case clang::UO_PostDec: - case clang::UO_PostInc: - case clang::UO_PreDec: - case clang::UO_PreInc: { - const FindVarResult &res = findBlockVarDecl(uo->getSubExpr()); - if (const VarDecl *vd = res.getDecl()) { - // We assume that DeclRefExprs wrapped in a unary operator ++/-- - // cannot be block-level expressions. Therefore, we determine if - // a DeclRefExpr is involved in a "load" by comparing it to the current - // DeclRefExpr found when analyzing the last lvalue-to-rvalue CastExpr. - SaveAndRestore lastDR(currentDR, - res.getDeclRefExpr()); - Visit(uo->getSubExpr()); - - llvm::BitVector::reference bit = vals[vd]; - if (bit == Uninitialized) { - reportUninit(res.getDeclRefExpr(), vd); - bit = Initialized; - } - return; - } - break; - } - default: - break; - } - Visit(uo->getSubExpr()); -} - -void TransferFunctions::VisitCastExpr(clang::CastExpr *ce) { - if (ce->getCastKind() == CK_LValueToRValue) { - const FindVarResult &res = findBlockVarDecl(ce->getSubExpr()); - if (const VarDecl *vd = res.getDecl()) { - // We assume that DeclRefExprs wrapped in an lvalue-to-rvalue cast - // cannot be block-level expressions. Therefore, we determine if - // a DeclRefExpr is involved in a "load" by comparing it to the current - // DeclRefExpr found when analyzing the last lvalue-to-rvalue CastExpr. - // Here we update 'currentDR' to be the one associated with this - // lvalue-to-rvalue cast. Then, when we analyze the DeclRefExpr, we - // will know that we are not computing its lvalue for other purposes - // than to perform a load. - SaveAndRestore lastDR(currentDR, - res.getDeclRefExpr()); - Visit(ce->getSubExpr()); - if (currentVoidCast != ce && vals[vd] == Uninitialized) { - reportUninit(res.getDeclRefExpr(), vd); - // Don't cascade warnings. - vals[vd] = Initialized; - } - return; - } - } - else if (CStyleCastExpr *cse = dyn_cast(ce)) { - if (cse->getType()->isVoidType()) { - // e.g. (void) x; - SaveAndRestore - lastVoidCast(currentVoidCast, cse->getSubExpr()->IgnoreParens()); - Visit(cse->getSubExpr()); - return; - } - } - Visit(ce->getSubExpr()); -} - -void TransferFunctions::VisitUnaryExprOrTypeTraitExpr( - UnaryExprOrTypeTraitExpr *se) { - if (se->getKind() == UETT_SizeOf) { - if (se->getType()->isConstantSizeType()) - return; - // Handle VLAs. - Visit(se->getArgumentExpr()); - } -} - -//------------------------------------------------------------------------====// -// High-level "driver" logic for uninitialized values analysis. -//====------------------------------------------------------------------------// - -static bool runOnBlock(const CFGBlock *block, const CFG &cfg, - AnalysisContext &ac, CFGBlockValues &vals, - UninitVariablesHandler *handler = 0, - bool flagBlockUses = false) { - - if (const BinaryOperator *b = getLogicalOperatorInChain(block)) { - CFGBlock::const_pred_iterator itr = block->pred_begin(); - BVPair vA = vals.getBitVectors(*itr, false); - ++itr; - BVPair vB = vals.getBitVectors(*itr, false); - - BVPair valsAB; - - if (b->getOpcode() == BO_LAnd) { - // Merge the 'F' bits from the first and second. - vals.mergeIntoScratch(*(vA.second ? vA.second : vA.first), true); - vals.mergeIntoScratch(*(vB.second ? vB.second : vB.first), false); - valsAB.first = vA.first; - valsAB.second = &vals.getScratch(); - } - else { - // Merge the 'T' bits from the first and second. - assert(b->getOpcode() == BO_LOr); - vals.mergeIntoScratch(*vA.first, true); - vals.mergeIntoScratch(*vB.first, false); - valsAB.first = &vals.getScratch(); - valsAB.second = vA.second ? vA.second : vA.first; - } - return vals.updateBitVectors(block, valsAB); - } - - // Default behavior: merge in values of predecessor blocks. - vals.resetScratch(); - bool isFirst = true; - for (CFGBlock::const_pred_iterator I = block->pred_begin(), - E = block->pred_end(); I != E; ++I) { - vals.mergeIntoScratch(vals.getBitVector(*I, block), isFirst); - isFirst = false; - } - // Apply the transfer function. - TransferFunctions tf(vals, cfg, ac, handler, flagBlockUses); - for (CFGBlock::const_iterator I = block->begin(), E = block->end(); - I != E; ++I) { - if (const CFGStmt *cs = dyn_cast(&*I)) { - tf.BlockStmt_Visit(cs->getStmt()); - } - } - return vals.updateBitVectorWithScratch(block); -} - -void clang::runUninitializedVariablesAnalysis(const DeclContext &dc, - const CFG &cfg, - AnalysisContext &ac, - UninitVariablesHandler &handler) { - CFGBlockValues vals(cfg); - vals.computeSetOfDeclarations(dc); - if (vals.hasNoDeclarations()) - return; - DataflowWorklist worklist(cfg); - llvm::BitVector previouslyVisited(cfg.getNumBlockIDs()); - - worklist.enqueueSuccessors(&cfg.getEntry()); - - while (const CFGBlock *block = worklist.dequeue()) { - // Did the block change? - bool changed = runOnBlock(block, cfg, ac, vals); - if (changed || !previouslyVisited[block->getBlockID()]) - worklist.enqueueSuccessors(block); - previouslyVisited[block->getBlockID()] = true; - } - - // Run through the blocks one more time, and report uninitialized variabes. - for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) { - runOnBlock(*BI, cfg, ac, vals, &handler, /* flagBlockUses */ true); - } -} - -UninitVariablesHandler::~UninitVariablesHandler() {} - Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=127657&r1=127656&r2=127657&view=diff ============================================================================== --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original) +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Mar 14 22:17:07 2011 @@ -29,7 +29,7 @@ #include "clang/Analysis/Analyses/ReachableCode.h" #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h" #include "clang/Analysis/CFGStmtMap.h" -#include "clang/Analysis/Analyses/UninitializedValuesV2.h" +#include "clang/Analysis/Analyses/UninitializedValues.h" #include "llvm/ADT/BitVector.h" #include "llvm/Support/Casting.h" From pichet2000 at gmail.com Mon Mar 14 23:29:19 2011 From: pichet2000 at gmail.com (Francois Pichet) Date: Tue, 15 Mar 2011 00:29:19 -0400 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing In-Reply-To: References: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> <045D8E3B-670A-4306-B5A1-EE9343BC5343@apple.com> Message-ID: On Mon, Mar 14, 2011 at 5:04 PM, Douglas Gregor wrote: > > On Mar 14, 2011, at 2:03 PM, Francois Pichet wrote: > >> On Mon, Mar 14, 2011 at 1:46 PM, Douglas Gregor wrote: >>> >>> On Mar 14, 2011, at 10:36 AM, John McCall wrote: >>> >>>> On Mar 13, 2011, at 11:07 PM, Francois Pichet wrote: >>>>> This patch implements "Late template parsing" in Microsoft mode. >>>>> It solves the problem of Microsoft allowing names not yet declared in >>>>> template code. >>>> >>>> I haven't looked at the patch yet, but this defintely needs to be enabled >>>> by its own -cc1 language option; ?that option should then be enabled by >>>> windows targets, rather than tying this to -fms-extensions. >>> >>> >>> Yes. -fdelayed-template-parsing seems a good name. >>> >>> ? ? ? ?- Doug >>> >> >> ok then i'll provide a new patch soon. I'll remove the *Microsoft* >> from all the structs and functions names to make the patch more >> generic. > > Thanks! hi, Here is an updated patch. Currently all delayed template functions are parsed at the end of the translation unit. What I would like to do in a next patch is to parse delayed template code only when it is necessary because it is needed by template instantiation. As such template code never instantiated will be never be parsed with the -fdelayed-template-parsing. -------------- next part -------------- A non-text attachment was scrubbed... Name: LateParsedMSTemplate.patch Type: application/octet-stream Size: 19466 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110315/bcda3be5/attachment-0001.obj From kremenek at apple.com Mon Mar 14 23:57:32 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 04:57:32 -0000 Subject: [cfe-commits] r127665 - /cfe/trunk/lib/Analysis/UninitializedValues.cpp Message-ID: <20110315045732.C008C2A6C12E@llvm.org> Author: kremenek Date: Mon Mar 14 23:57:32 2011 New Revision: 127665 URL: http://llvm.org/viewvc/llvm-project?rev=127665&view=rev Log: UninitializedValues: introduce ValueVector:reference class to forward to llvm::BitVector. No real functionality change, but this is a stepping stone to moving to tri-state logic. Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127665&r1=127664&r2=127665&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 14 23:57:32 2011 @@ -74,20 +74,37 @@ // CFGBlockValues: dataflow values for CFG blocks. //====------------------------------------------------------------------------// -static const bool Initialized = false; -static const bool Uninitialized = true; +enum Value { Initialized = 0, Uninitialized = 1 }; class ValueVector { llvm::BitVector vec; public: ValueVector() {} ValueVector(unsigned size) : vec(size) {} - typedef llvm::BitVector::reference reference; void resize(unsigned n) { vec.resize(n); } void merge(const ValueVector &rhs) { vec |= rhs.vec; } bool operator!=(const ValueVector &rhs) const { return vec != rhs.vec; } - reference operator[](unsigned idx) { return vec[idx]; } void reset() { vec.reset(); } + + class reference { + ValueVector &vv; + const unsigned idx; + + reference(); // Undefined + public: + reference(ValueVector &vv, unsigned idx) : vv(vv), idx(idx) {} + ~reference() {} + + reference &operator=(Value v) { + vv.vec[idx] = (v == Initialized ? false : true); + return *this; + } + bool operator==(Value v) { + return vv.vec[idx] == (v == Initialized ? false : true); + } + }; + + reference operator[](unsigned idx) { return reference(*this, idx); } }; typedef std::pair BVPair; @@ -260,7 +277,7 @@ namespace { class DataflowWorklist { llvm::SmallVector worklist; - ValueVector enqueuedBlocks; + llvm::BitVector enqueuedBlocks; public: DataflowWorklist(const CFG &cfg) : enqueuedBlocks(cfg.getNumBlockIDs()) {} @@ -450,11 +467,11 @@ Visit(bo->getRHS()); Visit(bo->getLHS()); - ValueVector::reference bit = vals[vd]; - if (bit == Uninitialized) { + ValueVector::reference val = vals[vd]; + if (val == Uninitialized) { if (bo->getOpcode() != BO_Assign) reportUninit(res.getDeclRefExpr(), vd); - bit = Initialized; + val = Initialized; } return; } @@ -602,7 +619,7 @@ if (vals.hasNoDeclarations()) return; DataflowWorklist worklist(cfg); - ValueVector previouslyVisited(cfg.getNumBlockIDs()); + llvm::BitVector previouslyVisited(cfg.getNumBlockIDs()); worklist.enqueueSuccessors(&cfg.getEntry()); From kremenek at apple.com Mon Mar 14 23:57:27 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 04:57:27 -0000 Subject: [cfe-commits] r127663 - /cfe/trunk/lib/Analysis/UninitializedValues.cpp Message-ID: <20110315045727.6D0702A6C12C@llvm.org> Author: kremenek Date: Mon Mar 14 23:57:27 2011 New Revision: 127663 URL: http://llvm.org/viewvc/llvm-project?rev=127663&view=rev Log: Substitue term "BitVector" with "ValueVector" to prep for further revisions. No functionality change. Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127663&r1=127662&r2=127663&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 14 23:57:27 2011 @@ -32,14 +32,14 @@ } //------------------------------------------------------------------------====// -// DeclToBit: a mapping from Decls we track to bitvector indices. +// DeclToIndex: a mapping from Decls we track to value indices. //====------------------------------------------------------------------------// namespace { -class DeclToBit { +class DeclToIndex { llvm::DenseMap map; public: - DeclToBit() {} + DeclToIndex() {} /// Compute the actual mapping from declarations to bits. void computeMap(const DeclContext &dc); @@ -48,11 +48,11 @@ unsigned size() const { return map.size(); } /// Returns the bit vector index for a given declaration. - llvm::Optional getBitVectorIndex(const VarDecl *d); + llvm::Optional getValueIndex(const VarDecl *d); }; } -void DeclToBit::computeMap(const DeclContext &dc) { +void DeclToIndex::computeMap(const DeclContext &dc) { unsigned count = 0; DeclContext::specific_decl_iterator I(dc.decls_begin()), E(dc.decls_end()); @@ -63,7 +63,7 @@ } } -llvm::Optional DeclToBit::getBitVectorIndex(const VarDecl *d) { +llvm::Optional DeclToIndex::getValueIndex(const VarDecl *d) { llvm::DenseMap::iterator I = map.find(d); if (I == map.end()) return llvm::Optional(); @@ -74,38 +74,39 @@ // CFGBlockValues: dataflow values for CFG blocks. //====------------------------------------------------------------------------// -typedef std::pair BVPair; +typedef llvm::BitVector ValueVector; +typedef std::pair BVPair; namespace { class CFGBlockValues { const CFG &cfg; BVPair *vals; - llvm::BitVector scratch; - DeclToBit declToBit; + ValueVector scratch; + DeclToIndex DeclToIndex; - llvm::BitVector &lazyCreate(llvm::BitVector *&bv); + ValueVector &lazyCreate(ValueVector *&bv); public: CFGBlockValues(const CFG &cfg); ~CFGBlockValues(); void computeSetOfDeclarations(const DeclContext &dc); - llvm::BitVector &getBitVector(const CFGBlock *block, + ValueVector &getValueVector(const CFGBlock *block, const CFGBlock *dstBlock); - BVPair &getBitVectors(const CFGBlock *block, bool shouldLazyCreate); + BVPair &getValueVectors(const CFGBlock *block, bool shouldLazyCreate); - void mergeIntoScratch(llvm::BitVector const &source, bool isFirst); - bool updateBitVectorWithScratch(const CFGBlock *block); - bool updateBitVectors(const CFGBlock *block, const BVPair &newVals); + void mergeIntoScratch(ValueVector const &source, bool isFirst); + bool updateValueVectorWithScratch(const CFGBlock *block); + bool updateValueVectors(const CFGBlock *block, const BVPair &newVals); bool hasNoDeclarations() const { - return declToBit.size() == 0; + return DeclToIndex.size() == 0; } void resetScratch(); - llvm::BitVector &getScratch() { return scratch; } + ValueVector &getScratch() { return scratch; } - llvm::BitVector::reference operator[](const VarDecl *vd); + ValueVector::reference operator[](const VarDecl *vd); }; } @@ -113,7 +114,7 @@ unsigned n = cfg.getNumBlockIDs(); if (!n) return; - vals = new std::pair[n]; + vals = new std::pair[n]; memset(vals, 0, sizeof(*vals) * n); } @@ -129,13 +130,13 @@ } void CFGBlockValues::computeSetOfDeclarations(const DeclContext &dc) { - declToBit.computeMap(dc); - scratch.resize(declToBit.size()); + DeclToIndex.computeMap(dc); + scratch.resize(DeclToIndex.size()); } -llvm::BitVector &CFGBlockValues::lazyCreate(llvm::BitVector *&bv) { +ValueVector &CFGBlockValues::lazyCreate(ValueVector *&bv) { if (!bv) - bv = new llvm::BitVector(declToBit.size()); + bv = new ValueVector(DeclToIndex.size()); return *bv; } @@ -160,8 +161,8 @@ return 0; } -llvm::BitVector &CFGBlockValues::getBitVector(const CFGBlock *block, - const CFGBlock *dstBlock) { +ValueVector &CFGBlockValues::getValueVector(const CFGBlock *block, + const CFGBlock *dstBlock) { unsigned idx = block->getBlockID(); if (dstBlock && getLogicalOperatorInChain(block)) { if (*block->succ_begin() == dstBlock) @@ -174,8 +175,8 @@ return lazyCreate(vals[idx].first); } -BVPair &CFGBlockValues::getBitVectors(const clang::CFGBlock *block, - bool shouldLazyCreate) { +BVPair &CFGBlockValues::getValueVectors(const clang::CFGBlock *block, + bool shouldLazyCreate) { unsigned idx = block->getBlockID(); lazyCreate(vals[idx].first); if (shouldLazyCreate) @@ -183,7 +184,7 @@ return vals[idx]; } -void CFGBlockValues::mergeIntoScratch(llvm::BitVector const &source, +void CFGBlockValues::mergeIntoScratch(ValueVector const &source, bool isFirst) { if (isFirst) scratch = source; @@ -191,7 +192,7 @@ scratch |= source; } #if 0 -static void printVector(const CFGBlock *block, llvm::BitVector &bv, +static void printVector(const CFGBlock *block, ValueVector &bv, unsigned num) { llvm::errs() << block->getBlockID() << " :"; @@ -202,8 +203,8 @@ } #endif -bool CFGBlockValues::updateBitVectorWithScratch(const CFGBlock *block) { - llvm::BitVector &dst = getBitVector(block, 0); +bool CFGBlockValues::updateValueVectorWithScratch(const CFGBlock *block) { + ValueVector &dst = getValueVector(block, 0); bool changed = (dst != scratch); if (changed) dst = scratch; @@ -213,9 +214,9 @@ return changed; } -bool CFGBlockValues::updateBitVectors(const CFGBlock *block, +bool CFGBlockValues::updateValueVectors(const CFGBlock *block, const BVPair &newVals) { - BVPair &vals = getBitVectors(block, true); + BVPair &vals = getValueVectors(block, true); bool changed = *newVals.first != *vals.first || *newVals.second != *vals.second; *vals.first = *newVals.first; @@ -231,8 +232,8 @@ scratch.reset(); } -llvm::BitVector::reference CFGBlockValues::operator[](const VarDecl *vd) { - const llvm::Optional &idx = declToBit.getBitVectorIndex(vd); +ValueVector::reference CFGBlockValues::operator[](const VarDecl *vd) { + const llvm::Optional &idx = DeclToIndex.getValueIndex(vd); assert(idx.hasValue()); return scratch[idx.getValue()]; } @@ -244,7 +245,7 @@ namespace { class DataflowWorklist { llvm::SmallVector worklist; - llvm::BitVector enqueuedBlocks; + ValueVector enqueuedBlocks; public: DataflowWorklist(const CFG &cfg) : enqueuedBlocks(cfg.getNumBlockIDs()) {} @@ -437,7 +438,7 @@ Visit(bo->getRHS()); Visit(bo->getLHS()); - llvm::BitVector::reference bit = vals[vd]; + ValueVector::reference bit = vals[vd]; if (bit == Uninitialized) { if (bo->getOpcode() != BO_Assign) reportUninit(res.getDeclRefExpr(), vd); @@ -466,7 +467,7 @@ res.getDeclRefExpr()); Visit(uo->getSubExpr()); - llvm::BitVector::reference bit = vals[vd]; + ValueVector::reference bit = vals[vd]; if (bit == Uninitialized) { reportUninit(res.getDeclRefExpr(), vd); bit = Initialized; @@ -537,9 +538,9 @@ if (const BinaryOperator *b = getLogicalOperatorInChain(block)) { CFGBlock::const_pred_iterator itr = block->pred_begin(); - BVPair vA = vals.getBitVectors(*itr, false); + BVPair vA = vals.getValueVectors(*itr, false); ++itr; - BVPair vB = vals.getBitVectors(*itr, false); + BVPair vB = vals.getValueVectors(*itr, false); BVPair valsAB; @@ -558,7 +559,7 @@ valsAB.first = &vals.getScratch(); valsAB.second = vA.second ? vA.second : vA.first; } - return vals.updateBitVectors(block, valsAB); + return vals.updateValueVectors(block, valsAB); } // Default behavior: merge in values of predecessor blocks. @@ -566,7 +567,7 @@ bool isFirst = true; for (CFGBlock::const_pred_iterator I = block->pred_begin(), E = block->pred_end(); I != E; ++I) { - vals.mergeIntoScratch(vals.getBitVector(*I, block), isFirst); + vals.mergeIntoScratch(vals.getValueVector(*I, block), isFirst); isFirst = false; } // Apply the transfer function. @@ -577,7 +578,7 @@ tf.BlockStmt_Visit(cs->getStmt()); } } - return vals.updateBitVectorWithScratch(block); + return vals.updateValueVectorWithScratch(block); } void clang::runUninitializedVariablesAnalysis(const DeclContext &dc, @@ -589,7 +590,7 @@ if (vals.hasNoDeclarations()) return; DataflowWorklist worklist(cfg); - llvm::BitVector previouslyVisited(cfg.getNumBlockIDs()); + ValueVector previouslyVisited(cfg.getNumBlockIDs()); worklist.enqueueSuccessors(&cfg.getEntry()); From kremenek at apple.com Mon Mar 14 23:57:30 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 04:57:30 -0000 Subject: [cfe-commits] r127664 - /cfe/trunk/lib/Analysis/UninitializedValues.cpp Message-ID: <20110315045730.19B182A6C12D@llvm.org> Author: kremenek Date: Mon Mar 14 23:57:29 2011 New Revision: 127664 URL: http://llvm.org/viewvc/llvm-project?rev=127664&view=rev Log: UninitializedValues: wrap BitVector references in a new class ValueVector. No functionality change. This defines the minimum interface that ValueVector needs to support when we no longer base it strictly on a direct interpretation of BitVector. Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127664&r1=127663&r2=127664&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 14 23:57:29 2011 @@ -74,7 +74,22 @@ // CFGBlockValues: dataflow values for CFG blocks. //====------------------------------------------------------------------------// -typedef llvm::BitVector ValueVector; +static const bool Initialized = false; +static const bool Uninitialized = true; + +class ValueVector { + llvm::BitVector vec; +public: + ValueVector() {} + ValueVector(unsigned size) : vec(size) {} + typedef llvm::BitVector::reference reference; + void resize(unsigned n) { vec.resize(n); } + void merge(const ValueVector &rhs) { vec |= rhs.vec; } + bool operator!=(const ValueVector &rhs) const { return vec != rhs.vec; } + reference operator[](unsigned idx) { return vec[idx]; } + void reset() { vec.reset(); } +}; + typedef std::pair BVPair; namespace { @@ -189,7 +204,7 @@ if (isFirst) scratch = source; else - scratch |= source; + scratch.merge(source); } #if 0 static void printVector(const CFGBlock *block, ValueVector &bv, @@ -286,9 +301,6 @@ // Transfer function for uninitialized values analysis. //====------------------------------------------------------------------------// -static const bool Initialized = false; -static const bool Uninitialized = true; - namespace { class FindVarResult { const VarDecl *vd; From kremenek at apple.com Mon Mar 14 23:57:38 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 04:57:38 -0000 Subject: [cfe-commits] r127666 - in /cfe/trunk: include/clang/Analysis/Analyses/UninitializedValues.h include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Analysis/UninitializedValues.cpp lib/Sema/AnalysisBasedWarnings.cpp test/Sema/uninit-variables.c Message-ID: <20110315045738.B785E2A6C12C@llvm.org> Author: kremenek Date: Mon Mar 14 23:57:38 2011 New Revision: 127666 URL: http://llvm.org/viewvc/llvm-project?rev=127666&view=rev Log: Split warnings from -Wuninitialized-experimental into "must-be-initialized" and "may-be-initialized" warnings, each controlled by different flags. Modified: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Analysis/UninitializedValues.cpp cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp cfe/trunk/test/Sema/uninit-variables.c Modified: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h?rev=127666&r1=127665&r2=127666&view=diff ============================================================================== --- cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h (original) +++ cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h Mon Mar 14 23:57:38 2011 @@ -29,7 +29,8 @@ virtual ~UninitVariablesHandler(); virtual void handleUseOfUninitVariable(const Expr *ex, - const VarDecl *vd) {} + const VarDecl *vd, + bool isAlwaysUninit) {} }; void runUninitializedVariablesAnalysis(const DeclContext &dc, const CFG &cfg, Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=127666&r1=127665&r2=127666&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Mar 14 23:57:38 2011 @@ -136,7 +136,8 @@ def Trigraphs : DiagGroup<"trigraphs">; def : DiagGroup<"type-limits">; -def Uninitialized : DiagGroup<"uninitialized">; + +def UninitializedMaybe : DiagGroup<"uninitialized-maybe">; def UnknownPragmas : DiagGroup<"unknown-pragmas">; def UnknownAttributes : DiagGroup<"unknown-attributes">; def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args">; @@ -199,6 +200,10 @@ UnusedValue, UnusedVariable]>, DiagCategory<"Unused Entity Issue">; +def Uninitialized : DiagGroup<"uninitialized", + [UninitializedMaybe]>, + DiagCategory<"Uninitialized Value Issues">; + // Format settings. def FormatSecurity : DiagGroup<"format-security">; def Format : DiagGroup<"format", Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127666&r1=127665&r2=127666&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Mar 14 23:57:38 2011 @@ -868,11 +868,17 @@ InGroup; def warn_uninit_var : Warning<"variable %0 is possibly uninitialized when used here">, InGroup>, DefaultIgnore; +def warn_maybe_uninit_var : + Warning<"variable %0 is possibly uninitialized when used here">, + InGroup, DefaultIgnore; def note_uninit_var_def : Note< "variable %0 is declared here">; def warn_uninit_var_captured_by_block : Warning< "variable %0 is possibly uninitialized when captured by block">, InGroup>, DefaultIgnore; +def warn_maybe_uninit_var_captured_by_block : Warning< + "variable %0 is possibly uninitialized when captured by block">, + InGroup, DefaultIgnore; def note_var_fixit_add_initialization : Note< "add initialization to silence this warning">; def err_init_incomplete_type : Error<"initialization of incomplete type %0">; Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127666&r1=127665&r2=127666&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 14 23:57:38 2011 @@ -74,14 +74,26 @@ // CFGBlockValues: dataflow values for CFG blocks. //====------------------------------------------------------------------------// -enum Value { Initialized = 0, Uninitialized = 1 }; +// These values are defined in such a way that a merge can be done using +// a bitwise OR. +enum Value { Unknown = 0x0, /* 00 */ + Initialized = 0x1, /* 01 */ + Uninitialized = 0x2, /* 10 */ + MayUninitialized = 0x3 /* 11 */ }; + +static bool isUninitialized(const Value v) { + return v >= Uninitialized; +} +static bool isAlwaysUninit(const Value v) { + return v == Uninitialized; +} class ValueVector { llvm::BitVector vec; public: ValueVector() {} - ValueVector(unsigned size) : vec(size) {} - void resize(unsigned n) { vec.resize(n); } + ValueVector(unsigned size) : vec(size << 1) {} + void resize(unsigned n) { vec.resize(n << 1); } void merge(const ValueVector &rhs) { vec |= rhs.vec; } bool operator!=(const ValueVector &rhs) const { return vec != rhs.vec; } void reset() { vec.reset(); } @@ -96,11 +108,17 @@ ~reference() {} reference &operator=(Value v) { - vv.vec[idx] = (v == Initialized ? false : true); + vv.vec[idx << 1] = (((unsigned) v) & 0x1) ? true : false; + vv.vec[(idx << 1) | 1] = (((unsigned) v) & 0x2) ? true : false; return *this; } + operator Value() { + unsigned x = (vv.vec[idx << 1] ? 1 : 0) | (vv.vec[(idx << 1) | 1] ? 2 :0); + return (Value) x; + } + bool operator==(Value v) { - return vv.vec[idx] == (v == Initialized ? false : true); + return v = operator Value(); } }; @@ -346,7 +364,8 @@ currentVoidCast(0), flagBlockUses(flagBlockUses) {} const CFG &getCFG() { return cfg; } - void reportUninit(const DeclRefExpr *ex, const VarDecl *vd); + void reportUninit(const DeclRefExpr *ex, const VarDecl *vd, + bool isAlwaysUninit); void VisitBlockExpr(BlockExpr *be); void VisitDeclStmt(DeclStmt *ds); @@ -366,8 +385,8 @@ } void TransferFunctions::reportUninit(const DeclRefExpr *ex, - const VarDecl *vd) { - if (handler) handler->handleUseOfUninitVariable(ex, vd); + const VarDecl *vd, bool isAlwaysUnit) { + if (handler) handler->handleUseOfUninitVariable(ex, vd, isAlwaysUnit); } FindVarResult TransferFunctions::findBlockVarDecl(Expr* ex) { @@ -416,8 +435,9 @@ if (vd->getAttr() || !vd->hasLocalStorage() || !isTrackedVar(vd)) continue; - if (vals[vd] == Uninitialized) - handler->handleUseOfUninitVariable(be, vd); + Value v = vals[vd]; + if (isUninitialized(v)) + handler->handleUseOfUninitVariable(be, vd, isAlwaysUninit(v)); } } @@ -468,9 +488,9 @@ Visit(bo->getLHS()); ValueVector::reference val = vals[vd]; - if (val == Uninitialized) { + if (isUninitialized(val)) { if (bo->getOpcode() != BO_Assign) - reportUninit(res.getDeclRefExpr(), vd); + reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val)); val = Initialized; } return; @@ -496,10 +516,11 @@ res.getDeclRefExpr()); Visit(uo->getSubExpr()); - ValueVector::reference bit = vals[vd]; - if (bit == Uninitialized) { - reportUninit(res.getDeclRefExpr(), vd); - bit = Initialized; + ValueVector::reference val = vals[vd]; + if (isUninitialized(val)) { + reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val)); + // Don't cascade warnings. + val = Initialized; } return; } @@ -526,10 +547,13 @@ SaveAndRestore lastDR(currentDR, res.getDeclRefExpr()); Visit(ce->getSubExpr()); - if (currentVoidCast != ce && vals[vd] == Uninitialized) { - reportUninit(res.getDeclRefExpr(), vd); - // Don't cascade warnings. - vals[vd] = Initialized; + if (currentVoidCast != ce) { + Value val = vals[vd]; + if (isUninitialized(val)) { + reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val)); + // Don't cascade warnings. + vals[vd] = Initialized; + } } return; } Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=127666&r1=127665&r2=127666&view=diff ============================================================================== --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original) +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Mar 14 23:57:38 2011 @@ -377,18 +377,20 @@ // -Wuninitialized //===----------------------------------------------------------------------===// +typedef std::pair UninitUse; + namespace { struct SLocSort { - bool operator()(const Expr *a, const Expr *b) { - SourceLocation aLoc = a->getLocStart(); - SourceLocation bLoc = b->getLocStart(); + bool operator()(const UninitUse &a, const UninitUse &b) { + SourceLocation aLoc = a.first->getLocStart(); + SourceLocation bLoc = b.first->getLocStart(); return aLoc.getRawEncoding() < bLoc.getRawEncoding(); } }; class UninitValsDiagReporter : public UninitVariablesHandler { Sema &S; - typedef llvm::SmallVector UsesVec; + typedef llvm::SmallVector UsesVec; typedef llvm::DenseMap UsesMap; UsesMap *uses; @@ -398,7 +400,8 @@ flushDiagnostics(); } - void handleUseOfUninitVariable(const Expr *ex, const VarDecl *vd) { + void handleUseOfUninitVariable(const Expr *ex, const VarDecl *vd, + bool isAlwaysUninit) { if (!uses) uses = new UsesMap(); @@ -406,7 +409,7 @@ if (!vec) vec = new UsesVec(); - vec->push_back(ex); + vec->push_back(std::make_pair(ex, isAlwaysUninit)); } void flushDiagnostics() { @@ -426,13 +429,18 @@ for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve; ++vi) { - if (const DeclRefExpr *dr = dyn_cast(*vi)) { - S.Diag(dr->getLocStart(), diag::warn_uninit_var) + const bool isAlwaysUninit = vi->second; + if (const DeclRefExpr *dr = dyn_cast(vi->first)) { + S.Diag(dr->getLocStart(), + isAlwaysUninit ? diag::warn_uninit_var + : diag::warn_maybe_uninit_var) << vd->getDeclName() << dr->getSourceRange(); } else { - const BlockExpr *be = cast(*vi); - S.Diag(be->getLocStart(), diag::warn_uninit_var_captured_by_block) + const BlockExpr *be = cast(vi->first); + S.Diag(be->getLocStart(), + isAlwaysUninit ? diag::warn_uninit_var_captured_by_block + : diag::warn_maybe_uninit_var_captured_by_block) << vd->getDeclName(); } Modified: cfe/trunk/test/Sema/uninit-variables.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=127666&r1=127665&r2=127666&view=diff ============================================================================== --- cfe/trunk/test/Sema/uninit-variables.c (original) +++ cfe/trunk/test/Sema/uninit-variables.c Mon Mar 14 23:57:38 2011 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -Wuninitialized-maybe -fsyntax-only -fblocks %s -verify int test1() { int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} From kremenek at apple.com Tue Mar 15 00:22:28 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 05:22:28 -0000 Subject: [cfe-commits] r127669 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td lib/Analysis/UninitializedValues.cpp lib/Sema/AnalysisBasedWarnings.cpp Message-ID: <20110315052228.78BC12A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 00:22:28 2011 New Revision: 127669 URL: http://llvm.org/viewvc/llvm-project?rev=127669&view=rev Log: Split warnings from -Wuninitialized-experimental into "must-be-initialized" and "may-be-initialized" warnings, each controlled by different flags. Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/lib/Analysis/UninitializedValues.cpp cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=127669&r1=127668&r2=127669&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar 15 00:22:28 2011 @@ -136,7 +136,7 @@ def Trigraphs : DiagGroup<"trigraphs">; def : DiagGroup<"type-limits">; - +def Uninitialized : DiagGroup<"uninitialized">; def UninitializedMaybe : DiagGroup<"uninitialized-maybe">; def UnknownPragmas : DiagGroup<"unknown-pragmas">; def UnknownAttributes : DiagGroup<"unknown-attributes">; Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127669&r1=127668&r2=127669&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Tue Mar 15 00:22:28 2011 @@ -198,6 +198,9 @@ return 0; const CFGStmt *cstmt = block->front().getAs(); + if (!cstmt) + return 0; + BinaryOperator *b = llvm::dyn_cast_or_null(cstmt->getStmt()); if (!b || !b->isLogicalOp()) Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=127669&r1=127668&r2=127669&view=diff ============================================================================== --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original) +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Mar 15 00:22:28 2011 @@ -608,6 +608,8 @@ CheckUnreachable(S, AC); if (Diags.getDiagnosticLevel(diag::warn_uninit_var, D->getLocStart()) + != Diagnostic::Ignored || + Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart()) != Diagnostic::Ignored) { ASTContext &ctx = D->getASTContext(); llvm::OwningPtr tmpCFG; From kremenek at apple.com Tue Mar 15 00:22:33 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 05:22:33 -0000 Subject: [cfe-commits] r127670 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td test/Sema/uninit-variables.c test/SemaCXX/uninit-variables.cpp test/SemaObjC/uninit-variables.m Message-ID: <20110315052233.3FA8B2A6C12D@llvm.org> Author: kremenek Date: Tue Mar 15 00:22:33 2011 New Revision: 127670 URL: http://llvm.org/viewvc/llvm-project?rev=127670&view=rev Log: Take 2: merge -Wuninitialized-experimental into -Wuninitialized. Only *must-be-uninitialized* warnings are reported, with *maybe-uninitialized* under a separate flag. I await any fallout/comments/feedback, although hopefully this will produce no noise for users. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/test/Sema/uninit-variables.c cfe/trunk/test/SemaCXX/uninit-variables.cpp cfe/trunk/test/SemaObjC/uninit-variables.m Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127670&r1=127669&r2=127670&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 15 00:22:33 2011 @@ -867,7 +867,7 @@ def warn_field_is_uninit : Warning<"field is uninitialized when used here">, InGroup; def warn_uninit_var : Warning<"variable %0 is possibly uninitialized when used here">, - InGroup>, DefaultIgnore; + InGroup, DefaultIgnore; def warn_maybe_uninit_var : Warning<"variable %0 is possibly uninitialized when used here">, InGroup, DefaultIgnore; @@ -875,7 +875,7 @@ "variable %0 is declared here">; def warn_uninit_var_captured_by_block : Warning< "variable %0 is possibly uninitialized when captured by block">, - InGroup>, DefaultIgnore; + InGroup, DefaultIgnore; def warn_maybe_uninit_var_captured_by_block : Warning< "variable %0 is possibly uninitialized when captured by block">, InGroup, DefaultIgnore; Modified: cfe/trunk/test/Sema/uninit-variables.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=127670&r1=127669&r2=127670&view=diff ============================================================================== --- cfe/trunk/test/Sema/uninit-variables.c (original) +++ cfe/trunk/test/Sema/uninit-variables.c Tue Mar 15 00:22:33 2011 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -Wuninitialized-maybe -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wuninitialized-maybe -fsyntax-only -fblocks %s -verify int test1() { int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} Modified: cfe/trunk/test/SemaCXX/uninit-variables.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables.cpp?rev=127670&r1=127669&r2=127670&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/uninit-variables.cpp (original) +++ cfe/trunk/test/SemaCXX/uninit-variables.cpp Tue Mar 15 00:22:33 2011 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify int test1_aux(int &x); int test1() { Modified: cfe/trunk/test/SemaObjC/uninit-variables.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/uninit-variables.m?rev=127670&r1=127669&r2=127670&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/uninit-variables.m (original) +++ cfe/trunk/test/SemaObjC/uninit-variables.m Tue Mar 15 00:22:33 2011 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fblocks %s -verify // Duplicated from uninit-variables.c. // Test just to ensure the analysis is working. From kremenek at apple.com Tue Mar 15 00:25:02 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 05:25:02 -0000 Subject: [cfe-commits] r127671 - /cfe/trunk/include/clang/Basic/DiagnosticGroups.td Message-ID: <20110315052502.757852A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 00:25:02 2011 New Revision: 127671 URL: http://llvm.org/viewvc/llvm-project?rev=127671&view=rev Log: Remove duplicate group definition that snuck in due to a merge conflict. Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=127671&r1=127670&r2=127671&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Mar 15 00:25:02 2011 @@ -200,10 +200,6 @@ UnusedValue, UnusedVariable]>, DiagCategory<"Unused Entity Issue">; -def Uninitialized : DiagGroup<"uninitialized", - [UninitializedMaybe]>, - DiagCategory<"Uninitialized Value Issues">; - // Format settings. def FormatSecurity : DiagGroup<"format-security">; def Format : DiagGroup<"format", From kremenek at apple.com Tue Mar 15 00:30:12 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 05:30:12 -0000 Subject: [cfe-commits] r127672 - /cfe/trunk/lib/Analysis/UninitializedValues.cpp Message-ID: <20110315053012.EDA332A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 00:30:12 2011 New Revision: 127672 URL: http://llvm.org/viewvc/llvm-project?rev=127672&view=rev Log: Appease GCC. I'm surprised Clang accepted this. Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127672&r1=127671&r2=127672&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Tue Mar 15 00:30:12 2011 @@ -116,10 +116,6 @@ unsigned x = (vv.vec[idx << 1] ? 1 : 0) | (vv.vec[(idx << 1) | 1] ? 2 :0); return (Value) x; } - - bool operator==(Value v) { - return v = operator Value(); - } }; reference operator[](unsigned idx) { return reference(*this, idx); } @@ -132,7 +128,7 @@ const CFG &cfg; BVPair *vals; ValueVector scratch; - DeclToIndex DeclToIndex; + DeclToIndex declToIndex; ValueVector &lazyCreate(ValueVector *&bv); public: @@ -150,7 +146,7 @@ bool updateValueVectors(const CFGBlock *block, const BVPair &newVals); bool hasNoDeclarations() const { - return DeclToIndex.size() == 0; + return declToIndex.size() == 0; } void resetScratch(); @@ -180,13 +176,13 @@ } void CFGBlockValues::computeSetOfDeclarations(const DeclContext &dc) { - DeclToIndex.computeMap(dc); - scratch.resize(DeclToIndex.size()); + declToIndex.computeMap(dc); + scratch.resize(declToIndex.size()); } ValueVector &CFGBlockValues::lazyCreate(ValueVector *&bv) { if (!bv) - bv = new ValueVector(DeclToIndex.size()); + bv = new ValueVector(declToIndex.size()); return *bv; } @@ -286,7 +282,7 @@ } ValueVector::reference CFGBlockValues::operator[](const VarDecl *vd) { - const llvm::Optional &idx = DeclToIndex.getValueIndex(vd); + const llvm::Optional &idx = declToIndex.getValueIndex(vd); assert(idx.hasValue()); return scratch[idx.getValue()]; } From sebastian.redl at getdesigned.at Tue Mar 15 05:50:02 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Tue, 15 Mar 2011 11:50:02 +0100 Subject: [cfe-commits] r127617 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp In-Reply-To: <201031D7-35EC-4F00-ABEA-F9D1D76EBDA7@2pi.dk> References: <20110314203321.1D6DD2A6C12C@llvm.org> <201031D7-35EC-4F00-ABEA-F9D1D76EBDA7@2pi.dk> Message-ID: <4D7F4459.1060702@getdesigned.at> On 15.03.2011 01:04, Jakob Stoklund Olesen wrote: > On Mar 14, 2011, at 1:33 PM, Sebastian Redl wrote: > >> Author: cornedbee >> Date: Mon Mar 14 15:33:20 2011 >> New Revision: 127617 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127617&view=rev >> Log: >> Code generation for noexcept. >> >> Added: >> cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp >> cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp > These tests are failing in a release (-Asserts) build: I have practically no experience with CodeGen. Does anyone have any idea why things would be different in Release-Assert? Sebastian From joerg at britannica.bec.de Tue Mar 15 08:28:26 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Tue, 15 Mar 2011 14:28:26 +0100 Subject: [cfe-commits] Inferring host triple from command name In-Reply-To: <20110314231906.GA1690@britannica.bec.de> References: <20110314231906.GA1690@britannica.bec.de> Message-ID: <20110315132826.GA19168@britannica.bec.de> Hi all, this is another try to get the program parsing correct. It tries to be less magical and more explicit. I think it allows all the usual ways of deployment, but if there is a suffix missing, it is easy to add. Comments? Joerg -------------- next part -------------- A non-text attachment was scrubbed... Name: driver-target.diff Type: text/x-diff Size: 4494 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110315/11bdfbbf/attachment.bin From rafael.espindola at gmail.com Tue Mar 15 09:12:08 2011 From: rafael.espindola at gmail.com (=?ISO-8859-1?Q?Rafael_=C1vila_de_Esp=EDndola?=) Date: Tue, 15 Mar 2011 10:12:08 -0400 Subject: [cfe-commits] r127617 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp In-Reply-To: <4D7F4459.1060702@getdesigned.at> References: <20110314203321.1D6DD2A6C12C@llvm.org> <201031D7-35EC-4F00-ABEA-F9D1D76EBDA7@2pi.dk> <4D7F4459.1060702@getdesigned.at> Message-ID: <4D7F73B8.8080703@gmail.com> > I have practically no experience with CodeGen. Does anyone have any idea > why things would be different in Release-Assert? Different labels and variables names maybe? > Sebastian Cheers, Rafael From stoklund at 2pi.dk Tue Mar 15 10:15:05 2011 From: stoklund at 2pi.dk (Jakob Stoklund Olesen) Date: Tue, 15 Mar 2011 08:15:05 -0700 Subject: [cfe-commits] r127617 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp In-Reply-To: <4D7F4459.1060702@getdesigned.at> References: <20110314203321.1D6DD2A6C12C@llvm.org> <201031D7-35EC-4F00-ABEA-F9D1D76EBDA7@2pi.dk> <4D7F4459.1060702@getdesigned.at> Message-ID: <868F53EE-0D77-44BE-819C-64475969A55F@2pi.dk> On Mar 15, 2011, at 3:50 AM, Sebastian Redl wrote: > On 15.03.2011 01:04, Jakob Stoklund Olesen wrote: >> On Mar 14, 2011, at 1:33 PM, Sebastian Redl wrote: >> >>> Author: cornedbee >>> Date: Mon Mar 14 15:33:20 2011 >>> New Revision: 127617 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=127617&view=rev >>> Log: >>> Code generation for noexcept. >>> >>> Added: >>> cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp >>> cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp >> These tests are failing in a release (-Asserts) build: > I have practically no experience with CodeGen. Does anyone have any idea why things would be different in Release-Assert? The -Asserts build omits all value names that aren't strictly necessary. From your p9-dynamic.cpp: +Asserts: lpad: ; preds = %entry %exn = call i8* @llvm.eh.exception() nounwind store i8* %exn, i8** %exn.slot %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind %ehspec.fails = icmp slt i32 %eh.selector, 0 br i1 %ehspec.fails, label %ehspec.unexpected, label %cleanup -Asserts: ;

  • C++0x inline namespaces
  • C++0x strongly-typed enumerations
  • C++0x trailing return type
  • +
  • C++0x noexcept specification
  • Checks for Type Traits
  • Blocks
  • @@ -436,6 +437,11 @@

    Use __has_feature(cxx_trailing_return) to determine if support for the alternate function declaration syntax with trailing return type is enabled.

    +

    C++0x noexcept

    + +

    Use __has_feature(cxx_noexcept) to determine if support for +noexcept exception specifications is enabled.

    +

    C++0x strongly typed enumerations

    Use __has_feature(cxx_strong_enums) to determine if support for Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=127701&r1=127700&r2=127701&view=diff ============================================================================== --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original) +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Mar 15 16:17:12 2011 @@ -560,6 +560,7 @@ .Case("cxx_deleted_functions", LangOpts.CPlusPlus0x) .Case("cxx_inline_namespaces", LangOpts.CPlusPlus0x) //.Case("cxx_lambdas", false) + .Case("cxx_noexcept", LangOpts.CPlusPlus0x) //.Case("cxx_nullptr", false) .Case("cxx_reference_qualified_functions", LangOpts.CPlusPlus0x) .Case("cxx_rvalue_references", LangOpts.CPlusPlus0x) Modified: cfe/trunk/test/Lexer/has_feature_cxx0x.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_feature_cxx0x.cpp?rev=127701&r1=127700&r2=127701&view=diff ============================================================================== --- cfe/trunk/test/Lexer/has_feature_cxx0x.cpp (original) +++ cfe/trunk/test/Lexer/has_feature_cxx0x.cpp Tue Mar 15 16:17:12 2011 @@ -117,3 +117,12 @@ // CHECK-0X: has_default_function_template_args // CHECK-NO-0X: no_default_function_template_args +#if __has_feature(cxx_noexcept) +int has_noexcept(); +#else +int no_noexcept(); +#endif + +// CHECK-0X: has_noexcept +// CHECK-NO-0X: no_noexcept + From rjmccall at apple.com Tue Mar 15 16:17:48 2011 From: rjmccall at apple.com (John McCall) Date: Tue, 15 Mar 2011 21:17:48 -0000 Subject: [cfe-commits] r127702 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/member-function-pointers.cpp Message-ID: <20110315211748.779FE2A6C12C@llvm.org> Author: rjmccall Date: Tue Mar 15 16:17:48 2011 New Revision: 127702 URL: http://llvm.org/viewvc/llvm-project?rev=127702&view=rev Log: Reorganize the emission of (unfoldable) constant casts a bit, and make sure that upcasts of member pointer types are covered as constants. Fixed rdar://problem/9130221 Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127702&r1=127701&r2=127702&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Mar 15 16:17:48 2011 @@ -483,18 +483,17 @@ } llvm::Constant *VisitCastExpr(CastExpr* E) { + Expr *subExpr = E->getSubExpr(); + llvm::Constant *C = CGM.EmitConstantExpr(subExpr, subExpr->getType(), CGF); + if (!C) return 0; + + const llvm::Type *destType = ConvertType(E->getType()); + switch (E->getCastKind()) { case CK_ToUnion: { // GCC cast to union extension assert(E->getType()->isUnionType() && "Destination type is not union type!"); - const llvm::Type *Ty = ConvertType(E->getType()); - Expr *SubExpr = E->getSubExpr(); - - llvm::Constant *C = - CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); - if (!C) - return 0; // Build a struct with the union sub-element as the first member, // and padded to the appropriate size @@ -503,7 +502,7 @@ Elts.push_back(C); Types.push_back(C->getType()); unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); - unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(Ty); + unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(destType); assert(CurSize <= TotalSize && "Union size mismatch!"); if (unsigned NumPadBytes = TotalSize - CurSize) { @@ -523,39 +522,101 @@ const MemberPointerType *MPT = E->getType()->getAs(); return CGM.getCXXABI().EmitNullMemberPointer(MPT); } - - case CK_BaseToDerivedMemberPointer: { - Expr *SubExpr = E->getSubExpr(); - llvm::Constant *C = - CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); - if (!C) return 0; + case CK_DerivedToBaseMemberPointer: + case CK_BaseToDerivedMemberPointer: return CGM.getCXXABI().EmitMemberPointerConversion(C, E); - } - case CK_BitCast: - // This must be a member function pointer cast. - return Visit(E->getSubExpr()); - - default: { - // FIXME: This should be handled by the CK_NoOp cast kind. - // Explicit and implicit no-op casts - QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); - if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) - return Visit(E->getSubExpr()); - - // Handle integer->integer casts for address-of-label differences. - if (Ty->isIntegerType() && SubTy->isIntegerType() && - CGF) { - llvm::Value *Src = Visit(E->getSubExpr()); - if (Src == 0) return 0; - - // Use EmitScalarConversion to perform the conversion. - return cast(CGF->EmitScalarConversion(Src, SubTy, Ty)); - } - + case CK_LValueToRValue: + case CK_NoOp: + return C; + + case CK_AnyPointerToObjCPointerCast: + case CK_AnyPointerToBlockPointerCast: + case CK_LValueBitCast: + case CK_BitCast: + if (C->getType() == destType) return C; + return llvm::ConstantExpr::getBitCast(C, destType); + + case CK_Dependent: llvm_unreachable("saw dependent cast!"); + + // These will never be supported. + case CK_ObjCObjectLValueCast: + case CK_GetObjCProperty: + case CK_ToVoid: + case CK_Dynamic: return 0; + + // These might need to be supported for constexpr. + case CK_UserDefinedConversion: + case CK_ConstructorConversion: + return 0; + + // These should eventually be supported. + case CK_ArrayToPointerDecay: + case CK_FunctionToPointerDecay: + case CK_BaseToDerived: + case CK_DerivedToBase: + case CK_UncheckedDerivedToBase: + case CK_MemberPointerToBoolean: + case CK_VectorSplat: + case CK_FloatingRealToComplex: + case CK_FloatingComplexToReal: + case CK_FloatingComplexToBoolean: + case CK_FloatingComplexCast: + case CK_FloatingComplexToIntegralComplex: + case CK_IntegralRealToComplex: + case CK_IntegralComplexToReal: + case CK_IntegralComplexToBoolean: + case CK_IntegralComplexCast: + case CK_IntegralComplexToFloatingComplex: + return 0; + + case CK_PointerToIntegral: + if (!E->getType()->isBooleanType()) + return llvm::ConstantExpr::getPtrToInt(C, destType); + // fallthrough + + case CK_PointerToBoolean: + return llvm::ConstantExpr::getICmp(llvm::CmpInst::ICMP_EQ, C, + llvm::ConstantPointerNull::get(cast(C->getType()))); + + case CK_NullToPointer: + return llvm::ConstantPointerNull::get(cast(destType)); + + case CK_IntegralCast: { + bool isSigned = subExpr->getType()->isSignedIntegerType(); + return llvm::ConstantExpr::getIntegerCast(C, destType, isSigned); + } + + case CK_IntegralToPointer: { + bool isSigned = subExpr->getType()->isSignedIntegerType(); + C = llvm::ConstantExpr::getIntegerCast(C, CGM.IntPtrTy, isSigned); + return llvm::ConstantExpr::getIntToPtr(C, destType); } + + case CK_IntegralToBoolean: + return llvm::ConstantExpr::getICmp(llvm::CmpInst::ICMP_EQ, C, + llvm::Constant::getNullValue(C->getType())); + + case CK_IntegralToFloating: + if (subExpr->getType()->isSignedIntegerType()) + return llvm::ConstantExpr::getSIToFP(C, destType); + else + return llvm::ConstantExpr::getUIToFP(C, destType); + + case CK_FloatingToIntegral: + if (E->getType()->isSignedIntegerType()) + return llvm::ConstantExpr::getFPToSI(C, destType); + else + return llvm::ConstantExpr::getFPToUI(C, destType); + + case CK_FloatingToBoolean: + return llvm::ConstantExpr::getFCmp(llvm::CmpInst::FCMP_UNE, C, + llvm::Constant::getNullValue(C->getType())); + + case CK_FloatingCast: + return llvm::ConstantExpr::getFPCast(C, destType); } } Modified: cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp?rev=127702&r1=127701&r2=127702&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp (original) +++ cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp Tue Mar 15 16:17:48 2011 @@ -209,3 +209,26 @@ return pmf(); } } + +namespace test9 { + struct A { + void foo(); + }; + struct B : A { + void foo(); + }; + + typedef void (A::*fooptr)(); + + struct S { + fooptr p; + }; + + // CHECK: define void @_ZN5test94testEv( + // CHECK: alloca i32 + // CHECK-NEXT: ret void + void test() { + int x; + static S array[] = { (fooptr) &B::foo }; + } +} From kremenek at apple.com Tue Mar 15 16:18:48 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 21:18:48 -0000 Subject: [cfe-commits] r127703 - /cfe/trunk/lib/Sema/SemaChecking.cpp Message-ID: <20110315211848.B828B2A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 16:18:48 2011 New Revision: 127703 URL: http://llvm.org/viewvc/llvm-project?rev=127703&view=rev Log: Don't warn about null characters in Objective-C format string literals. Modified: cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=127703&r1=127702&r2=127703&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 15 16:18:48 2011 @@ -1218,10 +1218,12 @@ } void CheckFormatHandler::HandleNullChar(const char *nullCharacter) { - // The presence of a null character is likely an error. - S.Diag(getLocationOfByte(nullCharacter), - diag::warn_printf_format_string_contains_null_char) - << getFormatStringRange(); + if (!IsObjCLiteral) { + // The presence of a null character is likely an error. + S.Diag(getLocationOfByte(nullCharacter), + diag::warn_printf_format_string_contains_null_char) + << getFormatStringRange(); + } } const Expr *CheckFormatHandler::getDataArg(unsigned i) const { From kremenek at apple.com Tue Mar 15 16:18:52 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 21:18:52 -0000 Subject: [cfe-commits] r127704 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp test/Sema/builtins.c test/SemaObjC/exprs.m Message-ID: <20110315211853.076EB2A6C12D@llvm.org> Author: kremenek Date: Tue Mar 15 16:18:52 2011 New Revision: 127704 URL: http://llvm.org/viewvc/llvm-project?rev=127704&view=rev Log: Remove warning for null characters in CFString literals. Clang handles them just fine, and GCC 4.2 doesn't warn here either. We added this warning back in 2007 when we were comparing against GCC 4.0. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/Sema/builtins.c cfe/trunk/test/SemaObjC/exprs.m Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127704&r1=127703&r2=127704&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 15 16:18:52 2011 @@ -3607,8 +3607,6 @@ // CFString checking def err_cfstring_literal_not_string_constant : Error< "CFString literal is not a string constant">; -def warn_cfstring_literal_contains_nul_character : Warning< - "CFString literal contains NUL character">; def warn_cfstring_truncated : Warning< "input conversion stopped due to an input byte that does not " "belong to the input codeset UTF-8">; Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=127704&r1=127703&r2=127704&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 15 16:18:52 2011 @@ -552,12 +552,6 @@ return true; } - size_t NulPos = Literal->getString().find('\0'); - if (NulPos != llvm::StringRef::npos) { - Diag(getLocationOfStringLiteralByte(Literal, NulPos), - diag::warn_cfstring_literal_contains_nul_character) - << Arg->getSourceRange(); - } if (Literal->containsNonAsciiOrNull()) { llvm::StringRef String = Literal->getString(); unsigned NumBytes = String.size(); Modified: cfe/trunk/test/Sema/builtins.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=127704&r1=127703&r2=127704&view=diff ============================================================================== --- cfe/trunk/test/Sema/builtins.c (original) +++ cfe/trunk/test/Sema/builtins.c Tue Mar 15 16:18:52 2011 @@ -27,7 +27,7 @@ void test7() { const void *X; X = CFSTR("\242"); // expected-warning {{input conversion stopped}} - X = CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }} + X = CFSTR("\0"); // no-warning X = CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}} X = CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}} } Modified: cfe/trunk/test/SemaObjC/exprs.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/exprs.m?rev=127704&r1=127703&r2=127704&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/exprs.m (original) +++ cfe/trunk/test/SemaObjC/exprs.m Tue Mar 15 16:18:52 2011 @@ -9,12 +9,12 @@ // rdar://6079877 void test2() { id str = @"foo" - "bar\0" // expected-warning {{literal contains NUL character}} + "bar\0" // no-warning @"baz" " blarg"; id str2 = @"foo" "bar" @"baz" - " b\0larg"; // expected-warning {{literal contains NUL character}} + " b\0larg"; // no-warning if (@encode(int) == "foo") { } // expected-warning {{result of comparison against @encode is unspecified}} From geek4civic at gmail.com Tue Mar 15 17:53:24 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Wed, 16 Mar 2011 07:53:24 +0900 Subject: [cfe-commits] r127405 - /cfe/trunk/lib/CodeGen/CGCall.cpp In-Reply-To: References: <20110310140221.6A27D2A6C12C@llvm.org> Message-ID: Bill, ping, please pick it up! ...Takumi On Sat, Mar 12, 2011 at 10:33 AM, Douglas Gregor wrote: > Bill, please pull this patch into the 2.9 branch. > > ? ? ? ?Thanks! > ? ? ? ?Doug > > On Mar 10, 2011, at 6:02 AM, NAKAMURA Takumi wrote: > >> Author: chapuni >> Date: Thu Mar 10 08:02:21 2011 >> New Revision: 127405 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127405&view=rev >> Log: >> lib/CodeGen/CGCall.cpp: Don't invoke multiple Builder.CreateBitCast() on Builder.CreateMemCpy. Or we would see sideeffect incompatibility among gcc and clang. >> >> Modified: >> ? ?cfe/trunk/lib/CodeGen/CGCall.cpp >> >> Modified: cfe/trunk/lib/CodeGen/CGCall.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=127405&r1=127404&r2=127405&view=diff >> ============================================================================== >> --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) >> +++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Mar 10 08:02:21 2011 >> @@ -909,8 +909,10 @@ >> ? ? ? ? ? // copy. >> ? ? ? ? ? const llvm::Type *I8PtrTy = Builder.getInt8PtrTy(); >> ? ? ? ? ? CharUnits Size = getContext().getTypeSizeInChars(Ty); >> - ? ? ? ? ?Builder.CreateMemCpy(Builder.CreateBitCast(AlignedTemp, I8PtrTy), >> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Builder.CreateBitCast(V, I8PtrTy), >> + ? ? ? ? ?llvm::Value *Dst = Builder.CreateBitCast(AlignedTemp, I8PtrTy); >> + ? ? ? ? ?llvm::Value *Src = Builder.CreateBitCast(V, I8PtrTy); >> + ? ? ? ? ?Builder.CreateMemCpy(Dst, >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Src, >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?llvm::ConstantInt::get(IntPtrTy, >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Size.getQuantity()), >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ArgI.getIndirectAlign(), >> >> >> _______________________________________________ >> cfe-commits mailing list >> cfe-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > From kremenek at apple.com Tue Mar 15 18:47:49 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 23:47:49 -0000 Subject: [cfe-commits] r127711 - in /cfe/trunk: test/Index/cindex-on-invalid.m tools/libclang/CIndex.cpp Message-ID: <20110315234750.116E92A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 18:47:49 2011 New Revision: 127711 URL: http://llvm.org/viewvc/llvm-project?rev=127711&view=rev Log: c-index-test shouldn't crash when a goto has no matching label. Fixes . Modified: cfe/trunk/test/Index/cindex-on-invalid.m cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/test/Index/cindex-on-invalid.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/cindex-on-invalid.m?rev=127711&r1=127710&r2=127711&view=diff ============================================================================== --- cfe/trunk/test/Index/cindex-on-invalid.m (original) +++ cfe/trunk/test/Index/cindex-on-invalid.m Tue Mar 15 18:47:49 2011 @@ -1,6 +1,13 @@ // RUN: c-index-test -test-load-source local %s 2>&1 | FileCheck %s +// +void test() { + goto exit; +} + int foo; int -// CHECK: cindex-on-invalid.m:6:70: error: expected identifier or '(' \ No newline at end of file +// CHECK: cindex-on-invalid.m:5:8: error: use of undeclared label 'exit' +// CHECK: cindex-on-invalid.m:13:1: error: expected identifier or '(' + Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127711&r1=127710&r2=127711&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Mar 15 18:47:49 2011 @@ -3709,7 +3709,9 @@ if (clang_isStatement(C.kind)) { Stmt *S = getCursorStmt(C); if (GotoStmt *Goto = dyn_cast_or_null(S)) - return MakeCXCursor(Goto->getLabel()->getStmt(), getCursorDecl(C), tu); + if (LabelDecl *label = Goto->getLabel()) + if (LabelStmt *labelS = label->getStmt()) + return MakeCXCursor(labelS, getCursorDecl(C), tu); return clang_getNullCursor(); } From kremenek at apple.com Tue Mar 15 19:22:51 2011 From: kremenek at apple.com (Ted Kremenek) Date: Wed, 16 Mar 2011 00:22:51 -0000 Subject: [cfe-commits] r127719 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp test/Analysis/variadic-method-types.m Message-ID: <20110316002251.4A6562A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 19:22:51 2011 New Revision: 127719 URL: http://llvm.org/viewvc/llvm-project?rev=127719&view=rev Log: VariadicMethodTypeChecker: don't warn for null pointer constants passed to variadic Objective-C methods. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp cfe/trunk/test/Analysis/variadic-method-types.m Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=127719&r1=127718&r2=127719&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Tue Mar 15 19:22:51 2011 @@ -584,12 +584,17 @@ // Verify that all arguments have Objective-C types. llvm::Optional errorNode; + const GRState *state = C.getState(); for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) { QualType ArgTy = msg.getArgType(I); if (ArgTy->isObjCObjectPointerType()) continue; + // Ignore pointer constants. + if (isa(msg.getArgSVal(I, state))) + continue; + // Generate only one error node to use for all bug reports. if (!errorNode.hasValue()) { errorNode = C.generateNode(); Modified: cfe/trunk/test/Analysis/variadic-method-types.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/variadic-method-types.m?rev=127719&r1=127718&r2=127719&view=diff ============================================================================== --- cfe/trunk/test/Analysis/variadic-method-types.m (original) +++ cfe/trunk/test/Analysis/variadic-method-types.m Tue Mar 15 19:22:51 2011 @@ -69,6 +69,7 @@ [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} } From rjmccall at apple.com Tue Mar 15 21:53:38 2011 From: rjmccall at apple.com (John McCall) Date: Wed, 16 Mar 2011 02:53:38 -0000 Subject: [cfe-commits] r127725 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenObjC/blocks.m Message-ID: <20110316025338.F13F32A6C12D@llvm.org> Author: rjmccall Date: Tue Mar 15 21:53:38 2011 New Revision: 127725 URL: http://llvm.org/viewvc/llvm-project?rev=127725&view=rev Log: Don't emit read barriers for reading __weak __block variables in non-GC mode. Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp cfe/trunk/test/CodeGenObjC/blocks.m Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=127725&r1=127724&r2=127725&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Mar 15 21:53:38 2011 @@ -1221,10 +1221,8 @@ } Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) { - llvm::Value *V = CGF.GetAddrOfBlockDecl(E); - if (E->getType().isObjCGCWeak()) - return CGF.CGM.getObjCRuntime().EmitObjCWeakRead(CGF, V); - return CGF.EmitLoadOfScalar(V, false, 0, E->getType()); + LValue LV = CGF.EmitBlockDeclRefLValue(E); + return CGF.EmitLoadOfLValue(LV, E->getType()).getScalarVal(); } //===----------------------------------------------------------------------===// Modified: cfe/trunk/test/CodeGenObjC/blocks.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/blocks.m?rev=127725&r1=127724&r2=127725&view=diff ============================================================================== --- cfe/trunk/test/CodeGenObjC/blocks.m (original) +++ cfe/trunk/test/CodeGenObjC/blocks.m Tue Mar 15 21:53:38 2011 @@ -87,3 +87,16 @@ __weak __block Test2 *weakX = x; test2_helper(^{ [weakX destroy]; }); } + +// rdar://problem/9124263 +// In the test above, check that the use in the invocation function +// doesn't require a read barrier. +// CHECK: define internal void @__test2_block_invoke_ +// CHECK: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]* +// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-NEXT: [[T1:%.*]] = load i8** [[T0]] +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[WEAK_T]]* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T2]], i32 0, i32 1 +// CHECK-NEXT: [[T4:%.*]] = load [[WEAK_T]]** [[T3]] +// CHECK-NEXT: [[WEAKX:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T4]], i32 0, i32 6 +// CHECK-NEXT: [[T0:%.*]] = load [[TEST2]]** [[WEAKX]], align 4 From jim at thegoodnows.net Tue Mar 15 23:13:18 2011 From: jim at thegoodnows.net (Jim Goodnow II) Date: Tue, 15 Mar 2011 21:13:18 -0700 Subject: [cfe-commits] [Patch][review request]update to IteratorsChecker Message-ID: <201103160413.p2G4DRGd018566@relay02.cites.uiuc.edu> Added support for handling pointers to containers that wasn't handled. - jim Index: test/Analysis/iterators.cpp =================================================================== --- test/Analysis/iterators.cpp (revision 127607) +++ test/Analysis/iterators.cpp (working copy) @@ -5,8 +5,7 @@ void fum(std::vector::iterator t); -void foo1() -{ +void foo1() { // iterators that are defined but not initialized std::vector::iterator it2; fum(it2); // expected-warning{{Use of iterator that is not defined}} @@ -64,8 +63,7 @@ } // work with using namespace -void foo2() -{ +void foo2() { using namespace std; vector v; @@ -78,8 +76,7 @@ } // using reserve eliminates some warnings -void foo3() -{ +void foo3() { std::vector v; std::vector::iterator b = v.begin(); v.reserve( 100 ); @@ -94,8 +91,7 @@ } // check on copying one iterator to another -void foo4() -{ +void foo4() { std::vector v, vv; std::vector::iterator it = v.begin(); *it; // no-warning @@ -103,3 +99,14 @@ *it; // expected-warning{{Attempt to use an iterator made invalid by copying another container to its container}} } +// check for pointers to containers as well +void foo5() { + std::vector v, *vp; + vp = &v; + std::vector::iterator it; + it = vp->begin(); + *it; // no-warning + vp->insert( it, 1 ); + *it; // expected-warning{{Attempt to use an iterator made invalid by call to 'insert'.}} +} + Index: lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp (revision 127607) +++ lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp (working copy) @@ -197,6 +197,8 @@ } static RefKind getTemplateKind(QualType T) { + if ( isa(T) ) + T = T->getPointeeType(); if (const TemplateSpecializationType *tsp = T->getAs()) { return getTemplateKind(tsp); @@ -266,7 +268,10 @@ if (const CallExpr *CE = dyn_cast(rexp)) { // Handle MemberCall. if (const MemberExpr *ME = dyn_cast(CE->getCallee())) { - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); + const Expr *exp = ME->getBase(); + if (isa(exp)) + exp = dyn_cast(exp)->getSubExpr(); + const DeclRefExpr *DRE = dyn_cast(exp); if (!DRE) return state; // Verify that the type is std::vector. @@ -549,8 +554,11 @@ const MemberExpr *ME = dyn_cast(MCE->getCallee()); if (!ME) return; + const Expr *exp = ME->getBase(); + if (isa(exp)) + exp = dyn_cast(exp)->getSubExpr(); // Make sure we have the right kind of container. - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); + const DeclRefExpr *DRE = dyn_cast(exp); if (!DRE || getTemplateKind(DRE->getType()) != VectorKind) return; SVal tsv = C.getState()->getSVal(DRE); -------------- next part -------------- A non-text attachment was scrubbed... Name: itptr.patch Type: application/octet-stream Size: 3015 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110315/e8c98613/attachment-0001.obj From kremenek at apple.com Tue Mar 15 23:32:01 2011 From: kremenek at apple.com (Ted Kremenek) Date: Wed, 16 Mar 2011 04:32:01 -0000 Subject: [cfe-commits] r127727 - in /cfe/trunk: lib/Analysis/CFG.cpp test/SemaCXX/array-bounds.cpp Message-ID: <20110316043201.C4F012A6C12C@llvm.org> Author: kremenek Date: Tue Mar 15 23:32:01 2011 New Revision: 127727 URL: http://llvm.org/viewvc/llvm-project?rev=127727&view=rev Log: Teach CFGBuilder that the 'default' branch of a switch statement is dead if all enum values in a switch conditioned are handled. Modified: cfe/trunk/lib/Analysis/CFG.cpp cfe/trunk/test/SemaCXX/array-bounds.cpp Modified: cfe/trunk/lib/Analysis/CFG.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=127727&r1=127726&r2=127727&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/CFG.cpp (original) +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Mar 15 23:32:01 2011 @@ -2249,9 +2249,11 @@ } // If we have no "default:" case, the default transition is to the code - // following the switch body. + // following the switch body. Moreover, take into account if all the + // cases of a switch are covered (e.g., switching on an enum value). addSuccessor(SwitchTerminatedBlock, - switchExclusivelyCovered ? 0 : DefaultCaseBlock); + switchExclusivelyCovered || Terminator->isAllEnumCasesCovered() + ? 0 : DefaultCaseBlock); // Add the terminator and condition in the switch block. SwitchTerminatedBlock->setTerminator(Terminator); Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=127727&r1=127726&r2=127727&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/array-bounds.cpp (original) +++ cfe/trunk/test/SemaCXX/array-bounds.cpp Tue Mar 15 23:32:01 2011 @@ -160,3 +160,16 @@ } } +// Test that if all the values of an enum covered, that the 'default' branch +// is unreachable. +enum Values { A, B, C, D }; +void test_all_enums_covered(enum Values v) { + int x[2]; + switch (v) { + case A: return; + case B: return; + case C: return; + case D: return; + } + x[2] = 0; // no-warning +} From kremenek at apple.com Wed Mar 16 00:54:57 2011 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 15 Mar 2011 22:54:57 -0700 Subject: [cfe-commits] [Patch][review request]update to IteratorsChecker In-Reply-To: <0LI4001G5UEISX50@postino.apple.com> References: <0LI4001G5UEISX50@postino.apple.com> Message-ID: Hi Jim, While a nice increment on top of the existing checker, I think this takes the checker in a more syntactic direction, which isn't going to be a general solution. Instead of pattern matching on specific expressions, we should instead move the checker in a direction where it just lets the analyzer engine handle evaluating the semantics of expressions and have the checker look at SVals and MemRegions (i.e., the "semantics" instead of the "syntax"). For example, in checkPreStmt(CXXMemberCallExpr), there is no reason we need to rely on the base expression being a DeclRefExpr. Instead, we can just let the analyzer engine evaluate that subexpression; if that expression evaluates to a MemRegion, then we can proceed. There is no reason to make this dependent on DeclRefExpr, or any other expression, that evaluates to what we care about. Here's a suggested change: @@ -549,11 +554,11 @@ void IteratorsChecker::checkPreStmt(const CXXMemberCallExpr *MCE, const MemberExpr *ME = dyn_cast(MCE->getCallee()); if (!ME) return; + const Expr *exp = ME->getBase(); // Make sure we have the right kind of container. - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); - if (!DRE || getTemplateKind(DRE->getType()) != VectorKind) + if (getTemplateKind(exp->getType()) != VectorKind) return; - SVal tsv = C.getState()->getSVal(DRE); + SVal tsv = C.getState()->getSVal(exp); Note that this differs from your patch. There is no reason to match against implicit casts or pointer types. We just reason about the values the analyzer engine gives us. Probably what needs to be reworked to fully generalize the checker to work with arbitrary expressions is 'handleAssign'. handleAssign does a bunch of AST pattern matching, looking that specific expressions appeared on the RHS of the assignment. While syntactic pattern matching is easy to understand, it isn't fully general. Instead, we should just let the analyzer engine evaluate each subexpression, and track what information we need to implement the checker through the associated SVals. For example, I would expect the handling of 'begin', 'insert', 'erase', and 'end' to be in a checkerPostStmt(const CXXMemberCallExpr). These would then toggle the state associated with the target of the method call (which would be a MemRegion). For 'begin' and 'end', the call returns a value, which the analyzer engine will likely make a SymbolRegion. For that SymbolicRegion, we can associate checker-specific state in the GDM saying that MemRegion represents and iterator associated with a specific container. Indeed, your checker already does this: typedef llvm::ImmutableMap EntryMap; In other words, let the analyzer engine do the work of propagating values around and evaluating subexpressions, and let your checker add "instrumentation" at key points (namely before and after method calls) to toggle the iterator state. Once this restructuring is in place, you can probably remove 'handleAssign' entirely. There's also no reason to restrict the container to 'VarRegions'. Any 'TypedRegion' should probably work. This will allow your checker to immediately fully generalize to cases the checker doesn't consider, e.g.: void test(std::vector **x) { std::vector::iterator itr = (*x)->begin(); ... } If you let the analyzer handle the abstraction of memory and the evaluation of expressions, you don't need to reason syntactically about all these corner cases. Everything just composes, and works as you would expect. On Mar 15, 2011, at 9:13 PM, Jim Goodnow II wrote: > Added support for handling pointers to containers that wasn't handled. > > - jim > > Index: test/Analysis/iterators.cpp > =================================================================== > --- test/Analysis/iterators.cpp (revision 127607) > +++ test/Analysis/iterators.cpp (working copy) > @@ -5,8 +5,7 @@ > > void fum(std::vector::iterator t); > > -void foo1() > -{ > +void foo1() { > // iterators that are defined but not initialized > std::vector::iterator it2; > fum(it2); // expected-warning{{Use of iterator that is not defined}} > @@ -64,8 +63,7 @@ > } > > // work with using namespace > -void foo2() > -{ > +void foo2() { > using namespace std; > > vector v; > @@ -78,8 +76,7 @@ > } > > // using reserve eliminates some warnings > -void foo3() > -{ > +void foo3() { > std::vector v; > std::vector::iterator b = v.begin(); > v.reserve( 100 ); > @@ -94,8 +91,7 @@ > } > > // check on copying one iterator to another > -void foo4() > -{ > +void foo4() { > std::vector v, vv; > std::vector::iterator it = v.begin(); > *it; // no-warning > @@ -103,3 +99,14 @@ > *it; // expected-warning{{Attempt to use an iterator made invalid by copying another container to its container}} > } > > +// check for pointers to containers as well > +void foo5() { > + std::vector v, *vp; > + vp = &v; > + std::vector::iterator it; > + it = vp->begin(); > + *it; // no-warning > + vp->insert( it, 1 ); > + *it; // expected-warning{{Attempt to use an iterator made invalid by call to 'insert'.}} > +} > + > Index: lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp > =================================================================== > --- lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp (revision 127607) > +++ lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp (working copy) > @@ -197,6 +197,8 @@ > } > > static RefKind getTemplateKind(QualType T) { > + if ( isa(T) ) > + T = T->getPointeeType(); > if (const TemplateSpecializationType *tsp = > T->getAs()) { > return getTemplateKind(tsp); > @@ -266,7 +268,10 @@ > if (const CallExpr *CE = dyn_cast(rexp)) { > // Handle MemberCall. > if (const MemberExpr *ME = dyn_cast(CE->getCallee())) { > - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); > + const Expr *exp = ME->getBase(); > + if (isa(exp)) > + exp = dyn_cast(exp)->getSubExpr(); > + const DeclRefExpr *DRE = dyn_cast(exp); > if (!DRE) > return state; > // Verify that the type is std::vector. > @@ -549,8 +554,11 @@ > const MemberExpr *ME = dyn_cast(MCE->getCallee()); > if (!ME) > return; > + const Expr *exp = ME->getBase(); > + if (isa(exp)) > + exp = dyn_cast(exp)->getSubExpr(); > // Make sure we have the right kind of container. > - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); > + const DeclRefExpr *DRE = dyn_cast(exp); > if (!DRE || getTemplateKind(DRE->getType()) != VectorKind) > return; > SVal tsv = C.getState()->getSVal(DRE); From pichet2000 at gmail.com Wed Mar 16 08:41:40 2011 From: pichet2000 at gmail.com (Francois Pichet) Date: Wed, 16 Mar 2011 09:41:40 -0400 Subject: [cfe-commits] [PATCH][MS][Review request] - Late Microsoft template parsing In-Reply-To: <20110315185416.GA31253@bloodbath.burble.org> References: <6634690B-1E07-4EB5-8A10-6607A87E2331@apple.com> <045D8E3B-670A-4306-B5A1-EE9343BC5343@apple.com> <20110315185416.GA31253@bloodbath.burble.org> Message-ID: On Tue, Mar 15, 2011 at 2:54 PM, wrote: > On Tue, Mar 15, 2011 at 12:29:19AM -0400, Francois Pichet wrote: >> >>>> I haven't looked at the patch yet, but this defintely needs to be enabled >> >>>> by its own -cc1 language option; ?that option should then be enabled by >> >>>> windows targets, rather than tying this to -fms-extensions. > > Why tie it to windows targets? ?We would use it on all platforms. > >> >>> Yes. -fdelayed-template-parsing seems a good name. > > Sounds good. ?Shouldn't that be enough to control the feature, so that > the target doen't matter? What I did in the patch is: + Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing) || + Opts.Microsoft; The rational is that : 1. Delayed template parsing should always be enabled if -fms-extensions is present. 2. To give an option to enable delayed template parsing without microsoft extensions. 3. Don't force delayed template parsing on Windows if -fms-extensions is not there (some people will want strict template support on Windows) PS: virtually all the remaining errors when parsing Microsof C++ template headers with clang are missing "typename". A problem I plan to fix in later patch. From geek4civic at gmail.com Wed Mar 16 08:51:46 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Wed, 16 Mar 2011 13:51:46 -0000 Subject: [cfe-commits] r127729 - /cfe/trunk/test/Driver/hello.c Message-ID: <20110316135146.973302A6C12C@llvm.org> Author: chapuni Date: Wed Mar 16 08:51:46 2011 New Revision: 127729 URL: http://llvm.org/viewvc/llvm-project?rev=127729&view=rev Log: test/Driver/hello.c: Tweak for cygming. - Driver's name may be "clang(-\d.\d).exe". - Emitted executable file is named as "%t.exe". It must be harmless on other OS. Modified: cfe/trunk/test/Driver/hello.c Modified: cfe/trunk/test/Driver/hello.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/hello.c?rev=127729&r1=127728&r2=127729&view=diff ============================================================================== --- cfe/trunk/test/Driver/hello.c (original) +++ cfe/trunk/test/Driver/hello.c Wed Mar 16 08:51:46 2011 @@ -1,9 +1,9 @@ -// RUN: %clang -ccc-echo -o %t %s 2> %t.log +// RUN: %clang -ccc-echo -o %t.exe %s 2> %t.log // Make sure we used clang. -// RUN: grep 'clang\(-[0-9.]\+\)\?" -cc1 .*hello.c' %t.log +// RUN: grep 'clang\(-[0-9.]\+\)\?\(\.[Ee][Xx][Ee]\)\?" -cc1 .*hello.c' %t.log -// RUN: %t > %t.out +// RUN: %t.exe > %t.out // RUN: grep "I'm a little driver, short and stout." %t.out // FIXME: We don't have a usable assembler on Windows, so we can't build real From abramo.bagnara at gmail.com Wed Mar 16 10:08:46 2011 From: abramo.bagnara at gmail.com (Abramo Bagnara) Date: Wed, 16 Mar 2011 15:08:46 -0000 Subject: [cfe-commits] r127735 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp Message-ID: <20110316150846.886342A6C12C@llvm.org> Author: abramo Date: Wed Mar 16 10:08:46 2011 New Revision: 127735 URL: http://llvm.org/viewvc/llvm-project?rev=127735&view=rev Log: Added missing methods to get Designators source range. Modified: cfe/trunk/include/clang/AST/Expr.h cfe/trunk/lib/AST/Expr.cpp Modified: cfe/trunk/include/clang/AST/Expr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=127735&r1=127734&r2=127735&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Expr.h (original) +++ cfe/trunk/include/clang/AST/Expr.h Wed Mar 16 10:08:46 2011 @@ -3489,6 +3489,12 @@ else return getLBracketLoc(); } + SourceLocation getEndLocation() const { + return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); + } + SourceRange getSourceRange() const { + return SourceRange(getStartLocation(), getEndLocation()); + } }; static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, @@ -3571,6 +3577,8 @@ void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last); + SourceRange getDesignatorsSourceRange() const; + SourceRange getSourceRange() const; static bool classof(const Stmt *T) { Modified: cfe/trunk/lib/AST/Expr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=127735&r1=127734&r2=127735&view=diff ============================================================================== --- cfe/trunk/lib/AST/Expr.cpp (original) +++ cfe/trunk/lib/AST/Expr.cpp Wed Mar 16 10:08:46 2011 @@ -2740,6 +2740,14 @@ Designators[I] = Desigs[I]; } +SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { + DesignatedInitExpr *DIE = const_cast(this); + if (size() == 1) + return DIE->getDesignator(0)->getSourceRange(); + return SourceRange(DIE->getDesignator(0)->getStartLocation(), + DIE->getDesignator(size()-1)->getEndLocation()); +} + SourceRange DesignatedInitExpr::getSourceRange() const { SourceLocation StartLoc; Designator &First = From csdavec at swan.ac.uk Wed Mar 16 10:44:28 2011 From: csdavec at swan.ac.uk (David Chisnall) Date: Wed, 16 Mar 2011 15:44:28 -0000 Subject: [cfe-commits] r127736 - /cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Message-ID: <20110316154428.F0DC62A6C12C@llvm.org> Author: theraven Date: Wed Mar 16 10:44:28 2011 New Revision: 127736 URL: http://llvm.org/viewvc/llvm-project?rev=127736&view=rev Log: Fix foreign exception handling (GNU runtime). Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=127736&r1=127735&r2=127736&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Mar 16 10:44:28 2011 @@ -1993,17 +1993,28 @@ // @catch() and @catch(id) both catch any ObjC exception. // Treat them as catch-alls. - // FIXME: this is what this code was doing before, but should 'id' // really be catching foreign exceptions? - if (!CatchDecl - || CatchDecl->getType()->isObjCIdType() - || CatchDecl->getType()->isObjCQualifiedIdType()) { - + + if (!CatchDecl) { Handler.TypeInfo = 0; // catch-all - // Don't consider any other catches. break; } + if (CatchDecl->getType()->isObjCIdType() + || CatchDecl->getType()->isObjCQualifiedIdType()) { + // With the old ABI, there was only one kind of catchall, which broke + // foreign exceptions. With the new ABI, we use __objc_id_typeinfo as + // a pointer indicating object catchalls, and NULL to indicate real + // catchalls + if (CGM.getLangOptions().ObjCNonFragileABI) { + Handler.TypeInfo = MakeConstantString("@id"); + continue; + } else { + Handler.TypeInfo = 0; // catch-all + // Don't consider any other catches. + break; + } + } // All other types should be Objective-C interface pointer types. const ObjCObjectPointerType *OPT = From dgregor at apple.com Wed Mar 16 11:39:03 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 16:39:03 -0000 Subject: [cfe-commits] r127737 - in /cfe/trunk: include/clang/Sema/IdentifierResolver.h lib/Sema/IdentifierResolver.cpp lib/Sema/SemaDecl.cpp test/SemaCXX/goto.cpp Message-ID: <20110316163903.5416E2A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 11:39:03 2011 New Revision: 127737 URL: http://llvm.org/viewvc/llvm-project?rev=127737&view=rev Log: When we're inserting a synthesized label declaration for a forward-looking "goto" statement, make sure to insert it *after* the last declaration in the identifier resolver's declaration chain that is either outside of the function/block/method's scope or that is declared in that function/block/method's specific scope. Previously, we could end up inserting the label ahead of declarations in inner scopes, confusing C++ name lookup. Fixes PR9491/ and . Note that the crash-on-invalid PR9495 is *not* fixed. That's a separate issue. Modified: cfe/trunk/include/clang/Sema/IdentifierResolver.h cfe/trunk/lib/Sema/IdentifierResolver.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/SemaCXX/goto.cpp Modified: cfe/trunk/include/clang/Sema/IdentifierResolver.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/IdentifierResolver.h?rev=127737&r1=127736&r2=127737&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/IdentifierResolver.h (original) +++ cfe/trunk/include/clang/Sema/IdentifierResolver.h Wed Mar 16 11:39:03 2011 @@ -171,9 +171,9 @@ /// (and, therefore, replaced). bool ReplaceDecl(NamedDecl *Old, NamedDecl *New); - /// \brief Insert the given declaration prior to the given iterator - /// position - void InsertDecl(iterator Pos, NamedDecl *D); + /// \brief Insert the given declaration after the given iterator + /// position. + void InsertDeclAfter(iterator Pos, NamedDecl *D); /// \brief Link the declaration into the chain of declarations for /// the given identifier. Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=127737&r1=127736&r2=127737&view=diff ============================================================================== --- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original) +++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Wed Mar 16 11:39:03 2011 @@ -168,36 +168,26 @@ IDI->AddDecl(D); } -void IdentifierResolver::InsertDecl(iterator Pos, NamedDecl *D) { - if (Pos == iterator()) { - // Simple case: insert at the beginning of the list (which is the - // end of the stored vector). - AddDecl(D); - return; - } - +void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) { DeclarationName Name = D->getDeclName(); void *Ptr = Name.getFETokenInfo(); - if (isDeclPtr(Ptr)) { - // There's only one element, and we want to insert before it in the list. - // Just create the storage for these identifiers and insert them in the - // opposite order we normally would. - assert(isDeclPtr(Ptr) && "Not a single declaration!"); - Name.setFETokenInfo(NULL); - IdDeclInfo *IDI = &(*IdDeclInfos)[Name]; - NamedDecl *PrevD = static_cast(Ptr); - IDI->AddDecl(D); - IDI->AddDecl(PrevD); + if (Pos == iterator() || isDeclPtr(Ptr)) { + // Simple case: insert at the end of the list (which is the + // end of the stored vector). + AddDecl(D); return; } + if (IdentifierInfo *II = Name.getAsIdentifierInfo()) + II->setIsFromAST(false); + // General case: insert the declaration at the appropriate point in the // list, which already has at least two elements. IdDeclInfo *IDI = toIdDeclInfo(Ptr); - if (Pos.isIterator()) - IDI->InsertDecl(Pos.getIterator(), D); - else + if (Pos.isIterator()) { + IDI->InsertDecl(Pos.getIterator() + 1, D); + } else IDI->InsertDecl(IDI->decls_begin(), D); } Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127737&r1=127736&r2=127737&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 16 11:39:03 2011 @@ -500,11 +500,15 @@ // isn't strictly lexical, which breaks name lookup. Be careful to insert // the label at the appropriate place in the identifier chain. for (I = IdResolver.begin(D->getDeclName()); I != IEnd; ++I) { - if ((*I)->getLexicalDeclContext()->Encloses(CurContext)) + DeclContext *IDC = (*I)->getLexicalDeclContext(); + if (IDC == CurContext) { + if (!S->isDeclScope(*I)) + continue; + } else if (IDC->Encloses(CurContext)) break; } - IdResolver.InsertDecl(I, D); + IdResolver.InsertDeclAfter(I, D); } else { IdResolver.AddDecl(D); } Modified: cfe/trunk/test/SemaCXX/goto.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/goto.cpp?rev=127737&r1=127736&r2=127737&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/goto.cpp (original) +++ cfe/trunk/test/SemaCXX/goto.cpp Wed Mar 16 11:39:03 2011 @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s - // PR9463 double *end; void f() { @@ -16,3 +15,32 @@ void g() { end = 1; // expected-error{{assigning to 'double *' from incompatible type 'int'}} } + +void h(int end) { + { + goto end; // expected-error{{use of undeclared label 'end'}} + } +} + +void h2(int end) { + { + __label__ end; + goto end; + + end: + ::end = 0; + } + end: + end = 1; +} + +class X { +public: + X(); +}; + +void rdar9135994() +{ +X: + goto X; +} From dgregor at apple.com Wed Mar 16 12:05:57 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 17:05:57 -0000 Subject: [cfe-commits] r127738 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseCXXInlineMethods.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseObjc.cpp lib/Parse/ParseStmt.cpp lib/Parse/Parser.cpp test/SemaCXX/goto.cpp test/SemaObjCXX/goto.mm Message-ID: <20110316170557.544072A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 12:05:57 2011 New Revision: 127738 URL: http://llvm.org/viewvc/llvm-project?rev=127738&view=rev Log: Make sure that we always pop a function's scope *before* we call ActOnFinishFunctionBody/ActOnBlockStmtExpr. This way, we ensure that we diagnose undefined labels before the jump-scope checker gets run, since the jump-scope checker requires (as its invariant) that all of the GotoStmts be wired up correctly. Fixes PR9495. Added: cfe/trunk/test/SemaObjCXX/goto.mm Modified: cfe/trunk/include/clang/Parse/Parser.h cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp cfe/trunk/lib/Parse/ParseExpr.cpp cfe/trunk/lib/Parse/ParseObjc.cpp cfe/trunk/lib/Parse/ParseStmt.cpp cfe/trunk/lib/Parse/Parser.cpp cfe/trunk/test/SemaCXX/goto.cpp Modified: cfe/trunk/include/clang/Parse/Parser.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/include/clang/Parse/Parser.h (original) +++ cfe/trunk/include/clang/Parse/Parser.h Wed Mar 16 12:05:57 2011 @@ -1286,8 +1286,8 @@ SourceLocation *DeclEnd = 0); Decl *ParseDeclarationAfterDeclarator(Declarator &D, const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); - Decl *ParseFunctionStatementBody(Decl *Decl); - Decl *ParseFunctionTryBlock(Decl *Decl); + Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); + Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); /// \brief When in code-completion, skip parsing of the function/method body /// unless the body contains the code-completion point. Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original) +++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Wed Mar 16 12:05:57 2011 @@ -261,7 +261,7 @@ Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D); if (Tok.is(tok::kw_try)) { - ParseFunctionTryBlock(LM.D); + ParseFunctionTryBlock(LM.D, FnScope); assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc, Tok.getLocation()) && "ParseFunctionTryBlock went over the cached tokens!"); @@ -276,13 +276,14 @@ // Error recovery. if (!Tok.is(tok::l_brace)) { + FnScope.Exit(); Actions.ActOnFinishFunctionBody(LM.D, 0); return; } } else Actions.ActOnDefaultCtorInitializers(LM.D); - ParseFunctionStatementBody(LM.D); + ParseFunctionStatementBody(LM.D, FnScope); if (Tok.getLocation() != origLoc) { // Due to parsing error, we either went over the cached tokens or Modified: cfe/trunk/lib/Parse/ParseExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseExpr.cpp (original) +++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Mar 16 12:05:57 2011 @@ -1954,6 +1954,7 @@ } StmtResult Stmt(ParseCompoundStatementBody()); + BlockScope.Exit(); if (!Stmt.isInvalid()) Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.take(), getCurScope()); else Modified: cfe/trunk/lib/Parse/ParseObjc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseObjc.cpp (original) +++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Mar 16 12:05:57 2011 @@ -1724,9 +1724,12 @@ // specified Declarator for the method. Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); - if (PP.isCodeCompletionEnabled()) - if (trySkippingFunctionBodyForCodeCompletion()) + if (PP.isCodeCompletionEnabled()) { + if (trySkippingFunctionBodyForCodeCompletion()) { + BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(MDecl, 0); + } + } StmtResult FnBody(ParseCompoundStatementBody()); @@ -1735,12 +1738,11 @@ FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, MultiStmtArg(Actions), false); - // TODO: Pass argument information. - Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); - // Leave the function body scope. BodyScope.Exit(); - + + // TODO: Pass argument information. + Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); return MDecl; } Modified: cfe/trunk/lib/Parse/ParseStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseStmt.cpp (original) +++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Mar 16 12:05:57 2011 @@ -1531,14 +1531,17 @@ return true; } -Decl *Parser::ParseFunctionStatementBody(Decl *Decl) { +Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) { assert(Tok.is(tok::l_brace)); SourceLocation LBraceLoc = Tok.getLocation(); - if (PP.isCodeCompletionEnabled()) - if (trySkippingFunctionBodyForCodeCompletion()) + if (PP.isCodeCompletionEnabled()) { + if (trySkippingFunctionBodyForCodeCompletion()) { + BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(Decl, 0); - + } + } + PrettyDeclStackTraceEntry CrashInfo(Actions, Decl, LBraceLoc, "parsing function body"); @@ -1552,6 +1555,7 @@ FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc, MultiStmtArg(Actions), false); + BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(Decl, FnBody.take()); } @@ -1560,7 +1564,7 @@ /// function-try-block: /// 'try' ctor-initializer[opt] compound-statement handler-seq /// -Decl *Parser::ParseFunctionTryBlock(Decl *Decl) { +Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) { assert(Tok.is(tok::kw_try) && "Expected 'try'"); SourceLocation TryLoc = ConsumeToken(); @@ -1571,9 +1575,12 @@ if (Tok.is(tok::colon)) ParseConstructorInitializer(Decl); - if (PP.isCodeCompletionEnabled()) - if (trySkippingFunctionBodyForCodeCompletion()) + if (PP.isCodeCompletionEnabled()) { + if (trySkippingFunctionBodyForCodeCompletion()) { + BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(Decl, 0); + } + } SourceLocation LBraceLoc = Tok.getLocation(); StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc)); @@ -1583,6 +1590,7 @@ FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc, MultiStmtArg(Actions), false); + BodyScope.Exit(); return Actions.ActOnFinishFunctionBody(Decl, FnBody.take()); } Modified: cfe/trunk/lib/Parse/Parser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/lib/Parse/Parser.cpp (original) +++ cfe/trunk/lib/Parse/Parser.cpp Wed Mar 16 12:05:57 2011 @@ -801,7 +801,7 @@ D.getMutableDeclSpec().abort(); if (Tok.is(tok::kw_try)) - return ParseFunctionTryBlock(Res); + return ParseFunctionTryBlock(Res, BodyScope); // If we have a colon, then we're probably parsing a C++ // ctor-initializer. @@ -810,13 +810,14 @@ // Recover from error. if (!Tok.is(tok::l_brace)) { + BodyScope.Exit(); Actions.ActOnFinishFunctionBody(Res, 0); return Res; } } else Actions.ActOnDefaultCtorInitializers(Res); - return ParseFunctionStatementBody(Res); + return ParseFunctionStatementBody(Res, BodyScope); } /// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides Modified: cfe/trunk/test/SemaCXX/goto.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/goto.cpp?rev=127738&r1=127737&r2=127738&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/goto.cpp (original) +++ cfe/trunk/test/SemaCXX/goto.cpp Wed Mar 16 12:05:57 2011 @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s + // PR9463 double *end; void f() { @@ -44,3 +45,25 @@ X: goto X; } + +namespace PR9495 { + struct NonPOD { NonPOD(); ~NonPOD(); }; + + void f(bool b) { + NonPOD np; + if (b) { + goto undeclared; // expected-error{{use of undeclared label 'undeclared'}} + } + } + + void g() { + (void)^(bool b){ + NonPOD np; + if (b) { + goto undeclared; // expected-error{{use of undeclared label 'undeclared'}} + } + }; + } +} + + Added: cfe/trunk/test/SemaObjCXX/goto.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/goto.mm?rev=127738&view=auto ============================================================================== --- cfe/trunk/test/SemaObjCXX/goto.mm (added) +++ cfe/trunk/test/SemaObjCXX/goto.mm Wed Mar 16 12:05:57 2011 @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR9495 +struct NonPOD { NonPOD(); ~NonPOD(); }; + + at interface A + at end + + at implementation A +- (void)method:(bool)b { + NonPOD np; + if (b) { + goto undeclared; // expected-error{{use of undeclared label 'undeclared'}} + } +} + at end From dgregor at apple.com Wed Mar 16 12:14:45 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 10:14:45 -0700 Subject: [cfe-commits] r127736 - /cfe/trunk/lib/CodeGen/CGObjCGNU.cpp In-Reply-To: <20110316154428.F0DC62A6C12C@llvm.org> References: <20110316154428.F0DC62A6C12C@llvm.org> Message-ID: <92A7D1A4-F907-410A-8BA4-D5B9903C23E9@apple.com> Bill, can you pull this into the 2.9 branch? Thanks! - Doug On Mar 16, 2011, at 8:44 AM, David Chisnall wrote: > Author: theraven > Date: Wed Mar 16 10:44:28 2011 > New Revision: 127736 > > URL: http://llvm.org/viewvc/llvm-project?rev=127736&view=rev > Log: > Fix foreign exception handling (GNU runtime). > > > Modified: > cfe/trunk/lib/CodeGen/CGObjCGNU.cpp > > Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=127736&r1=127735&r2=127736&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Mar 16 10:44:28 2011 > @@ -1993,17 +1993,28 @@ > > // @catch() and @catch(id) both catch any ObjC exception. > // Treat them as catch-alls. > - // FIXME: this is what this code was doing before, but should 'id' > // really be catching foreign exceptions? > - if (!CatchDecl > - || CatchDecl->getType()->isObjCIdType() > - || CatchDecl->getType()->isObjCQualifiedIdType()) { > - > + > + if (!CatchDecl) { > Handler.TypeInfo = 0; // catch-all > - > // Don't consider any other catches. > break; > } > + if (CatchDecl->getType()->isObjCIdType() > + || CatchDecl->getType()->isObjCQualifiedIdType()) { > + // With the old ABI, there was only one kind of catchall, which broke > + // foreign exceptions. With the new ABI, we use __objc_id_typeinfo as > + // a pointer indicating object catchalls, and NULL to indicate real > + // catchalls > + if (CGM.getLangOptions().ObjCNonFragileABI) { > + Handler.TypeInfo = MakeConstantString("@id"); > + continue; > + } else { > + Handler.TypeInfo = 0; // catch-all > + // Don't consider any other catches. > + break; > + } > + } > > // All other types should be Objective-C interface pointer types. > const ObjCObjectPointerType *OPT = > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From dgregor at apple.com Wed Mar 16 12:42:23 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 17:42:23 -0000 Subject: [cfe-commits] r127739 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/member-pointers-2.cpp Message-ID: <20110316174223.8EA9A2A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 12:42:23 2011 New Revision: 127739 URL: http://llvm.org/viewvc/llvm-project?rev=127739&view=rev Log: Allow function calls to dereferenced member pointers of pointer-to-function type. Fixes . Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/member-pointers-2.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=127739&r1=127738&r2=127739&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Mar 16 12:42:23 2011 @@ -4574,9 +4574,6 @@ return MaybeBindToTemporary(TheCall); } - return ExprError(Diag(Fn->getLocStart(), - diag::err_typecheck_call_not_function) - << Fn->getType() << Fn->getSourceRange()); } } } Modified: cfe/trunk/test/SemaCXX/member-pointers-2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointers-2.cpp?rev=127739&r1=127738&r2=127739&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/member-pointers-2.cpp (original) +++ cfe/trunk/test/SemaCXX/member-pointers-2.cpp Wed Mar 16 12:42:23 2011 @@ -34,3 +34,18 @@ Test0 mytest; mytest.test(); } + +namespace rdar9065289 { + typedef void (*FuncPtr)(); + struct X0 { }; + + struct X1 + { + X0* x0; + FuncPtr X0::*fptr; + }; + + void f(X1 p) { + (p.x0->*(p.fptr))(); + } +} From dgregor at apple.com Wed Mar 16 13:21:05 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 18:21:05 -0000 Subject: [cfe-commits] r127740 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/overloaded-operator.cpp Message-ID: <20110316182105.B5F0D2A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 13:21:05 2011 New Revision: 127740 URL: http://llvm.org/viewvc/llvm-project?rev=127740&view=rev Log: Don't indescriminately print overload candidates when we have invalid operands to a binary expression; it doesn't make sense in all contexts. The right answer would be to see if the user forgot at (). Fixes . Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/overloaded-operator.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=127740&r1=127739&r2=127740&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Mar 16 13:21:05 2011 @@ -6312,10 +6312,6 @@ Diag(Loc, diag::err_typecheck_invalid_operands) << lex->getType() << rex->getType() << lex->getSourceRange() << rex->getSourceRange(); - if (lex->getType() == Context.OverloadTy) - NoteAllOverloadCandidates(lex); - if (rex->getType() == Context.OverloadTy) - NoteAllOverloadCandidates(rex); return QualType(); } Modified: cfe/trunk/test/SemaCXX/overloaded-operator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator.cpp?rev=127740&r1=127739&r2=127740&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/overloaded-operator.cpp (original) +++ cfe/trunk/test/SemaCXX/overloaded-operator.cpp Wed Mar 16 13:21:05 2011 @@ -384,3 +384,19 @@ N::X2 x; x << 17; } + +namespace rdar9136502 { + struct X { + int i(); + int i(int); + }; + + struct Y { + Y &operator<<(int); // expected-note{{candidate function not viable: no overload of 'i' matching 'int' for 1st argument}} + }; + + void f(X x, Y y) { + // FIXME: This diagnostic is non-awesome. + y << x.i; // expected-error{{invalid operands to binary expression ('rdar9136502::Y' and '')}} + } +} From chandlerc at gmail.com Wed Mar 16 13:34:36 2011 From: chandlerc at gmail.com (Chandler Carruth) Date: Wed, 16 Mar 2011 18:34:36 -0000 Subject: [cfe-commits] r127742 - in /cfe/trunk: include/clang/Lex/DirectoryLookup.h include/clang/Lex/HeaderMap.h include/clang/Lex/HeaderSearch.h include/clang/Lex/PPCallbacks.h include/clang/Lex/PreprocessingRecord.h include/clang/Lex/Preprocessor.h lib/Lex/HeaderMap.cpp lib/Lex/HeaderSearch.cpp lib/Lex/PPDirectives.cpp lib/Lex/PPMacroExpansion.cpp lib/Lex/Pragma.cpp lib/Lex/PreprocessingRecord.cpp Message-ID: <20110316183436.64BD12A6C12C@llvm.org> Author: chandlerc Date: Wed Mar 16 13:34:36 2011 New Revision: 127742 URL: http://llvm.org/viewvc/llvm-project?rev=127742&view=rev Log: Add a 'RawPath' parameter to the PPCallbacks interface. This allows clients to observe the exact path through which an #included file was located. This is very useful when trying to record and replay inclusion operations without it beind influenced by the aggressive caching done inside the FileManager to avoid redundant system calls and filesystem operations. The work to compute and return this is only done in the presence of callbacks, so it should have no effect on normal compilation. Patch by Manuel Klimek. Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h cfe/trunk/include/clang/Lex/HeaderMap.h cfe/trunk/include/clang/Lex/HeaderSearch.h cfe/trunk/include/clang/Lex/PPCallbacks.h cfe/trunk/include/clang/Lex/PreprocessingRecord.h cfe/trunk/include/clang/Lex/Preprocessor.h cfe/trunk/lib/Lex/HeaderMap.cpp cfe/trunk/lib/Lex/HeaderSearch.cpp cfe/trunk/lib/Lex/PPDirectives.cpp cfe/trunk/lib/Lex/PPMacroExpansion.cpp cfe/trunk/lib/Lex/Pragma.cpp cfe/trunk/lib/Lex/PreprocessingRecord.cpp Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original) +++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Wed Mar 16 13:34:36 2011 @@ -18,6 +18,7 @@ namespace llvm { class StringRef; + template class SmallVectorImpl; } namespace clang { class HeaderMap; @@ -121,11 +122,17 @@ /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. - const FileEntry *LookupFile(llvm::StringRef Filename, HeaderSearch &HS) const; + /// If RawPath is not NULL and the file is found, RawPath will be set to the + /// raw path at which the file was found in the file system. For example, + /// for a search path ".." and a filename "../file.h" this would be + /// "../../file.h". + const FileEntry *LookupFile(llvm::StringRef Filename, HeaderSearch &HS, + llvm::SmallVectorImpl *RawPath) const; private: - const FileEntry *DoFrameworkLookup(llvm::StringRef Filename, - HeaderSearch &HS) const; + const FileEntry *DoFrameworkLookup( + llvm::StringRef Filename, HeaderSearch &HS, + llvm::SmallVectorImpl *RawPath) const; }; Modified: cfe/trunk/include/clang/Lex/HeaderMap.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderMap.h?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/HeaderMap.h (original) +++ cfe/trunk/include/clang/Lex/HeaderMap.h Wed Mar 16 13:34:36 2011 @@ -17,6 +17,7 @@ namespace llvm { class MemoryBuffer; class StringRef; + template class SmallVectorImpl; } namespace clang { class FileEntry; @@ -47,7 +48,12 @@ /// LookupFile - Check to see if the specified relative filename is located in /// this HeaderMap. If so, open it and return its FileEntry. - const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM) const; + /// If RawPath is not NULL and the file is found, RawPath will be set to the + /// raw path at which the file was found in the file system. For example, + /// for a search path ".." and a filename "../file.h" this would be + /// "../../file.h". + const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM, + llvm::SmallVectorImpl *RawPath) const; /// getFileName - Return the filename of the headermap. const char *getFileName() const; Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/HeaderSearch.h (original) +++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Mar 16 13:34:36 2011 @@ -192,15 +192,18 @@ const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, - const FileEntry *CurFileEnt); + const FileEntry *CurFileEnt, + llvm::SmallVectorImpl *RawPath); /// LookupSubframeworkHeader - Look up a subframework for the specified /// #include file. For example, if #include'ing from /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox /// is a subframework within Carbon.framework. If so, return the FileEntry /// for the designated file, otherwise return null. - const FileEntry *LookupSubframeworkHeader(llvm::StringRef Filename, - const FileEntry *RelativeFileEnt); + const FileEntry *LookupSubframeworkHeader( + llvm::StringRef Filename, + const FileEntry *RelativeFileEnt, + llvm::SmallVectorImpl *RawPath); /// LookupFrameworkCache - Look up the specified framework name in our /// framework cache, returning the DirectoryEntry it is in if we know, Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/PPCallbacks.h (original) +++ cfe/trunk/include/clang/Lex/PPCallbacks.h Wed Mar 16 13:34:36 2011 @@ -75,12 +75,17 @@ /// /// \param EndLoc The location of the last token within the inclusion /// directive. + /// + /// \param RawPath Contains the raw path at which the file was found in the + /// file system. For example, for a search path ".." and a filename + /// "../file.h" this would be "../../file.h". virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, const FileEntry *File, - SourceLocation EndLoc) { + SourceLocation EndLoc, + const llvm::SmallVectorImpl &RawPath) { } /// EndOfMainFile - This callback is invoked when the end of the main file is @@ -188,11 +193,12 @@ llvm::StringRef FileName, bool IsAngled, const FileEntry *File, - SourceLocation EndLoc) { - First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File, - EndLoc); - Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File, - EndLoc); + SourceLocation EndLoc, + const llvm::SmallVectorImpl &RawPath) { + First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File, + EndLoc, RawPath); + Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File, + EndLoc, RawPath); } virtual void EndOfMainFile() { Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original) +++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Wed Mar 16 13:34:36 2011 @@ -341,7 +341,8 @@ llvm::StringRef FileName, bool IsAngled, const FileEntry *File, - SourceLocation EndLoc); + SourceLocation EndLoc, + const llvm::SmallVectorImpl &RawPath); }; } // end namespace clang Modified: cfe/trunk/include/clang/Lex/Preprocessor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/Preprocessor.h (original) +++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Mar 16 13:34:36 2011 @@ -832,7 +832,8 @@ /// for system #include's or not (i.e. using <> instead of ""). const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, - const DirectoryLookup *&CurDir); + const DirectoryLookup *&CurDir, + llvm::SmallVectorImpl *RawPath); /// GetCurLookup - The DirectoryLookup structure used to find the current /// FileEntry, if CurLexer is non-null and if applicable. This allows us to Modified: cfe/trunk/lib/Lex/HeaderMap.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/lib/Lex/HeaderMap.cpp (original) +++ cfe/trunk/lib/Lex/HeaderMap.cpp Wed Mar 16 13:34:36 2011 @@ -199,8 +199,9 @@ /// LookupFile - Check to see if the specified relative filename is located in /// this HeaderMap. If so, open it and return its FileEntry. -const FileEntry *HeaderMap::LookupFile(llvm::StringRef Filename, - FileManager &FM) const { +const FileEntry *HeaderMap::LookupFile( + llvm::StringRef Filename, FileManager &FM, + llvm::SmallVectorImpl *RawPath) const { const HMapHeader &Hdr = getHeader(); unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets); @@ -223,6 +224,8 @@ llvm::SmallString<1024> DestPath; DestPath += getString(B.Prefix); DestPath += getString(B.Suffix); + if (RawPath != NULL) + *RawPath = DestPath; return FM.getFile(DestPath.str()); } } Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/lib/Lex/HeaderSearch.cpp (original) +++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Mar 16 13:34:36 2011 @@ -114,8 +114,9 @@ /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. -const FileEntry *DirectoryLookup::LookupFile(llvm::StringRef Filename, - HeaderSearch &HS) const { +const FileEntry *DirectoryLookup::LookupFile( + llvm::StringRef Filename, + HeaderSearch &HS, llvm::SmallVectorImpl *RawPath) const { llvm::SmallString<1024> TmpDir; if (isNormalDir()) { // Concatenate the requested file onto the directory. @@ -123,21 +124,24 @@ TmpDir += getDir()->getName(); TmpDir.push_back('/'); TmpDir.append(Filename.begin(), Filename.end()); + if (RawPath != NULL) + *RawPath = TmpDir; return HS.getFileMgr().getFile(TmpDir.str()); } if (isFramework()) - return DoFrameworkLookup(Filename, HS); + return DoFrameworkLookup(Filename, HS, RawPath); assert(isHeaderMap() && "Unknown directory lookup"); - return getHeaderMap()->LookupFile(Filename, HS.getFileMgr()); + return getHeaderMap()->LookupFile(Filename, HS.getFileMgr(), RawPath); } /// DoFrameworkLookup - Do a lookup of the specified file in the current /// DirectoryLookup, which is a framework directory. -const FileEntry *DirectoryLookup::DoFrameworkLookup(llvm::StringRef Filename, - HeaderSearch &HS) const { +const FileEntry *DirectoryLookup::DoFrameworkLookup( + llvm::StringRef Filename, + HeaderSearch &HS, llvm::SmallVectorImpl *RawPath) const { FileManager &FileMgr = HS.getFileMgr(); // Framework names must have a '/' in the filename. @@ -188,13 +192,18 @@ FrameworkName += "Headers/"; FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end()); - if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str())) + if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str())) { + if (RawPath != NULL) + *RawPath = FrameworkName; return FE; + } // Check "/System/Library/Frameworks/Cocoa.framework/PrivateHeaders/file.h" const char *Private = "Private"; FrameworkName.insert(FrameworkName.begin()+OrigSize, Private, Private+strlen(Private)); + if (RawPath != NULL) + *RawPath = FrameworkName; return FileMgr.getFile(FrameworkName.str()); } @@ -209,11 +218,13 @@ /// for system #include's or not (i.e. using <> instead of ""). CurFileEnt, if /// non-null, indicates where the #including file is, in case a relative search /// is needed. -const FileEntry *HeaderSearch::LookupFile(llvm::StringRef Filename, - bool isAngled, - const DirectoryLookup *FromDir, - const DirectoryLookup *&CurDir, - const FileEntry *CurFileEnt) { +const FileEntry *HeaderSearch::LookupFile( + llvm::StringRef Filename, + bool isAngled, + const DirectoryLookup *FromDir, + const DirectoryLookup *&CurDir, + const FileEntry *CurFileEnt, + llvm::SmallVectorImpl *RawPath) { // If 'Filename' is absolute, check to see if it exists and no searching. if (llvm::sys::path::is_absolute(Filename)) { CurDir = 0; @@ -221,6 +232,8 @@ // If this was an #include_next "/absolute/file", fail. if (FromDir) return 0; + if (RawPath != NULL) + llvm::Twine(Filename).toVector(*RawPath); // Otherwise, just return the file. return FileMgr.getFile(Filename); } @@ -246,6 +259,8 @@ // of evaluation. unsigned DirInfo = getFileInfo(CurFileEnt).DirInfo; getFileInfo(FE).DirInfo = DirInfo; + if (RawPath != NULL) + *RawPath = TmpDir; return FE; } } @@ -283,7 +298,7 @@ // Check each directory in sequence to see if it contains this file. for (; i != SearchDirs.size(); ++i) { const FileEntry *FE = - SearchDirs[i].LookupFile(Filename, *this); + SearchDirs[i].LookupFile(Filename, *this, RawPath); if (!FE) continue; CurDir = &SearchDirs[i]; @@ -308,7 +323,8 @@ /// for the designated file, otherwise return null. const FileEntry *HeaderSearch:: LookupSubframeworkHeader(llvm::StringRef Filename, - const FileEntry *ContextFileEnt) { + const FileEntry *ContextFileEnt, + llvm::SmallVectorImpl *RawPath) { assert(ContextFileEnt && "No context file?"); // Framework names must have a '/' in the filename. Find it. @@ -369,6 +385,8 @@ if (!(FE = FileMgr.getFile(HeadersFilename.str()))) return 0; } + if (RawPath != NULL) + *RawPath = HeadersFilename; // This file is a system header or C++ unfriendly if the old file is. // Modified: cfe/trunk/lib/Lex/PPDirectives.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/lib/Lex/PPDirectives.cpp (original) +++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Mar 16 13:34:36 2011 @@ -469,10 +469,12 @@ /// LookupFile - Given a "foo" or reference, look up the indicated file, /// return null on failure. isAngled indicates whether the file reference is /// for system #include's or not (i.e. using <> instead of ""). -const FileEntry *Preprocessor::LookupFile(llvm::StringRef Filename, - bool isAngled, - const DirectoryLookup *FromDir, - const DirectoryLookup *&CurDir) { +const FileEntry *Preprocessor::LookupFile( + llvm::StringRef Filename, + bool isAngled, + const DirectoryLookup *FromDir, + const DirectoryLookup *&CurDir, + llvm::SmallVectorImpl *RawPath) { // If the header lookup mechanism may be relative to the current file, pass in // info about where the current file is. const FileEntry *CurFileEnt = 0; @@ -494,8 +496,8 @@ // Do a standard file entry lookup. CurDir = CurDirLookup; - const FileEntry *FE = - HeaderInfo.LookupFile(Filename, isAngled, FromDir, CurDir, CurFileEnt); + const FileEntry *FE = HeaderInfo.LookupFile( + Filename, isAngled, FromDir, CurDir, CurFileEnt, RawPath); if (FE) return FE; // Otherwise, see if this is a subframework header. If so, this is relative @@ -503,7 +505,8 @@ // headers on the #include stack and pass them to HeaderInfo. if (IsFileLexer()) { if ((CurFileEnt = SourceMgr.getFileEntryForID(CurPPLexer->getFileID()))) - if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt))) + if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt, + RawPath))) return FE; } @@ -512,7 +515,8 @@ if (IsFileLexer(ISEntry)) { if ((CurFileEnt = SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID()))) - if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt))) + if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt, + RawPath))) return FE; } } @@ -1167,7 +1171,11 @@ // Search include directories. const DirectoryLookup *CurDir; - const FileEntry *File = LookupFile(Filename, isAngled, LookupFrom, CurDir); + llvm::SmallString<1024> RawPath; + // We get the raw path only if we have 'Callbacks' to which we later pass + // the path. + const FileEntry *File = LookupFile( + Filename, isAngled, LookupFrom, CurDir, Callbacks ? &RawPath : NULL); if (File == 0) { Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; return; @@ -1175,9 +1183,9 @@ // Notify the callback object that we've seen an inclusion directive. if (Callbacks) - Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled, File, - End); - + Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled, File, + End, RawPath); + // The #included file will be considered to be a system header if either it is // in a system include directory, or if the #includer is a system include // header. Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original) +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Mar 16 13:34:36 2011 @@ -662,7 +662,8 @@ // Search include directories. const DirectoryLookup *CurDir; - const FileEntry *File = PP.LookupFile(Filename, isAngled, LookupFrom, CurDir); + const FileEntry *File = + PP.LookupFile(Filename, isAngled, LookupFrom, CurDir, NULL); // Get the result value. Result = true means the file exists. bool Result = File != 0; Modified: cfe/trunk/lib/Lex/Pragma.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/lib/Lex/Pragma.cpp (original) +++ cfe/trunk/lib/Lex/Pragma.cpp Wed Mar 16 13:34:36 2011 @@ -368,7 +368,7 @@ // Search include directories for this file. const DirectoryLookup *CurDir; - const FileEntry *File = LookupFile(Filename, isAngled, 0, CurDir); + const FileEntry *File = LookupFile(Filename, isAngled, 0, CurDir, NULL); if (File == 0) { Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; return; Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=127742&r1=127741&r2=127742&view=diff ============================================================================== --- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original) +++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Wed Mar 16 13:34:36 2011 @@ -146,12 +146,14 @@ MacroDefinitions.erase(Pos); } -void PreprocessingRecord::InclusionDirective(SourceLocation HashLoc, - const clang::Token &IncludeTok, - llvm::StringRef FileName, - bool IsAngled, - const FileEntry *File, - clang::SourceLocation EndLoc) { +void PreprocessingRecord::InclusionDirective( + SourceLocation HashLoc, + const clang::Token &IncludeTok, + llvm::StringRef FileName, + bool IsAngled, + const FileEntry *File, + clang::SourceLocation EndLoc, + const llvm::SmallVectorImpl &RawPath) { InclusionDirective::InclusionKind Kind = InclusionDirective::Include; switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { From peter at pcc.me.uk Wed Mar 16 13:35:34 2011 From: peter at pcc.me.uk (Peter Collingbourne) Date: Wed, 16 Mar 2011 18:35:34 -0000 Subject: [cfe-commits] r127743 - /cfe/trunk/include/clang/Frontend/LangStandards.def Message-ID: <20110316183534.ABF762A6C12C@llvm.org> Author: pcc Date: Wed Mar 16 13:35:34 2011 New Revision: 127743 URL: http://llvm.org/viewvc/llvm-project?rev=127743&view=rev Log: Remove a duplicate language feature Modified: cfe/trunk/include/clang/Frontend/LangStandards.def Modified: cfe/trunk/include/clang/Frontend/LangStandards.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=127743&r1=127742&r2=127743&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/LangStandards.def (original) +++ cfe/trunk/include/clang/Frontend/LangStandards.def Wed Mar 16 13:35:34 2011 @@ -54,7 +54,7 @@ LANGSTANDARD(gnu99, "gnu99", "ISO C 1999 with GNU extensions", - BCPLComment | C99 | Digraphs | GNUMode | HexFloat | Digraphs) + BCPLComment | C99 | Digraphs | GNUMode | HexFloat) LANGSTANDARD(gnu9x, "gnu9x", "ISO C 1999 with GNU extensions", BCPLComment | C99 | Digraphs | GNUMode | HexFloat) From peter at pcc.me.uk Wed Mar 16 13:37:28 2011 From: peter at pcc.me.uk (Peter Collingbourne) Date: Wed, 16 Mar 2011 18:37:28 -0000 Subject: [cfe-commits] r127744 - in /cfe/trunk/lib/AST: DeclPrinter.cpp StmtDumper.cpp Message-ID: <20110316183728.1E84A2A6C12C@llvm.org> Author: pcc Date: Wed Mar 16 13:37:27 2011 New Revision: 127744 URL: http://llvm.org/viewvc/llvm-project?rev=127744&view=rev Log: Support for printing/dumping static asserts Modified: cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/lib/AST/StmtDumper.cpp Modified: cfe/trunk/lib/AST/DeclPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=127744&r1=127743&r2=127744&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclPrinter.cpp (original) +++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Mar 16 13:37:27 2011 @@ -54,6 +54,7 @@ void VisitLabelDecl(LabelDecl *D); void VisitParmVarDecl(ParmVarDecl *D); void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); + void VisitStaticAssertDecl(StaticAssertDecl *D); void VisitNamespaceDecl(NamespaceDecl *D); void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); @@ -590,6 +591,14 @@ Out << ")"; } +void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) { + Out << "static_assert("; + D->getAssertExpr()->printPretty(Out, Context, 0, Policy, Indentation); + Out << ", "; + D->getMessage()->printPretty(Out, Context, 0, Policy, Indentation); + Out << ")"; +} + //---------------------------------------------------------------------------- // C++ declarations //---------------------------------------------------------------------------- Modified: cfe/trunk/lib/AST/StmtDumper.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=127744&r1=127743&r2=127744&view=diff ============================================================================== --- cfe/trunk/lib/AST/StmtDumper.cpp (original) +++ cfe/trunk/lib/AST/StmtDumper.cpp Wed Mar 16 13:37:27 2011 @@ -284,6 +284,12 @@ OS << ";\""; } else if (LabelDecl *LD = dyn_cast(D)) { OS << "label " << LD->getNameAsString(); + } else if (StaticAssertDecl *SAD = dyn_cast(D)) { + OS << "\"static_assert(\n"; + DumpSubTree(SAD->getAssertExpr()); + OS << ",\n"; + DumpSubTree(SAD->getMessage()); + OS << ");\""; } else { assert(0 && "Unexpected decl"); } From peter at pcc.me.uk Wed Mar 16 14:16:40 2011 From: peter at pcc.me.uk (Peter Collingbourne) Date: Wed, 16 Mar 2011 19:16:40 +0000 Subject: [cfe-commits] [PATCH] C1X: generic selections, static asserts Message-ID: <20110316191615.GA11762@pcc.me.uk> This patch series implements support for C1X generic selections and static assertions. As an extension, generic selection support has been added for all supported languages. The syntax is the same as for C1X, except that the keyword is "__generic". OK to commit? -- Peter -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-C1X-add-a-language-standard.patch Type: text/x-diff Size: 8139 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110316/9e4554e5/attachment-0003.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: 0002-C1X-implement-generic-selections.patch Type: text/x-diff Size: 66015 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110316/9e4554e5/attachment-0004.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: 0003-C1X-implement-static-asserts.patch Type: text/x-diff Size: 4541 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110316/9e4554e5/attachment-0005.bin From deeppatel1987 at gmail.com Wed Mar 16 14:14:34 2011 From: deeppatel1987 at gmail.com (Sandeep Patel) Date: Wed, 16 Mar 2011 19:14:34 -0000 Subject: [cfe-commits] r127746 - /cfe/trunk/lib/Frontend/CompilerInvocation.cpp Message-ID: <20110316191434.DD6F62A6C12C@llvm.org> Author: sandeep Date: Wed Mar 16 14:14:34 2011 New Revision: 127746 URL: http://llvm.org/viewvc/llvm-project?rev=127746&view=rev Log: Fix duplicate argument processing Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=127746&r1=127745&r2=127746&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Mar 16 14:14:34 2011 @@ -98,7 +98,7 @@ Res.push_back("-trim-egraph"); if (Opts.VisualizeEGDot) Res.push_back("-analyzer-viz-egraph-graphviz"); - if (Opts.VisualizeEGDot) + if (Opts.VisualizeEGUbi) Res.push_back("-analyzer-viz-egraph-ubigraph"); for (unsigned i = 0, e = Opts.CheckersControlList.size(); i != e; ++i) { From dgregor at apple.com Wed Mar 16 14:16:25 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 19:16:25 -0000 Subject: [cfe-commits] r127747 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp test/CXX/expr/expr.unary/expr.unary.op/p6.cpp test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-nodeduct.cpp test/SemaCXX/alignof-sizeof-reference.cpp test/SemaCXX/decltype-overloaded-functions.cpp test/SemaCXX/overloaded-name.cpp test/SemaTemplate/resolve-single-template-id.cpp test/SemaTemplate/resolve-single-template-id.patch Message-ID: <20110316191626.91B1E2A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 14:16:25 2011 New Revision: 127747 URL: http://llvm.org/viewvc/llvm-project?rev=127747&view=rev Log: Clean up our handling of template-ids that resolve down to a single overload, so that we actually do the resolution for full expressions and emit more consistent, useful diagnostics. Also fixes an IRGen crasher, where Sema wouldn't diagnose a resolvable bound member function template-id used in a full-expression (). Added: cfe/trunk/test/SemaTemplate/resolve-single-template-id.cpp - copied, changed from r127734, cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch Removed: cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-nodeduct.cpp cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp cfe/trunk/test/SemaCXX/overloaded-name.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 16 14:16:25 2011 @@ -1499,7 +1499,7 @@ def err_ovl_no_oper : Error<"type %0 does not provide a %select{subscript|call}1 operator">; def err_ovl_unresolvable : - Error<"cannot resolve overloaded function from context">; + Error<"cannot resolve overloaded function %0 from context">; def err_ovl_no_viable_object_call : Error< Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Mar 16 14:16:25 2011 @@ -9790,17 +9790,8 @@ // If this is overload, check for a single overload. assert(BT->getKind() == BuiltinType::Overload); - - if (FunctionDecl *Specialization - = ResolveSingleFunctionTemplateSpecialization(E)) { - // The access doesn't really matter in this case. - DeclAccessPair Found = DeclAccessPair::make(Specialization, - Specialization->getAccess()); - E = FixOverloadedFunctionReference(E, Found, Specialization); - if (!E) return ExprError(); - return Owned(E); - } - - Diag(Loc, diag::err_ovl_unresolvable) << E->getSourceRange(); - return ExprError(); + return ResolveAndFixSingleFunctionTemplateSpecialization(E, false, true, + E->getSourceRange(), + QualType(), + diag::err_ovl_unresolvable); } Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Mar 16 14:16:25 2011 @@ -3944,14 +3944,17 @@ // fooT; if (FullExpr->getType() == Context.OverloadTy) { - if (!ResolveSingleFunctionTemplateSpecialization(FullExpr, - /* Complain */ false)) { - OverloadExpr* OvlExpr = OverloadExpr::find(FullExpr).Expression; - Diag(FullExpr->getLocStart(), diag::err_addr_ovl_ambiguous) - << OvlExpr->getName(); - NoteAllOverloadCandidates(OvlExpr); + ExprResult Fixed + = ResolveAndFixSingleFunctionTemplateSpecialization(FullExpr, + /*DoFunctionPointerConversion=*/false, + /*Complain=*/true, + FullExpr->getSourceRange(), + QualType(), + diag::err_addr_ovl_ambiguous); + if (Fixed.isInvalid()) return ExprError(); - } + + FullExpr = Fixed.get(); } Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Mar 16 14:16:25 2011 @@ -7518,13 +7518,17 @@ DefaultFunctionArrayLvalueConversion(SingleFunctionExpression); } } - if (!SingleFunctionExpression && Complain) { - OverloadExpr* oe = OverloadExpr::find(SrcExpr).Expression; - Diag(OpRangeForComplaining.getBegin(), DiagIDForComplaining) - << oe->getName() << DestTypeForComplaining << OpRangeForComplaining - << oe->getQualifierLoc().getSourceRange(); - NoteAllOverloadCandidates(SrcExpr); + if (!SingleFunctionExpression) { + if (Complain) { + OverloadExpr* oe = OverloadExpr::find(SrcExpr).Expression; + Diag(OpRangeForComplaining.getBegin(), DiagIDForComplaining) + << oe->getName() << DestTypeForComplaining << OpRangeForComplaining + << oe->getQualifierLoc().getSourceRange(); + NoteAllOverloadCandidates(SrcExpr); + } + return ExprError(); } + return SingleFunctionExpression; } Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp (original) +++ cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp Wed Mar 16 14:16:25 2011 @@ -29,8 +29,8 @@ namespace PR8181 { - void f() { } - void f(char) { } - bool b = !&f; //expected-error {{cannot resolve overloaded function from context}} + void f() { } // expected-note{{candidate function}} + void f(char) { } // expected-note{{candidate function}} + bool b = !&f; //expected-error {{cannot resolve overloaded function 'f' from context}} } Modified: cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-nodeduct.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-nodeduct.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-nodeduct.cpp (original) +++ cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3-nodeduct.cpp Wed Mar 16 14:16:25 2011 @@ -29,8 +29,8 @@ int typeof0[is_same<__typeof__(f), void (int)>::value? 1 : -1]; int typeof1[is_same<__typeof__(&f), void (*)(int)>::value? 1 : -1]; -template void g(T); -template void g(T, T); +template void g(T); // expected-note{{candidate function}} +template void g(T, T); // expected-note{{candidate function}} int typeof2[is_same<__typeof__(g), void (int)>::value? 1 : -1]; // \ - // expected-error{{cannot resolve overloaded function from context}} + // expected-error{{cannot resolve overloaded function 'g' from context}} Modified: cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp (original) +++ cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp Wed Mar 16 14:16:25 2011 @@ -8,8 +8,8 @@ static_assert(sizeof(r) == 1, "bad size"); } -void f(); -void f(int); +void f(); // expected-note{{candidate function}} +void f(int); // expected-note{{candidate function}} void g() { - sizeof(&f); // expected-error{{cannot resolve overloaded function from context}} + sizeof(&f); // expected-error{{cannot resolve overloaded function 'f' from context}} } Modified: cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp (original) +++ cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp Wed Mar 16 14:16:25 2011 @@ -1,12 +1,15 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x -void f(); -void f(int); -decltype(f) a; // expected-error{{cannot resolve overloaded function from context}} +void f(); // expected-note{{candidate function}} +void f(int); // expected-note{{candidate function}} +decltype(f) a; // expected-error{{cannot resolve overloaded function 'f' from context}} template struct S { - decltype(T::f) * f; // expected-error{{cannot resolve overloaded function from context}} + decltype(T::f) * f; // expected-error{{cannot resolve overloaded function 'f' from context}} }; -struct K { void f(); void f(int); }; +struct K { + void f(); // expected-note{{candidate function}} + void f(int); // expected-note{{candidate function}} +}; S b; // expected-note{{in instantiation of template class 'S' requested here}} Modified: cfe/trunk/test/SemaCXX/overloaded-name.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-name.cpp?rev=127747&r1=127746&r2=127747&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/overloaded-name.cpp (original) +++ cfe/trunk/test/SemaCXX/overloaded-name.cpp Wed Mar 16 14:16:25 2011 @@ -1,14 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int ovl(int); -float ovl(float); +int ovl(int); // expected-note 3{{candidate function}} +float ovl(float); // expected-note 3{{candidate function}} -template T ovl(T); +template T ovl(T); // expected-note 3{{candidate function}} void test(bool b) { - (void)((void)0, ovl); // expected-error{{cannot resolve overloaded function from context}} + (void)((void)0, ovl); // expected-error{{cannot resolve overloaded function 'ovl' from context}} // PR7863 - (void)(b? ovl : &ovl); // expected-error{{cannot resolve overloaded function from context}} - (void)(b? ovl : &ovl); // expected-error{{cannot resolve overloaded function from context}} + (void)(b? ovl : &ovl); // expected-error{{cannot resolve overloaded function 'ovl' from context}} + (void)(b? ovl : &ovl); // expected-error{{cannot resolve overloaded function 'ovl' from context}} (void)(b? ovl : ovl); } Copied: cfe/trunk/test/SemaTemplate/resolve-single-template-id.cpp (from r127734, cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/resolve-single-template-id.cpp?p2=cfe/trunk/test/SemaTemplate/resolve-single-template-id.cpp&p1=cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch&r1=127734&r2=127747&rev=127747&view=diff ============================================================================== --- cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch (original) +++ cfe/trunk/test/SemaTemplate/resolve-single-template-id.cpp Wed Mar 16 14:16:25 2011 @@ -1,11 +1,15 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s -//#include + +namespace std { + class type_info {}; +} + void one() { } -void two() { } // expected-note 3{{candidate}} -void two(int) { } // expected-note 3{{candidate}} +void two() { } // expected-note 2{{candidate}} +void two(int) { } // expected-note 2{{candidate}} -template void twoT() { } // expected-note 4{{candidate}} -template void twoT(int) { } // expected-note 4{{candidate}} +template void twoT() { } // expected-note 3{{candidate}} +template void twoT(int) { } // expected-note 3{{candidate}} template void oneT() { } template void oneT(U) { } @@ -28,15 +32,15 @@ two; // expected-error {{address of overloaded}} oneT; // expected-warning {{expression result unused}} twoT; // expected-error {{address of overloaded}} - typeid(oneT); //expected-error {{you need to include }} + typeid(oneT); // expected-warning{{expression result unused}} sizeof(oneT); // expected-warning {{expression result unused}} - sizeof(twoT); //expected-error {{cannot resolve overloaded function from context}} + sizeof(twoT); //expected-error {{cannot resolve overloaded function 'twoT' from context}} decltype(oneT)* fun = 0; *one; // expected-warning {{expression result unused}} *oneT; // expected-warning {{expression result unused}} - *two; //expected-error {{cannot resolve overloaded function from context}} - *twoT; //expected-error {{cannot resolve overloaded function from context}} + *two; //expected-error {{cannot resolve overloaded function 'two' from context}} + *twoT; //expected-error {{cannot resolve overloaded function 'twoT' from context}} !oneT; // expected-warning {{expression result unused}} +oneT; // expected-warning {{expression result unused}} -oneT; //expected-error {{invalid argument type}} @@ -50,7 +54,7 @@ (twoT) == oneT; //expected-error {{invalid operands to binary expression}} bool b = oneT; void (*p)() = oneT; - test> ti; + test > ti; void (*u)(int) = oneT; b = (void (*)()) twoT; @@ -66,3 +70,11 @@ oneT == 0; // expected-warning {{expression result unused}} } + +struct rdar9108698 { + template void f(); +}; + +void test_rdar9108698(rdar9108698 x) { + x.f; // expected-error{{a bound member function may only be called}} +} Removed: cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch?rev=127746&view=auto ============================================================================== --- cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch (original) +++ cfe/trunk/test/SemaTemplate/resolve-single-template-id.patch (removed) @@ -1,68 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s -//#include -void one() { } -void two() { } // expected-note 3{{candidate}} -void two(int) { } // expected-note 3{{candidate}} - -template void twoT() { } // expected-note 4{{candidate}} -template void twoT(int) { } // expected-note 4{{candidate}} - -template void oneT() { } -template void oneT(U) { } -/* -The target can be - an object or reference being initialized (8.5, 8.5.3), - the left side of an assignment (5.17), - a parameter of a function (5.2.2), - a parameter of a user-defined operator (13.5), - the return value of a function, operator function, or conversion (6.6.3), - an explicit type conversion (5.2.3, 5.2.9, 5.4), or - a non-type template-parameter (14.3.2) -*/ -//#include -template struct test { }; - -int main() -{ - one; // expected-warning {{expression result unused}} - two; // expected-error {{address of overloaded}} - oneT; // expected-warning {{expression result unused}} - twoT; // expected-error {{address of overloaded}} - typeid(oneT); //expected-error {{you need to include }} - sizeof(oneT); // expected-warning {{expression result unused}} - sizeof(twoT); //expected-error {{cannot resolve overloaded function from context}} - decltype(oneT)* fun = 0; - - *one; // expected-warning {{expression result unused}} - *oneT; // expected-warning {{expression result unused}} - *two; //expected-error {{cannot resolve overloaded function from context}} - *twoT; //expected-error {{cannot resolve overloaded function from context}} - !oneT; // expected-warning {{expression result unused}} - +oneT; // expected-warning {{expression result unused}} - -oneT; //expected-error {{invalid argument type}} - oneT == 0; // expected-warning {{expression result unused}} - 0 == oneT; // expected-warning {{expression result unused}} - 0 != oneT; // expected-warning {{expression result unused}} - (false ? one : oneT); // expected-warning {{expression result unused}} - void (*p1)(int); p1 = oneT; - - int i = (int) (false ? (void (*)(int))twoT : oneT); //expected-error {{incompatible operand}} - (twoT) == oneT; //expected-error {{invalid operands to binary expression}} - bool b = oneT; - void (*p)() = oneT; - test> ti; - void (*u)(int) = oneT; - - b = (void (*)()) twoT; - - one < one; //expected-warning {{self-comparison always evaluates to false}} \ - //expected-warning {{expression result unused}} - - oneT < oneT; //expected-warning {{self-comparison always evaluates to false}} \ - //expected-warning {{expression result unused}} - - two < two; //expected-error {{invalid operands to binary expression}} - twoT < twoT; //expected-error {{invalid operands to binary expression}} - oneT == 0; // expected-warning {{expression result unused}} - -} From akyrtzi at gmail.com Wed Mar 16 14:17:25 2011 From: akyrtzi at gmail.com (Argyrios Kyrtzidis) Date: Wed, 16 Mar 2011 19:17:25 -0000 Subject: [cfe-commits] r127748 - in /cfe/trunk: include/clang/Basic/FileManager.h lib/Basic/FileManager.cpp lib/Lex/HeaderSearch.cpp Message-ID: <20110316191725.66DAC2A6C12C@llvm.org> Author: akirtzidis Date: Wed Mar 16 14:17:25 2011 New Revision: 127748 URL: http://llvm.org/viewvc/llvm-project?rev=127748&view=rev Log: Having FileManager::getFile always open the file, brought much consternation and leaking of file descriptors. Add 'openFile' bool to FileManager::getFile to specify whether we want to have the file opened or not, have it false by default, and enable it only in HeaderSearch.cpp where the open+fstat optimization matters. Fixes rdar://9139899. Modified: cfe/trunk/include/clang/Basic/FileManager.h cfe/trunk/lib/Basic/FileManager.cpp cfe/trunk/lib/Lex/HeaderSearch.cpp Modified: cfe/trunk/include/clang/Basic/FileManager.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=127748&r1=127747&r2=127748&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/FileManager.h (original) +++ cfe/trunk/include/clang/Basic/FileManager.h Wed Mar 16 14:17:25 2011 @@ -176,10 +176,11 @@ /// const DirectoryEntry *getDirectory(llvm::StringRef DirName); - /// getFile - Lookup, cache, and verify the specified file (real or + /// \brief Lookup, cache, and verify the specified file (real or /// virtual). This returns NULL if the file doesn't exist. /// - const FileEntry *getFile(llvm::StringRef Filename); + /// \param openFile if true and the file exists, it will be opened. + const FileEntry *getFile(llvm::StringRef Filename, bool openFile = false); /// \brief Retrieve a file entry for a "virtual" file that acts as /// if there were a file with the given name on disk. The file Modified: cfe/trunk/lib/Basic/FileManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=127748&r1=127747&r2=127748&view=diff ============================================================================== --- cfe/trunk/lib/Basic/FileManager.cpp (original) +++ cfe/trunk/lib/Basic/FileManager.cpp Wed Mar 16 14:17:25 2011 @@ -313,7 +313,7 @@ /// getFile - Lookup, cache, and verify the specified file (real or /// virtual). This returns NULL if the file doesn't exist. /// -const FileEntry *FileManager::getFile(llvm::StringRef Filename) { +const FileEntry *FileManager::getFile(llvm::StringRef Filename, bool openFile) { ++NumFileLookups; // See if there is already an entry in the map. @@ -354,6 +354,11 @@ return 0; } + if (FileDescriptor != -1 && !openFile) { + close(FileDescriptor); + FileDescriptor = -1; + } + // It exists. See if we have already opened a file with the same inode. // This occurs when one dir is symlinked to another, for example. FileEntry &UFE = UniqueRealFiles.getFile(InterndFileName, StatBuf); Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=127748&r1=127747&r2=127748&view=diff ============================================================================== --- cfe/trunk/lib/Lex/HeaderSearch.cpp (original) +++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Mar 16 14:17:25 2011 @@ -126,7 +126,7 @@ TmpDir.append(Filename.begin(), Filename.end()); if (RawPath != NULL) *RawPath = TmpDir; - return HS.getFileMgr().getFile(TmpDir.str()); + return HS.getFileMgr().getFile(TmpDir.str(), /*openFile=*/true); } if (isFramework()) @@ -192,7 +192,8 @@ FrameworkName += "Headers/"; FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end()); - if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str())) { + if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(), + /*openFile=*/true)) { if (RawPath != NULL) *RawPath = FrameworkName; return FE; @@ -204,7 +205,7 @@ Private+strlen(Private)); if (RawPath != NULL) *RawPath = FrameworkName; - return FileMgr.getFile(FrameworkName.str()); + return FileMgr.getFile(FrameworkName.str(), /*openFile=*/true); } @@ -235,7 +236,7 @@ if (RawPath != NULL) llvm::Twine(Filename).toVector(*RawPath); // Otherwise, just return the file. - return FileMgr.getFile(Filename); + return FileMgr.getFile(Filename, /*openFile=*/true); } // Step #0, unless disabled, check to see if the file is in the #includer's @@ -250,7 +251,7 @@ TmpDir += CurFileEnt->getDir()->getName(); TmpDir.push_back('/'); TmpDir.append(Filename.begin(), Filename.end()); - if (const FileEntry *FE = FileMgr.getFile(TmpDir.str())) { + if (const FileEntry *FE = FileMgr.getFile(TmpDir.str(),/*openFile=*/true)) { // Leave CurDir unset. // This file is a system header or C++ unfriendly if the old file is. // @@ -376,13 +377,13 @@ llvm::SmallString<1024> HeadersFilename(FrameworkName); HeadersFilename += "Headers/"; HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end()); - if (!(FE = FileMgr.getFile(HeadersFilename.str()))) { + if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true))) { // Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h" HeadersFilename = FrameworkName; HeadersFilename += "PrivateHeaders/"; HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end()); - if (!(FE = FileMgr.getFile(HeadersFilename.str()))) + if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true))) return 0; } if (RawPath != NULL) From dgregor at apple.com Wed Mar 16 14:27:43 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 12:27:43 -0700 Subject: [cfe-commits] r127623 - in /cfe/trunk: include/clang/Sema/IdentifierResolver.h lib/Sema/IdentifierResolver.cpp lib/Sema/SemaDecl.cpp test/SemaCXX/goto.cpp In-Reply-To: <20110315211155.GA24531@britannica.bec.de> References: <20110314211951.DA5752A6C12C@llvm.org> <20110315211155.GA24531@britannica.bec.de> Message-ID: <4AF59C28-F687-4100-BEB7-C60E1BEE3283@apple.com> On Mar 15, 2011, at 2:11 PM, Joerg Sonnenberger wrote: > On Mon, Mar 14, 2011 at 09:19:51PM -0000, Douglas Gregor wrote: >> Author: dgregor >> Date: Mon Mar 14 16:19:51 2011 >> New Revision: 127623 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127623&view=rev >> Log: >> When synthesizing a label declaration based on a goto statement that >> cannot yet be resolved, be sure to push the new label declaration into >> the right place within the identifier chain. Otherwise, name lookup in >> C++ gets confused when searching for names that are lexically closer >> than the label. Fixes PR9463. > > This broke compiling src/roff/troff/input.cpp from groff in the NetBSD > tree. It now fails with > > lib/Sema/JumpDiagnostics.cpp:541: void::JumpScopeChecker::CheckJump(clang::Stmt*, clang::Stmt*, clang::SourceLocation, unsigned int): Assertion `LabelAndGotoScopes.count(To) && "Jump didn't get added to scopes?"' failed. Can you confirm that r127738 fixes this issue? - Doug From dgregor at apple.com Wed Mar 16 14:27:09 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 19:27:09 -0000 Subject: [cfe-commits] r127749 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp Message-ID: <20110316192709.606D32A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 14:27:09 2011 New Revision: 127749 URL: http://llvm.org/viewvc/llvm-project?rev=127749&view=rev Log: Detect attempts to provide a specialization of a function within a dependent scope and produce an error (rather than crashing). Fixes PR8979. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127749&r1=127748&r2=127749&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 16 14:27:09 2011 @@ -1733,6 +1733,8 @@ def err_not_class_template_specialization : Error< "cannot specialize a %select{dependent template|template template " "parameter}0">; +def err_function_specialization_in_class : Error< + "cannot specialize a function %0 within class scope">; // C++ class template specializations and out-of-line definitions def err_template_spec_needs_header : Error< Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127749&r1=127748&r2=127749&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 16 14:27:09 2011 @@ -4102,9 +4102,15 @@ Previous)) NewFD->setInvalidDecl(); } else if (isFunctionTemplateSpecialization) { - if (CheckFunctionTemplateSpecialization(NewFD, - (HasExplicitTemplateArgs ? &TemplateArgs : 0), - Previous)) + if (CurContext->isDependentContext() && CurContext->isRecord() + && !isFriend) { + Diag(NewFD->getLocation(), diag::err_function_specialization_in_class) + << NewFD->getDeclName(); + NewFD->setInvalidDecl(); + return 0; + } else if (CheckFunctionTemplateSpecialization(NewFD, + (HasExplicitTemplateArgs ? &TemplateArgs : 0), + Previous)) NewFD->setInvalidDecl(); } else if (isExplicitSpecialization && isa(NewFD)) { if (CheckMemberSpecialization(NewFD, Previous)) Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp?rev=127749&r1=127748&r2=127749&view=diff ============================================================================== --- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp (original) +++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp Wed Mar 16 14:27:09 2011 @@ -237,3 +237,15 @@ xvp.ft1(vp, i); xvp.ft1(vp, u); } + +namespace PR8979 { + template + struct X0 { + template class Inner; + struct OtherInner; + template void f(Inner&); + + typedef Inner MyInner; + template<> void f(MyInner&); // expected-error{{cannot specialize a function 'f' within class scope}} + }; +} From joerg at britannica.bec.de Wed Mar 16 14:36:37 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Wed, 16 Mar 2011 20:36:37 +0100 Subject: [cfe-commits] r127623 - in /cfe/trunk: include/clang/Sema/IdentifierResolver.h lib/Sema/IdentifierResolver.cpp lib/Sema/SemaDecl.cpp test/SemaCXX/goto.cpp In-Reply-To: <4AF59C28-F687-4100-BEB7-C60E1BEE3283@apple.com> References: <20110314211951.DA5752A6C12C@llvm.org> <20110315211155.GA24531@britannica.bec.de> <4AF59C28-F687-4100-BEB7-C60E1BEE3283@apple.com> Message-ID: <20110316193637.GA2771@britannica.bec.de> On Wed, Mar 16, 2011 at 12:27:43PM -0700, Douglas Gregor wrote: > > On Mar 15, 2011, at 2:11 PM, Joerg Sonnenberger wrote: > > > On Mon, Mar 14, 2011 at 09:19:51PM -0000, Douglas Gregor wrote: > >> Author: dgregor > >> Date: Mon Mar 14 16:19:51 2011 > >> New Revision: 127623 > >> > >> URL: http://llvm.org/viewvc/llvm-project?rev=127623&view=rev > >> Log: > >> When synthesizing a label declaration based on a goto statement that > >> cannot yet be resolved, be sure to push the new label declaration into > >> the right place within the identifier chain. Otherwise, name lookup in > >> C++ gets confused when searching for names that are lexically closer > >> than the label. Fixes PR9463. > > > > This broke compiling src/roff/troff/input.cpp from groff in the NetBSD > > tree. It now fails with > > > > lib/Sema/JumpDiagnostics.cpp:541: void::JumpScopeChecker::CheckJump(clang::Stmt*, clang::Stmt*, clang::SourceLocation, unsigned int): Assertion `LabelAndGotoScopes.count(To) && "Jump didn't get added to scopes?"' failed. > > Can you confirm that r127738 fixes this issue? It does, thanks. Joerg From joerg at bec.de Wed Mar 16 15:15:43 2011 From: joerg at bec.de (Joerg Sonnenberger) Date: Wed, 16 Mar 2011 20:15:43 -0000 Subject: [cfe-commits] r127753 - /cfe/trunk/tools/driver/driver.cpp Message-ID: <20110316201543.695612A6C12C@llvm.org> Author: joerg Date: Wed Mar 16 15:15:43 2011 New Revision: 127753 URL: http://llvm.org/viewvc/llvm-project?rev=127753&view=rev Log: Refactor program name logic. Extend it to infer the target triple from the program name, if it includes it as proper prefix. This makes calling clang with -ccc-host-triple x86_64-linux the same as calling it with the name x86_64-linux-clang. Modified: cfe/trunk/tools/driver/driver.cpp Modified: cfe/trunk/tools/driver/driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=127753&r1=127752&r2=127753&view=diff ============================================================================== --- cfe/trunk/tools/driver/driver.cpp (original) +++ cfe/trunk/tools/driver/driver.cpp Wed Mar 16 15:15:43 2011 @@ -35,6 +35,8 @@ #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/system_error.h" +#include "llvm/Target/TargetRegistry.h" +#include "llvm/Target/TargetSelect.h" #include using namespace clang; using namespace clang::driver; @@ -252,6 +254,85 @@ } } +static void ParseProgName(llvm::SmallVectorImpl &ArgVector, + std::set &SavedStrings, + Driver &TheDriver) +{ + // Try to infer frontend type and default target from the program name. + + // suffixes[] contains the list of known driver suffixes. + // Suffixes are compared against the program name in order. + // If there is a match, the frontend type is updated as necessary (CPP/C++). + // If there is no match, a second round is done after stripping the last + // hyphen and everything following it. This allows using something like + // "clang++-2.9". + + // If there is a match in either the first or second round, + // the function tries to identify a target as prefix. E.g. + // "x86_64-linux-clang" as interpreted as suffix "clang" with + // target prefix "x86_64-linux". If such a target prefix is found, + // is gets added via -ccc-host-triple as implicit first argument. + static const struct { + const char *Suffix; + bool IsCXX; + bool IsCPP; + } suffixes [] = { + { "clang", false, false }, + { "clang++", true, false }, + { "clang-c++", true, false }, + { "clang-cc", false, false }, + { "clang-cpp", false, true }, + { "clang-g++", true, false }, + { "clang-gcc", false, false }, + { "cc", false, false }, + { "cpp", false, true }, + { "++", true, false }, + }; + std::string ProgName(llvm::sys::path::stem(ArgVector[0])); + llvm::StringRef ProgNameRef(ProgName); + llvm::StringRef Prefix; + + for (int Components = 2; Components; --Components) { + bool FoundMatch = false; + size_t i; + + for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); ++i) { + if (ProgNameRef.endswith(suffixes[i].Suffix)) { + FoundMatch = true; + if (suffixes[i].IsCXX) + TheDriver.CCCIsCXX = true; + if (suffixes[i].IsCPP) + TheDriver.CCCIsCPP = true; + break; + } + } + + if (FoundMatch) { + llvm::StringRef::size_type LastComponent = ProgNameRef.rfind('-', + ProgNameRef.size() - strlen(suffixes[i].Suffix)); + if (LastComponent != llvm::StringRef::npos) + Prefix = ProgNameRef.slice(0, LastComponent); + break; + } + + llvm::StringRef::size_type LastComponent = ProgNameRef.rfind('-'); + if (LastComponent == llvm::StringRef::npos) + break; + ProgNameRef = ProgNameRef.slice(0, LastComponent); + } + + if (Prefix.empty()) + return; + + std::string IgnoredError; + if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) { + ArgVector.insert(&ArgVector[1], + SaveStringInSet(SavedStrings, Prefix)); + ArgVector.insert(&ArgVector[1], + SaveStringInSet(SavedStrings, std::string("-ccc-host-triple"))); + } +} + int main(int argc_, const char **argv_) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc_, argv_); @@ -328,24 +409,8 @@ TheDriver.setInstalledDir(InstalledPath); } - // Check for ".*++" or ".*++-[^-]*" to determine if we are a C++ - // compiler. This matches things like "c++", "clang++", and "clang++-1.1". - // - // Note that we intentionally want to use argv[0] here, to support "clang++" - // being a symlink. - // - // We use *argv instead of argv[0] to work around a bogus g++ warning. - const char *progname = argv_[0]; - std::string ProgName(llvm::sys::path::stem(progname)); - if (llvm::StringRef(ProgName).endswith("++") || - llvm::StringRef(ProgName).rsplit('-').first.endswith("++")) { - TheDriver.CCCIsCXX = true; - } - - if (llvm::StringRef(ProgName).endswith("cpp") || - llvm::StringRef(ProgName).rsplit('-').first.endswith("cpp")) { - TheDriver.CCCIsCPP = true; - } + llvm::InitializeAllTargets(); + ParseProgName(argv, SavedStrings, TheDriver); // Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE. TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS"); From abramo.bagnara at gmail.com Wed Mar 16 15:16:18 2011 From: abramo.bagnara at gmail.com (Abramo Bagnara) Date: Wed, 16 Mar 2011 20:16:18 -0000 Subject: [cfe-commits] r127755 - in /cfe/trunk: include/clang/AST/PrettyPrinter.h include/clang/Sema/DeclSpec.h lib/AST/TypePrinter.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaType.cpp test/Index/annotate-nested-name-specifier.cpp test/Index/annotate-tokens.c test/Index/recursive-member-access.c test/SemaCXX/sourceranges.cpp Message-ID: <20110316201618.B05492A6C12C@llvm.org> Author: abramo Date: Wed Mar 16 15:16:18 2011 New Revision: 127755 URL: http://llvm.org/viewvc/llvm-project?rev=127755&view=rev Log: Use ElaboratedType also for C. Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h cfe/trunk/include/clang/Sema/DeclSpec.h cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Parse/ParseDeclCXX.cpp cfe/trunk/lib/Sema/DeclSpec.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/Index/annotate-nested-name-specifier.cpp cfe/trunk/test/Index/annotate-tokens.c cfe/trunk/test/Index/recursive-member-access.c cfe/trunk/test/SemaCXX/sourceranges.cpp Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/PrettyPrinter.h (original) +++ cfe/trunk/include/clang/AST/PrettyPrinter.h Wed Mar 16 15:16:18 2011 @@ -38,7 +38,7 @@ /// \brief Create a default printing policy for C. PrintingPolicy(const LangOptions &LO) : Indentation(2), LangOpts(LO), SuppressSpecifiers(false), - SuppressTag(false), SuppressScope(false), + SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), Dump(false), ConstantArraySizeAsWritten(false), AnonymousTagLocations(true) { } @@ -64,6 +64,16 @@ /// "const int" type specifier and instead only print the "*y". bool SuppressSpecifiers : 1; + /// \brief Whether type printing should skip printing the tag keyword. + /// + /// This is used when printing the inner type of elaborated types, + /// (as the tag keyword is part of the elaborated type): + /// + /// \code + /// struct Geometry::Point; + /// \endcode + bool SuppressTagKeyword : 1; + /// \brief Whether type printing should skip printing the actual tag type. /// /// This is used when the caller needs to print a tag definition in front Modified: cfe/trunk/include/clang/Sema/DeclSpec.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/DeclSpec.h (original) +++ cfe/trunk/include/clang/Sema/DeclSpec.h Wed Mar 16 15:16:18 2011 @@ -329,6 +329,11 @@ SourceLocation StorageClassSpecLoc, SCS_threadLoc; SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; + /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union, + /// typename, then this is the location of the named type (if present); + /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and + /// TSTNameLoc provides source range info for tag types. + SourceLocation TSTNameLoc; SourceRange TypeofParensRange; SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc; SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc; @@ -431,6 +436,11 @@ SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } SourceLocation getAltiVecLoc() const { return AltiVecLoc; } + SourceLocation getTypeSpecTypeNameLoc() const { + assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename); + return TSTNameLoc; + } + SourceRange getTypeofParensRange() const { return TypeofParensRange; } void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; } @@ -522,6 +532,13 @@ unsigned &DiagID, ParsedType Rep); bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, Decl *Rep, bool Owned); + bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, + SourceLocation TagNameLoc, const char *&PrevSpec, + unsigned &DiagID, ParsedType Rep); + bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, + SourceLocation TagNameLoc, const char *&PrevSpec, + unsigned &DiagID, Decl *Rep, bool Owned); + bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, Expr *Rep); bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, Modified: cfe/trunk/lib/AST/TypePrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/lib/AST/TypePrinter.cpp (original) +++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Mar 16 15:16:18 2011 @@ -557,9 +557,13 @@ std::string Buffer; bool HasKindDecoration = false; + // bool SuppressTagKeyword + // = Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword; + // We don't print tags unless this is an elaborated type. // In C, we just assume every RecordType is an elaborated type. - if (!Policy.LangOpts.CPlusPlus && !D->getTypedefForAnonDecl()) { + if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword || + D->getTypedefForAnonDecl())) { HasKindDecoration = true; Buffer += D->getKindName(); Buffer += ' '; @@ -701,6 +705,7 @@ std::string TypeStr; PrintingPolicy InnerPolicy(Policy); + InnerPolicy.SuppressTagKeyword = true; InnerPolicy.SuppressScope = true; TypePrinter(InnerPolicy).print(T->getNamedType(), TypeStr); Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Mar 16 15:16:18 2011 @@ -2123,7 +2123,6 @@ bool Owned = false; bool IsDependent = false; - SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc; const char *PrevSpec = 0; unsigned DiagID; Decl *TagDecl = Actions.ActOnTag(getCurScope(), DeclSpec::TST_enum, TUK, @@ -2150,8 +2149,9 @@ return; } - if (DS.SetTypeSpecType(DeclSpec::TST_typename, TSTLoc, PrevSpec, DiagID, - Type.get())) + if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, + NameLoc.isValid() ? NameLoc : StartLoc, + PrevSpec, DiagID, Type.get())) Diag(StartLoc, DiagID) << PrevSpec; return; @@ -2172,10 +2172,9 @@ if (Tok.is(tok::l_brace)) ParseEnumBody(StartLoc, TagDecl); - // FIXME: The DeclSpec should keep the locations of both the keyword - // and the name (if there is one). - if (DS.SetTypeSpecType(DeclSpec::TST_enum, TSTLoc, PrevSpec, DiagID, - TagDecl, Owned)) + if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, + NameLoc.isValid() ? NameLoc : StartLoc, + PrevSpec, DiagID, TagDecl, Owned)) Diag(StartLoc, DiagID) << PrevSpec; } Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original) +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Mar 16 15:16:18 2011 @@ -1017,19 +1017,17 @@ ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); } - // FIXME: The DeclSpec should keep the locations of both the keyword and the - // name (if there is one). - SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc; - const char *PrevSpec = 0; unsigned DiagID; bool Result; if (!TypeResult.isInvalid()) { - Result = DS.SetTypeSpecType(DeclSpec::TST_typename, TSTLoc, + Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, + NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec, DiagID, TypeResult.get()); } else if (!TagOrTempResult.isInvalid()) { - Result = DS.SetTypeSpecType(TagType, TSTLoc, PrevSpec, DiagID, - TagOrTempResult.get(), Owned); + Result = DS.SetTypeSpecType(TagType, StartLoc, + NameLoc.isValid() ? NameLoc : StartLoc, + PrevSpec, DiagID, TagOrTempResult.get(), Owned); } else { DS.SetTypeSpecError(); return; Modified: cfe/trunk/lib/Sema/DeclSpec.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/lib/Sema/DeclSpec.cpp (original) +++ cfe/trunk/lib/Sema/DeclSpec.cpp Wed Mar 16 15:16:18 2011 @@ -421,6 +421,14 @@ const char *&PrevSpec, unsigned &DiagID, ParsedType Rep) { + return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep); +} + +bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, + SourceLocation TagNameLoc, + const char *&PrevSpec, + unsigned &DiagID, + ParsedType Rep) { assert(isTypeRep(T) && "T does not store a type"); assert(Rep && "no type provided!"); if (TypeSpecType != TST_unspecified) { @@ -430,7 +438,8 @@ } TypeSpecType = T; TypeRep = Rep; - TSTLoc = Loc; + TSTLoc = TagKwLoc; + TSTNameLoc = TagNameLoc; TypeSpecOwned = false; return false; } @@ -449,6 +458,7 @@ TypeSpecType = T; ExprRep = Rep; TSTLoc = Loc; + TSTNameLoc = Loc; TypeSpecOwned = false; return false; } @@ -457,6 +467,14 @@ const char *&PrevSpec, unsigned &DiagID, Decl *Rep, bool Owned) { + return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned); +} + +bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, + SourceLocation TagNameLoc, + const char *&PrevSpec, + unsigned &DiagID, + Decl *Rep, bool Owned) { assert(isDeclRep(T) && "T does not store a decl"); // Unlike the other cases, we don't assert that we actually get a decl. @@ -467,7 +485,8 @@ } TypeSpecType = T; DeclRep = Rep; - TSTLoc = Loc; + TSTLoc = TagKwLoc; + TSTNameLoc = TagNameLoc; TypeSpecOwned = Owned; return false; } @@ -482,13 +501,13 @@ DiagID = diag::err_invalid_decl_spec_combination; return true; } + TSTLoc = Loc; + TSTNameLoc = Loc; if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { TypeAltiVecBool = true; - TSTLoc = Loc; return false; } TypeSpecType = T; - TSTLoc = Loc; TypeSpecOwned = false; if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); @@ -520,6 +539,7 @@ } TypeAltiVecPixel = isAltiVecPixel; TSTLoc = Loc; + TSTNameLoc = Loc; return false; } @@ -527,6 +547,7 @@ TypeSpecType = TST_error; TypeSpecOwned = false; TSTLoc = SourceLocation(); + TSTNameLoc = SourceLocation(); return false; } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Mar 16 15:16:18 2011 @@ -728,7 +728,7 @@ } // If the type is deprecated or unavailable, diagnose it. - S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc()); + S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeNameLoc()); assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!"); @@ -736,12 +736,11 @@ // TypeQuals handled by caller. Result = Context.getTypeDeclType(D); - // In C++, make an ElaboratedType. - if (S.getLangOptions().CPlusPlus) { - ElaboratedTypeKeyword Keyword - = ElaboratedType::getKeywordForTypeSpec(DS.getTypeSpecType()); - Result = S.getElaboratedType(Keyword, DS.getTypeSpecScope(), Result); - } + // In both C and C++, make an ElaboratedType. + ElaboratedTypeKeyword Keyword + = ElaboratedType::getKeywordForTypeSpec(DS.getTypeSpecType()); + Result = S.getElaboratedType(Keyword, DS.getTypeSpecScope(), Result); + if (D->isInvalidDecl()) declarator.setInvalidType(true); break; @@ -2300,7 +2299,7 @@ // If we got no declarator info from previous Sema routines, // just fill with the typespec loc. if (!TInfo) { - TL.initialize(Context, DS.getTypeSpecTypeLoc()); + TL.initialize(Context, DS.getTypeSpecTypeNameLoc()); return; } @@ -2377,7 +2376,7 @@ : SourceLocation()); const CXXScopeSpec& SS = DS.getTypeSpecScope(); TL.setQualifierLoc(SS.getWithLocInContext(Context)); - TL.setNameLoc(DS.getTypeSpecTypeLoc()); + TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); } void VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL) { @@ -2398,7 +2397,10 @@ : SourceLocation()); const CXXScopeSpec& SS = DS.getTypeSpecScope(); TL.setQualifierLoc(SS.getWithLocInContext(Context)); - TL.setNameLoc(DS.getTypeSpecTypeLoc()); + TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); + } + void VisitTagTypeLoc(TagTypeLoc TL) { + TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); } void VisitTypeLoc(TypeLoc TL) { Modified: cfe/trunk/test/Index/annotate-nested-name-specifier.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-nested-name-specifier.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/test/Index/annotate-nested-name-specifier.cpp (original) +++ cfe/trunk/test/Index/annotate-nested-name-specifier.cpp Wed Mar 16 15:16:18 2011 @@ -149,13 +149,13 @@ // Base specifiers // CHECK: Identifier: "outer_alias" [16:19 - 16:30] NamespaceRef=outer_alias:10:11 -// CHECK: Punctuation: "::" [16:30 - 16:32] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] +// CHECK: Punctuation: "::" [16:30 - 16:32] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] // CHECK: Identifier: "inner" [16:32 - 16:37] NamespaceRef=inner:2:13 -// CHECK: Punctuation: "::" [16:37 - 16:39] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] +// CHECK: Punctuation: "::" [16:37 - 16:39] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] // CHECK: Identifier: "vector" [16:39 - 16:45] TemplateRef=vector:4:12 -// CHECK: Punctuation: "<" [16:45 - 16:46] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] +// CHECK: Punctuation: "<" [16:45 - 16:46] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] // CHECK: Identifier: "X" [16:46 - 16:47] TypeRef=struct X:12:8 -// CHECK: Punctuation: ">" [16:47 - 16:48] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] +// CHECK: Punctuation: ">" [16:47 - 16:48] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] // CHECK: Keyword: "using" [17:3 - 17:8] UsingDeclaration=iterator[5:18] Modified: cfe/trunk/test/Index/annotate-tokens.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.c?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/test/Index/annotate-tokens.c (original) +++ cfe/trunk/test/Index/annotate-tokens.c Wed Mar 16 15:16:18 2011 @@ -53,7 +53,7 @@ // CHECK: Punctuation: ")" [5:17 - 5:18] UnexposedExpr= // CHECK: Punctuation: ";" [5:18 - 5:19] UnexposedStmt= // CHECK: Comment: "/* A comment */" [6:3 - 6:18] UnexposedStmt= -// CHECK: Keyword: "struct" [7:3 - 7:9] UnexposedStmt= +// CHECK: Keyword: "struct" [7:3 - 7:9] VarDecl=x:7:12 (Definition) // CHECK: Identifier: "X" [7:10 - 7:11] TypeRef=struct X:2:8 // CHECK: Identifier: "x" [7:12 - 7:13] VarDecl=x:7:12 (Definition) // CHECK: Punctuation: "=" [7:14 - 7:15] VarDecl=x:7:12 (Definition) @@ -91,7 +91,7 @@ // CHECK: Identifier: "Int" [16:38 - 16:41] TypeRef=Int:12:13 // CHECK: Punctuation: "," [16:41 - 16:42] UnexposedExpr= // CHECK: Identifier: "Int" [16:43 - 16:46] TypeRef=Int:12:13 -// CHECK: Keyword: "struct" [18:3 - 18:9] UnexposedStmt= +// CHECK: Keyword: "struct" [18:3 - 18:9] VarDecl=x:18:12 (Definition) // CHECK: Identifier: "X" [18:10 - 18:11] TypeRef=struct X:2:8 // CHECK: Identifier: "x" [18:12 - 18:13] VarDecl=x:18:12 (Definition) // CHECK: Keyword: "do" [19:3 - 19:5] UnexposedStmt= @@ -107,7 +107,7 @@ // CHECK: Punctuation: "." [21:13 - 21:14] MemberRefExpr=a:2:16 // CHECK: Identifier: "a" [21:14 - 21:15] MemberRefExpr=a:2:16 -// CHECK: Keyword: "enum" [23:3 - 23:7] UnexposedStmt= +// CHECK: Keyword: "enum" [23:3 - 23:7] VarDecl=c:23:14 (Definition) // CHECK: Identifier: "Color" [23:8 - 23:13] TypeRef=enum Color:11:6 // CHECK: Identifier: "c" [23:14 - 23:15] VarDecl=c:23:14 (Definition) // CHECK: Punctuation: ";" [23:15 - 23:16] UnexposedStmt= Modified: cfe/trunk/test/Index/recursive-member-access.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/recursive-member-access.c?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/test/Index/recursive-member-access.c (original) +++ cfe/trunk/test/Index/recursive-member-access.c Wed Mar 16 15:16:18 2011 @@ -257,7 +257,7 @@ // CHECK-tokens: Keyword: "struct" [1:1 - 1:7] StructDecl=rdar8650865:1:8 (Definition) // CHECK-tokens: Identifier: "rdar8650865" [1:8 - 1:19] StructDecl=rdar8650865:1:8 (Definition) // CHECK-tokens: Punctuation: "{" [1:20 - 1:21] StructDecl=rdar8650865:1:8 (Definition) -// CHECK-tokens: Keyword: "struct" [2:3 - 2:9] StructDecl=rdar8650865:1:8 (Definition) +// CHECK-tokens: Keyword: "struct" [2:3 - 2:9] FieldDecl=first:2:23 (Definition) // CHECK-tokens: Identifier: "rdar8650865" [2:10 - 2:21] TypeRef=struct rdar8650865:1:8 // CHECK-tokens: Punctuation: "*" [2:22 - 2:23] FieldDecl=first:2:23 (Definition) // CHECK-tokens: Identifier: "first" [2:23 - 2:28] FieldDecl=first:2:23 (Definition) @@ -270,7 +270,7 @@ // CHECK-tokens: Keyword: "int" [6:1 - 6:4] FunctionDecl=test_rdar8650865:6:5 (Definition) // CHECK-tokens: Identifier: "test_rdar8650865" [6:5 - 6:21] FunctionDecl=test_rdar8650865:6:5 (Definition) // CHECK-tokens: Punctuation: "(" [6:21 - 6:22] FunctionDecl=test_rdar8650865:6:5 (Definition) -// CHECK-tokens: Keyword: "struct" [6:22 - 6:28] FunctionDecl=test_rdar8650865:6:5 (Definition) +// CHECK-tokens: Keyword: "struct" [6:22 - 6:28] ParmDecl=s:6:42 (Definition) // CHECK-tokens: Identifier: "rdar8650865" [6:29 - 6:40] TypeRef=struct rdar8650865:1:8 // CHECK-tokens: Punctuation: "*" [6:41 - 6:42] ParmDecl=s:6:42 (Definition) // CHECK-tokens: Identifier: "s" [6:42 - 6:43] ParmDecl=s:6:42 (Definition) Modified: cfe/trunk/test/SemaCXX/sourceranges.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/sourceranges.cpp?rev=127755&r1=127754&r2=127755&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/sourceranges.cpp (original) +++ cfe/trunk/test/SemaCXX/sourceranges.cpp Wed Mar 16 15:16:18 2011 @@ -13,15 +13,15 @@ } int main() { - // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::class A *' + // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::A *' P p14 = new foo::A; - // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::enum B *' + // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::B *' P p24 = new foo::B; // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::C *' P pr4 = new foo::C; } foo::A getName() { - // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} 'foo::class A' + // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} 'foo::A' return foo::A(); } From kremenek at apple.com Wed Mar 16 16:10:42 2011 From: kremenek at apple.com (Ted Kremenek) Date: Wed, 16 Mar 2011 21:10:42 -0000 Subject: [cfe-commits] r127758 - /cfe/trunk/tools/scan-build/ccc-analyzer Message-ID: <20110316211042.6D0002A6C12C@llvm.org> Author: kremenek Date: Wed Mar 16 16:10:42 2011 New Revision: 127758 URL: http://llvm.org/viewvc/llvm-project?rev=127758&view=rev Log: Compress argument processing in ccc-analyzer. No functionality change. Modified: cfe/trunk/tools/scan-build/ccc-analyzer Modified: cfe/trunk/tools/scan-build/ccc-analyzer URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/ccc-analyzer?rev=127758&r1=127757&r2=127758&view=diff ============================================================================== --- cfe/trunk/tools/scan-build/ccc-analyzer (original) +++ cfe/trunk/tools/scan-build/ccc-analyzer Wed Mar 16 16:10:42 2011 @@ -178,25 +178,20 @@ # Create arguments for doing static analysis. if (defined $ResultFile) { - push @Args,'-o'; - push @Args, $ResultFile; + push @Args, '-o', $ResultFile; } elsif (defined $HtmlDir) { - push @Args,'-o'; - push @Args, $HtmlDir; + push @Args, '-o', $HtmlDir; } - push @Args,"-Xclang"; - push @Args,"-analyzer-display-progress"; + push @Args, "-Xclang", "-analyzer-display-progress"; foreach my $arg (@$AnalyzeArgs) { - push @Args, "-Xclang"; - push @Args, $arg; + push @Args, "-Xclang", $arg; } - + # Display Ubiviz graph? if (defined $ENV{'CCC_UBI'}) { - push @Args, "-Xclang"; - push @Args,"-analyzer-viz-egraph-ubigraph"; + push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph"; } my $AnalysisArgs = GetCCArgs("--analyze", \@Args); @@ -613,8 +608,7 @@ my @AnalyzeArgs; if ($FileLang ne 'unknown') { - push @CmdArgs,'-x'; - push @CmdArgs,$FileLang; + push @CmdArgs, '-x', $FileLang; } if (defined $StoreModel) { @@ -646,8 +640,7 @@ if (scalar @Archs) { foreach my $arch (@Archs) { my @NewArgs; - push @NewArgs, '-arch'; - push @NewArgs, $arch; + push @NewArgs, '-arch', $arch; push @NewArgs, @CmdArgs; Analyze($Clang, \@NewArgs, \@AnalyzeArgs, $FileLang, $Output, $Verbose, $HtmlDir, $file); From matthewbg at google.com Wed Mar 16 16:33:34 2011 From: matthewbg at google.com (Matt Beaumont-Gay) Date: Wed, 16 Mar 2011 14:33:34 -0700 Subject: [cfe-commits] r127702 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/member-function-pointers.cpp In-Reply-To: <20110315211748.779FE2A6C12C@llvm.org> References: <20110315211748.779FE2A6C12C@llvm.org> Message-ID: Hi John, ' On Tue, Mar 15, 2011 at 14:17, John McCall wrote: > Author: rjmccall > Date: Tue Mar 15 16:17:48 2011 > New Revision: 127702 > > URL: http://llvm.org/viewvc/llvm-project?rev=127702&view=rev > Log: > Reorganize the emission of (unfoldable) constant casts a bit, and > make sure that upcasts of member pointer types are covered as constants. > Fixed rdar://problem/9130221 > > > Modified: > ? ?cfe/trunk/lib/CodeGen/CGExprConstant.cpp > ? ?cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp > > Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127702&r1=127701&r2=127702&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Mar 15 16:17:48 2011 > @@ -483,18 +483,17 @@ > ? } > > ? llvm::Constant *VisitCastExpr(CastExpr* E) { > + ? ?Expr *subExpr = E->getSubExpr(); > + ? ?llvm::Constant *C = CGM.EmitConstantExpr(subExpr, subExpr->getType(), CGF); > + ? ?if (!C) return 0; > + > + ? ?const llvm::Type *destType = ConvertType(E->getType()); > + > ? ? switch (E->getCastKind()) { > ? ? case CK_ToUnion: { > ? ? ? // GCC cast to union extension > ? ? ? assert(E->getType()->isUnionType() && > ? ? ? ? ? ? ?"Destination type is not union type!"); > - ? ? ?const llvm::Type *Ty = ConvertType(E->getType()); > - ? ? ?Expr *SubExpr = E->getSubExpr(); > - > - ? ? ?llvm::Constant *C = > - ? ? ? ?CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); > - ? ? ?if (!C) > - ? ? ? ?return 0; > > ? ? ? // Build a struct with the union sub-element as the first member, > ? ? ? // and padded to the appropriate size > @@ -503,7 +502,7 @@ > ? ? ? Elts.push_back(C); > ? ? ? Types.push_back(C->getType()); > ? ? ? unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); > - ? ? ?unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(Ty); > + ? ? ?unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(destType); > > ? ? ? assert(CurSize <= TotalSize && "Union size mismatch!"); > ? ? ? if (unsigned NumPadBytes = TotalSize - CurSize) { > @@ -523,39 +522,101 @@ > ? ? ? const MemberPointerType *MPT = E->getType()->getAs(); > ? ? ? return CGM.getCXXABI().EmitNullMemberPointer(MPT); > ? ? } > - > - ? ?case CK_BaseToDerivedMemberPointer: { > - ? ? ?Expr *SubExpr = E->getSubExpr(); > - ? ? ?llvm::Constant *C = > - ? ? ? ?CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); > - ? ? ?if (!C) return 0; > > + ? ?case CK_DerivedToBaseMemberPointer: > + ? ?case CK_BaseToDerivedMemberPointer: > ? ? ? return CGM.getCXXABI().EmitMemberPointerConversion(C, E); > - ? ?} > > - ? ?case CK_BitCast: > - ? ? ?// This must be a member function pointer cast. > - ? ? ?return Visit(E->getSubExpr()); > - > - ? ?default: { > - ? ? ?// FIXME: This should be handled by the CK_NoOp cast kind. > - ? ? ?// Explicit and implicit no-op casts > - ? ? ?QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); > - ? ? ?if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) > - ? ? ? ?return Visit(E->getSubExpr()); > - > - ? ? ?// Handle integer->integer casts for address-of-label differences. > - ? ? ?if (Ty->isIntegerType() && SubTy->isIntegerType() && > - ? ? ? ? ?CGF) { > - ? ? ? ?llvm::Value *Src = Visit(E->getSubExpr()); > - ? ? ? ?if (Src == 0) return 0; > - > - ? ? ? ?// Use EmitScalarConversion to perform the conversion. > - ? ? ? ?return cast(CGF->EmitScalarConversion(Src, SubTy, Ty)); > - ? ? ?} > - > + ? ?case CK_LValueToRValue: > + ? ?case CK_NoOp: > + ? ? ?return C; > + > + ? ?case CK_AnyPointerToObjCPointerCast: > + ? ?case CK_AnyPointerToBlockPointerCast: > + ? ?case CK_LValueBitCast: > + ? ?case CK_BitCast: > + ? ? ?if (C->getType() == destType) return C; > + ? ? ?return llvm::ConstantExpr::getBitCast(C, destType); > + > + ? ?case CK_Dependent: llvm_unreachable("saw dependent cast!"); > + > + ? ?// These will never be supported. > + ? ?case CK_ObjCObjectLValueCast: > + ? ?case CK_GetObjCProperty: > + ? ?case CK_ToVoid: > + ? ?case CK_Dynamic: > ? ? ? return 0; > + > + ? ?// These might need to be supported for constexpr. > + ? ?case CK_UserDefinedConversion: > + ? ?case CK_ConstructorConversion: > + ? ? ?return 0; > + > + ? ?// These should eventually be supported. > + ? ?case CK_ArrayToPointerDecay: > + ? ?case CK_FunctionToPointerDecay: > + ? ?case CK_BaseToDerived: > + ? ?case CK_DerivedToBase: > + ? ?case CK_UncheckedDerivedToBase: > + ? ?case CK_MemberPointerToBoolean: > + ? ?case CK_VectorSplat: > + ? ?case CK_FloatingRealToComplex: > + ? ?case CK_FloatingComplexToReal: > + ? ?case CK_FloatingComplexToBoolean: > + ? ?case CK_FloatingComplexCast: > + ? ?case CK_FloatingComplexToIntegralComplex: > + ? ?case CK_IntegralRealToComplex: > + ? ?case CK_IntegralComplexToReal: > + ? ?case CK_IntegralComplexToBoolean: > + ? ?case CK_IntegralComplexCast: > + ? ?case CK_IntegralComplexToFloatingComplex: > + ? ? ?return 0; > + > + ? ?case CK_PointerToIntegral: > + ? ? ?if (!E->getType()->isBooleanType()) > + ? ? ? ?return llvm::ConstantExpr::getPtrToInt(C, destType); > + ? ? ?// fallthrough > + > + ? ?case CK_PointerToBoolean: > + ? ? ?return llvm::ConstantExpr::getICmp(llvm::CmpInst::ICMP_EQ, C, > + ? ? ? ?llvm::ConstantPointerNull::get(cast(C->getType()))); > + > + ? ?case CK_NullToPointer: > + ? ? ?return llvm::ConstantPointerNull::get(cast(destType)); > + > + ? ?case CK_IntegralCast: { > + ? ? ?bool isSigned = subExpr->getType()->isSignedIntegerType(); > + ? ? ?return llvm::ConstantExpr::getIntegerCast(C, destType, isSigned); > + ? ?} > + > + ? ?case CK_IntegralToPointer: { > + ? ? ?bool isSigned = subExpr->getType()->isSignedIntegerType(); > + ? ? ?C = llvm::ConstantExpr::getIntegerCast(C, CGM.IntPtrTy, isSigned); > + ? ? ?return llvm::ConstantExpr::getIntToPtr(C, destType); > ? ? } > + > + ? ?case CK_IntegralToBoolean: > + ? ? ?return llvm::ConstantExpr::getICmp(llvm::CmpInst::ICMP_EQ, C, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? llvm::Constant::getNullValue(C->getType())); > + > + ? ?case CK_IntegralToFloating: > + ? ? ?if (subExpr->getType()->isSignedIntegerType()) > + ? ? ? ?return llvm::ConstantExpr::getSIToFP(C, destType); > + ? ? ?else > + ? ? ? ?return llvm::ConstantExpr::getUIToFP(C, destType); > + > + ? ?case CK_FloatingToIntegral: > + ? ? ?if (E->getType()->isSignedIntegerType()) > + ? ? ? ?return llvm::ConstantExpr::getFPToSI(C, destType); > + ? ? ?else > + ? ? ? ?return llvm::ConstantExpr::getFPToUI(C, destType); > + > + ? ?case CK_FloatingToBoolean: > + ? ? ?return llvm::ConstantExpr::getFCmp(llvm::CmpInst::FCMP_UNE, C, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? llvm::Constant::getNullValue(C->getType())); > + > + ? ?case CK_FloatingCast: > + ? ? ?return llvm::ConstantExpr::getFPCast(C, destType); > ? ? } > ? } Here's the latest salvo in my continuing feud with GCC's -Wreturn-type: tools/clang/lib/CodeGen/CGExprConstant.cpp: In member function 'llvm::Constant*::ConstExprEmitter::VisitCastExpr(clang::CastExpr*)': tools/clang/lib/CodeGen/CGExprConstant.cpp:621: error: control reaches end of non-void function Is the new llvm_unreachable the right tool here? E.g.: --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -618,6 +618,7 @@ public: case CK_FloatingCast: return llvm::ConstantExpr::getFPCast(C, destType); } + llvm_unreachable("Invalid CastKind"); } llvm::Constant *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { From dgregor at apple.com Wed Mar 16 16:37:00 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 14:37:00 -0700 Subject: [cfe-commits] r127755 - in /cfe/trunk: include/clang/AST/PrettyPrinter.h include/clang/Sema/DeclSpec.h lib/AST/TypePrinter.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaType.cpp test/Index/annotate-nested-name-specifier.cpp test/Index/annotate-tokens.c test/Index/recursive-member-access.c test/SemaCXX/sourceranges.cpp In-Reply-To: <20110316201618.B05492A6C12C@llvm.org> References: <20110316201618.B05492A6C12C@llvm.org> Message-ID: <749E9717-1DE9-47A3-8D47-33DB895B4EA1@apple.com> On Mar 16, 2011, at 1:16 PM, Abramo Bagnara wrote: > Author: abramo > Date: Wed Mar 16 15:16:18 2011 > New Revision: 127755 > > URL: http://llvm.org/viewvc/llvm-project?rev=127755&view=rev > Log: > Use ElaboratedType also for C. Did you measure the impact of this change on memory usage? - Doug > Modified: > cfe/trunk/include/clang/AST/PrettyPrinter.h > cfe/trunk/include/clang/Sema/DeclSpec.h > cfe/trunk/lib/AST/TypePrinter.cpp > cfe/trunk/lib/Parse/ParseDecl.cpp > cfe/trunk/lib/Parse/ParseDeclCXX.cpp > cfe/trunk/lib/Sema/DeclSpec.cpp > cfe/trunk/lib/Sema/SemaType.cpp > cfe/trunk/test/Index/annotate-nested-name-specifier.cpp > cfe/trunk/test/Index/annotate-tokens.c > cfe/trunk/test/Index/recursive-member-access.c > cfe/trunk/test/SemaCXX/sourceranges.cpp > > Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/PrettyPrinter.h (original) > +++ cfe/trunk/include/clang/AST/PrettyPrinter.h Wed Mar 16 15:16:18 2011 > @@ -38,7 +38,7 @@ > /// \brief Create a default printing policy for C. > PrintingPolicy(const LangOptions &LO) > : Indentation(2), LangOpts(LO), SuppressSpecifiers(false), > - SuppressTag(false), SuppressScope(false), > + SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), > Dump(false), ConstantArraySizeAsWritten(false), > AnonymousTagLocations(true) { } > > @@ -64,6 +64,16 @@ > /// "const int" type specifier and instead only print the "*y". > bool SuppressSpecifiers : 1; > > + /// \brief Whether type printing should skip printing the tag keyword. > + /// > + /// This is used when printing the inner type of elaborated types, > + /// (as the tag keyword is part of the elaborated type): > + /// > + /// \code > + /// struct Geometry::Point; > + /// \endcode > + bool SuppressTagKeyword : 1; > + > /// \brief Whether type printing should skip printing the actual tag type. > /// > /// This is used when the caller needs to print a tag definition in front > > Modified: cfe/trunk/include/clang/Sema/DeclSpec.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Sema/DeclSpec.h (original) > +++ cfe/trunk/include/clang/Sema/DeclSpec.h Wed Mar 16 15:16:18 2011 > @@ -329,6 +329,11 @@ > > SourceLocation StorageClassSpecLoc, SCS_threadLoc; > SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; > + /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union, > + /// typename, then this is the location of the named type (if present); > + /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and > + /// TSTNameLoc provides source range info for tag types. > + SourceLocation TSTNameLoc; > SourceRange TypeofParensRange; > SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc; > SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc; > @@ -431,6 +436,11 @@ > SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } > SourceLocation getAltiVecLoc() const { return AltiVecLoc; } > > + SourceLocation getTypeSpecTypeNameLoc() const { > + assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename); > + return TSTNameLoc; > + } > + > SourceRange getTypeofParensRange() const { return TypeofParensRange; } > void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; } > > @@ -522,6 +532,13 @@ > unsigned &DiagID, ParsedType Rep); > bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, > unsigned &DiagID, Decl *Rep, bool Owned); > + bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, > + SourceLocation TagNameLoc, const char *&PrevSpec, > + unsigned &DiagID, ParsedType Rep); > + bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, > + SourceLocation TagNameLoc, const char *&PrevSpec, > + unsigned &DiagID, Decl *Rep, bool Owned); > + > bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, > unsigned &DiagID, Expr *Rep); > bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, > > Modified: cfe/trunk/lib/AST/TypePrinter.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/TypePrinter.cpp (original) > +++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Mar 16 15:16:18 2011 > @@ -557,9 +557,13 @@ > std::string Buffer; > bool HasKindDecoration = false; > > + // bool SuppressTagKeyword > + // = Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword; > + > // We don't print tags unless this is an elaborated type. > // In C, we just assume every RecordType is an elaborated type. > - if (!Policy.LangOpts.CPlusPlus && !D->getTypedefForAnonDecl()) { > + if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword || > + D->getTypedefForAnonDecl())) { > HasKindDecoration = true; > Buffer += D->getKindName(); > Buffer += ' '; > @@ -701,6 +705,7 @@ > > std::string TypeStr; > PrintingPolicy InnerPolicy(Policy); > + InnerPolicy.SuppressTagKeyword = true; > InnerPolicy.SuppressScope = true; > TypePrinter(InnerPolicy).print(T->getNamedType(), TypeStr); > > > Modified: cfe/trunk/lib/Parse/ParseDecl.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) > +++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Mar 16 15:16:18 2011 > @@ -2123,7 +2123,6 @@ > > bool Owned = false; > bool IsDependent = false; > - SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc; > const char *PrevSpec = 0; > unsigned DiagID; > Decl *TagDecl = Actions.ActOnTag(getCurScope(), DeclSpec::TST_enum, TUK, > @@ -2150,8 +2149,9 @@ > return; > } > > - if (DS.SetTypeSpecType(DeclSpec::TST_typename, TSTLoc, PrevSpec, DiagID, > - Type.get())) > + if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, > + NameLoc.isValid() ? NameLoc : StartLoc, > + PrevSpec, DiagID, Type.get())) > Diag(StartLoc, DiagID) << PrevSpec; > > return; > @@ -2172,10 +2172,9 @@ > if (Tok.is(tok::l_brace)) > ParseEnumBody(StartLoc, TagDecl); > > - // FIXME: The DeclSpec should keep the locations of both the keyword > - // and the name (if there is one). > - if (DS.SetTypeSpecType(DeclSpec::TST_enum, TSTLoc, PrevSpec, DiagID, > - TagDecl, Owned)) > + if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, > + NameLoc.isValid() ? NameLoc : StartLoc, > + PrevSpec, DiagID, TagDecl, Owned)) > Diag(StartLoc, DiagID) << PrevSpec; > } > > > Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original) > +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Mar 16 15:16:18 2011 > @@ -1017,19 +1017,17 @@ > ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); > } > > - // FIXME: The DeclSpec should keep the locations of both the keyword and the > - // name (if there is one). > - SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc; > - > const char *PrevSpec = 0; > unsigned DiagID; > bool Result; > if (!TypeResult.isInvalid()) { > - Result = DS.SetTypeSpecType(DeclSpec::TST_typename, TSTLoc, > + Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, > + NameLoc.isValid() ? NameLoc : StartLoc, > PrevSpec, DiagID, TypeResult.get()); > } else if (!TagOrTempResult.isInvalid()) { > - Result = DS.SetTypeSpecType(TagType, TSTLoc, PrevSpec, DiagID, > - TagOrTempResult.get(), Owned); > + Result = DS.SetTypeSpecType(TagType, StartLoc, > + NameLoc.isValid() ? NameLoc : StartLoc, > + PrevSpec, DiagID, TagOrTempResult.get(), Owned); > } else { > DS.SetTypeSpecError(); > return; > > Modified: cfe/trunk/lib/Sema/DeclSpec.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/DeclSpec.cpp (original) > +++ cfe/trunk/lib/Sema/DeclSpec.cpp Wed Mar 16 15:16:18 2011 > @@ -421,6 +421,14 @@ > const char *&PrevSpec, > unsigned &DiagID, > ParsedType Rep) { > + return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep); > +} > + > +bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, > + SourceLocation TagNameLoc, > + const char *&PrevSpec, > + unsigned &DiagID, > + ParsedType Rep) { > assert(isTypeRep(T) && "T does not store a type"); > assert(Rep && "no type provided!"); > if (TypeSpecType != TST_unspecified) { > @@ -430,7 +438,8 @@ > } > TypeSpecType = T; > TypeRep = Rep; > - TSTLoc = Loc; > + TSTLoc = TagKwLoc; > + TSTNameLoc = TagNameLoc; > TypeSpecOwned = false; > return false; > } > @@ -449,6 +458,7 @@ > TypeSpecType = T; > ExprRep = Rep; > TSTLoc = Loc; > + TSTNameLoc = Loc; > TypeSpecOwned = false; > return false; > } > @@ -457,6 +467,14 @@ > const char *&PrevSpec, > unsigned &DiagID, > Decl *Rep, bool Owned) { > + return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned); > +} > + > +bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, > + SourceLocation TagNameLoc, > + const char *&PrevSpec, > + unsigned &DiagID, > + Decl *Rep, bool Owned) { > assert(isDeclRep(T) && "T does not store a decl"); > // Unlike the other cases, we don't assert that we actually get a decl. > > @@ -467,7 +485,8 @@ > } > TypeSpecType = T; > DeclRep = Rep; > - TSTLoc = Loc; > + TSTLoc = TagKwLoc; > + TSTNameLoc = TagNameLoc; > TypeSpecOwned = Owned; > return false; > } > @@ -482,13 +501,13 @@ > DiagID = diag::err_invalid_decl_spec_combination; > return true; > } > + TSTLoc = Loc; > + TSTNameLoc = Loc; > if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { > TypeAltiVecBool = true; > - TSTLoc = Loc; > return false; > } > TypeSpecType = T; > - TSTLoc = Loc; > TypeSpecOwned = false; > if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { > PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); > @@ -520,6 +539,7 @@ > } > TypeAltiVecPixel = isAltiVecPixel; > TSTLoc = Loc; > + TSTNameLoc = Loc; > return false; > } > > @@ -527,6 +547,7 @@ > TypeSpecType = TST_error; > TypeSpecOwned = false; > TSTLoc = SourceLocation(); > + TSTNameLoc = SourceLocation(); > return false; > } > > > Modified: cfe/trunk/lib/Sema/SemaType.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaType.cpp (original) > +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Mar 16 15:16:18 2011 > @@ -728,7 +728,7 @@ > } > > // If the type is deprecated or unavailable, diagnose it. > - S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc()); > + S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeNameLoc()); > > assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && > DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!"); > @@ -736,12 +736,11 @@ > // TypeQuals handled by caller. > Result = Context.getTypeDeclType(D); > > - // In C++, make an ElaboratedType. > - if (S.getLangOptions().CPlusPlus) { > - ElaboratedTypeKeyword Keyword > - = ElaboratedType::getKeywordForTypeSpec(DS.getTypeSpecType()); > - Result = S.getElaboratedType(Keyword, DS.getTypeSpecScope(), Result); > - } > + // In both C and C++, make an ElaboratedType. > + ElaboratedTypeKeyword Keyword > + = ElaboratedType::getKeywordForTypeSpec(DS.getTypeSpecType()); > + Result = S.getElaboratedType(Keyword, DS.getTypeSpecScope(), Result); > + > if (D->isInvalidDecl()) > declarator.setInvalidType(true); > break; > @@ -2300,7 +2299,7 @@ > // If we got no declarator info from previous Sema routines, > // just fill with the typespec loc. > if (!TInfo) { > - TL.initialize(Context, DS.getTypeSpecTypeLoc()); > + TL.initialize(Context, DS.getTypeSpecTypeNameLoc()); > return; > } > > @@ -2377,7 +2376,7 @@ > : SourceLocation()); > const CXXScopeSpec& SS = DS.getTypeSpecScope(); > TL.setQualifierLoc(SS.getWithLocInContext(Context)); > - TL.setNameLoc(DS.getTypeSpecTypeLoc()); > + TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); > } > void VisitDependentTemplateSpecializationTypeLoc( > DependentTemplateSpecializationTypeLoc TL) { > @@ -2398,7 +2397,10 @@ > : SourceLocation()); > const CXXScopeSpec& SS = DS.getTypeSpecScope(); > TL.setQualifierLoc(SS.getWithLocInContext(Context)); > - TL.setNameLoc(DS.getTypeSpecTypeLoc()); > + TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); > + } > + void VisitTagTypeLoc(TagTypeLoc TL) { > + TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); > } > > void VisitTypeLoc(TypeLoc TL) { > > Modified: cfe/trunk/test/Index/annotate-nested-name-specifier.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-nested-name-specifier.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/test/Index/annotate-nested-name-specifier.cpp (original) > +++ cfe/trunk/test/Index/annotate-nested-name-specifier.cpp Wed Mar 16 15:16:18 2011 > @@ -149,13 +149,13 @@ > > // Base specifiers > // CHECK: Identifier: "outer_alias" [16:19 - 16:30] NamespaceRef=outer_alias:10:11 > -// CHECK: Punctuation: "::" [16:30 - 16:32] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > +// CHECK: Punctuation: "::" [16:30 - 16:32] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > // CHECK: Identifier: "inner" [16:32 - 16:37] NamespaceRef=inner:2:13 > -// CHECK: Punctuation: "::" [16:37 - 16:39] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > +// CHECK: Punctuation: "::" [16:37 - 16:39] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > // CHECK: Identifier: "vector" [16:39 - 16:45] TemplateRef=vector:4:12 > -// CHECK: Punctuation: "<" [16:45 - 16:46] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > +// CHECK: Punctuation: "<" [16:45 - 16:46] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > // CHECK: Identifier: "X" [16:46 - 16:47] TypeRef=struct X:12:8 > -// CHECK: Punctuation: ">" [16:47 - 16:48] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > +// CHECK: Punctuation: ">" [16:47 - 16:48] C++ base class specifier=outer_alias::inner::vector:4:12 [access=public isVirtual=false] > > > // CHECK: Keyword: "using" [17:3 - 17:8] UsingDeclaration=iterator[5:18] > > Modified: cfe/trunk/test/Index/annotate-tokens.c > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.c?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/test/Index/annotate-tokens.c (original) > +++ cfe/trunk/test/Index/annotate-tokens.c Wed Mar 16 15:16:18 2011 > @@ -53,7 +53,7 @@ > // CHECK: Punctuation: ")" [5:17 - 5:18] UnexposedExpr= > // CHECK: Punctuation: ";" [5:18 - 5:19] UnexposedStmt= > // CHECK: Comment: "/* A comment */" [6:3 - 6:18] UnexposedStmt= > -// CHECK: Keyword: "struct" [7:3 - 7:9] UnexposedStmt= > +// CHECK: Keyword: "struct" [7:3 - 7:9] VarDecl=x:7:12 (Definition) > // CHECK: Identifier: "X" [7:10 - 7:11] TypeRef=struct X:2:8 > // CHECK: Identifier: "x" [7:12 - 7:13] VarDecl=x:7:12 (Definition) > // CHECK: Punctuation: "=" [7:14 - 7:15] VarDecl=x:7:12 (Definition) > @@ -91,7 +91,7 @@ > // CHECK: Identifier: "Int" [16:38 - 16:41] TypeRef=Int:12:13 > // CHECK: Punctuation: "," [16:41 - 16:42] UnexposedExpr= > // CHECK: Identifier: "Int" [16:43 - 16:46] TypeRef=Int:12:13 > -// CHECK: Keyword: "struct" [18:3 - 18:9] UnexposedStmt= > +// CHECK: Keyword: "struct" [18:3 - 18:9] VarDecl=x:18:12 (Definition) > // CHECK: Identifier: "X" [18:10 - 18:11] TypeRef=struct X:2:8 > // CHECK: Identifier: "x" [18:12 - 18:13] VarDecl=x:18:12 (Definition) > // CHECK: Keyword: "do" [19:3 - 19:5] UnexposedStmt= > @@ -107,7 +107,7 @@ > // CHECK: Punctuation: "." [21:13 - 21:14] MemberRefExpr=a:2:16 > // CHECK: Identifier: "a" [21:14 - 21:15] MemberRefExpr=a:2:16 > > -// CHECK: Keyword: "enum" [23:3 - 23:7] UnexposedStmt= > +// CHECK: Keyword: "enum" [23:3 - 23:7] VarDecl=c:23:14 (Definition) > // CHECK: Identifier: "Color" [23:8 - 23:13] TypeRef=enum Color:11:6 > // CHECK: Identifier: "c" [23:14 - 23:15] VarDecl=c:23:14 (Definition) > // CHECK: Punctuation: ";" [23:15 - 23:16] UnexposedStmt= > > Modified: cfe/trunk/test/Index/recursive-member-access.c > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/recursive-member-access.c?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/test/Index/recursive-member-access.c (original) > +++ cfe/trunk/test/Index/recursive-member-access.c Wed Mar 16 15:16:18 2011 > @@ -257,7 +257,7 @@ > // CHECK-tokens: Keyword: "struct" [1:1 - 1:7] StructDecl=rdar8650865:1:8 (Definition) > // CHECK-tokens: Identifier: "rdar8650865" [1:8 - 1:19] StructDecl=rdar8650865:1:8 (Definition) > // CHECK-tokens: Punctuation: "{" [1:20 - 1:21] StructDecl=rdar8650865:1:8 (Definition) > -// CHECK-tokens: Keyword: "struct" [2:3 - 2:9] StructDecl=rdar8650865:1:8 (Definition) > +// CHECK-tokens: Keyword: "struct" [2:3 - 2:9] FieldDecl=first:2:23 (Definition) > // CHECK-tokens: Identifier: "rdar8650865" [2:10 - 2:21] TypeRef=struct rdar8650865:1:8 > // CHECK-tokens: Punctuation: "*" [2:22 - 2:23] FieldDecl=first:2:23 (Definition) > // CHECK-tokens: Identifier: "first" [2:23 - 2:28] FieldDecl=first:2:23 (Definition) > @@ -270,7 +270,7 @@ > // CHECK-tokens: Keyword: "int" [6:1 - 6:4] FunctionDecl=test_rdar8650865:6:5 (Definition) > // CHECK-tokens: Identifier: "test_rdar8650865" [6:5 - 6:21] FunctionDecl=test_rdar8650865:6:5 (Definition) > // CHECK-tokens: Punctuation: "(" [6:21 - 6:22] FunctionDecl=test_rdar8650865:6:5 (Definition) > -// CHECK-tokens: Keyword: "struct" [6:22 - 6:28] FunctionDecl=test_rdar8650865:6:5 (Definition) > +// CHECK-tokens: Keyword: "struct" [6:22 - 6:28] ParmDecl=s:6:42 (Definition) > // CHECK-tokens: Identifier: "rdar8650865" [6:29 - 6:40] TypeRef=struct rdar8650865:1:8 > // CHECK-tokens: Punctuation: "*" [6:41 - 6:42] ParmDecl=s:6:42 (Definition) > // CHECK-tokens: Identifier: "s" [6:42 - 6:43] ParmDecl=s:6:42 (Definition) > > Modified: cfe/trunk/test/SemaCXX/sourceranges.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/sourceranges.cpp?rev=127755&r1=127754&r2=127755&view=diff > ============================================================================== > --- cfe/trunk/test/SemaCXX/sourceranges.cpp (original) > +++ cfe/trunk/test/SemaCXX/sourceranges.cpp Wed Mar 16 15:16:18 2011 > @@ -13,15 +13,15 @@ > } > > int main() { > - // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::class A *' > + // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::A *' > P p14 = new foo::A; > - // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::enum B *' > + // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::B *' > P p24 = new foo::B; > // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} 'foo::C *' > P pr4 = new foo::C; > } > > foo::A getName() { > - // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} 'foo::class A' > + // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} 'foo::A' > return foo::A(); > } > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From rjmccall at apple.com Wed Mar 16 16:40:22 2011 From: rjmccall at apple.com (John McCall) Date: Wed, 16 Mar 2011 14:40:22 -0700 Subject: [cfe-commits] r127702 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/member-function-pointers.cpp In-Reply-To: References: <20110315211748.779FE2A6C12C@llvm.org> Message-ID: On Mar 16, 2011, at 2:33 PM, Matt Beaumont-Gay wrote: > Hi John, > ' > On Tue, Mar 15, 2011 at 14:17, John McCall wrote: >> Author: rjmccall >> Date: Tue Mar 15 16:17:48 2011 >> New Revision: 127702 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127702&view=rev >> Log: >> Reorganize the emission of (unfoldable) constant casts a bit, and >> make sure that upcasts of member pointer types are covered as constants. >> Fixed rdar://problem/9130221 >> >> >> Modified: >> cfe/trunk/lib/CodeGen/CGExprConstant.cpp >> cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp >> >> Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127702&r1=127701&r2=127702&view=diff >> ============================================================================== >> --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) >> +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Mar 15 16:17:48 2011 >> @@ -483,18 +483,17 @@ >> } >> >> llvm::Constant *VisitCastExpr(CastExpr* E) { >> + Expr *subExpr = E->getSubExpr(); >> + llvm::Constant *C = CGM.EmitConstantExpr(subExpr, subExpr->getType(), CGF); >> + if (!C) return 0; >> + >> + const llvm::Type *destType = ConvertType(E->getType()); >> + >> switch (E->getCastKind()) { >> case CK_ToUnion: { >> // GCC cast to union extension >> assert(E->getType()->isUnionType() && >> "Destination type is not union type!"); >> - const llvm::Type *Ty = ConvertType(E->getType()); >> - Expr *SubExpr = E->getSubExpr(); >> - >> - llvm::Constant *C = >> - CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); >> - if (!C) >> - return 0; >> >> // Build a struct with the union sub-element as the first member, >> // and padded to the appropriate size >> @@ -503,7 +502,7 @@ >> Elts.push_back(C); >> Types.push_back(C->getType()); >> unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); >> - unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(Ty); >> + unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(destType); >> >> assert(CurSize <= TotalSize && "Union size mismatch!"); >> if (unsigned NumPadBytes = TotalSize - CurSize) { >> @@ -523,39 +522,101 @@ >> const MemberPointerType *MPT = E->getType()->getAs(); >> return CGM.getCXXABI().EmitNullMemberPointer(MPT); >> } >> - >> - case CK_BaseToDerivedMemberPointer: { >> - Expr *SubExpr = E->getSubExpr(); >> - llvm::Constant *C = >> - CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); >> - if (!C) return 0; >> >> + case CK_DerivedToBaseMemberPointer: >> + case CK_BaseToDerivedMemberPointer: >> return CGM.getCXXABI().EmitMemberPointerConversion(C, E); >> - } >> >> - case CK_BitCast: >> - // This must be a member function pointer cast. >> - return Visit(E->getSubExpr()); >> - >> - default: { >> - // FIXME: This should be handled by the CK_NoOp cast kind. >> - // Explicit and implicit no-op casts >> - QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); >> - if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) >> - return Visit(E->getSubExpr()); >> - >> - // Handle integer->integer casts for address-of-label differences. >> - if (Ty->isIntegerType() && SubTy->isIntegerType() && >> - CGF) { >> - llvm::Value *Src = Visit(E->getSubExpr()); >> - if (Src == 0) return 0; >> - >> - // Use EmitScalarConversion to perform the conversion. >> - return cast(CGF->EmitScalarConversion(Src, SubTy, Ty)); >> - } >> - >> + case CK_LValueToRValue: >> + case CK_NoOp: >> + return C; >> + >> + case CK_AnyPointerToObjCPointerCast: >> + case CK_AnyPointerToBlockPointerCast: >> + case CK_LValueBitCast: >> + case CK_BitCast: >> + if (C->getType() == destType) return C; >> + return llvm::ConstantExpr::getBitCast(C, destType); >> + >> + case CK_Dependent: llvm_unreachable("saw dependent cast!"); >> + >> + // These will never be supported. >> + case CK_ObjCObjectLValueCast: >> + case CK_GetObjCProperty: >> + case CK_ToVoid: >> + case CK_Dynamic: >> return 0; >> + >> + // These might need to be supported for constexpr. >> + case CK_UserDefinedConversion: >> + case CK_ConstructorConversion: >> + return 0; >> + >> + // These should eventually be supported. >> + case CK_ArrayToPointerDecay: >> + case CK_FunctionToPointerDecay: >> + case CK_BaseToDerived: >> + case CK_DerivedToBase: >> + case CK_UncheckedDerivedToBase: >> + case CK_MemberPointerToBoolean: >> + case CK_VectorSplat: >> + case CK_FloatingRealToComplex: >> + case CK_FloatingComplexToReal: >> + case CK_FloatingComplexToBoolean: >> + case CK_FloatingComplexCast: >> + case CK_FloatingComplexToIntegralComplex: >> + case CK_IntegralRealToComplex: >> + case CK_IntegralComplexToReal: >> + case CK_IntegralComplexToBoolean: >> + case CK_IntegralComplexCast: >> + case CK_IntegralComplexToFloatingComplex: >> + return 0; >> + >> + case CK_PointerToIntegral: >> + if (!E->getType()->isBooleanType()) >> + return llvm::ConstantExpr::getPtrToInt(C, destType); >> + // fallthrough >> + >> + case CK_PointerToBoolean: >> + return llvm::ConstantExpr::getICmp(llvm::CmpInst::ICMP_EQ, C, >> + llvm::ConstantPointerNull::get(cast(C->getType()))); >> + >> + case CK_NullToPointer: >> + return llvm::ConstantPointerNull::get(cast(destType)); >> + >> + case CK_IntegralCast: { >> + bool isSigned = subExpr->getType()->isSignedIntegerType(); >> + return llvm::ConstantExpr::getIntegerCast(C, destType, isSigned); >> + } >> + >> + case CK_IntegralToPointer: { >> + bool isSigned = subExpr->getType()->isSignedIntegerType(); >> + C = llvm::ConstantExpr::getIntegerCast(C, CGM.IntPtrTy, isSigned); >> + return llvm::ConstantExpr::getIntToPtr(C, destType); >> } >> + >> + case CK_IntegralToBoolean: >> + return llvm::ConstantExpr::getICmp(llvm::CmpInst::ICMP_EQ, C, >> + llvm::Constant::getNullValue(C->getType())); >> + >> + case CK_IntegralToFloating: >> + if (subExpr->getType()->isSignedIntegerType()) >> + return llvm::ConstantExpr::getSIToFP(C, destType); >> + else >> + return llvm::ConstantExpr::getUIToFP(C, destType); >> + >> + case CK_FloatingToIntegral: >> + if (E->getType()->isSignedIntegerType()) >> + return llvm::ConstantExpr::getFPToSI(C, destType); >> + else >> + return llvm::ConstantExpr::getFPToUI(C, destType); >> + >> + case CK_FloatingToBoolean: >> + return llvm::ConstantExpr::getFCmp(llvm::CmpInst::FCMP_UNE, C, >> + llvm::Constant::getNullValue(C->getType())); >> + >> + case CK_FloatingCast: >> + return llvm::ConstantExpr::getFPCast(C, destType); >> } >> } > > Here's the latest salvo in my continuing feud with GCC's -Wreturn-type: > tools/clang/lib/CodeGen/CGExprConstant.cpp: In member function > 'llvm::Constant*::ConstExprEmitter::VisitCastExpr(clang::CastExpr*)': > tools/clang/lib/CodeGen/CGExprConstant.cpp:621: error: control reaches > end of non-void function > > Is the new llvm_unreachable the right tool here? E.g.: Yes, that should work. The old llvm_unreachable would have worked fine, too. John. From eli.friedman at gmail.com Wed Mar 16 17:34:09 2011 From: eli.friedman at gmail.com (Eli Friedman) Date: Wed, 16 Mar 2011 22:34:09 -0000 Subject: [cfe-commits] r127768 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/references.cpp Message-ID: <20110316223409.515FB2A6C12C@llvm.org> Author: efriedma Date: Wed Mar 16 17:34:09 2011 New Revision: 127768 URL: http://llvm.org/viewvc/llvm-project?rev=127768&view=rev Log: PR9494: Get rid of bitcast which was both unnecessary and written incorrectly. Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/test/CodeGenCXX/references.cpp Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=127768&r1=127767&r2=127768&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Mar 16 17:34:09 2011 @@ -328,9 +328,8 @@ } } - - const llvm::Type *ResultPtrTy = CGF.ConvertType(ResultTy)->getPointerTo(); - return CGF.Builder.CreateBitCast(Object, ResultPtrTy, "temp"); + + return Object; } } Modified: cfe/trunk/test/CodeGenCXX/references.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=127768&r1=127767&r2=127768&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/references.cpp (original) +++ cfe/trunk/test/CodeGenCXX/references.cpp Wed Mar 16 17:34:09 2011 @@ -258,3 +258,14 @@ } } +// PR9494 +namespace N5 { +struct AnyS { bool b; }; +void f(const bool&); +AnyS g(); +void h() { + // CHECK: call i8 @_ZN2N51gEv() + // CHECK: call void @_ZN2N51fERKb(i8* + f(g().b); +} +} From joerg at bec.de Wed Mar 16 17:45:03 2011 From: joerg at bec.de (Joerg Sonnenberger) Date: Wed, 16 Mar 2011 22:45:03 -0000 Subject: [cfe-commits] r127769 - /cfe/trunk/lib/Driver/Driver.cpp Message-ID: <20110316224503.264C42A6C12C@llvm.org> Author: joerg Date: Wed Mar 16 17:45:02 2011 New Revision: 127769 URL: http://llvm.org/viewvc/llvm-project?rev=127769&view=rev Log: Use C as fallback type if in C preprocessor mode. Modified: cfe/trunk/lib/Driver/Driver.cpp Modified: cfe/trunk/lib/Driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=127769&r1=127768&r2=127769&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Driver.cpp (original) +++ cfe/trunk/lib/Driver/Driver.cpp Wed Mar 16 17:45:02 2011 @@ -725,14 +725,19 @@ Diag(clang::diag::err_drv_unknown_stdin_type); Ty = types::TY_C; } else { - // Otherwise lookup by extension, and fallback to ObjectType if not - // found. We use a host hook here because Darwin at least has its own + // Otherwise lookup by extension. + // Fallback is C if invoked as C preprocessor or Object otherwise. + // We use a host hook here because Darwin at least has its own // idea of what .s is. if (const char *Ext = strrchr(Value, '.')) Ty = TC.LookupTypeForExtension(Ext + 1); - if (Ty == types::TY_INVALID) - Ty = types::TY_Object; + if (Ty == types::TY_INVALID) { + if (CCCIsCPP) + Ty = types::TY_C; + else + Ty = types::TY_Object; + } // If the driver is invoked as C++ compiler (like clang++ or c++) it // should autodetect some input files as C++ for g++ compatibility. From dgregor at apple.com Wed Mar 16 18:23:30 2011 From: dgregor at apple.com (Douglas Gregor) Date: Wed, 16 Mar 2011 23:23:30 -0000 Subject: [cfe-commits] r127776 - in /cfe/trunk: test/Index/load-exprs.c tools/libclang/CIndex.cpp Message-ID: <20110316232331.041AB2A6C12C@llvm.org> Author: dgregor Date: Wed Mar 16 18:23:30 2011 New Revision: 127776 URL: http://llvm.org/viewvc/llvm-project?rev=127776&view=rev Log: When libclang visits a translation unit via clang_visitChildren(), walk the preprocessing record *before* walking the declarations, so they we pretend that we actually respect the phases of translation. We still walk the preprocessing record after the declarations when performing token annotation or finding the cursor at a location, since those routines depend on those semantics. Fixes . Modified: cfe/trunk/test/Index/load-exprs.c cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/test/Index/load-exprs.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-exprs.c?rev=127776&r1=127775&r2=127776&view=diff ============================================================================== --- cfe/trunk/test/Index/load-exprs.c (original) +++ cfe/trunk/test/Index/load-exprs.c Wed Mar 16 18:23:30 2011 @@ -32,7 +32,7 @@ } // RUN: c-index-test -test-load-source all %s -fblocks | FileCheck %s - +// CHECK: macro definition=__clang__ // CHECK: load-exprs.c:1:13: TypedefDecl=T:1:13 (Definition) Extent=[1:1 - 1:14] // CHECK: load-exprs.c:2:8: StructDecl=X:2:8 (Definition) Extent=[2:1 - 2:23] // CHECK: load-exprs.c:2:16: FieldDecl=a:2:16 (Definition) Extent=[2:12 - 2:17] Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127776&r1=127775&r2=127776&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Wed Mar 16 18:23:30 2011 @@ -188,6 +188,10 @@ // be suppressed. unsigned MaxPCHLevel; + /// \brief Whether we should visit the preprocessing record entries last, + /// after visiting other declarations. + bool VisitPreprocessorLast; + /// \brief When valid, a source range to which the cursor should restrict /// its search. SourceRange RegionOfInterest; @@ -235,11 +239,12 @@ CursorVisitor(CXTranslationUnit TU, CXCursorVisitor Visitor, CXClientData ClientData, unsigned MaxPCHLevel, + bool VisitPreprocessorLast, SourceRange RegionOfInterest = SourceRange()) : TU(TU), AU(static_cast(TU->TUData)), Visitor(Visitor), ClientData(ClientData), - MaxPCHLevel(MaxPCHLevel), RegionOfInterest(RegionOfInterest), - DI_current(0) + MaxPCHLevel(MaxPCHLevel), VisitPreprocessorLast(VisitPreprocessorLast), + RegionOfInterest(RegionOfInterest), DI_current(0) { Parent.kind = CXCursor_NoDeclFound; Parent.data[0] = 0; @@ -501,46 +506,54 @@ if (clang_isTranslationUnit(Cursor.kind)) { CXTranslationUnit tu = getCursorTU(Cursor); ASTUnit *CXXUnit = static_cast(tu->TUData); - if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() && - RegionOfInterest.isInvalid()) { - for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(), - TLEnd = CXXUnit->top_level_end(); - TL != TLEnd; ++TL) { - if (Visit(MakeCXCursor(*TL, tu), true)) + + int VisitOrder[2] = { VisitPreprocessorLast, !VisitPreprocessorLast }; + for (unsigned I = 0; I != 2; ++I) { + if (VisitOrder[I]) { + if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() && + RegionOfInterest.isInvalid()) { + for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(), + TLEnd = CXXUnit->top_level_end(); + TL != TLEnd; ++TL) { + if (Visit(MakeCXCursor(*TL, tu), true)) + return true; + } + } else if (VisitDeclContext( + CXXUnit->getASTContext().getTranslationUnitDecl())) return true; + continue; } - } else if (VisitDeclContext( - CXXUnit->getASTContext().getTranslationUnitDecl())) - return true; - // Walk the preprocessing record. - if (CXXUnit->getPreprocessor().getPreprocessingRecord()) { - // FIXME: Once we have the ability to deserialize a preprocessing record, - // do so. - PreprocessingRecord::iterator E, EEnd; - for (llvm::tie(E, EEnd) = getPreprocessedEntities(); E != EEnd; ++E) { - if (MacroInstantiation *MI = dyn_cast(*E)) { - if (Visit(MakeMacroInstantiationCursor(MI, tu))) - return true; - - continue; - } - - if (MacroDefinition *MD = dyn_cast(*E)) { - if (Visit(MakeMacroDefinitionCursor(MD, tu))) - return true; + // Walk the preprocessing record. + if (CXXUnit->getPreprocessor().getPreprocessingRecord()) { + // FIXME: Once we have the ability to deserialize a preprocessing record, + // do so. + PreprocessingRecord::iterator E, EEnd; + for (llvm::tie(E, EEnd) = getPreprocessedEntities(); E != EEnd; ++E) { + if (MacroInstantiation *MI = dyn_cast(*E)) { + if (Visit(MakeMacroInstantiationCursor(MI, tu))) + return true; + + continue; + } - continue; - } - - if (InclusionDirective *ID = dyn_cast(*E)) { - if (Visit(MakeInclusionDirectiveCursor(ID, tu))) - return true; + if (MacroDefinition *MD = dyn_cast(*E)) { + if (Visit(MakeMacroDefinitionCursor(MD, tu))) + return true; + + continue; + } - continue; + if (InclusionDirective *ID = dyn_cast(*E)) { + if (Visit(MakeInclusionDirectiveCursor(ID, tu))) + return true; + + continue; + } } } } + return false; } @@ -2860,7 +2873,8 @@ CXCursorVisitor visitor, CXClientData client_data) { CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data, - getCursorASTUnit(parent)->getMaxPCHLevel()); + getCursorASTUnit(parent)->getMaxPCHLevel(), + false); return CursorVis.VisitChildren(parent); } @@ -3316,7 +3330,7 @@ // the region of interest, rather than starting from the translation unit. CXCursor Parent = clang_getTranslationUnitCursor(TU); CursorVisitor CursorVis(TU, GetCursorVisitor, &Result, - Decl::MaxPCHLevel, SourceLocation(SLoc)); + Decl::MaxPCHLevel, true, SourceLocation(SLoc)); CursorVis.VisitChildren(Parent); } @@ -4283,7 +4297,7 @@ NumTokens(numTokens), TokIdx(0), PreprocessingTokIdx(0), AnnotateVis(tu, AnnotateTokensVisitor, this, - Decl::MaxPCHLevel, RegionOfInterest), + Decl::MaxPCHLevel, true, RegionOfInterest), SrcMgr(static_cast(tu->TUData)->getSourceManager()), HasContextSensitiveKeywords(false) { } From abramo.bagnara at gmail.com Wed Mar 16 18:31:30 2011 From: abramo.bagnara at gmail.com (Abramo Bagnara) Date: Thu, 17 Mar 2011 00:31:30 +0100 Subject: [cfe-commits] r127755 - in /cfe/trunk: include/clang/AST/PrettyPrinter.h include/clang/Sema/DeclSpec.h lib/AST/TypePrinter.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaType.cpp test/Index/annotate-nested-name-specifier.cpp test/Index/annotate-tokens.c test/Index/recursive-member-access.c test/SemaCXX/sourceranges.cpp In-Reply-To: <749E9717-1DE9-47A3-8D47-33DB895B4EA1@apple.com> References: <20110316201618.B05492A6C12C@llvm.org> <749E9717-1DE9-47A3-8D47-33DB895B4EA1@apple.com> Message-ID: <4D814852.7030207@gmail.com> Il 16/03/2011 22:37, Douglas Gregor ha scritto: > > On Mar 16, 2011, at 1:16 PM, Abramo Bagnara wrote: > >> Author: abramo >> Date: Wed Mar 16 15:16:18 2011 >> New Revision: 127755 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=127755&view=rev >> Log: >> Use ElaboratedType also for C. > > Did you measure the impact of this change on memory usage? I've tried with some big monolithical sources with clang -cc1 -w -fsyntax-only and the maximum resident set size increases on average of 0.4% with a maximum of 0.8% for monolithical gcc.c From daniel at zuster.org Wed Mar 16 19:07:34 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Thu, 17 Mar 2011 00:07:34 -0000 Subject: [cfe-commits] r127777 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/clang-translation.c Message-ID: <20110317000734.E96AA2A6C12C@llvm.org> Author: ddunbar Date: Wed Mar 16 19:07:34 2011 New Revision: 127777 URL: http://llvm.org/viewvc/llvm-project?rev=127777&view=rev Log: Driver/ARM: Match GCC behavior in that -msoft-float disables NEON, despite this not being consistent at all with other parts of the GCC implementation. Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/clang-translation.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127777&r1=127776&r2=127777&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Wed Mar 16 19:07:34 2011 @@ -583,6 +583,13 @@ } else D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); } + + // Setting -msoft-float effectively disables NEON because of the GCC + // implementation, although the same isn't true of VFP or VFP3. + if (FloatABI == "soft") { + CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-neon"); + } } void Clang::AddMIPSTargetArgs(const ArgList &Args, Modified: cfe/trunk/test/Driver/clang-translation.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-translation.c?rev=127777&r1=127776&r2=127777&view=diff ============================================================================== --- cfe/trunk/test/Driver/clang-translation.c (original) +++ cfe/trunk/test/Driver/clang-translation.c Wed Mar 16 19:07:34 2011 @@ -31,6 +31,8 @@ // ARMV7_SOFTFLOAT: "-cc1" // ARMV7_SOFTFLOAT: "-msoft-float" // ARMV7_SOFTFLOAT: "-mfloat-abi" "soft" +// ARMV7_SOFTFLOAT: "-target-feature" +// ARMV7_SOFTFLOAT: "-neon" // ARMV7_SOFTFLOAT: "-x" "c" // RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -### -S %s 2> %t.log \ From matthewbg at google.com Wed Mar 16 19:46:34 2011 From: matthewbg at google.com (Matt Beaumont-Gay) Date: Thu, 17 Mar 2011 00:46:34 -0000 Subject: [cfe-commits] r127783 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110317004634.2F5912A6C12C@llvm.org> Author: matthewbg Date: Wed Mar 16 19:46:34 2011 New Revision: 127783 URL: http://llvm.org/viewvc/llvm-project?rev=127783&view=rev Log: Politely inform GCC that we will never fall off the end of that switch. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127783&r1=127782&r2=127783&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed Mar 16 19:46:34 2011 @@ -618,6 +618,7 @@ case CK_FloatingCast: return llvm::ConstantExpr::getFPCast(C, destType); } + llvm_unreachable("Invalid CastKind"); } llvm::Constant *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { From aikavanak at gmail.com Wed Mar 16 20:37:09 2011 From: aikavanak at gmail.com (Ryan Gerleve) Date: Wed, 16 Mar 2011 20:37:09 -0500 Subject: [cfe-commits] [PATCH] Re-enabled and fixed fixit for main returning non-int In-Reply-To: References: Message-ID: I'll provide an updated patch soon, but one picky question about this issue first: how should a 'signed' specifier be handled? Currently, clang accepts these: signed main() {} signed int main() {} I assume these are correct, because they are equivalent to 'int', but I don't think the (C++) standard is specific about this. But what if the program looked like this, for example: signed long main() {} Here, there are multiple fixits that could result in a correct program. 1. Remove 'long', 2. Replace 'long' with 'int', or 3. Replace 'signed long' with 'int'. My instinct is that 3 is best, mainly because the error text currently states that 'main' must return 'int', and it seems awkward to have a fixit suggest text that differs from the error itself (which both 1 and 2 would do). But I can also see value in a fixit that makes minimal changes to the source. In that case, 2 seems best. The fixit would result in 'signed int' while the error would say 'int', so perhaps it's worth changing the error text to something like "'main' must return 'int' or equivalent". Since I'm still new at this, how are multiple potential fixits generally handled? From kd at kendyck.com Wed Mar 16 20:33:19 2011 From: kd at kendyck.com (Ken Dyck) Date: Thu, 17 Mar 2011 01:33:19 -0000 Subject: [cfe-commits] r127787 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110317013319.175072A6C12C@llvm.org> Author: kjdyck Date: Wed Mar 16 20:33:18 2011 New Revision: 127787 URL: http://llvm.org/viewvc/llvm-project?rev=127787&view=rev Log: Convert NextOffsetInBytes to CharUnits and rename to NextOffsetInChars. No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127787&r1=127786&r2=127787&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed Mar 16 20:33:18 2011 @@ -38,7 +38,7 @@ CodeGenFunction *CGF; bool Packed; - unsigned NextFieldOffsetInBytes; + CharUnits NextFieldOffsetInChars; unsigned LLVMStructAlignment; std::vector Elements; public: @@ -47,7 +47,8 @@ private: ConstStructBuilder(CodeGenModule &CGM, CodeGenFunction *CGF) - : CGM(CGM), CGF(CGF), Packed(false), NextFieldOffsetInBytes(0), + : CGM(CGM), CGF(CGF), Packed(false), + NextFieldOffsetInChars(CharUnits::Zero()), LLVMStructAlignment(1) { } bool AppendField(const FieldDecl *Field, uint64_t FieldOffset, @@ -81,41 +82,41 @@ const ASTContext &Context = CGM.getContext(); CharUnits FieldOffsetInChars = Context.toCharUnitsFromBits(FieldOffset); - uint64_t FieldOffsetInBytes = FieldOffsetInChars.getQuantity(); - assert(NextFieldOffsetInBytes <= FieldOffsetInBytes + assert(NextFieldOffsetInChars <= FieldOffsetInChars && "Field offset mismatch!"); unsigned FieldAlignment = getAlignment(InitCst); // Round up the field offset to the alignment of the field type. - uint64_t AlignedNextFieldOffsetInBytes = - llvm::RoundUpToAlignment(NextFieldOffsetInBytes, FieldAlignment); + CharUnits AlignedNextFieldOffsetInChars = + NextFieldOffsetInChars.RoundUpToAlignment( + CharUnits::fromQuantity(FieldAlignment)); - if (AlignedNextFieldOffsetInBytes > FieldOffsetInBytes) { + if (AlignedNextFieldOffsetInChars > FieldOffsetInChars) { assert(!Packed && "Alignment is wrong even with a packed struct!"); // Convert the struct to a packed struct. ConvertStructToPacked(); - AlignedNextFieldOffsetInBytes = NextFieldOffsetInBytes; + AlignedNextFieldOffsetInChars = NextFieldOffsetInChars; } - if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) { + if (AlignedNextFieldOffsetInChars < FieldOffsetInChars) { // We need to append padding. AppendPadding( - FieldOffsetInChars - CharUnits::fromQuantity(NextFieldOffsetInBytes)); + FieldOffsetInChars - NextFieldOffsetInChars); - assert(NextFieldOffsetInBytes == FieldOffsetInChars.getQuantity() && + assert(NextFieldOffsetInChars == FieldOffsetInChars && "Did not add enough padding!"); - AlignedNextFieldOffsetInBytes = NextFieldOffsetInBytes; + AlignedNextFieldOffsetInChars = NextFieldOffsetInChars; } // Add the field. Elements.push_back(InitCst); - NextFieldOffsetInBytes = AlignedNextFieldOffsetInBytes + - getSizeInBytes(InitCst); + NextFieldOffsetInChars = AlignedNextFieldOffsetInChars + + CharUnits::fromQuantity(getSizeInBytes(InitCst)); if (Packed) assert(LLVMStructAlignment == 1 && "Packed struct not byte-aligned!"); @@ -129,10 +130,11 @@ uint64_t FieldOffset, llvm::ConstantInt *CI) { const ASTContext &Context = CGM.getContext(); - if (FieldOffset > NextFieldOffsetInBytes * 8) { + uint64_t NextFieldOffsetInBits = Context.toBits(NextFieldOffsetInChars); + if (FieldOffset > NextFieldOffsetInBits) { // We need to add padding. CharUnits PadSize = Context.toCharUnitsFromBits( - llvm::RoundUpToAlignment(FieldOffset - NextFieldOffsetInBytes * 8, + llvm::RoundUpToAlignment(FieldOffset - NextFieldOffsetInBits, Context.Target.getCharAlign())); AppendPadding(PadSize); @@ -154,13 +156,13 @@ if (FieldSize < FieldValue.getBitWidth()) FieldValue = FieldValue.trunc(FieldSize); - if (FieldOffset < NextFieldOffsetInBytes * 8) { + NextFieldOffsetInBits = Context.toBits(NextFieldOffsetInChars); + if (FieldOffset < NextFieldOffsetInBits) { // Either part of the field or the entire field can go into the previous // byte. assert(!Elements.empty() && "Elements can't be empty!"); - unsigned BitsInPreviousByte = - NextFieldOffsetInBytes * 8 - FieldOffset; + unsigned BitsInPreviousByte = NextFieldOffsetInBits - FieldOffset; bool FitsCompletelyInPreviousByte = BitsInPreviousByte >= FieldValue.getBitWidth(); @@ -214,7 +216,7 @@ "Expected non-empty array padding of undefs"); // Remove the padding array. - NextFieldOffsetInBytes -= AT->getNumElements(); + NextFieldOffsetInChars -= CharUnits::fromQuantity(AT->getNumElements()); Elements.pop_back(); // Add the padding back in two chunks. @@ -246,7 +248,7 @@ } Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp)); - NextFieldOffsetInBytes++; + NextFieldOffsetInChars += CharUnits::One(); FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - 8); } @@ -268,7 +270,7 @@ // Append the last element. Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), FieldValue)); - NextFieldOffsetInBytes++; + NextFieldOffsetInChars += CharUnits::One(); } void ConstStructBuilder::AppendPadding(CharUnits PadSize) { @@ -283,14 +285,14 @@ Elements.push_back(C); assert(getAlignment(C) == 1 && "Padding must have 1 byte alignment!"); - NextFieldOffsetInBytes += getSizeInBytes(C); + NextFieldOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(C)); } void ConstStructBuilder::AppendTailPadding(CharUnits RecordSize) { - assert(NextFieldOffsetInBytes <= RecordSize.getQuantity() && + assert(NextFieldOffsetInChars <= RecordSize && "Size mismatch!"); - AppendPadding(RecordSize - CharUnits::fromQuantity(NextFieldOffsetInBytes)); + AppendPadding(RecordSize - NextFieldOffsetInChars); } void ConstStructBuilder::ConvertStructToPacked() { @@ -323,7 +325,8 @@ ElementOffsetInBytes += getSizeInBytes(C); } - assert(ElementOffsetInBytes == NextFieldOffsetInBytes && + assert(CharUnits::fromQuantity(ElementOffsetInBytes) == + NextFieldOffsetInChars && "Packing the struct changed its size!"); Elements = PackedElements; @@ -371,9 +374,9 @@ } } - uint64_t LayoutSizeInBytes = Layout.getSize().getQuantity(); + CharUnits LayoutSizeInChars = Layout.getSize(); - if (NextFieldOffsetInBytes > LayoutSizeInBytes) { + if (NextFieldOffsetInChars > LayoutSizeInChars) { // If the struct is bigger than the size of the record type, // we must have a flexible array member at the end. assert(RD->hasFlexibleArrayMember() && @@ -383,23 +386,24 @@ return true; } - uint64_t LLVMSizeInBytes = llvm::RoundUpToAlignment(NextFieldOffsetInBytes, - LLVMStructAlignment); + CharUnits LLVMSizeInChars = + NextFieldOffsetInChars.RoundUpToAlignment( + CharUnits::fromQuantity(LLVMStructAlignment)); // Check if we need to convert the struct to a packed struct. - if (NextFieldOffsetInBytes <= LayoutSizeInBytes && - LLVMSizeInBytes > LayoutSizeInBytes) { + if (NextFieldOffsetInChars <= LayoutSizeInChars && + LLVMSizeInChars > LayoutSizeInChars) { assert(!Packed && "Size mismatch!"); ConvertStructToPacked(); - assert(NextFieldOffsetInBytes <= LayoutSizeInBytes && + assert(NextFieldOffsetInChars <= LayoutSizeInChars && "Converting to packed did not help!"); } // Append tail padding if necessary. - AppendTailPadding(Layout.getSize()); + AppendTailPadding(LayoutSizeInChars); - assert(Layout.getSize().getQuantity() == NextFieldOffsetInBytes && + assert(LayoutSizeInChars == NextFieldOffsetInChars && "Tail padding mismatch!"); return true; @@ -416,7 +420,7 @@ llvm::ConstantStruct::get(CGM.getLLVMContext(), Builder.Elements, Builder.Packed); - assert(llvm::RoundUpToAlignment(Builder.NextFieldOffsetInBytes, + assert(llvm::RoundUpToAlignment(Builder.NextFieldOffsetInChars.getQuantity(), Builder.getAlignment(Result)) == Builder.getSizeInBytes(Result) && "Size mismatch!"); From joerg at britannica.bec.de Wed Mar 16 20:42:56 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Thu, 17 Mar 2011 02:42:56 +0100 Subject: [cfe-commits] [PATCH] Re-enabled and fixed fixit for main returning non-int In-Reply-To: References: Message-ID: <20110317014256.GA16535@britannica.bec.de> On Wed, Mar 16, 2011 at 08:37:09PM -0500, Ryan Gerleve wrote: > signed long main() {} > > Here, there are multiple fixits that could result in a correct program. > 1. Remove 'long', > 2. Replace 'long' with 'int', or > 3. Replace 'signed long' with 'int'. Go with (3). IMO there is exactly one situation when signed has actual semantic value and that's in combination with char. Otherwise it is just syntactic sugar. Joerg From rtrieu at google.com Wed Mar 16 20:58:21 2011 From: rtrieu at google.com (Richard Trieu) Date: Wed, 16 Mar 2011 18:58:21 -0700 Subject: [cfe-commits] Patch: Add flags to print or omit the include stacks of notes. Message-ID: This patch adds flags to print or omit the include stacks of notes. These stacks are less helpful in notes than those in errors and warnings. Below is the current output on an error, and how it will show up when the include stack is disabled. Current behavior: test/test.cpp:9:10: error: no matching function for call to 'foo' return foo(1, 1); ^~~ In file included from test/test.cpp:7: In file included from test/include7.h:1: In file included from test/include6.h:1: In file included from test/include5.h:1: In file included from test/include4.h:1: In file included from test/include3.h:1: In file included from test/include2.h:1: include1.h:1:5: note: candidate function not viable: requires 1 argument, but 2 were provided int foo(int x) { return x; } With new flag to omit note include stacks: test/test.cpp:9:10: error: no matching function for call to 'foo' return foo(1, 1); ^~~ include1.h:1:5: note: candidate function not viable: requires 1 argument, but 2 were provided int foo(int x) { return x; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110316/77785549/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: include_stack_suppression.patch Type: text/x-patch Size: 11570 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110316/77785549/attachment-0001.bin From aikavanak at gmail.com Wed Mar 16 21:39:31 2011 From: aikavanak at gmail.com (Ryan Gerleve) Date: Wed, 16 Mar 2011 21:39:31 -0500 Subject: [cfe-commits] [PATCH] Re-enabled and fixed fixit for main returning non-int In-Reply-To: <20110317014256.GA16535@britannica.bec.de> References: <20110317014256.GA16535@britannica.bec.de> Message-ID: On Wed, Mar 16, 2011 at 8:42 PM, Joerg Sonnenberger wrote: > On Wed, Mar 16, 2011 at 08:37:09PM -0500, Ryan Gerleve wrote: >> signed long main() {} >> >> Here, there are multiple fixits that could result in a correct program. >> 1. Remove 'long', >> 2. Replace 'long' with 'int', or >> 3. Replace 'signed long' with 'int'. > > Go with (3). IMO there is exactly one situation when signed has actual > semantic value and that's in combination with char. Otherwise it is just > syntactic sugar. > > Joerg Sounds good to me. But thinking about Johannes' question - does 'extern' have semantic value when applied to main? The C++ standard says main's linkage is implementation-defined, and I don't see how an extern main would be different from a non-extern main. (Please correct me if I'm wrong). If it doesn't have semantic value when applied to main, would it be best to be consistent in the fix-it and have it remove everything (or nothing) that's just semantic sugar? From joerg at britannica.bec.de Wed Mar 16 21:45:45 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Thu, 17 Mar 2011 03:45:45 +0100 Subject: [cfe-commits] [PATCH] Re-enabled and fixed fixit for main returning non-int In-Reply-To: References: <20110317014256.GA16535@britannica.bec.de> Message-ID: <20110317024545.GA18388@britannica.bec.de> On Wed, Mar 16, 2011 at 09:39:31PM -0500, Ryan Gerleve wrote: > Sounds good to me. But thinking about Johannes' question - does > 'extern' have semantic value when applied to main? The C++ standard > says main's linkage is implementation-defined, and I don't see how an > extern main would be different from a non-extern main. (Please correct > me if I'm wrong). If it doesn't have semantic value when applied to > main, would it be best to be consistent in the fix-it and have it > remove everything (or nothing) that's just semantic sugar? Hm. Good question. It's too late to go into language lawyer mode to decide whether extern on a function body has a semantic value. I leave that to someone else to decide. If the answer is yes, reorder would be nice though ("extern int main(){}", not "int extern main(){}"). Joerg From aikavanak at gmail.com Wed Mar 16 22:01:06 2011 From: aikavanak at gmail.com (Ryan Gerleve) Date: Wed, 16 Mar 2011 22:01:06 -0500 Subject: [cfe-commits] [PATCH] Re-enabled and fixed fixit for main returning non-int In-Reply-To: <20110317024545.GA18388@britannica.bec.de> References: <20110317014256.GA16535@britannica.bec.de> <20110317024545.GA18388@britannica.bec.de> Message-ID: On Wed, Mar 16, 2011 at 9:45 PM, Joerg Sonnenberger wrote: > On Wed, Mar 16, 2011 at 09:39:31PM -0500, Ryan Gerleve wrote: >> Sounds good to me. But thinking about Johannes' question - does >> 'extern' have semantic value when applied to main? The C++ standard >> says main's linkage is implementation-defined, and I don't see how an >> extern main would be different from a non-extern main. (Please correct >> me if I'm wrong). If it doesn't have semantic value when applied to >> main, would it be best to be consistent in the fix-it and have it >> remove everything (or nothing) that's just semantic sugar? > > Hm. Good question. It's too late to go into language lawyer mode to > decide whether extern on a function body has a semantic value. I leave > that to someone else to decide. If the answer is yes, reorder would be > nice though ("extern int main(){}", not "int extern main(){}"). > > Joerg Alright, that's fair. But while I prefer "extern int" over "int extern" also, should a fixit really be suggesting a coding style to the user, as opposed to trying to match what he or she already typed? From kremenek at apple.com Wed Mar 16 22:06:07 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 03:06:07 -0000 Subject: [cfe-commits] r127793 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td test/Sema/uninit-variables.c Message-ID: <20110317030607.CEC792A6C12C@llvm.org> Author: kremenek Date: Wed Mar 16 22:06:07 2011 New Revision: 127793 URL: http://llvm.org/viewvc/llvm-project?rev=127793&view=rev Log: Rename -Wuninitialized-maybe to -Wconditional-uninitialized. Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/test/Sema/uninit-variables.c Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=127793&r1=127792&r2=127793&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Mar 16 22:06:07 2011 @@ -137,7 +137,7 @@ def : DiagGroup<"type-limits">; def Uninitialized : DiagGroup<"uninitialized">; -def UninitializedMaybe : DiagGroup<"uninitialized-maybe">; +def UninitializedMaybe : DiagGroup<"conditional-uninitialized">; def UnknownPragmas : DiagGroup<"unknown-pragmas">; def UnknownAttributes : DiagGroup<"unknown-attributes">; def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args">; Modified: cfe/trunk/test/Sema/uninit-variables.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=127793&r1=127792&r2=127793&view=diff ============================================================================== --- cfe/trunk/test/Sema/uninit-variables.c (original) +++ cfe/trunk/test/Sema/uninit-variables.c Wed Mar 16 22:06:07 2011 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wuninitialized-maybe -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify int test1() { int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} From kremenek at apple.com Wed Mar 16 22:06:11 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 03:06:11 -0000 Subject: [cfe-commits] r127794 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp test/Sema/uninit-variables-vectors.c Message-ID: <20110317030611.6C0DC2A6C12D@llvm.org> Author: kremenek Date: Wed Mar 16 22:06:11 2011 New Revision: 127794 URL: http://llvm.org/viewvc/llvm-project?rev=127794&view=rev Log: Extend -Wuninitialized to support vector types. Added: cfe/trunk/test/Sema/uninit-variables-vectors.c Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=127794&r1=127793&r2=127794&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original) +++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Wed Mar 16 22:06:11 2011 @@ -26,9 +26,12 @@ using namespace clang; static bool isTrackedVar(const VarDecl *vd, const DeclContext *dc) { - return vd->isLocalVarDecl() && !vd->hasGlobalStorage() && - vd->getType()->isScalarType() && - vd->getDeclContext() == dc; + if (vd->isLocalVarDecl() && !vd->hasGlobalStorage() && + vd->getDeclContext() == dc) { + QualType ty = vd->getType(); + return ty->isScalarType() || ty->isVectorType(); + } + return false; } //------------------------------------------------------------------------====// Added: cfe/trunk/test/Sema/uninit-variables-vectors.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables-vectors.c?rev=127794&view=auto ============================================================================== --- cfe/trunk/test/Sema/uninit-variables-vectors.c (added) +++ cfe/trunk/test/Sema/uninit-variables-vectors.c Wed Mar 16 22:06:11 2011 @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify + +#include + +void test1(float *input) { + __m128 x, y, z, w, X; // expected-note {{variable 'x' is declared here}} expected-note {{variable 'y' is declared here}} expected-note {{variable 'w' is declared here}} expected-note {{variable 'z' is declared here}} + x = _mm_xor_ps(x,x); // expected-warning {{variable 'x' is possibly uninitialized when used here}} + y = _mm_xor_ps(y,y); // expected-warning {{variable 'y' is possibly uninitialized when used here}} + z = _mm_xor_ps(z,z); // expected-warning {{variable 'z' is possibly uninitialized when used here}} + w = _mm_xor_ps(w,w); // expected-warning {{variable 'w' is possibly uninitialized when used here}} + X = _mm_loadu_ps(&input[0]); + X = _mm_xor_ps(X,X); // no-warning +} + From kremenek at apple.com Wed Mar 16 22:51:51 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 03:51:51 -0000 Subject: [cfe-commits] r127796 - in /cfe/trunk: lib/StaticAnalyzer/Core/RegionStore.cpp test/Analysis/misc-ps-region-store.m Message-ID: <20110317035151.EAD2B2A6C12C@llvm.org> Author: kremenek Date: Wed Mar 16 22:51:51 2011 New Revision: 127796 URL: http://llvm.org/viewvc/llvm-project?rev=127796&view=rev Log: Tweak RegionStore's handling of lazy compound values to use the 'Default' versus 'Direct' binding key, thus allowing specific elements of an array/struct to be overwritten without invalidating the entire binding. Fixes PR 9455. Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp cfe/trunk/test/Analysis/misc-ps-region-store.m Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=127796&r1=127795&r2=127796&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed Mar 16 22:51:51 2011 @@ -337,6 +337,9 @@ SVal RetrieveFieldOrElementCommon(Store store, const TypedRegion *R, QualType Ty, const MemRegion *superR); + + SVal RetrieveLazyBinding(const MemRegion *lazyBindingRegion, + Store lazyBindingStore); /// Retrieve the values in a struct and return a CompoundVal, used when doing /// struct copy: @@ -977,11 +980,6 @@ std::pair RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { - if (Optional OV = getDirectBinding(B, R)) - if (const nonloc::LazyCompoundVal *V = - dyn_cast(OV.getPointer())) - return std::make_pair(V->getStore(), V->getRegion()); - if (const ElementRegion *ER = dyn_cast(R)) { const std::pair &X = GetLazyBinding(B, ER->getSuperRegion()); @@ -1009,6 +1007,12 @@ return std::make_pair(X.first, MRMgr.getCXXBaseObjectRegionWithSuper(baseReg, X.second)); } + else if (Optional OV = getDefaultBinding(B, R)) { + if (const nonloc::LazyCompoundVal *V = + dyn_cast(OV.getPointer())) + return std::make_pair(V->getStore(), V->getRegion()); + } + // The NULL MemRegion indicates an non-existent lazy binding. A NULL Store is // possible for a valid lazy binding. return std::make_pair((Store) 0, (const MemRegion *) 0); @@ -1098,14 +1102,19 @@ QualType Ty) { if (const Optional &D = getDefaultBinding(B, superR)) { - if (SymbolRef parentSym = D->getAsSymbol()) + const SVal &val = D.getValue(); + if (SymbolRef parentSym = val.getAsSymbol()) return svalBuilder.getDerivedRegionValueSymbolVal(parentSym, R); - if (D->isZeroConstant()) + if (val.isZeroConstant()) return svalBuilder.makeZeroVal(Ty); - if (D->isUnknownOrUndef()) - return *D; + if (val.isUnknownOrUndef()) + return val; + + // Lazy bindings are handled later. + if (isa(val)) + return Optional(); assert(0 && "Unknown default value"); } @@ -1113,6 +1122,15 @@ return Optional(); } +SVal RegionStoreManager::RetrieveLazyBinding(const MemRegion *lazyBindingRegion, + Store lazyBindingStore) { + if (const ElementRegion *ER = dyn_cast(lazyBindingRegion)) + return RetrieveElement(lazyBindingStore, ER); + + return RetrieveField(lazyBindingStore, + cast(lazyBindingRegion)); +} + SVal RegionStoreManager::RetrieveFieldOrElementCommon(Store store, const TypedRegion *R, QualType Ty, @@ -1142,12 +1160,8 @@ const MemRegion *lazyBindingRegion = NULL; llvm::tie(lazyBindingStore, lazyBindingRegion) = GetLazyBinding(B, R); - if (lazyBindingRegion) { - if (const ElementRegion *ER = dyn_cast(lazyBindingRegion)) - return RetrieveElement(lazyBindingStore, ER); - return RetrieveField(lazyBindingStore, - cast(lazyBindingRegion)); - } + if (lazyBindingRegion) + return RetrieveLazyBinding(lazyBindingRegion, lazyBindingStore); if (R->hasStackNonParametersStorage()) { if (const ElementRegion *ER = dyn_cast(R)) { @@ -1530,7 +1544,7 @@ // Now copy the bindings. This amounts to just binding 'V' to 'R'. This // results in a zero-copy algorithm. - return StoreRef(addBinding(B, R, BindingKey::Direct, + return StoreRef(addBinding(B, R, BindingKey::Default, V).getRootWithoutRetain(), *this); } Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=127796&r1=127795&r2=127796&view=diff ============================================================================== --- cfe/trunk/test/Analysis/misc-ps-region-store.m (original) +++ cfe/trunk/test/Analysis/misc-ps-region-store.m Wed Mar 16 22:51:51 2011 @@ -1253,4 +1253,24 @@ } } +// Test handling binding lazy compound values to a region and then have +// specific elements have other bindings. +int PR9455() { + char arr[4] = "000"; + arr[0] = '1'; + if (arr[1] == '0') + return 1; + int *p = 0; + *p = 0xDEADBEEF; // no-warning + return 1; +} +int PR9455_2() { + char arr[4] = "000"; + arr[0] = '1'; + if (arr[1] == '0') { + int *p = 0; + *p = 0xDEADBEEF; // expected-warning {{null}} + } + return 1; +} From kremenek at apple.com Wed Mar 16 23:01:35 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 04:01:35 -0000 Subject: [cfe-commits] r127797 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp test/Analysis/variadic-method-types.m Message-ID: <20110317040135.84C5E2A6C12C@llvm.org> Author: kremenek Date: Wed Mar 16 23:01:35 2011 New Revision: 127797 URL: http://llvm.org/viewvc/llvm-project?rev=127797&view=rev Log: Teach VariadicMethodTypeChecker that CF references are valid arguments to variadic Objective-C methods. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp cfe/trunk/test/Analysis/variadic-method-types.m Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=127797&r1=127796&r2=127797&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Wed Mar 16 23:01:35 2011 @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "ClangSACheckers.h" +#include "clang/Analysis/DomainSpecific/CocoaConventions.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" @@ -594,6 +595,10 @@ // Ignore pointer constants. if (isa(msg.getArgSVal(I, state))) continue; + + // Ignore CF references, which can be toll-free bridged. + if (cocoa::isCFObjectRef(ArgTy)) + continue; // Generate only one error node to use for all bug reports. if (!errorNode.hasValue()) { Modified: cfe/trunk/test/Analysis/variadic-method-types.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/variadic-method-types.m?rev=127797&r1=127796&r2=127797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/variadic-method-types.m (original) +++ cfe/trunk/test/Analysis/variadic-method-types.m Wed Mar 16 23:01:35 2011 @@ -11,7 +11,8 @@ //===----------------------------------------------------------------------===// #define nil (void*)0 - +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kCGImageSourceShouldCache __attribute__((visibility("default"))); typedef signed char BOOL; typedef struct _NSZone NSZone; typedef unsigned int NSUInteger; @@ -70,6 +71,7 @@ [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} } From kremenek at apple.com Wed Mar 16 23:10:25 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 04:10:25 -0000 Subject: [cfe-commits] r127798 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp test/Analysis/variadic-method-types.m Message-ID: <20110317041025.879132A6C12C@llvm.org> Author: kremenek Date: Wed Mar 16 23:10:25 2011 New Revision: 127798 URL: http://llvm.org/viewvc/llvm-project?rev=127798&view=rev Log: Teach VariadicMethodTypeChecker about pointers attributed as 'NSObject'. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp cfe/trunk/test/Analysis/variadic-method-types.m Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=127798&r1=127797&r2=127798&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Wed Mar 16 23:10:25 2011 @@ -596,6 +596,10 @@ if (isa(msg.getArgSVal(I, state))) continue; + // Ignore pointer types annotated with 'NSObject' attribute. + if (C.getASTContext().isObjCNSObjectType(ArgTy)) + continue; + // Ignore CF references, which can be toll-free bridged. if (cocoa::isCFObjectRef(ArgTy)) continue; Modified: cfe/trunk/test/Analysis/variadic-method-types.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/variadic-method-types.m?rev=127798&r1=127797&r2=127798&view=diff ============================================================================== --- cfe/trunk/test/Analysis/variadic-method-types.m (original) +++ cfe/trunk/test/Analysis/variadic-method-types.m Wed Mar 16 23:10:25 2011 @@ -61,7 +61,11 @@ @protocol P; @class C; -void f(id a, id

    b, C* c, C

    *d) { +typedef struct FooType * __attribute__ ((NSObject)) FooType; +typedef struct BarType * BarType; + + +void f(id a, id

    b, C* c, C

    *d, FooType fooType, BarType barType) { [NSArray arrayWithObjects:@"Hello", a, b, c, d, nil]; [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}} @@ -72,9 +76,8 @@ [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", fooType, nil] autorelease]; // no-warning + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", barType, nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'BarType'}} [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} } -int main() { - f(nil, nil, nil, nil); -} From kremenek at apple.com Wed Mar 16 23:16:45 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 04:16:45 -0000 Subject: [cfe-commits] r127799 - /cfe/trunk/test/Sema/uninit-variables-vectors.c Message-ID: <20110317041645.321F42A6C12C@llvm.org> Author: kremenek Date: Wed Mar 16 23:16:45 2011 New Revision: 127799 URL: http://llvm.org/viewvc/llvm-project?rev=127799&view=rev Log: Make test more portable. Modified: cfe/trunk/test/Sema/uninit-variables-vectors.c Modified: cfe/trunk/test/Sema/uninit-variables-vectors.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables-vectors.c?rev=127799&r1=127798&r2=127799&view=diff ============================================================================== --- cfe/trunk/test/Sema/uninit-variables-vectors.c (original) +++ cfe/trunk/test/Sema/uninit-variables-vectors.c Wed Mar 16 23:16:45 2011 @@ -1,6 +1,9 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify -#include +typedef int __v4si __attribute__((__vector_size__(16))); +typedef float __m128 __attribute__((__vector_size__(16))); +__m128 _mm_xor_ps(__m128 a, __m128 b); +__m128 _mm_loadu_ps(const float *p); void test1(float *input) { __m128 x, y, z, w, X; // expected-note {{variable 'x' is declared here}} expected-note {{variable 'y' is declared here}} expected-note {{variable 'w' is declared here}} expected-note {{variable 'z' is declared here}} From geek4civic at gmail.com Wed Mar 16 23:51:42 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Thu, 17 Mar 2011 13:51:42 +0900 Subject: [cfe-commits] [PATCH] test/Driver/darwin-cc.c, sysroot-flags.c: FileCheck-ize and tweak for Mingw MSYS bash. Message-ID: MSYS substitutes path (that begins with "/") to de-mounted Windows path, even if it were nonexistent. "/tmp" might be substituted as "C:/DOCUME~1/chapuni/LOCALS~1/Temp". "/foo/bar" might be substituted to "C:/msysgit/foo/bar". --- test/Driver/darwin-cc.c | 7 +++---- test/Driver/sysroot-flags.c | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) --- I know they must be ugly, though, I would like to propose to loosen expressions in them. For now, they are the last failures on mingw-msys in ToT. Or, I could add the feature, "Do not execute when 'Windows' and 'bash'." Please take a glance into them. ;) ...Takumi -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-test-Driver-darwin-cc.c-sysroot-flags.c-FileChec.patch.txt Type: text/x-patch Size: 4758 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/6507a767/attachment.bin From kremenek at apple.com Thu Mar 17 00:29:57 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 05:29:57 -0000 Subject: [cfe-commits] r127802 - in /cfe/trunk: lib/Sema/AnalysisBasedWarnings.cpp test/SemaCXX/uninit-variables-conditional.cpp Message-ID: <20110317052957.798EE2A6C12C@llvm.org> Author: kremenek Date: Thu Mar 17 00:29:57 2011 New Revision: 127802 URL: http://llvm.org/viewvc/llvm-project?rev=127802&view=rev Log: Don't construct two CFGs just to run -Wuninitialized. While this causes new warnings to be flagged under -Wconditional-uninitialized, this is something we can improve over time. Added: cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=127802&r1=127801&r2=127802&view=diff ============================================================================== --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original) +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Mar 17 00:29:57 2011 @@ -611,24 +611,7 @@ != Diagnostic::Ignored || Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart()) != Diagnostic::Ignored) { - ASTContext &ctx = D->getASTContext(); - llvm::OwningPtr tmpCFG; - bool useAlternateCFG = false; - if (ctx.getLangOptions().CPlusPlus) { - // Temporary workaround: implicit dtors in the CFG can confuse - // the path-sensitivity in the uninitialized values analysis. - // For now create (if necessary) a separate CFG without implicit dtors. - // FIXME: We should not need to do this, as it results in multiple - // CFGs getting constructed. - CFG::BuildOptions B; - B.AddEHEdges = false; - B.AddImplicitDtors = false; - B.AddInitializers = true; - tmpCFG.reset(CFG::buildCFG(D, AC.getBody(), &ctx, B)); - useAlternateCFG = true; - } - CFG *cfg = useAlternateCFG ? tmpCFG.get() : AC.getCFG(); - if (cfg) { + if (CFG *cfg = AC.getCFG()) { UninitValsDiagReporter reporter(S); runUninitializedVariablesAnalysis(*cast(D), *cfg, AC, reporter); Added: cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp?rev=127802&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp (added) +++ cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp Thu Mar 17 00:29:57 2011 @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -Wconditional-uninitialized -fsyntax-only %s -verify + +class Foo { +public: + Foo(); + ~Foo(); + operator bool(); +}; + +int bar(); +int baz(); +int init(double *); + +// This case flags a false positive under -Wconditional-uninitialized because +// the destructor in Foo fouls about the minor bit of path-sensitivity in +// -Wuninitialized. +double test() { + double x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + if (bar() || baz() || Foo() || init(&x)) { + return x; // expected-warning {{variable 'x' is possibly uninitialized when used here}} + } + return 1.0; +} From kremenek at apple.com Thu Mar 17 00:34:58 2011 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 17 Mar 2011 05:34:58 -0000 Subject: [cfe-commits] r127803 - /cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp Message-ID: <20110317053458.9AB512A6C12C@llvm.org> Author: kremenek Date: Thu Mar 17 00:34:58 2011 New Revision: 127803 URL: http://llvm.org/viewvc/llvm-project?rev=127803&view=rev Log: Fix test to test the right thing. Modified: cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp Modified: cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp?rev=127803&r1=127802&r2=127803&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp (original) +++ cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp Thu Mar 17 00:34:58 2011 @@ -16,8 +16,8 @@ // -Wuninitialized. double test() { double x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} - if (bar() || baz() || Foo() || init(&x)) { - return x; // expected-warning {{variable 'x' is possibly uninitialized when used here}} - } - return 1.0; + if (bar() || baz() || Foo() || init(&x)) + return 1.0; + + return x; // expected-warning {{variable 'x' is possibly uninitialized when used here}} } From richard at metafoo.co.uk Thu Mar 17 07:06:44 2011 From: richard at metafoo.co.uk (Richard Smith) Date: Thu, 17 Mar 2011 12:06:44 -0000 (UTC) Subject: [cfe-commits] [PATCH] PR9488: don't assert/crash if auto type substitution fails Message-ID: <35698.10.0.16.53.1300363604.squirrel@webmail.cantab.net> Hi, In PR9488 I observed that clang crashes if auto type substitution fails. This can happen if 'auto' is deduced as 'void' in the context of an 'auto &' type. Testing the fix for this issue exposed another issue: the type source information for the substituted type was not being built. The attached patch fixes these issues. Please review! Thanks, Richard -------------- next part -------------- A non-text attachment was scrubbed... Name: clang-9488.diff Type: text/x-patch Size: 5328 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/eb1b42a4/attachment-0001.bin From csdavec at swan.ac.uk Thu Mar 17 09:19:08 2011 From: csdavec at swan.ac.uk (David Chisnall) Date: Thu, 17 Mar 2011 14:19:08 -0000 Subject: [cfe-commits] r127806 - /cfe/trunk/lib/CodeGen/CodeGenModule.cpp Message-ID: <20110317141908.EC60E2A6C12C@llvm.org> Author: theraven Date: Thu Mar 17 09:19:08 2011 New Revision: 127806 URL: http://llvm.org/viewvc/llvm-project?rev=127806&view=rev Log: Remove code that was intentionally generating bad code on the GNU runtime for no reason (failing to emit .cxx_constructor / .cxx_destructor methods). Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127806&r1=127805&r2=127806&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Mar 17 09:19:08 2011 @@ -1934,7 +1934,7 @@ /// EmitObjCIvarInitializations - Emit information for ivar initialization /// for an implementation. void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) { - if (!Features.NeXTRuntime || D->getNumIvarInitializers() == 0) + if (D->getNumIvarInitializers() == 0) return; DeclContext* DC = const_cast(dyn_cast(D)); assert(DC && "EmitObjCIvarInitializations - null DeclContext"); From richard at metafoo.co.uk Thu Mar 17 09:52:12 2011 From: richard at metafoo.co.uk (Richard Smith) Date: Thu, 17 Mar 2011 14:52:12 -0000 (UTC) Subject: [cfe-commits] [PATCH] PR9488: don't assert/crash if auto type substitution fails In-Reply-To: <35698.10.0.16.53.1300363604.squirrel@webmail.cantab.net> References: <35698.10.0.16.53.1300363604.squirrel@webmail.cantab.net> Message-ID: <52044.10.0.7.178.1300373532.squirrel@webmail.cantab.net> On Thu, March 17, 2011 12:06, Richard Smith wrote: > In PR9488 I observed that clang crashes if auto type substitution fails. > This can happen if 'auto' is deduced as 'void' in the context of an 'auto > &' type. Testing the fix for this issue exposed another issue: the type > source information for the substituted type was not being built. > > The attached patch fixes these issues. Please review! Oops, I forgot to 'svn add' the new test before creating the patch! Test is attached. Thanks! Richard -------------- next part -------------- A non-text attachment was scrubbed... Name: clang-9488-test.diff Type: text/x-patch Size: 1026 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/9d0e6dc3/attachment.bin From dgregor at apple.com Thu Mar 17 10:31:07 2011 From: dgregor at apple.com (Douglas Gregor) Date: Thu, 17 Mar 2011 08:31:07 -0700 Subject: [cfe-commits] [PATCH] PR9488: don't assert/crash if auto type substitution fails In-Reply-To: <35698.10.0.16.53.1300363604.squirrel@webmail.cantab.net> References: <35698.10.0.16.53.1300363604.squirrel@webmail.cantab.net> Message-ID: <5378A61E-38D2-4888-BDBC-733AD34815AD@apple.com> LGTM! On Mar 17, 2011, at 5:06 AM, Richard Smith wrote: > Hi, > > In PR9488 I observed that clang crashes if auto type substitution fails. > This can happen if 'auto' is deduced as 'void' in the context of an 'auto > &' type. Testing the fix for this issue exposed another issue: the type > source information for the substituted type was not being built. > > The attached patch fixes these issues. Please review! > > Thanks, > Richard_______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From anton at korobeynikov.info Thu Mar 17 10:45:32 2011 From: anton at korobeynikov.info (Anton Korobeynikov) Date: Thu, 17 Mar 2011 18:45:32 +0300 Subject: [cfe-commits] Skip UTF-8 BOM Message-ID: Hello Everyone Attached simple patch allows clang to skip UTF-8 BOM if seen in the begining of lexing buffer. Ok to commit? -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University -------------- next part -------------- A non-text attachment was scrubbed... Name: bom.diff Type: application/octet-stream Size: 2504 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/da8f59d3/attachment.obj From richard-llvm at metafoo.co.uk Thu Mar 17 11:11:59 2011 From: richard-llvm at metafoo.co.uk (Richard Smith) Date: Thu, 17 Mar 2011 16:11:59 -0000 Subject: [cfe-commits] r127811 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaTemplateDeduction.cpp test/SemaCXX/auto-subst-failure.cpp Message-ID: <20110317161159.B87892A6C12C@llvm.org> Author: rsmith Date: Thu Mar 17 11:11:59 2011 New Revision: 127811 URL: http://llvm.org/viewvc/llvm-project?rev=127811&view=rev Log: Fix PR9488: 'auto' type substitution can fail (for instance, if it creates a reference-to-void type). Don't crash if it does. Also fix an issue where type source information for the resulting type was being lost. Added: cfe/trunk/test/SemaCXX/auto-subst-failure.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=127811&r1=127810&r2=127811&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Thu Mar 17 11:11:59 2011 @@ -3879,7 +3879,8 @@ FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info); - bool DeduceAutoType(QualType AutoType, Expr *Initializer, QualType &Result); + bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, + TypeSourceInfo *&Result); FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127811&r1=127810&r2=127811&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar 17 11:11:59 2011 @@ -4664,15 +4664,17 @@ // C++0x [decl.spec.auto]p6. Deduce the type which 'auto' stands in for. if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) { - QualType DeducedType; - if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { + TypeSourceInfo *DeducedType = 0; + if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType)) Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) << VDecl->getDeclName() << VDecl->getType() << Init->getType() << Init->getSourceRange(); + if (!DeducedType) { RealDecl->setInvalidDecl(); return; } - VDecl->setType(DeducedType); + VDecl->setTypeSourceInfo(DeducedType); + VDecl->setType(DeducedType->getType()); // If this is a redeclaration, check that the type we just deduced matches // the previously declared type. Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=127811&r1=127810&r2=127811&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Mar 17 11:11:59 2011 @@ -6137,15 +6137,17 @@ } Expr *Init = Exprs.get()[0]; - QualType DeducedType; - if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { + TypeSourceInfo *DeducedType = 0; + if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType)) Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) << VDecl->getDeclName() << VDecl->getType() << Init->getType() << Init->getSourceRange(); + if (!DeducedType) { RealDecl->setInvalidDecl(); return; } - VDecl->setType(DeducedType); + VDecl->setTypeSourceInfo(DeducedType); + VDecl->setType(DeducedType->getType()); // If this is a redeclaration, check that the type we just deduced matches // the previously declared type. Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127811&r1=127810&r2=127811&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Mar 17 11:11:59 2011 @@ -848,16 +848,18 @@ diag::err_auto_new_ctor_multiple_expressions) << AllocType << TypeRange); } - QualType DeducedType; - if (!DeduceAutoType(AllocType, ConstructorArgs.get()[0], DeducedType)) + TypeSourceInfo *DeducedType = 0; + if (!DeduceAutoType(AllocTypeInfo, ConstructorArgs.get()[0], DeducedType)) return ExprError(Diag(StartLoc, diag::err_auto_new_deduction_failure) << AllocType << ConstructorArgs.get()[0]->getType() << TypeRange << ConstructorArgs.get()[0]->getSourceRange()); + if (!DeducedType) + return ExprError(); - AllocType = DeducedType; - AllocTypeInfo = Context.getTrivialTypeSourceInfo(AllocType, StartLoc); + AllocTypeInfo = DeducedType; + AllocType = AllocTypeInfo->getType(); } // Per C++0x [expr.new]p5, the type being constructed may be a Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=127811&r1=127810&r2=127811&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Mar 17 11:11:59 2011 @@ -3003,11 +3003,14 @@ /// /// \param Result if type deduction was successful, this will be set to the /// deduced type. This may still contain undeduced autos if the type is -/// dependent. +/// dependent. This will be set to null if deduction succeeded, but auto +/// substitution failed; the appropriate diagnostic will already have been +/// produced in that case. /// /// \returns true if deduction succeeded, false if it failed. bool -Sema::DeduceAutoType(QualType Type, Expr *Init, QualType &Result) { +Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *Init, + TypeSourceInfo *&Result) { if (Init->isTypeDependent()) { Result = Type; return true; @@ -3025,8 +3028,10 @@ FixedSizeTemplateParameterList<1> TemplateParams(Loc, Loc, &TemplParamPtr, Loc); - QualType FuncParam = + TypeSourceInfo *FuncParamInfo = SubstituteAutoTransform(*this, TemplArg).TransformType(Type); + assert(FuncParamInfo && "substituting template parameter for 'auto' failed"); + QualType FuncParam = FuncParamInfo->getType(); // Deduce type of TemplParam in Func(Init) llvm::SmallVector Deduced; Added: cfe/trunk/test/SemaCXX/auto-subst-failure.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/auto-subst-failure.cpp?rev=127811&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/auto-subst-failure.cpp (added) +++ cfe/trunk/test/SemaCXX/auto-subst-failure.cpp Thu Mar 17 11:11:59 2011 @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x + +void f() { + auto a = f(); // expected-error {{variable has incomplete type 'void'}} + auto &b = f(); // expected-error {{cannot form a reference to 'void'}} + auto *c = f(); // expected-error {{incompatible initializer of type 'void'}} + + auto d(f()); // expected-error {{variable has incomplete type 'void'}} + auto &&e(f()); // expected-error {{cannot form a reference to 'void'}} + auto *g(f()); // expected-error {{incompatible initializer of type 'void'}} + + (void)new auto(f()); // expected-error {{allocation of incomplete type 'void'}} + (void)new auto&(f()); // expected-error {{cannot form a reference to 'void'}} + (void)new auto*(f()); // expected-error {{incompatible constructor argument of type 'void'}} +} From richard at metafoo.co.uk Thu Mar 17 11:18:03 2011 From: richard at metafoo.co.uk (Richard Smith) Date: Thu, 17 Mar 2011 16:18:03 -0000 (UTC) Subject: [cfe-commits] [PATCH] PR9488: don't assert/crash if auto type substitution fails In-Reply-To: <5378A61E-38D2-4888-BDBC-733AD34815AD@apple.com> References: <35698.10.0.16.53.1300363604.squirrel@webmail.cantab.net> <5378A61E-38D2-4888-BDBC-733AD34815AD@apple.com> Message-ID: <58418.10.0.7.178.1300378683.squirrel@webmail.cantab.net> Great, in r127811. Should this be merged into 2.9? On Thu, March 17, 2011 15:31, Douglas Gregor wrote: > LGTM! > > > On Mar 17, 2011, at 5:06 AM, Richard Smith wrote: > > >> Hi, >> >> >> In PR9488 I observed that clang crashes if auto type substitution >> fails. This can happen if 'auto' is deduced as 'void' in the context of >> an 'auto &' type. Testing the fix for this issue exposed another issue: >> the type source information for the substituted type was not being >> built. >> >> The attached patch fixes these issues. Please review! >> >> >> Thanks, >> Richard_______________________________________________ >> cfe-commits mailing list cfe-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> > > From daniel at zuster.org Thu Mar 17 12:10:06 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Thu, 17 Mar 2011 17:10:06 -0000 Subject: [cfe-commits] r127815 - in /cfe/trunk: lib/Driver/Tools.cpp lib/Driver/Tools.h test/Driver/apple-kext-mkernel.c Message-ID: <20110317171006.BFDF82A6C12C@llvm.org> Author: ddunbar Date: Thu Mar 17 12:10:06 2011 New Revision: 127815 URL: http://llvm.org/viewvc/llvm-project?rev=127815&view=rev Log: Driver/Darwin/ARM: Kernel/kext code has more strict alignment requirements. Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Driver/Tools.h cfe/trunk/test/Driver/apple-kext-mkernel.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127815&r1=127814&r2=127815&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Mar 17 12:10:06 2011 @@ -420,7 +420,8 @@ } void Clang::AddARMTargetArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs, + bool KernelOrKext) const { const Driver &D = getToolChain().getDriver(); llvm::Triple Triple = getToolChain().getTriple(); @@ -587,8 +588,17 @@ // Setting -msoft-float effectively disables NEON because of the GCC // implementation, although the same isn't true of VFP or VFP3. if (FloatABI == "soft") { - CmdArgs.push_back("-target-feature"); - CmdArgs.push_back("-neon"); + CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-neon"); + } + + // Kernel code has more strict alignment requirements. + if (KernelOrKext) { + CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-arm-long-calls"); + + CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-arm-strict-align"); } } @@ -1173,7 +1183,7 @@ case llvm::Triple::arm: case llvm::Triple::thumb: - AddARMTargetArgs(Args, CmdArgs); + AddARMTargetArgs(Args, CmdArgs, KernelOrKext); break; case llvm::Triple::mips: Modified: cfe/trunk/lib/Driver/Tools.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=127815&r1=127814&r2=127815&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.h (original) +++ cfe/trunk/lib/Driver/Tools.h Thu Mar 17 12:10:06 2011 @@ -34,7 +34,8 @@ const InputInfo &Output, const InputInfoList &Inputs) const; - void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; + void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs, + bool KernelOrKext) const; void AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; void AddSparcTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; Modified: cfe/trunk/test/Driver/apple-kext-mkernel.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/apple-kext-mkernel.c?rev=127815&r1=127814&r2=127815&view=diff ============================================================================== --- cfe/trunk/test/Driver/apple-kext-mkernel.c (original) +++ cfe/trunk/test/Driver/apple-kext-mkernel.c Thu Mar 17 12:10:06 2011 @@ -1,6 +1,18 @@ -// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -mkernel -### -fsyntax-only %s 2> %t -// RUN grep "-disable-red-zone" %t -// RUN grep "-fapple-kext" %t -// RUN grep "-fno-builtin" %t -// RUN grep "-fno-rtti" %t -// RUN grep "-fno-common" %t +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 \ +// RUN: -mkernel -### -fsyntax-only %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-X86 < %t %s + +// CHECK-X86: "-disable-red-zone" +// CHECK-X86: "-fno-builtin" +// CHECK-X86: "-fno-rtti" +// CHECK-X86: "-fno-common" + +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 \ +// RUN: -arch armv7 -mkernel -### -fsyntax-only %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-ARM < %t %s + +// CHECK-ARM: "-target-feature" "-arm-long-calls" +// CHECK-ARM: "-target-feature" "-arm-strict-align" +// CHECK-ARM: "-fno-builtin" +// CHECK-ARM: "-fno-rtti" +// CHECK-ARM: "-fno-common" From daniel at zuster.org Thu Mar 17 12:37:29 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Thu, 17 Mar 2011 17:37:29 -0000 Subject: [cfe-commits] r127819 - /cfe/trunk/lib/Driver/Tools.cpp Message-ID: <20110317173729.6BA202A6C12C@llvm.org> Author: ddunbar Date: Thu Mar 17 12:37:29 2011 New Revision: 127819 URL: http://llvm.org/viewvc/llvm-project?rev=127819&view=rev Log: Driver/Darwin: Suppress spurious warning about -force_cpusubtype_ALL. Modified: cfe/trunk/lib/Driver/Tools.cpp Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127819&r1=127818&r2=127819&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Mar 17 12:37:29 2011 @@ -1905,7 +1905,8 @@ !IsOpt)) CmdArgs.push_back("-relax-all"); - // FIXME: Add -force_cpusubtype_ALL support, once we have it. + // Ignore explicit -force_cpusubtype_ALL option. + (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); // FIXME: Add -g support, once we have it. From dgregor at apple.com Thu Mar 17 12:42:24 2011 From: dgregor at apple.com (Douglas Gregor) Date: Thu, 17 Mar 2011 10:42:24 -0700 Subject: [cfe-commits] Skip UTF-8 BOM In-Reply-To: References: Message-ID: <905B0E46-EC94-4470-95D8-0706805A883A@apple.com> On Mar 17, 2011, at 8:45 AM, Anton Korobeynikov wrote: > Hello Everyone > > Attached simple patch allows clang to skip UTF-8 BOM if seen in the > begining of lexing buffer. > > Ok to commit? I'm no expert in the lexer, but it looks good to me. - Doug From ismail at namtrac.org Thu Mar 17 12:47:01 2011 From: ismail at namtrac.org (=?UTF-8?B?xLBzbWFpbCBEw7ZubWV6?=) Date: Thu, 17 Mar 2011 18:47:01 +0100 Subject: [cfe-commits] Skip UTF-8 BOM In-Reply-To: References: Message-ID: On Thu, Mar 17, 2011 at 4:45 PM, Anton Korobeynikov wrote: > Hello Everyone > > Attached simple patch allows clang to skip UTF-8 BOM if seen in the > begining of lexing buffer. > > Ok to commit? > I also had some files which had UTF-16 BOM at start, does it make sense to handle that also? Regards, ismail -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/85ef14cc/attachment.html From anton at korobeynikov.info Thu Mar 17 13:06:24 2011 From: anton at korobeynikov.info (Anton Korobeynikov) Date: Thu, 17 Mar 2011 21:06:24 +0300 Subject: [cfe-commits] Skip UTF-8 BOM In-Reply-To: References: Message-ID: > I also had some files which had UTF-16 BOM at start, does it make sense to > handle that also? As soon as someone else will implement UTF-16 in clang - yes. Right now clang supports utf-8 only, so skipping utf-8 BOM is perfectly ok. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University From daniel at zuster.org Thu Mar 17 13:29:04 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Thu, 17 Mar 2011 18:29:04 -0000 Subject: [cfe-commits] r127820 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/apple-kext-mkernel.c Message-ID: <20110317182904.D8FD72A6C12C@llvm.org> Author: ddunbar Date: Thu Mar 17 13:29:04 2011 New Revision: 127820 URL: http://llvm.org/viewvc/llvm-project?rev=127820&view=rev Log: Driver/Darwin: These are command line options, not target features. Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/apple-kext-mkernel.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127820&r1=127819&r2=127820&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Mar 17 13:29:04 2011 @@ -594,10 +594,10 @@ // Kernel code has more strict alignment requirements. if (KernelOrKext) { - CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-arm-long-calls"); - CmdArgs.push_back("-target-feature"); + CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-arm-strict-align"); } } Modified: cfe/trunk/test/Driver/apple-kext-mkernel.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/apple-kext-mkernel.c?rev=127820&r1=127819&r2=127820&view=diff ============================================================================== --- cfe/trunk/test/Driver/apple-kext-mkernel.c (original) +++ cfe/trunk/test/Driver/apple-kext-mkernel.c Thu Mar 17 13:29:04 2011 @@ -11,8 +11,8 @@ // RUN: -arch armv7 -mkernel -### -fsyntax-only %s 2> %t // RUN: FileCheck --check-prefix=CHECK-ARM < %t %s -// CHECK-ARM: "-target-feature" "-arm-long-calls" -// CHECK-ARM: "-target-feature" "-arm-strict-align" +// CHECK-ARM: "-mllvm" "-arm-long-calls" +// CHECK-ARM: "-mllvm" "-arm-strict-align" // CHECK-ARM: "-fno-builtin" // CHECK-ARM: "-fno-rtti" // CHECK-ARM: "-fno-common" From ofv at wanadoo.es Thu Mar 17 14:03:04 2011 From: ofv at wanadoo.es (Oscar Fuentes) Date: Thu, 17 Mar 2011 19:03:04 -0000 Subject: [cfe-commits] r127822 - /cfe/trunk/CMakeLists.txt Message-ID: <20110317190304.637452A6C12C@llvm.org> Author: ofv Date: Thu Mar 17 14:03:04 2011 New Revision: 127822 URL: http://llvm.org/viewvc/llvm-project?rev=127822&view=rev Log: Fix some issues with include directories: remove a duplicate and put Clang binary and source directories first (on that order). Modified: cfe/trunk/CMakeLists.txt Modified: cfe/trunk/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=127822&r1=127821&r2=127822&view=diff ============================================================================== --- cfe/trunk/CMakeLists.txt (original) +++ cfe/trunk/CMakeLists.txt Thu Mar 17 14:03:04 2011 @@ -40,9 +40,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) include_directories("${PATH_TO_LLVM_BUILD}/include" "${LLVM_MAIN_INCLUDE_DIR}") - if( NOT PATH_TO_LLVM_BUILD STREQUAL LLVM_MAIN_SRC_DIR ) - include_directories("${LLVM_MAIN_INCLUDE_DIR}") - endif() link_directories("${PATH_TO_LLVM_BUILD}/lib") set(LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/tblgen") @@ -211,9 +208,9 @@ set_target_properties(${name} PROPERTIES FOLDER "Clang executables") endmacro(add_clang_executable) -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/include +include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/include ) install(DIRECTORY include/ From erg at chromium.org Thu Mar 17 13:05:25 2011 From: erg at chromium.org (Elliot Glaysher (Chromium)) Date: Thu, 17 Mar 2011 11:05:25 -0700 Subject: [cfe-commits] [PATCH] Re: [cfe-dev] Interest in a -Wusing-namespace-in-headers? In-Reply-To: References: Message-ID: Adds a -Wheader-hygiene warning for warnings that should only trigger in #included files. The first -Wheader-hygiene check is to make sure a using directive isn't placed in the global context in a header. On Wed, Mar 16, 2011 at 6:15 PM, Douglas Gregor wrote: > You don't need to perform the getDiagnosticLevel() check yourself, because the diagnostic system will handle warning suppression itself. > > However, I do suggest performing the CurContext->getDeclKind() == Decl::TranslationUnit check before the isFromMainFile() check, since the former is cheaper. Done. -- Elliot Glaysher -------------- next part -------------- A non-text attachment was scrubbed... Name: using-namespace-3.diff Type: text/x-patch Size: 3554 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/a9241baf/attachment-0001.bin From joerg at britannica.bec.de Thu Mar 17 16:24:47 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Thu, 17 Mar 2011 22:24:47 +0100 Subject: [cfe-commits] [PATCH] Improved cross-compiling support for calling helper programs Message-ID: <20110317212447.GA26735@britannica.bec.de> Hi all, the attached patch changes the driver to look for "x86_64--netbsd-ld" and "x86_64--netbsd-as" when compiling for x86_64--netbsd as target triple. If they can't be found, it falls back to the normal "ld" and "as" lookup. This simplifies the cross compiling setup quite a bit. What other platforms are interested in this behavior? Joerg -------------- next part -------------- A non-text attachment was scrubbed... Name: cross-driver.diff Type: text/x-diff Size: 1736 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/e820d79c/attachment.bin From anton at korobeynikov.info Thu Mar 17 16:37:07 2011 From: anton at korobeynikov.info (Anton Korobeynikov) Date: Fri, 18 Mar 2011 00:37:07 +0300 Subject: [cfe-commits] [PATCH] Improved cross-compiling support for calling helper programs In-Reply-To: <20110317212447.GA26735@britannica.bec.de> References: <20110317212447.GA26735@britannica.bec.de> Message-ID: Hi Joerg, > the attached patch changes the driver to look for "x86_64--netbsd-ld" > and "x86_64--netbsd-as" when compiling for x86_64--netbsd as target > triple. If they can't be found, it falls back to the normal "ld" and > "as" lookup. This simplifies the cross compiling setup quite a bit. > What other platforms are interested in this behavior? Just quick q: does NetBSD use cross-directory layout? So, do you have something like /usr/x86_64-netbsd/bin/as? -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University From dimitry at andric.com Thu Mar 17 16:41:20 2011 From: dimitry at andric.com (Dimitry Andric) Date: Thu, 17 Mar 2011 22:41:20 +0100 Subject: [cfe-commits] [PATCH] Improved cross-compiling support for calling helper programs In-Reply-To: <20110317212447.GA26735@britannica.bec.de> References: <20110317212447.GA26735@britannica.bec.de> Message-ID: <4D828000.6020807@andric.com> On 2011-03-17 22:24, Joerg Sonnenberger wrote: > the attached patch changes the driver to look for "x86_64--netbsd-ld" > and "x86_64--netbsd-as" when compiling for x86_64--netbsd as target > triple. If they can't be found, it falls back to the normal "ld" and > "as" lookup. This simplifies the cross compiling setup quite a bit. > What other platforms are interested in this behavior? FreeBSD, at least. :) But I guess it would also be appropriate for most Linuxes. From joerg at britannica.bec.de Thu Mar 17 17:11:01 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Thu, 17 Mar 2011 23:11:01 +0100 Subject: [cfe-commits] [PATCH] Improved cross-compiling support for calling helper programs In-Reply-To: References: <20110317212447.GA26735@britannica.bec.de> Message-ID: <20110317221101.GA2865@britannica.bec.de> On Fri, Mar 18, 2011 at 12:37:07AM +0300, Anton Korobeynikov wrote: > Hi Joerg, > > > the attached patch changes the driver to look for "x86_64--netbsd-ld" > > and "x86_64--netbsd-as" when compiling for x86_64--netbsd as target > > triple. If they can't be found, it falls back to the normal "ld" and > > "as" lookup. This simplifies the cross compiling setup quite a bit. > > What other platforms are interested in this behavior? > Just quick q: does NetBSD use cross-directory layout? So, do you have > something like /usr/x86_64-netbsd/bin/as? The NetBSD build system is essentially always using cross-compilation. There are three pathes that influence the build: - tooldir - objdir - destdir The tooldir contains the various native programs, prefix to not conflict with normal $PATH content. This includes make, the compiler, binutils and whatever else is needed for the build. Let's consider building for i386. This uses i486--netbsdelf as target for various reasons. Under tooldir, this creates: ... bin/i486--netbsdelf-as bin/i486--netbsdelf-ld bin/i486--netbsdelf-gcc ... bin/nbmake-i386 ... i486--netbsdelf/as i486--netbsdelf/gcc i486--netbsdelf/ld but the i486--netbsdelf is only really used for the ldscripts and hardlinks for the GNU stuff also found in bin/. This tooldir can now be used for different objdir/destdir pairs to compile the tree. At the moment, it is using -B$DESTDIR/usr/lib, -nostdlib -L$DESTDIR/usr/lib -lgcc -lc, -nostdinc -isysroot $DESTDIR/usr/include -cxx-isysroot $DESTDIR/usr/include/c++ ...but with the exception of the first -B, that's what --sysroot $DESTDIR gives. I would expect a sane cross-compiling setup for other platforms to be quite similar. With some additional changes to make the look up for crt0.o and libgcc honour --sysroot, all that is needed for cross-compiliation is using "clang -ccc-host-triple i486--netbsdelf --sysroot $DESTDIR" or adding a symlink and using "i486--netbsdelf-clang --sysroot $DESTDIR". Joerg From daniel at zuster.org Thu Mar 17 18:28:31 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Thu, 17 Mar 2011 23:28:31 -0000 Subject: [cfe-commits] r127836 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/exceptions.m Message-ID: <20110317232831.4F2102A6C12C@llvm.org> Author: ddunbar Date: Thu Mar 17 18:28:31 2011 New Revision: 127836 URL: http://llvm.org/viewvc/llvm-project?rev=127836&view=rev Log: Driver/Obj-C: Be compatible with GCC behavior in that -fno-exceptions *does not* disable Obj-C exceptions. Added: cfe/trunk/test/Driver/exceptions.m Modified: cfe/trunk/lib/Driver/Tools.cpp Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127836&r1=127835&r2=127836&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Mar 17 18:28:31 2011 @@ -843,25 +843,16 @@ if (ExceptionsEnabled && DidHaveExplicitExceptionFlag) ShouldUseExceptionTables = true; - if (types::isObjC(InputType)) { - bool ObjCExceptionsEnabled = ExceptionsEnabled; + // Obj-C exceptions are enabled by default, regardless of -fexceptions. This + // is not necessarily sensible, but follows GCC. + if (types::isObjC(InputType) && + Args.hasFlag(options::OPT_fobjc_exceptions, + options::OPT_fno_objc_exceptions, + true)) { + CmdArgs.push_back("-fobjc-exceptions"); - if (Arg *A = Args.getLastArg(options::OPT_fobjc_exceptions, - options::OPT_fno_objc_exceptions, - options::OPT_fexceptions, - options::OPT_fno_exceptions)) { - if (A->getOption().matches(options::OPT_fobjc_exceptions)) - ObjCExceptionsEnabled = true; - else if (A->getOption().matches(options::OPT_fno_objc_exceptions)) - ObjCExceptionsEnabled = false; - } - - if (ObjCExceptionsEnabled) { - CmdArgs.push_back("-fobjc-exceptions"); - - ShouldUseExceptionTables |= - shouldUseExceptionTablesForObjCExceptions(Args, Triple); - } + ShouldUseExceptionTables |= + shouldUseExceptionTablesForObjCExceptions(Args, Triple); } if (types::isCXX(InputType)) { Added: cfe/trunk/test/Driver/exceptions.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/exceptions.m?rev=127836&view=auto ============================================================================== --- cfe/trunk/test/Driver/exceptions.m (added) +++ cfe/trunk/test/Driver/exceptions.m Thu Mar 17 18:28:31 2011 @@ -0,0 +1,19 @@ +// RUN: %clang -ccc-host-triple x86_64-apple-darwin9 \ +// RUN: -fsyntax-only -fno-exceptions %s + +void f1() { + @throw @"A"; +} + +void f0() { + @try { + f1(); + } @catch (id x) { + ; + } +} + +int main() { + f0(); + return 0; +} From jorr at apple.com Thu Mar 17 19:04:28 2011 From: jorr at apple.com (James Orr) Date: Thu, 17 Mar 2011 17:04:28 -0700 Subject: [cfe-commits] [PATCH] Add support for cortex-m0 cpu Message-ID: <0D53FF44-3ED3-4ABB-A236-572F07ACBE06@apple.com> Hi, Currently clang supports the cortex-m3 cpu and gcc-llvm supports this and cortex-m0. In order to maintain parity between clang and gcc-llvm this patch adds support for the cortex-m0. Was able to compile firmware and it ran successfully. -arch armv6 -mcpu=cortex-m0 -mthumb -James -------------- next part -------------- A non-text attachment was scrubbed... Name: cortex-m0-cpu-flag-support.diff Type: application/octet-stream Size: 1861 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110317/63d56562/attachment.obj From kd at kendyck.com Thu Mar 17 19:55:06 2011 From: kd at kendyck.com (Ken Dyck) Date: Fri, 18 Mar 2011 00:55:06 -0000 Subject: [cfe-commits] r127844 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110318005506.C7C6F2A6C12C@llvm.org> Author: kjdyck Date: Thu Mar 17 19:55:06 2011 New Revision: 127844 URL: http://llvm.org/viewvc/llvm-project?rev=127844&view=rev Log: Convert variables to CharUnits in ConvertStructToPacked(). No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127844&r1=127843&r2=127844&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Mar 17 19:55:06 2011 @@ -297,36 +297,36 @@ void ConstStructBuilder::ConvertStructToPacked() { std::vector PackedElements; - uint64_t ElementOffsetInBytes = 0; + CharUnits ElementOffsetInChars = CharUnits::Zero(); for (unsigned i = 0, e = Elements.size(); i != e; ++i) { llvm::Constant *C = Elements[i]; unsigned ElementAlign = CGM.getTargetData().getABITypeAlignment(C->getType()); - uint64_t AlignedElementOffsetInBytes = - llvm::RoundUpToAlignment(ElementOffsetInBytes, ElementAlign); + CharUnits AlignedElementOffsetInChars = + ElementOffsetInChars.RoundUpToAlignment( + CharUnits::fromQuantity(ElementAlign)); - if (AlignedElementOffsetInBytes > ElementOffsetInBytes) { + if (AlignedElementOffsetInChars > ElementOffsetInChars) { // We need some padding. - uint64_t NumBytes = - AlignedElementOffsetInBytes - ElementOffsetInBytes; + CharUnits NumChars = + AlignedElementOffsetInChars - ElementOffsetInChars; const llvm::Type *Ty = llvm::Type::getInt8Ty(CGM.getLLVMContext()); - if (NumBytes > 1) - Ty = llvm::ArrayType::get(Ty, NumBytes); + if (NumChars > CharUnits::One()) + Ty = llvm::ArrayType::get(Ty, NumChars.getQuantity()); llvm::Constant *Padding = llvm::UndefValue::get(Ty); PackedElements.push_back(Padding); - ElementOffsetInBytes += getSizeInBytes(Padding); + ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(Padding)); } PackedElements.push_back(C); - ElementOffsetInBytes += getSizeInBytes(C); + ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(C)); } - assert(CharUnits::fromQuantity(ElementOffsetInBytes) == - NextFieldOffsetInChars && + assert(ElementOffsetInChars == NextFieldOffsetInChars && "Packing the struct changed its size!"); Elements = PackedElements; From kd at kendyck.com Thu Mar 17 20:12:13 2011 From: kd at kendyck.com (Ken Dyck) Date: Fri, 18 Mar 2011 01:12:13 -0000 Subject: [cfe-commits] r127846 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110318011213.525302A6C12C@llvm.org> Author: kjdyck Date: Thu Mar 17 20:12:13 2011 New Revision: 127846 URL: http://llvm.org/viewvc/llvm-project?rev=127846&view=rev Log: Convert getSizeInBytes() to getSizeInChars(), which returns its result in CharUnits. No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127846&r1=127845&r2=127846&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Mar 17 20:12:13 2011 @@ -70,8 +70,9 @@ return CGM.getTargetData().getABITypeAlignment(C->getType()); } - uint64_t getSizeInBytes(const llvm::Constant *C) const { - return CGM.getTargetData().getTypeAllocSize(C->getType()); + CharUnits getSizeInChars(const llvm::Constant *C) const { + return CharUnits::fromQuantity( + CGM.getTargetData().getTypeAllocSize(C->getType())); } }; @@ -116,7 +117,7 @@ // Add the field. Elements.push_back(InitCst); NextFieldOffsetInChars = AlignedNextFieldOffsetInChars + - CharUnits::fromQuantity(getSizeInBytes(InitCst)); + getSizeInChars(InitCst); if (Packed) assert(LLVMStructAlignment == 1 && "Packed struct not byte-aligned!"); @@ -285,7 +286,7 @@ Elements.push_back(C); assert(getAlignment(C) == 1 && "Padding must have 1 byte alignment!"); - NextFieldOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(C)); + NextFieldOffsetInChars += getSizeInChars(C); } void ConstStructBuilder::AppendTailPadding(CharUnits RecordSize) { @@ -319,11 +320,11 @@ llvm::Constant *Padding = llvm::UndefValue::get(Ty); PackedElements.push_back(Padding); - ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(Padding)); + ElementOffsetInChars += getSizeInChars(Padding); } PackedElements.push_back(C); - ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(C)); + ElementOffsetInChars += getSizeInChars(C); } assert(ElementOffsetInChars == NextFieldOffsetInChars && @@ -420,9 +421,9 @@ llvm::ConstantStruct::get(CGM.getLLVMContext(), Builder.Elements, Builder.Packed); - assert(llvm::RoundUpToAlignment(Builder.NextFieldOffsetInChars.getQuantity(), - Builder.getAlignment(Result)) == - Builder.getSizeInBytes(Result) && "Size mismatch!"); + assert(Builder.NextFieldOffsetInChars.RoundUpToAlignment( + CharUnits::fromQuantity(Builder.getAlignment(Result))) == + Builder.getSizeInChars(Result) && "Size mismatch!"); return Result; } From kd at kendyck.com Thu Mar 17 20:26:17 2011 From: kd at kendyck.com (Ken Dyck) Date: Fri, 18 Mar 2011 01:26:17 -0000 Subject: [cfe-commits] r127848 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110318012618.067582A6C12C@llvm.org> Author: kjdyck Date: Thu Mar 17 20:26:17 2011 New Revision: 127848 URL: http://llvm.org/viewvc/llvm-project?rev=127848&view=rev Log: Convert alignment values to CharUnits. No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127848&r1=127847&r2=127848&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Mar 17 20:26:17 2011 @@ -39,7 +39,7 @@ bool Packed; CharUnits NextFieldOffsetInChars; - unsigned LLVMStructAlignment; + CharUnits LLVMStructAlignment; std::vector Elements; public: static llvm::Constant *BuildStruct(CodeGenModule &CGM, CodeGenFunction *CGF, @@ -49,7 +49,7 @@ ConstStructBuilder(CodeGenModule &CGM, CodeGenFunction *CGF) : CGM(CGM), CGF(CGF), Packed(false), NextFieldOffsetInChars(CharUnits::Zero()), - LLVMStructAlignment(1) { } + LLVMStructAlignment(CharUnits::One()) { } bool AppendField(const FieldDecl *Field, uint64_t FieldOffset, llvm::Constant *InitExpr); @@ -65,9 +65,10 @@ bool Build(InitListExpr *ILE); - unsigned getAlignment(const llvm::Constant *C) const { - if (Packed) return 1; - return CGM.getTargetData().getABITypeAlignment(C->getType()); + CharUnits getAlignment(const llvm::Constant *C) const { + if (Packed) return CharUnits::One(); + return CharUnits::fromQuantity( + CGM.getTargetData().getABITypeAlignment(C->getType())); } CharUnits getSizeInChars(const llvm::Constant *C) const { @@ -87,12 +88,11 @@ assert(NextFieldOffsetInChars <= FieldOffsetInChars && "Field offset mismatch!"); - unsigned FieldAlignment = getAlignment(InitCst); + CharUnits FieldAlignment = getAlignment(InitCst); // Round up the field offset to the alignment of the field type. CharUnits AlignedNextFieldOffsetInChars = - NextFieldOffsetInChars.RoundUpToAlignment( - CharUnits::fromQuantity(FieldAlignment)); + NextFieldOffsetInChars.RoundUpToAlignment(FieldAlignment); if (AlignedNextFieldOffsetInChars > FieldOffsetInChars) { assert(!Packed && "Alignment is wrong even with a packed struct!"); @@ -120,7 +120,8 @@ getSizeInChars(InitCst); if (Packed) - assert(LLVMStructAlignment == 1 && "Packed struct not byte-aligned!"); + assert(LLVMStructAlignment == CharUnits::One() && + "Packed struct not byte-aligned!"); else LLVMStructAlignment = std::max(LLVMStructAlignment, FieldAlignment); @@ -284,7 +285,8 @@ llvm::Constant *C = llvm::UndefValue::get(Ty); Elements.push_back(C); - assert(getAlignment(C) == 1 && "Padding must have 1 byte alignment!"); + assert(getAlignment(C) == CharUnits::One() && + "Padding must have 1 byte alignment!"); NextFieldOffsetInChars += getSizeInChars(C); } @@ -303,11 +305,10 @@ for (unsigned i = 0, e = Elements.size(); i != e; ++i) { llvm::Constant *C = Elements[i]; - unsigned ElementAlign = - CGM.getTargetData().getABITypeAlignment(C->getType()); + CharUnits ElementAlign = CharUnits::fromQuantity( + CGM.getTargetData().getABITypeAlignment(C->getType())); CharUnits AlignedElementOffsetInChars = - ElementOffsetInChars.RoundUpToAlignment( - CharUnits::fromQuantity(ElementAlign)); + ElementOffsetInChars.RoundUpToAlignment(ElementAlign); if (AlignedElementOffsetInChars > ElementOffsetInChars) { // We need some padding. @@ -331,7 +332,7 @@ "Packing the struct changed its size!"); Elements = PackedElements; - LLVMStructAlignment = 1; + LLVMStructAlignment = CharUnits::One(); Packed = true; } @@ -388,8 +389,7 @@ } CharUnits LLVMSizeInChars = - NextFieldOffsetInChars.RoundUpToAlignment( - CharUnits::fromQuantity(LLVMStructAlignment)); + NextFieldOffsetInChars.RoundUpToAlignment(LLVMStructAlignment); // Check if we need to convert the struct to a packed struct. if (NextFieldOffsetInChars <= LayoutSizeInChars && @@ -422,7 +422,7 @@ Builder.Elements, Builder.Packed); assert(Builder.NextFieldOffsetInChars.RoundUpToAlignment( - CharUnits::fromQuantity(Builder.getAlignment(Result))) == + Builder.getAlignment(Result)) == Builder.getSizeInChars(Result) && "Size mismatch!"); return Result; From joerg at britannica.bec.de Thu Mar 17 20:51:01 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Fri, 18 Mar 2011 02:51:01 +0100 Subject: [cfe-commits] [PATCH] Improved cross-compiling support for calling helper programs In-Reply-To: <20110317221101.GA2865@britannica.bec.de> References: <20110317212447.GA26735@britannica.bec.de> <20110317221101.GA2865@britannica.bec.de> Message-ID: <20110318015101.GA11719@britannica.bec.de> On Thu, Mar 17, 2011 at 11:11:01PM +0100, Joerg Sonnenberger wrote: > I would expect a sane cross-compiling setup for other platforms to be > quite similar. With some additional changes to make the look up for > crt0.o and libgcc honour --sysroot, all that is needed for > cross-compiliation is using "clang -ccc-host-triple i486--netbsdelf > --sysroot $DESTDIR" or adding a symlink and using "i486--netbsdelf-clang > --sysroot $DESTDIR". Attached patch implements the missing parts of --sysroot. I'm not completely happy of moving it to driver, but I wouldn't find an easier way to get to the command line arguments early enough. Again, other platforms likely want to have the same changes. Joerg -------------- next part -------------- A non-text attachment was scrubbed... Name: sysroot.diff Type: text/x-diff Size: 2768 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110318/802bf3df/attachment.bin From kremenek at apple.com Thu Mar 17 21:06:53 2011 From: kremenek at apple.com (Ted Kremenek) Date: Fri, 18 Mar 2011 02:06:53 -0000 Subject: [cfe-commits] r127850 - /cfe/trunk/lib/Parse/ParseAST.cpp Message-ID: <20110318020654.08F3D2A6C12C@llvm.org> Author: kremenek Date: Thu Mar 17 21:06:53 2011 New Revision: 127850 URL: http://llvm.org/viewvc/llvm-project?rev=127850&view=rev Log: Use CrashRecoveryContextCleanup objects to release resources associated with Sema during a crash while parsing. Modified: cfe/trunk/lib/Parse/ParseAST.cpp Modified: cfe/trunk/lib/Parse/ParseAST.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=127850&r1=127849&r2=127850&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseAST.cpp (original) +++ cfe/trunk/lib/Parse/ParseAST.cpp Thu Mar 17 21:06:53 2011 @@ -21,6 +21,7 @@ #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Stmt.h" #include "clang/Parse/Parser.h" +#include "llvm/Support/CrashRecoveryContext.h" #include using namespace clang; @@ -38,6 +39,12 @@ bool CompleteTranslationUnit, CodeCompleteConsumer *CompletionConsumer) { Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer); + + // Recover resources if we crash before exiting this method. + llvm::CrashRecoveryContextCleanupRegistrar + SemaCleanupInCrash(llvm::CrashRecoveryContextCleanup:: + create(&S)); + ParseAST(S, PrintStats); } From kremenek at apple.com Thu Mar 17 21:06:56 2011 From: kremenek at apple.com (Ted Kremenek) Date: Fri, 18 Mar 2011 02:06:56 -0000 Subject: [cfe-commits] r127851 - /cfe/trunk/lib/Frontend/ASTUnit.cpp Message-ID: <20110318020656.410602A6C12D@llvm.org> Author: kremenek Date: Thu Mar 17 21:06:56 2011 New Revision: 127851 URL: http://llvm.org/viewvc/llvm-project?rev=127851&view=rev Log: Use CrashRecoveryContextCleanup objects to recover an ASTUnit if we crash in ASTUnit::LoadFromCommandLine() and ASTUnit::LoadFromCompilerInvocation(). Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=127851&r1=127850&r2=127851&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Mar 17 21:06:56 2011 @@ -44,6 +44,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Timer.h" +#include "llvm/Support/CrashRecoveryContext.h" #include #include #include @@ -500,6 +501,12 @@ unsigned NumRemappedFiles, bool CaptureDiagnostics) { llvm::OwningPtr AST(new ASTUnit(true)); + + // Recover resources if we crash before exiting this method. + llvm::CrashRecoveryContextCleanupRegistrar + ASTUnitCleanup(llvm::CrashRecoveryContextCleanup:: + create(AST.get())); + ConfigureDiags(Diags, 0, 0, *AST, CaptureDiagnostics); AST->OnlyLocalDecls = OnlyLocalDecls; @@ -1579,6 +1586,11 @@ AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; AST->Invocation.reset(CI); + // Recover resources if we crash before exiting this method. + llvm::CrashRecoveryContextCleanupRegistrar + ASTUnitCleanup(llvm::CrashRecoveryContextCleanup:: + create(AST.get())); + return AST->LoadFromCompilerInvocation(PrecompilePreamble)? 0 : AST.take(); } @@ -1704,6 +1716,12 @@ AST->NumStoredDiagnosticsInPreamble = StoredDiagnostics.size(); AST->StoredDiagnostics.swap(StoredDiagnostics); AST->Invocation.reset(CI.take()); + + // Recover resources if we crash before exiting this method. + llvm::CrashRecoveryContextCleanupRegistrar + ASTUnitCleanup(llvm::CrashRecoveryContextCleanup:: + create(AST.get())); + return AST->LoadFromCompilerInvocation(PrecompilePreamble) ? 0 : AST.take(); } From joerg at britannica.bec.de Thu Mar 17 21:32:27 2011 From: joerg at britannica.bec.de (Joerg Sonnenberger) Date: Fri, 18 Mar 2011 03:32:27 +0100 Subject: [cfe-commits] [PATCH] Improved cross-compiling support for calling helper programs In-Reply-To: <20110318015101.GA11719@britannica.bec.de> References: <20110317212447.GA26735@britannica.bec.de> <20110317221101.GA2865@britannica.bec.de> <20110318015101.GA11719@britannica.bec.de> Message-ID: <20110318023227.GA21009@britannica.bec.de> On Fri, Mar 18, 2011 at 02:51:01AM +0100, Joerg Sonnenberger wrote: > On Thu, Mar 17, 2011 at 11:11:01PM +0100, Joerg Sonnenberger wrote: > > I would expect a sane cross-compiling setup for other platforms to be > > quite similar. With some additional changes to make the look up for > > crt0.o and libgcc honour --sysroot, all that is needed for > > cross-compiliation is using "clang -ccc-host-triple i486--netbsdelf > > --sysroot $DESTDIR" or adding a symlink and using "i486--netbsdelf-clang > > --sysroot $DESTDIR". > > Attached patch implements the missing parts of --sysroot. I'm not > completely happy of moving it to driver, but I wouldn't find an easier > way to get to the command line arguments early enough. > > Again, other platforms likely want to have the same changes. Better version. This makes -B =/foobar work as side effect. Note the --sysroot invocation for linuxtools::Link::ConstructJob should be checked. At least the version of ld I have doesn't allow "--sysroot /foo", but requires "--sysroot=/foo" (without error). Joerg -------------- next part -------------- A non-text attachment was scrubbed... Name: sysroot.diff Type: text/x-diff Size: 3676 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110318/53a6fd93/attachment.bin From rjmccall at apple.com Thu Mar 17 21:56:14 2011 From: rjmccall at apple.com (John McCall) Date: Fri, 18 Mar 2011 02:56:14 -0000 Subject: [cfe-commits] r127854 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CGDeclCXX.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGenCXX/apple-kext-guard-variable.cpp Message-ID: <20110318025614.ADA9A2A6C12C@llvm.org> Author: rjmccall Date: Thu Mar 17 21:56:14 2011 New Revision: 127854 URL: http://llvm.org/viewvc/llvm-project?rev=127854&view=rev Log: The Darwin kernel does not provide useful guard variable support. Issue this as an IR-gen error; it's not really worthwhile doing this "right", i.e. in Sema, because IR gen knows a lot of tricks beyond what the constant evaluator knows. Added: cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp Modified: cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/Frontend/CodeGenOptions.h cfe/trunk/lib/CodeGen/CGDeclCXX.cpp cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/CodeGen/CodeGenModule.h cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Mar 17 21:56:14 2011 @@ -110,6 +110,8 @@ HelpText<"Do not emit code that uses the red zone.">; def dwarf_debug_flags : Separate<"-dwarf-debug-flags">, HelpText<"The string to embed in the Dwarf debug flags record.">; +def fforbid_guard_variables : Flag<"-fforbid-guard-variables">, + HelpText<"Emit an error if a C++ static local initializer would need a guard variable">; def g : Flag<"-g">, HelpText<"Generate source level debug information">; def fcatch_undefined_behavior : Flag<"-fcatch-undefined-behavior">, HelpText<"Generate runtime checks for undefined behavior.">; Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original) +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Thu Mar 17 21:56:14 2011 @@ -51,6 +51,8 @@ /// Decl* various IR entities came from. Only /// useful when running CodeGen as a /// subroutine. + unsigned ForbidGuardVariables : 1; /// Issue errors if C++ guard variables + /// are required unsigned FunctionSections : 1; /// Set when -ffunction-sections is enabled unsigned HiddenWeakTemplateVTables : 1; /// Emit weak vtables and RTTI for /// template classes with hidden visibility @@ -128,6 +130,7 @@ DisableLLVMOpts = 0; DisableRedZone = 0; EmitDeclMetadata = 0; + ForbidGuardVariables = 0; FunctionSections = 0; HiddenWeakTemplateVTables = 0; HiddenWeakVTables = 0; Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Thu Mar 17 21:56:14 2011 @@ -149,6 +149,14 @@ void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr) { + // If we've been asked to forbid guard variables, emit an error now. + // This diagnostic is hard-coded for Darwin's use case; we can find + // better phrasing if someone else needs it. + if (CGM.getCodeGenOpts().ForbidGuardVariables) + CGM.Error(D.getLocation(), + "this initialization requires a guard variable, which " + "the kernel does not support"); + CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr); } Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Mar 17 21:56:14 2011 @@ -154,6 +154,11 @@ return getContext().Target.getTriple().getOS() == llvm::Triple::Darwin; } +void CodeGenModule::Error(SourceLocation loc, llvm::StringRef error) { + unsigned diagID = getDiags().getCustomDiagID(Diagnostic::Error, error); + getDiags().Report(Context.getFullLoc(loc), diagID); +} + /// ErrorUnsupported - Print out an error that codegen doesn't support the /// specified stmt yet. void CodeGenModule::ErrorUnsupported(const Stmt *S, const char *Type, Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.h (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Mar 17 21:56:14 2011 @@ -527,6 +527,9 @@ llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, const AnnotateAttr *AA, unsigned LineNo); + /// Error - Emit a general error that something can't be done. + void Error(SourceLocation loc, llvm::StringRef error); + /// ErrorUnsupported - Print out an error that codegen doesn't support the /// specified stmt yet. /// \param OmitOnError - If true, then this error should only be emitted if no Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Mar 17 21:56:14 2011 @@ -1138,6 +1138,12 @@ if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin) CmdArgs.push_back("-mconstructor-aliases"); + // Darwin's kernel doesn't support guard variables; just die if we + // try to use them. + if (KernelOrKext && + getToolChain().getTriple().getOS() == llvm::Triple::Darwin) + CmdArgs.push_back("-fforbid-guard-variables"); + if (Args.hasArg(options::OPT_mms_bitfields)) { CmdArgs.push_back("-mms-bitfields"); } Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=127854&r1=127853&r2=127854&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Mar 17 21:56:14 2011 @@ -127,6 +127,8 @@ Res.push_back("-fno-merge-all-constants"); if (Opts.NoCommon) Res.push_back("-fno-common"); + if (Opts.ForbidGuardVariables) + Res.push_back("-fforbid-guard-variables"); if (Opts.NoImplicitFloat) Res.push_back("-no-implicit-float"); if (Opts.OmitLeafFramePointer) @@ -896,6 +898,7 @@ Opts.LimitDebugInfo = Args.hasArg(OPT_flimit_debug_info); Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); + Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants); Added: cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp?rev=127854&view=auto ============================================================================== --- cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp (added) +++ cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp Thu Mar 17 21:56:14 2011 @@ -0,0 +1,9 @@ +// RUN: %clang -mtriple=x86_64-apple-darwin10 -S -mkernel -Xclang -verify %s + +// rdar://problem/9143356 + +int foo(); +void test() { + static int y = 0; + static int x = foo(); // expected-error {{this initialization requires a guard variable, which the kernel does not support}} +} From geek4civic at gmail.com Thu Mar 17 22:21:26 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 03:21:26 -0000 Subject: [cfe-commits] r127860 - /cfe/trunk/test/Driver/darwin-cc.c Message-ID: <20110318032126.8A5462A6C12C@llvm.org> Author: chapuni Date: Thu Mar 17 22:21:26 2011 New Revision: 127860 URL: http://llvm.org/viewvc/llvm-project?rev=127860&view=rev Log: test/Driver/darwin-cc.c: FileCheck-ize and tweak for Mingw MSYS bash. MSYS substitutes path (that begins with "/") to de-mounted Windows path. "/tmp" might be substituted as "C:/DOCUME~1/chapuni/LOCALS~1/Temp". Modified: cfe/trunk/test/Driver/darwin-cc.c Modified: cfe/trunk/test/Driver/darwin-cc.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-cc.c?rev=127860&r1=127859&r2=127860&view=diff ============================================================================== --- cfe/trunk/test/Driver/darwin-cc.c (original) +++ cfe/trunk/test/Driver/darwin-cc.c Thu Mar 17 22:21:26 2011 @@ -1,5 +1,4 @@ // RUN: %clang -ccc-no-clang -ccc-host-triple i386-apple-darwin10 -m32 -### -MD -g -fast -Q -dA -mkernel -ansi -aFOO -S -o /tmp/OUTPUTNAME -g0 -gfull -O2 -Werror -pedantic -Wmost -w -std=c99 -trigraphs -v -pg -fFOO -undef -Qn --param a=b -fmudflap -coverage -save-temps -nostdinc -I ARG0 -F ARG1 -I ARG2 -P -MF ARG3 -MG -MP -remap -g3 -H -D ARG4 -U ARG5 -A ARG6 -D ARG7 -U ARG8 -A ARG9 -include ARG10 -pthread %s 2> %t.log -// RUN: grep ' ".*cc1" "-E" "-nostdinc" "-v" "-I" "ARG0" "-FARG1" "-I" "ARG2" "-P" "-MD" "/tmp/OUTPUTNAME.d" "-MF" "ARG3" "-MG" "-MP" "-MQ" "/tmp/OUTPUTNAME" "-remap" "-dD" "-H" "-D__STATIC__" "-D_REENTRANT" "-D" "ARG4" "-U" "ARG5" "-A" "ARG6" "-D" "ARG7" "-U" "ARG8" "-A" "ARG9" "-include" "ARG10" ".*darwin-cc.c" "-D_MUDFLAP" "-include" "mf-runtime.h" "-m32" "-mkernel" "-mtune=core2" "-mmacosx-version-min=10.6.0" "-ansi" "-std=c99" "-trigraphs" "-Werror" "-pedantic" "-Wmost" "-w" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-O2" "-undef" "-fpch-preprocess" "-o" ".*darwin-cc.i"' %t.log -// RUN: grep ' ".*cc1" "-fpreprocessed" ".*darwin-cc.i" "-O3" "-dumpbase" ".*darwin-cc.c" "-dA" "-m32" "-mkernel" "-mtune=core2" "-mmacosx-version-min=10.6.0" "-ansi" "-aFOO" "-auxbase-strip" "/tmp/OUTPUTNAME" "-g" "-g0" "-g" "-g3" "-O2" "-Werror" "-pedantic" "-Wmost" "-w" "-ansi" "-std=c99" "-trigraphs" "-version" "-p" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-undef" "-fno-ident" "-o" "/tmp/OUTPUTNAME" "--param" "a=b" "-fno-builtin" "-fno-merge-constants" "-fprofile-arcs" "-ftest-coverage"' %t.log - - +// RUN: FileCheck %s < %t.log +// CHECK: {{ ".*cc1.*" "-E" "-nostdinc" "-v" "-I" "ARG0" "-FARG1" "-I" "ARG2" "-P" "-MD" "[^"]*/OUTPUTNAME.d" "-MF" "ARG3" "-MG" "-MP" "-MQ" "[^"]*/OUTPUTNAME" "-remap" "-dD" "-H" "-D__STATIC__" "-D_REENTRANT" "-D" "ARG4" "-U" "ARG5" "-A" "ARG6" "-D" "ARG7" "-U" "ARG8" "-A" "ARG9" "-include" "ARG10" ".*darwin-cc.c" "-D_MUDFLAP" "-include" "mf-runtime.h" "-m32" "-mkernel" "-mtune=core2" "-mmacosx-version-min=10.6.0" "-ansi" "-std=c99" "-trigraphs" "-Werror" "-pedantic" "-Wmost" "-w" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-O2" "-undef" "-fpch-preprocess" "-o" ".*darwin-cc.i"}} +// CHECK: {{ ".*cc1.*" "-fpreprocessed" ".*darwin-cc.i" "-O3" "-dumpbase" ".*darwin-cc.c" "-dA" "-m32" "-mkernel" "-mtune=core2" "-mmacosx-version-min=10.6.0" "-ansi" "-aFOO" "-auxbase-strip" "[^"]*/OUTPUTNAME" "-g" "-g0" "-g" "-g3" "-O2" "-Werror" "-pedantic" "-Wmost" "-w" "-ansi" "-std=c99" "-trigraphs" "-version" "-p" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-undef" "-fno-ident" "-o" "[^"]*/OUTPUTNAME" "--param" "a=b" "-fno-builtin" "-fno-merge-constants" "-fprofile-arcs" "-ftest-coverage"}} From geek4civic at gmail.com Thu Mar 17 22:21:33 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 03:21:33 -0000 Subject: [cfe-commits] r127861 - /cfe/trunk/test/Driver/sysroot-flags.c Message-ID: <20110318032133.427702A6C12D@llvm.org> Author: chapuni Date: Thu Mar 17 22:21:33 2011 New Revision: 127861 URL: http://llvm.org/viewvc/llvm-project?rev=127861&view=rev Log: test/Driver/sysroot-flags.c: Tweak for Mingw MSYS bash. MSYS substitutes path (that begins with "/") to de-mounted Windows path, even if it were nonexistent. "/foo/bar" might be substituted to "C:/msysgit/foo/bar". Modified: cfe/trunk/test/Driver/sysroot-flags.c Modified: cfe/trunk/test/Driver/sysroot-flags.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sysroot-flags.c?rev=127861&r1=127860&r2=127861&view=diff ============================================================================== --- cfe/trunk/test/Driver/sysroot-flags.c (original) +++ cfe/trunk/test/Driver/sysroot-flags.c Thu Mar 17 22:21:33 2011 @@ -2,27 +2,27 @@ // RUN: %clang -### -fsyntax-only -isysroot /foo/bar %s 2>&1 | \ // RUN: FileCheck %s -check-prefix=ISYSROOT -// ISYSROOT: "-isysroot" "/foo/bar" +// ISYSROOT: "-isysroot" "{{[^"]*}}/foo/bar" // Check that we get both isysroot for headers, and pass --sysroot on to GCC to // produce the final binary. // RUN: %clang -### -ccc-host-triple x86_64-unknown-linux-gnu \ // RUN: --sysroot=/foo/bar -o /dev/null %s 2>&1 | \ // RUN: FileCheck %s -check-prefix=SYSROOT_EQ -// SYSROOT_EQ: "-isysroot" "/foo/bar" -// SYSROOT_EQ: "--sysroot{{" "|=}}/foo/bar" +// SYSROOT_EQ: "-isysroot" "{{[^"]*}}/foo/bar" +// SYSROOT_EQ: "--sysroot{{" "|=}}{{[^"]*}}/foo/bar" // Check for overriding the header sysroot by providing both --sysroot and // -isysroot. // RUN: %clang -### -ccc-host-triple x86_64-unknown-linux-gnu -isysroot /baz \ // RUN: --sysroot=/foo/bar -o /dev/null %s 2>&1 | FileCheck %s \ // RUN: -check-prefix=ISYSROOT_AND_SYSROOT -// ISYSROOT_AND_SYSROOT: "-isysroot" "/baz" -// ISYSROOT_AND_SYSROOT: "--sysroot{{" "|=}}/foo/bar" +// ISYSROOT_AND_SYSROOT: "-isysroot" "{{[^"]*}}/baz" +// ISYSROOT_AND_SYSROOT: "--sysroot{{" "|=}}{{[^"]*}}/foo/bar" // Check that omitting the equals works as well. // RUN: %clang -### -ccc-host-triple x86_64-unknown-linux-gnu \ // RUN: --sysroot /foo/bar -o /dev/null %s 2>&1 | \ // RUN: FileCheck %s -check-prefix=SYSROOT_SEPARATE -// SYSROOT_SEPARATE: "-isysroot" "/foo/bar" -// SYSROOT_SEPARATE: "--sysroot{{" "|=}}/foo/bar" +// SYSROOT_SEPARATE: "-isysroot" "{{[^"]*}}/foo/bar" +// SYSROOT_SEPARATE: "--sysroot{{" "|=}}{{[^"]*}}/foo/bar" From geek4civic at gmail.com Thu Mar 17 22:21:38 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 03:21:38 -0000 Subject: [cfe-commits] r127862 - /cfe/trunk/www/hacking.html Message-ID: <20110318032138.AFBFD2A6C12C@llvm.org> Author: chapuni Date: Thu Mar 17 22:21:38 2011 New Revision: 127862 URL: http://llvm.org/viewvc/llvm-project?rev=127862&view=rev Log: www/hacking.html: Cosmetic change, to detabify, eliminate whitespace, and add proper slashes to URL. Modified: cfe/trunk/www/hacking.html Modified: cfe/trunk/www/hacking.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/hacking.html?rev=127862&r1=127861&r2=127862&view=diff ============================================================================== --- cfe/trunk/www/hacking.html (original) +++ cfe/trunk/www/hacking.html Thu Mar 17 22:21:38 2011 @@ -1,4 +1,4 @@ - @@ -14,7 +14,7 @@

    Hacking on Clang

    - +

    This document provides some hints for how to get started hacking on Clang for developers who are new to the Clang and/or LLVM codebases.

    @@ -24,18 +24,18 @@
  • Debugging
  • Testing
  • +
  • Testing on Unix-like Systems
  • +
  • Testing using Visual Studio on Windows
  • +
  • Testing on the Command Line
  • +
  • Creating Patch Files
  • LLVM IR Generation
  • - +

    Coding Standards

    - +

    Clang follows the LLVM Coding Standards. When submitting patches, please take care to follow these standards @@ -56,14 +56,14 @@

    Developer Documentation

    - +

    Both Clang and LLVM use doxygen to provide API documentation. Their respective web pages (generated nightly) are here:

    - +

    For work on the LLVM IR generation, the LLVM assembly language reference manual is also useful.

    @@ -71,7 +71,7 @@

    Debugging

    - +

    Inspecting data structures in a debugger:

    • Many LLVM and Clang data structures provide @@ -84,18 +84,18 @@ qualifiers, and the getTypePtr() method to get the wrapped Type* which you can then dump.
    - +

    Testing

    - +

    [Note: The test running mechanism is currently under revision, so the following might change shortly.]

    - +

    Testing on Unix-like Systems

    - +

    Clang includes a basic regression suite in the tree which can be run with make test from the top-level clang directory, or just make in the test sub-directory. @@ -113,15 +113,15 @@ the test runner that an error is expected at the current line. Any output files produced by the test will be placed under a created Output directory.

    - +

    During the run of make test, the terminal output will display a line similar to the following:

    - +
      --- Running clang tests for i686-pc-linux-gnu ---
    - +

    followed by a line continually overwritten with the current test file being compiled, and an overall completion percentage.

    - +

    After the make test run completes, the absence of any Failing Tests (count): message indicates that no tests failed unexpectedly. If any tests did fail, the @@ -148,38 +148,38 @@ override LLVMGCC, as in: make LLVMGCC="clang -std=gnu89" TEST=nightly report (make sure clang is in your PATH or use the full path).

    - +

    Testing using Visual Studio on Windows

    The Clang test suite can be run from either Visual Studio or the command line.

    - +

    Note that the test runner is based on Python, which must be installed. Find Python at: - http://www.python.org/download. + http://www.python.org/download/. Download the latest stable version (2.6.2 at the time of this writing).

    - +

    The GnuWin32 tools are also necessary for running the tests. (Note that the grep from MSYS or Cygwin doesn't work with the tests because of embedded double-quotes in the search strings. The GNU grep does work in this case.) - Get them from - http://getgnuwin32.sourceforge.net.

    - + Get them from + http://getgnuwin32.sourceforge.net/.

    +

    The cmake build tool is set up to create Visual Studio project files for running the tests, "clang-test" being the root. Therefore, to run the test from Visual Studio, right-click the clang-test project and select "Build".

    - +

    Testing on the Command Line

    To run all the tests from the command line, execute a command like the following:

    - + python (path to llvm)/llvm/utils/lit/lit.py -sv --no-progress-bar (path to llvm)/llvm/tools/clang/test @@ -190,14 +190,14 @@ --param=build_config=(build config).

    To run a single test:

    - + python (path to llvm)/llvm/utils/lit/lit.py -sv --no-progress-bar (path to llvm)/llvm/tools/clang/test/(dir)/(test)

    For example:

    - + python C:/Tools/llvm/utils/lit/lit.py -sv --no-progress-bar C:/Tools/llvm/tools/clang/test/Sema/wchar.c @@ -215,7 +215,7 @@ Expected Passes : 2503 Expected Failures : 28 Unsupported Tests : 3 - +

    The statistic, "Unexpected Failures" (not shown if all tests pass), is the important one.

    @@ -230,18 +230,18 @@ you are doing, such as if you are new to Clang development, you can use the cfe-dev mailing list also.

    - +

    To create these patch files, change directory to the llvm/tools/clang root and run:

    - +
      svn diff (relative path) >(patch file name)

    For example, for getting the diffs of all of clang:

    - +
      svn diff . >~/mypatchfile.patch

    For example, for getting the diffs of a single file:

    - +
      svn diff lib/Parse/ParseDeclCXX.cpp >~/ParseDeclCXX.patch

    Note that the paths embedded in the patch depend on where you run it, @@ -256,7 +256,7 @@ Representation (IR). Historically, this was referred to as "codegen", and the Clang code for this lives in lib/CodeGen.

    - +

    The output is most easily inspected using the -emit-llvm option to clang (possibly in conjunction with -o -). You can also use -emit-llvm-bc to write an LLVM bitcode file From geek4civic at gmail.com Thu Mar 17 22:21:44 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 03:21:44 -0000 Subject: [cfe-commits] r127863 - /cfe/trunk/www/hacking.html Message-ID: <20110318032144.A20E82A6C12D@llvm.org> Author: chapuni Date: Thu Mar 17 22:21:44 2011 New Revision: 127863 URL: http://llvm.org/viewvc/llvm-project?rev=127863&view=rev Log: www/hacking.html: Add blurb of LLVM_LIT_TOOLS_DIR. Modified: cfe/trunk/www/hacking.html Modified: cfe/trunk/www/hacking.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/hacking.html?rev=127863&r1=127862&r2=127863&view=diff ============================================================================== --- cfe/trunk/www/hacking.html (original) +++ cfe/trunk/www/hacking.html Thu Mar 17 22:21:44 2011 @@ -162,17 +162,25 @@ Download the latest stable version (2.6.2 at the time of this writing).

    The GnuWin32 tools are also necessary for running the tests. - (Note that the grep from MSYS or Cygwin doesn't work with the tests - because of embedded double-quotes in the search strings. The GNU - grep does work in this case.) Get them from - http://getgnuwin32.sourceforge.net/.

    + http://getgnuwin32.sourceforge.net/. + If the environment variable %PATH% does not have GnuWin32, + or if other grep(s) supercedes GnuWin32 on %PATH%, + you should specify LLVM_LIT_TOOLS_DIR + to CMake explicitly.

    The cmake build tool is set up to create Visual Studio project files for running the tests, "clang-test" being the root. Therefore, to run the test from Visual Studio, right-click the clang-test project and select "Build".

    +

    + Please see also + Getting Started + with the LLVM System using Microsoft Visual Studio and + Building LLVM with CMake. +

    +

    Testing on the Command Line

    From kremenek at apple.com Thu Mar 17 22:44:21 2011 From: kremenek at apple.com (Ted Kremenek) Date: Fri, 18 Mar 2011 03:44:21 -0000 Subject: [cfe-commits] r127864 - /cfe/trunk/lib/Parse/ParseAST.cpp Message-ID: <20110318034422.036B22A6C12C@llvm.org> Author: kremenek Date: Thu Mar 17 22:44:21 2011 New Revision: 127864 URL: http://llvm.org/viewvc/llvm-project?rev=127864&view=rev Log: Construct 'Sema' object on the stack, so that crash recovery can recovery it's associated resources without walking over dead stack space. Modified: cfe/trunk/lib/Parse/ParseAST.cpp Modified: cfe/trunk/lib/Parse/ParseAST.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=127864&r1=127863&r2=127864&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseAST.cpp (original) +++ cfe/trunk/lib/Parse/ParseAST.cpp Thu Mar 17 22:44:21 2011 @@ -21,6 +21,7 @@ #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Stmt.h" #include "clang/Parse/Parser.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/CrashRecoveryContext.h" #include @@ -38,14 +39,17 @@ ASTContext &Ctx, bool PrintStats, bool CompleteTranslationUnit, CodeCompleteConsumer *CompletionConsumer) { - Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer); + + llvm::OwningPtr S(new Sema(PP, Ctx, *Consumer, + CompleteTranslationUnit, + CompletionConsumer)); // Recover resources if we crash before exiting this method. llvm::CrashRecoveryContextCleanupRegistrar SemaCleanupInCrash(llvm::CrashRecoveryContextCleanup:: - create(&S)); + create(S.get())); - ParseAST(S, PrintStats); + ParseAST(*S.get(), PrintStats); } void clang::ParseAST(Sema &S, bool PrintStats) { From rjmccall at apple.com Thu Mar 17 22:51:49 2011 From: rjmccall at apple.com (John McCall) Date: Fri, 18 Mar 2011 03:51:49 -0000 Subject: [cfe-commits] r127866 - /cfe/trunk/docs/LanguageExtensions.html Message-ID: <20110318035149.A3AAE2A6C12C@llvm.org> Author: rjmccall Date: Thu Mar 17 22:51:49 2011 New Revision: 127866 URL: http://llvm.org/viewvc/llvm-project?rev=127866&view=rev Log: Improve the documentation for some of the analyzer attributes I added a while back. Modified: cfe/trunk/docs/LanguageExtensions.html Modified: cfe/trunk/docs/LanguageExtensions.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=127866&r1=127865&r2=127866&view=diff ============================================================================== --- cfe/trunk/docs/LanguageExtensions.html (original) +++ cfe/trunk/docs/LanguageExtensions.html Thu Mar 17 22:51:49 2011 @@ -62,11 +62,7 @@
  • X86/X86-64 Language Extensions
  • -
  • Static Analysis-Specific Extensions - -
  • +
  • Static Analysis-Specific Extensions
  • @@ -760,11 +756,7 @@ href="http://clang.llvm.org/StaticAnalysis.html">path-sensitive static analyzer engine that is part of Clang's Analysis library.

    - -

    Analyzer Attributes

    - - -

    analyzer_noreturn

    +

    The analyzer_noreturn attribute

    Clang's static analysis engine understands the standard noreturn attribute. This attribute, which is typically affixed to a function prototype, @@ -792,16 +784,47 @@ void foo() __attribute__((analyzer_noreturn)); -

    Query for this feature with __has_feature(attribute_analyzer_noreturn).

    +

    Query for this feature with +__has_attribute(analyzer_noreturn).

    + +

    The objc_method_family attribute

    + +

    Many methods in Objective-C have conventional meanings determined +by their selectors. For the purposes of static analysis, it is +sometimes useful to be able to mark a method as having a particular +conventional meaning despite not having the right selector, or as not +having the conventional meaning that its selector would suggest. +For these use cases, we provide an attribute to specifically describe +the method family that a method belongs to.

    + +

    Usage: __attribute__((objc_method_family(X))), +where X is one of none, alloc, copy, +init, mutableCopy, or new. This attribute +can only be placed at the end of a method declaration:

    + +
    +  - (NSString*) initMyStringValue __attribute__((objc_method_family(none)));
    +
    + +

    Users who do not wish to change the conventional meaning of a +method, and who merely want to document its non-standard retain and +release semantics, should use the +retaining behavior attributes +described below.

    + +

    Query for this feature with +__has_attribute(objc_method_family).

    -

    Objective-C retaining behavior attributes

    +

    Objective-C retaining behavior attributes

    In Objective-C, functions and methods are generally assumed to take and return objects with +0 retain counts, with some exceptions for special methods like +alloc and init. However, there are exceptions, and so Clang provides attributes to allow these exceptions to be documented, which helps the analyzer find leaks (and -ignore non-leaks).

    +ignore non-leaks). Some exceptions may be better described using +the objc_method_family +attribute instead.

    Usage: The ns_returns_retained, ns_returns_not_retained, ns_returns_autoreleased, cf_returns_retained, @@ -840,6 +863,9 @@ - (void) baz: (id) __attribute__((ns_consumed)) x; +

    Query for these features with __has_attribute(ns_consumed), +__has_attribute(ns_returns_retained), etc.

    + From geek4civic at gmail.com Thu Mar 17 23:46:08 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 04:46:08 -0000 Subject: [cfe-commits] r127869 - /cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp Message-ID: <20110318044608.392AD2A6C12C@llvm.org> Author: chapuni Date: Thu Mar 17 23:46:08 2011 New Revision: 127869 URL: http://llvm.org/viewvc/llvm-project?rev=127869&view=rev Log: test/CodeGenCXX/apple-kext-guard-variable.cpp: May I appease non-darwin hosts? Modified: cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp Modified: cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp?rev=127869&r1=127868&r2=127869&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp (original) +++ cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp Thu Mar 17 23:46:08 2011 @@ -1,4 +1,4 @@ -// RUN: %clang -mtriple=x86_64-apple-darwin10 -S -mkernel -Xclang -verify %s +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -S -mkernel -Xclang -verify %s // rdar://problem/9143356 From geek4civic at gmail.com Thu Mar 17 23:52:40 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 13:52:40 +0900 Subject: [cfe-commits] r127854 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CGDeclCXX.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/Driver/Tools.cpp lib/Frontend/CompilerInvoca Message-ID: > Author: rjmccall > Date: Thu Mar 17 21:56:14 2011 > New Revision: 127854 > +// RUN: %clang -mtriple=x86_64-apple-darwin10 -S -mkernel -Xclang -verify %s I believe r127869 should fix failure. Could you reconfirm whether it is reasonable or not? ...Takumi From jorr at apple.com Fri Mar 18 04:06:06 2011 From: jorr at apple.com (James Orr) Date: Fri, 18 Mar 2011 02:06:06 -0700 Subject: [cfe-commits] [PATCH] Add support for cortex-m0 cpu In-Reply-To: <0D53FF44-3ED3-4ABB-A236-572F07ACBE06@apple.com> References: <0D53FF44-3ED3-4ABB-A236-572F07ACBE06@apple.com> Message-ID: On Mar 17, 2011, at 5:04 PM, James Orr wrote: > Hi, > > Currently clang supports the cortex-m3 cpu and gcc-llvm supports this and cortex-m0. In order to maintain parity between clang and gcc-llvm this patch adds support for the cortex-m0. > > Was able to compile firmware and it ran successfully. > > -arch armv6 -mcpu=cortex-m0 -mthumb > > -James > The previous patch was sending the triple "thumb-apple-darwin10.0.0". Updated it to use: "thumbv6m-apple-darwin10.0.0" for Cortex-M0 and "thumbv7m-apple-darwin10.0.0" for Cortex-M3. These are the same arch part of the triples as used by llvm-gcc. -James -------------- next part -------------- A non-text attachment was scrubbed... Name: cortex-m0-cpu-flag-support.diff Type: application/octet-stream Size: 1625 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110318/21fa9d91/attachment.obj From jim at thegoodnows.net Fri Mar 18 06:04:18 2011 From: jim at thegoodnows.net (Jim Goodnow II) Date: Fri, 18 Mar 2011 04:04:18 -0700 Subject: [cfe-commits] [Patch][review request]update to IteratorsChecker In-Reply-To: References: <0LI4001G5UEISX50@postino.apple.com> Message-ID: <201103181104.p2IB4YPt006044@relay05.cites.uiuc.edu> Hi Ted, Okay, I agree and that was what I had originally intended, but ran into difficulties implementing it. So, as a first step, let's talk just about something simple: it = v.begin(); Conceptually, the MemberCall for begin() returns a symbol region which I mark as BeginValid. It is also linked with the MemRegion associated with the instance or really any 'TypedRegion' associated with the Base of the MemberCall which is the instance. When the symbol region is assigned to the iterator, 'it', the BeginValid state gets propogated to the MemRegion associated with the iterator. First, does the returned symbol region actually get created by the engine or do I have to do that in checkPostStmt(CXXMemberCall) or somewhere else? Second, do I still need to handle the assignment in OperatorCall since it is essentially a structure/class assignment or will that be handled by the Engine logic? - jim At 10:54 PM 3/15/2011, Ted Kremenek wrote: >Hi Jim, > >While a nice increment on top of the existing checker, I think this >takes the checker in a more syntactic direction, which isn't going >to be a general solution. Instead of pattern matching on specific >expressions, we should instead move the checker in a direction where >it just lets the analyzer engine handle evaluating the semantics of >expressions and have the checker look at SVals and MemRegions (i.e., >the "semantics" instead of the "syntax"). > >For example, in checkPreStmt(CXXMemberCallExpr), there is no reason >we need to rely on the base expression being a >DeclRefExpr. Instead, we can just let the analyzer engine evaluate >that subexpression; if that expression evaluates to a MemRegion, >then we can proceed. There is no reason to make this dependent on >DeclRefExpr, or any other expression, that evaluates to what we care >about. Here's a suggested change: > >@@ -549,11 +554,11 @@ void IteratorsChecker::checkPreStmt(const >CXXMemberCallExpr *MCE, > const MemberExpr *ME = dyn_cast(MCE->getCallee()); > if (!ME) > return; >+ const Expr *exp = ME->getBase(); > // Make sure we have the right kind of container. >- const DeclRefExpr *DRE = dyn_cast(ME->getBase()); >- if (!DRE || getTemplateKind(DRE->getType()) != VectorKind) >+ if (getTemplateKind(exp->getType()) != VectorKind) > return; >- SVal tsv = C.getState()->getSVal(DRE); >+ SVal tsv = C.getState()->getSVal(exp); > >Note that this differs from your patch. There is no reason to match >against implicit casts or pointer types. We just reason about the >values the analyzer engine gives us. > >Probably what needs to be reworked to fully generalize the checker >to work with arbitrary expressions is 'handleAssign'. handleAssign >does a bunch of AST pattern matching, looking that specific >expressions appeared on the RHS of the assignment. While syntactic >pattern matching is easy to understand, it isn't fully >general. Instead, we should just let the analyzer engine evaluate >each subexpression, and track what information we need to implement >the checker through the associated SVals. > >For example, I would expect the handling of 'begin', 'insert', >'erase', and 'end' to be in a checkerPostStmt(const >CXXMemberCallExpr). These would then toggle the state associated >with the target of the method call (which would be a >MemRegion). For 'begin' and 'end', the call returns a value, which >the analyzer engine will likely make a SymbolRegion. For that >SymbolicRegion, we can associate checker-specific state in the GDM >saying that MemRegion represents and iterator associated with a >specific container. Indeed, your checker already does this: > > typedef llvm::ImmutableMap EntryMap; > >In other words, let the analyzer engine do the work of propagating >values around and evaluating subexpressions, and let your checker >add "instrumentation" at key points (namely before and after method >calls) to toggle the iterator state. Once this restructuring is in >place, you can probably remove 'handleAssign' entirely. > >There's also no reason to restrict the container to >'VarRegions'. Any 'TypedRegion' should probably work. This will >allow your checker to immediately fully generalize to cases the >checker doesn't consider, e.g.: > > void test(std::vector **x) { > std::vector::iterator itr = (*x)->begin(); > ... > } > >If you let the analyzer handle the abstraction of memory and the >evaluation of expressions, you don't need to reason syntactically >about all these corner cases. Everything just composes, and works >as you would expect. > >On Mar 15, 2011, at 9:13 PM, Jim Goodnow II wrote: > > > Added support for handling pointers to containers that wasn't handled. > > > > - jim > > > > Index: test/Analysis/iterators.cpp > > =================================================================== > > --- test/Analysis/iterators.cpp (revision 127607) > > +++ test/Analysis/iterators.cpp (working copy) > > @@ -5,8 +5,7 @@ > > > > void fum(std::vector::iterator t); > > > > -void foo1() > > -{ > > +void foo1() { > > // iterators that are defined but not initialized > > std::vector::iterator it2; > > fum(it2); // expected-warning{{Use of iterator that is not defined}} > > @@ -64,8 +63,7 @@ > > } > > > > // work with using namespace > > -void foo2() > > -{ > > +void foo2() { > > using namespace std; > > > > vector v; > > @@ -78,8 +76,7 @@ > > } > > > > // using reserve eliminates some warnings > > -void foo3() > > -{ > > +void foo3() { > > std::vector v; > > std::vector::iterator b = v.begin(); > > v.reserve( 100 ); > > @@ -94,8 +91,7 @@ > > } > > > > // check on copying one iterator to another > > -void foo4() > > -{ > > +void foo4() { > > std::vector v, vv; > > std::vector::iterator it = v.begin(); > > *it; // no-warning > > @@ -103,3 +99,14 @@ > > *it; // expected-warning{{Attempt to use an iterator made > invalid by copying another container to its container}} > > } > > > > +// check for pointers to containers as well > > +void foo5() { > > + std::vector v, *vp; > > + vp = &v; > > + std::vector::iterator it; > > + it = vp->begin(); > > + *it; // no-warning > > + vp->insert( it, 1 ); > > + *it; // expected-warning{{Attempt to use an iterator made > invalid by call to 'insert'.}} > > +} > > + > > Index: lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp > > =================================================================== > > --- lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp (revision 127607) > > +++ lib/StaticAnalyzer/Checkers/IteratorsChecker.cpp (working copy) > > @@ -197,6 +197,8 @@ > > } > > > > static RefKind getTemplateKind(QualType T) { > > + if ( isa(T) ) > > + T = T->getPointeeType(); > > if (const TemplateSpecializationType *tsp = > > T->getAs()) { > > return getTemplateKind(tsp); > > @@ -266,7 +268,10 @@ > > if (const CallExpr *CE = dyn_cast(rexp)) { > > // Handle MemberCall. > > if (const MemberExpr *ME = dyn_cast(CE->getCallee())) { > > - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); > > + const Expr *exp = ME->getBase(); > > + if (isa(exp)) > > + exp = dyn_cast(exp)->getSubExpr(); > > + const DeclRefExpr *DRE = dyn_cast(exp); > > if (!DRE) > > return state; > > // Verify that the type is std::vector. > > @@ -549,8 +554,11 @@ > > const MemberExpr *ME = dyn_cast(MCE->getCallee()); > > if (!ME) > > return; > > + const Expr *exp = ME->getBase(); > > + if (isa(exp)) > > + exp = dyn_cast(exp)->getSubExpr(); > > // Make sure we have the right kind of container. > > - const DeclRefExpr *DRE = dyn_cast(ME->getBase()); > > + const DeclRefExpr *DRE = dyn_cast(exp); > > if (!DRE || getTemplateKind(DRE->getType()) != VectorKind) > > return; > > SVal tsv = C.getState()->getSVal(DRE); From geek4civic at gmail.com Fri Mar 18 06:51:08 2011 From: geek4civic at gmail.com (NAKAMURA Takumi) Date: Fri, 18 Mar 2011 20:51:08 +0900 Subject: [cfe-commits] [RC1] Status of llvm and clang for Windows x64 Message-ID: Good evening, guys! For Windows x64 aka Win64, llvm and clang can be built on RC1 but it would not work. PR9483 is potentially problematic to mingw32 (x86). It does not affect selfhosting i686-clang for now (w/o +sse) [LLVM] - r127328 Fix Win64 va_arg. - [PR8778] alloca/chkstk fix https://github.com/chapuni/LLVM/commit/e0187c66454f4a45172f34501d5eaa060954a8ad - [PR9483] (working) [clang] - r127238 mingw-w64 should define __MINGW32__, too. - r127329 declarations of __builtin_ia32_crc32**() - r127652 Tweak InitHeaderSearch.cpp for mingw-w64-gcc - r127654 _mm_malloc tweak - r127655 Tweak __declspec and __attribute__ for mingw * How to build stage2 x86_64-clang with i686-clang selfhost stage1 1. Get appropriate mingw-w64-gcc package. I am using 20101129. 2. Layout files to copy directories. C:/mingw/bin-w64 <- x86_64-mingw32/bin C:/mingw/libexec/gcc/x86_64-w64-mingw32 <- libexec/gcc/x86_64-w64-mingw32 C:/mingw/x86_64-w64-mingw32 <- x86_64-mingw32 3. Set $PATH PATH=/c/mingw/bin-w64:/c/mingw/x86_64-w64-mingw32/bin:$PATH:/c/Python27 4. Run configure, make, test... /path/to/configure --build=x86_64-w64-mingw32 CC="/path/to/stage1/Release+Asserts/bin/clang -m64 -std=gnu89" CXX="/path/to/stage1/Release+Asserts/bin/clang++ -m64" --with-optimize-option=-O3 --enable-optimized --disable-docs --disable-pthreads ...Takumi From dgregor at apple.com Fri Mar 18 09:15:45 2011 From: dgregor at apple.com (Douglas Gregor) Date: Fri, 18 Mar 2011 07:15:45 -0700 Subject: [cfe-commits] r127806 - /cfe/trunk/lib/CodeGen/CodeGenModule.cpp In-Reply-To: <20110317141908.EC60E2A6C12C@llvm.org> References: <20110317141908.EC60E2A6C12C@llvm.org> Message-ID: <37AF2D05-9103-400B-A2BD-886EE979045D@apple.com> Bill, please merge this to the 2.9 release branch. Thanks! - Doug On Mar 17, 2011, at 7:19 AM, David Chisnall wrote: > Author: theraven > Date: Thu Mar 17 09:19:08 2011 > New Revision: 127806 > > URL: http://llvm.org/viewvc/llvm-project?rev=127806&view=rev > Log: > Remove code that was intentionally generating bad code on the GNU runtime for no reason (failing to emit .cxx_constructor / .cxx_destructor methods). > > > Modified: > cfe/trunk/lib/CodeGen/CodeGenModule.cpp > > Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127806&r1=127805&r2=127806&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) > +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Mar 17 09:19:08 2011 > @@ -1934,7 +1934,7 @@ > /// EmitObjCIvarInitializations - Emit information for ivar initialization > /// for an implementation. > void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) { > - if (!Features.NeXTRuntime || D->getNumIvarInitializers() == 0) > + if (D->getNumIvarInitializers() == 0) > return; > DeclContext* DC = const_cast(dyn_cast(D)); > assert(DC && "EmitObjCIvarInitializations - null DeclContext"); > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From abramo.bagnara at gmail.com Fri Mar 18 10:16:37 2011 From: abramo.bagnara at gmail.com (Abramo Bagnara) Date: Fri, 18 Mar 2011 15:16:37 -0000 Subject: [cfe-commits] r127876 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplate.cpp Message-ID: <20110318151637.B5A932A6C12C@llvm.org> Author: abramo Date: Fri Mar 18 10:16:37 2011 New Revision: 127876 URL: http://llvm.org/viewvc/llvm-project?rev=127876&view=rev Log: Fixed inconsistency when adding TemplateParameterListsInfo. Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=127876&r1=127875&r2=127876&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar 18 10:16:37 2011 @@ -507,16 +507,24 @@ /// name qualifier, to be used for the case of out-of-line declarations. struct QualifierInfo { NestedNameSpecifierLoc QualifierLoc; - /// NumTemplParamLists - The number of template parameter lists - /// that were matched against the template-ids occurring into the NNS. + + /// NumTemplParamLists - The number of "outer" template parameter lists. + /// The count includes all of the template parameter lists that were matched + /// against the template-ids occurring into the NNS and possibly (in the + /// case of an explicit specialization) a final "template <>". unsigned NumTemplParamLists; + /// TemplParamLists - A new-allocated array of size NumTemplParamLists, - /// containing pointers to the matched template parameter lists. + /// containing pointers to the "outer" template parameter lists. + /// It includes all of the template parameter lists that were matched + /// against the template-ids occurring into the NNS and possibly (in the + /// case of an explicit specialization) a final "template <>". TemplateParameterList** TemplParamLists; /// Default constructor. QualifierInfo() : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(0) {} - /// setTemplateParameterListsInfo - Sets info about matched template + + /// setTemplateParameterListsInfo - Sets info about "outer" template /// parameter lists. void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, @@ -603,9 +611,7 @@ return getExtInfo()->TemplParamLists[index]; } void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, - TemplateParameterList **TPLists) { - getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists); - } + TemplateParameterList **TPLists); SourceLocation getTypeSpecStartLoc() const; @@ -2238,9 +2244,7 @@ return getExtInfo()->TemplParamLists[i]; } void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, - TemplateParameterList **TPLists) { - getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists); - } + TemplateParameterList **TPLists); // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=127876&r1=127875&r2=127876&view=diff ============================================================================== --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Fri Mar 18 10:16:37 2011 @@ -961,16 +961,38 @@ else { // Here Qualifier == 0, i.e., we are removing the qualifier (if any). if (hasExtInfo()) { - // Save type source info pointer. - TypeSourceInfo *savedTInfo = getExtInfo()->TInfo; - // Deallocate the extended decl info. - getASTContext().Deallocate(getExtInfo()); - // Restore savedTInfo into (non-extended) decl info. - DeclInfo = savedTInfo; + if (getExtInfo()->NumTemplParamLists == 0) { + // Save type source info pointer. + TypeSourceInfo *savedTInfo = getExtInfo()->TInfo; + // Deallocate the extended decl info. + getASTContext().Deallocate(getExtInfo()); + // Restore savedTInfo into (non-extended) decl info. + DeclInfo = savedTInfo; + } + else + getExtInfo()->QualifierLoc = QualifierLoc; } } } +void +DeclaratorDecl::setTemplateParameterListsInfo(ASTContext &Context, + unsigned NumTPLists, + TemplateParameterList **TPLists) { + assert(NumTPLists > 0); + // Make sure the extended decl info is allocated. + if (!hasExtInfo()) { + // Save (non-extended) type source info pointer. + TypeSourceInfo *savedTInfo = DeclInfo.get(); + // Allocate external info struct. + DeclInfo = new (getASTContext()) ExtInfo; + // Restore savedTInfo into (extended) decl info. + getExtInfo()->TInfo = savedTInfo; + } + // Set the template parameter lists info. + getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists); +} + SourceLocation DeclaratorDecl::getOuterLocStart() const { return getTemplateOrInnerLocStart(this); } @@ -1030,8 +1052,6 @@ TemplateParameterList **TPLists) { assert((NumTPLists == 0 || TPLists != 0) && "Empty array of template parameters with positive size!"); - assert((NumTPLists == 0 || QualifierLoc) && - "Nonempty array of template parameters with no qualifier!"); // Free previous template parameters (if any). if (NumTemplParamLists > 0) { @@ -2100,12 +2120,28 @@ else { // Here Qualifier == 0, i.e., we are removing the qualifier (if any). if (hasExtInfo()) { - getASTContext().Deallocate(getExtInfo()); - TypedefDeclOrQualifier = (TypedefDecl*) 0; + if (getExtInfo()->NumTemplParamLists == 0) { + getASTContext().Deallocate(getExtInfo()); + TypedefDeclOrQualifier = (TypedefDecl*) 0; + } + else + getExtInfo()->QualifierLoc = QualifierLoc; } } } +void TagDecl::setTemplateParameterListsInfo(ASTContext &Context, + unsigned NumTPLists, + TemplateParameterList **TPLists) { + assert(NumTPLists > 0); + // Make sure the extended decl info is allocated. + if (!hasExtInfo()) + // Allocate external info struct. + TypedefDeclOrQualifier = new (getASTContext()) ExtInfo; + // Set the template parameter lists info. + getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists); +} + //===----------------------------------------------------------------------===// // EnumDecl Implementation //===----------------------------------------------------------------------===// Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127876&r1=127875&r2=127876&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 18 10:16:37 2011 @@ -3094,7 +3094,6 @@ // Match up the template parameter lists with the scope specifier, then // determine whether we have a template or a template specialization. isExplicitSpecialization = false; - unsigned NumMatchedTemplateParamLists = TemplateParamLists.size(); bool Invalid = false; if (TemplateParameterList *TemplateParams = MatchTemplateParametersToScopeSpecifier( @@ -3105,9 +3104,6 @@ /*never a friend*/ false, isExplicitSpecialization, Invalid)) { - // All but one template parameter lists have been matching. - --NumMatchedTemplateParamLists; - if (TemplateParams->size() > 0) { // There is no such thing as a variable template. Diag(D.getIdentifierLoc(), diag::err_template_variable) @@ -3123,7 +3119,6 @@ << II << SourceRange(TemplateParams->getTemplateLoc(), TemplateParams->getRAngleLoc()); - isExplicitSpecialization = true; } } @@ -3143,9 +3138,9 @@ SetNestedNameSpecifier(NewVD, D); - if (NumMatchedTemplateParamLists > 0 && D.getCXXScopeSpec().isSet()) { + if (TemplateParamLists.size() > 0 && D.getCXXScopeSpec().isSet()) { NewVD->setTemplateParameterListsInfo(Context, - NumMatchedTemplateParamLists, + TemplateParamLists.size(), TemplateParamLists.release()); } } @@ -3636,8 +3631,7 @@ FunctionTemplateDecl *FunctionTemplate = 0; bool isExplicitSpecialization = false; bool isFunctionTemplateSpecialization = false; - unsigned NumMatchedTemplateParamLists = 0; - + if (!getLangOptions().CPlusPlus) { // Determine whether the function was written with a // prototype. This true when: @@ -3783,7 +3777,6 @@ SetNestedNameSpecifier(NewFD, D); isExplicitSpecialization = false; isFunctionTemplateSpecialization = false; - NumMatchedTemplateParamLists = TemplateParamLists.size(); if (D.isInvalidType()) NewFD->setInvalidDecl(); @@ -3804,61 +3797,71 @@ isFriend, isExplicitSpecialization, Invalid)) { - // All but one template parameter lists have been matching. - --NumMatchedTemplateParamLists; + if (TemplateParams->size() > 0) { + // This is a function template - if (TemplateParams->size() > 0) { - // This is a function template + // Check that we can declare a template here. + if (CheckTemplateDeclScope(S, TemplateParams)) + return 0; - // Check that we can declare a template here. - if (CheckTemplateDeclScope(S, TemplateParams)) - return 0; - - // A destructor cannot be a template. - if (Name.getNameKind() == DeclarationName::CXXDestructorName) { - Diag(NewFD->getLocation(), diag::err_destructor_template); - return 0; - } - - - FunctionTemplate = FunctionTemplateDecl::Create(Context, DC, - NewFD->getLocation(), - Name, TemplateParams, - NewFD); - FunctionTemplate->setLexicalDeclContext(CurContext); - NewFD->setDescribedFunctionTemplate(FunctionTemplate); - } else { - // This is a function template specialization. - isFunctionTemplateSpecialization = true; - - // C++0x [temp.expl.spec]p20 forbids "template<> friend void foo(int);". - if (isFriend && isFunctionTemplateSpecialization) { - // We want to remove the "template<>", found here. - SourceRange RemoveRange = TemplateParams->getSourceRange(); - - // If we remove the template<> and the name is not a - // template-id, we're actually silently creating a problem: - // the friend declaration will refer to an untemplated decl, - // and clearly the user wants a template specialization. So - // we need to insert '<>' after the name. - SourceLocation InsertLoc; - if (D.getName().getKind() != UnqualifiedId::IK_TemplateId) { - InsertLoc = D.getName().getSourceRange().getEnd(); - InsertLoc = PP.getLocForEndOfToken(InsertLoc); - } + // A destructor cannot be a template. + if (Name.getNameKind() == DeclarationName::CXXDestructorName) { + Diag(NewFD->getLocation(), diag::err_destructor_template); + return 0; + } - Diag(D.getIdentifierLoc(), diag::err_template_spec_decl_friend) - << Name << RemoveRange - << FixItHint::CreateRemoval(RemoveRange) - << FixItHint::CreateInsertion(InsertLoc, "<>"); - } - } + FunctionTemplate = FunctionTemplateDecl::Create(Context, DC, + NewFD->getLocation(), + Name, TemplateParams, + NewFD); + FunctionTemplate->setLexicalDeclContext(CurContext); + NewFD->setDescribedFunctionTemplate(FunctionTemplate); + + // For source fidelity, store the other template param lists. + if (TemplateParamLists.size() > 1) { + NewFD->setTemplateParameterListsInfo(Context, + TemplateParamLists.size() - 1, + TemplateParamLists.release()); } + } else { + // This is a function template specialization. + isFunctionTemplateSpecialization = true; + // For source fidelity, store all the template param lists. + NewFD->setTemplateParameterListsInfo(Context, + TemplateParamLists.size(), + TemplateParamLists.release()); + + // C++0x [temp.expl.spec]p20 forbids "template<> friend void foo(int);". + if (isFriend) { + // We want to remove the "template<>", found here. + SourceRange RemoveRange = TemplateParams->getSourceRange(); + + // If we remove the template<> and the name is not a + // template-id, we're actually silently creating a problem: + // the friend declaration will refer to an untemplated decl, + // and clearly the user wants a template specialization. So + // we need to insert '<>' after the name. + SourceLocation InsertLoc; + if (D.getName().getKind() != UnqualifiedId::IK_TemplateId) { + InsertLoc = D.getName().getSourceRange().getEnd(); + InsertLoc = PP.getLocForEndOfToken(InsertLoc); + } - if (NumMatchedTemplateParamLists > 0 && D.getCXXScopeSpec().isSet()) { - NewFD->setTemplateParameterListsInfo(Context, - NumMatchedTemplateParamLists, - TemplateParamLists.release()); + Diag(D.getIdentifierLoc(), diag::err_template_spec_decl_friend) + << Name << RemoveRange + << FixItHint::CreateRemoval(RemoveRange) + << FixItHint::CreateInsertion(InsertLoc, "<>"); + } + } + } + else { + // All template param lists were matched against the scope specifier: + // this is NOT (an explicit specialization of) a template. + if (TemplateParamLists.size() > 0) + // For source fidelity, store all the template param lists. + NewFD->setTemplateParameterListsInfo(Context, + TemplateParamLists.size(), + TemplateParamLists.release()); } if (Invalid) { @@ -4180,7 +4183,7 @@ // are situations where these conditions don't apply and we // can actually do this check immediately. if (isFriend && - (NumMatchedTemplateParamLists || + (TemplateParamLists.size() || D.getCXXScopeSpec().getScopeRep()->isDependent() || CurContext->isDependentContext())) { // ignore these @@ -6035,27 +6038,24 @@ // FIXME: Check explicit specializations more carefully. bool isExplicitSpecialization = false; - unsigned NumMatchedTemplateParamLists = TemplateParameterLists.size(); bool Invalid = false; // We only need to do this matching if we have template parameters // or a scope specifier, which also conveniently avoids this work // for non-C++ cases. - if (NumMatchedTemplateParamLists || + if (TemplateParameterLists.size() > 0 || (SS.isNotEmpty() && TUK != TUK_Reference)) { if (TemplateParameterList *TemplateParams = MatchTemplateParametersToScopeSpecifier(KWLoc, SS, TemplateParameterLists.get(), - TemplateParameterLists.size(), + TemplateParameterLists.size(), TUK == TUK_Friend, isExplicitSpecialization, Invalid)) { - // All but one template parameter lists have been matching. - --NumMatchedTemplateParamLists; - if (TemplateParams->size() > 0) { // This is a declaration or definition of a class template (which may // be a member of another template). + if (Invalid) return 0; @@ -6063,7 +6063,7 @@ DeclResult Result = CheckClassTemplate(S, TagSpec, TUK, KWLoc, SS, Name, NameLoc, Attr, TemplateParams, AS, - NumMatchedTemplateParamLists, + TemplateParameterLists.size() - 1, (TemplateParameterList**) TemplateParameterLists.release()); return Result.get(); } else { @@ -6584,9 +6584,9 @@ if (SS.isNotEmpty()) { if (SS.isSet()) { New->setQualifierInfo(SS.getWithLocInContext(Context)); - if (NumMatchedTemplateParamLists > 0) { + if (TemplateParameterLists.size() > 0) { New->setTemplateParameterListsInfo(Context, - NumMatchedTemplateParamLists, + TemplateParameterLists.size(), (TemplateParameterList**) TemplateParameterLists.release()); } } Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=127876&r1=127875&r2=127876&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Mar 18 10:16:37 2011 @@ -6977,7 +6977,6 @@ TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForTypeSpec(TagSpec); bool isExplicitSpecialization = false; - unsigned NumMatchedTemplateParamLists = TempParamLists.size(); bool Invalid = false; if (TemplateParameterList *TemplateParams @@ -6987,8 +6986,6 @@ /*friend*/ true, isExplicitSpecialization, Invalid)) { - --NumMatchedTemplateParamLists; - if (TemplateParams->size() > 0) { // This is a declaration of a class template. if (Invalid) @@ -6997,7 +6994,7 @@ return CheckClassTemplate(S, TagSpec, TUK_Friend, TagLoc, SS, Name, NameLoc, Attr, TemplateParams, AS_public, - NumMatchedTemplateParamLists, + TempParamLists.size() - 1, (TemplateParameterList**) TempParamLists.release()).take(); } else { // The "template<>" header is extraneous. @@ -7012,7 +7009,7 @@ assert(SS.isNotEmpty() && "valid templated tag with no SS and no direct?"); bool isAllExplicitSpecializations = true; - for (unsigned I = 0; I != NumMatchedTemplateParamLists; ++I) { + for (unsigned I = TempParamLists.size(); I-- > 0; ) { if (TempParamLists.get()[I]->size()) { isAllExplicitSpecializations = false; break; Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=127876&r1=127875&r2=127876&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Mar 18 10:16:37 2011 @@ -1456,9 +1456,9 @@ /// /// \returns the template parameter list, if any, that corresponds to the /// name that is preceded by the scope specifier @p SS. This template -/// parameter list may be have template parameters (if we're declaring a +/// parameter list may have template parameters (if we're declaring a /// template) or may have no template parameters (if we're declaring a -/// template specialization), or may be NULL (if we were's declaring isn't +/// template specialization), or may be NULL (if what we're declaring isn't /// itself a template). TemplateParameterList * Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, @@ -4390,6 +4390,11 @@ MultiTemplateParamsArg TemplateParameterLists) { assert(TUK != TUK_Reference && "References are not specializations"); + // NOTE: KWLoc is the location of the tag keyword. This will instead + // store the location of the outermost template keyword in the declaration. + SourceLocation TemplateKWLoc = TemplateParameterLists.size() > 0 + ? TemplateParameterLists.get()[0]->getTemplateLoc() : SourceLocation(); + // Find the class template we're specializing TemplateName Name = TemplateD.getAsVal(); ClassTemplateDecl *ClassTemplate @@ -4420,10 +4425,6 @@ if (Invalid) return true; - unsigned NumMatchedTemplateParamLists = TemplateParameterLists.size(); - if (TemplateParams) - --NumMatchedTemplateParamLists; - if (TemplateParams && TemplateParams->size() > 0) { isPartialSpecialization = true; @@ -4565,10 +4566,15 @@ // Since the only prior class template specialization with these // arguments was referenced but not declared, or we're only // referencing this specialization as a friend, reuse that - // declaration node as our own, updating its source location to - // reflect our new declaration. + // declaration node as our own, updating its source location and + // the list of outer template parameters to reflect our new declaration. Specialization = PrevDecl; Specialization->setLocation(TemplateNameLoc); + if (TemplateParameterLists.size() > 0) { + Specialization->setTemplateParameterListsInfo(Context, + TemplateParameterLists.size(), + (TemplateParameterList**) TemplateParameterLists.release()); + } PrevDecl = 0; CanonType = Context.getTypeDeclType(Specialization); } else if (isPartialSpecialization) { @@ -4594,7 +4600,7 @@ Attr, TemplateParams, AS_none, - NumMatchedTemplateParamLists, + TemplateParameterLists.size() - 1, (TemplateParameterList**) TemplateParameterLists.release()); } @@ -4616,9 +4622,9 @@ PrevPartial, SequenceNumber); SetNestedNameSpecifier(Partial, SS); - if (NumMatchedTemplateParamLists > 0 && SS.isSet()) { + if (TemplateParameterLists.size() > 1 && SS.isSet()) { Partial->setTemplateParameterListsInfo(Context, - NumMatchedTemplateParamLists, + TemplateParameterLists.size() - 1, (TemplateParameterList**) TemplateParameterLists.release()); } @@ -4675,9 +4681,9 @@ Converted.size(), PrevDecl); SetNestedNameSpecifier(Specialization, SS); - if (NumMatchedTemplateParamLists > 0 && SS.isSet()) { + if (TemplateParameterLists.size() > 0) { Specialization->setTemplateParameterListsInfo(Context, - NumMatchedTemplateParamLists, + TemplateParameterLists.size(), (TemplateParameterList**) TemplateParameterLists.release()); } @@ -4747,8 +4753,7 @@ TemplateArgs, CanonType); if (TUK != TUK_Friend) { Specialization->setTypeAsWritten(WrittenTy); - if (TemplateParams) - Specialization->setTemplateKeywordLoc(TemplateParams->getTemplateLoc()); + Specialization->setTemplateKeywordLoc(TemplateKWLoc); } TemplateArgsIn.release(); From abramo.bagnara at gmail.com Fri Mar 18 10:21:59 2011 From: abramo.bagnara at gmail.com (Abramo Bagnara) Date: Fri, 18 Mar 2011 15:21:59 -0000 Subject: [cfe-commits] r127877 - /cfe/trunk/lib/Sema/SemaDecl.cpp Message-ID: <20110318152159.C9DA62A6C12C@llvm.org> Author: abramo Date: Fri Mar 18 10:21:59 2011 New Revision: 127877 URL: http://llvm.org/viewvc/llvm-project?rev=127877&view=rev Log: Defined friend functions are *implicitly* inlined, unless the inline specifier occurs explicitly. Modified: cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127877&r1=127876&r2=127877&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 18 10:21:59 2011 @@ -3669,14 +3669,6 @@ AbstractReturnType)) D.setInvalidType(); - - if (isFriend) { - // C++ [class.friend]p5 - // A function can be defined in a friend declaration of a - // class . . . . Such a function is implicitly inline. - isInline |= IsFunctionDefinition; - } - if (Name.getNameKind() == DeclarationName::CXXConstructorName) { // This is a C++ constructor declaration. assert(DC->isRecord() && @@ -3774,6 +3766,14 @@ NameInfo, R, TInfo, SC, SCAsWritten, isInline, true/*HasPrototype*/); } + + if (isFriend && !isInline && IsFunctionDefinition) { + // C++ [class.friend]p5 + // A function can be defined in a friend declaration of a + // class . . . . Such a function is implicitly inline. + NewFD->setImplicitlyInline(); + } + SetNestedNameSpecifier(NewFD, D); isExplicitSpecialization = false; isFunctionTemplateSpecialization = false; From rafael.espindola at gmail.com Fri Mar 18 10:50:12 2011 From: rafael.espindola at gmail.com (Rafael Espindola) Date: Fri, 18 Mar 2011 15:50:12 -0000 Subject: [cfe-commits] r127879 - /cfe/trunk/lib/Driver/Driver.cpp Message-ID: <20110318155012.8AA7F2A6C12C@llvm.org> Author: rafael Date: Fri Mar 18 10:50:12 2011 New Revision: 127879 URL: http://llvm.org/viewvc/llvm-project?rev=127879&view=rev Log: On !Darwin, do use the integrated as with -static. Modified: cfe/trunk/lib/Driver/Driver.cpp Modified: cfe/trunk/lib/Driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=127879&r1=127878&r2=127879&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Driver.cpp (original) +++ cfe/trunk/lib/Driver/Driver.cpp Fri Mar 18 10:50:12 2011 @@ -1079,7 +1079,9 @@ bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) || C.getArgs().hasArg(options::OPT_static) || C.getArgs().hasArg(options::OPT_fapple_kext)); - bool IsIADefault = (TC->IsIntegratedAssemblerDefault() && !HasStatic); + bool IsDarwin = TC->getTriple().getOS() == llvm::Triple::Darwin; + bool IsIADefault = TC->IsIntegratedAssemblerDefault() && + !(HasStatic && IsDarwin); if (C.getArgs().hasFlag(options::OPT_integrated_as, options::OPT_no_integrated_as, IsIADefault) && From dgregor at apple.com Fri Mar 18 11:10:52 2011 From: dgregor at apple.com (Douglas Gregor) Date: Fri, 18 Mar 2011 16:10:52 -0000 Subject: [cfe-commits] r127881 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/warn-using-namespace-in-header.cpp test/SemaCXX/warn-using-namespace-in-header.h Message-ID: <20110318161053.1950A2A6C12C@llvm.org> Author: dgregor Date: Fri Mar 18 11:10:52 2011 New Revision: 127881 URL: http://llvm.org/viewvc/llvm-project?rev=127881&view=rev Log: Add an opt-in -Wheader-hygiene, which current diagnoses the use of global using directives in C++ headers, from Elliot Glaysher! Added: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp (with props) cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h (with props) Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDeclCXX.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=127881&r1=127880&r2=127881&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Mar 18 11:10:52 2011 @@ -109,6 +109,7 @@ def : DiagGroup<"switch-default">; def : DiagGroup<"synth">; def TautologicalCompare : DiagGroup<"tautological-compare">; +def HeaderHygiene : DiagGroup<"header-hygiene">; // Preprocessor warnings. def : DiagGroup<"builtin-macro-redefined">; Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127881&r1=127880&r2=127881&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 18 11:10:52 2011 @@ -2928,6 +2928,9 @@ InGroup, DefaultIgnore; def note_hidden_overloaded_virtual_declared_here : Note< "hidden overloaded virtual function %q0 declared here">; +def warn_using_directive_in_header : Warning< + "using namespace directive in global context in header">, + InGroup, DefaultIgnore; def err_conditional_void_nonvoid : Error< "%select{left|right}1 operand to ? is void, but %select{right|left}1 operand " Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=127881&r1=127880&r2=127881&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Mar 18 11:10:52 2011 @@ -3922,6 +3922,12 @@ UDir = UsingDirectiveDecl::Create(Context, CurContext, UsingLoc, NamespcLoc, SS.getWithLocInContext(Context), IdentLoc, Named, CommonAncestor); + + if (CurContext->getDeclKind() == Decl::TranslationUnit && + !SourceMgr.isFromMainFile(IdentLoc)) { + Diag(IdentLoc, diag::warn_using_directive_in_header); + } + PushUsingDirective(S, UDir); } else { Diag(IdentLoc, diag::err_expected_namespace_name) << SS.getRange(); Added: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp?rev=127881&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp (added) +++ cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp Fri Mar 18 11:10:52 2011 @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s + +#include "warn-using-namespace-in-header.h" + +namespace dont_warn {} +using namespace dont_warn; + +// Warning is actually in the header but only the cpp file gets scanned. +// expected-warning {{using namespace directive in global context in header}} Propchange: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.cpp ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h?rev=127881&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h (added) +++ cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h Fri Mar 18 11:10:52 2011 @@ -0,0 +1,15 @@ + + + + + +// Lots of vertical space to make the error line match up with the line of the +// expected line in the source file. +namespace warn_in_header_in_global_context {} +using namespace warn_in_header_in_global_context; + +// While we want to error on the previous using directive, we don't when we are +// inside a namespace +namespace dont_warn_here { +using namespace warn_in_header_in_global_context; +} Propchange: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cfe/trunk/test/SemaCXX/warn-using-namespace-in-header.h ------------------------------------------------------------------------------ svn:mime-type = text/plain From dgregor at apple.com Fri Mar 18 11:15:12 2011 From: dgregor at apple.com (Douglas Gregor) Date: Fri, 18 Mar 2011 09:15:12 -0700 Subject: [cfe-commits] [PATCH] Re: [cfe-dev] Interest in a -Wusing-namespace-in-headers? In-Reply-To: References: Message-ID: On Mar 17, 2011, at 11:05 AM, Elliot Glaysher (Chromium) wrote: > Adds a -Wheader-hygiene warning for warnings that should only trigger > in #included files. > > The first -Wheader-hygiene check is to make sure a using directive > isn't placed in the global context in a header. > > On Wed, Mar 16, 2011 at 6:15 PM, Douglas Gregor wrote: >> You don't need to perform the getDiagnosticLevel() check yourself, because the diagnostic system will handle warning suppression itself. >> >> However, I do suggest performing the CurContext->getDeclKind() == Decl::TranslationUnit check before the isFromMainFile() check, since the former is cheaper. > > Done. Committed in r127881, thanks! - Doug From dgregor at apple.com Fri Mar 18 11:15:44 2011 From: dgregor at apple.com (Douglas Gregor) Date: Fri, 18 Mar 2011 09:15:44 -0700 Subject: [cfe-commits] r127811 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaTemplateDeduction.cpp test/SemaCXX/auto-subst-failure.cpp In-Reply-To: <20110317161159.B87892A6C12C@llvm.org> References: <20110317161159.B87892A6C12C@llvm.org> Message-ID: <4650C467-FCF4-4866-AFDF-662D9DDC9FCF@apple.com> Bill, can you pull this into the 2.9 branch? Thanks! - Doug On Mar 17, 2011, at 9:11 AM, Richard Smith wrote: > Author: rsmith > Date: Thu Mar 17 11:11:59 2011 > New Revision: 127811 > > URL: http://llvm.org/viewvc/llvm-project?rev=127811&view=rev > Log: > Fix PR9488: 'auto' type substitution can fail (for instance, if it creates a reference-to-void type). Don't crash if it does. > Also fix an issue where type source information for the resulting type was being lost. > > Added: > cfe/trunk/test/SemaCXX/auto-subst-failure.cpp > Modified: > cfe/trunk/include/clang/Sema/Sema.h > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/lib/Sema/SemaDeclCXX.cpp > cfe/trunk/lib/Sema/SemaExprCXX.cpp > cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp > > Modified: cfe/trunk/include/clang/Sema/Sema.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=127811&r1=127810&r2=127811&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Sema/Sema.h (original) > +++ cfe/trunk/include/clang/Sema/Sema.h Thu Mar 17 11:11:59 2011 > @@ -3879,7 +3879,8 @@ > FunctionDecl *&Specialization, > sema::TemplateDeductionInfo &Info); > > - bool DeduceAutoType(QualType AutoType, Expr *Initializer, QualType &Result); > + bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, > + TypeSourceInfo *&Result); > > FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, > FunctionTemplateDecl *FT2, > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127811&r1=127810&r2=127811&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar 17 11:11:59 2011 > @@ -4664,15 +4664,17 @@ > > // C++0x [decl.spec.auto]p6. Deduce the type which 'auto' stands in for. > if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) { > - QualType DeducedType; > - if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { > + TypeSourceInfo *DeducedType = 0; > + if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType)) > Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) > << VDecl->getDeclName() << VDecl->getType() << Init->getType() > << Init->getSourceRange(); > + if (!DeducedType) { > RealDecl->setInvalidDecl(); > return; > } > - VDecl->setType(DeducedType); > + VDecl->setTypeSourceInfo(DeducedType); > + VDecl->setType(DeducedType->getType()); > > // If this is a redeclaration, check that the type we just deduced matches > // the previously declared type. > > Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=127811&r1=127810&r2=127811&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Mar 17 11:11:59 2011 > @@ -6137,15 +6137,17 @@ > } > > Expr *Init = Exprs.get()[0]; > - QualType DeducedType; > - if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { > + TypeSourceInfo *DeducedType = 0; > + if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType)) > Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) > << VDecl->getDeclName() << VDecl->getType() << Init->getType() > << Init->getSourceRange(); > + if (!DeducedType) { > RealDecl->setInvalidDecl(); > return; > } > - VDecl->setType(DeducedType); > + VDecl->setTypeSourceInfo(DeducedType); > + VDecl->setType(DeducedType->getType()); > > // If this is a redeclaration, check that the type we just deduced matches > // the previously declared type. > > Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=127811&r1=127810&r2=127811&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) > +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Mar 17 11:11:59 2011 > @@ -848,16 +848,18 @@ > diag::err_auto_new_ctor_multiple_expressions) > << AllocType << TypeRange); > } > - QualType DeducedType; > - if (!DeduceAutoType(AllocType, ConstructorArgs.get()[0], DeducedType)) > + TypeSourceInfo *DeducedType = 0; > + if (!DeduceAutoType(AllocTypeInfo, ConstructorArgs.get()[0], DeducedType)) > return ExprError(Diag(StartLoc, diag::err_auto_new_deduction_failure) > << AllocType > << ConstructorArgs.get()[0]->getType() > << TypeRange > << ConstructorArgs.get()[0]->getSourceRange()); > + if (!DeducedType) > + return ExprError(); > > - AllocType = DeducedType; > - AllocTypeInfo = Context.getTrivialTypeSourceInfo(AllocType, StartLoc); > + AllocTypeInfo = DeducedType; > + AllocType = AllocTypeInfo->getType(); > } > > // Per C++0x [expr.new]p5, the type being constructed may be a > > Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=127811&r1=127810&r2=127811&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original) > +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Mar 17 11:11:59 2011 > @@ -3003,11 +3003,14 @@ > /// > /// \param Result if type deduction was successful, this will be set to the > /// deduced type. This may still contain undeduced autos if the type is > -/// dependent. > +/// dependent. This will be set to null if deduction succeeded, but auto > +/// substitution failed; the appropriate diagnostic will already have been > +/// produced in that case. > /// > /// \returns true if deduction succeeded, false if it failed. > bool > -Sema::DeduceAutoType(QualType Type, Expr *Init, QualType &Result) { > +Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *Init, > + TypeSourceInfo *&Result) { > if (Init->isTypeDependent()) { > Result = Type; > return true; > @@ -3025,8 +3028,10 @@ > FixedSizeTemplateParameterList<1> TemplateParams(Loc, Loc, &TemplParamPtr, > Loc); > > - QualType FuncParam = > + TypeSourceInfo *FuncParamInfo = > SubstituteAutoTransform(*this, TemplArg).TransformType(Type); > + assert(FuncParamInfo && "substituting template parameter for 'auto' failed"); > + QualType FuncParam = FuncParamInfo->getType(); > > // Deduce type of TemplParam in Func(Init) > llvm::SmallVector Deduced; > > Added: cfe/trunk/test/SemaCXX/auto-subst-failure.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/auto-subst-failure.cpp?rev=127811&view=auto > ============================================================================== > --- cfe/trunk/test/SemaCXX/auto-subst-failure.cpp (added) > +++ cfe/trunk/test/SemaCXX/auto-subst-failure.cpp Thu Mar 17 11:11:59 2011 > @@ -0,0 +1,15 @@ > +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x > + > +void f() { > + auto a = f(); // expected-error {{variable has incomplete type 'void'}} > + auto &b = f(); // expected-error {{cannot form a reference to 'void'}} > + auto *c = f(); // expected-error {{incompatible initializer of type 'void'}} > + > + auto d(f()); // expected-error {{variable has incomplete type 'void'}} > + auto &&e(f()); // expected-error {{cannot form a reference to 'void'}} > + auto *g(f()); // expected-error {{incompatible initializer of type 'void'}} > + > + (void)new auto(f()); // expected-error {{allocation of incomplete type 'void'}} > + (void)new auto&(f()); // expected-error {{cannot form a reference to 'void'}} > + (void)new auto*(f()); // expected-error {{incompatible constructor argument of type 'void'}} > +} > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From dgregor at apple.com Fri Mar 18 11:25:30 2011 From: dgregor at apple.com (Douglas Gregor) Date: Fri, 18 Mar 2011 09:25:30 -0700 Subject: [cfe-commits] [PATCH][Review request] correct initialization of AltiVec vectors In-Reply-To: <4D5BA715.70204@Gmail.com> References: <4CF32459.2000700@Gmail.com> <4D1BCEFC.8020303@Gmail.com> <87A3C667-726E-4C41-B463-8614B8B295D7@apple.com> <4D3F4468.1030000@Gmail.com> <400B9C54-D5E0-4B94-9A79-58997009DB9E@apple.com> <4D5BA715.70204@Gmail.com> Message-ID: <3A38D3F1-D548-419F-9095-7EFE65F72299@apple.com> On Feb 16, 2011, at 2:29 AM, Anton Yartsev wrote: > >> Index: lib/Sema/SemaCXXCast.cpp >> =================================================================== >> --- lib/Sema/SemaCXXCast.cpp (revision 124051) >> +++ lib/Sema/SemaCXXCast.cpp (working copy) >> @@ -1227,7 +1227,16 @@ >> >> // FIXME: Should this also apply to floating point types? >> bool srcIsScalar = SrcType->isIntegralType(Self.Context); >> bool destIsScalar = DestType->isIntegralType(Self.Context); >> - >> + >> + // Case of AltiVec vector initialization with a single literal >> + if (destIsVector >> +&& DestType->getAs()->getVectorKind() == >> + VectorType::AltiVecVector >> +&& (SrcType->isIntegerType() || SrcType->isFloatingType())) { >> + Kind = CK_VectorSplat; >> + return TC_Success; >> + } >> + >> // Check if this is a cast between a vector and something else. >> if (!(srcIsScalar&& destIsVector)&& !(srcIsVector&& destIsScalar)&& >> !(srcIsVector&& destIsVector)) >> >> What's your motivation for this change? This is along the reinterpret_cast path, and reinterpret_cast is meant only for conversions that take the same bits and interpret them in a different way. A vector splat isn't such a conversion. >> >> This change basically ends up taking something that used to work in a reinterpret_cast---say, reinterpreting an int as a vector of 4 chars---and introduces an conceptual ambiguity (it could also mean a vector splat), then resolves it to the vector splat. Is this really what you intended? >> > That was the wrong place for the code, moved to the right one > >> @@ -4885,18 +4893,45 @@ >> >> } >> if (PE->getNumExprs() == 1) { >> if (!PE->getExpr(0)->getType()->isVectorType()) >> - isAltiVecLiteral = true; >> + isVectorLiteral = true; >> } >> else >> - isAltiVecLiteral = true; >> + isVectorLiteral = true; >> } >> >> - // If this is an altivec initializer, '(' type ')' '(' init, ..., init ')' >> + // If this is a vector initializer, '(' type ')' '(' init, ..., init ')' >> // then handle it as such. >> - if (isAltiVecLiteral) { >> + if (isVectorLiteral) { >> llvm::SmallVector initExprs; >> - for (unsigned i = 0, e = PE->getNumExprs(); i != e; ++i) >> - initExprs.push_back(PE->getExpr(i)); >> + // '(...)' form of vector initialization in AltiVec: the number of >> + // initializers must be one or must match the size of the vector. >> + // If a single value is specified in the initializer then it will be >> + // replicated to all the components of the vector >> + if (Ty->getAs()->getVectorKind() == >> + VectorType::AltiVecVector) { >> + unsigned numElems = Ty->getAs()->getNumElements(); >> + // The number of initializers must be one or must match the size of the >> + // vector. If a single value is specified in the initializer then it will >> + // be replicated to all the components of the vector >> + if (PE->getNumExprs() == 1) { >> + QualType ElemTy = Ty->getAs()->getElementType(); >> + Expr *Literal = PE->getExpr(0); >> + ImpCastExprToType(Literal, ElemTy, >> + PrepareScalarCast(*this, Literal, ElemTy)); >> + return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal); >> + } >> >> This looks good. One question: if we have a one-element vector, shouldn't this be handled as an initializer of that one-element vector rather than a splat? I expect that code generation will be roughly the same, but it would be cleaner to represent this as an initialization. > There are no one-element vector types in AltiVec. > > Initialization is cleaner, but it gives a little bit complicated bitcode. Transforming the following code > > int main() { > vector int v = (vector int)(1); > return 0; > } > > with the solution using initialization we obtain > > define i32 @main() nounwind { > entry: > %retval = alloca i32, align 4 > %v = alloca <4 x i32>, align 16 > %.compoundliteral = alloca <4 x i32>, align 16 > store i32 0, i32* %retval > store <4 x i32> , <4 x i32>* %.compoundliteral > %tmp = load <4 x i32>* %.compoundliteral > store <4 x i32> %tmp, <4 x i32>* %v, align 16 > ret i32 0 > } > > and with the solution using cast - > > define i32 @main() nounwind { > entry: > %retval = alloca i32, align 4 > %v = alloca <4 x i32>, align 16 > store i32 0, i32* %retval > store <4 x i32> , <4 x i32>* %v, align 16 > ret i32 0 > } > >> There seem to be a bunch of whitespace changes in the diff for test/CodeGen/builtins-ppc-altivec.c, which make it hard to see any actual changes. > This are not whitespace changes - the bitcode changed > > Attached are fixed patches performed one as cast and another as initialization, please review and chose! I definitely prefer the VectorSplat cast approach. One question about the patch: Index: lib/CodeGen/CGExprConstant.cpp =================================================================== --- lib/CodeGen/CGExprConstant.cpp (revision 124983) +++ lib/CodeGen/CGExprConstant.cpp (working copy) @@ -907,12 +907,29 @@ llvm::SmallVector Inits; unsigned NumElts = Result.Val.getVectorLength(); - for (unsigned i = 0; i != NumElts; ++i) { - APValue &Elt = Result.Val.getVectorElt(i); - if (Elt.isInt()) - Inits.push_back(llvm::ConstantInt::get(VMContext, Elt.getInt())); - else - Inits.push_back(llvm::ConstantFP::get(VMContext, Elt.getFloat())); + if (Context.getLangOptions().AltiVec && + isa(E) && + dyn_cast(E)->getCastKind() == CK_VectorSplat) { Why check for a C-style cast here? Why not just check for a (general) CastExpr, which would also cover C-style casts (e.g., static_cast) and implicit casts? Also, one little nit: if you've already done an isa(X), you can just cast(X) rather than dyn_cast(X), and save ourselves some checking. Sorry for the long-delayed review :( - Doug From andersca at mac.com Fri Mar 18 13:22:40 2011 From: andersca at mac.com (Anders Carlsson) Date: Fri, 18 Mar 2011 18:22:40 -0000 Subject: [cfe-commits] r127890 - in /cfe/trunk: lib/Frontend/ASTUnit.cpp tools/libclang/CIndexCodeCompletion.cpp Message-ID: <20110318182240.797E42A6C12C@llvm.org> Author: andersca Date: Fri Mar 18 13:22:40 2011 New Revision: 127890 URL: http://llvm.org/viewvc/llvm-project?rev=127890&view=rev Log: Correctly store and keep track of the FileSystemOptions in ASTUnit and in clang_codeCompleteAt. Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=127890&r1=127889&r2=127890&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Mar 18 13:22:40 2011 @@ -881,7 +881,7 @@ // Configure the various subsystems. // FIXME: Should we retain the previous file manager? FileSystemOpts = Clang.getFileSystemOpts(); - FileMgr.reset(new FileManager(Clang.getFileSystemOpts())); + FileMgr.reset(new FileManager(FileSystemOpts)); SourceMgr.reset(new SourceManager(getDiagnostics(), *FileMgr)); TheSema.reset(); Ctx.reset(); @@ -1537,7 +1537,8 @@ ConfigureDiags(Diags, 0, 0, *AST, /*CaptureDiagnostics=*/false); AST->Diagnostics = Diags; AST->Invocation.reset(CI); - AST->FileMgr.reset(new FileManager(CI->getFileSystemOpts())); + AST->FileSystemOpts = CI->getFileSystemOpts(); + AST->FileMgr.reset(new FileManager(AST->FileSystemOpts)); AST->SourceMgr.reset(new SourceManager(*Diags, *AST->FileMgr)); return AST.take(); @@ -1706,8 +1707,9 @@ AST.reset(new ASTUnit(false)); ConfigureDiags(Diags, ArgBegin, ArgEnd, *AST, CaptureDiagnostics); AST->Diagnostics = Diags; - - AST->FileMgr.reset(new FileManager(FileSystemOptions())); + + AST->FileSystemOpts = CI->getFileSystemOpts(); + AST->FileMgr.reset(new FileManager(AST->FileSystemOpts)); AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; AST->CompleteTranslationUnit = CompleteTranslationUnit; Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=127890&r1=127889&r2=127890&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original) +++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Fri Mar 18 13:22:40 2011 @@ -201,7 +201,7 @@ /// \brief The CXCodeCompleteResults structure we allocate internally; /// the client only sees the initial CXCodeCompleteResults structure. struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { - AllocatedCXCodeCompleteResults(); + AllocatedCXCodeCompleteResults(const FileSystemOptions& FileSystemOpts); ~AllocatedCXCodeCompleteResults(); /// \brief Diagnostics produced while performing code completion. @@ -243,10 +243,12 @@ /// Used for debugging purposes only. static llvm::sys::cas_flag CodeCompletionResultObjects; -AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults() +AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( + const FileSystemOptions& FileSystemOpts) : CXCodeCompleteResults(), Diag(new Diagnostic( llvm::IntrusiveRefCntPtr(new DiagnosticIDs))), + FileSystemOpts(FileSystemOpts), FileMgr(FileSystemOpts), SourceMgr(*Diag, FileMgr) { if (getenv("LIBCLANG_OBJTRACKING")) { @@ -380,7 +382,8 @@ } // Parse the resulting source file to find code-completion results. - AllocatedCXCodeCompleteResults *Results = new AllocatedCXCodeCompleteResults; + AllocatedCXCodeCompleteResults *Results = + new AllocatedCXCodeCompleteResults(AST->getFileSystemOpts()); Results->Results = 0; Results->NumResults = 0; From andersca at mac.com Fri Mar 18 14:23:19 2011 From: andersca at mac.com (Anders Carlsson) Date: Fri, 18 Mar 2011 19:23:19 -0000 Subject: [cfe-commits] r127893 - in /cfe/trunk: include/clang/Basic/FileManager.h lib/Basic/FileManager.cpp Message-ID: <20110318192319.5C1DA2A6C12C@llvm.org> Author: andersca Date: Fri Mar 18 14:23:19 2011 New Revision: 127893 URL: http://llvm.org/viewvc/llvm-project?rev=127893&view=rev Log: Add FileManager::getNoncachedStatValue, which will resolve relative paths against the working directory specified in the file system options. Modified: cfe/trunk/include/clang/Basic/FileManager.h cfe/trunk/lib/Basic/FileManager.cpp Modified: cfe/trunk/include/clang/Basic/FileManager.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=127893&r1=127892&r2=127893&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/FileManager.h (original) +++ cfe/trunk/include/clang/Basic/FileManager.h Fri Mar 18 14:23:19 2011 @@ -195,6 +195,11 @@ llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename, std::string *ErrorStr = 0); + // getNoncachedStatValue - Will get the 'stat' information for the given path. + // If the path is relative, it will be resolved against the WorkingDir of the + // FileManager's FileSystemOptions. + bool getNoncachedStatValue(llvm::StringRef Path, struct stat &StatBuf); + /// \brief If path is not absolute and FileSystemOptions set the working /// directory, the path is modified to be relative to the given /// working directory. Modified: cfe/trunk/lib/Basic/FileManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=127893&r1=127892&r2=127893&view=diff ============================================================================== --- cfe/trunk/lib/Basic/FileManager.cpp (original) +++ cfe/trunk/lib/Basic/FileManager.cpp Fri Mar 18 14:23:19 2011 @@ -541,6 +541,14 @@ StatCache.get()); } +bool FileManager::getNoncachedStatValue(llvm::StringRef Path, + struct stat &StatBuf) { + llvm::SmallString<128> FilePath(Path); + FixupRelativePath(FilePath); + + return ::stat(FilePath.c_str(), &StatBuf) != 0; +} + void FileManager::GetUniqueIDMapping( llvm::SmallVectorImpl &UIDToFiles) const { UIDToFiles.clear(); From andersca at mac.com Fri Mar 18 14:23:38 2011 From: andersca at mac.com (Anders Carlsson) Date: Fri, 18 Mar 2011 19:23:38 -0000 Subject: [cfe-commits] r127894 - /cfe/trunk/lib/Frontend/ASTUnit.cpp Message-ID: <20110318192338.2ED092A6C12C@llvm.org> Author: andersca Date: Fri Mar 18 14:23:38 2011 New Revision: 127894 URL: http://llvm.org/viewvc/llvm-project?rev=127894&view=rev Log: Use the newly added FileManager::getNoncachedStatValue when trying to determine if any files in the preamble have changed. Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=127894&r1=127893&r2=127894&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Mar 18 14:23:38 2011 @@ -1185,7 +1185,7 @@ !AnyFileChanged && R != REnd; ++R) { struct stat StatBuf; - if (stat(R->second.c_str(), &StatBuf)) { + if (FileMgr->getNoncachedStatValue(R->second, StatBuf)) { // If we can't stat the file we're remapping to, assume that something // horrible happened. AnyFileChanged = true; @@ -1223,7 +1223,7 @@ // The file was not remapped; check whether it has changed on disk. struct stat StatBuf; - if (stat(F->first(), &StatBuf)) { + if (FileMgr->getNoncachedStatValue(F->first(), StatBuf)) { // If we can't stat the file, assume that something horrible happened. AnyFileChanged = true; } else if (StatBuf.st_size != F->second.first || From daniel at zuster.org Fri Mar 18 14:25:10 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Fri, 18 Mar 2011 19:25:10 -0000 Subject: [cfe-commits] r127896 - in /cfe/trunk/lib/Driver: HostInfo.cpp ToolChains.cpp ToolChains.h Message-ID: <20110318192510.F20E82A6C12C@llvm.org> Author: ddunbar Date: Fri Mar 18 14:25:10 2011 New Revision: 127896 URL: http://llvm.org/viewvc/llvm-project?rev=127896&view=rev Log: Driver/Darwin: Kill the DarwinGCC toolchain. Modified: cfe/trunk/lib/Driver/HostInfo.cpp cfe/trunk/lib/Driver/ToolChains.cpp cfe/trunk/lib/Driver/ToolChains.h Modified: cfe/trunk/lib/Driver/HostInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/HostInfo.cpp?rev=127896&r1=127895&r2=127896&view=diff ============================================================================== --- cfe/trunk/lib/Driver/HostInfo.cpp (original) +++ cfe/trunk/lib/Driver/HostInfo.cpp Fri Mar 18 14:25:10 2011 @@ -113,14 +113,9 @@ TCTriple.setArch(Arch); // If we recognized the arch, match it to the toolchains we support. - const char *UseNewToolChain = ::getenv("CCC_ENABLE_NEW_DARWIN_TOOLCHAIN"); - if (UseNewToolChain || - Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64 || + if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) { TC = new toolchains::DarwinClang(*this, TCTriple); - } else if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) { - // We still use the legacy DarwinGCC toolchain on X86. - TC = new toolchains::DarwinGCC(*this, TCTriple); } else TC = new toolchains::Darwin_Generic_GCC(*this, TCTriple); } Modified: cfe/trunk/lib/Driver/ToolChains.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=127896&r1=127895&r2=127896&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Mar 18 14:25:10 2011 @@ -130,82 +130,6 @@ } } -DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple) - : Darwin(Host, Triple) -{ - // We can only work with 4.2.1 currently. - GCCVersion[0] = 4; - GCCVersion[1] = 2; - GCCVersion[2] = 1; - - // Set up the tool chain paths to match gcc. - ToolChainDir = "i686-apple-darwin"; - ToolChainDir += llvm::utostr(DarwinVersion[0]); - ToolChainDir += "/"; - ToolChainDir += llvm::utostr(GCCVersion[0]); - ToolChainDir += '.'; - ToolChainDir += llvm::utostr(GCCVersion[1]); - ToolChainDir += '.'; - ToolChainDir += llvm::utostr(GCCVersion[2]); - - // Try the next major version if that tool chain dir is invalid. - std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; - bool Exists; - if (llvm::sys::fs::exists(Tmp, Exists) || Exists) { - std::string Next = "i686-apple-darwin"; - Next += llvm::utostr(DarwinVersion[0] + 1); - Next += "/"; - Next += llvm::utostr(GCCVersion[0]); - Next += '.'; - Next += llvm::utostr(GCCVersion[1]); - Next += '.'; - Next += llvm::utostr(GCCVersion[2]); - - // Use that if it exists, otherwise hope the user isn't linking. - // - // FIXME: Drop dependency on gcc's tool chain. - Tmp = "/usr/lib/gcc/" + Next; - if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) - ToolChainDir = Next; - } - - std::string Path; - if (getArchName() == "x86_64") { - Path = getDriver().Dir; - Path += "/../lib/gcc/"; - Path += ToolChainDir; - Path += "/x86_64"; - getFilePaths().push_back(Path); - - Path = "/usr/lib/gcc/"; - Path += ToolChainDir; - Path += "/x86_64"; - getFilePaths().push_back(Path); - } - - Path = getDriver().Dir; - Path += "/../lib/gcc/"; - Path += ToolChainDir; - getFilePaths().push_back(Path); - - Path = "/usr/lib/gcc/"; - Path += ToolChainDir; - getFilePaths().push_back(Path); - - Path = getDriver().Dir; - Path += "/../libexec/gcc/"; - Path += ToolChainDir; - getProgramPaths().push_back(Path); - - Path = "/usr/libexec/gcc/"; - Path += ToolChainDir; - getProgramPaths().push_back(Path); - - getProgramPaths().push_back(getDriver().getInstalledDir()); - if (getDriver().getInstalledDir() != getDriver().Dir) - getProgramPaths().push_back(getDriver().Dir); -} - Darwin::~Darwin() { // Free tool implementations. for (llvm::DenseMap::iterator @@ -294,87 +218,6 @@ return *T; } -void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { - std::string Tmp; - - // FIXME: Derive these correctly. - if (getArchName() == "x86_64") { - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + - "/x86_64")); - // Intentionally duplicated for (temporary) gcc bug compatibility. - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + - "/x86_64")); - } - - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); - - Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir; - bool Exists; - if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) - CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); - Tmp = getDriver().Dir + "/../lib/gcc"; - if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) - CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); - // Intentionally duplicated for (temporary) gcc bug compatibility. - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); - Tmp = getDriver().Dir + "/../lib/" + ToolChainDir; - if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) - CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); - Tmp = getDriver().Dir + "/../lib"; - if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) - CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + - "/../../../" + ToolChainDir)); - CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + - "/../../..")); -} - -void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { - // Note that this routine is only used for targetting OS X. - - // Derived from libgcc and lib specs but refactored. - if (Args.hasArg(options::OPT_static)) { - CmdArgs.push_back("-lgcc_static"); - } else { - if (Args.hasArg(options::OPT_static_libgcc)) { - CmdArgs.push_back("-lgcc_eh"); - } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { - // Derived from darwin_iphoneos_libgcc spec. - if (isTargetIPhoneOS()) { - CmdArgs.push_back("-lgcc_s.1"); - } else { - CmdArgs.push_back("-lgcc_s.10.5"); - } - } else if (Args.hasArg(options::OPT_shared_libgcc) || - Args.hasFlag(options::OPT_fexceptions, - options::OPT_fno_exceptions) || - Args.hasArg(options::OPT_fgnu_runtime)) { - // FIXME: This is probably broken on 10.3? - if (isMacosxVersionLT(10, 5)) - CmdArgs.push_back("-lgcc_s.10.4"); - else if (isMacosxVersionLT(10, 6)) - CmdArgs.push_back("-lgcc_s.10.5"); - } else { - if (isMacosxVersionLT(10, 3, 9)) - ; // Do nothing. - else if (isMacosxVersionLT(10, 5)) - CmdArgs.push_back("-lgcc_s.10.4"); - else if (isMacosxVersionLT(10, 6)) - CmdArgs.push_back("-lgcc_s.10.5"); - } - - if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) { - CmdArgs.push_back("-lgcc"); - CmdArgs.push_back("-lSystem"); - } else { - CmdArgs.push_back("-lSystem"); - CmdArgs.push_back("-lgcc"); - } - } -} DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple) : Darwin(Host, Triple) Modified: cfe/trunk/lib/Driver/ToolChains.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=127896&r1=127895&r2=127896&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.h (original) +++ cfe/trunk/lib/Driver/ToolChains.h Fri Mar 18 14:25:10 2011 @@ -246,29 +246,6 @@ /// } }; -/// DarwinGCC - The Darwin toolchain used by GCC. -class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin { - /// GCC version to use. - unsigned GCCVersion[3]; - - /// The directory suffix for this tool chain. - std::string ToolChainDir; - -public: - DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple); - - /// @name Darwin ToolChain Implementation - /// { - - virtual void AddLinkSearchPathArgs(const ArgList &Args, - ArgStringList &CmdArgs) const; - - virtual void AddLinkRuntimeLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const; - - /// } -}; - /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC { public: From daniel at zuster.org Fri Mar 18 14:25:15 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Fri, 18 Mar 2011 19:25:15 -0000 Subject: [cfe-commits] r127897 - /cfe/trunk/lib/Driver/ToolChains.cpp Message-ID: <20110318192515.E83372A6C12D@llvm.org> Author: ddunbar Date: Fri Mar 18 14:25:15 2011 New Revision: 127897 URL: http://llvm.org/viewvc/llvm-project?rev=127897&view=rev Log: Driver/Darwin: Change fallback to use llvm-gcc search paths instead of GCC. Modified: cfe/trunk/lib/Driver/ToolChains.cpp Modified: cfe/trunk/lib/Driver/ToolChains.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=127897&r1=127896&r2=127897&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Mar 18 14:25:15 2011 @@ -222,6 +222,8 @@ DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple) : Darwin(Host, Triple) { + std::string UsrPrefix = "llvm-gcc-4.2/"; + getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) getProgramPaths().push_back(getDriver().Dir); @@ -232,18 +234,18 @@ getProgramPaths().push_back(getDriver().Dir); // For fallback, we need to know how to find the GCC cc1 executables, so we - // also add the GCC libexec paths. This is legiy code that can be removed once - // fallback is no longer useful. + // also add the GCC libexec paths. This is legacy code that can be removed + // once fallback is no longer useful. std::string ToolChainDir = "i686-apple-darwin"; ToolChainDir += llvm::utostr(DarwinVersion[0]); ToolChainDir += "/4.2.1"; std::string Path = getDriver().Dir; - Path += "/../libexec/gcc/"; + Path += "/../" + UsrPrefix + "libexec/gcc/"; Path += ToolChainDir; getProgramPaths().push_back(Path); - Path = "/usr/libexec/gcc/"; + Path = "/usr/" + UsrPrefix + "libexec/gcc/"; Path += ToolChainDir; getProgramPaths().push_back(Path); } From daniel at zuster.org Fri Mar 18 15:14:00 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Fri, 18 Mar 2011 20:14:00 -0000 Subject: [cfe-commits] r127902 - in /cfe/trunk: include/clang/Driver/ToolChain.h lib/Driver/Driver.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h Message-ID: <20110318201400.6CD9D2A6C12C@llvm.org> Author: ddunbar Date: Fri Mar 18 15:14:00 2011 New Revision: 127902 URL: http://llvm.org/viewvc/llvm-project?rev=127902&view=rev Log: Driver: Give SelectTool access to the action inputs. Modified: cfe/trunk/include/clang/Driver/ToolChain.h cfe/trunk/lib/Driver/Driver.cpp cfe/trunk/lib/Driver/ToolChains.cpp cfe/trunk/lib/Driver/ToolChains.h Modified: cfe/trunk/include/clang/Driver/ToolChain.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=127902&r1=127901&r2=127902&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/ToolChain.h (original) +++ cfe/trunk/include/clang/Driver/ToolChain.h Fri Mar 18 15:14:00 2011 @@ -88,8 +88,10 @@ return 0; } - /// SelectTool - Choose a tool to use to handle the action \arg JA. - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0; + /// SelectTool - Choose a tool to use to handle the action \arg JA with the + /// given \arg Inputs. + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const = 0; // Helper methods Modified: cfe/trunk/lib/Driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=127902&r1=127901&r2=127902&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Driver.cpp (original) +++ cfe/trunk/lib/Driver/Driver.cpp Fri Mar 18 15:14:00 2011 @@ -1088,7 +1088,8 @@ !C.getArgs().hasArg(options::OPT_save_temps) && isa(JA) && Inputs->size() == 1 && isa(*Inputs->begin())) { - const Tool &Compiler = TC->SelectTool(C,cast(**Inputs->begin())); + const Tool &Compiler = TC->SelectTool( + C, cast(**Inputs->begin()), (*Inputs)[0]->getInputs()); if (Compiler.hasIntegratedAssembler()) { Inputs = &(*Inputs)[0]->getInputs(); ToolForJob = &Compiler; @@ -1097,7 +1098,7 @@ // Otherwise use the tool for the current job. if (!ToolForJob) - ToolForJob = &TC->SelectTool(C, *JA); + ToolForJob = &TC->SelectTool(C, *JA, *Inputs); // See if we should use an integrated preprocessor. We do so when we have // exactly one input, since this is the only use case we care about Modified: cfe/trunk/lib/Driver/ToolChains.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=127902&r1=127901&r2=127902&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Mar 18 15:14:00 2011 @@ -169,7 +169,8 @@ return Triple.getTriple(); } -Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -798,7 +799,8 @@ } Tool &Generic_GCC::SelectTool(const Compilation &C, - const JobAction &JA) const { + const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -886,7 +888,8 @@ } Tool &TCEToolChain::SelectTool(const Compilation &C, - const JobAction &JA) const { + const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; Key = Action::AnalyzeJobClass; @@ -912,7 +915,8 @@ getFilePaths().push_back("/usr/lib"); } -Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -936,7 +940,7 @@ case Action::LinkJobClass: T = new tools::openbsd::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -962,7 +966,8 @@ } } -Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -985,7 +990,7 @@ case Action::LinkJobClass: T = new tools::freebsd::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -1013,7 +1018,8 @@ } } -Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -1036,7 +1042,7 @@ case Action::LinkJobClass: T = new tools::netbsd::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -1053,7 +1059,8 @@ getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3"); } -Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -1068,7 +1075,7 @@ case Action::LinkJobClass: T = new tools::minix::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -1092,7 +1099,8 @@ } -Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -1107,7 +1115,7 @@ case Action::LinkJobClass: T = new tools::auroraux::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -1382,7 +1390,8 @@ return true; } -Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -1405,7 +1414,7 @@ case Action::LinkJobClass: T = new tools::linuxtools::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -1427,7 +1436,8 @@ getFilePaths().push_back("/usr/lib/gcc41"); } -Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; @@ -1442,7 +1452,7 @@ case Action::LinkJobClass: T = new tools::dragonfly::Link(*this); break; default: - T = &Generic_GCC::SelectTool(C, JA); + T = &Generic_GCC::SelectTool(C, JA, Inputs); } } @@ -1453,7 +1463,8 @@ : ToolChain(Host, Triple) { } -Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA) const { +Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const { Action::ActionClass Key; if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; Modified: cfe/trunk/lib/Driver/ToolChains.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=127902&r1=127901&r2=127902&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.h (original) +++ cfe/trunk/lib/Driver/ToolChains.h Fri Mar 18 15:14:00 2011 @@ -33,7 +33,8 @@ Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple); ~Generic_GCC(); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; virtual bool IsUnwindTablesDefault() const; virtual const char *GetDefaultRelocationModel() const; @@ -160,7 +161,8 @@ virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, const char *BoundArch) const; - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; virtual bool IsBlocksDefault() const { // Always allow blocks on Darwin; users interested in versioning are @@ -273,42 +275,48 @@ public: AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; }; class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF { public: OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; }; class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF { public: FreeBSD(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; }; class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF { public: NetBSD(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; }; class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC { public: Minix(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; }; class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF { public: DragonFly(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; }; class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { @@ -317,7 +325,8 @@ virtual bool HasNativeLLVMSupport() const; - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; std::string Linker; std::vector ExtraOpts; @@ -331,7 +340,8 @@ TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple); ~TCEToolChain(); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; bool IsMathErrnoDefault() const; bool IsUnwindTablesDefault() const; const char* GetDefaultRelocationModel() const; @@ -348,7 +358,8 @@ public: Windows(const HostInfo &Host, const llvm::Triple& Triple); - virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; + virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, + const ActionList &Inputs) const; virtual bool IsIntegratedAssemblerDefault() const; virtual bool IsUnwindTablesDefault() const; From daniel at zuster.org Fri Mar 18 15:14:03 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Fri, 18 Mar 2011 20:14:03 -0000 Subject: [cfe-commits] r127903 - in /cfe/trunk: lib/Driver/ToolChains.cpp test/Driver/apple-kext-i386.cpp Message-ID: <20110318201403.903232A6C12D@llvm.org> Author: ddunbar Date: Fri Mar 18 15:14:03 2011 New Revision: 127903 URL: http://llvm.org/viewvc/llvm-project?rev=127903&view=rev Log: Driver/Darwin: Transparently fallback when compiling i386 -fapple-kext code, we don't support the ABI yet. Added: cfe/trunk/test/Driver/apple-kext-i386.cpp Modified: cfe/trunk/lib/Driver/ToolChains.cpp Modified: cfe/trunk/lib/Driver/ToolChains.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=127903&r1=127902&r2=127903&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Mar 18 15:14:03 2011 @@ -172,9 +172,18 @@ Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA, const ActionList &Inputs) const { Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) - Key = Action::AnalyzeJobClass; - else + + if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) { + // Fallback to llvm-gcc for i386 kext compiles, we don't support that ABI. + if (Inputs.size() == 1 && + types::isCXX(Inputs[0]->getType()) && + getTriple().getOS() == llvm::Triple::Darwin && + getTriple().getArch() == llvm::Triple::x86 && + C.getArgs().getLastArg(options::OPT_fapple_kext)) + Key = JA.getKind(); + else + Key = Action::AnalyzeJobClass; + } else Key = JA.getKind(); // FIXME: This doesn't belong here, but ideally we will support static soon Added: cfe/trunk/test/Driver/apple-kext-i386.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/apple-kext-i386.cpp?rev=127903&view=auto ============================================================================== --- cfe/trunk/test/Driver/apple-kext-i386.cpp (added) +++ cfe/trunk/test/Driver/apple-kext-i386.cpp Fri Mar 18 15:14:03 2011 @@ -0,0 +1,9 @@ +// Check that we transparently fallback to llvm-gcc for i386 kexts, we don't +// support the ABI they use (yet). + +// RUN: %clang -ccc-host-triple i386-apple-darwin10 \ +// RUN: -fapple-kext -### -fsyntax-only %s 2> %t +// RUN: FileCheck --check-prefix=CHECK < %t %s + +// CHECK: cc1plus" +// CHECK: "-fapple-kext" From clattner at apple.com Fri Mar 18 15:22:28 2011 From: clattner at apple.com (Chris Lattner) Date: Fri, 18 Mar 2011 13:22:28 -0700 Subject: [cfe-commits] Skip UTF-8 BOM In-Reply-To: References: Message-ID: <8C4024BF-89B4-4158-A451-2056EAD2AA33@apple.com> On Mar 17, 2011, at 11:06 AM, Anton Korobeynikov wrote: >> I also had some files which had UTF-16 BOM at start, does it make sense to >> handle that also? > As soon as someone else will implement UTF-16 in clang - yes. Right > now clang supports utf-8 only, so skipping utf-8 BOM is perfectly ok. This looks great to me Anton, thanks for implementing this. Please commit it, *with* a testcase :) -Chris From daniel at zuster.org Fri Mar 18 16:23:38 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Fri, 18 Mar 2011 21:23:38 -0000 Subject: [cfe-commits] r127910 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Driver/CC1Options.td lib/Frontend/CompilerInvocation.cpp lib/Lex/Lexer.cpp test/Preprocessor/traditional-cpp.c Message-ID: <20110318212338.635892A6C12C@llvm.org> Author: ddunbar Date: Fri Mar 18 16:23:38 2011 New Revision: 127910 URL: http://llvm.org/viewvc/llvm-project?rev=127910&view=rev Log: Lexer: Add extremely limited support for -traditional-cpp, ignoring BCPL comments. Added: cfe/trunk/test/Preprocessor/traditional-cpp.c Modified: cfe/trunk/include/clang/Basic/LangOptions.h cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Lex/Lexer.cpp Modified: cfe/trunk/include/clang/Basic/LangOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=127910&r1=127909&r2=127910&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.h (original) +++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Mar 18 16:23:38 2011 @@ -56,6 +56,7 @@ unsigned ObjCExceptions : 1; // Support Objective-C exceptions. unsigned CXXExceptions : 1; // Support C++ exceptions. unsigned SjLjExceptions : 1; // Use setjmp-longjump exception handling. + unsigned TraditionalCPP : 1; /// Enable some traditional CPP emulation. unsigned RTTI : 1; // Support RTTI information. unsigned MSBitfields : 1; // MS-compatible structure layout @@ -169,7 +170,7 @@ C99 = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0; CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0; Exceptions = ObjCExceptions = CXXExceptions = SjLjExceptions = 0; - Freestanding = NoBuiltin = 0; + TraditionalCPP = Freestanding = NoBuiltin = 0; MSBitfields = 0; NeXTRuntime = 1; RTTI = 1; Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=127910&r1=127909&r2=127910&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Mar 18 16:23:38 2011 @@ -511,6 +511,8 @@ HelpText<"Store string literals as writable data">; def fno_bitfield_type_align : Flag<"-fno-bitfield-type-align">, HelpText<"Ignore bit-field types when aligning structures">; +def traditional_cpp : Flag<"-traditional-cpp">, + HelpText<"Enable some traditional CPP emulation">; //===----------------------------------------------------------------------===// // Header Search Options Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=127910&r1=127909&r2=127910&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Mar 18 16:23:38 2011 @@ -574,6 +574,8 @@ Res.push_back("-fcxx-exceptions"); if (Opts.SjLjExceptions) Res.push_back("-fsjlj-exceptions"); + if (Opts.TraditionalCPP) + Res.push_back("-traditional-cpp"); if (!Opts.RTTI) Res.push_back("-fno-rtti"); if (Opts.MSBitfields) @@ -1442,6 +1444,7 @@ Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); + Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); Opts.RTTI = !Args.hasArg(OPT_fno_rtti); Opts.Blocks = Args.hasArg(OPT_fblocks); Modified: cfe/trunk/lib/Lex/Lexer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=127910&r1=127909&r2=127910&view=diff ============================================================================== --- cfe/trunk/lib/Lex/Lexer.cpp (original) +++ cfe/trunk/lib/Lex/Lexer.cpp Fri Mar 18 16:23:38 2011 @@ -2091,7 +2091,7 @@ // If the next token is obviously a // or /* */ comment, skip it efficiently // too (without going through the big switch stmt). if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() && - Features.BCPLComment) { + Features.BCPLComment && !Features.TraditionalCPP) { if (SkipBCPLComment(Result, CurPtr+2)) return; // There is a token to return. goto SkipIgnoredUnits; @@ -2280,8 +2280,10 @@ // this as "foo / bar" and langauges with BCPL comments would lex it as // "foo". Check to see if the character after the second slash is a '*'. // If so, we will lex that as a "/" instead of the start of a comment. - if (Features.BCPLComment || - getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') { + // However, we never do this in -traditional-cpp mode. + if ((Features.BCPLComment || + getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') && + !Features.TraditionalCPP) { if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) return; // There is a token to return. Added: cfe/trunk/test/Preprocessor/traditional-cpp.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/traditional-cpp.c?rev=127910&view=auto ============================================================================== --- cfe/trunk/test/Preprocessor/traditional-cpp.c (added) +++ cfe/trunk/test/Preprocessor/traditional-cpp.c Fri Mar 18 16:23:38 2011 @@ -0,0 +1,12 @@ +/* Clang supports a very limited subset of -traditional-cpp, basically we only + * intend to add support for things that people actually rely on when doing + * things like using /usr/bin/cpp to preprocess non-source files. */ + +/* + RUN: %clang_cc1 -traditional-cpp %s -E -o %t + RUN: FileCheck < %t %s +*/ + +/* CHECK: foo // bar + */ +foo // bar From daniel at zuster.org Fri Mar 18 16:23:40 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Fri, 18 Mar 2011 21:23:40 -0000 Subject: [cfe-commits] r127911 - /cfe/trunk/lib/Driver/Tools.cpp Message-ID: <20110318212340.EA89A2A6C12D@llvm.org> Author: ddunbar Date: Fri Mar 18 16:23:40 2011 New Revision: 127911 URL: http://llvm.org/viewvc/llvm-project?rev=127911&view=rev Log: Driver: Forward -traditional and -traditional-cpp in preprocessing modes. - We don't really support the majority of the horrible -traditional-cpp behavior, but it is unlikely that we ever will either. This allows us to start trying to use clang as a /usr/bin/cpp replacement and see what pieces of -traditional-cpp mode people actually care about. Modified: cfe/trunk/lib/Driver/Tools.cpp Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127911&r1=127910&r2=127911&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Fri Mar 18 16:23:40 2011 @@ -1773,9 +1773,14 @@ } #endif + // Only allow -traditional or -traditional-cpp outside in preprocessing modes. if (Arg *A = Args.getLastArg(options::OPT_traditional, - options::OPT_traditional_cpp)) - D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); + options::OPT_traditional_cpp)) { + if (isa(JA)) + CmdArgs.push_back("-traditional-cpp"); + else + D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); + } Args.AddLastArg(CmdArgs, options::OPT_dM); Args.AddLastArg(CmdArgs, options::OPT_dD); From kremenek at apple.com Fri Mar 18 17:11:41 2011 From: kremenek at apple.com (Ted Kremenek) Date: Fri, 18 Mar 2011 22:11:41 -0000 Subject: [cfe-commits] r127914 - /cfe/trunk/docs/tools/clang.pod Message-ID: <20110318221141.2C7B52A6C12C@llvm.org> Author: kremenek Date: Fri Mar 18 17:11:40 2011 New Revision: 127914 URL: http://llvm.org/viewvc/llvm-project?rev=127914&view=rev Log: Remove '-Xclang' and '-mllvm' entries from Clang man page. The later is only available in debug builds and the former is not supposed to be used by end-users. Modified: cfe/trunk/docs/tools/clang.pod Modified: cfe/trunk/docs/tools/clang.pod URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/clang.pod?rev=127914&r1=127913&r2=127914&view=diff ============================================================================== --- cfe/trunk/docs/tools/clang.pod (original) +++ cfe/trunk/docs/tools/clang.pod Fri Mar 18 17:11:40 2011 @@ -356,18 +356,10 @@ Pass I to the assembler. -=item B<-Xclang> I - -Pass I to the clang compiler frontend. - =item B<-Xlinker> I Pass I to the linker. -=item B<-mllvm> I - -Pass I to the LLVM backend. - =item B<-Xpreprocessor> I Pass I to the preprocessor. From anton.yartsev at gmail.com Fri Mar 18 17:16:54 2011 From: anton.yartsev at gmail.com (Anton Yartsev) Date: Sat, 19 Mar 2011 01:16:54 +0300 Subject: [cfe-commits] [PATCH][Review request] correct initialization of AltiVec vectors In-Reply-To: <3A38D3F1-D548-419F-9095-7EFE65F72299@apple.com> References: <4CF32459.2000700@Gmail.com> <4D1BCEFC.8020303@Gmail.com> <87A3C667-726E-4C41-B463-8614B8B295D7@apple.com> <4D3F4468.1030000@Gmail.com> <400B9C54-D5E0-4B94-9A79-58997009DB9E@apple.com> <4D5BA715.70204@Gmail.com> <3A38D3F1-D548-419F-9095-7EFE65F72299@apple.com> Message-ID: <4D83D9D6.1080606@Gmail.com> Thanks for the review! > Index: lib/CodeGen/CGExprConstant.cpp > > =================================================================== > --- lib/CodeGen/CGExprConstant.cpp (revision 124983) > +++ lib/CodeGen/CGExprConstant.cpp (working copy) > @@ -907,12 +907,29 @@ > > llvm::SmallVector Inits; > unsigned NumElts = Result.Val.getVectorLength(); > > - for (unsigned i = 0; i != NumElts; ++i) { > - APValue&Elt = Result.Val.getVectorElt(i); > - if (Elt.isInt()) > - Inits.push_back(llvm::ConstantInt::get(VMContext, Elt.getInt())); > - else > - Inits.push_back(llvm::ConstantFP::get(VMContext, Elt.getFloat())); > + if (Context.getLangOptions().AltiVec&& > + isa(E)&& > + dyn_cast(E)->getCastKind() == CK_VectorSplat) { > > Why check for a C-style cast here? Why not just check for a (general) CastExpr, which would also cover C-style casts (e.g., static_cast) and implicit casts? The goal of this 'if' is to detect an AltiVec vector initialization with a single literal and I know that it should be exactly CStyleCastExpr: Index: lib/Sema/SemaExpr.cpp =================================================================== ..... + if (PE->getNumExprs() == 1) { ..... + return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal); + } > Also, one little nit: if you've already done an isa(X), you can just cast(X) rather than dyn_cast(X), and save ourselves some checking. corrected! Can I commit the patch? -- Anton From peter at pcc.me.uk Fri Mar 18 17:38:30 2011 From: peter at pcc.me.uk (Peter Collingbourne) Date: Fri, 18 Mar 2011 22:38:30 -0000 Subject: [cfe-commits] r127915 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ include/clang/Driver/ include/clang/Parse/ include/clang/Sema/ lib/AST/ lib/Basic/ lib/CodeGen/ lib/Frontend/ lib/Parse/ lib/Sema/ test/CodeGenOpenCL/ test/Parser/ Message-ID: <20110318223830.D70C82A6C12C@llvm.org> Author: pcc Date: Fri Mar 18 17:38:29 2011 New Revision: 127915 URL: http://llvm.org/viewvc/llvm-project?rev=127915&view=rev Log: Add support for language-specific address spaces. On top of that, add support for the OpenCL __private, __local, __constant and __global address spaces, as well as the __read_only, _read_write and __write_only image access specifiers. Patch originally by ARM; language-specific address space support by myself. Added: cfe/trunk/include/clang/Basic/AddressSpaces.h cfe/trunk/include/clang/Basic/OpenCL.h cfe/trunk/test/CodeGenOpenCL/address-spaces.cl cfe/trunk/test/Parser/opencl-image-access.cl Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/include/clang/Basic/LangOptions.h cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/include/clang/Basic/TokenKinds.def cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/Parse/Parser.h cfe/trunk/include/clang/Sema/AttributeList.h cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/Basic/TargetInfo.cpp cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDecl.cpp cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/CodeGen/CodeGenTypes.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Sema/AttributeList.cpp cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Fri Mar 18 17:38:29 2011 @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_AST_ASTCONTEXT_H #define LLVM_CLANG_AST_ASTCONTEXT_H +#include "clang/Basic/AddressSpaces.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/OperatorKinds.h" @@ -311,6 +312,9 @@ llvm::OwningPtr ABI; CXXABI *createCXXABI(const TargetInfo &T); + /// \brief The logical -> physical address space map. + const LangAS::Map &AddrSpaceMap; + friend class ASTDeclReader; public: @@ -1295,6 +1299,21 @@ QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, QualType typeDomain) const; + unsigned getTargetAddressSpace(QualType T) const { + return getTargetAddressSpace(T.getQualifiers()); + } + + unsigned getTargetAddressSpace(Qualifiers Q) const { + return getTargetAddressSpace(Q.getAddressSpace()); + } + + unsigned getTargetAddressSpace(unsigned AS) const { + if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count) + return AS; + else + return AddrSpaceMap[AS - LangAS::Offset]; + } + private: // Helper for integer ordering unsigned getIntegerRank(const Type *T) const; Added: cfe/trunk/include/clang/Basic/AddressSpaces.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=127915&view=auto ============================================================================== --- cfe/trunk/include/clang/Basic/AddressSpaces.h (added) +++ cfe/trunk/include/clang/Basic/AddressSpaces.h Fri Mar 18 17:38:29 2011 @@ -0,0 +1,44 @@ +//===--- AddressSpaces.h - Language-specific address spaces -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides definitions for the various language-specific address +// spaces. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H +#define LLVM_CLANG_BASIC_ADDRESSSPACES_H + +namespace clang { + +namespace LangAS { + +/// This enum defines the set of possible language-specific address spaces. +/// It uses a high starting offset so as not to conflict with any address +/// space used by a target. +enum ID { + Offset = 0xFFFF00, + + opencl_global = Offset, + opencl_local, + opencl_constant, + + Last, + Count = Last-Offset +}; + +/// The type of a lookup table which maps from language-specific address spaces +/// to target-specific ones. +typedef unsigned Map[Count]; + +} + +} + +#endif Modified: cfe/trunk/include/clang/Basic/LangOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.h (original) +++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Mar 18 17:38:29 2011 @@ -124,6 +124,8 @@ unsigned DefaultFPContract : 1; // Default setting for FP_CONTRACT // FIXME: This is just a temporary option, for testing purposes. unsigned NoBitFieldTypeAlign : 1; + unsigned FakeAddressSpaceMap : 1; // Use a fake address space map, for + // testing languages such as OpenCL. unsigned MRTD : 1; // -mrtd calling convention Added: cfe/trunk/include/clang/Basic/OpenCL.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCL.h?rev=127915&view=auto ============================================================================== --- cfe/trunk/include/clang/Basic/OpenCL.h (added) +++ cfe/trunk/include/clang/Basic/OpenCL.h Fri Mar 18 17:38:29 2011 @@ -0,0 +1,28 @@ +//===--- OpenCL.h - OpenCL enums --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines some OpenCL-specific enums. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_OPENCL_H +#define LLVM_CLANG_BASIC_OPENCL_H + +namespace clang { + +/// Names for the OpenCL image access qualifiers (OpenCL 1.1 6.6). +enum OpenCLImageAccess { + CLIA_read_only = 1, + CLIA_write_only = 2, + CLIA_read_write = 3 +}; + +} + +#endif Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Mar 18 17:38:29 2011 @@ -19,6 +19,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Support/DataTypes.h" +#include "clang/Basic/AddressSpaces.h" #include #include #include @@ -78,6 +79,7 @@ const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat; unsigned char RegParmMax, SSERegParmMax; TargetCXXABI CXXABI; + const LangAS::Map *AddrSpaceMap; unsigned HasAlignMac68kSupport : 1; unsigned RealTypeUsesObjCFPRet : 3; @@ -530,6 +532,11 @@ virtual const char *getStaticInitSectionSpecifier() const { return 0; } + + const LangAS::Map &getAddressSpaceMap() const { + return *AddrSpaceMap; + } + protected: virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return PointerWidth; Modified: cfe/trunk/include/clang/Basic/TokenKinds.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/TokenKinds.def (original) +++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Mar 18 17:38:29 2011 @@ -252,7 +252,7 @@ KEYWORD(namespace , KEYCXX) KEYWORD(new , KEYCXX) KEYWORD(operator , KEYCXX) -KEYWORD(private , KEYCXX) +KEYWORD(private , KEYCXX|KEYOPENCL) KEYWORD(protected , KEYCXX) KEYWORD(public , KEYCXX) KEYWORD(reinterpret_cast , KEYCXX) @@ -350,6 +350,19 @@ KEYWORD(__kernel , KEYOPENCL) ALIAS("kernel", __kernel , KEYOPENCL) KEYWORD(vec_step , KEYOPENCL) +KEYWORD(__private , KEYOPENCL) +KEYWORD(__global , KEYOPENCL) +KEYWORD(__local , KEYOPENCL) +KEYWORD(__constant , KEYOPENCL) +ALIAS("global", __global , KEYOPENCL) +ALIAS("local", __local , KEYOPENCL) +ALIAS("constant", __constant , KEYOPENCL) +KEYWORD(__read_only , KEYOPENCL) +KEYWORD(__write_only , KEYOPENCL) +KEYWORD(__read_write , KEYOPENCL) +ALIAS("read_only", __read_only , KEYOPENCL) +ALIAS("write_only", __write_only , KEYOPENCL) +ALIAS("read_write", __read_write , KEYOPENCL) // Borland Extensions. KEYWORD(__pascal , KEYALL) Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Mar 18 17:38:29 2011 @@ -513,6 +513,8 @@ HelpText<"Ignore bit-field types when aligning structures">; def traditional_cpp : Flag<"-traditional-cpp">, HelpText<"Enable some traditional CPP emulation">; +def ffake_address_space_map : Flag<"-ffake-address-space-map">, + HelpText<"Use a fake address space map; OpenCL testing purposes only">; //===----------------------------------------------------------------------===// // Header Search Options Modified: cfe/trunk/include/clang/Parse/Parser.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/Parse/Parser.h (original) +++ cfe/trunk/include/clang/Parse/Parser.h Fri Mar 18 17:38:29 2011 @@ -1546,6 +1546,7 @@ void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); void ParseBorlandTypeAttributes(ParsedAttributes &attrs); void ParseOpenCLAttributes(ParsedAttributes &attrs); + void ParseOpenCLQualifiers(DeclSpec &DS); void ParseTypeofSpecifier(DeclSpec &DS); void ParseDecltypeSpecifier(DeclSpec &DS); Modified: cfe/trunk/include/clang/Sema/AttributeList.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/AttributeList.h (original) +++ cfe/trunk/include/clang/Sema/AttributeList.h Fri Mar 18 17:38:29 2011 @@ -18,6 +18,7 @@ #include "llvm/Support/Allocator.h" #include "clang/Sema/Ownership.h" #include "clang/Basic/SourceLocation.h" +#include "clang/AST/Expr.h" #include namespace clang { @@ -76,6 +77,13 @@ declspec, cxx0x); return Mem; } + + AttributeList* CreateIntegerAttribute(ASTContext &C, IdentifierInfo *Name, + SourceLocation TokLoc, int Arg) { + Expr* IArg = IntegerLiteral::Create(C, llvm::APInt(32, (uint64_t)Arg), + C.IntTy, TokLoc); + return Create( Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0); + } }; enum Kind { // Please keep this list alphabetized. @@ -135,6 +143,7 @@ AT_ns_consumed, // Clang-specific. AT_ns_consumes_self, // Clang-specific. AT_objc_gc, + AT_opencl_image_access, // OpenCL-specific. AT_opencl_kernel_function, // OpenCL-specific. AT_overloadable, // Clang-specific. AT_ownership_holds, // Clang-specific. Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Fri Mar 18 17:38:29 2011 @@ -190,6 +190,22 @@ return 0; } +static const LangAS::Map &getAddressSpaceMap(const TargetInfo &T, + const LangOptions &LOpts) { + if (LOpts.FakeAddressSpaceMap) { + // The fake address space map must have a distinct entry for each + // language-specific address space. + static const unsigned FakeAddrSpaceMap[] = { + 1, // opencl_global + 2, // opencl_local + 3 // opencl_constant + }; + return FakeAddrSpaceMap; + } else { + return T.getAddressSpaceMap(); + } +} + ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t, IdentifierTable &idents, SelectorTable &sels, @@ -204,7 +220,8 @@ sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0), NullTypeSourceInfo(QualType()), - SourceMgr(SM), LangOpts(LOpts), ABI(createCXXABI(t)), Target(t), + SourceMgr(SM), LangOpts(LOpts), ABI(createCXXABI(t)), + AddrSpaceMap(getAddressSpaceMap(t, LOpts)), Target(t), Idents(idents), Selectors(sels), BuiltinInfo(builtins), DeclarationNames(*this), @@ -806,7 +823,8 @@ Align = Target.getPointerAlign(0); break; case Type::BlockPointer: { - unsigned AS = cast(T)->getPointeeType().getAddressSpace(); + unsigned AS = getTargetAddressSpace( + cast(T)->getPointeeType()); Width = Target.getPointerWidth(AS); Align = Target.getPointerAlign(AS); break; @@ -815,13 +833,14 @@ case Type::RValueReference: { // alignof and sizeof should never enter this code path here, so we go // the pointer route. - unsigned AS = cast(T)->getPointeeType().getAddressSpace(); + unsigned AS = getTargetAddressSpace( + cast(T)->getPointeeType()); Width = Target.getPointerWidth(AS); Align = Target.getPointerAlign(AS); break; } case Type::Pointer: { - unsigned AS = cast(T)->getPointeeType().getAddressSpace(); + unsigned AS = getTargetAddressSpace(cast(T)->getPointeeType()); Width = Target.getPointerWidth(AS); Align = Target.getPointerAlign(AS); break; @@ -1468,7 +1487,7 @@ // the target. llvm::APInt ArySize(ArySizeIn); ArySize = - ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); + ArySize.zextOrTrunc(Target.getPointerWidth(getTargetAddressSpace(EltTy))); llvm::FoldingSetNodeID ID; ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, IndexTypeQuals); Modified: cfe/trunk/lib/Basic/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/Basic/TargetInfo.cpp (original) +++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Mar 18 17:38:29 2011 @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/AddressSpaces.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/LangOptions.h" #include "llvm/ADT/APFloat.h" @@ -19,6 +20,8 @@ #include using namespace clang; +static const LangAS::Map DefaultAddrSpaceMap = { 0 }; + // TargetInfo Constructor. TargetInfo::TargetInfo(const std::string &T) : Triple(T) { // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or @@ -64,6 +67,9 @@ // Default to using the Itanium ABI. CXXABI = CXXABI_Itanium; + + // Default to an empty address space map. + AddrSpaceMap = &DefaultAddrSpaceMap; } // Out of line virtual dtor for TargetInfo. Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Mar 18 17:38:29 2011 @@ -627,7 +627,8 @@ assert(!RetAI.getIndirectAlign() && "Align unused on indirect return."); ResultType = llvm::Type::getVoidTy(getLLVMContext()); const llvm::Type *STy = ConvertType(RetTy, IsRecursive); - ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace())); + unsigned AS = Context.getTargetAddressSpace(RetTy); + ArgTys.push_back(llvm::PointerType::get(STy, AS)); break; } Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Mar 18 17:38:29 2011 @@ -462,8 +462,8 @@ // Bit size, align and offset of the type. // Size is always the size of a pointer. We can't use getTypeSize here // because that does not return the correct value for references. - uint64_t Size = - CGM.getContext().Target.getPointerWidth(PointeeTy.getAddressSpace()); + unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy); + uint64_t Size = CGM.getContext().Target.getPointerWidth(AS); uint64_t Align = CGM.getContext().getTypeAlign(Ty); return Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Mar 18 17:38:29 2011 @@ -179,7 +179,8 @@ new llvm::GlobalVariable(CGM.getModule(), LTy, Ty.isConstant(getContext()), Linkage, CGM.EmitNullConstant(D.getType()), Name, 0, - D.isThreadSpecified(), Ty.getAddressSpace()); + D.isThreadSpecified(), + CGM.getContext().getTargetAddressSpace(Ty)); GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); if (Linkage != llvm::GlobalValue::InternalLinkage) GV->setVisibility(CurFn->getVisibility()); @@ -222,7 +223,7 @@ OldGV->getLinkage(), Init, "", /*InsertBefore*/ OldGV, D.isThreadSpecified(), - D.getType().getAddressSpace()); + CGM.getContext().getTargetAddressSpace(D.getType())); GV->setVisibility(OldGV->getVisibility()); // Steal the name of the old global @@ -289,7 +290,8 @@ // FIXME: It is really dangerous to store this in the map; if anyone // RAUW's the GV uses of this constant will be invalid. const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType()); - const llvm::Type *LPtrTy = LTy->getPointerTo(D.getType().getAddressSpace()); + const llvm::Type *LPtrTy = + LTy->getPointerTo(CGM.getContext().getTargetAddressSpace(D.getType())); DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy); // Emit global variable debug descriptor for static vars. @@ -724,7 +726,8 @@ // Get the element type. const llvm::Type *LElemTy = ConvertTypeForMem(Ty); - const llvm::Type *LElemPtrTy = LElemTy->getPointerTo(Ty.getAddressSpace()); + const llvm::Type *LElemPtrTy = + LElemTy->getPointerTo(CGM.getContext().getTargetAddressSpace(Ty)); llvm::Value *VLASize = EmitVLASize(Ty); Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Mar 18 17:38:29 2011 @@ -726,7 +726,7 @@ // Cast to the access type. const llvm::Type *PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), AI.AccessWidth, - ExprType.getAddressSpace()); + CGM.getContext().getTargetAddressSpace(ExprType)); Ptr = Builder.CreateBitCast(Ptr, PTy); // Perform the load. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Mar 18 17:38:29 2011 @@ -800,7 +800,7 @@ E->getType().isConstant(CGM.getContext()), llvm::GlobalValue::InternalLinkage, C, ".compoundliteral", 0, false, - E->getType().getAddressSpace()); + CGM.getContext().getTargetAddressSpace(E->getType())); return C; } case Expr::DeclRefExprClass: { Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Mar 18 17:38:29 2011 @@ -1060,7 +1060,7 @@ Ty = getTypes().ConvertTypeForMem(ASTTy); const llvm::PointerType *PTy = - llvm::PointerType::get(Ty, ASTTy.getAddressSpace()); + llvm::PointerType::get(Ty, getContext().getTargetAddressSpace(ASTTy)); llvm::StringRef MangledName = getMangledName(D); return GetOrCreateLLVMGlobal(MangledName, PTy, D); @@ -1239,7 +1239,8 @@ // from the type of the global (this happens with unions). if (GV == 0 || GV->getType()->getElementType() != InitType || - GV->getType()->getAddressSpace() != ASTTy.getAddressSpace()) { + GV->getType()->getAddressSpace() != + getContext().getTargetAddressSpace(ASTTy)) { // Move the old entry aside so that we'll create a new one. Entry->setName(llvm::StringRef()); Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Fri Mar 18 17:38:29 2011 @@ -270,14 +270,16 @@ QualType ETy = RTy.getPointeeType(); llvm::OpaqueType *PointeeType = llvm::OpaqueType::get(getLLVMContext()); PointersToResolve.push_back(std::make_pair(ETy, PointeeType)); - return llvm::PointerType::get(PointeeType, ETy.getAddressSpace()); + unsigned AS = Context.getTargetAddressSpace(ETy); + return llvm::PointerType::get(PointeeType, AS); } case Type::Pointer: { const PointerType &PTy = cast(Ty); QualType ETy = PTy.getPointeeType(); llvm::OpaqueType *PointeeType = llvm::OpaqueType::get(getLLVMContext()); PointersToResolve.push_back(std::make_pair(ETy, PointeeType)); - return llvm::PointerType::get(PointeeType, ETy.getAddressSpace()); + unsigned AS = Context.getTargetAddressSpace(ETy); + return llvm::PointerType::get(PointeeType, AS); } case Type::VariableArray: { @@ -402,7 +404,8 @@ const QualType FTy = cast(Ty).getPointeeType(); llvm::OpaqueType *PointeeType = llvm::OpaqueType::get(getLLVMContext()); PointersToResolve.push_back(std::make_pair(FTy, PointeeType)); - return llvm::PointerType::get(PointeeType, FTy.getAddressSpace()); + unsigned AS = Context.getTargetAddressSpace(FTy); + return llvm::PointerType::get(PointeeType, AS); } case Type::MemberPointer: { Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Mar 18 17:38:29 2011 @@ -672,6 +672,8 @@ Res.push_back("-fconstant-string-class"); Res.push_back(Opts.ObjCConstantStringClass); } + if (Opts.FakeAddressSpaceMap) + Res.push_back("-ffake-address-space-map"); } static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts, @@ -1483,6 +1485,7 @@ Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); Opts.OptimizeSize = 0; Opts.MRTD = Args.hasArg(OPT_mrtd); + Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); // FIXME: Eliminate this dependency. unsigned Opt = getOptimizationLevel(Args, IK, Diags); Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Mar 18 17:38:29 2011 @@ -13,6 +13,7 @@ #include "clang/Parse/Parser.h" #include "clang/Parse/ParseDiagnostic.h" +#include "clang/Basic/OpenCL.h" #include "clang/Sema/Scope.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/PrettyDeclStackTrace.h" @@ -311,6 +312,56 @@ } } +void Parser::ParseOpenCLQualifiers(DeclSpec &DS) { + SourceLocation Loc = Tok.getLocation(); + switch(Tok.getKind()) { + // OpenCL qualifiers: + case tok::kw___private: + case tok::kw_private: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("address_space"), Loc, 0)); + break; + + case tok::kw___global: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("address_space"), Loc, LangAS::opencl_global)); + break; + + case tok::kw___local: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("address_space"), Loc, LangAS::opencl_local)); + break; + + case tok::kw___constant: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("address_space"), Loc, LangAS::opencl_constant)); + break; + + case tok::kw___read_only: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("opencl_image_access"), Loc, CLIA_read_only)); + break; + + case tok::kw___write_only: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("opencl_image_access"), Loc, CLIA_write_only)); + break; + + case tok::kw___read_write: + DS.addAttributes(AttrFactory.CreateIntegerAttribute( + Actions.getASTContext(), + PP.getIdentifierInfo("opencl_image_access"), Loc, CLIA_read_write)); + break; + default: break; + } +} + void Parser::DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs) { Diag(attrs.Range.getBegin(), diag::err_attributes_not_allowed) << attrs.Range; @@ -1446,6 +1497,20 @@ ParseDecltypeSpecifier(DS); continue; + // OpenCL qualifiers: + case tok::kw_private: + if (!getLang().OpenCL) + goto DoneWithDeclSpec; + case tok::kw___private: + case tok::kw___global: + case tok::kw___local: + case tok::kw___constant: + case tok::kw___read_only: + case tok::kw___write_only: + case tok::kw___read_write: + ParseOpenCLQualifiers(DS); + break; + case tok::less: // GCC ObjC supports types like "" as a synonym for // "id". This is hopelessly old fashioned and dangerous, @@ -1697,6 +1762,20 @@ ParseDecltypeSpecifier(DS); return true; + // OpenCL qualifiers: + case tok::kw_private: + if (!getLang().OpenCL) + return false; + case tok::kw___private: + case tok::kw___global: + case tok::kw___local: + case tok::kw___constant: + case tok::kw___read_only: + case tok::kw___write_only: + case tok::kw___read_write: + ParseOpenCLQualifiers(DS); + break; + // C++0x auto support. case tok::kw_auto: if (!getLang().CPlusPlus0x) @@ -2269,10 +2348,22 @@ bool Parser::isTypeQualifier() const { switch (Tok.getKind()) { default: return false; + + // type-qualifier only in OpenCL + case tok::kw_private: + return getLang().OpenCL; + // type-qualifier case tok::kw_const: case tok::kw_volatile: case tok::kw_restrict: + case tok::kw___private: + case tok::kw___local: + case tok::kw___global: + case tok::kw___constant: + case tok::kw___read_only: + case tok::kw___read_write: + case tok::kw___write_only: return true; } } @@ -2400,7 +2491,19 @@ case tok::kw___w64: case tok::kw___ptr64: case tok::kw___pascal: + + case tok::kw___private: + case tok::kw___local: + case tok::kw___global: + case tok::kw___constant: + case tok::kw___read_only: + case tok::kw___read_write: + case tok::kw___write_only: + return true; + + case tok::kw_private: + return getLang().OpenCL; } } @@ -2413,6 +2516,9 @@ switch (Tok.getKind()) { default: return false; + case tok::kw_private: + return getLang().OpenCL; + case tok::identifier: // foo::bar // Unfortunate hack to support "Class.factoryMethod" notation. if (getLang().ObjC1 && NextToken().is(tok::period)) @@ -2522,6 +2628,15 @@ case tok::kw___ptr64: case tok::kw___forceinline: case tok::kw___pascal: + + case tok::kw___private: + case tok::kw___local: + case tok::kw___global: + case tok::kw___constant: + case tok::kw___read_only: + case tok::kw___read_write: + case tok::kw___write_only: + return true; } } @@ -2627,6 +2742,21 @@ isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID, getLang()); break; + + // OpenCL qualifiers: + case tok::kw_private: + if (!getLang().OpenCL) + goto DoneWithTypeQuals; + case tok::kw___private: + case tok::kw___global: + case tok::kw___local: + case tok::kw___constant: + case tok::kw___read_only: + case tok::kw___write_only: + case tok::kw___read_write: + ParseOpenCLQualifiers(DS); + break; + case tok::kw___w64: case tok::kw___ptr64: case tok::kw___cdecl: Modified: cfe/trunk/lib/Sema/AttributeList.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/Sema/AttributeList.cpp (original) +++ cfe/trunk/lib/Sema/AttributeList.cpp Fri Mar 18 17:38:29 2011 @@ -94,6 +94,7 @@ .Case("unavailable", AT_unavailable) .Case("overloadable", AT_overloadable) .Case("address_space", AT_address_space) + .Case("opencl_image_access", AT_opencl_image_access) .Case("always_inline", AT_always_inline) .Case("returns_twice", IgnoredAttribute) .Case("vec_type_hint", IgnoredAttribute) Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Mar 18 17:38:29 2011 @@ -2724,6 +2724,7 @@ case AttributeList::AT_IBOutletCollection: HandleIBOutletCollection(D, Attr, S); break; case AttributeList::AT_address_space: + case AttributeList::AT_opencl_image_access: case AttributeList::AT_objc_gc: case AttributeList::AT_vector_size: case AttributeList::AT_neon_vector_type: Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127915&r1=127914&r2=127915&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Fri Mar 18 17:38:29 2011 @@ -13,6 +13,7 @@ #include "clang/Sema/SemaInternal.h" #include "clang/Sema/Template.h" +#include "clang/Basic/OpenCL.h" #include "clang/AST/ASTContext.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/DeclObjC.h" @@ -2965,6 +2966,41 @@ return true; } +/// Handle OpenCL image access qualifiers: read_only, write_only, read_write +static void HandleOpenCLImageAccessAttribute(QualType& CurType, + const AttributeList &Attr, + Sema &S) { + // Check the attribute arguments. + if (Attr.getNumArgs() != 1) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; + Attr.setInvalid(); + return; + } + Expr *sizeExpr = static_cast(Attr.getArg(0)); + llvm::APSInt arg(32); + if (sizeExpr->isTypeDependent() || sizeExpr->isValueDependent() || + !sizeExpr->isIntegerConstantExpr(arg, S.Context)) { + S.Diag(Attr.getLoc(), diag::err_attribute_argument_not_int) + << "opencl_image_access" << sizeExpr->getSourceRange(); + Attr.setInvalid(); + return; + } + unsigned iarg = static_cast(arg.getZExtValue()); + switch (iarg) { + case CLIA_read_only: + case CLIA_write_only: + case CLIA_read_write: + // Implemented in a separate patch + break; + default: + // Implemented in a separate patch + S.Diag(Attr.getLoc(), diag::err_attribute_invalid_size) + << sizeExpr->getSourceRange(); + Attr.setInvalid(); + break; + } +} + /// HandleVectorSizeAttribute - this attribute is only applicable to integral /// and float scalars, although arrays, pointers, and function return values are /// allowed in conjunction with this construct. Aggregates with this attribute @@ -3119,6 +3155,10 @@ "neon_polyvector_type"); break; + case AttributeList::AT_opencl_image_access: + HandleOpenCLImageAccessAttribute(type, attr, state.getSema()); + break; + FUNCTION_TYPE_ATTRS_CASELIST: // Never process function type attributes as part of the // declaration-specifiers. Added: cfe/trunk/test/CodeGenOpenCL/address-spaces.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/address-spaces.cl?rev=127915&view=auto ============================================================================== --- cfe/trunk/test/CodeGenOpenCL/address-spaces.cl (added) +++ cfe/trunk/test/CodeGenOpenCL/address-spaces.cl Fri Mar 18 17:38:29 2011 @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -ffake-address-space-map -emit-llvm -o - | FileCheck %s + +void f__p(__private int *arg) { } +// CHECK: i32* nocapture %arg + +void f__g(__global int *arg) { } +// CHECK: i32 addrspace(1)* nocapture %arg + +void f__l(__local int *arg) { } +// CHECK: i32 addrspace(2)* nocapture %arg + +void f__c(__constant int *arg) { } +// CHECK: i32 addrspace(3)* nocapture %arg + + +void fp(private int *arg) { } +// CHECK: i32* nocapture %arg + +void fg(global int *arg) { } +// CHECK: i32 addrspace(1)* nocapture %arg + +void fl(local int *arg) { } +// CHECK: i32 addrspace(2)* nocapture %arg + +void fc(constant int *arg) { } +// CHECK: i32 addrspace(3)* nocapture %arg + Added: cfe/trunk/test/Parser/opencl-image-access.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/opencl-image-access.cl?rev=127915&view=auto ============================================================================== --- cfe/trunk/test/Parser/opencl-image-access.cl (added) +++ cfe/trunk/test/Parser/opencl-image-access.cl Fri Mar 18 17:38:29 2011 @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -fsyntax-only + +typedef void* image2d_t; + +__kernel void f__ro(__read_only image2d_t a) { } + +__kernel void f__wo(__write_only image2d_t a) { } + +__kernel void f__rw(__read_write image2d_t a) { } + + +__kernel void fro(read_only image2d_t a) { } + +__kernel void fwo(write_only image2d_t a) { } + +__kernel void frw(read_write image2d_t a) { } From kremenek at apple.com Fri Mar 18 17:51:30 2011 From: kremenek at apple.com (Ted Kremenek) Date: Fri, 18 Mar 2011 22:51:30 -0000 Subject: [cfe-commits] r127919 - /cfe/trunk/tools/libclang/CIndex.cpp Message-ID: <20110318225130.424FC2A6C12C@llvm.org> Author: kremenek Date: Fri Mar 18 17:51:30 2011 New Revision: 127919 URL: http://llvm.org/viewvc/llvm-project?rev=127919&view=rev Log: Run all functional logic of clang_annotateTokens() within a CrashRecoveryContext. Fixes . Modified: cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127919&r1=127918&r2=127919&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Fri Mar 18 17:51:30 2011 @@ -4566,43 +4566,36 @@ return static_cast(client_data)->Visit(cursor, parent); } -// This gets run a separate thread to avoid stack blowout. -static void runAnnotateTokensWorker(void *UserData) { - ((AnnotateTokensWorker*)UserData)->AnnotateTokens(); +namespace { + struct clang_annotateTokens_Data { + CXTranslationUnit TU; + ASTUnit *CXXUnit; + CXToken *Tokens; + unsigned NumTokens; + CXCursor *Cursors; + }; } -extern "C" { - -void clang_annotateTokens(CXTranslationUnit TU, - CXToken *Tokens, unsigned NumTokens, - CXCursor *Cursors) { - - if (NumTokens == 0 || !Tokens || !Cursors) - return; - - // Any token we don't specifically annotate will have a NULL cursor. - CXCursor C = clang_getNullCursor(); - for (unsigned I = 0; I != NumTokens; ++I) - Cursors[I] = C; - - ASTUnit *CXXUnit = static_cast(TU->TUData); - if (!CXXUnit) - return; - - ASTUnit::ConcurrencyCheck Check(*CXXUnit); +// This gets run a separate thread to avoid stack blowout. +static void clang_annotateTokensImpl(void *UserData) { + CXTranslationUnit TU = ((clang_annotateTokens_Data*)UserData)->TU; + ASTUnit *CXXUnit = ((clang_annotateTokens_Data*)UserData)->CXXUnit; + CXToken *Tokens = ((clang_annotateTokens_Data*)UserData)->Tokens; + const unsigned NumTokens = ((clang_annotateTokens_Data*)UserData)->NumTokens; + CXCursor *Cursors = ((clang_annotateTokens_Data*)UserData)->Cursors; // Determine the region of interest, which contains all of the tokens. SourceRange RegionOfInterest; - RegionOfInterest.setBegin(cxloc::translateSourceLocation( - clang_getTokenLocation(TU, Tokens[0]))); - RegionOfInterest.setEnd(cxloc::translateSourceLocation( - clang_getTokenLocation(TU, - Tokens[NumTokens - 1]))); + RegionOfInterest.setBegin( + cxloc::translateSourceLocation(clang_getTokenLocation(TU, Tokens[0]))); + RegionOfInterest.setEnd( + cxloc::translateSourceLocation(clang_getTokenLocation(TU, + Tokens[NumTokens-1]))); // A mapping from the source locations found when re-lexing or traversing the // region of interest to the corresponding cursors. AnnotateTokensData Annotated; - + // Relex the tokens within the source range to look for preprocessing // directives. SourceManager &SourceMgr = CXXUnit->getSourceManager(); @@ -4610,7 +4603,7 @@ = SourceMgr.getDecomposedLoc(RegionOfInterest.getBegin()); std::pair EndLocInfo = SourceMgr.getDecomposedLoc(RegionOfInterest.getEnd()); - + llvm::StringRef Buffer; bool Invalid = false; if (BeginLocInfo.first == EndLocInfo.first && @@ -4621,13 +4614,13 @@ Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end()); Lex.SetCommentRetentionState(true); - + // Lex tokens in raw mode until we hit the end of the range, to avoid // entering #includes or expanding macros. while (true) { Token Tok; Lex.LexFromRawLexer(Tok); - + reprocess: if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { // We have found a preprocessing directive. Gobble it up so that we @@ -4637,49 +4630,44 @@ // // FIXME: Some simple tests here could identify macro definitions and // #undefs, to provide specific cursor kinds for those. - std::vector Locations; + llvm::SmallVector Locations; do { Locations.push_back(Tok.getLocation()); Lex.LexFromRawLexer(Tok); } while (!Tok.isAtStartOfLine() && !Tok.is(tok::eof)); - + using namespace cxcursor; CXCursor Cursor - = MakePreprocessingDirectiveCursor(SourceRange(Locations.front(), - Locations.back()), + = MakePreprocessingDirectiveCursor(SourceRange(Locations.front(), + Locations.back()), TU); for (unsigned I = 0, N = Locations.size(); I != N; ++I) { Annotated[Locations[I].getRawEncoding()] = Cursor; } - + if (Tok.isAtStartOfLine()) goto reprocess; - + continue; } - + if (Tok.is(tok::eof)) break; } } - + // Annotate all of the source locations in the region of interest that map to // a specific cursor. AnnotateTokensWorker W(Annotated, Tokens, Cursors, NumTokens, TU, RegionOfInterest); - - // Run the worker within a CrashRecoveryContext. + // FIXME: We use a ridiculous stack size here because the data-recursion // algorithm uses a large stack frame than the non-data recursive version, // and AnnotationTokensWorker currently transforms the data-recursion // algorithm back into a traditional recursion by explicitly calling // VisitChildren(). We will need to remove this explicit recursive call. - llvm::CrashRecoveryContext CRC; - if (!RunSafely(CRC, runAnnotateTokensWorker, &W, - GetSafetyThreadStackSize() * 2)) { - fprintf(stderr, "libclang: crash detected while annotating tokens\n"); - } - + W.AnnotateTokens(); + // If we ran into any entities that involve context-sensitive keywords, // take another pass through the tokens to mark them as such. if (W.hasContextSensitiveKeywords()) { @@ -4690,19 +4678,19 @@ if (Cursors[I].kind == CXCursor_ObjCPropertyDecl) { IdentifierInfo *II = static_cast(Tokens[I].ptr_data); if (ObjCPropertyDecl *Property - = dyn_cast_or_null(getCursorDecl(Cursors[I]))) { + = dyn_cast_or_null(getCursorDecl(Cursors[I]))) { if (Property->getPropertyAttributesAsWritten() != 0 && llvm::StringSwitch(II->getName()) - .Case("readonly", true) - .Case("assign", true) - .Case("readwrite", true) - .Case("retain", true) - .Case("copy", true) - .Case("nonatomic", true) - .Case("atomic", true) - .Case("getter", true) - .Case("setter", true) - .Default(false)) + .Case("readonly", true) + .Case("assign", true) + .Case("readwrite", true) + .Case("retain", true) + .Case("copy", true) + .Case("nonatomic", true) + .Case("atomic", true) + .Case("getter", true) + .Case("setter", true) + .Default(false)) Tokens[I].int_data[0] = CXToken_Keyword; } continue; @@ -4712,13 +4700,13 @@ Cursors[I].kind == CXCursor_ObjCClassMethodDecl) { IdentifierInfo *II = static_cast(Tokens[I].ptr_data); if (llvm::StringSwitch(II->getName()) - .Case("in", true) - .Case("out", true) - .Case("inout", true) - .Case("oneway", true) - .Case("bycopy", true) - .Case("byref", true) - .Default(false)) + .Case("in", true) + .Case("out", true) + .Case("inout", true) + .Case("oneway", true) + .Case("bycopy", true) + .Case("byref", true) + .Default(false)) Tokens[I].int_data[0] = CXToken_Keyword; continue; } @@ -4726,14 +4714,14 @@ if (Cursors[I].kind == CXCursor_CXXMethod) { IdentifierInfo *II = static_cast(Tokens[I].ptr_data); if (CXXMethodDecl *Method - = dyn_cast_or_null(getCursorDecl(Cursors[I]))) { + = dyn_cast_or_null(getCursorDecl(Cursors[I]))) { if ((Method->hasAttr() || Method->hasAttr()) && Method->getLocation().getRawEncoding() != Tokens[I].int_data[1] && llvm::StringSwitch(II->getName()) - .Case("final", true) - .Case("override", true) - .Default(false)) + .Case("final", true) + .Case("override", true) + .Default(false)) Tokens[I].int_data[0] = CXToken_Keyword; } continue; @@ -4753,18 +4741,47 @@ Record->getIdentifier() != II) Tokens[I].int_data[0] = CXToken_Keyword; } else if (ClassTemplateDecl *ClassTemplate - = dyn_cast_or_null(D)) { + = dyn_cast_or_null(D)) { CXXRecordDecl *Record = ClassTemplate->getTemplatedDecl(); if ((Record->hasAttr()) && Record->getIdentifier() != II) - Tokens[I].int_data[0] = CXToken_Keyword; + Tokens[I].int_data[0] = CXToken_Keyword; } } - continue; + continue; } } } } + +extern "C" { + +void clang_annotateTokens(CXTranslationUnit TU, + CXToken *Tokens, unsigned NumTokens, + CXCursor *Cursors) { + + if (NumTokens == 0 || !Tokens || !Cursors) + return; + + // Any token we don't specifically annotate will have a NULL cursor. + CXCursor C = clang_getNullCursor(); + for (unsigned I = 0; I != NumTokens; ++I) + Cursors[I] = C; + + ASTUnit *CXXUnit = static_cast(TU->TUData); + if (!CXXUnit) + return; + + ASTUnit::ConcurrencyCheck Check(*CXXUnit); + + clang_annotateTokens_Data data = { TU, CXXUnit, Tokens, NumTokens, Cursors }; + llvm::CrashRecoveryContext CRC; + if (!RunSafely(CRC, clang_annotateTokensImpl, &data, + GetSafetyThreadStackSize() * 2)) { + fprintf(stderr, "libclang: crash detected while annotating tokens\n"); + } +} + } // end: extern "C" //===----------------------------------------------------------------------===// From kremenek at apple.com Fri Mar 18 18:05:39 2011 From: kremenek at apple.com (Ted Kremenek) Date: Fri, 18 Mar 2011 23:05:39 -0000 Subject: [cfe-commits] r127920 - in /cfe/trunk: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports Message-ID: <20110318230539.EE08F2A6C12C@llvm.org> Author: kremenek Date: Fri Mar 18 18:05:39 2011 New Revision: 127920 URL: http://llvm.org/viewvc/llvm-project?rev=127920&view=rev Log: Add libclang hook 'clang_toggleCrashRecovery()', which provides a mechanism for a client to enable/disable CrashRecovery within libclang function calls. Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/tools/libclang/libclang.darwin.exports cfe/trunk/tools/libclang/libclang.exports Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=127920&r1=127919&r2=127920&view=diff ============================================================================== --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Fri Mar 18 18:05:39 2011 @@ -2871,6 +2871,15 @@ */ CINDEX_LINKAGE CXString clang_getClangVersion(); + +/** + * \brief Enable/disable crash recovery. + * + * \param Flag to indicate if crash recovery is enabled. A non-zero value + * enables crash recovery, while 0 disables it. + */ +CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled); + /** * \brief Visitor invoked for each file in a translation unit * (used with clang_getInclusions()). Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127920&r1=127919&r2=127920&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Fri Mar 18 18:05:39 2011 @@ -2309,6 +2309,13 @@ delete static_cast(CIdx); } +void clang_toggleCrashRecovery(unsigned isEnabled) { + if (isEnabled) + llvm::CrashRecoveryContext::Enable(); + else + llvm::CrashRecoveryContext::Disable(); +} + CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, const char *ast_filename) { if (!CIdx) Modified: cfe/trunk/tools/libclang/libclang.darwin.exports URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=127920&r1=127919&r2=127920&view=diff ============================================================================== --- cfe/trunk/tools/libclang/libclang.darwin.exports (original) +++ cfe/trunk/tools/libclang/libclang.darwin.exports Fri Mar 18 18:05:39 2011 @@ -108,8 +108,8 @@ _clang_getTypeDeclaration _clang_getTypeKindSpelling _clang_hashCursor -_clang_isCursorDefinition _clang_isConstQualifiedType +_clang_isCursorDefinition _clang_isDeclaration _clang_isExpression _clang_isInvalid @@ -126,6 +126,7 @@ _clang_reparseTranslationUnit _clang_saveTranslationUnit _clang_sortCodeCompletionResults +_clang_toggleCrashRecovery _clang_tokenize _clang_visitChildren _clang_visitChildrenWithBlock Modified: cfe/trunk/tools/libclang/libclang.exports URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=127920&r1=127919&r2=127920&view=diff ============================================================================== --- cfe/trunk/tools/libclang/libclang.exports (original) +++ cfe/trunk/tools/libclang/libclang.exports Fri Mar 18 18:05:39 2011 @@ -126,6 +126,7 @@ clang_reparseTranslationUnit clang_saveTranslationUnit clang_sortCodeCompletionResults +clang_toggleCrashRecovery clang_tokenize clang_visitChildren clang_visitChildrenWithBlock From anton.yartsev at gmail.com Fri Mar 18 18:54:06 2011 From: anton.yartsev at gmail.com (Anton Yartsev) Date: Sat, 19 Mar 2011 02:54:06 +0300 Subject: [cfe-commits] [PATCH] fix conditions for applying AltiVec vector comparison (fixes issue 9347) Message-ID: <4D83F09E.7030300@Gmail.com> Hi all, the patch makes AltiVec vector comparison logic affect only vectors of fundamental AltiVec vector types. It fixes 9347. Please review. -- Anton -------------- next part -------------- A non-text attachment was scrubbed... Name: fix_for_9347.patch Type: text/x-diff Size: 1644 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110319/85b1aff5/attachment.bin From kd at kendyck.com Fri Mar 18 19:57:28 2011 From: kd at kendyck.com (Ken Dyck) Date: Sat, 19 Mar 2011 00:57:28 -0000 Subject: [cfe-commits] r127927 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110319005728.BFE062A6C12C@llvm.org> Author: kjdyck Date: Fri Mar 18 19:57:28 2011 New Revision: 127927 URL: http://llvm.org/viewvc/llvm-project?rev=127927&view=rev Log: Replace literal '8's with CharWidth in AppendBitField. No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127927&r1=127926&r2=127927&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Mar 18 19:57:28 2011 @@ -132,6 +132,7 @@ uint64_t FieldOffset, llvm::ConstantInt *CI) { const ASTContext &Context = CGM.getContext(); + const uint64_t CharWidth = Context.getCharWidth(); uint64_t NextFieldOffsetInBits = Context.toBits(NextFieldOffsetInChars); if (FieldOffset > NextFieldOffsetInBits) { // We need to add padding. @@ -189,12 +190,12 @@ } } - Tmp = Tmp.zext(8); + Tmp = Tmp.zext(CharWidth); if (CGM.getTargetData().isBigEndian()) { if (FitsCompletelyInPreviousByte) Tmp = Tmp.shl(BitsInPreviousByte - FieldValue.getBitWidth()); } else { - Tmp = Tmp.shl(8 - BitsInPreviousByte); + Tmp = Tmp.shl(CharWidth - BitsInPreviousByte); } // 'or' in the bits that go into the previous byte. @@ -213,7 +214,7 @@ assert(isa(LastElt->getType()) && "Expected array padding of undefs"); const llvm::ArrayType *AT = cast(LastElt->getType()); - assert(AT->getElementType()->isIntegerTy(8) && + assert(AT->getElementType()->isIntegerTy(CharWidth) && AT->getNumElements() != 0 && "Expected non-empty array padding of undefs"); @@ -225,7 +226,7 @@ AppendPadding(CharUnits::fromQuantity(AT->getNumElements()-1)); AppendPadding(CharUnits::One()); assert(isa(Elements.back()) && - Elements.back()->getType()->isIntegerTy(8) && + Elements.back()->getType()->isIntegerTy(CharWidth) && "Padding addition didn't work right"); } } @@ -236,37 +237,38 @@ return; } - while (FieldValue.getBitWidth() > 8) { + while (FieldValue.getBitWidth() > CharWidth) { llvm::APInt Tmp; if (CGM.getTargetData().isBigEndian()) { // We want the high bits. - Tmp = FieldValue.lshr(FieldValue.getBitWidth() - 8).trunc(8); + Tmp = + FieldValue.lshr(FieldValue.getBitWidth() - CharWidth).trunc(CharWidth); } else { // We want the low bits. - Tmp = FieldValue.trunc(8); + Tmp = FieldValue.trunc(CharWidth); - FieldValue = FieldValue.lshr(8); + FieldValue = FieldValue.lshr(CharWidth); } Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp)); NextFieldOffsetInChars += CharUnits::One(); - FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - 8); + FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - CharWidth); } assert(FieldValue.getBitWidth() > 0 && "Should have at least one bit left!"); - assert(FieldValue.getBitWidth() <= 8 && + assert(FieldValue.getBitWidth() <= CharWidth && "Should not have more than a byte left!"); - if (FieldValue.getBitWidth() < 8) { + if (FieldValue.getBitWidth() < CharWidth) { if (CGM.getTargetData().isBigEndian()) { unsigned BitWidth = FieldValue.getBitWidth(); - FieldValue = FieldValue.zext(8) << (8 - BitWidth); + FieldValue = FieldValue.zext(CharWidth) << (CharWidth - BitWidth); } else - FieldValue = FieldValue.zext(8); + FieldValue = FieldValue.zext(CharWidth); } // Append the last element. From kremenek at apple.com Fri Mar 18 20:00:33 2011 From: kremenek at apple.com (Ted Kremenek) Date: Sat, 19 Mar 2011 01:00:33 -0000 Subject: [cfe-commits] r127930 - in /cfe/trunk: include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h include/clang/Analysis/AnalysisContext.h lib/Analysis/AnalysisContext.cpp lib/Analysis/CFGReachabilityAnalysis.cpp lib/Sema/AnalysisBasedWarnings.cpp lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp Message-ID: <20110319010033.BEA462A6C12C@llvm.org> Author: kremenek Date: Fri Mar 18 20:00:33 2011 New Revision: 127930 URL: http://llvm.org/viewvc/llvm-project?rev=127930&view=rev Log: Rename class 'CFGReachabilityAnalysis' to 'CFGReverseBlockReachabilityAnalysis'. This rename serves two purposes: - It reflects the actual functionality of this analysis. - We will have more than one reachability analysis. Modified: cfe/trunk/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h cfe/trunk/include/clang/Analysis/AnalysisContext.h cfe/trunk/lib/Analysis/AnalysisContext.cpp cfe/trunk/lib/Analysis/CFGReachabilityAnalysis.cpp cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp cfe/trunk/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp Modified: cfe/trunk/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h?rev=127930&r1=127929&r2=127930&view=diff ============================================================================== --- cfe/trunk/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h (original) +++ cfe/trunk/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h Fri Mar 18 20:00:33 2011 @@ -29,13 +29,13 @@ // tend to have a common destination, so we lazily do a predecessor search // from the destination node and cache the results to prevent work // duplication. -class CFGReachabilityAnalysis { +class CFGReverseBlockReachabilityAnalysis { typedef llvm::BitVector ReachableSet; typedef llvm::DenseMap ReachableMap; ReachableSet analyzed; ReachableMap reachable; public: - CFGReachabilityAnalysis(const CFG &cfg); + CFGReverseBlockReachabilityAnalysis(const CFG &cfg); /// Returns true if the block 'Dst' can be reached from block 'Src'. bool isReachable(const CFGBlock *Src, const CFGBlock *Dst); Modified: cfe/trunk/include/clang/Analysis/AnalysisContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisContext.h?rev=127930&r1=127929&r2=127930&view=diff ============================================================================== --- cfe/trunk/include/clang/Analysis/AnalysisContext.h (original) +++ cfe/trunk/include/clang/Analysis/AnalysisContext.h Fri Mar 18 20:00:33 2011 @@ -28,7 +28,7 @@ class Decl; class Stmt; -class CFGReachabilityAnalysis; +class CFGReverseBlockReachabilityAnalysis; class CFGStmtMap; class LiveVariables; class ParentMap; @@ -60,7 +60,7 @@ llvm::OwningPtr relaxedLiveness; llvm::OwningPtr PM; llvm::OwningPtr PCA; - llvm::OwningPtr CFA; + llvm::OwningPtr CFA; llvm::BumpPtrAllocator A; @@ -100,7 +100,7 @@ CFGStmtMap *getCFGStmtMap(); - CFGReachabilityAnalysis *getCFGReachablityAnalysis(); + CFGReverseBlockReachabilityAnalysis *getCFGReachablityAnalysis(); /// Return a version of the CFG without any edges pruned. CFG *getUnoptimizedCFG(); Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=127930&r1=127929&r2=127930&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original) +++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Fri Mar 18 20:00:33 2011 @@ -132,12 +132,12 @@ return 0; } -CFGReachabilityAnalysis *AnalysisContext::getCFGReachablityAnalysis() { +CFGReverseBlockReachabilityAnalysis *AnalysisContext::getCFGReachablityAnalysis() { if (CFA) return CFA.get(); if (CFG *c = getCFG()) { - CFA.reset(new CFGReachabilityAnalysis(*c)); + CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c)); return CFA.get(); } Modified: cfe/trunk/lib/Analysis/CFGReachabilityAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFGReachabilityAnalysis.cpp?rev=127930&r1=127929&r2=127930&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/CFGReachabilityAnalysis.cpp (original) +++ cfe/trunk/lib/Analysis/CFGReachabilityAnalysis.cpp Fri Mar 18 20:00:33 2011 @@ -19,10 +19,10 @@ using namespace clang; -CFGReachabilityAnalysis::CFGReachabilityAnalysis(const CFG &cfg) +CFGReverseBlockReachabilityAnalysis::CFGReverseBlockReachabilityAnalysis(const CFG &cfg) : analyzed(cfg.getNumBlockIDs(), false) {} -bool CFGReachabilityAnalysis::isReachable(const CFGBlock *Src, +bool CFGReverseBlockReachabilityAnalysis::isReachable(const CFGBlock *Src, const CFGBlock *Dst) { const unsigned DstBlockID = Dst->getBlockID(); @@ -39,7 +39,7 @@ // Maps reachability to a common node by walking the predecessors of the // destination node. -void CFGReachabilityAnalysis::mapReachability(const CFGBlock *Dst) { +void CFGReverseBlockReachabilityAnalysis::mapReachability(const CFGBlock *Dst) { llvm::SmallVector worklist; llvm::BitVector visited(analyzed.size()); Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=127930&r1=127929&r2=127930&view=diff ============================================================================== --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original) +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Mar 18 20:00:33 2011 @@ -576,7 +576,7 @@ if (const Stmt *stmt = i->stmt) { const CFGBlock *block = AC.getBlockForRegisteredExpression(stmt); assert(block); - if (CFGReachabilityAnalysis *cra = AC.getCFGReachablityAnalysis()) { + if (CFGReverseBlockReachabilityAnalysis *cra = AC.getCFGReachablityAnalysis()) { // Can this block be reached from the entrance? if (cra->isReachable(&AC.getCFG()->getEntry(), block)) S.Diag(D.Loc, D.PD); Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp?rev=127930&r1=127929&r2=127930&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp Fri Mar 18 20:00:33 2011 @@ -531,7 +531,7 @@ const CFGBlock *CB, const CoreEngine &CE) { - CFGReachabilityAnalysis *CRA = AC->getCFGReachablityAnalysis(); + CFGReverseBlockReachabilityAnalysis *CRA = AC->getCFGReachablityAnalysis(); // Test for reachability from any aborted blocks to this block typedef CoreEngine::BlocksAborted::const_iterator AbortedIterator; @@ -556,10 +556,10 @@ class VisitWL : public WorkList::Visitor { const CFGStmtMap *CBM; const CFGBlock *TargetBlock; - CFGReachabilityAnalysis &CRA; + CFGReverseBlockReachabilityAnalysis &CRA; public: VisitWL(const CFGStmtMap *cbm, const CFGBlock *targetBlock, - CFGReachabilityAnalysis &cra) + CFGReverseBlockReachabilityAnalysis &cra) : CBM(cbm), TargetBlock(targetBlock), CRA(cra) {} virtual bool visit(const WorkListUnit &U) { ProgramPoint P = U.getNode()->getLocation(); From kremenek at apple.com Fri Mar 18 20:00:36 2011 From: kremenek at apple.com (Ted Kremenek) Date: Sat, 19 Mar 2011 01:00:36 -0000 Subject: [cfe-commits] r127931 - /cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Message-ID: <20110319010036.848132A6C12D@llvm.org> Author: kremenek Date: Fri Mar 18 20:00:36 2011 New Revision: 127931 URL: http://llvm.org/viewvc/llvm-project?rev=127931&view=rev Log: Recover memory from RecordLayoutBuilders during crashes. Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=127931&r1=127930&r2=127931&view=diff ============================================================================== --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original) +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Mar 18 20:00:36 2011 @@ -19,7 +19,7 @@ #include "llvm/Support/Format.h" #include "llvm/ADT/SmallSet.h" #include "llvm/Support/MathExtras.h" -#include +#include "llvm/Support/CrashRecoveryContext.h" using namespace clang; @@ -1708,6 +1708,11 @@ case CXXABI_Microsoft: Builder.reset(new MSRecordLayoutBuilder(*this, &EmptySubobjects)); } + // Recover resources if we crash before exiting this method. + llvm::CrashRecoveryContextCleanupRegistrar + RecordBuilderCleanup(llvm::CrashRecoveryContextCleanup:: + create(Builder.get())); + Builder->Layout(RD); // FIXME: This is not always correct. See the part about bitfields at From kremenek at apple.com Fri Mar 18 20:00:38 2011 From: kremenek at apple.com (Ted Kremenek) Date: Sat, 19 Mar 2011 01:00:38 -0000 Subject: [cfe-commits] r127932 - /cfe/trunk/lib/Sema/TypeLocBuilder.h Message-ID: <20110319010039.02A1E2A6C12E@llvm.org> Author: kremenek Date: Fri Mar 18 20:00:38 2011 New Revision: 127932 URL: http://llvm.org/viewvc/llvm-project?rev=127932&view=rev Log: Recovery memory from TypeLocBuilders during crashes. Modified: cfe/trunk/lib/Sema/TypeLocBuilder.h Modified: cfe/trunk/lib/Sema/TypeLocBuilder.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TypeLocBuilder.h?rev=127932&r1=127931&r2=127932&view=diff ============================================================================== --- cfe/trunk/lib/Sema/TypeLocBuilder.h (original) +++ cfe/trunk/lib/Sema/TypeLocBuilder.h Fri Mar 18 20:00:38 2011 @@ -18,6 +18,7 @@ #include "clang/AST/TypeLoc.h" #include "llvm/ADT/SmallVector.h" #include "clang/AST/ASTContext.h" +#include "llvm/Support/CrashRecoveryContext.h" namespace clang { @@ -42,9 +43,13 @@ /// The inline buffer. char InlineBuffer[InlineCapacity]; + llvm::CrashRecoveryContextCleanupRegistrar cleanupBuffer; + public: TypeLocBuilder() - : Buffer(InlineBuffer), Capacity(InlineCapacity), Index(InlineCapacity) + : Buffer(InlineBuffer), Capacity(InlineCapacity), Index(InlineCapacity), + cleanupBuffer(llvm::CrashRecoveryContextCleanup::create( + this, llvm::CrashRecoveryContextCleanup::DestructorCleanup)) {} ~TypeLocBuilder() { From daniel at zuster.org Fri Mar 18 20:04:12 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Sat, 19 Mar 2011 01:04:12 -0000 Subject: [cfe-commits] r127933 - /cfe/trunk/lib/Frontend/InitPreprocessor.cpp Message-ID: <20110319010412.8F98B2A6C12C@llvm.org> Author: ddunbar Date: Fri Mar 18 20:04:12 2011 New Revision: 127933 URL: http://llvm.org/viewvc/llvm-project?rev=127933&view=rev Log: Preprocessor: Don't define __STDC__ in -traditional-cpp mode. Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=127933&r1=127932&r2=127933&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Fri Mar 18 20:04:12 2011 @@ -253,7 +253,7 @@ // These should all be defined in the preprocessor according to the // current language configuration. - if (!LangOpts.Microsoft) + if (!LangOpts.Microsoft && !LangOpts.TraditionalCPP) Builder.defineMacro("__STDC__"); if (LangOpts.AsmPreprocessor) Builder.defineMacro("__ASSEMBLER__"); From clattner at apple.com Fri Mar 18 20:20:18 2011 From: clattner at apple.com (Chris Lattner) Date: Fri, 18 Mar 2011 18:20:18 -0700 Subject: [cfe-commits] r127910 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Driver/CC1Options.td lib/Frontend/CompilerInvocation.cpp lib/Lex/Lexer.cpp test/Preprocessor/traditional-cpp.c In-Reply-To: <20110318212338.635892A6C12C@llvm.org> References: <20110318212338.635892A6C12C@llvm.org> Message-ID: <5634AF6B-591F-40A1-B339-58C01C904B00@apple.com> On Mar 18, 2011, at 2:23 PM, Daniel Dunbar wrote: > Author: ddunbar > Date: Fri Mar 18 16:23:38 2011 > New Revision: 127910 > > URL: http://llvm.org/viewvc/llvm-project?rev=127910&view=rev > Log: > Lexer: Add extremely limited support for -traditional-cpp, ignoring BCPL > comments. Hi Daniel, Why not just have TraditionalCPP turn off LangOpts.BCPLComment? -Chris > > Added: > cfe/trunk/test/Preprocessor/traditional-cpp.c > Modified: > cfe/trunk/include/clang/Basic/LangOptions.h > cfe/trunk/include/clang/Driver/CC1Options.td > cfe/trunk/lib/Frontend/CompilerInvocation.cpp > cfe/trunk/lib/Lex/Lexer.cpp > > Modified: cfe/trunk/include/clang/Basic/LangOptions.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Basic/LangOptions.h (original) > +++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Mar 18 16:23:38 2011 > @@ -56,6 +56,7 @@ > unsigned ObjCExceptions : 1; // Support Objective-C exceptions. > unsigned CXXExceptions : 1; // Support C++ exceptions. > unsigned SjLjExceptions : 1; // Use setjmp-longjump exception handling. > + unsigned TraditionalCPP : 1; /// Enable some traditional CPP emulation. > unsigned RTTI : 1; // Support RTTI information. > > unsigned MSBitfields : 1; // MS-compatible structure layout > @@ -169,7 +170,7 @@ > C99 = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0; > CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0; > Exceptions = ObjCExceptions = CXXExceptions = SjLjExceptions = 0; > - Freestanding = NoBuiltin = 0; > + TraditionalCPP = Freestanding = NoBuiltin = 0; > MSBitfields = 0; > NeXTRuntime = 1; > RTTI = 1; > > Modified: cfe/trunk/include/clang/Driver/CC1Options.td > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Driver/CC1Options.td (original) > +++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Mar 18 16:23:38 2011 > @@ -511,6 +511,8 @@ > HelpText<"Store string literals as writable data">; > def fno_bitfield_type_align : Flag<"-fno-bitfield-type-align">, > HelpText<"Ignore bit-field types when aligning structures">; > +def traditional_cpp : Flag<"-traditional-cpp">, > + HelpText<"Enable some traditional CPP emulation">; > > //===----------------------------------------------------------------------===// > // Header Search Options > > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Mar 18 16:23:38 2011 > @@ -574,6 +574,8 @@ > Res.push_back("-fcxx-exceptions"); > if (Opts.SjLjExceptions) > Res.push_back("-fsjlj-exceptions"); > + if (Opts.TraditionalCPP) > + Res.push_back("-traditional-cpp"); > if (!Opts.RTTI) > Res.push_back("-fno-rtti"); > if (Opts.MSBitfields) > @@ -1442,6 +1444,7 @@ > Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); > Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); > Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); > + Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); > > Opts.RTTI = !Args.hasArg(OPT_fno_rtti); > Opts.Blocks = Args.hasArg(OPT_fblocks); > > Modified: cfe/trunk/lib/Lex/Lexer.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/lib/Lex/Lexer.cpp (original) > +++ cfe/trunk/lib/Lex/Lexer.cpp Fri Mar 18 16:23:38 2011 > @@ -2091,7 +2091,7 @@ > // If the next token is obviously a // or /* */ comment, skip it efficiently > // too (without going through the big switch stmt). > if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() && > - Features.BCPLComment) { > + Features.BCPLComment && !Features.TraditionalCPP) { > if (SkipBCPLComment(Result, CurPtr+2)) > return; // There is a token to return. > goto SkipIgnoredUnits; > @@ -2280,8 +2280,10 @@ > // this as "foo / bar" and langauges with BCPL comments would lex it as > // "foo". Check to see if the character after the second slash is a '*'. > // If so, we will lex that as a "/" instead of the start of a comment. > - if (Features.BCPLComment || > - getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') { > + // However, we never do this in -traditional-cpp mode. > + if ((Features.BCPLComment || > + getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') && > + !Features.TraditionalCPP) { > if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) > return; // There is a token to return. > > > Added: cfe/trunk/test/Preprocessor/traditional-cpp.c > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/traditional-cpp.c?rev=127910&view=auto > ============================================================================== > --- cfe/trunk/test/Preprocessor/traditional-cpp.c (added) > +++ cfe/trunk/test/Preprocessor/traditional-cpp.c Fri Mar 18 16:23:38 2011 > @@ -0,0 +1,12 @@ > +/* Clang supports a very limited subset of -traditional-cpp, basically we only > + * intend to add support for things that people actually rely on when doing > + * things like using /usr/bin/cpp to preprocess non-source files. */ > + > +/* > + RUN: %clang_cc1 -traditional-cpp %s -E -o %t > + RUN: FileCheck < %t %s > +*/ > + > +/* CHECK: foo // bar > + */ > +foo // bar > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From kd at kendyck.com Fri Mar 18 20:25:59 2011 From: kd at kendyck.com (Ken Dyck) Date: Sat, 19 Mar 2011 01:25:59 -0000 Subject: [cfe-commits] r127937 - /cfe/trunk/include/clang/AST/CharUnits.h Message-ID: <20110319012559.9CA832A6C130@llvm.org> Author: kjdyck Date: Fri Mar 18 20:25:59 2011 New Revision: 127937 URL: http://llvm.org/viewvc/llvm-project?rev=127937&view=rev Log: Add pre- and post-increment/decrement operators to CharUnits. Modified: cfe/trunk/include/clang/AST/CharUnits.h Modified: cfe/trunk/include/clang/AST/CharUnits.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=127937&r1=127936&r2=127937&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/CharUnits.h (original) +++ cfe/trunk/include/clang/AST/CharUnits.h Fri Mar 18 20:25:59 2011 @@ -70,10 +70,24 @@ Quantity += Other.Quantity; return *this; } + CharUnits& operator++ () { + ++Quantity; + return *this; + } + CharUnits operator++ (int) { + return CharUnits(Quantity++); + } CharUnits& operator-= (const CharUnits &Other) { Quantity -= Other.Quantity; return *this; } + CharUnits& operator-- () { + --Quantity; + return *this; + } + CharUnits operator-- (int) { + return CharUnits(Quantity--); + } // Comparison operators. bool operator== (const CharUnits &Other) const { From kd at kendyck.com Fri Mar 18 20:28:07 2011 From: kd at kendyck.com (Ken Dyck) Date: Sat, 19 Mar 2011 01:28:07 -0000 Subject: [cfe-commits] r127938 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp Message-ID: <20110319012807.1AF9D2A6C130@llvm.org> Author: kjdyck Date: Fri Mar 18 20:28:06 2011 New Revision: 127938 URL: http://llvm.org/viewvc/llvm-project?rev=127938&view=rev Log: Use CharUnits's new increment operator. No change in functionality intended. Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=127938&r1=127937&r2=127938&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Mar 18 20:28:06 2011 @@ -252,7 +252,7 @@ } Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp)); - NextFieldOffsetInChars += CharUnits::One(); + ++NextFieldOffsetInChars; FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - CharWidth); } @@ -274,7 +274,7 @@ // Append the last element. Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), FieldValue)); - NextFieldOffsetInChars += CharUnits::One(); + ++NextFieldOffsetInChars; } void ConstStructBuilder::AppendPadding(CharUnits PadSize) { From daniel at zuster.org Fri Mar 18 21:06:21 2011 From: daniel at zuster.org (Daniel Dunbar) Date: Sat, 19 Mar 2011 02:06:21 -0000 Subject: [cfe-commits] r127942 - /cfe/trunk/lib/Basic/Targets.cpp Message-ID: <20110319020621.392DB2A6C12C@llvm.org> Author: ddunbar Date: Fri Mar 18 21:06:21 2011 New Revision: 127942 URL: http://llvm.org/viewvc/llvm-project?rev=127942&view=rev Log: Unbreak build. Modified: cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=127942&r1=127941&r2=127942&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Fri Mar 18 21:06:21 2011 @@ -159,8 +159,9 @@ // Let MCSectionMachO validate this. llvm::StringRef Segment, Section; unsigned TAA, StubSize; + bool HasTAA; return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section, - TAA, StubSize); + TAA, HasTAA, StubSize); } virtual const char *getStaticInitSectionSpecifier() const { From anton.yartsev at gmail.com Sat Mar 19 02:53:43 2011 From: anton.yartsev at gmail.com (Anton Yartsev) Date: Sat, 19 Mar 2011 07:53:43 -0000 Subject: [cfe-commits] r127949 - in /cfe/trunk: include/clang/Basic/TokenKinds.def test/SemaCXX/altivec.cpp Message-ID: <20110319075343.CA45F2A6C12D@llvm.org> Author: ayartsev Date: Sat Mar 19 02:53:43 2011 New Revision: 127949 URL: http://llvm.org/viewvc/llvm-project?rev=127949&view=rev Log: makes vec_step operator work when AltiVec support is enabled Modified: cfe/trunk/include/clang/Basic/TokenKinds.def cfe/trunk/test/SemaCXX/altivec.cpp Modified: cfe/trunk/include/clang/Basic/TokenKinds.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=127949&r1=127948&r2=127949&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/TokenKinds.def (original) +++ cfe/trunk/include/clang/Basic/TokenKinds.def Sat Mar 19 02:53:43 2011 @@ -349,7 +349,7 @@ // OpenCL-specific keywords KEYWORD(__kernel , KEYOPENCL) ALIAS("kernel", __kernel , KEYOPENCL) -KEYWORD(vec_step , KEYOPENCL) +KEYWORD(vec_step , KEYOPENCL|KEYALTIVEC) KEYWORD(__private , KEYOPENCL) KEYWORD(__global , KEYOPENCL) KEYWORD(__local , KEYOPENCL) Modified: cfe/trunk/test/SemaCXX/altivec.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/altivec.cpp?rev=127949&r1=127948&r2=127949&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/altivec.cpp (original) +++ cfe/trunk/test/SemaCXX/altivec.cpp Sat Mar 19 02:53:43 2011 @@ -2,6 +2,36 @@ typedef int V4i __attribute__((vector_size(16))); +void test_vec_step(vector short arg1) { + vector bool char vbc; + vector signed char vsc; + vector unsigned char vuc; + vector bool short vbs; + vector short vs; + vector unsigned short vus; + vector pixel vp; + vector bool int vbi; + vector int vi; + vector unsigned int vui; + vector float vf; + + vector int *pvi; + + int res1[vec_step(arg1) == 8 ? 1 : -1]; + int res2[vec_step(vbc) == 16 ? 1 : -1]; + int res3[vec_step(vsc) == 16 ? 1 : -1]; + int res4[vec_step(vuc) == 16 ? 1 : -1]; + int res5[vec_step(vbs) == 8 ? 1 : -1]; + int res6[vec_step(vs) == 8 ? 1 : -1]; + int res7[vec_step(vus) == 8 ? 1 : -1]; + int res8[vec_step(vp) == 8 ? 1 : -1]; + int res9[vec_step(vbi) == 4 ? 1 : -1]; + int res10[vec_step(vi) == 4 ? 1 : -1]; + int res11[vec_step(vui) == 4 ? 1 : -1]; + int res12[vec_step(vf) == 4 ? 1 : -1]; + int res13[vec_step(*pvi) == 4 ? 1 : -1]; +} + void f(V4i a) { } From sebastian.redl at getdesigned.at Sat Mar 19 05:27:48 2011 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Sat, 19 Mar 2011 11:27:48 +0100 Subject: [cfe-commits] [PATCH] Re: [cfe-dev] Interest in a -Wusing-namespace-in-headers? In-Reply-To: References: Message-ID: <8F36AE7C-C56F-47BA-9995-31D5FE76AE4A@getdesigned.at> On 18.03.2011, at 17:15, Douglas Gregor wrote: > > On Mar 17, 2011, at 11:05 AM, Elliot Glaysher (Chromium) wrote: > >> Adds a -Wheader-hygiene warning for warnings that should only trigger >> in #included files. >> >> The first -Wheader-hygiene check is to make sure a using directive >> isn't placed in the global context in a header. >> >> On Wed, Mar 16, 2011 at 6:15 PM, Douglas Gregor wrote: >>> You don't need to perform the getDiagnosticLevel() check yourself, because the diagnostic system will handle warning suppression itself. >>> >>> However, I do suggest performing the CurContext->getDeclKind() == Decl::TranslationUnit check before the isFromMainFile() check, since the former is cheaper. >> >> Done. > > Committed in r127881, thanks! Do we want to warn about this? extern "C++" { using namespace foo; } Because the fact that extern blocks are decl contexts has bitten me before, and the above suggestion would fall prey to the same issue. Sebastian From benny.kra at googlemail.com Sat Mar 19 08:04:25 2011 From: benny.kra at googlemail.com (Benjamin Kramer) Date: Sat, 19 Mar 2011 13:04:25 -0000 Subject: [cfe-commits] r127950 - /cfe/trunk/include/clang/Basic/LangOptions.h Message-ID: <20110319130425.975E92A6C12C@llvm.org> Author: d0k Date: Sat Mar 19 08:04:25 2011 New Revision: 127950 URL: http://llvm.org/viewvc/llvm-project?rev=127950&view=rev Log: Initialize FakeAddressSpaceMap flag. Modified: cfe/trunk/include/clang/Basic/LangOptions.h Modified: cfe/trunk/include/clang/Basic/LangOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=127950&r1=127949&r2=127950&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.h (original) +++ cfe/trunk/include/clang/Basic/LangOptions.h Sat Mar 19 08:04:25 2011 @@ -221,6 +221,7 @@ FastRelaxedMath = 0; DefaultFPContract = 0; NoBitFieldTypeAlign = 0; + FakeAddressSpaceMap = 0; MRTD = 0; } From jorr at apple.com Sat Mar 19 17:15:14 2011 From: jorr at apple.com (James Orr) Date: Sat, 19 Mar 2011 15:15:14 -0700 Subject: [cfe-commits] [PATCH][review request] Add support for LLVM intrinsic bswap16 Message-ID: <77874776-2EC8-490A-9C19-951FC2BBAD94@apple.com> Add support for built in 16bit byte swap. -James Index: include/clang/Basic/Builtins.def =================================================================== --- include/clang/Basic/Builtins.def (revision 127948) +++ include/clang/Basic/Builtins.def (working copy) @@ -380,6 +380,7 @@ // FIXME: These type signatures are not correct for targets with int != 32-bits // or with ULL != 64-bits. +BUILTIN(__builtin_bswap16, "UsUs", "nc") BUILTIN(__builtin_bswap32, "UiUi", "nc") BUILTIN(__builtin_bswap64, "ULLiULLi", "nc") Index: lib/CodeGen/CGBuiltin.cpp =================================================================== --- lib/CodeGen/CGBuiltin.cpp (revision 127948) +++ lib/CodeGen/CGBuiltin.cpp (working copy) @@ -316,6 +316,7 @@ (void)EmitScalarExpr(E->getArg(1)); return RValue::get(EmitScalarExpr(E->getArg(0))); } + case Builtin::BI__builtin_bswap16: case Builtin::BI__builtin_bswap32: case Builtin::BI__builtin_bswap64: { Value *ArgValue = EmitScalarExpr(E->getArg(0)); From eli.friedman at gmail.com Sat Mar 19 17:24:53 2011 From: eli.friedman at gmail.com (Eli Friedman) Date: Sat, 19 Mar 2011 15:24:53 -0700 Subject: [cfe-commits] [PATCH][review request] Add support for LLVM intrinsic bswap16 In-Reply-To: <77874776-2EC8-490A-9C19-951FC2BBAD94@apple.com> References: <77874776-2EC8-490A-9C19-951FC2BBAD94@apple.com> Message-ID: On Sat, Mar 19, 2011 at 3:15 PM, James Orr wrote: > Add support for built in 16bit byte swap. Why? -Eli > -James > > Index: include/clang/Basic/Builtins.def > =================================================================== > --- include/clang/Basic/Builtins.def ? ?(revision 127948) > +++ include/clang/Basic/Builtins.def ? ?(working copy) > @@ -380,6 +380,7 @@ > > ?// FIXME: These type signatures are not correct for targets with int != 32-bits > ?// or with ULL != 64-bits. > +BUILTIN(__builtin_bswap16, "UsUs", "nc") > ?BUILTIN(__builtin_bswap32, "UiUi", "nc") > ?BUILTIN(__builtin_bswap64, "ULLiULLi", "nc") > > Index: lib/CodeGen/CGBuiltin.cpp > =================================================================== > --- lib/CodeGen/CGBuiltin.cpp ? (revision 127948) > +++ lib/CodeGen/CGBuiltin.cpp ? (working copy) > @@ -316,6 +316,7 @@ > ? ? ? (void)EmitScalarExpr(E->getArg(1)); > ? ? return RValue::get(EmitScalarExpr(E->getArg(0))); > ? } > + ?case Builtin::BI__builtin_bswap16: > ? case Builtin::BI__builtin_bswap32: > ? case Builtin::BI__builtin_bswap64: { > ? ? Value *ArgValue = EmitScalarExpr(E->getArg(0)); > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > From dgregor at apple.com Sat Mar 19 17:55:35 2011 From: dgregor at apple.com (Douglas Gregor) Date: Sat, 19 Mar 2011 15:55:35 -0700 Subject: [cfe-commits] [PATCH] Re: [cfe-dev] Interest in a -Wusing-namespace-in-headers? In-Reply-To: <8F36AE7C-C56F-47BA-9995-31D5FE76AE4A@getdesigned.at> References: <8F36AE7C-C56F-47BA-9995-31D5FE76AE4A@getdesigned.at> Message-ID: <27AE1209-CC2A-4374-8EA7-F51442D3E860@apple.com> Sent from my iPhone On Mar 19, 2011, at 3:27 AM, Sebastian Redl wrote: > > On 18.03.2011, at 17:15, Douglas Gregor wrote: > >> >> On Mar 17, 2011, at 11:05 AM, Elliot Glaysher (Chromium) wrote: >> >>> Adds a -Wheader-hygiene warning for warnings that should only trigger >>> in #included files. >>> >>> The first -Wheader-hygiene check is to make sure a using directive >>> isn't placed in the global context in a header. >>> >>> On Wed, Mar 16, 2011 at 6:15 PM, Douglas Gregor wrote: >>>> You don't need to perform the getDiagnosticLevel() check yourself, because the diagnostic system will handle warning suppression itself. >>>> >>>> However, I do suggest performing the CurContext->getDeclKind() == Decl::TranslationUnit check before the isFromMainFile() check, since the former is cheaper. >>> >>> Done. >> >> Committed in r127881, thanks! > > Do we want to warn about this? > > extern "C++" { > using namespace foo; > } > > Because the fact that extern blocks are decl contexts has bitten me before, and the above suggestion would fall prey to the same issue. Good point! Yes, we do want to warn about that. From pichet2000 at gmail.com Sat Mar 19 18:05:18 2011 From: pichet2000 at gmail.com (Francois Pichet) Date: Sat, 19 Mar 2011 23:05:18 -0000 Subject: [cfe-commits] r127961 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExceptionSpec.cpp test/SemaCXX/MicrosoftExtensions.cpp Message-ID: <20110319230518.764F02A6C12C@llvm.org> Author: fpichet Date: Sat Mar 19 18:05:18 2011 New Revision: 127961 URL: http://llvm.org/viewvc/llvm-project?rev=127961&view=rev Log: Downgrade err_mismatched_exception_spec to a ExtWarning in Microsoft mode. MSVC doesn't do any validation on exception specifications. This remove 1 error when parsing MSVC stl lib with clang. Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExceptionSpec.cpp cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127961&r1=127960&r2=127961&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Mar 19 18:05:18 2011 @@ -551,6 +551,8 @@ "in exception specification">; def err_mismatched_exception_spec : Error< "exception specification in declaration does not match previous declaration">; +def war_mismatched_exception_spec : ExtWarn< + "exception specification in declaration does not match previous declaration">; def err_override_exception_spec : Error< "exception specification of overriding function is more lax than " "base version">; Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=127961&r1=127960&r2=127961&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original) +++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Sat Mar 19 18:05:18 2011 @@ -100,7 +100,11 @@ bool IsOperatorNew = OO == OO_New || OO == OO_Array_New; bool MissingExceptionSpecification = false; bool MissingEmptyExceptionSpecification = false; - if (!CheckEquivalentExceptionSpec(PDiag(diag::err_mismatched_exception_spec), + unsigned DiagID = diag::err_mismatched_exception_spec; + if (getLangOptions().Microsoft) + DiagID = diag::war_mismatched_exception_spec; + + if (!CheckEquivalentExceptionSpec(PDiag(DiagID), PDiag(diag::note_previous_declaration), Old->getType()->getAs(), Old->getLocation(), @@ -247,7 +251,7 @@ return false; } - Diag(New->getLocation(), diag::err_mismatched_exception_spec); + Diag(New->getLocation(), DiagID); Diag(Old->getLocation(), diag::note_previous_declaration); return true; } @@ -259,8 +263,11 @@ bool Sema::CheckEquivalentExceptionSpec( const FunctionProtoType *Old, SourceLocation OldLoc, const FunctionProtoType *New, SourceLocation NewLoc) { + unsigned DiagID = diag::err_mismatched_exception_spec; + if (getLangOptions().Microsoft) + DiagID = diag::war_mismatched_exception_spec; return CheckEquivalentExceptionSpec( - PDiag(diag::err_mismatched_exception_spec), + PDiag(DiagID), PDiag(diag::note_previous_declaration), Old, OldLoc, New, NewLoc); } @@ -339,14 +346,6 @@ return true; } - if (getLangOptions().Microsoft) { - // Treat throw(whatever) as throw(...) to be compatible with MS headers. - if (OldEST == EST_Dynamic) - OldEST = EST_MSAny; - if (NewEST == EST_Dynamic) - NewEST = EST_MSAny; - } - // The MS extension throw(...) is compatible with itself. if (OldEST == EST_MSAny && NewEST == EST_MSAny) return false; Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=127961&r1=127960&r2=127961&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original) +++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Sat Mar 19 18:05:18 2011 @@ -4,21 +4,13 @@ // ::type_info is predeclared with forward class declartion void f(const type_info &a); -// The following three are all equivalent when ms-extensions are on -void foo() throw(int); -void foo() throw(int, long); -void foo() throw(...); -void foo(); // expected-note {{previous declaration}} - -// Only nothrow specification is treated specially. -void foo() throw(); // expected-error {{exception specification in declaration does not match previous declaration}} -// throw(...) -void r3(); -void r3() throw(...); +// Microsoft doesn't validate exception specification. +void foo(); // expected-note {{previous declaration}} +void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}} -void r6() throw(...); -void r6() throw(int); // okay +void r6() throw(...); // expected-note {{previous declaration}} +void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}} struct Base { virtual void f2(); From clattner at apple.com Sat Mar 19 21:25:51 2011 From: clattner at apple.com (Chris Lattner) Date: Sat, 19 Mar 2011 19:25:51 -0700 Subject: [cfe-commits] [PATCH][review request] Add support for LLVM intrinsic bswap16 In-Reply-To: References: <77874776-2EC8-490A-9C19-951FC2BBAD94@apple.com> Message-ID: On Mar 19, 2011, at 3:24 PM, Eli Friedman wrote: > On Sat, Mar 19, 2011 at 3:15 PM, James Orr wrote: >> Add support for built in 16bit byte swap. > > Why? Yes, why? GCC doesn't support this either IIRC. -Chris > > -Eli > >> -James >> >> Index: include/clang/Basic/Builtins.def >> =================================================================== >> --- include/clang/Basic/Builtins.def (revision 127948) >> +++ include/clang/Basic/Builtins.def (working copy) >> @@ -380,6 +380,7 @@ >> >> // FIXME: These type signatures are not correct for targets with int != 32-bits >> // or with ULL != 64-bits. >> +BUILTIN(__builtin_bswap16, "UsUs", "nc") >> BUILTIN(__builtin_bswap32, "UiUi", "nc") >> BUILTIN(__builtin_bswap64, "ULLiULLi", "nc") >> >> Index: lib/CodeGen/CGBuiltin.cpp >> =================================================================== >> --- lib/CodeGen/CGBuiltin.cpp (revision 127948) >> +++ lib/CodeGen/CGBuiltin.cpp (working copy) >> @@ -316,6 +316,7 @@ >> (void)EmitScalarExpr(E->getArg(1)); >> return RValue::get(EmitScalarExpr(E->getArg(0))); >> } >> + case Builtin::BI__builtin_bswap16: >> case Builtin::BI__builtin_bswap32: >> case Builtin::BI__builtin_bswap64: { >> Value *ArgValue = EmitScalarExpr(E->getArg(0)); >> >> _______________________________________________ >> cfe-commits mailing list >> cfe-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From jorr at apple.com Sat Mar 19 22:02:26 2011 From: jorr at apple.com (James Orr) Date: Sat, 19 Mar 2011 20:02:26 -0700 Subject: [cfe-commits] [PATCH][review request] Add support for LLVM intrinsic bswap16 In-Reply-To: References: <77874776-2EC8-490A-9C19-951FC2BBAD94@apple.com> Message-ID: <313FE2C5-CED7-4396-B9B6-D53FCD0445F7@apple.com> On Mar 19, 2011, at 7:25 PM, Chris Lattner wrote: > > On Mar 19, 2011, at 3:24 PM, Eli Friedman wrote: > >> On Sat, Mar 19, 2011 at 3:15 PM, James Orr wrote: >>> Add support for built in 16bit byte swap. >> >> Why? > > Yes, why? GCC doesn't support this either IIRC. > > -Chris I want to convert a big endian short to little endian (ie Cortex-M0 reading over I2C a 16bit ADC value returned in big endian). Clang does not recognize the following as a byte swap: (uint16_t)( a >> 8) | (uint16_t)( a << 8); (llvm-gcc does) In the ARM architecture this can be accomplished with single instruction (REV16, or in the case I really care about REVSH) Even with this patch LLVM generates two instructions: REV (which is 32 bit byte swap) and LSRS. But now the LLVM representation looks better: // using intrinsic define zeroext i16 @bswapI(i16 zeroext %a) nounwind readnone optsize ssp { %1 = tail call i16 @llvm.bswap.i16(i16 %a) ret i16 %1 } declare i16 @llvm.bswap.i16(i16) nounwind readnone // C - code define zeroext i16 @bswapC(i16 zeroext %a) nounwind readnone optsize ssp { %1 = zext i16 %a to i32 %2 = lshr i16 %a, 8 %3 = zext i16 %2 to i32 %4 = shl nuw nsw i32 %1, 8 %5 = or i32 %3, %4 %6 = trunc i32 %5 to i16 ret i16 %6 } I agree this should not be necessary if Clang be taught to recognize this itself, but I could not figure that out (yet). In the meantime this patch enables me to look into the LLVM half of generating the instructions. I realize GCC only supports 32, and 64, but LLVM supports 16 as well and I did not see the harm in exposing it. -James > >> >> -Eli >> >>> -James >>> >>> Index: include/clang/Basic/Builtins.def >>> =================================================================== >>> --- include/clang/Basic/Builtins.def (revision 127948) >>> +++ include/clang/Basic/Builtins.def (working copy) >>> @@ -380,6 +380,7 @@ >>> >>> // FIXME: These type signatures are not correct for targets with int != 32-bits >>> // or with ULL != 64-bits. >>> +BUILTIN(__builtin_bswap16, "UsUs", "nc") >>> BUILTIN(__builtin_bswap32, "UiUi", "nc") >>> BUILTIN(__builtin_bswap64, "ULLiULLi", "nc") >>> >>> Index: lib/CodeGen/CGBuiltin.cpp >>> =================================================================== >>> --- lib/CodeGen/CGBuiltin.cpp (revision 127948) >>> +++ lib/CodeGen/CGBuiltin.cpp (working copy) >>> @@ -316,6 +316,7 @@ >>> (void)EmitScalarExpr(E->getArg(1)); >>> return RValue::get(EmitScalarExpr(E->getArg(0))); >>> } >>> + case Builtin::BI__builtin_bswap16: >>> case Builtin::BI__builtin_bswap32: >>> case Builtin::BI__builtin_bswap64: { >>> Value *ArgValue = EmitScalarExpr(E->getArg(0)); >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> cfe-commits at cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >>> >> >> _______________________________________________ >> cfe-commits mailing list >> cfe-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > From peter at pcc.me.uk Sun Mar 20 03:06:46 2011 From: peter at pcc.me.uk (Peter Collingbourne) Date: Sun, 20 Mar 2011 08:06:46 -0000 Subject: [cfe-commits] r127967 - in /cfe/trunk: lib/Sema/SemaType.cpp test/SemaCXX/cxx0x-constexpr-const.cpp Message-ID: <20110320080646.2FD8F2A6C12D@llvm.org> Author: pcc Date: Sun Mar 20 03:06:45 2011 New Revision: 127967 URL: http://llvm.org/viewvc/llvm-project?rev=127967&view=rev Log: Only objects are declared const by a constexpr specifier, per C++0x [dcl.constexpr]p9 Added: cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127967&r1=127966&r2=127967&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Sun Mar 20 03:06:45 2011 @@ -2116,8 +2116,10 @@ // Diagnose any ignored type attributes. if (!T.isNull()) state.diagnoseIgnoredTypeAttrs(T); - // If there's a constexpr specifier, treat it as a top-level const. - if (D.getDeclSpec().isConstexprSpecified()) { + // C++0x [dcl.constexpr]p9: + // A constexpr specifier used in an object declaration declares the object + // as const. + if (D.getDeclSpec().isConstexprSpecified() && T->isObjectType()) { T.addConst(); } Added: cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp?rev=127967&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp (added) +++ cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp Sun Mar 20 03:06:45 2011 @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +constexpr int x = 1; +constexpr int id(int x) { return x; } + +void foo(void) { + x = 2; // expected-error {{read-only variable is not assignable}} + int (*idp)(int) = id; +} + From akyrtzi at gmail.com Sun Mar 20 13:17:53 2011 From: akyrtzi at gmail.com (Argyrios Kyrtzidis) Date: Sun, 20 Mar 2011 18:17:53 -0000 Subject: [cfe-commits] r127971 - /cfe/trunk/tools/libclang/CIndex.cpp Message-ID: <20110320181753.1A1D62A6C12C@llvm.org> Author: akirtzidis Date: Sun Mar 20 13:17:52 2011 New Revision: 127971 URL: http://llvm.org/viewvc/llvm-project?rev=127971&view=rev Log: In clang_parseTranslationUnit_Impl,p ut the source file after command_line_args otherwise if '-x' flag is present it will be unused. Modified: cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127971&r1=127970&r2=127971&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Sun Mar 20 13:17:52 2011 @@ -2404,12 +2404,6 @@ } llvm::SmallVector Args; - - // The 'source_filename' argument is optional. If the caller does not - // specify it then it is assumed that the source file is specified - // in the actual argument list. - if (source_filename) - Args.push_back(source_filename); // Since the Clang C library is primarily used by batch tools dealing with // (often very broken) source code, where spell-checking can have a @@ -2430,6 +2424,14 @@ Args.insert(Args.end(), command_line_args, command_line_args + num_command_line_args); + // The 'source_filename' argument is optional. If the caller does not + // specify it then it is assumed that the source file is specified + // in the actual argument list. + // Put the source file after command_line_args otherwise if '-x' flag is + // present it will be unused. + if (source_filename) + Args.push_back(source_filename); + // Do we need the detailed preprocessing record? if (options & CXTranslationUnit_DetailedPreprocessingRecord) { Args.push_back("-Xclang"); From dgregor at apple.com Sun Mar 20 15:42:09 2011 From: dgregor at apple.com (Douglas Gregor) Date: Sun, 20 Mar 2011 21:42:09 +0100 Subject: [cfe-commits] r127971 - /cfe/trunk/tools/libclang/CIndex.cpp In-Reply-To: <20110320181753.1A1D62A6C12C@llvm.org> References: <20110320181753.1A1D62A6C12C@llvm.org> Message-ID: Bill, please merge this into the 2.9 branch. Thanks! - Doug On Mar 20, 2011, at 7:17 PM, Argyrios Kyrtzidis wrote: > Author: akirtzidis > Date: Sun Mar 20 13:17:52 2011 > New Revision: 127971 > > URL: http://llvm.org/viewvc/llvm-project?rev=127971&view=rev > Log: > In clang_parseTranslationUnit_Impl,p ut the source file after command_line_args otherwise > if '-x' flag is present it will be unused. > > Modified: > cfe/trunk/tools/libclang/CIndex.cpp > > Modified: cfe/trunk/tools/libclang/CIndex.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=127971&r1=127970&r2=127971&view=diff > ============================================================================== > --- cfe/trunk/tools/libclang/CIndex.cpp (original) > +++ cfe/trunk/tools/libclang/CIndex.cpp Sun Mar 20 13:17:52 2011 > @@ -2404,12 +2404,6 @@ > } > > llvm::SmallVector Args; > - > - // The 'source_filename' argument is optional. If the caller does not > - // specify it then it is assumed that the source file is specified > - // in the actual argument list. > - if (source_filename) > - Args.push_back(source_filename); > > // Since the Clang C library is primarily used by batch tools dealing with > // (often very broken) source code, where spell-checking can have a > @@ -2430,6 +2424,14 @@ > Args.insert(Args.end(), command_line_args, > command_line_args + num_command_line_args); > > + // The 'source_filename' argument is optional. If the caller does not > + // specify it then it is assumed that the source file is specified > + // in the actual argument list. > + // Put the source file after command_line_args otherwise if '-x' flag is > + // present it will be unused. > + if (source_filename) > + Args.push_back(source_filename); > + > // Do we need the detailed preprocessing record? > if (options & CXTranslationUnit_DetailedPreprocessingRecord) { > Args.push_back("-Xclang"); > > > _______________________________________________ > cfe-commits mailing list > cfe-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits From andersca at mac.com Sun Mar 20 15:52:32 2011 From: andersca at mac.com (Anders Carlsson) Date: Sun, 20 Mar 2011 20:52:32 -0000 Subject: [cfe-commits] r127977 - /cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Message-ID: <20110320205232.7AB382A6C12C@llvm.org> Author: andersca Date: Sun Mar 20 15:52:32 2011 New Revision: 127977 URL: http://llvm.org/viewvc/llvm-project?rev=127977&view=rev Log: __cxa_atexit does not throw. Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=127977&r1=127976&r2=127977&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Sun Mar 20 15:52:32 2011 @@ -138,6 +138,8 @@ llvm::Constant *AtExitFn = CGM.CreateRuntimeFunction(AtExitFnTy, "__cxa_atexit"); + if (llvm::Function *Fn = dyn_cast(AtExitFn)) + Fn->setDoesNotThrow(); llvm::Constant *Handle = CGM.CreateRuntimeVariable(Int8PtrTy, "__dso_handle"); From csdavec at swan.ac.uk Sun Mar 20 16:35:39 2011 From: csdavec at swan.ac.uk (David Chisnall) Date: Sun, 20 Mar 2011 21:35:39 -0000 Subject: [cfe-commits] r127980 - in /cfe/trunk/lib: CodeGen/CGException.cpp CodeGen/CGException.h CodeGen/CGObjCGNU.cpp CodeGen/CGRTTI.cpp Sema/SemaDeclCXX.cpp Message-ID: <20110320213539.D5C382A6C12C@llvm.org> Author: theraven Date: Sun Mar 20 16:35:39 2011 New Revision: 127980 URL: http://llvm.org/viewvc/llvm-project?rev=127980&view=rev Log: Fix Objective-C++ exceptions (GNU runtime). Modified: cfe/trunk/lib/CodeGen/CGException.cpp cfe/trunk/lib/CodeGen/CGException.h cfe/trunk/lib/CodeGen/CGObjCGNU.cpp cfe/trunk/lib/CodeGen/CGRTTI.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp Modified: cfe/trunk/lib/CodeGen/CGException.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=127980&r1=127979&r2=127980&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGException.cpp (original) +++ cfe/trunk/lib/CodeGen/CGException.cpp Sun Mar 20 16:35:39 2011 @@ -160,6 +160,7 @@ const EHPersonality EHPersonality::GNU_CPlusPlus_SJLJ("__gxx_personality_sj0"); const EHPersonality EHPersonality::GNU_ObjC("__gnu_objc_personality_v0", "objc_exception_throw"); +const EHPersonality EHPersonality::GNU_ObjCXX("__gnustep_objcxx_personality_v0"); static const EHPersonality &getCPersonality(const LangOptions &L) { if (L.SjLjExceptions) @@ -201,7 +202,7 @@ // The GNU runtime's personality function inherently doesn't support // mixed EH. Use the C++ personality just to avoid returning null. - return getCXXPersonality(L); + return EHPersonality::GNU_ObjCXX; } const EHPersonality &EHPersonality::get(const LangOptions &L) { Modified: cfe/trunk/lib/CodeGen/CGException.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.h?rev=127980&r1=127979&r2=127980&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGException.h (original) +++ cfe/trunk/lib/CodeGen/CGException.h Sun Mar 20 16:35:39 2011 @@ -41,6 +41,7 @@ static const EHPersonality GNU_C; static const EHPersonality GNU_C_SJLJ; static const EHPersonality GNU_ObjC; + static const EHPersonality GNU_ObjCXX; static const EHPersonality NeXT_ObjC; static const EHPersonality GNU_CPlusPlus; static const EHPersonality GNU_CPlusPlus_SJLJ; Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=127980&r1=127979&r2=127980&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Mar 20 16:35:39 2011 @@ -30,6 +30,7 @@ #include "llvm/LLVMContext.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" +#include "llvm/Support/CallSite.h" #include "llvm/Support/Compiler.h" #include "llvm/Target/TargetData.h" @@ -141,6 +142,7 @@ if (V->getType() == Ty) return V; return B.CreateBitCast(V, Ty); } + void EmitObjCXXTryStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtTryStmt &S); public: CGObjCGNU(CodeGen::CodeGenModule &cgm); virtual llvm::Constant *GenerateConstantString(const StringLiteral *); @@ -416,8 +418,62 @@ } llvm::Constant *CGObjCGNU::GetEHType(QualType T) { - llvm_unreachable("asking for catch type for ObjC type in GNU runtime"); - return 0; + // For Objective-C++, we want to provide the ability to catch both C++ and + // Objective-C objects in the same function. + + // There's a particular fixed type info for 'id'. + if (T->isObjCIdType() || + T->isObjCQualifiedIdType()) { + llvm::Constant *IDEHType = + CGM.getModule().getGlobalVariable("__objc_id_type_info"); + if (!IDEHType) + IDEHType = + new llvm::GlobalVariable(CGM.getModule(), PtrToInt8Ty, + false, + llvm::GlobalValue::ExternalLinkage, + 0, "__objc_id_type_info"); + return llvm::ConstantExpr::getBitCast(IDEHType, PtrToInt8Ty); + } + + const ObjCObjectPointerType *PT = + T->getAs(); + assert(PT && "Invalid @catch type."); + const ObjCInterfaceType *IT = PT->getInterfaceType(); + assert(IT && "Invalid @catch type."); + std::string className = IT->getDecl()->getIdentifier()->getName(); + + std::string typeinfoName = "__objc_eh_typeinfo_" + className; + + // Return the existing typeinfo if it exists + llvm::Constant *typeinfo = TheModule.getGlobalVariable(typeinfoName); + if (typeinfo) return typeinfo; + + // Otherwise create it. + + // vtable for gnustep::libobjc::__objc_class_type_info + // It's quite ugly hard-coding this. Ideally we'd generate it using the host + // platform's name mangling. + const char *vtableName = "_ZTVN7gnustep7libobjc22__objc_class_type_infoE"; + llvm::Constant *Vtable = TheModule.getGlobalVariable(vtableName); + if (!Vtable) { + Vtable = new llvm::GlobalVariable(TheModule, PtrToInt8Ty, true, + llvm::GlobalValue::ExternalLinkage, 0, vtableName); + } + llvm::Constant *Two = llvm::ConstantInt::get(IntTy, 2); + Vtable = llvm::ConstantExpr::getGetElementPtr(Vtable, &Two, 1); + Vtable = llvm::ConstantExpr::getBitCast(Vtable, PtrToInt8Ty); + + llvm::Constant *typeName = + ExportUniqueString(className, "__objc_eh_typename_"); + + std::vector fields; + fields.push_back(Vtable); + fields.push_back(typeName); + llvm::Constant *TI = + MakeGlobal(llvm::StructType::get(VMContext, PtrToInt8Ty, PtrToInt8Ty, + NULL), fields, "__objc_eh_typeinfo_" + className, + llvm::GlobalValue::LinkOnceODRLinkage); + return llvm::ConstantExpr::getBitCast(TI, PtrToInt8Ty); } llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str, @@ -1945,6 +2001,138 @@ llvm::BasicBlock *Block; llvm::Value *TypeInfo; }; + + struct CallObjCEndCatch : EHScopeStack::Cleanup { + CallObjCEndCatch(bool MightThrow, llvm::Value *Fn) : + MightThrow(MightThrow), Fn(Fn) {} + bool MightThrow; + llvm::Value *Fn; + + void Emit(CodeGenFunction &CGF, bool IsForEH) { + if (!MightThrow) { + CGF.Builder.CreateCall(Fn)->setDoesNotThrow(); + return; + } + + CGF.EmitCallOrInvoke(Fn, 0, 0); + } + }; +} + +void CGObjCGNU::EmitObjCXXTryStmt(CodeGen::CodeGenFunction &CGF, + const ObjCAtTryStmt &S) { + std::vector Args(1, PtrToInt8Ty); + llvm::FunctionType *FTy = llvm::FunctionType::get(PtrToInt8Ty, Args, false); + const llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); + + llvm::Constant *beginCatchFn = + CGM.CreateRuntimeFunction(FTy, "__cxa_begin_catch"); + + FTy = llvm::FunctionType::get(VoidTy, false); + llvm::Constant *endCatchFn = + CGM.CreateRuntimeFunction(FTy, "__cxa_end_catch"); + FTy = llvm::FunctionType::get(VoidTy, Args, false); + llvm::Constant *exceptionRethrowFn = + CGM.CreateRuntimeFunction(FTy, "_Unwind_Resume_or_Rethrow"); + + // Jump destination for falling out of catch bodies. + CodeGenFunction::JumpDest Cont; + if (S.getNumCatchStmts()) + Cont = CGF.getJumpDestInCurrentScope("eh.cont"); + + CodeGenFunction::FinallyInfo FinallyInfo; + if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt()) + FinallyInfo = CGF.EnterFinallyBlock(Finally->getFinallyBody(), + beginCatchFn, + endCatchFn, + exceptionRethrowFn); + + llvm::SmallVector Handlers; + + // Enter the catch, if there is one. + if (S.getNumCatchStmts()) { + for (unsigned I = 0, N = S.getNumCatchStmts(); I != N; ++I) { + const ObjCAtCatchStmt *CatchStmt = S.getCatchStmt(I); + const VarDecl *CatchDecl = CatchStmt->getCatchParamDecl(); + + Handlers.push_back(CatchHandler()); + CatchHandler &Handler = Handlers.back(); + Handler.Variable = CatchDecl; + Handler.Body = CatchStmt->getCatchBody(); + Handler.Block = CGF.createBasicBlock("catch"); + + // @catch(...) always matches. + if (!CatchDecl) { + Handler.TypeInfo = 0; // catch-all + // Don't consider any other catches. + break; + } + + Handler.TypeInfo = GetEHType(CatchDecl->getType()); + } + + EHCatchScope *Catch = CGF.EHStack.pushCatch(Handlers.size()); + for (unsigned I = 0, E = Handlers.size(); I != E; ++I) + Catch->setHandler(I, Handlers[I].TypeInfo, Handlers[I].Block); + } + + // Emit the try body. + CGF.EmitStmt(S.getTryBody()); + + // Leave the try. + if (S.getNumCatchStmts()) + CGF.EHStack.popCatch(); + + // Remember where we were. + CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP(); + + // Emit the handlers. + for (unsigned I = 0, E = Handlers.size(); I != E; ++I) { + CatchHandler &Handler = Handlers[I]; + + CGF.EmitBlock(Handler.Block); + llvm::Value *RawExn = CGF.Builder.CreateLoad(CGF.getExceptionSlot()); + + // Enter the catch. + llvm::CallInst *Exn = + CGF.Builder.CreateCall(beginCatchFn, RawExn, + "exn.adjusted"); + Exn->setDoesNotThrow(); + + // Add a cleanup to leave the catch. + bool EndCatchMightThrow = (Handler.Variable == 0); + CGF.EHStack.pushCleanup(NormalAndEHCleanup, + EndCatchMightThrow, + endCatchFn); + + // Bind the catch parameter if it exists. + if (const VarDecl *CatchParam = Handler.Variable) { + const llvm::Type *CatchType = CGF.ConvertType(CatchParam->getType()); + llvm::Value *CastExn = CGF.Builder.CreateBitCast(Exn, CatchType); + + CGF.EmitAutoVarDecl(*CatchParam); + CGF.Builder.CreateStore(CastExn, CGF.GetAddrOfLocalVar(CatchParam)); + } + + CGF.ObjCEHValueStack.push_back(Exn); + CGF.EmitStmt(Handler.Body); + CGF.ObjCEHValueStack.pop_back(); + + // Leave the earlier cleanup. + CGF.PopCleanupBlock(); + + CGF.EmitBranchThroughCleanup(Cont); + } + + // Go back to the try-statement fallthrough. + CGF.Builder.restoreIP(SavedIP); + + // Pop out of the normal cleanup on the finally. + if (S.getFinallyStmt()) + CGF.ExitFinallyBlock(FinallyInfo); + + if (Cont.isValid()) + CGF.EmitBlock(Cont.getBlock()); } void CGObjCGNU::EmitTryStmt(CodeGen::CodeGenFunction &CGF, @@ -1958,6 +2146,13 @@ // (or even _Unwind_DeleteException), but probably doesn't // interoperate very well with foreign exceptions. + // In Objective-C++ mode, we actually emit something equivalent to the C++ + // exception handler. + if (CGM.getLangOptions().CPlusPlus) { + EmitObjCXXTryStmt(CGF, S); + return; + } + // Jump destination for falling out of catch bodies. CodeGenFunction::JumpDest Cont; if (S.getNumCatchStmts()) Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=127980&r1=127979&r2=127980&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original) +++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Sun Mar 20 16:35:39 2011 @@ -16,6 +16,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/AST/Type.h" #include "clang/Frontend/CodeGenOptions.h" +#include "CGObjCRuntime.h" using namespace clang; using namespace CodeGen; @@ -977,6 +978,10 @@ const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); return llvm::Constant::getNullValue(Int8PtrTy); } + + if (ForEH && Ty->isObjCObjectPointerType() && !Features.NeXTRuntime) { + return Runtime->GetEHType(Ty); + } return RTTIBuilder(*this).BuildTypeInfo(Ty); } Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=127980&r1=127979&r2=127980&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Mar 20 16:35:39 2011 @@ -6775,10 +6775,7 @@ Diag(Loc, diag::err_objc_object_catch); Invalid = true; } else if (T->isObjCObjectPointerType()) { - if (!getLangOptions().NeXTRuntime) { - Diag(Loc, diag::err_objc_pointer_cxx_catch_gnu); - Invalid = true; - } else if (!getLangOptions().ObjCNonFragileABI) { + if (!getLangOptions().ObjCNonFragileABI) { Diag(Loc, diag::err_objc_pointer_cxx_catch_fragile); Invalid = true; } From richard at metafoo.co.uk Sun Mar 20 18:56:34 2011 From: richard at metafoo.co.uk (Richard Smith) Date: Sun, 20 Mar 2011 23:56:34 -0000 (UTC) Subject: [cfe-commits] [PATCH] C++0x range-based for loop Message-ID: <37942.10.0.7.178.1300665394.squirrel@webmail.cantab.net> Hi, The attached patch adds support for C++0x's range-based for loops to clang, according to the current draft (N3242). Specifically: A new Stmt subclass, CXXForRangeStmt, has been added. This class provides two views of the for-statement: a partially-desugared representation (just enough desugaring is done to be able to perform the semantic checks needed), and an implicit source-as-written representation (extracted from the partially-desugared representation). In order to avoid tentative parsing, the parsing of the for-range-declaration is performed by ParseSimpleDeclaration. The for-range-initializer is parsed there too, in order to ensure that the for-range-declaration is not in scope in the initializer: "int a = {1,2,3}; for (auto a : a)" appears to be legal. Most of the semantic analysis for a for-range statement is performed before the body is parsed, so that the type of the loop variable can be deduced (in case it contains 'auto'). Attaching the body is performed as a separate finalization step. For a dependently-typed range expression, much of the semantic analysis is deferred until template instantiation time. A new flag has been added to VarDecl to indicate whether it's a for-range-declarator. This flag is used to skip ActOnUninitializedDecl (specifically, while instantiating a template containing a dependent for-range statement); such declarators are never actually uninitialized, but appear that way in the AST if the required semantic analysis could not be performed. As a small extension, this implementation allows the deduced 'begin' and 'end' iterators to be of differing types; this allows for-range to be used for iterators where it's easy to determine whether an iterator is at the end, but difficult or expensive to construct an explicit iterator object representing the 'end', or to compare general iterators. The wording for for-range statements seems likely to change at the upcoming WG21 meeting in Madrid (per N3257). Resolution 2 for this change can be implemented by changing the NeedsADL flag from true to false in BuildForRangeBeginEndCall in SemaStmt.cpp. Please review! Thanks, Richard -------------- next part -------------- A non-text attachment was scrubbed... Name: clang-for-range.diff Type: text/x-patch Size: 82171 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/cfe-commits/attachments/20110320/52466365/attachment-0001.bin From peter at pcc.me.uk Sun Mar 20 20:45:18 2011 From: peter at pcc.me.uk (Peter Collingbourne) Date: Mon, 21 Mar 2011 01:45:18 -0000 Subject: [cfe-commits] r127983 - /cfe/trunk/docs/InternalsManual.html Message-ID: <20110321014518.4969B2A6C12C@llvm.org> Author: pcc Date: Sun Mar 20 20:45:18 2011 New Revision: 127983 URL: http://llvm.org/viewvc/llvm-project?rev=127983&view=rev Log: Code modification hints have been known as fix-it hints for almost a year now. Update the internals manual. Modified: cfe/trunk/docs/InternalsManual.html Modified: cfe/trunk/docs/InternalsManual.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/InternalsManual.html?rev=127983&r1=127982&r2=127983&view=diff ============================================================================== --- cfe/trunk/docs/InternalsManual.html (original) +++ cfe/trunk/docs/InternalsManual.html Sun Mar 20 20:45:18 2011 @@ -412,7 +412,7 @@

    -

    Code Modification Hints

    +

    Fix-It Hints

    In some cases, the front end emits diagnostics when it is clear @@ -422,14 +422,14 @@ Clang tries very hard to emit the diagnostic and recover gracefully in these and other cases.

    -

    However, for these cases where the fix is obvious, the diagnostic -can be annotated with a code -modification "hint" that describes how to change the code referenced -by the diagnostic to fix the problem. For example, it might add the -missing semicolon at the end of the statement or rewrite the use of a -deprecated construct into something more palatable. Here is one such -example C++ front end, where we warn about the right-shift operator -changing meaning from C++98 to C++0x:

    +

    However, for these cases where the fix is obvious, the diagnostic +can be annotated with a hint (referred to as a "fix-it hint") that +describes how to change the code referenced by the diagnostic to fix +the problem. For example, it might add the missing semicolon at the +end of the statement or rewrite the use of a deprecated construct +into something more palatable. Here is one such example from the C++ +front end, where we warn about the right-shift operator changing +meaning from C++98 to C++0x:

     test.cpp:3:7: warning: use of right-shift operator ('>>') in template argument will require parentheses in C++0x
    @@ -438,33 +438,31 @@
       (       )
     
    -

    Here, the code modification hint is suggesting that parentheses be -added, and showing exactly where those parentheses would be inserted -into the source code. The code modification hints themselves describe -what changes to make to the source code in an abstract manner, which -the text diagnostic printer renders as a line of "insertions" below -the caret line. Other diagnostic -clients might choose to render the code differently (e.g., as -markup inline) or even give the user the ability to automatically fix -the problem.

    - -

    All code modification hints are described by the -CodeModificationHint class, instances of which should be -attached to the diagnostic using the << operator in the same way -that highlighted source ranges and arguments are passed to the -diagnostic. Code modification hints can be created with one of three -constructors:

    +

    Here, the fix-it hint is suggesting that parentheses be added, +and showing exactly where those parentheses would be inserted into the +source code. The fix-it hints themselves describe what changes to make +to the source code in an abstract manner, which the text diagnostic +printer renders as a line of "insertions" below the caret line. Other diagnostic clients might choose +to render the code differently (e.g., as markup inline) or even give +the user the ability to automatically fix the problem.

    + +

    All fix-it hints are described by the FixItHint class, +instances of which should be attached to the diagnostic using the +<< operator in the same way that highlighted source ranges and +arguments are passed to the diagnostic. Fix-it hints can be created +with one of three constructors:

    -
    CodeModificationHint::CreateInsertion(Loc, Code)
    +
    FixItHint::CreateInsertion(Loc, Code)
    Specifies that the given Code (a string) should be inserted before the source location Loc.
    -
    CodeModificationHint::CreateRemoval(Range)
    +
    FixItHint::CreateRemoval(Range)
    Specifies that the code in the given source Range should be removed.
    -
    CodeModificationHint::CreateReplacement(Range, Code)
    +
    FixItHint::CreateReplacement(Range, Code)
    Specifies that the code in the given source Range should be removed, and replaced with the given Code string.